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