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(
662 COLORREF vColor
= 0x00ffffff;
665 // Might be a memory DC with no Paint rect.
667 if (!(m_vRclPaint
.yTop
== 0 &&
668 m_vRclPaint
.yBottom
== 0 &&
669 m_vRclPaint
.xRight
== 0 &&
670 m_vRclPaint
.xLeft
== 0))
681 vColor
= m_pen
.GetColour().GetPixel();
683 ::GpiSetColor(m_hPS
, vColor
);
684 ::GpiMove(m_hPS
, &vPoint
[0]);
685 ::GpiLine(m_hPS
, &vPoint
[1]);
686 CalcBoundingBox(vX1
, vY1
);
687 CalcBoundingBox(vX2
, vY2
);
688 } // end of wxDC::DoDrawLine
690 //////////////////////////////////////////////////////////////////////////////
691 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
692 // and ending at (x2, y2). The current pen is used for the outline and the
693 // current brush for filling the shape. The arc is drawn in an anticlockwise
694 // direction from the start point to the end point.
695 //////////////////////////////////////////////////////////////////////////////
696 void wxDC
::DoDrawArc(
706 POINTL vPtlArc
[2]; // Structure for current position
715 ARCPARAMS vArcp
; // Structure for arc parameters
717 if((vX1
== vXc
&& vY1
== vXc
) || (vX2
== vXc
&& vY2
== vXc
))
718 return; // Draw point ??
719 dRadius
= 0.5 * ( hypot( (double)(vY1
- vYc
)
722 hypot( (double)(vY2
- vYc
)
727 dAngl1
= atan2( (double)(vY1
- vYc
)
730 dAngl2
= atan2( (double)(vY2
- vYc
)
737 // GpiPointArc can't draw full arc
739 if(dAngl2
== dAngl1
|| (vX1
== vX2
&& vY1
== vY2
) )
744 dAnglmid
= (dAngl1
+ dAngl2
)/2. + M_PI
;
745 vXm
= vXc
+ dRadius
* cos(dAnglmid
);
746 vYm
= vYc
+ dRadius
* sin(dAnglmid
);
761 dAnglmid
= (dAngl1
+ dAngl2
)/2.;
762 vXm
= vXc
+ dRadius
* cos(dAnglmid
);
763 vYm
= vYc
+ dRadius
* sin(dAnglmid
);
766 // Ellipse main axis (r,q), (p,s) with center at (0,0) */
772 ::GpiSetArcParams(m_hPS
, &vArcp
); // Sets parameters to default
774 vPtlPos
.x
= vX1
; // Loads x-coordinate
775 vPtlPos
.y
= vY1
; // Loads y-coordinate
776 ::GpiMove(m_hPS
, &vPtlPos
); // Sets current position
781 ::GpiPointArc(m_hPS
, vPtlArc
); // Draws the arc
782 CalcBoundingBox( (vXc
- dRadius
)
785 CalcBoundingBox( (vXc
+ dRadius
)
788 } // end of wxDC::DoDrawArc
790 void wxDC
::DoDrawCheckMark(
799 vY1
= OS2Y(vY1
,vHeight
);
803 vPoint
[1].x
= vX1
+ vWidth
;
804 vPoint
[1].y
= vY1
+ vHeight
;
806 ::GpiMove(m_hPS
, &vPoint
[0]);
807 ::GpiBox( m_hPS
// handle to a presentation space
808 ,DRO_OUTLINE
// draw the box outline ? or ?
809 ,&vPoint
[1] // address of the corner
810 ,0L // horizontal corner radius
811 ,0L // vertical corner radius
813 if(vWidth
> 4 && vHeight
> 4)
817 vPoint
[0].x
+= 2; vPoint
[0].y
+= 2;
818 vPoint
[1].x
-= 2; vPoint
[1].y
-= 2;
819 ::GpiMove(m_hPS
, &vPoint
[0]);
820 ::GpiLine(m_hPS
, &vPoint
[1]);
822 vPoint
[0].x
= vPoint
[1].x
;
824 ::GpiMove(m_hPS
, &vPoint
[0]);
825 ::GpiLine(m_hPS
, &vPoint
[1]);
831 wxCoord vX2
= vX1
+ vWidth
;
832 wxCoord vY2
= vY1
+ vHeight
;
837 } // end of wxDC::DoDrawCheckMark
839 void wxDC
::DoDrawPoint(
845 COLORREF vColor
= 0x00ffffff;
849 vColor
= m_pen
.GetColour().GetPixel();
851 ::GpiSetColor(m_hPS
, vColor
);
853 vPoint
.y
= OS2Y(vY
,0);
854 ::GpiSetPel(m_hPS
, &vPoint
);
858 } // end of wxDC::DoDrawPoint
860 void wxDC
::DoDrawPolygon(
868 ULONG ulCount
= 1; // Number of polygons.
869 POLYGON vPlgn
; // polygon.
870 ULONG flOptions
= 0L; // Drawing options.
872 //////////////////////////////////////////////////////////////////////////////
873 // This contains fields of option bits... to draw boundary lines as well as
874 // the area interior.
876 // Drawing boundary lines:
877 // POLYGON_NOBOUNDARY Does not draw boundary lines.
878 // POLYGON_BOUNDARY Draws boundary lines (the default).
880 // Construction of the area interior:
881 // POLYGON_ALTERNATE Constructs interior in alternate mode
883 // POLYGON_WINDING Constructs interior in winding mode.
884 //////////////////////////////////////////////////////////////////////////////
886 ULONG flModel
= 0L; // Drawing model.
888 //////////////////////////////////////////////////////////////////////////////
890 // POLYGON_INCL Fill is inclusive of bottom right (the default).
891 // POLYGON_EXCL Fill is exclusive of bottom right.
892 // This is provided to aid migration from other graphics models.
893 //////////////////////////////////////////////////////////////////////////////
895 LONG lHits
= 0L; // Correlation/error indicator.
898 int nIsTRANSPARENT
= 0;
899 LONG lBorderColor
= 0L;
902 lBorderColor
= m_pen
.GetColour().GetPixel();
903 lColor
= m_brush
.GetColour().GetPixel();
904 if(m_brush
.GetStyle() == wxTRANSPARENT
)
908 vPlgn
.aPointl
= (POINTL
*) calloc( n
+ 1
910 ); // well, new will call malloc
912 for(i
= 0; i
< n
; i
++)
914 vPlgn
.aPointl
[i
].x
= vPoints
[i
].x
; // +xoffset;
915 vPlgn
.aPointl
[i
].y
= OS2Y(vPoints
[i
].y
,0); // +yoffset;
917 flModel
= POLYGON_BOUNDARY
;
918 if(nFillStyle
== wxWINDING_RULE
)
919 flModel
|= POLYGON_WINDING
;
921 flModel
|= POLYGON_ALTERNATE
;
924 vPoint
.y
= OS2Y(vYoffset
,0);
926 ::GpiSetColor(m_hPS
, lBorderColor
);
927 ::GpiMove(m_hPS
, &vPoint
);
928 lHits
= ::GpiPolygons(m_hPS
, ulCount
, &vPlgn
, flOptions
, flModel
);
930 } // end of wxDC::DoDrawPolygon
932 void wxDC
::DoDrawLines(
941 if (vXoffset
!= 0L || vXoffset
!= 0L)
945 vPoint
.x
= vPoints
[0].x
+ vXoffset
;
946 vPoint
.y
= OS2Y(vPoints
[0].y
+ vYoffset
,0);
947 ::GpiMove(m_hPS
, &vPoint
);
949 LONG lBorderColor
= m_pen
.GetColour().GetPixel();
951 ::GpiSetColor(m_hPS
, lBorderColor
);
952 for(i
= 1; i
< n
; i
++)
954 vPoint
.x
= vPoints
[i
].x
+ vXoffset
;
955 vPoint
.y
= OS2Y(vPoints
[i
].y
+ vYoffset
,0);
956 ::GpiLine(m_hPS
, &vPoint
);
963 CalcBoundingBox( vPoints
[i
].x
966 vPoint
.x
= vPoints
[0].x
;
967 vPoint
.y
= OS2Y(vPoints
[0].y
,0);
968 ::GpiMove(m_hPS
, &vPoint
);
970 for (i
= 0; i
< n
; i
++)
972 CalcBoundingBox( vPoints
[i
].x
975 vPoint
.x
= vPoints
[i
].x
;
976 vPoint
.y
= OS2Y(vPoints
[i
].y
,0);
977 ::GpiLine(m_hPS
, &vPoint
);
980 } // end of wxDC::DoDrawLines
982 void wxDC
::DoDrawRectangle(
993 int nIsTRANSPARENT
= 0;
996 // Might be a memory DC with no Paint rect.
998 if (!(m_vRclPaint
.yTop
== 0 &&
999 m_vRclPaint
.yBottom
== 0 &&
1000 m_vRclPaint
.xRight
== 0 &&
1001 m_vRclPaint
.xLeft
== 0))
1002 vY
= OS2Y(vY
,vHeight
);
1004 wxCoord vX2
= vX
+ vWidth
;
1005 wxCoord vY2
= vY
+ vHeight
;
1009 vPoint
[1].x
= vX
+ vWidth
- 1;
1010 vPoint
[1].y
= vY
+ vHeight
- 1;
1011 ::GpiMove(m_hPS
, &vPoint
[0]);
1012 lColor
= m_brush
.GetColour().GetPixel();
1013 lBorderColor
= m_pen
.GetColour().GetPixel();
1014 if (m_brush
.GetStyle() == wxTRANSPARENT
)
1016 if(lColor
== lBorderColor
|| nIsTRANSPARENT
)
1018 lControl
= DRO_OUTLINEFILL
; //DRO_FILL;
1019 if(m_brush
.GetStyle() == wxTRANSPARENT
)
1020 lControl
= DRO_OUTLINE
;
1022 ::GpiSetColor(m_hPS
, lColor
);
1023 ::GpiBox( m_hPS
// handle to a presentation space
1024 ,lControl
// draw the box outline ? or ?
1025 ,&vPoint
[1] // address of the corner
1026 ,0L // horizontal corner radius
1027 ,0L // vertical corner radius
1032 lControl
= DRO_OUTLINE
;
1033 ::GpiSetColor( m_hPS
1042 lControl
= DRO_FILL
;
1043 ::GpiSetColor( m_hPS
1046 vPoint
[0].x
= vX
+ 1;
1047 vPoint
[0].y
= vY
+ 1;
1048 vPoint
[1].x
= vX
+ vWidth
- 2;
1049 vPoint
[1].y
= vY
+ vHeight
- 2;
1050 ::GpiMove(m_hPS
, &vPoint
[0]);
1058 CalcBoundingBox(vX
, vY
);
1059 CalcBoundingBox(vX2
, vY2
);
1060 } // end of wxDC::DoDrawRectangle
1062 void wxDC
::DoDrawRoundedRectangle(
1074 // Might be a memory DC with no Paint rect.
1076 if (!(m_vRclPaint
.yTop
== 0 &&
1077 m_vRclPaint
.yBottom
== 0 &&
1078 m_vRclPaint
.xRight
== 0 &&
1079 m_vRclPaint
.xLeft
== 0))
1080 vY
= OS2Y(vY
,vHeight
);
1082 wxCoord vX2
= (vX
+ vWidth
);
1083 wxCoord vY2
= (vY
+ vHeight
);
1086 vPoint
[0].y
= YLOG2DEV(vY
) - vHeight
;
1087 vPoint
[1].x
= vX
+ vWidth
;
1089 ::GpiMove(m_hPS
, &vPoint
[0]);
1091 lControl
= DRO_OUTLINEFILL
; //DRO_FILL;
1092 if (m_brush
.GetStyle() == wxTRANSPARENT
)
1093 lControl
= DRO_OUTLINE
;
1094 ::GpiBox( m_hPS
// handle to a presentation space
1095 ,DRO_OUTLINE
// draw the box outline ? or ?
1096 ,&vPoint
[1] // address of the corner
1097 ,(LONG
)dRadius
// horizontal corner radius
1098 ,(LONG
)dRadius
// vertical corner radius
1100 CalcBoundingBox(vX
, vY
);
1101 CalcBoundingBox(vX2
, vY2
);
1102 } // end of wxDC::DoDrawRoundedRectangle
1104 // Draw Ellipse within box (x,y) - (x+width, y+height)
1105 void wxDC
::DoDrawEllipse(
1112 POINTL vPtlPos
; // Structure for current position
1113 FIXED vFxMult
; // Multiplier for ellipse
1114 ARCPARAMS vArcp
; // Structure for arc parameters
1116 vY
= OS2Y(vY
,vHeight
);
1119 vArcp
.lQ
= vHeight
/2;
1120 vArcp
.lP
= vWidth
/2;
1122 ::GpiSetArcParams( m_hPS
1124 ); // Sets parameters to default
1125 vPtlPos
.x
= vX
+ vWidth
/2; // Loads x-coordinate
1126 vPtlPos
.y
= vY
+ vHeight
/2; // Loads y-coordinate
1129 ); // Sets current position
1130 vFxMult
= MAKEFIXED(1, 0); /* Sets multiplier */
1133 // DRO_FILL, DRO_OTLINEFILL - where to get
1138 ); // Draws full arc with center at current position
1140 wxCoord vX2
= (vX
+ vWidth
);
1141 wxCoord vY2
= (vY
+ vHeight
);
1143 CalcBoundingBox(vX
, vY
);
1144 CalcBoundingBox(vX2
, vY2
);
1145 } // end of wxDC::DoDrawEllipse
1147 void wxDC
::DoDrawEllipticArc(
1156 POINTL vPtlPos
; // Structure for current position
1157 FIXED vFxMult
; // Multiplier for ellipse
1158 ARCPARAMS vArcp
; // Structure for arc parameters
1160 FIXED vFSweepa
; // Start angle, sweep angle
1165 vY
= OS2Y(vY
,vHeight
);
1167 dFractPart
= modf(dSa
,&dIntPart
);
1168 vFSa
= MAKEFIXED((int)dIntPart
, (int)(dFractPart
* 0xffff) );
1169 dFractPart
= modf(dEa
- dSa
, &dIntPart
);
1170 vFSweepa
= MAKEFIXED((int)dIntPart
, (int)(dFractPart
* 0xffff) );
1173 // Ellipse main axis (r,q), (p,s) with center at (0,0)
1176 vArcp
.lQ
= vHeight
/2;
1177 vArcp
.lP
= vWidth
/2;
1179 ::GpiSetArcParams(m_hPS
, &vArcp
); // Sets parameters to default
1180 vPtlPos
.x
= vX
+ vWidth
/2 * (1. + cos(DegToRad(dSa
))); // Loads x-coordinate
1181 vPtlPos
.y
= vY
+ vHeight
/2 * (1. + sin(DegToRad(dSa
))); // Loads y-coordinate
1182 ::GpiMove(m_hPS
, &vPtlPos
); // Sets current position
1185 // May be not to the center ?
1187 vPtlPos
.x
= vX
+ vWidth
/2 ; // Loads x-coordinate
1188 vPtlPos
.y
= vY
+ vHeight
/2; // Loads y-coordinate
1189 vFxMult
= MAKEFIXED(1, 0); // Sets multiplier
1192 // DRO_FILL, DRO_OTLINEFILL - where to get
1194 ::GpiPartialArc( m_hPS
1200 wxCoord vX2
= (vX
+ vWidth
);
1201 wxCoord vY2
= (vY
+ vHeight
);
1203 CalcBoundingBox(vX
, vY
);
1204 CalcBoundingBox(vX2
, vY2
);
1205 } // end of wxDC::DoDrawEllipticArc
1207 void wxDC
::DoDrawIcon(
1214 // Need to copy back into a bitmap. ::WinDrawPointer uses device coords
1215 // and I don't feel like figuring those out for scrollable windows so
1216 // just convert to a bitmap then let the DoDrawBitmap routing display it
1220 DoDrawBitmap(rIcon
.GetXpmSrc(), vX
, vY
, TRUE
);
1224 wxBitmap
vBitmap(rIcon
);
1226 DoDrawBitmap(vBitmap
, vX
, vY
, FALSE
);
1228 CalcBoundingBox(vX
, vY
);
1229 CalcBoundingBox(vX
+ rIcon
.GetWidth(), vY
+ rIcon
.GetHeight());
1230 } // end of wxDC::DoDrawIcon
1232 void wxDC
::DoDrawBitmap(
1233 const wxBitmap
& rBmp
1239 if (!IsKindOf(CLASSINFO(wxPrinterDC
)))
1241 HBITMAP hBitmap
= (HBITMAP
)rBmp
.GetHBITMAP();
1244 vY
= OS2Y(vY
,rBmp
.GetHeight());
1247 // Flip the picture as OS/2 is upside-down
1249 POINTL vPoint
[4] = { vX
, vY
+ rBmp
.GetHeight()
1250 ,vX
+ rBmp
.GetWidth(), vY
1252 ,rBmp
.GetWidth(), rBmp
.GetHeight()
1256 wxMask
* pMask
= rBmp
.GetMask();
1261 // Need to imitate ::MaskBlt in windows.
1262 // 1) Extract the bits from from the bitmap.
1263 // 2) Extract the bits from the mask
1264 // 3) Using the mask bits do the following:
1265 // A) If the mask byte is 00 leave the bitmap byte alone
1266 // B) If the mask byte is FF copy the screen color into
1268 // 4) Create a new bitmap and set its bits to the above result
1269 // 5) Blit this to the screen PS
1271 HBITMAP hMask
= (HBITMAP
)pMask
->GetMaskBitmap();
1272 HBITMAP hOldMask
= NULLHANDLE
;
1273 HBITMAP hOldBitmap
= NULLHANDLE
;
1274 HBITMAP hNewBitmap
= NULLHANDLE
;
1275 unsigned char* pucBits
; // buffer that will contain the bitmap data
1276 unsigned char* pucBitsMask
; // buffer that will contain the mask data
1277 unsigned char* pucData
; // pointer to use to traverse bitmap data
1278 unsigned char* pucDataMask
; // pointer to use to traverse mask data
1284 // The usual Memory context creation stuff
1286 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
1287 SIZEL vSize
= {0, 0};
1288 HDC hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
1289 HPS hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIA_ASSOC
);
1292 // The usual bitmap header stuff
1294 BITMAPINFOHEADER2 vHeader
;
1297 memset(&vHeader
, '\0', 16);
1300 memset(&vInfo
, '\0', 16);
1302 vInfo
.cx
= (ULONG
)rBmp
.GetWidth();
1303 vInfo
.cy
= (ULONG
)rBmp
.GetHeight();
1305 vInfo
.cBitCount
= 24; // Set to desired count going in
1308 // Create the buffers for data....all wxBitmaps are 24 bit internally
1310 int nBytesPerLine
= rBmp
.GetWidth() * 3;
1311 int nSizeDWORD
= sizeof(DWORD
);
1312 int nLineBoundary
= nBytesPerLine
% nSizeDWORD
;
1320 // Need to get a background color for mask blitting
1322 if (IsKindOf(CLASSINFO(wxPaintDC
)))
1324 wxPaintDC
* pPaintDC
= wxDynamicCast(this, wxPaintDC
);
1326 lColor
= pPaintDC
->m_pCanvas
->GetBackgroundColour().GetPixel();
1328 else if (GetBrush() != wxNullBrush
)
1329 lColor
= GetBrush().GetColour().GetPixel();
1331 lColor
= m_textBackgroundColour
.GetPixel();
1334 // Bitmap must be ina double-word alligned address so we may
1335 // have some padding to worry about
1337 if (nLineBoundary
> 0)
1339 nPadding
= nSizeDWORD
- nLineBoundary
;
1340 nBytesPerLine
+= nPadding
;
1342 pucBits
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
1343 pucBitsMask
= (unsigned char *)malloc(nBytesPerLine
* rBmp
.GetHeight());
1344 memset(pucBits
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
1345 memset(pucBitsMask
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
1348 // Extract the bitmap and mask data
1350 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hBitmap
)) == HBM_ERROR
)
1352 vError
= ::WinGetLastError(vHabmain
);
1353 sError
= wxPMErrorToStr(vError
);
1355 ::GpiQueryBitmapInfoHeader(hBitmap
, &vHeader
);
1356 vInfo
.cBitCount
= 24;
1357 if ((lScans
= ::GpiQueryBitmapBits( hPS
1359 ,(LONG
)rBmp
.GetHeight()
1364 vError
= ::WinGetLastError(vHabmain
);
1365 sError
= wxPMErrorToStr(vError
);
1367 if ((hOldMask
= ::GpiSetBitmap(hPS
, hMask
)) == HBM_ERROR
)
1369 vError
= ::WinGetLastError(vHabmain
);
1370 sError
= wxPMErrorToStr(vError
);
1372 ::GpiQueryBitmapInfoHeader(hMask
, &vHeader
);
1373 vInfo
.cBitCount
= 24;
1374 if ((lScans
= ::GpiQueryBitmapBits( hPS
1376 ,(LONG
)rBmp
.GetHeight()
1381 vError
= ::WinGetLastError(vHabmain
);
1382 sError
= wxPMErrorToStr(vError
);
1384 if (( hMask
= ::GpiSetBitmap(hPS
, hOldMask
)) == HBM_ERROR
)
1386 vError
= ::WinGetLastError(vHabmain
);
1387 sError
= wxPMErrorToStr(vError
);
1391 // Now set the bytes(bits) according to the mask values
1392 // 3 bytes per pel...must handle one at a time
1395 pucDataMask
= pucBitsMask
;
1398 // 16 bit kludge really only kinda works. The mask gets applied
1399 // where needed but the original bitmap bits are dorked sometimes
1401 bool bpp16
= (wxDisplayDepth() == 16);
1403 for (i
= 0; i
< rBmp
.GetHeight(); i
++)
1405 for (j
= 0; j
< rBmp
.GetWidth(); j
++)
1408 if (bpp16
&& *pucDataMask
== 0xF8) // 16 bit display gobblygook
1410 else if (*pucDataMask
== 0xFF) // leave bitmap byte alone
1414 *pucData
= ((unsigned char)(lColor
>> 16));
1418 if (bpp16
&& *(pucDataMask
+ 1) == 0xFC) // 16 bit display gobblygook
1420 else if (*(pucDataMask
+ 1) == 0xFF) // leave bitmap byte alone
1424 *pucData
= ((unsigned char)(lColor
>> 8));
1429 if (bpp16
&& *(pucDataMask
+ 2) == 0xF8) // 16 bit display gobblygook
1431 else if (*(pucDataMask
+ 2) == 0xFF) // leave bitmap byte alone
1435 *pucData
= ((unsigned char)lColor
);
1440 for (j
= 0; j
< nPadding
; j
++)
1447 // Create a new bitmap
1449 vHeader
.cx
= (ULONG
)rBmp
.GetWidth();
1450 vHeader
.cy
= (ULONG
)rBmp
.GetHeight();
1451 vHeader
.cPlanes
= 1L;
1452 vHeader
.cBitCount
= 24;
1453 if ((hNewBitmap
= ::GpiCreateBitmap( hPS
1460 vError
= ::WinGetLastError(vHabmain
);
1461 sError
= wxPMErrorToStr(vError
);
1465 // Now blit it to the screen PS
1467 if ((lHits
= ::GpiWCBitBlt( (HPS
)GetHPS()
1475 vError
= ::WinGetLastError(vHabmain
);
1476 sError
= wxPMErrorToStr(vError
);
1484 ::GpiSetBitmap(hPS
, NULLHANDLE
);
1485 ::GpiDeleteBitmap(hNewBitmap
);
1486 ::GpiDestroyPS(hPS
);
1492 LONG lOldForeGround
= ::GpiQueryColor((HPS
)GetHPS());
1493 LONG lOldBackGround
= ::GpiQueryBackColor((HPS
)GetHPS());
1495 if (m_textForegroundColour
.Ok())
1497 ::GpiSetColor( (HPS
)GetHPS()
1498 ,m_textForegroundColour
.GetPixel()
1501 if (m_textBackgroundColour
.Ok())
1503 ::GpiSetBackColor( (HPS
)GetHPS()
1504 ,m_textBackgroundColour
.GetPixel()
1508 // Need to alter bits in a mono bitmap to match the new
1509 // background-foreground if it is different.
1511 if (rBmp
.IsMono() &&
1512 ((m_textForegroundColour
.GetPixel() != lOldForeGround
) ||
1513 (m_textBackgroundColour
.GetPixel() != lOldBackGround
)))
1515 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
1516 SIZEL vSize
= {0, 0};
1517 HDC hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
1518 HPS hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIA_ASSOC
);
1520 int nBytesPerLine
= rBmp
.GetWidth() * 3;
1522 LONG lForeGround
= m_textForegroundColour
.GetPixel();
1523 LONG lBackGround
= m_textBackgroundColour
.GetPixel();
1525 HBITMAP hOldBitmap
= NULLHANDLE
;
1531 memset(&vInfo
, '\0', 16);
1533 vInfo
.cx
= (ULONG
)rBmp
.GetWidth();
1534 vInfo
.cy
= (ULONG
)rBmp
.GetHeight();
1536 vInfo
.cBitCount
= 24;
1538 unsigned char* pucBits
; // buffer that will contain the bitmap data
1539 unsigned char* pucData
; // pointer to use to traverse bitmap data
1541 pucBits
= new unsigned char[nBytesPerLine
* rBmp
.GetHeight()];
1542 memset(pucBits
, '\0', (nBytesPerLine
* rBmp
.GetHeight()));
1544 if ((hOldBitmap
= ::GpiSetBitmap(hPS
, hBitmap
)) == HBM_ERROR
)
1546 vError
= ::WinGetLastError(vHabmain
);
1547 sError
= wxPMErrorToStr(vError
);
1550 if ((lScans
= ::GpiQueryBitmapBits( hPS
1552 ,(LONG
)rBmp
.GetHeight()
1557 vError
= ::WinGetLastError(vHabmain
);
1558 sError
= wxPMErrorToStr(vError
);
1561 unsigned char cOldRedFore
= (unsigned char)(lOldForeGround
>> 16);
1562 unsigned char cOldGreenFore
= (unsigned char)(lOldForeGround
>> 8);
1563 unsigned char cOldBlueFore
= (unsigned char)lOldForeGround
;
1565 unsigned char cOldRedBack
= (unsigned char)(lOldBackGround
>> 16);
1566 unsigned char cOldGreenBack
= (unsigned char)(lOldBackGround
>> 8);
1567 unsigned char cOldBlueBack
= (unsigned char)lOldBackGround
;
1569 unsigned char cRedFore
= (unsigned char)(lForeGround
>> 16);
1570 unsigned char cGreenFore
= (unsigned char)(lForeGround
>> 8);
1571 unsigned char cBlueFore
= (unsigned char)lForeGround
;
1573 unsigned char cRedBack
= (unsigned char)(lBackGround
>> 16);
1574 unsigned char cGreenBack
= (unsigned char)(lBackGround
>> 8);
1575 unsigned char cBlueBack
= (unsigned char)lBackGround
;
1578 for (i
= 0; i
< rBmp
.GetHeight(); i
++)
1580 for (j
= 0; j
< rBmp
.GetWidth(); j
++)
1582 unsigned char cBmpRed
= *pucData
;
1583 unsigned char cBmpGreen
= *(pucData
+ 1);
1584 unsigned char cBmpBlue
= *(pucData
+ 2);
1586 if ((cBmpRed
== cOldRedFore
) &&
1587 (cBmpGreen
== cOldGreenFore
) &&
1588 (cBmpBlue
== cOldBlueFore
))
1590 *pucData
= cBlueFore
;
1592 *pucData
= cGreenFore
;
1594 *pucData
= cRedFore
;
1599 *pucData
= cBlueBack
;
1601 *pucData
= cGreenBack
;
1603 *pucData
= cRedBack
;
1608 if ((lScans
= ::GpiSetBitmapBits( hPS
1610 ,(LONG
)rBmp
.GetHeight()
1615 vError
= ::WinGetLastError(vHabmain
);
1616 sError
= wxPMErrorToStr(vError
);
1620 ::GpiSetBitmap(hPS
, NULLHANDLE
);
1621 ::GpiDestroyPS(hPS
);
1624 ::GpiWCBitBlt( (HPS
)GetHPS()
1631 ::GpiSetBitmap((HPS
)GetHPS(), hBitmapOld
);
1632 ::GpiSetColor((HPS
)GetHPS(), lOldForeGround
);
1633 ::GpiSetBackColor((HPS
)GetHPS(), lOldBackGround
);
1636 } // end of wxDC::DoDrawBitmap
1638 void wxDC
::DoDrawText(
1639 const wxString
& rsText
1652 CalcBoundingBox(vX
, vY
);
1653 GetTextExtent(rsText
, &vWidth
, &vHeight
);
1654 CalcBoundingBox((vX
+ vWidth
), (vY
+ vHeight
));
1655 } // end of wxDC::DoDrawText
1657 void wxDC
::DrawAnyText(
1658 const wxString
& rsText
1663 int nOldBackground
= 0;
1670 // prepare for drawing the text
1674 // Set text color attributes
1676 if (m_textForegroundColour
.Ok())
1679 ,(int)m_textForegroundColour
.GetPixel()
1683 if (m_textBackgroundColour
.Ok())
1685 nOldBackground
= SetTextBkColor( m_hPS
1686 ,(int)m_textBackgroundColour
.GetPixel()
1692 GetTextExtent( rsText
1697 if (!(m_vRclPaint
.yTop
== 0 &&
1698 m_vRclPaint
.yBottom
== 0 &&
1699 m_vRclPaint
.xRight
== 0 &&
1700 m_vRclPaint
.xLeft
== 0))
1701 vPtlStart
.y
= OS2Y(vY
,vTextY
);
1705 PCH pzStr
= (PCH
)rsText
.c_str();
1707 ::GpiMove(m_hPS
, &vPtlStart
);
1708 lHits
= ::GpiCharString( m_hPS
1712 if (lHits
!= GPI_OK
)
1714 wxLogLastError(wxT("TextOut"));
1718 // Restore the old parameters (text foreground colour may be left because
1719 // it never is set to anything else, but background should remain
1720 // transparent even if we just drew an opaque string)
1722 if (m_textBackgroundColour
.Ok())
1723 SetTextBkColor( m_hPS
1731 void wxDC
::DoDrawRotatedText(
1732 const wxString
& rsText
1750 DoDrawText(text, x, y);
1755 wxFillLogFont(&lf, &m_font);
1757 // GDI wants the angle in tenth of degree
1758 long angle10 = (long)(angle * 10);
1759 lf.lfEscapement = angle10;
1760 lf. lfOrientation = angle10;
1762 HFONT hfont = ::CreateFontIndirect(&lf);
1765 wxLogLastError("CreateFont");
1769 HFONT hfontOld = ::SelectObject(GetHdc(), hfont);
1771 DrawAnyText(text, x, y);
1773 (void)::SelectObject(GetHdc(), hfontOld);
1776 // call the bounding box by adding all four vertices of the rectangle
1777 // containing the text to it (simpler and probably not slower than
1778 // determining which of them is really topmost/leftmost/...)
1780 GetTextExtent(text, &w, &h);
1782 double rad = DegToRad(angle);
1784 // "upper left" and "upper right"
1785 CalcBoundingBox(x, y);
1786 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
1787 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1789 // "bottom left" and "bottom right"
1790 x += (wxCoord)(h*sin(rad));
1791 y += (wxCoord)(h*cos(rad));
1792 CalcBoundingBox(x, y);
1793 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1798 // ---------------------------------------------------------------------------
1800 // ---------------------------------------------------------------------------
1802 void wxDC
::DoSelectPalette(
1807 // Set the old object temporarily, in case the assignment deletes an object
1808 // that's not yet selected out.
1819 hOldPal
= ::GpiSelectPalette((HDC
) m_hPS
, (HPALETTE
) m_palette
.GetHPALETTE());
1821 m_hOldPalette
= (WXHPALETTE
)hOldPal
;
1823 } // end of wxDC::DoSelectPalette
1825 void wxDC
::InitializePalette()
1827 if (wxDisplayDepth() <= 8 )
1830 // Look for any window or parent that has a custom palette. If any has
1831 // one then we need to use it in drawing operations
1833 wxWindow
* pWin
= m_pCanvas
->GetAncestorWithCustomPalette();
1835 m_hasCustomPalette
= pWin
&& pWin
->HasCustomPalette();
1836 if (m_hasCustomPalette
)
1838 m_palette
= pWin
->GetPalette();
1841 // turn on PM translation for this palette
1846 } // end of wxDC::InitializePalette
1848 void wxDC
::SetPalette(
1849 const wxPalette
& rPalette
1856 m_palette
= rPalette
;
1864 HPALETTE hOldPal
= ::GpiSelectPalette((HDC
) m_hPS
, (HPALETTE
) m_palette
.GetHPALETTE());
1866 m_hOldPalette
= (WXHPALETTE
)hOldPal
;
1867 } // end of wxDC::SetPalette
1874 // Set the old object temporarily, in case the assignment deletes an object
1875 // that's not yet selected out.
1887 m_font
.SetPS(m_hPS
); // this will realize the font
1891 HFONT hFont
= m_font
.GetResourceHandle();
1892 if (hFont
== (HFONT
) NULL
)
1894 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1897 m_hOldFont
= (WXHFONT
) hFont
;
1899 } // end of wxDC::SetFont
1905 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1921 m_pen
.SetPS((HPS
)m_hOldPen
);
1928 if (m_pen
.GetResourceHandle())
1932 m_hOldPen
= m_pen
.GetPS();
1934 ::GpiSetColor(m_hPS
, m_pen
.GetColour().GetPixel());
1938 void wxDC
::SetBrush(
1939 const wxBrush
& rBrush
1942 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1948 if (m_brush
== rBrush
)
1958 m_brush
.SetPS((HPS
)m_hOldBrush
);
1965 if (m_brush
.GetResourceHandle())
1967 m_brush
.SetPS(m_hPS
);
1969 m_hOldBrush
= (WXHWND
)m_brush
.GetPS();
1972 } // end of wxDC::SetBrush
1974 void wxDC
::SetBackground(
1975 const wxBrush
& rBrush
1978 m_backgroundBrush
= rBrush
;
1979 if (!m_backgroundBrush
.Ok())
1983 bool bCustomColours
= TRUE
;
1986 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
1987 // change background colours from the control-panel specified colours.
1989 if (m_pCanvas
->IsKindOf(CLASSINFO(wxWindow
)) &&
1990 ((m_pCanvas
->GetWindowStyleFlag() & wxUSER_COLOURS
) != wxUSER_COLOURS
))
1991 bCustomColours
= FALSE
;
1994 if (m_backgroundBrush
.GetStyle()==wxTRANSPARENT
)
1996 m_pCanvas
->SetTransparent(TRUE
);
2001 // Setting the background brush of a DC
2002 // doesn't affect the window background colour. However,
2003 // I'm leaving in the transparency setting because it's needed by
2004 // various controls (e.g. wxStaticText) to determine whether to draw
2005 // transparently or not. TODO: maybe this should be a new function
2006 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
2008 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
2010 m_pCanvas
->SetTransparent(FALSE
);
2014 COLORREF vNewColor
= m_backgroundBrush
.GetColour().GetPixel();
2015 (void)::GpiSetBackColor((HPS
)m_hPS
, (LONG
)vNewColor
);
2016 } // end of wxDC::SetBackground
2018 void wxDC
::SetBackgroundMode(
2022 m_backgroundMode
= nMode
;
2023 } // end of wxDC::SetBackgroundMode
2025 void wxDC
::SetLogicalFunction(
2029 m_logicalFunction
= nFunction
;
2030 SetRop((WXHDC
)m_hDC
);
2031 } // wxDC::SetLogicalFunction
2037 if (!hDC
|| m_logicalFunction
< 0)
2041 switch (m_logicalFunction
)
2052 lCRop
= FM_MERGESRCNOT
;
2056 lCRop
= FM_NOTMASKSRC
;
2068 lCRop
= FM_MERGENOTSRC
;
2072 lCRop
= FM_MERGESRCNOT
;
2084 lCRop
= FM_SUBTRACT
;
2091 lCRop
= FM_OVERPAINT
;
2094 ::GpiSetMix((HPS
)hDC
, lCRop
);
2095 } // end of wxDC::SetRop
2097 bool wxDC
::StartDoc(
2098 const wxString
& rsMessage
2101 // We might be previewing, so return TRUE to let it continue.
2103 } // end of wxDC::StartDoc
2107 } // end of wxDC::EndDoc
2109 void wxDC
::StartPage()
2111 } // end of wxDC::StartPage
2113 void wxDC
::EndPage()
2115 } // end of wxDC::EndPage
2117 // ---------------------------------------------------------------------------
2119 // ---------------------------------------------------------------------------
2121 wxCoord wxDC
::GetCharHeight() const
2123 FONTMETRICS vFM
; // metrics structure
2125 ::GpiQueryFontMetrics( m_hPS
2126 ,sizeof(FONTMETRICS
)
2129 return YDEV2LOGREL(vFM
.lXHeight
);
2132 wxCoord wxDC
::GetCharWidth() const
2134 FONTMETRICS vFM
; // metrics structure
2136 ::GpiQueryFontMetrics( m_hPS
2137 ,sizeof(FONTMETRICS
)
2140 return XDEV2LOGREL(vFM
.lAveCharWidth
);
2143 void wxDC
::DoGetTextExtent(
2144 const wxString
& rsString
2147 , wxCoord
* pvDescent
2148 , wxCoord
* pvExternalLeading
2152 POINTL avPoint
[TXTBOX_COUNT
];
2157 FONTMETRICS vFM
; // metrics structure
2160 ERRORID vErrorCode
; // last error id code
2161 wxFont
* pFontToUse
= (wxFont
*)pTheFont
;
2163 char zMsg
[128]; // DEBUG
2167 pFontToUse
= (wxFont
*)&m_font
;
2168 l
= rsString
.length();
2169 pStr
= (PCH
) rsString
.c_str();
2172 // In world coordinates.
2174 bRc
= ::GpiQueryTextBox( m_hPS
2177 ,TXTBOX_COUNT
// return maximum information
2178 ,avPoint
// array of coordinates points
2182 vErrorCode
= ::WinGetLastError(wxGetInstance());
2183 sError
= wxPMErrorToStr(vErrorCode
);
2185 sprintf(zMsg
, "GpiQueryTextBox for %s: failed with Error: %x - %s", pStr
, vErrorCode
, sError
.c_str());
2186 (void)wxMessageBox( "wxWindows Menu sample"
2192 vPtMin
.x
= avPoint
[0].x
;
2193 vPtMax
.x
= avPoint
[0].x
;
2194 vPtMin
.y
= avPoint
[0].y
;
2195 vPtMax
.y
= avPoint
[0].y
;
2196 for (i
= 1; i
< 4; i
++)
2198 if(vPtMin
.x
> avPoint
[i
].x
) vPtMin
.x
= avPoint
[i
].x
;
2199 if(vPtMin
.y
> avPoint
[i
].y
) vPtMin
.y
= avPoint
[i
].y
;
2200 if(vPtMax
.x
< avPoint
[i
].x
) vPtMax
.x
= avPoint
[i
].x
;
2201 if(vPtMax
.y
< avPoint
[i
].y
) vPtMax
.y
= avPoint
[i
].y
;
2203 ::GpiQueryFontMetrics( m_hPS
2204 ,sizeof(FONTMETRICS
)
2209 *pvX
= (wxCoord
)(vPtMax
.x
- vPtMin
.x
+ 1);
2211 *pvY
= (wxCoord
)(vPtMax
.y
- vPtMin
.y
+ 1);
2213 *pvDescent
= vFM
.lMaxDescender
;
2214 if (pvExternalLeading
)
2215 *pvExternalLeading
= vFM
.lExternalLeading
;
2218 void wxDC
::SetMapMode(
2222 int nPixelWidth
= 0;
2223 int nPixelHeight
= 0;
2226 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2228 m_mappingMode
= nMode
;
2230 if(::DevQueryCaps( m_hDC
2232 ,CAPS_VERTICAL_RESOLUTION
2239 nPixelWidth
= lArray
[CAPS_WIDTH
];
2240 nPixelHeight
= lArray
[CAPS_HEIGHT
];
2241 lHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2242 lVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2243 nMmWidth
= (lHorzRes
/1000) * nPixelWidth
;
2244 nMmWidth
= (lVertRes
/1000) * nPixelHeight
;
2246 if ((nPixelWidth
== 0) || (nPixelHeight
== 0) || (nMmWidth
== 0) || (nMmHeight
== 0))
2251 double dMm2pixelsX
= nPixelWidth
/nMmWidth
;
2252 double dMm2pixelsY
= nPixelHeight
/nMmHeight
;
2257 m_logicalScaleX
= (twips2mm
* dMm2pixelsX
);
2258 m_logicalScaleY
= (twips2mm
* dMm2pixelsY
);
2262 m_logicalScaleX
= (pt2mm
* dMm2pixelsX
);
2263 m_logicalScaleY
= (pt2mm
* dMm2pixelsY
);
2267 m_logicalScaleX
= dMm2pixelsX
;
2268 m_logicalScaleY
= dMm2pixelsY
;
2272 m_logicalScaleX
= (dMm2pixelsX
/10.0);
2273 m_logicalScaleY
= (dMm2pixelsY
/10.0);
2278 m_logicalScaleX
= 1.0;
2279 m_logicalScaleY
= 1.0;
2285 ulOptions
= ::GpiQueryPS(m_hPS
, &vSize
);
2286 if (!ulOptions
& PU_ARBITRARY
)
2288 ulOptions
= PU_ARBITRARY
| GPIF_DEFAULT
;
2289 ::GpiSetPS(m_hPS
, &vSize
, ulOptions
);
2291 m_nWindowExtX
= (int)MS_XDEV2LOG(VIEWPORT_EXTENT
);
2292 m_nWindowExtY
= (int)MS_YDEV2LOG(VIEWPORT_EXTENT
);
2294 }; // end of wxDC::SetMapMode
2296 void wxDC
::SetUserScale(
2304 SetMapMode(m_mappingMode
);
2305 } // end of wxDC::SetUserScale
2307 void wxDC
::SetAxisOrientation(
2312 m_signX
= bXLeftRight ?
1 : -1;
2313 m_signY
= bYBottomUp ?
-1 : 1;
2315 SetMapMode(m_mappingMode
);
2316 } // end of wxDC::SetAxisOrientation
2318 void wxDC
::SetSystemScale(
2326 SetMapMode(m_mappingMode
);
2327 } // end of wxDC::SetSystemScale
2329 void wxDC
::SetLogicalOrigin(
2336 ::GpiQueryPageViewport( m_hPS
2343 ::GpiSetPageViewport( m_hPS
2346 }; // end of wxDC::SetLogicalOrigin
2348 void wxDC
::SetDeviceOrigin(
2355 m_deviceOriginX
= vX
;
2356 m_deviceOriginY
= vY
;
2357 ::GpiQueryPageViewport( m_hPS
2362 vRect
.yBottom
-= vY
;
2364 ::GpiSetPageViewport( m_hPS
2367 }; // end of wxDC::SetDeviceOrigin
2369 // ---------------------------------------------------------------------------
2370 // coordinates transformations
2371 // ---------------------------------------------------------------------------
2373 wxCoord wxDCBase
::DeviceToLogicalX(wxCoord x
) const
2375 return (wxCoord
) (((x
) - m_deviceOriginX
)/(m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
) - m_logicalOriginX
);
2378 wxCoord wxDCBase
::DeviceToLogicalXRel(wxCoord x
) const
2380 // axis orientation is not taken into account for conversion of a distance
2381 return (wxCoord
) ((x
)/(m_logicalScaleX
*m_userScaleX
*m_scaleX
));
2384 wxCoord wxDCBase
::DeviceToLogicalY(wxCoord y
) const
2386 return (wxCoord
) (((y
) - m_deviceOriginY
)/(m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
) - m_logicalOriginY
);
2389 wxCoord wxDCBase
::DeviceToLogicalYRel(wxCoord y
) const
2391 // axis orientation is not taken into account for conversion of a distance
2392 return (wxCoord
) ((y
)/(m_logicalScaleY
*m_userScaleY
*m_scaleY
));
2395 wxCoord wxDCBase
::LogicalToDeviceX(wxCoord x
) const
2397 return (wxCoord
) ((x
- m_logicalOriginX
)*m_logicalScaleX
*m_userScaleX
*m_signX
*m_scaleX
+ m_deviceOriginX
);
2400 wxCoord wxDCBase
::LogicalToDeviceXRel(wxCoord x
) const
2402 // axis orientation is not taken into account for conversion of a distance
2403 return (wxCoord
) (x
*m_logicalScaleX
*m_userScaleX
*m_scaleX
);
2406 wxCoord wxDCBase
::LogicalToDeviceY(wxCoord y
) const
2408 return (wxCoord
) ((y
- m_logicalOriginY
)*m_logicalScaleY
*m_userScaleY
*m_signY
*m_scaleY
+ m_deviceOriginY
);
2411 wxCoord wxDCBase
::LogicalToDeviceYRel(wxCoord y
) const
2413 // axis orientation is not taken into account for conversion of a distance
2414 return (wxCoord
) (y
*m_logicalScaleY
*m_userScaleY
*m_scaleY
);
2417 // ---------------------------------------------------------------------------
2419 // ---------------------------------------------------------------------------
2435 wxMask
* pMask
= NULL
;
2437 COLORREF vOldTextColor
;
2438 COLORREF vOldBackground
= ::GpiQueryBackColor(m_hPS
);
2442 const wxBitmap
& rBmp
= pSource
->m_vSelectedBitmap
;
2444 pMask
= rBmp
.GetMask();
2445 if (!(rBmp
.Ok() && pMask
&& pMask
->GetMaskBitmap()))
2451 ::GpiQueryAttrs( m_hPS
2456 vOldTextColor
= (COLORREF
)vCbnd
.lColor
;
2458 if (m_textForegroundColour
.Ok())
2460 vCbnd
.lColor
= (LONG
)m_textForegroundColour
.GetPixel();
2461 ::GpiSetAttrs( m_hPS
// presentation-space handle
2462 ,PRIM_CHAR
// Char primitive.
2463 ,CBB_COLOR
// sets color.
2465 ,&vCbnd
// buffer for attributes.
2468 if (m_textBackgroundColour
.Ok())
2470 ::GpiSetBackColor(m_hPS
, (LONG
)m_textBackgroundColour
.GetPixel());
2473 LONG lRop
= ROP_SRCCOPY
;
2477 case wxXOR
: lRop
= ROP_SRCINVERT
; break;
2478 case wxINVERT
: lRop
= ROP_DSTINVERT
; break;
2479 case wxOR_REVERSE
: lRop
= 0x00DD0228; break;
2480 case wxAND_REVERSE
: lRop
= ROP_SRCERASE
; break;
2481 case wxCLEAR
: lRop
= ROP_ZERO
; break;
2482 case wxSET
: lRop
= ROP_ONE
; break;
2483 case wxOR_INVERT
: lRop
= ROP_MERGEPAINT
; break;
2484 case wxAND
: lRop
= ROP_SRCAND
; break;
2485 case wxOR
: lRop
= ROP_SRCPAINT
; break;
2486 case wxEQUIV
: lRop
= 0x00990066; break;
2487 case wxNAND
: lRop
= 0x007700E6; break;
2488 case wxAND_INVERT
: lRop
= 0x00220326; break;
2489 case wxCOPY
: lRop
= ROP_SRCCOPY
; break;
2490 case wxNO_OP
: lRop
= ROP_NOTSRCERASE
; break;
2491 case wxSRC_INVERT
: lRop
= ROP_SRCINVERT
; break;
2492 case wxNOR
: lRop
= ROP_NOTSRCCOPY
; break;
2494 wxFAIL_MSG( wxT("unsupported logical function") );
2503 // Blit bitmap with mask
2507 // Create a temp buffer bitmap and DCs/PSs to access it and the mask
2513 DEVOPENSTRUC vDOP
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
2514 BITMAPINFOHEADER2 vBmpHdr
;
2516 SIZEL vSize
= {0, 0};
2519 memset(&vBmpHdr
, 0, sizeof(BITMAPINFOHEADER2
));
2520 vBmpHdr
.cbFix
= sizeof(BITMAPINFOHEADER2
);
2521 vBmpHdr
.cx
= vWidth
;
2522 vBmpHdr
.cy
= vHeight
;
2523 vBmpHdr
.cPlanes
= 1;
2524 vBmpHdr
.cBitCount
= 24;
2526 #if wxUSE_DC_CACHEING
2530 // create a temp buffer bitmap and DCs to access it and the mask
2532 wxDCCacheEntry
* pDCCacheEntry1
= FindDCInCache( NULL
2535 wxDCCacheEntry
* pDCCacheEntry2
= FindDCInCache( pDCCacheEntry1
2538 wxDCCacheEntry
* pBitmapCacheEntry
= FindBitmapInCache( GetHPS()
2543 hPSMask
= pDCCacheEntry1
->m_hPS
;
2544 hDCBuffer
= (HDC
)pDCCacheEntry2
->m_hPS
;
2545 hBufBitmap
= (HBITMAP
)pBitmapCacheEntry
->m_hBitmap
;
2550 hDCMask
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
2551 hDCBuffer
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
2552 hPSMask
= ::GpiCreatePS(vHabmain
, hDCMask
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
2553 hPSBuffer
= ::GpiCreatePS(vHabmain
, hDCBuffer
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
2554 hBufBitmap
= ::GpiCreateBitmap(GetHPS(), &vBmpHdr
, 0L, NULL
, NULL
);
2557 POINTL aPoint1
[4] = { 0, 0
2560 ,vXdest
+ vWidth
, vYdest
+ vHeight
2562 POINTL aPoint2
[4] = { 0, 0
2565 ,vXsrc
+ vWidth
, vYsrc
+ vHeight
2567 POINTL aPoint3
[4] = { vXdest
, vYdest
2568 ,vXdest
+ vWidth
, vYdest
+ vHeight
2570 ,vXsrc
+ vWidth
, vYsrc
+ vHeight
2572 POINTL aPoint4
[4] = { vXdest
, vYdest
2573 ,vXdest
+ vWidth
, vYdest
+ vHeight
2577 ::GpiSetBitmap(hPSMask
, (HBITMAP
) pMask
->GetMaskBitmap());
2578 ::GpiSetBitmap(hPSBuffer
, (HBITMAP
) hBufBitmap
);
2581 // Copy dest to buffer
2583 rc
= ::GpiBitBlt( hPSBuffer
2590 if (rc
== GPI_ERROR
)
2592 wxLogLastError(wxT("BitBlt"));
2596 // Copy src to buffer using selected raster op
2598 rc
= ::GpiBitBlt( hPSBuffer
2605 if (rc
== GPI_ERROR
)
2607 wxLogLastError(wxT("BitBlt"));
2611 // Set masked area in buffer to BLACK (pixel value 0)
2613 COLORREF vPrevBkCol
= ::GpiQueryBackColor(GetHPS());
2614 COLORREF vPrevCol
= ::GpiQueryColor(GetHPS());
2616 ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255));
2617 ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0));
2619 rc
= ::GpiBitBlt( hPSBuffer
2626 if (rc
== GPI_ERROR
)
2628 wxLogLastError(wxT("BitBlt"));
2632 // Set unmasked area in dest to BLACK
2634 ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0));
2635 ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255));
2636 rc
= ::GpiBitBlt( GetHPS()
2643 if (rc
== GPI_ERROR
)
2645 wxLogLastError(wxT("BitBlt"));
2649 // Restore colours to original values
2651 ::GpiSetBackColor(GetHPS(), vPrevBkCol
);
2652 ::GpiSetColor(GetHPS(), vPrevCol
);
2655 // OR buffer to dest
2657 rc
= ::GpiBitBlt( GetHPS()
2664 if (rc
== GPI_ERROR
)
2667 wxLogLastError(wxT("BitBlt"));
2671 // Tidy up temporary DCs and bitmap
2673 ::GpiSetBitmap(hPSMask
, NULLHANDLE
);
2674 ::GpiSetBitmap(hPSBuffer
, NULLHANDLE
);
2675 #if !wxUSE_DC_CACHEING
2676 ::GpiDestroyPS(hPSMask
);
2677 ::GpiDestroyPS(hPSBuffer
);
2678 ::DevCloseDC(hDCMask
);
2679 ::DevCloseDC(hDCBuffer
);
2680 ::GpiDeleteBitmap(hBufBitmap
);
2684 else // no mask, just BitBlt() it
2686 POINTL aPoint
[4] = { vXdest
, vYdest
2687 ,vXdest
+ vWidth
, vYdest
+ vHeight
2689 ,vXsrc
+ vWidth
, vYsrc
+ vHeight
2692 bSuccess
= (::GpiBitBlt( m_hPS
2701 wxLogLastError(wxT("BitBlt"));
2704 vCbnd
.lColor
= (LONG
)vOldTextColor
;
2705 ::GpiSetAttrs( m_hPS
// presentation-space handle
2706 ,PRIM_CHAR
// Char primitive.
2707 ,CBB_COLOR
// sets color.
2709 ,&vCbnd
// buffer for attributes.
2711 ::GpiSetBackColor(m_hPS
, (LONG
)vOldBackground
);
2715 void wxDC
::DoGetSize(
2720 LONG lArray
[CAPS_HEIGHT
];
2722 if(::DevQueryCaps( m_hDC
2728 *pnWidth
= lArray
[CAPS_WIDTH
];
2729 *pnHeight
= lArray
[CAPS_HEIGHT
];
2731 }; // end of wxDC::DoGetSize(
2733 void wxDC
::DoGetSizeMM(
2738 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2740 if(::DevQueryCaps( m_hDC
2742 ,CAPS_VERTICAL_RESOLUTION
2751 nWidth
= lArray
[CAPS_WIDTH
];
2752 nHeight
= lArray
[CAPS_HEIGHT
];
2753 nHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2754 nVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2755 nWidth
= (nHorzRes
/1000) * nWidth
;
2756 nHeight
= (nVertRes
/1000) * nHeight
;
2758 }; // end of wxDC::DoGetSizeMM
2760 wxSize wxDC
::GetPPI() const
2762 LONG lArray
[CAPS_VERTICAL_RESOLUTION
];
2766 if(::DevQueryCaps( m_hDC
2768 ,CAPS_VERTICAL_RESOLUTION
2777 nPelWidth
= lArray
[CAPS_WIDTH
];
2778 nPelHeight
= lArray
[CAPS_HEIGHT
];
2779 nHorzRes
= lArray
[CAPS_HORIZONTAL_RESOLUTION
]; // returns pel/meter
2780 nVertRes
= lArray
[CAPS_VERTICAL_RESOLUTION
]; // returns pel/meter
2781 nWidth
= (nHorzRes
/39.3) * nPelWidth
;
2782 nHeight
= (nVertRes
/39.3) * nPelHeight
;
2784 return (wxSize(nWidth
,nHeight
));
2785 } // end of wxDC::GetPPI
2787 void wxDC
::SetLogicalScale(
2792 m_logicalScaleX
= dX
;
2793 m_logicalScaleY
= dY
;
2794 }; // end of wxDC::SetLogicalScale
2796 #if WXWIN_COMPATIBILITY
2797 void wxDC
::DoGetTextExtent(const wxString
& string
, float *x
, float *y
,
2798 float *descent
, float *externalLeading
,
2799 wxFont
*theFont
, bool use16bit
) const
2801 wxCoord x1
, y1
, descent1
, externalLeading1
;
2802 GetTextExtent(string
, & x1
, & y1
, & descent1
, & externalLeading1
, theFont
, use16bit
);
2805 *descent
= descent1
;
2806 if (externalLeading
)
2807 *externalLeading
= externalLeading1
;