]> git.saurik.com Git - wxWidgets.git/blob - src/os2/pen.cpp
wxWS_EX_VALIDATE_RECURSIVELY set by default if parent has it
[wxWidgets.git] / src / os2 / pen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: pen.cpp
3 // Purpose: wxPen
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/10/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include <stdio.h>
17 #include "wx/setup.h"
18 #include "wx/list.h"
19 #include "wx/utils.h"
20 #include "wx/app.h"
21 #include "wx/pen.h"
22 #endif
23
24 #include "wx/os2/private.h"
25 #include "assert.h"
26
27 IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject)
28
29 wxPenRefData::wxPenRefData()
30 {
31 m_style = wxSOLID;
32 m_width = 1;
33 m_join = wxJOIN_ROUND ;
34 m_cap = wxCAP_ROUND ;
35 m_nbDash = 0 ;
36 m_dash = 0 ;
37 m_hPen = 0;
38 }
39
40 wxPenRefData::wxPenRefData(const wxPenRefData& data)
41 {
42 m_style = data.m_style;
43 m_width = data.m_width;
44 m_join = data.m_join;
45 m_cap = data.m_cap;
46 m_nbDash = data.m_nbDash;
47 m_dash = data.m_dash;
48 m_colour = data.m_colour;
49 /* TODO: null data
50 m_hPen = 0;
51 */
52 }
53
54 wxPenRefData::~wxPenRefData()
55 {
56 // TODO: delete data
57 }
58
59 // Pens
60
61 wxPen::wxPen()
62 {
63 if ( wxThePenList )
64 wxThePenList->AddPen(this);
65 }
66
67 wxPen::~wxPen()
68 {
69 if (wxThePenList)
70 wxThePenList->RemovePen(this);
71 }
72
73 // Should implement Create
74 wxPen::wxPen(const wxColour& col, int Width, int Style)
75 {
76 m_refData = new wxPenRefData;
77
78 M_PENDATA->m_colour = col;
79 // M_PENDATA->m_stipple = NULL;
80 M_PENDATA->m_width = Width;
81 M_PENDATA->m_style = Style;
82 M_PENDATA->m_join = wxJOIN_ROUND ;
83 M_PENDATA->m_cap = wxCAP_ROUND ;
84 M_PENDATA->m_nbDash = 0 ;
85 M_PENDATA->m_dash = 0 ;
86 M_PENDATA->m_hPen = 0 ;
87
88 // TODO:
89 /*
90 if ((Style == wxDOT) || (Style == wxLONG_DASH) ||
91 (Style == wxSHORT_DASH) || (Style == wxDOT_DASH) ||
92 (Style == wxUSER_DASH))
93 M_PENDATA->m_width = 1;
94 */
95 RealizeResource();
96
97 if ( wxThePenList )
98 wxThePenList->AddPen(this);
99 }
100
101 wxPen::wxPen(const wxBitmap& stipple, int Width)
102 {
103 m_refData = new wxPenRefData;
104
105 M_PENDATA->m_stipple = stipple;
106 M_PENDATA->m_width = Width;
107 M_PENDATA->m_style = wxSTIPPLE;
108 M_PENDATA->m_join = wxJOIN_ROUND ;
109 M_PENDATA->m_cap = wxCAP_ROUND ;
110 M_PENDATA->m_nbDash = 0 ;
111 M_PENDATA->m_dash = 0 ;
112 M_PENDATA->m_hPen = 0 ;
113
114 RealizeResource();
115
116 if ( wxThePenList )
117 wxThePenList->AddPen(this);
118 }
119
120 bool wxPen::RealizeResource()
121 {
122 // TODO: create actual pen
123 return FALSE;
124 }
125
126 WXHANDLE wxPen::GetResourceHandle()
127 {
128 if ( !M_PENDATA )
129 return 0;
130 else
131 return (WXHANDLE)M_PENDATA->m_hPen;
132 }
133
134 bool wxPen::FreeResource(bool force)
135 {
136 if (M_PENDATA && (M_PENDATA->m_hPen != 0))
137 {
138 // TODO: DeleteObject((HPEN) M_PENDATA->m_hPen);
139 M_PENDATA->m_hPen = 0;
140 return TRUE;
141 }
142 else return FALSE;
143 }
144
145 bool wxPen::IsFree() const
146 {
147 return (M_PENDATA && M_PENDATA->m_hPen == 0);
148 }
149
150 void wxPen::Unshare()
151 {
152 // Don't change shared data
153 if (!m_refData)
154 {
155 m_refData = new wxPenRefData();
156 }
157 else
158 {
159 wxPenRefData* ref = new wxPenRefData(*(wxPenRefData*)m_refData);
160 UnRef();
161 m_refData = ref;
162 }
163 }
164
165 void wxPen::SetColour(const wxColour& col)
166 {
167 Unshare();
168
169 M_PENDATA->m_colour = col;
170
171 RealizeResource();
172 }
173
174 void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b)
175 {
176 Unshare();
177
178 M_PENDATA->m_colour.Set(r, g, b);
179
180 RealizeResource();
181 }
182
183 void wxPen::SetWidth(int Width)
184 {
185 Unshare();
186
187 M_PENDATA->m_width = Width;
188
189 RealizeResource();
190 }
191
192 void wxPen::SetStyle(int Style)
193 {
194 Unshare();
195
196 M_PENDATA->m_style = Style;
197
198 RealizeResource();
199 }
200
201 void wxPen::SetStipple(const wxBitmap& Stipple)
202 {
203 Unshare();
204
205 M_PENDATA->m_stipple = Stipple;
206 M_PENDATA->m_style = wxSTIPPLE;
207
208 RealizeResource();
209 }
210
211 void wxPen::SetDashes(int nb_dashes, const wxDash *Dash)
212 {
213 Unshare();
214
215 M_PENDATA->m_nbDash = nb_dashes;
216 M_PENDATA->m_dash = (wxDash *)Dash;
217
218 RealizeResource();
219 }
220
221 void wxPen::SetJoin(int Join)
222 {
223 Unshare();
224
225 M_PENDATA->m_join = Join;
226
227 RealizeResource();
228 }
229
230 void wxPen::SetCap(int Cap)
231 {
232 Unshare();
233
234 M_PENDATA->m_cap = Cap;
235
236 RealizeResource();
237 }
238
239 int wx2os2PenStyle(int wx_style)
240 {
241 int cstyle = 0;
242 // TODO:
243 /*
244 switch (wx_style)
245 {
246 case wxDOT:
247 cstyle = PS_DOT;
248 break;
249
250 case wxDOT_DASH:
251 cstyle = PS_DASHDOT;
252 break;
253
254 case wxSHORT_DASH:
255 case wxLONG_DASH:
256 cstyle = PS_DASH;
257 break;
258
259 case wxTRANSPARENT:
260 cstyle = PS_NULL;
261 break;
262
263 case wxUSER_DASH:
264 #ifdef __WIN32__
265 // Win32s doesn't have PS_USERSTYLE
266 if (wxGetOsVersion()==wxWINDOWS_NT || wxGetOsVersion()==wxWIN95)
267 cstyle = PS_USERSTYLE;
268 else
269 cstyle = PS_DOT; // We must make a choice... This is mine!
270 #else
271 cstyle = PS_DASH;
272 #endif
273 break;
274 case wxSOLID:
275 default:
276 cstyle = PS_SOLID;
277 break;
278 }
279 */
280 return cstyle;
281 }
282
283