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