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