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