]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/os2/dc.cpp
fixed huge memory leak in wxFileDialog (closes patch 544060)
[wxWidgets.git] / src / os2 / dc.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: dc.cpp
3// Purpose: wxDC class
4// Author: David Webster
5// Modified by:
6// Created: 10/14/99
7// RCS-ID: $Id$
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
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"
25 #include "wx/msgdlg.h"
26 #include "wx/module.h"
27#endif
28
29#include "wx/dcprint.h"
30
31#include <string.h>
32#include <math.h>
33
34#include "wx/os2/private.h"
35
36 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
37
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
59// ---------------------------------------------------------------------------
60// constants
61// ---------------------------------------------------------------------------
62
63static const int VIEWPORT_EXTENT = 1000;
64
65static const int MM_POINTS = 9;
66static const int MM_METRIC = 10;
67
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
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
103 ::GpiQueryAttrs( hPS // presentation-space handle
104 ,PRIM_CHAR // Char primitive.
105 ,CBB_BACK_COLOR // Background color.
106 ,&vCbnd // buffer for attributes.
107 );
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
149// ===========================================================================
150// implementation
151// ===========================================================================
152
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{
208 int nDepth = 24; // we'll fix this later ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
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
339// ---------------------------------------------------------------------------
340// wxDC
341// ---------------------------------------------------------------------------
342
343wxDC::wxDC(void)
344{
345 wxColour vColor;
346
347 m_pCanvas = NULL;
348
349 m_hOldBitmap = 0;
350 m_hOldPen = 0;
351 m_hOldBrush = 0;
352 m_hOldFont = 0;
353 m_hOldPalette = 0;
354
355 m_bOwnsDC = FALSE;
356 m_hDC = 0;
357 m_hOldPS = NULL;
358 m_hPS = NULL;
359 m_bIsPaintTime = FALSE; // True at Paint Time
360
361 vColor.InitFromName("BLACK");
362 m_pen.SetColour(vColor);
363 vColor.Set("WHITE");
364 m_brush.SetColour(vColor);
365} // end of wxDC::wxDC
366
367wxDC::~wxDC(void)
368{
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
397
398// This will select current objects out of the DC,
399// which is what you have to do before deleting the
400// DC.
401void wxDC::SelectOldObjects(
402 WXHDC hPS
403)
404{
405 if (hPS)
406 {
407 if (m_hOldBitmap)
408 {
409 ::GpiSetBitmap(hPS, (HBITMAP) m_hOldBitmap);
410 if (m_vSelectedBitmap.Ok())
411 {
412 m_vSelectedBitmap.SetSelectedInto(NULL);
413 }
414 }
415 m_hOldBitmap = 0;
416 //
417 // OS/2 has no other native GDI objects to set in a PS/DC like windows
418 //
419 m_hOldPen = 0;
420 m_hOldBrush = 0;
421 m_hOldFont = 0;
422 m_hOldPalette = 0;
423 }
424
425 m_brush = wxNullBrush;
426 m_pen = wxNullPen;
427 m_palette = wxNullPalette;
428 m_font = wxNullFont;
429 m_backgroundBrush = wxNullBrush;
430 m_vSelectedBitmap = wxNullBitmap;
431} // end of wxDC::SelectOldObjects
432
433// ---------------------------------------------------------------------------
434// clipping
435// ---------------------------------------------------------------------------
436
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); \
447}
448
449void wxDC::DoSetClippingRegion(
450 wxCoord vX
451, wxCoord vY
452, wxCoord vWidth
453, wxCoord vHeight
454)
455{
456 RECTL vRect;
457
458 vY = OS2Y(vY,vHeight);
459 m_clipping = TRUE;
460 vRect.xLeft = vX;
461 vRect.yTop = vY + vHeight;
462 vRect.xRight = vX + vWidth;
463 vRect.yBottom = vY;
464 ::GpiIntersectClipRectangle(m_hPS, &vRect);
465 DO_SET_CLIPPING_BOX()
466} // end of wxDC::DoSetClippingRegion
467
468void wxDC::DoSetClippingRegionAsRegion(
469 const wxRegion& rRegion
470)
471{
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
482
483void wxDC::DestroyClippingRegion(void)
484{
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
505
506// ---------------------------------------------------------------------------
507// query capabilities
508// ---------------------------------------------------------------------------
509
510bool wxDC::CanDrawBitmap() const
511{
512 return TRUE;
513}
514
515bool wxDC::CanGetTextExtent() const
516{
517 LONG lTechnology = 0L;
518
519 ::DevQueryCaps(GetHDC(), CAPS_TECHNOLOGY, 1L, &lTechnology);
520 return (lTechnology == CAPS_TECH_RASTER_DISPLAY) || (lTechnology == CAPS_TECH_RASTER_PRINTER);
521} // end of wxDC::CanGetTextExtent
522
523int wxDC::GetDepth() const
524{
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
538
539// ---------------------------------------------------------------------------
540// drawing
541// ---------------------------------------------------------------------------
542
543void wxDC::Clear()
544{
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
557 ::GpiErase(m_hPS);
558} // end of wxDC::Clear
559
560bool wxDC::DoFloodFill(
561 wxCoord vX
562, wxCoord vY
563, const wxColour& rCol
564, int nStyle
565)
566{
567 POINTL vPtlPos;
568 LONG lColor;
569 LONG lOptions;
570 LONG lHits;
571 bool bSuccess = FALSE;
572
573 vPtlPos.x = vX; // Loads x-coordinate
574 vPtlPos.y = OS2Y(vY,0); // Loads y-coordinate
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
581 if ((lHits = ::GpiFloodFill(m_hPS, lOptions, lColor)) != GPI_ERROR)
582 bSuccess = TRUE;
583 return TRUE;
584} // end of wxDC::DoFloodFill
585
586bool wxDC::DoGetPixel(
587 wxCoord vX
588, wxCoord vY
589, wxColour* pCol
590) const
591{
592 POINTL vPoint;
593 LONG lColor;
594
595 vPoint.x = vX;
596 vPoint.y = OS2Y(vY,0);
597 lColor = ::GpiSetPel(m_hPS, &vPoint);
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
619
620void wxDC::DoCrossHair(
621 wxCoord vX
622, wxCoord vY
623)
624{
625 vY = OS2Y(vY,0);
626
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;
634 vPoint[0].y = vY;
635
636 vPoint[1].x = vX2;
637 vPoint[1].y = vY;
638
639 ::GpiMove(m_hPS, &vPoint[0]);
640 ::GpiLine(m_hPS, &vPoint[1]);
641
642 vPoint[2].x = vX;
643 vPoint[2].y = vY1;
644
645 vPoint[3].x = vX;
646 vPoint[3].y = vY2;
647
648 ::GpiMove(m_hPS, &vPoint[2]);
649 ::GpiLine(m_hPS, &vPoint[3]);
650 CalcBoundingBox(vX1, vY1);
651 CalcBoundingBox(vX2, vY2);
652} // end of wxDC::DoCrossHair
653
654void wxDC::DoDrawLine(
655 wxCoord vX1
656, wxCoord vY1
657, wxCoord vX2
658, wxCoord vY2
659)
660{
661 POINTL vPoint[2];
662
663 vY1 = OS2Y(vY1,0);
664 vY2 = OS2Y(vY2,0);
665
666 vPoint[0].x = vX1;
667 vPoint[0].y = vY1;
668 vPoint[1].x = vX2;
669 vPoint[1].y = vY2;
670 ::GpiMove(m_hPS, &vPoint[0]);
671 ::GpiLine(m_hPS, &vPoint[1]);
672 CalcBoundingBox(vX1, vY1);
673 CalcBoundingBox(vX2, vY2);
674} // end of wxDC::DoDrawLine
675
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)
690{
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);
733 DoDrawArc( vX1, vY1
734 ,vXm, vYm
735 ,vXc, vYc
736 );
737 DoDrawArc( vXm, vYm
738 ,vX2, vY2
739 ,vXc, vYc
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
763 vPtlArc[0].x = vXm;
764 vPtlArc[0].y = vYm;
765 vPtlArc[1].x = vX2;
766 vPtlArc[1].y = vY2;
767 ::GpiPointArc(m_hPS, vPtlArc); // Draws the arc
768 CalcBoundingBox( (vXc - dRadius)
769 ,(vYc - dRadius)
770 );
771 CalcBoundingBox( (vXc + dRadius)
772 ,(vYc + dRadius)
773 );
774} // end of wxDC::DoDrawArc
775
776void wxDC::DoDrawCheckMark(
777 wxCoord vX1
778, wxCoord vY1
779, wxCoord vWidth
780, wxCoord vHeight
781)
782{
783 POINTL vPoint[2];
784
785 vY1 = OS2Y(vY1,vHeight);
786
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 }
813 CalcBoundingBox( vX1
814 ,vY1
815 );
816
817 wxCoord vX2 = vX1 + vWidth;
818 wxCoord vY2 = vY1 + vHeight;
819
820 CalcBoundingBox( vX2
821 ,vY2
822 );
823} // end of wxDC::DoDrawCheckMark
824
825void wxDC::DoDrawPoint(
826 wxCoord vX
827, wxCoord vY
828)
829{
830 POINTL vPoint;
831 COLORREF vColor = 0x00ffffff;
832
833 if (m_pen.Ok())
834 {
835 vColor = m_pen.GetColour().GetPixel();
836 }
837 ::GpiSetColor(m_hPS, vColor);
838 vPoint.x = vX;
839 vPoint.y = OS2Y(vY,0);
840 ::GpiSetPel(m_hPS, &vPoint);
841 CalcBoundingBox( vX
842 ,vY
843 );
844} // end of wxDC::DoDrawPoint
845
846void wxDC::DoDrawPolygon(
847 int n
848, wxPoint vPoints[]
849, wxCoord vXoffset
850, wxCoord vYoffset
851, int nFillStyle
852)
853{
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 {
900 vPlgn.aPointl[i].x = vPoints[i].x; // +xoffset;
901 vPlgn.aPointl[i].y = OS2Y(vPoints[i].y,0); // +yoffset;
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;
910 vPoint.y = OS2Y(vYoffset,0);
911
912 ::GpiSetColor(m_hPS, lBorderColor);
913 ::GpiMove(m_hPS, &vPoint);
914 lHits = ::GpiPolygons(m_hPS, ulCount, &vPlgn, flOptions, flModel);
915 free(vPlgn.aPointl);
916} // end of wxDC::DoDrawPolygon
917
918void wxDC::DoDrawLines(
919 int n
920, wxPoint vPoints[]
921, wxCoord vXoffset
922, wxCoord vYoffset
923)
924{
925 POINTL vPoint;
926
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);
934
935 LONG lBorderColor = m_pen.GetColour().GetPixel();
936
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
946 {
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 }
965 }
966} // end of wxDC::DoDrawLines
967
968void wxDC::DoDrawRectangle(
969 wxCoord vX
970, wxCoord vY
971, wxCoord vWidth
972, wxCoord vHeight
973)
974{
975 POINTL vPoint[2];
976 LONG lControl;
977 LONG lColor;
978 LONG lBorderColor;
979 int nIsTRANSPARENT = 0;
980
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);
989
990 wxCoord vX2 = vX + vWidth;
991 wxCoord vY2 = vY + vHeight;
992
993 vPoint[0].x = vX;
994 vPoint[0].y = vY;
995 vPoint[1].x = vX + vWidth;
996 vPoint[1].y = vY + vHeight;
997 ::GpiMove(m_hPS, &vPoint[0]);
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
1008 ::GpiSetColor(m_hPS, lColor);
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 );
1032 vPoint[0].x = vX + 1;
1033 vPoint[0].y = vY + 1;
1034 vPoint[1].x = vX + vWidth - 1;
1035 vPoint[1].y = vY + vHeight - 1;
1036 ::GpiMove(m_hPS, &vPoint[0]);
1037 ::GpiBox( m_hPS
1038 ,lControl
1039 ,&vPoint[1]
1040 ,0L
1041 ,0L
1042 );
1043 //
1044 // Debug testing:
1045 //
1046 for (int i = 0; i < vHeight; i++)
1047 {
1048 for (int j = 0; j < vHeight; j++)
1049 {
1050 vPoint[0].x = j; vPoint[0].y = i;
1051 lColor = ::GpiQueryPel(m_hPS, &vPoint[0]);
1052 }
1053 }
1054 }
1055 CalcBoundingBox(vX, vY);
1056 CalcBoundingBox(vX2, vY2);
1057} // end of wxDC::DoDrawRectangle
1058
1059void wxDC::DoDrawRoundedRectangle(
1060 wxCoord vX
1061, wxCoord vY
1062, wxCoord vWidth
1063, wxCoord vHeight
1064, double dRadius
1065)
1066{
1067 POINTL vPoint[2];
1068 LONG lControl;
1069
1070 vY = OS2Y(vY,vHeight);
1071
1072 wxCoord vX2 = (vX + vWidth);
1073 wxCoord vY2 = (vY + vHeight);
1074
1075 vPoint[0].x = vX;
1076 vPoint[0].y = YLOG2DEV(vY) - vHeight;
1077 vPoint[1].x = vX + vWidth;
1078 vPoint[1].y = vY;
1079 ::GpiMove(m_hPS, &vPoint[0]);
1080
1081 lControl = DRO_OUTLINEFILL; //DRO_FILL;
1082 if (m_brush.GetStyle() == wxTRANSPARENT)
1083 lControl = DRO_OUTLINE;
1084 ::GpiBox( m_hPS // handle to a presentation space
1085 ,DRO_OUTLINE // draw the box outline ? or ?
1086 ,&vPoint[1] // address of the corner
1087 ,(LONG)dRadius // horizontal corner radius
1088 ,(LONG)dRadius // vertical corner radius
1089 );
1090 CalcBoundingBox(vX, vY);
1091 CalcBoundingBox(vX2, vY2);
1092} // end of wxDC::DoDrawRoundedRectangle
1093
1094// Draw Ellipse within box (x,y) - (x+width, y+height)
1095void wxDC::DoDrawEllipse(
1096 wxCoord vX
1097, wxCoord vY
1098, wxCoord vWidth
1099, wxCoord vHeight
1100)
1101{
1102 POINTL vPtlPos; // Structure for current position
1103 FIXED vFxMult; // Multiplier for ellipse
1104 ARCPARAMS vArcp; // Structure for arc parameters
1105
1106 vY = OS2Y(vY,vHeight);
1107
1108 vArcp.lR = 0;
1109 vArcp.lQ = vHeight/2;
1110 vArcp.lP = vWidth/2;
1111 vArcp.lS = 0;
1112 ::GpiSetArcParams( m_hPS
1113 ,&vArcp
1114 ); // Sets parameters to default
1115 vPtlPos.x = vX + vWidth/2; // Loads x-coordinate
1116 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
1117 ::GpiMove( m_hPS
1118 ,&vPtlPos
1119 ); // Sets current position
1120 vFxMult = MAKEFIXED(1, 0); /* Sets multiplier */
1121
1122 //
1123 // DRO_FILL, DRO_OTLINEFILL - where to get
1124 //
1125 ::GpiFullArc( m_hPS
1126 ,DRO_OUTLINE
1127 ,vFxMult
1128 ); // Draws full arc with center at current position
1129
1130 wxCoord vX2 = (vX + vWidth);
1131 wxCoord vY2 = (vY + vHeight);
1132
1133 CalcBoundingBox(vX, vY);
1134 CalcBoundingBox(vX2, vY2);
1135} // end of wxDC::DoDrawEllipse
1136
1137void wxDC::DoDrawEllipticArc(
1138 wxCoord vX
1139, wxCoord vY
1140, wxCoord vWidth
1141, wxCoord vHeight
1142, double dSa
1143, double dEa
1144)
1145{
1146 POINTL vPtlPos; // Structure for current position
1147 FIXED vFxMult; // Multiplier for ellipse
1148 ARCPARAMS vArcp; // Structure for arc parameters
1149 FIXED vFSa;
1150 FIXED vFSweepa; // Start angle, sweep angle
1151 double dIntPart;
1152 double dFractPart;
1153 double dRadius;
1154
1155 vY = OS2Y(vY,vHeight);
1156
1157 dFractPart = modf(dSa,&dIntPart);
1158 vFSa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
1159 dFractPart = modf(dEa - dSa, &dIntPart);
1160 vFSweepa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
1161
1162 //
1163 // Ellipse main axis (r,q), (p,s) with center at (0,0)
1164 //
1165 vArcp.lR = 0;
1166 vArcp.lQ = vHeight/2;
1167 vArcp.lP = vWidth/2;
1168 vArcp.lS = 0;
1169 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
1170 vPtlPos.x = vX + vWidth/2 * (1. + cos(DegToRad(dSa))); // Loads x-coordinate
1171 vPtlPos.y = vY + vHeight/2 * (1. + sin(DegToRad(dSa))); // Loads y-coordinate
1172 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
1173
1174 //
1175 // May be not to the center ?
1176 //
1177 vPtlPos.x = vX + vWidth/2 ; // Loads x-coordinate
1178 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
1179 vFxMult = MAKEFIXED(1, 0); // Sets multiplier
1180
1181 //
1182 // DRO_FILL, DRO_OTLINEFILL - where to get
1183 //
1184 ::GpiPartialArc( m_hPS
1185 ,&vPtlPos
1186 ,vFxMult
1187 ,vFSa
1188 ,vFSweepa
1189 );
1190 wxCoord vX2 = (vX + vWidth);
1191 wxCoord vY2 = (vY + vHeight);
1192
1193 CalcBoundingBox(vX, vY);
1194 CalcBoundingBox(vX2, vY2);
1195} // end of wxDC::DoDrawEllipticArc
1196
1197void wxDC::DoDrawIcon(
1198 const wxIcon& rIcon
1199, wxCoord vX
1200, wxCoord vY
1201)
1202{
1203 vY = OS2Y(vY,rIcon.GetHeight());
1204 wxCHECK_RET( rIcon.Ok(), wxT("invalid icon in DrawIcon") );
1205
1206 ::WinDrawPointer( GetHPS()
1207 ,vX
1208 ,vY
1209 ,(HPOINTER)GetHiconOf(rIcon)
1210 ,DP_NORMAL
1211 );
1212 CalcBoundingBox(vX, vY);
1213 CalcBoundingBox(vX + rIcon.GetWidth(), vY + rIcon.GetHeight());
1214} // end of wxDC::DoDrawIcon
1215
1216void wxDC::DoDrawBitmap(
1217 const wxBitmap& rBmp
1218, wxCoord vX
1219, wxCoord vY
1220, bool bUseMask
1221)
1222{
1223 if (!bUseMask && !IsKindOf(CLASSINFO(wxPrinterDC)))
1224 {
1225 HBITMAP hBitmap = (HBITMAP)rBmp.GetHBITMAP();
1226 wxBitmap vNewBitmap( rBmp.GetWidth()
1227 ,rBmp.GetHeight()
1228 ,rBmp.GetDepth()
1229 );
1230 HBITMAP hBitmapOld = ::GpiSetBitmap((HPS)GetHPS(), vNewBitmap.GetHBITMAP());
1231 LONG lOldTextground = ::GpiQueryColor((HPS)GetHPS());
1232 LONG lOldBackground = ::GpiQueryBackColor((HPS)GetHPS());
1233
1234 if (m_textForegroundColour.Ok())
1235 {
1236 ::GpiSetColor( (HPS)GetHPS()
1237 ,m_textForegroundColour.GetPixel()
1238 );
1239 }
1240 if (m_textBackgroundColour.Ok())
1241 {
1242 ::GpiSetBackColor( (HPS)GetHPS()
1243 ,m_textBackgroundColour.GetPixel()
1244 );
1245 }
1246
1247 vY = OS2Y(vY,rBmp.GetHeight());
1248
1249 //
1250 // Flip the picture as OS/2 is upside-down
1251 //
1252 POINTL vPoint[4] = { vX, vY + rBmp.GetHeight()
1253 ,vX + rBmp.GetWidth(), vY
1254 ,0, 0
1255 ,rBmp.GetWidth(), rBmp.GetHeight()
1256 };
1257 ::GpiWCBitBlt( (HPS)GetHPS()
1258 ,hBitmap
1259 ,4
1260 ,vPoint
1261 ,ROP_SRCCOPY
1262 ,BBO_IGNORE
1263 );
1264 ::GpiSetBitmap((HPS)GetHPS(), hBitmapOld);
1265 ::GpiSetColor((HPS)GetHPS(), lOldTextground);
1266 ::GpiSetBackColor((HPS)GetHPS(), lOldBackground);
1267 }
1268} // end of wxDC::DoDrawBitmap
1269
1270void wxDC::DoDrawText(
1271 const wxString& rsText
1272, wxCoord vX
1273, wxCoord vY
1274)
1275{
1276 wxCoord vWidth;
1277 wxCoord vHeight;
1278
1279 DrawAnyText( rsText
1280 ,vX
1281 ,vY
1282 );
1283
1284 CalcBoundingBox(vX, vY);
1285 GetTextExtent(rsText, &vWidth, &vHeight);
1286 CalcBoundingBox((vX + vWidth), (vY + vHeight));
1287} // end of wxDC::DoDrawText
1288
1289void wxDC::DrawAnyText(
1290 const wxString& rsText
1291, wxCoord vX
1292, wxCoord vY
1293)
1294{
1295 int nOldBackground = 0;
1296 POINTL vPtlStart;
1297 LONG lHits;
1298 wxCoord vTextX = 0;
1299 wxCoord vTextY = 0;
1300
1301 //
1302 // prepare for drawing the text
1303 //
1304
1305 //
1306 // Set text color attributes
1307 //
1308 if (m_textForegroundColour.Ok())
1309 {
1310 SetTextColor( m_hPS
1311 ,(int)m_textForegroundColour.GetPixel()
1312 );
1313 }
1314
1315 if (m_textBackgroundColour.Ok())
1316 {
1317 nOldBackground = SetTextBkColor( m_hPS
1318 ,(int)m_textBackgroundColour.GetPixel()
1319 );
1320 }
1321 SetBkMode( m_hPS
1322 ,m_backgroundMode
1323 );
1324 GetTextExtent( rsText
1325 ,&vTextX
1326 ,&vTextY
1327 );
1328 vPtlStart.x = vX;
1329 vPtlStart.y = OS2Y(vY,vTextY);
1330
1331 lHits = ::GpiCharStringAt( m_hPS
1332 ,&vPtlStart
1333 ,rsText.length()
1334 ,(PCH)rsText.c_str()
1335 );
1336 if (lHits != GPI_OK)
1337 {
1338 wxLogLastError(wxT("TextOut"));
1339 }
1340
1341 //
1342 // Restore the old parameters (text foreground colour may be left because
1343 // it never is set to anything else, but background should remain
1344 // transparent even if we just drew an opaque string)
1345 //
1346 if (m_textBackgroundColour.Ok())
1347 SetTextBkColor( m_hPS
1348 ,nOldBackground
1349 );
1350 SetBkMode( m_hPS
1351 ,wxTRANSPARENT
1352 );
1353}
1354
1355void wxDC::DoDrawRotatedText(
1356 const wxString& rsText
1357, wxCoord vX
1358, wxCoord vY
1359, double dAngle
1360)
1361{
1362 if (dAngle == 0.0)
1363 {
1364 DoDrawText( rsText
1365 ,vX
1366 ,vY
1367 );
1368 }
1369
1370 // TODO:
1371 /*
1372 if ( angle == 0.0 )
1373 {
1374 DoDrawText(text, x, y);
1375 }
1376 else
1377 {
1378 LOGFONT lf;
1379 wxFillLogFont(&lf, &m_font);
1380
1381 // GDI wants the angle in tenth of degree
1382 long angle10 = (long)(angle * 10);
1383 lf.lfEscapement = angle10;
1384 lf. lfOrientation = angle10;
1385
1386 HFONT hfont = ::CreateFontIndirect(&lf);
1387 if ( !hfont )
1388 {
1389 wxLogLastError("CreateFont");
1390 }
1391 else
1392 {
1393 HFONT hfontOld = ::SelectObject(GetHdc(), hfont);
1394
1395 DrawAnyText(text, x, y);
1396
1397 (void)::SelectObject(GetHdc(), hfontOld);
1398 }
1399
1400 // call the bounding box by adding all four vertices of the rectangle
1401 // containing the text to it (simpler and probably not slower than
1402 // determining which of them is really topmost/leftmost/...)
1403 wxCoord w, h;
1404 GetTextExtent(text, &w, &h);
1405
1406 double rad = DegToRad(angle);
1407
1408 // "upper left" and "upper right"
1409 CalcBoundingBox(x, y);
1410 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
1411 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1412
1413 // "bottom left" and "bottom right"
1414 x += (wxCoord)(h*sin(rad));
1415 y += (wxCoord)(h*cos(rad));
1416 CalcBoundingBox(x, y);
1417 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1418 }
1419*/
1420}
1421
1422// ---------------------------------------------------------------------------
1423// set GDI objects
1424// ---------------------------------------------------------------------------
1425
1426void wxDC::DoSelectPalette(
1427 bool bRealize
1428)
1429{
1430 //
1431 // Set the old object temporarily, in case the assignment deletes an object
1432 // that's not yet selected out.
1433 //
1434 if (m_hOldPalette)
1435 {
1436 m_hOldPalette = 0;
1437 }
1438
1439 if (m_palette.Ok())
1440 {
1441 HPALETTE hOldPal;
1442
1443 hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE());
1444 if (!m_hOldPalette)
1445 m_hOldPalette = (WXHPALETTE)hOldPal;
1446 }
1447} // end of wxDC::DoSelectPalette
1448
1449void wxDC::InitializePalette()
1450{
1451 if (wxDisplayDepth() <= 8 )
1452 {
1453 //
1454 // Look for any window or parent that has a custom palette. If any has
1455 // one then we need to use it in drawing operations
1456 //
1457 wxWindow* pWin = m_pCanvas->GetAncestorWithCustomPalette();
1458
1459 m_hasCustomPalette = pWin && pWin->HasCustomPalette();
1460 if (m_hasCustomPalette)
1461 {
1462 m_palette = pWin->GetPalette();
1463
1464 //
1465 // turn on PM translation for this palette
1466 //
1467 DoSelectPalette();
1468 }
1469 }
1470} // end of wxDC::InitializePalette
1471
1472void wxDC::SetPalette(
1473 const wxPalette& rPalette
1474)
1475{
1476 if (m_hOldFont)
1477 {
1478 m_hOldFont = 0;
1479 }
1480 m_palette = rPalette;
1481 if (!rPalette.Ok())
1482 {
1483 if (m_hOldFont)
1484 {
1485 m_hOldFont = 0;
1486 }
1487 }
1488 HPALETTE hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE());
1489 if (!m_hOldPalette)
1490 m_hOldPalette = (WXHPALETTE)hOldPal;
1491} // end of wxDC::SetPalette
1492
1493void wxDC::SetFont(
1494 const wxFont& rFont
1495)
1496{
1497 //
1498 // Set the old object temporarily, in case the assignment deletes an object
1499 // that's not yet selected out.
1500 //
1501 if (m_hOldFont)
1502 {
1503 m_hOldFont = 0;
1504 }
1505 m_font = rFont;
1506 if (!rFont.Ok())
1507 {
1508 m_hOldFont = 0;
1509 }
1510
1511 m_font.SetPS(m_hPS); // this will realize the font
1512
1513 if (m_font.Ok())
1514 {
1515 HFONT hFont = m_font.GetResourceHandle();
1516 if (hFont == (HFONT) NULL)
1517 {
1518 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1519 }
1520 if (!m_hOldFont)
1521 m_hOldFont = (WXHFONT) hFont;
1522 }
1523} // end of wxDC::SetFont
1524
1525void wxDC::SetPen(
1526 const wxPen& rPen
1527)
1528{
1529 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1530
1531 if (m_pen == rPen)
1532 return;
1533 m_pen = rPen;
1534 if (!m_pen.Ok())
1535 return;
1536
1537 if (m_hOldPen)
1538 m_hOldPen = 0L;
1539 m_pen = rPen;
1540
1541 if (!m_pen.Ok())
1542 {
1543 if (m_hOldPen)
1544 {
1545 m_pen.SetPS((HPS)m_hOldPen);
1546 }
1547 m_hOldPen = 0L;
1548 }
1549
1550 if (m_pen.Ok())
1551 {
1552 if (m_pen.GetResourceHandle())
1553 {
1554 m_pen.SetPS(m_hPS);
1555 if (!m_hOldPen)
1556 m_hOldPen = m_pen.GetPS();
1557 }
1558 }
1559}
1560
1561void wxDC::SetBrush(
1562 const wxBrush& rBrush
1563)
1564{
1565 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1566
1567 if (m_hOldBrush)
1568 m_hOldBrush = 0L;
1569 m_brush = rBrush;
1570 if (!m_brush.Ok())
1571 if (m_brush == rBrush)
1572 return;
1573 if (!m_brush.Ok())
1574 if (m_hOldBrush)
1575 m_hOldBrush = 0L;
1576
1577 if (!m_brush.Ok())
1578 {
1579 if (m_hOldBrush)
1580 {
1581 m_brush.SetPS((HPS)m_hOldBrush);
1582 }
1583 m_hOldBrush = 0L;
1584 }
1585
1586 if (m_brush.Ok())
1587 {
1588 if (m_brush.GetResourceHandle())
1589 {
1590 m_brush.SetPS(m_hPS);
1591 if (!m_hOldBrush)
1592 m_hOldBrush = (WXHWND)m_brush.GetPS();
1593 }
1594 }
1595} // end of wxDC::SetBrush
1596
1597void wxDC::SetBackground(
1598 const wxBrush& rBrush
1599)
1600{
1601 m_backgroundBrush = rBrush;
1602 if (!m_backgroundBrush.Ok())
1603 return;
1604 if (m_pCanvas)
1605 {
1606 bool bCustomColours = TRUE;
1607
1608 //
1609 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
1610 // change background colours from the control-panel specified colours.
1611 //
1612 if (m_pCanvas->IsKindOf(CLASSINFO(wxWindow)) &&
1613 ((m_pCanvas->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS))
1614 bCustomColours = FALSE;
1615 if (bCustomColours)
1616 {
1617 if (m_backgroundBrush.GetStyle()==wxTRANSPARENT)
1618 {
1619 m_pCanvas->SetTransparent(TRUE);
1620 }
1621 else
1622 {
1623 //
1624 // Setting the background brush of a DC
1625 // doesn't affect the window background colour. However,
1626 // I'm leaving in the transparency setting because it's needed by
1627 // various controls (e.g. wxStaticText) to determine whether to draw
1628 // transparently or not. TODO: maybe this should be a new function
1629 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
1630 // parent?
1631 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
1632 //
1633 m_pCanvas->SetTransparent(FALSE);
1634 }
1635 }
1636 }
1637 COLORREF vNewColor = m_backgroundBrush.GetColour().GetPixel();
1638 (void)::GpiSetBackColor((HPS)m_hPS, (LONG)vNewColor);
1639} // end of wxDC::SetBackground
1640
1641void wxDC::SetBackgroundMode(
1642 int nMode
1643)
1644{
1645 m_backgroundMode = nMode;
1646} // end of wxDC::SetBackgroundMode
1647
1648void wxDC::SetLogicalFunction(
1649 int nFunction
1650)
1651{
1652 m_logicalFunction = nFunction;
1653 SetRop((WXHDC)m_hDC);
1654} // wxDC::SetLogicalFunction
1655
1656void wxDC::SetRop(
1657 WXHDC hDC
1658)
1659{
1660 if (!hDC || m_logicalFunction < 0)
1661 return;
1662
1663 LONG lCRop;
1664 switch (m_logicalFunction)
1665 {
1666 case wxXOR:
1667 lCRop = FM_XOR;
1668 break;
1669
1670 case wxINVERT:
1671 lCRop = FM_INVERT;
1672 break;
1673
1674 case wxOR_REVERSE:
1675 lCRop = FM_MERGESRCNOT;
1676 break;
1677
1678 case wxAND_REVERSE:
1679 lCRop = FM_NOTMASKSRC;
1680 break;
1681
1682 case wxCLEAR:
1683 lCRop = FM_ONE;
1684 break;
1685
1686 case wxSET:
1687 lCRop = FM_ZERO;
1688 break;
1689
1690 case wxSRC_INVERT:
1691 lCRop = FM_MERGENOTSRC;
1692 break;
1693
1694 case wxOR_INVERT:
1695 lCRop = FM_MERGESRCNOT;
1696 break;
1697
1698 case wxAND:
1699 lCRop = FM_AND;
1700 break;
1701
1702 case wxOR:
1703 lCRop = FM_OR;
1704 break;
1705
1706 case wxAND_INVERT:
1707 lCRop = FM_SUBTRACT;
1708 break;
1709
1710 case wxEQUIV:
1711 case wxNAND:
1712 case wxCOPY:
1713 default:
1714 lCRop = FM_OVERPAINT;
1715 break;
1716 }
1717 ::GpiSetMix((HPS)hDC, lCRop);
1718} // end of wxDC::SetRop
1719
1720bool wxDC::StartDoc(
1721 const wxString& rsMessage
1722)
1723{
1724 // We might be previewing, so return TRUE to let it continue.
1725 return TRUE;
1726} // end of wxDC::StartDoc
1727
1728void wxDC::EndDoc()
1729{
1730} // end of wxDC::EndDoc
1731
1732void wxDC::StartPage()
1733{
1734} // end of wxDC::StartPage
1735
1736void wxDC::EndPage()
1737{
1738} // end of wxDC::EndPage
1739
1740// ---------------------------------------------------------------------------
1741// text metrics
1742// ---------------------------------------------------------------------------
1743
1744wxCoord wxDC::GetCharHeight() const
1745{
1746 FONTMETRICS vFM; // metrics structure
1747
1748 ::GpiQueryFontMetrics( m_hPS
1749 ,sizeof(FONTMETRICS)
1750 ,&vFM
1751 );
1752 return YDEV2LOGREL(vFM.lXHeight);
1753}
1754
1755wxCoord wxDC::GetCharWidth() const
1756{
1757 FONTMETRICS vFM; // metrics structure
1758
1759 ::GpiQueryFontMetrics( m_hPS
1760 ,sizeof(FONTMETRICS)
1761 ,&vFM
1762 );
1763 return XDEV2LOGREL(vFM.lAveCharWidth);
1764}
1765
1766void wxDC::DoGetTextExtent(
1767 const wxString& rsString
1768, wxCoord* pvX
1769, wxCoord* pvY
1770, wxCoord* pvDescent
1771, wxCoord* pvExternalLeading
1772, wxFont* pTheFont
1773) const
1774{
1775 POINTL avPoint[TXTBOX_COUNT];
1776 POINTL vPtMin;
1777 POINTL vPtMax;
1778 int i;
1779 int l;
1780 FONTMETRICS vFM; // metrics structure
1781 BOOL bRc;
1782 char* pStr;
1783 ERRORID vErrorCode; // last error id code
1784 wxFont* pFontToUse = (wxFont*)pTheFont;
1785
1786 char zMsg[128]; // DEBUG
1787 wxString sError;
1788
1789 if (!pFontToUse)
1790 pFontToUse = (wxFont*)&m_font;
1791 l = rsString.length();
1792 pStr = (PCH) rsString.c_str();
1793
1794 //
1795 // In world coordinates.
1796 //
1797 bRc = ::GpiQueryTextBox( m_hPS
1798 ,l
1799 ,pStr
1800 ,TXTBOX_COUNT // return maximum information
1801 ,avPoint // array of coordinates points
1802 );
1803 if(!bRc)
1804 {
1805 vErrorCode = ::WinGetLastError(wxGetInstance());
1806 sError = wxPMErrorToStr(vErrorCode);
1807 // DEBUG
1808 sprintf(zMsg, "GpiQueryTextBox for %s: failed with Error: %x - %s", pStr, vErrorCode, sError.c_str());
1809 (void)wxMessageBox( "wxWindows Menu sample"
1810 ,zMsg
1811 ,wxICON_INFORMATION
1812 );
1813 }
1814
1815 vPtMin.x = avPoint[0].x;
1816 vPtMax.x = avPoint[0].x;
1817 vPtMin.y = avPoint[0].y;
1818 vPtMax.y = avPoint[0].y;
1819 for (i = 1; i < 4; i++)
1820 {
1821 if(vPtMin.x > avPoint[i].x) vPtMin.x = avPoint[i].x;
1822 if(vPtMin.y > avPoint[i].y) vPtMin.y = avPoint[i].y;
1823 if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x;
1824 if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y;
1825 }
1826 ::GpiQueryFontMetrics( m_hPS
1827 ,sizeof(FONTMETRICS)
1828 ,&vFM
1829 );
1830
1831 if (pvX)
1832 *pvX = (wxCoord)(vPtMax.x - vPtMin.x + 1);
1833 if (pvY)
1834 *pvY = (wxCoord)(vPtMax.y - vPtMin.y + 1);
1835 if (pvDescent)
1836 *pvDescent = vFM.lMaxDescender;
1837 if (pvExternalLeading)
1838 *pvExternalLeading = vFM.lExternalLeading;
1839}
1840
1841void wxDC::SetMapMode(
1842 int nMode
1843)
1844{
1845 int nPixelWidth = 0;
1846 int nPixelHeight = 0;
1847 int nMmWidth = 1;
1848 int nMmHeight = 1;
1849 LONG lArray[CAPS_VERTICAL_RESOLUTION];
1850
1851 m_mappingMode = nMode;
1852
1853 if(::DevQueryCaps( m_hDC
1854 ,CAPS_FAMILY
1855 ,CAPS_VERTICAL_RESOLUTION
1856 ,lArray
1857 ))
1858 {
1859 LONG lHorzRes;
1860 LONG lVertRes;
1861
1862 nPixelWidth = lArray[CAPS_WIDTH];
1863 nPixelHeight = lArray[CAPS_HEIGHT];
1864 lHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
1865 lVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
1866 nMmWidth = (lHorzRes/1000) * nPixelWidth;
1867 nMmWidth = (lVertRes/1000) * nPixelHeight;
1868 }
1869 if ((nPixelWidth == 0) || (nPixelHeight == 0) || (nMmWidth == 0) || (nMmHeight == 0))
1870 {
1871 return;
1872 }
1873
1874 double dMm2pixelsX = nPixelWidth/nMmWidth;
1875 double dMm2pixelsY = nPixelHeight/nMmHeight;
1876
1877 switch (nMode)
1878 {
1879 case wxMM_TWIPS:
1880 m_logicalScaleX = (twips2mm * dMm2pixelsX);
1881 m_logicalScaleY = (twips2mm * dMm2pixelsY);
1882 break;
1883
1884 case wxMM_POINTS:
1885 m_logicalScaleX = (pt2mm * dMm2pixelsX);
1886 m_logicalScaleY = (pt2mm * dMm2pixelsY);
1887 break;
1888
1889 case wxMM_METRIC:
1890 m_logicalScaleX = dMm2pixelsX;
1891 m_logicalScaleY = dMm2pixelsY;
1892 break;
1893
1894 case wxMM_LOMETRIC:
1895 m_logicalScaleX = (dMm2pixelsX/10.0);
1896 m_logicalScaleY = (dMm2pixelsY/10.0);
1897 break;
1898
1899 case wxMM_TEXT:
1900 default:
1901 m_logicalScaleX = 1.0;
1902 m_logicalScaleY = 1.0;
1903 break;
1904 }
1905 SIZEL vSize;
1906 ULONG ulOptions;
1907
1908 ulOptions = ::GpiQueryPS(m_hPS, &vSize);
1909 if (!ulOptions & PU_ARBITRARY)
1910 {
1911 ulOptions = PU_ARBITRARY | GPIF_DEFAULT;
1912 ::GpiSetPS(m_hPS, &vSize, ulOptions);
1913 }
1914 m_nWindowExtX = (int)MS_XDEV2LOG(VIEWPORT_EXTENT);
1915 m_nWindowExtY = (int)MS_YDEV2LOG(VIEWPORT_EXTENT);
1916 // ????
1917}; // end of wxDC::SetMapMode
1918
1919void wxDC::SetUserScale(
1920 double dX
1921, double dY
1922)
1923{
1924 m_userScaleX = dX;
1925 m_userScaleY = dY;
1926
1927 SetMapMode(m_mappingMode);
1928} // end of wxDC::SetUserScale
1929
1930void wxDC::SetAxisOrientation(
1931 bool bXLeftRight
1932, bool bYBottomUp
1933)
1934{
1935 m_signX = bXLeftRight ? 1 : -1;
1936 m_signY = bYBottomUp ? -1 : 1;
1937
1938 SetMapMode(m_mappingMode);
1939} // end of wxDC::SetAxisOrientation
1940
1941void wxDC::SetSystemScale(
1942 double dX
1943, double dY
1944)
1945{
1946 m_scaleX = dX;
1947 m_scaleY = dY;
1948
1949 SetMapMode(m_mappingMode);
1950} // end of wxDC::SetSystemScale
1951
1952void wxDC::SetLogicalOrigin(
1953 wxCoord vX
1954, wxCoord vY
1955)
1956{
1957 RECTL vRect;
1958
1959 ::GpiQueryPageViewport( m_hPS
1960 ,&vRect
1961 );
1962 vRect.xRight -= vX;
1963 vRect.yTop += vY;
1964 vRect.xLeft = vX;
1965 vRect.yBottom = vY;
1966 ::GpiSetPageViewport( m_hPS
1967 ,&vRect
1968 );
1969}; // end of wxDC::SetLogicalOrigin
1970
1971void wxDC::SetDeviceOrigin(
1972 wxCoord vX
1973, wxCoord vY
1974)
1975{
1976 RECTL vRect;
1977
1978 m_deviceOriginX = vX;
1979 m_deviceOriginY = vY;
1980 ::GpiQueryPageViewport( m_hPS
1981 ,&vRect
1982 );
1983 vRect.xLeft += vX;
1984 vRect.xRight += vX;
1985 vRect.yBottom -= vY;
1986 vRect.yTop -= vY;
1987 ::GpiSetPageViewport( m_hPS
1988 ,&vRect
1989 );
1990}; // end of wxDC::SetDeviceOrigin
1991
1992// ---------------------------------------------------------------------------
1993// coordinates transformations
1994// ---------------------------------------------------------------------------
1995
1996wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
1997{
1998 return (wxCoord) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX);
1999}
2000
2001wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
2002{
2003 // axis orientation is not taken into account for conversion of a distance
2004 return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_scaleX));
2005}
2006
2007wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
2008{
2009 return (wxCoord) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY);
2010}
2011
2012wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
2013{
2014 // axis orientation is not taken into account for conversion of a distance
2015 return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_scaleY));
2016}
2017
2018wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
2019{
2020 return (wxCoord) ((x - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX);
2021}
2022
2023wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
2024{
2025 // axis orientation is not taken into account for conversion of a distance
2026 return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_scaleX);
2027}
2028
2029wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
2030{
2031 return (wxCoord) ((y - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY);
2032}
2033
2034wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
2035{
2036 // axis orientation is not taken into account for conversion of a distance
2037 return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_scaleY);
2038}
2039
2040// ---------------------------------------------------------------------------
2041// bit blit
2042// ---------------------------------------------------------------------------
2043
2044bool wxDC::DoBlit(
2045 wxCoord vXdest
2046, wxCoord vYdest
2047, wxCoord vWidth
2048, wxCoord vHeight
2049, wxDC* pSource
2050, wxCoord vXsrc
2051, wxCoord vYsrc
2052, int nRop
2053, bool bUseMask
2054, wxCoord vXsrcMask
2055, wxCoord vYsrcMask
2056)
2057{
2058 wxMask* pMask = NULL;
2059 CHARBUNDLE vCbnd;
2060 COLORREF vOldTextColor;
2061 COLORREF vOldBackground = ::GpiQueryBackColor(m_hPS);
2062
2063 if (bUseMask)
2064 {
2065 const wxBitmap& rBmp = pSource->m_vSelectedBitmap;
2066
2067 pMask = rBmp.GetMask();
2068 if (!(rBmp.Ok() && pMask && pMask->GetMaskBitmap()))
2069 {
2070 bUseMask = FALSE;
2071 }
2072 }
2073
2074 ::GpiQueryAttrs( m_hPS
2075 ,PRIM_CHAR
2076 ,CBB_COLOR
2077 ,&vCbnd
2078 );
2079 vOldTextColor = (COLORREF)vCbnd.lColor;
2080
2081 if (m_textForegroundColour.Ok())
2082 {
2083 vCbnd.lColor = (LONG)m_textForegroundColour.GetPixel();
2084 ::GpiSetAttrs( m_hPS // presentation-space handle
2085 ,PRIM_CHAR // Char primitive.
2086 ,CBB_COLOR // sets color.
2087 ,0
2088 ,&vCbnd // buffer for attributes.
2089 );
2090 }
2091 if (m_textBackgroundColour.Ok())
2092 {
2093 ::GpiSetBackColor(m_hPS, (LONG)m_textBackgroundColour.GetPixel());
2094 }
2095
2096 LONG lRop = ROP_SRCCOPY;
2097
2098 switch (nRop)
2099 {
2100 case wxXOR: lRop = ROP_SRCINVERT; break;
2101 case wxINVERT: lRop = ROP_DSTINVERT; break;
2102 case wxOR_REVERSE: lRop = 0x00DD0228; break;
2103 case wxAND_REVERSE: lRop = ROP_SRCERASE; break;
2104 case wxCLEAR: lRop = ROP_ZERO; break;
2105 case wxSET: lRop = ROP_ONE; break;
2106 case wxOR_INVERT: lRop = ROP_MERGEPAINT; break;
2107 case wxAND: lRop = ROP_SRCAND; break;
2108 case wxOR: lRop = ROP_SRCPAINT; break;
2109 case wxEQUIV: lRop = 0x00990066; break;
2110 case wxNAND: lRop = 0x007700E6; break;
2111 case wxAND_INVERT: lRop = 0x00220326; break;
2112 case wxCOPY: lRop = ROP_SRCCOPY; break;
2113 case wxNO_OP: lRop = ROP_NOTSRCERASE; break;
2114 case wxSRC_INVERT: lRop = ROP_SRCINVERT; break;
2115 case wxNOR: lRop = ROP_NOTSRCCOPY; break;
2116 default:
2117 wxFAIL_MSG( wxT("unsupported logical function") );
2118 return FALSE;
2119 }
2120
2121 bool bSuccess;
2122
2123 if (bUseMask)
2124 {
2125 //
2126 // Blit bitmap with mask
2127 //
2128
2129 //
2130 // Create a temp buffer bitmap and DCs/PSs to access it and the mask
2131 //
2132 HDC hDCMask;
2133 HDC hDCBuffer;
2134 HPS hPSMask;
2135 HPS hPSBuffer;
2136 DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
2137 BITMAPINFOHEADER2 vBmpHdr;
2138 HBITMAP hBufBitmap;
2139 SIZEL vSize = {0, 0};
2140 LONG rc;
2141
2142 memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2));
2143 vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2);
2144 vBmpHdr.cx = vWidth;
2145 vBmpHdr.cy = vHeight;
2146 vBmpHdr.cPlanes = 1;
2147 vBmpHdr.cBitCount = 24;
2148
2149#if wxUSE_DC_CACHEING
2150 if (TRUE)
2151 {
2152 //
2153 // create a temp buffer bitmap and DCs to access it and the mask
2154 //
2155 wxDCCacheEntry* pDCCacheEntry1 = FindDCInCache( NULL
2156 ,pSource->GetHPS()
2157 );
2158 wxDCCacheEntry* pDCCacheEntry2 = FindDCInCache( pDCCacheEntry1
2159 ,GetHPS()
2160 );
2161 wxDCCacheEntry* pBitmapCacheEntry = FindBitmapInCache( GetHPS()
2162 ,vWidth
2163 ,vHeight
2164 );
2165
2166 hPSMask = pDCCacheEntry1->m_hPS;
2167 hDCBuffer = (HDC)pDCCacheEntry2->m_hPS;
2168 hBufBitmap = (HBITMAP)pBitmapCacheEntry->m_hBitmap;
2169 }
2170 else
2171#endif
2172 {
2173 hDCMask = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
2174 hDCBuffer = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
2175 hPSMask = ::GpiCreatePS(vHabmain, hDCMask, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
2176 hPSBuffer = ::GpiCreatePS(vHabmain, hDCBuffer, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
2177 hBufBitmap = ::GpiCreateBitmap(GetHPS(), &vBmpHdr, 0L, NULL, NULL);
2178 }
2179
2180 POINTL aPoint1[4] = { 0, 0
2181 ,vWidth, vHeight
2182 ,vXdest, vYdest
2183 ,vXdest + vWidth, vYdest + vHeight
2184 };
2185 POINTL aPoint2[4] = { 0, 0
2186 ,vWidth, vHeight
2187 ,vXsrc, vYsrc
2188 ,vXsrc + vWidth, vYsrc + vHeight
2189 };
2190 POINTL aPoint3[4] = { vXdest, vYdest
2191 ,vXdest + vWidth, vYdest + vHeight
2192 ,vXsrc, vYsrc
2193 ,vXsrc + vWidth, vYsrc + vHeight
2194 };
2195 POINTL aPoint4[4] = { vXdest, vYdest
2196 ,vXdest + vWidth, vYdest + vHeight
2197 ,0, 0
2198 ,vWidth, vHeight
2199 };
2200 ::GpiSetBitmap(hPSMask, (HBITMAP) pMask->GetMaskBitmap());
2201 ::GpiSetBitmap(hPSBuffer, (HBITMAP) hBufBitmap);
2202
2203 //
2204 // Copy dest to buffer
2205 //
2206 rc = ::GpiBitBlt( hPSBuffer
2207 ,GetHPS()
2208 ,4L
2209 ,aPoint1
2210 ,ROP_SRCCOPY
2211 ,BBO_IGNORE
2212 );
2213 if (rc == GPI_ERROR)
2214 {
2215 wxLogLastError(wxT("BitBlt"));
2216 }
2217
2218 //
2219 // Copy src to buffer using selected raster op
2220 //
2221 rc = ::GpiBitBlt( hPSBuffer
2222 ,GetHPS()
2223 ,4L
2224 ,aPoint2
2225 ,lRop
2226 ,BBO_IGNORE
2227 );
2228 if (rc == GPI_ERROR)
2229 {
2230 wxLogLastError(wxT("BitBlt"));
2231 }
2232
2233 //
2234 // Set masked area in buffer to BLACK (pixel value 0)
2235 //
2236 COLORREF vPrevBkCol = ::GpiQueryBackColor(GetHPS());
2237 COLORREF vPrevCol = ::GpiQueryColor(GetHPS());
2238
2239 ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255));
2240 ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0));
2241
2242 rc = ::GpiBitBlt( hPSBuffer
2243 ,hPSMask
2244 ,4L
2245 ,aPoint2
2246 ,ROP_SRCAND
2247 ,BBO_IGNORE
2248 );
2249 if (rc == GPI_ERROR)
2250 {
2251 wxLogLastError(wxT("BitBlt"));
2252 }
2253
2254 //
2255 // Set unmasked area in dest to BLACK
2256 //
2257 ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0));
2258 ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255));
2259 rc = ::GpiBitBlt( GetHPS()
2260 ,hPSMask
2261 ,4L
2262 ,aPoint3
2263 ,ROP_SRCAND
2264 ,BBO_IGNORE
2265 );
2266 if (rc == GPI_ERROR)
2267 {
2268 wxLogLastError(wxT("BitBlt"));
2269 }
2270
2271 //
2272 // Restore colours to original values
2273 //
2274 ::GpiSetBackColor(GetHPS(), vPrevBkCol);
2275 ::GpiSetColor(GetHPS(), vPrevCol);
2276
2277 //
2278 // OR buffer to dest
2279 //
2280 rc = ::GpiBitBlt( GetHPS()
2281 ,hPSMask
2282 ,4L
2283 ,aPoint4
2284 ,ROP_SRCPAINT
2285 ,BBO_IGNORE
2286 );
2287 if (rc == GPI_ERROR)
2288 {
2289 bSuccess = FALSE;
2290 wxLogLastError(wxT("BitBlt"));
2291 }
2292
2293 //
2294 // Tidy up temporary DCs and bitmap
2295 //
2296 ::GpiSetBitmap(hPSMask, NULLHANDLE);
2297 ::GpiSetBitmap(hPSBuffer, NULLHANDLE);
2298#if !wxUSE_DC_CACHEING
2299 ::GpiDestroyPS(hPSMask);
2300 ::GpiDestroyPS(hPSBuffer);
2301 ::DevCloseDC(hDCMask);
2302 ::DevCloseDC(hDCBuffer);
2303 ::GpiDeleteBitmap(hBufBitmap);
2304#endif
2305 bSuccess = TRUE;
2306 }
2307 else // no mask, just BitBlt() it
2308 {
2309 POINTL aPoint[4] = { vXdest, vYdest
2310 ,vXdest + vWidth, vYdest + vHeight
2311 ,vXsrc, vYsrc
2312 ,vXsrc + vWidth, vYsrc + vHeight
2313 };
2314
2315 bSuccess = (::GpiBitBlt( m_hPS
2316 ,pSource->GetHPS()
2317 ,4L
2318 ,aPoint
2319 ,lRop
2320 ,BBO_IGNORE
2321 ) != GPI_ERROR);
2322 if (!bSuccess )
2323 {
2324 wxLogLastError(wxT("BitBlt"));
2325 }
2326 }
2327 vCbnd.lColor = (LONG)vOldTextColor;
2328 ::GpiSetAttrs( m_hPS // presentation-space handle
2329 ,PRIM_CHAR // Char primitive.
2330 ,CBB_COLOR // sets color.
2331 ,0
2332 ,&vCbnd // buffer for attributes.
2333 );
2334 ::GpiSetBackColor(m_hPS, (LONG)vOldBackground);
2335 return bSuccess;
2336}
2337
2338void wxDC::DoGetSize(
2339 int* pnWidth
2340, int* pnHeight
2341) const
2342{
2343 LONG lArray[CAPS_HEIGHT];
2344
2345 if(::DevQueryCaps( m_hDC
2346 ,CAPS_FAMILY
2347 ,CAPS_HEIGHT
2348 ,lArray
2349 ))
2350 {
2351 *pnWidth = lArray[CAPS_WIDTH];
2352 *pnHeight = lArray[CAPS_HEIGHT];
2353 }
2354}; // end of wxDC::DoGetSize(
2355
2356void wxDC::DoGetSizeMM(
2357 int* pnWidth
2358, int* pnHeight
2359) const
2360{
2361 LONG lArray[CAPS_VERTICAL_RESOLUTION];
2362
2363 if(::DevQueryCaps( m_hDC
2364 ,CAPS_FAMILY
2365 ,CAPS_VERTICAL_RESOLUTION
2366 ,lArray
2367 ))
2368 {
2369 int nWidth;
2370 int nHeight;
2371 int nHorzRes;
2372 int nVertRes;
2373
2374 nWidth = lArray[CAPS_WIDTH];
2375 nHeight = lArray[CAPS_HEIGHT];
2376 nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
2377 nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
2378 nWidth = (nHorzRes/1000) * nWidth;
2379 nHeight = (nVertRes/1000) * nHeight;
2380 }
2381}; // end of wxDC::DoGetSizeMM
2382
2383wxSize wxDC::GetPPI() const
2384{
2385 LONG lArray[CAPS_VERTICAL_RESOLUTION];
2386 int nWidth;
2387 int nHeight;
2388
2389 if(::DevQueryCaps( m_hDC
2390 ,CAPS_FAMILY
2391 ,CAPS_VERTICAL_RESOLUTION
2392 ,lArray
2393 ))
2394 {
2395 int nPelWidth;
2396 int nPelHeight;
2397 int nHorzRes;
2398 int nVertRes;
2399
2400 nPelWidth = lArray[CAPS_WIDTH];
2401 nPelHeight = lArray[CAPS_HEIGHT];
2402 nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
2403 nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
2404 nWidth = (nHorzRes/39.3) * nPelWidth;
2405 nHeight = (nVertRes/39.3) * nPelHeight;
2406 }
2407 return (wxSize(nWidth,nHeight));
2408} // end of wxDC::GetPPI
2409
2410void wxDC::SetLogicalScale(
2411 double dX
2412, double dY
2413)
2414{
2415 m_logicalScaleX = dX;
2416 m_logicalScaleY = dY;
2417}; // end of wxDC::SetLogicalScale
2418
2419#if WXWIN_COMPATIBILITY
2420void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y,
2421 float *descent, float *externalLeading,
2422 wxFont *theFont, bool use16bit) const
2423{
2424 wxCoord x1, y1, descent1, externalLeading1;
2425 GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit);
2426 *x = x1; *y = y1;
2427 if (descent)
2428 *descent = descent1;
2429 if (externalLeading)
2430 *externalLeading = externalLeading1;
2431}
2432#endif
2433