]>
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 | } | |
7e99520b | 675 | vPoint[0].x = vX1; |
5fd2b2c6 | 676 | vPoint[0].y = vY1; |
7e99520b | 677 | vPoint[1].x = vX2; |
5fd2b2c6 | 678 | vPoint[1].y = vY2; |
d6d749aa DW |
679 | if (m_pen.Ok()) |
680 | { | |
681 | vColor = m_pen.GetColour().GetPixel(); | |
682 | } | |
683 | ::GpiSetColor(m_hPS, vColor); | |
7e99520b DW |
684 | ::GpiMove(m_hPS, &vPoint[0]); |
685 | ::GpiLine(m_hPS, &vPoint[1]); | |
5fd2b2c6 DW |
686 | CalcBoundingBox(vX1, vY1); |
687 | CalcBoundingBox(vX2, vY2); | |
f07bb01b | 688 | } // end of wxDC::DoDrawLine |
1408104d | 689 | |
51c1d535 DW |
690 | ////////////////////////////////////////////////////////////////////////////// |
691 | // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1) | |
692 | // and ending at (x2, y2). The current pen is used for the outline and the | |
693 | // current brush for filling the shape. The arc is drawn in an anticlockwise | |
694 | // direction from the start point to the end point. | |
695 | ////////////////////////////////////////////////////////////////////////////// | |
696 | void wxDC::DoDrawArc( | |
697 | wxCoord vX1 | |
698 | , wxCoord vY1 | |
699 | , wxCoord vX2 | |
700 | , wxCoord vY2 | |
701 | , wxCoord vXc | |
702 | , wxCoord vYc | |
703 | ) | |
1408104d | 704 | { |
51c1d535 DW |
705 | POINTL vPtlPos; |
706 | POINTL vPtlArc[2]; // Structure for current position | |
707 | int nDx; | |
708 | int nDy; | |
709 | double dRadius; | |
710 | double dAngl1; | |
711 | double dAngl2; | |
712 | double dAnglmid; | |
713 | wxCoord vXm; | |
714 | wxCoord vYm; | |
715 | ARCPARAMS vArcp; // Structure for arc parameters | |
716 | ||
717 | if((vX1 == vXc && vY1 == vXc) || (vX2 == vXc && vY2 == vXc)) | |
718 | return; // Draw point ?? | |
719 | dRadius = 0.5 * ( hypot( (double)(vY1 - vYc) | |
720 | ,(double)(vX1 - vXc) | |
721 | ) + | |
722 | hypot( (double)(vY2 - vYc) | |
723 | ,(double)(vX2 - vXc) | |
724 | ) | |
725 | ); | |
726 | ||
727 | dAngl1 = atan2( (double)(vY1 - vYc) | |
728 | ,(double)(vX1 - vXc) | |
729 | ); | |
730 | dAngl2 = atan2( (double)(vY2 - vYc) | |
731 | ,(double)(vX2 - vXc) | |
732 | ); | |
733 | if(dAngl2 < dAngl1) | |
734 | dAngl2 += M_PI * 2; | |
735 | ||
736 | // | |
737 | // GpiPointArc can't draw full arc | |
738 | // | |
739 | if(dAngl2 == dAngl1 || (vX1 == vX2 && vY1 == vY2) ) | |
740 | { | |
741 | // | |
742 | // Medium point | |
743 | // | |
744 | dAnglmid = (dAngl1 + dAngl2)/2. + M_PI; | |
745 | vXm = vXc + dRadius * cos(dAnglmid); | |
746 | vYm = vYc + dRadius * sin(dAnglmid); | |
e99762c0 DW |
747 | DoDrawArc( vX1, vY1 |
748 | ,vXm, vYm | |
749 | ,vXc, vYc | |
51c1d535 | 750 | ); |
e99762c0 DW |
751 | DoDrawArc( vXm, vYm |
752 | ,vX2, vY2 | |
753 | ,vXc, vYc | |
51c1d535 DW |
754 | ); |
755 | return; | |
756 | } | |
757 | ||
758 | // | |
759 | // Medium point | |
760 | // | |
761 | dAnglmid = (dAngl1 + dAngl2)/2.; | |
762 | vXm = vXc + dRadius * cos(dAnglmid); | |
763 | vYm = vYc + dRadius * sin(dAnglmid); | |
764 | ||
765 | // | |
766 | // Ellipse main axis (r,q), (p,s) with center at (0,0) */ | |
767 | // | |
768 | vArcp.lR = 0; | |
769 | vArcp.lQ = 1; | |
770 | vArcp.lP = 1; | |
771 | vArcp.lS = 0; | |
772 | ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default | |
773 | ||
774 | vPtlPos.x = vX1; // Loads x-coordinate | |
775 | vPtlPos.y = vY1; // Loads y-coordinate | |
776 | ::GpiMove(m_hPS, &vPtlPos); // Sets current position | |
e99762c0 DW |
777 | vPtlArc[0].x = vXm; |
778 | vPtlArc[0].y = vYm; | |
51c1d535 DW |
779 | vPtlArc[1].x = vX2; |
780 | vPtlArc[1].y = vY2; | |
781 | ::GpiPointArc(m_hPS, vPtlArc); // Draws the arc | |
5fd2b2c6 DW |
782 | CalcBoundingBox( (vXc - dRadius) |
783 | ,(vYc - dRadius) | |
784 | ); | |
785 | CalcBoundingBox( (vXc + dRadius) | |
786 | ,(vYc + dRadius) | |
787 | ); | |
f07bb01b | 788 | } // end of wxDC::DoDrawArc |
1408104d | 789 | |
51c1d535 DW |
790 | void wxDC::DoDrawCheckMark( |
791 | wxCoord vX1 | |
792 | , wxCoord vY1 | |
793 | , wxCoord vWidth | |
794 | , wxCoord vHeight | |
795 | ) | |
f6bcfd97 | 796 | { |
51c1d535 DW |
797 | POINTL vPoint[2]; |
798 | ||
5fd2b2c6 DW |
799 | vY1 = OS2Y(vY1,vHeight); |
800 | ||
51c1d535 DW |
801 | vPoint[0].x = vX1; |
802 | vPoint[0].y = vY1; | |
803 | vPoint[1].x = vX1 + vWidth; | |
804 | vPoint[1].y = vY1 + vHeight; | |
805 | ||
806 | ::GpiMove(m_hPS, &vPoint[0]); | |
807 | ::GpiBox( m_hPS // handle to a presentation space | |
808 | ,DRO_OUTLINE // draw the box outline ? or ? | |
809 | ,&vPoint[1] // address of the corner | |
810 | ,0L // horizontal corner radius | |
811 | ,0L // vertical corner radius | |
812 | ); | |
813 | if(vWidth > 4 && vHeight > 4) | |
814 | { | |
815 | int nTmp; | |
816 | ||
817 | vPoint[0].x += 2; vPoint[0].y += 2; | |
818 | vPoint[1].x -= 2; vPoint[1].y -= 2; | |
819 | ::GpiMove(m_hPS, &vPoint[0]); | |
820 | ::GpiLine(m_hPS, &vPoint[1]); | |
821 | nTmp = vPoint[0].x; | |
822 | vPoint[0].x = vPoint[1].x; | |
823 | vPoint[1].x = nTmp; | |
824 | ::GpiMove(m_hPS, &vPoint[0]); | |
825 | ::GpiLine(m_hPS, &vPoint[1]); | |
826 | } | |
5fd2b2c6 DW |
827 | CalcBoundingBox( vX1 |
828 | ,vY1 | |
829 | ); | |
830 | ||
831 | wxCoord vX2 = vX1 + vWidth; | |
832 | wxCoord vY2 = vY1 + vHeight; | |
833 | ||
834 | CalcBoundingBox( vX2 | |
835 | ,vY2 | |
836 | ); | |
f07bb01b | 837 | } // end of wxDC::DoDrawCheckMark |
f6bcfd97 | 838 | |
51c1d535 DW |
839 | void wxDC::DoDrawPoint( |
840 | wxCoord vX | |
841 | , wxCoord vY | |
842 | ) | |
1408104d | 843 | { |
51c1d535 | 844 | POINTL vPoint; |
5fd2b2c6 | 845 | COLORREF vColor = 0x00ffffff; |
51c1d535 | 846 | |
5fd2b2c6 DW |
847 | if (m_pen.Ok()) |
848 | { | |
849 | vColor = m_pen.GetColour().GetPixel(); | |
850 | } | |
851 | ::GpiSetColor(m_hPS, vColor); | |
51c1d535 | 852 | vPoint.x = vX; |
5fd2b2c6 | 853 | vPoint.y = OS2Y(vY,0); |
51c1d535 | 854 | ::GpiSetPel(m_hPS, &vPoint); |
5fd2b2c6 DW |
855 | CalcBoundingBox( vX |
856 | ,vY | |
857 | ); | |
f07bb01b | 858 | } // end of wxDC::DoDrawPoint |
1408104d | 859 | |
51c1d535 DW |
860 | void wxDC::DoDrawPolygon( |
861 | int n | |
862 | , wxPoint vPoints[] | |
863 | , wxCoord vXoffset | |
864 | , wxCoord vYoffset | |
865 | , int nFillStyle | |
866 | ) | |
1408104d | 867 | { |
51c1d535 DW |
868 | ULONG ulCount = 1; // Number of polygons. |
869 | POLYGON vPlgn; // polygon. | |
870 | ULONG flOptions = 0L; // Drawing options. | |
871 | ||
872 | ////////////////////////////////////////////////////////////////////////////// | |
873 | // This contains fields of option bits... to draw boundary lines as well as | |
874 | // the area interior. | |
875 | // | |
876 | // Drawing boundary lines: | |
877 | // POLYGON_NOBOUNDARY Does not draw boundary lines. | |
878 | // POLYGON_BOUNDARY Draws boundary lines (the default). | |
879 | // | |
880 | // Construction of the area interior: | |
881 | // POLYGON_ALTERNATE Constructs interior in alternate mode | |
882 | // (the default). | |
883 | // POLYGON_WINDING Constructs interior in winding mode. | |
884 | ////////////////////////////////////////////////////////////////////////////// | |
885 | ||
886 | ULONG flModel = 0L; // Drawing model. | |
887 | ||
888 | ////////////////////////////////////////////////////////////////////////////// | |
889 | // Drawing model. | |
890 | // POLYGON_INCL Fill is inclusive of bottom right (the default). | |
891 | // POLYGON_EXCL Fill is exclusive of bottom right. | |
892 | // This is provided to aid migration from other graphics models. | |
893 | ////////////////////////////////////////////////////////////////////////////// | |
894 | ||
895 | LONG lHits = 0L; // Correlation/error indicator. | |
896 | POINTL vPoint; | |
897 | int i; | |
898 | int nIsTRANSPARENT = 0; | |
899 | LONG lBorderColor = 0L; | |
900 | LONG lColor = 0L; | |
901 | ||
902 | lBorderColor = m_pen.GetColour().GetPixel(); | |
903 | lColor = m_brush.GetColour().GetPixel(); | |
904 | if(m_brush.GetStyle() == wxTRANSPARENT) | |
905 | nIsTRANSPARENT = 1; | |
906 | ||
907 | vPlgn.ulPoints = n; | |
908 | vPlgn.aPointl = (POINTL*) calloc( n + 1 | |
909 | ,sizeof(POINTL) | |
910 | ); // well, new will call malloc | |
911 | ||
912 | for(i = 0; i < n; i++) | |
913 | { | |
5fd2b2c6 DW |
914 | vPlgn.aPointl[i].x = vPoints[i].x; // +xoffset; |
915 | vPlgn.aPointl[i].y = OS2Y(vPoints[i].y,0); // +yoffset; | |
51c1d535 DW |
916 | } |
917 | flModel = POLYGON_BOUNDARY; | |
918 | if(nFillStyle == wxWINDING_RULE) | |
919 | flModel |= POLYGON_WINDING; | |
920 | else | |
921 | flModel |= POLYGON_ALTERNATE; | |
922 | ||
923 | vPoint.x = vXoffset; | |
5fd2b2c6 | 924 | vPoint.y = OS2Y(vYoffset,0); |
51c1d535 DW |
925 | |
926 | ::GpiSetColor(m_hPS, lBorderColor); | |
927 | ::GpiMove(m_hPS, &vPoint); | |
928 | lHits = ::GpiPolygons(m_hPS, ulCount, &vPlgn, flOptions, flModel); | |
929 | free(vPlgn.aPointl); | |
f07bb01b | 930 | } // end of wxDC::DoDrawPolygon |
1408104d | 931 | |
51c1d535 DW |
932 | void wxDC::DoDrawLines( |
933 | int n | |
934 | , wxPoint vPoints[] | |
935 | , wxCoord vXoffset | |
936 | , wxCoord vYoffset | |
937 | ) | |
1408104d | 938 | { |
51c1d535 DW |
939 | POINTL vPoint; |
940 | ||
5fd2b2c6 DW |
941 | if (vXoffset != 0L || vXoffset != 0L) |
942 | { | |
943 | int i; | |
944 | ||
945 | vPoint.x = vPoints[0].x + vXoffset; | |
946 | vPoint.y = OS2Y(vPoints[0].y + vYoffset,0); | |
947 | ::GpiMove(m_hPS, &vPoint); | |
51c1d535 | 948 | |
5fd2b2c6 | 949 | LONG lBorderColor = m_pen.GetColour().GetPixel(); |
51c1d535 | 950 | |
5fd2b2c6 DW |
951 | ::GpiSetColor(m_hPS, lBorderColor); |
952 | for(i = 1; i < n; i++) | |
953 | { | |
954 | vPoint.x = vPoints[i].x + vXoffset; | |
955 | vPoint.y = OS2Y(vPoints[i].y + vYoffset,0); | |
956 | ::GpiLine(m_hPS, &vPoint); | |
957 | } | |
958 | } | |
959 | else | |
51c1d535 | 960 | { |
5fd2b2c6 DW |
961 | int i; |
962 | ||
963 | CalcBoundingBox( vPoints[i].x | |
964 | ,vPoints[i].y | |
965 | ); | |
966 | vPoint.x = vPoints[0].x; | |
967 | vPoint.y = OS2Y(vPoints[0].y,0); | |
968 | ::GpiMove(m_hPS, &vPoint); | |
969 | ||
970 | for (i = 0; i < n; i++) | |
971 | { | |
972 | CalcBoundingBox( vPoints[i].x | |
973 | ,vPoints[i].y | |
974 | ); | |
975 | vPoint.x = vPoints[i].x; | |
976 | vPoint.y = OS2Y(vPoints[i].y,0); | |
977 | ::GpiLine(m_hPS, &vPoint); | |
978 | } | |
51c1d535 | 979 | } |
f07bb01b | 980 | } // end of wxDC::DoDrawLines |
1408104d | 981 | |
7e99520b | 982 | void wxDC::DoDrawRectangle( |
f44fdfb0 | 983 | wxCoord vX |
7e99520b DW |
984 | , wxCoord vY |
985 | , wxCoord vWidth | |
986 | , wxCoord vHeight | |
987 | ) | |
1408104d | 988 | { |
7e99520b | 989 | POINTL vPoint[2]; |
51c1d535 DW |
990 | LONG lControl; |
991 | LONG lColor; | |
992 | LONG lBorderColor; | |
993 | int nIsTRANSPARENT = 0; | |
7e99520b | 994 | |
1d0edc0f | 995 | // |
d6d749aa | 996 | // Might be a memory DC with no Paint rect. |
1d0edc0f DW |
997 | // |
998 | if (!(m_vRclPaint.yTop == 0 && | |
999 | m_vRclPaint.yBottom == 0 && | |
1000 | m_vRclPaint.xRight == 0 && | |
1001 | m_vRclPaint.xLeft == 0)) | |
1002 | vY = OS2Y(vY,vHeight); | |
5fd2b2c6 DW |
1003 | |
1004 | wxCoord vX2 = vX + vWidth; | |
1005 | wxCoord vY2 = vY + vHeight; | |
1006 | ||
7e99520b | 1007 | vPoint[0].x = vX; |
5fd2b2c6 | 1008 | vPoint[0].y = vY; |
ba3e10c9 DW |
1009 | vPoint[1].x = vX + vWidth - 1; |
1010 | vPoint[1].y = vY + vHeight - 1; | |
7e99520b | 1011 | ::GpiMove(m_hPS, &vPoint[0]); |
51c1d535 DW |
1012 | lColor = m_brush.GetColour().GetPixel(); |
1013 | lBorderColor = m_pen.GetColour().GetPixel(); | |
1014 | if (m_brush.GetStyle() == wxTRANSPARENT) | |
1015 | nIsTRANSPARENT = 1; | |
1016 | if(lColor == lBorderColor || nIsTRANSPARENT) | |
1017 | { | |
1018 | lControl = DRO_OUTLINEFILL; //DRO_FILL; | |
1019 | if(m_brush.GetStyle() == wxTRANSPARENT) | |
1020 | lControl = DRO_OUTLINE; | |
1021 | ||
8d854fa9 | 1022 | ::GpiSetColor(m_hPS, lColor); |
51c1d535 DW |
1023 | ::GpiBox( m_hPS // handle to a presentation space |
1024 | ,lControl // draw the box outline ? or ? | |
1025 | ,&vPoint[1] // address of the corner | |
1026 | ,0L // horizontal corner radius | |
1027 | ,0L // vertical corner radius | |
1028 | ); | |
1029 | } | |
1030 | else | |
1031 | { | |
1032 | lControl = DRO_OUTLINE; | |
1033 | ::GpiSetColor( m_hPS | |
1034 | ,lBorderColor | |
1035 | ); | |
1036 | ::GpiBox( m_hPS | |
1037 | ,lControl | |
1038 | ,&vPoint[1] | |
1039 | ,0L | |
1040 | ,0L | |
1041 | ); | |
1042 | lControl = DRO_FILL; | |
1043 | ::GpiSetColor( m_hPS | |
1044 | ,lColor | |
1045 | ); | |
8d854fa9 | 1046 | vPoint[0].x = vX + 1; |
5fd2b2c6 | 1047 | vPoint[0].y = vY + 1; |
ba3e10c9 DW |
1048 | vPoint[1].x = vX + vWidth - 2; |
1049 | vPoint[1].y = vY + vHeight - 2; | |
8d854fa9 | 1050 | ::GpiMove(m_hPS, &vPoint[0]); |
51c1d535 DW |
1051 | ::GpiBox( m_hPS |
1052 | ,lControl | |
1053 | ,&vPoint[1] | |
1054 | ,0L | |
1055 | ,0L | |
1056 | ); | |
1057 | } | |
5fd2b2c6 DW |
1058 | CalcBoundingBox(vX, vY); |
1059 | CalcBoundingBox(vX2, vY2); | |
f07bb01b | 1060 | } // end of wxDC::DoDrawRectangle |
1408104d | 1061 | |
7e99520b DW |
1062 | void wxDC::DoDrawRoundedRectangle( |
1063 | wxCoord vX | |
1064 | , wxCoord vY | |
1065 | , wxCoord vWidth | |
1066 | , wxCoord vHeight | |
1067 | , double dRadius | |
1068 | ) | |
1408104d | 1069 | { |
7e99520b | 1070 | POINTL vPoint[2]; |
51c1d535 | 1071 | LONG lControl; |
7e99520b | 1072 | |
d6d749aa DW |
1073 | // |
1074 | // Might be a memory DC with no Paint rect. | |
1075 | // | |
1076 | if (!(m_vRclPaint.yTop == 0 && | |
1077 | m_vRclPaint.yBottom == 0 && | |
1078 | m_vRclPaint.xRight == 0 && | |
1079 | m_vRclPaint.xLeft == 0)) | |
1080 | vY = OS2Y(vY,vHeight); | |
5fd2b2c6 DW |
1081 | |
1082 | wxCoord vX2 = (vX + vWidth); | |
1083 | wxCoord vY2 = (vY + vHeight); | |
1084 | ||
7e99520b | 1085 | vPoint[0].x = vX; |
8d854fa9 | 1086 | vPoint[0].y = YLOG2DEV(vY) - vHeight; |
7e99520b | 1087 | vPoint[1].x = vX + vWidth; |
8d854fa9 | 1088 | vPoint[1].y = vY; |
7e99520b | 1089 | ::GpiMove(m_hPS, &vPoint[0]); |
51c1d535 DW |
1090 | |
1091 | lControl = DRO_OUTLINEFILL; //DRO_FILL; | |
1092 | if (m_brush.GetStyle() == wxTRANSPARENT) | |
1093 | lControl = DRO_OUTLINE; | |
f44fdfb0 DW |
1094 | ::GpiBox( m_hPS // handle to a presentation space |
1095 | ,DRO_OUTLINE // draw the box outline ? or ? | |
1096 | ,&vPoint[1] // address of the corner | |
1097 | ,(LONG)dRadius // horizontal corner radius | |
1098 | ,(LONG)dRadius // vertical corner radius | |
7e99520b | 1099 | ); |
5fd2b2c6 DW |
1100 | CalcBoundingBox(vX, vY); |
1101 | CalcBoundingBox(vX2, vY2); | |
f07bb01b | 1102 | } // end of wxDC::DoDrawRoundedRectangle |
1408104d | 1103 | |
51c1d535 DW |
1104 | // Draw Ellipse within box (x,y) - (x+width, y+height) |
1105 | void wxDC::DoDrawEllipse( | |
1106 | wxCoord vX | |
1107 | , wxCoord vY | |
1108 | , wxCoord vWidth | |
1109 | , wxCoord vHeight | |
1110 | ) | |
1408104d | 1111 | { |
51c1d535 DW |
1112 | POINTL vPtlPos; // Structure for current position |
1113 | FIXED vFxMult; // Multiplier for ellipse | |
1114 | ARCPARAMS vArcp; // Structure for arc parameters | |
1115 | ||
5fd2b2c6 DW |
1116 | vY = OS2Y(vY,vHeight); |
1117 | ||
51c1d535 DW |
1118 | vArcp.lR = 0; |
1119 | vArcp.lQ = vHeight/2; | |
1120 | vArcp.lP = vWidth/2; | |
1121 | vArcp.lS = 0; | |
1122 | ::GpiSetArcParams( m_hPS | |
1123 | ,&vArcp | |
1124 | ); // Sets parameters to default | |
1125 | vPtlPos.x = vX + vWidth/2; // Loads x-coordinate | |
1126 | vPtlPos.y = vY + vHeight/2; // Loads y-coordinate | |
1127 | ::GpiMove( m_hPS | |
1128 | ,&vPtlPos | |
1129 | ); // Sets current position | |
1130 | vFxMult = MAKEFIXED(1, 0); /* Sets multiplier */ | |
1131 | ||
1132 | // | |
1133 | // DRO_FILL, DRO_OTLINEFILL - where to get | |
1134 | // | |
1135 | ::GpiFullArc( m_hPS | |
1136 | ,DRO_OUTLINE | |
1137 | ,vFxMult | |
1138 | ); // Draws full arc with center at current position | |
5fd2b2c6 DW |
1139 | |
1140 | wxCoord vX2 = (vX + vWidth); | |
1141 | wxCoord vY2 = (vY + vHeight); | |
1142 | ||
1143 | CalcBoundingBox(vX, vY); | |
1144 | CalcBoundingBox(vX2, vY2); | |
f07bb01b | 1145 | } // end of wxDC::DoDrawEllipse |
1408104d | 1146 | |
51c1d535 DW |
1147 | void wxDC::DoDrawEllipticArc( |
1148 | wxCoord vX | |
1149 | , wxCoord vY | |
1150 | , wxCoord vWidth | |
1151 | , wxCoord vHeight | |
1152 | , double dSa | |
1153 | , double dEa | |
1154 | ) | |
1408104d | 1155 | { |
51c1d535 DW |
1156 | POINTL vPtlPos; // Structure for current position |
1157 | FIXED vFxMult; // Multiplier for ellipse | |
1158 | ARCPARAMS vArcp; // Structure for arc parameters | |
1159 | FIXED vFSa; | |
1160 | FIXED vFSweepa; // Start angle, sweep angle | |
1161 | double dIntPart; | |
1162 | double dFractPart; | |
1163 | double dRadius; | |
1164 | ||
5fd2b2c6 DW |
1165 | vY = OS2Y(vY,vHeight); |
1166 | ||
51c1d535 DW |
1167 | dFractPart = modf(dSa,&dIntPart); |
1168 | vFSa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) ); | |
1169 | dFractPart = modf(dEa - dSa, &dIntPart); | |
1170 | vFSweepa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) ); | |
1171 | ||
1172 | // | |
1173 | // Ellipse main axis (r,q), (p,s) with center at (0,0) | |
1174 | // | |
1175 | vArcp.lR = 0; | |
1176 | vArcp.lQ = vHeight/2; | |
1177 | vArcp.lP = vWidth/2; | |
1178 | vArcp.lS = 0; | |
1179 | ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default | |
1180 | vPtlPos.x = vX + vWidth/2 * (1. + cos(DegToRad(dSa))); // Loads x-coordinate | |
1181 | vPtlPos.y = vY + vHeight/2 * (1. + sin(DegToRad(dSa))); // Loads y-coordinate | |
1182 | ::GpiMove(m_hPS, &vPtlPos); // Sets current position | |
1183 | ||
1184 | // | |
1185 | // May be not to the center ? | |
1186 | // | |
1187 | vPtlPos.x = vX + vWidth/2 ; // Loads x-coordinate | |
1188 | vPtlPos.y = vY + vHeight/2; // Loads y-coordinate | |
1189 | vFxMult = MAKEFIXED(1, 0); // Sets multiplier | |
1190 | ||
1191 | // | |
1192 | // DRO_FILL, DRO_OTLINEFILL - where to get | |
1193 | // | |
1194 | ::GpiPartialArc( m_hPS | |
1195 | ,&vPtlPos | |
1196 | ,vFxMult | |
1197 | ,vFSa | |
1198 | ,vFSweepa | |
1199 | ); | |
5fd2b2c6 DW |
1200 | wxCoord vX2 = (vX + vWidth); |
1201 | wxCoord vY2 = (vY + vHeight); | |
1202 | ||
1203 | CalcBoundingBox(vX, vY); | |
1204 | CalcBoundingBox(vX2, vY2); | |
f07bb01b | 1205 | } // end of wxDC::DoDrawEllipticArc |
1408104d | 1206 | |
f07bb01b DW |
1207 | void wxDC::DoDrawIcon( |
1208 | const wxIcon& rIcon | |
1209 | , wxCoord vX | |
1210 | , wxCoord vY | |
1211 | ) | |
1408104d | 1212 | { |
16ff355b DW |
1213 | // |
1214 | // Need to copy back into a bitmap. ::WinDrawPointer uses device coords | |
1215 | // and I don't feel like figuring those out for scrollable windows so | |
1216 | // just convert to a bitmap then let the DoDrawBitmap routing display it | |
1217 | // | |
1218 | if (rIcon.IsXpm()) | |
1219 | { | |
1220 | DoDrawBitmap(rIcon.GetXpmSrc(), vX, vY, TRUE); | |
1221 | } | |
1222 | else | |
1223 | { | |
1224 | wxBitmap vBitmap(rIcon); | |
1225 | ||
1226 | DoDrawBitmap(vBitmap, vX, vY, FALSE); | |
1227 | } | |
5fd2b2c6 DW |
1228 | CalcBoundingBox(vX, vY); |
1229 | CalcBoundingBox(vX + rIcon.GetWidth(), vY + rIcon.GetHeight()); | |
f07bb01b DW |
1230 | } // end of wxDC::DoDrawIcon |
1231 | ||
1232 | void wxDC::DoDrawBitmap( | |
1233 | const wxBitmap& rBmp | |
1234 | , wxCoord vX | |
1235 | , wxCoord vY | |
1236 | , bool bUseMask | |
1237 | ) | |
1408104d | 1238 | { |
ba3e10c9 | 1239 | if (!IsKindOf(CLASSINFO(wxPrinterDC))) |
c354beea DW |
1240 | { |
1241 | HBITMAP hBitmap = (HBITMAP)rBmp.GetHBITMAP(); | |
52315bc3 | 1242 | HBITMAP hBitmapOld; |
c354beea | 1243 | |
ba3e10c9 DW |
1244 | vY = OS2Y(vY,rBmp.GetHeight()); |
1245 | ||
1246 | // | |
1247 | // Flip the picture as OS/2 is upside-down | |
1248 | // | |
1249 | POINTL vPoint[4] = { vX, vY + rBmp.GetHeight() | |
1250 | ,vX + rBmp.GetWidth(), vY | |
1251 | ,0, 0 | |
1252 | ,rBmp.GetWidth(), rBmp.GetHeight() | |
1253 | }; | |
ba3e10c9 DW |
1254 | if (bUseMask) |
1255 | { | |
1256 | wxMask* pMask = rBmp.GetMask(); | |
c354beea | 1257 | |
52315bc3 | 1258 | if (pMask) |
ba3e10c9 | 1259 | { |
52315bc3 DW |
1260 | // |
1261 | // Need to imitate ::MaskBlt in windows. | |
1262 | // 1) Extract the bits from from the bitmap. | |
1263 | // 2) Extract the bits from the mask | |
1264 | // 3) Using the mask bits do the following: | |
1265 | // A) If the mask byte is 00 leave the bitmap byte alone | |
1266 | // B) If the mask byte is FF copy the screen color into | |
1267 | // bitmap byte | |
1268 | // 4) Create a new bitmap and set its bits to the above result | |
1269 | // 5) Blit this to the screen PS | |
1270 | // | |
1271 | HBITMAP hMask = (HBITMAP)pMask->GetMaskBitmap(); | |
d6d749aa | 1272 | HBITMAP hOldMask = NULLHANDLE; |
52315bc3 DW |
1273 | HBITMAP hOldBitmap = NULLHANDLE; |
1274 | HBITMAP hNewBitmap = NULLHANDLE; | |
1275 | unsigned char* pucBits; // buffer that will contain the bitmap data | |
1276 | unsigned char* pucBitsMask; // buffer that will contain the mask data | |
1277 | unsigned char* pucData; // pointer to use to traverse bitmap data | |
1278 | unsigned char* pucDataMask; // pointer to use to traverse mask data | |
1279 | LONG lHits; | |
1280 | ERRORID vError; | |
1281 | wxString sError; | |
1282 | ||
1283 | // | |
1284 | // The usual Memory context creation stuff | |
1285 | // | |
ba3e10c9 DW |
1286 | DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L}; |
1287 | SIZEL vSize = {0, 0}; | |
52315bc3 DW |
1288 | HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE); |
1289 | HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC); | |
1290 | ||
1291 | // | |
1292 | // The usual bitmap header stuff | |
1293 | // | |
1294 | BITMAPINFOHEADER2 vHeader; | |
1295 | BITMAPINFO2 vInfo; | |
1296 | ||
1297 | memset(&vHeader, '\0', 16); | |
1298 | vHeader.cbFix = 16; | |
52315bc3 DW |
1299 | |
1300 | memset(&vInfo, '\0', 16); | |
1301 | vInfo.cbFix = 16; | |
1302 | vInfo.cx = (ULONG)rBmp.GetWidth(); | |
1303 | vInfo.cy = (ULONG)rBmp.GetHeight(); | |
1304 | vInfo.cPlanes = 1; | |
1305 | vInfo.cBitCount = 24; // Set to desired count going in | |
1306 | ||
1307 | // | |
1308 | // Create the buffers for data....all wxBitmaps are 24 bit internally | |
1309 | // | |
1310 | int nBytesPerLine = rBmp.GetWidth() * 3; | |
1311 | int nSizeDWORD = sizeof(DWORD); | |
1312 | int nLineBoundary = nBytesPerLine % nSizeDWORD; | |
1313 | int nPadding = 0; | |
1314 | int i; | |
1315 | int j; | |
1316 | LONG lScans = 0L; | |
1317 | LONG lColor = 0L; | |
1318 | ||
1319 | // | |
1320 | // Need to get a background color for mask blitting | |
1321 | // | |
1322 | if (IsKindOf(CLASSINFO(wxPaintDC))) | |
1323 | { | |
1324 | wxPaintDC* pPaintDC = wxDynamicCast(this, wxPaintDC); | |
c354beea | 1325 | |
52315bc3 DW |
1326 | lColor = pPaintDC->m_pCanvas->GetBackgroundColour().GetPixel(); |
1327 | } | |
1328 | else if (GetBrush() != wxNullBrush) | |
1329 | lColor = GetBrush().GetColour().GetPixel(); | |
1330 | else | |
1331 | lColor = m_textBackgroundColour.GetPixel(); | |
1332 | ||
1333 | // | |
1334 | // Bitmap must be ina double-word alligned address so we may | |
1335 | // have some padding to worry about | |
1336 | // | |
1337 | if (nLineBoundary > 0) | |
1338 | { | |
1339 | nPadding = nSizeDWORD - nLineBoundary; | |
1340 | nBytesPerLine += nPadding; | |
1341 | } | |
1342 | pucBits = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight()); | |
1343 | pucBitsMask = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight()); | |
1344 | memset(pucBits, '\0', (nBytesPerLine * rBmp.GetHeight())); | |
1345 | memset(pucBitsMask, '\0', (nBytesPerLine * rBmp.GetHeight())); | |
1346 | ||
1347 | // | |
1348 | // Extract the bitmap and mask data | |
1349 | // | |
1350 | if ((hOldBitmap = ::GpiSetBitmap(hPS, hBitmap)) == HBM_ERROR) | |
1351 | { | |
1352 | vError = ::WinGetLastError(vHabmain); | |
1353 | sError = wxPMErrorToStr(vError); | |
1354 | } | |
d6d749aa DW |
1355 | ::GpiQueryBitmapInfoHeader(hBitmap, &vHeader); |
1356 | vInfo.cBitCount = 24; | |
ba3e10c9 DW |
1357 | if ((lScans = ::GpiQueryBitmapBits( hPS |
1358 | ,0L | |
1359 | ,(LONG)rBmp.GetHeight() | |
52315bc3 | 1360 | ,(PBYTE)pucBits |
ba3e10c9 DW |
1361 | ,&vInfo |
1362 | )) == GPI_ALTERROR) | |
1363 | { | |
ba3e10c9 DW |
1364 | vError = ::WinGetLastError(vHabmain); |
1365 | sError = wxPMErrorToStr(vError); | |
1366 | } | |
d6d749aa | 1367 | if ((hOldMask = ::GpiSetBitmap(hPS, hMask)) == HBM_ERROR) |
ba3e10c9 | 1368 | { |
ba3e10c9 DW |
1369 | vError = ::WinGetLastError(vHabmain); |
1370 | sError = wxPMErrorToStr(vError); | |
1371 | } | |
d6d749aa DW |
1372 | ::GpiQueryBitmapInfoHeader(hMask, &vHeader); |
1373 | vInfo.cBitCount = 24; | |
52315bc3 DW |
1374 | if ((lScans = ::GpiQueryBitmapBits( hPS |
1375 | ,0L | |
1376 | ,(LONG)rBmp.GetHeight() | |
1377 | ,(PBYTE)pucBitsMask | |
1378 | ,&vInfo | |
1379 | )) == GPI_ALTERROR) | |
ba3e10c9 | 1380 | { |
ba3e10c9 DW |
1381 | vError = ::WinGetLastError(vHabmain); |
1382 | sError = wxPMErrorToStr(vError); | |
1383 | } | |
d6d749aa DW |
1384 | if (( hMask = ::GpiSetBitmap(hPS, hOldMask)) == HBM_ERROR) |
1385 | { | |
1386 | vError = ::WinGetLastError(vHabmain); | |
1387 | sError = wxPMErrorToStr(vError); | |
1388 | } | |
52315bc3 DW |
1389 | |
1390 | // | |
1391 | // Now set the bytes(bits) according to the mask values | |
1392 | // 3 bytes per pel...must handle one at a time | |
1393 | // | |
1394 | pucData = pucBits; | |
1395 | pucDataMask = pucBitsMask; | |
1396 | ||
d6d749aa DW |
1397 | // |
1398 | // 16 bit kludge really only kinda works. The mask gets applied | |
1399 | // where needed but the original bitmap bits are dorked sometimes | |
1400 | // | |
1401 | bool bpp16 = (wxDisplayDepth() == 16); | |
1402 | ||
52315bc3 | 1403 | for (i = 0; i < rBmp.GetHeight(); i++) |
ba3e10c9 | 1404 | { |
52315bc3 DW |
1405 | for (j = 0; j < rBmp.GetWidth(); j++) |
1406 | { | |
1407 | // Byte 1 | |
d6d749aa DW |
1408 | if (bpp16 && *pucDataMask == 0xF8) // 16 bit display gobblygook |
1409 | pucData++; | |
1410 | else if (*pucDataMask == 0xFF) // leave bitmap byte alone | |
52315bc3 DW |
1411 | pucData++; |
1412 | else | |
1413 | { | |
16ff355b | 1414 | *pucData = ((unsigned char)(lColor >> 16)); |
52315bc3 DW |
1415 | pucData++; |
1416 | } | |
1417 | // Byte 2 | |
d6d749aa DW |
1418 | if (bpp16 && *(pucDataMask + 1) == 0xFC) // 16 bit display gobblygook |
1419 | pucData++; | |
1420 | else if (*(pucDataMask + 1) == 0xFF) // leave bitmap byte alone | |
52315bc3 DW |
1421 | pucData++; |
1422 | else | |
1423 | { | |
16ff355b | 1424 | *pucData = ((unsigned char)(lColor >> 8)); |
52315bc3 DW |
1425 | pucData++; |
1426 | } | |
1427 | ||
1428 | // Byte 3 | |
d6d749aa DW |
1429 | if (bpp16 && *(pucDataMask + 2) == 0xF8) // 16 bit display gobblygook |
1430 | pucData++; | |
1431 | else if (*(pucDataMask + 2) == 0xFF) // leave bitmap byte alone | |
52315bc3 DW |
1432 | pucData++; |
1433 | else | |
1434 | { | |
16ff355b | 1435 | *pucData = ((unsigned char)lColor); |
52315bc3 DW |
1436 | pucData++; |
1437 | } | |
1438 | pucDataMask += 3; | |
1439 | } | |
1440 | for (j = 0; j < nPadding; j++) | |
1441 | { | |
1442 | pucData++; | |
1443 | pucDataMask++; | |
1444 | } | |
1445 | } | |
52315bc3 DW |
1446 | // |
1447 | // Create a new bitmap | |
1448 | // | |
d6d749aa DW |
1449 | vHeader.cx = (ULONG)rBmp.GetWidth(); |
1450 | vHeader.cy = (ULONG)rBmp.GetHeight(); | |
1451 | vHeader.cPlanes = 1L; | |
1452 | vHeader.cBitCount = 24; | |
52315bc3 DW |
1453 | if ((hNewBitmap = ::GpiCreateBitmap( hPS |
1454 | ,&vHeader | |
1455 | ,CBM_INIT | |
1456 | ,(PBYTE)pucBits | |
1457 | ,&vInfo | |
1458 | )) == GPI_ERROR) | |
1459 | { | |
ba3e10c9 DW |
1460 | vError = ::WinGetLastError(vHabmain); |
1461 | sError = wxPMErrorToStr(vError); | |
1462 | } | |
ba3e10c9 | 1463 | |
52315bc3 DW |
1464 | // |
1465 | // Now blit it to the screen PS | |
1466 | // | |
1467 | if ((lHits = ::GpiWCBitBlt( (HPS)GetHPS() | |
1468 | ,hNewBitmap | |
1469 | ,4 | |
1470 | ,vPoint | |
1471 | ,ROP_SRCCOPY | |
1472 | ,BBO_IGNORE | |
1473 | )) == GPI_ERROR) | |
1474 | { | |
ba3e10c9 DW |
1475 | vError = ::WinGetLastError(vHabmain); |
1476 | sError = wxPMErrorToStr(vError); | |
1477 | } | |
52315bc3 DW |
1478 | |
1479 | // | |
1480 | // Clean up | |
1481 | // | |
1482 | free(pucBits); | |
1483 | free(pucBitsMask); | |
1484 | ::GpiSetBitmap(hPS, NULLHANDLE); | |
d6d749aa | 1485 | ::GpiDeleteBitmap(hNewBitmap); |
52315bc3 DW |
1486 | ::GpiDestroyPS(hPS); |
1487 | ::DevCloseDC(hDC); | |
ba3e10c9 DW |
1488 | } |
1489 | } | |
1490 | else | |
1491 | { | |
16ff355b DW |
1492 | LONG lOldForeGround = ::GpiQueryColor((HPS)GetHPS()); |
1493 | LONG lOldBackGround = ::GpiQueryBackColor((HPS)GetHPS()); | |
52315bc3 DW |
1494 | |
1495 | if (m_textForegroundColour.Ok()) | |
1496 | { | |
1497 | ::GpiSetColor( (HPS)GetHPS() | |
1498 | ,m_textForegroundColour.GetPixel() | |
1499 | ); | |
1500 | } | |
1501 | if (m_textBackgroundColour.Ok()) | |
1502 | { | |
1503 | ::GpiSetBackColor( (HPS)GetHPS() | |
1504 | ,m_textBackgroundColour.GetPixel() | |
1505 | ); | |
1506 | } | |
16ff355b DW |
1507 | // |
1508 | // Need to alter bits in a mono bitmap to match the new | |
1509 | // background-foreground if it is different. | |
1510 | // | |
1511 | if (rBmp.IsMono() && | |
1512 | ((m_textForegroundColour.GetPixel() != lOldForeGround) || | |
1513 | (m_textBackgroundColour.GetPixel() != lOldBackGround))) | |
1514 | { | |
1515 | DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L}; | |
1516 | SIZEL vSize = {0, 0}; | |
1517 | HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE); | |
1518 | HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC); | |
1519 | ||
1520 | int nBytesPerLine = rBmp.GetWidth() * 3; | |
1521 | int i, j; | |
1522 | LONG lForeGround = m_textForegroundColour.GetPixel(); | |
1523 | LONG lBackGround = m_textBackgroundColour.GetPixel(); | |
1524 | LONG lScans; | |
1525 | HBITMAP hOldBitmap = NULLHANDLE; | |
1526 | BITMAPINFO2 vInfo; | |
1527 | ERRORID vError; | |
1528 | wxString sError; | |
1529 | ||
1530 | ||
1531 | memset(&vInfo, '\0', 16); | |
1532 | vInfo.cbFix = 16; | |
1533 | vInfo.cx = (ULONG)rBmp.GetWidth(); | |
1534 | vInfo.cy = (ULONG)rBmp.GetHeight(); | |
1535 | vInfo.cPlanes = 1; | |
1536 | vInfo.cBitCount = 24; | |
1537 | ||
1538 | unsigned char* pucBits; // buffer that will contain the bitmap data | |
1539 | unsigned char* pucData; // pointer to use to traverse bitmap data | |
1540 | ||
1541 | pucBits = new unsigned char[nBytesPerLine * rBmp.GetHeight()]; | |
1542 | memset(pucBits, '\0', (nBytesPerLine * rBmp.GetHeight())); | |
1543 | ||
1544 | if ((hOldBitmap = ::GpiSetBitmap(hPS, hBitmap)) == HBM_ERROR) | |
1545 | { | |
1546 | vError = ::WinGetLastError(vHabmain); | |
1547 | sError = wxPMErrorToStr(vError); | |
1548 | return; | |
1549 | } | |
1550 | if ((lScans = ::GpiQueryBitmapBits( hPS | |
1551 | ,0L | |
1552 | ,(LONG)rBmp.GetHeight() | |
1553 | ,(PBYTE)pucBits | |
1554 | ,&vInfo | |
1555 | )) == GPI_ALTERROR) | |
1556 | { | |
1557 | vError = ::WinGetLastError(vHabmain); | |
1558 | sError = wxPMErrorToStr(vError); | |
1559 | return; | |
1560 | } | |
1561 | unsigned char cOldRedFore = (unsigned char)(lOldForeGround >> 16); | |
1562 | unsigned char cOldGreenFore = (unsigned char)(lOldForeGround >> 8); | |
1563 | unsigned char cOldBlueFore = (unsigned char)lOldForeGround; | |
1564 | ||
1565 | unsigned char cOldRedBack = (unsigned char)(lOldBackGround >> 16); | |
1566 | unsigned char cOldGreenBack = (unsigned char)(lOldBackGround >> 8); | |
1567 | unsigned char cOldBlueBack = (unsigned char)lOldBackGround; | |
1568 | ||
1569 | unsigned char cRedFore = (unsigned char)(lForeGround >> 16); | |
1570 | unsigned char cGreenFore = (unsigned char)(lForeGround >> 8); | |
1571 | unsigned char cBlueFore = (unsigned char)lForeGround; | |
1572 | ||
1573 | unsigned char cRedBack = (unsigned char)(lBackGround >> 16); | |
1574 | unsigned char cGreenBack = (unsigned char)(lBackGround >> 8); | |
1575 | unsigned char cBlueBack = (unsigned char)lBackGround; | |
1576 | ||
1577 | pucData = pucBits; | |
1578 | for (i = 0; i < rBmp.GetHeight(); i++) | |
1579 | { | |
1580 | for (j = 0; j < rBmp.GetWidth(); j++) | |
1581 | { | |
1582 | unsigned char cBmpRed = *pucData; | |
1583 | unsigned char cBmpGreen = *(pucData + 1); | |
1584 | unsigned char cBmpBlue = *(pucData + 2); | |
1585 | ||
1586 | if ((cBmpRed == cOldRedFore) && | |
1587 | (cBmpGreen == cOldGreenFore) && | |
1588 | (cBmpBlue == cOldBlueFore)) | |
1589 | { | |
29172908 | 1590 | *pucData = cBlueFore; |
16ff355b DW |
1591 | pucData++; |
1592 | *pucData = cGreenFore; | |
1593 | pucData++; | |
29172908 | 1594 | *pucData = cRedFore; |
16ff355b DW |
1595 | pucData++; |
1596 | } | |
1597 | else | |
1598 | { | |
29172908 | 1599 | *pucData = cBlueBack; |
16ff355b DW |
1600 | pucData++; |
1601 | *pucData = cGreenBack; | |
1602 | pucData++; | |
29172908 | 1603 | *pucData = cRedBack; |
16ff355b DW |
1604 | pucData++; |
1605 | } | |
1606 | } | |
1607 | } | |
1608 | if ((lScans = ::GpiSetBitmapBits( hPS | |
1609 | ,0L | |
1610 | ,(LONG)rBmp.GetHeight() | |
1611 | ,(PBYTE)pucBits | |
1612 | ,&vInfo | |
1613 | )) == GPI_ALTERROR) | |
1614 | { | |
1615 | vError = ::WinGetLastError(vHabmain); | |
1616 | sError = wxPMErrorToStr(vError); | |
1617 | return; | |
1618 | } | |
1619 | delete [] pucBits; | |
1620 | ::GpiSetBitmap(hPS, NULLHANDLE); | |
1621 | ::GpiDestroyPS(hPS); | |
1622 | ::DevCloseDC(hDC); | |
1623 | } | |
ba3e10c9 DW |
1624 | ::GpiWCBitBlt( (HPS)GetHPS() |
1625 | ,hBitmap | |
1626 | ,4 | |
1627 | ,vPoint | |
1628 | ,ROP_SRCCOPY | |
1629 | ,BBO_IGNORE | |
1630 | ); | |
52315bc3 | 1631 | ::GpiSetBitmap((HPS)GetHPS(), hBitmapOld); |
16ff355b DW |
1632 | ::GpiSetColor((HPS)GetHPS(), lOldForeGround); |
1633 | ::GpiSetBackColor((HPS)GetHPS(), lOldBackGround); | |
ba3e10c9 | 1634 | } |
c354beea | 1635 | } |
f07bb01b | 1636 | } // end of wxDC::DoDrawBitmap |
1408104d | 1637 | |
7e99520b DW |
1638 | void wxDC::DoDrawText( |
1639 | const wxString& rsText | |
1640 | , wxCoord vX | |
1641 | , wxCoord vY | |
1642 | ) | |
1408104d | 1643 | { |
5fd2b2c6 DW |
1644 | wxCoord vWidth; |
1645 | wxCoord vHeight; | |
1646 | ||
7e99520b DW |
1647 | DrawAnyText( rsText |
1648 | ,vX | |
1649 | ,vY | |
1650 | ); | |
5fd2b2c6 DW |
1651 | |
1652 | CalcBoundingBox(vX, vY); | |
1653 | GetTextExtent(rsText, &vWidth, &vHeight); | |
1654 | CalcBoundingBox((vX + vWidth), (vY + vHeight)); | |
1655 | } // end of wxDC::DoDrawText | |
1408104d | 1656 | |
7e99520b DW |
1657 | void wxDC::DrawAnyText( |
1658 | const wxString& rsText | |
1659 | , wxCoord vX | |
1660 | , wxCoord vY | |
1661 | ) | |
f6bcfd97 | 1662 | { |
7e99520b DW |
1663 | int nOldBackground = 0; |
1664 | POINTL vPtlStart; | |
1665 | LONG lHits; | |
5fd2b2c6 DW |
1666 | wxCoord vTextX = 0; |
1667 | wxCoord vTextY = 0; | |
f6bcfd97 | 1668 | |
7e99520b DW |
1669 | // |
1670 | // prepare for drawing the text | |
1671 | // | |
1672 | ||
1673 | // | |
1674 | // Set text color attributes | |
1675 | // | |
1676 | if (m_textForegroundColour.Ok()) | |
1677 | { | |
1678 | SetTextColor( m_hPS | |
1679 | ,(int)m_textForegroundColour.GetPixel() | |
1680 | ); | |
1681 | } | |
1682 | ||
1683 | if (m_textBackgroundColour.Ok()) | |
1684 | { | |
1685 | nOldBackground = SetTextBkColor( m_hPS | |
1686 | ,(int)m_textBackgroundColour.GetPixel() | |
1687 | ); | |
1688 | } | |
1689 | SetBkMode( m_hPS | |
1690 | ,m_backgroundMode | |
1691 | ); | |
5fd2b2c6 DW |
1692 | GetTextExtent( rsText |
1693 | ,&vTextX | |
1694 | ,&vTextY | |
1695 | ); | |
7e99520b | 1696 | vPtlStart.x = vX; |
d6d749aa DW |
1697 | if (!(m_vRclPaint.yTop == 0 && |
1698 | m_vRclPaint.yBottom == 0 && | |
1699 | m_vRclPaint.xRight == 0 && | |
1700 | m_vRclPaint.xLeft == 0)) | |
1701 | vPtlStart.y = OS2Y(vY,vTextY); | |
1702 | else | |
1703 | vPtlStart.y = vY; | |
1704 | ||
1705 | PCH pzStr = (PCH)rsText.c_str(); | |
7e99520b | 1706 | |
d6d749aa DW |
1707 | ::GpiMove(m_hPS, &vPtlStart); |
1708 | lHits = ::GpiCharString( m_hPS | |
1709 | ,rsText.length() | |
1710 | ,pzStr | |
1711 | ); | |
7e99520b DW |
1712 | if (lHits != GPI_OK) |
1713 | { | |
1714 | wxLogLastError(wxT("TextOut")); | |
1715 | } | |
1716 | ||
1717 | // | |
1718 | // Restore the old parameters (text foreground colour may be left because | |
1719 | // it never is set to anything else, but background should remain | |
1720 | // transparent even if we just drew an opaque string) | |
1721 | // | |
1722 | if (m_textBackgroundColour.Ok()) | |
1723 | SetTextBkColor( m_hPS | |
1724 | ,nOldBackground | |
1725 | ); | |
1726 | SetBkMode( m_hPS | |
1727 | ,wxTRANSPARENT | |
1728 | ); | |
1729 | } | |
1730 | ||
1731 | void wxDC::DoDrawRotatedText( | |
1732 | const wxString& rsText | |
1733 | , wxCoord vX | |
1734 | , wxCoord vY | |
1735 | , double dAngle | |
1736 | ) | |
c8ce6bcc | 1737 | { |
7e99520b DW |
1738 | if (dAngle == 0.0) |
1739 | { | |
1740 | DoDrawText( rsText | |
1741 | ,vX | |
1742 | ,vY | |
1743 | ); | |
1744 | } | |
1745 | ||
c8ce6bcc DW |
1746 | // TODO: |
1747 | /* | |
1748 | if ( angle == 0.0 ) | |
1749 | { | |
1750 | DoDrawText(text, x, y); | |
1751 | } | |
1752 | else | |
1753 | { | |
1754 | LOGFONT lf; | |
1755 | wxFillLogFont(&lf, &m_font); | |
1756 | ||
1757 | // GDI wants the angle in tenth of degree | |
1758 | long angle10 = (long)(angle * 10); | |
1759 | lf.lfEscapement = angle10; | |
1760 | lf. lfOrientation = angle10; | |
1761 | ||
1762 | HFONT hfont = ::CreateFontIndirect(&lf); | |
1763 | if ( !hfont ) | |
1764 | { | |
1765 | wxLogLastError("CreateFont"); | |
1766 | } | |
1767 | else | |
1768 | { | |
1769 | HFONT hfontOld = ::SelectObject(GetHdc(), hfont); | |
1770 | ||
1771 | DrawAnyText(text, x, y); | |
1772 | ||
1773 | (void)::SelectObject(GetHdc(), hfontOld); | |
1774 | } | |
1775 | ||
1776 | // call the bounding box by adding all four vertices of the rectangle | |
1777 | // containing the text to it (simpler and probably not slower than | |
1778 | // determining which of them is really topmost/leftmost/...) | |
1779 | wxCoord w, h; | |
1780 | GetTextExtent(text, &w, &h); | |
1781 | ||
1782 | double rad = DegToRad(angle); | |
1783 | ||
1784 | // "upper left" and "upper right" | |
1785 | CalcBoundingBox(x, y); | |
1786 | CalcBoundingBox(x + w*cos(rad), y - h*sin(rad)); | |
1787 | CalcBoundingBox(x + h*sin(rad), y + h*cos(rad)); | |
1788 | ||
1789 | // "bottom left" and "bottom right" | |
1790 | x += (wxCoord)(h*sin(rad)); | |
1791 | y += (wxCoord)(h*cos(rad)); | |
1792 | CalcBoundingBox(x, y); | |
1793 | CalcBoundingBox(x + h*sin(rad), y + h*cos(rad)); | |
1794 | } | |
1795 | */ | |
1796 | } | |
1797 | ||
fb46a9a6 DW |
1798 | // --------------------------------------------------------------------------- |
1799 | // set GDI objects | |
1800 | // --------------------------------------------------------------------------- | |
1408104d | 1801 | |
938aa9c4 DW |
1802 | void wxDC::DoSelectPalette( |
1803 | bool bRealize | |
1804 | ) | |
1805 | { | |
1806 | // | |
1807 | // Set the old object temporarily, in case the assignment deletes an object | |
1808 | // that's not yet selected out. | |
1809 | // | |
1810 | if (m_hOldPalette) | |
1811 | { | |
1812 | m_hOldPalette = 0; | |
1813 | } | |
1814 | ||
1815 | if (m_palette.Ok()) | |
1816 | { | |
1817 | HPALETTE hOldPal; | |
1818 | ||
1819 | hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE()); | |
1820 | if (!m_hOldPalette) | |
1821 | m_hOldPalette = (WXHPALETTE)hOldPal; | |
1822 | } | |
1823 | } // end of wxDC::DoSelectPalette | |
1824 | ||
1825 | void wxDC::InitializePalette() | |
1826 | { | |
1827 | if (wxDisplayDepth() <= 8 ) | |
1828 | { | |
1829 | // | |
1830 | // Look for any window or parent that has a custom palette. If any has | |
1831 | // one then we need to use it in drawing operations | |
1832 | // | |
1833 | wxWindow* pWin = m_pCanvas->GetAncestorWithCustomPalette(); | |
1834 | ||
1835 | m_hasCustomPalette = pWin && pWin->HasCustomPalette(); | |
1836 | if (m_hasCustomPalette) | |
1837 | { | |
1838 | m_palette = pWin->GetPalette(); | |
1839 | ||
1840 | // | |
1841 | // turn on PM translation for this palette | |
1842 | // | |
1843 | DoSelectPalette(); | |
1844 | } | |
1845 | } | |
1846 | } // end of wxDC::InitializePalette | |
1847 | ||
5fd2b2c6 DW |
1848 | void wxDC::SetPalette( |
1849 | const wxPalette& rPalette | |
1850 | ) | |
1408104d | 1851 | { |
5fd2b2c6 DW |
1852 | if (m_hOldFont) |
1853 | { | |
1854 | m_hOldFont = 0; | |
1855 | } | |
1856 | m_palette = rPalette; | |
1857 | if (!rPalette.Ok()) | |
1858 | { | |
1859 | if (m_hOldFont) | |
1860 | { | |
1861 | m_hOldFont = 0; | |
1862 | } | |
1863 | } | |
1864 | HPALETTE hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE()); | |
1865 | if (!m_hOldPalette) | |
1866 | m_hOldPalette = (WXHPALETTE)hOldPal; | |
1867 | } // end of wxDC::SetPalette | |
1408104d | 1868 | |
f6bcfd97 BP |
1869 | void wxDC::SetFont( |
1870 | const wxFont& rFont | |
1871 | ) | |
1408104d | 1872 | { |
f6bcfd97 BP |
1873 | // |
1874 | // Set the old object temporarily, in case the assignment deletes an object | |
1875 | // that's not yet selected out. | |
1876 | // | |
1877 | if (m_hOldFont) | |
1878 | { | |
f6bcfd97 BP |
1879 | m_hOldFont = 0; |
1880 | } | |
f6bcfd97 | 1881 | m_font = rFont; |
f6bcfd97 BP |
1882 | if (!rFont.Ok()) |
1883 | { | |
f6bcfd97 BP |
1884 | m_hOldFont = 0; |
1885 | } | |
1886 | ||
e99762c0 DW |
1887 | m_font.SetPS(m_hPS); // this will realize the font |
1888 | ||
1889 | if (m_font.Ok()) | |
f6bcfd97 | 1890 | { |
e99762c0 | 1891 | HFONT hFont = m_font.GetResourceHandle(); |
f6bcfd97 BP |
1892 | if (hFont == (HFONT) NULL) |
1893 | { | |
1894 | wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont.")); | |
1895 | } | |
1896 | if (!m_hOldFont) | |
1897 | m_hOldFont = (WXHFONT) hFont; | |
1898 | } | |
e99762c0 | 1899 | } // end of wxDC::SetFont |
1408104d | 1900 | |
7e99520b DW |
1901 | void wxDC::SetPen( |
1902 | const wxPen& rPen | |
1903 | ) | |
1408104d | 1904 | { |
7e99520b DW |
1905 | wxCHECK_RET( Ok(), wxT("invalid window dc") ); |
1906 | ||
1907 | if (m_pen == rPen) | |
1908 | return; | |
1909 | m_pen = rPen; | |
1910 | if (!m_pen.Ok()) | |
1911 | return; | |
1912 | ||
26ac77db DW |
1913 | if (m_hOldPen) |
1914 | m_hOldPen = 0L; | |
1915 | m_pen = rPen; | |
7e99520b | 1916 | |
26ac77db | 1917 | if (!m_pen.Ok()) |
7e99520b | 1918 | { |
26ac77db DW |
1919 | if (m_hOldPen) |
1920 | { | |
1921 | m_pen.SetPS((HPS)m_hOldPen); | |
1922 | } | |
1923 | m_hOldPen = 0L; | |
7e99520b | 1924 | } |
51c1d535 | 1925 | |
26ac77db | 1926 | if (m_pen.Ok()) |
51c1d535 | 1927 | { |
26ac77db DW |
1928 | if (m_pen.GetResourceHandle()) |
1929 | { | |
1930 | m_pen.SetPS(m_hPS); | |
1931 | if (!m_hOldPen) | |
1932 | m_hOldPen = m_pen.GetPS(); | |
1933 | } | |
29172908 | 1934 | ::GpiSetColor(m_hPS, m_pen.GetColour().GetPixel()); |
51c1d535 | 1935 | } |
1408104d | 1936 | } |
7e99520b | 1937 | |
51c1d535 DW |
1938 | void wxDC::SetBrush( |
1939 | const wxBrush& rBrush | |
1940 | ) | |
1408104d | 1941 | { |
15f03b25 DW |
1942 | wxCHECK_RET( Ok(), wxT("invalid window dc") ); |
1943 | ||
15f03b25 DW |
1944 | if (m_hOldBrush) |
1945 | m_hOldBrush = 0L; | |
1946 | m_brush = rBrush; | |
5fd2b2c6 DW |
1947 | if (!m_brush.Ok()) |
1948 | if (m_brush == rBrush) | |
1949 | return; | |
1950 | if (!m_brush.Ok()) | |
1951 | if (m_hOldBrush) | |
1952 | m_hOldBrush = 0L; | |
15f03b25 DW |
1953 | |
1954 | if (!m_brush.Ok()) | |
1955 | { | |
1956 | if (m_hOldBrush) | |
1957 | { | |
1958 | m_brush.SetPS((HPS)m_hOldBrush); | |
1959 | } | |
1960 | m_hOldBrush = 0L; | |
1961 | } | |
1962 | ||
1963 | if (m_brush.Ok()) | |
1964 | { | |
1965 | if (m_brush.GetResourceHandle()) | |
1966 | { | |
1967 | m_brush.SetPS(m_hPS); | |
1968 | if (!m_hOldBrush) | |
5fd2b2c6 | 1969 | m_hOldBrush = (WXHWND)m_brush.GetPS(); |
15f03b25 DW |
1970 | } |
1971 | } | |
1972 | } // end of wxDC::SetBrush | |
1408104d | 1973 | |
5fd2b2c6 DW |
1974 | void wxDC::SetBackground( |
1975 | const wxBrush& rBrush | |
1976 | ) | |
1408104d | 1977 | { |
5fd2b2c6 DW |
1978 | m_backgroundBrush = rBrush; |
1979 | if (!m_backgroundBrush.Ok()) | |
1980 | return; | |
1981 | if (m_pCanvas) | |
1982 | { | |
1983 | bool bCustomColours = TRUE; | |
1984 | ||
1985 | // | |
1986 | // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to | |
1987 | // change background colours from the control-panel specified colours. | |
1988 | // | |
1989 | if (m_pCanvas->IsKindOf(CLASSINFO(wxWindow)) && | |
1990 | ((m_pCanvas->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS)) | |
1991 | bCustomColours = FALSE; | |
1992 | if (bCustomColours) | |
1993 | { | |
1994 | if (m_backgroundBrush.GetStyle()==wxTRANSPARENT) | |
1995 | { | |
1996 | m_pCanvas->SetTransparent(TRUE); | |
1997 | } | |
1998 | else | |
1999 | { | |
2000 | // | |
2001 | // Setting the background brush of a DC | |
2002 | // doesn't affect the window background colour. However, | |
2003 | // I'm leaving in the transparency setting because it's needed by | |
2004 | // various controls (e.g. wxStaticText) to determine whether to draw | |
2005 | // transparently or not. TODO: maybe this should be a new function | |
2006 | // wxWindow::SetTransparency(). Should that apply to the child itself, or the | |
2007 | // parent? | |
2008 | // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour()); | |
2009 | // | |
2010 | m_pCanvas->SetTransparent(FALSE); | |
2011 | } | |
2012 | } | |
2013 | } | |
2014 | COLORREF vNewColor = m_backgroundBrush.GetColour().GetPixel(); | |
2015 | (void)::GpiSetBackColor((HPS)m_hPS, (LONG)vNewColor); | |
2016 | } // end of wxDC::SetBackground | |
1408104d | 2017 | |
7e99520b DW |
2018 | void wxDC::SetBackgroundMode( |
2019 | int nMode | |
2020 | ) | |
1408104d | 2021 | { |
7e99520b | 2022 | m_backgroundMode = nMode; |
5fd2b2c6 | 2023 | } // end of wxDC::SetBackgroundMode |
1408104d | 2024 | |
5fd2b2c6 DW |
2025 | void wxDC::SetLogicalFunction( |
2026 | int nFunction | |
2027 | ) | |
1408104d | 2028 | { |
5fd2b2c6 DW |
2029 | m_logicalFunction = nFunction; |
2030 | SetRop((WXHDC)m_hDC); | |
2031 | } // wxDC::SetLogicalFunction | |
1408104d | 2032 | |
5fd2b2c6 DW |
2033 | void wxDC::SetRop( |
2034 | WXHDC hDC | |
2035 | ) | |
ce44c50e | 2036 | { |
5fd2b2c6 | 2037 | if (!hDC || m_logicalFunction < 0) |
ce44c50e DW |
2038 | return; |
2039 | ||
5fd2b2c6 | 2040 | LONG lCRop; |
ce44c50e DW |
2041 | switch (m_logicalFunction) |
2042 | { | |
5fd2b2c6 DW |
2043 | case wxXOR: |
2044 | lCRop = FM_XOR; | |
2045 | break; | |
2046 | ||
2047 | case wxINVERT: | |
2048 | lCRop = FM_INVERT; | |
2049 | break; | |
2050 | ||
2051 | case wxOR_REVERSE: | |
2052 | lCRop = FM_MERGESRCNOT; | |
2053 | break; | |
2054 | ||
2055 | case wxAND_REVERSE: | |
2056 | lCRop = FM_NOTMASKSRC; | |
2057 | break; | |
2058 | ||
2059 | case wxCLEAR: | |
2060 | lCRop = FM_ONE; | |
2061 | break; | |
2062 | ||
2063 | case wxSET: | |
2064 | lCRop = FM_ZERO; | |
2065 | break; | |
2066 | ||
2067 | case wxSRC_INVERT: | |
2068 | lCRop = FM_MERGENOTSRC; | |
2069 | break; | |
2070 | ||
2071 | case wxOR_INVERT: | |
2072 | lCRop = FM_MERGESRCNOT; | |
2073 | break; | |
2074 | ||
2075 | case wxAND: | |
2076 | lCRop = FM_AND; | |
2077 | break; | |
2078 | ||
2079 | case wxOR: | |
2080 | lCRop = FM_OR; | |
2081 | break; | |
2082 | ||
2083 | case wxAND_INVERT: | |
2084 | lCRop = FM_SUBTRACT; | |
2085 | break; | |
2086 | ||
2087 | case wxEQUIV: | |
2088 | case wxNAND: | |
2089 | case wxCOPY: | |
2090 | default: | |
2091 | lCRop = FM_OVERPAINT; | |
2092 | break; | |
ce44c50e | 2093 | } |
5fd2b2c6 DW |
2094 | ::GpiSetMix((HPS)hDC, lCRop); |
2095 | } // end of wxDC::SetRop | |
ce44c50e | 2096 | |
5fd2b2c6 DW |
2097 | bool wxDC::StartDoc( |
2098 | const wxString& rsMessage | |
2099 | ) | |
ce44c50e | 2100 | { |
fb46a9a6 DW |
2101 | // We might be previewing, so return TRUE to let it continue. |
2102 | return TRUE; | |
5fd2b2c6 | 2103 | } // end of wxDC::StartDoc |
fb46a9a6 DW |
2104 | |
2105 | void wxDC::EndDoc() | |
2106 | { | |
5fd2b2c6 | 2107 | } // end of wxDC::EndDoc |
fb46a9a6 DW |
2108 | |
2109 | void wxDC::StartPage() | |
2110 | { | |
5fd2b2c6 | 2111 | } // end of wxDC::StartPage |
fb46a9a6 DW |
2112 | |
2113 | void wxDC::EndPage() | |
2114 | { | |
5fd2b2c6 | 2115 | } // end of wxDC::EndPage |
fb46a9a6 DW |
2116 | |
2117 | // --------------------------------------------------------------------------- | |
2118 | // text metrics | |
2119 | // --------------------------------------------------------------------------- | |
2120 | ||
7cdc2f1e | 2121 | wxCoord wxDC::GetCharHeight() const |
fb46a9a6 | 2122 | { |
05a8bfed DW |
2123 | FONTMETRICS vFM; // metrics structure |
2124 | ||
2125 | ::GpiQueryFontMetrics( m_hPS | |
2126 | ,sizeof(FONTMETRICS) | |
2127 | ,&vFM | |
2128 | ); | |
2129 | return YDEV2LOGREL(vFM.lXHeight); | |
fb46a9a6 DW |
2130 | } |
2131 | ||
7cdc2f1e | 2132 | wxCoord wxDC::GetCharWidth() const |
fb46a9a6 | 2133 | { |
05a8bfed DW |
2134 | FONTMETRICS vFM; // metrics structure |
2135 | ||
2136 | ::GpiQueryFontMetrics( m_hPS | |
2137 | ,sizeof(FONTMETRICS) | |
2138 | ,&vFM | |
2139 | ); | |
2140 | return XDEV2LOGREL(vFM.lAveCharWidth); | |
7e99520b DW |
2141 | } |
2142 | ||
2143 | void wxDC::DoGetTextExtent( | |
2144 | const wxString& rsString | |
2145 | , wxCoord* pvX | |
2146 | , wxCoord* pvY | |
f44fdfb0 | 2147 | , wxCoord* pvDescent |
7e99520b DW |
2148 | , wxCoord* pvExternalLeading |
2149 | , wxFont* pTheFont | |
2150 | ) const | |
2151 | { | |
2152 | POINTL avPoint[TXTBOX_COUNT]; | |
2153 | POINTL vPtMin; | |
2154 | POINTL vPtMax; | |
2155 | int i; | |
2156 | int l; | |
2157 | FONTMETRICS vFM; // metrics structure | |
2158 | BOOL bRc; | |
2159 | char* pStr; | |
2160 | ERRORID vErrorCode; // last error id code | |
2161 | wxFont* pFontToUse = (wxFont*)pTheFont; | |
2162 | ||
2c4a8d17 DW |
2163 | char zMsg[128]; // DEBUG |
2164 | wxString sError; | |
2165 | ||
7e99520b DW |
2166 | if (!pFontToUse) |
2167 | pFontToUse = (wxFont*)&m_font; | |
2168 | l = rsString.length(); | |
2169 | pStr = (PCH) rsString.c_str(); | |
fb46a9a6 | 2170 | |
7e99520b DW |
2171 | // |
2172 | // In world coordinates. | |
2173 | // | |
2174 | bRc = ::GpiQueryTextBox( m_hPS | |
2175 | ,l | |
2176 | ,pStr | |
2177 | ,TXTBOX_COUNT // return maximum information | |
2178 | ,avPoint // array of coordinates points | |
f44fdfb0 | 2179 | ); |
7e99520b DW |
2180 | if(!bRc) |
2181 | { | |
2182 | vErrorCode = ::WinGetLastError(wxGetInstance()); | |
2c4a8d17 DW |
2183 | sError = wxPMErrorToStr(vErrorCode); |
2184 | // DEBUG | |
2185 | sprintf(zMsg, "GpiQueryTextBox for %s: failed with Error: %x - %s", pStr, vErrorCode, sError.c_str()); | |
2186 | (void)wxMessageBox( "wxWindows Menu sample" | |
2187 | ,zMsg | |
2188 | ,wxICON_INFORMATION | |
2189 | ); | |
7e99520b DW |
2190 | } |
2191 | ||
2192 | vPtMin.x = avPoint[0].x; | |
2193 | vPtMax.x = avPoint[0].x; | |
2194 | vPtMin.y = avPoint[0].y; | |
2195 | vPtMax.y = avPoint[0].y; | |
2196 | for (i = 1; i < 4; i++) | |
2197 | { | |
2198 | if(vPtMin.x > avPoint[i].x) vPtMin.x = avPoint[i].x; | |
2199 | if(vPtMin.y > avPoint[i].y) vPtMin.y = avPoint[i].y; | |
2200 | if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x; | |
2201 | if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y; | |
2202 | } | |
2203 | ::GpiQueryFontMetrics( m_hPS | |
2204 | ,sizeof(FONTMETRICS) | |
2205 | ,&vFM | |
2206 | ); | |
2207 | ||
2208 | if (pvX) | |
2209 | *pvX = (wxCoord)(vPtMax.x - vPtMin.x + 1); | |
2210 | if (pvY) | |
2211 | *pvY = (wxCoord)(vPtMax.y - vPtMin.y + 1); | |
2212 | if (pvDescent) | |
2213 | *pvDescent = vFM.lMaxDescender; | |
f44fdfb0 | 2214 | if (pvExternalLeading) |
7e99520b | 2215 | *pvExternalLeading = vFM.lExternalLeading; |
fb46a9a6 DW |
2216 | } |
2217 | ||
5fd2b2c6 DW |
2218 | void wxDC::SetMapMode( |
2219 | int nMode | |
2220 | ) | |
fb46a9a6 | 2221 | { |
5fd2b2c6 DW |
2222 | int nPixelWidth = 0; |
2223 | int nPixelHeight = 0; | |
2224 | int nMmWidth = 1; | |
2225 | int nMmHeight = 1; | |
2226 | LONG lArray[CAPS_VERTICAL_RESOLUTION]; | |
fb46a9a6 | 2227 | |
5fd2b2c6 DW |
2228 | m_mappingMode = nMode; |
2229 | ||
2230 | if(::DevQueryCaps( m_hDC | |
2231 | ,CAPS_FAMILY | |
2232 | ,CAPS_VERTICAL_RESOLUTION | |
2233 | ,lArray | |
2234 | )) | |
2235 | { | |
2236 | LONG lHorzRes; | |
2237 | LONG lVertRes; | |
2238 | ||
2239 | nPixelWidth = lArray[CAPS_WIDTH]; | |
2240 | nPixelHeight = lArray[CAPS_HEIGHT]; | |
2241 | lHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter | |
2242 | lVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter | |
2243 | nMmWidth = (lHorzRes/1000) * nPixelWidth; | |
2244 | nMmWidth = (lVertRes/1000) * nPixelHeight; | |
2245 | } | |
2246 | if ((nPixelWidth == 0) || (nPixelHeight == 0) || (nMmWidth == 0) || (nMmHeight == 0)) | |
2247 | { | |
2248 | return; | |
2249 | } | |
2250 | ||
2251 | double dMm2pixelsX = nPixelWidth/nMmWidth; | |
2252 | double dMm2pixelsY = nPixelHeight/nMmHeight; | |
2253 | ||
2254 | switch (nMode) | |
2255 | { | |
2256 | case wxMM_TWIPS: | |
2257 | m_logicalScaleX = (twips2mm * dMm2pixelsX); | |
2258 | m_logicalScaleY = (twips2mm * dMm2pixelsY); | |
2259 | break; | |
2260 | ||
2261 | case wxMM_POINTS: | |
2262 | m_logicalScaleX = (pt2mm * dMm2pixelsX); | |
2263 | m_logicalScaleY = (pt2mm * dMm2pixelsY); | |
2264 | break; | |
2265 | ||
2266 | case wxMM_METRIC: | |
2267 | m_logicalScaleX = dMm2pixelsX; | |
2268 | m_logicalScaleY = dMm2pixelsY; | |
2269 | break; | |
2270 | ||
2271 | case wxMM_LOMETRIC: | |
2272 | m_logicalScaleX = (dMm2pixelsX/10.0); | |
2273 | m_logicalScaleY = (dMm2pixelsY/10.0); | |
2274 | break; | |
2275 | ||
2276 | case wxMM_TEXT: | |
2277 | default: | |
2278 | m_logicalScaleX = 1.0; | |
2279 | m_logicalScaleY = 1.0; | |
2280 | break; | |
2281 | } | |
2282 | SIZEL vSize; | |
2283 | ULONG ulOptions; | |
2284 | ||
2285 | ulOptions = ::GpiQueryPS(m_hPS, &vSize); | |
2286 | if (!ulOptions & PU_ARBITRARY) | |
2287 | { | |
2288 | ulOptions = PU_ARBITRARY | GPIF_DEFAULT; | |
2289 | ::GpiSetPS(m_hPS, &vSize, ulOptions); | |
2290 | } | |
74de9ed6 GD |
2291 | m_nWindowExtX = (int)MS_XDEV2LOG(VIEWPORT_EXTENT); |
2292 | m_nWindowExtY = (int)MS_YDEV2LOG(VIEWPORT_EXTENT); | |
5fd2b2c6 DW |
2293 | // ???? |
2294 | }; // end of wxDC::SetMapMode | |
2295 | ||
2296 | void wxDC::SetUserScale( | |
2297 | double dX | |
2298 | , double dY | |
2299 | ) | |
fb46a9a6 | 2300 | { |
5fd2b2c6 DW |
2301 | m_userScaleX = dX; |
2302 | m_userScaleY = dY; | |
fb46a9a6 DW |
2303 | |
2304 | SetMapMode(m_mappingMode); | |
5fd2b2c6 | 2305 | } // end of wxDC::SetUserScale |
fb46a9a6 | 2306 | |
5fd2b2c6 DW |
2307 | void wxDC::SetAxisOrientation( |
2308 | bool bXLeftRight | |
2309 | , bool bYBottomUp | |
2310 | ) | |
fb46a9a6 | 2311 | { |
5fd2b2c6 DW |
2312 | m_signX = bXLeftRight ? 1 : -1; |
2313 | m_signY = bYBottomUp ? -1 : 1; | |
fb46a9a6 DW |
2314 | |
2315 | SetMapMode(m_mappingMode); | |
5fd2b2c6 | 2316 | } // end of wxDC::SetAxisOrientation |
fb46a9a6 | 2317 | |
5fd2b2c6 DW |
2318 | void wxDC::SetSystemScale( |
2319 | double dX | |
2320 | , double dY | |
2321 | ) | |
fb46a9a6 | 2322 | { |
5fd2b2c6 DW |
2323 | m_scaleX = dX; |
2324 | m_scaleY = dY; | |
fb46a9a6 DW |
2325 | |
2326 | SetMapMode(m_mappingMode); | |
5fd2b2c6 | 2327 | } // end of wxDC::SetSystemScale |
fb46a9a6 | 2328 | |
5fd2b2c6 DW |
2329 | void wxDC::SetLogicalOrigin( |
2330 | wxCoord vX | |
2331 | , wxCoord vY | |
2332 | ) | |
fb46a9a6 | 2333 | { |
5fd2b2c6 DW |
2334 | RECTL vRect; |
2335 | ||
2336 | ::GpiQueryPageViewport( m_hPS | |
2337 | ,&vRect | |
2338 | ); | |
2339 | vRect.xRight -= vX; | |
2340 | vRect.yTop += vY; | |
2341 | vRect.xLeft = vX; | |
2342 | vRect.yBottom = vY; | |
2343 | ::GpiSetPageViewport( m_hPS | |
2344 | ,&vRect | |
2345 | ); | |
2346 | }; // end of wxDC::SetLogicalOrigin | |
fb46a9a6 | 2347 | |
8d854fa9 | 2348 | void wxDC::SetDeviceOrigin( |
5fd2b2c6 DW |
2349 | wxCoord vX |
2350 | , wxCoord vY | |
8d854fa9 | 2351 | ) |
fb46a9a6 | 2352 | { |
26ac77db DW |
2353 | RECTL vRect; |
2354 | ||
5fd2b2c6 DW |
2355 | m_deviceOriginX = vX; |
2356 | m_deviceOriginY = vY; | |
26ac77db DW |
2357 | ::GpiQueryPageViewport( m_hPS |
2358 | ,&vRect | |
2359 | ); | |
5fd2b2c6 DW |
2360 | vRect.xLeft += vX; |
2361 | vRect.xRight += vX; | |
2362 | vRect.yBottom -= vY; | |
2363 | vRect.yTop -= vY; | |
26ac77db DW |
2364 | ::GpiSetPageViewport( m_hPS |
2365 | ,&vRect | |
2366 | ); | |
5fd2b2c6 | 2367 | }; // end of wxDC::SetDeviceOrigin |
fb46a9a6 DW |
2368 | |
2369 | // --------------------------------------------------------------------------- | |
2370 | // coordinates transformations | |
2371 | // --------------------------------------------------------------------------- | |
2372 | ||
7cdc2f1e | 2373 | wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const |
fb46a9a6 | 2374 | { |
f6bcfd97 BP |
2375 | return (wxCoord) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX); |
2376 | } | |
fb46a9a6 | 2377 | |
7cdc2f1e | 2378 | wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const |
fb46a9a6 | 2379 | { |
74de9ed6 GD |
2380 | // axis orientation is not taken into account for conversion of a distance |
2381 | return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_scaleX)); | |
f6bcfd97 | 2382 | } |
fb46a9a6 | 2383 | |
7cdc2f1e | 2384 | wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const |
fb46a9a6 | 2385 | { |
f6bcfd97 BP |
2386 | return (wxCoord) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY); |
2387 | } | |
fb46a9a6 | 2388 | |
7cdc2f1e | 2389 | wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const |
fb46a9a6 | 2390 | { |
74de9ed6 GD |
2391 | // axis orientation is not taken into account for conversion of a distance |
2392 | return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_scaleY)); | |
f6bcfd97 | 2393 | } |
fb46a9a6 | 2394 | |
7cdc2f1e | 2395 | wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const |
fb46a9a6 | 2396 | { |
f6bcfd97 BP |
2397 | return (wxCoord) ((x - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX); |
2398 | } | |
fb46a9a6 | 2399 | |
7cdc2f1e | 2400 | wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const |
fb46a9a6 | 2401 | { |
74de9ed6 GD |
2402 | // axis orientation is not taken into account for conversion of a distance |
2403 | return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_scaleX); | |
f6bcfd97 | 2404 | } |
fb46a9a6 | 2405 | |
7cdc2f1e | 2406 | wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const |
fb46a9a6 | 2407 | { |
f6bcfd97 BP |
2408 | return (wxCoord) ((y - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY); |
2409 | } | |
fb46a9a6 | 2410 | |
7cdc2f1e | 2411 | wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const |
fb46a9a6 | 2412 | { |
74de9ed6 GD |
2413 | // axis orientation is not taken into account for conversion of a distance |
2414 | return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_scaleY); | |
f6bcfd97 | 2415 | } |
fb46a9a6 DW |
2416 | |
2417 | // --------------------------------------------------------------------------- | |
2418 | // bit blit | |
2419 | // --------------------------------------------------------------------------- | |
2420 | ||
5afb9458 DW |
2421 | bool wxDC::DoBlit( |
2422 | wxCoord vXdest | |
2423 | , wxCoord vYdest | |
2424 | , wxCoord vWidth | |
2425 | , wxCoord vHeight | |
2426 | , wxDC* pSource | |
2427 | , wxCoord vXsrc | |
2428 | , wxCoord vYsrc | |
2429 | , int nRop | |
2430 | , bool bUseMask | |
893758d5 DW |
2431 | , wxCoord vXsrcMask |
2432 | , wxCoord vYsrcMask | |
5afb9458 | 2433 | ) |
fb46a9a6 | 2434 | { |
5afb9458 DW |
2435 | wxMask* pMask = NULL; |
2436 | CHARBUNDLE vCbnd; | |
2437 | COLORREF vOldTextColor; | |
2438 | COLORREF vOldBackground = ::GpiQueryBackColor(m_hPS); | |
5afb9458 DW |
2439 | |
2440 | if (bUseMask) | |
2441 | { | |
2442 | const wxBitmap& rBmp = pSource->m_vSelectedBitmap; | |
2443 | ||
2444 | pMask = rBmp.GetMask(); | |
2445 | if (!(rBmp.Ok() && pMask && pMask->GetMaskBitmap())) | |
2446 | { | |
2447 | bUseMask = FALSE; | |
2448 | } | |
2449 | } | |
2450 | ||
2451 | ::GpiQueryAttrs( m_hPS | |
2452 | ,PRIM_CHAR | |
2453 | ,CBB_COLOR | |
2454 | ,&vCbnd | |
2455 | ); | |
2456 | vOldTextColor = (COLORREF)vCbnd.lColor; | |
2457 | ||
2458 | if (m_textForegroundColour.Ok()) | |
2459 | { | |
2460 | vCbnd.lColor = (LONG)m_textForegroundColour.GetPixel(); | |
2461 | ::GpiSetAttrs( m_hPS // presentation-space handle | |
2462 | ,PRIM_CHAR // Char primitive. | |
2463 | ,CBB_COLOR // sets color. | |
2464 | ,0 | |
2465 | ,&vCbnd // buffer for attributes. | |
2466 | ); | |
2467 | } | |
2468 | if (m_textBackgroundColour.Ok()) | |
2469 | { | |
2470 | ::GpiSetBackColor(m_hPS, (LONG)m_textBackgroundColour.GetPixel()); | |
2471 | } | |
2472 | ||
2473 | LONG lRop = ROP_SRCCOPY; | |
2474 | ||
2475 | switch (nRop) | |
2476 | { | |
2477 | case wxXOR: lRop = ROP_SRCINVERT; break; | |
2478 | case wxINVERT: lRop = ROP_DSTINVERT; break; | |
2479 | case wxOR_REVERSE: lRop = 0x00DD0228; break; | |
2480 | case wxAND_REVERSE: lRop = ROP_SRCERASE; break; | |
2481 | case wxCLEAR: lRop = ROP_ZERO; break; | |
2482 | case wxSET: lRop = ROP_ONE; break; | |
2483 | case wxOR_INVERT: lRop = ROP_MERGEPAINT; break; | |
2484 | case wxAND: lRop = ROP_SRCAND; break; | |
2485 | case wxOR: lRop = ROP_SRCPAINT; break; | |
2486 | case wxEQUIV: lRop = 0x00990066; break; | |
2487 | case wxNAND: lRop = 0x007700E6; break; | |
2488 | case wxAND_INVERT: lRop = 0x00220326; break; | |
2489 | case wxCOPY: lRop = ROP_SRCCOPY; break; | |
2490 | case wxNO_OP: lRop = ROP_NOTSRCERASE; break; | |
2491 | case wxSRC_INVERT: lRop = ROP_SRCINVERT; break; | |
2492 | case wxNOR: lRop = ROP_NOTSRCCOPY; break; | |
2493 | default: | |
2494 | wxFAIL_MSG( wxT("unsupported logical function") ); | |
2495 | return FALSE; | |
2496 | } | |
2497 | ||
2498 | bool bSuccess; | |
b02121c3 | 2499 | |
5afb9458 DW |
2500 | if (bUseMask) |
2501 | { | |
2502 | // | |
2503 | // Blit bitmap with mask | |
2504 | // | |
2505 | ||
2506 | // | |
b02121c3 | 2507 | // Create a temp buffer bitmap and DCs/PSs to access it and the mask |
5afb9458 | 2508 | // |
b02121c3 DW |
2509 | HDC hDCMask; |
2510 | HDC hDCBuffer; | |
2511 | HPS hPSMask; | |
2512 | HPS hPSBuffer; | |
2513 | DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L}; | |
2514 | BITMAPINFOHEADER2 vBmpHdr; | |
893758d5 | 2515 | HBITMAP hBufBitmap; |
b02121c3 DW |
2516 | SIZEL vSize = {0, 0}; |
2517 | LONG rc; | |
2518 | ||
b02121c3 DW |
2519 | memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2)); |
2520 | vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2); | |
2521 | vBmpHdr.cx = vWidth; | |
2522 | vBmpHdr.cy = vHeight; | |
2523 | vBmpHdr.cPlanes = 1; | |
2524 | vBmpHdr.cBitCount = 24; | |
2525 | ||
893758d5 DW |
2526 | #if wxUSE_DC_CACHEING |
2527 | if (TRUE) | |
2528 | { | |
2529 | // | |
2530 | // create a temp buffer bitmap and DCs to access it and the mask | |
2531 | // | |
2532 | wxDCCacheEntry* pDCCacheEntry1 = FindDCInCache( NULL | |
2533 | ,pSource->GetHPS() | |
2534 | ); | |
2535 | wxDCCacheEntry* pDCCacheEntry2 = FindDCInCache( pDCCacheEntry1 | |
2536 | ,GetHPS() | |
2537 | ); | |
2538 | wxDCCacheEntry* pBitmapCacheEntry = FindBitmapInCache( GetHPS() | |
2539 | ,vWidth | |
2540 | ,vHeight | |
2541 | ); | |
2542 | ||
2543 | hPSMask = pDCCacheEntry1->m_hPS; | |
2544 | hDCBuffer = (HDC)pDCCacheEntry2->m_hPS; | |
2545 | hBufBitmap = (HBITMAP)pBitmapCacheEntry->m_hBitmap; | |
2546 | } | |
2547 | else | |
2548 | #endif | |
2549 | { | |
2550 | hDCMask = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE); | |
2551 | hDCBuffer = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE); | |
2552 | hPSMask = ::GpiCreatePS(vHabmain, hDCMask, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC); | |
2553 | hPSBuffer = ::GpiCreatePS(vHabmain, hDCBuffer, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC); | |
2554 | hBufBitmap = ::GpiCreateBitmap(GetHPS(), &vBmpHdr, 0L, NULL, NULL); | |
2555 | } | |
2556 | ||
b02121c3 DW |
2557 | POINTL aPoint1[4] = { 0, 0 |
2558 | ,vWidth, vHeight | |
2559 | ,vXdest, vYdest | |
2560 | ,vXdest + vWidth, vYdest + vHeight | |
2561 | }; | |
2562 | POINTL aPoint2[4] = { 0, 0 | |
2563 | ,vWidth, vHeight | |
2564 | ,vXsrc, vYsrc | |
2565 | ,vXsrc + vWidth, vYsrc + vHeight | |
2566 | }; | |
2567 | POINTL aPoint3[4] = { vXdest, vYdest | |
23e356de DW |
2568 | ,vXdest + vWidth, vYdest + vHeight |
2569 | ,vXsrc, vYsrc | |
2570 | ,vXsrc + vWidth, vYsrc + vHeight | |
2571 | }; | |
2572 | POINTL aPoint4[4] = { vXdest, vYdest | |
b02121c3 DW |
2573 | ,vXdest + vWidth, vYdest + vHeight |
2574 | ,0, 0 | |
2575 | ,vWidth, vHeight | |
2576 | }; | |
2577 | ::GpiSetBitmap(hPSMask, (HBITMAP) pMask->GetMaskBitmap()); | |
2578 | ::GpiSetBitmap(hPSBuffer, (HBITMAP) hBufBitmap); | |
5afb9458 | 2579 | |
b02121c3 DW |
2580 | // |
2581 | // Copy dest to buffer | |
2582 | // | |
2583 | rc = ::GpiBitBlt( hPSBuffer | |
2584 | ,GetHPS() | |
2585 | ,4L | |
2586 | ,aPoint1 | |
2587 | ,ROP_SRCCOPY | |
2588 | ,BBO_IGNORE | |
2589 | ); | |
2590 | if (rc == GPI_ERROR) | |
2591 | { | |
2592 | wxLogLastError(wxT("BitBlt")); | |
2593 | } | |
5afb9458 | 2594 | |
b02121c3 DW |
2595 | // |
2596 | // Copy src to buffer using selected raster op | |
2597 | // | |
2598 | rc = ::GpiBitBlt( hPSBuffer | |
2599 | ,GetHPS() | |
2600 | ,4L | |
2601 | ,aPoint2 | |
2602 | ,lRop | |
2603 | ,BBO_IGNORE | |
2604 | ); | |
2605 | if (rc == GPI_ERROR) | |
2606 | { | |
2607 | wxLogLastError(wxT("BitBlt")); | |
2608 | } | |
5afb9458 | 2609 | |
b02121c3 DW |
2610 | // |
2611 | // Set masked area in buffer to BLACK (pixel value 0) | |
2612 | // | |
2613 | COLORREF vPrevBkCol = ::GpiQueryBackColor(GetHPS()); | |
2614 | COLORREF vPrevCol = ::GpiQueryColor(GetHPS()); | |
2615 | ||
2616 | ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255)); | |
2617 | ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0)); | |
2618 | ||
2619 | rc = ::GpiBitBlt( hPSBuffer | |
2620 | ,hPSMask | |
2621 | ,4L | |
2622 | ,aPoint2 | |
2623 | ,ROP_SRCAND | |
2624 | ,BBO_IGNORE | |
2625 | ); | |
2626 | if (rc == GPI_ERROR) | |
2627 | { | |
2628 | wxLogLastError(wxT("BitBlt")); | |
2629 | } | |
5afb9458 | 2630 | |
b02121c3 DW |
2631 | // |
2632 | // Set unmasked area in dest to BLACK | |
2633 | // | |
2634 | ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0)); | |
2635 | ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255)); | |
2636 | rc = ::GpiBitBlt( GetHPS() | |
2637 | ,hPSMask | |
2638 | ,4L | |
23e356de | 2639 | ,aPoint3 |
b02121c3 DW |
2640 | ,ROP_SRCAND |
2641 | ,BBO_IGNORE | |
2642 | ); | |
2643 | if (rc == GPI_ERROR) | |
2644 | { | |
2645 | wxLogLastError(wxT("BitBlt")); | |
5afb9458 | 2646 | } |
b02121c3 DW |
2647 | |
2648 | // | |
2649 | // Restore colours to original values | |
2650 | // | |
2651 | ::GpiSetBackColor(GetHPS(), vPrevBkCol); | |
2652 | ::GpiSetColor(GetHPS(), vPrevCol); | |
2653 | ||
2654 | // | |
2655 | // OR buffer to dest | |
2656 | // | |
2657 | rc = ::GpiBitBlt( GetHPS() | |
2658 | ,hPSMask | |
2659 | ,4L | |
23e356de | 2660 | ,aPoint4 |
b02121c3 DW |
2661 | ,ROP_SRCPAINT |
2662 | ,BBO_IGNORE | |
2663 | ); | |
2664 | if (rc == GPI_ERROR) | |
2665 | { | |
2666 | bSuccess = FALSE; | |
2667 | wxLogLastError(wxT("BitBlt")); | |
2668 | } | |
2669 | ||
2670 | // | |
2671 | // Tidy up temporary DCs and bitmap | |
2672 | // | |
2673 | ::GpiSetBitmap(hPSMask, NULLHANDLE); | |
2674 | ::GpiSetBitmap(hPSBuffer, NULLHANDLE); | |
893758d5 | 2675 | #if !wxUSE_DC_CACHEING |
b02121c3 DW |
2676 | ::GpiDestroyPS(hPSMask); |
2677 | ::GpiDestroyPS(hPSBuffer); | |
2678 | ::DevCloseDC(hDCMask); | |
2679 | ::DevCloseDC(hDCBuffer); | |
2680 | ::GpiDeleteBitmap(hBufBitmap); | |
893758d5 | 2681 | #endif |
b02121c3 | 2682 | bSuccess = TRUE; |
5afb9458 | 2683 | } |
b02121c3 DW |
2684 | else // no mask, just BitBlt() it |
2685 | { | |
2686 | POINTL aPoint[4] = { vXdest, vYdest | |
2687 | ,vXdest + vWidth, vYdest + vHeight | |
2688 | ,vXsrc, vYsrc | |
2689 | ,vXsrc + vWidth, vYsrc + vHeight | |
2690 | }; | |
2691 | ||
5afb9458 DW |
2692 | bSuccess = (::GpiBitBlt( m_hPS |
2693 | ,pSource->GetHPS() | |
2694 | ,4L | |
2695 | ,aPoint | |
2696 | ,lRop | |
2697 | ,BBO_IGNORE | |
2698 | ) != GPI_ERROR); | |
2699 | if (!bSuccess ) | |
2700 | { | |
2701 | wxLogLastError(wxT("BitBlt")); | |
2702 | } | |
b02121c3 | 2703 | } |
5afb9458 DW |
2704 | vCbnd.lColor = (LONG)vOldTextColor; |
2705 | ::GpiSetAttrs( m_hPS // presentation-space handle | |
2706 | ,PRIM_CHAR // Char primitive. | |
2707 | ,CBB_COLOR // sets color. | |
2708 | ,0 | |
2709 | ,&vCbnd // buffer for attributes. | |
2710 | ); | |
2711 | ::GpiSetBackColor(m_hPS, (LONG)vOldBackground); | |
2712 | return bSuccess; | |
fb46a9a6 DW |
2713 | } |
2714 | ||
5fd2b2c6 DW |
2715 | void wxDC::DoGetSize( |
2716 | int* pnWidth | |
2717 | , int* pnHeight | |
2718 | ) const | |
fb46a9a6 | 2719 | { |
5fd2b2c6 DW |
2720 | LONG lArray[CAPS_HEIGHT]; |
2721 | ||
2722 | if(::DevQueryCaps( m_hDC | |
2723 | ,CAPS_FAMILY | |
2724 | ,CAPS_HEIGHT | |
2725 | ,lArray | |
2726 | )) | |
2727 | { | |
2728 | *pnWidth = lArray[CAPS_WIDTH]; | |
2729 | *pnHeight = lArray[CAPS_HEIGHT]; | |
2730 | } | |
2731 | }; // end of wxDC::DoGetSize( | |
fb46a9a6 | 2732 | |
5fd2b2c6 DW |
2733 | void wxDC::DoGetSizeMM( |
2734 | int* pnWidth | |
2735 | , int* pnHeight | |
2736 | ) const | |
fb46a9a6 | 2737 | { |
5fd2b2c6 DW |
2738 | LONG lArray[CAPS_VERTICAL_RESOLUTION]; |
2739 | ||
2740 | if(::DevQueryCaps( m_hDC | |
2741 | ,CAPS_FAMILY | |
2742 | ,CAPS_VERTICAL_RESOLUTION | |
2743 | ,lArray | |
2744 | )) | |
2745 | { | |
2746 | int nWidth; | |
2747 | int nHeight; | |
2748 | int nHorzRes; | |
2749 | int nVertRes; | |
2750 | ||
2751 | nWidth = lArray[CAPS_WIDTH]; | |
2752 | nHeight = lArray[CAPS_HEIGHT]; | |
2753 | nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter | |
2754 | nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter | |
2755 | nWidth = (nHorzRes/1000) * nWidth; | |
2756 | nHeight = (nVertRes/1000) * nHeight; | |
2757 | } | |
2758 | }; // end of wxDC::DoGetSizeMM | |
fb46a9a6 DW |
2759 | |
2760 | wxSize wxDC::GetPPI() const | |
2761 | { | |
5fd2b2c6 DW |
2762 | LONG lArray[CAPS_VERTICAL_RESOLUTION]; |
2763 | int nWidth; | |
2764 | int nHeight; | |
fb46a9a6 | 2765 | |
5fd2b2c6 DW |
2766 | if(::DevQueryCaps( m_hDC |
2767 | ,CAPS_FAMILY | |
2768 | ,CAPS_VERTICAL_RESOLUTION | |
2769 | ,lArray | |
2770 | )) | |
2771 | { | |
2772 | int nPelWidth; | |
2773 | int nPelHeight; | |
2774 | int nHorzRes; | |
2775 | int nVertRes; | |
2776 | ||
2777 | nPelWidth = lArray[CAPS_WIDTH]; | |
2778 | nPelHeight = lArray[CAPS_HEIGHT]; | |
2779 | nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter | |
2780 | nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter | |
2781 | nWidth = (nHorzRes/39.3) * nPelWidth; | |
2782 | nHeight = (nVertRes/39.3) * nPelHeight; | |
2783 | } | |
2784 | return (wxSize(nWidth,nHeight)); | |
2785 | } // end of wxDC::GetPPI | |
2786 | ||
2787 | void wxDC::SetLogicalScale( | |
2788 | double dX | |
2789 | , double dY | |
2790 | ) | |
fb46a9a6 | 2791 | { |
5fd2b2c6 DW |
2792 | m_logicalScaleX = dX; |
2793 | m_logicalScaleY = dY; | |
2794 | }; // end of wxDC::SetLogicalScale | |
fb46a9a6 DW |
2795 | |
2796 | #if WXWIN_COMPATIBILITY | |
2797 | void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y, | |
2798 | float *descent, float *externalLeading, | |
2799 | wxFont *theFont, bool use16bit) const | |
2800 | { | |
7cdc2f1e | 2801 | wxCoord x1, y1, descent1, externalLeading1; |
fb46a9a6 DW |
2802 | GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit); |
2803 | *x = x1; *y = y1; | |
2804 | if (descent) | |
2805 | *descent = descent1; | |
2806 | if (externalLeading) | |
2807 | *externalLeading = externalLeading1; | |
2808 | } | |
2809 | #endif | |
2810 |