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