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 gs_drawTextStringFormat
= new StringFormat(StringFormat::GenericTypographic());
94 // This doesn't make any difference for DrawText() actually but we want
95 // this behaviour when measuring text.
96 gs_drawTextStringFormat
->SetFormatFlags
98 gs_drawTextStringFormat
->GetFormatFlags()
99 | StringFormatFlagsMeasureTrailingSpaces
103 return gs_drawTextStringFormat
;
106 } // anonymous namespace
108 //-----------------------------------------------------------------------------
109 // device context implementation
111 // more and more of the dc functionality should be implemented by calling
112 // the appropricate wxGDIPlusContext, but we will have to do that step by step
113 // also coordinate conversions should be moved to native matrix ops
114 //-----------------------------------------------------------------------------
116 // we always stock two context states, one at entry, to be able to preserve the
117 // state we were called with, the other one after changing to HI Graphics orientation
118 // (this one is used for getting back clippings etc)
120 //-----------------------------------------------------------------------------
121 // wxGraphicsPath implementation
122 //-----------------------------------------------------------------------------
124 class wxGDIPlusContext
;
126 class wxGDIPlusPathData
: public wxGraphicsPathData
129 wxGDIPlusPathData(wxGraphicsRenderer
* renderer
, GraphicsPath
* path
= NULL
);
130 ~wxGDIPlusPathData();
132 virtual wxGraphicsObjectRefData
*Clone() const;
135 // These are the path primitives from which everything else can be constructed
138 // begins a new subpath at (x,y)
139 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
141 // adds a straight line from the current point to (x,y)
142 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
144 // adds a cubic Bezier curve from the current point, using two control points and an end point
145 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
148 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
149 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
) ;
151 // gets the last point of the current path, (0,0) if not yet set
152 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
155 virtual void AddPath( const wxGraphicsPathData
* path
);
157 // closes the current sub-path
158 virtual void CloseSubpath();
161 // These are convenience functions which - if not available natively will be assembled
162 // using the primitives from above
165 // appends a rectangle as a new closed subpath
166 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) ;
169 // appends an ellipsis as a new closed subpath fitting the passed rectangle
170 virtual void AddEllipsis( wxDouble x, wxDouble y, wxDouble w , wxDouble h ) ;
172 // 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)
173 virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
176 // returns the native path
177 virtual void * GetNativePath() const { return m_path
; }
179 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
180 virtual void UnGetNativePath(void * WXUNUSED(path
)) const {}
182 // transforms each point of this path by the matrix
183 virtual void Transform( const wxGraphicsMatrixData
* matrix
) ;
185 // gets the bounding box enclosing all points (possibly including control points)
186 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const;
188 virtual bool Contains( wxDouble x
, wxDouble y
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
) const;
191 GraphicsPath
* m_path
;
194 class wxGDIPlusMatrixData
: public wxGraphicsMatrixData
197 wxGDIPlusMatrixData(wxGraphicsRenderer
* renderer
, Matrix
* matrix
= NULL
) ;
198 virtual ~wxGDIPlusMatrixData() ;
200 virtual wxGraphicsObjectRefData
* Clone() const ;
202 // concatenates the matrix
203 virtual void Concat( const wxGraphicsMatrixData
*t
);
205 // sets the matrix to the respective values
206 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
207 wxDouble tx
=0.0, wxDouble ty
=0.0);
209 // gets the component valuess of the matrix
210 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
211 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
213 // makes this the inverse matrix
214 virtual void Invert();
216 // returns true if the elements of the transformation matrix are equal ?
217 virtual bool IsEqual( const wxGraphicsMatrixData
* t
) const ;
219 // return true if this is the identity matrix
220 virtual bool IsIdentity() const;
226 // add the translation to this matrix
227 virtual void Translate( wxDouble dx
, wxDouble dy
);
229 // add the scale to this matrix
230 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
232 // add the rotation to this matrix (radians)
233 virtual void Rotate( wxDouble angle
);
236 // apply the transforms
239 // applies that matrix to the point
240 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
242 // applies the matrix except for translations
243 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
245 // returns the native representation
246 virtual void * GetNativeMatrix() const;
251 class wxGDIPlusPenData
: public wxGraphicsObjectRefData
254 wxGDIPlusPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
);
259 virtual wxDouble
GetWidth() { return m_width
; }
260 virtual Pen
* GetGDIPlusPen() { return m_pen
; }
270 class wxGDIPlusBrushData
: public wxGraphicsObjectRefData
273 wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
);
274 wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
);
275 ~wxGDIPlusBrushData ();
277 void CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
278 wxDouble x2
, wxDouble y2
,
279 const wxGraphicsGradientStops
& stops
);
280 void CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
281 wxDouble xc
, wxDouble yc
,
283 const wxGraphicsGradientStops
& stops
);
285 virtual Brush
* GetGDIPlusBrush() { return m_brush
; }
291 // common part of Create{Linear,Radial}GradientBrush()
292 template <typename T
>
293 void SetGradientStops(T
*brush
, const wxGraphicsGradientStops
& stops
);
297 GraphicsPath
* m_brushPath
;
300 class WXDLLIMPEXP_CORE wxGDIPlusBitmapData
: public wxGraphicsBitmapData
303 wxGDIPlusBitmapData( wxGraphicsRenderer
* renderer
, Bitmap
* bitmap
);
304 wxGDIPlusBitmapData( wxGraphicsRenderer
* renderer
, const wxBitmap
&bmp
);
305 ~wxGDIPlusBitmapData ();
307 virtual Bitmap
* GetGDIPlusBitmap() { return m_bitmap
; }
308 virtual void* GetNativeBitmap() const { return m_bitmap
; }
311 wxImage
ConvertToImage() const;
312 #endif // wxUSE_IMAGE
319 class wxGDIPlusFontData
: public wxGraphicsObjectRefData
322 wxGDIPlusFontData( wxGraphicsRenderer
* renderer
,
324 const wxColour
& col
);
325 wxGDIPlusFontData(wxGraphicsRenderer
* renderer
,
326 const wxString
& name
,
329 const wxColour
& col
);
330 ~wxGDIPlusFontData();
332 virtual Brush
* GetGDIPlusBrush() { return m_textBrush
; }
333 virtual Font
* GetGDIPlusFont() { return m_font
; }
336 // Common part of all ctors, flags here is a combination of values of
337 // FontStyle GDI+ enum.
338 void Init(const wxString
& name
,
348 class wxGDIPlusContext
: public wxGraphicsContext
351 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, const wxDC
& dc
);
352 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HDC hdc
, wxDouble width
, wxDouble height
);
353 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HWND hwnd
);
354 wxGDIPlusContext( wxGraphicsRenderer
* renderer
, Graphics
* gr
);
355 wxGDIPlusContext(wxGraphicsRenderer
* renderer
);
357 virtual ~wxGDIPlusContext();
359 virtual void Clip( const wxRegion
®ion
);
360 // clips drawings to the rect
361 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
363 // resets the clipping to original extent
364 virtual void ResetClip();
366 virtual void * GetNativeContext();
368 virtual void StrokePath( const wxGraphicsPath
& p
);
369 virtual void FillPath( const wxGraphicsPath
& p
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
371 virtual void DrawRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
373 // stroke lines connecting each of the points
374 virtual void StrokeLines( size_t n
, const wxPoint2DDouble
*points
);
376 // We don't have any specific implementation for this one in wxMSW but
377 // override it just to avoid warnings about hiding the base class virtual.
378 virtual void StrokeLines( size_t n
, const wxPoint2DDouble
*beginPoints
, const wxPoint2DDouble
*endPoints
)
380 wxGraphicsContext::StrokeLines(n
, beginPoints
, endPoints
);
384 virtual void DrawLines( size_t n
, const wxPoint2DDouble
*points
, wxPolygonFillMode fillStyle
= wxODDEVEN_RULE
);
386 virtual bool SetAntialiasMode(wxAntialiasMode antialias
);
388 virtual bool SetInterpolationQuality(wxInterpolationQuality interpolation
);
390 virtual bool SetCompositionMode(wxCompositionMode op
);
392 virtual void BeginLayer(wxDouble opacity
);
394 virtual void EndLayer();
396 virtual void Translate( wxDouble dx
, wxDouble dy
);
397 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
398 virtual void Rotate( wxDouble angle
);
400 // concatenates this transform with the current transform of this context
401 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
);
403 // sets the transform of this context
404 virtual void SetTransform( const wxGraphicsMatrix
& matrix
);
406 // gets the matrix of this context
407 virtual wxGraphicsMatrix
GetTransform() const;
409 virtual void DrawBitmap( const wxGraphicsBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
410 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
411 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
412 virtual void PushState();
413 virtual void PopState();
415 virtual void GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
416 wxDouble
*descent
, wxDouble
*externalLeading
) const;
417 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const;
418 virtual bool ShouldOffset() const;
419 virtual void GetSize( wxDouble
* width
, wxDouble
*height
);
421 Graphics
* GetGraphics() const { return m_context
; }
425 wxDouble m_fontScaleRatio
;
427 // Used from ctors (including those in the derived classes) and takes
428 // ownership of the graphics pointer that must be non-NULL.
429 void Init(Graphics
* graphics
, int width
, int height
);
432 virtual void DoDrawText(const wxString
& str
, wxDouble x
, wxDouble y
);
435 wxStack
<GraphicsState
> m_stateStack
;
436 GraphicsState m_state1
;
437 GraphicsState m_state2
;
439 wxDECLARE_NO_COPY_CLASS(wxGDIPlusContext
);
444 class wxGDIPlusImageContext
: public wxGDIPlusContext
447 wxGDIPlusImageContext(wxGraphicsRenderer
* renderer
, wxImage
& image
) :
448 wxGDIPlusContext(renderer
),
450 m_bitmap(renderer
, image
)
454 new Graphics(m_bitmap
.GetGDIPlusBitmap()),
460 virtual ~wxGDIPlusImageContext()
462 m_image
= m_bitmap
.ConvertToImage();
467 wxGDIPlusBitmapData m_bitmap
;
469 wxDECLARE_NO_COPY_CLASS(wxGDIPlusImageContext
);
472 #endif // wxUSE_IMAGE
474 class wxGDIPlusMeasuringContext
: public wxGDIPlusContext
477 wxGDIPlusMeasuringContext( wxGraphicsRenderer
* renderer
) : wxGDIPlusContext( renderer
, m_hdc
= GetDC(NULL
), 1000, 1000 )
481 virtual ~wxGDIPlusMeasuringContext()
483 ReleaseDC( NULL
, m_hdc
);
490 class wxGDIPlusPrintingContext
: public wxGDIPlusContext
493 wxGDIPlusPrintingContext( wxGraphicsRenderer
* renderer
, const wxDC
& dc
);
494 virtual ~wxGDIPlusPrintingContext() { }
498 //-----------------------------------------------------------------------------
499 // wxGDIPlusRenderer declaration
500 //-----------------------------------------------------------------------------
502 class wxGDIPlusRenderer
: public wxGraphicsRenderer
511 virtual ~wxGDIPlusRenderer()
521 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
);
523 virtual wxGraphicsContext
* CreateContext( const wxMemoryDC
& dc
);
525 #if wxUSE_PRINTING_ARCHITECTURE
526 virtual wxGraphicsContext
* CreateContext( const wxPrinterDC
& dc
);
529 #if wxUSE_ENH_METAFILE
530 virtual wxGraphicsContext
* CreateContext( const wxEnhMetaFileDC
& dc
);
533 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
);
535 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
);
537 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
);
540 virtual wxGraphicsContext
* CreateContextFromImage(wxImage
& image
);
541 #endif // wxUSE_IMAGE
543 virtual wxGraphicsContext
* CreateMeasuringContext();
547 virtual wxGraphicsPath
CreatePath();
551 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
552 wxDouble tx
=0.0, wxDouble ty
=0.0);
555 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) ;
557 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) ;
559 virtual wxGraphicsBrush
560 CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
561 wxDouble x2
, wxDouble y2
,
562 const wxGraphicsGradientStops
& stops
);
564 virtual wxGraphicsBrush
565 CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
566 wxDouble xc
, wxDouble yc
,
568 const wxGraphicsGradientStops
& stops
);
570 // create a native bitmap representation
571 virtual wxGraphicsBitmap
CreateBitmap( const wxBitmap
&bitmap
);
573 virtual wxGraphicsBitmap
CreateBitmapFromImage(const wxImage
& image
);
574 virtual wxImage
CreateImageFromBitmap(const wxGraphicsBitmap
& bmp
);
575 #endif // wxUSE_IMAGE
577 virtual wxGraphicsFont
CreateFont( const wxFont
& font
,
578 const wxColour
& col
);
580 virtual wxGraphicsFont
CreateFont(double size
,
581 const wxString
& facename
,
582 int flags
= wxFONTFLAG_DEFAULT
,
583 const wxColour
& col
= *wxBLACK
);
585 // create a graphics bitmap from a native bitmap
586 virtual wxGraphicsBitmap
CreateBitmapFromNativeBitmap( void* bitmap
);
588 // create a subimage from a native image representation
589 virtual wxGraphicsBitmap
CreateSubBitmap( const wxGraphicsBitmap
&bitmap
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
592 bool EnsureIsLoaded();
595 friend class wxGDIPlusRendererModule
;
599 ULONG_PTR m_gditoken
;
601 DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusRenderer
)
604 //-----------------------------------------------------------------------------
605 // wxGDIPlusPen implementation
606 //-----------------------------------------------------------------------------
608 wxGDIPlusPenData::~wxGDIPlusPenData()
615 void wxGDIPlusPenData::Init()
622 wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
)
623 : wxGraphicsObjectRefData(renderer
)
626 m_width
= pen
.GetWidth();
630 m_pen
= new Pen(wxColourToColor(pen
.GetColour()), m_width
);
633 switch ( pen
.GetCap() )
639 case wxCAP_PROJECTING
:
644 cap
= LineCapFlat
; // TODO verify
651 m_pen
->SetLineCap(cap
,cap
, DashCapFlat
);
654 switch ( pen
.GetJoin() )
657 join
= LineJoinBevel
;
661 join
= LineJoinMiter
;
665 join
= LineJoinRound
;
669 join
= LineJoinMiter
;
673 m_pen
->SetLineJoin(join
);
675 m_pen
->SetDashStyle(DashStyleSolid
);
677 DashStyle dashStyle
= DashStyleSolid
;
678 switch ( pen
.GetStyle() )
680 case wxPENSTYLE_SOLID
:
683 case wxPENSTYLE_DOT
:
684 dashStyle
= DashStyleDot
;
687 case wxPENSTYLE_LONG_DASH
:
688 dashStyle
= DashStyleDash
; // TODO verify
691 case wxPENSTYLE_SHORT_DASH
:
692 dashStyle
= DashStyleDash
;
695 case wxPENSTYLE_DOT_DASH
:
696 dashStyle
= DashStyleDashDot
;
698 case wxPENSTYLE_USER_DASH
:
700 dashStyle
= DashStyleCustom
;
702 int count
= pen
.GetDashes( &dashes
);
703 if ((dashes
!= NULL
) && (count
> 0))
705 REAL
*userLengths
= new REAL
[count
];
706 for ( int i
= 0; i
< count
; ++i
)
708 userLengths
[i
] = dashes
[i
];
710 m_pen
->SetDashPattern( userLengths
, count
);
711 delete[] userLengths
;
715 case wxPENSTYLE_STIPPLE
:
717 wxBitmap
* bmp
= pen
.GetStipple();
718 if ( bmp
&& bmp
->IsOk() )
720 m_penImage
= Bitmap::FromHBITMAP((HBITMAP
)bmp
->GetHBITMAP(),
722 (HPALETTE
)bmp
->GetPalette()->GetHPALETTE()
727 m_penBrush
= new TextureBrush(m_penImage
);
728 m_pen
->SetBrush( m_penBrush
);
734 if ( pen
.GetStyle() >= wxPENSTYLE_FIRST_HATCH
&&
735 pen
.GetStyle() <= wxPENSTYLE_LAST_HATCH
)
738 switch( pen
.GetStyle() )
740 case wxPENSTYLE_BDIAGONAL_HATCH
:
741 style
= HatchStyleBackwardDiagonal
;
743 case wxPENSTYLE_CROSSDIAG_HATCH
:
744 style
= HatchStyleDiagonalCross
;
746 case wxPENSTYLE_FDIAGONAL_HATCH
:
747 style
= HatchStyleForwardDiagonal
;
749 case wxPENSTYLE_CROSS_HATCH
:
750 style
= HatchStyleCross
;
752 case wxPENSTYLE_HORIZONTAL_HATCH
:
753 style
= HatchStyleHorizontal
;
755 case wxPENSTYLE_VERTICAL_HATCH
:
756 style
= HatchStyleVertical
;
759 style
= HatchStyleHorizontal
;
761 m_penBrush
= new HatchBrush
764 wxColourToColor(pen
.GetColour()),
767 m_pen
->SetBrush( m_penBrush
);
771 if ( dashStyle
!= DashStyleSolid
)
772 m_pen
->SetDashStyle(dashStyle
);
775 //-----------------------------------------------------------------------------
776 // wxGDIPlusBrush implementation
777 //-----------------------------------------------------------------------------
779 wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
)
780 : wxGraphicsObjectRefData(renderer
)
785 wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
)
786 : wxGraphicsObjectRefData(renderer
)
789 if ( brush
.GetStyle() == wxSOLID
)
791 m_brush
= new SolidBrush(wxColourToColor( brush
.GetColour()));
793 else if ( brush
.IsHatch() )
796 switch( brush
.GetStyle() )
798 case wxBRUSHSTYLE_BDIAGONAL_HATCH
:
799 style
= HatchStyleBackwardDiagonal
;
801 case wxBRUSHSTYLE_CROSSDIAG_HATCH
:
802 style
= HatchStyleDiagonalCross
;
804 case wxBRUSHSTYLE_FDIAGONAL_HATCH
:
805 style
= HatchStyleForwardDiagonal
;
807 case wxBRUSHSTYLE_CROSS_HATCH
:
808 style
= HatchStyleCross
;
810 case wxBRUSHSTYLE_HORIZONTAL_HATCH
:
811 style
= HatchStyleHorizontal
;
813 case wxBRUSHSTYLE_VERTICAL_HATCH
:
814 style
= HatchStyleVertical
;
817 style
= HatchStyleHorizontal
;
819 m_brush
= new HatchBrush
822 wxColourToColor(brush
.GetColour()),
828 wxBitmap
* bmp
= brush
.GetStipple();
829 if ( bmp
&& bmp
->IsOk() )
831 wxDELETE( m_brushImage
);
832 m_brushImage
= Bitmap::FromHBITMAP((HBITMAP
)bmp
->GetHBITMAP(),
834 (HPALETTE
)bmp
->GetPalette()->GetHPALETTE()
839 m_brush
= new TextureBrush(m_brushImage
);
844 wxGDIPlusBrushData::~wxGDIPlusBrushData()
851 void wxGDIPlusBrushData::Init()
858 template <typename T
>
860 wxGDIPlusBrushData::SetGradientStops(T
*brush
,
861 const wxGraphicsGradientStops
& stops
)
863 const unsigned numStops
= stops
.GetCount();
866 // initial and final colours are set during the brush creation, nothing
871 wxVector
<Color
> colors(numStops
);
872 wxVector
<REAL
> positions(numStops
);
874 for ( unsigned i
= 0; i
< numStops
; i
++ )
876 wxGraphicsGradientStop stop
= stops
.Item(i
);
878 colors
[i
] = wxColourToColor(stop
.GetColour());
879 positions
[i
] = stop
.GetPosition();
882 brush
->SetInterpolationColors(&colors
[0], &positions
[0], numStops
);
886 wxGDIPlusBrushData::CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
887 wxDouble x2
, wxDouble y2
,
888 const wxGraphicsGradientStops
& stops
)
890 LinearGradientBrush
* const
891 brush
= new LinearGradientBrush(PointF(x1
, y1
) , PointF(x2
, y2
),
892 wxColourToColor(stops
.GetStartColour()),
893 wxColourToColor(stops
.GetEndColour()));
896 SetGradientStops(brush
, stops
);
900 wxGDIPlusBrushData::CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
901 wxDouble xc
, wxDouble yc
,
903 const wxGraphicsGradientStops
& stops
)
905 m_brushPath
= new GraphicsPath();
906 m_brushPath
->AddEllipse( (REAL
)(xc
-radius
), (REAL
)(yc
-radius
),
907 (REAL
)(2*radius
), (REAL
)(2*radius
));
909 PathGradientBrush
* const brush
= new PathGradientBrush(m_brushPath
);
911 brush
->SetCenterPoint(PointF(xo
, yo
));
912 brush
->SetCenterColor(wxColourToColor(stops
.GetStartColour()));
914 const Color
col(wxColourToColor(stops
.GetEndColour()));
916 brush
->SetSurroundColors(&col
, &count
);
918 SetGradientStops(brush
, stops
);
921 //-----------------------------------------------------------------------------
922 // wxGDIPlusFont implementation
923 //-----------------------------------------------------------------------------
926 wxGDIPlusFontData::Init(const wxString
& name
,
932 m_font
= new Font(name
.wc_str(), size
, style
, fontUnit
);
934 m_textBrush
= new SolidBrush(wxColourToColor(col
));
937 wxGDIPlusFontData::wxGDIPlusFontData( wxGraphicsRenderer
* renderer
,
939 const wxColour
& col
)
940 : wxGraphicsObjectRefData( renderer
)
942 int style
= FontStyleRegular
;
943 if ( font
.GetStyle() == wxFONTSTYLE_ITALIC
)
944 style
|= FontStyleItalic
;
945 if ( font
.GetUnderlined() )
946 style
|= FontStyleUnderline
;
947 if ( font
.GetWeight() == wxFONTWEIGHT_BOLD
)
948 style
|= FontStyleBold
;
950 Init(font
.GetFaceName(), font
.GetPointSize(), style
, col
, UnitPoint
);
953 wxGDIPlusFontData::wxGDIPlusFontData(wxGraphicsRenderer
* renderer
,
954 const wxString
& name
,
957 const wxColour
& col
) :
958 wxGraphicsObjectRefData(renderer
)
960 Init(name
, sizeInPixels
, style
, col
, UnitPixel
);
963 wxGDIPlusFontData::~wxGDIPlusFontData()
969 // the built-in conversions functions create non-premultiplied bitmaps, while GDIPlus needs them in the
970 // premultiplied format, therefore in the failing cases we create a new bitmap using the non-premultiplied
971 // bytes as parameter, since there is no real copying of the data going in, only references are stored
972 // m_helper has to be kept alive as well
974 //-----------------------------------------------------------------------------
975 // wxGDIPlusBitmapData implementation
976 //-----------------------------------------------------------------------------
978 wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer
* renderer
, Bitmap
* bitmap
) :
979 wxGraphicsBitmapData( renderer
), m_bitmap( bitmap
)
984 wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer
* renderer
,
985 const wxBitmap
&bmp
) : wxGraphicsBitmapData( renderer
)
990 Bitmap
* image
= NULL
;
993 Bitmap
interim((HBITMAP
)bmp
.GetHBITMAP(),
995 (HPALETTE
)bmp
.GetPalette()->GetHPALETTE()
1001 size_t width
= interim
.GetWidth();
1002 size_t height
= interim
.GetHeight();
1003 Rect
bounds(0,0,width
,height
);
1005 image
= new Bitmap(width
,height
,PixelFormat32bppPARGB
) ;
1007 Bitmap
interimMask((HBITMAP
)bmp
.GetMask()->GetMaskBitmap(),NULL
);
1008 wxASSERT(interimMask
.GetPixelFormat() == PixelFormat1bppIndexed
);
1010 BitmapData dataMask
;
1011 interimMask
.LockBits(&bounds
,ImageLockModeRead
,
1012 interimMask
.GetPixelFormat(),&dataMask
);
1015 BitmapData imageData
;
1016 image
->LockBits(&bounds
,ImageLockModeWrite
, PixelFormat32bppPARGB
, &imageData
);
1018 BYTE maskPattern
= 0 ;
1022 for ( size_t y
= 0 ; y
< height
; ++y
)
1025 for( size_t x
= 0 ; x
< width
; ++x
)
1030 maskByte
= *((BYTE
*)dataMask
.Scan0
+ dataMask
.Stride
*y
+ maskIndex
);
1034 maskPattern
= maskPattern
>> 1;
1036 ARGB
*dest
= (ARGB
*)((BYTE
*)imageData
.Scan0
+ imageData
.Stride
*y
+ x
*4);
1037 if ( (maskByte
& maskPattern
) == 0 )
1042 interim
.GetPixel(x
,y
,&c
) ;
1043 *dest
= (c
.GetValue() | Color::AlphaMask
);
1048 image
->UnlockBits(&imageData
);
1050 interimMask
.UnlockBits(&dataMask
);
1051 interim
.UnlockBits(&dataMask
);
1055 image
= Bitmap::FromHBITMAP((HBITMAP
)bmp
.GetHBITMAP(),
1057 (HPALETTE
)bmp
.GetPalette()->GetHPALETTE()
1062 if ( bmp
.HasAlpha() && GetPixelFormatSize(image
->GetPixelFormat()) == 32 )
1064 size_t width
= image
->GetWidth();
1065 size_t height
= image
->GetHeight();
1066 Rect
bounds(0,0,width
,height
);
1067 static BitmapData data
;
1071 m_helper
->LockBits(&bounds
, ImageLockModeRead
,
1072 m_helper
->GetPixelFormat(),&data
);
1074 image
= new Bitmap(data
.Width
, data
.Height
, data
.Stride
,
1075 PixelFormat32bppPARGB
, (BYTE
*) data
.Scan0
);
1077 m_helper
->UnlockBits(&data
);
1086 wxImage
wxGDIPlusBitmapData::ConvertToImage() const
1088 // We could use Bitmap::LockBits() and convert to wxImage directly but
1089 // passing by wxBitmap is easier. It would be nice to measure performance
1090 // of the two methods but for this the second one would need to be written
1093 if ( m_bitmap
->GetHBITMAP(Color(0xffffffff), &hbmp
) != Gdiplus::Ok
)
1097 bmp
.SetWidth(m_bitmap
->GetWidth());
1098 bmp
.SetHeight(m_bitmap
->GetHeight());
1099 bmp
.SetHBITMAP(hbmp
);
1100 bmp
.SetDepth(IsAlphaPixelFormat(m_bitmap
->GetPixelFormat()) ? 32 : 24);
1101 return bmp
.ConvertToImage();
1104 #endif // wxUSE_IMAGE
1106 wxGDIPlusBitmapData::~wxGDIPlusBitmapData()
1112 //-----------------------------------------------------------------------------
1113 // wxGDIPlusPath implementation
1114 //-----------------------------------------------------------------------------
1116 wxGDIPlusPathData::wxGDIPlusPathData(wxGraphicsRenderer
* renderer
, GraphicsPath
* path
) : wxGraphicsPathData(renderer
)
1121 m_path
= new GraphicsPath();
1124 wxGDIPlusPathData::~wxGDIPlusPathData()
1129 wxGraphicsObjectRefData
* wxGDIPlusPathData::Clone() const
1131 return new wxGDIPlusPathData( GetRenderer() , m_path
->Clone());
1138 void wxGDIPlusPathData::MoveToPoint( wxDouble x
, wxDouble y
)
1140 m_path
->StartFigure();
1141 m_path
->AddLine((REAL
) x
,(REAL
) y
,(REAL
) x
,(REAL
) y
);
1144 void wxGDIPlusPathData::AddLineToPoint( wxDouble x
, wxDouble y
)
1146 m_path
->AddLine((REAL
) x
,(REAL
) y
,(REAL
) x
,(REAL
) y
);
1149 void wxGDIPlusPathData::CloseSubpath()
1151 m_path
->CloseFigure();
1154 void wxGDIPlusPathData::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
1160 m_path
->GetLastPoint(&start
);
1161 m_path
->AddBezier(start
,c1
,c2
,end
);
1164 // gets the last point of the current path, (0,0) if not yet set
1165 void wxGDIPlusPathData::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
1168 m_path
->GetLastPoint(&start
);
1173 void wxGDIPlusPathData::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, double startAngle
, double endAngle
, bool clockwise
)
1175 double sweepAngle
= endAngle
- startAngle
;
1176 if( fabs(sweepAngle
) >= 2*M_PI
)
1178 sweepAngle
= 2 * M_PI
;
1184 if( sweepAngle
< 0 )
1185 sweepAngle
+= 2 * M_PI
;
1189 if( sweepAngle
> 0 )
1190 sweepAngle
-= 2 * M_PI
;
1194 m_path
->AddArc((REAL
) (x
-r
),(REAL
) (y
-r
),(REAL
) (2*r
),(REAL
) (2*r
),RadToDeg(startAngle
),RadToDeg(sweepAngle
));
1197 void wxGDIPlusPathData::AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1199 m_path
->AddRectangle(RectF(x
,y
,w
,h
));
1202 void wxGDIPlusPathData::AddPath( const wxGraphicsPathData
* path
)
1204 m_path
->AddPath( (GraphicsPath
*) path
->GetNativePath(), FALSE
);
1208 // transforms each point of this path by the matrix
1209 void wxGDIPlusPathData::Transform( const wxGraphicsMatrixData
* matrix
)
1211 m_path
->Transform( (Matrix
*) matrix
->GetNativeMatrix() );
1214 // gets the bounding box enclosing all points (possibly including control points)
1215 void wxGDIPlusPathData::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
1218 m_path
->GetBounds( &bounds
, NULL
, NULL
) ;
1225 bool wxGDIPlusPathData::Contains( wxDouble x
, wxDouble y
, wxPolygonFillMode fillStyle
) const
1227 m_path
->SetFillMode( fillStyle
== wxODDEVEN_RULE
? FillModeAlternate
: FillModeWinding
);
1228 return m_path
->IsVisible( (FLOAT
) x
,(FLOAT
) y
) == TRUE
;
1231 //-----------------------------------------------------------------------------
1232 // wxGDIPlusMatrixData implementation
1233 //-----------------------------------------------------------------------------
1235 wxGDIPlusMatrixData::wxGDIPlusMatrixData(wxGraphicsRenderer
* renderer
, Matrix
* matrix
)
1236 : wxGraphicsMatrixData(renderer
)
1241 m_matrix
= new Matrix();
1244 wxGDIPlusMatrixData::~wxGDIPlusMatrixData()
1249 wxGraphicsObjectRefData
*wxGDIPlusMatrixData::Clone() const
1251 return new wxGDIPlusMatrixData( GetRenderer(), m_matrix
->Clone());
1254 // concatenates the matrix
1255 void wxGDIPlusMatrixData::Concat( const wxGraphicsMatrixData
*t
)
1257 m_matrix
->Multiply( (Matrix
*) t
->GetNativeMatrix());
1260 // sets the matrix to the respective values
1261 void wxGDIPlusMatrixData::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
1262 wxDouble tx
, wxDouble ty
)
1264 m_matrix
->SetElements(a
,b
,c
,d
,tx
,ty
);
1267 // gets the component valuess of the matrix
1268 void wxGDIPlusMatrixData::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
1269 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
1272 m_matrix
->GetElements(elements
);
1273 if (a
) *a
= elements
[0];
1274 if (b
) *b
= elements
[1];
1275 if (c
) *c
= elements
[2];
1276 if (d
) *d
= elements
[3];
1277 if (tx
) *tx
= elements
[4];
1278 if (ty
) *ty
= elements
[5];
1281 // makes this the inverse matrix
1282 void wxGDIPlusMatrixData::Invert()
1287 // returns true if the elements of the transformation matrix are equal ?
1288 bool wxGDIPlusMatrixData::IsEqual( const wxGraphicsMatrixData
* t
) const
1290 return m_matrix
->Equals((Matrix
*) t
->GetNativeMatrix())== TRUE
;
1293 // return true if this is the identity matrix
1294 bool wxGDIPlusMatrixData::IsIdentity() const
1296 return m_matrix
->IsIdentity() == TRUE
;
1303 // add the translation to this matrix
1304 void wxGDIPlusMatrixData::Translate( wxDouble dx
, wxDouble dy
)
1306 m_matrix
->Translate(dx
,dy
);
1309 // add the scale to this matrix
1310 void wxGDIPlusMatrixData::Scale( wxDouble xScale
, wxDouble yScale
)
1312 m_matrix
->Scale(xScale
,yScale
);
1315 // add the rotation to this matrix (radians)
1316 void wxGDIPlusMatrixData::Rotate( wxDouble angle
)
1318 m_matrix
->Rotate( RadToDeg(angle
) );
1322 // apply the transforms
1325 // applies that matrix to the point
1326 void wxGDIPlusMatrixData::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
1329 m_matrix
->TransformPoints(&pt
);
1334 // applies the matrix except for translations
1335 void wxGDIPlusMatrixData::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
1338 m_matrix
->TransformVectors(&pt
);
1343 // returns the native representation
1344 void * wxGDIPlusMatrixData::GetNativeMatrix() const
1349 //-----------------------------------------------------------------------------
1350 // wxGDIPlusContext implementation
1351 //-----------------------------------------------------------------------------
1353 class wxGDIPlusOffsetHelper
1356 wxGDIPlusOffsetHelper( Graphics
* gr
, bool offset
)
1361 m_gr
->TranslateTransform( 0.5, 0.5 );
1363 ~wxGDIPlusOffsetHelper( )
1366 m_gr
->TranslateTransform( -0.5, -0.5 );
1373 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HDC hdc
, wxDouble width
, wxDouble height
)
1374 : wxGraphicsContext(renderer
)
1376 Init(new Graphics(hdc
), width
, height
);
1379 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, const wxDC
& dc
)
1380 : wxGraphicsContext(renderer
)
1382 wxMSWDCImpl
*msw
= wxDynamicCast( dc
.GetImpl() , wxMSWDCImpl
);
1383 HDC hdc
= (HDC
) msw
->GetHDC();
1384 wxSize sz
= dc
.GetSize();
1386 Init(new Graphics(hdc
), sz
.x
, sz
.y
);
1389 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, HWND hwnd
)
1390 : wxGraphicsContext(renderer
)
1392 RECT rect
= wxGetWindowRect(hwnd
);
1393 Init(new Graphics(hwnd
), rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
1394 m_enableOffset
= true;
1397 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer
* renderer
, Graphics
* gr
)
1398 : wxGraphicsContext(renderer
)
1403 wxGDIPlusContext::wxGDIPlusContext(wxGraphicsRenderer
* renderer
)
1404 : wxGraphicsContext(renderer
)
1406 // Derived class must call Init() later but just set m_context to NULL for
1407 // safety to avoid crashing in our dtor if Init() ends up not being called.
1411 void wxGDIPlusContext::Init(Graphics
* graphics
, int width
, int height
)
1413 m_context
= graphics
;
1418 m_fontScaleRatio
= 1.0;
1420 m_context
->SetTextRenderingHint(TextRenderingHintSystemDefault
);
1421 m_context
->SetPixelOffsetMode(PixelOffsetModeHalf
);
1422 m_context
->SetSmoothingMode(SmoothingModeHighQuality
);
1423 m_context
->SetInterpolationMode(InterpolationModeHighQuality
);
1424 m_state1
= m_context
->Save();
1425 m_state2
= m_context
->Save();
1428 wxGDIPlusContext::~wxGDIPlusContext()
1432 m_context
->Restore( m_state2
);
1433 m_context
->Restore( m_state1
);
1439 void wxGDIPlusContext::Clip( const wxRegion
®ion
)
1441 Region
rgn((HRGN
)region
.GetHRGN());
1442 m_context
->SetClip(&rgn
,CombineModeIntersect
);
1445 void wxGDIPlusContext::Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1447 m_context
->SetClip(RectF(x
,y
,w
,h
),CombineModeIntersect
);
1450 void wxGDIPlusContext::ResetClip()
1452 m_context
->ResetClip();
1455 void wxGDIPlusContext::DrawRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1457 if (m_composition
== wxCOMPOSITION_DEST
)
1460 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1461 Brush
*brush
= m_brush
.IsNull() ? NULL
: ((wxGDIPlusBrushData
*)m_brush
.GetRefData())->GetGDIPlusBrush();
1462 Pen
*pen
= m_pen
.IsNull() ? NULL
: ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen();
1466 // the offset is used to fill only the inside of the rectangle and not paint underneath
1467 // its border which may influence a transparent Pen
1470 offset
= pen
->GetWidth();
1471 m_context
->FillRectangle( brush
, (REAL
)x
+ offset
/2, (REAL
)y
+ offset
/2, (REAL
)w
- offset
, (REAL
)h
- offset
);
1476 m_context
->DrawRectangle( pen
, (REAL
)x
, (REAL
)y
, (REAL
)w
, (REAL
)h
);
1480 void wxGDIPlusContext::StrokeLines( size_t n
, const wxPoint2DDouble
*points
)
1482 if (m_composition
== wxCOMPOSITION_DEST
)
1485 if ( !m_pen
.IsNull() )
1487 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1488 Point
*cpoints
= new Point
[n
];
1489 for (size_t i
= 0; i
< n
; i
++)
1491 cpoints
[i
].X
= (int)(points
[i
].m_x
);
1492 cpoints
[i
].Y
= (int)(points
[i
].m_y
);
1494 } // for (size_t i = 0; i < n; i++)
1495 m_context
->DrawLines( ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen() , cpoints
, n
) ;
1500 void wxGDIPlusContext::DrawLines( size_t n
, const wxPoint2DDouble
*points
, wxPolygonFillMode
WXUNUSED(fillStyle
) )
1502 if (m_composition
== wxCOMPOSITION_DEST
)
1505 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1506 Point
*cpoints
= new Point
[n
];
1507 for (size_t i
= 0; i
< n
; i
++)
1509 cpoints
[i
].X
= (int)(points
[i
].m_x
);
1510 cpoints
[i
].Y
= (int)(points
[i
].m_y
);
1512 } // for (int i = 0; i < n; i++)
1513 if ( !m_brush
.IsNull() )
1514 m_context
->FillPolygon( ((wxGDIPlusBrushData
*)m_brush
.GetRefData())->GetGDIPlusBrush() , cpoints
, n
) ;
1515 if ( !m_pen
.IsNull() )
1516 m_context
->DrawLines( ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen() , cpoints
, n
) ;
1520 void wxGDIPlusContext::StrokePath( const wxGraphicsPath
& path
)
1522 if (m_composition
== wxCOMPOSITION_DEST
)
1525 if ( !m_pen
.IsNull() )
1527 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1528 m_context
->DrawPath( ((wxGDIPlusPenData
*)m_pen
.GetGraphicsData())->GetGDIPlusPen() , (GraphicsPath
*) path
.GetNativePath() );
1532 void wxGDIPlusContext::FillPath( const wxGraphicsPath
& path
, wxPolygonFillMode fillStyle
)
1534 if (m_composition
== wxCOMPOSITION_DEST
)
1537 if ( !m_brush
.IsNull() )
1539 wxGDIPlusOffsetHelper
helper( m_context
, ShouldOffset() );
1540 ((GraphicsPath
*) path
.GetNativePath())->SetFillMode( fillStyle
== wxODDEVEN_RULE
? FillModeAlternate
: FillModeWinding
);
1541 m_context
->FillPath( ((wxGDIPlusBrushData
*)m_brush
.GetRefData())->GetGDIPlusBrush() ,
1542 (GraphicsPath
*) path
.GetNativePath());
1546 bool wxGDIPlusContext::SetAntialiasMode(wxAntialiasMode antialias
)
1548 if (m_antialias
== antialias
)
1551 m_antialias
= antialias
;
1553 SmoothingMode antialiasMode
;
1556 case wxANTIALIAS_DEFAULT
:
1557 antialiasMode
= SmoothingModeHighQuality
;
1559 case wxANTIALIAS_NONE
:
1560 antialiasMode
= SmoothingModeNone
;
1565 m_context
->SetSmoothingMode(antialiasMode
);
1569 bool wxGDIPlusContext::SetInterpolationQuality(wxInterpolationQuality interpolation
)
1571 if (m_interpolation
== interpolation
)
1574 InterpolationMode interpolationMode
= InterpolationModeDefault
;
1575 switch (interpolation
)
1577 case wxINTERPOLATION_DEFAULT
:
1578 interpolationMode
= InterpolationModeDefault
;
1581 case wxINTERPOLATION_NONE
:
1582 interpolationMode
= InterpolationModeNearestNeighbor
;
1585 case wxINTERPOLATION_FAST
:
1586 interpolationMode
= InterpolationModeLowQuality
;
1589 case wxINTERPOLATION_GOOD
:
1590 interpolationMode
= InterpolationModeHighQuality
;
1593 case wxINTERPOLATION_BEST
:
1594 interpolationMode
= InterpolationModeHighQualityBicubic
;
1601 if ( m_context
->SetInterpolationMode(interpolationMode
) != Gdiplus::Ok
)
1604 m_interpolation
= interpolation
;
1609 bool wxGDIPlusContext::SetCompositionMode(wxCompositionMode op
)
1611 if ( m_composition
== op
)
1616 if (m_composition
== wxCOMPOSITION_DEST
)
1619 CompositingMode cop
;
1622 case wxCOMPOSITION_SOURCE
:
1623 cop
= CompositingModeSourceCopy
;
1625 case wxCOMPOSITION_OVER
:
1626 cop
= CompositingModeSourceOver
;
1632 m_context
->SetCompositingMode(cop
);
1636 void wxGDIPlusContext::BeginLayer(wxDouble
/* opacity */)
1641 void wxGDIPlusContext::EndLayer()
1646 void wxGDIPlusContext::Rotate( wxDouble angle
)
1648 m_context
->RotateTransform( RadToDeg(angle
) );
1651 void wxGDIPlusContext::Translate( wxDouble dx
, wxDouble dy
)
1653 m_context
->TranslateTransform( dx
, dy
);
1656 void wxGDIPlusContext::Scale( wxDouble xScale
, wxDouble yScale
)
1658 m_context
->ScaleTransform(xScale
,yScale
);
1661 void wxGDIPlusContext::PushState()
1663 GraphicsState state
= m_context
->Save();
1664 m_stateStack
.push(state
);
1667 void wxGDIPlusContext::PopState()
1669 wxCHECK_RET( !m_stateStack
.empty(), wxT("No state to pop") );
1671 GraphicsState state
= m_stateStack
.top();
1673 m_context
->Restore(state
);
1676 void wxGDIPlusContext::DrawBitmap( const wxGraphicsBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1678 if (m_composition
== wxCOMPOSITION_DEST
)
1681 Bitmap
* image
= static_cast<wxGDIPlusBitmapData
*>(bmp
.GetRefData())->GetGDIPlusBitmap();
1684 if( image
->GetWidth() != (UINT
) w
|| image
->GetHeight() != (UINT
) h
)
1686 Rect
drawRect((REAL
) x
, (REAL
)y
, (REAL
)w
, (REAL
)h
);
1687 m_context
->SetPixelOffsetMode( PixelOffsetModeNone
);
1688 m_context
->DrawImage(image
, drawRect
, 0 , 0 , image
->GetWidth(), image
->GetHeight(), UnitPixel
) ;
1689 m_context
->SetPixelOffsetMode( PixelOffsetModeHalf
);
1692 m_context
->DrawImage(image
,(REAL
) x
,(REAL
) y
,(REAL
) w
,(REAL
) h
) ;
1696 void wxGDIPlusContext::DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1698 wxGraphicsBitmap bitmap
= GetRenderer()->CreateBitmap(bmp
);
1699 DrawBitmap(bitmap
, x
, y
, w
, h
);
1702 void wxGDIPlusContext::DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1704 if (m_composition
== wxCOMPOSITION_DEST
)
1707 // the built-in conversion fails when there is alpha in the HICON (eg XP style icons), we can only
1708 // find out by looking at the bitmap data whether there really was alpha in it
1709 HICON hIcon
= (HICON
)icon
.GetHICON();
1711 // IconInfo creates the bitmaps for color and mask, we must dispose of them after use
1712 if (!GetIconInfo(hIcon
,&iconInfo
))
1715 Bitmap
interim(iconInfo
.hbmColor
,NULL
);
1717 Bitmap
* image
= NULL
;
1719 // if it's not 32 bit, it doesn't have an alpha channel, note that since the conversion doesn't
1720 // work correctly, asking IsAlphaPixelFormat at this point fails as well
1721 if( GetPixelFormatSize(interim
.GetPixelFormat())!= 32 )
1723 image
= Bitmap::FromHICON(hIcon
);
1727 size_t width
= interim
.GetWidth();
1728 size_t height
= interim
.GetHeight();
1729 Rect
bounds(0,0,width
,height
);
1732 interim
.LockBits(&bounds
, ImageLockModeRead
,
1733 interim
.GetPixelFormat(),&data
);
1735 bool hasAlpha
= false;
1736 for ( size_t y
= 0 ; y
< height
&& !hasAlpha
; ++y
)
1738 for( size_t x
= 0 ; x
< width
&& !hasAlpha
; ++x
)
1740 ARGB
*dest
= (ARGB
*)((BYTE
*)data
.Scan0
+ data
.Stride
*y
+ x
*4);
1741 if ( ( *dest
& Color::AlphaMask
) != 0 )
1748 image
= new Bitmap(data
.Width
, data
.Height
, data
.Stride
,
1749 PixelFormat32bppARGB
, (BYTE
*) data
.Scan0
);
1753 image
= Bitmap::FromHICON(hIcon
);
1756 interim
.UnlockBits(&data
);
1759 m_context
->DrawImage(image
,(REAL
) x
,(REAL
) y
,(REAL
) w
,(REAL
) h
) ;
1762 DeleteObject(iconInfo
.hbmColor
);
1763 DeleteObject(iconInfo
.hbmMask
);
1766 void wxGDIPlusContext::DoDrawText(const wxString
& str
,
1767 wxDouble x
, wxDouble y
)
1769 if (m_composition
== wxCOMPOSITION_DEST
)
1772 wxCHECK_RET( !m_font
.IsNull(),
1773 wxT("wxGDIPlusContext::DrawText - no valid font set") );
1778 wxGDIPlusFontData
* const
1779 fontData
= (wxGDIPlusFontData
*)m_font
.GetRefData();
1781 m_context
->DrawString
1783 str
.wc_str(*wxConvUI
), // string to draw, always Unicode
1784 -1, // length: string is NUL-terminated
1785 fontData
->GetGDIPlusFont(),
1787 GetDrawTextStringFormat(),
1788 fontData
->GetGDIPlusBrush()
1792 void wxGDIPlusContext::GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
1793 wxDouble
*descent
, wxDouble
*externalLeading
) const
1795 wxCHECK_RET( !m_font
.IsNull(), wxT("wxGDIPlusContext::GetTextExtent - no valid font set") );
1797 wxWCharBuffer s
= str
.wc_str( *wxConvUI
);
1798 FontFamily ffamily
;
1799 Font
* f
= ((wxGDIPlusFontData
*)m_font
.GetRefData())->GetGDIPlusFont();
1801 f
->GetFamily(&ffamily
) ;
1803 REAL factorY
= m_fontScaleRatio
;
1805 // Notice that we must use the real font style or the results would be
1806 // incorrect for italic/bold fonts.
1807 const INT style
= f
->GetStyle();
1808 const REAL size
= f
->GetSize();
1809 const REAL emHeight
= ffamily
.GetEmHeight(style
);
1810 REAL rDescent
= ffamily
.GetCellDescent(style
) * size
/ emHeight
;
1811 REAL rAscent
= ffamily
.GetCellAscent(style
) * size
/ emHeight
;
1812 REAL rHeight
= ffamily
.GetLineSpacing(style
) * size
/ emHeight
;
1815 *height
= rHeight
* factorY
;
1817 *descent
= rDescent
* factorY
;
1818 if ( externalLeading
)
1819 *externalLeading
= (rHeight
- rAscent
- rDescent
) * factorY
;
1820 // measuring empty strings is not guaranteed, so do it by hand
1828 RectF
layoutRect(0,0, 100000.0f
, 100000.0f
);
1831 m_context
->MeasureString((const wchar_t *) s
, wcslen(s
) , f
, layoutRect
, GetDrawTextStringFormat(), &bounds
) ;
1833 *width
= bounds
.Width
;
1835 *height
= bounds
.Height
;
1839 void wxGDIPlusContext::GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const
1842 widths
.Add(0, text
.length());
1844 wxCHECK_RET( !m_font
.IsNull(), wxT("wxGDIPlusContext::GetPartialTextExtents - no valid font set") );
1849 Font
* f
= ((wxGDIPlusFontData
*)m_font
.GetRefData())->GetGDIPlusFont();
1850 wxWCharBuffer ws
= text
.wc_str( *wxConvUI
);
1851 size_t len
= wcslen( ws
) ;
1852 wxASSERT_MSG(text
.length() == len
, wxT("GetPartialTextExtents not yet implemented for multichar situations"));
1854 RectF
layoutRect(0,0, 100000.0f
, 100000.0f
);
1855 StringFormat
strFormat( GetDrawTextStringFormat() );
1857 size_t startPosition
= 0;
1858 size_t remainder
= len
;
1859 const size_t maxSpan
= 32;
1860 CharacterRange
* ranges
= new CharacterRange
[maxSpan
] ;
1861 Region
* regions
= new Region
[maxSpan
];
1863 while( remainder
> 0 )
1865 size_t span
= wxMin( maxSpan
, remainder
);
1867 for( size_t i
= 0 ; i
< span
; ++i
)
1869 ranges
[i
].First
= 0 ;
1870 ranges
[i
].Length
= startPosition
+i
+1 ;
1872 strFormat
.SetMeasurableCharacterRanges(span
,ranges
);
1873 m_context
->MeasureCharacterRanges(ws
, -1 , f
,layoutRect
, &strFormat
,span
,regions
) ;
1876 for ( size_t i
= 0 ; i
< span
; ++i
)
1878 regions
[i
].GetBounds(&bbox
,m_context
);
1879 widths
[startPosition
+i
] = bbox
.Width
;
1882 startPosition
+= span
;
1889 bool wxGDIPlusContext::ShouldOffset() const
1891 if ( !m_enableOffset
)
1895 if ( !m_pen
.IsNull() )
1897 penwidth
= (int)((wxGDIPlusPenData
*)m_pen
.GetRefData())->GetWidth();
1898 if ( penwidth
== 0 )
1901 return ( penwidth
% 2 ) == 1;
1904 void* wxGDIPlusContext::GetNativeContext()
1909 // concatenates this transform with the current transform of this context
1910 void wxGDIPlusContext::ConcatTransform( const wxGraphicsMatrix
& matrix
)
1912 m_context
->MultiplyTransform((Matrix
*) matrix
.GetNativeMatrix());
1915 // sets the transform of this context
1916 void wxGDIPlusContext::SetTransform( const wxGraphicsMatrix
& matrix
)
1918 m_context
->SetTransform((Matrix
*) matrix
.GetNativeMatrix());
1921 // gets the matrix of this context
1922 wxGraphicsMatrix
wxGDIPlusContext::GetTransform() const
1924 wxGraphicsMatrix matrix
= CreateMatrix();
1925 m_context
->GetTransform((Matrix
*) matrix
.GetNativeMatrix());
1929 void wxGDIPlusContext::GetSize( wxDouble
* width
, wxDouble
*height
)
1935 //-----------------------------------------------------------------------------
1936 // wxGDIPlusPrintingContext implementation
1937 //-----------------------------------------------------------------------------
1939 wxGDIPlusPrintingContext::wxGDIPlusPrintingContext( wxGraphicsRenderer
* renderer
,
1941 : wxGDIPlusContext(renderer
, dc
)
1943 Graphics
* context
= GetGraphics();
1945 //m_context->SetPageUnit(UnitDocument);
1947 // Setup page scale, based on DPI ratio.
1948 // Antecedent should be 100dpi when the default page unit
1949 // (UnitDisplay) is used. Page unit UnitDocument would require 300dpi
1950 // instead. Note that calling SetPageScale() does not have effect on
1951 // non-printing DCs (that is, any other than wxPrinterDC or
1952 // wxEnhMetaFileDC).
1953 REAL dpiRatio
= 100.0 / context
->GetDpiY();
1954 context
->SetPageScale(dpiRatio
);
1956 // We use this modifier when measuring fonts. It is needed because the
1957 // page scale is modified above.
1958 m_fontScaleRatio
= context
->GetDpiY() / 72.0;
1961 //-----------------------------------------------------------------------------
1962 // wxGDIPlusRenderer implementation
1963 //-----------------------------------------------------------------------------
1965 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRenderer
,wxGraphicsRenderer
)
1967 static wxGDIPlusRenderer gs_GDIPlusRenderer
;
1969 wxGraphicsRenderer
* wxGraphicsRenderer::GetDefaultRenderer()
1971 return &gs_GDIPlusRenderer
;
1974 bool wxGDIPlusRenderer::EnsureIsLoaded()
1976 // load gdiplus.dll if not yet loaded, but don't bother doing it again
1977 // if we already tried and failed (we don't want to spend lot of time
1978 // returning NULL from wxGraphicsContext::Create(), which may be called
1979 // relatively frequently):
1980 if ( m_loaded
== -1 )
1985 return m_loaded
== 1;
1988 // call EnsureIsLoaded() and return returnOnFail value if it fails
1989 #define ENSURE_LOADED_OR_RETURN(returnOnFail) \
1990 if ( !EnsureIsLoaded() ) \
1991 return (returnOnFail)
1994 void wxGDIPlusRenderer::Load()
1996 GdiplusStartupInput input
;
1997 GdiplusStartupOutput output
;
1998 if ( GdiplusStartup(&m_gditoken
,&input
,&output
) == Gdiplus::Ok
)
2000 wxLogTrace("gdiplus", "successfully initialized GDI+");
2005 wxLogTrace("gdiplus", "failed to initialize GDI+, missing gdiplus.dll?");
2010 void wxGDIPlusRenderer::Unload()
2014 GdiplusShutdown(m_gditoken
);
2017 m_loaded
= -1; // next Load() will try again
2020 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxWindowDC
& dc
)
2022 ENSURE_LOADED_OR_RETURN(NULL
);
2023 wxGDIPlusContext
* context
= new wxGDIPlusContext(this, dc
);
2024 context
->EnableOffset(true);
2028 #if wxUSE_PRINTING_ARCHITECTURE
2029 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxPrinterDC
& dc
)
2031 ENSURE_LOADED_OR_RETURN(NULL
);
2032 wxGDIPlusContext
* context
= new wxGDIPlusPrintingContext(this, dc
);
2037 #if wxUSE_ENH_METAFILE
2038 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxEnhMetaFileDC
& dc
)
2040 ENSURE_LOADED_OR_RETURN(NULL
);
2041 wxGDIPlusContext
* context
= new wxGDIPlusPrintingContext(this, dc
);
2046 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( const wxMemoryDC
& dc
)
2048 ENSURE_LOADED_OR_RETURN(NULL
);
2049 wxGDIPlusContext
* context
= new wxGDIPlusContext(this, dc
);
2050 context
->EnableOffset(true);
2055 wxGraphicsContext
* wxGDIPlusRenderer::CreateContextFromImage(wxImage
& image
)
2057 ENSURE_LOADED_OR_RETURN(NULL
);
2058 wxGDIPlusContext
* context
= new wxGDIPlusImageContext(this, image
);
2059 context
->EnableOffset(true);
2063 #endif // wxUSE_IMAGE
2065 wxGraphicsContext
* wxGDIPlusRenderer::CreateMeasuringContext()
2067 ENSURE_LOADED_OR_RETURN(NULL
);
2068 return new wxGDIPlusMeasuringContext(this);
2071 wxGraphicsContext
* wxGDIPlusRenderer::CreateContextFromNativeContext( void * context
)
2073 ENSURE_LOADED_OR_RETURN(NULL
);
2074 return new wxGDIPlusContext(this,(Graphics
*) context
);
2078 wxGraphicsContext
* wxGDIPlusRenderer::CreateContextFromNativeWindow( void * window
)
2080 ENSURE_LOADED_OR_RETURN(NULL
);
2081 return new wxGDIPlusContext(this,(HWND
) window
);
2084 wxGraphicsContext
* wxGDIPlusRenderer::CreateContext( wxWindow
* window
)
2086 ENSURE_LOADED_OR_RETURN(NULL
);
2087 return new wxGDIPlusContext(this, (HWND
) window
->GetHWND() );
2092 wxGraphicsPath
wxGDIPlusRenderer::CreatePath()
2094 ENSURE_LOADED_OR_RETURN(wxNullGraphicsPath
);
2096 m
.SetRefData( new wxGDIPlusPathData(this));
2103 wxGraphicsMatrix
wxGDIPlusRenderer::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
2104 wxDouble tx
, wxDouble ty
)
2107 ENSURE_LOADED_OR_RETURN(wxNullGraphicsMatrix
);
2109 wxGDIPlusMatrixData
* data
= new wxGDIPlusMatrixData( this );
2110 data
->Set( a
,b
,c
,d
,tx
,ty
) ;
2115 wxGraphicsPen
wxGDIPlusRenderer::CreatePen(const wxPen
& pen
)
2117 ENSURE_LOADED_OR_RETURN(wxNullGraphicsPen
);
2118 if ( !pen
.IsOk() || pen
.GetStyle() == wxTRANSPARENT
)
2119 return wxNullGraphicsPen
;
2123 p
.SetRefData(new wxGDIPlusPenData( this, pen
));
2128 wxGraphicsBrush
wxGDIPlusRenderer::CreateBrush(const wxBrush
& brush
)
2130 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush
);
2131 if ( !brush
.IsOk() || brush
.GetStyle() == wxTRANSPARENT
)
2132 return wxNullGraphicsBrush
;
2136 p
.SetRefData(new wxGDIPlusBrushData( this, brush
));
2142 wxGDIPlusRenderer::CreateLinearGradientBrush(wxDouble x1
, wxDouble y1
,
2143 wxDouble x2
, wxDouble y2
,
2144 const wxGraphicsGradientStops
& stops
)
2146 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush
);
2148 wxGDIPlusBrushData
* d
= new wxGDIPlusBrushData( this );
2149 d
->CreateLinearGradientBrush(x1
, y1
, x2
, y2
, stops
);
2155 wxGDIPlusRenderer::CreateRadialGradientBrush(wxDouble xo
, wxDouble yo
,
2156 wxDouble xc
, wxDouble yc
,
2158 const wxGraphicsGradientStops
& stops
)
2160 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush
);
2162 wxGDIPlusBrushData
* d
= new wxGDIPlusBrushData( this );
2163 d
->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,stops
);
2169 wxGDIPlusRenderer::CreateFont( const wxFont
&font
,
2170 const wxColour
&col
)
2172 ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont
);
2176 p
.SetRefData(new wxGDIPlusFontData( this, font
, col
));
2180 return wxNullGraphicsFont
;
2184 wxGDIPlusRenderer::CreateFont(double size
,
2185 const wxString
& facename
,
2187 const wxColour
& col
)
2189 ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont
);
2191 // Convert wxFont flags to GDI+ style:
2192 int style
= FontStyleRegular
;
2193 if ( flags
& wxFONTFLAG_ITALIC
)
2194 style
|= FontStyleItalic
;
2195 if ( flags
& wxFONTFLAG_UNDERLINED
)
2196 style
|= FontStyleUnderline
;
2197 if ( flags
& wxFONTFLAG_BOLD
)
2198 style
|= FontStyleBold
;
2199 if ( flags
& wxFONTFLAG_STRIKETHROUGH
)
2200 style
|= FontStyleStrikeout
;
2204 f
.SetRefData(new wxGDIPlusFontData(this, facename
, size
, style
, col
));
2208 wxGraphicsBitmap
wxGDIPlusRenderer::CreateBitmap( const wxBitmap
&bitmap
)
2210 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap
);
2211 if ( bitmap
.IsOk() )
2214 p
.SetRefData(new wxGDIPlusBitmapData( this , bitmap
));
2218 return wxNullGraphicsBitmap
;
2223 wxGraphicsBitmap
wxGDIPlusRenderer::CreateBitmapFromImage(const wxImage
& image
)
2225 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap
);
2228 // Notice that we rely on conversion from wxImage to wxBitmap here but
2229 // we could probably do it more efficiently by converting from wxImage
2230 // to GDI+ Bitmap directly, i.e. copying wxImage pixels to the buffer
2231 // returned by Bitmap::LockBits(). However this would require writing
2232 // code specific for this task while like this we can reuse existing
2233 // code (see also wxGDIPlusBitmapData::ConvertToImage()).
2234 wxGraphicsBitmap gb
;
2235 gb
.SetRefData(new wxGDIPlusBitmapData(this, image
));
2239 return wxNullGraphicsBitmap
;
2243 wxImage
wxGDIPlusRenderer::CreateImageFromBitmap(const wxGraphicsBitmap
& bmp
)
2245 ENSURE_LOADED_OR_RETURN(wxNullImage
);
2246 const wxGDIPlusBitmapData
* const
2247 data
= static_cast<wxGDIPlusBitmapData
*>(bmp
.GetGraphicsData());
2249 return data
? data
->ConvertToImage() : wxNullImage
;
2252 #endif // wxUSE_IMAGE
2255 wxGraphicsBitmap
wxGDIPlusRenderer::CreateBitmapFromNativeBitmap( void *bitmap
)
2257 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap
);
2258 if ( bitmap
!= NULL
)
2261 p
.SetRefData(new wxGDIPlusBitmapData( this , (Bitmap
*) bitmap
));
2265 return wxNullGraphicsBitmap
;
2268 wxGraphicsBitmap
wxGDIPlusRenderer::CreateSubBitmap( const wxGraphicsBitmap
&bitmap
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
2270 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap
);
2271 Bitmap
* image
= static_cast<wxGDIPlusBitmapData
*>(bitmap
.GetRefData())->GetGDIPlusBitmap();
2275 p
.SetRefData(new wxGDIPlusBitmapData( this , image
->Clone( (REAL
) x
, (REAL
) y
, (REAL
) w
, (REAL
) h
, PixelFormat32bppPARGB
) ));
2279 return wxNullGraphicsBitmap
;
2282 // Shutdown GDI+ at app exit, before possible dll unload
2283 class wxGDIPlusRendererModule
: public wxModule
2286 wxGDIPlusRendererModule()
2288 // We must be uninitialized before GDI+ DLL itself is unloaded.
2289 AddDependency("wxGdiPlusModule");
2292 virtual bool OnInit() { return true; }
2293 virtual void OnExit()
2295 wxDELETE(gs_drawTextStringFormat
);
2297 gs_GDIPlusRenderer
.Unload();
2301 DECLARE_DYNAMIC_CLASS(wxGDIPlusRendererModule
)
2304 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRendererModule
, wxModule
)
2306 // ----------------------------------------------------------------------------
2307 // wxMSW-specific parts of wxGCDC
2308 // ----------------------------------------------------------------------------
2310 WXHDC
wxGCDC::AcquireHDC()
2312 wxGraphicsContext
* const gc
= GetGraphicsContext();
2317 // we can't get the HDC if it is not a GDI+ context
2318 wxGraphicsRenderer
* r1
= gc
->GetRenderer();
2319 wxGraphicsRenderer
* r2
= wxGraphicsRenderer::GetCairoRenderer();
2324 Graphics
* const g
= static_cast<Graphics
*>(gc
->GetNativeContext());
2325 return g
? g
->GetHDC() : NULL
;
2328 void wxGCDC::ReleaseHDC(WXHDC hdc
)
2333 wxGraphicsContext
* const gc
= GetGraphicsContext();
2334 wxCHECK_RET( gc
, "can't release HDC because there is no wxGraphicsContext" );
2337 // we can't get the HDC if it is not a GDI+ context
2338 wxGraphicsRenderer
* r1
= gc
->GetRenderer();
2339 wxGraphicsRenderer
* r2
= wxGraphicsRenderer::GetCairoRenderer();
2344 Graphics
* const g
= static_cast<Graphics
*>(gc
->GetNativeContext());
2345 wxCHECK_RET( g
, "can't release HDC because there is no Graphics" );
2347 g
->ReleaseHDC((HDC
)hdc
);
2350 #endif // wxUSE_GRAPHICS_CONTEXT