]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/os2/pen.cpp
Honour wxSB_WRAP in wxMotif spin button
[wxWidgets.git] / src / os2 / pen.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: pen.cpp
3// Purpose: wxPen
4// Author: David Webster
5// Modified by:
6// Created: 10/10/99
7// RCS-ID: $Id$
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifndef WX_PRECOMP
16#include <stdio.h>
17#include "wx/setup.h"
18#include "wx/list.h"
19#include "wx/utils.h"
20#include "wx/app.h"
21#include "wx/pen.h"
22#endif
23
24#include "wx/os2/private.h"
25#include "assert.h"
26
27IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject)
28
29wxPenRefData::wxPenRefData()
30{
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)
41{
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
49
50wxPenRefData::~wxPenRefData()
51{
52} // end of wxPenRefData::~wxPenRefData
53
54//
55// Pens
56//
57wxPen::wxPen()
58{
59 if ( wxThePenList )
60 wxThePenList->AddPen(this);
61} // end of wxPen::wxPen
62
63wxPen::~wxPen()
64{
65 if (wxThePenList)
66 wxThePenList->RemovePen(this);
67} // end of wxPen::wxPen
68
69// Should implement Create
70wxPen::wxPen(
71 const wxColour& rColour
72, int nWidth
73, int nStyle
74)
75{
76 m_refData = new wxPenRefData;
77
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
85 RealizeResource();
86
87 if ( wxThePenList )
88 wxThePenList->AddPen(this);
89} // end of wxPen::wxPen
90
91wxPen::wxPen(
92 const wxBitmap& rStipple
93, int nWidth
94)
95{
96 m_refData = new wxPenRefData;
97
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;
104
105 RealizeResource();
106
107 if ( wxThePenList )
108 wxThePenList->AddPen(this);
109} // end of wxPen::wxPen
110
111int wx2os2PenStyle(
112 int nWxStyle
113);
114
115bool wxPen::RealizeResource()
116{
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);
153 wxLogError("Unable to set current color table to RGB mode. Error: %s\n", sError);
154 return FALSE;
155 }
156 if (M_PENDATA->m_nStyle == wxTRANSPARENT)
157 {
158 return TRUE;
159 }
160
161 COLORREF vPmColour = 0L;
162 USHORT uLineType = wx2os2PenStyle(M_PENDATA->m_nStyle);
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);
217 wxLogError("Can't set Gpi attributes for a LINEBUNDLE. Error: %s\n", sError);
218 return FALSE;
219 }
220
221 ULONG flAttrMask = 0L;
222 ULONG flDefMask = 0L;
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 );
233 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SET | ABB_SYMBOL;
234 flDefMask = ABB_REF_POINT;
235 break;
236
237 case wxBDIAGONAL_HATCH:
238 m_vAreaBundle.usSymbol = PATSYM_DIAG3;
239 m_vAreaBundle.usSet = LCID_DEFAULT;
240 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
241 flDefMask = ABB_SET | ABB_REF_POINT;
242 break;
243
244 case wxCROSSDIAG_HATCH:
245 m_vAreaBundle.usSymbol = PATSYM_DIAGHATCH;
246 m_vAreaBundle.usSet = LCID_DEFAULT;
247 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
248 flDefMask = ABB_SET | ABB_REF_POINT;
249 break;
250
251 case wxFDIAGONAL_HATCH:
252 m_vAreaBundle.usSymbol = PATSYM_DIAG1;
253 m_vAreaBundle.usSet = LCID_DEFAULT;
254 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
255 flDefMask = ABB_SET | ABB_REF_POINT;
256 break;
257
258 case wxCROSS_HATCH:
259 m_vAreaBundle.usSymbol = PATSYM_HATCH;
260 m_vAreaBundle.usSet = LCID_DEFAULT;
261 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
262 flDefMask = ABB_SET | ABB_REF_POINT;
263 break;
264
265 case wxHORIZONTAL_HATCH:
266 m_vAreaBundle.usSymbol = PATSYM_HORIZ;
267 m_vAreaBundle.usSet = LCID_DEFAULT;
268 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
269 flDefMask = ABB_SET | ABB_REF_POINT;
270 break;
271
272 case wxVERTICAL_HATCH:
273 m_vAreaBundle.usSymbol = PATSYM_VERT;
274 m_vAreaBundle.usSet = LCID_DEFAULT;
275 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
276 flDefMask = ABB_SET | ABB_REF_POINT;
277 break;
278
279 default:
280 m_vAreaBundle.usSymbol = PATSYM_SOLID;
281 m_vAreaBundle.usSet = LCID_DEFAULT;
282 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
283 flDefMask = ABB_SET | ABB_REF_POINT;
284 break;
285 }
286
287 m_vAreaBundle.lColor = vPmColour;
288 m_vAreaBundle.lBackColor = RGB_WHITE;
289 m_vAreaBundle.usMixMode = FM_OVERPAINT;
290 m_vAreaBundle.usBackMixMode = BM_OVERPAINT;
291
292 bOk = ::GpiSetAttrs( M_PENDATA->m_hPen
293 ,PRIM_AREA
294 ,flAttrMask
295 ,flDefMask
296 ,&m_vAreaBundle
297 );
298 if (!bOk)
299 {
300 vError = ::WinGetLastError(vHabmain);
301 sError = wxPMErrorToStr(vError);
302 wxLogError("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n", sError);
303 }
304 return bOk;
305 }
306 return FALSE;
307} // end of wxPen::RealizeResource
308
309WXHANDLE wxPen::GetResourceHandle()
310{
311 if (!M_PENDATA)
312 return 0;
313 else
314 return (WXHANDLE)M_PENDATA->m_hPen;
315} // end of wxPen::GetResourceHandle
316
317bool wxPen::FreeResource(
318 bool bForce
319)
320{
321 if (M_PENDATA && (M_PENDATA->m_hPen != 0))
322 {
323 M_PENDATA->m_hPen = 0;
324 return TRUE;
325 }
326 else return FALSE;
327} // end of wxPen::FreeResource
328
329bool wxPen::IsFree() const
330{
331 return (M_PENDATA && M_PENDATA->m_hPen == 0);
332}
333
334void wxPen::Unshare()
335{
336 // Don't change shared data
337 if (!m_refData)
338 {
339 m_refData = new wxPenRefData();
340 }
341 else
342 {
343 wxPenRefData* ref = new wxPenRefData(*(wxPenRefData*)m_refData);
344 UnRef();
345 m_refData = ref;
346 }
347} // end of wxPen::Unshare
348
349void wxPen::SetColour(
350 const wxColour& rColour
351)
352{
353 Unshare();
354 M_PENDATA->m_vColour = rColour;
355 RealizeResource();
356} // end of wxPen::SetColour
357
358void wxPen::SetColour(
359 unsigned char cRed
360, unsigned char cGreen
361, unsigned char cBlue
362)
363{
364 Unshare();
365 M_PENDATA->m_vColour.Set(cRed, cGreen, cBlue);
366 RealizeResource();
367} // end of wxPen::SetColour
368
369void wxPen::SetPS(
370 HPS hPS
371)
372{
373 Unshare();
374 if (M_PENDATA->m_hPen)
375 ::GpiDestroyPS(M_PENDATA->m_hPen);
376 M_PENDATA->m_hPen = hPS;
377 RealizeResource();
378} // end of WxWinGdi_CPen::SetPS
379
380void wxPen::SetWidth(
381 int nWidth
382)
383{
384 Unshare();
385 M_PENDATA->m_nWidth = nWidth;
386 RealizeResource();
387} // end of wxPen::SetWidth
388
389void wxPen::SetStyle(
390 int nStyle
391)
392{
393 Unshare();
394 M_PENDATA->m_nStyle = nStyle;
395 RealizeResource();
396} // end of wxPen::SetStyle
397
398void wxPen::SetStipple(
399 const wxBitmap& rStipple
400)
401{
402 Unshare();
403 M_PENDATA->m_vStipple = rStipple;
404 M_PENDATA->m_nStyle = wxSTIPPLE;
405 RealizeResource();
406} // end of wxPen::SetStipple
407
408void wxPen::SetDashes(
409 int nNbDashes
410, const wxDash* pDash
411)
412{
413 //
414 // Does nothing under OS/2
415 //
416} // end of wxPen::SetDashes
417
418void wxPen::SetJoin(
419 int nJoin
420)
421{
422 Unshare();
423 M_PENDATA->m_nJoin = nJoin;
424 RealizeResource();
425} // end of wxPen::SetJoin
426
427void wxPen::SetCap(
428 int nCap
429)
430{
431 Unshare();
432 M_PENDATA->m_nCap = nCap;
433 RealizeResource();
434} // end of wxPen::SetCap
435
436int wx2os2PenStyle(
437 int nWxStyle
438)
439{
440 int nPMStyle = 0;
441
442 switch (nWxStyle)
443 {
444 case wxDOT:
445 nPMStyle = LINETYPE_DOT;
446 break;
447
448 case wxDOT_DASH:
449 nPMStyle = LINETYPE_DASHDOT;
450 break;
451
452 case wxSHORT_DASH:
453 nPMStyle = LINETYPE_SHORTDASH;
454 break;
455
456 case wxLONG_DASH:
457 nPMStyle = LINETYPE_LONGDASH;
458 break;
459
460 case wxTRANSPARENT:
461 nPMStyle = LINETYPE_INVISIBLE;
462 break;
463
464 case wxUSER_DASH:
465 nPMStyle = LINETYPE_DASHDOUBLEDOT; // We must make a choice... This is mine!
466 break;
467
468 case wxSOLID:
469 default:
470 nPMStyle = LINETYPE_SOLID;
471 break;
472 }
473 return nPMStyle;
474} // end of wx2os2PenStyle
475
476