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 void 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
);
581 } // end of wxDC::DoFloodFill
583 bool wxDC::DoGetPixel(
593 vPoint
.y
= OS2Y(vY
,0);
594 lColor
= ::GpiSetPel(m_hPS
, &vPoint
);
597 // Get the color of the pen
599 LONG lPencolor
= 0x00ffffff;
603 lPencolor
= m_pen
.GetColour().GetPixel();
607 // return the color of the pixel
610 pCol
->Set( GetRValue(lColor
)
614 return(lColor
== lPencolor
);
615 } // end of wxDC::DoGetPixel
617 void wxDC::DoCrossHair(
624 wxCoord vX1
= vX
- VIEWPORT_EXTENT
;
625 wxCoord vY1
= vY
- VIEWPORT_EXTENT
;
626 wxCoord vX2
= vX
+ VIEWPORT_EXTENT
;
627 wxCoord vY2
= vY
+ VIEWPORT_EXTENT
;
636 ::GpiMove(m_hPS
, &vPoint
[0]);
637 ::GpiLine(m_hPS
, &vPoint
[1]);
645 ::GpiMove(m_hPS
, &vPoint
[2]);
646 ::GpiLine(m_hPS
, &vPoint
[3]);
647 CalcBoundingBox(vX1
, vY1
);
648 CalcBoundingBox(vX2
, vY2
);
649 } // end of wxDC::DoCrossHair
651 void wxDC::DoDrawLine(
667 ::GpiMove(m_hPS
, &vPoint
[0]);
668 ::GpiLine(m_hPS
, &vPoint
[1]);
669 CalcBoundingBox(vX1
, vY1
);
670 CalcBoundingBox(vX2
, vY2
);
671 } // end of wxDC::DoDrawLine
673 //////////////////////////////////////////////////////////////////////////////
674 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
675 // and ending at (x2, y2). The current pen is used for the outline and the
676 // current brush for filling the shape. The arc is drawn in an anticlockwise
677 // direction from the start point to the end point.
678 //////////////////////////////////////////////////////////////////////////////
679 void wxDC::DoDrawArc(
689 POINTL vPtlArc
[2]; // Structure for current position
698 ARCPARAMS vArcp
; // Structure for arc parameters
700 if((vX1
== vXc
&& vY1
== vXc
) || (vX2
== vXc
&& vY2
== vXc
))
701 return; // Draw point ??
702 dRadius
= 0.5 * ( hypot( (double)(vY1
- vYc
)
705 hypot( (double)(vY2
- vYc
)
710 dAngl1
= atan2( (double)(vY1
- vYc
)
713 dAngl2
= atan2( (double)(vY2
- vYc
)
720 // GpiPointArc can't draw full arc
722 if(dAngl2
== dAngl1
|| (vX1
== vX2
&& vY1
== vY2
) )
727 dAnglmid
= (dAngl1
+ dAngl2
)/2. + M_PI
;
728 vXm
= vXc
+ dRadius
* cos(dAnglmid
);
729 vYm
= vYc
+ dRadius
* sin(dAnglmid
);
744 dAnglmid
= (dAngl1
+ dAngl2
)/2.;
745 vXm
= vXc
+ dRadius
* cos(dAnglmid
);
746 vYm
= vYc
+ dRadius
* sin(dAnglmid
);
749 // Ellipse main axis (r,q), (p,s) with center at (0,0) */
755 ::GpiSetArcParams(m_hPS
, &vArcp
); // Sets parameters to default
757 vPtlPos
.x
= vX1
; // Loads x-coordinate
758 vPtlPos
.y
= vY1
; // Loads y-coordinate
759 ::GpiMove(m_hPS
, &vPtlPos
); // Sets current position
764 ::GpiPointArc(m_hPS
, vPtlArc
); // Draws the arc
765 CalcBoundingBox( (vXc
- dRadius
)
768 CalcBoundingBox( (vXc
+ dRadius
)
771 } // end of wxDC::DoDrawArc
773 void wxDC::DoDrawCheckMark(
782 vY1
= OS2Y(vY1
,vHeight
);
786 vPoint
[1].x
= vX1
+ vWidth
;
787 vPoint
[1].y
= vY1
+ vHeight
;
789 ::GpiMove(m_hPS
, &vPoint
[0]);
790 ::GpiBox( m_hPS
// handle to a presentation space
791 ,DRO_OUTLINE
// draw the box outline ? or ?
792 ,&vPoint
[1] // address of the corner
793 ,0L // horizontal corner radius
794 ,0L // vertical corner radius
796 if(vWidth
> 4 && vHeight
> 4)
800 vPoint
[0].x
+= 2; vPoint
[0].y
+= 2;
801 vPoint
[1].x
-= 2; vPoint
[1].y
-= 2;
802 ::GpiMove(m_hPS
, &vPoint
[0]);
803 ::GpiLine(m_hPS
, &vPoint
[1]);
805 vPoint
[0].x
= vPoint
[1].x
;
807 ::GpiMove(m_hPS
, &vPoint
[0]);
808 ::GpiLine(m_hPS
, &vPoint
[1]);
814 wxCoord vX2
= vX1
+ vWidth
;
815 wxCoord vY2
= vY1
+ vHeight
;
820 } // end of wxDC::DoDrawCheckMark
822 void wxDC::DoDrawPoint(
828 COLORREF vColor
= 0x00ffffff;
832 vColor
= m_pen
.GetColour().GetPixel();
834 ::GpiSetColor(m_hPS
, vColor
);
836 vPoint
.y
= OS2Y(vY
,0);
837 ::GpiSetPel(m_hPS
, &vPoint
);
841 } // end of wxDC::DoDrawPoint
843 void wxDC::DoDrawPolygon(
851 ULONG ulCount
= 1; // Number of polygons.
852 POLYGON vPlgn
; // polygon.
853 ULONG flOptions
= 0L; // Drawing options.
855 //////////////////////////////////////////////////////////////////////////////
856 // This contains fields of option bits... to draw boundary lines as well as
857 // the area interior.
859 // Drawing boundary lines:
860 // POLYGON_NOBOUNDARY Does not draw boundary lines.
861 // POLYGON_BOUNDARY Draws boundary lines (the default).
863 // Construction of the area interior:
864 // POLYGON_ALTERNATE Constructs interior in alternate mode
866 // POLYGON_WINDING Constructs interior in winding mode.
867 //////////////////////////////////////////////////////////////////////////////
869 ULONG flModel
= 0L; // Drawing model.
871 //////////////////////////////////////////////////////////////////////////////
873 // POLYGON_INCL Fill is inclusive of bottom right (the default).
874 // POLYGON_EXCL Fill is exclusive of bottom right.
875 // This is provided to aid migration from other graphics models.
876 //////////////////////////////////////////////////////////////////////////////
878 LONG lHits
= 0L; // Correlation/error indicator.
881 int nIsTRANSPARENT
= 0;
882 LONG lBorderColor
= 0L;
885 lBorderColor
= m_pen
.GetColour().GetPixel();
886 lColor
= m_brush
.GetColour().GetPixel();
887 if(m_brush
.GetStyle() == wxTRANSPARENT
)
891 vPlgn
.aPointl
= (POINTL
*) calloc( n
+ 1
893 ); // well, new will call malloc
895 for(i
= 0; i
< n
; i
++)
897 vPlgn
.aPointl
[i
].x
= vPoints
[i
].x
; // +xoffset;
898 vPlgn
.aPointl
[i
].y
= OS2Y(vPoints
[i
].y
,0); // +yoffset;
900 flModel
= POLYGON_BOUNDARY
;
901 if(nFillStyle
== wxWINDING_RULE
)
902 flModel
|= POLYGON_WINDING
;
904 flModel
|= POLYGON_ALTERNATE
;
907 vPoint
.y
= OS2Y(vYoffset
,0);
909 ::GpiSetColor(m_hPS
, lBorderColor
);
910 ::GpiMove(m_hPS
, &vPoint
);
911 lHits
= ::GpiPolygons(m_hPS
, ulCount
, &vPlgn
, flOptions
, flModel
);
913 } // end of wxDC::DoDrawPolygon
915 void wxDC::DoDrawLines(
924 if (vXoffset
!= 0L || vXoffset
!= 0L)
928 vPoint
.x
= vPoints
[0].x
+ vXoffset
;
929 vPoint
.y
= OS2Y(vPoints
[0].y
+ vYoffset
,0);
930 ::GpiMove(m_hPS
, &vPoint
);
932 LONG lBorderColor
= m_pen
.GetColour().GetPixel();
934 ::GpiSetColor(m_hPS
, lBorderColor
);
935 for(i
= 1; i
< n
; i
++)
937 vPoint
.x
= vPoints
[i
].x
+ vXoffset
;
938 vPoint
.y
= OS2Y(vPoints
[i
].y
+ vYoffset
,0);
939 ::GpiLine(m_hPS
, &vPoint
);
946 CalcBoundingBox( vPoints
[i
].x
949 vPoint
.x
= vPoints
[0].x
;
950 vPoint
.y
= OS2Y(vPoints
[0].y
,0);
951 ::GpiMove(m_hPS
, &vPoint
);
953 for (i
= 0; i
< n
; i
++)
955 CalcBoundingBox( vPoints
[i
].x
958 vPoint
.x
= vPoints
[i
].x
;
959 vPoint
.y
= OS2Y(vPoints
[i
].y
,0);
960 ::GpiLine(m_hPS
, &vPoint
);
963 } // end of wxDC::DoDrawLines
965 void wxDC::DoDrawRectangle(
976 int nIsTRANSPARENT
= 0;
978 vY
= OS2Y(vY
,vHeight
);
980 wxCoord vX2
= vX
+ vWidth
;
981 wxCoord vY2
= vY
+ vHeight
;
985 vPoint
[1].x
= vX
+ vWidth
;
986 vPoint
[1].y
= vY
+ vHeight
;
987 ::GpiMove(m_hPS
, &vPoint
[0]);
988 lColor
= m_brush
.GetColour().GetPixel();
989 lBorderColor
= m_pen
.GetColour().GetPixel();
990 if (m_brush
.GetStyle() == wxTRANSPARENT
)
992 if(lColor
== lBorderColor
|| nIsTRANSPARENT
)
994 lControl
= DRO_OUTLINEFILL
; //DRO_FILL;
995 if(m_brush
.GetStyle() == wxTRANSPARENT
)
996 lControl
= DRO_OUTLINE
;
998 ::GpiSetColor(m_hPS
, lColor
);
999 ::GpiBox( m_hPS
// handle to a presentation space
1000 ,lControl
// draw the box outline ? or ?
1001 ,&vPoint
[1] // address of the corner
1002 ,0L // horizontal corner radius
1003 ,0L // vertical corner radius
1008 lControl
= DRO_OUTLINE
;
1009 ::GpiSetColor( m_hPS
1018 lControl
= DRO_FILL
;
1019 ::GpiSetColor( m_hPS
1022 vPoint
[0].x
= vX
+ 1;
1023 vPoint
[0].y
= vY
+ 1;
1024 vPoint
[1].x
= vX
+ vWidth
- 1;
1025 vPoint
[1].y
= vY
+ vHeight
- 1;
1026 ::GpiMove(m_hPS
, &vPoint
[0]);
1034 CalcBoundingBox(vX
, vY
);
1035 CalcBoundingBox(vX2
, vY2
);
1036 } // end of wxDC::DoDrawRectangle
1038 void wxDC::DoDrawRoundedRectangle(
1049 vY
= OS2Y(vY
,vHeight
);
1051 wxCoord vX2
= (vX
+ vWidth
);
1052 wxCoord vY2
= (vY
+ vHeight
);
1055 vPoint
[0].y
= YLOG2DEV(vY
) - vHeight
;
1056 vPoint
[1].x
= vX
+ vWidth
;
1058 ::GpiMove(m_hPS
, &vPoint
[0]);
1060 lControl
= DRO_OUTLINEFILL
; //DRO_FILL;
1061 if (m_brush
.GetStyle() == wxTRANSPARENT
)
1062 lControl
= DRO_OUTLINE
;
1063 ::GpiBox( m_hPS
// handle to a presentation space
1064 ,DRO_OUTLINE
// draw the box outline ? or ?
1065 ,&vPoint
[1] // address of the corner
1066 ,(LONG
)dRadius
// horizontal corner radius
1067 ,(LONG
)dRadius
// vertical corner radius
1069 CalcBoundingBox(vX
, vY
);
1070 CalcBoundingBox(vX2
, vY2
);
1071 } // end of wxDC::DoDrawRoundedRectangle
1073 // Draw Ellipse within box (x,y) - (x+width, y+height)
1074 void wxDC::DoDrawEllipse(
1081 POINTL vPtlPos
; // Structure for current position
1082 FIXED vFxMult
; // Multiplier for ellipse
1083 ARCPARAMS vArcp
; // Structure for arc parameters
1085 vY
= OS2Y(vY
,vHeight
);
1088 vArcp
.lQ
= vHeight
/2;
1089 vArcp
.lP
= vWidth
/2;
1091 ::GpiSetArcParams( m_hPS
1093 ); // Sets parameters to default
1094 vPtlPos
.x
= vX
+ vWidth
/2; // Loads x-coordinate
1095 vPtlPos
.y
= vY
+ vHeight
/2; // Loads y-coordinate
1098 ); // Sets current position
1099 vFxMult
= MAKEFIXED(1, 0); /* Sets multiplier */
1102 // DRO_FILL, DRO_OTLINEFILL - where to get
1107 ); // Draws full arc with center at current position
1109 wxCoord vX2
= (vX
+ vWidth
);
1110 wxCoord vY2
= (vY
+ vHeight
);
1112 CalcBoundingBox(vX
, vY
);
1113 CalcBoundingBox(vX2
, vY2
);
1114 } // end of wxDC::DoDrawEllipse
1116 void wxDC::DoDrawEllipticArc(
1125 POINTL vPtlPos
; // Structure for current position
1126 FIXED vFxMult
; // Multiplier for ellipse
1127 ARCPARAMS vArcp
; // Structure for arc parameters
1129 FIXED vFSweepa
; // Start angle, sweep angle
1134 vY
= OS2Y(vY
,vHeight
);
1136 dFractPart
= modf(dSa
,&dIntPart
);
1137 vFSa
= MAKEFIXED((int)dIntPart
, (int)(dFractPart
* 0xffff) );
1138 dFractPart
= modf(dEa
- dSa
, &dIntPart
);
1139 vFSweepa
= MAKEFIXED((int)dIntPart
, (int)(dFractPart
* 0xffff) );
1142 // Ellipse main axis (r,q), (p,s) with center at (0,0)
1145 vArcp
.lQ
= vHeight
/2;
1146 vArcp
.lP
= vWidth
/2;
1148 ::GpiSetArcParams(m_hPS
, &vArcp
); // Sets parameters to default
1149 vPtlPos
.x
= vX
+ vWidth
/2 * (1. + cos(DegToRad(dSa
))); // Loads x-coordinate
1150 vPtlPos
.y
= vY
+ vHeight
/2 * (1. + sin(DegToRad(dSa
))); // Loads y-coordinate
1151 ::GpiMove(m_hPS
, &vPtlPos
); // Sets current position
1154 // May be not to the center ?
1156 vPtlPos
.x
= vX
+ vWidth
/2 ; // Loads x-coordinate
1157 vPtlPos
.y
= vY
+ vHeight
/2; // Loads y-coordinate
1158 vFxMult
= MAKEFIXED(1, 0); // Sets multiplier
1161 // DRO_FILL, DRO_OTLINEFILL - where to get
1163 ::GpiPartialArc( m_hPS
1169 wxCoord vX2
= (vX
+ vWidth
);
1170 wxCoord vY2
= (vY
+ vHeight
);
1172 CalcBoundingBox(vX
, vY
);
1173 CalcBoundingBox(vX2
, vY2
);
1174 } // end of wxDC::DoDrawEllipticArc
1176 void wxDC::DoDrawIcon(
1182 vY
= OS2Y(vY
,rIcon
.GetHeight());
1183 wxCHECK_RET( rIcon
.Ok(), wxT("invalid icon in DrawIcon") );
1185 ::WinDrawPointer( GetHPS()
1188 ,(HPOINTER
)GetHiconOf(rIcon
)
1191 CalcBoundingBox(vX
, vY
);
1192 CalcBoundingBox(vX
+ rIcon
.GetWidth(), vY
+ rIcon
.GetHeight());
1193 } // end of wxDC::DoDrawIcon
1195 void wxDC::DoDrawBitmap(
1196 const wxBitmap
& rBmp
1202 if (!bUseMask
&& !IsKindOf(CLASSINFO(wxPrinterDC
)))
1204 HBITMAP hBitmap
= (HBITMAP
)rBmp
.GetHBITMAP();
1205 wxBitmap
vNewBitmap( rBmp
.GetWidth()
1209 HBITMAP hBitmapOld
= ::GpiSetBitmap((HPS
)GetHPS(), vNewBitmap
.GetHBITMAP());
1210 LONG lOldTextground
= ::GpiQueryColor((HPS
)GetHPS());
1211 LONG lOldBackground
= ::GpiQueryBackColor((HPS
)GetHPS());
1213 if (m_textForegroundColour
.Ok())
1215 ::GpiSetColor( (HPS
)GetHPS()
1216 ,m_textForegroundColour
.GetPixel()
1219 if (m_textBackgroundColour
.Ok())
1221 ::GpiSetBackColor( (HPS
)GetHPS()
1222 ,m_textBackgroundColour
.GetPixel()
1226 vY
= OS2Y(vY
,rBmp
.GetHeight());
1229 // Flip the picture as OS/2 is upside-down
1231 POINTL vPoint
[4] = { vX
, vY
+ rBmp
.GetHeight()
1232 ,vX
+ rBmp
.GetWidth(), vY
1234 ,rBmp
.GetWidth(), rBmp
.GetHeight()
1236 ::GpiWCBitBlt( (HPS
)GetHPS()
1243 ::GpiSetBitmap((HPS
)GetHPS(), hBitmapOld
);
1244 ::GpiSetColor((HPS
)GetHPS(), lOldTextground
);
1245 ::GpiSetBackColor((HPS
)GetHPS(), lOldBackground
);
1247 } // end of wxDC::DoDrawBitmap
1249 void wxDC::DoDrawText(
1250 const wxString
& rsText
1263 CalcBoundingBox(vX
, vY
);
1264 GetTextExtent(rsText
, &vWidth
, &vHeight
);
1265 CalcBoundingBox((vX
+ vWidth
), (vY
+ vHeight
));
1266 } // end of wxDC::DoDrawText
1268 void wxDC::DrawAnyText(
1269 const wxString
& rsText
1274 int nOldBackground
= 0;
1281 // prepare for drawing the text
1285 // Set text color attributes
1287 if (m_textForegroundColour
.Ok())
1290 ,(int)m_textForegroundColour
.GetPixel()
1294 if (m_textBackgroundColour
.Ok())
1296 nOldBackground
= SetTextBkColor( m_hPS
1297 ,(int)m_textBackgroundColour
.GetPixel()
1303 GetTextExtent( rsText
1308 vPtlStart
.y
= OS2Y(vY
,vTextY
);
1310 lHits
= ::GpiCharStringAt( m_hPS
1313 ,(PCH
)rsText
.c_str()
1315 if (lHits
!= GPI_OK
)
1317 wxLogLastError(wxT("TextOut"));
1321 // Restore the old parameters (text foreground colour may be left because
1322 // it never is set to anything else, but background should remain
1323 // transparent even if we just drew an opaque string)
1325 if (m_textBackgroundColour
.Ok())
1326 SetTextBkColor( m_hPS
1334 void wxDC::DoDrawRotatedText(
1335 const wxString
& rsText
1353 DoDrawText(text, x, y);
1358 wxFillLogFont(&lf, &m_font);
1360 // GDI wants the angle in tenth of degree
1361 long angle10 = (long)(angle * 10);
1362 lf.lfEscapement = angle10;
1363 lf. lfOrientation = angle10;
1365 HFONT hfont = ::CreateFontIndirect(&lf);
1368 wxLogLastError("CreateFont");
1372 HFONT hfontOld = ::SelectObject(GetHdc(), hfont);
1374 DrawAnyText(text, x, y);
1376 (void)::SelectObject(GetHdc(), hfontOld);
1379 // call the bounding box by adding all four vertices of the rectangle
1380 // containing the text to it (simpler and probably not slower than
1381 // determining which of them is really topmost/leftmost/...)
1383 GetTextExtent(text, &w, &h);
1385 double rad = DegToRad(angle);
1387 // "upper left" and "upper right"
1388 CalcBoundingBox(x, y);
1389 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
1390 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1392 // "bottom left" and "bottom right"
1393 x += (wxCoord)(h*sin(rad));
1394 y += (wxCoord)(h*cos(rad));
1395 CalcBoundingBox(x, y);
1396 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1401 // ---------------------------------------------------------------------------
1403 // ---------------------------------------------------------------------------
1405 void wxDC::DoSelectPalette(
1410 // Set the old object temporarily, in case the assignment deletes an object
1411 // that's not yet selected out.
1422 hOldPal
= ::GpiSelectPalette((HDC
) m_hPS
, (HPALETTE
) m_palette
.GetHPALETTE());
1424 m_hOldPalette
= (WXHPALETTE
)hOldPal
;
1426 } // end of wxDC::DoSelectPalette
1428 void wxDC::InitializePalette()
1430 if (wxDisplayDepth() <= 8 )
1433 // Look for any window or parent that has a custom palette. If any has
1434 // one then we need to use it in drawing operations
1436 wxWindow
* pWin
= m_pCanvas
->GetAncestorWithCustomPalette();
1438 m_hasCustomPalette
= pWin
&& pWin
->HasCustomPalette();
1439 if (m_hasCustomPalette
)
1441 m_palette
= pWin
->GetPalette();
1444 // turn on PM translation for this palette
1449 } // end of wxDC::InitializePalette
1451 void wxDC::SetPalette(
1452 const wxPalette
& rPalette
1459 m_palette
= rPalette
;
1467 HPALETTE hOldPal
= ::GpiSelectPalette((HDC
) m_hPS
, (HPALETTE
) m_palette
.GetHPALETTE());
1469 m_hOldPalette
= (WXHPALETTE
)hOldPal
;
1470 } // end of wxDC::SetPalette
1477 // Set the old object temporarily, in case the assignment deletes an object
1478 // that's not yet selected out.
1490 m_font
.SetPS(m_hPS
); // this will realize the font
1494 HFONT hFont
= m_font
.GetResourceHandle();
1495 if (hFont
== (HFONT
) NULL
)
1497 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1500 m_hOldFont
= (WXHFONT
) hFont
;
1502 } // end of wxDC::SetFont
1508 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1524 m_pen
.SetPS((HPS
)m_hOldPen
);
1531 if (m_pen
.GetResourceHandle())
1535 m_hOldPen
= m_pen
.GetPS();
1540 void wxDC::SetBrush(
1541 const wxBrush
& rBrush
1544 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1550 if (m_brush
== rBrush
)
1560 m_brush
.SetPS((HPS
)m_hOldBrush
);
1567 if (m_brush
.GetResourceHandle())
1569 m_brush
.SetPS(m_hPS
);
1571 m_hOldBrush
= (WXHWND
)m_brush
.GetPS();
1574 } // end of wxDC::SetBrush
1576 void wxDC::SetBackground(
1577 const wxBrush
& rBrush
1580 m_backgroundBrush
= rBrush
;
1581 if (!m_backgroundBrush
.Ok())
1585 bool bCustomColours
= TRUE
;
1588 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
1589 // change background colours from the control-panel specified colours.
1591 if (m_pCanvas
->IsKindOf(CLASSINFO(wxWindow
)) &&
1592 ((m_pCanvas
->GetWindowStyleFlag() & wxUSER_COLOURS
) != wxUSER_COLOURS
))
1593 bCustomColours
= FALSE
;
1596 if (m_backgroundBrush
.GetStyle()==wxTRANSPARENT
)
1598 m_pCanvas
->SetTransparent(TRUE
);
1603 // Setting the background brush of a DC
1604 // doesn't affect the window background colour. However,
1605 // I'm leaving in the transparency setting because it's needed by
1606 // various controls (e.g. wxStaticText) to determine whether to draw
1607 // transparently or not. TODO: maybe this should be a new function
1608 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
1610 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
1612 m_pCanvas
->SetTransparent(FALSE
);
1616 COLORREF vNewColor
= m_backgroundBrush
.GetColour().GetPixel();
1617 (void)::GpiSetBackColor((HPS
)m_hPS
, (LONG
)vNewColor
);
1618 } // end of wxDC::SetBackground
1620 void wxDC::SetBackgroundMode(
1624 m_backgroundMode
= nMode
;
1625 } // end of wxDC::SetBackgroundMode
1627 void wxDC::SetLogicalFunction(
1631 m_logicalFunction
= nFunction
;
1632 SetRop((WXHDC
)m_hDC
);
1633 } // wxDC::SetLogicalFunction
1639 if (!hDC
|| m_logicalFunction
< 0)
1643 switch (m_logicalFunction
)
1654 lCRop
= FM_MERGESRCNOT
;
1658 lCRop
= FM_NOTMASKSRC
;
1670 lCRop
= FM_MERGENOTSRC
;
1674 lCRop
= FM_MERGESRCNOT
;
1686 lCRop
= FM_SUBTRACT
;
1693 lCRop
= FM_OVERPAINT
;
1696 ::GpiSetMix((HPS
)hDC
, lCRop
);
1697 } // end of wxDC::SetRop
1699 bool wxDC::StartDoc(
1700 const wxString
& rsMessage
1703 // We might be previewing, so return TRUE to let it continue.
1705 } // end of wxDC::StartDoc
1709 } // end of wxDC::EndDoc
1711 void wxDC::StartPage()
1713 } // end of wxDC::StartPage
1715 void wxDC::EndPage()
1717 } // end of wxDC::EndPage
1719 // ---------------------------------------------------------------------------
1721 // ---------------------------------------------------------------------------
1723 wxCoord
wxDC::GetCharHeight() const
1725 FONTMETRICS vFM
; // metrics structure
1727 ::GpiQueryFontMetrics( m_hPS
1728 ,sizeof(FONTMETRICS
)
1731 return YDEV2LOGREL(vFM
.lXHeight
);
1734 wxCoord
wxDC::GetCharWidth() const
1736 FONTMETRICS vFM
; // metrics structure
1738 ::GpiQueryFontMetrics( m_hPS
1739 ,sizeof(FONTMETRICS
)
1742 return XDEV2LOGREL(vFM
.lAveCharWidth
);
1745 void wxDC::DoGetTextExtent(
1746 const wxString
& rsString
1749 , wxCoord
* pvDescent
1750 , wxCoord
* pvExternalLeading
1754 POINTL avPoint
[TXTBOX_COUNT
];
1759 FONTMETRICS vFM
; // metrics structure
1762 ERRORID vErrorCode
; // last error id code
1763 wxFont
* pFontToUse
= (wxFont
*)pTheFont
;
1765 char zMsg
[128]; // DEBUG
1769 pFontToUse
= (wxFont
*)&m_font
;
1770 l
= rsString
.length();
1771 pStr
= (PCH
) rsString
.c_str();
1774 // In world coordinates.
1776 bRc
= ::GpiQueryTextBox( m_hPS
1779 ,TXTBOX_COUNT
// return maximum information
1780 ,avPoint
// array of coordinates points
1784 vErrorCode
= ::WinGetLastError(wxGetInstance());
1785 sError
= wxPMErrorToStr(vErrorCode
);
1787 sprintf(zMsg
, "GpiQueryTextBox for %s: failed with Error: %x - %s", pStr
, vErrorCode
, sError
.c_str());
1788 (void)wxMessageBox( "wxWindows Menu sample"
1794 vPtMin
.x
= avPoint
[0].x
;
1795 vPtMax
.x
= avPoint
[0].x
;
1796 vPtMin
.y
= avPoint
[0].y
;
1797 vPtMax
.y
= avPoint
[0].y
;
1798 for (i
= 1; i
< 4; i
++)
1800 if(vPtMin
.x
> avPoint
[i
].x
) vPtMin
.x
= avPoint
[i
].x
;
1801 if(vPtMin
.y
> avPoint
[i
].y
) vPtMin
.y
= avPoint
[i
].y
;
1802 if(vPtMax
.x
< avPoint
[i
].x
) vPtMax
.x
= avPoint
[i
].x
;
1803 if(vPtMax
.y
< avPoint
[i
].y
) vPtMax
.y
= avPoint
[i
].y
;
1805 ::GpiQueryFontMetrics( m_hPS
1806 ,sizeof(FONTMETRICS
)
1811 *pvX
= (wxCoord
)(vPtMax
.x
- vPtMin
.x
+ 1);
1813 *pvY
= (wxCoord
)(vPtMax
.y
- vPtMin
.y
+ 1);
1815 *pvDescent
= vFM
.lMaxDescender
;
1816 if (pvExternalLeading
)
1817 *pvExternalLeading
= vFM
.lExternalLeading
;
1820 void wxDC::SetMapMode(
1824 int nPixelWidth
= 0;
1825 int nPixelHeight
= 0;
1828 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
1830 m_mappingMode
= nMode
;
1832 if(::DevQueryCaps( m_hDC
1834 ,CAPS_VERTICAL_RESOLUTION
1841 nPixelWidth
= lArray
[CAPS_WIDTH
];
1842 nPixelHeight
= lArray
[CAPS_HEIGHT
];
1843 lHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
1844 lVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
1845 nMmWidth
= (lHorzRes
/1000) * nPixelWidth
;
1846 nMmWidth
= (lVertRes
/1000) * nPixelHeight
;
1848 if ((nPixelWidth
== 0) || (nPixelHeight
== 0) || (nMmWidth
== 0) || (nMmHeight
== 0))
1853 double dMm2pixelsX
= nPixelWidth
/nMmWidth
;
1854 double dMm2pixelsY
= nPixelHeight
/nMmHeight
;
1859 m_logicalScaleX
= (twips2mm
* dMm2pixelsX
);
1860 m_logicalScaleY
= (twips2mm
* dMm2pixelsY
);
1864 m_logicalScaleX
= (pt2mm
* dMm2pixelsX
);
1865 m_logicalScaleY
= (pt2mm
* dMm2pixelsY
);
1869 m_logicalScaleX
= dMm2pixelsX
;
1870 m_logicalScaleY
= dMm2pixelsY
;
1874 m_logicalScaleX
= (dMm2pixelsX
/10.0);
1875 m_logicalScaleY
= (dMm2pixelsY
/10.0);
1880 m_logicalScaleX
= 1.0;
1881 m_logicalScaleY
= 1.0;
1887 ulOptions
= ::GpiQueryPS(m_hPS
, &vSize
);
1888 if (!ulOptions
& PU_ARBITRARY
)
1890 ulOptions
= PU_ARBITRARY
| GPIF_DEFAULT
;
1891 ::GpiSetPS(m_hPS
, &vSize
, ulOptions
);
1893 m_nWindowExtX
= (int)MS_XDEV2LOG(VIEWPORT_EXTENT
);
1894 m_nWindowExtY
= (int)MS_YDEV2LOG(VIEWPORT_EXTENT
);
1896 }; // end of wxDC::SetMapMode
1898 void wxDC::SetUserScale(
1906 SetMapMode(m_mappingMode
);
1907 } // end of wxDC::SetUserScale
1909 void wxDC::SetAxisOrientation(
1914 m_signX
= bXLeftRight
? 1 : -1;
1915 m_signY
= bYBottomUp
? -1 : 1;
1917 SetMapMode(m_mappingMode
);
1918 } // end of wxDC::SetAxisOrientation
1920 void wxDC::SetSystemScale(
1928 SetMapMode(m_mappingMode
);
1929 } // end of wxDC::SetSystemScale
1931 void wxDC::SetLogicalOrigin(
1938 ::GpiQueryPageViewport( m_hPS
1945 ::GpiSetPageViewport( m_hPS
1948 }; // end of wxDC::SetLogicalOrigin
1950 void wxDC::SetDeviceOrigin(
1957 m_deviceOriginX
= vX
;
1958 m_deviceOriginY
= vY
;
1959 ::GpiQueryPageViewport( m_hPS
1964 vRect
.yBottom
-= vY
;
1966 ::GpiSetPageViewport( m_hPS
1969 }; // end of wxDC::SetDeviceOrigin
1971 // ---------------------------------------------------------------------------
1972 // coordinates transformations
1973 // ---------------------------------------------------------------------------
1975 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1977 return (wxCoord
) (((x
) - m_deviceOriginX
)/(m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
) - m_logicalOriginX
);
1980 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1982 // axis orientation is not taken into account for conversion of a distance
1983 return (wxCoord
) ((x
)/(m_logicalScaleX
*m_userScaleX
*m_scaleX
));
1986 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1988 return (wxCoord
) (((y
) - m_deviceOriginY
)/(m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
) - m_logicalOriginY
);
1991 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1993 // axis orientation is not taken into account for conversion of a distance
1994 return (wxCoord
) ((y
)/(m_logicalScaleY
*m_userScaleY
*m_scaleY
));
1997 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1999 return (wxCoord
) ((x
- m_logicalOriginX
)*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
+ m_deviceOriginX
);
2002 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2004 // axis orientation is not taken into account for conversion of a distance
2005 return (wxCoord
) (x
*m_logicalScaleX
*m_userScaleX
*m_scaleX
);
2008 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2010 return (wxCoord
) ((y
- m_logicalOriginY
)*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
+ m_deviceOriginY
);
2013 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2015 // axis orientation is not taken into account for conversion of a distance
2016 return (wxCoord
) (y
*m_logicalScaleY
*m_userScaleY
*m_scaleY
);
2019 // ---------------------------------------------------------------------------
2021 // ---------------------------------------------------------------------------
2037 wxMask
* pMask
= NULL
;
2039 COLORREF vOldTextColor
;
2040 COLORREF vOldBackground
= ::GpiQueryBackColor(m_hPS
);
2044 const wxBitmap
& rBmp
= pSource
->m_vSelectedBitmap
;
2046 pMask
= rBmp
.GetMask();
2047 if (!(rBmp
.Ok() && pMask
&& pMask
->GetMaskBitmap()))
2053 ::GpiQueryAttrs( m_hPS
2058 vOldTextColor
= (COLORREF
)vCbnd
.lColor
;
2060 if (m_textForegroundColour
.Ok())
2062 vCbnd
.lColor
= (LONG
)m_textForegroundColour
.GetPixel();
2063 ::GpiSetAttrs( m_hPS
// presentation-space handle
2064 ,PRIM_CHAR
// Char primitive.
2065 ,CBB_COLOR
// sets color.
2067 ,&vCbnd
// buffer for attributes.
2070 if (m_textBackgroundColour
.Ok())
2072 ::GpiSetBackColor(m_hPS
, (LONG
)m_textBackgroundColour
.GetPixel());
2075 LONG lRop
= ROP_SRCCOPY
;
2079 case wxXOR
: lRop
= ROP_SRCINVERT
; break;
2080 case wxINVERT
: lRop
= ROP_DSTINVERT
; break;
2081 case wxOR_REVERSE
: lRop
= 0x00DD0228; break;
2082 case wxAND_REVERSE
: lRop
= ROP_SRCERASE
; break;
2083 case wxCLEAR
: lRop
= ROP_ZERO
; break;
2084 case wxSET
: lRop
= ROP_ONE
; break;
2085 case wxOR_INVERT
: lRop
= ROP_MERGEPAINT
; break;
2086 case wxAND
: lRop
= ROP_SRCAND
; break;
2087 case wxOR
: lRop
= ROP_SRCPAINT
; break;
2088 case wxEQUIV
: lRop
= 0x00990066; break;
2089 case wxNAND
: lRop
= 0x007700E6; break;
2090 case wxAND_INVERT
: lRop
= 0x00220326; break;
2091 case wxCOPY
: lRop
= ROP_SRCCOPY
; break;
2092 case wxNO_OP
: lRop
= ROP_NOTSRCERASE
; break;
2093 case wxSRC_INVERT
: lRop
= ROP_SRCINVERT
; break;
2094 case wxNOR
: lRop
= ROP_NOTSRCCOPY
; break;
2096 wxFAIL_MSG( wxT("unsupported logical function") );
2105 // Blit bitmap with mask
2109 // Create a temp buffer bitmap and DCs/PSs to access it and the mask
2115 DEVOPENSTRUC vDOP
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
2116 BITMAPINFOHEADER2 vBmpHdr
;
2118 SIZEL vSize
= {0, 0};
2121 memset(&vBmpHdr
, 0, sizeof(BITMAPINFOHEADER2
));
2122 vBmpHdr
.cbFix
= sizeof(BITMAPINFOHEADER2
);
2123 vBmpHdr
.cx
= vWidth
;
2124 vBmpHdr
.cy
= vHeight
;
2125 vBmpHdr
.cPlanes
= 1;
2126 vBmpHdr
.cBitCount
= 24;
2128 #if wxUSE_DC_CACHEING
2132 // create a temp buffer bitmap and DCs to access it and the mask
2134 wxDCCacheEntry
* pDCCacheEntry1
= FindDCInCache( NULL
2137 wxDCCacheEntry
* pDCCacheEntry2
= FindDCInCache( pDCCacheEntry1
2140 wxDCCacheEntry
* pBitmapCacheEntry
= FindBitmapInCache( GetHPS()
2145 hPSMask
= pDCCacheEntry1
->m_hPS
;
2146 hDCBuffer
= (HDC
)pDCCacheEntry2
->m_hPS
;
2147 hBufBitmap
= (HBITMAP
)pBitmapCacheEntry
->m_hBitmap
;
2152 hDCMask
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
2153 hDCBuffer
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
2154 hPSMask
= ::GpiCreatePS(vHabmain
, hDCMask
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
2155 hPSBuffer
= ::GpiCreatePS(vHabmain
, hDCBuffer
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
2156 hBufBitmap
= ::GpiCreateBitmap(GetHPS(), &vBmpHdr
, 0L, NULL
, NULL
);
2159 POINTL aPoint1
[4] = { 0, 0
2162 ,vXdest
+ vWidth
, vYdest
+ vHeight
2164 POINTL aPoint2
[4] = { 0, 0
2167 ,vXsrc
+ vWidth
, vYsrc
+ vHeight
2169 POINTL aPoint3
[4] = { vXdest
, vYdest
2170 ,vXdest
+ vWidth
, vYdest
+ vHeight
2172 ,vXsrc
+ vWidth
, vYsrc
+ vHeight
2174 POINTL aPoint4
[4] = { vXdest
, vYdest
2175 ,vXdest
+ vWidth
, vYdest
+ vHeight
2179 ::GpiSetBitmap(hPSMask
, (HBITMAP
) pMask
->GetMaskBitmap());
2180 ::GpiSetBitmap(hPSBuffer
, (HBITMAP
) hBufBitmap
);
2183 // Copy dest to buffer
2185 rc
= ::GpiBitBlt( hPSBuffer
2192 if (rc
== GPI_ERROR
)
2194 wxLogLastError(wxT("BitBlt"));
2198 // Copy src to buffer using selected raster op
2200 rc
= ::GpiBitBlt( hPSBuffer
2207 if (rc
== GPI_ERROR
)
2209 wxLogLastError(wxT("BitBlt"));
2213 // Set masked area in buffer to BLACK (pixel value 0)
2215 COLORREF vPrevBkCol
= ::GpiQueryBackColor(GetHPS());
2216 COLORREF vPrevCol
= ::GpiQueryColor(GetHPS());
2218 ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255));
2219 ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0));
2221 rc
= ::GpiBitBlt( hPSBuffer
2228 if (rc
== GPI_ERROR
)
2230 wxLogLastError(wxT("BitBlt"));
2234 // Set unmasked area in dest to BLACK
2236 ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0));
2237 ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255));
2238 rc
= ::GpiBitBlt( GetHPS()
2245 if (rc
== GPI_ERROR
)
2247 wxLogLastError(wxT("BitBlt"));
2251 // Restore colours to original values
2253 ::GpiSetBackColor(GetHPS(), vPrevBkCol
);
2254 ::GpiSetColor(GetHPS(), vPrevCol
);
2257 // OR buffer to dest
2259 rc
= ::GpiBitBlt( GetHPS()
2266 if (rc
== GPI_ERROR
)
2269 wxLogLastError(wxT("BitBlt"));
2273 // Tidy up temporary DCs and bitmap
2275 ::GpiSetBitmap(hPSMask
, NULLHANDLE
);
2276 ::GpiSetBitmap(hPSBuffer
, NULLHANDLE
);
2277 #if !wxUSE_DC_CACHEING
2278 ::GpiDestroyPS(hPSMask
);
2279 ::GpiDestroyPS(hPSBuffer
);
2280 ::DevCloseDC(hDCMask
);
2281 ::DevCloseDC(hDCBuffer
);
2282 ::GpiDeleteBitmap(hBufBitmap
);
2286 else // no mask, just BitBlt() it
2288 POINTL aPoint
[4] = { vXdest
, vYdest
2289 ,vXdest
+ vWidth
, vYdest
+ vHeight
2291 ,vXsrc
+ vWidth
, vYsrc
+ vHeight
2294 bSuccess
= (::GpiBitBlt( m_hPS
2303 wxLogLastError(wxT("BitBlt"));
2306 vCbnd
.lColor
= (LONG
)vOldTextColor
;
2307 ::GpiSetAttrs( m_hPS
// presentation-space handle
2308 ,PRIM_CHAR
// Char primitive.
2309 ,CBB_COLOR
// sets color.
2311 ,&vCbnd
// buffer for attributes.
2313 ::GpiSetBackColor(m_hPS
, (LONG
)vOldBackground
);
2317 void wxDC::DoGetSize(
2322 LONG lArray
[CAPS_HEIGHT
];
2324 if(::DevQueryCaps( m_hDC
2330 *pnWidth
= lArray
[CAPS_WIDTH
];
2331 *pnHeight
= lArray
[CAPS_HEIGHT
];
2333 }; // end of wxDC::DoGetSize(
2335 void wxDC::DoGetSizeMM(
2340 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2342 if(::DevQueryCaps( m_hDC
2344 ,CAPS_VERTICAL_RESOLUTION
2353 nWidth
= lArray
[CAPS_WIDTH
];
2354 nHeight
= lArray
[CAPS_HEIGHT
];
2355 nHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2356 nVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2357 nWidth
= (nHorzRes
/1000) * nWidth
;
2358 nHeight
= (nVertRes
/1000) * nHeight
;
2360 }; // end of wxDC::DoGetSizeMM
2362 wxSize
wxDC::GetPPI() const
2364 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2368 if(::DevQueryCaps( m_hDC
2370 ,CAPS_VERTICAL_RESOLUTION
2379 nPelWidth
= lArray
[CAPS_WIDTH
];
2380 nPelHeight
= lArray
[CAPS_HEIGHT
];
2381 nHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2382 nVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2383 nWidth
= (nHorzRes
/39.3) * nPelWidth
;
2384 nHeight
= (nVertRes
/39.3) * nPelHeight
;
2386 return (wxSize(nWidth
,nHeight
));
2387 } // end of wxDC::GetPPI
2389 void wxDC::SetLogicalScale(
2394 m_logicalScaleX
= dX
;
2395 m_logicalScaleY
= dY
;
2396 }; // end of wxDC::SetLogicalScale
2398 #if WXWIN_COMPATIBILITY
2399 void wxDC::DoGetTextExtent(const wxString
& string
, float *x
, float *y
,
2400 float *descent
, float *externalLeading
,
2401 wxFont
*theFont
, bool use16bit
) const
2403 wxCoord x1
, y1
, descent1
, externalLeading1
;
2404 GetTextExtent(string
, & x1
, & y1
, & descent1
, & externalLeading1
, theFont
, use16bit
);
2407 *descent
= descent1
;
2408 if (externalLeading
)
2409 *externalLeading
= externalLeading1
;