1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/graphics.cpp
3 // Purpose: wxGCDC class
4 // Author: Stefan Csomor
8 // Copyright: (c) 2006 Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
20 #if wxUSE_GRAPHICS_CONTEXT
23 #include "wx/msw/wrapcdlg.h"
25 #include "wx/window.h"
27 #include "wx/dialog.h"
29 #include "wx/bitmap.h"
32 #include "wx/module.h"
33 // include all dc types that are used as a param
35 #include "wx/dcclient.h"
36 #include "wx/dcmemory.h"
37 #include "wx/dcprint.h"
42 #include "wx/private/graphics.h"
43 #include "wx/msw/wrapgdip.h"
44 #include "wx/msw/dc.h"
45 #if wxUSE_ENH_METAFILE
46 #include "wx/msw/enhmeta.h"
48 #include "wx/dcgraph.h"
50 #include "wx/msw/private.h" // needs to be before #include <commdlg.h>
52 #if wxUSE_COMMON_DIALOGS && !defined(__WXMICROWIN__)
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
63 const double RAD2DEG
= 180.0 / M_PI
;
65 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
69 inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
70 inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
72 inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
73 inline double RadToDeg(double deg
) { return (deg
* 180.0) / M_PI
; }
75 // translate a wxColour to a Color
76 inline Color
wxColourToColor(const wxColour
& col
)
78 return Color(col
.Alpha(), col
.Red(), col
.Green(), col
.Blue());
81 } // anonymous namespace
83 //-----------------------------------------------------------------------------
84 // device context implementation
86 // more and more of the dc functionality should be implemented by calling
87 // the appropricate wxGDIPlusContext, but we will have to do that step by step
88 // also coordinate conversions should be moved to native matrix ops
89 //-----------------------------------------------------------------------------
91 // we always stock two context states, one at entry, to be able to preserve the
92 // state we were called with, the other one after changing to HI Graphics orientation
93 // (this one is used for getting back clippings etc)
95 //-----------------------------------------------------------------------------
96 // wxGraphicsPath implementation
97 //-----------------------------------------------------------------------------
99 class wxGDIPlusContext
;
101 class wxGDIPlusPathData
: public wxGraphicsPathData
104 wxGDIPlusPathData(wxGraphicsRenderer
* renderer
, GraphicsPath
* path
= NULL
);
105 ~wxGDIPlusPathData();
107 virtual wxGraphicsObjectRefData
*Clone() const;
110 // These are the path primitives from which everything else can be constructed
113 // begins a new subpath at (x,y)
114 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
116 // adds a straight line from the current point to (x,y)
117 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
119 // adds a cubic Bezier curve from the current point, using two control points and an end point
120 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
123 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
124 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
) ;
126 // gets the last point of the current path, (0,0) if not yet set
127 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
130 virtual void AddPath( const wxGraphicsPathData
* path
);
132 // closes the current sub-path
133 virtual void CloseSubpath();
136 // These are convenience functions which - if not available natively will be assembled
137 // using the primitives from above
140 // appends a rectangle as a new closed subpath
141 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) ;
144 // appends an ellipsis as a new closed subpath fitting the passed rectangle
145 virtual void AddEllipsis( wxDouble x, wxDouble y, wxDouble w , wxDouble h ) ;
147 // draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1)
148 virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
151 // returns the native path
152 virtual void * GetNativePath() const { return m_path
; }
154 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
155 virtual void UnGetNativePath(void * WXUNUSED(path
)) const {}
157 // transforms each point of this path by the matrix
158 virtual void Transform( const wxGraphicsMatrixData
* matrix
) ;
160 // gets the bounding box enclosing all points (possibly including control points)
161 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const;
163 virtual bool Contains( wxDouble x
, wxDouble y
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
) const;
166 GraphicsPath
* m_path
;
169 class wxGDIPlusMatrixData
: public wxGraphicsMatrixData
172 wxGDIPlusMatrixData(wxGraphicsRenderer
* renderer
, Matrix
* matrix
= NULL
) ;
173 virtual ~wxGDIPlusMatrixData() ;
175 virtual wxGraphicsObjectRefData
* Clone() const ;
177 // concatenates the matrix
178 virtual void Concat( const wxGraphicsMatrixData
*t
);
180 // sets the matrix to the respective values
181 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
182 wxDouble tx
=0.0, wxDouble ty
=0.0);
184 // gets the component valuess of the matrix
185 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
186 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
188 // makes this the inverse matrix
189 virtual void Invert();
191 // returns true if the elements of the transformation matrix are equal ?
192 virtual bool IsEqual( const wxGraphicsMatrixData
* t
) const ;
194 // return true if this is the identity matrix
195 virtual bool IsIdentity() const;
201 // add the translation to this matrix
202 virtual void Translate( wxDouble dx
, wxDouble dy
);
204 // add the scale to this matrix
205 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
207 // add the rotation to this matrix (radians)
208 virtual void Rotate( wxDouble angle
);
211 // apply the transforms
214 // applies that matrix to the point
215 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
217 // applies the matrix except for translations
218 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
220 // returns the native representation
221 virtual void * GetNativeMatrix() const;
226 class wxGDIPlusPenData
: public wxGraphicsObjectRefData
229 wxGDIPlusPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
);
234 virtual wxDouble
GetWidth() { return m_width
; }
235 virtual Pen
* GetGDIPlusPen() { return m_pen
; }
245 class wxGDIPlusBrushData
: public wxGraphicsObjectRefData
248 wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
);
249 wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
);
250 ~wxGDIPlusBrushData ();
252 void CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
253 wxDouble x2
, wxDouble y2
,
254 const wxGraphicsGradientStops
& stops
);
255 void CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
256 wxDouble xc
, wxDouble yc
,
258 const wxGraphicsGradientStops
& stops
);
260 virtual Brush
* GetGDIPlusBrush() { return m_brush
; }
266 // common part of Create{Linear,Radial}GradientBrush()
267 template <typename T
>
268 void SetGradientStops(T
*brush
, const wxGraphicsGradientStops
& stops
);
272 GraphicsPath
* m_brushPath
;
275 class WXDLLIMPEXP_CORE wxGDIPlusBitmapData
: public wxGraphicsObjectRefData
278 wxGDIPlusBitmapData( wxGraphicsRenderer
* renderer
, Bitmap
* bitmap
);
279 wxGDIPlusBitmapData( wxGraphicsRenderer
* renderer
, const wxBitmap
&bmp
);
280 ~wxGDIPlusBitmapData ();
282 virtual Bitmap
* GetGDIPlusBitmap() { return m_bitmap
; }
285 wxImage
ConvertToImage() const;
286 #endif // wxUSE_IMAGE
293 class wxGDIPlusFontData
: public wxGraphicsObjectRefData
296 wxGDIPlusFontData( wxGraphicsRenderer
* renderer
,
298 const wxColour
& col
);
299 wxGDIPlusFontData(wxGraphicsRenderer
* renderer
,
300 const wxString
& name
,
303 const wxColour
& col
);
304 ~wxGDIPlusFontData();
306 virtual Brush
* GetGDIPlusBrush() { return m_textBrush
; }
307 virtual Font
* GetGDIPlusFont() { return m_font
; }
310 // Common part of all ctors, flags here is a combination of values of
311 // FontStyle GDI+ enum.
312 void Init(const wxString
& name
,
322 class wxGDIPlusContext
: public wxGraphicsContext
325 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, const wxDC
& dc
);
326 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HDC hdc
, wxDouble width
, wxDouble height
);
327 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HWND hwnd
);
328 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, Graphics
* gr
);
329 wxGDIPlusContext(wxGraphicsRenderer
* renderer
);
331 virtual ~wxGDIPlusContext();
333 virtual void Clip( const wxRegion
®ion
);
334 // clips drawings to the rect
335 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
337 // resets the clipping to original extent
338 virtual void ResetClip();
340 virtual void * GetNativeContext();
342 virtual void StrokePath( const wxGraphicsPath
& p
);
343 virtual void FillPath( const wxGraphicsPath
& p
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
345 virtual void DrawRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
347 // stroke lines connecting each of the points
348 virtual void StrokeLines( size_t n
, const wxPoint2DDouble
*points
);
351 virtual void DrawLines( size_t n
, const wxPoint2DDouble
*points
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
353 virtual bool SetAntialiasMode(wxAntialiasMode antialias
);
355 virtual bool SetInterpolationQuality(wxInterpolationQuality interpolation
);
357 virtual bool SetCompositionMode(wxCompositionMode op
);
359 virtual void BeginLayer(wxDouble opacity
);
361 virtual void EndLayer();
363 virtual void Translate( wxDouble dx
, wxDouble dy
);
364 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
365 virtual void Rotate( wxDouble angle
);
367 // concatenates this transform with the current transform of this context
368 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
);
370 // sets the transform of this context
371 virtual void SetTransform( const wxGraphicsMatrix
& matrix
);
373 // gets the matrix of this context
374 virtual wxGraphicsMatrix
GetTransform() const;
376 virtual void DrawBitmap( const wxGraphicsBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
377 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
378 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
379 virtual void PushState();
380 virtual void PopState();
382 virtual void GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
383 wxDouble
*descent
, wxDouble
*externalLeading
) const;
384 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const;
385 virtual bool ShouldOffset() const;
386 virtual void GetSize( wxDouble
* width
, wxDouble
*height
);
388 Graphics
* GetGraphics() const { return m_context
; }
392 wxDouble m_fontScaleRatio
;
394 // Used from ctors (including those in the derived classes) and takes
395 // ownership of the graphics pointer that must be non-NULL.
396 void Init(Graphics
* graphics
, int width
, int height
);
399 virtual void DoDrawText(const wxString
& str
, wxDouble x
, wxDouble y
)
400 { DoDrawFilledText(str
, x
, y
, wxNullGraphicsBrush
); }
401 virtual void DoDrawFilledText(const wxString
& str
, wxDouble x
, wxDouble y
,
402 const wxGraphicsBrush
& backgroundBrush
);
405 wxStack
<GraphicsState
> m_stateStack
;
406 GraphicsState m_state1
;
407 GraphicsState m_state2
;
409 wxDECLARE_NO_COPY_CLASS(wxGDIPlusContext
);
414 class wxGDIPlusImageContext
: public wxGDIPlusContext
417 wxGDIPlusImageContext(wxGraphicsRenderer
* renderer
, wxImage
& image
) :
418 wxGDIPlusContext(renderer
),
420 m_bitmap(renderer
, image
)
424 new Graphics(m_bitmap
.GetGDIPlusBitmap()),
430 virtual ~wxGDIPlusImageContext()
432 m_image
= m_bitmap
.ConvertToImage();
437 wxGDIPlusBitmapData m_bitmap
;
439 wxDECLARE_NO_COPY_CLASS(wxGDIPlusImageContext
);
442 #endif // wxUSE_IMAGE
444 class wxGDIPlusMeasuringContext
: public wxGDIPlusContext
447 wxGDIPlusMeasuringContext( wxGraphicsRenderer
* renderer
) : wxGDIPlusContext( renderer
, m_hdc
= GetDC(NULL
), 1000, 1000 )
451 virtual ~wxGDIPlusMeasuringContext()
453 ReleaseDC( NULL
, m_hdc
);
460 class wxGDIPlusPrintingContext
: public wxGDIPlusContext
463 wxGDIPlusPrintingContext( wxGraphicsRenderer
* renderer
, const wxDC
& dc
);
464 virtual ~wxGDIPlusPrintingContext() { }
468 //-----------------------------------------------------------------------------
469 // wxGDIPlusRenderer declaration
470 //-----------------------------------------------------------------------------
472 class wxGDIPlusRenderer
: public wxGraphicsRenderer
481 virtual ~wxGDIPlusRenderer()
491 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
);
493 virtual wxGraphicsContext
* CreateContext( const wxMemoryDC
& dc
);
495 #if wxUSE_PRINTING_ARCHITECTURE
496 virtual wxGraphicsContext
* CreateContext( const wxPrinterDC
& dc
);
499 #if wxUSE_ENH_METAFILE
500 virtual wxGraphicsContext
* CreateContext( const wxEnhMetaFileDC
& dc
);
503 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
);
505 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
);
507 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
);
510 virtual wxGraphicsContext
* CreateContextFromImage(wxImage
& image
);
511 #endif // wxUSE_IMAGE
513 virtual wxGraphicsContext
* CreateMeasuringContext();
517 virtual wxGraphicsPath
CreatePath();
521 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
522 wxDouble tx
=0.0, wxDouble ty
=0.0);
525 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) ;
527 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) ;
529 virtual wxGraphicsBrush
530 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
531 wxDouble x2
, wxDouble y2
,
532 const wxGraphicsGradientStops
& stops
);
534 virtual wxGraphicsBrush
535 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
536 wxDouble xc
, wxDouble yc
,
538 const wxGraphicsGradientStops
& stops
);
540 // create a native bitmap representation
541 virtual wxGraphicsBitmap
CreateBitmap( const wxBitmap
&bitmap
);
543 virtual wxGraphicsBitmap
CreateBitmapFromImage(const wxImage
& image
);
544 virtual wxImage
CreateImageFromBitmap(const wxGraphicsBitmap
& bmp
);
545 #endif // wxUSE_IMAGE
547 virtual wxGraphicsFont
CreateFont( const wxFont
& font
,
548 const wxColour
& col
);
550 virtual wxGraphicsFont
CreateFont(double size
,
551 const wxString
& facename
,
552 int flags
= wxFONTFLAG_DEFAULT
,
553 const wxColour
& col
= *wxBLACK
);
555 // create a graphics bitmap from a native bitmap
556 virtual wxGraphicsBitmap
CreateBitmapFromNativeBitmap( void* bitmap
);
558 // create a subimage from a native image representation
559 virtual wxGraphicsBitmap
CreateSubBitmap( const wxGraphicsBitmap
&bitmap
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
562 bool EnsureIsLoaded();
565 friend class wxGDIPlusRendererModule
;
569 ULONG_PTR m_gditoken
;
571 DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusRenderer
)
574 //-----------------------------------------------------------------------------
575 // wxGDIPlusPen implementation
576 //-----------------------------------------------------------------------------
578 wxGDIPlusPenData::~wxGDIPlusPenData()
585 void wxGDIPlusPenData::Init()
592 wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
)
593 : wxGraphicsObjectRefData(renderer
)
596 m_width
= pen
.GetWidth();
600 m_pen
= new Pen(wxColourToColor(pen
.GetColour()), m_width
);
603 switch ( pen
.GetCap() )
609 case wxCAP_PROJECTING
:
614 cap
= LineCapFlat
; // TODO verify
621 m_pen
->SetLineCap(cap
,cap
, DashCapFlat
);
624 switch ( pen
.GetJoin() )
627 join
= LineJoinBevel
;
631 join
= LineJoinMiter
;
635 join
= LineJoinRound
;
639 join
= LineJoinMiter
;
643 m_pen
->SetLineJoin(join
);
645 m_pen
->SetDashStyle(DashStyleSolid
);
647 DashStyle dashStyle
= DashStyleSolid
;
648 switch ( pen
.GetStyle() )
650 case wxPENSTYLE_SOLID
:
653 case wxPENSTYLE_DOT
:
654 dashStyle
= DashStyleDot
;
657 case wxPENSTYLE_LONG_DASH
:
658 dashStyle
= DashStyleDash
; // TODO verify
661 case wxPENSTYLE_SHORT_DASH
:
662 dashStyle
= DashStyleDash
;
665 case wxPENSTYLE_DOT_DASH
:
666 dashStyle
= DashStyleDashDot
;
668 case wxPENSTYLE_USER_DASH
:
670 dashStyle
= DashStyleCustom
;
672 int count
= pen
.GetDashes( &dashes
);
673 if ((dashes
!= NULL
) && (count
> 0))
675 REAL
*userLengths
= new REAL
[count
];
676 for ( int i
= 0; i
< count
; ++i
)
678 userLengths
[i
] = dashes
[i
];
680 m_pen
->SetDashPattern( userLengths
, count
);
681 delete[] userLengths
;
685 case wxPENSTYLE_STIPPLE
:
687 wxBitmap
* bmp
= pen
.GetStipple();
688 if ( bmp
&& bmp
->IsOk() )
690 m_penImage
= Bitmap::FromHBITMAP((HBITMAP
)bmp
->GetHBITMAP(),
692 (HPALETTE
)bmp
->GetPalette()->GetHPALETTE()
697 m_penBrush
= new TextureBrush(m_penImage
);
698 m_pen
->SetBrush( m_penBrush
);
704 if ( pen
.GetStyle() >= wxPENSTYLE_FIRST_HATCH
&&
705 pen
.GetStyle() <= wxPENSTYLE_LAST_HATCH
)
708 switch( pen
.GetStyle() )
710 case wxPENSTYLE_BDIAGONAL_HATCH
:
711 style
= HatchStyleBackwardDiagonal
;
713 case wxPENSTYLE_CROSSDIAG_HATCH
:
714 style
= HatchStyleDiagonalCross
;
716 case wxPENSTYLE_FDIAGONAL_HATCH
:
717 style
= HatchStyleForwardDiagonal
;
719 case wxPENSTYLE_CROSS_HATCH
:
720 style
= HatchStyleCross
;
722 case wxPENSTYLE_HORIZONTAL_HATCH
:
723 style
= HatchStyleHorizontal
;
725 case wxPENSTYLE_VERTICAL_HATCH
:
726 style
= HatchStyleVertical
;
729 style
= HatchStyleHorizontal
;
731 m_penBrush
= new HatchBrush
734 wxColourToColor(pen
.GetColour()),
737 m_pen
->SetBrush( m_penBrush
);
741 if ( dashStyle
!= DashStyleSolid
)
742 m_pen
->SetDashStyle(dashStyle
);
745 //-----------------------------------------------------------------------------
746 // wxGDIPlusBrush implementation
747 //-----------------------------------------------------------------------------
749 wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
)
750 : wxGraphicsObjectRefData(renderer
)
755 wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
)
756 : wxGraphicsObjectRefData(renderer
)
759 if ( brush
.GetStyle() == wxSOLID
)
761 m_brush
= new SolidBrush(wxColourToColor( brush
.GetColour()));
763 else if ( brush
.IsHatch() )
766 switch( brush
.GetStyle() )
768 case wxBRUSHSTYLE_BDIAGONAL_HATCH
:
769 style
= HatchStyleBackwardDiagonal
;
771 case wxBRUSHSTYLE_CROSSDIAG_HATCH
:
772 style
= HatchStyleDiagonalCross
;
774 case wxBRUSHSTYLE_FDIAGONAL_HATCH
:
775 style
= HatchStyleForwardDiagonal
;
777 case wxBRUSHSTYLE_CROSS_HATCH
:
778 style
= HatchStyleCross
;
780 case wxBRUSHSTYLE_HORIZONTAL_HATCH
:
781 style
= HatchStyleHorizontal
;
783 case wxBRUSHSTYLE_VERTICAL_HATCH
:
784 style
= HatchStyleVertical
;
787 style
= HatchStyleHorizontal
;
789 m_brush
= new HatchBrush
792 wxColourToColor(brush
.GetColour()),
798 wxBitmap
* bmp
= brush
.GetStipple();
799 if ( bmp
&& bmp
->IsOk() )
801 wxDELETE( m_brushImage
);
802 m_brushImage
= Bitmap::FromHBITMAP((HBITMAP
)bmp
->GetHBITMAP(),
804 (HPALETTE
)bmp
->GetPalette()->GetHPALETTE()
809 m_brush
= new TextureBrush(m_brushImage
);
814 wxGDIPlusBrushData::~wxGDIPlusBrushData()
821 void wxGDIPlusBrushData::Init()
828 template <typename T
>
830 wxGDIPlusBrushData::SetGradientStops(T
*brush
,
831 const wxGraphicsGradientStops
& stops
)
833 const unsigned numStops
= stops
.GetCount();
836 // initial and final colours are set during the brush creation, nothing
841 wxVector
<Color
> colors(numStops
);
842 wxVector
<REAL
> positions(numStops
);
844 for ( unsigned i
= 0; i
< numStops
; i
++ )
846 wxGraphicsGradientStop stop
= stops
.Item(i
);
848 colors
[i
] = wxColourToColor(stop
.GetColour());
849 positions
[i
] = stop
.GetPosition();
852 brush
->SetInterpolationColors(&colors
[0], &positions
[0], numStops
);
856 wxGDIPlusBrushData::CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
857 wxDouble x2
, wxDouble y2
,
858 const wxGraphicsGradientStops
& stops
)
860 LinearGradientBrush
* const
861 brush
= new LinearGradientBrush(PointF(x1
, y1
) , PointF(x2
, y2
),
862 wxColourToColor(stops
.GetStartColour()),
863 wxColourToColor(stops
.GetEndColour()));
866 SetGradientStops(brush
, stops
);
870 wxGDIPlusBrushData::CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
871 wxDouble xc
, wxDouble yc
,
873 const wxGraphicsGradientStops
& stops
)
875 m_brushPath
= new GraphicsPath();
876 m_brushPath
->AddEllipse( (REAL
)(xc
-radius
), (REAL
)(yc
-radius
),
877 (REAL
)(2*radius
), (REAL
)(2*radius
));
879 PathGradientBrush
* const brush
= new PathGradientBrush(m_brushPath
);
881 brush
->SetCenterPoint(PointF(xo
, yo
));
882 brush
->SetCenterColor(wxColourToColor(stops
.GetStartColour()));
884 const Color
col(wxColourToColor(stops
.GetEndColour()));
886 brush
->SetSurroundColors(&col
, &count
);
888 SetGradientStops(brush
, stops
);
891 //-----------------------------------------------------------------------------
892 // wxGDIPlusFont implementation
893 //-----------------------------------------------------------------------------
896 wxGDIPlusFontData::Init(const wxString
& name
,
902 m_font
= new Font(name
.wc_str(), size
, style
, fontUnit
);
904 m_textBrush
= new SolidBrush(wxColourToColor(col
));
907 wxGDIPlusFontData::wxGDIPlusFontData( wxGraphicsRenderer
* renderer
,
909 const wxColour
& col
)
910 : wxGraphicsObjectRefData( renderer
)
912 int style
= FontStyleRegular
;
913 if ( font
.GetStyle() == wxFONTSTYLE_ITALIC
)
914 style
|= FontStyleItalic
;
915 if ( font
.GetUnderlined() )
916 style
|= FontStyleUnderline
;
917 if ( font
.GetWeight() == wxFONTWEIGHT_BOLD
)
918 style
|= FontStyleBold
;
920 Init(font
.GetFaceName(), font
.GetPointSize(), style
, col
, UnitPoint
);
923 wxGDIPlusFontData::wxGDIPlusFontData(wxGraphicsRenderer
* renderer
,
924 const wxString
& name
,
927 const wxColour
& col
) :
928 wxGraphicsObjectRefData(renderer
)
930 Init(name
, sizeInPixels
, style
, col
, UnitPixel
);
933 wxGDIPlusFontData::~wxGDIPlusFontData()
939 // the built-in conversions functions create non-premultiplied bitmaps, while GDIPlus needs them in the
940 // premultiplied format, therefore in the failing cases we create a new bitmap using the non-premultiplied
941 // bytes as parameter, since there is no real copying of the data going in, only references are stored
942 // m_helper has to be kept alive as well
944 //-----------------------------------------------------------------------------
945 // wxGDIPlusBitmapData implementation
946 //-----------------------------------------------------------------------------
948 wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer
* renderer
, Bitmap
* bitmap
) :
949 wxGraphicsObjectRefData( renderer
), m_bitmap( bitmap
)
954 wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer
* renderer
,
955 const wxBitmap
&bmp
) : wxGraphicsObjectRefData( renderer
)
960 Bitmap
* image
= NULL
;
963 Bitmap
interim((HBITMAP
)bmp
.GetHBITMAP(),
965 (HPALETTE
)bmp
.GetPalette()->GetHPALETTE()
971 size_t width
= interim
.GetWidth();
972 size_t height
= interim
.GetHeight();
973 Rect
bounds(0,0,width
,height
);
975 image
= new Bitmap(width
,height
,PixelFormat32bppPARGB
) ;
977 Bitmap
interimMask((HBITMAP
)bmp
.GetMask()->GetMaskBitmap(),NULL
);
978 wxASSERT(interimMask
.GetPixelFormat() == PixelFormat1bppIndexed
);
980 BitmapData dataMask
;
981 interimMask
.LockBits(&bounds
,ImageLockModeRead
,
982 interimMask
.GetPixelFormat(),&dataMask
);
985 BitmapData imageData
;
986 image
->LockBits(&bounds
,ImageLockModeWrite
, PixelFormat32bppPARGB
, &imageData
);
988 BYTE maskPattern
= 0 ;
992 for ( size_t y
= 0 ; y
< height
; ++y
)
995 for( size_t x
= 0 ; x
< width
; ++x
)
1000 maskByte
= *((BYTE
*)dataMask
.Scan0
+ dataMask
.Stride
*y
+ maskIndex
);
1004 maskPattern
= maskPattern
>> 1;
1006 ARGB
*dest
= (ARGB
*)((BYTE
*)imageData
.Scan0
+ imageData
.Stride
*y
+ x
*4);
1007 if ( (maskByte
& maskPattern
) == 0 )
1012 interim
.GetPixel(x
,y
,&c
) ;
1013 *dest
= (c
.GetValue() | Color::AlphaMask
);
1018 image
->UnlockBits(&imageData
);
1020 interimMask
.UnlockBits(&dataMask
);
1021 interim
.UnlockBits(&dataMask
);
1025 image
= Bitmap::FromHBITMAP((HBITMAP
)bmp
.GetHBITMAP(),
1027 (HPALETTE
)bmp
.GetPalette()->GetHPALETTE()
1032 if ( bmp
.HasAlpha() && GetPixelFormatSize(image
->GetPixelFormat()) == 32 )
1034 size_t width
= image
->GetWidth();
1035 size_t height
= image
->GetHeight();
1036 Rect
bounds(0,0,width
,height
);
1037 static BitmapData data
;
1041 m_helper
->LockBits(&bounds
, ImageLockModeRead
,
1042 m_helper
->GetPixelFormat(),&data
);
1044 image
= new Bitmap(data
.Width
, data
.Height
, data
.Stride
,
1045 PixelFormat32bppPARGB
, (BYTE
*) data
.Scan0
);
1047 m_helper
->UnlockBits(&data
);
1056 wxImage
wxGDIPlusBitmapData::ConvertToImage() const
1058 // We could use Bitmap::LockBits() and convert to wxImage directly but
1059 // passing by wxBitmap is easier. It would be nice to measure performance
1060 // of the two methods but for this the second one would need to be written
1063 if ( m_bitmap
->GetHBITMAP(Color(0xffffffff), &hbmp
) != Gdiplus::Ok
)
1067 bmp
.SetWidth(m_bitmap
->GetWidth());
1068 bmp
.SetHeight(m_bitmap
->GetHeight());
1069 bmp
.SetHBITMAP(hbmp
);
1070 bmp
.SetDepth(IsAlphaPixelFormat(m_bitmap
->GetPixelFormat()) ? 32 : 24);
1071 return bmp
.ConvertToImage();
1074 #endif // wxUSE_IMAGE
1076 wxGDIPlusBitmapData::~wxGDIPlusBitmapData()
1082 //-----------------------------------------------------------------------------
1083 // wxGDIPlusPath implementation
1084 //-----------------------------------------------------------------------------
1086 wxGDIPlusPathData::wxGDIPlusPathData(wxGraphicsRenderer
* renderer
, GraphicsPath
* path
) : wxGraphicsPathData(renderer
)
1091 m_path
= new GraphicsPath();
1094 wxGDIPlusPathData::~wxGDIPlusPathData()
1099 wxGraphicsObjectRefData
* wxGDIPlusPathData::Clone() const
1101 return new wxGDIPlusPathData( GetRenderer() , m_path
->Clone());
1108 void wxGDIPlusPathData::MoveToPoint( wxDouble x
, wxDouble y
)
1110 m_path
->StartFigure();
1111 m_path
->AddLine((REAL
) x
,(REAL
) y
,(REAL
) x
,(REAL
) y
);
1114 void wxGDIPlusPathData::AddLineToPoint( wxDouble x
, wxDouble y
)
1116 m_path
->AddLine((REAL
) x
,(REAL
) y
,(REAL
) x
,(REAL
) y
);
1119 void wxGDIPlusPathData::CloseSubpath()
1121 m_path
->CloseFigure();
1124 void wxGDIPlusPathData::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
1130 m_path
->GetLastPoint(&start
);
1131 m_path
->AddBezier(start
,c1
,c2
,end
);
1134 // gets the last point of the current path, (0,0) if not yet set
1135 void wxGDIPlusPathData::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
1138 m_path
->GetLastPoint(&start
);
1143 void wxGDIPlusPathData::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, double startAngle
, double endAngle
, bool clockwise
)
1145 double sweepAngle
= endAngle
- startAngle
;
1146 if( fabs(sweepAngle
) >= 2*M_PI
)
1148 sweepAngle
= 2 * M_PI
;
1154 if( sweepAngle
< 0 )
1155 sweepAngle
+= 2 * M_PI
;
1159 if( sweepAngle
> 0 )
1160 sweepAngle
-= 2 * M_PI
;
1164 m_path
->AddArc((REAL
) (x
-r
),(REAL
) (y
-r
),(REAL
) (2*r
),(REAL
) (2*r
),RadToDeg(startAngle
),RadToDeg(sweepAngle
));
1167 void wxGDIPlusPathData::AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1169 m_path
->AddRectangle(RectF(x
,y
,w
,h
));
1172 void wxGDIPlusPathData::AddPath( const wxGraphicsPathData
* path
)
1174 m_path
->AddPath( (GraphicsPath
*) path
->GetNativePath(), FALSE
);
1178 // transforms each point of this path by the matrix
1179 void wxGDIPlusPathData::Transform( const wxGraphicsMatrixData
* matrix
)
1181 m_path
->Transform( (Matrix
*) matrix
->GetNativeMatrix() );
1184 // gets the bounding box enclosing all points (possibly including control points)
1185 void wxGDIPlusPathData::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
1188 m_path
->GetBounds( &bounds
, NULL
, NULL
) ;
1195 bool wxGDIPlusPathData::Contains( wxDouble x
, wxDouble y
, wxPolygonFillMode fillStyle
) const
1197 m_path
->SetFillMode( fillStyle
== wxODDEVEN_RULE
? FillModeAlternate
: FillModeWinding
);
1198 return m_path
->IsVisible( (FLOAT
) x
,(FLOAT
) y
) == TRUE
;
1201 //-----------------------------------------------------------------------------
1202 // wxGDIPlusMatrixData implementation
1203 //-----------------------------------------------------------------------------
1205 wxGDIPlusMatrixData::wxGDIPlusMatrixData(wxGraphicsRenderer
* renderer
, Matrix
* matrix
)
1206 : wxGraphicsMatrixData(renderer
)
1211 m_matrix
= new Matrix();
1214 wxGDIPlusMatrixData::~wxGDIPlusMatrixData()
1219 wxGraphicsObjectRefData
*wxGDIPlusMatrixData::Clone() const
1221 return new wxGDIPlusMatrixData( GetRenderer(), m_matrix
->Clone());
1224 // concatenates the matrix
1225 void wxGDIPlusMatrixData::Concat( const wxGraphicsMatrixData
*t
)
1227 m_matrix
->Multiply( (Matrix
*) t
->GetNativeMatrix());
1230 // sets the matrix to the respective values
1231 void wxGDIPlusMatrixData::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
1232 wxDouble tx
, wxDouble ty
)
1234 m_matrix
->SetElements(a
,b
,c
,d
,tx
,ty
);
1237 // gets the component valuess of the matrix
1238 void wxGDIPlusMatrixData::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
1239 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
1242 m_matrix
->GetElements(elements
);
1243 if (a
) *a
= elements
[0];
1244 if (b
) *b
= elements
[1];
1245 if (c
) *c
= elements
[2];
1246 if (d
) *d
= elements
[3];
1247 if (tx
) *tx
= elements
[4];
1248 if (ty
) *ty
= elements
[5];
1251 // makes this the inverse matrix
1252 void wxGDIPlusMatrixData::Invert()
1257 // returns true if the elements of the transformation matrix are equal ?
1258 bool wxGDIPlusMatrixData::IsEqual( const wxGraphicsMatrixData
* t
) const
1260 return m_matrix
->Equals((Matrix
*) t
->GetNativeMatrix())== TRUE
;
1263 // return true if this is the identity matrix
1264 bool wxGDIPlusMatrixData::IsIdentity() const
1266 return m_matrix
->IsIdentity() == TRUE
;
1273 // add the translation to this matrix
1274 void wxGDIPlusMatrixData::Translate( wxDouble dx
, wxDouble dy
)
1276 m_matrix
->Translate(dx
,dy
);
1279 // add the scale to this matrix
1280 void wxGDIPlusMatrixData::Scale( wxDouble xScale
, wxDouble yScale
)
1282 m_matrix
->Scale(xScale
,yScale
);
1285 // add the rotation to this matrix (radians)
1286 void wxGDIPlusMatrixData::Rotate( wxDouble angle
)
1288 m_matrix
->Rotate( RadToDeg(angle
) );
1292 // apply the transforms
1295 // applies that matrix to the point
1296 void wxGDIPlusMatrixData::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
1299 m_matrix
->TransformPoints(&pt
);
1304 // applies the matrix except for translations
1305 void wxGDIPlusMatrixData::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
1308 m_matrix
->TransformVectors(&pt
);
1313 // returns the native representation
1314 void * wxGDIPlusMatrixData::GetNativeMatrix() const
1319 //-----------------------------------------------------------------------------
1320 // wxGDIPlusContext implementation
1321 //-----------------------------------------------------------------------------
1323 class wxGDIPlusOffsetHelper
1326 wxGDIPlusOffsetHelper( Graphics
* gr
, bool offset
)
1331 m_gr
->TranslateTransform( 0.5, 0.5 );
1333 ~wxGDIPlusOffsetHelper( )
1336 m_gr
->TranslateTransform( -0.5, -0.5 );
1343 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HDC hdc
, wxDouble width
, wxDouble height
)
1344 : wxGraphicsContext(renderer
)
1346 Init(new Graphics(hdc
), width
, height
);
1349 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, const wxDC
& dc
)
1350 : wxGraphicsContext(renderer
)
1352 wxMSWDCImpl
*msw
= wxDynamicCast( dc
.GetImpl() , wxMSWDCImpl
);
1353 HDC hdc
= (HDC
) msw
->GetHDC();
1354 wxSize sz
= dc
.GetSize();
1356 Init(new Graphics(hdc
), sz
.x
, sz
.y
);
1359 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HWND hwnd
)
1360 : wxGraphicsContext(renderer
)
1362 RECT rect
= wxGetWindowRect(hwnd
);
1363 Init(new Graphics(hwnd
), rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
1364 m_enableOffset
= true;
1367 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, Graphics
* gr
)
1368 : wxGraphicsContext(renderer
)
1373 wxGDIPlusContext::wxGDIPlusContext(wxGraphicsRenderer
* renderer
)
1374 : wxGraphicsContext(renderer
)
1376 // Derived class must call Init() later but just set m_context to NULL for
1377 // safety to avoid crashing in our dtor if Init() ends up not being called.
1381 void wxGDIPlusContext::Init(Graphics
* graphics
, int width
, int height
)
1383 m_context
= graphics
;
1388 m_fontScaleRatio
= 1.0;
1390 m_context
->SetTextRenderingHint(TextRenderingHintSystemDefault
);
1391 m_context
->SetPixelOffsetMode(PixelOffsetModeHalf
);
1392 m_context
->SetSmoothingMode(SmoothingModeHighQuality
);
1393 m_context
->SetInterpolationMode(InterpolationModeHighQuality
);
1394 m_state1
= m_context
->Save();
1395 m_state2
= m_context
->Save();
1398 wxGDIPlusContext::~wxGDIPlusContext()
1402 m_context
->Restore( m_state2
);
1403 m_context
->Restore( m_state1
);
1409 void wxGDIPlusContext::Clip( const wxRegion
®ion
)
1411 Region
rgn((HRGN
)region
.GetHRGN());
1412 m_context
->SetClip(&rgn
,CombineModeIntersect
);
1415 void wxGDIPlusContext::Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1417 m_context
->SetClip(RectF(x
,y
,w
,h
),CombineModeIntersect
);
1420 void wxGDIPlusContext::ResetClip()
1422 m_context
->ResetClip();
1425 void wxGDIPlusContext::DrawRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1427 if (m_composition
== wxCOMPOSITION_DEST
)
1430 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1431 Brush
*brush
= m_brush
.IsNull() ? NULL
: ((wxGDIPlusBrushData
*)m_brush
.GetRefData())->GetGDIPlusBrush();
1432 Pen
*pen
= m_pen
.IsNull() ? NULL
: ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen();
1436 // the offset is used to fill only the inside of the rectangle and not paint underneath
1437 // its border which may influence a transparent Pen
1440 offset
= pen
->GetWidth();
1441 m_context
->FillRectangle( brush
, (REAL
)x
+ offset
/2, (REAL
)y
+ offset
/2, (REAL
)w
- offset
, (REAL
)h
- offset
);
1446 m_context
->DrawRectangle( pen
, (REAL
)x
, (REAL
)y
, (REAL
)w
, (REAL
)h
);
1450 void wxGDIPlusContext::StrokeLines( size_t n
, const wxPoint2DDouble
*points
)
1452 if (m_composition
== wxCOMPOSITION_DEST
)
1455 if ( !m_pen
.IsNull() )
1457 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1458 Point
*cpoints
= new Point
[n
];
1459 for (size_t i
= 0; i
< n
; i
++)
1461 cpoints
[i
].X
= (int)(points
[i
].m_x
);
1462 cpoints
[i
].Y
= (int)(points
[i
].m_y
);
1464 } // for (size_t i = 0; i < n; i++)
1465 m_context
->DrawLines( ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen() , cpoints
, n
) ;
1470 void wxGDIPlusContext::DrawLines( size_t n
, const wxPoint2DDouble
*points
, wxPolygonFillMode
WXUNUSED(fillStyle
) )
1472 if (m_composition
== wxCOMPOSITION_DEST
)
1475 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1476 Point
*cpoints
= new Point
[n
];
1477 for (size_t i
= 0; i
< n
; i
++)
1479 cpoints
[i
].X
= (int)(points
[i
].m_x
);
1480 cpoints
[i
].Y
= (int)(points
[i
].m_y
);
1482 } // for (int i = 0; i < n; i++)
1483 if ( !m_brush
.IsNull() )
1484 m_context
->FillPolygon( ((wxGDIPlusBrushData
*)m_brush
.GetRefData())->GetGDIPlusBrush() , cpoints
, n
) ;
1485 if ( !m_pen
.IsNull() )
1486 m_context
->DrawLines( ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen() , cpoints
, n
) ;
1490 void wxGDIPlusContext::StrokePath( const wxGraphicsPath
& path
)
1492 if (m_composition
== wxCOMPOSITION_DEST
)
1495 if ( !m_pen
.IsNull() )
1497 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1498 m_context
->DrawPath( ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen() , (GraphicsPath
*) path
.GetNativePath() );
1502 void wxGDIPlusContext::FillPath( const wxGraphicsPath
& path
, wxPolygonFillMode fillStyle
)
1504 if (m_composition
== wxCOMPOSITION_DEST
)
1507 if ( !m_brush
.IsNull() )
1509 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1510 ((GraphicsPath
*) path
.GetNativePath())->SetFillMode( fillStyle
== wxODDEVEN_RULE
? FillModeAlternate
: FillModeWinding
);
1511 m_context
->FillPath( ((wxGDIPlusBrushData
*)m_brush
.GetRefData())->GetGDIPlusBrush() ,
1512 (GraphicsPath
*) path
.GetNativePath());
1516 bool wxGDIPlusContext::SetAntialiasMode(wxAntialiasMode antialias
)
1518 if (m_antialias
== antialias
)
1521 m_antialias
= antialias
;
1523 SmoothingMode antialiasMode
;
1526 case wxANTIALIAS_DEFAULT
:
1527 antialiasMode
= SmoothingModeHighQuality
;
1529 case wxANTIALIAS_NONE
:
1530 antialiasMode
= SmoothingModeNone
;
1535 m_context
->SetSmoothingMode(antialiasMode
);
1539 bool wxGDIPlusContext::SetInterpolationQuality(wxInterpolationQuality interpolation
)
1541 if (m_interpolation
== interpolation
)
1544 m_interpolation
= interpolation
;
1546 InterpolationMode interpolationMode
= InterpolationModeDefault
;
1547 switch (interpolation
)
1549 case wxINTERPOLATION_DEFAULT
:
1550 interpolationMode
= InterpolationModeDefault
;
1553 case wxINTERPOLATION_NONE
:
1554 interpolationMode
= InterpolationModeNearestNeighbor
;
1557 case wxINTERPOLATION_FAST
:
1558 interpolationMode
= InterpolationModeLowQuality
;
1561 case wxINTERPOLATION_GOOD
:
1562 interpolationMode
= InterpolationModeHighQuality
;
1565 case wxINTERPOLATION_BEST
:
1566 interpolationMode
= InterpolationModeHighQualityBicubic
;
1572 m_context
->SetInterpolationMode(interpolationMode
);
1576 bool wxGDIPlusContext::SetCompositionMode(wxCompositionMode op
)
1578 if ( m_composition
== op
)
1583 if (m_composition
== wxCOMPOSITION_DEST
)
1586 CompositingMode cop
;
1589 case wxCOMPOSITION_SOURCE
:
1590 cop
= CompositingModeSourceCopy
;
1592 case wxCOMPOSITION_OVER
:
1593 cop
= CompositingModeSourceOver
;
1599 m_context
->SetCompositingMode(cop
);
1603 void wxGDIPlusContext::BeginLayer(wxDouble
/* opacity */)
1608 void wxGDIPlusContext::EndLayer()
1613 void wxGDIPlusContext::Rotate( wxDouble angle
)
1615 m_context
->RotateTransform( RadToDeg(angle
) );
1618 void wxGDIPlusContext::Translate( wxDouble dx
, wxDouble dy
)
1620 m_context
->TranslateTransform( dx
, dy
);
1623 void wxGDIPlusContext::Scale( wxDouble xScale
, wxDouble yScale
)
1625 m_context
->ScaleTransform(xScale
,yScale
);
1628 void wxGDIPlusContext::PushState()
1630 GraphicsState state
= m_context
->Save();
1631 m_stateStack
.push(state
);
1634 void wxGDIPlusContext::PopState()
1636 wxCHECK_RET( !m_stateStack
.empty(), wxT("No state to pop") );
1638 GraphicsState state
= m_stateStack
.top();
1640 m_context
->Restore(state
);
1643 void wxGDIPlusContext::DrawBitmap( const wxGraphicsBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1645 if (m_composition
== wxCOMPOSITION_DEST
)
1648 Bitmap
* image
= static_cast<wxGDIPlusBitmapData
*>(bmp
.GetRefData())->GetGDIPlusBitmap();
1651 if( image
->GetWidth() != (UINT
) w
|| image
->GetHeight() != (UINT
) h
)
1653 Rect
drawRect((REAL
) x
, (REAL
)y
, (REAL
)w
, (REAL
)h
);
1654 m_context
->SetPixelOffsetMode( PixelOffsetModeNone
);
1655 m_context
->DrawImage(image
, drawRect
, 0 , 0 , image
->GetWidth(), image
->GetHeight(), UnitPixel
) ;
1656 m_context
->SetPixelOffsetMode( PixelOffsetModeHalf
);
1659 m_context
->DrawImage(image
,(REAL
) x
,(REAL
) y
,(REAL
) w
,(REAL
) h
) ;
1663 void wxGDIPlusContext::DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1665 wxGraphicsBitmap bitmap
= GetRenderer()->CreateBitmap(bmp
);
1666 DrawBitmap(bitmap
, x
, y
, w
, h
);
1669 void wxGDIPlusContext::DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1671 if (m_composition
== wxCOMPOSITION_DEST
)
1674 // the built-in conversion fails when there is alpha in the HICON (eg XP style icons), we can only
1675 // find out by looking at the bitmap data whether there really was alpha in it
1676 HICON hIcon
= (HICON
)icon
.GetHICON();
1678 // IconInfo creates the bitmaps for color and mask, we must dispose of them after use
1679 if (!GetIconInfo(hIcon
,&iconInfo
))
1682 Bitmap
interim(iconInfo
.hbmColor
,NULL
);
1684 Bitmap
* image
= NULL
;
1686 // if it's not 32 bit, it doesn't have an alpha channel, note that since the conversion doesn't
1687 // work correctly, asking IsAlphaPixelFormat at this point fails as well
1688 if( GetPixelFormatSize(interim
.GetPixelFormat())!= 32 )
1690 image
= Bitmap::FromHICON(hIcon
);
1694 size_t width
= interim
.GetWidth();
1695 size_t height
= interim
.GetHeight();
1696 Rect
bounds(0,0,width
,height
);
1699 interim
.LockBits(&bounds
, ImageLockModeRead
,
1700 interim
.GetPixelFormat(),&data
);
1702 bool hasAlpha
= false;
1703 for ( size_t y
= 0 ; y
< height
&& !hasAlpha
; ++y
)
1705 for( size_t x
= 0 ; x
< width
&& !hasAlpha
; ++x
)
1707 ARGB
*dest
= (ARGB
*)((BYTE
*)data
.Scan0
+ data
.Stride
*y
+ x
*4);
1708 if ( ( *dest
& Color::AlphaMask
) != 0 )
1715 image
= new Bitmap(data
.Width
, data
.Height
, data
.Stride
,
1716 PixelFormat32bppARGB
, (BYTE
*) data
.Scan0
);
1720 image
= Bitmap::FromHICON(hIcon
);
1723 interim
.UnlockBits(&data
);
1726 m_context
->DrawImage(image
,(REAL
) x
,(REAL
) y
,(REAL
) w
,(REAL
) h
) ;
1729 DeleteObject(iconInfo
.hbmColor
);
1730 DeleteObject(iconInfo
.hbmMask
);
1733 void wxGDIPlusContext::DoDrawFilledText(const wxString
& str
,
1734 wxDouble x
, wxDouble y
,
1735 const wxGraphicsBrush
& brush
)
1737 if (m_composition
== wxCOMPOSITION_DEST
)
1740 wxCHECK_RET( !m_font
.IsNull(),
1741 wxT("wxGDIPlusContext::DrawText - no valid font set") );
1746 wxGDIPlusFontData
* const
1747 fontData
= (wxGDIPlusFontData
*)m_font
.GetRefData();
1748 wxGDIPlusBrushData
* const
1749 brushData
= (wxGDIPlusBrushData
*)brush
.GetRefData();
1751 m_context
->DrawString
1753 str
.wc_str(*wxConvUI
), // string to draw, always Unicode
1754 -1, // length: string is NUL-terminated
1755 fontData
->GetGDIPlusFont(),
1757 StringFormat::GenericTypographic(),
1758 brushData
? brushData
->GetGDIPlusBrush()
1759 : fontData
->GetGDIPlusBrush()
1763 void wxGDIPlusContext::GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
1764 wxDouble
*descent
, wxDouble
*externalLeading
) const
1766 wxCHECK_RET( !m_font
.IsNull(), wxT("wxGDIPlusContext::GetTextExtent - no valid font set") );
1768 wxWCharBuffer s
= str
.wc_str( *wxConvUI
);
1769 FontFamily ffamily
;
1770 Font
* f
= ((wxGDIPlusFontData
*)m_font
.GetRefData())->GetGDIPlusFont();
1772 f
->GetFamily(&ffamily
) ;
1774 REAL factorY
= m_fontScaleRatio
;
1776 REAL rDescent
= ffamily
.GetCellDescent(FontStyleRegular
) *
1777 f
->GetSize() / ffamily
.GetEmHeight(FontStyleRegular
);
1778 REAL rAscent
= ffamily
.GetCellAscent(FontStyleRegular
) *
1779 f
->GetSize() / ffamily
.GetEmHeight(FontStyleRegular
);
1780 REAL rHeight
= ffamily
.GetLineSpacing(FontStyleRegular
) *
1781 f
->GetSize() / ffamily
.GetEmHeight(FontStyleRegular
);
1784 *height
= rHeight
* factorY
;
1786 *descent
= rDescent
* factorY
;
1787 if ( externalLeading
)
1788 *externalLeading
= (rHeight
- rAscent
- rDescent
) * factorY
;
1789 // measuring empty strings is not guaranteed, so do it by hand
1797 RectF
layoutRect(0,0, 100000.0f
, 100000.0f
);
1798 StringFormat
strFormat( StringFormat::GenericTypographic() );
1799 strFormat
.SetFormatFlags( StringFormatFlagsMeasureTrailingSpaces
| strFormat
.GetFormatFlags() );
1802 m_context
->MeasureString((const wchar_t *) s
, wcslen(s
) , f
, layoutRect
, &strFormat
, &bounds
) ;
1804 *width
= bounds
.Width
;
1806 *height
= bounds
.Height
;
1810 void wxGDIPlusContext::GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const
1813 widths
.Add(0, text
.length());
1815 wxCHECK_RET( !m_font
.IsNull(), wxT("wxGDIPlusContext::GetPartialTextExtents - no valid font set") );
1820 Font
* f
= ((wxGDIPlusFontData
*)m_font
.GetRefData())->GetGDIPlusFont();
1821 wxWCharBuffer ws
= text
.wc_str( *wxConvUI
);
1822 size_t len
= wcslen( ws
) ;
1823 wxASSERT_MSG(text
.length() == len
, wxT("GetPartialTextExtents not yet implemented for multichar situations"));
1825 RectF
layoutRect(0,0, 100000.0f
, 100000.0f
);
1826 StringFormat
strFormat( StringFormat::GenericTypographic() );
1828 size_t startPosition
= 0;
1829 size_t remainder
= len
;
1830 const size_t maxSpan
= 32;
1831 CharacterRange
* ranges
= new CharacterRange
[maxSpan
] ;
1832 Region
* regions
= new Region
[maxSpan
];
1834 while( remainder
> 0 )
1836 size_t span
= wxMin( maxSpan
, remainder
);
1838 for( size_t i
= 0 ; i
< span
; ++i
)
1840 ranges
[i
].First
= 0 ;
1841 ranges
[i
].Length
= startPosition
+i
+1 ;
1843 strFormat
.SetMeasurableCharacterRanges(span
,ranges
);
1844 strFormat
.SetFormatFlags( StringFormatFlagsMeasureTrailingSpaces
| strFormat
.GetFormatFlags() );
1845 m_context
->MeasureCharacterRanges(ws
, -1 , f
,layoutRect
, &strFormat
,span
,regions
) ;
1848 for ( size_t i
= 0 ; i
< span
; ++i
)
1850 regions
[i
].GetBounds(&bbox
,m_context
);
1851 widths
[startPosition
+i
] = bbox
.Width
;
1854 startPosition
+= span
;
1861 bool wxGDIPlusContext::ShouldOffset() const
1863 if ( !m_enableOffset
)
1867 if ( !m_pen
.IsNull() )
1869 penwidth
= (int)((wxGDIPlusPenData
*)m_pen
.GetRefData())->GetWidth();
1870 if ( penwidth
== 0 )
1873 return ( penwidth
% 2 ) == 1;
1876 void* wxGDIPlusContext::GetNativeContext()
1881 // concatenates this transform with the current transform of this context
1882 void wxGDIPlusContext::ConcatTransform( const wxGraphicsMatrix
& matrix
)
1884 m_context
->MultiplyTransform((Matrix
*) matrix
.GetNativeMatrix());
1887 // sets the transform of this context
1888 void wxGDIPlusContext::SetTransform( const wxGraphicsMatrix
& matrix
)
1890 m_context
->SetTransform((Matrix
*) matrix
.GetNativeMatrix());
1893 // gets the matrix of this context
1894 wxGraphicsMatrix
wxGDIPlusContext::GetTransform() const
1896 wxGraphicsMatrix matrix
= CreateMatrix();
1897 m_context
->GetTransform((Matrix
*) matrix
.GetNativeMatrix());
1901 void wxGDIPlusContext::GetSize( wxDouble
* width
, wxDouble
*height
)
1907 //-----------------------------------------------------------------------------
1908 // wxGDIPlusPrintingContext implementation
1909 //-----------------------------------------------------------------------------
1911 wxGDIPlusPrintingContext::wxGDIPlusPrintingContext( wxGraphicsRenderer
* renderer
,
1913 : wxGDIPlusContext(renderer
, dc
)
1915 Graphics
* context
= GetGraphics();
1917 //m_context->SetPageUnit(UnitDocument);
1919 // Setup page scale, based on DPI ratio.
1920 // Antecedent should be 100dpi when the default page unit
1921 // (UnitDisplay) is used. Page unit UnitDocument would require 300dpi
1922 // instead. Note that calling SetPageScale() does not have effect on
1923 // non-printing DCs (that is, any other than wxPrinterDC or
1924 // wxEnhMetaFileDC).
1925 REAL dpiRatio
= 100.0 / context
->GetDpiY();
1926 context
->SetPageScale(dpiRatio
);
1928 // We use this modifier when measuring fonts. It is needed because the
1929 // page scale is modified above.
1930 m_fontScaleRatio
= context
->GetDpiY() / 72.0;
1933 //-----------------------------------------------------------------------------
1934 // wxGDIPlusRenderer implementation
1935 //-----------------------------------------------------------------------------
1937 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRenderer
,wxGraphicsRenderer
)
1939 static wxGDIPlusRenderer gs_GDIPlusRenderer
;
1941 wxGraphicsRenderer
* wxGraphicsRenderer::GetDefaultRenderer()
1943 return &gs_GDIPlusRenderer
;
1946 bool wxGDIPlusRenderer::EnsureIsLoaded()
1948 // load gdiplus.dll if not yet loaded, but don't bother doing it again
1949 // if we already tried and failed (we don't want to spend lot of time
1950 // returning NULL from wxGraphicsContext::Create(), which may be called
1951 // relatively frequently):
1952 if ( m_loaded
== -1 )
1957 return m_loaded
== 1;
1960 // call EnsureIsLoaded() and return returnOnFail value if it fails
1961 #define ENSURE_LOADED_OR_RETURN(returnOnFail) \
1962 if ( !EnsureIsLoaded() ) \
1963 return (returnOnFail)
1966 void wxGDIPlusRenderer::Load()
1968 GdiplusStartupInput input
;
1969 GdiplusStartupOutput output
;
1970 if ( GdiplusStartup(&m_gditoken
,&input
,&output
) == Gdiplus::Ok
)
1972 wxLogTrace("gdiplus", "successfully initialized GDI+");
1977 wxLogTrace("gdiplus", "failed to initialize GDI+, missing gdiplus.dll?");
1982 void wxGDIPlusRenderer::Unload()
1986 GdiplusShutdown(m_gditoken
);
1989 m_loaded
= -1; // next Load() will try again
1992 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxWindowDC
& dc
)
1994 ENSURE_LOADED_OR_RETURN(NULL
);
1995 wxGDIPlusContext
* context
= new wxGDIPlusContext(this, dc
);
1996 context
->EnableOffset(true);
2000 #if wxUSE_PRINTING_ARCHITECTURE
2001 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxPrinterDC
& dc
)
2003 ENSURE_LOADED_OR_RETURN(NULL
);
2004 wxGDIPlusContext
* context
= new wxGDIPlusPrintingContext(this, dc
);
2009 #if wxUSE_ENH_METAFILE
2010 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxEnhMetaFileDC
& dc
)
2012 ENSURE_LOADED_OR_RETURN(NULL
);
2013 wxGDIPlusContext
* context
= new wxGDIPlusPrintingContext(this, dc
);
2018 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxMemoryDC
& dc
)
2020 ENSURE_LOADED_OR_RETURN(NULL
);
2021 wxGDIPlusContext
* context
= new wxGDIPlusContext(this, dc
);
2022 context
->EnableOffset(true);
2027 wxGraphicsContext
* wxGDIPlusRenderer::CreateContextFromImage(wxImage
& image
)
2029 ENSURE_LOADED_OR_RETURN(NULL
);
2030 wxGDIPlusContext
* context
= new wxGDIPlusImageContext(this, image
);
2031 context
->EnableOffset(true);
2035 #endif // wxUSE_IMAGE
2037 wxGraphicsContext
* wxGDIPlusRenderer::CreateMeasuringContext()
2039 ENSURE_LOADED_OR_RETURN(NULL
);
2040 return new wxGDIPlusMeasuringContext(this);
2043 wxGraphicsContext
* wxGDIPlusRenderer::CreateContextFromNativeContext( void * context
)
2045 ENSURE_LOADED_OR_RETURN(NULL
);
2046 return new wxGDIPlusContext(this,(Graphics
*) context
);
2050 wxGraphicsContext
* wxGDIPlusRenderer::CreateContextFromNativeWindow( void * window
)
2052 ENSURE_LOADED_OR_RETURN(NULL
);
2053 return new wxGDIPlusContext(this,(HWND
) window
);
2056 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( wxWindow
* window
)
2058 ENSURE_LOADED_OR_RETURN(NULL
);
2059 return new wxGDIPlusContext(this, (HWND
) window
->GetHWND() );
2064 wxGraphicsPath
wxGDIPlusRenderer::CreatePath()
2066 ENSURE_LOADED_OR_RETURN(wxNullGraphicsPath
);
2068 m
.SetRefData( new wxGDIPlusPathData(this));
2075 wxGraphicsMatrix
wxGDIPlusRenderer::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
2076 wxDouble tx
, wxDouble ty
)
2079 ENSURE_LOADED_OR_RETURN(wxNullGraphicsMatrix
);
2081 wxGDIPlusMatrixData
* data
= new wxGDIPlusMatrixData( this );
2082 data
->Set( a
,b
,c
,d
,tx
,ty
) ;
2087 wxGraphicsPen
wxGDIPlusRenderer::CreatePen(const wxPen
& pen
)
2089 ENSURE_LOADED_OR_RETURN(wxNullGraphicsPen
);
2090 if ( !pen
.IsOk() || pen
.GetStyle() == wxTRANSPARENT
)
2091 return wxNullGraphicsPen
;
2095 p
.SetRefData(new wxGDIPlusPenData( this, pen
));
2100 wxGraphicsBrush
wxGDIPlusRenderer::CreateBrush(const wxBrush
& brush
)
2102 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush
);
2103 if ( !brush
.IsOk() || brush
.GetStyle() == wxTRANSPARENT
)
2104 return wxNullGraphicsBrush
;
2108 p
.SetRefData(new wxGDIPlusBrushData( this, brush
));
2114 wxGDIPlusRenderer::CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
2115 wxDouble x2
, wxDouble y2
,
2116 const wxGraphicsGradientStops
& stops
)
2118 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush
);
2120 wxGDIPlusBrushData
* d
= new wxGDIPlusBrushData( this );
2121 d
->CreateLinearGradientBrush(x1
, y1
, x2
, y2
, stops
);
2127 wxGDIPlusRenderer::CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
2128 wxDouble xc
, wxDouble yc
,
2130 const wxGraphicsGradientStops
& stops
)
2132 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush
);
2134 wxGDIPlusBrushData
* d
= new wxGDIPlusBrushData( this );
2135 d
->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,stops
);
2141 wxGDIPlusRenderer::CreateFont( const wxFont
&font
,
2142 const wxColour
&col
)
2144 ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont
);
2148 p
.SetRefData(new wxGDIPlusFontData( this, font
, col
));
2152 return wxNullGraphicsFont
;
2156 wxGDIPlusRenderer::CreateFont(double size
,
2157 const wxString
& facename
,
2159 const wxColour
& col
)
2161 ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont
);
2163 // Convert wxFont flags to GDI+ style:
2164 int style
= FontStyleRegular
;
2165 if ( flags
& wxFONTFLAG_ITALIC
)
2166 style
|= FontStyleItalic
;
2167 if ( flags
& wxFONTFLAG_UNDERLINED
)
2168 style
|= FontStyleUnderline
;
2169 if ( flags
& wxFONTFLAG_BOLD
)
2170 style
|= FontStyleBold
;
2171 if ( flags
& wxFONTFLAG_STRIKETHROUGH
)
2172 style
|= FontStyleStrikeout
;
2176 f
.SetRefData(new wxGDIPlusFontData(this, facename
, size
, style
, col
));
2180 wxGraphicsBitmap
wxGDIPlusRenderer::CreateBitmap( const wxBitmap
&bitmap
)
2182 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap
);
2183 if ( bitmap
.IsOk() )
2186 p
.SetRefData(new wxGDIPlusBitmapData( this , bitmap
));
2190 return wxNullGraphicsBitmap
;
2195 wxGraphicsBitmap
wxGDIPlusRenderer::CreateBitmapFromImage(const wxImage
& image
)
2197 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap
);
2200 // Notice that we rely on conversion from wxImage to wxBitmap here but
2201 // we could probably do it more efficiently by converting from wxImage
2202 // to GDI+ Bitmap directly, i.e. copying wxImage pixels to the buffer
2203 // returned by Bitmap::LockBits(). However this would require writing
2204 // code specific for this task while like this we can reuse existing
2205 // code (see also wxGDIPlusBitmapData::ConvertToImage()).
2206 wxGraphicsBitmap gb
;
2207 gb
.SetRefData(new wxGDIPlusBitmapData(this, image
));
2211 return wxNullGraphicsBitmap
;
2215 wxImage
wxGDIPlusRenderer::CreateImageFromBitmap(const wxGraphicsBitmap
& bmp
)
2217 ENSURE_LOADED_OR_RETURN(wxNullImage
);
2218 const wxGDIPlusBitmapData
* const
2219 data
= static_cast<wxGDIPlusBitmapData
*>(bmp
.GetGraphicsData());
2221 return data
? data
->ConvertToImage() : wxNullImage
;
2224 #endif // wxUSE_IMAGE
2227 wxGraphicsBitmap
wxGDIPlusRenderer::CreateBitmapFromNativeBitmap( void *bitmap
)
2229 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap
);
2230 if ( bitmap
!= NULL
)
2233 p
.SetRefData(new wxGDIPlusBitmapData( this , (Bitmap
*) bitmap
));
2237 return wxNullGraphicsBitmap
;
2240 wxGraphicsBitmap
wxGDIPlusRenderer::CreateSubBitmap( const wxGraphicsBitmap
&bitmap
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
2242 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap
);
2243 Bitmap
* image
= static_cast<wxGDIPlusBitmapData
*>(bitmap
.GetRefData())->GetGDIPlusBitmap();
2247 p
.SetRefData(new wxGDIPlusBitmapData( this , image
->Clone( (REAL
) x
, (REAL
) y
, (REAL
) w
, (REAL
) h
, PixelFormat32bppPARGB
) ));
2251 return wxNullGraphicsBitmap
;
2254 // Shutdown GDI+ at app exit, before possible dll unload
2255 class wxGDIPlusRendererModule
: public wxModule
2258 virtual bool OnInit() { return true; }
2259 virtual void OnExit() { gs_GDIPlusRenderer
.Unload(); }
2262 DECLARE_DYNAMIC_CLASS(wxGDIPlusRendererModule
)
2265 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRendererModule
, wxModule
)
2267 // ----------------------------------------------------------------------------
2268 // wxMSW-specific parts of wxGCDC
2269 // ----------------------------------------------------------------------------
2271 WXHDC
wxGCDC::AcquireHDC()
2273 wxGraphicsContext
* const gc
= GetGraphicsContext();
2278 // we can't get the HDC if it is not a GDI+ context
2279 wxGraphicsRenderer
* r1
= gc
->GetRenderer();
2280 wxGraphicsRenderer
* r2
= wxGraphicsRenderer::GetCairoRenderer();
2285 Graphics
* const g
= static_cast<Graphics
*>(gc
->GetNativeContext());
2286 return g
? g
->GetHDC() : NULL
;
2289 void wxGCDC::ReleaseHDC(WXHDC hdc
)
2294 wxGraphicsContext
* const gc
= GetGraphicsContext();
2295 wxCHECK_RET( gc
, "can't release HDC because there is no wxGraphicsContext" );
2298 // we can't get the HDC if it is not a GDI+ context
2299 wxGraphicsRenderer
* r1
= gc
->GetRenderer();
2300 wxGraphicsRenderer
* r2
= wxGraphicsRenderer::GetCairoRenderer();
2305 Graphics
* const g
= static_cast<Graphics
*>(gc
->GetNativeContext());
2306 wxCHECK_RET( g
, "can't release HDC because there is no Graphics" );
2308 g
->ReleaseHDC((HDC
)hdc
);
2311 #endif // wxUSE_GRAPHICS_CONTEXT