1 /////////////////////////////////////////////////////////////////////////////
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
16 #include "wx/window.h"
19 #include "wx/dialog.h"
21 #include "wx/bitmap.h"
22 #include "wx/dcmemory.h"
25 #include "wx/msgdlg.h"
26 #include "wx/module.h"
29 #include "wx/dcprint.h"
34 #include "wx/os2/private.h"
36 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
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:
44 // Parent object height: POBJHEIGHT
45 // Desried origin: WXORIGINY
46 // Object to place's height: OBJHEIGHT
48 // To get the OS2 position from the wxWindows one:
50 // OS2Y = POBJHEIGHT - (WXORIGINY + OBJHEIGHT)
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.
57 #define OS2Y(y, objy) ((m_vRclPaint.yTop - m_vRclPaint.yBottom) - (y + objy))
59 // ---------------------------------------------------------------------------
61 // ---------------------------------------------------------------------------
63 static const int VIEWPORT_EXTENT
= 1000;
65 static const int MM_POINTS
= 9;
66 static const int MM_METRIC
= 10;
68 // usually this is defined in math.h
70 static const double M_PI
= 3.14159265358979323846;
73 // ---------------------------------------------------------------------------
75 // ---------------------------------------------------------------------------
77 // convert degrees to radians
78 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
82 , int nForegroundColour
87 vCbnd
.lColor
= nForegroundColour
;
88 ::GpiSetAttrs( hPS
// presentation-space handle
89 ,PRIM_CHAR
// Char primitive.
90 ,CBB_COLOR
// sets color.
92 ,&vCbnd
// buffer for attributes.
103 ::GpiQueryAttrs( hPS
// presentation-space handle
104 ,PRIM_CHAR
// Char primitive.
105 ,CBB_BACK_COLOR
// Background color.
106 ,&vCbnd
// buffer for attributes.
108 return vCbnd
.lBackColor
;
114 , int nBackgroundColour
120 rc
= QueryTextBkColor(hPS
);
122 vCbnd
.lBackColor
= nBackgroundColour
;
123 ::GpiSetAttrs(hPS
, // presentation-space handle
124 PRIM_CHAR
, // Char primitive.
125 CBB_BACK_COLOR
, // sets color.
127 &vCbnd
// buffer for attributes.
134 , int nBackgroundMode
137 if(nBackgroundMode
== wxTRANSPARENT
)
142 // the background of the primitive takes over whatever is underneath.
149 // ===========================================================================
151 // ===========================================================================
153 #if wxUSE_DC_CACHEING
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
161 // ---------------------------------------------------------------------------
163 // ---------------------------------------------------------------------------
165 wxList
wxDC::m_svBitmapCache
;
166 wxList
wxDC::m_svDCCache
;
168 wxDCCacheEntry::wxDCCacheEntry(
180 } // end of wxDCCacheEntry::wxDCCacheEntry
182 wxDCCacheEntry::wxDCCacheEntry(
187 m_hBitmap
= NULLHANDLE
;
192 } // end of wxDCCacheEntry::wxDCCacheEntry
194 wxDCCacheEntry::~wxDCCacheEntry()
197 ::GpiDeleteBitmap(m_hBitmap
);
199 ::GpiDestroyPS(m_hPS
);
200 } // end of wxDCCacheEntry::~wxDCCacheEntry
202 wxDCCacheEntry
* wxDC::FindBitmapInCache(
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
;
214 wxDCCacheEntry
* pEntry
= (wxDCCacheEntry
*)pNode
->Data();
216 if (pEntry
->m_nDepth
== nDepth
)
218 memset(&vBmpHdr
, 0, sizeof(BITMAPINFOHEADER2
));
220 if (pEntry
->m_nWidth
< nWidth
|| pEntry
->m_nHeight
< nHeight
)
222 ::GpiDeleteBitmap((HBITMAP
)pEntry
->m_hBitmap
);
223 vBmpHdr
.cbFix
= sizeof(BITMAPINFOHEADER2
);
225 vBmpHdr
.cy
= nHeight
;
227 vBmpHdr
.cBitCount
= nDepth
;
229 pEntry
->m_hBitmap
= (WXHBITMAP
) ::GpiCreateBitmap( hPS
233 if (!pEntry
->m_hBitmap
)
235 wxLogLastError(wxT("CreateCompatibleBitmap"));
237 pEntry
->m_nWidth
= nWidth
;
238 pEntry
->m_nHeight
= nHeight
;
243 pNode
= pNode
->Next();
245 memset(&vBmpHdr
, 0, sizeof(BITMAPINFOHEADER2
));
246 vBmpHdr
.cbFix
= sizeof(BITMAPINFOHEADER2
);
248 vBmpHdr
.cy
= nHeight
;
250 vBmpHdr
.cBitCount
= nDepth
;
252 WXHBITMAP hBitmap
= (WXHBITMAP
) ::GpiCreateBitmap( hPS
258 wxLogLastError(wxT("CreateCompatibleBitmap"));
260 wxDCCacheEntry
* pEntry
= new wxDCCacheEntry( hBitmap
265 AddToBitmapCache(pEntry
);
267 } // end of FindBitmapInCache
269 wxDCCacheEntry
* wxDC::FindDCInCache(
270 wxDCCacheEntry
* pNotThis
274 int nDepth
= 24; // we'll fix this up later ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
275 wxNode
* pNode
= m_svDCCache
.First();
279 wxDCCacheEntry
* pEntry
= (wxDCCacheEntry
*)pNode
->Data();
282 // Don't return the same one as we already have
284 if (!pNotThis
|| (pNotThis
!= pEntry
))
286 if (pEntry
->m_nDepth
== nDepth
)
291 pNode
= pNode
->Next();
293 wxDCCacheEntry
* pEntry
= new wxDCCacheEntry( hPS
296 AddToDCCache(pEntry
);
298 } // end of wxDC::FindDCInCache
300 void wxDC::AddToBitmapCache(
301 wxDCCacheEntry
* pEntry
304 m_svBitmapCache
.Append(pEntry
);
305 } // end of wxDC::AddToBitmapCache
307 void wxDC::AddToDCCache(
308 wxDCCacheEntry
* pEntry
311 m_svDCCache
.Append(pEntry
);
312 } // end of wxDC::AddToDCCache
314 void wxDC::ClearCache()
316 m_svBitmapCache
.DeleteContents(TRUE
);
317 m_svBitmapCache
.Clear();
318 m_svBitmapCache
.DeleteContents(FALSE
);
319 m_svDCCache
.DeleteContents(TRUE
);
321 m_svDCCache
.DeleteContents(FALSE
);
322 } // end of wxDC::ClearCache
324 // Clean up cache at app exit
325 class wxDCModule
: public wxModule
328 virtual bool OnInit() { return TRUE
; }
329 virtual void OnExit() { wxDC::ClearCache(); }
332 DECLARE_DYNAMIC_CLASS(wxDCModule
)
333 }; // end of CLASS wxDCModule
335 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
337 #endif // ndef for wxUSE_DC_CACHEING
339 // ---------------------------------------------------------------------------
341 // ---------------------------------------------------------------------------
359 m_bIsPaintTime
= FALSE
; // True at Paint Time
361 vColor
.InitFromName("BLACK");
362 m_pen
.SetColour(vColor
);
364 m_brush
.SetColour(vColor
);
365 } // end of wxDC::wxDC
371 SelectOldObjects(m_hDC
);
373 // if we own the HDC, we delete it, otherwise we just release it
379 ::GpiAssociate(m_hPS
, NULLHANDLE
);
380 ::GpiDestroyPS(m_hPS
);
383 ::DevCloseDC((HDC
)m_hDC
);
388 // Just Dissacociate, not destroy if we don't own the DC
392 ::GpiAssociate(m_hPS
, NULLHANDLE
);
396 } // end of wxDC::~wxDC
398 // This will select current objects out of the DC,
399 // which is what you have to do before deleting the
401 void wxDC::SelectOldObjects(
409 ::GpiSetBitmap(hPS
, (HBITMAP
) m_hOldBitmap
);
410 if (m_vSelectedBitmap
.Ok())
412 m_vSelectedBitmap
.SetSelectedInto(NULL
);
417 // OS/2 has no other native GDI objects to set in a PS/DC like windows
425 m_brush
= wxNullBrush
;
427 m_palette
= wxNullPalette
;
429 m_backgroundBrush
= wxNullBrush
;
430 m_vSelectedBitmap
= wxNullBitmap
;
431 } // end of wxDC::SelectOldObjects
433 // ---------------------------------------------------------------------------
435 // ---------------------------------------------------------------------------
437 #define DO_SET_CLIPPING_BOX() \
441 ::GpiQueryClipBox(m_hPS, &rect); \
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); \
449 void wxDC::DoSetClippingRegion(
458 vY
= OS2Y(vY
,vHeight
);
461 vRect
.yTop
= vY
+ vHeight
;
462 vRect
.xRight
= vX
+ vWidth
;
464 ::GpiIntersectClipRectangle(m_hPS
, &vRect
);
465 DO_SET_CLIPPING_BOX()
466 } // end of wxDC::DoSetClippingRegion
468 void wxDC::DoSetClippingRegionAsRegion(
469 const wxRegion
& rRegion
472 wxCHECK_RET(rRegion
.GetHRGN(), wxT("invalid clipping region"));
476 ::GpiSetClipRegion( m_hPS
477 ,(HRGN
)rRegion
.GetHRGN()
480 DO_SET_CLIPPING_BOX()
481 } // end of wxDC::DoSetClippingRegionAsRegion
483 void wxDC::DestroyClippingRegion(void)
485 if (m_clipping
&& m_hPS
)
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);
499 HRGN hRgn
= ::GpiCreateRegion(m_hPS
, 1, &vRect
);
501 ::GpiSetClipRegion(m_hPS
, hRgn
, &hRgnOld
);
504 } // end of wxDC::DestroyClippingRegion
506 // ---------------------------------------------------------------------------
507 // query capabilities
508 // ---------------------------------------------------------------------------
510 bool wxDC::CanDrawBitmap() const
515 bool wxDC::CanGetTextExtent() const
517 LONG lTechnology
= 0L;
519 ::DevQueryCaps(GetHDC(), CAPS_TECHNOLOGY
, 1L, &lTechnology
);
520 return (lTechnology
== CAPS_TECH_RASTER_DISPLAY
) || (lTechnology
== CAPS_TECH_RASTER_PRINTER
);
521 } // end of wxDC::CanGetTextExtent
523 int wxDC::GetDepth() const
525 LONG lArray
[CAPS_COLOR_BITCOUNT
];
528 if(::DevQueryCaps( GetHDC()
534 nBitsPerPixel
= (int)lArray
[CAPS_COLOR_BITCOUNT
];
536 return nBitsPerPixel
;
537 } // end of wxDC::GetDepth
539 // ---------------------------------------------------------------------------
541 // ---------------------------------------------------------------------------
546 // If this is a canvas DC then just fill with the background color
547 // Otherwise purge the whole thing
553 ::GpiQueryClipBox(m_hPS
, &vRect
);
554 ::WinFillRect(m_hPS
, &vRect
, ::GpiQueryBackColor(m_hPS
));
558 } // end of wxDC::Clear
560 bool wxDC::DoFloodFill(
563 , const wxColour
& rCol
571 vPtlPos
.x
= vX
; // Loads x-coordinate
572 vPtlPos
.y
= OS2Y(vY
,0); // Loads y-coordinate
573 ::GpiMove(m_hPS
, &vPtlPos
); // Sets current position
574 lColor
= rCol
.GetPixel();
575 lOptions
= FF_BOUNDARY
;
576 if(wxFLOOD_SURFACE
== nStyle
)
577 lOptions
= FF_SURFACE
;
579 ::GpiFloodFill(m_hPS
, lOptions
, lColor
);
582 } // end of wxDC::DoFloodFill
584 bool wxDC::DoGetPixel(
594 vPoint
.y
= OS2Y(vY
,0);
595 lColor
= ::GpiSetPel(m_hPS
, &vPoint
);
598 // Get the color of the pen
600 LONG lPencolor
= 0x00ffffff;
604 lPencolor
= m_pen
.GetColour().GetPixel();
608 // return the color of the pixel
611 pCol
->Set( GetRValue(lColor
)
615 return(lColor
== lPencolor
);
616 } // end of wxDC::DoGetPixel
618 void wxDC::DoCrossHair(
625 wxCoord vX1
= vX
- VIEWPORT_EXTENT
;
626 wxCoord vY1
= vY
- VIEWPORT_EXTENT
;
627 wxCoord vX2
= vX
+ VIEWPORT_EXTENT
;
628 wxCoord vY2
= vY
+ VIEWPORT_EXTENT
;
637 ::GpiMove(m_hPS
, &vPoint
[0]);
638 ::GpiLine(m_hPS
, &vPoint
[1]);
646 ::GpiMove(m_hPS
, &vPoint
[2]);
647 ::GpiLine(m_hPS
, &vPoint
[3]);
648 CalcBoundingBox(vX1
, vY1
);
649 CalcBoundingBox(vX2
, vY2
);
650 } // end of wxDC::DoCrossHair
652 void wxDC::DoDrawLine(
668 ::GpiMove(m_hPS
, &vPoint
[0]);
669 ::GpiLine(m_hPS
, &vPoint
[1]);
670 CalcBoundingBox(vX1
, vY1
);
671 CalcBoundingBox(vX2
, vY2
);
672 } // end of wxDC::DoDrawLine
674 //////////////////////////////////////////////////////////////////////////////
675 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
676 // and ending at (x2, y2). The current pen is used for the outline and the
677 // current brush for filling the shape. The arc is drawn in an anticlockwise
678 // direction from the start point to the end point.
679 //////////////////////////////////////////////////////////////////////////////
680 void wxDC::DoDrawArc(
690 POINTL vPtlArc
[2]; // Structure for current position
699 ARCPARAMS vArcp
; // Structure for arc parameters
701 if((vX1
== vXc
&& vY1
== vXc
) || (vX2
== vXc
&& vY2
== vXc
))
702 return; // Draw point ??
703 dRadius
= 0.5 * ( hypot( (double)(vY1
- vYc
)
706 hypot( (double)(vY2
- vYc
)
711 dAngl1
= atan2( (double)(vY1
- vYc
)
714 dAngl2
= atan2( (double)(vY2
- vYc
)
721 // GpiPointArc can't draw full arc
723 if(dAngl2
== dAngl1
|| (vX1
== vX2
&& vY1
== vY2
) )
728 dAnglmid
= (dAngl1
+ dAngl2
)/2. + M_PI
;
729 vXm
= vXc
+ dRadius
* cos(dAnglmid
);
730 vYm
= vYc
+ dRadius
* sin(dAnglmid
);
745 dAnglmid
= (dAngl1
+ dAngl2
)/2.;
746 vXm
= vXc
+ dRadius
* cos(dAnglmid
);
747 vYm
= vYc
+ dRadius
* sin(dAnglmid
);
750 // Ellipse main axis (r,q), (p,s) with center at (0,0) */
756 ::GpiSetArcParams(m_hPS
, &vArcp
); // Sets parameters to default
758 vPtlPos
.x
= vX1
; // Loads x-coordinate
759 vPtlPos
.y
= vY1
; // Loads y-coordinate
760 ::GpiMove(m_hPS
, &vPtlPos
); // Sets current position
765 ::GpiPointArc(m_hPS
, vPtlArc
); // Draws the arc
766 CalcBoundingBox( (vXc
- dRadius
)
769 CalcBoundingBox( (vXc
+ dRadius
)
772 } // end of wxDC::DoDrawArc
774 void wxDC::DoDrawCheckMark(
783 vY1
= OS2Y(vY1
,vHeight
);
787 vPoint
[1].x
= vX1
+ vWidth
;
788 vPoint
[1].y
= vY1
+ vHeight
;
790 ::GpiMove(m_hPS
, &vPoint
[0]);
791 ::GpiBox( m_hPS
// handle to a presentation space
792 ,DRO_OUTLINE
// draw the box outline ? or ?
793 ,&vPoint
[1] // address of the corner
794 ,0L // horizontal corner radius
795 ,0L // vertical corner radius
797 if(vWidth
> 4 && vHeight
> 4)
801 vPoint
[0].x
+= 2; vPoint
[0].y
+= 2;
802 vPoint
[1].x
-= 2; vPoint
[1].y
-= 2;
803 ::GpiMove(m_hPS
, &vPoint
[0]);
804 ::GpiLine(m_hPS
, &vPoint
[1]);
806 vPoint
[0].x
= vPoint
[1].x
;
808 ::GpiMove(m_hPS
, &vPoint
[0]);
809 ::GpiLine(m_hPS
, &vPoint
[1]);
815 wxCoord vX2
= vX1
+ vWidth
;
816 wxCoord vY2
= vY1
+ vHeight
;
821 } // end of wxDC::DoDrawCheckMark
823 void wxDC::DoDrawPoint(
829 COLORREF vColor
= 0x00ffffff;
833 vColor
= m_pen
.GetColour().GetPixel();
835 ::GpiSetColor(m_hPS
, vColor
);
837 vPoint
.y
= OS2Y(vY
,0);
838 ::GpiSetPel(m_hPS
, &vPoint
);
842 } // end of wxDC::DoDrawPoint
844 void wxDC::DoDrawPolygon(
852 ULONG ulCount
= 1; // Number of polygons.
853 POLYGON vPlgn
; // polygon.
854 ULONG flOptions
= 0L; // Drawing options.
856 //////////////////////////////////////////////////////////////////////////////
857 // This contains fields of option bits... to draw boundary lines as well as
858 // the area interior.
860 // Drawing boundary lines:
861 // POLYGON_NOBOUNDARY Does not draw boundary lines.
862 // POLYGON_BOUNDARY Draws boundary lines (the default).
864 // Construction of the area interior:
865 // POLYGON_ALTERNATE Constructs interior in alternate mode
867 // POLYGON_WINDING Constructs interior in winding mode.
868 //////////////////////////////////////////////////////////////////////////////
870 ULONG flModel
= 0L; // Drawing model.
872 //////////////////////////////////////////////////////////////////////////////
874 // POLYGON_INCL Fill is inclusive of bottom right (the default).
875 // POLYGON_EXCL Fill is exclusive of bottom right.
876 // This is provided to aid migration from other graphics models.
877 //////////////////////////////////////////////////////////////////////////////
879 LONG lHits
= 0L; // Correlation/error indicator.
882 int nIsTRANSPARENT
= 0;
883 LONG lBorderColor
= 0L;
886 lBorderColor
= m_pen
.GetColour().GetPixel();
887 lColor
= m_brush
.GetColour().GetPixel();
888 if(m_brush
.GetStyle() == wxTRANSPARENT
)
892 vPlgn
.aPointl
= (POINTL
*) calloc( n
+ 1
894 ); // well, new will call malloc
896 for(i
= 0; i
< n
; i
++)
898 vPlgn
.aPointl
[i
].x
= vPoints
[i
].x
; // +xoffset;
899 vPlgn
.aPointl
[i
].y
= OS2Y(vPoints
[i
].y
,0); // +yoffset;
901 flModel
= POLYGON_BOUNDARY
;
902 if(nFillStyle
== wxWINDING_RULE
)
903 flModel
|= POLYGON_WINDING
;
905 flModel
|= POLYGON_ALTERNATE
;
908 vPoint
.y
= OS2Y(vYoffset
,0);
910 ::GpiSetColor(m_hPS
, lBorderColor
);
911 ::GpiMove(m_hPS
, &vPoint
);
912 lHits
= ::GpiPolygons(m_hPS
, ulCount
, &vPlgn
, flOptions
, flModel
);
914 } // end of wxDC::DoDrawPolygon
916 void wxDC::DoDrawLines(
925 if (vXoffset
!= 0L || vXoffset
!= 0L)
929 vPoint
.x
= vPoints
[0].x
+ vXoffset
;
930 vPoint
.y
= OS2Y(vPoints
[0].y
+ vYoffset
,0);
931 ::GpiMove(m_hPS
, &vPoint
);
933 LONG lBorderColor
= m_pen
.GetColour().GetPixel();
935 ::GpiSetColor(m_hPS
, lBorderColor
);
936 for(i
= 1; i
< n
; i
++)
938 vPoint
.x
= vPoints
[i
].x
+ vXoffset
;
939 vPoint
.y
= OS2Y(vPoints
[i
].y
+ vYoffset
,0);
940 ::GpiLine(m_hPS
, &vPoint
);
947 CalcBoundingBox( vPoints
[i
].x
950 vPoint
.x
= vPoints
[0].x
;
951 vPoint
.y
= OS2Y(vPoints
[0].y
,0);
952 ::GpiMove(m_hPS
, &vPoint
);
954 for (i
= 0; i
< n
; i
++)
956 CalcBoundingBox( vPoints
[i
].x
959 vPoint
.x
= vPoints
[i
].x
;
960 vPoint
.y
= OS2Y(vPoints
[i
].y
,0);
961 ::GpiLine(m_hPS
, &vPoint
);
964 } // end of wxDC::DoDrawLines
966 void wxDC::DoDrawRectangle(
977 int nIsTRANSPARENT
= 0;
979 vY
= OS2Y(vY
,vHeight
);
981 wxCoord vX2
= vX
+ vWidth
;
982 wxCoord vY2
= vY
+ vHeight
;
986 vPoint
[1].x
= vX
+ vWidth
;
987 vPoint
[1].y
= vY
+ vHeight
;
988 ::GpiMove(m_hPS
, &vPoint
[0]);
989 lColor
= m_brush
.GetColour().GetPixel();
990 lBorderColor
= m_pen
.GetColour().GetPixel();
991 if (m_brush
.GetStyle() == wxTRANSPARENT
)
993 if(lColor
== lBorderColor
|| nIsTRANSPARENT
)
995 lControl
= DRO_OUTLINEFILL
; //DRO_FILL;
996 if(m_brush
.GetStyle() == wxTRANSPARENT
)
997 lControl
= DRO_OUTLINE
;
999 ::GpiSetColor(m_hPS
, lColor
);
1000 ::GpiBox( m_hPS
// handle to a presentation space
1001 ,lControl
// draw the box outline ? or ?
1002 ,&vPoint
[1] // address of the corner
1003 ,0L // horizontal corner radius
1004 ,0L // vertical corner radius
1009 lControl
= DRO_OUTLINE
;
1010 ::GpiSetColor( m_hPS
1019 lControl
= DRO_FILL
;
1020 ::GpiSetColor( m_hPS
1023 vPoint
[0].x
= vX
+ 1;
1024 vPoint
[0].y
= vY
+ 1;
1025 vPoint
[1].x
= vX
+ vWidth
- 1;
1026 vPoint
[1].y
= vY
+ vHeight
- 1;
1027 ::GpiMove(m_hPS
, &vPoint
[0]);
1035 CalcBoundingBox(vX
, vY
);
1036 CalcBoundingBox(vX2
, vY2
);
1037 } // end of wxDC::DoDrawRectangle
1039 void wxDC::DoDrawRoundedRectangle(
1050 vY
= OS2Y(vY
,vHeight
);
1052 wxCoord vX2
= (vX
+ vWidth
);
1053 wxCoord vY2
= (vY
+ vHeight
);
1056 vPoint
[0].y
= YLOG2DEV(vY
) - vHeight
;
1057 vPoint
[1].x
= vX
+ vWidth
;
1059 ::GpiMove(m_hPS
, &vPoint
[0]);
1061 lControl
= DRO_OUTLINEFILL
; //DRO_FILL;
1062 if (m_brush
.GetStyle() == wxTRANSPARENT
)
1063 lControl
= DRO_OUTLINE
;
1064 ::GpiBox( m_hPS
// handle to a presentation space
1065 ,DRO_OUTLINE
// draw the box outline ? or ?
1066 ,&vPoint
[1] // address of the corner
1067 ,(LONG
)dRadius
// horizontal corner radius
1068 ,(LONG
)dRadius
// vertical corner radius
1070 CalcBoundingBox(vX
, vY
);
1071 CalcBoundingBox(vX2
, vY2
);
1072 } // end of wxDC::DoDrawRoundedRectangle
1074 // Draw Ellipse within box (x,y) - (x+width, y+height)
1075 void wxDC::DoDrawEllipse(
1082 POINTL vPtlPos
; // Structure for current position
1083 FIXED vFxMult
; // Multiplier for ellipse
1084 ARCPARAMS vArcp
; // Structure for arc parameters
1086 vY
= OS2Y(vY
,vHeight
);
1089 vArcp
.lQ
= vHeight
/2;
1090 vArcp
.lP
= vWidth
/2;
1092 ::GpiSetArcParams( m_hPS
1094 ); // Sets parameters to default
1095 vPtlPos
.x
= vX
+ vWidth
/2; // Loads x-coordinate
1096 vPtlPos
.y
= vY
+ vHeight
/2; // Loads y-coordinate
1099 ); // Sets current position
1100 vFxMult
= MAKEFIXED(1, 0); /* Sets multiplier */
1103 // DRO_FILL, DRO_OTLINEFILL - where to get
1108 ); // Draws full arc with center at current position
1110 wxCoord vX2
= (vX
+ vWidth
);
1111 wxCoord vY2
= (vY
+ vHeight
);
1113 CalcBoundingBox(vX
, vY
);
1114 CalcBoundingBox(vX2
, vY2
);
1115 } // end of wxDC::DoDrawEllipse
1117 void wxDC::DoDrawEllipticArc(
1126 POINTL vPtlPos
; // Structure for current position
1127 FIXED vFxMult
; // Multiplier for ellipse
1128 ARCPARAMS vArcp
; // Structure for arc parameters
1130 FIXED vFSweepa
; // Start angle, sweep angle
1135 vY
= OS2Y(vY
,vHeight
);
1137 dFractPart
= modf(dSa
,&dIntPart
);
1138 vFSa
= MAKEFIXED((int)dIntPart
, (int)(dFractPart
* 0xffff) );
1139 dFractPart
= modf(dEa
- dSa
, &dIntPart
);
1140 vFSweepa
= MAKEFIXED((int)dIntPart
, (int)(dFractPart
* 0xffff) );
1143 // Ellipse main axis (r,q), (p,s) with center at (0,0)
1146 vArcp
.lQ
= vHeight
/2;
1147 vArcp
.lP
= vWidth
/2;
1149 ::GpiSetArcParams(m_hPS
, &vArcp
); // Sets parameters to default
1150 vPtlPos
.x
= vX
+ vWidth
/2 * (1. + cos(DegToRad(dSa
))); // Loads x-coordinate
1151 vPtlPos
.y
= vY
+ vHeight
/2 * (1. + sin(DegToRad(dSa
))); // Loads y-coordinate
1152 ::GpiMove(m_hPS
, &vPtlPos
); // Sets current position
1155 // May be not to the center ?
1157 vPtlPos
.x
= vX
+ vWidth
/2 ; // Loads x-coordinate
1158 vPtlPos
.y
= vY
+ vHeight
/2; // Loads y-coordinate
1159 vFxMult
= MAKEFIXED(1, 0); // Sets multiplier
1162 // DRO_FILL, DRO_OTLINEFILL - where to get
1164 ::GpiPartialArc( m_hPS
1170 wxCoord vX2
= (vX
+ vWidth
);
1171 wxCoord vY2
= (vY
+ vHeight
);
1173 CalcBoundingBox(vX
, vY
);
1174 CalcBoundingBox(vX2
, vY2
);
1175 } // end of wxDC::DoDrawEllipticArc
1177 void wxDC::DoDrawIcon(
1183 vY
= OS2Y(vY
,rIcon
.GetHeight());
1184 wxCHECK_RET( rIcon
.Ok(), wxT("invalid icon in DrawIcon") );
1186 ::WinDrawPointer( GetHPS()
1189 ,(HPOINTER
)GetHiconOf(rIcon
)
1192 CalcBoundingBox(vX
, vY
);
1193 CalcBoundingBox(vX
+ rIcon
.GetWidth(), vY
+ rIcon
.GetHeight());
1194 } // end of wxDC::DoDrawIcon
1196 void wxDC::DoDrawBitmap(
1197 const wxBitmap
& rBmp
1203 if (!bUseMask
&& !IsKindOf(CLASSINFO(wxPrinterDC
)))
1205 HBITMAP hBitmap
= (HBITMAP
)rBmp
.GetHBITMAP();
1206 wxBitmap
vNewBitmap( rBmp
.GetWidth()
1210 HBITMAP hBitmapOld
= ::GpiSetBitmap((HPS
)GetHPS(), vNewBitmap
.GetHBITMAP());
1211 LONG lOldTextground
= ::GpiQueryColor((HPS
)GetHPS());
1212 LONG lOldBackground
= ::GpiQueryBackColor((HPS
)GetHPS());
1214 if (m_textForegroundColour
.Ok())
1216 ::GpiSetColor( (HPS
)GetHPS()
1217 ,m_textForegroundColour
.GetPixel()
1220 if (m_textBackgroundColour
.Ok())
1222 ::GpiSetBackColor( (HPS
)GetHPS()
1223 ,m_textBackgroundColour
.GetPixel()
1227 vY
= OS2Y(vY
,rBmp
.GetHeight());
1229 POINTL vPoint
[4] = { vX
, vY
+ rBmp
.GetHeight()
1230 ,vX
+ rBmp
.GetWidth(), vY
1232 ,rBmp
.GetWidth(), rBmp
.GetHeight()
1234 ::GpiWCBitBlt( (HPS
)GetHPS()
1241 ::GpiSetBitmap((HPS
)GetHPS(), hBitmapOld
);
1242 ::GpiSetColor((HPS
)GetHPS(), lOldTextground
);
1243 ::GpiSetBackColor((HPS
)GetHPS(), lOldBackground
);
1245 } // end of wxDC::DoDrawBitmap
1247 void wxDC::DoDrawText(
1248 const wxString
& rsText
1261 CalcBoundingBox(vX
, vY
);
1262 GetTextExtent(rsText
, &vWidth
, &vHeight
);
1263 CalcBoundingBox((vX
+ vWidth
), (vY
+ vHeight
));
1264 } // end of wxDC::DoDrawText
1266 void wxDC::DrawAnyText(
1267 const wxString
& rsText
1272 int nOldBackground
= 0;
1279 // prepare for drawing the text
1283 // Set text color attributes
1285 if (m_textForegroundColour
.Ok())
1288 ,(int)m_textForegroundColour
.GetPixel()
1292 if (m_textBackgroundColour
.Ok())
1294 nOldBackground
= SetTextBkColor( m_hPS
1295 ,(int)m_textBackgroundColour
.GetPixel()
1301 GetTextExtent( rsText
1306 vPtlStart
.y
= OS2Y(vY
,vTextY
);
1308 lHits
= ::GpiCharStringAt( m_hPS
1311 ,(PCH
)rsText
.c_str()
1313 if (lHits
!= GPI_OK
)
1315 wxLogLastError(wxT("TextOut"));
1319 // Restore the old parameters (text foreground colour may be left because
1320 // it never is set to anything else, but background should remain
1321 // transparent even if we just drew an opaque string)
1323 if (m_textBackgroundColour
.Ok())
1324 SetTextBkColor( m_hPS
1332 void wxDC::DoDrawRotatedText(
1333 const wxString
& rsText
1351 DoDrawText(text, x, y);
1356 wxFillLogFont(&lf, &m_font);
1358 // GDI wants the angle in tenth of degree
1359 long angle10 = (long)(angle * 10);
1360 lf.lfEscapement = angle10;
1361 lf. lfOrientation = angle10;
1363 HFONT hfont = ::CreateFontIndirect(&lf);
1366 wxLogLastError("CreateFont");
1370 HFONT hfontOld = ::SelectObject(GetHdc(), hfont);
1372 DrawAnyText(text, x, y);
1374 (void)::SelectObject(GetHdc(), hfontOld);
1377 // call the bounding box by adding all four vertices of the rectangle
1378 // containing the text to it (simpler and probably not slower than
1379 // determining which of them is really topmost/leftmost/...)
1381 GetTextExtent(text, &w, &h);
1383 double rad = DegToRad(angle);
1385 // "upper left" and "upper right"
1386 CalcBoundingBox(x, y);
1387 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
1388 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1390 // "bottom left" and "bottom right"
1391 x += (wxCoord)(h*sin(rad));
1392 y += (wxCoord)(h*cos(rad));
1393 CalcBoundingBox(x, y);
1394 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1399 // ---------------------------------------------------------------------------
1401 // ---------------------------------------------------------------------------
1403 void wxDC::DoSelectPalette(
1408 // Set the old object temporarily, in case the assignment deletes an object
1409 // that's not yet selected out.
1420 hOldPal
= ::GpiSelectPalette((HDC
) m_hPS
, (HPALETTE
) m_palette
.GetHPALETTE());
1422 m_hOldPalette
= (WXHPALETTE
)hOldPal
;
1424 } // end of wxDC::DoSelectPalette
1426 void wxDC::InitializePalette()
1428 if (wxDisplayDepth() <= 8 )
1431 // Look for any window or parent that has a custom palette. If any has
1432 // one then we need to use it in drawing operations
1434 wxWindow
* pWin
= m_pCanvas
->GetAncestorWithCustomPalette();
1436 m_hasCustomPalette
= pWin
&& pWin
->HasCustomPalette();
1437 if (m_hasCustomPalette
)
1439 m_palette
= pWin
->GetPalette();
1442 // turn on PM translation for this palette
1447 } // end of wxDC::InitializePalette
1449 void wxDC::SetPalette(
1450 const wxPalette
& rPalette
1457 m_palette
= rPalette
;
1465 HPALETTE hOldPal
= ::GpiSelectPalette((HDC
) m_hPS
, (HPALETTE
) m_palette
.GetHPALETTE());
1467 m_hOldPalette
= (WXHPALETTE
)hOldPal
;
1468 } // end of wxDC::SetPalette
1475 // Set the old object temporarily, in case the assignment deletes an object
1476 // that's not yet selected out.
1488 m_font
.SetPS(m_hPS
); // this will realize the font
1492 HFONT hFont
= m_font
.GetResourceHandle();
1493 if (hFont
== (HFONT
) NULL
)
1495 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1498 m_hOldFont
= (WXHFONT
) hFont
;
1500 } // end of wxDC::SetFont
1506 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1522 m_pen
.SetPS((HPS
)m_hOldPen
);
1529 if (m_pen
.GetResourceHandle())
1533 m_hOldPen
= m_pen
.GetPS();
1538 void wxDC::SetBrush(
1539 const wxBrush
& rBrush
1542 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1548 if (m_brush
== rBrush
)
1558 m_brush
.SetPS((HPS
)m_hOldBrush
);
1565 if (m_brush
.GetResourceHandle())
1567 m_brush
.SetPS(m_hPS
);
1569 m_hOldBrush
= (WXHWND
)m_brush
.GetPS();
1572 } // end of wxDC::SetBrush
1574 void wxDC::SetBackground(
1575 const wxBrush
& rBrush
1578 m_backgroundBrush
= rBrush
;
1579 if (!m_backgroundBrush
.Ok())
1583 bool bCustomColours
= TRUE
;
1586 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
1587 // change background colours from the control-panel specified colours.
1589 if (m_pCanvas
->IsKindOf(CLASSINFO(wxWindow
)) &&
1590 ((m_pCanvas
->GetWindowStyleFlag() & wxUSER_COLOURS
) != wxUSER_COLOURS
))
1591 bCustomColours
= FALSE
;
1594 if (m_backgroundBrush
.GetStyle()==wxTRANSPARENT
)
1596 m_pCanvas
->SetTransparent(TRUE
);
1601 // Setting the background brush of a DC
1602 // doesn't affect the window background colour. However,
1603 // I'm leaving in the transparency setting because it's needed by
1604 // various controls (e.g. wxStaticText) to determine whether to draw
1605 // transparently or not. TODO: maybe this should be a new function
1606 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
1608 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
1610 m_pCanvas
->SetTransparent(FALSE
);
1614 COLORREF vNewColor
= m_backgroundBrush
.GetColour().GetPixel();
1615 (void)::GpiSetBackColor((HPS
)m_hPS
, (LONG
)vNewColor
);
1616 } // end of wxDC::SetBackground
1618 void wxDC::SetBackgroundMode(
1622 m_backgroundMode
= nMode
;
1623 } // end of wxDC::SetBackgroundMode
1625 void wxDC::SetLogicalFunction(
1629 m_logicalFunction
= nFunction
;
1630 SetRop((WXHDC
)m_hDC
);
1631 } // wxDC::SetLogicalFunction
1637 if (!hDC
|| m_logicalFunction
< 0)
1641 switch (m_logicalFunction
)
1652 lCRop
= FM_MERGESRCNOT
;
1656 lCRop
= FM_NOTMASKSRC
;
1668 lCRop
= FM_MERGENOTSRC
;
1672 lCRop
= FM_MERGESRCNOT
;
1684 lCRop
= FM_SUBTRACT
;
1691 lCRop
= FM_OVERPAINT
;
1694 ::GpiSetMix((HPS
)hDC
, lCRop
);
1695 } // end of wxDC::SetRop
1697 bool wxDC::StartDoc(
1698 const wxString
& rsMessage
1701 // We might be previewing, so return TRUE to let it continue.
1703 } // end of wxDC::StartDoc
1707 } // end of wxDC::EndDoc
1709 void wxDC::StartPage()
1711 } // end of wxDC::StartPage
1713 void wxDC::EndPage()
1715 } // end of wxDC::EndPage
1717 // ---------------------------------------------------------------------------
1719 // ---------------------------------------------------------------------------
1721 wxCoord
wxDC::GetCharHeight() const
1723 FONTMETRICS vFM
; // metrics structure
1725 ::GpiQueryFontMetrics( m_hPS
1726 ,sizeof(FONTMETRICS
)
1729 return YDEV2LOGREL(vFM
.lXHeight
);
1732 wxCoord
wxDC::GetCharWidth() const
1734 FONTMETRICS vFM
; // metrics structure
1736 ::GpiQueryFontMetrics( m_hPS
1737 ,sizeof(FONTMETRICS
)
1740 return XDEV2LOGREL(vFM
.lAveCharWidth
);
1743 void wxDC::DoGetTextExtent(
1744 const wxString
& rsString
1747 , wxCoord
* pvDescent
1748 , wxCoord
* pvExternalLeading
1752 POINTL avPoint
[TXTBOX_COUNT
];
1757 FONTMETRICS vFM
; // metrics structure
1760 ERRORID vErrorCode
; // last error id code
1761 wxFont
* pFontToUse
= (wxFont
*)pTheFont
;
1763 char zMsg
[128]; // DEBUG
1767 pFontToUse
= (wxFont
*)&m_font
;
1768 l
= rsString
.length();
1769 pStr
= (PCH
) rsString
.c_str();
1772 // In world coordinates.
1774 bRc
= ::GpiQueryTextBox( m_hPS
1777 ,TXTBOX_COUNT
// return maximum information
1778 ,avPoint
// array of coordinates points
1782 vErrorCode
= ::WinGetLastError(wxGetInstance());
1783 sError
= wxPMErrorToStr(vErrorCode
);
1785 sprintf(zMsg
, "GpiQueryTextBox for %s: failed with Error: %x - %s", pStr
, vErrorCode
, sError
.c_str());
1786 (void)wxMessageBox( "wxWindows Menu sample"
1792 vPtMin
.x
= avPoint
[0].x
;
1793 vPtMax
.x
= avPoint
[0].x
;
1794 vPtMin
.y
= avPoint
[0].y
;
1795 vPtMax
.y
= avPoint
[0].y
;
1796 for (i
= 1; i
< 4; i
++)
1798 if(vPtMin
.x
> avPoint
[i
].x
) vPtMin
.x
= avPoint
[i
].x
;
1799 if(vPtMin
.y
> avPoint
[i
].y
) vPtMin
.y
= avPoint
[i
].y
;
1800 if(vPtMax
.x
< avPoint
[i
].x
) vPtMax
.x
= avPoint
[i
].x
;
1801 if(vPtMax
.y
< avPoint
[i
].y
) vPtMax
.y
= avPoint
[i
].y
;
1803 ::GpiQueryFontMetrics( m_hPS
1804 ,sizeof(FONTMETRICS
)
1809 *pvX
= (wxCoord
)(vPtMax
.x
- vPtMin
.x
+ 1);
1811 *pvY
= (wxCoord
)(vPtMax
.y
- vPtMin
.y
+ 1);
1813 *pvDescent
= vFM
.lMaxDescender
;
1814 if (pvExternalLeading
)
1815 *pvExternalLeading
= vFM
.lExternalLeading
;
1818 void wxDC::SetMapMode(
1822 int nPixelWidth
= 0;
1823 int nPixelHeight
= 0;
1826 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
1828 m_mappingMode
= nMode
;
1830 if(::DevQueryCaps( m_hDC
1832 ,CAPS_VERTICAL_RESOLUTION
1839 nPixelWidth
= lArray
[CAPS_WIDTH
];
1840 nPixelHeight
= lArray
[CAPS_HEIGHT
];
1841 lHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
1842 lVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
1843 nMmWidth
= (lHorzRes
/1000) * nPixelWidth
;
1844 nMmWidth
= (lVertRes
/1000) * nPixelHeight
;
1846 if ((nPixelWidth
== 0) || (nPixelHeight
== 0) || (nMmWidth
== 0) || (nMmHeight
== 0))
1851 double dMm2pixelsX
= nPixelWidth
/nMmWidth
;
1852 double dMm2pixelsY
= nPixelHeight
/nMmHeight
;
1857 m_logicalScaleX
= (twips2mm
* dMm2pixelsX
);
1858 m_logicalScaleY
= (twips2mm
* dMm2pixelsY
);
1862 m_logicalScaleX
= (pt2mm
* dMm2pixelsX
);
1863 m_logicalScaleY
= (pt2mm
* dMm2pixelsY
);
1867 m_logicalScaleX
= dMm2pixelsX
;
1868 m_logicalScaleY
= dMm2pixelsY
;
1872 m_logicalScaleX
= (dMm2pixelsX
/10.0);
1873 m_logicalScaleY
= (dMm2pixelsY
/10.0);
1878 m_logicalScaleX
= 1.0;
1879 m_logicalScaleY
= 1.0;
1885 ulOptions
= ::GpiQueryPS(m_hPS
, &vSize
);
1886 if (!ulOptions
& PU_ARBITRARY
)
1888 ulOptions
= PU_ARBITRARY
| GPIF_DEFAULT
;
1889 ::GpiSetPS(m_hPS
, &vSize
, ulOptions
);
1891 m_nWindowExtX
= (int)MS_XDEV2LOG(VIEWPORT_EXTENT
);
1892 m_nWindowExtY
= (int)MS_YDEV2LOG(VIEWPORT_EXTENT
);
1894 }; // end of wxDC::SetMapMode
1896 void wxDC::SetUserScale(
1904 SetMapMode(m_mappingMode
);
1905 } // end of wxDC::SetUserScale
1907 void wxDC::SetAxisOrientation(
1912 m_signX
= bXLeftRight
? 1 : -1;
1913 m_signY
= bYBottomUp
? -1 : 1;
1915 SetMapMode(m_mappingMode
);
1916 } // end of wxDC::SetAxisOrientation
1918 void wxDC::SetSystemScale(
1926 SetMapMode(m_mappingMode
);
1927 } // end of wxDC::SetSystemScale
1929 void wxDC::SetLogicalOrigin(
1936 ::GpiQueryPageViewport( m_hPS
1943 ::GpiSetPageViewport( m_hPS
1946 }; // end of wxDC::SetLogicalOrigin
1948 void wxDC::SetDeviceOrigin(
1955 m_deviceOriginX
= vX
;
1956 m_deviceOriginY
= vY
;
1957 ::GpiQueryPageViewport( m_hPS
1962 vRect
.yBottom
-= vY
;
1964 ::GpiSetPageViewport( m_hPS
1967 }; // end of wxDC::SetDeviceOrigin
1969 // ---------------------------------------------------------------------------
1970 // coordinates transformations
1971 // ---------------------------------------------------------------------------
1973 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1975 return (wxCoord
) (((x
) - m_deviceOriginX
)/(m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
) - m_logicalOriginX
);
1978 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1980 // axis orientation is not taken into account for conversion of a distance
1981 return (wxCoord
) ((x
)/(m_logicalScaleX
*m_userScaleX
*m_scaleX
));
1984 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1986 return (wxCoord
) (((y
) - m_deviceOriginY
)/(m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
) - m_logicalOriginY
);
1989 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1991 // axis orientation is not taken into account for conversion of a distance
1992 return (wxCoord
) ((y
)/(m_logicalScaleY
*m_userScaleY
*m_scaleY
));
1995 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1997 return (wxCoord
) ((x
- m_logicalOriginX
)*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
+ m_deviceOriginX
);
2000 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2002 // axis orientation is not taken into account for conversion of a distance
2003 return (wxCoord
) (x
*m_logicalScaleX
*m_userScaleX
*m_scaleX
);
2006 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2008 return (wxCoord
) ((y
- m_logicalOriginY
)*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
+ m_deviceOriginY
);
2011 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2013 // axis orientation is not taken into account for conversion of a distance
2014 return (wxCoord
) (y
*m_logicalScaleY
*m_userScaleY
*m_scaleY
);
2017 // ---------------------------------------------------------------------------
2019 // ---------------------------------------------------------------------------
2035 wxMask
* pMask
= NULL
;
2037 COLORREF vOldTextColor
;
2038 COLORREF vOldBackground
= ::GpiQueryBackColor(m_hPS
);
2042 const wxBitmap
& rBmp
= pSource
->m_vSelectedBitmap
;
2044 pMask
= rBmp
.GetMask();
2045 if (!(rBmp
.Ok() && pMask
&& pMask
->GetMaskBitmap()))
2051 ::GpiQueryAttrs( m_hPS
2056 vOldTextColor
= (COLORREF
)vCbnd
.lColor
;
2058 if (m_textForegroundColour
.Ok())
2060 vCbnd
.lColor
= (LONG
)m_textForegroundColour
.GetPixel();
2061 ::GpiSetAttrs( m_hPS
// presentation-space handle
2062 ,PRIM_CHAR
// Char primitive.
2063 ,CBB_COLOR
// sets color.
2065 ,&vCbnd
// buffer for attributes.
2068 if (m_textBackgroundColour
.Ok())
2070 ::GpiSetBackColor(m_hPS
, (LONG
)m_textBackgroundColour
.GetPixel());
2073 LONG lRop
= ROP_SRCCOPY
;
2077 case wxXOR
: lRop
= ROP_SRCINVERT
; break;
2078 case wxINVERT
: lRop
= ROP_DSTINVERT
; break;
2079 case wxOR_REVERSE
: lRop
= 0x00DD0228; break;
2080 case wxAND_REVERSE
: lRop
= ROP_SRCERASE
; break;
2081 case wxCLEAR
: lRop
= ROP_ZERO
; break;
2082 case wxSET
: lRop
= ROP_ONE
; break;
2083 case wxOR_INVERT
: lRop
= ROP_MERGEPAINT
; break;
2084 case wxAND
: lRop
= ROP_SRCAND
; break;
2085 case wxOR
: lRop
= ROP_SRCPAINT
; break;
2086 case wxEQUIV
: lRop
= 0x00990066; break;
2087 case wxNAND
: lRop
= 0x007700E6; break;
2088 case wxAND_INVERT
: lRop
= 0x00220326; break;
2089 case wxCOPY
: lRop
= ROP_SRCCOPY
; break;
2090 case wxNO_OP
: lRop
= ROP_NOTSRCERASE
; break;
2091 case wxSRC_INVERT
: lRop
= ROP_SRCINVERT
; break;
2092 case wxNOR
: lRop
= ROP_NOTSRCCOPY
; break;
2094 wxFAIL_MSG( wxT("unsupported logical function") );
2103 // Blit bitmap with mask
2107 // Create a temp buffer bitmap and DCs/PSs to access it and the mask
2113 DEVOPENSTRUC vDOP
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
2114 BITMAPINFOHEADER2 vBmpHdr
;
2116 SIZEL vSize
= {0, 0};
2119 memset(&vBmpHdr
, 0, sizeof(BITMAPINFOHEADER2
));
2120 vBmpHdr
.cbFix
= sizeof(BITMAPINFOHEADER2
);
2121 vBmpHdr
.cx
= vWidth
;
2122 vBmpHdr
.cy
= vHeight
;
2123 vBmpHdr
.cPlanes
= 1;
2124 vBmpHdr
.cBitCount
= 24;
2126 #if wxUSE_DC_CACHEING
2130 // create a temp buffer bitmap and DCs to access it and the mask
2132 wxDCCacheEntry
* pDCCacheEntry1
= FindDCInCache( NULL
2135 wxDCCacheEntry
* pDCCacheEntry2
= FindDCInCache( pDCCacheEntry1
2138 wxDCCacheEntry
* pBitmapCacheEntry
= FindBitmapInCache( GetHPS()
2143 hPSMask
= pDCCacheEntry1
->m_hPS
;
2144 hDCBuffer
= (HDC
)pDCCacheEntry2
->m_hPS
;
2145 hBufBitmap
= (HBITMAP
)pBitmapCacheEntry
->m_hBitmap
;
2150 hDCMask
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
2151 hDCBuffer
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
2152 hPSMask
= ::GpiCreatePS(vHabmain
, hDCMask
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
2153 hPSBuffer
= ::GpiCreatePS(vHabmain
, hDCBuffer
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
2154 hBufBitmap
= ::GpiCreateBitmap(GetHPS(), &vBmpHdr
, 0L, NULL
, NULL
);
2157 POINTL aPoint1
[4] = { 0, 0
2160 ,vXdest
+ vWidth
, vYdest
+ vHeight
2162 POINTL aPoint2
[4] = { 0, 0
2165 ,vXsrc
+ vWidth
, vYsrc
+ vHeight
2167 POINTL aPoint3
[4] = { vXdest
, vYdest
2168 ,vXdest
+ vWidth
, vYdest
+ vHeight
2170 ,vXsrc
+ vWidth
, vYsrc
+ vHeight
2172 POINTL aPoint4
[4] = { vXdest
, vYdest
2173 ,vXdest
+ vWidth
, vYdest
+ vHeight
2177 ::GpiSetBitmap(hPSMask
, (HBITMAP
) pMask
->GetMaskBitmap());
2178 ::GpiSetBitmap(hPSBuffer
, (HBITMAP
) hBufBitmap
);
2181 // Copy dest to buffer
2183 rc
= ::GpiBitBlt( hPSBuffer
2190 if (rc
== GPI_ERROR
)
2192 wxLogLastError(wxT("BitBlt"));
2196 // Copy src to buffer using selected raster op
2198 rc
= ::GpiBitBlt( hPSBuffer
2205 if (rc
== GPI_ERROR
)
2207 wxLogLastError(wxT("BitBlt"));
2211 // Set masked area in buffer to BLACK (pixel value 0)
2213 COLORREF vPrevBkCol
= ::GpiQueryBackColor(GetHPS());
2214 COLORREF vPrevCol
= ::GpiQueryColor(GetHPS());
2216 ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255));
2217 ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0));
2219 rc
= ::GpiBitBlt( hPSBuffer
2226 if (rc
== GPI_ERROR
)
2228 wxLogLastError(wxT("BitBlt"));
2232 // Set unmasked area in dest to BLACK
2234 ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0));
2235 ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255));
2236 rc
= ::GpiBitBlt( GetHPS()
2243 if (rc
== GPI_ERROR
)
2245 wxLogLastError(wxT("BitBlt"));
2249 // Restore colours to original values
2251 ::GpiSetBackColor(GetHPS(), vPrevBkCol
);
2252 ::GpiSetColor(GetHPS(), vPrevCol
);
2255 // OR buffer to dest
2257 rc
= ::GpiBitBlt( GetHPS()
2264 if (rc
== GPI_ERROR
)
2267 wxLogLastError(wxT("BitBlt"));
2271 // Tidy up temporary DCs and bitmap
2273 ::GpiSetBitmap(hPSMask
, NULLHANDLE
);
2274 ::GpiSetBitmap(hPSBuffer
, NULLHANDLE
);
2275 #if !wxUSE_DC_CACHEING
2276 ::GpiDestroyPS(hPSMask
);
2277 ::GpiDestroyPS(hPSBuffer
);
2278 ::DevCloseDC(hDCMask
);
2279 ::DevCloseDC(hDCBuffer
);
2280 ::GpiDeleteBitmap(hBufBitmap
);
2284 else // no mask, just BitBlt() it
2286 POINTL aPoint
[4] = { vXdest
, vYdest
2287 ,vXdest
+ vWidth
, vYdest
+ vHeight
2289 ,vXsrc
+ vWidth
, vYsrc
+ vHeight
2292 bSuccess
= (::GpiBitBlt( m_hPS
2301 wxLogLastError(wxT("BitBlt"));
2304 vCbnd
.lColor
= (LONG
)vOldTextColor
;
2305 ::GpiSetAttrs( m_hPS
// presentation-space handle
2306 ,PRIM_CHAR
// Char primitive.
2307 ,CBB_COLOR
// sets color.
2309 ,&vCbnd
// buffer for attributes.
2311 ::GpiSetBackColor(m_hPS
, (LONG
)vOldBackground
);
2315 void wxDC::DoGetSize(
2320 LONG lArray
[CAPS_HEIGHT
];
2322 if(::DevQueryCaps( m_hDC
2328 *pnWidth
= lArray
[CAPS_WIDTH
];
2329 *pnHeight
= lArray
[CAPS_HEIGHT
];
2331 }; // end of wxDC::DoGetSize(
2333 void wxDC::DoGetSizeMM(
2338 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2340 if(::DevQueryCaps( m_hDC
2342 ,CAPS_VERTICAL_RESOLUTION
2351 nWidth
= lArray
[CAPS_WIDTH
];
2352 nHeight
= lArray
[CAPS_HEIGHT
];
2353 nHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2354 nVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2355 nWidth
= (nHorzRes
/1000) * nWidth
;
2356 nHeight
= (nVertRes
/1000) * nHeight
;
2358 }; // end of wxDC::DoGetSizeMM
2360 wxSize
wxDC::GetPPI() const
2362 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2366 if(::DevQueryCaps( m_hDC
2368 ,CAPS_VERTICAL_RESOLUTION
2377 nPelWidth
= lArray
[CAPS_WIDTH
];
2378 nPelHeight
= lArray
[CAPS_HEIGHT
];
2379 nHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2380 nVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2381 nWidth
= (nHorzRes
/39.3) * nPelWidth
;
2382 nHeight
= (nVertRes
/39.3) * nPelHeight
;
2384 return (wxSize(nWidth
,nHeight
));
2385 } // end of wxDC::GetPPI
2387 void wxDC::SetLogicalScale(
2392 m_logicalScaleX
= dX
;
2393 m_logicalScaleY
= dY
;
2394 }; // end of wxDC::SetLogicalScale
2396 #if WXWIN_COMPATIBILITY
2397 void wxDC::DoGetTextExtent(const wxString
& string
, float *x
, float *y
,
2398 float *descent
, float *externalLeading
,
2399 wxFont
*theFont
, bool use16bit
) const
2401 wxCoord x1
, y1
, descent1
, externalLeading1
;
2402 GetTextExtent(string
, & x1
, & y1
, & descent1
, & externalLeading1
, theFont
, use16bit
);
2405 *descent
= descent1
;
2406 if (externalLeading
)
2407 *externalLeading
= externalLeading1
;