1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/dc.cpp
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
777 ::GpiPointArc(m_hPS
, vPtlArc
); // Draws the arc
778 CalcBoundingBox( (wxCoord
)(vXc
- dRadius
)
779 ,(wxCoord
)(vYc
- dRadius
)
781 CalcBoundingBox( (wxCoord
)(vXc
+ dRadius
)
782 ,(wxCoord
)(vYc
+ dRadius
)
784 } // end of wxDC::DoDrawArc
786 void wxDC::DoDrawCheckMark(
795 vY1
= OS2Y(vY1
,vHeight
);
799 vPoint
[1].x
= vX1
+ vWidth
;
800 vPoint
[1].y
= vY1
+ vHeight
;
802 ::GpiMove(m_hPS
, &vPoint
[0]);
803 ::GpiBox( m_hPS
// handle to a presentation space
804 ,DRO_OUTLINE
// draw the box outline ? or ?
805 ,&vPoint
[1] // address of the corner
806 ,0L // horizontal corner radius
807 ,0L // vertical corner radius
809 if(vWidth
> 4 && vHeight
> 4)
813 vPoint
[0].x
+= 2; vPoint
[0].y
+= 2;
814 vPoint
[1].x
-= 2; vPoint
[1].y
-= 2;
815 ::GpiMove(m_hPS
, &vPoint
[0]);
816 ::GpiLine(m_hPS
, &vPoint
[1]);
818 vPoint
[0].x
= vPoint
[1].x
;
820 ::GpiMove(m_hPS
, &vPoint
[0]);
821 ::GpiLine(m_hPS
, &vPoint
[1]);
827 wxCoord vX2
= vX1
+ vWidth
;
828 wxCoord vY2
= vY1
+ vHeight
;
833 } // end of wxDC::DoDrawCheckMark
835 void wxDC::DoDrawPoint(
841 COLORREF vColor
= 0x00ffffff;
845 vColor
= m_pen
.GetColour().GetPixel();
847 ::GpiSetColor(m_hPS
, vColor
);
849 vPoint
.y
= OS2Y(vY
,0);
850 ::GpiSetPel(m_hPS
, &vPoint
);
854 } // end of wxDC::DoDrawPoint
856 void wxDC::DoDrawPolygon(
864 ULONG ulCount
= 1; // Number of polygons.
865 POLYGON vPlgn
; // polygon.
866 ULONG flOptions
= 0L; // Drawing options.
868 //////////////////////////////////////////////////////////////////////////////
869 // This contains fields of option bits... to draw boundary lines as well as
870 // the area interior.
872 // Drawing boundary lines:
873 // POLYGON_NOBOUNDARY Does not draw boundary lines.
874 // POLYGON_BOUNDARY Draws boundary lines (the default).
876 // Construction of the area interior:
877 // POLYGON_ALTERNATE Constructs interior in alternate mode
879 // POLYGON_WINDING Constructs interior in winding mode.
880 //////////////////////////////////////////////////////////////////////////////
882 ULONG flModel
= 0L; // Drawing model.
884 //////////////////////////////////////////////////////////////////////////////
886 // POLYGON_INCL Fill is inclusive of bottom right (the default).
887 // POLYGON_EXCL Fill is exclusive of bottom right.
888 // This is provided to aid migration from other graphics models.
889 //////////////////////////////////////////////////////////////////////////////
891 LONG lHits
= 0L; // Correlation/error indicator.
894 int nIsTRANSPARENT
= 0;
895 LONG lBorderColor
= 0L;
898 lBorderColor
= m_pen
.GetColour().GetPixel();
899 lColor
= m_brush
.GetColour().GetPixel();
900 if(m_brush
.GetStyle() == wxTRANSPARENT
)
904 vPlgn
.aPointl
= (POINTL
*) calloc( n
+ 1
906 ); // well, new will call malloc
908 for(i
= 0; i
< n
; i
++)
910 vPlgn
.aPointl
[i
].x
= vPoints
[i
].x
; // +xoffset;
911 vPlgn
.aPointl
[i
].y
= OS2Y(vPoints
[i
].y
,0); // +yoffset;
913 flModel
= POLYGON_BOUNDARY
;
914 if(nFillStyle
== wxWINDING_RULE
)
915 flModel
|= POLYGON_WINDING
;
917 flModel
|= POLYGON_ALTERNATE
;
920 vPoint
.y
= OS2Y(vYoffset
,0);
922 ::GpiSetColor(m_hPS
, lBorderColor
);
923 ::GpiMove(m_hPS
, &vPoint
);
924 lHits
= ::GpiPolygons(m_hPS
, ulCount
, &vPlgn
, flOptions
, flModel
);
926 } // end of wxDC::DoDrawPolygon
928 void wxDC::DoDrawLines(
937 if (vXoffset
!= 0L || vXoffset
!= 0L)
941 vPoint
.x
= vPoints
[0].x
+ vXoffset
;
942 vPoint
.y
= OS2Y(vPoints
[0].y
+ vYoffset
,0);
943 ::GpiMove(m_hPS
, &vPoint
);
945 LONG lBorderColor
= m_pen
.GetColour().GetPixel();
947 ::GpiSetColor(m_hPS
, lBorderColor
);
948 for(i
= 1; i
< n
; i
++)
950 vPoint
.x
= vPoints
[i
].x
+ vXoffset
;
951 vPoint
.y
= OS2Y(vPoints
[i
].y
+ vYoffset
,0);
952 ::GpiLine(m_hPS
, &vPoint
);
959 CalcBoundingBox( vPoints
[0].x
962 vPoint
.x
= vPoints
[0].x
;
963 vPoint
.y
= OS2Y(vPoints
[0].y
,0);
964 ::GpiMove(m_hPS
, &vPoint
);
966 for (i
= 0; i
< n
; i
++)
968 CalcBoundingBox( vPoints
[i
].x
971 vPoint
.x
= vPoints
[i
].x
;
972 vPoint
.y
= OS2Y(vPoints
[i
].y
,0);
973 ::GpiLine(m_hPS
, &vPoint
);
976 } // end of wxDC::DoDrawLines
978 void wxDC::DoDrawRectangle(
989 int nIsTRANSPARENT
= 0;
992 // Might be a memory DC with no Paint rect.
994 if (!(m_vRclPaint
.yTop
== 0 &&
995 m_vRclPaint
.yBottom
== 0 &&
996 m_vRclPaint
.xRight
== 0 &&
997 m_vRclPaint
.xLeft
== 0))
998 vY
= OS2Y(vY
,vHeight
);
1001 if (m_vSelectedBitmap
!= wxNullBitmap
)
1003 m_vRclPaint
.yTop
= m_vSelectedBitmap
.GetHeight();
1004 m_vRclPaint
.xRight
= m_vSelectedBitmap
.GetWidth();
1005 vY
= OS2Y(vY
,vHeight
);
1009 wxCoord vX2
= vX
+ vWidth
;
1010 wxCoord vY2
= vY
+ vHeight
;
1014 vPoint
[1].x
= vX
+ vWidth
- 1;
1015 vPoint
[1].y
= vY
+ vHeight
- 1;
1016 ::GpiMove(m_hPS
, &vPoint
[0]);
1017 lColor
= m_brush
.GetColour().GetPixel();
1018 lBorderColor
= m_pen
.GetColour().GetPixel();
1019 if (m_brush
.GetStyle() == wxTRANSPARENT
)
1021 if(lColor
== lBorderColor
|| nIsTRANSPARENT
)
1023 lControl
= DRO_OUTLINEFILL
; //DRO_FILL;
1024 if(m_brush
.GetStyle() == wxTRANSPARENT
)
1025 lControl
= DRO_OUTLINE
;
1027 ::GpiSetColor(m_hPS
, lBorderColor
);
1028 ::GpiBox( m_hPS
// handle to a presentation space
1029 ,lControl
// draw the box outline ? or ?
1030 ,&vPoint
[1] // address of the corner
1031 ,0L // horizontal corner radius
1032 ,0L // vertical corner radius
1037 lControl
= DRO_OUTLINE
;
1038 ::GpiSetColor( m_hPS
1047 lControl
= DRO_FILL
;
1048 ::GpiSetColor( m_hPS
1051 vPoint
[0].x
= vX
+ 1;
1052 vPoint
[0].y
= vY
+ 1;
1053 vPoint
[1].x
= vX
+ vWidth
- 2;
1054 vPoint
[1].y
= vY
+ vHeight
- 2;
1055 ::GpiMove(m_hPS
, &vPoint
[0]);
1063 CalcBoundingBox(vX
, vY
);
1064 CalcBoundingBox(vX2
, vY2
);
1065 } // end of wxDC::DoDrawRectangle
1067 void wxDC::DoDrawRoundedRectangle(
1079 int nIsTRANSPARENT
= 0;
1082 // Might be a memory DC with no Paint rect.
1084 if (!(m_vRclPaint
.yTop
== 0 &&
1085 m_vRclPaint
.yBottom
== 0 &&
1086 m_vRclPaint
.xRight
== 0 &&
1087 m_vRclPaint
.xLeft
== 0))
1088 vY
= OS2Y(vY
,vHeight
);
1091 if (m_vSelectedBitmap
!= wxNullBitmap
)
1093 m_vRclPaint
.yTop
= m_vSelectedBitmap
.GetHeight();
1094 m_vRclPaint
.xRight
= m_vSelectedBitmap
.GetWidth();
1095 vY
= OS2Y(vY
,vHeight
);
1099 wxCoord vX2
= (vX
+ vWidth
);
1100 wxCoord vY2
= (vY
+ vHeight
);
1104 vPoint
[1].x
= vX
+ vWidth
- 1;
1105 vPoint
[1].y
= vY
+ vHeight
- 1;
1106 ::GpiMove(m_hPS
, &vPoint
[0]);
1108 lColor
= m_brush
.GetColour().GetPixel();
1109 lBorderColor
= m_pen
.GetColour().GetPixel();
1110 lControl
= DRO_OUTLINEFILL
; //DRO_FILL;
1111 if (m_brush
.GetStyle() == wxTRANSPARENT
)
1113 if(lColor
== lBorderColor
|| nIsTRANSPARENT
)
1115 lControl
= DRO_OUTLINEFILL
; //DRO_FILL;
1116 if(m_brush
.GetStyle() == wxTRANSPARENT
)
1117 lControl
= DRO_OUTLINE
;
1119 ::GpiSetColor(m_hPS
, lColor
);
1120 ::GpiBox( m_hPS
// handle to a presentation space
1121 ,lControl
// draw the box outline ? or ?
1122 ,&vPoint
[1] // address of the corner
1123 ,(LONG
)dRadius
// horizontal corner radius
1124 ,(LONG
)dRadius
// vertical corner radius
1129 lControl
= DRO_OUTLINE
;
1130 ::GpiSetColor( m_hPS
1139 lControl
= DRO_FILL
;
1140 ::GpiSetColor( m_hPS
1143 vPoint
[0].x
= vX
+ 1;
1144 vPoint
[0].y
= vY
+ 1;
1145 vPoint
[1].x
= vX
+ vWidth
- 2;
1146 vPoint
[1].y
= vY
+ vHeight
- 2;
1147 ::GpiMove(m_hPS
, &vPoint
[0]);
1156 CalcBoundingBox(vX
, vY
);
1157 CalcBoundingBox(vX2
, vY2
);
1158 } // end of wxDC::DoDrawRoundedRectangle
1160 // Draw Ellipse within box (x,y) - (x+width, y+height)
1161 void wxDC::DoDrawEllipse(
1168 POINTL vPtlPos
; // Structure for current position
1169 FIXED vFxMult
; // Multiplier for ellipse
1170 ARCPARAMS vArcp
; // Structure for arc parameters
1172 vY
= OS2Y(vY
,vHeight
);
1175 vArcp
.lQ
= vHeight
/2;
1176 vArcp
.lP
= vWidth
/2;
1178 ::GpiSetArcParams( m_hPS
1180 ); // Sets parameters to default
1181 vPtlPos
.x
= vX
+ vWidth
/2; // Loads x-coordinate
1182 vPtlPos
.y
= vY
+ vHeight
/2; // Loads y-coordinate
1185 ); // Sets current position
1186 vFxMult
= MAKEFIXED(1, 0); /* Sets multiplier */
1189 // DRO_FILL, DRO_OTLINEFILL - where to get
1194 ); // Draws full arc with center at current position
1196 wxCoord vX2
= (vX
+ vWidth
);
1197 wxCoord vY2
= (vY
+ vHeight
);
1199 CalcBoundingBox(vX
, vY
);
1200 CalcBoundingBox(vX2
, vY2
);
1201 } // end of wxDC::DoDrawEllipse
1203 void wxDC::DoDrawEllipticArc(
1212 POINTL vPtlPos
; // Structure for current position
1213 FIXED vFxMult
; // Multiplier for ellipse
1214 ARCPARAMS vArcp
; // Structure for arc parameters
1216 FIXED vFSweepa
; // Start angle, sweep angle
1220 vY
= OS2Y(vY
,vHeight
);
1222 dFractPart
= modf(dSa
,&dIntPart
);
1223 vFSa
= MAKEFIXED((int)dIntPart
, (int)(dFractPart
* 0xffff) );
1224 dFractPart
= modf(dEa
- dSa
, &dIntPart
);
1225 vFSweepa
= MAKEFIXED((int)dIntPart
, (int)(dFractPart
* 0xffff) );
1228 // Ellipse main axis (r,q), (p,s) with center at (0,0)
1231 vArcp
.lQ
= vHeight
/2;
1232 vArcp
.lP
= vWidth
/2;
1234 ::GpiSetArcParams(m_hPS
, &vArcp
); // Sets parameters to default
1235 vPtlPos
.x
= (wxCoord
)(vX
+ vWidth
/2 * (1. + cos(DegToRad(dSa
)))); // Loads x-coordinate
1236 vPtlPos
.y
= (wxCoord
)(vY
+ vHeight
/2 * (1. + sin(DegToRad(dSa
)))); // Loads y-coordinate
1237 ::GpiMove(m_hPS
, &vPtlPos
); // Sets current position
1240 // May be not to the center ?
1242 vPtlPos
.x
= vX
+ vWidth
/2 ; // Loads x-coordinate
1243 vPtlPos
.y
= vY
+ vHeight
/2; // Loads y-coordinate
1244 vFxMult
= MAKEFIXED(1, 0); // Sets multiplier
1247 // DRO_FILL, DRO_OTLINEFILL - where to get
1249 ::GpiPartialArc( m_hPS
1255 wxCoord vX2
= (vX
+ vWidth
);
1256 wxCoord vY2
= (vY
+ vHeight
);
1258 CalcBoundingBox(vX
, vY
);
1259 CalcBoundingBox(vX2
, vY2
);
1260 } // end of wxDC::DoDrawEllipticArc
1262 void wxDC::DoDrawIcon(
1269 // Need to copy back into a bitmap. ::WinDrawPointer uses device coords
1270 // and I don't feel like figuring those out for scrollable windows so
1271 // just convert to a bitmap then let the DoDrawBitmap routing display it
1275 DoDrawBitmap(rIcon
.GetXpmSrc(), vX
, vY
, true);
1279 wxBitmap
vBitmap(rIcon
);
1281 DoDrawBitmap(vBitmap
, vX
, vY
, false);
1283 CalcBoundingBox(vX
, vY
);
1284 CalcBoundingBox(vX
+ rIcon
.GetWidth(), vY
+ rIcon
.GetHeight());
1285 } // end of wxDC::DoDrawIcon
1287 void wxDC::DoDrawBitmap(
1288 const wxBitmap
& rBmp
1294 #if wxUSE_PRINTING_ARCHITECTURE
1295 if (!IsKindOf(CLASSINFO(wxPrinterDC
)))
1298 HBITMAP hBitmap
= (HBITMAP
)rBmp
.GetHBITMAP();
1299 HBITMAP hBitmapOld
= NULLHANDLE
;
1302 vY
= OS2Y(vY
,rBmp
.GetHeight());
1305 vPoint
[0].y
= vY
+ rBmp
.GetHeight();
1306 vPoint
[1].x
= vX
+ rBmp
.GetWidth();
1310 vPoint
[3].x
= rBmp
.GetWidth();
1311 vPoint
[3].y
= rBmp
.GetHeight();
1314 wxMask
* pMask
= rBmp
.GetMask();
1319 // Need to imitate ::MaskBlt in windows.
1320 // 1) Extract the bits from from the bitmap.
1321 // 2) Extract the bits from the mask
1322 // 3) Using the mask bits do the following:
1323 // A) If the mask byte is 00 leave the bitmap byte alone
1324 // B) If the mask byte is FF copy the screen color into
1326 // 4) Create a new bitmap and set its bits to the above result
1327 // 5) Blit this to the screen PS
1329 HBITMAP hMask
= (HBITMAP
)pMask
->GetMaskBitmap();
1330 HBITMAP hOldMask
= NULLHANDLE
;
1331 HBITMAP hOldBitmap
= NULLHANDLE
;
1332 HBITMAP hNewBitmap
= NULLHANDLE
;
1333 unsigned char* pucBits
; // buffer that will contain the bitmap data
1334 unsigned char* pucBitsMask
; // buffer that will contain the mask data
1335 unsigned char* pucData
; // pointer to use to traverse bitmap data
1336 unsigned char* pucDataMask
; // pointer to use to traverse mask data
1342 // The usual Memory context creation stuff
1344 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
1345 SIZEL vSize
= {0, 0};
1346 HDC hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
1347 HPS hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIA_ASSOC
);
1350 // The usual bitmap header stuff
1352 BITMAPINFOHEADER2 vHeader
;
1355 memset(&vHeader
, '\0', 16);
1358 memset(&vInfo
, '\0', 16);
1360 vInfo
.cx
= (ULONG
)rBmp
.GetWidth();
1361 vInfo
.cy
= (ULONG
)rBmp
.GetHeight();
1363 vInfo
.cBitCount
= 24; // Set to desired count going in
1366 // Create the buffers for data....all wxBitmaps are 24 bit internally
1368 int nBytesPerLine
= rBmp
.GetWidth() * 3;
1369 int nSizeDWORD
= sizeof(DWORD
);
1370 int nLineBoundary
= nBytesPerLine
% nSizeDWORD
;
1378 // Need to get a background color for mask blitting
1380 if (IsKindOf(CLASSINFO(wxWindowDC
)))
1382 wxWindowDC
* pWindowDC
= wxDynamicCast(this, wxWindowDC
);
1384 lColor
= pWindowDC
->m_pCanvas
->GetBackgroundColour().GetPixel();
1386 else if (GetBrush().Ok())
1387 lColor
= GetBrush().GetColour().GetPixel();
1389 lColor
= m_textBackgroundColour
.GetPixel();
1392 // Bitmap must be in a double-word aligned address so we may
1393 // have some padding to worry about
1395 if (nLineBoundary
> 0)
1397 nPadding
= nSizeDWORD
- nLineBoundary
;
1398 nBytesPerLine
+= nPadding
;
1400 pucBits
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
1401 pucBitsMask
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
1402 memset(pucBits
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
1403 memset(pucBitsMask
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
1406 // Extract the bitmap and mask data
1408 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hBitmap
)) == HBM_ERROR
)
1410 vError
= ::WinGetLastError(vHabmain
);
1411 sError
= wxPMErrorToStr(vError
);
1413 ::GpiQueryBitmapInfoHeader(hBitmap
, &vHeader
);
1414 vInfo
.cBitCount
= 24;
1415 if ((lScans
= ::GpiQueryBitmapBits( hPS
1417 ,(LONG
)rBmp
.GetHeight()
1422 vError
= ::WinGetLastError(vHabmain
);
1423 sError
= wxPMErrorToStr(vError
);
1425 if ((hOldMask
= ::GpiSetBitmap(hPS
, hMask
)) == HBM_ERROR
)
1427 vError
= ::WinGetLastError(vHabmain
);
1428 sError
= wxPMErrorToStr(vError
);
1430 ::GpiQueryBitmapInfoHeader(hMask
, &vHeader
);
1431 vInfo
.cBitCount
= 24;
1432 if ((lScans
= ::GpiQueryBitmapBits( hPS
1434 ,(LONG
)rBmp
.GetHeight()
1439 vError
= ::WinGetLastError(vHabmain
);
1440 sError
= wxPMErrorToStr(vError
);
1442 if (( hMask
= ::GpiSetBitmap(hPS
, hOldMask
)) == HBM_ERROR
)
1444 vError
= ::WinGetLastError(vHabmain
);
1445 sError
= wxPMErrorToStr(vError
);
1449 // Now set the bytes(bits) according to the mask values
1450 // 3 bytes per pel...must handle one at a time
1453 pucDataMask
= pucBitsMask
;
1456 // 16 bit kludge really only kinda works. The mask gets applied
1457 // where needed but the original bitmap bits are dorked sometimes
1459 bool bpp16
= (wxDisplayDepth() == 16);
1461 for (i
= 0; i
< rBmp
.GetHeight(); i
++)
1463 for (j
= 0; j
< rBmp
.GetWidth(); j
++)
1466 if (bpp16
&& *pucDataMask
== 0xF8) // 16 bit display gobblygook
1468 else if (*pucDataMask
== 0xFF) // leave bitmap byte alone
1472 *pucData
= ((unsigned char)(lColor
>> 16));
1476 if (bpp16
&& *(pucDataMask
+ 1) == 0xFC) // 16 bit display gobblygook
1478 else if (*(pucDataMask
+ 1) == 0xFF) // leave bitmap byte alone
1482 *pucData
= ((unsigned char)(lColor
>> 8));
1487 if (bpp16
&& *(pucDataMask
+ 2) == 0xF8) // 16 bit display gobblygook
1489 else if (*(pucDataMask
+ 2) == 0xFF) // leave bitmap byte alone
1493 *pucData
= ((unsigned char)lColor
);
1498 for (j
= 0; j
< nPadding
; j
++)
1505 // Create a new bitmap
1507 vHeader
.cx
= (ULONG
)rBmp
.GetWidth();
1508 vHeader
.cy
= (ULONG
)rBmp
.GetHeight();
1509 vHeader
.cPlanes
= 1L;
1510 vHeader
.cBitCount
= 24;
1511 if ((hNewBitmap
= ::GpiCreateBitmap( hPS
1518 vError
= ::WinGetLastError(vHabmain
);
1519 sError
= wxPMErrorToStr(vError
);
1523 // Now blit it to the screen PS
1525 if ((lHits
= ::GpiWCBitBlt( (HPS
)GetHPS()
1533 vError
= ::WinGetLastError(vHabmain
);
1534 sError
= wxPMErrorToStr(vError
);
1542 ::GpiSetBitmap(hPS
, NULLHANDLE
);
1543 ::GpiDeleteBitmap(hNewBitmap
);
1544 ::GpiDestroyPS(hPS
);
1550 ULONG lOldForeGround
= ::GpiQueryColor((HPS
)GetHPS());
1551 ULONG lOldBackGround
= ::GpiQueryBackColor((HPS
)GetHPS());
1553 if (m_textForegroundColour
.Ok())
1555 ::GpiSetColor( (HPS
)GetHPS()
1556 ,m_textForegroundColour
.GetPixel()
1559 if (m_textBackgroundColour
.Ok())
1561 ::GpiSetBackColor( (HPS
)GetHPS()
1562 ,m_textBackgroundColour
.GetPixel()
1566 // Need to alter bits in a mono bitmap to match the new
1567 // background-foreground if it is different.
1569 if (rBmp
.IsMono() &&
1570 ((m_textForegroundColour
.GetPixel() != lOldForeGround
) ||
1571 (m_textBackgroundColour
.GetPixel() != lOldBackGround
)))
1573 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
1574 SIZEL vSize
= {0, 0};
1575 HDC hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
1576 HPS hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIA_ASSOC
);
1578 int nBytesPerLine
= rBmp
.GetWidth() * 3;
1580 LONG lForeGround
= m_textForegroundColour
.GetPixel();
1581 LONG lBackGround
= m_textBackgroundColour
.GetPixel();
1583 HBITMAP hOldBitmap
= NULLHANDLE
;
1589 memset(&vInfo
, '\0', 16);
1591 vInfo
.cx
= (ULONG
)rBmp
.GetWidth();
1592 vInfo
.cy
= (ULONG
)rBmp
.GetHeight();
1594 vInfo
.cBitCount
= 24;
1596 unsigned char* pucBits
; // buffer that will contain the bitmap data
1597 unsigned char* pucData
; // pointer to use to traverse bitmap data
1599 pucBits
= new unsigned char[nBytesPerLine
* rBmp
.GetHeight()];
1600 memset(pucBits
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
1602 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hBitmap
)) == HBM_ERROR
)
1604 vError
= ::WinGetLastError(vHabmain
);
1605 sError
= wxPMErrorToStr(vError
);
1608 if ((lScans
= ::GpiQueryBitmapBits( hPS
1610 ,(LONG
)rBmp
.GetHeight()
1615 vError
= ::WinGetLastError(vHabmain
);
1616 sError
= wxPMErrorToStr(vError
);
1619 unsigned char cOldRedFore
= (unsigned char)(lOldForeGround
>> 16);
1620 unsigned char cOldGreenFore
= (unsigned char)(lOldForeGround
>> 8);
1621 unsigned char cOldBlueFore
= (unsigned char)lOldForeGround
;
1623 unsigned char cRedFore
= (unsigned char)(lForeGround
>> 16);
1624 unsigned char cGreenFore
= (unsigned char)(lForeGround
>> 8);
1625 unsigned char cBlueFore
= (unsigned char)lForeGround
;
1627 unsigned char cRedBack
= (unsigned char)(lBackGround
>> 16);
1628 unsigned char cGreenBack
= (unsigned char)(lBackGround
>> 8);
1629 unsigned char cBlueBack
= (unsigned char)lBackGround
;
1632 for (i
= 0; i
< rBmp
.GetHeight(); i
++)
1634 for (j
= 0; j
< rBmp
.GetWidth(); j
++)
1636 unsigned char cBmpRed
= *pucData
;
1637 unsigned char cBmpGreen
= *(pucData
+ 1);
1638 unsigned char cBmpBlue
= *(pucData
+ 2);
1640 if ((cBmpRed
== cOldRedFore
) &&
1641 (cBmpGreen
== cOldGreenFore
) &&
1642 (cBmpBlue
== cOldBlueFore
))
1644 *pucData
= cBlueFore
;
1646 *pucData
= cGreenFore
;
1648 *pucData
= cRedFore
;
1653 *pucData
= cBlueBack
;
1655 *pucData
= cGreenBack
;
1657 *pucData
= cRedBack
;
1662 if ((lScans
= ::GpiSetBitmapBits( hPS
1664 ,(LONG
)rBmp
.GetHeight()
1669 vError
= ::WinGetLastError(vHabmain
);
1670 sError
= wxPMErrorToStr(vError
);
1674 ::GpiSetBitmap(hPS
, NULLHANDLE
);
1675 ::GpiDestroyPS(hPS
);
1678 ::GpiWCBitBlt( (HPS
)GetHPS()
1685 ::GpiSetBitmap((HPS
)GetHPS(), hBitmapOld
);
1686 ::GpiSetColor((HPS
)GetHPS(), lOldForeGround
);
1687 ::GpiSetBackColor((HPS
)GetHPS(), lOldBackGround
);
1690 } // end of wxDC::DoDrawBitmap
1692 void wxDC::DoDrawText(
1693 const wxString
& rsText
1706 CalcBoundingBox(vX
, vY
);
1707 GetTextExtent(rsText
, &vWidth
, &vHeight
);
1708 CalcBoundingBox((vX
+ vWidth
), (vY
+ vHeight
));
1709 } // end of wxDC::DoDrawText
1711 void wxDC::DrawAnyText(
1712 const wxString
& rsText
1717 int nOldBackground
= 0;
1724 // prepare for drawing the text
1728 // Set text color attributes
1730 if (m_textForegroundColour
.Ok())
1733 ,(int)m_textForegroundColour
.GetPixel()
1737 if (m_textBackgroundColour
.Ok())
1739 nOldBackground
= SetTextBkColor( m_hPS
1740 ,(int)m_textBackgroundColour
.GetPixel()
1746 GetTextExtent( rsText
1751 if (!(m_vRclPaint
.yTop
== 0 &&
1752 m_vRclPaint
.yBottom
== 0 &&
1753 m_vRclPaint
.xRight
== 0 &&
1754 m_vRclPaint
.xLeft
== 0))
1757 // Position Text a little differently in the Statusbar from other panels
1759 if (m_pCanvas
&& m_pCanvas
->IsKindOf(CLASSINFO(wxStatusBar
)))
1760 vPtlStart
.y
= OS2Y(vY
,vTextY
);
1762 vPtlStart
.y
= (wxCoord
)(OS2Y(vY
,vTextY
/1.5)); // Full extent is a bit much
1766 if (m_vSelectedBitmap
!= wxNullBitmap
)
1768 m_vRclPaint
.yTop
= m_vSelectedBitmap
.GetHeight();
1769 m_vRclPaint
.xRight
= m_vSelectedBitmap
.GetWidth();
1770 if (m_pCanvas
&& m_pCanvas
->IsKindOf(CLASSINFO(wxStatusBar
)))
1771 vPtlStart
.y
= OS2Y(vY
,vTextY
);
1773 vPtlStart
.y
= (LONG
)(OS2Y(vY
,vTextY
/1.5));
1779 PCH pzStr
= (PCH
)rsText
.c_str();
1781 ::GpiMove(m_hPS
, &vPtlStart
);
1782 lHits
= ::GpiCharString( m_hPS
1786 if (lHits
!= GPI_OK
)
1788 wxLogLastError(wxT("TextOut"));
1792 // Restore the old parameters (text foreground colour may be left because
1793 // it never is set to anything else, but background should remain
1794 // transparent even if we just drew an opaque string)
1796 if (m_textBackgroundColour
.Ok())
1797 SetTextBkColor( m_hPS
1805 void wxDC::DoDrawRotatedText(
1806 const wxString
& rsText
1824 DoDrawText(text, x, y);
1829 wxFillLogFont(&lf, &m_font);
1831 // GDI wants the angle in tenth of degree
1832 long angle10 = (long)(angle * 10);
1833 lf.lfEscapement = angle10;
1834 lf. lfOrientation = angle10;
1836 HFONT hfont = ::CreateFontIndirect(&lf);
1839 wxLogLastError("CreateFont");
1843 HFONT hfontOld = ::SelectObject(GetHdc(), hfont);
1845 DrawAnyText(text, x, y);
1847 (void)::SelectObject(GetHdc(), hfontOld);
1850 // call the bounding box by adding all four vertices of the rectangle
1851 // containing the text to it (simpler and probably not slower than
1852 // determining which of them is really topmost/leftmost/...)
1854 GetTextExtent(text, &w, &h);
1856 double rad = DegToRad(angle);
1858 // "upper left" and "upper right"
1859 CalcBoundingBox(x, y);
1860 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
1861 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1863 // "bottom left" and "bottom right"
1864 x += (wxCoord)(h*sin(rad));
1865 y += (wxCoord)(h*cos(rad));
1866 CalcBoundingBox(x, y);
1867 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1872 // ---------------------------------------------------------------------------
1874 // ---------------------------------------------------------------------------
1876 void wxDC::DoSelectPalette( bool WXUNUSED(bRealize
) )
1879 // Set the old object temporarily, in case the assignment deletes an object
1880 // that's not yet selected out.
1891 hOldPal
= ::GpiSelectPalette((HDC
) m_hPS
, (HPALETTE
) m_palette
.GetHPALETTE());
1893 m_hOldPalette
= (WXHPALETTE
)hOldPal
;
1895 } // end of wxDC::DoSelectPalette
1897 void wxDC::InitializePalette()
1899 if (wxDisplayDepth() <= 8 )
1902 // Look for any window or parent that has a custom palette. If any has
1903 // one then we need to use it in drawing operations
1905 wxWindow
* pWin
= m_pCanvas
->GetAncestorWithCustomPalette();
1907 m_hasCustomPalette
= pWin
&& pWin
->HasCustomPalette();
1908 if (m_hasCustomPalette
)
1910 m_palette
= pWin
->GetPalette();
1913 // turn on PM translation for this palette
1918 } // end of wxDC::InitializePalette
1920 void wxDC::SetPalette(
1921 const wxPalette
& rPalette
1928 m_palette
= rPalette
;
1936 HPALETTE hOldPal
= ::GpiSelectPalette((HDC
) m_hPS
, (HPALETTE
) m_palette
.GetHPALETTE());
1938 m_hOldPalette
= (WXHPALETTE
)hOldPal
;
1939 } // end of wxDC::SetPalette
1946 // Set the old object temporarily, in case the assignment deletes an object
1947 // that's not yet selected out.
1959 m_font
.SetPS(m_hPS
); // this will realize the font
1963 HFONT hFont
= m_font
.GetResourceHandle();
1964 if (hFont
== (HFONT
) NULL
)
1966 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1969 m_hOldFont
= (WXHFONT
) hFont
;
1971 } // end of wxDC::SetFont
1977 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1993 m_pen
.SetPS((HPS
)m_hOldPen
);
2000 if (m_pen
.GetResourceHandle())
2004 m_hOldPen
= m_pen
.GetPS();
2006 ::GpiSetColor(m_hPS
, m_pen
.GetColour().GetPixel());
2010 void wxDC::SetBrush(
2011 const wxBrush
& rBrush
2014 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2020 if (m_brush
== rBrush
)
2030 m_brush
.SetPS((HPS
)m_hOldBrush
);
2037 if (m_brush
.GetResourceHandle())
2039 m_brush
.SetPS(m_hPS
);
2041 m_hOldBrush
= (WXHWND
)m_brush
.GetPS();
2044 } // end of wxDC::SetBrush
2046 void wxDC::SetBackground(
2047 const wxBrush
& rBrush
2050 m_backgroundBrush
= rBrush
;
2051 if (!m_backgroundBrush
.Ok())
2055 bool bCustomColours
= true;
2058 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
2059 // change background colours from the control-panel specified colours.
2061 if (m_pCanvas
->IsKindOf(CLASSINFO(wxWindow
)) &&
2062 ((m_pCanvas
->GetWindowStyleFlag() & wxUSER_COLOURS
) != wxUSER_COLOURS
))
2063 bCustomColours
= false;
2066 if (m_backgroundBrush
.GetStyle()==wxTRANSPARENT
)
2068 m_pCanvas
->SetTransparent(true);
2073 // Setting the background brush of a DC
2074 // doesn't affect the window background colour. However,
2075 // I'm leaving in the transparency setting because it's needed by
2076 // various controls (e.g. wxStaticText) to determine whether to draw
2077 // transparently or not. TODO: maybe this should be a new function
2078 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
2080 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
2082 m_pCanvas
->SetTransparent(false);
2086 COLORREF vNewColor
= m_backgroundBrush
.GetColour().GetPixel();
2087 (void)::GpiSetBackColor((HPS
)m_hPS
, (LONG
)vNewColor
);
2088 } // end of wxDC::SetBackground
2090 void wxDC::SetBackgroundMode(
2094 m_backgroundMode
= nMode
;
2095 } // end of wxDC::SetBackgroundMode
2097 void wxDC::SetLogicalFunction(
2101 m_logicalFunction
= nFunction
;
2102 SetRop((WXHDC
)m_hDC
);
2103 } // wxDC::SetLogicalFunction
2109 if (!hDC
|| m_logicalFunction
< 0)
2113 switch (m_logicalFunction
)
2124 lCRop
= FM_MERGESRCNOT
;
2128 lCRop
= FM_NOTMASKSRC
;
2140 lCRop
= FM_MERGENOTSRC
;
2144 lCRop
= FM_MERGESRCNOT
;
2156 lCRop
= FM_SUBTRACT
;
2163 lCRop
= FM_OVERPAINT
;
2166 ::GpiSetMix((HPS
)hDC
, lCRop
);
2167 } // end of wxDC::SetRop
2169 bool wxDC::StartDoc( const wxString
& WXUNUSED(rsMessage
) )
2171 // We might be previewing, so return true to let it continue.
2173 } // end of wxDC::StartDoc
2177 } // end of wxDC::EndDoc
2179 void wxDC::StartPage()
2181 } // end of wxDC::StartPage
2183 void wxDC::EndPage()
2185 } // end of wxDC::EndPage
2187 // ---------------------------------------------------------------------------
2189 // ---------------------------------------------------------------------------
2191 wxCoord
wxDC::GetCharHeight() const
2193 FONTMETRICS vFM
; // metrics structure
2195 ::GpiQueryFontMetrics( m_hPS
2196 ,sizeof(FONTMETRICS
)
2199 return YDEV2LOGREL(vFM
.lXHeight
);
2202 wxCoord
wxDC::GetCharWidth() const
2204 FONTMETRICS vFM
; // metrics structure
2206 ::GpiQueryFontMetrics( m_hPS
2207 ,sizeof(FONTMETRICS
)
2210 return XDEV2LOGREL(vFM
.lAveCharWidth
);
2213 void wxDC::DoGetTextExtent(
2214 const wxString
& rsString
2217 , wxCoord
* pvDescent
2218 , wxCoord
* pvExternalLeading
2222 POINTL avPoint
[TXTBOX_COUNT
];
2227 FONTMETRICS vFM
; // metrics structure
2229 ERRORID vErrorCode
; // last error id code
2230 wxFont
* pFontToUse
= (wxFont
*)pTheFont
;
2232 wxChar zMsg
[128]; // DEBUG
2236 pFontToUse
= (wxFont
*)&m_font
;
2237 l
= rsString
.length();
2240 // In world coordinates.
2242 bRc
= ::GpiQueryTextBox( m_hPS
2244 ,(PCH
)rsString
.c_str()
2245 ,TXTBOX_COUNT
// return maximum information
2246 ,avPoint
// array of coordinates points
2250 vErrorCode
= ::WinGetLastError(wxGetInstance());
2251 sError
= wxPMErrorToStr(vErrorCode
);
2253 wxSprintf(zMsg
, _T("GpiQueryTextBox for %s: failed with Error: %lx - %s"), rsString
.c_str(), vErrorCode
, sError
.c_str());
2254 (void)wxMessageBox( _T("wxWidgets Menu sample")
2260 vPtMin
.x
= avPoint
[0].x
;
2261 vPtMax
.x
= avPoint
[0].x
;
2262 vPtMin
.y
= avPoint
[0].y
;
2263 vPtMax
.y
= avPoint
[0].y
;
2264 for (i
= 1; i
< 4; i
++)
2266 if(vPtMin
.x
> avPoint
[i
].x
) vPtMin
.x
= avPoint
[i
].x
;
2267 if(vPtMin
.y
> avPoint
[i
].y
) vPtMin
.y
= avPoint
[i
].y
;
2268 if(vPtMax
.x
< avPoint
[i
].x
) vPtMax
.x
= avPoint
[i
].x
;
2269 if(vPtMax
.y
< avPoint
[i
].y
) vPtMax
.y
= avPoint
[i
].y
;
2271 ::GpiQueryFontMetrics( m_hPS
2272 ,sizeof(FONTMETRICS
)
2277 *pvX
= (wxCoord
)(vPtMax
.x
- vPtMin
.x
+ 1);
2279 *pvY
= (wxCoord
)(vPtMax
.y
- vPtMin
.y
+ 1);
2281 *pvDescent
= vFM
.lMaxDescender
;
2282 if (pvExternalLeading
)
2283 *pvExternalLeading
= vFM
.lExternalLeading
;
2286 void wxDC::SetMapMode(
2290 int nPixelWidth
= 0;
2291 int nPixelHeight
= 0;
2294 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2296 m_mappingMode
= nMode
;
2298 if(::DevQueryCaps( m_hDC
2300 ,CAPS_VERTICAL_RESOLUTION
2307 nPixelWidth
= lArray
[CAPS_WIDTH
];
2308 nPixelHeight
= lArray
[CAPS_HEIGHT
];
2309 lHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2310 lVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2311 nMmWidth
= (lHorzRes
/1000) * nPixelWidth
;
2312 nMmWidth
= (lVertRes
/1000) * nPixelHeight
;
2314 if ((nPixelWidth
== 0) || (nPixelHeight
== 0) || (nMmWidth
== 0) || (nMmHeight
== 0))
2319 double dMm2pixelsX
= nPixelWidth
/nMmWidth
;
2320 double dMm2pixelsY
= nPixelHeight
/nMmHeight
;
2325 m_logicalScaleX
= (twips2mm
* dMm2pixelsX
);
2326 m_logicalScaleY
= (twips2mm
* dMm2pixelsY
);
2330 m_logicalScaleX
= (pt2mm
* dMm2pixelsX
);
2331 m_logicalScaleY
= (pt2mm
* dMm2pixelsY
);
2335 m_logicalScaleX
= dMm2pixelsX
;
2336 m_logicalScaleY
= dMm2pixelsY
;
2340 m_logicalScaleX
= (dMm2pixelsX
/10.0);
2341 m_logicalScaleY
= (dMm2pixelsY
/10.0);
2346 m_logicalScaleX
= 1.0;
2347 m_logicalScaleY
= 1.0;
2353 ulOptions
= ::GpiQueryPS(m_hPS
, &vSize
);
2354 if (!ulOptions
& PU_ARBITRARY
)
2356 ulOptions
= PU_ARBITRARY
| GPIF_DEFAULT
;
2357 ::GpiSetPS(m_hPS
, &vSize
, ulOptions
);
2359 m_nWindowExtX
= (int)MS_XDEV2LOG(VIEWPORT_EXTENT
);
2360 m_nWindowExtY
= (int)MS_YDEV2LOG(VIEWPORT_EXTENT
);
2362 }; // end of wxDC::SetMapMode
2364 void wxDC::SetUserScale( double dX
,
2370 SetMapMode(m_mappingMode
);
2371 } // end of wxDC::SetUserScale
2373 void wxDC::SetAxisOrientation( bool bXLeftRight
,
2376 m_signX
= bXLeftRight
? 1 : -1;
2377 m_signY
= bYBottomUp
? -1 : 1;
2379 SetMapMode(m_mappingMode
);
2380 } // end of wxDC::SetAxisOrientation
2382 void wxDC::SetSystemScale(
2390 SetMapMode(m_mappingMode
);
2391 } // end of wxDC::SetSystemScale
2393 void wxDC::SetLogicalOrigin(
2400 ::GpiQueryPageViewport( m_hPS
2407 ::GpiSetPageViewport( m_hPS
2410 }; // end of wxDC::SetLogicalOrigin
2412 void wxDC::SetDeviceOrigin(
2419 m_deviceOriginX
= vX
;
2420 m_deviceOriginY
= vY
;
2421 ::GpiQueryPageViewport( m_hPS
2426 vRect
.yBottom
-= vY
;
2428 ::GpiSetPageViewport( m_hPS
2431 }; // end of wxDC::SetDeviceOrigin
2433 // ---------------------------------------------------------------------------
2434 // coordinates transformations
2435 // ---------------------------------------------------------------------------
2437 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2439 return (wxCoord
) (((x
) - m_deviceOriginX
)/(m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
) - m_logicalOriginX
);
2442 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2444 // axis orientation is not taken into account for conversion of a distance
2445 return (wxCoord
) ((x
)/(m_logicalScaleX
*m_userScaleX
*m_scaleX
));
2448 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2450 return (wxCoord
) (((y
) - m_deviceOriginY
)/(m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
) - m_logicalOriginY
);
2453 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2455 // axis orientation is not taken into account for conversion of a distance
2456 return (wxCoord
) ((y
)/(m_logicalScaleY
*m_userScaleY
*m_scaleY
));
2459 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2461 return (wxCoord
) ((x
- m_logicalOriginX
)*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
+ m_deviceOriginX
);
2464 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2466 // axis orientation is not taken into account for conversion of a distance
2467 return (wxCoord
) (x
*m_logicalScaleX
*m_userScaleX
*m_scaleX
);
2470 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2472 return (wxCoord
) ((y
- m_logicalOriginY
)*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
+ m_deviceOriginY
);
2475 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2477 // axis orientation is not taken into account for conversion of a distance
2478 return (wxCoord
) (y
*m_logicalScaleY
*m_userScaleY
*m_scaleY
);
2481 // ---------------------------------------------------------------------------
2483 // ---------------------------------------------------------------------------
2485 bool wxDC::DoBlit( wxCoord vXdest
,
2494 wxCoord
WXUNUSED(vXsrcMask
),
2495 wxCoord
WXUNUSED(vYsrcMask
) )
2497 wxMask
* pMask
= NULL
;
2499 COLORREF vOldTextColor
;
2500 COLORREF vOldBackground
= ::GpiQueryBackColor(m_hPS
);
2504 const wxBitmap
& rBmp
= pSource
->m_vSelectedBitmap
;
2506 pMask
= rBmp
.GetMask();
2507 if (!(rBmp
.Ok() && pMask
&& pMask
->GetMaskBitmap()))
2513 ::GpiQueryAttrs( m_hPS
2518 vOldTextColor
= (COLORREF
)vCbnd
.lColor
;
2520 if (m_textForegroundColour
.Ok())
2522 vCbnd
.lColor
= (LONG
)m_textForegroundColour
.GetPixel();
2523 ::GpiSetAttrs( m_hPS
// presentation-space handle
2524 ,PRIM_CHAR
// Char primitive.
2525 ,CBB_COLOR
// sets color.
2527 ,&vCbnd
// buffer for attributes.
2530 if (m_textBackgroundColour
.Ok())
2532 ::GpiSetBackColor(m_hPS
, (LONG
)m_textBackgroundColour
.GetPixel());
2535 LONG lRop
= ROP_SRCCOPY
;
2539 case wxXOR
: lRop
= ROP_SRCINVERT
; break;
2540 case wxINVERT
: lRop
= ROP_DSTINVERT
; break;
2541 case wxOR_REVERSE
: lRop
= 0x00DD0228; break;
2542 case wxAND_REVERSE
: lRop
= ROP_SRCERASE
; break;
2543 case wxCLEAR
: lRop
= ROP_ZERO
; break;
2544 case wxSET
: lRop
= ROP_ONE
; break;
2545 case wxOR_INVERT
: lRop
= ROP_MERGEPAINT
; break;
2546 case wxAND
: lRop
= ROP_SRCAND
; break;
2547 case wxOR
: lRop
= ROP_SRCPAINT
; break;
2548 case wxEQUIV
: lRop
= 0x00990066; break;
2549 case wxNAND
: lRop
= 0x007700E6; break;
2550 case wxAND_INVERT
: lRop
= 0x00220326; break;
2551 case wxCOPY
: lRop
= ROP_SRCCOPY
; break;
2552 case wxNO_OP
: lRop
= ROP_NOTSRCERASE
; break;
2553 case wxSRC_INVERT
: lRop
= ROP_SRCINVERT
; break;
2554 case wxNOR
: lRop
= ROP_NOTSRCCOPY
; break;
2556 wxFAIL_MSG( wxT("unsupported logical function") );
2565 // Blit bitmap with mask
2569 // Create a temp buffer bitmap and DCs/PSs to access it and the mask
2575 DEVOPENSTRUC vDOP
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
2576 BITMAPINFOHEADER2 vBmpHdr
;
2578 SIZEL vSize
= {0, 0};
2581 memset(&vBmpHdr
, 0, sizeof(BITMAPINFOHEADER2
));
2582 vBmpHdr
.cbFix
= sizeof(BITMAPINFOHEADER2
);
2583 vBmpHdr
.cx
= vWidth
;
2584 vBmpHdr
.cy
= vHeight
;
2585 vBmpHdr
.cPlanes
= 1;
2586 vBmpHdr
.cBitCount
= 24;
2588 #if wxUSE_DC_CACHEING
2591 // create a temp buffer bitmap and DCs to access it and the mask
2593 wxDCCacheEntry
* pDCCacheEntry1
= FindDCInCache( NULL
2596 wxDCCacheEntry
* pDCCacheEntry2
= FindDCInCache( pDCCacheEntry1
2599 wxDCCacheEntry
* pBitmapCacheEntry
= FindBitmapInCache( GetHPS()
2604 hPSMask
= pDCCacheEntry1
->m_hPS
;
2605 hDCBuffer
= (HDC
)pDCCacheEntry2
->m_hPS
;
2606 hBufBitmap
= (HBITMAP
)pBitmapCacheEntry
->m_hBitmap
;
2607 wxUnusedVar(hDCMask
);
2611 hDCMask
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
2612 hDCBuffer
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
2613 hPSMask
= ::GpiCreatePS(vHabmain
, hDCMask
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
2614 hPSBuffer
= ::GpiCreatePS(vHabmain
, hDCBuffer
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
2615 hBufBitmap
= ::GpiCreateBitmap(GetHPS(), &vBmpHdr
, 0L, NULL
, NULL
);
2619 POINTL aPoint1
[4] = { {0, 0}
2622 ,{vXdest
+ vWidth
, vYdest
+ vHeight
}
2624 POINTL aPoint2
[4] = { {0, 0}
2627 ,{vXsrc
+ vWidth
, vYsrc
+ vHeight
}
2629 POINTL aPoint3
[4] = { {vXdest
, vYdest
}
2630 ,{vXdest
+ vWidth
, vYdest
+ vHeight
}
2632 ,{vXsrc
+ vWidth
, vYsrc
+ vHeight
}
2634 POINTL aPoint4
[4] = { {vXdest
, vYdest
}
2635 ,{vXdest
+ vWidth
, vYdest
+ vHeight
}
2639 ::GpiSetBitmap(hPSMask
, (HBITMAP
) pMask
->GetMaskBitmap());
2640 ::GpiSetBitmap(hPSBuffer
, (HBITMAP
) hBufBitmap
);
2643 // Copy dest to buffer
2645 rc
= ::GpiBitBlt( hPSBuffer
2652 if (rc
== GPI_ERROR
)
2654 wxLogLastError(wxT("BitBlt"));
2658 // Copy src to buffer using selected raster op
2660 rc
= ::GpiBitBlt( hPSBuffer
2667 if (rc
== GPI_ERROR
)
2669 wxLogLastError(wxT("BitBlt"));
2673 // Set masked area in buffer to BLACK (pixel value 0)
2675 COLORREF vPrevBkCol
= ::GpiQueryBackColor(GetHPS());
2676 COLORREF vPrevCol
= ::GpiQueryColor(GetHPS());
2678 ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255));
2679 ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0));
2681 rc
= ::GpiBitBlt( hPSBuffer
2688 if (rc
== GPI_ERROR
)
2690 wxLogLastError(wxT("BitBlt"));
2694 // Set unmasked area in dest to BLACK
2696 ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0));
2697 ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255));
2698 rc
= ::GpiBitBlt( GetHPS()
2705 if (rc
== GPI_ERROR
)
2707 wxLogLastError(wxT("BitBlt"));
2711 // Restore colours to original values
2713 ::GpiSetBackColor(GetHPS(), vPrevBkCol
);
2714 ::GpiSetColor(GetHPS(), vPrevCol
);
2717 // OR buffer to dest
2719 rc
= ::GpiBitBlt( GetHPS()
2726 if (rc
== GPI_ERROR
)
2729 wxLogLastError(wxT("BitBlt"));
2733 // Tidy up temporary DCs and bitmap
2735 ::GpiSetBitmap(hPSMask
, NULLHANDLE
);
2736 ::GpiSetBitmap(hPSBuffer
, NULLHANDLE
);
2737 #if !wxUSE_DC_CACHEING
2738 ::GpiDestroyPS(hPSMask
);
2739 ::GpiDestroyPS(hPSBuffer
);
2740 ::DevCloseDC(hDCMask
);
2741 ::DevCloseDC(hDCBuffer
);
2742 ::GpiDeleteBitmap(hBufBitmap
);
2746 else // no mask, just BitBlt() it
2748 POINTL aPoint
[4] = { {vXdest
, vYdest
}
2749 ,{vXdest
+ vWidth
, vYdest
+ vHeight
}
2751 ,{vXsrc
+ vWidth
, vYsrc
+ vHeight
}
2754 bSuccess
= (::GpiBitBlt( m_hPS
2763 wxLogLastError(wxT("BitBlt"));
2766 vCbnd
.lColor
= (LONG
)vOldTextColor
;
2767 ::GpiSetAttrs( m_hPS
// presentation-space handle
2768 ,PRIM_CHAR
// Char primitive.
2769 ,CBB_COLOR
// sets color.
2771 ,&vCbnd
// buffer for attributes.
2773 ::GpiSetBackColor(m_hPS
, (LONG
)vOldBackground
);
2777 void wxDC::DoGetSize(
2782 LONG lArray
[CAPS_HEIGHT
];
2784 if(::DevQueryCaps( m_hDC
2790 *pnWidth
= lArray
[CAPS_WIDTH
];
2791 *pnHeight
= lArray
[CAPS_HEIGHT
];
2793 }; // end of wxDC::DoGetSize(
2795 void wxDC::DoGetSizeMM( int* pnWidth
,
2796 int* pnHeight
) const
2798 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2800 if(::DevQueryCaps( m_hDC
2802 ,CAPS_VERTICAL_RESOLUTION
2808 int nWidth
= lArray
[CAPS_WIDTH
];
2809 int nHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2810 *pnWidth
= (nHorzRes
/1000) * nWidth
;
2815 int nHeight
= lArray
[CAPS_HEIGHT
];
2816 int nVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2817 *pnHeight
= (nVertRes
/1000) * nHeight
;
2820 }; // end of wxDC::DoGetSizeMM
2822 wxSize
wxDC::GetPPI() const
2824 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2828 if(::DevQueryCaps( m_hDC
2830 ,CAPS_VERTICAL_RESOLUTION
2839 nPelWidth
= lArray
[CAPS_WIDTH
];
2840 nPelHeight
= lArray
[CAPS_HEIGHT
];
2841 nHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2842 nVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2843 nWidth
= (int)((nHorzRes
/39.3) * nPelWidth
);
2844 nHeight
= (int)((nVertRes
/39.3) * nPelHeight
);
2846 wxSize
ppisize(nWidth
, nHeight
);
2848 } // end of wxDC::GetPPI
2850 void wxDC::SetLogicalScale(
2855 m_logicalScaleX
= dX
;
2856 m_logicalScaleY
= dY
;
2857 }; // end of wxDC::SetLogicalScale