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