*** empty log message ***
[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 // TODO: DeleteObject((HPEN) M_PENDATA->m_hPen);
137 M_PENDATA->m_hPen = 0;
138 return TRUE;
139 }
140 else return FALSE;
141 }
142
143 bool wxPen::IsFree() const
144 {
145 return (M_PENDATA && M_PENDATA->m_hPen == 0);
146 }
147
148 void wxPen::Unshare()
149 {
150 // Don't change shared data
151 if (!m_refData)
152 {
153 m_refData = new wxPenRefData();
154 }
155 else
156 {
157 wxPenRefData* ref = new wxPenRefData(*(wxPenRefData*)m_refData);
158 UnRef();
159 m_refData = ref;
160 }
161 }
162
163 void wxPen::SetColour(const wxColour& col)
164 {
165 Unshare();
166
167 M_PENDATA->m_colour = col;
168
169 RealizeResource();
170 }
171
172 void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b)
173 {
174 Unshare();
175
176 M_PENDATA->m_colour.Set(r, g, b);
177
178 RealizeResource();
179 }
180
181 void wxPen::SetWidth(int Width)
182 {
183 Unshare();
184
185 M_PENDATA->m_width = Width;
186
187 RealizeResource();
188 }
189
190 void wxPen::SetStyle(int Style)
191 {
192 Unshare();
193
194 M_PENDATA->m_style = Style;
195
196 RealizeResource();
197 }
198
199 void wxPen::SetStipple(const wxBitmap& Stipple)
200 {
201 Unshare();
202
203 M_PENDATA->m_stipple = Stipple;
204 M_PENDATA->m_style = wxSTIPPLE;
205
206 RealizeResource();
207 }
208
209 void wxPen::SetDashes(int nb_dashes, const wxDash *Dash)
210 {
211 Unshare();
212
213 M_PENDATA->m_nbDash = nb_dashes;
214 M_PENDATA->m_dash = (wxDash *)Dash;
215
216 RealizeResource();
217 }
218
219 void wxPen::SetJoin(int Join)
220 {
221 Unshare();
222
223 M_PENDATA->m_join = Join;
224
225 RealizeResource();
226 }
227
228 void wxPen::SetCap(int Cap)
229 {
230 Unshare();
231
232 M_PENDATA->m_cap = Cap;
233
234 RealizeResource();
235 }
236
237 int wx2os2PenStyle(int wx_style)
238 {
239 int cstyle;
240 // TODO:
241 /*
242 switch (wx_style)
243 {
244 case wxDOT:
245 cstyle = PS_DOT;
246 break;
247
248 case wxDOT_DASH:
249 cstyle = PS_DASHDOT;
250 break;
251
252 case wxSHORT_DASH:
253 case wxLONG_DASH:
254 cstyle = PS_DASH;
255 break;
256
257 case wxTRANSPARENT:
258 cstyle = PS_NULL;
259 break;
260
261 case wxUSER_DASH:
262 #ifdef __WIN32__
263 // Win32s doesn't have PS_USERSTYLE
264 if (wxGetOsVersion()==wxWINDOWS_NT || wxGetOsVersion()==wxWIN95)
265 cstyle = PS_USERSTYLE;
266 else
267 cstyle = PS_DOT; // We must make a choice... This is mine!
268 #else
269 cstyle = PS_DASH;
270 #endif
271 break;
272 case wxSOLID:
273 default:
274 cstyle = PS_SOLID;
275 break;
276 }
277 */
278 return cstyle;
279 }
280
281