1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        src/dfb/pen.cpp
3 // Purpose:     wxPen class implementation
4 // Author:      Vaclav Slavik
5 // Created:     2006-08-04
6 // Copyright:   (c) 2006 REA Elektronik GmbH
7 // Licence:     wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9 
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12 
13 
14 #include "wx/pen.h"
15 
16 #ifndef WX_PRECOMP
17     #include "wx/bitmap.h"
18     #include "wx/colour.h"
19 #endif
20 
21 //-----------------------------------------------------------------------------
22 // wxPen
23 //-----------------------------------------------------------------------------
24 
25 class wxPenRefData : public wxGDIRefData
26 {
27 public:
wxPenRefData(const wxColour & clr=wxNullColour,wxPenStyle style=wxPENSTYLE_SOLID)28     wxPenRefData(const wxColour& clr = wxNullColour, wxPenStyle style = wxPENSTYLE_SOLID)
29     {
30         m_colour = clr;
31         SetStyle(style);
32     }
33 
wxPenRefData(const wxPenRefData & data)34     wxPenRefData(const wxPenRefData& data)
35         : m_style(data.m_style), m_colour(data.m_colour) {}
36 
IsOk() const37     virtual bool IsOk() const { return m_colour.IsOk(); }
38 
SetStyle(wxPenStyle style)39     void SetStyle(wxPenStyle style)
40     {
41         if ( style != wxPENSTYLE_SOLID && style != wxPENSTYLE_TRANSPARENT )
42         {
43             wxFAIL_MSG( "only wxPENSTYLE_SOLID and wxPENSTYLE_TRANSPARENT styles are supported" );
44             style = wxPENSTYLE_SOLID;
45         }
46 
47         m_style = style;
48     }
49 
50     wxPenStyle     m_style;
51     wxColour       m_colour;
52 };
53 
54 //-----------------------------------------------------------------------------
55 
56 #define M_PENDATA ((wxPenRefData *)m_refData)
57 
58 wxIMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject);
59 
wxPen(const wxColour & colour,int width,wxPenStyle style)60 wxPen::wxPen(const wxColour &colour, int width, wxPenStyle style)
61 {
62     wxASSERT_MSG( width <= 1, "only width=0,1 are supported" );
63 
64     m_refData = new wxPenRefData(colour, style);
65 }
66 
wxPen(const wxColour & col,int width,int style)67 wxPen::wxPen(const wxColour& col, int width, int style)
68 {
69     m_refData = new wxPenRefData(col, (wxPenStyle)style);
70 }
71 
wxPen(const wxBitmap & WXUNUSED (stipple),int WXUNUSED (width))72 wxPen::wxPen(const wxBitmap& WXUNUSED(stipple), int WXUNUSED(width))
73 {
74     wxFAIL_MSG( "stipple pens not supported" );
75 
76     m_refData = new wxPenRefData();
77 }
78 
wxPen(const wxPenInfo & info)79 wxPen::wxPen(const wxPenInfo& info)
80 {
81     m_refData = new wxPenRefData(info.GetColour(), info.GetStyle());
82 }
83 
operator ==(const wxPen & pen) const84 bool wxPen::operator==(const wxPen& pen) const
85 {
86 #warning "this is incorrect"
87     return m_refData == pen.m_refData;
88 }
89 
SetColour(const wxColour & colour)90 void wxPen::SetColour(const wxColour &colour)
91 {
92     AllocExclusive();
93     M_PENDATA->m_colour = colour;
94 }
95 
SetDashes(int WXUNUSED (number_of_dashes),const wxDash * WXUNUSED (dash))96 void wxPen::SetDashes(int WXUNUSED(number_of_dashes), const wxDash *WXUNUSED(dash))
97 {
98     wxFAIL_MSG( "SetDashes not implemented" );
99 }
100 
SetColour(unsigned char red,unsigned char green,unsigned char blue)101 void wxPen::SetColour(unsigned char red, unsigned char green, unsigned char blue)
102 {
103     AllocExclusive();
104     M_PENDATA->m_colour.Set(red, green, blue);
105 }
106 
SetCap(wxPenCap WXUNUSED (capStyle))107 void wxPen::SetCap(wxPenCap WXUNUSED(capStyle))
108 {
109     wxFAIL_MSG( "SetCap not implemented" );
110 }
111 
SetJoin(wxPenJoin WXUNUSED (joinStyle))112 void wxPen::SetJoin(wxPenJoin WXUNUSED(joinStyle))
113 {
114     wxFAIL_MSG( "SetJoin not implemented" );
115 }
116 
SetStyle(wxPenStyle style)117 void wxPen::SetStyle(wxPenStyle style)
118 {
119     AllocExclusive();
120     M_PENDATA->SetStyle(style);
121 }
122 
SetStipple(const wxBitmap & WXUNUSED (stipple))123 void wxPen::SetStipple(const wxBitmap& WXUNUSED(stipple))
124 {
125     wxFAIL_MSG( "SetStipple not implemented" );
126 }
127 
SetWidth(int width)128 void wxPen::SetWidth(int width)
129 {
130     wxASSERT_MSG( width <= 1, "only width=0,1 are implemented" );
131 }
132 
GetDashes(wxDash ** ptr) const133 int wxPen::GetDashes(wxDash **ptr) const
134 {
135     wxFAIL_MSG( "GetDashes not implemented" );
136 
137     *ptr = NULL;
138     return 0;
139 }
140 
GetDashCount() const141 int wxPen::GetDashCount() const
142 {
143     wxFAIL_MSG( "GetDashCount not implemented" );
144 
145     return 0;
146 }
147 
GetDash() const148 wxDash* wxPen::GetDash() const
149 {
150     wxFAIL_MSG( "GetDash not implemented" );
151 
152     return NULL;
153 }
154 
GetCap() const155 wxPenCap wxPen::GetCap() const
156 {
157     wxCHECK_MSG( IsOk(), wxCAP_INVALID, wxT("invalid pen") );
158 
159     wxFAIL_MSG( "GetCap not implemented" );
160     return wxCAP_INVALID;
161 }
162 
GetJoin() const163 wxPenJoin wxPen::GetJoin() const
164 {
165     wxCHECK_MSG( IsOk(), wxJOIN_INVALID, wxT("invalid pen") );
166 
167     wxFAIL_MSG( "GetJoin not implemented" );
168     return wxJOIN_INVALID;
169 }
170 
GetStyle() const171 wxPenStyle wxPen::GetStyle() const
172 {
173     wxCHECK_MSG( IsOk(), wxPENSTYLE_INVALID, wxT("invalid pen") );
174 
175     return M_PENDATA->m_style;
176 }
177 
GetWidth() const178 int wxPen::GetWidth() const
179 {
180     wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
181 
182     return 1;
183 }
184 
GetColour() const185 wxColour wxPen::GetColour() const
186 {
187     wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid pen") );
188 
189     return M_PENDATA->m_colour;
190 }
191 
GetStipple() const192 wxBitmap *wxPen::GetStipple() const
193 {
194     wxCHECK_MSG( IsOk(), NULL, wxT("invalid pen") );
195 
196     wxFAIL_MSG( "GetStipple not implemented" );
197     return NULL;
198 }
199 
CreateGDIRefData() const200 wxGDIRefData *wxPen::CreateGDIRefData() const
201 {
202     return new wxPenRefData;
203 }
204 
CloneGDIRefData(const wxGDIRefData * data) const205 wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const
206 {
207     return new wxPenRefData(*(wxPenRefData *)data);
208 }
209