]> git.saurik.com Git - wxWidgets.git/blame - src/os2/pen.cpp
renamed RGBColor setter to avoid former overload being an override
[wxWidgets.git] / src / os2 / pen.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
46562151 2// Name: src/os2/pen.cpp
0e320a79 3// Purpose: wxPen
cdf1e714 4// Author: David Webster
0e320a79 5// Modified by:
cdf1e714 6// Created: 10/10/99
0e320a79 7// RCS-ID: $Id$
cdf1e714 8// Copyright: (c) David Webster
65571936 9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
cdf1e714
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
0e320a79 14
cdf1e714 15#ifndef WX_PRECOMP
521bf4ff
WS
16 #include <stdio.h>
17 #include "wx/list.h"
18 #include "wx/utils.h"
19 #include "wx/app.h"
20 #include "wx/pen.h"
21 #include "wx/log.h"
0e320a79
DW
22#endif
23
cdf1e714
DW
24#include "wx/os2/private.h"
25#include "assert.h"
26
004fd0c8 27IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject)
004fd0c8 28
0e320a79
DW
29wxPenRefData::wxPenRefData()
30{
26ac77db
DW
31 m_nStyle = wxSOLID;
32 m_nWidth = 1;
33 m_nJoin = wxJOIN_ROUND ;
34 m_nCap = wxCAP_ROUND ;
9e878707
SN
35 m_nbDash = 0 ;
36 m_dash = (wxDash*)NULL;
26ac77db
DW
37 m_hPen = 0L;
38} // end of wxPenRefData::wxPenRefData
39
40wxPenRefData::wxPenRefData(
41 const wxPenRefData& rData
42)
0e320a79 43{
26ac77db
DW
44 m_nStyle = rData.m_nStyle;
45 m_nWidth = rData.m_nWidth;
46 m_nJoin = rData.m_nJoin;
47 m_nCap = rData.m_nCap;
9e878707
SN
48 m_nbDash = rData.m_nbDash;
49 m_dash = rData.m_dash;
26ac77db
DW
50 m_vColour = rData.m_vColour;
51 m_hPen = 0L;
52} // end of wxPenRefData::wxPenRefData
0e320a79
DW
53
54wxPenRefData::~wxPenRefData()
55{
26ac77db 56} // end of wxPenRefData::~wxPenRefData
0e320a79 57
26ac77db 58//
0e320a79 59// Pens
26ac77db 60//
0e320a79
DW
61wxPen::wxPen()
62{
26ac77db 63} // end of wxPen::wxPen
0e320a79
DW
64
65wxPen::~wxPen()
66{
26ac77db 67} // end of wxPen::wxPen
0e320a79
DW
68
69// Should implement Create
26ac77db
DW
70wxPen::wxPen(
71 const wxColour& rColour
72, int nWidth
73, int nStyle
74)
0e320a79
DW
75{
76 m_refData = new wxPenRefData;
77
26ac77db
DW
78 M_PENDATA->m_vColour = rColour;
79 M_PENDATA->m_nWidth = nWidth;
80 M_PENDATA->m_nStyle = nStyle;
81 M_PENDATA->m_nJoin = wxJOIN_ROUND ;
82 M_PENDATA->m_nCap = wxCAP_ROUND ;
83 M_PENDATA->m_hPen = 0L;
84
0e320a79 85 RealizeResource();
26ac77db 86} // end of wxPen::wxPen
0e320a79 87
26ac77db
DW
88wxPen::wxPen(
89 const wxBitmap& rStipple
90, int nWidth
91)
0e320a79
DW
92{
93 m_refData = new wxPenRefData;
94
26ac77db
DW
95 M_PENDATA->m_vStipple = rStipple;
96 M_PENDATA->m_nWidth = nWidth;
97 M_PENDATA->m_nStyle = wxSTIPPLE;
98 M_PENDATA->m_nJoin = wxJOIN_ROUND ;
99 M_PENDATA->m_nCap = wxCAP_ROUND ;
100 M_PENDATA->m_hPen = 0;
0e320a79
DW
101
102 RealizeResource();
26ac77db 103} // end of wxPen::wxPen
0e320a79 104
272ebf16
SN
105int wx2os2PenStyle(
106 int nWxStyle
107);
108
cdf1e714
DW
109bool wxPen::RealizeResource()
110{
26ac77db
DW
111 BOOL bOk;
112 ERRORID vError;
113 wxString sError;
114
115 if (M_PENDATA && M_PENDATA->m_hPen == 0L)
116 {
117 SIZEL vSize = {0, 0};
118 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
119 HDC hDC = ::DevOpenDC( vHabmain
120 ,OD_MEMORY
121 ,"*"
122 ,5L
123 ,(PDEVOPENDATA)&vDop
124 ,NULLHANDLE
125 );
126 M_PENDATA->m_hPen = (WXHPEN)::GpiCreatePS( vHabmain
127 ,hDC
128 ,&vSize
129 ,PU_PELS | GPIT_MICRO | GPIA_ASSOC
130 );
131 }
132 if (M_PENDATA)
133 {
134 //
135 // Set the color table to RGB mode
136 //
137 if (!::GpiCreateLogColorTable( (HPS)M_PENDATA->m_hPen
138 ,0L
139 ,LCOLF_RGB
140 ,0L
141 ,0L
142 ,NULL
143 ))
144 {
145 vError = ::WinGetLastError(vHabmain);
146 sError = wxPMErrorToStr(vError);
0fba44b4 147 wxLogError(_T("Unable to set current color table to RGB mode. Error: %s\n"), sError.c_str());
46562151 148 return false;
26ac77db
DW
149 }
150 if (M_PENDATA->m_nStyle == wxTRANSPARENT)
151 {
6670f564 152 return true;
26ac77db
DW
153 }
154
6670f564
WS
155 COLORREF vPmColour = 0L;
156 USHORT uLineType = (USHORT)wx2os2PenStyle(M_PENDATA->m_nStyle);
26ac77db
DW
157
158 vPmColour = M_PENDATA->m_vColour.GetPixel();
159
160 USHORT uJoin = 0L;
161
162 switch(M_PENDATA->m_nJoin)
163 {
164 case wxJOIN_BEVEL:
165 uJoin = LINEJOIN_BEVEL;
166 break;
167
168 case wxJOIN_MITER:
169 uJoin = LINEJOIN_MITRE;
170 break;
171
172 case wxJOIN_ROUND:
173 uJoin = LINEJOIN_ROUND;
174 break;
175 }
176
177 USHORT uCap = 0L;
178
179 switch(M_PENDATA->m_nCap)
180 {
181 case wxCAP_PROJECTING:
182 uCap = LINEEND_SQUARE;
183 break;
184
185 case wxCAP_BUTT:
186 uCap = LINEEND_FLAT;
187 break;
188
189 case wxCAP_ROUND:
190 uCap = LINEEND_ROUND;
191 break;
192 }
193 m_vLineBundle.lColor = (LONG)vPmColour;
194 m_vLineBundle.usMixMode = FM_OVERPAINT;
195 m_vLineBundle.fxWidth = M_PENDATA->m_nWidth;
196 m_vLineBundle.lGeomWidth = M_PENDATA->m_nWidth;
197 m_vLineBundle.usType = uLineType;
198 m_vLineBundle.usEnd = uCap;
199 m_vLineBundle.usJoin = uJoin;
200
201 bOk = ::GpiSetAttrs( M_PENDATA->m_hPen
202 ,PRIM_LINE
203 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE | LBB_END | LBB_JOIN
204 ,0L
205 ,&m_vLineBundle
206 );
207 if (!bOk)
208 {
209 vError = ::WinGetLastError(vHabmain);
210 sError = wxPMErrorToStr(vError);
0fba44b4 211 wxLogError(_T("Can't set Gpi attributes for a LINEBUNDLE. Error: %s\n"), sError.c_str());
46562151 212 return false;
26ac77db
DW
213 }
214
d697657f
DW
215 ULONG flAttrMask = 0L;
216 ULONG flDefMask = 0L;
26ac77db
DW
217 switch(M_PENDATA->m_nStyle)
218 {
219 case wxSTIPPLE:
220 ::GpiSetBitmapId( M_PENDATA->m_hPen
221 ,(USHORT)M_PENDATA->m_vStipple.GetHBITMAP()
222 ,(USHORT)M_PENDATA->m_vStipple.GetId()
223 );
224 ::GpiSetPatternSet( M_PENDATA->m_hPen
225 ,(USHORT)M_PENDATA->m_vStipple.GetId()
226 );
d697657f
DW
227 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SET | ABB_SYMBOL;
228 flDefMask = ABB_REF_POINT;
26ac77db
DW
229 break;
230
231 case wxBDIAGONAL_HATCH:
232 m_vAreaBundle.usSymbol = PATSYM_DIAG3;
233 m_vAreaBundle.usSet = LCID_DEFAULT;
d697657f
DW
234 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
235 flDefMask = ABB_SET | ABB_REF_POINT;
26ac77db
DW
236 break;
237
238 case wxCROSSDIAG_HATCH:
239 m_vAreaBundle.usSymbol = PATSYM_DIAGHATCH;
240 m_vAreaBundle.usSet = LCID_DEFAULT;
d697657f
DW
241 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
242 flDefMask = ABB_SET | ABB_REF_POINT;
26ac77db
DW
243 break;
244
245 case wxFDIAGONAL_HATCH:
246 m_vAreaBundle.usSymbol = PATSYM_DIAG1;
247 m_vAreaBundle.usSet = LCID_DEFAULT;
d697657f
DW
248 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
249 flDefMask = ABB_SET | ABB_REF_POINT;
26ac77db
DW
250 break;
251
252 case wxCROSS_HATCH:
253 m_vAreaBundle.usSymbol = PATSYM_HATCH;
254 m_vAreaBundle.usSet = LCID_DEFAULT;
d697657f
DW
255 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
256 flDefMask = ABB_SET | ABB_REF_POINT;
26ac77db
DW
257 break;
258
259 case wxHORIZONTAL_HATCH:
260 m_vAreaBundle.usSymbol = PATSYM_HORIZ;
261 m_vAreaBundle.usSet = LCID_DEFAULT;
d697657f
DW
262 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
263 flDefMask = ABB_SET | ABB_REF_POINT;
26ac77db
DW
264 break;
265
266 case wxVERTICAL_HATCH:
267 m_vAreaBundle.usSymbol = PATSYM_VERT;
268 m_vAreaBundle.usSet = LCID_DEFAULT;
d697657f
DW
269 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
270 flDefMask = ABB_SET | ABB_REF_POINT;
26ac77db
DW
271 break;
272
273 default:
274 m_vAreaBundle.usSymbol = PATSYM_SOLID;
275 m_vAreaBundle.usSet = LCID_DEFAULT;
d697657f
DW
276 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
277 flDefMask = ABB_SET | ABB_REF_POINT;
26ac77db
DW
278 break;
279 }
280
281 m_vAreaBundle.lColor = vPmColour;
8d854fa9 282 m_vAreaBundle.lBackColor = RGB_WHITE;
26ac77db
DW
283 m_vAreaBundle.usMixMode = FM_OVERPAINT;
284 m_vAreaBundle.usBackMixMode = BM_OVERPAINT;
285
286 bOk = ::GpiSetAttrs( M_PENDATA->m_hPen
287 ,PRIM_AREA
d697657f
DW
288 ,flAttrMask
289 ,flDefMask
26ac77db
DW
290 ,&m_vAreaBundle
291 );
292 if (!bOk)
293 {
294 vError = ::WinGetLastError(vHabmain);
295 sError = wxPMErrorToStr(vError);
0fba44b4 296 wxLogError(_T("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n"), sError.c_str());
26ac77db 297 }
6670f564
WS
298
299 return (bool)bOk;
26ac77db 300 }
6670f564 301 return false;
26ac77db 302} // end of wxPen::RealizeResource
cdf1e714
DW
303
304WXHANDLE wxPen::GetResourceHandle()
305{
26ac77db 306 if (!M_PENDATA)
cdf1e714
DW
307 return 0;
308 else
309 return (WXHANDLE)M_PENDATA->m_hPen;
26ac77db 310} // end of wxPen::GetResourceHandle
cdf1e714 311
6670f564 312bool wxPen::FreeResource( bool WXUNUSED(bForce) )
cdf1e714
DW
313{
314 if (M_PENDATA && (M_PENDATA->m_hPen != 0))
315 {
cdf1e714 316 M_PENDATA->m_hPen = 0;
6670f564 317 return true;
cdf1e714 318 }
6670f564 319 else return false;
26ac77db 320} // end of wxPen::FreeResource
cdf1e714 321
e6ebb514
DW
322bool wxPen::IsFree() const
323{
26ac77db 324 return (M_PENDATA && M_PENDATA->m_hPen == 0);
e6ebb514
DW
325}
326
0e320a79
DW
327void wxPen::Unshare()
328{
cdf1e714
DW
329 // Don't change shared data
330 if (!m_refData)
0e320a79 331 {
cdf1e714
DW
332 m_refData = new wxPenRefData();
333 }
0e320a79
DW
334 else
335 {
cdf1e714
DW
336 wxPenRefData* ref = new wxPenRefData(*(wxPenRefData*)m_refData);
337 UnRef();
338 m_refData = ref;
339 }
26ac77db 340} // end of wxPen::Unshare
0e320a79 341
46562151 342void wxPen::SetColour( const wxColour& rColour )
0e320a79
DW
343{
344 Unshare();
26ac77db 345 M_PENDATA->m_vColour = rColour;
0e320a79 346 RealizeResource();
26ac77db 347} // end of wxPen::SetColour
0e320a79 348
1a1498c0 349void wxPen::SetColour( unsigned char cRed, unsigned char cGreen, unsigned char cBlue)
0e320a79
DW
350{
351 Unshare();
26ac77db 352 M_PENDATA->m_vColour.Set(cRed, cGreen, cBlue);
0e320a79 353 RealizeResource();
26ac77db 354} // end of wxPen::SetColour
0e320a79 355
46562151 356void wxPen::SetPS( HPS hPS )
0e320a79
DW
357{
358 Unshare();
26ac77db
DW
359 if (M_PENDATA->m_hPen)
360 ::GpiDestroyPS(M_PENDATA->m_hPen);
361 M_PENDATA->m_hPen = hPS;
0e320a79 362 RealizeResource();
26ac77db 363} // end of WxWinGdi_CPen::SetPS
0e320a79 364
26ac77db
DW
365void wxPen::SetWidth(
366 int nWidth
367)
0e320a79
DW
368{
369 Unshare();
26ac77db 370 M_PENDATA->m_nWidth = nWidth;
0e320a79 371 RealizeResource();
26ac77db 372} // end of wxPen::SetWidth
0e320a79 373
26ac77db
DW
374void wxPen::SetStyle(
375 int nStyle
376)
0e320a79
DW
377{
378 Unshare();
26ac77db 379 M_PENDATA->m_nStyle = nStyle;
0e320a79 380 RealizeResource();
26ac77db 381} // end of wxPen::SetStyle
0e320a79 382
26ac77db
DW
383void wxPen::SetStipple(
384 const wxBitmap& rStipple
385)
0e320a79
DW
386{
387 Unshare();
26ac77db
DW
388 M_PENDATA->m_vStipple = rStipple;
389 M_PENDATA->m_nStyle = wxSTIPPLE;
0e320a79 390 RealizeResource();
26ac77db 391} // end of wxPen::SetStipple
0e320a79 392
6670f564
WS
393void wxPen::SetDashes( int WXUNUSED(nNbDashes),
394 const wxDash* WXUNUSED(pDash) )
26ac77db
DW
395{
396 //
397 // Does nothing under OS/2
398 //
399} // end of wxPen::SetDashes
400
401void wxPen::SetJoin(
402 int nJoin
403)
0e320a79
DW
404{
405 Unshare();
26ac77db 406 M_PENDATA->m_nJoin = nJoin;
0e320a79 407 RealizeResource();
26ac77db 408} // end of wxPen::SetJoin
0e320a79 409
26ac77db
DW
410void wxPen::SetCap(
411 int nCap
412)
0e320a79
DW
413{
414 Unshare();
26ac77db 415 M_PENDATA->m_nCap = nCap;
0e320a79 416 RealizeResource();
26ac77db 417} // end of wxPen::SetCap
0e320a79 418
26ac77db
DW
419int wx2os2PenStyle(
420 int nWxStyle
421)
cdf1e714 422{
26ac77db
DW
423 int nPMStyle = 0;
424
425 switch (nWxStyle)
fb46a9a6 426 {
26ac77db
DW
427 case wxDOT:
428 nPMStyle = LINETYPE_DOT;
429 break;
430
431 case wxDOT_DASH:
432 nPMStyle = LINETYPE_DASHDOT;
433 break;
434
435 case wxSHORT_DASH:
436 nPMStyle = LINETYPE_SHORTDASH;
437 break;
438
439 case wxLONG_DASH:
440 nPMStyle = LINETYPE_LONGDASH;
441 break;
442
443 case wxTRANSPARENT:
444 nPMStyle = LINETYPE_INVISIBLE;
445 break;
446
447 case wxUSER_DASH:
448 nPMStyle = LINETYPE_DASHDOUBLEDOT; // We must make a choice... This is mine!
449 break;
450
451 case wxSOLID:
452 default:
453 nPMStyle = LINETYPE_SOLID;
454 break;
455 }
456 return nPMStyle;
457} // end of wx2os2PenStyle