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