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 // Do not use this pointer directly, it's only used by
82 // GetDrawTextStringFormat() and the cleanup code in wxGDIPlusRendererModule.
83 StringFormat
* gs_drawTextStringFormat
= NULL
;
85 // Get the string format used for the text drawing and measuring functions:
86 // notice that it must be the same one for all of them, otherwise the drawn
87 // text might be of different size than what measuring it returned.
88 inline StringFormat
* GetDrawTextStringFormat()
90 if ( !gs_drawTextStringFormat
)
92 // We create this string format with exactly the same flags as
93 // StringFormat::GenericTypographic() is documented to use in MSDN
94 // except for the last one which doesn't make any difference for
95 // DrawText() but that we do want to use when measuring text.
97 // The reason for not just using GenericTypographic itself is that it
98 // does something else (what exactly is unfortunately not documented),
99 // which results in string being displayed quite differently from the
100 // default rendering, see #14537.
101 gs_drawTextStringFormat
104 StringFormatFlagsLineLimit
|
105 StringFormatFlagsNoClip
|
106 StringFormatFlagsNoFitBlackBox
|
107 StringFormatFlagsMeasureTrailingSpaces
111 return gs_drawTextStringFormat
;
114 } // anonymous namespace
116 //-----------------------------------------------------------------------------
117 // device context implementation
119 // more and more of the dc functionality should be implemented by calling
120 // the appropricate wxGDIPlusContext, but we will have to do that step by step
121 // also coordinate conversions should be moved to native matrix ops
122 //-----------------------------------------------------------------------------
124 // we always stock two context states, one at entry, to be able to preserve the
125 // state we were called with, the other one after changing to HI Graphics orientation
126 // (this one is used for getting back clippings etc)
128 //-----------------------------------------------------------------------------
129 // wxGraphicsPath implementation
130 //-----------------------------------------------------------------------------
132 class wxGDIPlusContext
;
134 class wxGDIPlusPathData
: public wxGraphicsPathData
137 wxGDIPlusPathData(wxGraphicsRenderer
* renderer
, GraphicsPath
* path
= NULL
);
138 ~wxGDIPlusPathData();
140 virtual wxGraphicsObjectRefData
*Clone() const;
143 // These are the path primitives from which everything else can be constructed
146 // begins a new subpath at (x,y)
147 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
149 // adds a straight line from the current point to (x,y)
150 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
152 // adds a cubic Bezier curve from the current point, using two control points and an end point
153 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
156 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
157 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
) ;
159 // gets the last point of the current path, (0,0) if not yet set
160 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
163 virtual void AddPath( const wxGraphicsPathData
* path
);
165 // closes the current sub-path
166 virtual void CloseSubpath();
169 // These are convenience functions which - if not available natively will be assembled
170 // using the primitives from above
173 // appends a rectangle as a new closed subpath
174 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) ;
177 // appends an ellipsis as a new closed subpath fitting the passed rectangle
178 virtual void AddEllipsis( wxDouble x, wxDouble y, wxDouble w , wxDouble h ) ;
180 // 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)
181 virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
184 // returns the native path
185 virtual void * GetNativePath() const { return m_path
; }
187 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
188 virtual void UnGetNativePath(void * WXUNUSED(path
)) const {}
190 // transforms each point of this path by the matrix
191 virtual void Transform( const wxGraphicsMatrixData
* matrix
) ;
193 // gets the bounding box enclosing all points (possibly including control points)
194 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const;
196 virtual bool Contains( wxDouble x
, wxDouble y
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
) const;
199 GraphicsPath
* m_path
;
202 class wxGDIPlusMatrixData
: public wxGraphicsMatrixData
205 wxGDIPlusMatrixData(wxGraphicsRenderer
* renderer
, Matrix
* matrix
= NULL
) ;
206 virtual ~wxGDIPlusMatrixData() ;
208 virtual wxGraphicsObjectRefData
* Clone() const ;
210 // concatenates the matrix
211 virtual void Concat( const wxGraphicsMatrixData
*t
);
213 // sets the matrix to the respective values
214 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
215 wxDouble tx
=0.0, wxDouble ty
=0.0);
217 // gets the component valuess of the matrix
218 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
219 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
221 // makes this the inverse matrix
222 virtual void Invert();
224 // returns true if the elements of the transformation matrix are equal ?
225 virtual bool IsEqual( const wxGraphicsMatrixData
* t
) const ;
227 // return true if this is the identity matrix
228 virtual bool IsIdentity() const;
234 // add the translation to this matrix
235 virtual void Translate( wxDouble dx
, wxDouble dy
);
237 // add the scale to this matrix
238 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
240 // add the rotation to this matrix (radians)
241 virtual void Rotate( wxDouble angle
);
244 // apply the transforms
247 // applies that matrix to the point
248 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
250 // applies the matrix except for translations
251 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
253 // returns the native representation
254 virtual void * GetNativeMatrix() const;
259 class wxGDIPlusPenData
: public wxGraphicsObjectRefData
262 wxGDIPlusPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
);
267 virtual wxDouble
GetWidth() { return m_width
; }
268 virtual Pen
* GetGDIPlusPen() { return m_pen
; }
278 class wxGDIPlusBrushData
: public wxGraphicsObjectRefData
281 wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
);
282 wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
);
283 ~wxGDIPlusBrushData ();
285 void CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
286 wxDouble x2
, wxDouble y2
,
287 const wxGraphicsGradientStops
& stops
);
288 void CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
289 wxDouble xc
, wxDouble yc
,
291 const wxGraphicsGradientStops
& stops
);
293 virtual Brush
* GetGDIPlusBrush() { return m_brush
; }
299 // common part of Create{Linear,Radial}GradientBrush()
300 template <typename T
>
301 void SetGradientStops(T
*brush
, const wxGraphicsGradientStops
& stops
);
305 GraphicsPath
* m_brushPath
;
308 class WXDLLIMPEXP_CORE wxGDIPlusBitmapData
: public wxGraphicsBitmapData
311 wxGDIPlusBitmapData( wxGraphicsRenderer
* renderer
, Bitmap
* bitmap
);
312 wxGDIPlusBitmapData( wxGraphicsRenderer
* renderer
, const wxBitmap
&bmp
);
313 ~wxGDIPlusBitmapData ();
315 virtual Bitmap
* GetGDIPlusBitmap() { return m_bitmap
; }
316 virtual void* GetNativeBitmap() const { return m_bitmap
; }
319 wxImage
ConvertToImage() const;
320 #endif // wxUSE_IMAGE
327 class wxGDIPlusFontData
: public wxGraphicsObjectRefData
330 wxGDIPlusFontData( wxGraphicsRenderer
* renderer
,
332 const wxColour
& col
);
333 wxGDIPlusFontData(wxGraphicsRenderer
* renderer
,
334 const wxString
& name
,
337 const wxColour
& col
);
338 ~wxGDIPlusFontData();
340 virtual Brush
* GetGDIPlusBrush() { return m_textBrush
; }
341 virtual Font
* GetGDIPlusFont() { return m_font
; }
344 // Common part of all ctors, flags here is a combination of values of
345 // FontStyle GDI+ enum.
346 void Init(const wxString
& name
,
356 class wxGDIPlusContext
: public wxGraphicsContext
359 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, const wxDC
& dc
);
360 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HDC hdc
, wxDouble width
, wxDouble height
);
361 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HWND hwnd
);
362 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, Graphics
* gr
);
363 wxGDIPlusContext(wxGraphicsRenderer
* renderer
);
365 virtual ~wxGDIPlusContext();
367 virtual void Clip( const wxRegion
®ion
);
368 // clips drawings to the rect
369 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
371 // resets the clipping to original extent
372 virtual void ResetClip();
374 virtual void * GetNativeContext();
376 virtual void StrokePath( const wxGraphicsPath
& p
);
377 virtual void FillPath( const wxGraphicsPath
& p
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
379 virtual void DrawRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
381 // stroke lines connecting each of the points
382 virtual void StrokeLines( size_t n
, const wxPoint2DDouble
*points
);
385 virtual void DrawLines( size_t n
, const wxPoint2DDouble
*points
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
387 virtual bool SetAntialiasMode(wxAntialiasMode antialias
);
389 virtual bool SetInterpolationQuality(wxInterpolationQuality interpolation
);
391 virtual bool SetCompositionMode(wxCompositionMode op
);
393 virtual void BeginLayer(wxDouble opacity
);
395 virtual void EndLayer();
397 virtual void Translate( wxDouble dx
, wxDouble dy
);
398 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
399 virtual void Rotate( wxDouble angle
);
401 // concatenates this transform with the current transform of this context
402 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
);
404 // sets the transform of this context
405 virtual void SetTransform( const wxGraphicsMatrix
& matrix
);
407 // gets the matrix of this context
408 virtual wxGraphicsMatrix
GetTransform() const;
410 virtual void DrawBitmap( const wxGraphicsBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
411 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
412 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
413 virtual void PushState();
414 virtual void PopState();
416 virtual void GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
417 wxDouble
*descent
, wxDouble
*externalLeading
) const;
418 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const;
419 virtual bool ShouldOffset() const;
420 virtual void GetSize( wxDouble
* width
, wxDouble
*height
);
422 Graphics
* GetGraphics() const { return m_context
; }
426 wxDouble m_fontScaleRatio
;
428 // Used from ctors (including those in the derived classes) and takes
429 // ownership of the graphics pointer that must be non-NULL.
430 void Init(Graphics
* graphics
, int width
, int height
);
433 virtual void DoDrawText(const wxString
& str
, wxDouble x
, wxDouble y
);
436 wxStack
<GraphicsState
> m_stateStack
;
437 GraphicsState m_state1
;
438 GraphicsState m_state2
;
440 wxDECLARE_NO_COPY_CLASS(wxGDIPlusContext
);
445 class wxGDIPlusImageContext
: public wxGDIPlusContext
448 wxGDIPlusImageContext(wxGraphicsRenderer
* renderer
, wxImage
& image
) :
449 wxGDIPlusContext(renderer
),
451 m_bitmap(renderer
, image
)
455 new Graphics(m_bitmap
.GetGDIPlusBitmap()),
461 virtual ~wxGDIPlusImageContext()
463 m_image
= m_bitmap
.ConvertToImage();
468 wxGDIPlusBitmapData m_bitmap
;
470 wxDECLARE_NO_COPY_CLASS(wxGDIPlusImageContext
);
473 #endif // wxUSE_IMAGE
475 class wxGDIPlusMeasuringContext
: public wxGDIPlusContext
478 wxGDIPlusMeasuringContext( wxGraphicsRenderer
* renderer
) : wxGDIPlusContext( renderer
, m_hdc
= GetDC(NULL
), 1000, 1000 )
482 virtual ~wxGDIPlusMeasuringContext()
484 ReleaseDC( NULL
, m_hdc
);
491 class wxGDIPlusPrintingContext
: public wxGDIPlusContext
494 wxGDIPlusPrintingContext( wxGraphicsRenderer
* renderer
, const wxDC
& dc
);
495 virtual ~wxGDIPlusPrintingContext() { }
499 //-----------------------------------------------------------------------------
500 // wxGDIPlusRenderer declaration
501 //-----------------------------------------------------------------------------
503 class wxGDIPlusRenderer
: public wxGraphicsRenderer
512 virtual ~wxGDIPlusRenderer()
522 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
);
524 virtual wxGraphicsContext
* CreateContext( const wxMemoryDC
& dc
);
526 #if wxUSE_PRINTING_ARCHITECTURE
527 virtual wxGraphicsContext
* CreateContext( const wxPrinterDC
& dc
);
530 #if wxUSE_ENH_METAFILE
531 virtual wxGraphicsContext
* CreateContext( const wxEnhMetaFileDC
& dc
);
534 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
);
536 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
);
538 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
);
541 virtual wxGraphicsContext
* CreateContextFromImage(wxImage
& image
);
542 #endif // wxUSE_IMAGE
544 virtual wxGraphicsContext
* CreateMeasuringContext();
548 virtual wxGraphicsPath
CreatePath();
552 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
553 wxDouble tx
=0.0, wxDouble ty
=0.0);
556 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) ;
558 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) ;
560 virtual wxGraphicsBrush
561 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
562 wxDouble x2
, wxDouble y2
,
563 const wxGraphicsGradientStops
& stops
);
565 virtual wxGraphicsBrush
566 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
567 wxDouble xc
, wxDouble yc
,
569 const wxGraphicsGradientStops
& stops
);
571 // create a native bitmap representation
572 virtual wxGraphicsBitmap
CreateBitmap( const wxBitmap
&bitmap
);
574 virtual wxGraphicsBitmap
CreateBitmapFromImage(const wxImage
& image
);
575 virtual wxImage
CreateImageFromBitmap(const wxGraphicsBitmap
& bmp
);
576 #endif // wxUSE_IMAGE
578 virtual wxGraphicsFont
CreateFont( const wxFont
& font
,
579 const wxColour
& col
);
581 virtual wxGraphicsFont
CreateFont(double size
,
582 const wxString
& facename
,
583 int flags
= wxFONTFLAG_DEFAULT
,
584 const wxColour
& col
= *wxBLACK
);
586 // create a graphics bitmap from a native bitmap
587 virtual wxGraphicsBitmap
CreateBitmapFromNativeBitmap( void* bitmap
);
589 // create a subimage from a native image representation
590 virtual wxGraphicsBitmap
CreateSubBitmap( const wxGraphicsBitmap
&bitmap
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
593 bool EnsureIsLoaded();
596 friend class wxGDIPlusRendererModule
;
600 ULONG_PTR m_gditoken
;
602 DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusRenderer
)
605 //-----------------------------------------------------------------------------
606 // wxGDIPlusPen implementation
607 //-----------------------------------------------------------------------------
609 wxGDIPlusPenData::~wxGDIPlusPenData()
616 void wxGDIPlusPenData::Init()
623 wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
)
624 : wxGraphicsObjectRefData(renderer
)
627 m_width
= pen
.GetWidth();
631 m_pen
= new Pen(wxColourToColor(pen
.GetColour()), m_width
);
634 switch ( pen
.GetCap() )
640 case wxCAP_PROJECTING
:
645 cap
= LineCapFlat
; // TODO verify
652 m_pen
->SetLineCap(cap
,cap
, DashCapFlat
);
655 switch ( pen
.GetJoin() )
658 join
= LineJoinBevel
;
662 join
= LineJoinMiter
;
666 join
= LineJoinRound
;
670 join
= LineJoinMiter
;
674 m_pen
->SetLineJoin(join
);
676 m_pen
->SetDashStyle(DashStyleSolid
);
678 DashStyle dashStyle
= DashStyleSolid
;
679 switch ( pen
.GetStyle() )
681 case wxPENSTYLE_SOLID
:
684 case wxPENSTYLE_DOT
:
685 dashStyle
= DashStyleDot
;
688 case wxPENSTYLE_LONG_DASH
:
689 dashStyle
= DashStyleDash
; // TODO verify
692 case wxPENSTYLE_SHORT_DASH
:
693 dashStyle
= DashStyleDash
;
696 case wxPENSTYLE_DOT_DASH
:
697 dashStyle
= DashStyleDashDot
;
699 case wxPENSTYLE_USER_DASH
:
701 dashStyle
= DashStyleCustom
;
703 int count
= pen
.GetDashes( &dashes
);
704 if ((dashes
!= NULL
) && (count
> 0))
706 REAL
*userLengths
= new REAL
[count
];
707 for ( int i
= 0; i
< count
; ++i
)
709 userLengths
[i
] = dashes
[i
];
711 m_pen
->SetDashPattern( userLengths
, count
);
712 delete[] userLengths
;
716 case wxPENSTYLE_STIPPLE
:
718 wxBitmap
* bmp
= pen
.GetStipple();
719 if ( bmp
&& bmp
->IsOk() )
721 m_penImage
= Bitmap::FromHBITMAP((HBITMAP
)bmp
->GetHBITMAP(),
723 (HPALETTE
)bmp
->GetPalette()->GetHPALETTE()
728 m_penBrush
= new TextureBrush(m_penImage
);
729 m_pen
->SetBrush( m_penBrush
);
735 if ( pen
.GetStyle() >= wxPENSTYLE_FIRST_HATCH
&&
736 pen
.GetStyle() <= wxPENSTYLE_LAST_HATCH
)
739 switch( pen
.GetStyle() )
741 case wxPENSTYLE_BDIAGONAL_HATCH
:
742 style
= HatchStyleBackwardDiagonal
;
744 case wxPENSTYLE_CROSSDIAG_HATCH
:
745 style
= HatchStyleDiagonalCross
;
747 case wxPENSTYLE_FDIAGONAL_HATCH
:
748 style
= HatchStyleForwardDiagonal
;
750 case wxPENSTYLE_CROSS_HATCH
:
751 style
= HatchStyleCross
;
753 case wxPENSTYLE_HORIZONTAL_HATCH
:
754 style
= HatchStyleHorizontal
;
756 case wxPENSTYLE_VERTICAL_HATCH
:
757 style
= HatchStyleVertical
;
760 style
= HatchStyleHorizontal
;
762 m_penBrush
= new HatchBrush
765 wxColourToColor(pen
.GetColour()),
768 m_pen
->SetBrush( m_penBrush
);
772 if ( dashStyle
!= DashStyleSolid
)
773 m_pen
->SetDashStyle(dashStyle
);
776 //-----------------------------------------------------------------------------
777 // wxGDIPlusBrush implementation
778 //-----------------------------------------------------------------------------
780 wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
)
781 : wxGraphicsObjectRefData(renderer
)
786 wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
)
787 : wxGraphicsObjectRefData(renderer
)
790 if ( brush
.GetStyle() == wxSOLID
)
792 m_brush
= new SolidBrush(wxColourToColor( brush
.GetColour()));
794 else if ( brush
.IsHatch() )
797 switch( brush
.GetStyle() )
799 case wxBRUSHSTYLE_BDIAGONAL_HATCH
:
800 style
= HatchStyleBackwardDiagonal
;
802 case wxBRUSHSTYLE_CROSSDIAG_HATCH
:
803 style
= HatchStyleDiagonalCross
;
805 case wxBRUSHSTYLE_FDIAGONAL_HATCH
:
806 style
= HatchStyleForwardDiagonal
;
808 case wxBRUSHSTYLE_CROSS_HATCH
:
809 style
= HatchStyleCross
;
811 case wxBRUSHSTYLE_HORIZONTAL_HATCH
:
812 style
= HatchStyleHorizontal
;
814 case wxBRUSHSTYLE_VERTICAL_HATCH
:
815 style
= HatchStyleVertical
;
818 style
= HatchStyleHorizontal
;
820 m_brush
= new HatchBrush
823 wxColourToColor(brush
.GetColour()),
829 wxBitmap
* bmp
= brush
.GetStipple();
830 if ( bmp
&& bmp
->IsOk() )
832 wxDELETE( m_brushImage
);
833 m_brushImage
= Bitmap::FromHBITMAP((HBITMAP
)bmp
->GetHBITMAP(),
835 (HPALETTE
)bmp
->GetPalette()->GetHPALETTE()
840 m_brush
= new TextureBrush(m_brushImage
);
845 wxGDIPlusBrushData::~wxGDIPlusBrushData()
852 void wxGDIPlusBrushData::Init()
859 template <typename T
>
861 wxGDIPlusBrushData::SetGradientStops(T
*brush
,
862 const wxGraphicsGradientStops
& stops
)
864 const unsigned numStops
= stops
.GetCount();
867 // initial and final colours are set during the brush creation, nothing
872 wxVector
<Color
> colors(numStops
);
873 wxVector
<REAL
> positions(numStops
);
875 for ( unsigned i
= 0; i
< numStops
; i
++ )
877 wxGraphicsGradientStop stop
= stops
.Item(i
);
879 colors
[i
] = wxColourToColor(stop
.GetColour());
880 positions
[i
] = stop
.GetPosition();
883 brush
->SetInterpolationColors(&colors
[0], &positions
[0], numStops
);
887 wxGDIPlusBrushData::CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
888 wxDouble x2
, wxDouble y2
,
889 const wxGraphicsGradientStops
& stops
)
891 LinearGradientBrush
* const
892 brush
= new LinearGradientBrush(PointF(x1
, y1
) , PointF(x2
, y2
),
893 wxColourToColor(stops
.GetStartColour()),
894 wxColourToColor(stops
.GetEndColour()));
897 SetGradientStops(brush
, stops
);
901 wxGDIPlusBrushData::CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
902 wxDouble xc
, wxDouble yc
,
904 const wxGraphicsGradientStops
& stops
)
906 m_brushPath
= new GraphicsPath();
907 m_brushPath
->AddEllipse( (REAL
)(xc
-radius
), (REAL
)(yc
-radius
),
908 (REAL
)(2*radius
), (REAL
)(2*radius
));
910 PathGradientBrush
* const brush
= new PathGradientBrush(m_brushPath
);
912 brush
->SetCenterPoint(PointF(xo
, yo
));
913 brush
->SetCenterColor(wxColourToColor(stops
.GetStartColour()));
915 const Color
col(wxColourToColor(stops
.GetEndColour()));
917 brush
->SetSurroundColors(&col
, &count
);
919 SetGradientStops(brush
, stops
);
922 //-----------------------------------------------------------------------------
923 // wxGDIPlusFont implementation
924 //-----------------------------------------------------------------------------
927 wxGDIPlusFontData::Init(const wxString
& name
,
933 m_font
= new Font(name
.wc_str(), size
, style
, fontUnit
);
935 m_textBrush
= new SolidBrush(wxColourToColor(col
));
938 wxGDIPlusFontData::wxGDIPlusFontData( wxGraphicsRenderer
* renderer
,
940 const wxColour
& col
)
941 : wxGraphicsObjectRefData( renderer
)
943 int style
= FontStyleRegular
;
944 if ( font
.GetStyle() == wxFONTSTYLE_ITALIC
)
945 style
|= FontStyleItalic
;
946 if ( font
.GetUnderlined() )
947 style
|= FontStyleUnderline
;
948 if ( font
.GetWeight() == wxFONTWEIGHT_BOLD
)
949 style
|= FontStyleBold
;
951 Init(font
.GetFaceName(), font
.GetPointSize(), style
, col
, UnitPoint
);
954 wxGDIPlusFontData::wxGDIPlusFontData(wxGraphicsRenderer
* renderer
,
955 const wxString
& name
,
958 const wxColour
& col
) :
959 wxGraphicsObjectRefData(renderer
)
961 Init(name
, sizeInPixels
, style
, col
, UnitPixel
);
964 wxGDIPlusFontData::~wxGDIPlusFontData()
970 // the built-in conversions functions create non-premultiplied bitmaps, while GDIPlus needs them in the
971 // premultiplied format, therefore in the failing cases we create a new bitmap using the non-premultiplied
972 // bytes as parameter, since there is no real copying of the data going in, only references are stored
973 // m_helper has to be kept alive as well
975 //-----------------------------------------------------------------------------
976 // wxGDIPlusBitmapData implementation
977 //-----------------------------------------------------------------------------
979 wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer
* renderer
, Bitmap
* bitmap
) :
980 wxGraphicsBitmapData( renderer
), m_bitmap( bitmap
)
985 wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer
* renderer
,
986 const wxBitmap
&bmp
) : wxGraphicsBitmapData( renderer
)
991 Bitmap
* image
= NULL
;
994 Bitmap
interim((HBITMAP
)bmp
.GetHBITMAP(),
996 (HPALETTE
)bmp
.GetPalette()->GetHPALETTE()
1002 size_t width
= interim
.GetWidth();
1003 size_t height
= interim
.GetHeight();
1004 Rect
bounds(0,0,width
,height
);
1006 image
= new Bitmap(width
,height
,PixelFormat32bppPARGB
) ;
1008 Bitmap
interimMask((HBITMAP
)bmp
.GetMask()->GetMaskBitmap(),NULL
);
1009 wxASSERT(interimMask
.GetPixelFormat() == PixelFormat1bppIndexed
);
1011 BitmapData dataMask
;
1012 interimMask
.LockBits(&bounds
,ImageLockModeRead
,
1013 interimMask
.GetPixelFormat(),&dataMask
);
1016 BitmapData imageData
;
1017 image
->LockBits(&bounds
,ImageLockModeWrite
, PixelFormat32bppPARGB
, &imageData
);
1019 BYTE maskPattern
= 0 ;
1023 for ( size_t y
= 0 ; y
< height
; ++y
)
1026 for( size_t x
= 0 ; x
< width
; ++x
)
1031 maskByte
= *((BYTE
*)dataMask
.Scan0
+ dataMask
.Stride
*y
+ maskIndex
);
1035 maskPattern
= maskPattern
>> 1;
1037 ARGB
*dest
= (ARGB
*)((BYTE
*)imageData
.Scan0
+ imageData
.Stride
*y
+ x
*4);
1038 if ( (maskByte
& maskPattern
) == 0 )
1043 interim
.GetPixel(x
,y
,&c
) ;
1044 *dest
= (c
.GetValue() | Color::AlphaMask
);
1049 image
->UnlockBits(&imageData
);
1051 interimMask
.UnlockBits(&dataMask
);
1052 interim
.UnlockBits(&dataMask
);
1056 image
= Bitmap::FromHBITMAP((HBITMAP
)bmp
.GetHBITMAP(),
1058 (HPALETTE
)bmp
.GetPalette()->GetHPALETTE()
1063 if ( bmp
.HasAlpha() && GetPixelFormatSize(image
->GetPixelFormat()) == 32 )
1065 size_t width
= image
->GetWidth();
1066 size_t height
= image
->GetHeight();
1067 Rect
bounds(0,0,width
,height
);
1068 static BitmapData data
;
1072 m_helper
->LockBits(&bounds
, ImageLockModeRead
,
1073 m_helper
->GetPixelFormat(),&data
);
1075 image
= new Bitmap(data
.Width
, data
.Height
, data
.Stride
,
1076 PixelFormat32bppPARGB
, (BYTE
*) data
.Scan0
);
1078 m_helper
->UnlockBits(&data
);
1087 wxImage
wxGDIPlusBitmapData::ConvertToImage() const
1089 // We could use Bitmap::LockBits() and convert to wxImage directly but
1090 // passing by wxBitmap is easier. It would be nice to measure performance
1091 // of the two methods but for this the second one would need to be written
1094 if ( m_bitmap
->GetHBITMAP(Color(0xffffffff), &hbmp
) != Gdiplus::Ok
)
1098 bmp
.SetWidth(m_bitmap
->GetWidth());
1099 bmp
.SetHeight(m_bitmap
->GetHeight());
1100 bmp
.SetHBITMAP(hbmp
);
1101 bmp
.SetDepth(IsAlphaPixelFormat(m_bitmap
->GetPixelFormat()) ? 32 : 24);
1102 return bmp
.ConvertToImage();
1105 #endif // wxUSE_IMAGE
1107 wxGDIPlusBitmapData::~wxGDIPlusBitmapData()
1113 //-----------------------------------------------------------------------------
1114 // wxGDIPlusPath implementation
1115 //-----------------------------------------------------------------------------
1117 wxGDIPlusPathData::wxGDIPlusPathData(wxGraphicsRenderer
* renderer
, GraphicsPath
* path
) : wxGraphicsPathData(renderer
)
1122 m_path
= new GraphicsPath();
1125 wxGDIPlusPathData::~wxGDIPlusPathData()
1130 wxGraphicsObjectRefData
* wxGDIPlusPathData::Clone() const
1132 return new wxGDIPlusPathData( GetRenderer() , m_path
->Clone());
1139 void wxGDIPlusPathData::MoveToPoint( wxDouble x
, wxDouble y
)
1141 m_path
->StartFigure();
1142 m_path
->AddLine((REAL
) x
,(REAL
) y
,(REAL
) x
,(REAL
) y
);
1145 void wxGDIPlusPathData::AddLineToPoint( wxDouble x
, wxDouble y
)
1147 m_path
->AddLine((REAL
) x
,(REAL
) y
,(REAL
) x
,(REAL
) y
);
1150 void wxGDIPlusPathData::CloseSubpath()
1152 m_path
->CloseFigure();
1155 void wxGDIPlusPathData::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
1161 m_path
->GetLastPoint(&start
);
1162 m_path
->AddBezier(start
,c1
,c2
,end
);
1165 // gets the last point of the current path, (0,0) if not yet set
1166 void wxGDIPlusPathData::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
1169 m_path
->GetLastPoint(&start
);
1174 void wxGDIPlusPathData::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, double startAngle
, double endAngle
, bool clockwise
)
1176 double sweepAngle
= endAngle
- startAngle
;
1177 if( fabs(sweepAngle
) >= 2*M_PI
)
1179 sweepAngle
= 2 * M_PI
;
1185 if( sweepAngle
< 0 )
1186 sweepAngle
+= 2 * M_PI
;
1190 if( sweepAngle
> 0 )
1191 sweepAngle
-= 2 * M_PI
;
1195 m_path
->AddArc((REAL
) (x
-r
),(REAL
) (y
-r
),(REAL
) (2*r
),(REAL
) (2*r
),RadToDeg(startAngle
),RadToDeg(sweepAngle
));
1198 void wxGDIPlusPathData::AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1200 m_path
->AddRectangle(RectF(x
,y
,w
,h
));
1203 void wxGDIPlusPathData::AddPath( const wxGraphicsPathData
* path
)
1205 m_path
->AddPath( (GraphicsPath
*) path
->GetNativePath(), FALSE
);
1209 // transforms each point of this path by the matrix
1210 void wxGDIPlusPathData::Transform( const wxGraphicsMatrixData
* matrix
)
1212 m_path
->Transform( (Matrix
*) matrix
->GetNativeMatrix() );
1215 // gets the bounding box enclosing all points (possibly including control points)
1216 void wxGDIPlusPathData::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
1219 m_path
->GetBounds( &bounds
, NULL
, NULL
) ;
1226 bool wxGDIPlusPathData::Contains( wxDouble x
, wxDouble y
, wxPolygonFillMode fillStyle
) const
1228 m_path
->SetFillMode( fillStyle
== wxODDEVEN_RULE
? FillModeAlternate
: FillModeWinding
);
1229 return m_path
->IsVisible( (FLOAT
) x
,(FLOAT
) y
) == TRUE
;
1232 //-----------------------------------------------------------------------------
1233 // wxGDIPlusMatrixData implementation
1234 //-----------------------------------------------------------------------------
1236 wxGDIPlusMatrixData::wxGDIPlusMatrixData(wxGraphicsRenderer
* renderer
, Matrix
* matrix
)
1237 : wxGraphicsMatrixData(renderer
)
1242 m_matrix
= new Matrix();
1245 wxGDIPlusMatrixData::~wxGDIPlusMatrixData()
1250 wxGraphicsObjectRefData
*wxGDIPlusMatrixData::Clone() const
1252 return new wxGDIPlusMatrixData( GetRenderer(), m_matrix
->Clone());
1255 // concatenates the matrix
1256 void wxGDIPlusMatrixData::Concat( const wxGraphicsMatrixData
*t
)
1258 m_matrix
->Multiply( (Matrix
*) t
->GetNativeMatrix());
1261 // sets the matrix to the respective values
1262 void wxGDIPlusMatrixData::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
1263 wxDouble tx
, wxDouble ty
)
1265 m_matrix
->SetElements(a
,b
,c
,d
,tx
,ty
);
1268 // gets the component valuess of the matrix
1269 void wxGDIPlusMatrixData::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
1270 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
1273 m_matrix
->GetElements(elements
);
1274 if (a
) *a
= elements
[0];
1275 if (b
) *b
= elements
[1];
1276 if (c
) *c
= elements
[2];
1277 if (d
) *d
= elements
[3];
1278 if (tx
) *tx
= elements
[4];
1279 if (ty
) *ty
= elements
[5];
1282 // makes this the inverse matrix
1283 void wxGDIPlusMatrixData::Invert()
1288 // returns true if the elements of the transformation matrix are equal ?
1289 bool wxGDIPlusMatrixData::IsEqual( const wxGraphicsMatrixData
* t
) const
1291 return m_matrix
->Equals((Matrix
*) t
->GetNativeMatrix())== TRUE
;
1294 // return true if this is the identity matrix
1295 bool wxGDIPlusMatrixData::IsIdentity() const
1297 return m_matrix
->IsIdentity() == TRUE
;
1304 // add the translation to this matrix
1305 void wxGDIPlusMatrixData::Translate( wxDouble dx
, wxDouble dy
)
1307 m_matrix
->Translate(dx
,dy
);
1310 // add the scale to this matrix
1311 void wxGDIPlusMatrixData::Scale( wxDouble xScale
, wxDouble yScale
)
1313 m_matrix
->Scale(xScale
,yScale
);
1316 // add the rotation to this matrix (radians)
1317 void wxGDIPlusMatrixData::Rotate( wxDouble angle
)
1319 m_matrix
->Rotate( RadToDeg(angle
) );
1323 // apply the transforms
1326 // applies that matrix to the point
1327 void wxGDIPlusMatrixData::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
1330 m_matrix
->TransformPoints(&pt
);
1335 // applies the matrix except for translations
1336 void wxGDIPlusMatrixData::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
1339 m_matrix
->TransformVectors(&pt
);
1344 // returns the native representation
1345 void * wxGDIPlusMatrixData::GetNativeMatrix() const
1350 //-----------------------------------------------------------------------------
1351 // wxGDIPlusContext implementation
1352 //-----------------------------------------------------------------------------
1354 class wxGDIPlusOffsetHelper
1357 wxGDIPlusOffsetHelper( Graphics
* gr
, bool offset
)
1362 m_gr
->TranslateTransform( 0.5, 0.5 );
1364 ~wxGDIPlusOffsetHelper( )
1367 m_gr
->TranslateTransform( -0.5, -0.5 );
1374 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HDC hdc
, wxDouble width
, wxDouble height
)
1375 : wxGraphicsContext(renderer
)
1377 Init(new Graphics(hdc
), width
, height
);
1380 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, const wxDC
& dc
)
1381 : wxGraphicsContext(renderer
)
1383 wxMSWDCImpl
*msw
= wxDynamicCast( dc
.GetImpl() , wxMSWDCImpl
);
1384 HDC hdc
= (HDC
) msw
->GetHDC();
1385 wxSize sz
= dc
.GetSize();
1387 Init(new Graphics(hdc
), sz
.x
, sz
.y
);
1390 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HWND hwnd
)
1391 : wxGraphicsContext(renderer
)
1393 RECT rect
= wxGetWindowRect(hwnd
);
1394 Init(new Graphics(hwnd
), rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
1395 m_enableOffset
= true;
1398 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, Graphics
* gr
)
1399 : wxGraphicsContext(renderer
)
1404 wxGDIPlusContext::wxGDIPlusContext(wxGraphicsRenderer
* renderer
)
1405 : wxGraphicsContext(renderer
)
1407 // Derived class must call Init() later but just set m_context to NULL for
1408 // safety to avoid crashing in our dtor if Init() ends up not being called.
1412 void wxGDIPlusContext::Init(Graphics
* graphics
, int width
, int height
)
1414 m_context
= graphics
;
1419 m_fontScaleRatio
= 1.0;
1421 m_context
->SetTextRenderingHint(TextRenderingHintSystemDefault
);
1422 m_context
->SetPixelOffsetMode(PixelOffsetModeHalf
);
1423 m_context
->SetSmoothingMode(SmoothingModeHighQuality
);
1424 m_context
->SetInterpolationMode(InterpolationModeHighQuality
);
1425 m_state1
= m_context
->Save();
1426 m_state2
= m_context
->Save();
1429 wxGDIPlusContext::~wxGDIPlusContext()
1433 m_context
->Restore( m_state2
);
1434 m_context
->Restore( m_state1
);
1440 void wxGDIPlusContext::Clip( const wxRegion
®ion
)
1442 Region
rgn((HRGN
)region
.GetHRGN());
1443 m_context
->SetClip(&rgn
,CombineModeIntersect
);
1446 void wxGDIPlusContext::Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1448 m_context
->SetClip(RectF(x
,y
,w
,h
),CombineModeIntersect
);
1451 void wxGDIPlusContext::ResetClip()
1453 m_context
->ResetClip();
1456 void wxGDIPlusContext::DrawRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1458 if (m_composition
== wxCOMPOSITION_DEST
)
1461 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1462 Brush
*brush
= m_brush
.IsNull() ? NULL
: ((wxGDIPlusBrushData
*)m_brush
.GetRefData())->GetGDIPlusBrush();
1463 Pen
*pen
= m_pen
.IsNull() ? NULL
: ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen();
1467 // the offset is used to fill only the inside of the rectangle and not paint underneath
1468 // its border which may influence a transparent Pen
1471 offset
= pen
->GetWidth();
1472 m_context
->FillRectangle( brush
, (REAL
)x
+ offset
/2, (REAL
)y
+ offset
/2, (REAL
)w
- offset
, (REAL
)h
- offset
);
1477 m_context
->DrawRectangle( pen
, (REAL
)x
, (REAL
)y
, (REAL
)w
, (REAL
)h
);
1481 void wxGDIPlusContext::StrokeLines( size_t n
, const wxPoint2DDouble
*points
)
1483 if (m_composition
== wxCOMPOSITION_DEST
)
1486 if ( !m_pen
.IsNull() )
1488 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1489 Point
*cpoints
= new Point
[n
];
1490 for (size_t i
= 0; i
< n
; i
++)
1492 cpoints
[i
].X
= (int)(points
[i
].m_x
);
1493 cpoints
[i
].Y
= (int)(points
[i
].m_y
);
1495 } // for (size_t i = 0; i < n; i++)
1496 m_context
->DrawLines( ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen() , cpoints
, n
) ;
1501 void wxGDIPlusContext::DrawLines( size_t n
, const wxPoint2DDouble
*points
, wxPolygonFillMode
WXUNUSED(fillStyle
) )
1503 if (m_composition
== wxCOMPOSITION_DEST
)
1506 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1507 Point
*cpoints
= new Point
[n
];
1508 for (size_t i
= 0; i
< n
; i
++)
1510 cpoints
[i
].X
= (int)(points
[i
].m_x
);
1511 cpoints
[i
].Y
= (int)(points
[i
].m_y
);
1513 } // for (int i = 0; i < n; i++)
1514 if ( !m_brush
.IsNull() )
1515 m_context
->FillPolygon( ((wxGDIPlusBrushData
*)m_brush
.GetRefData())->GetGDIPlusBrush() , cpoints
, n
) ;
1516 if ( !m_pen
.IsNull() )
1517 m_context
->DrawLines( ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen() , cpoints
, n
) ;
1521 void wxGDIPlusContext::StrokePath( const wxGraphicsPath
& path
)
1523 if (m_composition
== wxCOMPOSITION_DEST
)
1526 if ( !m_pen
.IsNull() )
1528 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1529 m_context
->DrawPath( ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen() , (GraphicsPath
*) path
.GetNativePath() );
1533 void wxGDIPlusContext::FillPath( const wxGraphicsPath
& path
, wxPolygonFillMode fillStyle
)
1535 if (m_composition
== wxCOMPOSITION_DEST
)
1538 if ( !m_brush
.IsNull() )
1540 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1541 ((GraphicsPath
*) path
.GetNativePath())->SetFillMode( fillStyle
== wxODDEVEN_RULE
? FillModeAlternate
: FillModeWinding
);
1542 m_context
->FillPath( ((wxGDIPlusBrushData
*)m_brush
.GetRefData())->GetGDIPlusBrush() ,
1543 (GraphicsPath
*) path
.GetNativePath());
1547 bool wxGDIPlusContext::SetAntialiasMode(wxAntialiasMode antialias
)
1549 if (m_antialias
== antialias
)
1552 m_antialias
= antialias
;
1554 SmoothingMode antialiasMode
;
1557 case wxANTIALIAS_DEFAULT
:
1558 antialiasMode
= SmoothingModeHighQuality
;
1560 case wxANTIALIAS_NONE
:
1561 antialiasMode
= SmoothingModeNone
;
1566 m_context
->SetSmoothingMode(antialiasMode
);
1570 bool wxGDIPlusContext::SetInterpolationQuality(wxInterpolationQuality interpolation
)
1572 if (m_interpolation
== interpolation
)
1575 InterpolationMode interpolationMode
= InterpolationModeDefault
;
1576 switch (interpolation
)
1578 case wxINTERPOLATION_DEFAULT
:
1579 interpolationMode
= InterpolationModeDefault
;
1582 case wxINTERPOLATION_NONE
:
1583 interpolationMode
= InterpolationModeNearestNeighbor
;
1586 case wxINTERPOLATION_FAST
:
1587 interpolationMode
= InterpolationModeLowQuality
;
1590 case wxINTERPOLATION_GOOD
:
1591 interpolationMode
= InterpolationModeHighQuality
;
1594 case wxINTERPOLATION_BEST
:
1595 interpolationMode
= InterpolationModeHighQualityBicubic
;
1602 if ( m_context
->SetInterpolationMode(interpolationMode
) != Gdiplus::Ok
)
1605 m_interpolation
= interpolation
;
1610 bool wxGDIPlusContext::SetCompositionMode(wxCompositionMode op
)
1612 if ( m_composition
== op
)
1617 if (m_composition
== wxCOMPOSITION_DEST
)
1620 CompositingMode cop
;
1623 case wxCOMPOSITION_SOURCE
:
1624 cop
= CompositingModeSourceCopy
;
1626 case wxCOMPOSITION_OVER
:
1627 cop
= CompositingModeSourceOver
;
1633 m_context
->SetCompositingMode(cop
);
1637 void wxGDIPlusContext::BeginLayer(wxDouble
/* opacity */)
1642 void wxGDIPlusContext::EndLayer()
1647 void wxGDIPlusContext::Rotate( wxDouble angle
)
1649 m_context
->RotateTransform( RadToDeg(angle
) );
1652 void wxGDIPlusContext::Translate( wxDouble dx
, wxDouble dy
)
1654 m_context
->TranslateTransform( dx
, dy
);
1657 void wxGDIPlusContext::Scale( wxDouble xScale
, wxDouble yScale
)
1659 m_context
->ScaleTransform(xScale
,yScale
);
1662 void wxGDIPlusContext::PushState()
1664 GraphicsState state
= m_context
->Save();
1665 m_stateStack
.push(state
);
1668 void wxGDIPlusContext::PopState()
1670 wxCHECK_RET( !m_stateStack
.empty(), wxT("No state to pop") );
1672 GraphicsState state
= m_stateStack
.top();
1674 m_context
->Restore(state
);
1677 void wxGDIPlusContext::DrawBitmap( const wxGraphicsBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1679 if (m_composition
== wxCOMPOSITION_DEST
)
1682 Bitmap
* image
= static_cast<wxGDIPlusBitmapData
*>(bmp
.GetRefData())->GetGDIPlusBitmap();
1685 if( image
->GetWidth() != (UINT
) w
|| image
->GetHeight() != (UINT
) h
)
1687 Rect
drawRect((REAL
) x
, (REAL
)y
, (REAL
)w
, (REAL
)h
);
1688 m_context
->SetPixelOffsetMode( PixelOffsetModeNone
);
1689 m_context
->DrawImage(image
, drawRect
, 0 , 0 , image
->GetWidth(), image
->GetHeight(), UnitPixel
) ;
1690 m_context
->SetPixelOffsetMode( PixelOffsetModeHalf
);
1693 m_context
->DrawImage(image
,(REAL
) x
,(REAL
) y
,(REAL
) w
,(REAL
) h
) ;
1697 void wxGDIPlusContext::DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1699 wxGraphicsBitmap bitmap
= GetRenderer()->CreateBitmap(bmp
);
1700 DrawBitmap(bitmap
, x
, y
, w
, h
);
1703 void wxGDIPlusContext::DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1705 if (m_composition
== wxCOMPOSITION_DEST
)
1708 // the built-in conversion fails when there is alpha in the HICON (eg XP style icons), we can only
1709 // find out by looking at the bitmap data whether there really was alpha in it
1710 HICON hIcon
= (HICON
)icon
.GetHICON();
1712 // IconInfo creates the bitmaps for color and mask, we must dispose of them after use
1713 if (!GetIconInfo(hIcon
,&iconInfo
))
1716 Bitmap
interim(iconInfo
.hbmColor
,NULL
);
1718 Bitmap
* image
= NULL
;
1720 // if it's not 32 bit, it doesn't have an alpha channel, note that since the conversion doesn't
1721 // work correctly, asking IsAlphaPixelFormat at this point fails as well
1722 if( GetPixelFormatSize(interim
.GetPixelFormat())!= 32 )
1724 image
= Bitmap::FromHICON(hIcon
);
1728 size_t width
= interim
.GetWidth();
1729 size_t height
= interim
.GetHeight();
1730 Rect
bounds(0,0,width
,height
);
1733 interim
.LockBits(&bounds
, ImageLockModeRead
,
1734 interim
.GetPixelFormat(),&data
);
1736 bool hasAlpha
= false;
1737 for ( size_t y
= 0 ; y
< height
&& !hasAlpha
; ++y
)
1739 for( size_t x
= 0 ; x
< width
&& !hasAlpha
; ++x
)
1741 ARGB
*dest
= (ARGB
*)((BYTE
*)data
.Scan0
+ data
.Stride
*y
+ x
*4);
1742 if ( ( *dest
& Color::AlphaMask
) != 0 )
1749 image
= new Bitmap(data
.Width
, data
.Height
, data
.Stride
,
1750 PixelFormat32bppARGB
, (BYTE
*) data
.Scan0
);
1754 image
= Bitmap::FromHICON(hIcon
);
1757 interim
.UnlockBits(&data
);
1760 m_context
->DrawImage(image
,(REAL
) x
,(REAL
) y
,(REAL
) w
,(REAL
) h
) ;
1763 DeleteObject(iconInfo
.hbmColor
);
1764 DeleteObject(iconInfo
.hbmMask
);
1767 void wxGDIPlusContext::DoDrawText(const wxString
& str
,
1768 wxDouble x
, wxDouble y
)
1770 if (m_composition
== wxCOMPOSITION_DEST
)
1773 wxCHECK_RET( !m_font
.IsNull(),
1774 wxT("wxGDIPlusContext::DrawText - no valid font set") );
1779 wxGDIPlusFontData
* const
1780 fontData
= (wxGDIPlusFontData
*)m_font
.GetRefData();
1782 m_context
->DrawString
1784 str
.wc_str(*wxConvUI
), // string to draw, always Unicode
1785 -1, // length: string is NUL-terminated
1786 fontData
->GetGDIPlusFont(),
1788 GetDrawTextStringFormat(),
1789 fontData
->GetGDIPlusBrush()
1793 void wxGDIPlusContext::GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
1794 wxDouble
*descent
, wxDouble
*externalLeading
) const
1796 wxCHECK_RET( !m_font
.IsNull(), wxT("wxGDIPlusContext::GetTextExtent - no valid font set") );
1798 wxWCharBuffer s
= str
.wc_str( *wxConvUI
);
1799 FontFamily ffamily
;
1800 Font
* f
= ((wxGDIPlusFontData
*)m_font
.GetRefData())->GetGDIPlusFont();
1802 f
->GetFamily(&ffamily
) ;
1804 REAL factorY
= m_fontScaleRatio
;
1806 // Notice that we must use the real font style or the results would be
1807 // incorrect for italic/bold fonts.
1808 const INT style
= f
->GetStyle();
1809 const REAL size
= f
->GetSize();
1810 const REAL emHeight
= ffamily
.GetEmHeight(style
);
1811 REAL rDescent
= ffamily
.GetCellDescent(style
) * size
/ emHeight
;
1812 REAL rAscent
= ffamily
.GetCellAscent(style
) * size
/ emHeight
;
1813 REAL rHeight
= ffamily
.GetLineSpacing(style
) * size
/ emHeight
;
1816 *height
= rHeight
* factorY
;
1818 *descent
= rDescent
* factorY
;
1819 if ( externalLeading
)
1820 *externalLeading
= (rHeight
- rAscent
- rDescent
) * factorY
;
1821 // measuring empty strings is not guaranteed, so do it by hand
1829 RectF
layoutRect(0,0, 100000.0f
, 100000.0f
);
1832 m_context
->MeasureString((const wchar_t *) s
, wcslen(s
) , f
, layoutRect
, GetDrawTextStringFormat(), &bounds
) ;
1834 *width
= bounds
.Width
;
1836 *height
= bounds
.Height
;
1840 void wxGDIPlusContext::GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const
1843 widths
.Add(0, text
.length());
1845 wxCHECK_RET( !m_font
.IsNull(), wxT("wxGDIPlusContext::GetPartialTextExtents - no valid font set") );
1850 Font
* f
= ((wxGDIPlusFontData
*)m_font
.GetRefData())->GetGDIPlusFont();
1851 wxWCharBuffer ws
= text
.wc_str( *wxConvUI
);
1852 size_t len
= wcslen( ws
) ;
1853 wxASSERT_MSG(text
.length() == len
, wxT("GetPartialTextExtents not yet implemented for multichar situations"));
1855 RectF
layoutRect(0,0, 100000.0f
, 100000.0f
);
1856 StringFormat
strFormat( GetDrawTextStringFormat() );
1858 size_t startPosition
= 0;
1859 size_t remainder
= len
;
1860 const size_t maxSpan
= 32;
1861 CharacterRange
* ranges
= new CharacterRange
[maxSpan
] ;
1862 Region
* regions
= new Region
[maxSpan
];
1864 while( remainder
> 0 )
1866 size_t span
= wxMin( maxSpan
, remainder
);
1868 for( size_t i
= 0 ; i
< span
; ++i
)
1870 ranges
[i
].First
= 0 ;
1871 ranges
[i
].Length
= startPosition
+i
+1 ;
1873 strFormat
.SetMeasurableCharacterRanges(span
,ranges
);
1874 m_context
->MeasureCharacterRanges(ws
, -1 , f
,layoutRect
, &strFormat
,span
,regions
) ;
1877 for ( size_t i
= 0 ; i
< span
; ++i
)
1879 regions
[i
].GetBounds(&bbox
,m_context
);
1880 widths
[startPosition
+i
] = bbox
.Width
;
1883 startPosition
+= span
;
1890 bool wxGDIPlusContext::ShouldOffset() const
1892 if ( !m_enableOffset
)
1896 if ( !m_pen
.IsNull() )
1898 penwidth
= (int)((wxGDIPlusPenData
*)m_pen
.GetRefData())->GetWidth();
1899 if ( penwidth
== 0 )
1902 return ( penwidth
% 2 ) == 1;
1905 void* wxGDIPlusContext::GetNativeContext()
1910 // concatenates this transform with the current transform of this context
1911 void wxGDIPlusContext::ConcatTransform( const wxGraphicsMatrix
& matrix
)
1913 m_context
->MultiplyTransform((Matrix
*) matrix
.GetNativeMatrix());
1916 // sets the transform of this context
1917 void wxGDIPlusContext::SetTransform( const wxGraphicsMatrix
& matrix
)
1919 m_context
->SetTransform((Matrix
*) matrix
.GetNativeMatrix());
1922 // gets the matrix of this context
1923 wxGraphicsMatrix
wxGDIPlusContext::GetTransform() const
1925 wxGraphicsMatrix matrix
= CreateMatrix();
1926 m_context
->GetTransform((Matrix
*) matrix
.GetNativeMatrix());
1930 void wxGDIPlusContext::GetSize( wxDouble
* width
, wxDouble
*height
)
1936 //-----------------------------------------------------------------------------
1937 // wxGDIPlusPrintingContext implementation
1938 //-----------------------------------------------------------------------------
1940 wxGDIPlusPrintingContext::wxGDIPlusPrintingContext( wxGraphicsRenderer
* renderer
,
1942 : wxGDIPlusContext(renderer
, dc
)
1944 Graphics
* context
= GetGraphics();
1946 //m_context->SetPageUnit(UnitDocument);
1948 // Setup page scale, based on DPI ratio.
1949 // Antecedent should be 100dpi when the default page unit
1950 // (UnitDisplay) is used. Page unit UnitDocument would require 300dpi
1951 // instead. Note that calling SetPageScale() does not have effect on
1952 // non-printing DCs (that is, any other than wxPrinterDC or
1953 // wxEnhMetaFileDC).
1954 REAL dpiRatio
= 100.0 / context
->GetDpiY();
1955 context
->SetPageScale(dpiRatio
);
1957 // We use this modifier when measuring fonts. It is needed because the
1958 // page scale is modified above.
1959 m_fontScaleRatio
= context
->GetDpiY() / 72.0;
1962 //-----------------------------------------------------------------------------
1963 // wxGDIPlusRenderer implementation
1964 //-----------------------------------------------------------------------------
1966 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRenderer
,wxGraphicsRenderer
)
1968 static wxGDIPlusRenderer gs_GDIPlusRenderer
;
1970 wxGraphicsRenderer
* wxGraphicsRenderer::GetDefaultRenderer()
1972 return &gs_GDIPlusRenderer
;
1975 bool wxGDIPlusRenderer::EnsureIsLoaded()
1977 // load gdiplus.dll if not yet loaded, but don't bother doing it again
1978 // if we already tried and failed (we don't want to spend lot of time
1979 // returning NULL from wxGraphicsContext::Create(), which may be called
1980 // relatively frequently):
1981 if ( m_loaded
== -1 )
1986 return m_loaded
== 1;
1989 // call EnsureIsLoaded() and return returnOnFail value if it fails
1990 #define ENSURE_LOADED_OR_RETURN(returnOnFail) \
1991 if ( !EnsureIsLoaded() ) \
1992 return (returnOnFail)
1995 void wxGDIPlusRenderer::Load()
1997 GdiplusStartupInput input
;
1998 GdiplusStartupOutput output
;
1999 if ( GdiplusStartup(&m_gditoken
,&input
,&output
) == Gdiplus::Ok
)
2001 wxLogTrace("gdiplus", "successfully initialized GDI+");
2006 wxLogTrace("gdiplus", "failed to initialize GDI+, missing gdiplus.dll?");
2011 void wxGDIPlusRenderer::Unload()
2015 GdiplusShutdown(m_gditoken
);
2018 m_loaded
= -1; // next Load() will try again
2021 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxWindowDC
& dc
)
2023 ENSURE_LOADED_OR_RETURN(NULL
);
2024 wxGDIPlusContext
* context
= new wxGDIPlusContext(this, dc
);
2025 context
->EnableOffset(true);
2029 #if wxUSE_PRINTING_ARCHITECTURE
2030 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxPrinterDC
& dc
)
2032 ENSURE_LOADED_OR_RETURN(NULL
);
2033 wxGDIPlusContext
* context
= new wxGDIPlusPrintingContext(this, dc
);
2038 #if wxUSE_ENH_METAFILE
2039 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxEnhMetaFileDC
& dc
)
2041 ENSURE_LOADED_OR_RETURN(NULL
);
2042 wxGDIPlusContext
* context
= new wxGDIPlusPrintingContext(this, dc
);
2047 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxMemoryDC
& dc
)
2049 ENSURE_LOADED_OR_RETURN(NULL
);
2050 wxGDIPlusContext
* context
= new wxGDIPlusContext(this, dc
);
2051 context
->EnableOffset(true);
2056 wxGraphicsContext
* wxGDIPlusRenderer::CreateContextFromImage(wxImage
& image
)
2058 ENSURE_LOADED_OR_RETURN(NULL
);
2059 wxGDIPlusContext
* context
= new wxGDIPlusImageContext(this, image
);
2060 context
->EnableOffset(true);
2064 #endif // wxUSE_IMAGE
2066 wxGraphicsContext
* wxGDIPlusRenderer::CreateMeasuringContext()
2068 ENSURE_LOADED_OR_RETURN(NULL
);
2069 return new wxGDIPlusMeasuringContext(this);
2072 wxGraphicsContext
* wxGDIPlusRenderer::CreateContextFromNativeContext( void * context
)
2074 ENSURE_LOADED_OR_RETURN(NULL
);
2075 return new wxGDIPlusContext(this,(Graphics
*) context
);
2079 wxGraphicsContext
* wxGDIPlusRenderer::CreateContextFromNativeWindow( void * window
)
2081 ENSURE_LOADED_OR_RETURN(NULL
);
2082 return new wxGDIPlusContext(this,(HWND
) window
);
2085 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( wxWindow
* window
)
2087 ENSURE_LOADED_OR_RETURN(NULL
);
2088 return new wxGDIPlusContext(this, (HWND
) window
->GetHWND() );
2093 wxGraphicsPath
wxGDIPlusRenderer::CreatePath()
2095 ENSURE_LOADED_OR_RETURN(wxNullGraphicsPath
);
2097 m
.SetRefData( new wxGDIPlusPathData(this));
2104 wxGraphicsMatrix
wxGDIPlusRenderer::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
2105 wxDouble tx
, wxDouble ty
)
2108 ENSURE_LOADED_OR_RETURN(wxNullGraphicsMatrix
);
2110 wxGDIPlusMatrixData
* data
= new wxGDIPlusMatrixData( this );
2111 data
->Set( a
,b
,c
,d
,tx
,ty
) ;
2116 wxGraphicsPen
wxGDIPlusRenderer::CreatePen(const wxPen
& pen
)
2118 ENSURE_LOADED_OR_RETURN(wxNullGraphicsPen
);
2119 if ( !pen
.IsOk() || pen
.GetStyle() == wxTRANSPARENT
)
2120 return wxNullGraphicsPen
;
2124 p
.SetRefData(new wxGDIPlusPenData( this, pen
));
2129 wxGraphicsBrush
wxGDIPlusRenderer::CreateBrush(const wxBrush
& brush
)
2131 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush
);
2132 if ( !brush
.IsOk() || brush
.GetStyle() == wxTRANSPARENT
)
2133 return wxNullGraphicsBrush
;
2137 p
.SetRefData(new wxGDIPlusBrushData( this, brush
));
2143 wxGDIPlusRenderer::CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
2144 wxDouble x2
, wxDouble y2
,
2145 const wxGraphicsGradientStops
& stops
)
2147 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush
);
2149 wxGDIPlusBrushData
* d
= new wxGDIPlusBrushData( this );
2150 d
->CreateLinearGradientBrush(x1
, y1
, x2
, y2
, stops
);
2156 wxGDIPlusRenderer::CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
2157 wxDouble xc
, wxDouble yc
,
2159 const wxGraphicsGradientStops
& stops
)
2161 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush
);
2163 wxGDIPlusBrushData
* d
= new wxGDIPlusBrushData( this );
2164 d
->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,stops
);
2170 wxGDIPlusRenderer::CreateFont( const wxFont
&font
,
2171 const wxColour
&col
)
2173 ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont
);
2177 p
.SetRefData(new wxGDIPlusFontData( this, font
, col
));
2181 return wxNullGraphicsFont
;
2185 wxGDIPlusRenderer::CreateFont(double size
,
2186 const wxString
& facename
,
2188 const wxColour
& col
)
2190 ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont
);
2192 // Convert wxFont flags to GDI+ style:
2193 int style
= FontStyleRegular
;
2194 if ( flags
& wxFONTFLAG_ITALIC
)
2195 style
|= FontStyleItalic
;
2196 if ( flags
& wxFONTFLAG_UNDERLINED
)
2197 style
|= FontStyleUnderline
;
2198 if ( flags
& wxFONTFLAG_BOLD
)
2199 style
|= FontStyleBold
;
2200 if ( flags
& wxFONTFLAG_STRIKETHROUGH
)
2201 style
|= FontStyleStrikeout
;
2205 f
.SetRefData(new wxGDIPlusFontData(this, facename
, size
, style
, col
));
2209 wxGraphicsBitmap
wxGDIPlusRenderer::CreateBitmap( const wxBitmap
&bitmap
)
2211 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap
);
2212 if ( bitmap
.IsOk() )
2215 p
.SetRefData(new wxGDIPlusBitmapData( this , bitmap
));
2219 return wxNullGraphicsBitmap
;
2224 wxGraphicsBitmap
wxGDIPlusRenderer::CreateBitmapFromImage(const wxImage
& image
)
2226 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap
);
2229 // Notice that we rely on conversion from wxImage to wxBitmap here but
2230 // we could probably do it more efficiently by converting from wxImage
2231 // to GDI+ Bitmap directly, i.e. copying wxImage pixels to the buffer
2232 // returned by Bitmap::LockBits(). However this would require writing
2233 // code specific for this task while like this we can reuse existing
2234 // code (see also wxGDIPlusBitmapData::ConvertToImage()).
2235 wxGraphicsBitmap gb
;
2236 gb
.SetRefData(new wxGDIPlusBitmapData(this, image
));
2240 return wxNullGraphicsBitmap
;
2244 wxImage
wxGDIPlusRenderer::CreateImageFromBitmap(const wxGraphicsBitmap
& bmp
)
2246 ENSURE_LOADED_OR_RETURN(wxNullImage
);
2247 const wxGDIPlusBitmapData
* const
2248 data
= static_cast<wxGDIPlusBitmapData
*>(bmp
.GetGraphicsData());
2250 return data
? data
->ConvertToImage() : wxNullImage
;
2253 #endif // wxUSE_IMAGE
2256 wxGraphicsBitmap
wxGDIPlusRenderer::CreateBitmapFromNativeBitmap( void *bitmap
)
2258 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap
);
2259 if ( bitmap
!= NULL
)
2262 p
.SetRefData(new wxGDIPlusBitmapData( this , (Bitmap
*) bitmap
));
2266 return wxNullGraphicsBitmap
;
2269 wxGraphicsBitmap
wxGDIPlusRenderer::CreateSubBitmap( const wxGraphicsBitmap
&bitmap
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
2271 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap
);
2272 Bitmap
* image
= static_cast<wxGDIPlusBitmapData
*>(bitmap
.GetRefData())->GetGDIPlusBitmap();
2276 p
.SetRefData(new wxGDIPlusBitmapData( this , image
->Clone( (REAL
) x
, (REAL
) y
, (REAL
) w
, (REAL
) h
, PixelFormat32bppPARGB
) ));
2280 return wxNullGraphicsBitmap
;
2283 // Shutdown GDI+ at app exit, before possible dll unload
2284 class wxGDIPlusRendererModule
: public wxModule
2287 virtual bool OnInit() { return true; }
2288 virtual void OnExit()
2290 wxDELETE(gs_drawTextStringFormat
);
2292 gs_GDIPlusRenderer
.Unload();
2296 DECLARE_DYNAMIC_CLASS(wxGDIPlusRendererModule
)
2299 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRendererModule
, wxModule
)
2301 // ----------------------------------------------------------------------------
2302 // wxMSW-specific parts of wxGCDC
2303 // ----------------------------------------------------------------------------
2305 WXHDC
wxGCDC::AcquireHDC()
2307 wxGraphicsContext
* const gc
= GetGraphicsContext();
2312 // we can't get the HDC if it is not a GDI+ context
2313 wxGraphicsRenderer
* r1
= gc
->GetRenderer();
2314 wxGraphicsRenderer
* r2
= wxGraphicsRenderer::GetCairoRenderer();
2319 Graphics
* const g
= static_cast<Graphics
*>(gc
->GetNativeContext());
2320 return g
? g
->GetHDC() : NULL
;
2323 void wxGCDC::ReleaseHDC(WXHDC hdc
)
2328 wxGraphicsContext
* const gc
= GetGraphicsContext();
2329 wxCHECK_RET( gc
, "can't release HDC because there is no wxGraphicsContext" );
2332 // we can't get the HDC if it is not a GDI+ context
2333 wxGraphicsRenderer
* r1
= gc
->GetRenderer();
2334 wxGraphicsRenderer
* r2
= wxGraphicsRenderer::GetCairoRenderer();
2339 Graphics
* const g
= static_cast<Graphics
*>(gc
->GetNativeContext());
2340 wxCHECK_RET( g
, "can't release HDC because there is no Graphics" );
2342 g
->ReleaseHDC((HDC
)hdc
);
2345 #endif // wxUSE_GRAPHICS_CONTEXT