]> git.saurik.com Git - wxWidgets.git/blob - src/dfb/pen.cpp
avoid GCC warning about type-punned pointer breaking strict aliasing rules
[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, int style = wxSOLID)
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 int 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, int 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 wxBitmap& WXUNUSED(stipple), int WXUNUSED(width))
72 {
73 wxFAIL_MSG( "stipple pens not supported" );
74
75 m_refData = new wxPenRefData();
76 }
77
78 bool wxPen::operator==(const wxPen& pen) const
79 {
80 #warning "this is incorrect (MGL too)"
81 return m_refData == pen.m_refData;
82 }
83
84 void wxPen::SetColour(const wxColour &colour)
85 {
86 AllocExclusive();
87 M_PENDATA->m_colour = colour;
88 }
89
90 void wxPen::SetDashes(int WXUNUSED(number_of_dashes), const wxDash *WXUNUSED(dash))
91 {
92 wxFAIL_MSG( "SetDashes not implemented" );
93 }
94
95 void wxPen::SetColour(unsigned char red, unsigned char green, unsigned char blue)
96 {
97 AllocExclusive();
98 M_PENDATA->m_colour.Set(red, green, blue);
99 }
100
101 void wxPen::SetCap(int WXUNUSED(capStyle))
102 {
103 wxFAIL_MSG( "SetCap not implemented" );
104 }
105
106 void wxPen::SetJoin(int WXUNUSED(joinStyle))
107 {
108 wxFAIL_MSG( "SetJoin not implemented" );
109 }
110
111 void wxPen::SetStyle(int style)
112 {
113 AllocExclusive();
114 M_PENDATA->SetStyle(style);
115 }
116
117 void wxPen::SetStipple(const wxBitmap& WXUNUSED(stipple))
118 {
119 wxFAIL_MSG( "SetStipple not implemented" );
120 }
121
122 void wxPen::SetWidth(int width)
123 {
124 wxASSERT_MSG( width <= 1, "only width=0,1 are implemented" );
125 }
126
127 int wxPen::GetDashes(wxDash **ptr) const
128 {
129 wxFAIL_MSG( "GetDashes not implemented" );
130
131 *ptr = NULL;
132 return 0;
133 }
134
135 int wxPen::GetDashCount() const
136 {
137 wxFAIL_MSG( "GetDashCount not implemented" );
138
139 return 0;
140 }
141
142 wxDash* wxPen::GetDash() const
143 {
144 wxFAIL_MSG( "GetDash not implemented" );
145
146 return NULL;
147 }
148
149 int wxPen::GetCap() const
150 {
151 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
152
153 wxFAIL_MSG( "GetCap not implemented" );
154 return -1;
155 }
156
157 int wxPen::GetJoin() const
158 {
159 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
160
161 wxFAIL_MSG( "GetJoin not implemented" );
162 return -1;
163 }
164
165 int wxPen::GetStyle() const
166 {
167 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
168
169 return M_PENDATA->m_style;
170 }
171
172 int wxPen::GetWidth() const
173 {
174 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
175
176 return 1;
177 }
178
179 wxColour &wxPen::GetColour() const
180 {
181 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
182
183 return M_PENDATA->m_colour;
184 }
185
186 wxBitmap *wxPen::GetStipple() const
187 {
188 wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
189
190 wxFAIL_MSG( "GetStipple not implemented" );
191 return NULL;
192 }
193
194 wxGDIRefData *wxPen::CreateGDIRefData() const
195 {
196 return new wxPenRefData;
197 }
198
199 wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const
200 {
201 return new wxPenRefData(*(wxPenRefData *)data);
202 }