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