]>
Commit | Line | Data |
---|---|---|
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 | 28 | IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject) |
004fd0c8 | 29 | |
0e320a79 DW |
30 | wxPenRefData::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 | ||
41 | wxPenRefData::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 | |
55 | wxPenRefData::~wxPenRefData() | |
56 | { | |
26ac77db | 57 | } // end of wxPenRefData::~wxPenRefData |
0e320a79 | 58 | |
26ac77db | 59 | // |
0e320a79 | 60 | // Pens |
26ac77db | 61 | // |
0e320a79 DW |
62 | wxPen::wxPen() |
63 | { | |
26ac77db | 64 | } // end of wxPen::wxPen |
0e320a79 DW |
65 | |
66 | wxPen::~wxPen() | |
67 | { | |
26ac77db | 68 | } // end of wxPen::wxPen |
0e320a79 DW |
69 | |
70 | // Should implement Create | |
26ac77db DW |
71 | wxPen::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 |
89 | wxPen::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 |
106 | int wx2os2PenStyle( |
107 | int nWxStyle | |
108 | ); | |
109 | ||
cdf1e714 DW |
110 | bool 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; | |
aa2f364e SN |
196 | if (M_PENDATA->m_nWidth < 1) |
197 | M_PENDATA->m_nWidth = 1; | |
26ac77db DW |
198 | m_vLineBundle.fxWidth = M_PENDATA->m_nWidth; |
199 | m_vLineBundle.lGeomWidth = M_PENDATA->m_nWidth; | |
200 | m_vLineBundle.usType = uLineType; | |
201 | m_vLineBundle.usEnd = uCap; | |
202 | m_vLineBundle.usJoin = uJoin; | |
203 | ||
204 | bOk = ::GpiSetAttrs( M_PENDATA->m_hPen | |
205 | ,PRIM_LINE | |
206 | ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE | LBB_END | LBB_JOIN | |
207 | ,0L | |
208 | ,&m_vLineBundle | |
209 | ); | |
210 | if (!bOk) | |
211 | { | |
212 | vError = ::WinGetLastError(vHabmain); | |
213 | sError = wxPMErrorToStr(vError); | |
0fba44b4 | 214 | wxLogError(_T("Can't set Gpi attributes for a LINEBUNDLE. Error: %s\n"), sError.c_str()); |
46562151 | 215 | return false; |
26ac77db DW |
216 | } |
217 | ||
d697657f DW |
218 | ULONG flAttrMask = 0L; |
219 | ULONG flDefMask = 0L; | |
26ac77db DW |
220 | switch(M_PENDATA->m_nStyle) |
221 | { | |
222 | case wxSTIPPLE: | |
223 | ::GpiSetBitmapId( M_PENDATA->m_hPen | |
224 | ,(USHORT)M_PENDATA->m_vStipple.GetHBITMAP() | |
225 | ,(USHORT)M_PENDATA->m_vStipple.GetId() | |
226 | ); | |
227 | ::GpiSetPatternSet( M_PENDATA->m_hPen | |
228 | ,(USHORT)M_PENDATA->m_vStipple.GetId() | |
229 | ); | |
d697657f DW |
230 | flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SET | ABB_SYMBOL; |
231 | flDefMask = ABB_REF_POINT; | |
26ac77db DW |
232 | break; |
233 | ||
234 | case wxBDIAGONAL_HATCH: | |
235 | m_vAreaBundle.usSymbol = PATSYM_DIAG3; | |
236 | m_vAreaBundle.usSet = LCID_DEFAULT; | |
d697657f DW |
237 | flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL; |
238 | flDefMask = ABB_SET | ABB_REF_POINT; | |
26ac77db DW |
239 | break; |
240 | ||
241 | case wxCROSSDIAG_HATCH: | |
242 | m_vAreaBundle.usSymbol = PATSYM_DIAGHATCH; | |
243 | m_vAreaBundle.usSet = LCID_DEFAULT; | |
d697657f DW |
244 | flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL; |
245 | flDefMask = ABB_SET | ABB_REF_POINT; | |
26ac77db DW |
246 | break; |
247 | ||
248 | case wxFDIAGONAL_HATCH: | |
249 | m_vAreaBundle.usSymbol = PATSYM_DIAG1; | |
250 | m_vAreaBundle.usSet = LCID_DEFAULT; | |
d697657f DW |
251 | flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL; |
252 | flDefMask = ABB_SET | ABB_REF_POINT; | |
26ac77db DW |
253 | break; |
254 | ||
255 | case wxCROSS_HATCH: | |
256 | m_vAreaBundle.usSymbol = PATSYM_HATCH; | |
257 | m_vAreaBundle.usSet = LCID_DEFAULT; | |
d697657f DW |
258 | flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL; |
259 | flDefMask = ABB_SET | ABB_REF_POINT; | |
26ac77db DW |
260 | break; |
261 | ||
262 | case wxHORIZONTAL_HATCH: | |
263 | m_vAreaBundle.usSymbol = PATSYM_HORIZ; | |
264 | m_vAreaBundle.usSet = LCID_DEFAULT; | |
d697657f DW |
265 | flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL; |
266 | flDefMask = ABB_SET | ABB_REF_POINT; | |
26ac77db DW |
267 | break; |
268 | ||
269 | case wxVERTICAL_HATCH: | |
270 | m_vAreaBundle.usSymbol = PATSYM_VERT; | |
271 | m_vAreaBundle.usSet = LCID_DEFAULT; | |
d697657f DW |
272 | flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL; |
273 | flDefMask = ABB_SET | ABB_REF_POINT; | |
26ac77db DW |
274 | break; |
275 | ||
276 | default: | |
277 | m_vAreaBundle.usSymbol = PATSYM_SOLID; | |
278 | m_vAreaBundle.usSet = LCID_DEFAULT; | |
d697657f DW |
279 | flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL; |
280 | flDefMask = ABB_SET | ABB_REF_POINT; | |
26ac77db DW |
281 | break; |
282 | } | |
283 | ||
284 | m_vAreaBundle.lColor = vPmColour; | |
8d854fa9 | 285 | m_vAreaBundle.lBackColor = RGB_WHITE; |
26ac77db DW |
286 | m_vAreaBundle.usMixMode = FM_OVERPAINT; |
287 | m_vAreaBundle.usBackMixMode = BM_OVERPAINT; | |
288 | ||
289 | bOk = ::GpiSetAttrs( M_PENDATA->m_hPen | |
290 | ,PRIM_AREA | |
d697657f DW |
291 | ,flAttrMask |
292 | ,flDefMask | |
26ac77db DW |
293 | ,&m_vAreaBundle |
294 | ); | |
295 | if (!bOk) | |
296 | { | |
297 | vError = ::WinGetLastError(vHabmain); | |
298 | sError = wxPMErrorToStr(vError); | |
0fba44b4 | 299 | wxLogError(_T("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n"), sError.c_str()); |
26ac77db | 300 | } |
6670f564 WS |
301 | |
302 | return (bool)bOk; | |
26ac77db | 303 | } |
6670f564 | 304 | return false; |
26ac77db | 305 | } // end of wxPen::RealizeResource |
cdf1e714 | 306 | |
17b1d76b | 307 | WXHANDLE wxPen::GetResourceHandle() const |
cdf1e714 | 308 | { |
26ac77db | 309 | if (!M_PENDATA) |
cdf1e714 DW |
310 | return 0; |
311 | else | |
312 | return (WXHANDLE)M_PENDATA->m_hPen; | |
26ac77db | 313 | } // end of wxPen::GetResourceHandle |
cdf1e714 | 314 | |
6670f564 | 315 | bool wxPen::FreeResource( bool WXUNUSED(bForce) ) |
cdf1e714 DW |
316 | { |
317 | if (M_PENDATA && (M_PENDATA->m_hPen != 0)) | |
318 | { | |
cdf1e714 | 319 | M_PENDATA->m_hPen = 0; |
6670f564 | 320 | return true; |
cdf1e714 | 321 | } |
6670f564 | 322 | else return false; |
26ac77db | 323 | } // end of wxPen::FreeResource |
cdf1e714 | 324 | |
e6ebb514 DW |
325 | bool wxPen::IsFree() const |
326 | { | |
26ac77db | 327 | return (M_PENDATA && M_PENDATA->m_hPen == 0); |
e6ebb514 DW |
328 | } |
329 | ||
4b3f61d1 | 330 | wxGDIRefData* wxPen::CreateGDIRefData() const |
0e320a79 | 331 | { |
4b3f61d1 SN |
332 | return new wxPenRefData; |
333 | } | |
334 | ||
335 | wxGDIRefData* wxPen::CloneGDIRefData(const wxGDIRefData* data) const | |
336 | { | |
337 | return new wxPenRefData(*wx_static_cast(const wxPenRefData*, data)); | |
338 | } | |
0e320a79 | 339 | |
46562151 | 340 | void wxPen::SetColour( const wxColour& rColour ) |
0e320a79 | 341 | { |
4b3f61d1 | 342 | AllocExclusive(); |
26ac77db | 343 | M_PENDATA->m_vColour = rColour; |
0e320a79 | 344 | RealizeResource(); |
26ac77db | 345 | } // end of wxPen::SetColour |
0e320a79 | 346 | |
1a1498c0 | 347 | void wxPen::SetColour( unsigned char cRed, unsigned char cGreen, unsigned char cBlue) |
0e320a79 | 348 | { |
4b3f61d1 | 349 | AllocExclusive(); |
26ac77db | 350 | M_PENDATA->m_vColour.Set(cRed, cGreen, cBlue); |
0e320a79 | 351 | RealizeResource(); |
26ac77db | 352 | } // end of wxPen::SetColour |
0e320a79 | 353 | |
46562151 | 354 | void wxPen::SetPS( HPS hPS ) |
0e320a79 | 355 | { |
4b3f61d1 | 356 | AllocExclusive(); |
26ac77db DW |
357 | if (M_PENDATA->m_hPen) |
358 | ::GpiDestroyPS(M_PENDATA->m_hPen); | |
359 | M_PENDATA->m_hPen = hPS; | |
0e320a79 | 360 | RealizeResource(); |
26ac77db | 361 | } // end of WxWinGdi_CPen::SetPS |
0e320a79 | 362 | |
26ac77db DW |
363 | void wxPen::SetWidth( |
364 | int nWidth | |
365 | ) | |
0e320a79 | 366 | { |
4b3f61d1 | 367 | AllocExclusive(); |
26ac77db | 368 | M_PENDATA->m_nWidth = nWidth; |
0e320a79 | 369 | RealizeResource(); |
26ac77db | 370 | } // end of wxPen::SetWidth |
0e320a79 | 371 | |
26ac77db DW |
372 | void wxPen::SetStyle( |
373 | int nStyle | |
374 | ) | |
0e320a79 | 375 | { |
4b3f61d1 | 376 | AllocExclusive(); |
26ac77db | 377 | M_PENDATA->m_nStyle = nStyle; |
0e320a79 | 378 | RealizeResource(); |
26ac77db | 379 | } // end of wxPen::SetStyle |
0e320a79 | 380 | |
26ac77db DW |
381 | void wxPen::SetStipple( |
382 | const wxBitmap& rStipple | |
383 | ) | |
0e320a79 | 384 | { |
4b3f61d1 | 385 | AllocExclusive(); |
26ac77db DW |
386 | M_PENDATA->m_vStipple = rStipple; |
387 | M_PENDATA->m_nStyle = wxSTIPPLE; | |
0e320a79 | 388 | RealizeResource(); |
26ac77db | 389 | } // end of wxPen::SetStipple |
0e320a79 | 390 | |
6670f564 WS |
391 | void wxPen::SetDashes( int WXUNUSED(nNbDashes), |
392 | const wxDash* WXUNUSED(pDash) ) | |
26ac77db DW |
393 | { |
394 | // | |
395 | // Does nothing under OS/2 | |
396 | // | |
397 | } // end of wxPen::SetDashes | |
398 | ||
399 | void wxPen::SetJoin( | |
400 | int nJoin | |
401 | ) | |
0e320a79 | 402 | { |
4b3f61d1 | 403 | AllocExclusive(); |
26ac77db | 404 | M_PENDATA->m_nJoin = nJoin; |
0e320a79 | 405 | RealizeResource(); |
26ac77db | 406 | } // end of wxPen::SetJoin |
0e320a79 | 407 | |
26ac77db DW |
408 | void wxPen::SetCap( |
409 | int nCap | |
410 | ) | |
0e320a79 | 411 | { |
4b3f61d1 | 412 | AllocExclusive(); |
26ac77db | 413 | M_PENDATA->m_nCap = nCap; |
0e320a79 | 414 | RealizeResource(); |
26ac77db | 415 | } // end of wxPen::SetCap |
0e320a79 | 416 | |
26ac77db DW |
417 | int wx2os2PenStyle( |
418 | int nWxStyle | |
419 | ) | |
cdf1e714 | 420 | { |
26ac77db DW |
421 | int nPMStyle = 0; |
422 | ||
423 | switch (nWxStyle) | |
fb46a9a6 | 424 | { |
26ac77db DW |
425 | case wxDOT: |
426 | nPMStyle = LINETYPE_DOT; | |
427 | break; | |
428 | ||
429 | case wxDOT_DASH: | |
430 | nPMStyle = LINETYPE_DASHDOT; | |
431 | break; | |
432 | ||
433 | case wxSHORT_DASH: | |
434 | nPMStyle = LINETYPE_SHORTDASH; | |
435 | break; | |
436 | ||
437 | case wxLONG_DASH: | |
438 | nPMStyle = LINETYPE_LONGDASH; | |
439 | break; | |
440 | ||
441 | case wxTRANSPARENT: | |
442 | nPMStyle = LINETYPE_INVISIBLE; | |
443 | break; | |
444 | ||
445 | case wxUSER_DASH: | |
446 | nPMStyle = LINETYPE_DASHDOUBLEDOT; // We must make a choice... This is mine! | |
447 | break; | |
448 | ||
449 | case wxSOLID: | |
450 | default: | |
451 | nPMStyle = LINETYPE_SOLID; | |
452 | break; | |
453 | } | |
454 | return nPMStyle; | |
455 | } // end of wx2os2PenStyle |