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