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