]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dc.cpp | |
3 | // Purpose: wxDC class | |
fb46a9a6 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
fb46a9a6 | 6 | // Created: 10/14/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
fb46a9a6 DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
fb46a9a6 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifndef WX_PRECOMP | |
16 | #include "wx/window.h" | |
17 | #include "wx/dc.h" | |
18 | #include "wx/utils.h" | |
19 | #include "wx/dialog.h" | |
20 | #include "wx/app.h" | |
21 | #include "wx/bitmap.h" | |
22 | #include "wx/dcmemory.h" | |
23 | #include "wx/log.h" | |
24 | #include "wx/icon.h" | |
b9c15d10 | 25 | #include "wx/msgdlg.h" |
19193a2c | 26 | #include "wx/module.h" |
0e320a79 DW |
27 | #endif |
28 | ||
fb46a9a6 DW |
29 | #include "wx/dcprint.h" |
30 | ||
31 | #include <string.h> | |
32 | #include <math.h> | |
33 | ||
34 | #include "wx/os2/private.h" | |
0e320a79 | 35 | |
fb46a9a6 | 36 | IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) |
0e320a79 | 37 | |
5fd2b2c6 DW |
38 | // |
39 | // wxWindows uses the Microsoft convention that the origin is the UPPER left. | |
40 | // Native OS/2 however in the GPI and PM define the origin as the LOWER left. | |
41 | // In order to map OS/2 GPI/PM y coordinates to wxWindows coordinates we must | |
42 | // perform the following transformation: | |
43 | // | |
44 | // Parent object height: POBJHEIGHT | |
45 | // Desried origin: WXORIGINY | |
46 | // Object to place's height: OBJHEIGHT | |
47 | // | |
48 | // To get the OS2 position from the wxWindows one: | |
49 | // | |
50 | // OS2Y = POBJHEIGHT - (WXORIGINY + OBJHEIGHT) | |
51 | // | |
52 | // For OS/2 wxDC's we will always determine m_vRclPaint as the size of the | |
53 | // OS/2 Presentation Space associated with the device context. y is the | |
54 | // desired application's y coordinate of the origin in wxWindows space. | |
55 | // objy is the height of the object we are going to draw. | |
56 | // | |
57 | #define OS2Y(y, objy) ((m_vRclPaint.yTop - m_vRclPaint.yBottom) - (y + objy)) | |
58 | ||
fb46a9a6 | 59 | // --------------------------------------------------------------------------- |
0e320a79 | 60 | // constants |
fb46a9a6 | 61 | // --------------------------------------------------------------------------- |
1408104d | 62 | |
fb46a9a6 | 63 | static const int VIEWPORT_EXTENT = 1000; |
1408104d | 64 | |
fb46a9a6 DW |
65 | static const int MM_POINTS = 9; |
66 | static const int MM_METRIC = 10; | |
1408104d | 67 | |
f6bcfd97 BP |
68 | // usually this is defined in math.h |
69 | #ifndef M_PI | |
70 | static const double M_PI = 3.14159265358979323846; | |
71 | #endif // M_PI | |
72 | ||
73 | // --------------------------------------------------------------------------- | |
74 | // private functions | |
75 | // --------------------------------------------------------------------------- | |
76 | ||
77 | // convert degrees to radians | |
78 | static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; } | |
79 | ||
7e99520b DW |
80 | int SetTextColor( |
81 | HPS hPS | |
82 | , int nForegroundColour | |
83 | ) | |
84 | { | |
85 | CHARBUNDLE vCbnd; | |
86 | ||
87 | vCbnd.lColor = nForegroundColour; | |
88 | ::GpiSetAttrs( hPS // presentation-space handle | |
89 | ,PRIM_CHAR // Char primitive. | |
90 | ,CBB_COLOR // sets color. | |
91 | ,0 // | |
92 | ,&vCbnd // buffer for attributes. | |
93 | ); | |
94 | return 0; | |
95 | } | |
96 | ||
97 | int QueryTextBkColor( | |
98 | HPS hPS | |
99 | ) | |
100 | { | |
101 | CHARBUNDLE vCbnd; | |
102 | ||
f44fdfb0 DW |
103 | ::GpiQueryAttrs( hPS // presentation-space handle |
104 | ,PRIM_CHAR // Char primitive. | |
105 | ,CBB_BACK_COLOR // Background color. | |
106 | ,&vCbnd // buffer for attributes. | |
107 | ); | |
7e99520b DW |
108 | return vCbnd.lBackColor; |
109 | } | |
110 | ||
111 | ||
112 | int SetTextBkColor( | |
113 | HPS hPS | |
114 | , int nBackgroundColour | |
115 | ) | |
116 | { | |
117 | CHARBUNDLE vCbnd; | |
118 | int rc; | |
119 | ||
120 | rc = QueryTextBkColor(hPS); | |
121 | ||
122 | vCbnd.lBackColor = nBackgroundColour; | |
123 | ::GpiSetAttrs(hPS, // presentation-space handle | |
124 | PRIM_CHAR, // Char primitive. | |
125 | CBB_BACK_COLOR, // sets color. | |
126 | 0, | |
127 | &vCbnd // buffer for attributes. | |
128 | ); | |
129 | return rc; | |
130 | } | |
131 | ||
132 | int SetBkMode( | |
133 | HPS hPS | |
134 | , int nBackgroundMode | |
135 | ) | |
136 | { | |
137 | if(nBackgroundMode == wxTRANSPARENT) | |
138 | ::GpiSetBackMix( hPS | |
139 | ,BM_LEAVEALONE | |
140 | ); | |
141 | else | |
142 | // the background of the primitive takes over whatever is underneath. | |
143 | ::GpiSetBackMix( hPS | |
144 | ,BM_OVERPAINT | |
145 | ); | |
146 | return 0; | |
147 | } | |
148 | ||
fb46a9a6 DW |
149 | // =========================================================================== |
150 | // implementation | |
151 | // =========================================================================== | |
1408104d | 152 | |
893758d5 DW |
153 | #if wxUSE_DC_CACHEING |
154 | ||
155 | /* | |
156 | * This implementation is a bit ugly and uses the old-fashioned wxList class, so I will | |
157 | * improve it in due course, either using arrays, or simply storing pointers to one | |
158 | * entry for the bitmap, and two for the DCs. -- JACS | |
159 | */ | |
160 | ||
161 | // --------------------------------------------------------------------------- | |
162 | // wxDCCacheEntry | |
163 | // --------------------------------------------------------------------------- | |
164 | ||
165 | wxList wxDC::m_svBitmapCache; | |
166 | wxList wxDC::m_svDCCache; | |
167 | ||
168 | wxDCCacheEntry::wxDCCacheEntry( | |
169 | WXHBITMAP hBitmap | |
170 | , int nWidth | |
171 | , int nHeight | |
172 | , int nDepth | |
173 | ) | |
174 | { | |
175 | m_hBitmap = hBitmap; | |
176 | m_hPS = NULLHANDLE; | |
177 | m_nWidth = nWidth; | |
178 | m_nHeight = nHeight; | |
179 | m_nDepth = nDepth; | |
180 | } // end of wxDCCacheEntry::wxDCCacheEntry | |
181 | ||
182 | wxDCCacheEntry::wxDCCacheEntry( | |
183 | HPS hPS | |
184 | , int nDepth | |
185 | ) | |
186 | { | |
187 | m_hBitmap = NULLHANDLE; | |
188 | m_hPS = hPS; | |
189 | m_nWidth = 0; | |
190 | m_nHeight = 0; | |
191 | m_nDepth = nDepth; | |
192 | } // end of wxDCCacheEntry::wxDCCacheEntry | |
193 | ||
194 | wxDCCacheEntry::~wxDCCacheEntry() | |
195 | { | |
196 | if (m_hBitmap) | |
197 | ::GpiDeleteBitmap(m_hBitmap); | |
198 | if (m_hPS) | |
199 | ::GpiDestroyPS(m_hPS); | |
200 | } // end of wxDCCacheEntry::~wxDCCacheEntry | |
201 | ||
202 | wxDCCacheEntry* wxDC::FindBitmapInCache( | |
203 | HPS hPS | |
204 | , int nWidth | |
205 | , int nHeight | |
206 | ) | |
207 | { | |
19193a2c | 208 | int nDepth = 24; // we'll fix this later ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL); |
893758d5 DW |
209 | wxNode* pNode = m_svBitmapCache.First(); |
210 | BITMAPINFOHEADER2 vBmpHdr; | |
211 | ||
212 | while(pNode) | |
213 | { | |
214 | wxDCCacheEntry* pEntry = (wxDCCacheEntry*)pNode->Data(); | |
215 | ||
216 | if (pEntry->m_nDepth == nDepth) | |
217 | { | |
218 | memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2)); | |
219 | ||
220 | if (pEntry->m_nWidth < nWidth || pEntry->m_nHeight < nHeight) | |
221 | { | |
222 | ::GpiDeleteBitmap((HBITMAP)pEntry->m_hBitmap); | |
223 | vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2); | |
224 | vBmpHdr.cx = nWidth; | |
225 | vBmpHdr.cy = nHeight; | |
226 | vBmpHdr.cPlanes = 1; | |
227 | vBmpHdr.cBitCount = nDepth; | |
228 | ||
229 | pEntry->m_hBitmap = (WXHBITMAP) ::GpiCreateBitmap( hPS | |
230 | ,&vBmpHdr | |
231 | ,0L, NULL, NULL | |
232 | ); | |
233 | if (!pEntry->m_hBitmap) | |
234 | { | |
235 | wxLogLastError(wxT("CreateCompatibleBitmap")); | |
236 | } | |
237 | pEntry->m_nWidth = nWidth; | |
238 | pEntry->m_nHeight = nHeight; | |
239 | return pEntry; | |
240 | } | |
241 | return pEntry; | |
242 | } | |
243 | pNode = pNode->Next(); | |
244 | } | |
245 | memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2)); | |
246 | vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2); | |
247 | vBmpHdr.cx = nWidth; | |
248 | vBmpHdr.cy = nHeight; | |
249 | vBmpHdr.cPlanes = 1; | |
250 | vBmpHdr.cBitCount = nDepth; | |
251 | ||
252 | WXHBITMAP hBitmap = (WXHBITMAP) ::GpiCreateBitmap( hPS | |
253 | ,&vBmpHdr | |
254 | ,0L, NULL, NULL | |
255 | ); | |
256 | if (!hBitmap) | |
257 | { | |
258 | wxLogLastError(wxT("CreateCompatibleBitmap")); | |
259 | } | |
260 | wxDCCacheEntry* pEntry = new wxDCCacheEntry( hBitmap | |
261 | ,nWidth | |
262 | ,nHeight | |
263 | ,nDepth | |
264 | ); | |
265 | AddToBitmapCache(pEntry); | |
266 | return pEntry; | |
267 | } // end of FindBitmapInCache | |
268 | ||
269 | wxDCCacheEntry* wxDC::FindDCInCache( | |
270 | wxDCCacheEntry* pNotThis | |
271 | , HPS hPS | |
272 | ) | |
273 | { | |
274 | int nDepth = 24; // we'll fix this up later ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL); | |
275 | wxNode* pNode = m_svDCCache.First(); | |
276 | ||
277 | while(pNode) | |
278 | { | |
279 | wxDCCacheEntry* pEntry = (wxDCCacheEntry*)pNode->Data(); | |
280 | ||
281 | // | |
282 | // Don't return the same one as we already have | |
283 | // | |
284 | if (!pNotThis || (pNotThis != pEntry)) | |
285 | { | |
286 | if (pEntry->m_nDepth == nDepth) | |
287 | { | |
288 | return pEntry; | |
289 | } | |
290 | } | |
291 | pNode = pNode->Next(); | |
292 | } | |
293 | wxDCCacheEntry* pEntry = new wxDCCacheEntry( hPS | |
294 | ,nDepth | |
295 | ); | |
296 | AddToDCCache(pEntry); | |
297 | return pEntry; | |
298 | } // end of wxDC::FindDCInCache | |
299 | ||
300 | void wxDC::AddToBitmapCache( | |
301 | wxDCCacheEntry* pEntry | |
302 | ) | |
303 | { | |
304 | m_svBitmapCache.Append(pEntry); | |
305 | } // end of wxDC::AddToBitmapCache | |
306 | ||
307 | void wxDC::AddToDCCache( | |
308 | wxDCCacheEntry* pEntry | |
309 | ) | |
310 | { | |
311 | m_svDCCache.Append(pEntry); | |
312 | } // end of wxDC::AddToDCCache | |
313 | ||
314 | void wxDC::ClearCache() | |
315 | { | |
316 | m_svBitmapCache.DeleteContents(TRUE); | |
317 | m_svBitmapCache.Clear(); | |
318 | m_svBitmapCache.DeleteContents(FALSE); | |
319 | m_svDCCache.DeleteContents(TRUE); | |
320 | m_svDCCache.Clear(); | |
321 | m_svDCCache.DeleteContents(FALSE); | |
322 | } // end of wxDC::ClearCache | |
323 | ||
324 | // Clean up cache at app exit | |
325 | class wxDCModule : public wxModule | |
326 | { | |
327 | public: | |
328 | virtual bool OnInit() { return TRUE; } | |
329 | virtual void OnExit() { wxDC::ClearCache(); } | |
330 | ||
331 | private: | |
332 | DECLARE_DYNAMIC_CLASS(wxDCModule) | |
333 | }; // end of CLASS wxDCModule | |
334 | ||
335 | IMPLEMENT_DYNAMIC_CLASS(wxDCModule, wxModule) | |
336 | ||
337 | #endif // ndef for wxUSE_DC_CACHEING | |
338 | ||
fb46a9a6 | 339 | // --------------------------------------------------------------------------- |
0e320a79 | 340 | // wxDC |
fb46a9a6 | 341 | // --------------------------------------------------------------------------- |
0e320a79 DW |
342 | |
343 | wxDC::wxDC(void) | |
344 | { | |
2b0ec34b DW |
345 | wxColour vColor; |
346 | ||
7e99520b | 347 | m_pCanvas = NULL; |
c3d43472 | 348 | |
7e99520b DW |
349 | m_hOldBitmap = 0; |
350 | m_hOldPen = 0; | |
351 | m_hOldBrush = 0; | |
352 | m_hOldFont = 0; | |
353 | m_hOldPalette = 0; | |
ce44c50e | 354 | |
7e99520b DW |
355 | m_bOwnsDC = FALSE; |
356 | m_hDC = 0; | |
7e99520b DW |
357 | m_hOldPS = NULL; |
358 | m_hPS = NULL; | |
e99762c0 | 359 | m_bIsPaintTime = FALSE; // True at Paint Time |
2b0ec34b DW |
360 | |
361 | vColor.InitFromName("BLACK"); | |
362 | m_pen.SetColour(vColor); | |
363 | vColor.Set("WHITE"); | |
364 | m_brush.SetColour(vColor); | |
e1a688e4 | 365 | } // end of wxDC::wxDC |
0e320a79 DW |
366 | |
367 | wxDC::~wxDC(void) | |
368 | { | |
e1a688e4 DW |
369 | if ( m_hDC != 0 ) |
370 | { | |
371 | SelectOldObjects(m_hDC); | |
372 | ||
373 | // if we own the HDC, we delete it, otherwise we just release it | |
374 | ||
375 | if (m_bOwnsDC) | |
376 | { | |
377 | if(m_hPS) | |
378 | { | |
379 | ::GpiAssociate(m_hPS, NULLHANDLE); | |
380 | ::GpiDestroyPS(m_hPS); | |
381 | } | |
382 | m_hPS = NULLHANDLE; | |
383 | ::DevCloseDC((HDC)m_hDC); | |
384 | } | |
385 | else | |
386 | { | |
387 | // | |
388 | // Just Dissacociate, not destroy if we don't own the DC | |
389 | // | |
390 | if(m_hPS) | |
391 | { | |
392 | ::GpiAssociate(m_hPS, NULLHANDLE); | |
393 | } | |
394 | } | |
395 | } | |
396 | } // end of wxDC::~wxDC | |
0e320a79 | 397 | |
fb46a9a6 DW |
398 | // This will select current objects out of the DC, |
399 | // which is what you have to do before deleting the | |
400 | // DC. | |
f07bb01b DW |
401 | void wxDC::SelectOldObjects( |
402 | WXHDC hPS | |
403 | ) | |
0e320a79 | 404 | { |
f07bb01b | 405 | if (hPS) |
fb46a9a6 | 406 | { |
f6bcfd97 | 407 | if (m_hOldBitmap) |
fb46a9a6 | 408 | { |
f07bb01b | 409 | ::GpiSetBitmap(hPS, (HBITMAP) m_hOldBitmap); |
f6bcfd97 | 410 | if (m_vSelectedBitmap.Ok()) |
fb46a9a6 | 411 | { |
f6bcfd97 | 412 | m_vSelectedBitmap.SetSelectedInto(NULL); |
fb46a9a6 DW |
413 | } |
414 | } | |
f6bcfd97 | 415 | m_hOldBitmap = 0; |
f07bb01b DW |
416 | // |
417 | // OS/2 has no other native GDI objects to set in a PS/DC like windows | |
418 | // | |
f6bcfd97 | 419 | m_hOldPen = 0; |
f6bcfd97 | 420 | m_hOldBrush = 0; |
f6bcfd97 | 421 | m_hOldFont = 0; |
f6bcfd97 | 422 | m_hOldPalette = 0; |
fb46a9a6 | 423 | } |
0e320a79 | 424 | |
f6bcfd97 BP |
425 | m_brush = wxNullBrush; |
426 | m_pen = wxNullPen; | |
427 | m_palette = wxNullPalette; | |
428 | m_font = wxNullFont; | |
fb46a9a6 | 429 | m_backgroundBrush = wxNullBrush; |
f6bcfd97 | 430 | m_vSelectedBitmap = wxNullBitmap; |
e1a688e4 | 431 | } // end of wxDC::SelectOldObjects |
0e320a79 | 432 | |
fb46a9a6 DW |
433 | // --------------------------------------------------------------------------- |
434 | // clipping | |
435 | // --------------------------------------------------------------------------- | |
0e320a79 | 436 | |
fa5593ac DW |
437 | #define DO_SET_CLIPPING_BOX() \ |
438 | { \ | |
439 | RECTL rect; \ | |
440 | \ | |
441 | ::GpiQueryClipBox(m_hPS, &rect); \ | |
442 | \ | |
443 | m_clipX1 = (wxCoord) XDEV2LOG(rect.xLeft); \ | |
444 | m_clipY1 = (wxCoord) YDEV2LOG(rect.yTop); \ | |
445 | m_clipX2 = (wxCoord) XDEV2LOG(rect.xRight); \ | |
446 | m_clipY2 = (wxCoord) YDEV2LOG(rect.yBottom); \ | |
fb46a9a6 | 447 | } |
0e320a79 | 448 | |
fa5593ac | 449 | void wxDC::DoSetClippingRegion( |
5fd2b2c6 DW |
450 | wxCoord vX |
451 | , wxCoord vY | |
452 | , wxCoord vWidth | |
453 | , wxCoord vHeight | |
fa5593ac | 454 | ) |
0e320a79 | 455 | { |
fa5593ac DW |
456 | RECTL vRect; |
457 | ||
5fd2b2c6 | 458 | vY = OS2Y(vY,vHeight); |
fa5593ac | 459 | m_clipping = TRUE; |
5fd2b2c6 DW |
460 | vRect.xLeft = vX; |
461 | vRect.yTop = vY + vHeight; | |
462 | vRect.xRight = vX + vWidth; | |
463 | vRect.yBottom = vY; | |
fa5593ac DW |
464 | ::GpiIntersectClipRectangle(m_hPS, &vRect); |
465 | DO_SET_CLIPPING_BOX() | |
466 | } // end of wxDC::DoSetClippingRegion | |
467 | ||
468 | void wxDC::DoSetClippingRegionAsRegion( | |
469 | const wxRegion& rRegion | |
470 | ) | |
0e320a79 | 471 | { |
fa5593ac DW |
472 | wxCHECK_RET(rRegion.GetHRGN(), wxT("invalid clipping region")); |
473 | HRGN hRgnOld; | |
474 | ||
475 | m_clipping = TRUE; | |
476 | ::GpiSetClipRegion( m_hPS | |
477 | ,(HRGN)rRegion.GetHRGN() | |
478 | ,&hRgnOld | |
479 | ); | |
480 | DO_SET_CLIPPING_BOX() | |
481 | } // end of wxDC::DoSetClippingRegionAsRegion | |
0e320a79 | 482 | |
fb46a9a6 | 483 | void wxDC::DestroyClippingRegion(void) |
0e320a79 | 484 | { |
fa5593ac DW |
485 | if (m_clipping && m_hPS) |
486 | { | |
487 | HRGN hRgnOld; | |
488 | RECTL vRect; | |
489 | ||
490 | // TODO: this should restore the previous clipped region | |
491 | // so that OnPaint processing works correctly, and | |
492 | // the update doesn't get destroyed after the first | |
493 | // DestroyClippingRegion | |
494 | vRect.xLeft = XLOG2DEV(0); | |
495 | vRect.yTop = YLOG2DEV(32000); | |
496 | vRect.xRight = XLOG2DEV(32000); | |
497 | vRect.yBottom = YLOG2DEV(0); | |
498 | ||
499 | HRGN hRgn = ::GpiCreateRegion(m_hPS, 1, &vRect); | |
500 | ||
501 | ::GpiSetClipRegion(m_hPS, hRgn, &hRgnOld); | |
502 | } | |
503 | m_clipping = FALSE; | |
504 | } // end of wxDC::DestroyClippingRegion | |
0e320a79 | 505 | |
fb46a9a6 DW |
506 | // --------------------------------------------------------------------------- |
507 | // query capabilities | |
508 | // --------------------------------------------------------------------------- | |
0e320a79 | 509 | |
fb46a9a6 | 510 | bool wxDC::CanDrawBitmap() const |
0e320a79 | 511 | { |
fb46a9a6 DW |
512 | return TRUE; |
513 | } | |
0e320a79 | 514 | |
fb46a9a6 | 515 | bool wxDC::CanGetTextExtent() const |
0e320a79 | 516 | { |
f07bb01b | 517 | LONG lTechnology = 0L; |
0e320a79 | 518 | |
f07bb01b DW |
519 | ::DevQueryCaps(GetHDC(), CAPS_TECHNOLOGY, 1L, &lTechnology); |
520 | return (lTechnology == CAPS_TECH_RASTER_DISPLAY) || (lTechnology == CAPS_TECH_RASTER_PRINTER); | |
521 | } // end of wxDC::CanGetTextExtent | |
1408104d DW |
522 | |
523 | int wxDC::GetDepth() const | |
0e320a79 | 524 | { |
f07bb01b DW |
525 | LONG lArray[CAPS_COLOR_BITCOUNT]; |
526 | int nBitsPerPixel; | |
527 | ||
528 | if(::DevQueryCaps( GetHDC() | |
529 | ,CAPS_FAMILY | |
530 | ,CAPS_COLOR_BITCOUNT | |
531 | ,lArray | |
532 | )) | |
533 | { | |
534 | nBitsPerPixel = (int)lArray[CAPS_COLOR_BITCOUNT]; | |
535 | } | |
536 | return nBitsPerPixel; | |
537 | } // end of wxDC::GetDepth | |
0e320a79 | 538 | |
fb46a9a6 DW |
539 | // --------------------------------------------------------------------------- |
540 | // drawing | |
541 | // --------------------------------------------------------------------------- | |
0e320a79 | 542 | |
1408104d | 543 | void wxDC::Clear() |
0e320a79 | 544 | { |
81039e0d DW |
545 | // |
546 | // If this is a canvas DC then just fill with the background color | |
547 | // Otherwise purge the whole thing | |
548 | // | |
549 | if (m_pCanvas) | |
550 | { | |
551 | RECTL vRect; | |
552 | ||
553 | ::GpiQueryClipBox(m_hPS, &vRect); | |
554 | ::WinFillRect(m_hPS, &vRect, ::GpiQueryBackColor(m_hPS)); | |
555 | } | |
556 | else | |
445c7bca | 557 | ::GpiErase(m_hPS); |
5fd2b2c6 | 558 | } // end of wxDC::Clear |
0e320a79 | 559 | |
1d0edc0f | 560 | bool wxDC::DoFloodFill( |
51c1d535 DW |
561 | wxCoord vX |
562 | , wxCoord vY | |
563 | , const wxColour& rCol | |
564 | , int nStyle | |
565 | ) | |
0e320a79 | 566 | { |
51c1d535 DW |
567 | POINTL vPtlPos; |
568 | LONG lColor; | |
569 | LONG lOptions; | |
1d0edc0f DW |
570 | LONG lHits; |
571 | bool bSuccess = FALSE; | |
51c1d535 DW |
572 | |
573 | vPtlPos.x = vX; // Loads x-coordinate | |
5fd2b2c6 | 574 | vPtlPos.y = OS2Y(vY,0); // Loads y-coordinate |
51c1d535 DW |
575 | ::GpiMove(m_hPS, &vPtlPos); // Sets current position |
576 | lColor = rCol.GetPixel(); | |
577 | lOptions = FF_BOUNDARY; | |
578 | if(wxFLOOD_SURFACE == nStyle) | |
579 | lOptions = FF_SURFACE; | |
580 | ||
1d0edc0f DW |
581 | if ((lHits = ::GpiFloodFill(m_hPS, lOptions, lColor)) != GPI_ERROR) |
582 | bSuccess = TRUE; | |
583 | return TRUE; | |
5fd2b2c6 | 584 | } // end of wxDC::DoFloodFill |
0e320a79 | 585 | |
51c1d535 DW |
586 | bool wxDC::DoGetPixel( |
587 | wxCoord vX | |
588 | , wxCoord vY | |
589 | , wxColour* pCol | |
590 | ) const | |
1408104d | 591 | { |
51c1d535 DW |
592 | POINTL vPoint; |
593 | LONG lColor; | |
594 | ||
595 | vPoint.x = vX; | |
5fd2b2c6 | 596 | vPoint.y = OS2Y(vY,0); |
51c1d535 | 597 | lColor = ::GpiSetPel(m_hPS, &vPoint); |
5fd2b2c6 DW |
598 | |
599 | // | |
600 | // Get the color of the pen | |
601 | // | |
602 | LONG lPencolor = 0x00ffffff; | |
603 | ||
604 | if (m_pen.Ok()) | |
605 | { | |
606 | lPencolor = m_pen.GetColour().GetPixel(); | |
607 | } | |
608 | ||
609 | // | |
610 | // return the color of the pixel | |
611 | // | |
612 | if(pCol) | |
613 | pCol->Set( GetRValue(lColor) | |
614 | ,GetGValue(lColor) | |
615 | ,GetBValue(lColor) | |
616 | ); | |
617 | return(lColor == lPencolor); | |
618 | } // end of wxDC::DoGetPixel | |
0e320a79 | 619 | |
f07bb01b DW |
620 | void wxDC::DoCrossHair( |
621 | wxCoord vX | |
622 | , wxCoord vY | |
623 | ) | |
0e320a79 | 624 | { |
5fd2b2c6 DW |
625 | vY = OS2Y(vY,0); |
626 | ||
f07bb01b DW |
627 | wxCoord vX1 = vX - VIEWPORT_EXTENT; |
628 | wxCoord vY1 = vY - VIEWPORT_EXTENT; | |
629 | wxCoord vX2 = vX + VIEWPORT_EXTENT; | |
630 | wxCoord vY2 = vY + VIEWPORT_EXTENT; | |
631 | POINTL vPoint[4]; | |
632 | ||
633 | vPoint[0].x = vX1; | |
5fd2b2c6 | 634 | vPoint[0].y = vY; |
f07bb01b DW |
635 | |
636 | vPoint[1].x = vX2; | |
5fd2b2c6 | 637 | vPoint[1].y = vY; |
f07bb01b DW |
638 | |
639 | ::GpiMove(m_hPS, &vPoint[0]); | |
640 | ::GpiLine(m_hPS, &vPoint[1]); | |
641 | ||
642 | vPoint[2].x = vX; | |
5fd2b2c6 | 643 | vPoint[2].y = vY1; |
f07bb01b DW |
644 | |
645 | vPoint[3].x = vX; | |
5fd2b2c6 | 646 | vPoint[3].y = vY2; |
f07bb01b DW |
647 | |
648 | ::GpiMove(m_hPS, &vPoint[2]); | |
649 | ::GpiLine(m_hPS, &vPoint[3]); | |
5fd2b2c6 DW |
650 | CalcBoundingBox(vX1, vY1); |
651 | CalcBoundingBox(vX2, vY2); | |
f07bb01b | 652 | } // end of wxDC::DoCrossHair |
1408104d | 653 | |
7e99520b DW |
654 | void wxDC::DoDrawLine( |
655 | wxCoord vX1 | |
656 | , wxCoord vY1 | |
657 | , wxCoord vX2 | |
658 | , wxCoord vY2 | |
659 | ) | |
0e320a79 | 660 | { |
7e99520b | 661 | POINTL vPoint[2]; |
d6d749aa | 662 | COLORREF vColor = 0x00ffffff; |
7e99520b | 663 | |
d6d749aa DW |
664 | // |
665 | // Might be a memory DC with no Paint rect. | |
666 | // | |
667 | if (!(m_vRclPaint.yTop == 0 && | |
668 | m_vRclPaint.yBottom == 0 && | |
669 | m_vRclPaint.xRight == 0 && | |
670 | m_vRclPaint.xLeft == 0)) | |
671 | { | |
672 | vY1 = OS2Y(vY1,0); | |
673 | vY2 = OS2Y(vY2,0); | |
674 | } | |
1c9a789e DW |
675 | else |
676 | { | |
677 | if (m_vSelectedBitmap != wxNullBitmap) | |
678 | { | |
679 | m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight(); | |
680 | m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth(); | |
681 | vY1 = OS2Y(vY1,0); | |
682 | vY2 = OS2Y(vY2,0); | |
683 | } | |
684 | } | |
7e99520b | 685 | vPoint[0].x = vX1; |
5fd2b2c6 | 686 | vPoint[0].y = vY1; |
7e99520b | 687 | vPoint[1].x = vX2; |
5fd2b2c6 | 688 | vPoint[1].y = vY2; |
d6d749aa DW |
689 | if (m_pen.Ok()) |
690 | { | |
691 | vColor = m_pen.GetColour().GetPixel(); | |
692 | } | |
693 | ::GpiSetColor(m_hPS, vColor); | |
7e99520b DW |
694 | ::GpiMove(m_hPS, &vPoint[0]); |
695 | ::GpiLine(m_hPS, &vPoint[1]); | |
5fd2b2c6 DW |
696 | CalcBoundingBox(vX1, vY1); |
697 | CalcBoundingBox(vX2, vY2); | |
f07bb01b | 698 | } // end of wxDC::DoDrawLine |
1408104d | 699 | |
51c1d535 DW |
700 | ////////////////////////////////////////////////////////////////////////////// |
701 | // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1) | |
702 | // and ending at (x2, y2). The current pen is used for the outline and the | |
703 | // current brush for filling the shape. The arc is drawn in an anticlockwise | |
704 | // direction from the start point to the end point. | |
705 | ////////////////////////////////////////////////////////////////////////////// | |
706 | void wxDC::DoDrawArc( | |
707 | wxCoord vX1 | |
708 | , wxCoord vY1 | |
709 | , wxCoord vX2 | |
710 | , wxCoord vY2 | |
711 | , wxCoord vXc | |
712 | , wxCoord vYc | |
713 | ) | |
1408104d | 714 | { |
51c1d535 DW |
715 | POINTL vPtlPos; |
716 | POINTL vPtlArc[2]; // Structure for current position | |
717 | int nDx; | |
718 | int nDy; | |
719 | double dRadius; | |
720 | double dAngl1; | |
721 | double dAngl2; | |
722 | double dAnglmid; | |
723 | wxCoord vXm; | |
724 | wxCoord vYm; | |
725 | ARCPARAMS vArcp; // Structure for arc parameters | |
726 | ||
727 | if((vX1 == vXc && vY1 == vXc) || (vX2 == vXc && vY2 == vXc)) | |
728 | return; // Draw point ?? | |
729 | dRadius = 0.5 * ( hypot( (double)(vY1 - vYc) | |
730 | ,(double)(vX1 - vXc) | |
731 | ) + | |
732 | hypot( (double)(vY2 - vYc) | |
733 | ,(double)(vX2 - vXc) | |
734 | ) | |
735 | ); | |
736 | ||
737 | dAngl1 = atan2( (double)(vY1 - vYc) | |
738 | ,(double)(vX1 - vXc) | |
739 | ); | |
740 | dAngl2 = atan2( (double)(vY2 - vYc) | |
741 | ,(double)(vX2 - vXc) | |
742 | ); | |
743 | if(dAngl2 < dAngl1) | |
744 | dAngl2 += M_PI * 2; | |
745 | ||
746 | // | |
747 | // GpiPointArc can't draw full arc | |
748 | // | |
749 | if(dAngl2 == dAngl1 || (vX1 == vX2 && vY1 == vY2) ) | |
750 | { | |
751 | // | |
752 | // Medium point | |
753 | // | |
754 | dAnglmid = (dAngl1 + dAngl2)/2. + M_PI; | |
755 | vXm = vXc + dRadius * cos(dAnglmid); | |
756 | vYm = vYc + dRadius * sin(dAnglmid); | |
e99762c0 DW |
757 | DoDrawArc( vX1, vY1 |
758 | ,vXm, vYm | |
759 | ,vXc, vYc | |
51c1d535 | 760 | ); |
e99762c0 DW |
761 | DoDrawArc( vXm, vYm |
762 | ,vX2, vY2 | |
763 | ,vXc, vYc | |
51c1d535 DW |
764 | ); |
765 | return; | |
766 | } | |
767 | ||
768 | // | |
769 | // Medium point | |
770 | // | |
771 | dAnglmid = (dAngl1 + dAngl2)/2.; | |
772 | vXm = vXc + dRadius * cos(dAnglmid); | |
773 | vYm = vYc + dRadius * sin(dAnglmid); | |
774 | ||
775 | // | |
776 | // Ellipse main axis (r,q), (p,s) with center at (0,0) */ | |
777 | // | |
778 | vArcp.lR = 0; | |
779 | vArcp.lQ = 1; | |
780 | vArcp.lP = 1; | |
781 | vArcp.lS = 0; | |
782 | ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default | |
783 | ||
784 | vPtlPos.x = vX1; // Loads x-coordinate | |
785 | vPtlPos.y = vY1; // Loads y-coordinate | |
786 | ::GpiMove(m_hPS, &vPtlPos); // Sets current position | |
e99762c0 DW |
787 | vPtlArc[0].x = vXm; |
788 | vPtlArc[0].y = vYm; | |
51c1d535 DW |
789 | vPtlArc[1].x = vX2; |
790 | vPtlArc[1].y = vY2; | |
791 | ::GpiPointArc(m_hPS, vPtlArc); // Draws the arc | |
5fd2b2c6 DW |
792 | CalcBoundingBox( (vXc - dRadius) |
793 | ,(vYc - dRadius) | |
794 | ); | |
795 | CalcBoundingBox( (vXc + dRadius) | |
796 | ,(vYc + dRadius) | |
797 | ); | |
f07bb01b | 798 | } // end of wxDC::DoDrawArc |
1408104d | 799 | |
51c1d535 DW |
800 | void wxDC::DoDrawCheckMark( |
801 | wxCoord vX1 | |
802 | , wxCoord vY1 | |
803 | , wxCoord vWidth | |
804 | , wxCoord vHeight | |
805 | ) | |
f6bcfd97 | 806 | { |
51c1d535 DW |
807 | POINTL vPoint[2]; |
808 | ||
5fd2b2c6 DW |
809 | vY1 = OS2Y(vY1,vHeight); |
810 | ||
51c1d535 DW |
811 | vPoint[0].x = vX1; |
812 | vPoint[0].y = vY1; | |
813 | vPoint[1].x = vX1 + vWidth; | |
814 | vPoint[1].y = vY1 + vHeight; | |
815 | ||
816 | ::GpiMove(m_hPS, &vPoint[0]); | |
817 | ::GpiBox( m_hPS // handle to a presentation space | |
818 | ,DRO_OUTLINE // draw the box outline ? or ? | |
819 | ,&vPoint[1] // address of the corner | |
820 | ,0L // horizontal corner radius | |
821 | ,0L // vertical corner radius | |
822 | ); | |
823 | if(vWidth > 4 && vHeight > 4) | |
824 | { | |
825 | int nTmp; | |
826 | ||
827 | vPoint[0].x += 2; vPoint[0].y += 2; | |
828 | vPoint[1].x -= 2; vPoint[1].y -= 2; | |
829 | ::GpiMove(m_hPS, &vPoint[0]); | |
830 | ::GpiLine(m_hPS, &vPoint[1]); | |
831 | nTmp = vPoint[0].x; | |
832 | vPoint[0].x = vPoint[1].x; | |
833 | vPoint[1].x = nTmp; | |
834 | ::GpiMove(m_hPS, &vPoint[0]); | |
835 | ::GpiLine(m_hPS, &vPoint[1]); | |
836 | } | |
5fd2b2c6 DW |
837 | CalcBoundingBox( vX1 |
838 | ,vY1 | |
839 | ); | |
840 | ||
841 | wxCoord vX2 = vX1 + vWidth; | |
842 | wxCoord vY2 = vY1 + vHeight; | |
843 | ||
844 | CalcBoundingBox( vX2 | |
845 | ,vY2 | |
846 | ); | |
f07bb01b | 847 | } // end of wxDC::DoDrawCheckMark |
f6bcfd97 | 848 | |
51c1d535 DW |
849 | void wxDC::DoDrawPoint( |
850 | wxCoord vX | |
851 | , wxCoord vY | |
852 | ) | |
1408104d | 853 | { |
51c1d535 | 854 | POINTL vPoint; |
5fd2b2c6 | 855 | COLORREF vColor = 0x00ffffff; |
51c1d535 | 856 | |
5fd2b2c6 DW |
857 | if (m_pen.Ok()) |
858 | { | |
859 | vColor = m_pen.GetColour().GetPixel(); | |
860 | } | |
861 | ::GpiSetColor(m_hPS, vColor); | |
51c1d535 | 862 | vPoint.x = vX; |
5fd2b2c6 | 863 | vPoint.y = OS2Y(vY,0); |
51c1d535 | 864 | ::GpiSetPel(m_hPS, &vPoint); |
5fd2b2c6 DW |
865 | CalcBoundingBox( vX |
866 | ,vY | |
867 | ); | |
f07bb01b | 868 | } // end of wxDC::DoDrawPoint |
1408104d | 869 | |
51c1d535 DW |
870 | void wxDC::DoDrawPolygon( |
871 | int n | |
872 | , wxPoint vPoints[] | |
873 | , wxCoord vXoffset | |
874 | , wxCoord vYoffset | |
875 | , int nFillStyle | |
876 | ) | |
1408104d | 877 | { |
51c1d535 DW |
878 | ULONG ulCount = 1; // Number of polygons. |
879 | POLYGON vPlgn; // polygon. | |
880 | ULONG flOptions = 0L; // Drawing options. | |
881 | ||
882 | ////////////////////////////////////////////////////////////////////////////// | |
883 | // This contains fields of option bits... to draw boundary lines as well as | |
884 | // the area interior. | |
885 | // | |
886 | // Drawing boundary lines: | |
887 | // POLYGON_NOBOUNDARY Does not draw boundary lines. | |
888 | // POLYGON_BOUNDARY Draws boundary lines (the default). | |
889 | // | |
890 | // Construction of the area interior: | |
891 | // POLYGON_ALTERNATE Constructs interior in alternate mode | |
892 | // (the default). | |
893 | // POLYGON_WINDING Constructs interior in winding mode. | |
894 | ////////////////////////////////////////////////////////////////////////////// | |
895 | ||
896 | ULONG flModel = 0L; // Drawing model. | |
897 | ||
898 | ////////////////////////////////////////////////////////////////////////////// | |
899 | // Drawing model. | |
900 | // POLYGON_INCL Fill is inclusive of bottom right (the default). | |
901 | // POLYGON_EXCL Fill is exclusive of bottom right. | |
902 | // This is provided to aid migration from other graphics models. | |
903 | ////////////////////////////////////////////////////////////////////////////// | |
904 | ||
905 | LONG lHits = 0L; // Correlation/error indicator. | |
906 | POINTL vPoint; | |
907 | int i; | |
908 | int nIsTRANSPARENT = 0; | |
909 | LONG lBorderColor = 0L; | |
910 | LONG lColor = 0L; | |
911 | ||
912 | lBorderColor = m_pen.GetColour().GetPixel(); | |
913 | lColor = m_brush.GetColour().GetPixel(); | |
914 | if(m_brush.GetStyle() == wxTRANSPARENT) | |
915 | nIsTRANSPARENT = 1; | |
916 | ||
917 | vPlgn.ulPoints = n; | |
918 | vPlgn.aPointl = (POINTL*) calloc( n + 1 | |
919 | ,sizeof(POINTL) | |
920 | ); // well, new will call malloc | |
921 | ||
922 | for(i = 0; i < n; i++) | |
923 | { | |
5fd2b2c6 DW |
924 | vPlgn.aPointl[i].x = vPoints[i].x; // +xoffset; |
925 | vPlgn.aPointl[i].y = OS2Y(vPoints[i].y,0); // +yoffset; | |
51c1d535 DW |
926 | } |
927 | flModel = POLYGON_BOUNDARY; | |
928 | if(nFillStyle == wxWINDING_RULE) | |
929 | flModel |= POLYGON_WINDING; | |
930 | else | |
931 | flModel |= POLYGON_ALTERNATE; | |
932 | ||
933 | vPoint.x = vXoffset; | |
5fd2b2c6 | 934 | vPoint.y = OS2Y(vYoffset,0); |
51c1d535 DW |
935 | |
936 | ::GpiSetColor(m_hPS, lBorderColor); | |
937 | ::GpiMove(m_hPS, &vPoint); | |
938 | lHits = ::GpiPolygons(m_hPS, ulCount, &vPlgn, flOptions, flModel); | |
939 | free(vPlgn.aPointl); | |
f07bb01b | 940 | } // end of wxDC::DoDrawPolygon |
1408104d | 941 | |
51c1d535 DW |
942 | void wxDC::DoDrawLines( |
943 | int n | |
944 | , wxPoint vPoints[] | |
945 | , wxCoord vXoffset | |
946 | , wxCoord vYoffset | |
947 | ) | |
1408104d | 948 | { |
51c1d535 DW |
949 | POINTL vPoint; |
950 | ||
5fd2b2c6 DW |
951 | if (vXoffset != 0L || vXoffset != 0L) |
952 | { | |
953 | int i; | |
954 | ||
955 | vPoint.x = vPoints[0].x + vXoffset; | |
956 | vPoint.y = OS2Y(vPoints[0].y + vYoffset,0); | |
957 | ::GpiMove(m_hPS, &vPoint); | |
51c1d535 | 958 | |
5fd2b2c6 | 959 | LONG lBorderColor = m_pen.GetColour().GetPixel(); |
51c1d535 | 960 | |
5fd2b2c6 DW |
961 | ::GpiSetColor(m_hPS, lBorderColor); |
962 | for(i = 1; i < n; i++) | |
963 | { | |
964 | vPoint.x = vPoints[i].x + vXoffset; | |
965 | vPoint.y = OS2Y(vPoints[i].y + vYoffset,0); | |
966 | ::GpiLine(m_hPS, &vPoint); | |
967 | } | |
968 | } | |
969 | else | |
51c1d535 | 970 | { |
5fd2b2c6 DW |
971 | int i; |
972 | ||
973 | CalcBoundingBox( vPoints[i].x | |
974 | ,vPoints[i].y | |
975 | ); | |
976 | vPoint.x = vPoints[0].x; | |
977 | vPoint.y = OS2Y(vPoints[0].y,0); | |
978 | ::GpiMove(m_hPS, &vPoint); | |
979 | ||
980 | for (i = 0; i < n; i++) | |
981 | { | |
982 | CalcBoundingBox( vPoints[i].x | |
983 | ,vPoints[i].y | |
984 | ); | |
985 | vPoint.x = vPoints[i].x; | |
986 | vPoint.y = OS2Y(vPoints[i].y,0); | |
987 | ::GpiLine(m_hPS, &vPoint); | |
988 | } | |
51c1d535 | 989 | } |
f07bb01b | 990 | } // end of wxDC::DoDrawLines |
1408104d | 991 | |
7e99520b | 992 | void wxDC::DoDrawRectangle( |
f44fdfb0 | 993 | wxCoord vX |
7e99520b DW |
994 | , wxCoord vY |
995 | , wxCoord vWidth | |
996 | , wxCoord vHeight | |
997 | ) | |
1408104d | 998 | { |
7e99520b | 999 | POINTL vPoint[2]; |
51c1d535 DW |
1000 | LONG lControl; |
1001 | LONG lColor; | |
1002 | LONG lBorderColor; | |
1003 | int nIsTRANSPARENT = 0; | |
7e99520b | 1004 | |
1d0edc0f | 1005 | // |
d6d749aa | 1006 | // Might be a memory DC with no Paint rect. |
1d0edc0f DW |
1007 | // |
1008 | if (!(m_vRclPaint.yTop == 0 && | |
1009 | m_vRclPaint.yBottom == 0 && | |
1010 | m_vRclPaint.xRight == 0 && | |
1011 | m_vRclPaint.xLeft == 0)) | |
1012 | vY = OS2Y(vY,vHeight); | |
1c9a789e DW |
1013 | else |
1014 | { | |
1015 | if (m_vSelectedBitmap != wxNullBitmap) | |
1016 | { | |
1017 | m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight(); | |
1018 | m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth(); | |
1019 | vY = OS2Y(vY,vHeight); | |
1020 | } | |
1021 | } | |
5fd2b2c6 DW |
1022 | |
1023 | wxCoord vX2 = vX + vWidth; | |
1024 | wxCoord vY2 = vY + vHeight; | |
1025 | ||
7e99520b | 1026 | vPoint[0].x = vX; |
5fd2b2c6 | 1027 | vPoint[0].y = vY; |
ba3e10c9 DW |
1028 | vPoint[1].x = vX + vWidth - 1; |
1029 | vPoint[1].y = vY + vHeight - 1; | |
7e99520b | 1030 | ::GpiMove(m_hPS, &vPoint[0]); |
51c1d535 DW |
1031 | lColor = m_brush.GetColour().GetPixel(); |
1032 | lBorderColor = m_pen.GetColour().GetPixel(); | |
1033 | if (m_brush.GetStyle() == wxTRANSPARENT) | |
1034 | nIsTRANSPARENT = 1; | |
1035 | if(lColor == lBorderColor || nIsTRANSPARENT) | |
1036 | { | |
1037 | lControl = DRO_OUTLINEFILL; //DRO_FILL; | |
1038 | if(m_brush.GetStyle() == wxTRANSPARENT) | |
1039 | lControl = DRO_OUTLINE; | |
1040 | ||
8d854fa9 | 1041 | ::GpiSetColor(m_hPS, lColor); |
51c1d535 DW |
1042 | ::GpiBox( m_hPS // handle to a presentation space |
1043 | ,lControl // draw the box outline ? or ? | |
1044 | ,&vPoint[1] // address of the corner | |
1045 | ,0L // horizontal corner radius | |
1046 | ,0L // vertical corner radius | |
1047 | ); | |
1048 | } | |
1049 | else | |
1050 | { | |
1051 | lControl = DRO_OUTLINE; | |
1052 | ::GpiSetColor( m_hPS | |
1053 | ,lBorderColor | |
1054 | ); | |
1055 | ::GpiBox( m_hPS | |
1056 | ,lControl | |
1057 | ,&vPoint[1] | |
1058 | ,0L | |
1059 | ,0L | |
1060 | ); | |
1061 | lControl = DRO_FILL; | |
1062 | ::GpiSetColor( m_hPS | |
1063 | ,lColor | |
1064 | ); | |
8d854fa9 | 1065 | vPoint[0].x = vX + 1; |
5fd2b2c6 | 1066 | vPoint[0].y = vY + 1; |
ba3e10c9 DW |
1067 | vPoint[1].x = vX + vWidth - 2; |
1068 | vPoint[1].y = vY + vHeight - 2; | |
8d854fa9 | 1069 | ::GpiMove(m_hPS, &vPoint[0]); |
51c1d535 DW |
1070 | ::GpiBox( m_hPS |
1071 | ,lControl | |
1072 | ,&vPoint[1] | |
1073 | ,0L | |
1074 | ,0L | |
1075 | ); | |
1076 | } | |
5fd2b2c6 DW |
1077 | CalcBoundingBox(vX, vY); |
1078 | CalcBoundingBox(vX2, vY2); | |
f07bb01b | 1079 | } // end of wxDC::DoDrawRectangle |
1408104d | 1080 | |
7e99520b DW |
1081 | void wxDC::DoDrawRoundedRectangle( |
1082 | wxCoord vX | |
1083 | , wxCoord vY | |
1084 | , wxCoord vWidth | |
1085 | , wxCoord vHeight | |
1086 | , double dRadius | |
1087 | ) | |
1408104d | 1088 | { |
7e99520b | 1089 | POINTL vPoint[2]; |
51c1d535 | 1090 | LONG lControl; |
1c9a789e DW |
1091 | LONG lColor; |
1092 | LONG lBorderColor; | |
1093 | int nIsTRANSPARENT = 0; | |
7e99520b | 1094 | |
d6d749aa DW |
1095 | // |
1096 | // Might be a memory DC with no Paint rect. | |
1097 | // | |
1098 | if (!(m_vRclPaint.yTop == 0 && | |
1099 | m_vRclPaint.yBottom == 0 && | |
1100 | m_vRclPaint.xRight == 0 && | |
1101 | m_vRclPaint.xLeft == 0)) | |
1102 | vY = OS2Y(vY,vHeight); | |
1c9a789e DW |
1103 | else |
1104 | { | |
1105 | if (m_vSelectedBitmap != wxNullBitmap) | |
1106 | { | |
1107 | m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight(); | |
1108 | m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth(); | |
1109 | vY = OS2Y(vY,vHeight); | |
1110 | } | |
1111 | } | |
5fd2b2c6 DW |
1112 | |
1113 | wxCoord vX2 = (vX + vWidth); | |
1114 | wxCoord vY2 = (vY + vHeight); | |
1115 | ||
7e99520b | 1116 | vPoint[0].x = vX; |
1c9a789e DW |
1117 | vPoint[0].y = vY; |
1118 | vPoint[1].x = vX + vWidth - 1; | |
1119 | vPoint[1].y = vY + vHeight - 1; | |
7e99520b | 1120 | ::GpiMove(m_hPS, &vPoint[0]); |
51c1d535 | 1121 | |
1c9a789e DW |
1122 | lColor = m_brush.GetColour().GetPixel(); |
1123 | lBorderColor = m_pen.GetColour().GetPixel(); | |
51c1d535 DW |
1124 | lControl = DRO_OUTLINEFILL; //DRO_FILL; |
1125 | if (m_brush.GetStyle() == wxTRANSPARENT) | |
1c9a789e DW |
1126 | nIsTRANSPARENT = 1; |
1127 | if(lColor == lBorderColor || nIsTRANSPARENT) | |
1128 | { | |
1129 | lControl = DRO_OUTLINEFILL; //DRO_FILL; | |
1130 | if(m_brush.GetStyle() == wxTRANSPARENT) | |
1131 | lControl = DRO_OUTLINE; | |
1132 | ||
1133 | ::GpiSetColor(m_hPS, lColor); | |
1134 | ::GpiBox( m_hPS // handle to a presentation space | |
1135 | ,lControl // draw the box outline ? or ? | |
1136 | ,&vPoint[1] // address of the corner | |
1137 | ,(LONG)dRadius // horizontal corner radius | |
1138 | ,(LONG)dRadius // vertical corner radius | |
1139 | ); | |
1140 | } | |
1141 | else | |
1142 | { | |
51c1d535 | 1143 | lControl = DRO_OUTLINE; |
1c9a789e DW |
1144 | ::GpiSetColor( m_hPS |
1145 | ,lBorderColor | |
1146 | ); | |
1147 | ::GpiBox( m_hPS | |
1148 | ,lControl | |
1149 | ,&vPoint[1] | |
1150 | ,0L | |
1151 | ,0L | |
1152 | ); | |
1153 | lControl = DRO_FILL; | |
1154 | ::GpiSetColor( m_hPS | |
1155 | ,lColor | |
1156 | ); | |
1157 | vPoint[0].x = vX + 1; | |
1158 | vPoint[0].y = vY + 1; | |
1159 | vPoint[1].x = vX + vWidth - 2; | |
1160 | vPoint[1].y = vY + vHeight - 2; | |
1161 | ::GpiMove(m_hPS, &vPoint[0]); | |
1162 | ::GpiBox( m_hPS | |
1163 | ,lControl | |
1164 | ,&vPoint[1] | |
1165 | ,0L | |
1166 | ,0L | |
1167 | ); | |
1168 | } | |
1169 | ||
5fd2b2c6 DW |
1170 | CalcBoundingBox(vX, vY); |
1171 | CalcBoundingBox(vX2, vY2); | |
f07bb01b | 1172 | } // end of wxDC::DoDrawRoundedRectangle |
1408104d | 1173 | |
51c1d535 DW |
1174 | // Draw Ellipse within box (x,y) - (x+width, y+height) |
1175 | void wxDC::DoDrawEllipse( | |
1176 | wxCoord vX | |
1177 | , wxCoord vY | |
1178 | , wxCoord vWidth | |
1179 | , wxCoord vHeight | |
1180 | ) | |
1408104d | 1181 | { |
51c1d535 DW |
1182 | POINTL vPtlPos; // Structure for current position |
1183 | FIXED vFxMult; // Multiplier for ellipse | |
1184 | ARCPARAMS vArcp; // Structure for arc parameters | |
1185 | ||
5fd2b2c6 DW |
1186 | vY = OS2Y(vY,vHeight); |
1187 | ||
51c1d535 DW |
1188 | vArcp.lR = 0; |
1189 | vArcp.lQ = vHeight/2; | |
1190 | vArcp.lP = vWidth/2; | |
1191 | vArcp.lS = 0; | |
1192 | ::GpiSetArcParams( m_hPS | |
1193 | ,&vArcp | |
1194 | ); // Sets parameters to default | |
1195 | vPtlPos.x = vX + vWidth/2; // Loads x-coordinate | |
1196 | vPtlPos.y = vY + vHeight/2; // Loads y-coordinate | |
1197 | ::GpiMove( m_hPS | |
1198 | ,&vPtlPos | |
1199 | ); // Sets current position | |
1200 | vFxMult = MAKEFIXED(1, 0); /* Sets multiplier */ | |
1201 | ||
1202 | // | |
1203 | // DRO_FILL, DRO_OTLINEFILL - where to get | |
1204 | // | |
1205 | ::GpiFullArc( m_hPS | |
1206 | ,DRO_OUTLINE | |
1207 | ,vFxMult | |
1208 | ); // Draws full arc with center at current position | |
5fd2b2c6 DW |
1209 | |
1210 | wxCoord vX2 = (vX + vWidth); | |
1211 | wxCoord vY2 = (vY + vHeight); | |
1212 | ||
1213 | CalcBoundingBox(vX, vY); | |
1214 | CalcBoundingBox(vX2, vY2); | |
f07bb01b | 1215 | } // end of wxDC::DoDrawEllipse |
1408104d | 1216 | |
51c1d535 DW |
1217 | void wxDC::DoDrawEllipticArc( |
1218 | wxCoord vX | |
1219 | , wxCoord vY | |
1220 | , wxCoord vWidth | |
1221 | , wxCoord vHeight | |
1222 | , double dSa | |
1223 | , double dEa | |
1224 | ) | |
1408104d | 1225 | { |
51c1d535 DW |
1226 | POINTL vPtlPos; // Structure for current position |
1227 | FIXED vFxMult; // Multiplier for ellipse | |
1228 | ARCPARAMS vArcp; // Structure for arc parameters | |
1229 | FIXED vFSa; | |
1230 | FIXED vFSweepa; // Start angle, sweep angle | |
1231 | double dIntPart; | |
1232 | double dFractPart; | |
1233 | double dRadius; | |
1234 | ||
5fd2b2c6 DW |
1235 | vY = OS2Y(vY,vHeight); |
1236 | ||
51c1d535 DW |
1237 | dFractPart = modf(dSa,&dIntPart); |
1238 | vFSa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) ); | |
1239 | dFractPart = modf(dEa - dSa, &dIntPart); | |
1240 | vFSweepa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) ); | |
1241 | ||
1242 | // | |
1243 | // Ellipse main axis (r,q), (p,s) with center at (0,0) | |
1244 | // | |
1245 | vArcp.lR = 0; | |
1246 | vArcp.lQ = vHeight/2; | |
1247 | vArcp.lP = vWidth/2; | |
1248 | vArcp.lS = 0; | |
1249 | ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default | |
1250 | vPtlPos.x = vX + vWidth/2 * (1. + cos(DegToRad(dSa))); // Loads x-coordinate | |
1251 | vPtlPos.y = vY + vHeight/2 * (1. + sin(DegToRad(dSa))); // Loads y-coordinate | |
1252 | ::GpiMove(m_hPS, &vPtlPos); // Sets current position | |
1253 | ||
1254 | // | |
1255 | // May be not to the center ? | |
1256 | // | |
1257 | vPtlPos.x = vX + vWidth/2 ; // Loads x-coordinate | |
1258 | vPtlPos.y = vY + vHeight/2; // Loads y-coordinate | |
1259 | vFxMult = MAKEFIXED(1, 0); // Sets multiplier | |
1260 | ||
1261 | // | |
1262 | // DRO_FILL, DRO_OTLINEFILL - where to get | |
1263 | // | |
1264 | ::GpiPartialArc( m_hPS | |
1265 | ,&vPtlPos | |
1266 | ,vFxMult | |
1267 | ,vFSa | |
1268 | ,vFSweepa | |
1269 | ); | |
5fd2b2c6 DW |
1270 | wxCoord vX2 = (vX + vWidth); |
1271 | wxCoord vY2 = (vY + vHeight); | |
1272 | ||
1273 | CalcBoundingBox(vX, vY); | |
1274 | CalcBoundingBox(vX2, vY2); | |
f07bb01b | 1275 | } // end of wxDC::DoDrawEllipticArc |
1408104d | 1276 | |
f07bb01b DW |
1277 | void wxDC::DoDrawIcon( |
1278 | const wxIcon& rIcon | |
1279 | , wxCoord vX | |
1280 | , wxCoord vY | |
1281 | ) | |
1408104d | 1282 | { |
16ff355b DW |
1283 | // |
1284 | // Need to copy back into a bitmap. ::WinDrawPointer uses device coords | |
1285 | // and I don't feel like figuring those out for scrollable windows so | |
1286 | // just convert to a bitmap then let the DoDrawBitmap routing display it | |
1287 | // | |
1288 | if (rIcon.IsXpm()) | |
1289 | { | |
1290 | DoDrawBitmap(rIcon.GetXpmSrc(), vX, vY, TRUE); | |
1291 | } | |
1292 | else | |
1293 | { | |
1294 | wxBitmap vBitmap(rIcon); | |
1295 | ||
1296 | DoDrawBitmap(vBitmap, vX, vY, FALSE); | |
1297 | } | |
5fd2b2c6 DW |
1298 | CalcBoundingBox(vX, vY); |
1299 | CalcBoundingBox(vX + rIcon.GetWidth(), vY + rIcon.GetHeight()); | |
f07bb01b DW |
1300 | } // end of wxDC::DoDrawIcon |
1301 | ||
1302 | void wxDC::DoDrawBitmap( | |
1303 | const wxBitmap& rBmp | |
1304 | , wxCoord vX | |
1305 | , wxCoord vY | |
1306 | , bool bUseMask | |
1307 | ) | |
1408104d | 1308 | { |
ba3e10c9 | 1309 | if (!IsKindOf(CLASSINFO(wxPrinterDC))) |
c354beea DW |
1310 | { |
1311 | HBITMAP hBitmap = (HBITMAP)rBmp.GetHBITMAP(); | |
52315bc3 | 1312 | HBITMAP hBitmapOld; |
1c9a789e | 1313 | POINTL vPoint[4]; |
c354beea | 1314 | |
ba3e10c9 DW |
1315 | vY = OS2Y(vY,rBmp.GetHeight()); |
1316 | ||
1317 | // | |
1318 | // Flip the picture as OS/2 is upside-down | |
1319 | // | |
1c9a789e DW |
1320 | if (rBmp.Flip()) |
1321 | { | |
1322 | vPoint[0].x = vX; | |
1323 | vPoint[0].y = vY + rBmp.GetHeight(); | |
1324 | vPoint[1].x = vX + rBmp.GetWidth(); | |
1325 | vPoint[1].y = vY; | |
1326 | vPoint[2].x = 0; | |
1327 | vPoint[2].y = 0; | |
1328 | vPoint[3].x = rBmp.GetWidth(); | |
1329 | vPoint[3].y = rBmp.GetHeight(); | |
1330 | } | |
1331 | else | |
1332 | { | |
1333 | vPoint[0].x = vX; | |
1334 | vPoint[0].y = vY; | |
1335 | vPoint[1].x = vX + rBmp.GetWidth(); | |
1336 | vPoint[1].y = vY + rBmp.GetHeight(); | |
1337 | vPoint[2].x = 0; | |
1338 | vPoint[2].y = 0; | |
1339 | vPoint[3].x = rBmp.GetWidth(); | |
1340 | vPoint[3].y = rBmp.GetHeight(); | |
1341 | } | |
ba3e10c9 DW |
1342 | if (bUseMask) |
1343 | { | |
1344 | wxMask* pMask = rBmp.GetMask(); | |
c354beea | 1345 | |
52315bc3 | 1346 | if (pMask) |
ba3e10c9 | 1347 | { |
52315bc3 DW |
1348 | // |
1349 | // Need to imitate ::MaskBlt in windows. | |
1350 | // 1) Extract the bits from from the bitmap. | |
1351 | // 2) Extract the bits from the mask | |
1352 | // 3) Using the mask bits do the following: | |
1353 | // A) If the mask byte is 00 leave the bitmap byte alone | |
1354 | // B) If the mask byte is FF copy the screen color into | |
1355 | // bitmap byte | |
1356 | // 4) Create a new bitmap and set its bits to the above result | |
1357 | // 5) Blit this to the screen PS | |
1358 | // | |
1359 | HBITMAP hMask = (HBITMAP)pMask->GetMaskBitmap(); | |
d6d749aa | 1360 | HBITMAP hOldMask = NULLHANDLE; |
52315bc3 DW |
1361 | HBITMAP hOldBitmap = NULLHANDLE; |
1362 | HBITMAP hNewBitmap = NULLHANDLE; | |
1363 | unsigned char* pucBits; // buffer that will contain the bitmap data | |
1364 | unsigned char* pucBitsMask; // buffer that will contain the mask data | |
1365 | unsigned char* pucData; // pointer to use to traverse bitmap data | |
1366 | unsigned char* pucDataMask; // pointer to use to traverse mask data | |
1367 | LONG lHits; | |
1368 | ERRORID vError; | |
1369 | wxString sError; | |
1370 | ||
1371 | // | |
1372 | // The usual Memory context creation stuff | |
1373 | // | |
ba3e10c9 DW |
1374 | DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L}; |
1375 | SIZEL vSize = {0, 0}; | |
52315bc3 DW |
1376 | HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE); |
1377 | HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC); | |
1378 | ||
1379 | // | |
1380 | // The usual bitmap header stuff | |
1381 | // | |
1382 | BITMAPINFOHEADER2 vHeader; | |
1383 | BITMAPINFO2 vInfo; | |
1384 | ||
1385 | memset(&vHeader, '\0', 16); | |
1386 | vHeader.cbFix = 16; | |
52315bc3 DW |
1387 | |
1388 | memset(&vInfo, '\0', 16); | |
1389 | vInfo.cbFix = 16; | |
1390 | vInfo.cx = (ULONG)rBmp.GetWidth(); | |
1391 | vInfo.cy = (ULONG)rBmp.GetHeight(); | |
1392 | vInfo.cPlanes = 1; | |
1393 | vInfo.cBitCount = 24; // Set to desired count going in | |
1394 | ||
1395 | // | |
1396 | // Create the buffers for data....all wxBitmaps are 24 bit internally | |
1397 | // | |
1398 | int nBytesPerLine = rBmp.GetWidth() * 3; | |
1399 | int nSizeDWORD = sizeof(DWORD); | |
1400 | int nLineBoundary = nBytesPerLine % nSizeDWORD; | |
1401 | int nPadding = 0; | |
1402 | int i; | |
1403 | int j; | |
1404 | LONG lScans = 0L; | |
1405 | LONG lColor = 0L; | |
1406 | ||
1407 | // | |
1408 | // Need to get a background color for mask blitting | |
1409 | // | |
1410 | if (IsKindOf(CLASSINFO(wxPaintDC))) | |
1411 | { | |
1412 | wxPaintDC* pPaintDC = wxDynamicCast(this, wxPaintDC); | |
c354beea | 1413 | |
52315bc3 DW |
1414 | lColor = pPaintDC->m_pCanvas->GetBackgroundColour().GetPixel(); |
1415 | } | |
1416 | else if (GetBrush() != wxNullBrush) | |
1417 | lColor = GetBrush().GetColour().GetPixel(); | |
1418 | else | |
1419 | lColor = m_textBackgroundColour.GetPixel(); | |
1420 | ||
1421 | // | |
1422 | // Bitmap must be ina double-word alligned address so we may | |
1423 | // have some padding to worry about | |
1424 | // | |
1425 | if (nLineBoundary > 0) | |
1426 | { | |
1427 | nPadding = nSizeDWORD - nLineBoundary; | |
1428 | nBytesPerLine += nPadding; | |
1429 | } | |
1430 | pucBits = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight()); | |
1431 | pucBitsMask = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight()); | |
1432 | memset(pucBits, '\0', (nBytesPerLine * rBmp.GetHeight())); | |
1433 | memset(pucBitsMask, '\0', (nBytesPerLine * rBmp.GetHeight())); | |
1434 | ||
1435 | // | |
1436 | // Extract the bitmap and mask data | |
1437 | // | |
1438 | if ((hOldBitmap = ::GpiSetBitmap(hPS, hBitmap)) == HBM_ERROR) | |
1439 | { | |
1440 | vError = ::WinGetLastError(vHabmain); | |
1441 | sError = wxPMErrorToStr(vError); | |
1442 | } | |
d6d749aa DW |
1443 | ::GpiQueryBitmapInfoHeader(hBitmap, &vHeader); |
1444 | vInfo.cBitCount = 24; | |
ba3e10c9 DW |
1445 | if ((lScans = ::GpiQueryBitmapBits( hPS |
1446 | ,0L | |
1447 | ,(LONG)rBmp.GetHeight() | |
52315bc3 | 1448 | ,(PBYTE)pucBits |
ba3e10c9 DW |
1449 | ,&vInfo |
1450 | )) == GPI_ALTERROR) | |
1451 | { | |
ba3e10c9 DW |
1452 | vError = ::WinGetLastError(vHabmain); |
1453 | sError = wxPMErrorToStr(vError); | |
1454 | } | |
d6d749aa | 1455 | if ((hOldMask = ::GpiSetBitmap(hPS, hMask)) == HBM_ERROR) |
ba3e10c9 | 1456 | { |
ba3e10c9 DW |
1457 | vError = ::WinGetLastError(vHabmain); |
1458 | sError = wxPMErrorToStr(vError); | |
1459 | } | |
d6d749aa DW |
1460 | ::GpiQueryBitmapInfoHeader(hMask, &vHeader); |
1461 | vInfo.cBitCount = 24; | |
52315bc3 DW |
1462 | if ((lScans = ::GpiQueryBitmapBits( hPS |
1463 | ,0L | |
1464 | ,(LONG)rBmp.GetHeight() | |
1465 | ,(PBYTE)pucBitsMask | |
1466 | ,&vInfo | |
1467 | )) == GPI_ALTERROR) | |
ba3e10c9 | 1468 | { |
ba3e10c9 DW |
1469 | vError = ::WinGetLastError(vHabmain); |
1470 | sError = wxPMErrorToStr(vError); | |
1471 | } | |
d6d749aa DW |
1472 | if (( hMask = ::GpiSetBitmap(hPS, hOldMask)) == HBM_ERROR) |
1473 | { | |
1474 | vError = ::WinGetLastError(vHabmain); | |
1475 | sError = wxPMErrorToStr(vError); | |
1476 | } | |
52315bc3 DW |
1477 | |
1478 | // | |
1479 | // Now set the bytes(bits) according to the mask values | |
1480 | // 3 bytes per pel...must handle one at a time | |
1481 | // | |
1482 | pucData = pucBits; | |
1483 | pucDataMask = pucBitsMask; | |
1484 | ||
d6d749aa DW |
1485 | // |
1486 | // 16 bit kludge really only kinda works. The mask gets applied | |
1487 | // where needed but the original bitmap bits are dorked sometimes | |
1488 | // | |
1489 | bool bpp16 = (wxDisplayDepth() == 16); | |
1490 | ||
52315bc3 | 1491 | for (i = 0; i < rBmp.GetHeight(); i++) |
ba3e10c9 | 1492 | { |
52315bc3 DW |
1493 | for (j = 0; j < rBmp.GetWidth(); j++) |
1494 | { | |
1495 | // Byte 1 | |
d6d749aa DW |
1496 | if (bpp16 && *pucDataMask == 0xF8) // 16 bit display gobblygook |
1497 | pucData++; | |
1498 | else if (*pucDataMask == 0xFF) // leave bitmap byte alone | |
52315bc3 DW |
1499 | pucData++; |
1500 | else | |
1501 | { | |
16ff355b | 1502 | *pucData = ((unsigned char)(lColor >> 16)); |
52315bc3 DW |
1503 | pucData++; |
1504 | } | |
1505 | // Byte 2 | |
d6d749aa DW |
1506 | if (bpp16 && *(pucDataMask + 1) == 0xFC) // 16 bit display gobblygook |
1507 | pucData++; | |
1508 | else if (*(pucDataMask + 1) == 0xFF) // leave bitmap byte alone | |
52315bc3 DW |
1509 | pucData++; |
1510 | else | |
1511 | { | |
16ff355b | 1512 | *pucData = ((unsigned char)(lColor >> 8)); |
52315bc3 DW |
1513 | pucData++; |
1514 | } | |
1515 | ||
1516 | // Byte 3 | |
d6d749aa DW |
1517 | if (bpp16 && *(pucDataMask + 2) == 0xF8) // 16 bit display gobblygook |
1518 | pucData++; | |
1519 | else if (*(pucDataMask + 2) == 0xFF) // leave bitmap byte alone | |
52315bc3 DW |
1520 | pucData++; |
1521 | else | |
1522 | { | |
16ff355b | 1523 | *pucData = ((unsigned char)lColor); |
52315bc3 DW |
1524 | pucData++; |
1525 | } | |
1526 | pucDataMask += 3; | |
1527 | } | |
1528 | for (j = 0; j < nPadding; j++) | |
1529 | { | |
1530 | pucData++; | |
1531 | pucDataMask++; | |
1532 | } | |
1533 | } | |
52315bc3 DW |
1534 | // |
1535 | // Create a new bitmap | |
1536 | // | |
d6d749aa DW |
1537 | vHeader.cx = (ULONG)rBmp.GetWidth(); |
1538 | vHeader.cy = (ULONG)rBmp.GetHeight(); | |
1539 | vHeader.cPlanes = 1L; | |
1540 | vHeader.cBitCount = 24; | |
52315bc3 DW |
1541 | if ((hNewBitmap = ::GpiCreateBitmap( hPS |
1542 | ,&vHeader | |
1543 | ,CBM_INIT | |
1544 | ,(PBYTE)pucBits | |
1545 | ,&vInfo | |
1546 | )) == GPI_ERROR) | |
1547 | { | |
ba3e10c9 DW |
1548 | vError = ::WinGetLastError(vHabmain); |
1549 | sError = wxPMErrorToStr(vError); | |
1550 | } | |
ba3e10c9 | 1551 | |
52315bc3 DW |
1552 | // |
1553 | // Now blit it to the screen PS | |
1554 | // | |
1555 | if ((lHits = ::GpiWCBitBlt( (HPS)GetHPS() | |
1556 | ,hNewBitmap | |
1557 | ,4 | |
1558 | ,vPoint | |
1559 | ,ROP_SRCCOPY | |
1560 | ,BBO_IGNORE | |
1561 | )) == GPI_ERROR) | |
1562 | { | |
ba3e10c9 DW |
1563 | vError = ::WinGetLastError(vHabmain); |
1564 | sError = wxPMErrorToStr(vError); | |
1565 | } | |
52315bc3 DW |
1566 | |
1567 | // | |
1568 | // Clean up | |
1569 | // | |
1570 | free(pucBits); | |
1571 | free(pucBitsMask); | |
1572 | ::GpiSetBitmap(hPS, NULLHANDLE); | |
d6d749aa | 1573 | ::GpiDeleteBitmap(hNewBitmap); |
52315bc3 DW |
1574 | ::GpiDestroyPS(hPS); |
1575 | ::DevCloseDC(hDC); | |
ba3e10c9 DW |
1576 | } |
1577 | } | |
1578 | else | |
1579 | { | |
16ff355b DW |
1580 | LONG lOldForeGround = ::GpiQueryColor((HPS)GetHPS()); |
1581 | LONG lOldBackGround = ::GpiQueryBackColor((HPS)GetHPS()); | |
52315bc3 DW |
1582 | |
1583 | if (m_textForegroundColour.Ok()) | |
1584 | { | |
1585 | ::GpiSetColor( (HPS)GetHPS() | |
1586 | ,m_textForegroundColour.GetPixel() | |
1587 | ); | |
1588 | } | |
1589 | if (m_textBackgroundColour.Ok()) | |
1590 | { | |
1591 | ::GpiSetBackColor( (HPS)GetHPS() | |
1592 | ,m_textBackgroundColour.GetPixel() | |
1593 | ); | |
1594 | } | |
16ff355b DW |
1595 | // |
1596 | // Need to alter bits in a mono bitmap to match the new | |
1597 | // background-foreground if it is different. | |
1598 | // | |
1599 | if (rBmp.IsMono() && | |
1600 | ((m_textForegroundColour.GetPixel() != lOldForeGround) || | |
1601 | (m_textBackgroundColour.GetPixel() != lOldBackGround))) | |
1602 | { | |
1603 | DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L}; | |
1604 | SIZEL vSize = {0, 0}; | |
1605 | HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE); | |
1606 | HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC); | |
1607 | ||
1608 | int nBytesPerLine = rBmp.GetWidth() * 3; | |
1609 | int i, j; | |
1610 | LONG lForeGround = m_textForegroundColour.GetPixel(); | |
1611 | LONG lBackGround = m_textBackgroundColour.GetPixel(); | |
1612 | LONG lScans; | |
1613 | HBITMAP hOldBitmap = NULLHANDLE; | |
1614 | BITMAPINFO2 vInfo; | |
1615 | ERRORID vError; | |
1616 | wxString sError; | |
1617 | ||
1618 | ||
1619 | memset(&vInfo, '\0', 16); | |
1620 | vInfo.cbFix = 16; | |
1621 | vInfo.cx = (ULONG)rBmp.GetWidth(); | |
1622 | vInfo.cy = (ULONG)rBmp.GetHeight(); | |
1623 | vInfo.cPlanes = 1; | |
1624 | vInfo.cBitCount = 24; | |
1625 | ||
1626 | unsigned char* pucBits; // buffer that will contain the bitmap data | |
1627 | unsigned char* pucData; // pointer to use to traverse bitmap data | |
1628 | ||
1629 | pucBits = new unsigned char[nBytesPerLine * rBmp.GetHeight()]; | |
1630 | memset(pucBits, '\0', (nBytesPerLine * rBmp.GetHeight())); | |
1631 | ||
1632 | if ((hOldBitmap = ::GpiSetBitmap(hPS, hBitmap)) == HBM_ERROR) | |
1633 | { | |
1634 | vError = ::WinGetLastError(vHabmain); | |
1635 | sError = wxPMErrorToStr(vError); | |
1636 | return; | |
1637 | } | |
1638 | if ((lScans = ::GpiQueryBitmapBits( hPS | |
1639 | ,0L | |
1640 | ,(LONG)rBmp.GetHeight() | |
1641 | ,(PBYTE)pucBits | |
1642 | ,&vInfo | |
1643 | )) == GPI_ALTERROR) | |
1644 | { | |
1645 | vError = ::WinGetLastError(vHabmain); | |
1646 | sError = wxPMErrorToStr(vError); | |
1647 | return; | |
1648 | } | |
1649 | unsigned char cOldRedFore = (unsigned char)(lOldForeGround >> 16); | |
1650 | unsigned char cOldGreenFore = (unsigned char)(lOldForeGround >> 8); | |
1651 | unsigned char cOldBlueFore = (unsigned char)lOldForeGround; | |
1652 | ||
1653 | unsigned char cOldRedBack = (unsigned char)(lOldBackGround >> 16); | |
1654 | unsigned char cOldGreenBack = (unsigned char)(lOldBackGround >> 8); | |
1655 | unsigned char cOldBlueBack = (unsigned char)lOldBackGround; | |
1656 | ||
1657 | unsigned char cRedFore = (unsigned char)(lForeGround >> 16); | |
1658 | unsigned char cGreenFore = (unsigned char)(lForeGround >> 8); | |
1659 | unsigned char cBlueFore = (unsigned char)lForeGround; | |
1660 | ||
1661 | unsigned char cRedBack = (unsigned char)(lBackGround >> 16); | |
1662 | unsigned char cGreenBack = (unsigned char)(lBackGround >> 8); | |
1663 | unsigned char cBlueBack = (unsigned char)lBackGround; | |
1664 | ||
1665 | pucData = pucBits; | |
1666 | for (i = 0; i < rBmp.GetHeight(); i++) | |
1667 | { | |
1668 | for (j = 0; j < rBmp.GetWidth(); j++) | |
1669 | { | |
1670 | unsigned char cBmpRed = *pucData; | |
1671 | unsigned char cBmpGreen = *(pucData + 1); | |
1672 | unsigned char cBmpBlue = *(pucData + 2); | |
1673 | ||
1674 | if ((cBmpRed == cOldRedFore) && | |
1675 | (cBmpGreen == cOldGreenFore) && | |
1676 | (cBmpBlue == cOldBlueFore)) | |
1677 | { | |
29172908 | 1678 | *pucData = cBlueFore; |
16ff355b DW |
1679 | pucData++; |
1680 | *pucData = cGreenFore; | |
1681 | pucData++; | |
29172908 | 1682 | *pucData = cRedFore; |
16ff355b DW |
1683 | pucData++; |
1684 | } | |
1685 | else | |
1686 | { | |
29172908 | 1687 | *pucData = cBlueBack; |
16ff355b DW |
1688 | pucData++; |
1689 | *pucData = cGreenBack; | |
1690 | pucData++; | |
29172908 | 1691 | *pucData = cRedBack; |
16ff355b DW |
1692 | pucData++; |
1693 | } | |
1694 | } | |
1695 | } | |
1696 | if ((lScans = ::GpiSetBitmapBits( hPS | |
1697 | ,0L | |
1698 | ,(LONG)rBmp.GetHeight() | |
1699 | ,(PBYTE)pucBits | |
1700 | ,&vInfo | |
1701 | )) == GPI_ALTERROR) | |
1702 | { | |
1703 | vError = ::WinGetLastError(vHabmain); | |
1704 | sError = wxPMErrorToStr(vError); | |
1705 | return; | |
1706 | } | |
1707 | delete [] pucBits; | |
1708 | ::GpiSetBitmap(hPS, NULLHANDLE); | |
1709 | ::GpiDestroyPS(hPS); | |
1710 | ::DevCloseDC(hDC); | |
1711 | } | |
ba3e10c9 DW |
1712 | ::GpiWCBitBlt( (HPS)GetHPS() |
1713 | ,hBitmap | |
1714 | ,4 | |
1715 | ,vPoint | |
1716 | ,ROP_SRCCOPY | |
1717 | ,BBO_IGNORE | |
1718 | ); | |
52315bc3 | 1719 | ::GpiSetBitmap((HPS)GetHPS(), hBitmapOld); |
16ff355b DW |
1720 | ::GpiSetColor((HPS)GetHPS(), lOldForeGround); |
1721 | ::GpiSetBackColor((HPS)GetHPS(), lOldBackGround); | |
ba3e10c9 | 1722 | } |
c354beea | 1723 | } |
f07bb01b | 1724 | } // end of wxDC::DoDrawBitmap |
1408104d | 1725 | |
7e99520b DW |
1726 | void wxDC::DoDrawText( |
1727 | const wxString& rsText | |
1728 | , wxCoord vX | |
1729 | , wxCoord vY | |
1730 | ) | |
1408104d | 1731 | { |
5fd2b2c6 DW |
1732 | wxCoord vWidth; |
1733 | wxCoord vHeight; | |
1734 | ||
7e99520b DW |
1735 | DrawAnyText( rsText |
1736 | ,vX | |
1737 | ,vY | |
1738 | ); | |
5fd2b2c6 DW |
1739 | |
1740 | CalcBoundingBox(vX, vY); | |
1741 | GetTextExtent(rsText, &vWidth, &vHeight); | |
1742 | CalcBoundingBox((vX + vWidth), (vY + vHeight)); | |
1743 | } // end of wxDC::DoDrawText | |
1408104d | 1744 | |
7e99520b DW |
1745 | void wxDC::DrawAnyText( |
1746 | const wxString& rsText | |
1747 | , wxCoord vX | |
1748 | , wxCoord vY | |
1749 | ) | |
f6bcfd97 | 1750 | { |
7e99520b DW |
1751 | int nOldBackground = 0; |
1752 | POINTL vPtlStart; | |
1753 | LONG lHits; | |
5fd2b2c6 DW |
1754 | wxCoord vTextX = 0; |
1755 | wxCoord vTextY = 0; | |
f6bcfd97 | 1756 | |
7e99520b DW |
1757 | // |
1758 | // prepare for drawing the text | |
1759 | // | |
1760 | ||
1761 | // | |
1762 | // Set text color attributes | |
1763 | // | |
1764 | if (m_textForegroundColour.Ok()) | |
1765 | { | |
1766 | SetTextColor( m_hPS | |
1767 | ,(int)m_textForegroundColour.GetPixel() | |
1768 | ); | |
1769 | } | |
1770 | ||
1771 | if (m_textBackgroundColour.Ok()) | |
1772 | { | |
1773 | nOldBackground = SetTextBkColor( m_hPS | |
1774 | ,(int)m_textBackgroundColour.GetPixel() | |
1775 | ); | |
1776 | } | |
1777 | SetBkMode( m_hPS | |
1778 | ,m_backgroundMode | |
1779 | ); | |
5fd2b2c6 DW |
1780 | GetTextExtent( rsText |
1781 | ,&vTextX | |
1782 | ,&vTextY | |
1783 | ); | |
7e99520b | 1784 | vPtlStart.x = vX; |
d6d749aa DW |
1785 | if (!(m_vRclPaint.yTop == 0 && |
1786 | m_vRclPaint.yBottom == 0 && | |
1787 | m_vRclPaint.xRight == 0 && | |
1788 | m_vRclPaint.xLeft == 0)) | |
1789 | vPtlStart.y = OS2Y(vY,vTextY); | |
1790 | else | |
1c9a789e DW |
1791 | { |
1792 | if (m_vSelectedBitmap != wxNullBitmap) | |
1793 | { | |
1794 | m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight(); | |
1795 | m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth(); | |
1796 | vPtlStart.y = OS2Y(vY,vTextY); | |
1797 | } | |
1798 | else | |
1799 | vPtlStart.y = vY; | |
1800 | } | |
d6d749aa DW |
1801 | |
1802 | PCH pzStr = (PCH)rsText.c_str(); | |
7e99520b | 1803 | |
d6d749aa DW |
1804 | ::GpiMove(m_hPS, &vPtlStart); |
1805 | lHits = ::GpiCharString( m_hPS | |
1806 | ,rsText.length() | |
1807 | ,pzStr | |
1808 | ); | |
7e99520b DW |
1809 | if (lHits != GPI_OK) |
1810 | { | |
1811 | wxLogLastError(wxT("TextOut")); | |
1812 | } | |
1813 | ||
1814 | // | |
1815 | // Restore the old parameters (text foreground colour may be left because | |
1816 | // it never is set to anything else, but background should remain | |
1817 | // transparent even if we just drew an opaque string) | |
1818 | // | |
1819 | if (m_textBackgroundColour.Ok()) | |
1820 | SetTextBkColor( m_hPS | |
1821 | ,nOldBackground | |
1822 | ); | |
1823 | SetBkMode( m_hPS | |
1824 | ,wxTRANSPARENT | |
1825 | ); | |
1826 | } | |
1827 | ||
1828 | void wxDC::DoDrawRotatedText( | |
1829 | const wxString& rsText | |
1830 | , wxCoord vX | |
1831 | , wxCoord vY | |
1832 | , double dAngle | |
1833 | ) | |
c8ce6bcc | 1834 | { |
7e99520b DW |
1835 | if (dAngle == 0.0) |
1836 | { | |
1837 | DoDrawText( rsText | |
1838 | ,vX | |
1839 | ,vY | |
1840 | ); | |
1841 | } | |
1842 | ||
c8ce6bcc DW |
1843 | // TODO: |
1844 | /* | |
1845 | if ( angle == 0.0 ) | |
1846 | { | |
1847 | DoDrawText(text, x, y); | |
1848 | } | |
1849 | else | |
1850 | { | |
1851 | LOGFONT lf; | |
1852 | wxFillLogFont(&lf, &m_font); | |
1853 | ||
1854 | // GDI wants the angle in tenth of degree | |
1855 | long angle10 = (long)(angle * 10); | |
1856 | lf.lfEscapement = angle10; | |
1857 | lf. lfOrientation = angle10; | |
1858 | ||
1859 | HFONT hfont = ::CreateFontIndirect(&lf); | |
1860 | if ( !hfont ) | |
1861 | { | |
1862 | wxLogLastError("CreateFont"); | |
1863 | } | |
1864 | else | |
1865 | { | |
1866 | HFONT hfontOld = ::SelectObject(GetHdc(), hfont); | |
1867 | ||
1868 | DrawAnyText(text, x, y); | |
1869 | ||
1870 | (void)::SelectObject(GetHdc(), hfontOld); | |
1871 | } | |
1872 | ||
1873 | // call the bounding box by adding all four vertices of the rectangle | |
1874 | // containing the text to it (simpler and probably not slower than | |
1875 | // determining which of them is really topmost/leftmost/...) | |
1876 | wxCoord w, h; | |
1877 | GetTextExtent(text, &w, &h); | |
1878 | ||
1879 | double rad = DegToRad(angle); | |
1880 | ||
1881 | // "upper left" and "upper right" | |
1882 | CalcBoundingBox(x, y); | |
1883 | CalcBoundingBox(x + w*cos(rad), y - h*sin(rad)); | |
1884 | CalcBoundingBox(x + h*sin(rad), y + h*cos(rad)); | |
1885 | ||
1886 | // "bottom left" and "bottom right" | |
1887 | x += (wxCoord)(h*sin(rad)); | |
1888 | y += (wxCoord)(h*cos(rad)); | |
1889 | CalcBoundingBox(x, y); | |
1890 | CalcBoundingBox(x + h*sin(rad), y + h*cos(rad)); | |
1891 | } | |
1892 | */ | |
1893 | } | |
1894 | ||
fb46a9a6 DW |
1895 | // --------------------------------------------------------------------------- |
1896 | // set GDI objects | |
1897 | // --------------------------------------------------------------------------- | |
1408104d | 1898 | |
938aa9c4 DW |
1899 | void wxDC::DoSelectPalette( |
1900 | bool bRealize | |
1901 | ) | |
1902 | { | |
1903 | // | |
1904 | // Set the old object temporarily, in case the assignment deletes an object | |
1905 | // that's not yet selected out. | |
1906 | // | |
1907 | if (m_hOldPalette) | |
1908 | { | |
1909 | m_hOldPalette = 0; | |
1910 | } | |
1911 | ||
1912 | if (m_palette.Ok()) | |
1913 | { | |
1914 | HPALETTE hOldPal; | |
1915 | ||
1916 | hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE()); | |
1917 | if (!m_hOldPalette) | |
1918 | m_hOldPalette = (WXHPALETTE)hOldPal; | |
1919 | } | |
1920 | } // end of wxDC::DoSelectPalette | |
1921 | ||
1922 | void wxDC::InitializePalette() | |
1923 | { | |
1924 | if (wxDisplayDepth() <= 8 ) | |
1925 | { | |
1926 | // | |
1927 | // Look for any window or parent that has a custom palette. If any has | |
1928 | // one then we need to use it in drawing operations | |
1929 | // | |
1930 | wxWindow* pWin = m_pCanvas->GetAncestorWithCustomPalette(); | |
1931 | ||
1932 | m_hasCustomPalette = pWin && pWin->HasCustomPalette(); | |
1933 | if (m_hasCustomPalette) | |
1934 | { | |
1935 | m_palette = pWin->GetPalette(); | |
1936 | ||
1937 | // | |
1938 | // turn on PM translation for this palette | |
1939 | // | |
1940 | DoSelectPalette(); | |
1941 | } | |
1942 | } | |
1943 | } // end of wxDC::InitializePalette | |
1944 | ||
5fd2b2c6 DW |
1945 | void wxDC::SetPalette( |
1946 | const wxPalette& rPalette | |
1947 | ) | |
1408104d | 1948 | { |
5fd2b2c6 DW |
1949 | if (m_hOldFont) |
1950 | { | |
1951 | m_hOldFont = 0; | |
1952 | } | |
1953 | m_palette = rPalette; | |
1954 | if (!rPalette.Ok()) | |
1955 | { | |
1956 | if (m_hOldFont) | |
1957 | { | |
1958 | m_hOldFont = 0; | |
1959 | } | |
1960 | } | |
1961 | HPALETTE hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE()); | |
1962 | if (!m_hOldPalette) | |
1963 | m_hOldPalette = (WXHPALETTE)hOldPal; | |
1964 | } // end of wxDC::SetPalette | |
1408104d | 1965 | |
f6bcfd97 BP |
1966 | void wxDC::SetFont( |
1967 | const wxFont& rFont | |
1968 | ) | |
1408104d | 1969 | { |
f6bcfd97 BP |
1970 | // |
1971 | // Set the old object temporarily, in case the assignment deletes an object | |
1972 | // that's not yet selected out. | |
1973 | // | |
1974 | if (m_hOldFont) | |
1975 | { | |
f6bcfd97 BP |
1976 | m_hOldFont = 0; |
1977 | } | |
f6bcfd97 | 1978 | m_font = rFont; |
f6bcfd97 BP |
1979 | if (!rFont.Ok()) |
1980 | { | |
f6bcfd97 BP |
1981 | m_hOldFont = 0; |
1982 | } | |
1983 | ||
e99762c0 DW |
1984 | m_font.SetPS(m_hPS); // this will realize the font |
1985 | ||
1986 | if (m_font.Ok()) | |
f6bcfd97 | 1987 | { |
e99762c0 | 1988 | HFONT hFont = m_font.GetResourceHandle(); |
f6bcfd97 BP |
1989 | if (hFont == (HFONT) NULL) |
1990 | { | |
1991 | wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont.")); | |
1992 | } | |
1993 | if (!m_hOldFont) | |
1994 | m_hOldFont = (WXHFONT) hFont; | |
1995 | } | |
e99762c0 | 1996 | } // end of wxDC::SetFont |
1408104d | 1997 | |
7e99520b DW |
1998 | void wxDC::SetPen( |
1999 | const wxPen& rPen | |
2000 | ) | |
1408104d | 2001 | { |
7e99520b DW |
2002 | wxCHECK_RET( Ok(), wxT("invalid window dc") ); |
2003 | ||
2004 | if (m_pen == rPen) | |
2005 | return; | |
2006 | m_pen = rPen; | |
2007 | if (!m_pen.Ok()) | |
2008 | return; | |
2009 | ||
26ac77db DW |
2010 | if (m_hOldPen) |
2011 | m_hOldPen = 0L; | |
2012 | m_pen = rPen; | |
7e99520b | 2013 | |
26ac77db | 2014 | if (!m_pen.Ok()) |
7e99520b | 2015 | { |
26ac77db DW |
2016 | if (m_hOldPen) |
2017 | { | |
2018 | m_pen.SetPS((HPS)m_hOldPen); | |
2019 | } | |
2020 | m_hOldPen = 0L; | |
7e99520b | 2021 | } |
51c1d535 | 2022 | |
26ac77db | 2023 | if (m_pen.Ok()) |
51c1d535 | 2024 | { |
26ac77db DW |
2025 | if (m_pen.GetResourceHandle()) |
2026 | { | |
2027 | m_pen.SetPS(m_hPS); | |
2028 | if (!m_hOldPen) | |
2029 | m_hOldPen = m_pen.GetPS(); | |
2030 | } | |
29172908 | 2031 | ::GpiSetColor(m_hPS, m_pen.GetColour().GetPixel()); |
51c1d535 | 2032 | } |
1408104d | 2033 | } |
7e99520b | 2034 | |
51c1d535 DW |
2035 | void wxDC::SetBrush( |
2036 | const wxBrush& rBrush | |
2037 | ) | |
1408104d | 2038 | { |
15f03b25 DW |
2039 | wxCHECK_RET( Ok(), wxT("invalid window dc") ); |
2040 | ||
15f03b25 DW |
2041 | if (m_hOldBrush) |
2042 | m_hOldBrush = 0L; | |
2043 | m_brush = rBrush; | |
5fd2b2c6 DW |
2044 | if (!m_brush.Ok()) |
2045 | if (m_brush == rBrush) | |
2046 | return; | |
2047 | if (!m_brush.Ok()) | |
2048 | if (m_hOldBrush) | |
2049 | m_hOldBrush = 0L; | |
15f03b25 DW |
2050 | |
2051 | if (!m_brush.Ok()) | |
2052 | { | |
2053 | if (m_hOldBrush) | |
2054 | { | |
2055 | m_brush.SetPS((HPS)m_hOldBrush); | |
2056 | } | |
2057 | m_hOldBrush = 0L; | |
2058 | } | |
2059 | ||
2060 | if (m_brush.Ok()) | |
2061 | { | |
2062 | if (m_brush.GetResourceHandle()) | |
2063 | { | |
2064 | m_brush.SetPS(m_hPS); | |
2065 | if (!m_hOldBrush) | |
5fd2b2c6 | 2066 | m_hOldBrush = (WXHWND)m_brush.GetPS(); |
15f03b25 DW |
2067 | } |
2068 | } | |
2069 | } // end of wxDC::SetBrush | |
1408104d | 2070 | |
5fd2b2c6 DW |
2071 | void wxDC::SetBackground( |
2072 | const wxBrush& rBrush | |
2073 | ) | |
1408104d | 2074 | { |
5fd2b2c6 DW |
2075 | m_backgroundBrush = rBrush; |
2076 | if (!m_backgroundBrush.Ok()) | |
2077 | return; | |
2078 | if (m_pCanvas) | |
2079 | { | |
2080 | bool bCustomColours = TRUE; | |
2081 | ||
2082 | // | |
2083 | // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to | |
2084 | // change background colours from the control-panel specified colours. | |
2085 | // | |
2086 | if (m_pCanvas->IsKindOf(CLASSINFO(wxWindow)) && | |
2087 | ((m_pCanvas->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS)) | |
2088 | bCustomColours = FALSE; | |
2089 | if (bCustomColours) | |
2090 | { | |
2091 | if (m_backgroundBrush.GetStyle()==wxTRANSPARENT) | |
2092 | { | |
2093 | m_pCanvas->SetTransparent(TRUE); | |
2094 | } | |
2095 | else | |
2096 | { | |
2097 | // | |
2098 | // Setting the background brush of a DC | |
2099 | // doesn't affect the window background colour. However, | |
2100 | // I'm leaving in the transparency setting because it's needed by | |
2101 | // various controls (e.g. wxStaticText) to determine whether to draw | |
2102 | // transparently or not. TODO: maybe this should be a new function | |
2103 | // wxWindow::SetTransparency(). Should that apply to the child itself, or the | |
2104 | // parent? | |
2105 | // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour()); | |
2106 | // | |
2107 | m_pCanvas->SetTransparent(FALSE); | |
2108 | } | |
2109 | } | |
2110 | } | |
2111 | COLORREF vNewColor = m_backgroundBrush.GetColour().GetPixel(); | |
2112 | (void)::GpiSetBackColor((HPS)m_hPS, (LONG)vNewColor); | |
2113 | } // end of wxDC::SetBackground | |
1408104d | 2114 | |
7e99520b DW |
2115 | void wxDC::SetBackgroundMode( |
2116 | int nMode | |
2117 | ) | |
1408104d | 2118 | { |
7e99520b | 2119 | m_backgroundMode = nMode; |
5fd2b2c6 | 2120 | } // end of wxDC::SetBackgroundMode |
1408104d | 2121 | |
5fd2b2c6 DW |
2122 | void wxDC::SetLogicalFunction( |
2123 | int nFunction | |
2124 | ) | |
1408104d | 2125 | { |
5fd2b2c6 DW |
2126 | m_logicalFunction = nFunction; |
2127 | SetRop((WXHDC)m_hDC); | |
2128 | } // wxDC::SetLogicalFunction | |
1408104d | 2129 | |
5fd2b2c6 DW |
2130 | void wxDC::SetRop( |
2131 | WXHDC hDC | |
2132 | ) | |
ce44c50e | 2133 | { |
5fd2b2c6 | 2134 | if (!hDC || m_logicalFunction < 0) |
ce44c50e DW |
2135 | return; |
2136 | ||
5fd2b2c6 | 2137 | LONG lCRop; |
ce44c50e DW |
2138 | switch (m_logicalFunction) |
2139 | { | |
5fd2b2c6 DW |
2140 | case wxXOR: |
2141 | lCRop = FM_XOR; | |
2142 | break; | |
2143 | ||
2144 | case wxINVERT: | |
2145 | lCRop = FM_INVERT; | |
2146 | break; | |
2147 | ||
2148 | case wxOR_REVERSE: | |
2149 | lCRop = FM_MERGESRCNOT; | |
2150 | break; | |
2151 | ||
2152 | case wxAND_REVERSE: | |
2153 | lCRop = FM_NOTMASKSRC; | |
2154 | break; | |
2155 | ||
2156 | case wxCLEAR: | |
2157 | lCRop = FM_ONE; | |
2158 | break; | |
2159 | ||
2160 | case wxSET: | |
2161 | lCRop = FM_ZERO; | |
2162 | break; | |
2163 | ||
2164 | case wxSRC_INVERT: | |
2165 | lCRop = FM_MERGENOTSRC; | |
2166 | break; | |
2167 | ||
2168 | case wxOR_INVERT: | |
2169 | lCRop = FM_MERGESRCNOT; | |
2170 | break; | |
2171 | ||
2172 | case wxAND: | |
2173 | lCRop = FM_AND; | |
2174 | break; | |
2175 | ||
2176 | case wxOR: | |
2177 | lCRop = FM_OR; | |
2178 | break; | |
2179 | ||
2180 | case wxAND_INVERT: | |
2181 | lCRop = FM_SUBTRACT; | |
2182 | break; | |
2183 | ||
2184 | case wxEQUIV: | |
2185 | case wxNAND: | |
2186 | case wxCOPY: | |
2187 | default: | |
2188 | lCRop = FM_OVERPAINT; | |
2189 | break; | |
ce44c50e | 2190 | } |
5fd2b2c6 DW |
2191 | ::GpiSetMix((HPS)hDC, lCRop); |
2192 | } // end of wxDC::SetRop | |
ce44c50e | 2193 | |
5fd2b2c6 DW |
2194 | bool wxDC::StartDoc( |
2195 | const wxString& rsMessage | |
2196 | ) | |
ce44c50e | 2197 | { |
fb46a9a6 DW |
2198 | // We might be previewing, so return TRUE to let it continue. |
2199 | return TRUE; | |
5fd2b2c6 | 2200 | } // end of wxDC::StartDoc |
fb46a9a6 DW |
2201 | |
2202 | void wxDC::EndDoc() | |
2203 | { | |
5fd2b2c6 | 2204 | } // end of wxDC::EndDoc |
fb46a9a6 DW |
2205 | |
2206 | void wxDC::StartPage() | |
2207 | { | |
5fd2b2c6 | 2208 | } // end of wxDC::StartPage |
fb46a9a6 DW |
2209 | |
2210 | void wxDC::EndPage() | |
2211 | { | |
5fd2b2c6 | 2212 | } // end of wxDC::EndPage |
fb46a9a6 DW |
2213 | |
2214 | // --------------------------------------------------------------------------- | |
2215 | // text metrics | |
2216 | // --------------------------------------------------------------------------- | |
2217 | ||
7cdc2f1e | 2218 | wxCoord wxDC::GetCharHeight() const |
fb46a9a6 | 2219 | { |
05a8bfed DW |
2220 | FONTMETRICS vFM; // metrics structure |
2221 | ||
2222 | ::GpiQueryFontMetrics( m_hPS | |
2223 | ,sizeof(FONTMETRICS) | |
2224 | ,&vFM | |
2225 | ); | |
2226 | return YDEV2LOGREL(vFM.lXHeight); | |
fb46a9a6 DW |
2227 | } |
2228 | ||
7cdc2f1e | 2229 | wxCoord wxDC::GetCharWidth() const |
fb46a9a6 | 2230 | { |
05a8bfed DW |
2231 | FONTMETRICS vFM; // metrics structure |
2232 | ||
2233 | ::GpiQueryFontMetrics( m_hPS | |
2234 | ,sizeof(FONTMETRICS) | |
2235 | ,&vFM | |
2236 | ); | |
2237 | return XDEV2LOGREL(vFM.lAveCharWidth); | |
7e99520b DW |
2238 | } |
2239 | ||
2240 | void wxDC::DoGetTextExtent( | |
2241 | const wxString& rsString | |
2242 | , wxCoord* pvX | |
2243 | , wxCoord* pvY | |
f44fdfb0 | 2244 | , wxCoord* pvDescent |
7e99520b DW |
2245 | , wxCoord* pvExternalLeading |
2246 | , wxFont* pTheFont | |
2247 | ) const | |
2248 | { | |
2249 | POINTL avPoint[TXTBOX_COUNT]; | |
2250 | POINTL vPtMin; | |
2251 | POINTL vPtMax; | |
2252 | int i; | |
2253 | int l; | |
2254 | FONTMETRICS vFM; // metrics structure | |
2255 | BOOL bRc; | |
2256 | char* pStr; | |
2257 | ERRORID vErrorCode; // last error id code | |
2258 | wxFont* pFontToUse = (wxFont*)pTheFont; | |
2259 | ||
2c4a8d17 DW |
2260 | char zMsg[128]; // DEBUG |
2261 | wxString sError; | |
2262 | ||
7e99520b DW |
2263 | if (!pFontToUse) |
2264 | pFontToUse = (wxFont*)&m_font; | |
2265 | l = rsString.length(); | |
2266 | pStr = (PCH) rsString.c_str(); | |
fb46a9a6 | 2267 | |
7e99520b DW |
2268 | // |
2269 | // In world coordinates. | |
2270 | // | |
2271 | bRc = ::GpiQueryTextBox( m_hPS | |
2272 | ,l | |
2273 | ,pStr | |
2274 | ,TXTBOX_COUNT // return maximum information | |
2275 | ,avPoint // array of coordinates points | |
f44fdfb0 | 2276 | ); |
7e99520b DW |
2277 | if(!bRc) |
2278 | { | |
2279 | vErrorCode = ::WinGetLastError(wxGetInstance()); | |
2c4a8d17 DW |
2280 | sError = wxPMErrorToStr(vErrorCode); |
2281 | // DEBUG | |
2282 | sprintf(zMsg, "GpiQueryTextBox for %s: failed with Error: %x - %s", pStr, vErrorCode, sError.c_str()); | |
2283 | (void)wxMessageBox( "wxWindows Menu sample" | |
2284 | ,zMsg | |
2285 | ,wxICON_INFORMATION | |
2286 | ); | |
7e99520b DW |
2287 | } |
2288 | ||
2289 | vPtMin.x = avPoint[0].x; | |
2290 | vPtMax.x = avPoint[0].x; | |
2291 | vPtMin.y = avPoint[0].y; | |
2292 | vPtMax.y = avPoint[0].y; | |
2293 | for (i = 1; i < 4; i++) | |
2294 | { | |
2295 | if(vPtMin.x > avPoint[i].x) vPtMin.x = avPoint[i].x; | |
2296 | if(vPtMin.y > avPoint[i].y) vPtMin.y = avPoint[i].y; | |
2297 | if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x; | |
2298 | if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y; | |
2299 | } | |
2300 | ::GpiQueryFontMetrics( m_hPS | |
2301 | ,sizeof(FONTMETRICS) | |
2302 | ,&vFM | |
2303 | ); | |
2304 | ||
2305 | if (pvX) | |
2306 | *pvX = (wxCoord)(vPtMax.x - vPtMin.x + 1); | |
2307 | if (pvY) | |
2308 | *pvY = (wxCoord)(vPtMax.y - vPtMin.y + 1); | |
2309 | if (pvDescent) | |
2310 | *pvDescent = vFM.lMaxDescender; | |
f44fdfb0 | 2311 | if (pvExternalLeading) |
7e99520b | 2312 | *pvExternalLeading = vFM.lExternalLeading; |
fb46a9a6 DW |
2313 | } |
2314 | ||
5fd2b2c6 DW |
2315 | void wxDC::SetMapMode( |
2316 | int nMode | |
2317 | ) | |
fb46a9a6 | 2318 | { |
5fd2b2c6 DW |
2319 | int nPixelWidth = 0; |
2320 | int nPixelHeight = 0; | |
2321 | int nMmWidth = 1; | |
2322 | int nMmHeight = 1; | |
2323 | LONG lArray[CAPS_VERTICAL_RESOLUTION]; | |
fb46a9a6 | 2324 | |
5fd2b2c6 DW |
2325 | m_mappingMode = nMode; |
2326 | ||
2327 | if(::DevQueryCaps( m_hDC | |
2328 | ,CAPS_FAMILY | |
2329 | ,CAPS_VERTICAL_RESOLUTION | |
2330 | ,lArray | |
2331 | )) | |
2332 | { | |
2333 | LONG lHorzRes; | |
2334 | LONG lVertRes; | |
2335 | ||
2336 | nPixelWidth = lArray[CAPS_WIDTH]; | |
2337 | nPixelHeight = lArray[CAPS_HEIGHT]; | |
2338 | lHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter | |
2339 | lVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter | |
2340 | nMmWidth = (lHorzRes/1000) * nPixelWidth; | |
2341 | nMmWidth = (lVertRes/1000) * nPixelHeight; | |
2342 | } | |
2343 | if ((nPixelWidth == 0) || (nPixelHeight == 0) || (nMmWidth == 0) || (nMmHeight == 0)) | |
2344 | { | |
2345 | return; | |
2346 | } | |
2347 | ||
2348 | double dMm2pixelsX = nPixelWidth/nMmWidth; | |
2349 | double dMm2pixelsY = nPixelHeight/nMmHeight; | |
2350 | ||
2351 | switch (nMode) | |
2352 | { | |
2353 | case wxMM_TWIPS: | |
2354 | m_logicalScaleX = (twips2mm * dMm2pixelsX); | |
2355 | m_logicalScaleY = (twips2mm * dMm2pixelsY); | |
2356 | break; | |
2357 | ||
2358 | case wxMM_POINTS: | |
2359 | m_logicalScaleX = (pt2mm * dMm2pixelsX); | |
2360 | m_logicalScaleY = (pt2mm * dMm2pixelsY); | |
2361 | break; | |
2362 | ||
2363 | case wxMM_METRIC: | |
2364 | m_logicalScaleX = dMm2pixelsX; | |
2365 | m_logicalScaleY = dMm2pixelsY; | |
2366 | break; | |
2367 | ||
2368 | case wxMM_LOMETRIC: | |
2369 | m_logicalScaleX = (dMm2pixelsX/10.0); | |
2370 | m_logicalScaleY = (dMm2pixelsY/10.0); | |
2371 | break; | |
2372 | ||
2373 | case wxMM_TEXT: | |
2374 | default: | |
2375 | m_logicalScaleX = 1.0; | |
2376 | m_logicalScaleY = 1.0; | |
2377 | break; | |
2378 | } | |
2379 | SIZEL vSize; | |
2380 | ULONG ulOptions; | |
2381 | ||
2382 | ulOptions = ::GpiQueryPS(m_hPS, &vSize); | |
2383 | if (!ulOptions & PU_ARBITRARY) | |
2384 | { | |
2385 | ulOptions = PU_ARBITRARY | GPIF_DEFAULT; | |
2386 | ::GpiSetPS(m_hPS, &vSize, ulOptions); | |
2387 | } | |
74de9ed6 GD |
2388 | m_nWindowExtX = (int)MS_XDEV2LOG(VIEWPORT_EXTENT); |
2389 | m_nWindowExtY = (int)MS_YDEV2LOG(VIEWPORT_EXTENT); | |
5fd2b2c6 DW |
2390 | // ???? |
2391 | }; // end of wxDC::SetMapMode | |
2392 | ||
2393 | void wxDC::SetUserScale( | |
2394 | double dX | |
2395 | , double dY | |
2396 | ) | |
fb46a9a6 | 2397 | { |
5fd2b2c6 DW |
2398 | m_userScaleX = dX; |
2399 | m_userScaleY = dY; | |
fb46a9a6 DW |
2400 | |
2401 | SetMapMode(m_mappingMode); | |
5fd2b2c6 | 2402 | } // end of wxDC::SetUserScale |
fb46a9a6 | 2403 | |
5fd2b2c6 DW |
2404 | void wxDC::SetAxisOrientation( |
2405 | bool bXLeftRight | |
2406 | , bool bYBottomUp | |
2407 | ) | |
fb46a9a6 | 2408 | { |
5fd2b2c6 DW |
2409 | m_signX = bXLeftRight ? 1 : -1; |
2410 | m_signY = bYBottomUp ? -1 : 1; | |
fb46a9a6 DW |
2411 | |
2412 | SetMapMode(m_mappingMode); | |
5fd2b2c6 | 2413 | } // end of wxDC::SetAxisOrientation |
fb46a9a6 | 2414 | |
5fd2b2c6 DW |
2415 | void wxDC::SetSystemScale( |
2416 | double dX | |
2417 | , double dY | |
2418 | ) | |
fb46a9a6 | 2419 | { |
5fd2b2c6 DW |
2420 | m_scaleX = dX; |
2421 | m_scaleY = dY; | |
fb46a9a6 DW |
2422 | |
2423 | SetMapMode(m_mappingMode); | |
5fd2b2c6 | 2424 | } // end of wxDC::SetSystemScale |
fb46a9a6 | 2425 | |
5fd2b2c6 DW |
2426 | void wxDC::SetLogicalOrigin( |
2427 | wxCoord vX | |
2428 | , wxCoord vY | |
2429 | ) | |
fb46a9a6 | 2430 | { |
5fd2b2c6 DW |
2431 | RECTL vRect; |
2432 | ||
2433 | ::GpiQueryPageViewport( m_hPS | |
2434 | ,&vRect | |
2435 | ); | |
2436 | vRect.xRight -= vX; | |
2437 | vRect.yTop += vY; | |
2438 | vRect.xLeft = vX; | |
2439 | vRect.yBottom = vY; | |
2440 | ::GpiSetPageViewport( m_hPS | |
2441 | ,&vRect | |
2442 | ); | |
2443 | }; // end of wxDC::SetLogicalOrigin | |
fb46a9a6 | 2444 | |
8d854fa9 | 2445 | void wxDC::SetDeviceOrigin( |
5fd2b2c6 DW |
2446 | wxCoord vX |
2447 | , wxCoord vY | |
8d854fa9 | 2448 | ) |
fb46a9a6 | 2449 | { |
26ac77db DW |
2450 | RECTL vRect; |
2451 | ||
5fd2b2c6 DW |
2452 | m_deviceOriginX = vX; |
2453 | m_deviceOriginY = vY; | |
26ac77db DW |
2454 | ::GpiQueryPageViewport( m_hPS |
2455 | ,&vRect | |
2456 | ); | |
5fd2b2c6 DW |
2457 | vRect.xLeft += vX; |
2458 | vRect.xRight += vX; | |
2459 | vRect.yBottom -= vY; | |
2460 | vRect.yTop -= vY; | |
26ac77db DW |
2461 | ::GpiSetPageViewport( m_hPS |
2462 | ,&vRect | |
2463 | ); | |
5fd2b2c6 | 2464 | }; // end of wxDC::SetDeviceOrigin |
fb46a9a6 DW |
2465 | |
2466 | // --------------------------------------------------------------------------- | |
2467 | // coordinates transformations | |
2468 | // --------------------------------------------------------------------------- | |
2469 | ||
7cdc2f1e | 2470 | wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const |
fb46a9a6 | 2471 | { |
f6bcfd97 BP |
2472 | return (wxCoord) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX); |
2473 | } | |
fb46a9a6 | 2474 | |
7cdc2f1e | 2475 | wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const |
fb46a9a6 | 2476 | { |
74de9ed6 GD |
2477 | // axis orientation is not taken into account for conversion of a distance |
2478 | return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_scaleX)); | |
f6bcfd97 | 2479 | } |
fb46a9a6 | 2480 | |
7cdc2f1e | 2481 | wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const |
fb46a9a6 | 2482 | { |
f6bcfd97 BP |
2483 | return (wxCoord) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY); |
2484 | } | |
fb46a9a6 | 2485 | |
7cdc2f1e | 2486 | wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const |
fb46a9a6 | 2487 | { |
74de9ed6 GD |
2488 | // axis orientation is not taken into account for conversion of a distance |
2489 | return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_scaleY)); | |
f6bcfd97 | 2490 | } |
fb46a9a6 | 2491 | |
7cdc2f1e | 2492 | wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const |
fb46a9a6 | 2493 | { |
f6bcfd97 BP |
2494 | return (wxCoord) ((x - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX); |
2495 | } | |
fb46a9a6 | 2496 | |
7cdc2f1e | 2497 | wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const |
fb46a9a6 | 2498 | { |
74de9ed6 GD |
2499 | // axis orientation is not taken into account for conversion of a distance |
2500 | return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_scaleX); | |
f6bcfd97 | 2501 | } |
fb46a9a6 | 2502 | |
7cdc2f1e | 2503 | wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const |
fb46a9a6 | 2504 | { |
f6bcfd97 BP |
2505 | return (wxCoord) ((y - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY); |
2506 | } | |
fb46a9a6 | 2507 | |
7cdc2f1e | 2508 | wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const |
fb46a9a6 | 2509 | { |
74de9ed6 GD |
2510 | // axis orientation is not taken into account for conversion of a distance |
2511 | return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_scaleY); | |
f6bcfd97 | 2512 | } |
fb46a9a6 DW |
2513 | |
2514 | // --------------------------------------------------------------------------- | |
2515 | // bit blit | |
2516 | // --------------------------------------------------------------------------- | |
2517 | ||
5afb9458 DW |
2518 | bool wxDC::DoBlit( |
2519 | wxCoord vXdest | |
2520 | , wxCoord vYdest | |
2521 | , wxCoord vWidth | |
2522 | , wxCoord vHeight | |
2523 | , wxDC* pSource | |
2524 | , wxCoord vXsrc | |
2525 | , wxCoord vYsrc | |
2526 | , int nRop | |
2527 | , bool bUseMask | |
893758d5 DW |
2528 | , wxCoord vXsrcMask |
2529 | , wxCoord vYsrcMask | |
5afb9458 | 2530 | ) |
fb46a9a6 | 2531 | { |
5afb9458 DW |
2532 | wxMask* pMask = NULL; |
2533 | CHARBUNDLE vCbnd; | |
2534 | COLORREF vOldTextColor; | |
2535 | COLORREF vOldBackground = ::GpiQueryBackColor(m_hPS); | |
5afb9458 DW |
2536 | |
2537 | if (bUseMask) | |
2538 | { | |
2539 | const wxBitmap& rBmp = pSource->m_vSelectedBitmap; | |
2540 | ||
2541 | pMask = rBmp.GetMask(); | |
2542 | if (!(rBmp.Ok() && pMask && pMask->GetMaskBitmap())) | |
2543 | { | |
2544 | bUseMask = FALSE; | |
2545 | } | |
2546 | } | |
2547 | ||
2548 | ::GpiQueryAttrs( m_hPS | |
2549 | ,PRIM_CHAR | |
2550 | ,CBB_COLOR | |
2551 | ,&vCbnd | |
2552 | ); | |
2553 | vOldTextColor = (COLORREF)vCbnd.lColor; | |
2554 | ||
2555 | if (m_textForegroundColour.Ok()) | |
2556 | { | |
2557 | vCbnd.lColor = (LONG)m_textForegroundColour.GetPixel(); | |
2558 | ::GpiSetAttrs( m_hPS // presentation-space handle | |
2559 | ,PRIM_CHAR // Char primitive. | |
2560 | ,CBB_COLOR // sets color. | |
2561 | ,0 | |
2562 | ,&vCbnd // buffer for attributes. | |
2563 | ); | |
2564 | } | |
2565 | if (m_textBackgroundColour.Ok()) | |
2566 | { | |
2567 | ::GpiSetBackColor(m_hPS, (LONG)m_textBackgroundColour.GetPixel()); | |
2568 | } | |
2569 | ||
2570 | LONG lRop = ROP_SRCCOPY; | |
2571 | ||
2572 | switch (nRop) | |
2573 | { | |
2574 | case wxXOR: lRop = ROP_SRCINVERT; break; | |
2575 | case wxINVERT: lRop = ROP_DSTINVERT; break; | |
2576 | case wxOR_REVERSE: lRop = 0x00DD0228; break; | |
2577 | case wxAND_REVERSE: lRop = ROP_SRCERASE; break; | |
2578 | case wxCLEAR: lRop = ROP_ZERO; break; | |
2579 | case wxSET: lRop = ROP_ONE; break; | |
2580 | case wxOR_INVERT: lRop = ROP_MERGEPAINT; break; | |
2581 | case wxAND: lRop = ROP_SRCAND; break; | |
2582 | case wxOR: lRop = ROP_SRCPAINT; break; | |
2583 | case wxEQUIV: lRop = 0x00990066; break; | |
2584 | case wxNAND: lRop = 0x007700E6; break; | |
2585 | case wxAND_INVERT: lRop = 0x00220326; break; | |
2586 | case wxCOPY: lRop = ROP_SRCCOPY; break; | |
2587 | case wxNO_OP: lRop = ROP_NOTSRCERASE; break; | |
2588 | case wxSRC_INVERT: lRop = ROP_SRCINVERT; break; | |
2589 | case wxNOR: lRop = ROP_NOTSRCCOPY; break; | |
2590 | default: | |
2591 | wxFAIL_MSG( wxT("unsupported logical function") ); | |
2592 | return FALSE; | |
2593 | } | |
2594 | ||
2595 | bool bSuccess; | |
b02121c3 | 2596 | |
5afb9458 DW |
2597 | if (bUseMask) |
2598 | { | |
2599 | // | |
2600 | // Blit bitmap with mask | |
2601 | // | |
2602 | ||
2603 | // | |
b02121c3 | 2604 | // Create a temp buffer bitmap and DCs/PSs to access it and the mask |
5afb9458 | 2605 | // |
b02121c3 DW |
2606 | HDC hDCMask; |
2607 | HDC hDCBuffer; | |
2608 | HPS hPSMask; | |
2609 | HPS hPSBuffer; | |
2610 | DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L}; | |
2611 | BITMAPINFOHEADER2 vBmpHdr; | |
893758d5 | 2612 | HBITMAP hBufBitmap; |
b02121c3 DW |
2613 | SIZEL vSize = {0, 0}; |
2614 | LONG rc; | |
2615 | ||
b02121c3 DW |
2616 | memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2)); |
2617 | vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2); | |
2618 | vBmpHdr.cx = vWidth; | |
2619 | vBmpHdr.cy = vHeight; | |
2620 | vBmpHdr.cPlanes = 1; | |
2621 | vBmpHdr.cBitCount = 24; | |
2622 | ||
893758d5 DW |
2623 | #if wxUSE_DC_CACHEING |
2624 | if (TRUE) | |
2625 | { | |
2626 | // | |
2627 | // create a temp buffer bitmap and DCs to access it and the mask | |
2628 | // | |
2629 | wxDCCacheEntry* pDCCacheEntry1 = FindDCInCache( NULL | |
2630 | ,pSource->GetHPS() | |
2631 | ); | |
2632 | wxDCCacheEntry* pDCCacheEntry2 = FindDCInCache( pDCCacheEntry1 | |
2633 | ,GetHPS() | |
2634 | ); | |
2635 | wxDCCacheEntry* pBitmapCacheEntry = FindBitmapInCache( GetHPS() | |
2636 | ,vWidth | |
2637 | ,vHeight | |
2638 | ); | |
2639 | ||
2640 | hPSMask = pDCCacheEntry1->m_hPS; | |
2641 | hDCBuffer = (HDC)pDCCacheEntry2->m_hPS; | |
2642 | hBufBitmap = (HBITMAP)pBitmapCacheEntry->m_hBitmap; | |
2643 | } | |
2644 | else | |
2645 | #endif | |
2646 | { | |
2647 | hDCMask = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE); | |
2648 | hDCBuffer = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE); | |
2649 | hPSMask = ::GpiCreatePS(vHabmain, hDCMask, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC); | |
2650 | hPSBuffer = ::GpiCreatePS(vHabmain, hDCBuffer, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC); | |
2651 | hBufBitmap = ::GpiCreateBitmap(GetHPS(), &vBmpHdr, 0L, NULL, NULL); | |
2652 | } | |
2653 | ||
b02121c3 DW |
2654 | POINTL aPoint1[4] = { 0, 0 |
2655 | ,vWidth, vHeight | |
2656 | ,vXdest, vYdest | |
2657 | ,vXdest + vWidth, vYdest + vHeight | |
2658 | }; | |
2659 | POINTL aPoint2[4] = { 0, 0 | |
2660 | ,vWidth, vHeight | |
2661 | ,vXsrc, vYsrc | |
2662 | ,vXsrc + vWidth, vYsrc + vHeight | |
2663 | }; | |
2664 | POINTL aPoint3[4] = { vXdest, vYdest | |
23e356de DW |
2665 | ,vXdest + vWidth, vYdest + vHeight |
2666 | ,vXsrc, vYsrc | |
2667 | ,vXsrc + vWidth, vYsrc + vHeight | |
2668 | }; | |
2669 | POINTL aPoint4[4] = { vXdest, vYdest | |
b02121c3 DW |
2670 | ,vXdest + vWidth, vYdest + vHeight |
2671 | ,0, 0 | |
2672 | ,vWidth, vHeight | |
2673 | }; | |
2674 | ::GpiSetBitmap(hPSMask, (HBITMAP) pMask->GetMaskBitmap()); | |
2675 | ::GpiSetBitmap(hPSBuffer, (HBITMAP) hBufBitmap); | |
5afb9458 | 2676 | |
b02121c3 DW |
2677 | // |
2678 | // Copy dest to buffer | |
2679 | // | |
2680 | rc = ::GpiBitBlt( hPSBuffer | |
2681 | ,GetHPS() | |
2682 | ,4L | |
2683 | ,aPoint1 | |
2684 | ,ROP_SRCCOPY | |
2685 | ,BBO_IGNORE | |
2686 | ); | |
2687 | if (rc == GPI_ERROR) | |
2688 | { | |
2689 | wxLogLastError(wxT("BitBlt")); | |
2690 | } | |
5afb9458 | 2691 | |
b02121c3 DW |
2692 | // |
2693 | // Copy src to buffer using selected raster op | |
2694 | // | |
2695 | rc = ::GpiBitBlt( hPSBuffer | |
2696 | ,GetHPS() | |
2697 | ,4L | |
2698 | ,aPoint2 | |
2699 | ,lRop | |
2700 | ,BBO_IGNORE | |
2701 | ); | |
2702 | if (rc == GPI_ERROR) | |
2703 | { | |
2704 | wxLogLastError(wxT("BitBlt")); | |
2705 | } | |
5afb9458 | 2706 | |
b02121c3 DW |
2707 | // |
2708 | // Set masked area in buffer to BLACK (pixel value 0) | |
2709 | // | |
2710 | COLORREF vPrevBkCol = ::GpiQueryBackColor(GetHPS()); | |
2711 | COLORREF vPrevCol = ::GpiQueryColor(GetHPS()); | |
2712 | ||
2713 | ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255)); | |
2714 | ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0)); | |
2715 | ||
2716 | rc = ::GpiBitBlt( hPSBuffer | |
2717 | ,hPSMask | |
2718 | ,4L | |
2719 | ,aPoint2 | |
2720 | ,ROP_SRCAND | |
2721 | ,BBO_IGNORE | |
2722 | ); | |
2723 | if (rc == GPI_ERROR) | |
2724 | { | |
2725 | wxLogLastError(wxT("BitBlt")); | |
2726 | } | |
5afb9458 | 2727 | |
b02121c3 DW |
2728 | // |
2729 | // Set unmasked area in dest to BLACK | |
2730 | // | |
2731 | ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0)); | |
2732 | ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255)); | |
2733 | rc = ::GpiBitBlt( GetHPS() | |
2734 | ,hPSMask | |
2735 | ,4L | |
23e356de | 2736 | ,aPoint3 |
b02121c3 DW |
2737 | ,ROP_SRCAND |
2738 | ,BBO_IGNORE | |
2739 | ); | |
2740 | if (rc == GPI_ERROR) | |
2741 | { | |
2742 | wxLogLastError(wxT("BitBlt")); | |
5afb9458 | 2743 | } |
b02121c3 DW |
2744 | |
2745 | // | |
2746 | // Restore colours to original values | |
2747 | // | |
2748 | ::GpiSetBackColor(GetHPS(), vPrevBkCol); | |
2749 | ::GpiSetColor(GetHPS(), vPrevCol); | |
2750 | ||
2751 | // | |
2752 | // OR buffer to dest | |
2753 | // | |
2754 | rc = ::GpiBitBlt( GetHPS() | |
2755 | ,hPSMask | |
2756 | ,4L | |
23e356de | 2757 | ,aPoint4 |
b02121c3 DW |
2758 | ,ROP_SRCPAINT |
2759 | ,BBO_IGNORE | |
2760 | ); | |
2761 | if (rc == GPI_ERROR) | |
2762 | { | |
2763 | bSuccess = FALSE; | |
2764 | wxLogLastError(wxT("BitBlt")); | |
2765 | } | |
2766 | ||
2767 | // | |
2768 | // Tidy up temporary DCs and bitmap | |
2769 | // | |
2770 | ::GpiSetBitmap(hPSMask, NULLHANDLE); | |
2771 | ::GpiSetBitmap(hPSBuffer, NULLHANDLE); | |
893758d5 | 2772 | #if !wxUSE_DC_CACHEING |
b02121c3 DW |
2773 | ::GpiDestroyPS(hPSMask); |
2774 | ::GpiDestroyPS(hPSBuffer); | |
2775 | ::DevCloseDC(hDCMask); | |
2776 | ::DevCloseDC(hDCBuffer); | |
2777 | ::GpiDeleteBitmap(hBufBitmap); | |
893758d5 | 2778 | #endif |
b02121c3 | 2779 | bSuccess = TRUE; |
5afb9458 | 2780 | } |
b02121c3 DW |
2781 | else // no mask, just BitBlt() it |
2782 | { | |
2783 | POINTL aPoint[4] = { vXdest, vYdest | |
2784 | ,vXdest + vWidth, vYdest + vHeight | |
2785 | ,vXsrc, vYsrc | |
2786 | ,vXsrc + vWidth, vYsrc + vHeight | |
2787 | }; | |
2788 | ||
5afb9458 DW |
2789 | bSuccess = (::GpiBitBlt( m_hPS |
2790 | ,pSource->GetHPS() | |
2791 | ,4L | |
2792 | ,aPoint | |
2793 | ,lRop | |
2794 | ,BBO_IGNORE | |
2795 | ) != GPI_ERROR); | |
2796 | if (!bSuccess ) | |
2797 | { | |
2798 | wxLogLastError(wxT("BitBlt")); | |
2799 | } | |
b02121c3 | 2800 | } |
5afb9458 DW |
2801 | vCbnd.lColor = (LONG)vOldTextColor; |
2802 | ::GpiSetAttrs( m_hPS // presentation-space handle | |
2803 | ,PRIM_CHAR // Char primitive. | |
2804 | ,CBB_COLOR // sets color. | |
2805 | ,0 | |
2806 | ,&vCbnd // buffer for attributes. | |
2807 | ); | |
2808 | ::GpiSetBackColor(m_hPS, (LONG)vOldBackground); | |
2809 | return bSuccess; | |
fb46a9a6 DW |
2810 | } |
2811 | ||
5fd2b2c6 DW |
2812 | void wxDC::DoGetSize( |
2813 | int* pnWidth | |
2814 | , int* pnHeight | |
2815 | ) const | |
fb46a9a6 | 2816 | { |
5fd2b2c6 DW |
2817 | LONG lArray[CAPS_HEIGHT]; |
2818 | ||
2819 | if(::DevQueryCaps( m_hDC | |
2820 | ,CAPS_FAMILY | |
2821 | ,CAPS_HEIGHT | |
2822 | ,lArray | |
2823 | )) | |
2824 | { | |
2825 | *pnWidth = lArray[CAPS_WIDTH]; | |
2826 | *pnHeight = lArray[CAPS_HEIGHT]; | |
2827 | } | |
2828 | }; // end of wxDC::DoGetSize( | |
fb46a9a6 | 2829 | |
5fd2b2c6 DW |
2830 | void wxDC::DoGetSizeMM( |
2831 | int* pnWidth | |
2832 | , int* pnHeight | |
2833 | ) const | |
fb46a9a6 | 2834 | { |
5fd2b2c6 DW |
2835 | LONG lArray[CAPS_VERTICAL_RESOLUTION]; |
2836 | ||
2837 | if(::DevQueryCaps( m_hDC | |
2838 | ,CAPS_FAMILY | |
2839 | ,CAPS_VERTICAL_RESOLUTION | |
2840 | ,lArray | |
2841 | )) | |
2842 | { | |
2843 | int nWidth; | |
2844 | int nHeight; | |
2845 | int nHorzRes; | |
2846 | int nVertRes; | |
2847 | ||
2848 | nWidth = lArray[CAPS_WIDTH]; | |
2849 | nHeight = lArray[CAPS_HEIGHT]; | |
2850 | nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter | |
2851 | nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter | |
2852 | nWidth = (nHorzRes/1000) * nWidth; | |
2853 | nHeight = (nVertRes/1000) * nHeight; | |
2854 | } | |
2855 | }; // end of wxDC::DoGetSizeMM | |
fb46a9a6 DW |
2856 | |
2857 | wxSize wxDC::GetPPI() const | |
2858 | { | |
5fd2b2c6 DW |
2859 | LONG lArray[CAPS_VERTICAL_RESOLUTION]; |
2860 | int nWidth; | |
2861 | int nHeight; | |
fb46a9a6 | 2862 | |
5fd2b2c6 DW |
2863 | if(::DevQueryCaps( m_hDC |
2864 | ,CAPS_FAMILY | |
2865 | ,CAPS_VERTICAL_RESOLUTION | |
2866 | ,lArray | |
2867 | )) | |
2868 | { | |
2869 | int nPelWidth; | |
2870 | int nPelHeight; | |
2871 | int nHorzRes; | |
2872 | int nVertRes; | |
2873 | ||
2874 | nPelWidth = lArray[CAPS_WIDTH]; | |
2875 | nPelHeight = lArray[CAPS_HEIGHT]; | |
2876 | nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter | |
2877 | nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter | |
2878 | nWidth = (nHorzRes/39.3) * nPelWidth; | |
2879 | nHeight = (nVertRes/39.3) * nPelHeight; | |
2880 | } | |
2881 | return (wxSize(nWidth,nHeight)); | |
2882 | } // end of wxDC::GetPPI | |
2883 | ||
2884 | void wxDC::SetLogicalScale( | |
2885 | double dX | |
2886 | , double dY | |
2887 | ) | |
fb46a9a6 | 2888 | { |
5fd2b2c6 DW |
2889 | m_logicalScaleX = dX; |
2890 | m_logicalScaleY = dY; | |
2891 | }; // end of wxDC::SetLogicalScale | |
fb46a9a6 DW |
2892 | |
2893 | #if WXWIN_COMPATIBILITY | |
2894 | void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y, | |
2895 | float *descent, float *externalLeading, | |
2896 | wxFont *theFont, bool use16bit) const | |
2897 | { | |
7cdc2f1e | 2898 | wxCoord x1, y1, descent1, externalLeading1; |
fb46a9a6 DW |
2899 | GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit); |
2900 | *x = x1; *y = y1; | |
2901 | if (descent) | |
2902 | *descent = descent1; | |
2903 | if (externalLeading) | |
2904 | *externalLeading = externalLeading1; | |
2905 | } | |
2906 | #endif | |
2907 |