1 /////////////////////////////////////////////////////////////////////////////
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
16 #include "wx/window.h"
19 #include "wx/dialog.h"
21 #include "wx/bitmap.h"
22 #include "wx/dcmemory.h"
25 #include "wx/msgdlg.h"
26 #include "wx/module.h"
29 #include "wx/dcprint.h"
34 #include "wx/os2/private.h"
36 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
39 // wxWindows uses the Microsoft convention that the origin is the UPPER left.
40 // Native OS/2 however in the GPI and PM define the origin as the LOWER left.
41 // In order to map OS/2 GPI/PM y coordinates to wxWindows coordinates we must
42 // perform the following transformation:
44 // Parent object height: POBJHEIGHT
45 // Desried origin: WXORIGINY
46 // Object to place's height: OBJHEIGHT
48 // To get the OS2 position from the wxWindows one:
50 // OS2Y = POBJHEIGHT - (WXORIGINY + OBJHEIGHT)
52 // For OS/2 wxDC's we will always determine m_vRclPaint as the size of the
53 // OS/2 Presentation Space associated with the device context. y is the
54 // desired application's y coordinate of the origin in wxWindows space.
55 // objy is the height of the object we are going to draw.
57 #define OS2Y(y, objy) ((m_vRclPaint.yTop - m_vRclPaint.yBottom) - (y + objy))
59 // ---------------------------------------------------------------------------
61 // ---------------------------------------------------------------------------
63 static const int VIEWPORT_EXTENT
= 1000;
65 static const int MM_POINTS
= 9;
66 static const int MM_METRIC
= 10;
68 // usually this is defined in math.h
70 static const double M_PI
= 3.14159265358979323846;
73 // ---------------------------------------------------------------------------
75 // ---------------------------------------------------------------------------
77 // convert degrees to radians
78 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
82 , int nForegroundColour
87 vCbnd
.lColor
= nForegroundColour
;
88 ::GpiSetAttrs( hPS
// presentation-space handle
89 ,PRIM_CHAR
// Char primitive.
90 ,CBB_COLOR
// sets color.
92 ,&vCbnd
// buffer for attributes.
103 ::GpiQueryAttrs( hPS
// presentation-space handle
104 ,PRIM_CHAR
// Char primitive.
105 ,CBB_BACK_COLOR
// Background color.
106 ,&vCbnd
// buffer for attributes.
108 return vCbnd
.lBackColor
;
114 , int nBackgroundColour
120 rc
= QueryTextBkColor(hPS
);
122 vCbnd
.lBackColor
= nBackgroundColour
;
123 ::GpiSetAttrs(hPS
, // presentation-space handle
124 PRIM_CHAR
, // Char primitive.
125 CBB_BACK_COLOR
, // sets color.
127 &vCbnd
// buffer for attributes.
134 , int nBackgroundMode
137 if(nBackgroundMode
== wxTRANSPARENT
)
142 // the background of the primitive takes over whatever is underneath.
149 // ===========================================================================
151 // ===========================================================================
153 #if wxUSE_DC_CACHEING
156 * This implementation is a bit ugly and uses the old-fashioned wxList class, so I will
157 * improve it in due course, either using arrays, or simply storing pointers to one
158 * entry for the bitmap, and two for the DCs. -- JACS
161 // ---------------------------------------------------------------------------
163 // ---------------------------------------------------------------------------
165 wxList
wxDC::m_svBitmapCache
;
166 wxList
wxDC::m_svDCCache
;
168 wxDCCacheEntry::wxDCCacheEntry(
180 } // end of wxDCCacheEntry::wxDCCacheEntry
182 wxDCCacheEntry::wxDCCacheEntry(
187 m_hBitmap
= NULLHANDLE
;
192 } // end of wxDCCacheEntry::wxDCCacheEntry
194 wxDCCacheEntry::~wxDCCacheEntry()
197 ::GpiDeleteBitmap(m_hBitmap
);
199 ::GpiDestroyPS(m_hPS
);
200 } // end of wxDCCacheEntry::~wxDCCacheEntry
202 wxDCCacheEntry
* wxDC::FindBitmapInCache(
208 int nDepth
= 24; // we'll fix this later ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
209 wxNode
* pNode
= m_svBitmapCache
.First();
210 BITMAPINFOHEADER2 vBmpHdr
;
214 wxDCCacheEntry
* pEntry
= (wxDCCacheEntry
*)pNode
->Data();
216 if (pEntry
->m_nDepth
== nDepth
)
218 memset(&vBmpHdr
, 0, sizeof(BITMAPINFOHEADER2
));
220 if (pEntry
->m_nWidth
< nWidth
|| pEntry
->m_nHeight
< nHeight
)
222 ::GpiDeleteBitmap((HBITMAP
)pEntry
->m_hBitmap
);
223 vBmpHdr
.cbFix
= sizeof(BITMAPINFOHEADER2
);
225 vBmpHdr
.cy
= nHeight
;
227 vBmpHdr
.cBitCount
= nDepth
;
229 pEntry
->m_hBitmap
= (WXHBITMAP
) ::GpiCreateBitmap( hPS
233 if (!pEntry
->m_hBitmap
)
235 wxLogLastError(wxT("CreateCompatibleBitmap"));
237 pEntry
->m_nWidth
= nWidth
;
238 pEntry
->m_nHeight
= nHeight
;
243 pNode
= pNode
->Next();
245 memset(&vBmpHdr
, 0, sizeof(BITMAPINFOHEADER2
));
246 vBmpHdr
.cbFix
= sizeof(BITMAPINFOHEADER2
);
248 vBmpHdr
.cy
= nHeight
;
250 vBmpHdr
.cBitCount
= nDepth
;
252 WXHBITMAP hBitmap
= (WXHBITMAP
) ::GpiCreateBitmap( hPS
258 wxLogLastError(wxT("CreateCompatibleBitmap"));
260 wxDCCacheEntry
* pEntry
= new wxDCCacheEntry( hBitmap
265 AddToBitmapCache(pEntry
);
267 } // end of FindBitmapInCache
269 wxDCCacheEntry
* wxDC::FindDCInCache(
270 wxDCCacheEntry
* pNotThis
274 int nDepth
= 24; // we'll fix this up later ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
275 wxNode
* pNode
= m_svDCCache
.First();
279 wxDCCacheEntry
* pEntry
= (wxDCCacheEntry
*)pNode
->Data();
282 // Don't return the same one as we already have
284 if (!pNotThis
|| (pNotThis
!= pEntry
))
286 if (pEntry
->m_nDepth
== nDepth
)
291 pNode
= pNode
->Next();
293 wxDCCacheEntry
* pEntry
= new wxDCCacheEntry( hPS
296 AddToDCCache(pEntry
);
298 } // end of wxDC::FindDCInCache
300 void wxDC::AddToBitmapCache(
301 wxDCCacheEntry
* pEntry
304 m_svBitmapCache
.Append(pEntry
);
305 } // end of wxDC::AddToBitmapCache
307 void wxDC::AddToDCCache(
308 wxDCCacheEntry
* pEntry
311 m_svDCCache
.Append(pEntry
);
312 } // end of wxDC::AddToDCCache
314 void wxDC::ClearCache()
316 m_svBitmapCache
.DeleteContents(TRUE
);
317 m_svBitmapCache
.Clear();
318 m_svBitmapCache
.DeleteContents(FALSE
);
319 m_svDCCache
.DeleteContents(TRUE
);
321 m_svDCCache
.DeleteContents(FALSE
);
322 } // end of wxDC::ClearCache
324 // Clean up cache at app exit
325 class wxDCModule
: public wxModule
328 virtual bool OnInit() { return TRUE
; }
329 virtual void OnExit() { wxDC::ClearCache(); }
332 DECLARE_DYNAMIC_CLASS(wxDCModule
)
333 }; // end of CLASS wxDCModule
335 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
337 #endif // ndef for wxUSE_DC_CACHEING
339 // ---------------------------------------------------------------------------
341 // ---------------------------------------------------------------------------
359 m_bIsPaintTime
= FALSE
; // True at Paint Time
361 vColor
.InitFromName("BLACK");
362 m_pen
.SetColour(vColor
);
364 m_brush
.SetColour(vColor
);
365 } // end of wxDC::wxDC
371 SelectOldObjects(m_hDC
);
373 // if we own the HDC, we delete it, otherwise we just release it
379 ::GpiAssociate(m_hPS
, NULLHANDLE
);
380 ::GpiDestroyPS(m_hPS
);
383 ::DevCloseDC((HDC
)m_hDC
);
388 // Just Dissacociate, not destroy if we don't own the DC
392 ::GpiAssociate(m_hPS
, NULLHANDLE
);
396 } // end of wxDC::~wxDC
398 // This will select current objects out of the DC,
399 // which is what you have to do before deleting the
401 void wxDC::SelectOldObjects(
409 ::GpiSetBitmap(hPS
, (HBITMAP
) m_hOldBitmap
);
410 if (m_vSelectedBitmap
.Ok())
412 m_vSelectedBitmap
.SetSelectedInto(NULL
);
417 // OS/2 has no other native GDI objects to set in a PS/DC like windows
425 m_brush
= wxNullBrush
;
427 m_palette
= wxNullPalette
;
429 m_backgroundBrush
= wxNullBrush
;
430 m_vSelectedBitmap
= wxNullBitmap
;
431 } // end of wxDC::SelectOldObjects
433 // ---------------------------------------------------------------------------
435 // ---------------------------------------------------------------------------
437 #define DO_SET_CLIPPING_BOX() \
441 ::GpiQueryClipBox(m_hPS, &rect); \
443 m_clipX1 = (wxCoord) XDEV2LOG(rect.xLeft); \
444 m_clipY1 = (wxCoord) YDEV2LOG(rect.yTop); \
445 m_clipX2 = (wxCoord) XDEV2LOG(rect.xRight); \
446 m_clipY2 = (wxCoord) YDEV2LOG(rect.yBottom); \
449 void wxDC::DoSetClippingRegion(
458 vY
= OS2Y(vY
,vHeight
);
461 vRect
.yTop
= vY
+ vHeight
;
462 vRect
.xRight
= vX
+ vWidth
;
464 ::GpiIntersectClipRectangle(m_hPS
, &vRect
);
465 DO_SET_CLIPPING_BOX()
466 } // end of wxDC::DoSetClippingRegion
468 void wxDC::DoSetClippingRegionAsRegion(
469 const wxRegion
& rRegion
472 wxCHECK_RET(rRegion
.GetHRGN(), wxT("invalid clipping region"));
476 ::GpiSetClipRegion( m_hPS
477 ,(HRGN
)rRegion
.GetHRGN()
480 DO_SET_CLIPPING_BOX()
481 } // end of wxDC::DoSetClippingRegionAsRegion
483 void wxDC::DestroyClippingRegion(void)
485 if (m_clipping
&& m_hPS
)
490 // TODO: this should restore the previous clipped region
491 // so that OnPaint processing works correctly, and
492 // the update doesn't get destroyed after the first
493 // DestroyClippingRegion
494 vRect
.xLeft
= XLOG2DEV(0);
495 vRect
.yTop
= YLOG2DEV(32000);
496 vRect
.xRight
= XLOG2DEV(32000);
497 vRect
.yBottom
= YLOG2DEV(0);
499 HRGN hRgn
= ::GpiCreateRegion(m_hPS
, 1, &vRect
);
501 ::GpiSetClipRegion(m_hPS
, hRgn
, &hRgnOld
);
504 } // end of wxDC::DestroyClippingRegion
506 // ---------------------------------------------------------------------------
507 // query capabilities
508 // ---------------------------------------------------------------------------
510 bool wxDC::CanDrawBitmap() const
515 bool wxDC::CanGetTextExtent() const
517 LONG lTechnology
= 0L;
519 ::DevQueryCaps(GetHDC(), CAPS_TECHNOLOGY
, 1L, &lTechnology
);
520 return (lTechnology
== CAPS_TECH_RASTER_DISPLAY
) || (lTechnology
== CAPS_TECH_RASTER_PRINTER
);
521 } // end of wxDC::CanGetTextExtent
523 int wxDC::GetDepth() const
525 LONG lArray
[CAPS_COLOR_BITCOUNT
];
528 if(::DevQueryCaps( GetHDC()
534 nBitsPerPixel
= (int)lArray
[CAPS_COLOR_BITCOUNT
];
536 return nBitsPerPixel
;
537 } // end of wxDC::GetDepth
539 // ---------------------------------------------------------------------------
541 // ---------------------------------------------------------------------------
546 // If this is a canvas DC then just fill with the background color
547 // Otherwise purge the whole thing
553 ::GpiQueryClipBox(m_hPS
, &vRect
);
554 ::WinFillRect(m_hPS
, &vRect
, ::GpiQueryBackColor(m_hPS
));
558 } // end of wxDC::Clear
560 bool wxDC::DoFloodFill(
563 , const wxColour
& rCol
571 bool bSuccess
= FALSE
;
573 vPtlPos
.x
= vX
; // Loads x-coordinate
574 vPtlPos
.y
= OS2Y(vY
,0); // Loads y-coordinate
575 ::GpiMove(m_hPS
, &vPtlPos
); // Sets current position
576 lColor
= rCol
.GetPixel();
577 lOptions
= FF_BOUNDARY
;
578 if(wxFLOOD_SURFACE
== nStyle
)
579 lOptions
= FF_SURFACE
;
581 if ((lHits
= ::GpiFloodFill(m_hPS
, lOptions
, lColor
)) != GPI_ERROR
)
584 } // end of wxDC::DoFloodFill
586 bool wxDC::DoGetPixel(
596 vPoint
.y
= OS2Y(vY
,0);
597 lColor
= ::GpiSetPel(m_hPS
, &vPoint
);
600 // Get the color of the pen
602 LONG lPencolor
= 0x00ffffff;
606 lPencolor
= m_pen
.GetColour().GetPixel();
610 // return the color of the pixel
613 pCol
->Set( GetRValue(lColor
)
617 return(lColor
== lPencolor
);
618 } // end of wxDC::DoGetPixel
620 void wxDC::DoCrossHair(
627 wxCoord vX1
= vX
- VIEWPORT_EXTENT
;
628 wxCoord vY1
= vY
- VIEWPORT_EXTENT
;
629 wxCoord vX2
= vX
+ VIEWPORT_EXTENT
;
630 wxCoord vY2
= vY
+ VIEWPORT_EXTENT
;
639 ::GpiMove(m_hPS
, &vPoint
[0]);
640 ::GpiLine(m_hPS
, &vPoint
[1]);
648 ::GpiMove(m_hPS
, &vPoint
[2]);
649 ::GpiLine(m_hPS
, &vPoint
[3]);
650 CalcBoundingBox(vX1
, vY1
);
651 CalcBoundingBox(vX2
, vY2
);
652 } // end of wxDC::DoCrossHair
654 void wxDC::DoDrawLine(
670 ::GpiMove(m_hPS
, &vPoint
[0]);
671 ::GpiLine(m_hPS
, &vPoint
[1]);
672 CalcBoundingBox(vX1
, vY1
);
673 CalcBoundingBox(vX2
, vY2
);
674 } // end of wxDC::DoDrawLine
676 //////////////////////////////////////////////////////////////////////////////
677 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
678 // and ending at (x2, y2). The current pen is used for the outline and the
679 // current brush for filling the shape. The arc is drawn in an anticlockwise
680 // direction from the start point to the end point.
681 //////////////////////////////////////////////////////////////////////////////
682 void wxDC::DoDrawArc(
692 POINTL vPtlArc
[2]; // Structure for current position
701 ARCPARAMS vArcp
; // Structure for arc parameters
703 if((vX1
== vXc
&& vY1
== vXc
) || (vX2
== vXc
&& vY2
== vXc
))
704 return; // Draw point ??
705 dRadius
= 0.5 * ( hypot( (double)(vY1
- vYc
)
708 hypot( (double)(vY2
- vYc
)
713 dAngl1
= atan2( (double)(vY1
- vYc
)
716 dAngl2
= atan2( (double)(vY2
- vYc
)
723 // GpiPointArc can't draw full arc
725 if(dAngl2
== dAngl1
|| (vX1
== vX2
&& vY1
== vY2
) )
730 dAnglmid
= (dAngl1
+ dAngl2
)/2. + M_PI
;
731 vXm
= vXc
+ dRadius
* cos(dAnglmid
);
732 vYm
= vYc
+ dRadius
* sin(dAnglmid
);
747 dAnglmid
= (dAngl1
+ dAngl2
)/2.;
748 vXm
= vXc
+ dRadius
* cos(dAnglmid
);
749 vYm
= vYc
+ dRadius
* sin(dAnglmid
);
752 // Ellipse main axis (r,q), (p,s) with center at (0,0) */
758 ::GpiSetArcParams(m_hPS
, &vArcp
); // Sets parameters to default
760 vPtlPos
.x
= vX1
; // Loads x-coordinate
761 vPtlPos
.y
= vY1
; // Loads y-coordinate
762 ::GpiMove(m_hPS
, &vPtlPos
); // Sets current position
767 ::GpiPointArc(m_hPS
, vPtlArc
); // Draws the arc
768 CalcBoundingBox( (vXc
- dRadius
)
771 CalcBoundingBox( (vXc
+ dRadius
)
774 } // end of wxDC::DoDrawArc
776 void wxDC::DoDrawCheckMark(
785 vY1
= OS2Y(vY1
,vHeight
);
789 vPoint
[1].x
= vX1
+ vWidth
;
790 vPoint
[1].y
= vY1
+ vHeight
;
792 ::GpiMove(m_hPS
, &vPoint
[0]);
793 ::GpiBox( m_hPS
// handle to a presentation space
794 ,DRO_OUTLINE
// draw the box outline ? or ?
795 ,&vPoint
[1] // address of the corner
796 ,0L // horizontal corner radius
797 ,0L // vertical corner radius
799 if(vWidth
> 4 && vHeight
> 4)
803 vPoint
[0].x
+= 2; vPoint
[0].y
+= 2;
804 vPoint
[1].x
-= 2; vPoint
[1].y
-= 2;
805 ::GpiMove(m_hPS
, &vPoint
[0]);
806 ::GpiLine(m_hPS
, &vPoint
[1]);
808 vPoint
[0].x
= vPoint
[1].x
;
810 ::GpiMove(m_hPS
, &vPoint
[0]);
811 ::GpiLine(m_hPS
, &vPoint
[1]);
817 wxCoord vX2
= vX1
+ vWidth
;
818 wxCoord vY2
= vY1
+ vHeight
;
823 } // end of wxDC::DoDrawCheckMark
825 void wxDC::DoDrawPoint(
831 COLORREF vColor
= 0x00ffffff;
835 vColor
= m_pen
.GetColour().GetPixel();
837 ::GpiSetColor(m_hPS
, vColor
);
839 vPoint
.y
= OS2Y(vY
,0);
840 ::GpiSetPel(m_hPS
, &vPoint
);
844 } // end of wxDC::DoDrawPoint
846 void wxDC::DoDrawPolygon(
854 ULONG ulCount
= 1; // Number of polygons.
855 POLYGON vPlgn
; // polygon.
856 ULONG flOptions
= 0L; // Drawing options.
858 //////////////////////////////////////////////////////////////////////////////
859 // This contains fields of option bits... to draw boundary lines as well as
860 // the area interior.
862 // Drawing boundary lines:
863 // POLYGON_NOBOUNDARY Does not draw boundary lines.
864 // POLYGON_BOUNDARY Draws boundary lines (the default).
866 // Construction of the area interior:
867 // POLYGON_ALTERNATE Constructs interior in alternate mode
869 // POLYGON_WINDING Constructs interior in winding mode.
870 //////////////////////////////////////////////////////////////////////////////
872 ULONG flModel
= 0L; // Drawing model.
874 //////////////////////////////////////////////////////////////////////////////
876 // POLYGON_INCL Fill is inclusive of bottom right (the default).
877 // POLYGON_EXCL Fill is exclusive of bottom right.
878 // This is provided to aid migration from other graphics models.
879 //////////////////////////////////////////////////////////////////////////////
881 LONG lHits
= 0L; // Correlation/error indicator.
884 int nIsTRANSPARENT
= 0;
885 LONG lBorderColor
= 0L;
888 lBorderColor
= m_pen
.GetColour().GetPixel();
889 lColor
= m_brush
.GetColour().GetPixel();
890 if(m_brush
.GetStyle() == wxTRANSPARENT
)
894 vPlgn
.aPointl
= (POINTL
*) calloc( n
+ 1
896 ); // well, new will call malloc
898 for(i
= 0; i
< n
; i
++)
900 vPlgn
.aPointl
[i
].x
= vPoints
[i
].x
; // +xoffset;
901 vPlgn
.aPointl
[i
].y
= OS2Y(vPoints
[i
].y
,0); // +yoffset;
903 flModel
= POLYGON_BOUNDARY
;
904 if(nFillStyle
== wxWINDING_RULE
)
905 flModel
|= POLYGON_WINDING
;
907 flModel
|= POLYGON_ALTERNATE
;
910 vPoint
.y
= OS2Y(vYoffset
,0);
912 ::GpiSetColor(m_hPS
, lBorderColor
);
913 ::GpiMove(m_hPS
, &vPoint
);
914 lHits
= ::GpiPolygons(m_hPS
, ulCount
, &vPlgn
, flOptions
, flModel
);
916 } // end of wxDC::DoDrawPolygon
918 void wxDC::DoDrawLines(
927 if (vXoffset
!= 0L || vXoffset
!= 0L)
931 vPoint
.x
= vPoints
[0].x
+ vXoffset
;
932 vPoint
.y
= OS2Y(vPoints
[0].y
+ vYoffset
,0);
933 ::GpiMove(m_hPS
, &vPoint
);
935 LONG lBorderColor
= m_pen
.GetColour().GetPixel();
937 ::GpiSetColor(m_hPS
, lBorderColor
);
938 for(i
= 1; i
< n
; i
++)
940 vPoint
.x
= vPoints
[i
].x
+ vXoffset
;
941 vPoint
.y
= OS2Y(vPoints
[i
].y
+ vYoffset
,0);
942 ::GpiLine(m_hPS
, &vPoint
);
949 CalcBoundingBox( vPoints
[i
].x
952 vPoint
.x
= vPoints
[0].x
;
953 vPoint
.y
= OS2Y(vPoints
[0].y
,0);
954 ::GpiMove(m_hPS
, &vPoint
);
956 for (i
= 0; i
< n
; i
++)
958 CalcBoundingBox( vPoints
[i
].x
961 vPoint
.x
= vPoints
[i
].x
;
962 vPoint
.y
= OS2Y(vPoints
[i
].y
,0);
963 ::GpiLine(m_hPS
, &vPoint
);
966 } // end of wxDC::DoDrawLines
968 void wxDC::DoDrawRectangle(
979 int nIsTRANSPARENT
= 0;
982 // Might be a memory DC with no Paint rect
984 if (!(m_vRclPaint
.yTop
== 0 &&
985 m_vRclPaint
.yBottom
== 0 &&
986 m_vRclPaint
.xRight
== 0 &&
987 m_vRclPaint
.xLeft
== 0))
988 vY
= OS2Y(vY
,vHeight
);
990 wxCoord vX2
= vX
+ vWidth
;
991 wxCoord vY2
= vY
+ vHeight
;
995 vPoint
[1].x
= vX
+ vWidth
- 1;
996 vPoint
[1].y
= vY
+ vHeight
- 1;
997 ::GpiMove(m_hPS
, &vPoint
[0]);
998 lColor
= m_brush
.GetColour().GetPixel();
999 lBorderColor
= m_pen
.GetColour().GetPixel();
1000 if (m_brush
.GetStyle() == wxTRANSPARENT
)
1002 if(lColor
== lBorderColor
|| nIsTRANSPARENT
)
1004 lControl
= DRO_OUTLINEFILL
; //DRO_FILL;
1005 if(m_brush
.GetStyle() == wxTRANSPARENT
)
1006 lControl
= DRO_OUTLINE
;
1008 ::GpiSetColor(m_hPS
, lColor
);
1009 ::GpiBox( m_hPS
// handle to a presentation space
1010 ,lControl
// draw the box outline ? or ?
1011 ,&vPoint
[1] // address of the corner
1012 ,0L // horizontal corner radius
1013 ,0L // vertical corner radius
1018 lControl
= DRO_OUTLINE
;
1019 ::GpiSetColor( m_hPS
1028 lControl
= DRO_FILL
;
1029 ::GpiSetColor( m_hPS
1032 vPoint
[0].x
= vX
+ 1;
1033 vPoint
[0].y
= vY
+ 1;
1034 vPoint
[1].x
= vX
+ vWidth
- 2;
1035 vPoint
[1].y
= vY
+ vHeight
- 2;
1036 ::GpiMove(m_hPS
, &vPoint
[0]);
1044 CalcBoundingBox(vX
, vY
);
1045 CalcBoundingBox(vX2
, vY2
);
1046 } // end of wxDC::DoDrawRectangle
1048 void wxDC::DoDrawRoundedRectangle(
1059 vY
= OS2Y(vY
,vHeight
);
1061 wxCoord vX2
= (vX
+ vWidth
);
1062 wxCoord vY2
= (vY
+ vHeight
);
1065 vPoint
[0].y
= YLOG2DEV(vY
) - vHeight
;
1066 vPoint
[1].x
= vX
+ vWidth
;
1068 ::GpiMove(m_hPS
, &vPoint
[0]);
1070 lControl
= DRO_OUTLINEFILL
; //DRO_FILL;
1071 if (m_brush
.GetStyle() == wxTRANSPARENT
)
1072 lControl
= DRO_OUTLINE
;
1073 ::GpiBox( m_hPS
// handle to a presentation space
1074 ,DRO_OUTLINE
// draw the box outline ? or ?
1075 ,&vPoint
[1] // address of the corner
1076 ,(LONG
)dRadius
// horizontal corner radius
1077 ,(LONG
)dRadius
// vertical corner radius
1079 CalcBoundingBox(vX
, vY
);
1080 CalcBoundingBox(vX2
, vY2
);
1081 } // end of wxDC::DoDrawRoundedRectangle
1083 // Draw Ellipse within box (x,y) - (x+width, y+height)
1084 void wxDC::DoDrawEllipse(
1091 POINTL vPtlPos
; // Structure for current position
1092 FIXED vFxMult
; // Multiplier for ellipse
1093 ARCPARAMS vArcp
; // Structure for arc parameters
1095 vY
= OS2Y(vY
,vHeight
);
1098 vArcp
.lQ
= vHeight
/2;
1099 vArcp
.lP
= vWidth
/2;
1101 ::GpiSetArcParams( m_hPS
1103 ); // Sets parameters to default
1104 vPtlPos
.x
= vX
+ vWidth
/2; // Loads x-coordinate
1105 vPtlPos
.y
= vY
+ vHeight
/2; // Loads y-coordinate
1108 ); // Sets current position
1109 vFxMult
= MAKEFIXED(1, 0); /* Sets multiplier */
1112 // DRO_FILL, DRO_OTLINEFILL - where to get
1117 ); // Draws full arc with center at current position
1119 wxCoord vX2
= (vX
+ vWidth
);
1120 wxCoord vY2
= (vY
+ vHeight
);
1122 CalcBoundingBox(vX
, vY
);
1123 CalcBoundingBox(vX2
, vY2
);
1124 } // end of wxDC::DoDrawEllipse
1126 void wxDC::DoDrawEllipticArc(
1135 POINTL vPtlPos
; // Structure for current position
1136 FIXED vFxMult
; // Multiplier for ellipse
1137 ARCPARAMS vArcp
; // Structure for arc parameters
1139 FIXED vFSweepa
; // Start angle, sweep angle
1144 vY
= OS2Y(vY
,vHeight
);
1146 dFractPart
= modf(dSa
,&dIntPart
);
1147 vFSa
= MAKEFIXED((int)dIntPart
, (int)(dFractPart
* 0xffff) );
1148 dFractPart
= modf(dEa
- dSa
, &dIntPart
);
1149 vFSweepa
= MAKEFIXED((int)dIntPart
, (int)(dFractPart
* 0xffff) );
1152 // Ellipse main axis (r,q), (p,s) with center at (0,0)
1155 vArcp
.lQ
= vHeight
/2;
1156 vArcp
.lP
= vWidth
/2;
1158 ::GpiSetArcParams(m_hPS
, &vArcp
); // Sets parameters to default
1159 vPtlPos
.x
= vX
+ vWidth
/2 * (1. + cos(DegToRad(dSa
))); // Loads x-coordinate
1160 vPtlPos
.y
= vY
+ vHeight
/2 * (1. + sin(DegToRad(dSa
))); // Loads y-coordinate
1161 ::GpiMove(m_hPS
, &vPtlPos
); // Sets current position
1164 // May be not to the center ?
1166 vPtlPos
.x
= vX
+ vWidth
/2 ; // Loads x-coordinate
1167 vPtlPos
.y
= vY
+ vHeight
/2; // Loads y-coordinate
1168 vFxMult
= MAKEFIXED(1, 0); // Sets multiplier
1171 // DRO_FILL, DRO_OTLINEFILL - where to get
1173 ::GpiPartialArc( m_hPS
1179 wxCoord vX2
= (vX
+ vWidth
);
1180 wxCoord vY2
= (vY
+ vHeight
);
1182 CalcBoundingBox(vX
, vY
);
1183 CalcBoundingBox(vX2
, vY2
);
1184 } // end of wxDC::DoDrawEllipticArc
1186 void wxDC::DoDrawIcon(
1193 // Need to copy back into a bitmap. ::WinDrawPointer uses device coords
1194 // and I don't feel like figuring those out for scrollable windows so
1195 // just convert to a bitmap then let the DoDrawBitmap routing display it
1199 DoDrawBitmap(rIcon
.GetXpmSrc(), vX
, vY
, TRUE
);
1203 wxBitmap
vBitmap(rIcon
);
1205 DoDrawBitmap(vBitmap
, vX
, vY
, FALSE
);
1207 CalcBoundingBox(vX
, vY
);
1208 CalcBoundingBox(vX
+ rIcon
.GetWidth(), vY
+ rIcon
.GetHeight());
1209 } // end of wxDC::DoDrawIcon
1211 void wxDC::DoDrawBitmap(
1212 const wxBitmap
& rBmp
1218 if (!IsKindOf(CLASSINFO(wxPrinterDC
)))
1220 HBITMAP hBitmap
= (HBITMAP
)rBmp
.GetHBITMAP();
1223 vY
= OS2Y(vY
,rBmp
.GetHeight());
1226 // Flip the picture as OS/2 is upside-down
1228 POINTL vPoint
[4] = { vX
, vY
+ rBmp
.GetHeight()
1229 ,vX
+ rBmp
.GetWidth(), vY
1231 ,rBmp
.GetWidth(), rBmp
.GetHeight()
1235 wxMask
* pMask
= rBmp
.GetMask();
1240 // Need to imitate ::MaskBlt in windows.
1241 // 1) Extract the bits from from the bitmap.
1242 // 2) Extract the bits from the mask
1243 // 3) Using the mask bits do the following:
1244 // A) If the mask byte is 00 leave the bitmap byte alone
1245 // B) If the mask byte is FF copy the screen color into
1247 // 4) Create a new bitmap and set its bits to the above result
1248 // 5) Blit this to the screen PS
1250 HBITMAP hMask
= (HBITMAP
)pMask
->GetMaskBitmap();
1251 HBITMAP hOldBitmap
= NULLHANDLE
;
1252 HBITMAP hNewBitmap
= NULLHANDLE
;
1253 unsigned char* pucBits
; // buffer that will contain the bitmap data
1254 unsigned char* pucBitsMask
; // buffer that will contain the mask data
1255 unsigned char* pucData
; // pointer to use to traverse bitmap data
1256 unsigned char* pucDataMask
; // pointer to use to traverse mask data
1262 // The usual Memory context creation stuff
1264 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
1265 SIZEL vSize
= {0, 0};
1266 HDC hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
1267 HPS hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIA_ASSOC
);
1270 // The usual bitmap header stuff
1272 BITMAPINFOHEADER2 vHeader
;
1275 memset(&vHeader
, '\0', 16);
1277 vHeader
.cx
= (ULONG
)rBmp
.GetWidth();
1278 vHeader
.cy
= (ULONG
)rBmp
.GetHeight();
1279 vHeader
.cPlanes
= 1L;
1280 vHeader
.cBitCount
= 24;
1282 memset(&vInfo
, '\0', 16);
1284 vInfo
.cx
= (ULONG
)rBmp
.GetWidth();
1285 vInfo
.cy
= (ULONG
)rBmp
.GetHeight();
1287 vInfo
.cBitCount
= 24; // Set to desired count going in
1290 // Create the buffers for data....all wxBitmaps are 24 bit internally
1292 int nBytesPerLine
= rBmp
.GetWidth() * 3;
1293 int nSizeDWORD
= sizeof(DWORD
);
1294 int nLineBoundary
= nBytesPerLine
% nSizeDWORD
;
1302 // Need to get a background color for mask blitting
1304 if (IsKindOf(CLASSINFO(wxPaintDC
)))
1306 wxPaintDC
* pPaintDC
= wxDynamicCast(this, wxPaintDC
);
1308 lColor
= pPaintDC
->m_pCanvas
->GetBackgroundColour().GetPixel();
1310 else if (GetBrush() != wxNullBrush
)
1311 lColor
= GetBrush().GetColour().GetPixel();
1313 lColor
= m_textBackgroundColour
.GetPixel();
1316 // Bitmap must be ina double-word alligned address so we may
1317 // have some padding to worry about
1319 if (nLineBoundary
> 0)
1321 nPadding
= nSizeDWORD
- nLineBoundary
;
1322 nBytesPerLine
+= nPadding
;
1324 pucBits
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
1325 pucBitsMask
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
1326 memset(pucBits
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
1327 memset(pucBitsMask
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
1330 // Extract the bitmap and mask data
1332 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hBitmap
)) == HBM_ERROR
)
1334 vError
= ::WinGetLastError(vHabmain
);
1335 sError
= wxPMErrorToStr(vError
);
1337 if ((lScans
= ::GpiQueryBitmapBits( hPS
1339 ,(LONG
)rBmp
.GetHeight()
1344 vError
= ::WinGetLastError(vHabmain
);
1345 sError
= wxPMErrorToStr(vError
);
1347 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hMask
)) == HBM_ERROR
)
1349 vError
= ::WinGetLastError(vHabmain
);
1350 sError
= wxPMErrorToStr(vError
);
1352 if ((lScans
= ::GpiQueryBitmapBits( hPS
1354 ,(LONG
)rBmp
.GetHeight()
1359 vError
= ::WinGetLastError(vHabmain
);
1360 sError
= wxPMErrorToStr(vError
);
1364 // Now set the bytes(bits) according to the mask values
1365 // 3 bytes per pel...must handle one at a time
1368 pucDataMask
= pucBitsMask
;
1370 for (i
= 0; i
< rBmp
.GetHeight(); i
++)
1372 for (j
= 0; j
< rBmp
.GetWidth(); j
++)
1375 if (*pucDataMask
== 0xFF) // leave bitmap byte alone
1379 *pucData
= ((unsigned char)(lColor
>> 16));
1383 if (*(pucDataMask
+ 1) == 0xFF) // leave bitmap byte alone
1387 *pucData
= ((unsigned char)(lColor
>> 8));
1392 if (*(pucDataMask
+ 2) == 0xFF) // leave bitmap byte alone
1396 *pucData
= ((unsigned char)lColor
);
1401 for (j
= 0; j
< nPadding
; j
++)
1408 // Create a new bitmap
1410 if ((hNewBitmap
= ::GpiCreateBitmap( hPS
1417 vError
= ::WinGetLastError(vHabmain
);
1418 sError
= wxPMErrorToStr(vError
);
1422 // Now blit it to the screen PS
1424 if ((lHits
= ::GpiWCBitBlt( (HPS
)GetHPS()
1432 vError
= ::WinGetLastError(vHabmain
);
1433 sError
= wxPMErrorToStr(vError
);
1441 ::GpiSetBitmap(hPS
, NULLHANDLE
);
1442 ::GpiDestroyPS(hPS
);
1448 LONG lOldForeGround
= ::GpiQueryColor((HPS
)GetHPS());
1449 LONG lOldBackGround
= ::GpiQueryBackColor((HPS
)GetHPS());
1451 if (m_textForegroundColour
.Ok())
1453 ::GpiSetColor( (HPS
)GetHPS()
1454 ,m_textForegroundColour
.GetPixel()
1457 if (m_textBackgroundColour
.Ok())
1459 ::GpiSetBackColor( (HPS
)GetHPS()
1460 ,m_textBackgroundColour
.GetPixel()
1464 // Need to alter bits in a mono bitmap to match the new
1465 // background-foreground if it is different.
1467 if (rBmp
.IsMono() &&
1468 ((m_textForegroundColour
.GetPixel() != lOldForeGround
) ||
1469 (m_textBackgroundColour
.GetPixel() != lOldBackGround
)))
1471 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
1472 SIZEL vSize
= {0, 0};
1473 HDC hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
1474 HPS hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIA_ASSOC
);
1476 int nBytesPerLine
= rBmp
.GetWidth() * 3;
1478 LONG lForeGround
= m_textForegroundColour
.GetPixel();
1479 LONG lBackGround
= m_textBackgroundColour
.GetPixel();
1481 HBITMAP hOldBitmap
= NULLHANDLE
;
1487 memset(&vInfo
, '\0', 16);
1489 vInfo
.cx
= (ULONG
)rBmp
.GetWidth();
1490 vInfo
.cy
= (ULONG
)rBmp
.GetHeight();
1492 vInfo
.cBitCount
= 24;
1494 unsigned char* pucBits
; // buffer that will contain the bitmap data
1495 unsigned char* pucData
; // pointer to use to traverse bitmap data
1497 pucBits
= new unsigned char[nBytesPerLine
* rBmp
.GetHeight()];
1498 memset(pucBits
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
1500 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hBitmap
)) == HBM_ERROR
)
1502 vError
= ::WinGetLastError(vHabmain
);
1503 sError
= wxPMErrorToStr(vError
);
1506 if ((lScans
= ::GpiQueryBitmapBits( hPS
1508 ,(LONG
)rBmp
.GetHeight()
1513 vError
= ::WinGetLastError(vHabmain
);
1514 sError
= wxPMErrorToStr(vError
);
1517 unsigned char cOldRedFore
= (unsigned char)(lOldForeGround
>> 16);
1518 unsigned char cOldGreenFore
= (unsigned char)(lOldForeGround
>> 8);
1519 unsigned char cOldBlueFore
= (unsigned char)lOldForeGround
;
1521 unsigned char cOldRedBack
= (unsigned char)(lOldBackGround
>> 16);
1522 unsigned char cOldGreenBack
= (unsigned char)(lOldBackGround
>> 8);
1523 unsigned char cOldBlueBack
= (unsigned char)lOldBackGround
;
1525 unsigned char cRedFore
= (unsigned char)(lForeGround
>> 16);
1526 unsigned char cGreenFore
= (unsigned char)(lForeGround
>> 8);
1527 unsigned char cBlueFore
= (unsigned char)lForeGround
;
1529 unsigned char cRedBack
= (unsigned char)(lBackGround
>> 16);
1530 unsigned char cGreenBack
= (unsigned char)(lBackGround
>> 8);
1531 unsigned char cBlueBack
= (unsigned char)lBackGround
;
1534 for (i
= 0; i
< rBmp
.GetHeight(); i
++)
1536 for (j
= 0; j
< rBmp
.GetWidth(); j
++)
1538 unsigned char cBmpRed
= *pucData
;
1539 unsigned char cBmpGreen
= *(pucData
+ 1);
1540 unsigned char cBmpBlue
= *(pucData
+ 2);
1542 if ((cBmpRed
== cOldRedFore
) &&
1543 (cBmpGreen
== cOldGreenFore
) &&
1544 (cBmpBlue
== cOldBlueFore
))
1546 *pucData
= cBlueFore
;
1548 *pucData
= cGreenFore
;
1550 *pucData
= cRedFore
;
1555 *pucData
= cBlueBack
;
1557 *pucData
= cGreenBack
;
1559 *pucData
= cRedBack
;
1564 if ((lScans
= ::GpiSetBitmapBits( hPS
1566 ,(LONG
)rBmp
.GetHeight()
1571 vError
= ::WinGetLastError(vHabmain
);
1572 sError
= wxPMErrorToStr(vError
);
1576 ::GpiSetBitmap(hPS
, NULLHANDLE
);
1577 ::GpiDestroyPS(hPS
);
1580 ::GpiWCBitBlt( (HPS
)GetHPS()
1587 ::GpiSetBitmap((HPS
)GetHPS(), hBitmapOld
);
1588 ::GpiSetColor((HPS
)GetHPS(), lOldForeGround
);
1589 ::GpiSetBackColor((HPS
)GetHPS(), lOldBackGround
);
1592 } // end of wxDC::DoDrawBitmap
1594 void wxDC::DoDrawText(
1595 const wxString
& rsText
1608 CalcBoundingBox(vX
, vY
);
1609 GetTextExtent(rsText
, &vWidth
, &vHeight
);
1610 CalcBoundingBox((vX
+ vWidth
), (vY
+ vHeight
));
1611 } // end of wxDC::DoDrawText
1613 void wxDC::DrawAnyText(
1614 const wxString
& rsText
1619 int nOldBackground
= 0;
1626 // prepare for drawing the text
1630 // Set text color attributes
1632 if (m_textForegroundColour
.Ok())
1635 ,(int)m_textForegroundColour
.GetPixel()
1639 if (m_textBackgroundColour
.Ok())
1641 nOldBackground
= SetTextBkColor( m_hPS
1642 ,(int)m_textBackgroundColour
.GetPixel()
1648 GetTextExtent( rsText
1653 vPtlStart
.y
= OS2Y(vY
,vTextY
);
1655 lHits
= ::GpiCharStringAt( m_hPS
1658 ,(PCH
)rsText
.c_str()
1660 if (lHits
!= GPI_OK
)
1662 wxLogLastError(wxT("TextOut"));
1666 // Restore the old parameters (text foreground colour may be left because
1667 // it never is set to anything else, but background should remain
1668 // transparent even if we just drew an opaque string)
1670 if (m_textBackgroundColour
.Ok())
1671 SetTextBkColor( m_hPS
1679 void wxDC::DoDrawRotatedText(
1680 const wxString
& rsText
1698 DoDrawText(text, x, y);
1703 wxFillLogFont(&lf, &m_font);
1705 // GDI wants the angle in tenth of degree
1706 long angle10 = (long)(angle * 10);
1707 lf.lfEscapement = angle10;
1708 lf. lfOrientation = angle10;
1710 HFONT hfont = ::CreateFontIndirect(&lf);
1713 wxLogLastError("CreateFont");
1717 HFONT hfontOld = ::SelectObject(GetHdc(), hfont);
1719 DrawAnyText(text, x, y);
1721 (void)::SelectObject(GetHdc(), hfontOld);
1724 // call the bounding box by adding all four vertices of the rectangle
1725 // containing the text to it (simpler and probably not slower than
1726 // determining which of them is really topmost/leftmost/...)
1728 GetTextExtent(text, &w, &h);
1730 double rad = DegToRad(angle);
1732 // "upper left" and "upper right"
1733 CalcBoundingBox(x, y);
1734 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
1735 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1737 // "bottom left" and "bottom right"
1738 x += (wxCoord)(h*sin(rad));
1739 y += (wxCoord)(h*cos(rad));
1740 CalcBoundingBox(x, y);
1741 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1746 // ---------------------------------------------------------------------------
1748 // ---------------------------------------------------------------------------
1750 void wxDC::DoSelectPalette(
1755 // Set the old object temporarily, in case the assignment deletes an object
1756 // that's not yet selected out.
1767 hOldPal
= ::GpiSelectPalette((HDC
) m_hPS
, (HPALETTE
) m_palette
.GetHPALETTE());
1769 m_hOldPalette
= (WXHPALETTE
)hOldPal
;
1771 } // end of wxDC::DoSelectPalette
1773 void wxDC::InitializePalette()
1775 if (wxDisplayDepth() <= 8 )
1778 // Look for any window or parent that has a custom palette. If any has
1779 // one then we need to use it in drawing operations
1781 wxWindow
* pWin
= m_pCanvas
->GetAncestorWithCustomPalette();
1783 m_hasCustomPalette
= pWin
&& pWin
->HasCustomPalette();
1784 if (m_hasCustomPalette
)
1786 m_palette
= pWin
->GetPalette();
1789 // turn on PM translation for this palette
1794 } // end of wxDC::InitializePalette
1796 void wxDC::SetPalette(
1797 const wxPalette
& rPalette
1804 m_palette
= rPalette
;
1812 HPALETTE hOldPal
= ::GpiSelectPalette((HDC
) m_hPS
, (HPALETTE
) m_palette
.GetHPALETTE());
1814 m_hOldPalette
= (WXHPALETTE
)hOldPal
;
1815 } // end of wxDC::SetPalette
1822 // Set the old object temporarily, in case the assignment deletes an object
1823 // that's not yet selected out.
1835 m_font
.SetPS(m_hPS
); // this will realize the font
1839 HFONT hFont
= m_font
.GetResourceHandle();
1840 if (hFont
== (HFONT
) NULL
)
1842 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1845 m_hOldFont
= (WXHFONT
) hFont
;
1847 } // end of wxDC::SetFont
1853 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1869 m_pen
.SetPS((HPS
)m_hOldPen
);
1876 if (m_pen
.GetResourceHandle())
1880 m_hOldPen
= m_pen
.GetPS();
1882 ::GpiSetColor(m_hPS
, m_pen
.GetColour().GetPixel());
1886 void wxDC::SetBrush(
1887 const wxBrush
& rBrush
1890 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1896 if (m_brush
== rBrush
)
1906 m_brush
.SetPS((HPS
)m_hOldBrush
);
1913 if (m_brush
.GetResourceHandle())
1915 m_brush
.SetPS(m_hPS
);
1917 m_hOldBrush
= (WXHWND
)m_brush
.GetPS();
1920 } // end of wxDC::SetBrush
1922 void wxDC::SetBackground(
1923 const wxBrush
& rBrush
1926 m_backgroundBrush
= rBrush
;
1927 if (!m_backgroundBrush
.Ok())
1931 bool bCustomColours
= TRUE
;
1934 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
1935 // change background colours from the control-panel specified colours.
1937 if (m_pCanvas
->IsKindOf(CLASSINFO(wxWindow
)) &&
1938 ((m_pCanvas
->GetWindowStyleFlag() & wxUSER_COLOURS
) != wxUSER_COLOURS
))
1939 bCustomColours
= FALSE
;
1942 if (m_backgroundBrush
.GetStyle()==wxTRANSPARENT
)
1944 m_pCanvas
->SetTransparent(TRUE
);
1949 // Setting the background brush of a DC
1950 // doesn't affect the window background colour. However,
1951 // I'm leaving in the transparency setting because it's needed by
1952 // various controls (e.g. wxStaticText) to determine whether to draw
1953 // transparently or not. TODO: maybe this should be a new function
1954 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
1956 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
1958 m_pCanvas
->SetTransparent(FALSE
);
1962 COLORREF vNewColor
= m_backgroundBrush
.GetColour().GetPixel();
1963 (void)::GpiSetBackColor((HPS
)m_hPS
, (LONG
)vNewColor
);
1964 } // end of wxDC::SetBackground
1966 void wxDC::SetBackgroundMode(
1970 m_backgroundMode
= nMode
;
1971 } // end of wxDC::SetBackgroundMode
1973 void wxDC::SetLogicalFunction(
1977 m_logicalFunction
= nFunction
;
1978 SetRop((WXHDC
)m_hDC
);
1979 } // wxDC::SetLogicalFunction
1985 if (!hDC
|| m_logicalFunction
< 0)
1989 switch (m_logicalFunction
)
2000 lCRop
= FM_MERGESRCNOT
;
2004 lCRop
= FM_NOTMASKSRC
;
2016 lCRop
= FM_MERGENOTSRC
;
2020 lCRop
= FM_MERGESRCNOT
;
2032 lCRop
= FM_SUBTRACT
;
2039 lCRop
= FM_OVERPAINT
;
2042 ::GpiSetMix((HPS
)hDC
, lCRop
);
2043 } // end of wxDC::SetRop
2045 bool wxDC::StartDoc(
2046 const wxString
& rsMessage
2049 // We might be previewing, so return TRUE to let it continue.
2051 } // end of wxDC::StartDoc
2055 } // end of wxDC::EndDoc
2057 void wxDC::StartPage()
2059 } // end of wxDC::StartPage
2061 void wxDC::EndPage()
2063 } // end of wxDC::EndPage
2065 // ---------------------------------------------------------------------------
2067 // ---------------------------------------------------------------------------
2069 wxCoord
wxDC::GetCharHeight() const
2071 FONTMETRICS vFM
; // metrics structure
2073 ::GpiQueryFontMetrics( m_hPS
2074 ,sizeof(FONTMETRICS
)
2077 return YDEV2LOGREL(vFM
.lXHeight
);
2080 wxCoord
wxDC::GetCharWidth() const
2082 FONTMETRICS vFM
; // metrics structure
2084 ::GpiQueryFontMetrics( m_hPS
2085 ,sizeof(FONTMETRICS
)
2088 return XDEV2LOGREL(vFM
.lAveCharWidth
);
2091 void wxDC::DoGetTextExtent(
2092 const wxString
& rsString
2095 , wxCoord
* pvDescent
2096 , wxCoord
* pvExternalLeading
2100 POINTL avPoint
[TXTBOX_COUNT
];
2105 FONTMETRICS vFM
; // metrics structure
2108 ERRORID vErrorCode
; // last error id code
2109 wxFont
* pFontToUse
= (wxFont
*)pTheFont
;
2111 char zMsg
[128]; // DEBUG
2115 pFontToUse
= (wxFont
*)&m_font
;
2116 l
= rsString
.length();
2117 pStr
= (PCH
) rsString
.c_str();
2120 // In world coordinates.
2122 bRc
= ::GpiQueryTextBox( m_hPS
2125 ,TXTBOX_COUNT
// return maximum information
2126 ,avPoint
// array of coordinates points
2130 vErrorCode
= ::WinGetLastError(wxGetInstance());
2131 sError
= wxPMErrorToStr(vErrorCode
);
2133 sprintf(zMsg
, "GpiQueryTextBox for %s: failed with Error: %x - %s", pStr
, vErrorCode
, sError
.c_str());
2134 (void)wxMessageBox( "wxWindows Menu sample"
2140 vPtMin
.x
= avPoint
[0].x
;
2141 vPtMax
.x
= avPoint
[0].x
;
2142 vPtMin
.y
= avPoint
[0].y
;
2143 vPtMax
.y
= avPoint
[0].y
;
2144 for (i
= 1; i
< 4; i
++)
2146 if(vPtMin
.x
> avPoint
[i
].x
) vPtMin
.x
= avPoint
[i
].x
;
2147 if(vPtMin
.y
> avPoint
[i
].y
) vPtMin
.y
= avPoint
[i
].y
;
2148 if(vPtMax
.x
< avPoint
[i
].x
) vPtMax
.x
= avPoint
[i
].x
;
2149 if(vPtMax
.y
< avPoint
[i
].y
) vPtMax
.y
= avPoint
[i
].y
;
2151 ::GpiQueryFontMetrics( m_hPS
2152 ,sizeof(FONTMETRICS
)
2157 *pvX
= (wxCoord
)(vPtMax
.x
- vPtMin
.x
+ 1);
2159 *pvY
= (wxCoord
)(vPtMax
.y
- vPtMin
.y
+ 1);
2161 *pvDescent
= vFM
.lMaxDescender
;
2162 if (pvExternalLeading
)
2163 *pvExternalLeading
= vFM
.lExternalLeading
;
2166 void wxDC::SetMapMode(
2170 int nPixelWidth
= 0;
2171 int nPixelHeight
= 0;
2174 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2176 m_mappingMode
= nMode
;
2178 if(::DevQueryCaps( m_hDC
2180 ,CAPS_VERTICAL_RESOLUTION
2187 nPixelWidth
= lArray
[CAPS_WIDTH
];
2188 nPixelHeight
= lArray
[CAPS_HEIGHT
];
2189 lHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2190 lVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2191 nMmWidth
= (lHorzRes
/1000) * nPixelWidth
;
2192 nMmWidth
= (lVertRes
/1000) * nPixelHeight
;
2194 if ((nPixelWidth
== 0) || (nPixelHeight
== 0) || (nMmWidth
== 0) || (nMmHeight
== 0))
2199 double dMm2pixelsX
= nPixelWidth
/nMmWidth
;
2200 double dMm2pixelsY
= nPixelHeight
/nMmHeight
;
2205 m_logicalScaleX
= (twips2mm
* dMm2pixelsX
);
2206 m_logicalScaleY
= (twips2mm
* dMm2pixelsY
);
2210 m_logicalScaleX
= (pt2mm
* dMm2pixelsX
);
2211 m_logicalScaleY
= (pt2mm
* dMm2pixelsY
);
2215 m_logicalScaleX
= dMm2pixelsX
;
2216 m_logicalScaleY
= dMm2pixelsY
;
2220 m_logicalScaleX
= (dMm2pixelsX
/10.0);
2221 m_logicalScaleY
= (dMm2pixelsY
/10.0);
2226 m_logicalScaleX
= 1.0;
2227 m_logicalScaleY
= 1.0;
2233 ulOptions
= ::GpiQueryPS(m_hPS
, &vSize
);
2234 if (!ulOptions
& PU_ARBITRARY
)
2236 ulOptions
= PU_ARBITRARY
| GPIF_DEFAULT
;
2237 ::GpiSetPS(m_hPS
, &vSize
, ulOptions
);
2239 m_nWindowExtX
= (int)MS_XDEV2LOG(VIEWPORT_EXTENT
);
2240 m_nWindowExtY
= (int)MS_YDEV2LOG(VIEWPORT_EXTENT
);
2242 }; // end of wxDC::SetMapMode
2244 void wxDC::SetUserScale(
2252 SetMapMode(m_mappingMode
);
2253 } // end of wxDC::SetUserScale
2255 void wxDC::SetAxisOrientation(
2260 m_signX
= bXLeftRight
? 1 : -1;
2261 m_signY
= bYBottomUp
? -1 : 1;
2263 SetMapMode(m_mappingMode
);
2264 } // end of wxDC::SetAxisOrientation
2266 void wxDC::SetSystemScale(
2274 SetMapMode(m_mappingMode
);
2275 } // end of wxDC::SetSystemScale
2277 void wxDC::SetLogicalOrigin(
2284 ::GpiQueryPageViewport( m_hPS
2291 ::GpiSetPageViewport( m_hPS
2294 }; // end of wxDC::SetLogicalOrigin
2296 void wxDC::SetDeviceOrigin(
2303 m_deviceOriginX
= vX
;
2304 m_deviceOriginY
= vY
;
2305 ::GpiQueryPageViewport( m_hPS
2310 vRect
.yBottom
-= vY
;
2312 ::GpiSetPageViewport( m_hPS
2315 }; // end of wxDC::SetDeviceOrigin
2317 // ---------------------------------------------------------------------------
2318 // coordinates transformations
2319 // ---------------------------------------------------------------------------
2321 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2323 return (wxCoord
) (((x
) - m_deviceOriginX
)/(m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
) - m_logicalOriginX
);
2326 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2328 // axis orientation is not taken into account for conversion of a distance
2329 return (wxCoord
) ((x
)/(m_logicalScaleX
*m_userScaleX
*m_scaleX
));
2332 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2334 return (wxCoord
) (((y
) - m_deviceOriginY
)/(m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
) - m_logicalOriginY
);
2337 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2339 // axis orientation is not taken into account for conversion of a distance
2340 return (wxCoord
) ((y
)/(m_logicalScaleY
*m_userScaleY
*m_scaleY
));
2343 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2345 return (wxCoord
) ((x
- m_logicalOriginX
)*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
+ m_deviceOriginX
);
2348 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2350 // axis orientation is not taken into account for conversion of a distance
2351 return (wxCoord
) (x
*m_logicalScaleX
*m_userScaleX
*m_scaleX
);
2354 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2356 return (wxCoord
) ((y
- m_logicalOriginY
)*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
+ m_deviceOriginY
);
2359 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2361 // axis orientation is not taken into account for conversion of a distance
2362 return (wxCoord
) (y
*m_logicalScaleY
*m_userScaleY
*m_scaleY
);
2365 // ---------------------------------------------------------------------------
2367 // ---------------------------------------------------------------------------
2383 wxMask
* pMask
= NULL
;
2385 COLORREF vOldTextColor
;
2386 COLORREF vOldBackground
= ::GpiQueryBackColor(m_hPS
);
2390 const wxBitmap
& rBmp
= pSource
->m_vSelectedBitmap
;
2392 pMask
= rBmp
.GetMask();
2393 if (!(rBmp
.Ok() && pMask
&& pMask
->GetMaskBitmap()))
2399 ::GpiQueryAttrs( m_hPS
2404 vOldTextColor
= (COLORREF
)vCbnd
.lColor
;
2406 if (m_textForegroundColour
.Ok())
2408 vCbnd
.lColor
= (LONG
)m_textForegroundColour
.GetPixel();
2409 ::GpiSetAttrs( m_hPS
// presentation-space handle
2410 ,PRIM_CHAR
// Char primitive.
2411 ,CBB_COLOR
// sets color.
2413 ,&vCbnd
// buffer for attributes.
2416 if (m_textBackgroundColour
.Ok())
2418 ::GpiSetBackColor(m_hPS
, (LONG
)m_textBackgroundColour
.GetPixel());
2421 LONG lRop
= ROP_SRCCOPY
;
2425 case wxXOR
: lRop
= ROP_SRCINVERT
; break;
2426 case wxINVERT
: lRop
= ROP_DSTINVERT
; break;
2427 case wxOR_REVERSE
: lRop
= 0x00DD0228; break;
2428 case wxAND_REVERSE
: lRop
= ROP_SRCERASE
; break;
2429 case wxCLEAR
: lRop
= ROP_ZERO
; break;
2430 case wxSET
: lRop
= ROP_ONE
; break;
2431 case wxOR_INVERT
: lRop
= ROP_MERGEPAINT
; break;
2432 case wxAND
: lRop
= ROP_SRCAND
; break;
2433 case wxOR
: lRop
= ROP_SRCPAINT
; break;
2434 case wxEQUIV
: lRop
= 0x00990066; break;
2435 case wxNAND
: lRop
= 0x007700E6; break;
2436 case wxAND_INVERT
: lRop
= 0x00220326; break;
2437 case wxCOPY
: lRop
= ROP_SRCCOPY
; break;
2438 case wxNO_OP
: lRop
= ROP_NOTSRCERASE
; break;
2439 case wxSRC_INVERT
: lRop
= ROP_SRCINVERT
; break;
2440 case wxNOR
: lRop
= ROP_NOTSRCCOPY
; break;
2442 wxFAIL_MSG( wxT("unsupported logical function") );
2451 // Blit bitmap with mask
2455 // Create a temp buffer bitmap and DCs/PSs to access it and the mask
2461 DEVOPENSTRUC vDOP
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
2462 BITMAPINFOHEADER2 vBmpHdr
;
2464 SIZEL vSize
= {0, 0};
2467 memset(&vBmpHdr
, 0, sizeof(BITMAPINFOHEADER2
));
2468 vBmpHdr
.cbFix
= sizeof(BITMAPINFOHEADER2
);
2469 vBmpHdr
.cx
= vWidth
;
2470 vBmpHdr
.cy
= vHeight
;
2471 vBmpHdr
.cPlanes
= 1;
2472 vBmpHdr
.cBitCount
= 24;
2474 #if wxUSE_DC_CACHEING
2478 // create a temp buffer bitmap and DCs to access it and the mask
2480 wxDCCacheEntry
* pDCCacheEntry1
= FindDCInCache( NULL
2483 wxDCCacheEntry
* pDCCacheEntry2
= FindDCInCache( pDCCacheEntry1
2486 wxDCCacheEntry
* pBitmapCacheEntry
= FindBitmapInCache( GetHPS()
2491 hPSMask
= pDCCacheEntry1
->m_hPS
;
2492 hDCBuffer
= (HDC
)pDCCacheEntry2
->m_hPS
;
2493 hBufBitmap
= (HBITMAP
)pBitmapCacheEntry
->m_hBitmap
;
2498 hDCMask
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
2499 hDCBuffer
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
2500 hPSMask
= ::GpiCreatePS(vHabmain
, hDCMask
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
2501 hPSBuffer
= ::GpiCreatePS(vHabmain
, hDCBuffer
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
2502 hBufBitmap
= ::GpiCreateBitmap(GetHPS(), &vBmpHdr
, 0L, NULL
, NULL
);
2505 POINTL aPoint1
[4] = { 0, 0
2508 ,vXdest
+ vWidth
, vYdest
+ vHeight
2510 POINTL aPoint2
[4] = { 0, 0
2513 ,vXsrc
+ vWidth
, vYsrc
+ vHeight
2515 POINTL aPoint3
[4] = { vXdest
, vYdest
2516 ,vXdest
+ vWidth
, vYdest
+ vHeight
2518 ,vXsrc
+ vWidth
, vYsrc
+ vHeight
2520 POINTL aPoint4
[4] = { vXdest
, vYdest
2521 ,vXdest
+ vWidth
, vYdest
+ vHeight
2525 ::GpiSetBitmap(hPSMask
, (HBITMAP
) pMask
->GetMaskBitmap());
2526 ::GpiSetBitmap(hPSBuffer
, (HBITMAP
) hBufBitmap
);
2529 // Copy dest to buffer
2531 rc
= ::GpiBitBlt( hPSBuffer
2538 if (rc
== GPI_ERROR
)
2540 wxLogLastError(wxT("BitBlt"));
2544 // Copy src to buffer using selected raster op
2546 rc
= ::GpiBitBlt( hPSBuffer
2553 if (rc
== GPI_ERROR
)
2555 wxLogLastError(wxT("BitBlt"));
2559 // Set masked area in buffer to BLACK (pixel value 0)
2561 COLORREF vPrevBkCol
= ::GpiQueryBackColor(GetHPS());
2562 COLORREF vPrevCol
= ::GpiQueryColor(GetHPS());
2564 ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255));
2565 ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0));
2567 rc
= ::GpiBitBlt( hPSBuffer
2574 if (rc
== GPI_ERROR
)
2576 wxLogLastError(wxT("BitBlt"));
2580 // Set unmasked area in dest to BLACK
2582 ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0));
2583 ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255));
2584 rc
= ::GpiBitBlt( GetHPS()
2591 if (rc
== GPI_ERROR
)
2593 wxLogLastError(wxT("BitBlt"));
2597 // Restore colours to original values
2599 ::GpiSetBackColor(GetHPS(), vPrevBkCol
);
2600 ::GpiSetColor(GetHPS(), vPrevCol
);
2603 // OR buffer to dest
2605 rc
= ::GpiBitBlt( GetHPS()
2612 if (rc
== GPI_ERROR
)
2615 wxLogLastError(wxT("BitBlt"));
2619 // Tidy up temporary DCs and bitmap
2621 ::GpiSetBitmap(hPSMask
, NULLHANDLE
);
2622 ::GpiSetBitmap(hPSBuffer
, NULLHANDLE
);
2623 #if !wxUSE_DC_CACHEING
2624 ::GpiDestroyPS(hPSMask
);
2625 ::GpiDestroyPS(hPSBuffer
);
2626 ::DevCloseDC(hDCMask
);
2627 ::DevCloseDC(hDCBuffer
);
2628 ::GpiDeleteBitmap(hBufBitmap
);
2632 else // no mask, just BitBlt() it
2634 POINTL aPoint
[4] = { vXdest
, vYdest
2635 ,vXdest
+ vWidth
, vYdest
+ vHeight
2637 ,vXsrc
+ vWidth
, vYsrc
+ vHeight
2640 bSuccess
= (::GpiBitBlt( m_hPS
2649 wxLogLastError(wxT("BitBlt"));
2652 vCbnd
.lColor
= (LONG
)vOldTextColor
;
2653 ::GpiSetAttrs( m_hPS
// presentation-space handle
2654 ,PRIM_CHAR
// Char primitive.
2655 ,CBB_COLOR
// sets color.
2657 ,&vCbnd
// buffer for attributes.
2659 ::GpiSetBackColor(m_hPS
, (LONG
)vOldBackground
);
2663 void wxDC::DoGetSize(
2668 LONG lArray
[CAPS_HEIGHT
];
2670 if(::DevQueryCaps( m_hDC
2676 *pnWidth
= lArray
[CAPS_WIDTH
];
2677 *pnHeight
= lArray
[CAPS_HEIGHT
];
2679 }; // end of wxDC::DoGetSize(
2681 void wxDC::DoGetSizeMM(
2686 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2688 if(::DevQueryCaps( m_hDC
2690 ,CAPS_VERTICAL_RESOLUTION
2699 nWidth
= lArray
[CAPS_WIDTH
];
2700 nHeight
= lArray
[CAPS_HEIGHT
];
2701 nHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2702 nVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2703 nWidth
= (nHorzRes
/1000) * nWidth
;
2704 nHeight
= (nVertRes
/1000) * nHeight
;
2706 }; // end of wxDC::DoGetSizeMM
2708 wxSize
wxDC::GetPPI() const
2710 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2714 if(::DevQueryCaps( m_hDC
2716 ,CAPS_VERTICAL_RESOLUTION
2725 nPelWidth
= lArray
[CAPS_WIDTH
];
2726 nPelHeight
= lArray
[CAPS_HEIGHT
];
2727 nHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2728 nVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2729 nWidth
= (nHorzRes
/39.3) * nPelWidth
;
2730 nHeight
= (nVertRes
/39.3) * nPelHeight
;
2732 return (wxSize(nWidth
,nHeight
));
2733 } // end of wxDC::GetPPI
2735 void wxDC::SetLogicalScale(
2740 m_logicalScaleX
= dX
;
2741 m_logicalScaleY
= dY
;
2742 }; // end of wxDC::SetLogicalScale
2744 #if WXWIN_COMPATIBILITY
2745 void wxDC::DoGetTextExtent(const wxString
& string
, float *x
, float *y
,
2746 float *descent
, float *externalLeading
,
2747 wxFont
*theFont
, bool use16bit
) const
2749 wxCoord x1
, y1
, descent1
, externalLeading1
;
2750 GetTextExtent(string
, & x1
, & y1
, & descent1
, & externalLeading1
, theFont
, use16bit
);
2753 *descent
= descent1
;
2754 if (externalLeading
)
2755 *externalLeading
= externalLeading1
;