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 } // end of wxDC::Clear
548 void wxDC::DoFloodFill(
551 , const wxColour
& rCol
559 vPtlPos
.x
= vX
; // Loads x-coordinate
560 vPtlPos
.y
= OS2Y(vY
,0); // Loads y-coordinate
561 ::GpiMove(m_hPS
, &vPtlPos
); // Sets current position
562 lColor
= rCol
.GetPixel();
563 lOptions
= FF_BOUNDARY
;
564 if(wxFLOOD_SURFACE
== nStyle
)
565 lOptions
= FF_SURFACE
;
567 ::GpiFloodFill(m_hPS
, lOptions
, lColor
);
568 } // end of wxDC::DoFloodFill
570 bool wxDC::DoGetPixel(
580 vPoint
.y
= OS2Y(vY
,0);
581 lColor
= ::GpiSetPel(m_hPS
, &vPoint
);
584 // Get the color of the pen
586 LONG lPencolor
= 0x00ffffff;
590 lPencolor
= m_pen
.GetColour().GetPixel();
594 // return the color of the pixel
597 pCol
->Set( GetRValue(lColor
)
601 return(lColor
== lPencolor
);
602 } // end of wxDC::DoGetPixel
604 void wxDC::DoCrossHair(
611 wxCoord vX1
= vX
- VIEWPORT_EXTENT
;
612 wxCoord vY1
= vY
- VIEWPORT_EXTENT
;
613 wxCoord vX2
= vX
+ VIEWPORT_EXTENT
;
614 wxCoord vY2
= vY
+ VIEWPORT_EXTENT
;
623 ::GpiMove(m_hPS
, &vPoint
[0]);
624 ::GpiLine(m_hPS
, &vPoint
[1]);
632 ::GpiMove(m_hPS
, &vPoint
[2]);
633 ::GpiLine(m_hPS
, &vPoint
[3]);
634 CalcBoundingBox(vX1
, vY1
);
635 CalcBoundingBox(vX2
, vY2
);
636 } // end of wxDC::DoCrossHair
638 void wxDC::DoDrawLine(
654 ::GpiMove(m_hPS
, &vPoint
[0]);
655 ::GpiLine(m_hPS
, &vPoint
[1]);
656 CalcBoundingBox(vX1
, vY1
);
657 CalcBoundingBox(vX2
, vY2
);
658 } // end of wxDC::DoDrawLine
660 //////////////////////////////////////////////////////////////////////////////
661 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
662 // and ending at (x2, y2). The current pen is used for the outline and the
663 // current brush for filling the shape. The arc is drawn in an anticlockwise
664 // direction from the start point to the end point.
665 //////////////////////////////////////////////////////////////////////////////
666 void wxDC::DoDrawArc(
676 POINTL vPtlArc
[2]; // Structure for current position
685 ARCPARAMS vArcp
; // Structure for arc parameters
687 if((vX1
== vXc
&& vY1
== vXc
) || (vX2
== vXc
&& vY2
== vXc
))
688 return; // Draw point ??
689 dRadius
= 0.5 * ( hypot( (double)(vY1
- vYc
)
692 hypot( (double)(vY2
- vYc
)
697 dAngl1
= atan2( (double)(vY1
- vYc
)
700 dAngl2
= atan2( (double)(vY2
- vYc
)
707 // GpiPointArc can't draw full arc
709 if(dAngl2
== dAngl1
|| (vX1
== vX2
&& vY1
== vY2
) )
714 dAnglmid
= (dAngl1
+ dAngl2
)/2. + M_PI
;
715 vXm
= vXc
+ dRadius
* cos(dAnglmid
);
716 vYm
= vYc
+ dRadius
* sin(dAnglmid
);
731 dAnglmid
= (dAngl1
+ dAngl2
)/2.;
732 vXm
= vXc
+ dRadius
* cos(dAnglmid
);
733 vYm
= vYc
+ dRadius
* sin(dAnglmid
);
736 // Ellipse main axis (r,q), (p,s) with center at (0,0) */
742 ::GpiSetArcParams(m_hPS
, &vArcp
); // Sets parameters to default
744 vPtlPos
.x
= vX1
; // Loads x-coordinate
745 vPtlPos
.y
= vY1
; // Loads y-coordinate
746 ::GpiMove(m_hPS
, &vPtlPos
); // Sets current position
751 ::GpiPointArc(m_hPS
, vPtlArc
); // Draws the arc
752 CalcBoundingBox( (vXc
- dRadius
)
755 CalcBoundingBox( (vXc
+ dRadius
)
758 } // end of wxDC::DoDrawArc
760 void wxDC::DoDrawCheckMark(
769 vY1
= OS2Y(vY1
,vHeight
);
773 vPoint
[1].x
= vX1
+ vWidth
;
774 vPoint
[1].y
= vY1
+ vHeight
;
776 ::GpiMove(m_hPS
, &vPoint
[0]);
777 ::GpiBox( m_hPS
// handle to a presentation space
778 ,DRO_OUTLINE
// draw the box outline ? or ?
779 ,&vPoint
[1] // address of the corner
780 ,0L // horizontal corner radius
781 ,0L // vertical corner radius
783 if(vWidth
> 4 && vHeight
> 4)
787 vPoint
[0].x
+= 2; vPoint
[0].y
+= 2;
788 vPoint
[1].x
-= 2; vPoint
[1].y
-= 2;
789 ::GpiMove(m_hPS
, &vPoint
[0]);
790 ::GpiLine(m_hPS
, &vPoint
[1]);
792 vPoint
[0].x
= vPoint
[1].x
;
794 ::GpiMove(m_hPS
, &vPoint
[0]);
795 ::GpiLine(m_hPS
, &vPoint
[1]);
801 wxCoord vX2
= vX1
+ vWidth
;
802 wxCoord vY2
= vY1
+ vHeight
;
807 } // end of wxDC::DoDrawCheckMark
809 void wxDC::DoDrawPoint(
815 COLORREF vColor
= 0x00ffffff;
819 vColor
= m_pen
.GetColour().GetPixel();
821 ::GpiSetColor(m_hPS
, vColor
);
823 vPoint
.y
= OS2Y(vY
,0);
824 ::GpiSetPel(m_hPS
, &vPoint
);
828 } // end of wxDC::DoDrawPoint
830 void wxDC::DoDrawPolygon(
838 ULONG ulCount
= 1; // Number of polygons.
839 POLYGON vPlgn
; // polygon.
840 ULONG flOptions
= 0L; // Drawing options.
842 //////////////////////////////////////////////////////////////////////////////
843 // This contains fields of option bits... to draw boundary lines as well as
844 // the area interior.
846 // Drawing boundary lines:
847 // POLYGON_NOBOUNDARY Does not draw boundary lines.
848 // POLYGON_BOUNDARY Draws boundary lines (the default).
850 // Construction of the area interior:
851 // POLYGON_ALTERNATE Constructs interior in alternate mode
853 // POLYGON_WINDING Constructs interior in winding mode.
854 //////////////////////////////////////////////////////////////////////////////
856 ULONG flModel
= 0L; // Drawing model.
858 //////////////////////////////////////////////////////////////////////////////
860 // POLYGON_INCL Fill is inclusive of bottom right (the default).
861 // POLYGON_EXCL Fill is exclusive of bottom right.
862 // This is provided to aid migration from other graphics models.
863 //////////////////////////////////////////////////////////////////////////////
865 LONG lHits
= 0L; // Correlation/error indicator.
868 int nIsTRANSPARENT
= 0;
869 LONG lBorderColor
= 0L;
872 lBorderColor
= m_pen
.GetColour().GetPixel();
873 lColor
= m_brush
.GetColour().GetPixel();
874 if(m_brush
.GetStyle() == wxTRANSPARENT
)
878 vPlgn
.aPointl
= (POINTL
*) calloc( n
+ 1
880 ); // well, new will call malloc
882 for(i
= 0; i
< n
; i
++)
884 vPlgn
.aPointl
[i
].x
= vPoints
[i
].x
; // +xoffset;
885 vPlgn
.aPointl
[i
].y
= OS2Y(vPoints
[i
].y
,0); // +yoffset;
887 flModel
= POLYGON_BOUNDARY
;
888 if(nFillStyle
== wxWINDING_RULE
)
889 flModel
|= POLYGON_WINDING
;
891 flModel
|= POLYGON_ALTERNATE
;
894 vPoint
.y
= OS2Y(vYoffset
,0);
896 ::GpiSetColor(m_hPS
, lBorderColor
);
897 ::GpiMove(m_hPS
, &vPoint
);
898 lHits
= ::GpiPolygons(m_hPS
, ulCount
, &vPlgn
, flOptions
, flModel
);
900 } // end of wxDC::DoDrawPolygon
902 void wxDC::DoDrawLines(
911 if (vXoffset
!= 0L || vXoffset
!= 0L)
915 vPoint
.x
= vPoints
[0].x
+ vXoffset
;
916 vPoint
.y
= OS2Y(vPoints
[0].y
+ vYoffset
,0);
917 ::GpiMove(m_hPS
, &vPoint
);
919 LONG lBorderColor
= m_pen
.GetColour().GetPixel();
921 ::GpiSetColor(m_hPS
, lBorderColor
);
922 for(i
= 1; i
< n
; i
++)
924 vPoint
.x
= vPoints
[i
].x
+ vXoffset
;
925 vPoint
.y
= OS2Y(vPoints
[i
].y
+ vYoffset
,0);
926 ::GpiLine(m_hPS
, &vPoint
);
933 CalcBoundingBox( vPoints
[i
].x
936 vPoint
.x
= vPoints
[0].x
;
937 vPoint
.y
= OS2Y(vPoints
[0].y
,0);
938 ::GpiMove(m_hPS
, &vPoint
);
940 for (i
= 0; i
< n
; i
++)
942 CalcBoundingBox( vPoints
[i
].x
945 vPoint
.x
= vPoints
[i
].x
;
946 vPoint
.y
= OS2Y(vPoints
[i
].y
,0);
947 ::GpiLine(m_hPS
, &vPoint
);
950 } // end of wxDC::DoDrawLines
952 void wxDC::DoDrawRectangle(
963 int nIsTRANSPARENT
= 0;
965 vY
= OS2Y(vY
,vHeight
);
967 wxCoord vX2
= vX
+ vWidth
;
968 wxCoord vY2
= vY
+ vHeight
;
972 vPoint
[1].x
= vX
+ vWidth
;
973 vPoint
[1].y
= vY
+ vHeight
;
974 ::GpiMove(m_hPS
, &vPoint
[0]);
975 lColor
= m_brush
.GetColour().GetPixel();
976 lBorderColor
= m_pen
.GetColour().GetPixel();
977 if (m_brush
.GetStyle() == wxTRANSPARENT
)
979 if(lColor
== lBorderColor
|| nIsTRANSPARENT
)
981 lControl
= DRO_OUTLINEFILL
; //DRO_FILL;
982 if(m_brush
.GetStyle() == wxTRANSPARENT
)
983 lControl
= DRO_OUTLINE
;
985 ::GpiSetColor(m_hPS
, lColor
);
986 ::GpiBox( m_hPS
// handle to a presentation space
987 ,lControl
// draw the box outline ? or ?
988 ,&vPoint
[1] // address of the corner
989 ,0L // horizontal corner radius
990 ,0L // vertical corner radius
995 lControl
= DRO_OUTLINE
;
1005 lControl
= DRO_FILL
;
1006 ::GpiSetColor( m_hPS
1009 vPoint
[0].x
= vX
+ 1;
1010 vPoint
[0].y
= vY
+ 1;
1011 vPoint
[1].x
= vX
+ vWidth
- 1;
1012 vPoint
[1].y
= vY
+ vHeight
- 1;
1013 ::GpiMove(m_hPS
, &vPoint
[0]);
1021 CalcBoundingBox(vX
, vY
);
1022 CalcBoundingBox(vX2
, vY2
);
1023 } // end of wxDC::DoDrawRectangle
1025 void wxDC::DoDrawRoundedRectangle(
1036 vY
= OS2Y(vY
,vHeight
);
1038 wxCoord vX2
= (vX
+ vWidth
);
1039 wxCoord vY2
= (vY
+ vHeight
);
1042 vPoint
[0].y
= YLOG2DEV(vY
) - vHeight
;
1043 vPoint
[1].x
= vX
+ vWidth
;
1045 ::GpiMove(m_hPS
, &vPoint
[0]);
1047 lControl
= DRO_OUTLINEFILL
; //DRO_FILL;
1048 if (m_brush
.GetStyle() == wxTRANSPARENT
)
1049 lControl
= DRO_OUTLINE
;
1050 ::GpiBox( m_hPS
// handle to a presentation space
1051 ,DRO_OUTLINE
// draw the box outline ? or ?
1052 ,&vPoint
[1] // address of the corner
1053 ,(LONG
)dRadius
// horizontal corner radius
1054 ,(LONG
)dRadius
// vertical corner radius
1056 CalcBoundingBox(vX
, vY
);
1057 CalcBoundingBox(vX2
, vY2
);
1058 } // end of wxDC::DoDrawRoundedRectangle
1060 // Draw Ellipse within box (x,y) - (x+width, y+height)
1061 void wxDC::DoDrawEllipse(
1068 POINTL vPtlPos
; // Structure for current position
1069 FIXED vFxMult
; // Multiplier for ellipse
1070 ARCPARAMS vArcp
; // Structure for arc parameters
1072 vY
= OS2Y(vY
,vHeight
);
1075 vArcp
.lQ
= vHeight
/2;
1076 vArcp
.lP
= vWidth
/2;
1078 ::GpiSetArcParams( m_hPS
1080 ); // Sets parameters to default
1081 vPtlPos
.x
= vX
+ vWidth
/2; // Loads x-coordinate
1082 vPtlPos
.y
= vY
+ vHeight
/2; // Loads y-coordinate
1085 ); // Sets current position
1086 vFxMult
= MAKEFIXED(1, 0); /* Sets multiplier */
1089 // DRO_FILL, DRO_OTLINEFILL - where to get
1094 ); // Draws full arc with center at current position
1096 wxCoord vX2
= (vX
+ vWidth
);
1097 wxCoord vY2
= (vY
+ vHeight
);
1099 CalcBoundingBox(vX
, vY
);
1100 CalcBoundingBox(vX2
, vY2
);
1101 } // end of wxDC::DoDrawEllipse
1103 void wxDC::DoDrawEllipticArc(
1112 POINTL vPtlPos
; // Structure for current position
1113 FIXED vFxMult
; // Multiplier for ellipse
1114 ARCPARAMS vArcp
; // Structure for arc parameters
1116 FIXED vFSweepa
; // Start angle, sweep angle
1121 vY
= OS2Y(vY
,vHeight
);
1123 dFractPart
= modf(dSa
,&dIntPart
);
1124 vFSa
= MAKEFIXED((int)dIntPart
, (int)(dFractPart
* 0xffff) );
1125 dFractPart
= modf(dEa
- dSa
, &dIntPart
);
1126 vFSweepa
= MAKEFIXED((int)dIntPart
, (int)(dFractPart
* 0xffff) );
1129 // Ellipse main axis (r,q), (p,s) with center at (0,0)
1132 vArcp
.lQ
= vHeight
/2;
1133 vArcp
.lP
= vWidth
/2;
1135 ::GpiSetArcParams(m_hPS
, &vArcp
); // Sets parameters to default
1136 vPtlPos
.x
= vX
+ vWidth
/2 * (1. + cos(DegToRad(dSa
))); // Loads x-coordinate
1137 vPtlPos
.y
= vY
+ vHeight
/2 * (1. + sin(DegToRad(dSa
))); // Loads y-coordinate
1138 ::GpiMove(m_hPS
, &vPtlPos
); // Sets current position
1141 // May be not to the center ?
1143 vPtlPos
.x
= vX
+ vWidth
/2 ; // Loads x-coordinate
1144 vPtlPos
.y
= vY
+ vHeight
/2; // Loads y-coordinate
1145 vFxMult
= MAKEFIXED(1, 0); // Sets multiplier
1148 // DRO_FILL, DRO_OTLINEFILL - where to get
1150 ::GpiPartialArc( m_hPS
1156 wxCoord vX2
= (vX
+ vWidth
);
1157 wxCoord vY2
= (vY
+ vHeight
);
1159 CalcBoundingBox(vX
, vY
);
1160 CalcBoundingBox(vX2
, vY2
);
1161 } // end of wxDC::DoDrawEllipticArc
1163 void wxDC::DoDrawIcon(
1169 vY
= OS2Y(vY
,rIcon
.GetHeight());
1170 wxCHECK_RET( rIcon
.Ok(), wxT("invalid icon in DrawIcon") );
1172 ::WinDrawPointer( GetHPS()
1175 ,(HPOINTER
)GetHiconOf(rIcon
)
1178 CalcBoundingBox(vX
, vY
);
1179 CalcBoundingBox(vX
+ rIcon
.GetWidth(), vY
+ rIcon
.GetHeight());
1180 } // end of wxDC::DoDrawIcon
1182 void wxDC::DoDrawBitmap(
1183 const wxBitmap
& rBmp
1189 POINTL vPoint
= {vX
, vY
};
1191 ::WinDrawBitmap( GetHPS()
1192 ,(HBITMAP
)GetHbitmapOf(rBmp
)
1199 } // end of wxDC::DoDrawBitmap
1201 void wxDC::DoDrawText(
1202 const wxString
& rsText
1215 CalcBoundingBox(vX
, vY
);
1216 GetTextExtent(rsText
, &vWidth
, &vHeight
);
1217 CalcBoundingBox((vX
+ vWidth
), (vY
+ vHeight
));
1218 } // end of wxDC::DoDrawText
1220 void wxDC::DrawAnyText(
1221 const wxString
& rsText
1226 int nOldBackground
= 0;
1233 // prepare for drawing the text
1237 // Set text color attributes
1239 if (m_textForegroundColour
.Ok())
1242 ,(int)m_textForegroundColour
.GetPixel()
1246 if (m_textBackgroundColour
.Ok())
1248 nOldBackground
= SetTextBkColor( m_hPS
1249 ,(int)m_textBackgroundColour
.GetPixel()
1255 GetTextExtent( rsText
1260 vPtlStart
.y
= OS2Y(vY
,vTextY
);
1262 lHits
= ::GpiCharStringAt( m_hPS
1265 ,(PCH
)rsText
.c_str()
1267 if (lHits
!= GPI_OK
)
1269 wxLogLastError(wxT("TextOut"));
1273 // Restore the old parameters (text foreground colour may be left because
1274 // it never is set to anything else, but background should remain
1275 // transparent even if we just drew an opaque string)
1277 if (m_textBackgroundColour
.Ok())
1278 SetTextBkColor( m_hPS
1286 void wxDC::DoDrawRotatedText(
1287 const wxString
& rsText
1305 DoDrawText(text, x, y);
1310 wxFillLogFont(&lf, &m_font);
1312 // GDI wants the angle in tenth of degree
1313 long angle10 = (long)(angle * 10);
1314 lf.lfEscapement = angle10;
1315 lf. lfOrientation = angle10;
1317 HFONT hfont = ::CreateFontIndirect(&lf);
1320 wxLogLastError("CreateFont");
1324 HFONT hfontOld = ::SelectObject(GetHdc(), hfont);
1326 DrawAnyText(text, x, y);
1328 (void)::SelectObject(GetHdc(), hfontOld);
1331 // call the bounding box by adding all four vertices of the rectangle
1332 // containing the text to it (simpler and probably not slower than
1333 // determining which of them is really topmost/leftmost/...)
1335 GetTextExtent(text, &w, &h);
1337 double rad = DegToRad(angle);
1339 // "upper left" and "upper right"
1340 CalcBoundingBox(x, y);
1341 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
1342 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1344 // "bottom left" and "bottom right"
1345 x += (wxCoord)(h*sin(rad));
1346 y += (wxCoord)(h*cos(rad));
1347 CalcBoundingBox(x, y);
1348 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1353 // ---------------------------------------------------------------------------
1355 // ---------------------------------------------------------------------------
1357 void wxDC::SetPalette(
1358 const wxPalette
& rPalette
1365 m_palette
= rPalette
;
1373 HPALETTE hOldPal
= ::GpiSelectPalette((HDC
) m_hPS
, (HPALETTE
) m_palette
.GetHPALETTE());
1375 m_hOldPalette
= (WXHPALETTE
)hOldPal
;
1376 } // end of wxDC::SetPalette
1383 // Set the old object temporarily, in case the assignment deletes an object
1384 // that's not yet selected out.
1396 m_font
.SetPS(m_hPS
); // this will realize the font
1400 HFONT hFont
= m_font
.GetResourceHandle();
1401 if (hFont
== (HFONT
) NULL
)
1403 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1406 m_hOldFont
= (WXHFONT
) hFont
;
1408 } // end of wxDC::SetFont
1414 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1430 m_pen
.SetPS((HPS
)m_hOldPen
);
1437 if (m_pen
.GetResourceHandle())
1441 m_hOldPen
= m_pen
.GetPS();
1446 void wxDC::SetBrush(
1447 const wxBrush
& rBrush
1450 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1456 if (m_brush
== rBrush
)
1466 m_brush
.SetPS((HPS
)m_hOldBrush
);
1473 if (m_brush
.GetResourceHandle())
1475 m_brush
.SetPS(m_hPS
);
1477 m_hOldBrush
= (WXHWND
)m_brush
.GetPS();
1480 } // end of wxDC::SetBrush
1482 void wxDC::SetBackground(
1483 const wxBrush
& rBrush
1486 m_backgroundBrush
= rBrush
;
1487 if (!m_backgroundBrush
.Ok())
1491 bool bCustomColours
= TRUE
;
1494 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
1495 // change background colours from the control-panel specified colours.
1497 if (m_pCanvas
->IsKindOf(CLASSINFO(wxWindow
)) &&
1498 ((m_pCanvas
->GetWindowStyleFlag() & wxUSER_COLOURS
) != wxUSER_COLOURS
))
1499 bCustomColours
= FALSE
;
1502 if (m_backgroundBrush
.GetStyle()==wxTRANSPARENT
)
1504 m_pCanvas
->SetTransparent(TRUE
);
1509 // Setting the background brush of a DC
1510 // doesn't affect the window background colour. However,
1511 // I'm leaving in the transparency setting because it's needed by
1512 // various controls (e.g. wxStaticText) to determine whether to draw
1513 // transparently or not. TODO: maybe this should be a new function
1514 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
1516 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
1518 m_pCanvas
->SetTransparent(FALSE
);
1522 COLORREF vNewColor
= m_backgroundBrush
.GetColour().GetPixel();
1523 (void)::GpiSetBackColor((HPS
)m_hPS
, (LONG
)vNewColor
);
1524 } // end of wxDC::SetBackground
1526 void wxDC::SetBackgroundMode(
1530 m_backgroundMode
= nMode
;
1531 } // end of wxDC::SetBackgroundMode
1533 void wxDC::SetLogicalFunction(
1537 m_logicalFunction
= nFunction
;
1538 SetRop((WXHDC
)m_hDC
);
1539 } // wxDC::SetLogicalFunction
1545 if (!hDC
|| m_logicalFunction
< 0)
1549 switch (m_logicalFunction
)
1560 lCRop
= FM_MERGESRCNOT
;
1564 lCRop
= FM_NOTMASKSRC
;
1576 lCRop
= FM_MERGENOTSRC
;
1580 lCRop
= FM_MERGESRCNOT
;
1592 lCRop
= FM_SUBTRACT
;
1599 lCRop
= FM_OVERPAINT
;
1602 ::GpiSetMix((HPS
)hDC
, lCRop
);
1603 } // end of wxDC::SetRop
1605 bool wxDC::StartDoc(
1606 const wxString
& rsMessage
1609 // We might be previewing, so return TRUE to let it continue.
1611 } // end of wxDC::StartDoc
1615 } // end of wxDC::EndDoc
1617 void wxDC::StartPage()
1619 } // end of wxDC::StartPage
1621 void wxDC::EndPage()
1623 } // end of wxDC::EndPage
1625 // ---------------------------------------------------------------------------
1627 // ---------------------------------------------------------------------------
1629 wxCoord
wxDC::GetCharHeight() const
1631 FONTMETRICS vFM
; // metrics structure
1633 ::GpiQueryFontMetrics( m_hPS
1634 ,sizeof(FONTMETRICS
)
1637 return YDEV2LOGREL(vFM
.lXHeight
);
1640 wxCoord
wxDC::GetCharWidth() const
1642 FONTMETRICS vFM
; // metrics structure
1644 ::GpiQueryFontMetrics( m_hPS
1645 ,sizeof(FONTMETRICS
)
1648 return XDEV2LOGREL(vFM
.lAveCharWidth
);
1651 void wxDC::DoGetTextExtent(
1652 const wxString
& rsString
1655 , wxCoord
* pvDescent
1656 , wxCoord
* pvExternalLeading
1660 POINTL avPoint
[TXTBOX_COUNT
];
1665 FONTMETRICS vFM
; // metrics structure
1668 ERRORID vErrorCode
; // last error id code
1669 wxFont
* pFontToUse
= (wxFont
*)pTheFont
;
1671 char zMsg
[128]; // DEBUG
1675 pFontToUse
= (wxFont
*)&m_font
;
1676 l
= rsString
.length();
1677 pStr
= (PCH
) rsString
.c_str();
1680 // In world coordinates.
1682 bRc
= ::GpiQueryTextBox( m_hPS
1685 ,TXTBOX_COUNT
// return maximum information
1686 ,avPoint
// array of coordinates points
1690 vErrorCode
= ::WinGetLastError(wxGetInstance());
1691 sError
= wxPMErrorToStr(vErrorCode
);
1693 sprintf(zMsg
, "GpiQueryTextBox for %s: failed with Error: %x - %s", pStr
, vErrorCode
, sError
.c_str());
1694 (void)wxMessageBox( "wxWindows Menu sample"
1700 vPtMin
.x
= avPoint
[0].x
;
1701 vPtMax
.x
= avPoint
[0].x
;
1702 vPtMin
.y
= avPoint
[0].y
;
1703 vPtMax
.y
= avPoint
[0].y
;
1704 for (i
= 1; i
< 4; i
++)
1706 if(vPtMin
.x
> avPoint
[i
].x
) vPtMin
.x
= avPoint
[i
].x
;
1707 if(vPtMin
.y
> avPoint
[i
].y
) vPtMin
.y
= avPoint
[i
].y
;
1708 if(vPtMax
.x
< avPoint
[i
].x
) vPtMax
.x
= avPoint
[i
].x
;
1709 if(vPtMax
.y
< avPoint
[i
].y
) vPtMax
.y
= avPoint
[i
].y
;
1711 ::GpiQueryFontMetrics( m_hPS
1712 ,sizeof(FONTMETRICS
)
1717 *pvX
= (wxCoord
)(vPtMax
.x
- vPtMin
.x
+ 1);
1719 *pvY
= (wxCoord
)(vPtMax
.y
- vPtMin
.y
+ 1);
1721 *pvDescent
= vFM
.lMaxDescender
;
1722 if (pvExternalLeading
)
1723 *pvExternalLeading
= vFM
.lExternalLeading
;
1726 void wxDC::SetMapMode(
1730 int nPixelWidth
= 0;
1731 int nPixelHeight
= 0;
1734 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
1736 m_mappingMode
= nMode
;
1738 if(::DevQueryCaps( m_hDC
1740 ,CAPS_VERTICAL_RESOLUTION
1747 nPixelWidth
= lArray
[CAPS_WIDTH
];
1748 nPixelHeight
= lArray
[CAPS_HEIGHT
];
1749 lHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
1750 lVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
1751 nMmWidth
= (lHorzRes
/1000) * nPixelWidth
;
1752 nMmWidth
= (lVertRes
/1000) * nPixelHeight
;
1754 if ((nPixelWidth
== 0) || (nPixelHeight
== 0) || (nMmWidth
== 0) || (nMmHeight
== 0))
1759 double dMm2pixelsX
= nPixelWidth
/nMmWidth
;
1760 double dMm2pixelsY
= nPixelHeight
/nMmHeight
;
1765 m_logicalScaleX
= (twips2mm
* dMm2pixelsX
);
1766 m_logicalScaleY
= (twips2mm
* dMm2pixelsY
);
1770 m_logicalScaleX
= (pt2mm
* dMm2pixelsX
);
1771 m_logicalScaleY
= (pt2mm
* dMm2pixelsY
);
1775 m_logicalScaleX
= dMm2pixelsX
;
1776 m_logicalScaleY
= dMm2pixelsY
;
1780 m_logicalScaleX
= (dMm2pixelsX
/10.0);
1781 m_logicalScaleY
= (dMm2pixelsY
/10.0);
1786 m_logicalScaleX
= 1.0;
1787 m_logicalScaleY
= 1.0;
1793 ulOptions
= ::GpiQueryPS(m_hPS
, &vSize
);
1794 if (!ulOptions
& PU_ARBITRARY
)
1796 ulOptions
= PU_ARBITRARY
| GPIF_DEFAULT
;
1797 ::GpiSetPS(m_hPS
, &vSize
, ulOptions
);
1799 m_nWindowExtX
= (int)MS_XDEV2LOGREL(VIEWPORT_EXTENT
);
1800 m_nWindowExtY
= (int)MS_YDEV2LOGREL(VIEWPORT_EXTENT
);
1802 }; // end of wxDC::SetMapMode
1804 void wxDC::SetUserScale(
1812 SetMapMode(m_mappingMode
);
1813 } // end of wxDC::SetUserScale
1815 void wxDC::SetAxisOrientation(
1820 m_signX
= bXLeftRight
? 1 : -1;
1821 m_signY
= bYBottomUp
? -1 : 1;
1823 SetMapMode(m_mappingMode
);
1824 } // end of wxDC::SetAxisOrientation
1826 void wxDC::SetSystemScale(
1834 SetMapMode(m_mappingMode
);
1835 } // end of wxDC::SetSystemScale
1837 void wxDC::SetLogicalOrigin(
1844 ::GpiQueryPageViewport( m_hPS
1851 ::GpiSetPageViewport( m_hPS
1854 }; // end of wxDC::SetLogicalOrigin
1856 void wxDC::SetDeviceOrigin(
1863 m_deviceOriginX
= vX
;
1864 m_deviceOriginY
= vY
;
1865 ::GpiQueryPageViewport( m_hPS
1870 vRect
.yBottom
-= vY
;
1872 ::GpiSetPageViewport( m_hPS
1875 }; // end of wxDC::SetDeviceOrigin
1877 // ---------------------------------------------------------------------------
1878 // coordinates transformations
1879 // ---------------------------------------------------------------------------
1881 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1883 return (wxCoord
) (((x
) - m_deviceOriginX
)/(m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
) - m_logicalOriginX
);
1886 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1888 return (wxCoord
) ((x
)/(m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
));
1891 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1893 return (wxCoord
) (((y
) - m_deviceOriginY
)/(m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
) - m_logicalOriginY
);
1896 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1898 return (wxCoord
) ((y
)/(m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
));
1901 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1903 return (wxCoord
) ((x
- m_logicalOriginX
)*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
+ m_deviceOriginX
);
1906 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1908 return (wxCoord
) (x
*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
);
1911 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1913 return (wxCoord
) ((y
- m_logicalOriginY
)*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
+ m_deviceOriginY
);
1916 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1918 return (wxCoord
) (y
*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
);
1921 // ---------------------------------------------------------------------------
1923 // ---------------------------------------------------------------------------
1939 wxMask
* pMask
= NULL
;
1941 COLORREF vOldTextColor
;
1942 COLORREF vOldBackground
= ::GpiQueryBackColor(m_hPS
);
1946 const wxBitmap
& rBmp
= pSource
->m_vSelectedBitmap
;
1948 pMask
= rBmp
.GetMask();
1949 if (!(rBmp
.Ok() && pMask
&& pMask
->GetMaskBitmap()))
1955 ::GpiQueryAttrs( m_hPS
1960 vOldTextColor
= (COLORREF
)vCbnd
.lColor
;
1962 if (m_textForegroundColour
.Ok())
1964 vCbnd
.lColor
= (LONG
)m_textForegroundColour
.GetPixel();
1965 ::GpiSetAttrs( m_hPS
// presentation-space handle
1966 ,PRIM_CHAR
// Char primitive.
1967 ,CBB_COLOR
// sets color.
1969 ,&vCbnd
// buffer for attributes.
1972 if (m_textBackgroundColour
.Ok())
1974 ::GpiSetBackColor(m_hPS
, (LONG
)m_textBackgroundColour
.GetPixel());
1977 LONG lRop
= ROP_SRCCOPY
;
1981 case wxXOR
: lRop
= ROP_SRCINVERT
; break;
1982 case wxINVERT
: lRop
= ROP_DSTINVERT
; break;
1983 case wxOR_REVERSE
: lRop
= 0x00DD0228; break;
1984 case wxAND_REVERSE
: lRop
= ROP_SRCERASE
; break;
1985 case wxCLEAR
: lRop
= ROP_ZERO
; break;
1986 case wxSET
: lRop
= ROP_ONE
; break;
1987 case wxOR_INVERT
: lRop
= ROP_MERGEPAINT
; break;
1988 case wxAND
: lRop
= ROP_SRCAND
; break;
1989 case wxOR
: lRop
= ROP_SRCPAINT
; break;
1990 case wxEQUIV
: lRop
= 0x00990066; break;
1991 case wxNAND
: lRop
= 0x007700E6; break;
1992 case wxAND_INVERT
: lRop
= 0x00220326; break;
1993 case wxCOPY
: lRop
= ROP_SRCCOPY
; break;
1994 case wxNO_OP
: lRop
= ROP_NOTSRCERASE
; break;
1995 case wxSRC_INVERT
: lRop
= ROP_SRCINVERT
; break;
1996 case wxNOR
: lRop
= ROP_NOTSRCCOPY
; break;
1998 wxFAIL_MSG( wxT("unsupported logical function") );
2007 // Blit bitmap with mask
2011 // Create a temp buffer bitmap and DCs/PSs to access it and the mask
2017 DEVOPENSTRUC vDOP
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
2018 BITMAPINFOHEADER2 vBmpHdr
;
2020 SIZEL vSize
= {0, 0};
2023 memset(&vBmpHdr
, 0, sizeof(BITMAPINFOHEADER2
));
2024 vBmpHdr
.cbFix
= sizeof(BITMAPINFOHEADER2
);
2025 vBmpHdr
.cx
= vWidth
;
2026 vBmpHdr
.cy
= vHeight
;
2027 vBmpHdr
.cPlanes
= 1;
2028 vBmpHdr
.cBitCount
= 24;
2030 #if wxUSE_DC_CACHEING
2034 // create a temp buffer bitmap and DCs to access it and the mask
2036 wxDCCacheEntry
* pDCCacheEntry1
= FindDCInCache( NULL
2039 wxDCCacheEntry
* pDCCacheEntry2
= FindDCInCache( pDCCacheEntry1
2042 wxDCCacheEntry
* pBitmapCacheEntry
= FindBitmapInCache( GetHPS()
2047 hPSMask
= pDCCacheEntry1
->m_hPS
;
2048 hDCBuffer
= (HDC
)pDCCacheEntry2
->m_hPS
;
2049 hBufBitmap
= (HBITMAP
)pBitmapCacheEntry
->m_hBitmap
;
2054 hDCMask
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
2055 hDCBuffer
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
2056 hPSMask
= ::GpiCreatePS(vHabmain
, hDCMask
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
2057 hPSBuffer
= ::GpiCreatePS(vHabmain
, hDCBuffer
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
2058 hBufBitmap
= ::GpiCreateBitmap(GetHPS(), &vBmpHdr
, 0L, NULL
, NULL
);
2061 POINTL aPoint1
[4] = { 0, 0
2064 ,vXdest
+ vWidth
, vYdest
+ vHeight
2066 POINTL aPoint2
[4] = { 0, 0
2069 ,vXsrc
+ vWidth
, vYsrc
+ vHeight
2071 POINTL aPoint3
[4] = { vXdest
, vYdest
2072 ,vXdest
+ vWidth
, vYdest
+ vHeight
2074 ,vXsrc
+ vWidth
, vYsrc
+ vHeight
2076 POINTL aPoint4
[4] = { vXdest
, vYdest
2077 ,vXdest
+ vWidth
, vYdest
+ vHeight
2081 ::GpiSetBitmap(hPSMask
, (HBITMAP
) pMask
->GetMaskBitmap());
2082 ::GpiSetBitmap(hPSBuffer
, (HBITMAP
) hBufBitmap
);
2085 // Copy dest to buffer
2087 rc
= ::GpiBitBlt( hPSBuffer
2094 if (rc
== GPI_ERROR
)
2096 wxLogLastError(wxT("BitBlt"));
2100 // Copy src to buffer using selected raster op
2102 rc
= ::GpiBitBlt( hPSBuffer
2109 if (rc
== GPI_ERROR
)
2111 wxLogLastError(wxT("BitBlt"));
2115 // Set masked area in buffer to BLACK (pixel value 0)
2117 COLORREF vPrevBkCol
= ::GpiQueryBackColor(GetHPS());
2118 COLORREF vPrevCol
= ::GpiQueryColor(GetHPS());
2120 ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255));
2121 ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0));
2123 rc
= ::GpiBitBlt( hPSBuffer
2130 if (rc
== GPI_ERROR
)
2132 wxLogLastError(wxT("BitBlt"));
2136 // Set unmasked area in dest to BLACK
2138 ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0));
2139 ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255));
2140 rc
= ::GpiBitBlt( GetHPS()
2147 if (rc
== GPI_ERROR
)
2149 wxLogLastError(wxT("BitBlt"));
2153 // Restore colours to original values
2155 ::GpiSetBackColor(GetHPS(), vPrevBkCol
);
2156 ::GpiSetColor(GetHPS(), vPrevCol
);
2159 // OR buffer to dest
2161 rc
= ::GpiBitBlt( GetHPS()
2168 if (rc
== GPI_ERROR
)
2171 wxLogLastError(wxT("BitBlt"));
2175 // Tidy up temporary DCs and bitmap
2177 ::GpiSetBitmap(hPSMask
, NULLHANDLE
);
2178 ::GpiSetBitmap(hPSBuffer
, NULLHANDLE
);
2179 #if !wxUSE_DC_CACHEING
2180 ::GpiDestroyPS(hPSMask
);
2181 ::GpiDestroyPS(hPSBuffer
);
2182 ::DevCloseDC(hDCMask
);
2183 ::DevCloseDC(hDCBuffer
);
2184 ::GpiDeleteBitmap(hBufBitmap
);
2188 else // no mask, just BitBlt() it
2190 POINTL aPoint
[4] = { vXdest
, vYdest
2191 ,vXdest
+ vWidth
, vYdest
+ vHeight
2193 ,vXsrc
+ vWidth
, vYsrc
+ vHeight
2196 bSuccess
= (::GpiBitBlt( m_hPS
2205 wxLogLastError(wxT("BitBlt"));
2208 vCbnd
.lColor
= (LONG
)vOldTextColor
;
2209 ::GpiSetAttrs( m_hPS
// presentation-space handle
2210 ,PRIM_CHAR
// Char primitive.
2211 ,CBB_COLOR
// sets color.
2213 ,&vCbnd
// buffer for attributes.
2215 ::GpiSetBackColor(m_hPS
, (LONG
)vOldBackground
);
2219 void wxDC::DoGetSize(
2224 LONG lArray
[CAPS_HEIGHT
];
2226 if(::DevQueryCaps( m_hDC
2232 *pnWidth
= lArray
[CAPS_WIDTH
];
2233 *pnHeight
= lArray
[CAPS_HEIGHT
];
2235 }; // end of wxDC::DoGetSize(
2237 void wxDC::DoGetSizeMM(
2242 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2244 if(::DevQueryCaps( m_hDC
2246 ,CAPS_VERTICAL_RESOLUTION
2255 nWidth
= lArray
[CAPS_WIDTH
];
2256 nHeight
= lArray
[CAPS_HEIGHT
];
2257 nHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2258 nVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2259 nWidth
= (nHorzRes
/1000) * nWidth
;
2260 nHeight
= (nVertRes
/1000) * nHeight
;
2262 }; // end of wxDC::DoGetSizeMM
2264 wxSize
wxDC::GetPPI() const
2266 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2270 if(::DevQueryCaps( m_hDC
2272 ,CAPS_VERTICAL_RESOLUTION
2281 nPelWidth
= lArray
[CAPS_WIDTH
];
2282 nPelHeight
= lArray
[CAPS_HEIGHT
];
2283 nHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2284 nVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2285 nWidth
= (nHorzRes
/39.3) * nPelWidth
;
2286 nHeight
= (nVertRes
/39.3) * nPelHeight
;
2288 return (wxSize(nWidth
,nHeight
));
2289 } // end of wxDC::GetPPI
2291 void wxDC::SetLogicalScale(
2296 m_logicalScaleX
= dX
;
2297 m_logicalScaleY
= dY
;
2298 }; // end of wxDC::SetLogicalScale
2300 #if WXWIN_COMPATIBILITY
2301 void wxDC::DoGetTextExtent(const wxString
& string
, float *x
, float *y
,
2302 float *descent
, float *externalLeading
,
2303 wxFont
*theFont
, bool use16bit
) const
2305 wxCoord x1
, y1
, descent1
, externalLeading1
;
2306 GetTextExtent(string
, & x1
, & y1
, & descent1
, & externalLeading1
, theFont
, use16bit
);
2309 *descent
= descent1
;
2310 if (externalLeading
)
2311 *externalLeading
= externalLeading1
;