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