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