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"
27 #include "wx/statusbr.h"
31 #include "wx/module.h"
32 #include "wx/dcprint.h"
36 #include "wx/os2/private.h"
38 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
41 // wxWidgets uses the Microsoft convention that the origin is the UPPER left.
42 // Native OS/2 however in the GPI and PM define the origin as the LOWER left.
43 // In order to map OS/2 GPI/PM y coordinates to wxWidgets coordinates we must
44 // perform the following transformation:
46 // Parent object height: POBJHEIGHT
47 // Desried origin: WXORIGINY
48 // Object to place's height: OBJHEIGHT
50 // To get the OS2 position from the wxWidgets one:
52 // OS2Y = POBJHEIGHT - (WXORIGINY + OBJHEIGHT)
54 // For OS/2 wxDC's we will always determine m_vRclPaint as the size of the
55 // OS/2 Presentation Space associated with the device context. y is the
56 // desired application's y coordinate of the origin in wxWidgets space.
57 // objy is the height of the object we are going to draw.
59 #define OS2Y(y, objy) ((m_vRclPaint.yTop - m_vRclPaint.yBottom) - (y + objy))
61 // ---------------------------------------------------------------------------
63 // ---------------------------------------------------------------------------
65 static const int VIEWPORT_EXTENT
= 1000;
67 static const int MM_POINTS
= 9;
68 static const int MM_METRIC
= 10;
70 // ---------------------------------------------------------------------------
72 // ---------------------------------------------------------------------------
74 // convert degrees to radians
75 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
79 , int nForegroundColour
84 vCbnd
.lColor
= nForegroundColour
;
85 ::GpiSetAttrs( hPS
// presentation-space handle
86 ,PRIM_CHAR
// Char primitive.
87 ,CBB_COLOR
// sets color.
89 ,&vCbnd
// buffer for attributes.
100 ::GpiQueryAttrs( hPS
// presentation-space handle
101 ,PRIM_CHAR
// Char primitive.
102 ,CBB_BACK_COLOR
// Background color.
103 ,&vCbnd
// buffer for attributes.
105 return vCbnd
.lBackColor
;
111 , int nBackgroundColour
117 rc
= QueryTextBkColor(hPS
);
119 vCbnd
.lBackColor
= nBackgroundColour
;
120 ::GpiSetAttrs(hPS
, // presentation-space handle
121 PRIM_CHAR
, // Char primitive.
122 CBB_BACK_COLOR
, // sets color.
124 &vCbnd
// buffer for attributes.
131 , int nBackgroundMode
134 if(nBackgroundMode
== wxTRANSPARENT
)
139 // the background of the primitive takes over whatever is underneath.
146 // ===========================================================================
148 // ===========================================================================
150 #if wxUSE_DC_CACHEING
153 * This implementation is a bit ugly and uses the old-fashioned wxList class, so I will
154 * improve it in due course, either using arrays, or simply storing pointers to one
155 * entry for the bitmap, and two for the DCs. -- JACS
158 // ---------------------------------------------------------------------------
160 // ---------------------------------------------------------------------------
162 wxList
wxDC::m_svBitmapCache
;
163 wxList
wxDC::m_svDCCache
;
165 wxDCCacheEntry::wxDCCacheEntry(
177 } // end of wxDCCacheEntry::wxDCCacheEntry
179 wxDCCacheEntry::wxDCCacheEntry(
184 m_hBitmap
= NULLHANDLE
;
189 } // end of wxDCCacheEntry::wxDCCacheEntry
191 wxDCCacheEntry::~wxDCCacheEntry()
194 ::GpiDeleteBitmap(m_hBitmap
);
196 ::GpiDestroyPS(m_hPS
);
197 } // end of wxDCCacheEntry::~wxDCCacheEntry
199 wxDCCacheEntry
* wxDC::FindBitmapInCache(
205 int nDepth
= 24; // we'll fix this later ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
206 wxNode
* pNode
= m_svBitmapCache
.First();
207 BITMAPINFOHEADER2 vBmpHdr
;
211 wxDCCacheEntry
* pEntry
= (wxDCCacheEntry
*)pNode
->Data();
213 if (pEntry
->m_nDepth
== nDepth
)
215 memset(&vBmpHdr
, 0, sizeof(BITMAPINFOHEADER2
));
217 if (pEntry
->m_nWidth
< nWidth
|| pEntry
->m_nHeight
< nHeight
)
219 ::GpiDeleteBitmap((HBITMAP
)pEntry
->m_hBitmap
);
220 vBmpHdr
.cbFix
= sizeof(BITMAPINFOHEADER2
);
222 vBmpHdr
.cy
= nHeight
;
224 vBmpHdr
.cBitCount
= (USHORT
)nDepth
;
226 pEntry
->m_hBitmap
= (WXHBITMAP
) ::GpiCreateBitmap( hPS
230 if (!pEntry
->m_hBitmap
)
232 wxLogLastError(wxT("CreateCompatibleBitmap"));
234 pEntry
->m_nWidth
= nWidth
;
235 pEntry
->m_nHeight
= nHeight
;
240 pNode
= pNode
->Next();
242 memset(&vBmpHdr
, 0, sizeof(BITMAPINFOHEADER2
));
243 vBmpHdr
.cbFix
= sizeof(BITMAPINFOHEADER2
);
245 vBmpHdr
.cy
= nHeight
;
247 vBmpHdr
.cBitCount
= (USHORT
)nDepth
;
249 WXHBITMAP hBitmap
= (WXHBITMAP
) ::GpiCreateBitmap( hPS
255 wxLogLastError(wxT("CreateCompatibleBitmap"));
257 wxDCCacheEntry
* pEntry
= new wxDCCacheEntry( hBitmap
262 AddToBitmapCache(pEntry
);
264 } // end of FindBitmapInCache
266 wxDCCacheEntry
* wxDC::FindDCInCache(
267 wxDCCacheEntry
* pNotThis
271 int nDepth
= 24; // we'll fix this up later ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
272 wxNode
* pNode
= m_svDCCache
.First();
276 wxDCCacheEntry
* pEntry
= (wxDCCacheEntry
*)pNode
->Data();
279 // Don't return the same one as we already have
281 if (!pNotThis
|| (pNotThis
!= pEntry
))
283 if (pEntry
->m_nDepth
== nDepth
)
288 pNode
= pNode
->Next();
290 wxDCCacheEntry
* pEntry
= new wxDCCacheEntry( hPS
293 AddToDCCache(pEntry
);
295 } // end of wxDC::FindDCInCache
297 void wxDC::AddToBitmapCache(
298 wxDCCacheEntry
* pEntry
301 m_svBitmapCache
.Append(pEntry
);
302 } // end of wxDC::AddToBitmapCache
304 void wxDC::AddToDCCache(
305 wxDCCacheEntry
* pEntry
308 m_svDCCache
.Append(pEntry
);
309 } // end of wxDC::AddToDCCache
311 void wxDC::ClearCache()
313 m_svBitmapCache
.DeleteContents(true);
314 m_svBitmapCache
.Clear();
315 m_svBitmapCache
.DeleteContents(false);
316 m_svDCCache
.DeleteContents(true);
318 m_svDCCache
.DeleteContents(false);
319 } // end of wxDC::ClearCache
321 // Clean up cache at app exit
322 class wxDCModule
: public wxModule
325 virtual bool OnInit() { return true; }
326 virtual void OnExit() { wxDC::ClearCache(); }
329 DECLARE_DYNAMIC_CLASS(wxDCModule
)
330 }; // end of CLASS wxDCModule
332 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
334 #endif // ndef for wxUSE_DC_CACHEING
336 // ---------------------------------------------------------------------------
338 // ---------------------------------------------------------------------------
354 m_bIsPaintTime
= false; // True at Paint Time
356 wxColour
vColor( wxT("BLACK") );
357 m_pen
.SetColour(vColor
);
359 vColor
.Set( wxT("WHITE") );
360 m_brush
.SetColour(vColor
);
362 } // end of wxDC::wxDC
368 SelectOldObjects(m_hDC
);
370 // if we own the HDC, we delete it, otherwise we just release it
376 ::GpiAssociate(m_hPS
, NULLHANDLE
);
377 ::GpiDestroyPS(m_hPS
);
380 ::DevCloseDC((HDC
)m_hDC
);
385 // Just Dissacociate, not destroy if we don't own the DC
389 ::GpiAssociate(m_hPS
, NULLHANDLE
);
393 } // end of wxDC::~wxDC
395 // This will select current objects out of the DC,
396 // which is what you have to do before deleting the
398 void wxDC::SelectOldObjects(
406 ::GpiSetBitmap(hPS
, (HBITMAP
) m_hOldBitmap
);
407 if (m_vSelectedBitmap
.Ok())
409 m_vSelectedBitmap
.SetSelectedInto(NULL
);
414 // OS/2 has no other native GDI objects to set in a PS/DC like windows
422 m_brush
= wxNullBrush
;
424 m_palette
= wxNullPalette
;
426 m_backgroundBrush
= wxNullBrush
;
427 m_vSelectedBitmap
= wxNullBitmap
;
428 } // end of wxDC::SelectOldObjects
430 // ---------------------------------------------------------------------------
432 // ---------------------------------------------------------------------------
434 #define DO_SET_CLIPPING_BOX() \
438 ::GpiQueryClipBox(m_hPS, &rect); \
440 m_clipX1 = (wxCoord) XDEV2LOG(rect.xLeft); \
441 m_clipY1 = (wxCoord) YDEV2LOG(rect.yTop); \
442 m_clipX2 = (wxCoord) XDEV2LOG(rect.xRight); \
443 m_clipY2 = (wxCoord) YDEV2LOG(rect.yBottom); \
446 void wxDC::DoSetClippingRegion(
455 vY
= OS2Y(vY
,vHeight
);
458 vRect
.yTop
= vY
+ vHeight
;
459 vRect
.xRight
= vX
+ vWidth
;
461 ::GpiIntersectClipRectangle(m_hPS
, &vRect
);
462 DO_SET_CLIPPING_BOX()
463 } // end of wxDC::DoSetClippingRegion
465 void wxDC::DoSetClippingRegionAsRegion(
466 const wxRegion
& rRegion
469 wxCHECK_RET(rRegion
.GetHRGN(), wxT("invalid clipping region"));
473 ::GpiSetClipRegion( m_hPS
474 ,(HRGN
)rRegion
.GetHRGN()
477 DO_SET_CLIPPING_BOX()
478 } // end of wxDC::DoSetClippingRegionAsRegion
480 void wxDC::DestroyClippingRegion(void)
482 if (m_clipping
&& m_hPS
)
487 // TODO: this should restore the previous clipped region
488 // so that OnPaint processing works correctly, and
489 // the update doesn't get destroyed after the first
490 // DestroyClippingRegion
491 vRect
.xLeft
= XLOG2DEV(0);
492 vRect
.yTop
= YLOG2DEV(32000);
493 vRect
.xRight
= XLOG2DEV(32000);
494 vRect
.yBottom
= YLOG2DEV(0);
496 HRGN hRgn
= ::GpiCreateRegion(m_hPS
, 1, &vRect
);
498 ::GpiSetClipRegion(m_hPS
, hRgn
, &hRgnOld
);
501 } // end of wxDC::DestroyClippingRegion
503 // ---------------------------------------------------------------------------
504 // query capabilities
505 // ---------------------------------------------------------------------------
507 bool wxDC::CanDrawBitmap() const
512 bool wxDC::CanGetTextExtent() const
514 LONG lTechnology
= 0L;
516 ::DevQueryCaps(GetHDC(), CAPS_TECHNOLOGY
, 1L, &lTechnology
);
517 return (lTechnology
== CAPS_TECH_RASTER_DISPLAY
) || (lTechnology
== CAPS_TECH_RASTER_PRINTER
);
518 } // end of wxDC::CanGetTextExtent
520 int wxDC::GetDepth() const
522 LONG lArray
[CAPS_COLOR_BITCOUNT
];
523 int nBitsPerPixel
= 0;
525 if(::DevQueryCaps( GetHDC()
531 nBitsPerPixel
= (int)lArray
[CAPS_COLOR_BITCOUNT
];
533 return nBitsPerPixel
;
534 } // end of wxDC::GetDepth
536 // ---------------------------------------------------------------------------
538 // ---------------------------------------------------------------------------
543 // If this is a canvas DC then just fill with the background color
544 // Otherwise purge the whole thing
550 ::GpiQueryClipBox(m_hPS
, &vRect
);
551 ::WinFillRect(m_hPS
, &vRect
, ::GpiQueryBackColor(m_hPS
));
555 } // end of wxDC::Clear
557 bool wxDC::DoFloodFill(
560 , const wxColour
& rCol
568 bool bSuccess
= false;
570 vPtlPos
.x
= vX
; // Loads x-coordinate
571 vPtlPos
.y
= OS2Y(vY
,0); // Loads y-coordinate
572 ::GpiMove(m_hPS
, &vPtlPos
); // Sets current position
573 lColor
= rCol
.GetPixel();
574 lOptions
= FF_BOUNDARY
;
575 if(wxFLOOD_SURFACE
== nStyle
)
576 lOptions
= FF_SURFACE
;
578 if ((lHits
= ::GpiFloodFill(m_hPS
, lOptions
, lColor
)) != GPI_ERROR
)
582 } // end of wxDC::DoFloodFill
584 bool wxDC::DoGetPixel(
594 vPoint
.y
= OS2Y(vY
,0);
595 lColor
= ::GpiQueryPel(m_hPS
, &vPoint
);
598 // return the color of the pixel
601 pCol
->Set( GetRValue(lColor
)
606 } // end of wxDC::DoGetPixel
608 void wxDC::DoCrossHair(
615 wxCoord vX1
= vX
- VIEWPORT_EXTENT
;
616 wxCoord vY1
= vY
- VIEWPORT_EXTENT
;
617 wxCoord vX2
= vX
+ VIEWPORT_EXTENT
;
618 wxCoord vY2
= vY
+ VIEWPORT_EXTENT
;
627 ::GpiMove(m_hPS
, &vPoint
[0]);
628 ::GpiLine(m_hPS
, &vPoint
[1]);
636 ::GpiMove(m_hPS
, &vPoint
[2]);
637 ::GpiLine(m_hPS
, &vPoint
[3]);
638 CalcBoundingBox(vX1
, vY1
);
639 CalcBoundingBox(vX2
, vY2
);
640 } // end of wxDC::DoCrossHair
642 void wxDC::DoDrawLine(
650 COLORREF vColor
= 0x00ffffff;
653 // Might be a memory DC with no Paint rect.
655 if (!(m_vRclPaint
.yTop
== 0 &&
656 m_vRclPaint
.yBottom
== 0 &&
657 m_vRclPaint
.xRight
== 0 &&
658 m_vRclPaint
.xLeft
== 0))
665 if (m_vSelectedBitmap
!= wxNullBitmap
)
667 m_vRclPaint
.yTop
= m_vSelectedBitmap
.GetHeight();
668 m_vRclPaint
.xRight
= m_vSelectedBitmap
.GetWidth();
679 vColor
= m_pen
.GetColour().GetPixel();
681 ::GpiSetColor(m_hPS
, vColor
);
682 ::GpiMove(m_hPS
, &vPoint
[0]);
683 ::GpiLine(m_hPS
, &vPoint
[1]);
684 CalcBoundingBox(vX1
, vY1
);
685 CalcBoundingBox(vX2
, vY2
);
686 } // end of wxDC::DoDrawLine
688 //////////////////////////////////////////////////////////////////////////////
689 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
690 // and ending at (x2, y2). The current pen is used for the outline and the
691 // current brush for filling the shape. The arc is drawn in an anticlockwise
692 // direction from the start point to the end point.
693 //////////////////////////////////////////////////////////////////////////////
694 void wxDC::DoDrawArc(
704 POINTL vPtlArc
[2]; // Structure for current position
711 ARCPARAMS vArcp
; // Structure for arc parameters
713 if((vX1
== vXc
&& vY1
== vXc
) || (vX2
== vXc
&& vY2
== vXc
))
714 return; // Draw point ??
715 dRadius
= 0.5 * ( hypot( (double)(vY1
- vYc
)
718 hypot( (double)(vY2
- vYc
)
723 dAngl1
= atan2( (double)(vY1
- vYc
)
726 dAngl2
= atan2( (double)(vY2
- vYc
)
733 // GpiPointArc can't draw full arc
735 if(dAngl2
== dAngl1
|| (vX1
== vX2
&& vY1
== vY2
) )
740 dAnglmid
= (dAngl1
+ dAngl2
)/2. + M_PI
;
741 vXm
= (wxCoord
)(vXc
+ dRadius
* cos(dAnglmid
));
742 vYm
= (wxCoord
)(vYc
+ dRadius
* sin(dAnglmid
));
757 dAnglmid
= (dAngl1
+ dAngl2
)/2.;
758 vXm
= (wxCoord
)(vXc
+ dRadius
* cos(dAnglmid
));
759 vYm
= (wxCoord
)(vYc
+ dRadius
* sin(dAnglmid
));
762 // Ellipse main axis (r,q), (p,s) with center at (0,0) */
768 ::GpiSetArcParams(m_hPS
, &vArcp
); // Sets parameters to default
770 vPtlPos
.x
= vX1
; // Loads x-coordinate
771 vPtlPos
.y
= vY1
; // Loads y-coordinate
772 ::GpiMove(m_hPS
, &vPtlPos
); // Sets current position
778 // FIXME: incomplete headers ???
779 ::GpiPointArc(m_hPS
, vPtlArc
); // Draws the arc
781 CalcBoundingBox( (wxCoord
)(vXc
- dRadius
)
782 ,(wxCoord
)(vYc
- dRadius
)
784 CalcBoundingBox( (wxCoord
)(vXc
+ dRadius
)
785 ,(wxCoord
)(vYc
+ dRadius
)
787 } // end of wxDC::DoDrawArc
789 void wxDC::DoDrawCheckMark(
798 vY1
= OS2Y(vY1
,vHeight
);
802 vPoint
[1].x
= vX1
+ vWidth
;
803 vPoint
[1].y
= vY1
+ vHeight
;
805 ::GpiMove(m_hPS
, &vPoint
[0]);
806 ::GpiBox( m_hPS
// handle to a presentation space
807 ,DRO_OUTLINE
// draw the box outline ? or ?
808 ,&vPoint
[1] // address of the corner
809 ,0L // horizontal corner radius
810 ,0L // vertical corner radius
812 if(vWidth
> 4 && vHeight
> 4)
816 vPoint
[0].x
+= 2; vPoint
[0].y
+= 2;
817 vPoint
[1].x
-= 2; vPoint
[1].y
-= 2;
818 ::GpiMove(m_hPS
, &vPoint
[0]);
819 ::GpiLine(m_hPS
, &vPoint
[1]);
821 vPoint
[0].x
= vPoint
[1].x
;
823 ::GpiMove(m_hPS
, &vPoint
[0]);
824 ::GpiLine(m_hPS
, &vPoint
[1]);
830 wxCoord vX2
= vX1
+ vWidth
;
831 wxCoord vY2
= vY1
+ vHeight
;
836 } // end of wxDC::DoDrawCheckMark
838 void wxDC::DoDrawPoint(
844 COLORREF vColor
= 0x00ffffff;
848 vColor
= m_pen
.GetColour().GetPixel();
850 ::GpiSetColor(m_hPS
, vColor
);
852 vPoint
.y
= OS2Y(vY
,0);
853 ::GpiSetPel(m_hPS
, &vPoint
);
857 } // end of wxDC::DoDrawPoint
859 void wxDC::DoDrawPolygon(
867 ULONG ulCount
= 1; // Number of polygons.
868 POLYGON vPlgn
; // polygon.
869 ULONG flOptions
= 0L; // Drawing options.
871 //////////////////////////////////////////////////////////////////////////////
872 // This contains fields of option bits... to draw boundary lines as well as
873 // the area interior.
875 // Drawing boundary lines:
876 // POLYGON_NOBOUNDARY Does not draw boundary lines.
877 // POLYGON_BOUNDARY Draws boundary lines (the default).
879 // Construction of the area interior:
880 // POLYGON_ALTERNATE Constructs interior in alternate mode
882 // POLYGON_WINDING Constructs interior in winding mode.
883 //////////////////////////////////////////////////////////////////////////////
885 ULONG flModel
= 0L; // Drawing model.
887 //////////////////////////////////////////////////////////////////////////////
889 // POLYGON_INCL Fill is inclusive of bottom right (the default).
890 // POLYGON_EXCL Fill is exclusive of bottom right.
891 // This is provided to aid migration from other graphics models.
892 //////////////////////////////////////////////////////////////////////////////
894 LONG lHits
= 0L; // Correlation/error indicator.
897 int nIsTRANSPARENT
= 0;
898 LONG lBorderColor
= 0L;
901 lBorderColor
= m_pen
.GetColour().GetPixel();
902 lColor
= m_brush
.GetColour().GetPixel();
903 if(m_brush
.GetStyle() == wxTRANSPARENT
)
907 vPlgn
.aPointl
= (POINTL
*) calloc( n
+ 1
909 ); // well, new will call malloc
911 for(i
= 0; i
< n
; i
++)
913 vPlgn
.aPointl
[i
].x
= vPoints
[i
].x
; // +xoffset;
914 vPlgn
.aPointl
[i
].y
= OS2Y(vPoints
[i
].y
,0); // +yoffset;
916 flModel
= POLYGON_BOUNDARY
;
917 if(nFillStyle
== wxWINDING_RULE
)
918 flModel
|= POLYGON_WINDING
;
920 flModel
|= POLYGON_ALTERNATE
;
923 vPoint
.y
= OS2Y(vYoffset
,0);
925 ::GpiSetColor(m_hPS
, lBorderColor
);
926 ::GpiMove(m_hPS
, &vPoint
);
927 lHits
= ::GpiPolygons(m_hPS
, ulCount
, &vPlgn
, flOptions
, flModel
);
929 } // end of wxDC::DoDrawPolygon
931 void wxDC::DoDrawLines(
940 if (vXoffset
!= 0L || vXoffset
!= 0L)
944 vPoint
.x
= vPoints
[0].x
+ vXoffset
;
945 vPoint
.y
= OS2Y(vPoints
[0].y
+ vYoffset
,0);
946 ::GpiMove(m_hPS
, &vPoint
);
948 LONG lBorderColor
= m_pen
.GetColour().GetPixel();
950 ::GpiSetColor(m_hPS
, lBorderColor
);
951 for(i
= 1; i
< n
; i
++)
953 vPoint
.x
= vPoints
[i
].x
+ vXoffset
;
954 vPoint
.y
= OS2Y(vPoints
[i
].y
+ vYoffset
,0);
955 ::GpiLine(m_hPS
, &vPoint
);
962 CalcBoundingBox( vPoints
[0].x
965 vPoint
.x
= vPoints
[0].x
;
966 vPoint
.y
= OS2Y(vPoints
[0].y
,0);
967 ::GpiMove(m_hPS
, &vPoint
);
969 for (i
= 0; i
< n
; i
++)
971 CalcBoundingBox( vPoints
[i
].x
974 vPoint
.x
= vPoints
[i
].x
;
975 vPoint
.y
= OS2Y(vPoints
[i
].y
,0);
976 ::GpiLine(m_hPS
, &vPoint
);
979 } // end of wxDC::DoDrawLines
981 void wxDC::DoDrawRectangle(
992 int nIsTRANSPARENT
= 0;
995 // Might be a memory DC with no Paint rect.
997 if (!(m_vRclPaint
.yTop
== 0 &&
998 m_vRclPaint
.yBottom
== 0 &&
999 m_vRclPaint
.xRight
== 0 &&
1000 m_vRclPaint
.xLeft
== 0))
1001 vY
= OS2Y(vY
,vHeight
);
1004 if (m_vSelectedBitmap
!= wxNullBitmap
)
1006 m_vRclPaint
.yTop
= m_vSelectedBitmap
.GetHeight();
1007 m_vRclPaint
.xRight
= m_vSelectedBitmap
.GetWidth();
1008 vY
= OS2Y(vY
,vHeight
);
1012 wxCoord vX2
= vX
+ vWidth
;
1013 wxCoord vY2
= vY
+ vHeight
;
1017 vPoint
[1].x
= vX
+ vWidth
- 1;
1018 vPoint
[1].y
= vY
+ vHeight
- 1;
1019 ::GpiMove(m_hPS
, &vPoint
[0]);
1020 lColor
= m_brush
.GetColour().GetPixel();
1021 lBorderColor
= m_pen
.GetColour().GetPixel();
1022 if (m_brush
.GetStyle() == wxTRANSPARENT
)
1024 if(lColor
== lBorderColor
|| nIsTRANSPARENT
)
1026 lControl
= DRO_OUTLINEFILL
; //DRO_FILL;
1027 if(m_brush
.GetStyle() == wxTRANSPARENT
)
1028 lControl
= DRO_OUTLINE
;
1030 ::GpiSetColor(m_hPS
, lBorderColor
);
1031 ::GpiBox( m_hPS
// handle to a presentation space
1032 ,lControl
// draw the box outline ? or ?
1033 ,&vPoint
[1] // address of the corner
1034 ,0L // horizontal corner radius
1035 ,0L // vertical corner radius
1040 lControl
= DRO_OUTLINE
;
1041 ::GpiSetColor( m_hPS
1050 lControl
= DRO_FILL
;
1051 ::GpiSetColor( m_hPS
1054 vPoint
[0].x
= vX
+ 1;
1055 vPoint
[0].y
= vY
+ 1;
1056 vPoint
[1].x
= vX
+ vWidth
- 2;
1057 vPoint
[1].y
= vY
+ vHeight
- 2;
1058 ::GpiMove(m_hPS
, &vPoint
[0]);
1066 CalcBoundingBox(vX
, vY
);
1067 CalcBoundingBox(vX2
, vY2
);
1068 } // end of wxDC::DoDrawRectangle
1070 void wxDC::DoDrawRoundedRectangle(
1082 int nIsTRANSPARENT
= 0;
1085 // Might be a memory DC with no Paint rect.
1087 if (!(m_vRclPaint
.yTop
== 0 &&
1088 m_vRclPaint
.yBottom
== 0 &&
1089 m_vRclPaint
.xRight
== 0 &&
1090 m_vRclPaint
.xLeft
== 0))
1091 vY
= OS2Y(vY
,vHeight
);
1094 if (m_vSelectedBitmap
!= wxNullBitmap
)
1096 m_vRclPaint
.yTop
= m_vSelectedBitmap
.GetHeight();
1097 m_vRclPaint
.xRight
= m_vSelectedBitmap
.GetWidth();
1098 vY
= OS2Y(vY
,vHeight
);
1102 wxCoord vX2
= (vX
+ vWidth
);
1103 wxCoord vY2
= (vY
+ vHeight
);
1107 vPoint
[1].x
= vX
+ vWidth
- 1;
1108 vPoint
[1].y
= vY
+ vHeight
- 1;
1109 ::GpiMove(m_hPS
, &vPoint
[0]);
1111 lColor
= m_brush
.GetColour().GetPixel();
1112 lBorderColor
= m_pen
.GetColour().GetPixel();
1113 lControl
= DRO_OUTLINEFILL
; //DRO_FILL;
1114 if (m_brush
.GetStyle() == wxTRANSPARENT
)
1116 if(lColor
== lBorderColor
|| nIsTRANSPARENT
)
1118 lControl
= DRO_OUTLINEFILL
; //DRO_FILL;
1119 if(m_brush
.GetStyle() == wxTRANSPARENT
)
1120 lControl
= DRO_OUTLINE
;
1122 ::GpiSetColor(m_hPS
, lColor
);
1123 ::GpiBox( m_hPS
// handle to a presentation space
1124 ,lControl
// draw the box outline ? or ?
1125 ,&vPoint
[1] // address of the corner
1126 ,(LONG
)dRadius
// horizontal corner radius
1127 ,(LONG
)dRadius
// vertical corner radius
1132 lControl
= DRO_OUTLINE
;
1133 ::GpiSetColor( m_hPS
1142 lControl
= DRO_FILL
;
1143 ::GpiSetColor( m_hPS
1146 vPoint
[0].x
= vX
+ 1;
1147 vPoint
[0].y
= vY
+ 1;
1148 vPoint
[1].x
= vX
+ vWidth
- 2;
1149 vPoint
[1].y
= vY
+ vHeight
- 2;
1150 ::GpiMove(m_hPS
, &vPoint
[0]);
1159 CalcBoundingBox(vX
, vY
);
1160 CalcBoundingBox(vX2
, vY2
);
1161 } // end of wxDC::DoDrawRoundedRectangle
1163 // Draw Ellipse within box (x,y) - (x+width, y+height)
1164 void wxDC::DoDrawEllipse(
1171 POINTL vPtlPos
; // Structure for current position
1172 FIXED vFxMult
; // Multiplier for ellipse
1173 ARCPARAMS vArcp
; // Structure for arc parameters
1175 vY
= OS2Y(vY
,vHeight
);
1178 vArcp
.lQ
= vHeight
/2;
1179 vArcp
.lP
= vWidth
/2;
1181 ::GpiSetArcParams( m_hPS
1183 ); // Sets parameters to default
1184 vPtlPos
.x
= vX
+ vWidth
/2; // Loads x-coordinate
1185 vPtlPos
.y
= vY
+ vHeight
/2; // Loads y-coordinate
1188 ); // Sets current position
1189 vFxMult
= MAKEFIXED(1, 0); /* Sets multiplier */
1192 // DRO_FILL, DRO_OTLINEFILL - where to get
1197 ); // Draws full arc with center at current position
1199 wxCoord vX2
= (vX
+ vWidth
);
1200 wxCoord vY2
= (vY
+ vHeight
);
1202 CalcBoundingBox(vX
, vY
);
1203 CalcBoundingBox(vX2
, vY2
);
1204 } // end of wxDC::DoDrawEllipse
1206 void wxDC::DoDrawEllipticArc(
1215 POINTL vPtlPos
; // Structure for current position
1216 FIXED vFxMult
; // Multiplier for ellipse
1217 ARCPARAMS vArcp
; // Structure for arc parameters
1219 FIXED vFSweepa
; // Start angle, sweep angle
1223 vY
= OS2Y(vY
,vHeight
);
1225 dFractPart
= modf(dSa
,&dIntPart
);
1226 vFSa
= MAKEFIXED((int)dIntPart
, (int)(dFractPart
* 0xffff) );
1227 dFractPart
= modf(dEa
- dSa
, &dIntPart
);
1228 vFSweepa
= MAKEFIXED((int)dIntPart
, (int)(dFractPart
* 0xffff) );
1231 // Ellipse main axis (r,q), (p,s) with center at (0,0)
1234 vArcp
.lQ
= vHeight
/2;
1235 vArcp
.lP
= vWidth
/2;
1237 ::GpiSetArcParams(m_hPS
, &vArcp
); // Sets parameters to default
1238 vPtlPos
.x
= (wxCoord
)(vX
+ vWidth
/2 * (1. + cos(DegToRad(dSa
)))); // Loads x-coordinate
1239 vPtlPos
.y
= (wxCoord
)(vY
+ vHeight
/2 * (1. + sin(DegToRad(dSa
)))); // Loads y-coordinate
1240 ::GpiMove(m_hPS
, &vPtlPos
); // Sets current position
1243 // May be not to the center ?
1245 vPtlPos
.x
= vX
+ vWidth
/2 ; // Loads x-coordinate
1246 vPtlPos
.y
= vY
+ vHeight
/2; // Loads y-coordinate
1247 vFxMult
= MAKEFIXED(1, 0); // Sets multiplier
1250 // DRO_FILL, DRO_OTLINEFILL - where to get
1252 ::GpiPartialArc( m_hPS
1258 wxCoord vX2
= (vX
+ vWidth
);
1259 wxCoord vY2
= (vY
+ vHeight
);
1261 CalcBoundingBox(vX
, vY
);
1262 CalcBoundingBox(vX2
, vY2
);
1263 } // end of wxDC::DoDrawEllipticArc
1265 void wxDC::DoDrawIcon(
1272 // Need to copy back into a bitmap. ::WinDrawPointer uses device coords
1273 // and I don't feel like figuring those out for scrollable windows so
1274 // just convert to a bitmap then let the DoDrawBitmap routing display it
1278 DoDrawBitmap(rIcon
.GetXpmSrc(), vX
, vY
, true);
1282 wxBitmap
vBitmap(rIcon
);
1284 DoDrawBitmap(vBitmap
, vX
, vY
, false);
1286 CalcBoundingBox(vX
, vY
);
1287 CalcBoundingBox(vX
+ rIcon
.GetWidth(), vY
+ rIcon
.GetHeight());
1288 } // end of wxDC::DoDrawIcon
1290 void wxDC::DoDrawBitmap(
1291 const wxBitmap
& rBmp
1297 #if wxUSE_PRINTING_ARCHITECTURE
1298 if (!IsKindOf(CLASSINFO(wxPrinterDC
)))
1301 HBITMAP hBitmap
= (HBITMAP
)rBmp
.GetHBITMAP();
1302 HBITMAP hBitmapOld
= NULLHANDLE
;
1305 vY
= OS2Y(vY
,rBmp
.GetHeight());
1308 vPoint
[0].y
= vY
+ rBmp
.GetHeight();
1309 vPoint
[1].x
= vX
+ rBmp
.GetWidth();
1313 vPoint
[3].x
= rBmp
.GetWidth();
1314 vPoint
[3].y
= rBmp
.GetHeight();
1317 wxMask
* pMask
= rBmp
.GetMask();
1322 // Need to imitate ::MaskBlt in windows.
1323 // 1) Extract the bits from from the bitmap.
1324 // 2) Extract the bits from the mask
1325 // 3) Using the mask bits do the following:
1326 // A) If the mask byte is 00 leave the bitmap byte alone
1327 // B) If the mask byte is FF copy the screen color into
1329 // 4) Create a new bitmap and set its bits to the above result
1330 // 5) Blit this to the screen PS
1332 HBITMAP hMask
= (HBITMAP
)pMask
->GetMaskBitmap();
1333 HBITMAP hOldMask
= NULLHANDLE
;
1334 HBITMAP hOldBitmap
= NULLHANDLE
;
1335 HBITMAP hNewBitmap
= NULLHANDLE
;
1336 unsigned char* pucBits
; // buffer that will contain the bitmap data
1337 unsigned char* pucBitsMask
; // buffer that will contain the mask data
1338 unsigned char* pucData
; // pointer to use to traverse bitmap data
1339 unsigned char* pucDataMask
; // pointer to use to traverse mask data
1345 // The usual Memory context creation stuff
1347 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
1348 SIZEL vSize
= {0, 0};
1349 HDC hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
1350 HPS hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIA_ASSOC
);
1353 // The usual bitmap header stuff
1355 BITMAPINFOHEADER2 vHeader
;
1358 memset(&vHeader
, '\0', 16);
1361 memset(&vInfo
, '\0', 16);
1363 vInfo
.cx
= (ULONG
)rBmp
.GetWidth();
1364 vInfo
.cy
= (ULONG
)rBmp
.GetHeight();
1366 vInfo
.cBitCount
= 24; // Set to desired count going in
1369 // Create the buffers for data....all wxBitmaps are 24 bit internally
1371 int nBytesPerLine
= rBmp
.GetWidth() * 3;
1372 int nSizeDWORD
= sizeof(DWORD
);
1373 int nLineBoundary
= nBytesPerLine
% nSizeDWORD
;
1381 // Need to get a background color for mask blitting
1383 if (IsKindOf(CLASSINFO(wxWindowDC
)))
1385 wxWindowDC
* pWindowDC
= wxDynamicCast(this, wxWindowDC
);
1387 lColor
= pWindowDC
->m_pCanvas
->GetBackgroundColour().GetPixel();
1389 else if (GetBrush().Ok())
1390 lColor
= GetBrush().GetColour().GetPixel();
1392 lColor
= m_textBackgroundColour
.GetPixel();
1395 // Bitmap must be in a double-word aligned address so we may
1396 // have some padding to worry about
1398 if (nLineBoundary
> 0)
1400 nPadding
= nSizeDWORD
- nLineBoundary
;
1401 nBytesPerLine
+= nPadding
;
1403 pucBits
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
1404 pucBitsMask
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
1405 memset(pucBits
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
1406 memset(pucBitsMask
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
1409 // Extract the bitmap and mask data
1411 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hBitmap
)) == HBM_ERROR
)
1413 vError
= ::WinGetLastError(vHabmain
);
1414 sError
= wxPMErrorToStr(vError
);
1416 ::GpiQueryBitmapInfoHeader(hBitmap
, &vHeader
);
1417 vInfo
.cBitCount
= 24;
1418 if ((lScans
= ::GpiQueryBitmapBits( hPS
1420 ,(LONG
)rBmp
.GetHeight()
1425 vError
= ::WinGetLastError(vHabmain
);
1426 sError
= wxPMErrorToStr(vError
);
1428 if ((hOldMask
= ::GpiSetBitmap(hPS
, hMask
)) == HBM_ERROR
)
1430 vError
= ::WinGetLastError(vHabmain
);
1431 sError
= wxPMErrorToStr(vError
);
1433 ::GpiQueryBitmapInfoHeader(hMask
, &vHeader
);
1434 vInfo
.cBitCount
= 24;
1435 if ((lScans
= ::GpiQueryBitmapBits( hPS
1437 ,(LONG
)rBmp
.GetHeight()
1442 vError
= ::WinGetLastError(vHabmain
);
1443 sError
= wxPMErrorToStr(vError
);
1445 if (( hMask
= ::GpiSetBitmap(hPS
, hOldMask
)) == HBM_ERROR
)
1447 vError
= ::WinGetLastError(vHabmain
);
1448 sError
= wxPMErrorToStr(vError
);
1452 // Now set the bytes(bits) according to the mask values
1453 // 3 bytes per pel...must handle one at a time
1456 pucDataMask
= pucBitsMask
;
1459 // 16 bit kludge really only kinda works. The mask gets applied
1460 // where needed but the original bitmap bits are dorked sometimes
1462 bool bpp16
= (wxDisplayDepth() == 16);
1464 for (i
= 0; i
< rBmp
.GetHeight(); i
++)
1466 for (j
= 0; j
< rBmp
.GetWidth(); j
++)
1469 if (bpp16
&& *pucDataMask
== 0xF8) // 16 bit display gobblygook
1471 else if (*pucDataMask
== 0xFF) // leave bitmap byte alone
1475 *pucData
= ((unsigned char)(lColor
>> 16));
1479 if (bpp16
&& *(pucDataMask
+ 1) == 0xFC) // 16 bit display gobblygook
1481 else if (*(pucDataMask
+ 1) == 0xFF) // leave bitmap byte alone
1485 *pucData
= ((unsigned char)(lColor
>> 8));
1490 if (bpp16
&& *(pucDataMask
+ 2) == 0xF8) // 16 bit display gobblygook
1492 else if (*(pucDataMask
+ 2) == 0xFF) // leave bitmap byte alone
1496 *pucData
= ((unsigned char)lColor
);
1501 for (j
= 0; j
< nPadding
; j
++)
1508 // Create a new bitmap
1510 vHeader
.cx
= (ULONG
)rBmp
.GetWidth();
1511 vHeader
.cy
= (ULONG
)rBmp
.GetHeight();
1512 vHeader
.cPlanes
= 1L;
1513 vHeader
.cBitCount
= 24;
1514 if ((hNewBitmap
= ::GpiCreateBitmap( hPS
1521 vError
= ::WinGetLastError(vHabmain
);
1522 sError
= wxPMErrorToStr(vError
);
1526 // Now blit it to the screen PS
1528 if ((lHits
= ::GpiWCBitBlt( (HPS
)GetHPS()
1536 vError
= ::WinGetLastError(vHabmain
);
1537 sError
= wxPMErrorToStr(vError
);
1545 ::GpiSetBitmap(hPS
, NULLHANDLE
);
1546 ::GpiDeleteBitmap(hNewBitmap
);
1547 ::GpiDestroyPS(hPS
);
1553 ULONG lOldForeGround
= ::GpiQueryColor((HPS
)GetHPS());
1554 ULONG lOldBackGround
= ::GpiQueryBackColor((HPS
)GetHPS());
1556 if (m_textForegroundColour
.Ok())
1558 ::GpiSetColor( (HPS
)GetHPS()
1559 ,m_textForegroundColour
.GetPixel()
1562 if (m_textBackgroundColour
.Ok())
1564 ::GpiSetBackColor( (HPS
)GetHPS()
1565 ,m_textBackgroundColour
.GetPixel()
1569 // Need to alter bits in a mono bitmap to match the new
1570 // background-foreground if it is different.
1572 if (rBmp
.IsMono() &&
1573 ((m_textForegroundColour
.GetPixel() != lOldForeGround
) ||
1574 (m_textBackgroundColour
.GetPixel() != lOldBackGround
)))
1576 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
1577 SIZEL vSize
= {0, 0};
1578 HDC hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
1579 HPS hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIA_ASSOC
);
1581 int nBytesPerLine
= rBmp
.GetWidth() * 3;
1583 LONG lForeGround
= m_textForegroundColour
.GetPixel();
1584 LONG lBackGround
= m_textBackgroundColour
.GetPixel();
1586 HBITMAP hOldBitmap
= NULLHANDLE
;
1592 memset(&vInfo
, '\0', 16);
1594 vInfo
.cx
= (ULONG
)rBmp
.GetWidth();
1595 vInfo
.cy
= (ULONG
)rBmp
.GetHeight();
1597 vInfo
.cBitCount
= 24;
1599 unsigned char* pucBits
; // buffer that will contain the bitmap data
1600 unsigned char* pucData
; // pointer to use to traverse bitmap data
1602 pucBits
= new unsigned char[nBytesPerLine
* rBmp
.GetHeight()];
1603 memset(pucBits
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
1605 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hBitmap
)) == HBM_ERROR
)
1607 vError
= ::WinGetLastError(vHabmain
);
1608 sError
= wxPMErrorToStr(vError
);
1611 if ((lScans
= ::GpiQueryBitmapBits( hPS
1613 ,(LONG
)rBmp
.GetHeight()
1618 vError
= ::WinGetLastError(vHabmain
);
1619 sError
= wxPMErrorToStr(vError
);
1622 unsigned char cOldRedFore
= (unsigned char)(lOldForeGround
>> 16);
1623 unsigned char cOldGreenFore
= (unsigned char)(lOldForeGround
>> 8);
1624 unsigned char cOldBlueFore
= (unsigned char)lOldForeGround
;
1626 unsigned char cRedFore
= (unsigned char)(lForeGround
>> 16);
1627 unsigned char cGreenFore
= (unsigned char)(lForeGround
>> 8);
1628 unsigned char cBlueFore
= (unsigned char)lForeGround
;
1630 unsigned char cRedBack
= (unsigned char)(lBackGround
>> 16);
1631 unsigned char cGreenBack
= (unsigned char)(lBackGround
>> 8);
1632 unsigned char cBlueBack
= (unsigned char)lBackGround
;
1635 for (i
= 0; i
< rBmp
.GetHeight(); i
++)
1637 for (j
= 0; j
< rBmp
.GetWidth(); j
++)
1639 unsigned char cBmpRed
= *pucData
;
1640 unsigned char cBmpGreen
= *(pucData
+ 1);
1641 unsigned char cBmpBlue
= *(pucData
+ 2);
1643 if ((cBmpRed
== cOldRedFore
) &&
1644 (cBmpGreen
== cOldGreenFore
) &&
1645 (cBmpBlue
== cOldBlueFore
))
1647 *pucData
= cBlueFore
;
1649 *pucData
= cGreenFore
;
1651 *pucData
= cRedFore
;
1656 *pucData
= cBlueBack
;
1658 *pucData
= cGreenBack
;
1660 *pucData
= cRedBack
;
1665 if ((lScans
= ::GpiSetBitmapBits( hPS
1667 ,(LONG
)rBmp
.GetHeight()
1672 vError
= ::WinGetLastError(vHabmain
);
1673 sError
= wxPMErrorToStr(vError
);
1677 ::GpiSetBitmap(hPS
, NULLHANDLE
);
1678 ::GpiDestroyPS(hPS
);
1681 ::GpiWCBitBlt( (HPS
)GetHPS()
1688 ::GpiSetBitmap((HPS
)GetHPS(), hBitmapOld
);
1689 ::GpiSetColor((HPS
)GetHPS(), lOldForeGround
);
1690 ::GpiSetBackColor((HPS
)GetHPS(), lOldBackGround
);
1693 } // end of wxDC::DoDrawBitmap
1695 void wxDC::DoDrawText(
1696 const wxString
& rsText
1709 CalcBoundingBox(vX
, vY
);
1710 GetTextExtent(rsText
, &vWidth
, &vHeight
);
1711 CalcBoundingBox((vX
+ vWidth
), (vY
+ vHeight
));
1712 } // end of wxDC::DoDrawText
1714 void wxDC::DrawAnyText(
1715 const wxString
& rsText
1720 int nOldBackground
= 0;
1727 // prepare for drawing the text
1731 // Set text color attributes
1733 if (m_textForegroundColour
.Ok())
1736 ,(int)m_textForegroundColour
.GetPixel()
1740 if (m_textBackgroundColour
.Ok())
1742 nOldBackground
= SetTextBkColor( m_hPS
1743 ,(int)m_textBackgroundColour
.GetPixel()
1749 GetTextExtent( rsText
1754 if (!(m_vRclPaint
.yTop
== 0 &&
1755 m_vRclPaint
.yBottom
== 0 &&
1756 m_vRclPaint
.xRight
== 0 &&
1757 m_vRclPaint
.xLeft
== 0))
1760 // Position Text a little differently in the Statusbar from other panels
1762 if (m_pCanvas
&& m_pCanvas
->IsKindOf(CLASSINFO(wxStatusBar
)))
1763 vPtlStart
.y
= OS2Y(vY
,vTextY
);
1765 vPtlStart
.y
= (wxCoord
)(OS2Y(vY
,vTextY
/1.5)); // Full extent is a bit much
1769 if (m_vSelectedBitmap
!= wxNullBitmap
)
1771 m_vRclPaint
.yTop
= m_vSelectedBitmap
.GetHeight();
1772 m_vRclPaint
.xRight
= m_vSelectedBitmap
.GetWidth();
1773 if (m_pCanvas
&& m_pCanvas
->IsKindOf(CLASSINFO(wxStatusBar
)))
1774 vPtlStart
.y
= OS2Y(vY
,vTextY
);
1776 vPtlStart
.y
= (LONG
)(OS2Y(vY
,vTextY
/1.5));
1782 PCH pzStr
= (PCH
)rsText
.c_str();
1784 ::GpiMove(m_hPS
, &vPtlStart
);
1785 lHits
= ::GpiCharString( m_hPS
1789 if (lHits
!= GPI_OK
)
1791 wxLogLastError(wxT("TextOut"));
1795 // Restore the old parameters (text foreground colour may be left because
1796 // it never is set to anything else, but background should remain
1797 // transparent even if we just drew an opaque string)
1799 if (m_textBackgroundColour
.Ok())
1800 SetTextBkColor( m_hPS
1808 void wxDC::DoDrawRotatedText(
1809 const wxString
& rsText
1827 DoDrawText(text, x, y);
1832 wxFillLogFont(&lf, &m_font);
1834 // GDI wants the angle in tenth of degree
1835 long angle10 = (long)(angle * 10);
1836 lf.lfEscapement = angle10;
1837 lf. lfOrientation = angle10;
1839 HFONT hfont = ::CreateFontIndirect(&lf);
1842 wxLogLastError("CreateFont");
1846 HFONT hfontOld = ::SelectObject(GetHdc(), hfont);
1848 DrawAnyText(text, x, y);
1850 (void)::SelectObject(GetHdc(), hfontOld);
1853 // call the bounding box by adding all four vertices of the rectangle
1854 // containing the text to it (simpler and probably not slower than
1855 // determining which of them is really topmost/leftmost/...)
1857 GetTextExtent(text, &w, &h);
1859 double rad = DegToRad(angle);
1861 // "upper left" and "upper right"
1862 CalcBoundingBox(x, y);
1863 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
1864 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1866 // "bottom left" and "bottom right"
1867 x += (wxCoord)(h*sin(rad));
1868 y += (wxCoord)(h*cos(rad));
1869 CalcBoundingBox(x, y);
1870 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1875 // ---------------------------------------------------------------------------
1877 // ---------------------------------------------------------------------------
1879 void wxDC::DoSelectPalette( bool WXUNUSED(bRealize
) )
1882 // Set the old object temporarily, in case the assignment deletes an object
1883 // that's not yet selected out.
1894 hOldPal
= ::GpiSelectPalette((HDC
) m_hPS
, (HPALETTE
) m_palette
.GetHPALETTE());
1896 m_hOldPalette
= (WXHPALETTE
)hOldPal
;
1898 } // end of wxDC::DoSelectPalette
1900 void wxDC::InitializePalette()
1902 if (wxDisplayDepth() <= 8 )
1905 // Look for any window or parent that has a custom palette. If any has
1906 // one then we need to use it in drawing operations
1908 wxWindow
* pWin
= m_pCanvas
->GetAncestorWithCustomPalette();
1910 m_hasCustomPalette
= pWin
&& pWin
->HasCustomPalette();
1911 if (m_hasCustomPalette
)
1913 m_palette
= pWin
->GetPalette();
1916 // turn on PM translation for this palette
1921 } // end of wxDC::InitializePalette
1923 void wxDC::SetPalette(
1924 const wxPalette
& rPalette
1931 m_palette
= rPalette
;
1939 HPALETTE hOldPal
= ::GpiSelectPalette((HDC
) m_hPS
, (HPALETTE
) m_palette
.GetHPALETTE());
1941 m_hOldPalette
= (WXHPALETTE
)hOldPal
;
1942 } // end of wxDC::SetPalette
1949 // Set the old object temporarily, in case the assignment deletes an object
1950 // that's not yet selected out.
1962 m_font
.SetPS(m_hPS
); // this will realize the font
1966 HFONT hFont
= m_font
.GetResourceHandle();
1967 if (hFont
== (HFONT
) NULL
)
1969 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1972 m_hOldFont
= (WXHFONT
) hFont
;
1974 } // end of wxDC::SetFont
1980 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1996 m_pen
.SetPS((HPS
)m_hOldPen
);
2003 if (m_pen
.GetResourceHandle())
2007 m_hOldPen
= m_pen
.GetPS();
2009 ::GpiSetColor(m_hPS
, m_pen
.GetColour().GetPixel());
2013 void wxDC::SetBrush(
2014 const wxBrush
& rBrush
2017 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2023 if (m_brush
== rBrush
)
2033 m_brush
.SetPS((HPS
)m_hOldBrush
);
2040 if (m_brush
.GetResourceHandle())
2042 m_brush
.SetPS(m_hPS
);
2044 m_hOldBrush
= (WXHWND
)m_brush
.GetPS();
2047 } // end of wxDC::SetBrush
2049 void wxDC::SetBackground(
2050 const wxBrush
& rBrush
2053 m_backgroundBrush
= rBrush
;
2054 if (!m_backgroundBrush
.Ok())
2058 bool bCustomColours
= true;
2061 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
2062 // change background colours from the control-panel specified colours.
2064 if (m_pCanvas
->IsKindOf(CLASSINFO(wxWindow
)) &&
2065 ((m_pCanvas
->GetWindowStyleFlag() & wxUSER_COLOURS
) != wxUSER_COLOURS
))
2066 bCustomColours
= false;
2069 if (m_backgroundBrush
.GetStyle()==wxTRANSPARENT
)
2071 m_pCanvas
->SetTransparent(true);
2076 // Setting the background brush of a DC
2077 // doesn't affect the window background colour. However,
2078 // I'm leaving in the transparency setting because it's needed by
2079 // various controls (e.g. wxStaticText) to determine whether to draw
2080 // transparently or not. TODO: maybe this should be a new function
2081 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
2083 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
2085 m_pCanvas
->SetTransparent(false);
2089 COLORREF vNewColor
= m_backgroundBrush
.GetColour().GetPixel();
2090 (void)::GpiSetBackColor((HPS
)m_hPS
, (LONG
)vNewColor
);
2091 } // end of wxDC::SetBackground
2093 void wxDC::SetBackgroundMode(
2097 m_backgroundMode
= nMode
;
2098 } // end of wxDC::SetBackgroundMode
2100 void wxDC::SetLogicalFunction(
2104 m_logicalFunction
= nFunction
;
2105 SetRop((WXHDC
)m_hDC
);
2106 } // wxDC::SetLogicalFunction
2112 if (!hDC
|| m_logicalFunction
< 0)
2116 switch (m_logicalFunction
)
2127 lCRop
= FM_MERGESRCNOT
;
2131 lCRop
= FM_NOTMASKSRC
;
2143 lCRop
= FM_MERGENOTSRC
;
2147 lCRop
= FM_MERGESRCNOT
;
2159 lCRop
= FM_SUBTRACT
;
2166 lCRop
= FM_OVERPAINT
;
2169 ::GpiSetMix((HPS
)hDC
, lCRop
);
2170 } // end of wxDC::SetRop
2172 bool wxDC::StartDoc( const wxString
& WXUNUSED(rsMessage
) )
2174 // We might be previewing, so return true to let it continue.
2176 } // end of wxDC::StartDoc
2180 } // end of wxDC::EndDoc
2182 void wxDC::StartPage()
2184 } // end of wxDC::StartPage
2186 void wxDC::EndPage()
2188 } // end of wxDC::EndPage
2190 // ---------------------------------------------------------------------------
2192 // ---------------------------------------------------------------------------
2194 wxCoord
wxDC::GetCharHeight() const
2196 FONTMETRICS vFM
; // metrics structure
2198 ::GpiQueryFontMetrics( m_hPS
2199 ,sizeof(FONTMETRICS
)
2202 return YDEV2LOGREL(vFM
.lXHeight
);
2205 wxCoord
wxDC::GetCharWidth() const
2207 FONTMETRICS vFM
; // metrics structure
2209 ::GpiQueryFontMetrics( m_hPS
2210 ,sizeof(FONTMETRICS
)
2213 return XDEV2LOGREL(vFM
.lAveCharWidth
);
2216 void wxDC::DoGetTextExtent(
2217 const wxString
& rsString
2220 , wxCoord
* pvDescent
2221 , wxCoord
* pvExternalLeading
2225 POINTL avPoint
[TXTBOX_COUNT
];
2230 FONTMETRICS vFM
; // metrics structure
2232 ERRORID vErrorCode
; // last error id code
2233 wxFont
* pFontToUse
= (wxFont
*)pTheFont
;
2235 wxChar zMsg
[128]; // DEBUG
2239 pFontToUse
= (wxFont
*)&m_font
;
2240 l
= rsString
.length();
2243 // In world coordinates.
2245 bRc
= ::GpiQueryTextBox( m_hPS
2247 ,(PCH
)rsString
.c_str()
2248 ,TXTBOX_COUNT
// return maximum information
2249 ,avPoint
// array of coordinates points
2253 vErrorCode
= ::WinGetLastError(wxGetInstance());
2254 sError
= wxPMErrorToStr(vErrorCode
);
2256 wxSprintf(zMsg
, _T("GpiQueryTextBox for %s: failed with Error: %lx - %s"), rsString
.c_str(), vErrorCode
, sError
.c_str());
2257 (void)wxMessageBox( _T("wxWidgets Menu sample")
2263 vPtMin
.x
= avPoint
[0].x
;
2264 vPtMax
.x
= avPoint
[0].x
;
2265 vPtMin
.y
= avPoint
[0].y
;
2266 vPtMax
.y
= avPoint
[0].y
;
2267 for (i
= 1; i
< 4; i
++)
2269 if(vPtMin
.x
> avPoint
[i
].x
) vPtMin
.x
= avPoint
[i
].x
;
2270 if(vPtMin
.y
> avPoint
[i
].y
) vPtMin
.y
= avPoint
[i
].y
;
2271 if(vPtMax
.x
< avPoint
[i
].x
) vPtMax
.x
= avPoint
[i
].x
;
2272 if(vPtMax
.y
< avPoint
[i
].y
) vPtMax
.y
= avPoint
[i
].y
;
2274 ::GpiQueryFontMetrics( m_hPS
2275 ,sizeof(FONTMETRICS
)
2280 *pvX
= (wxCoord
)(vPtMax
.x
- vPtMin
.x
+ 1);
2282 *pvY
= (wxCoord
)(vPtMax
.y
- vPtMin
.y
+ 1);
2284 *pvDescent
= vFM
.lMaxDescender
;
2285 if (pvExternalLeading
)
2286 *pvExternalLeading
= vFM
.lExternalLeading
;
2289 void wxDC::SetMapMode(
2293 int nPixelWidth
= 0;
2294 int nPixelHeight
= 0;
2297 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2299 m_mappingMode
= nMode
;
2301 if(::DevQueryCaps( m_hDC
2303 ,CAPS_VERTICAL_RESOLUTION
2310 nPixelWidth
= lArray
[CAPS_WIDTH
];
2311 nPixelHeight
= lArray
[CAPS_HEIGHT
];
2312 lHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2313 lVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2314 nMmWidth
= (lHorzRes
/1000) * nPixelWidth
;
2315 nMmWidth
= (lVertRes
/1000) * nPixelHeight
;
2317 if ((nPixelWidth
== 0) || (nPixelHeight
== 0) || (nMmWidth
== 0) || (nMmHeight
== 0))
2322 double dMm2pixelsX
= nPixelWidth
/nMmWidth
;
2323 double dMm2pixelsY
= nPixelHeight
/nMmHeight
;
2328 m_logicalScaleX
= (twips2mm
* dMm2pixelsX
);
2329 m_logicalScaleY
= (twips2mm
* dMm2pixelsY
);
2333 m_logicalScaleX
= (pt2mm
* dMm2pixelsX
);
2334 m_logicalScaleY
= (pt2mm
* dMm2pixelsY
);
2338 m_logicalScaleX
= dMm2pixelsX
;
2339 m_logicalScaleY
= dMm2pixelsY
;
2343 m_logicalScaleX
= (dMm2pixelsX
/10.0);
2344 m_logicalScaleY
= (dMm2pixelsY
/10.0);
2349 m_logicalScaleX
= 1.0;
2350 m_logicalScaleY
= 1.0;
2356 ulOptions
= ::GpiQueryPS(m_hPS
, &vSize
);
2357 if (!ulOptions
& PU_ARBITRARY
)
2359 ulOptions
= PU_ARBITRARY
| GPIF_DEFAULT
;
2360 ::GpiSetPS(m_hPS
, &vSize
, ulOptions
);
2362 m_nWindowExtX
= (int)MS_XDEV2LOG(VIEWPORT_EXTENT
);
2363 m_nWindowExtY
= (int)MS_YDEV2LOG(VIEWPORT_EXTENT
);
2365 }; // end of wxDC::SetMapMode
2367 void wxDC::SetUserScale(
2375 SetMapMode(m_mappingMode
);
2376 } // end of wxDC::SetUserScale
2378 void wxDC::SetAxisOrientation(
2383 m_signX
= bXLeftRight
? 1 : -1;
2384 m_signY
= bYBottomUp
? -1 : 1;
2386 SetMapMode(m_mappingMode
);
2387 } // end of wxDC::SetAxisOrientation
2389 void wxDC::SetSystemScale(
2397 SetMapMode(m_mappingMode
);
2398 } // end of wxDC::SetSystemScale
2400 void wxDC::SetLogicalOrigin(
2407 ::GpiQueryPageViewport( m_hPS
2414 ::GpiSetPageViewport( m_hPS
2417 }; // end of wxDC::SetLogicalOrigin
2419 void wxDC::SetDeviceOrigin(
2426 m_deviceOriginX
= vX
;
2427 m_deviceOriginY
= vY
;
2428 ::GpiQueryPageViewport( m_hPS
2433 vRect
.yBottom
-= vY
;
2435 ::GpiSetPageViewport( m_hPS
2438 }; // end of wxDC::SetDeviceOrigin
2440 // ---------------------------------------------------------------------------
2441 // coordinates transformations
2442 // ---------------------------------------------------------------------------
2444 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2446 return (wxCoord
) (((x
) - m_deviceOriginX
)/(m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
) - m_logicalOriginX
);
2449 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2451 // axis orientation is not taken into account for conversion of a distance
2452 return (wxCoord
) ((x
)/(m_logicalScaleX
*m_userScaleX
*m_scaleX
));
2455 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2457 return (wxCoord
) (((y
) - m_deviceOriginY
)/(m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
) - m_logicalOriginY
);
2460 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2462 // axis orientation is not taken into account for conversion of a distance
2463 return (wxCoord
) ((y
)/(m_logicalScaleY
*m_userScaleY
*m_scaleY
));
2466 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2468 return (wxCoord
) ((x
- m_logicalOriginX
)*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
+ m_deviceOriginX
);
2471 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2473 // axis orientation is not taken into account for conversion of a distance
2474 return (wxCoord
) (x
*m_logicalScaleX
*m_userScaleX
*m_scaleX
);
2477 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2479 return (wxCoord
) ((y
- m_logicalOriginY
)*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
+ m_deviceOriginY
);
2482 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2484 // axis orientation is not taken into account for conversion of a distance
2485 return (wxCoord
) (y
*m_logicalScaleY
*m_userScaleY
*m_scaleY
);
2488 // ---------------------------------------------------------------------------
2490 // ---------------------------------------------------------------------------
2492 bool wxDC::DoBlit( wxCoord vXdest
,
2501 wxCoord
WXUNUSED(vXsrcMask
),
2502 wxCoord
WXUNUSED(vYsrcMask
) )
2504 wxMask
* pMask
= NULL
;
2506 COLORREF vOldTextColor
;
2507 COLORREF vOldBackground
= ::GpiQueryBackColor(m_hPS
);
2511 const wxBitmap
& rBmp
= pSource
->m_vSelectedBitmap
;
2513 pMask
= rBmp
.GetMask();
2514 if (!(rBmp
.Ok() && pMask
&& pMask
->GetMaskBitmap()))
2520 ::GpiQueryAttrs( m_hPS
2525 vOldTextColor
= (COLORREF
)vCbnd
.lColor
;
2527 if (m_textForegroundColour
.Ok())
2529 vCbnd
.lColor
= (LONG
)m_textForegroundColour
.GetPixel();
2530 ::GpiSetAttrs( m_hPS
// presentation-space handle
2531 ,PRIM_CHAR
// Char primitive.
2532 ,CBB_COLOR
// sets color.
2534 ,&vCbnd
// buffer for attributes.
2537 if (m_textBackgroundColour
.Ok())
2539 ::GpiSetBackColor(m_hPS
, (LONG
)m_textBackgroundColour
.GetPixel());
2542 LONG lRop
= ROP_SRCCOPY
;
2546 case wxXOR
: lRop
= ROP_SRCINVERT
; break;
2547 case wxINVERT
: lRop
= ROP_DSTINVERT
; break;
2548 case wxOR_REVERSE
: lRop
= 0x00DD0228; break;
2549 case wxAND_REVERSE
: lRop
= ROP_SRCERASE
; break;
2550 case wxCLEAR
: lRop
= ROP_ZERO
; break;
2551 case wxSET
: lRop
= ROP_ONE
; break;
2552 case wxOR_INVERT
: lRop
= ROP_MERGEPAINT
; break;
2553 case wxAND
: lRop
= ROP_SRCAND
; break;
2554 case wxOR
: lRop
= ROP_SRCPAINT
; break;
2555 case wxEQUIV
: lRop
= 0x00990066; break;
2556 case wxNAND
: lRop
= 0x007700E6; break;
2557 case wxAND_INVERT
: lRop
= 0x00220326; break;
2558 case wxCOPY
: lRop
= ROP_SRCCOPY
; break;
2559 case wxNO_OP
: lRop
= ROP_NOTSRCERASE
; break;
2560 case wxSRC_INVERT
: lRop
= ROP_SRCINVERT
; break;
2561 case wxNOR
: lRop
= ROP_NOTSRCCOPY
; break;
2563 wxFAIL_MSG( wxT("unsupported logical function") );
2572 // Blit bitmap with mask
2576 // Create a temp buffer bitmap and DCs/PSs to access it and the mask
2582 DEVOPENSTRUC vDOP
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
2583 BITMAPINFOHEADER2 vBmpHdr
;
2585 SIZEL vSize
= {0, 0};
2588 memset(&vBmpHdr
, 0, sizeof(BITMAPINFOHEADER2
));
2589 vBmpHdr
.cbFix
= sizeof(BITMAPINFOHEADER2
);
2590 vBmpHdr
.cx
= vWidth
;
2591 vBmpHdr
.cy
= vHeight
;
2592 vBmpHdr
.cPlanes
= 1;
2593 vBmpHdr
.cBitCount
= 24;
2595 #if wxUSE_DC_CACHEING
2598 // create a temp buffer bitmap and DCs to access it and the mask
2600 wxDCCacheEntry
* pDCCacheEntry1
= FindDCInCache( NULL
2603 wxDCCacheEntry
* pDCCacheEntry2
= FindDCInCache( pDCCacheEntry1
2606 wxDCCacheEntry
* pBitmapCacheEntry
= FindBitmapInCache( GetHPS()
2611 hPSMask
= pDCCacheEntry1
->m_hPS
;
2612 hDCBuffer
= (HDC
)pDCCacheEntry2
->m_hPS
;
2613 hBufBitmap
= (HBITMAP
)pBitmapCacheEntry
->m_hBitmap
;
2614 wxUnusedVar(hDCMask
);
2618 hDCMask
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
2619 hDCBuffer
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
2620 hPSMask
= ::GpiCreatePS(vHabmain
, hDCMask
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
2621 hPSBuffer
= ::GpiCreatePS(vHabmain
, hDCBuffer
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
2622 hBufBitmap
= ::GpiCreateBitmap(GetHPS(), &vBmpHdr
, 0L, NULL
, NULL
);
2626 POINTL aPoint1
[4] = { {0, 0}
2629 ,{vXdest
+ vWidth
, vYdest
+ vHeight
}
2631 POINTL aPoint2
[4] = { {0, 0}
2634 ,{vXsrc
+ vWidth
, vYsrc
+ vHeight
}
2636 POINTL aPoint3
[4] = { {vXdest
, vYdest
}
2637 ,{vXdest
+ vWidth
, vYdest
+ vHeight
}
2639 ,{vXsrc
+ vWidth
, vYsrc
+ vHeight
}
2641 POINTL aPoint4
[4] = { {vXdest
, vYdest
}
2642 ,{vXdest
+ vWidth
, vYdest
+ vHeight
}
2646 ::GpiSetBitmap(hPSMask
, (HBITMAP
) pMask
->GetMaskBitmap());
2647 ::GpiSetBitmap(hPSBuffer
, (HBITMAP
) hBufBitmap
);
2650 // Copy dest to buffer
2652 rc
= ::GpiBitBlt( hPSBuffer
2659 if (rc
== GPI_ERROR
)
2661 wxLogLastError(wxT("BitBlt"));
2665 // Copy src to buffer using selected raster op
2667 rc
= ::GpiBitBlt( hPSBuffer
2674 if (rc
== GPI_ERROR
)
2676 wxLogLastError(wxT("BitBlt"));
2680 // Set masked area in buffer to BLACK (pixel value 0)
2682 COLORREF vPrevBkCol
= ::GpiQueryBackColor(GetHPS());
2683 COLORREF vPrevCol
= ::GpiQueryColor(GetHPS());
2685 ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255));
2686 ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0));
2688 rc
= ::GpiBitBlt( hPSBuffer
2695 if (rc
== GPI_ERROR
)
2697 wxLogLastError(wxT("BitBlt"));
2701 // Set unmasked area in dest to BLACK
2703 ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0));
2704 ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255));
2705 rc
= ::GpiBitBlt( GetHPS()
2712 if (rc
== GPI_ERROR
)
2714 wxLogLastError(wxT("BitBlt"));
2718 // Restore colours to original values
2720 ::GpiSetBackColor(GetHPS(), vPrevBkCol
);
2721 ::GpiSetColor(GetHPS(), vPrevCol
);
2724 // OR buffer to dest
2726 rc
= ::GpiBitBlt( GetHPS()
2733 if (rc
== GPI_ERROR
)
2736 wxLogLastError(wxT("BitBlt"));
2740 // Tidy up temporary DCs and bitmap
2742 ::GpiSetBitmap(hPSMask
, NULLHANDLE
);
2743 ::GpiSetBitmap(hPSBuffer
, NULLHANDLE
);
2744 #if !wxUSE_DC_CACHEING
2745 ::GpiDestroyPS(hPSMask
);
2746 ::GpiDestroyPS(hPSBuffer
);
2747 ::DevCloseDC(hDCMask
);
2748 ::DevCloseDC(hDCBuffer
);
2749 ::GpiDeleteBitmap(hBufBitmap
);
2753 else // no mask, just BitBlt() it
2755 POINTL aPoint
[4] = { {vXdest
, vYdest
}
2756 ,{vXdest
+ vWidth
, vYdest
+ vHeight
}
2758 ,{vXsrc
+ vWidth
, vYsrc
+ vHeight
}
2761 bSuccess
= (::GpiBitBlt( m_hPS
2770 wxLogLastError(wxT("BitBlt"));
2773 vCbnd
.lColor
= (LONG
)vOldTextColor
;
2774 ::GpiSetAttrs( m_hPS
// presentation-space handle
2775 ,PRIM_CHAR
// Char primitive.
2776 ,CBB_COLOR
// sets color.
2778 ,&vCbnd
// buffer for attributes.
2780 ::GpiSetBackColor(m_hPS
, (LONG
)vOldBackground
);
2784 void wxDC::DoGetSize(
2789 LONG lArray
[CAPS_HEIGHT
];
2791 if(::DevQueryCaps( m_hDC
2797 *pnWidth
= lArray
[CAPS_WIDTH
];
2798 *pnHeight
= lArray
[CAPS_HEIGHT
];
2800 }; // end of wxDC::DoGetSize(
2802 void wxDC::DoGetSizeMM( int* pnWidth
,
2803 int* pnHeight
) const
2805 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2807 if(::DevQueryCaps( m_hDC
2809 ,CAPS_VERTICAL_RESOLUTION
2815 int nWidth
= lArray
[CAPS_WIDTH
];
2816 int nHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2817 *pnWidth
= (nHorzRes
/1000) * nWidth
;
2822 int nHeight
= lArray
[CAPS_HEIGHT
];
2823 int nVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2824 *pnHeight
= (nVertRes
/1000) * nHeight
;
2827 }; // end of wxDC::DoGetSizeMM
2829 wxSize
wxDC::GetPPI() const
2831 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2835 if(::DevQueryCaps( m_hDC
2837 ,CAPS_VERTICAL_RESOLUTION
2846 nPelWidth
= lArray
[CAPS_WIDTH
];
2847 nPelHeight
= lArray
[CAPS_HEIGHT
];
2848 nHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2849 nVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2850 nWidth
= (int)((nHorzRes
/39.3) * nPelWidth
);
2851 nHeight
= (int)((nVertRes
/39.3) * nPelHeight
);
2853 wxSize
ppisize(nWidth
, nHeight
);
2855 } // end of wxDC::GetPPI
2857 void wxDC::SetLogicalScale(
2862 m_logicalScaleX
= dX
;
2863 m_logicalScaleY
= dY
;
2864 }; // end of wxDC::SetLogicalScale