]> git.saurik.com Git - wxWidgets.git/blob - src/msw/graphics.cpp
Correct drawing of mnemonics in wxStaticBox label under wxMSW.
[wxWidgets.git] / src / msw / graphics.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/graphics.cpp
3 // Purpose: wxGCDC class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 2006-09-30
7 // RCS-ID: $Id$
8 // Copyright: (c) 2006 Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #include "wx/dc.h"
19
20 #if wxUSE_GRAPHICS_CONTEXT
21
22 #ifndef WX_PRECOMP
23 #include "wx/msw/wrapcdlg.h"
24 #include "wx/image.h"
25 #include "wx/window.h"
26 #include "wx/utils.h"
27 #include "wx/dialog.h"
28 #include "wx/app.h"
29 #include "wx/bitmap.h"
30 #include "wx/log.h"
31 #include "wx/icon.h"
32 #include "wx/module.h"
33 // include all dc types that are used as a param
34 #include "wx/dc.h"
35 #include "wx/dcclient.h"
36 #include "wx/dcmemory.h"
37 #include "wx/dcprint.h"
38 #endif
39
40 #include "wx/private/graphics.h"
41 #include "wx/msw/wrapgdip.h"
42 #include "wx/msw/dc.h"
43 #include "wx/msw/enhmeta.h"
44 #include "wx/dcgraph.h"
45
46 #include "wx/msw/private.h" // needs to be before #include <commdlg.h>
47
48 #if wxUSE_COMMON_DIALOGS && !defined(__WXMICROWIN__)
49 #include <commdlg.h>
50 #endif
51
52 #include "wx/stack.h"
53
54 WX_DECLARE_STACK(GraphicsState, GraphicsStates);
55
56 namespace
57 {
58
59 //-----------------------------------------------------------------------------
60 // constants
61 //-----------------------------------------------------------------------------
62
63 const double RAD2DEG = 180.0 / M_PI;
64
65 //-----------------------------------------------------------------------------
66 // Local functions
67 //-----------------------------------------------------------------------------
68
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; }
71
72 inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
73 inline double RadToDeg(double deg) { return (deg * 180.0) / M_PI; }
74
75 // translate a wxColour to a Color
76 inline Color wxColourToColor(const wxColour& col)
77 {
78 return Color(col.Alpha(), col.Red(), col.Green(), col.Blue());
79 }
80
81 } // anonymous namespace
82
83 //-----------------------------------------------------------------------------
84 // device context implementation
85 //
86 // more and more of the dc functionality should be implemented by calling
87 // the appropricate wxGDIPlusContext, but we will have to do that step by step
88 // also coordinate conversions should be moved to native matrix ops
89 //-----------------------------------------------------------------------------
90
91 // we always stock two context states, one at entry, to be able to preserve the
92 // state we were called with, the other one after changing to HI Graphics orientation
93 // (this one is used for getting back clippings etc)
94
95 //-----------------------------------------------------------------------------
96 // wxGraphicsPath implementation
97 //-----------------------------------------------------------------------------
98
99 class wxGDIPlusPathData : public wxGraphicsPathData
100 {
101 public :
102 wxGDIPlusPathData(wxGraphicsRenderer* renderer, GraphicsPath* path = NULL);
103 ~wxGDIPlusPathData();
104
105 virtual wxGraphicsObjectRefData *Clone() const;
106
107 //
108 // These are the path primitives from which everything else can be constructed
109 //
110
111 // begins a new subpath at (x,y)
112 virtual void MoveToPoint( wxDouble x, wxDouble y );
113
114 // adds a straight line from the current point to (x,y)
115 virtual void AddLineToPoint( wxDouble x, wxDouble y );
116
117 // adds a cubic Bezier curve from the current point, using two control points and an end point
118 virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y );
119
120
121 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
122 virtual void AddArc( wxDouble x, wxDouble y, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise ) ;
123
124 // gets the last point of the current path, (0,0) if not yet set
125 virtual void GetCurrentPoint( wxDouble* x, wxDouble* y) const;
126
127 // adds another path
128 virtual void AddPath( const wxGraphicsPathData* path );
129
130 // closes the current sub-path
131 virtual void CloseSubpath();
132
133 //
134 // These are convenience functions which - if not available natively will be assembled
135 // using the primitives from above
136 //
137
138 // appends a rectangle as a new closed subpath
139 virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) ;
140 /*
141
142 // appends an ellipsis as a new closed subpath fitting the passed rectangle
143 virtual void AddEllipsis( wxDouble x, wxDouble y, wxDouble w , wxDouble h ) ;
144
145 // 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)
146 virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
147 */
148
149 // returns the native path
150 virtual void * GetNativePath() const { return m_path; }
151
152 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
153 virtual void UnGetNativePath(void * WXUNUSED(path)) const {}
154
155 // transforms each point of this path by the matrix
156 virtual void Transform( const wxGraphicsMatrixData* matrix ) ;
157
158 // gets the bounding box enclosing all points (possibly including control points)
159 virtual void GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h) const;
160
161 virtual bool Contains( wxDouble x, wxDouble y, wxPolygonFillMode fillStyle = wxODDEVEN_RULE) const;
162
163 private :
164 GraphicsPath* m_path;
165 };
166
167 class wxGDIPlusMatrixData : public wxGraphicsMatrixData
168 {
169 public :
170 wxGDIPlusMatrixData(wxGraphicsRenderer* renderer, Matrix* matrix = NULL) ;
171 virtual ~wxGDIPlusMatrixData() ;
172
173 virtual wxGraphicsObjectRefData* Clone() const ;
174
175 // concatenates the matrix
176 virtual void Concat( const wxGraphicsMatrixData *t );
177
178 // sets the matrix to the respective values
179 virtual void Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
180 wxDouble tx=0.0, wxDouble ty=0.0);
181
182 // gets the component valuess of the matrix
183 virtual void Get(wxDouble* a=NULL, wxDouble* b=NULL, wxDouble* c=NULL,
184 wxDouble* d=NULL, wxDouble* tx=NULL, wxDouble* ty=NULL) const;
185
186 // makes this the inverse matrix
187 virtual void Invert();
188
189 // returns true if the elements of the transformation matrix are equal ?
190 virtual bool IsEqual( const wxGraphicsMatrixData* t) const ;
191
192 // return true if this is the identity matrix
193 virtual bool IsIdentity() const;
194
195 //
196 // transformation
197 //
198
199 // add the translation to this matrix
200 virtual void Translate( wxDouble dx , wxDouble dy );
201
202 // add the scale to this matrix
203 virtual void Scale( wxDouble xScale , wxDouble yScale );
204
205 // add the rotation to this matrix (radians)
206 virtual void Rotate( wxDouble angle );
207
208 //
209 // apply the transforms
210 //
211
212 // applies that matrix to the point
213 virtual void TransformPoint( wxDouble *x, wxDouble *y ) const;
214
215 // applies the matrix except for translations
216 virtual void TransformDistance( wxDouble *dx, wxDouble *dy ) const;
217
218 // returns the native representation
219 virtual void * GetNativeMatrix() const;
220 private:
221 Matrix* m_matrix ;
222 } ;
223
224 class wxGDIPlusPenData : public wxGraphicsObjectRefData
225 {
226 public:
227 wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &pen );
228 ~wxGDIPlusPenData();
229
230 void Init();
231
232 virtual wxDouble GetWidth() { return m_width; }
233 virtual Pen* GetGDIPlusPen() { return m_pen; }
234
235 protected :
236 Pen* m_pen;
237 Image* m_penImage;
238 Brush* m_penBrush;
239
240 wxDouble m_width;
241 };
242
243 class wxGDIPlusBrushData : public wxGraphicsObjectRefData
244 {
245 public:
246 wxGDIPlusBrushData( wxGraphicsRenderer* renderer );
247 wxGDIPlusBrushData( wxGraphicsRenderer* renderer, const wxBrush &brush );
248 ~wxGDIPlusBrushData ();
249
250 void CreateLinearGradientBrush(wxDouble x1, wxDouble y1,
251 wxDouble x2, wxDouble y2,
252 const wxGraphicsGradientStops& stops);
253 void CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
254 wxDouble xc, wxDouble yc,
255 wxDouble radius,
256 const wxGraphicsGradientStops& stops);
257
258 virtual Brush* GetGDIPlusBrush() { return m_brush; }
259
260 protected:
261 virtual void Init();
262
263 private:
264 // common part of Create{Linear,Radial}GradientBrush()
265 template <typename T>
266 void SetGradientStops(T *brush, const wxGraphicsGradientStops& stops);
267
268 Brush* m_brush;
269 Image* m_brushImage;
270 GraphicsPath* m_brushPath;
271 };
272
273 class WXDLLIMPEXP_CORE wxGDIPlusBitmapData : public wxGraphicsObjectRefData
274 {
275 public:
276 wxGDIPlusBitmapData( wxGraphicsRenderer* renderer, Bitmap* bitmap );
277 wxGDIPlusBitmapData( wxGraphicsRenderer* renderer, const wxBitmap &bmp );
278 ~wxGDIPlusBitmapData ();
279
280 virtual Bitmap* GetGDIPlusBitmap() { return m_bitmap; }
281
282 private :
283 Bitmap* m_bitmap;
284 Bitmap* m_helper;
285 };
286
287 class wxGDIPlusFontData : public wxGraphicsObjectRefData
288 {
289 public:
290 wxGDIPlusFontData( wxGraphicsRenderer* renderer, const wxFont &font, const wxColour& col );
291 ~wxGDIPlusFontData();
292
293 virtual Brush* GetGDIPlusBrush() { return m_textBrush; }
294 virtual Font* GetGDIPlusFont() { return m_font; }
295 private :
296 Brush* m_textBrush;
297 Font* m_font;
298 };
299
300 class wxGDIPlusContext : public wxGraphicsContext
301 {
302 public:
303 wxGDIPlusContext( wxGraphicsRenderer* renderer, HDC hdc , wxDouble width, wxDouble height );
304 wxGDIPlusContext( wxGraphicsRenderer* renderer, HWND hwnd );
305 wxGDIPlusContext( wxGraphicsRenderer* renderer, Graphics* gr);
306 wxGDIPlusContext();
307
308 virtual ~wxGDIPlusContext();
309
310 virtual void Clip( const wxRegion &region );
311 // clips drawings to the rect
312 virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
313
314 // resets the clipping to original extent
315 virtual void ResetClip();
316
317 virtual void * GetNativeContext();
318
319 virtual void StrokePath( const wxGraphicsPath& p );
320 virtual void FillPath( const wxGraphicsPath& p , wxPolygonFillMode fillStyle = wxODDEVEN_RULE );
321
322 // stroke lines connecting each of the points
323 virtual void StrokeLines( size_t n, const wxPoint2DDouble *points);
324
325 // draws a polygon
326 virtual void DrawLines( size_t n, const wxPoint2DDouble *points, wxPolygonFillMode fillStyle = wxODDEVEN_RULE );
327
328 virtual bool SetAntialiasMode(wxAntialiasMode antialias);
329
330 virtual bool SetCompositionMode(wxCompositionMode op);
331
332 virtual void BeginLayer(wxDouble opacity);
333
334 virtual void EndLayer();
335
336 virtual void Translate( wxDouble dx , wxDouble dy );
337 virtual void Scale( wxDouble xScale , wxDouble yScale );
338 virtual void Rotate( wxDouble angle );
339
340 // concatenates this transform with the current transform of this context
341 virtual void ConcatTransform( const wxGraphicsMatrix& matrix );
342
343 // sets the transform of this context
344 virtual void SetTransform( const wxGraphicsMatrix& matrix );
345
346 // gets the matrix of this context
347 virtual wxGraphicsMatrix GetTransform() const;
348
349 virtual void DrawBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
350 virtual void DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
351 virtual void DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
352 virtual void PushState();
353 virtual void PopState();
354
355 virtual void GetTextExtent( const wxString &str, wxDouble *width, wxDouble *height,
356 wxDouble *descent, wxDouble *externalLeading ) const;
357 virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const;
358 virtual bool ShouldOffset() const;
359 virtual void GetSize( wxDouble* width, wxDouble *height );
360
361 private:
362 void Init();
363 void SetDefaults();
364
365 virtual void DoDrawText(const wxString& str, wxDouble x, wxDouble y)
366 { DoDrawFilledText(str, x, y, wxNullGraphicsBrush); }
367 virtual void DoDrawFilledText(const wxString& str, wxDouble x, wxDouble y,
368 const wxGraphicsBrush& backgroundBrush);
369
370 Graphics* m_context;
371 GraphicsStates m_stateStack;
372 GraphicsState m_state1;
373 GraphicsState m_state2;
374
375 wxDouble m_width;
376 wxDouble m_height;
377
378 DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusContext)
379 };
380
381 class wxGDIPlusMeasuringContext : public wxGDIPlusContext
382 {
383 public:
384 wxGDIPlusMeasuringContext( wxGraphicsRenderer* renderer ) : wxGDIPlusContext( renderer , m_hdc = GetDC(NULL), 1000, 1000 )
385 {
386 }
387 wxGDIPlusMeasuringContext()
388 {
389 }
390
391 virtual ~wxGDIPlusMeasuringContext()
392 {
393 ReleaseDC( NULL, m_hdc );
394 }
395
396 private:
397 HDC m_hdc ;
398 DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusMeasuringContext)
399 } ;
400
401 //-----------------------------------------------------------------------------
402 // wxGDIPlusPen implementation
403 //-----------------------------------------------------------------------------
404
405 wxGDIPlusPenData::~wxGDIPlusPenData()
406 {
407 delete m_pen;
408 delete m_penImage;
409 delete m_penBrush;
410 }
411
412 void wxGDIPlusPenData::Init()
413 {
414 m_pen = NULL ;
415 m_penImage = NULL;
416 m_penBrush = NULL;
417 }
418
419 wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &pen )
420 : wxGraphicsObjectRefData(renderer)
421 {
422 Init();
423 m_width = pen.GetWidth();
424 if (m_width <= 0.0)
425 m_width = 0.1;
426
427 m_pen = new Pen(wxColourToColor(pen.GetColour()), m_width );
428
429 LineCap cap;
430 switch ( pen.GetCap() )
431 {
432 case wxCAP_ROUND :
433 cap = LineCapRound;
434 break;
435
436 case wxCAP_PROJECTING :
437 cap = LineCapSquare;
438 break;
439
440 case wxCAP_BUTT :
441 cap = LineCapFlat; // TODO verify
442 break;
443
444 default :
445 cap = LineCapFlat;
446 break;
447 }
448 m_pen->SetLineCap(cap,cap, DashCapFlat);
449
450 LineJoin join;
451 switch ( pen.GetJoin() )
452 {
453 case wxJOIN_BEVEL :
454 join = LineJoinBevel;
455 break;
456
457 case wxJOIN_MITER :
458 join = LineJoinMiter;
459 break;
460
461 case wxJOIN_ROUND :
462 join = LineJoinRound;
463 break;
464
465 default :
466 join = LineJoinMiter;
467 break;
468 }
469
470 m_pen->SetLineJoin(join);
471
472 m_pen->SetDashStyle(DashStyleSolid);
473
474 DashStyle dashStyle = DashStyleSolid;
475 switch ( pen.GetStyle() )
476 {
477 case wxSOLID :
478 break;
479
480 case wxDOT :
481 dashStyle = DashStyleDot;
482 break;
483
484 case wxLONG_DASH :
485 dashStyle = DashStyleDash; // TODO verify
486 break;
487
488 case wxSHORT_DASH :
489 dashStyle = DashStyleDash;
490 break;
491
492 case wxDOT_DASH :
493 dashStyle = DashStyleDashDot;
494 break;
495 case wxUSER_DASH :
496 {
497 dashStyle = DashStyleCustom;
498 wxDash *dashes;
499 int count = pen.GetDashes( &dashes );
500 if ((dashes != NULL) && (count > 0))
501 {
502 REAL *userLengths = new REAL[count];
503 for ( int i = 0; i < count; ++i )
504 {
505 userLengths[i] = dashes[i];
506 }
507 m_pen->SetDashPattern( userLengths, count);
508 delete[] userLengths;
509 }
510 }
511 break;
512 case wxSTIPPLE :
513 {
514 wxBitmap* bmp = pen.GetStipple();
515 if ( bmp && bmp->Ok() )
516 {
517 m_penImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE());
518 m_penBrush = new TextureBrush(m_penImage);
519 m_pen->SetBrush( m_penBrush );
520 }
521
522 }
523 break;
524 default :
525 if ( pen.GetStyle() >= wxFIRST_HATCH && pen.GetStyle() <= wxLAST_HATCH )
526 {
527 HatchStyle style = HatchStyleHorizontal;
528 switch( pen.GetStyle() )
529 {
530 case wxBDIAGONAL_HATCH :
531 style = HatchStyleBackwardDiagonal;
532 break ;
533 case wxCROSSDIAG_HATCH :
534 style = HatchStyleDiagonalCross;
535 break ;
536 case wxFDIAGONAL_HATCH :
537 style = HatchStyleForwardDiagonal;
538 break ;
539 case wxCROSS_HATCH :
540 style = HatchStyleCross;
541 break ;
542 case wxHORIZONTAL_HATCH :
543 style = HatchStyleHorizontal;
544 break ;
545 case wxVERTICAL_HATCH :
546 style = HatchStyleVertical;
547 break ;
548
549 }
550 m_penBrush = new HatchBrush
551 (
552 style,
553 wxColourToColor(pen.GetColour()),
554 Color::Transparent
555 );
556 m_pen->SetBrush( m_penBrush );
557 }
558 break;
559 }
560 if ( dashStyle != DashStyleSolid )
561 m_pen->SetDashStyle(dashStyle);
562 }
563
564 //-----------------------------------------------------------------------------
565 // wxGDIPlusBrush implementation
566 //-----------------------------------------------------------------------------
567
568 wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer* renderer )
569 : wxGraphicsObjectRefData(renderer)
570 {
571 Init();
572 }
573
574 wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer* renderer , const wxBrush &brush )
575 : wxGraphicsObjectRefData(renderer)
576 {
577 Init();
578 if ( brush.GetStyle() == wxSOLID)
579 {
580 m_brush = new SolidBrush(wxColourToColor( brush.GetColour()));
581 }
582 else if ( brush.IsHatch() )
583 {
584 HatchStyle style = HatchStyleHorizontal;
585 switch( brush.GetStyle() )
586 {
587 case wxBDIAGONAL_HATCH :
588 style = HatchStyleBackwardDiagonal;
589 break ;
590 case wxCROSSDIAG_HATCH :
591 style = HatchStyleDiagonalCross;
592 break ;
593 case wxFDIAGONAL_HATCH :
594 style = HatchStyleForwardDiagonal;
595 break ;
596 case wxCROSS_HATCH :
597 style = HatchStyleCross;
598 break ;
599 case wxHORIZONTAL_HATCH :
600 style = HatchStyleHorizontal;
601 break ;
602 case wxVERTICAL_HATCH :
603 style = HatchStyleVertical;
604 break ;
605
606 }
607 m_brush = new HatchBrush
608 (
609 style,
610 wxColourToColor(brush.GetColour()),
611 Color::Transparent
612 );
613 }
614 else
615 {
616 wxBitmap* bmp = brush.GetStipple();
617 if ( bmp && bmp->Ok() )
618 {
619 wxDELETE( m_brushImage );
620 m_brushImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),(HPALETTE)bmp->GetPalette()->GetHPALETTE());
621 m_brush = new TextureBrush(m_brushImage);
622 }
623 }
624 }
625
626 wxGDIPlusBrushData::~wxGDIPlusBrushData()
627 {
628 delete m_brush;
629 delete m_brushImage;
630 delete m_brushPath;
631 };
632
633 void wxGDIPlusBrushData::Init()
634 {
635 m_brush = NULL;
636 m_brushImage= NULL;
637 m_brushPath= NULL;
638 }
639
640 template <typename T>
641 void
642 wxGDIPlusBrushData::SetGradientStops(T *brush,
643 const wxGraphicsGradientStops& stops)
644 {
645 const unsigned numStops = stops.GetCount();
646 if ( numStops <= 2 )
647 {
648 // initial and final colours are set during the brush creation, nothing
649 // more to do
650 return;
651 }
652
653 wxVector<Color> colors(numStops);
654 wxVector<REAL> positions(numStops);
655
656 for ( unsigned i = 0; i < numStops; i++ )
657 {
658 wxGraphicsGradientStop stop = stops.Item(i);
659
660 colors[i] = wxColourToColor(stop.GetColour());
661 positions[i] = stop.GetPosition();
662 }
663
664 brush->SetInterpolationColors(&colors[0], &positions[0], numStops);
665 }
666
667 void
668 wxGDIPlusBrushData::CreateLinearGradientBrush(wxDouble x1, wxDouble y1,
669 wxDouble x2, wxDouble y2,
670 const wxGraphicsGradientStops& stops)
671 {
672 LinearGradientBrush * const
673 brush = new LinearGradientBrush(PointF(x1, y1) , PointF(x2, y2),
674 wxColourToColor(stops.GetStartColour()),
675 wxColourToColor(stops.GetEndColour()));
676 m_brush = brush;
677
678 SetGradientStops(brush, stops);
679 }
680
681 void
682 wxGDIPlusBrushData::CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
683 wxDouble xc, wxDouble yc,
684 wxDouble radius,
685 const wxGraphicsGradientStops& stops)
686 {
687 m_brushPath = new GraphicsPath();
688 m_brushPath->AddEllipse( (REAL)(xc-radius), (REAL)(yc-radius),
689 (REAL)(2*radius), (REAL)(2*radius));
690
691 PathGradientBrush * const brush = new PathGradientBrush(m_brushPath);
692 m_brush = brush;
693 brush->SetCenterPoint(PointF(xo, yo));
694 brush->SetCenterColor(wxColourToColor(stops.GetStartColour()));
695
696 const Color col(wxColourToColor(stops.GetEndColour()));
697 int count = 1;
698 brush->SetSurroundColors(&col, &count);
699
700 SetGradientStops(brush, stops);
701 }
702
703 //-----------------------------------------------------------------------------
704 // wxGDIPlusFont implementation
705 //-----------------------------------------------------------------------------
706
707 wxGDIPlusFontData::wxGDIPlusFontData( wxGraphicsRenderer* renderer, const wxFont &font,
708 const wxColour& col ) : wxGraphicsObjectRefData( renderer )
709 {
710 m_textBrush = NULL;
711 m_font = NULL;
712
713 wxWCharBuffer s = font.GetFaceName().wc_str( *wxConvUI );
714 int size = font.GetPointSize();
715 int style = FontStyleRegular;
716 if ( font.GetStyle() == wxFONTSTYLE_ITALIC )
717 style |= FontStyleItalic;
718 if ( font.GetUnderlined() )
719 style |= FontStyleUnderline;
720 if ( font.GetWeight() == wxFONTWEIGHT_BOLD )
721 style |= FontStyleBold;
722 m_font = new Font( s , size , style );
723 m_textBrush = new SolidBrush(wxColourToColor(col));
724 }
725
726 wxGDIPlusFontData::~wxGDIPlusFontData()
727 {
728 delete m_textBrush;
729 delete m_font;
730 }
731
732 // the built-in conversions functions create non-premultiplied bitmaps, while GDIPlus needs them in the
733 // premultiplied format, therefore in the failing cases we create a new bitmap using the non-premultiplied
734 // bytes as parameter, since there is no real copying of the data going in, only references are stored
735 // m_helper has to be kept alive as well
736
737 //-----------------------------------------------------------------------------
738 // wxGDIPlusBitmapData implementation
739 //-----------------------------------------------------------------------------
740
741 wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer* renderer, Bitmap* bitmap ) :
742 wxGraphicsObjectRefData( renderer ), m_bitmap( bitmap )
743 {
744 m_helper = NULL;
745 }
746
747 wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer* renderer,
748 const wxBitmap &bmp) : wxGraphicsObjectRefData( renderer )
749 {
750 m_bitmap = NULL;
751 m_helper = NULL;
752
753 Bitmap* image = NULL;
754 if ( bmp.GetMask() )
755 {
756 Bitmap interim((HBITMAP)bmp.GetHBITMAP(),(HPALETTE)bmp.GetPalette()->GetHPALETTE()) ;
757
758 size_t width = interim.GetWidth();
759 size_t height = interim.GetHeight();
760 Rect bounds(0,0,width,height);
761
762 image = new Bitmap(width,height,PixelFormat32bppPARGB) ;
763
764 Bitmap interimMask((HBITMAP)bmp.GetMask()->GetMaskBitmap(),NULL);
765 wxASSERT(interimMask.GetPixelFormat() == PixelFormat1bppIndexed);
766
767 BitmapData dataMask ;
768 interimMask.LockBits(&bounds,ImageLockModeRead,
769 interimMask.GetPixelFormat(),&dataMask);
770
771
772 BitmapData imageData ;
773 image->LockBits(&bounds,ImageLockModeWrite, PixelFormat32bppPARGB, &imageData);
774
775 BYTE maskPattern = 0 ;
776 BYTE maskByte = 0;
777 size_t maskIndex ;
778
779 for ( size_t y = 0 ; y < height ; ++y)
780 {
781 maskIndex = 0 ;
782 for( size_t x = 0 ; x < width; ++x)
783 {
784 if ( x % 8 == 0)
785 {
786 maskPattern = 0x80;
787 maskByte = *((BYTE*)dataMask.Scan0 + dataMask.Stride*y + maskIndex);
788 maskIndex++;
789 }
790 else
791 maskPattern = maskPattern >> 1;
792
793 ARGB *dest = (ARGB*)((BYTE*)imageData.Scan0 + imageData.Stride*y + x*4);
794 if ( (maskByte & maskPattern) == 0 )
795 *dest = 0x00000000;
796 else
797 {
798 Color c ;
799 interim.GetPixel(x,y,&c) ;
800 *dest = (c.GetValue() | Color::AlphaMask);
801 }
802 }
803 }
804
805 image->UnlockBits(&imageData);
806
807 interimMask.UnlockBits(&dataMask);
808 interim.UnlockBits(&dataMask);
809 }
810 else
811 {
812 image = Bitmap::FromHBITMAP((HBITMAP)bmp.GetHBITMAP(),(HPALETTE)bmp.GetPalette()->GetHPALETTE());
813 if ( bmp.HasAlpha() && GetPixelFormatSize(image->GetPixelFormat()) == 32 )
814 {
815 size_t width = image->GetWidth();
816 size_t height = image->GetHeight();
817 Rect bounds(0,0,width,height);
818 static BitmapData data ;
819
820 m_helper = image ;
821 image = NULL ;
822 m_helper->LockBits(&bounds, ImageLockModeRead,
823 m_helper->GetPixelFormat(),&data);
824
825 image = new Bitmap(data.Width, data.Height, data.Stride,
826 PixelFormat32bppPARGB , (BYTE*) data.Scan0);
827
828 m_helper->UnlockBits(&data);
829 }
830 }
831 if ( image )
832 m_bitmap = image;
833 }
834
835 wxGDIPlusBitmapData::~wxGDIPlusBitmapData()
836 {
837 delete m_bitmap;
838 delete m_helper;
839 }
840
841 //-----------------------------------------------------------------------------
842 // wxGDIPlusPath implementation
843 //-----------------------------------------------------------------------------
844
845 wxGDIPlusPathData::wxGDIPlusPathData(wxGraphicsRenderer* renderer, GraphicsPath* path ) : wxGraphicsPathData(renderer)
846 {
847 if ( path )
848 m_path = path;
849 else
850 m_path = new GraphicsPath();
851 }
852
853 wxGDIPlusPathData::~wxGDIPlusPathData()
854 {
855 delete m_path;
856 }
857
858 wxGraphicsObjectRefData* wxGDIPlusPathData::Clone() const
859 {
860 return new wxGDIPlusPathData( GetRenderer() , m_path->Clone());
861 }
862
863 //
864 // The Primitives
865 //
866
867 void wxGDIPlusPathData::MoveToPoint( wxDouble x , wxDouble y )
868 {
869 m_path->StartFigure();
870 m_path->AddLine((REAL) x,(REAL) y,(REAL) x,(REAL) y);
871 }
872
873 void wxGDIPlusPathData::AddLineToPoint( wxDouble x , wxDouble y )
874 {
875 m_path->AddLine((REAL) x,(REAL) y,(REAL) x,(REAL) y);
876 }
877
878 void wxGDIPlusPathData::CloseSubpath()
879 {
880 m_path->CloseFigure();
881 }
882
883 void wxGDIPlusPathData::AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y )
884 {
885 PointF c1(cx1,cy1);
886 PointF c2(cx2,cy2);
887 PointF end(x,y);
888 PointF start;
889 m_path->GetLastPoint(&start);
890 m_path->AddBezier(start,c1,c2,end);
891 }
892
893 // gets the last point of the current path, (0,0) if not yet set
894 void wxGDIPlusPathData::GetCurrentPoint( wxDouble* x, wxDouble* y) const
895 {
896 PointF start;
897 m_path->GetLastPoint(&start);
898 *x = start.X ;
899 *y = start.Y ;
900 }
901
902 void wxGDIPlusPathData::AddArc( wxDouble x, wxDouble y, wxDouble r, double startAngle, double endAngle, bool clockwise )
903 {
904 double sweepAngle = endAngle - startAngle ;
905 if( fabs(sweepAngle) >= 2*M_PI)
906 {
907 sweepAngle = 2 * M_PI;
908 }
909 else
910 {
911 if ( clockwise )
912 {
913 if( sweepAngle < 0 )
914 sweepAngle += 2 * M_PI;
915 }
916 else
917 {
918 if( sweepAngle > 0 )
919 sweepAngle -= 2 * M_PI;
920
921 }
922 }
923 m_path->AddArc((REAL) (x-r),(REAL) (y-r),(REAL) (2*r),(REAL) (2*r),RadToDeg(startAngle),RadToDeg(sweepAngle));
924 }
925
926 void wxGDIPlusPathData::AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
927 {
928 m_path->AddRectangle(RectF(x,y,w,h));
929 }
930
931 void wxGDIPlusPathData::AddPath( const wxGraphicsPathData* path )
932 {
933 m_path->AddPath( (GraphicsPath*) path->GetNativePath(), FALSE);
934 }
935
936
937 // transforms each point of this path by the matrix
938 void wxGDIPlusPathData::Transform( const wxGraphicsMatrixData* matrix )
939 {
940 m_path->Transform( (Matrix*) matrix->GetNativeMatrix() );
941 }
942
943 // gets the bounding box enclosing all points (possibly including control points)
944 void wxGDIPlusPathData::GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h) const
945 {
946 RectF bounds;
947 m_path->GetBounds( &bounds, NULL, NULL) ;
948 *x = bounds.X;
949 *y = bounds.Y;
950 *w = bounds.Width;
951 *h = bounds.Height;
952 }
953
954 bool wxGDIPlusPathData::Contains( wxDouble x, wxDouble y, wxPolygonFillMode fillStyle ) const
955 {
956 m_path->SetFillMode( fillStyle == wxODDEVEN_RULE ? FillModeAlternate : FillModeWinding);
957 return m_path->IsVisible( (FLOAT) x,(FLOAT) y) == TRUE ;
958 }
959
960 //-----------------------------------------------------------------------------
961 // wxGDIPlusMatrixData implementation
962 //-----------------------------------------------------------------------------
963
964 wxGDIPlusMatrixData::wxGDIPlusMatrixData(wxGraphicsRenderer* renderer, Matrix* matrix )
965 : wxGraphicsMatrixData(renderer)
966 {
967 if ( matrix )
968 m_matrix = matrix ;
969 else
970 m_matrix = new Matrix();
971 }
972
973 wxGDIPlusMatrixData::~wxGDIPlusMatrixData()
974 {
975 delete m_matrix;
976 }
977
978 wxGraphicsObjectRefData *wxGDIPlusMatrixData::Clone() const
979 {
980 return new wxGDIPlusMatrixData( GetRenderer(), m_matrix->Clone());
981 }
982
983 // concatenates the matrix
984 void wxGDIPlusMatrixData::Concat( const wxGraphicsMatrixData *t )
985 {
986 m_matrix->Multiply( (Matrix*) t->GetNativeMatrix());
987 }
988
989 // sets the matrix to the respective values
990 void wxGDIPlusMatrixData::Set(wxDouble a, wxDouble b, wxDouble c, wxDouble d,
991 wxDouble tx, wxDouble ty)
992 {
993 m_matrix->SetElements(a,b,c,d,tx,ty);
994 }
995
996 // gets the component valuess of the matrix
997 void wxGDIPlusMatrixData::Get(wxDouble* a, wxDouble* b, wxDouble* c,
998 wxDouble* d, wxDouble* tx, wxDouble* ty) const
999 {
1000 REAL elements[6];
1001 m_matrix->GetElements(elements);
1002 if (a) *a = elements[0];
1003 if (b) *b = elements[1];
1004 if (c) *c = elements[2];
1005 if (d) *d = elements[3];
1006 if (tx) *tx= elements[4];
1007 if (ty) *ty= elements[5];
1008 }
1009
1010 // makes this the inverse matrix
1011 void wxGDIPlusMatrixData::Invert()
1012 {
1013 m_matrix->Invert();
1014 }
1015
1016 // returns true if the elements of the transformation matrix are equal ?
1017 bool wxGDIPlusMatrixData::IsEqual( const wxGraphicsMatrixData* t) const
1018 {
1019 return m_matrix->Equals((Matrix*) t->GetNativeMatrix())== TRUE ;
1020 }
1021
1022 // return true if this is the identity matrix
1023 bool wxGDIPlusMatrixData::IsIdentity() const
1024 {
1025 return m_matrix->IsIdentity() == TRUE ;
1026 }
1027
1028 //
1029 // transformation
1030 //
1031
1032 // add the translation to this matrix
1033 void wxGDIPlusMatrixData::Translate( wxDouble dx , wxDouble dy )
1034 {
1035 m_matrix->Translate(dx,dy);
1036 }
1037
1038 // add the scale to this matrix
1039 void wxGDIPlusMatrixData::Scale( wxDouble xScale , wxDouble yScale )
1040 {
1041 m_matrix->Scale(xScale,yScale);
1042 }
1043
1044 // add the rotation to this matrix (radians)
1045 void wxGDIPlusMatrixData::Rotate( wxDouble angle )
1046 {
1047 m_matrix->Rotate( RadToDeg(angle) );
1048 }
1049
1050 //
1051 // apply the transforms
1052 //
1053
1054 // applies that matrix to the point
1055 void wxGDIPlusMatrixData::TransformPoint( wxDouble *x, wxDouble *y ) const
1056 {
1057 PointF pt(*x,*y);
1058 m_matrix->TransformPoints(&pt);
1059 *x = pt.X;
1060 *y = pt.Y;
1061 }
1062
1063 // applies the matrix except for translations
1064 void wxGDIPlusMatrixData::TransformDistance( wxDouble *dx, wxDouble *dy ) const
1065 {
1066 PointF pt(*dx,*dy);
1067 m_matrix->TransformVectors(&pt);
1068 *dx = pt.X;
1069 *dy = pt.Y;
1070 }
1071
1072 // returns the native representation
1073 void * wxGDIPlusMatrixData::GetNativeMatrix() const
1074 {
1075 return m_matrix;
1076 }
1077
1078 //-----------------------------------------------------------------------------
1079 // wxGDIPlusContext implementation
1080 //-----------------------------------------------------------------------------
1081
1082 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusContext,wxGraphicsContext)
1083 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusMeasuringContext,wxGDIPlusContext)
1084
1085 class wxGDIPlusOffsetHelper
1086 {
1087 public :
1088 wxGDIPlusOffsetHelper( Graphics* gr , bool offset )
1089 {
1090 m_gr = gr;
1091 m_offset = offset;
1092 if ( m_offset )
1093 m_gr->TranslateTransform( 0.5, 0.5 );
1094 }
1095 ~wxGDIPlusOffsetHelper( )
1096 {
1097 if ( m_offset )
1098 m_gr->TranslateTransform( -0.5, -0.5 );
1099 }
1100 public :
1101 Graphics* m_gr;
1102 bool m_offset;
1103 } ;
1104
1105 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, HDC hdc, wxDouble width, wxDouble height )
1106 : wxGraphicsContext(renderer)
1107 {
1108 Init();
1109 m_context = new Graphics( hdc);
1110 m_width = width;
1111 m_height = height;
1112 SetDefaults();
1113 }
1114
1115 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, HWND hwnd )
1116 : wxGraphicsContext(renderer)
1117 {
1118 Init();
1119 m_context = new Graphics( hwnd);
1120 RECT rect = wxGetWindowRect(hwnd);
1121 m_width = rect.right - rect.left;
1122 m_height = rect.bottom - rect.top;
1123 SetDefaults();
1124 }
1125
1126 wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, Graphics* gr )
1127 : wxGraphicsContext(renderer)
1128 {
1129 Init();
1130 m_context = gr;
1131 SetDefaults();
1132 }
1133
1134 wxGDIPlusContext::wxGDIPlusContext() : wxGraphicsContext(NULL)
1135 {
1136 Init();
1137 }
1138
1139 void wxGDIPlusContext::Init()
1140 {
1141 m_context = NULL;
1142 m_state1 = 0;
1143 m_state2= 0;
1144 m_height = 0;
1145 m_width = 0;
1146 }
1147
1148 void wxGDIPlusContext::SetDefaults()
1149 {
1150 m_context->SetTextRenderingHint(TextRenderingHintSystemDefault);
1151 m_context->SetPixelOffsetMode(PixelOffsetModeHalf);
1152 m_context->SetSmoothingMode(SmoothingModeHighQuality);
1153 m_state1 = m_context->Save();
1154 m_state2 = m_context->Save();
1155
1156 // Setup page scale, based on DPI ratio.
1157 // Antecedent should be 100dpi when the default page unit (UnitDisplay)
1158 // is used. Page unit UnitDocument would require 300dpi instead.
1159 // Note that calling SetPageScale() does not have effect on non-printing
1160 // DCs (that is, any other than wxPrinterDC or wxEnhMetaFileDC).
1161 REAL dpiRatio = 100.0 / m_context->GetDpiY();
1162 m_context->SetPageScale(dpiRatio);
1163 }
1164
1165 wxGDIPlusContext::~wxGDIPlusContext()
1166 {
1167 if ( m_context )
1168 {
1169 m_context->Restore( m_state2 );
1170 m_context->Restore( m_state1 );
1171 delete m_context;
1172 }
1173 }
1174
1175
1176 void wxGDIPlusContext::Clip( const wxRegion &region )
1177 {
1178 Region rgn((HRGN)region.GetHRGN());
1179 m_context->SetClip(&rgn,CombineModeIntersect);
1180 }
1181
1182 void wxGDIPlusContext::Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
1183 {
1184 m_context->SetClip(RectF(x,y,w,h),CombineModeIntersect);
1185 }
1186
1187 void wxGDIPlusContext::ResetClip()
1188 {
1189 m_context->ResetClip();
1190 }
1191
1192 void wxGDIPlusContext::StrokeLines( size_t n, const wxPoint2DDouble *points)
1193 {
1194 if (m_composition == wxCOMPOSITION_DEST)
1195 return;
1196
1197 if ( !m_pen.IsNull() )
1198 {
1199 wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() );
1200 Point *cpoints = new Point[n];
1201 for (size_t i = 0; i < n; i++)
1202 {
1203 cpoints[i].X = (int)(points[i].m_x );
1204 cpoints[i].Y = (int)(points[i].m_y );
1205
1206 } // for (size_t i = 0; i < n; i++)
1207 m_context->DrawLines( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , cpoints , n ) ;
1208 delete[] cpoints;
1209 }
1210 }
1211
1212 void wxGDIPlusContext::DrawLines( size_t n, const wxPoint2DDouble *points, wxPolygonFillMode WXUNUSED(fillStyle) )
1213 {
1214 if (m_composition == wxCOMPOSITION_DEST)
1215 return;
1216
1217 wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() );
1218 Point *cpoints = new Point[n];
1219 for (size_t i = 0; i < n; i++)
1220 {
1221 cpoints[i].X = (int)(points[i].m_x );
1222 cpoints[i].Y = (int)(points[i].m_y );
1223
1224 } // for (int i = 0; i < n; i++)
1225 if ( !m_brush.IsNull() )
1226 m_context->FillPolygon( ((wxGDIPlusBrushData*)m_brush.GetRefData())->GetGDIPlusBrush() , cpoints , n ) ;
1227 if ( !m_pen.IsNull() )
1228 m_context->DrawLines( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , cpoints , n ) ;
1229 delete[] cpoints;
1230 }
1231
1232 void wxGDIPlusContext::StrokePath( const wxGraphicsPath& path )
1233 {
1234 if (m_composition == wxCOMPOSITION_DEST)
1235 return;
1236
1237 if ( !m_pen.IsNull() )
1238 {
1239 wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() );
1240 m_context->DrawPath( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , (GraphicsPath*) path.GetNativePath() );
1241 }
1242 }
1243
1244 void wxGDIPlusContext::FillPath( const wxGraphicsPath& path , wxPolygonFillMode fillStyle )
1245 {
1246 if (m_composition == wxCOMPOSITION_DEST)
1247 return;
1248
1249 if ( !m_brush.IsNull() )
1250 {
1251 wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() );
1252 ((GraphicsPath*) path.GetNativePath())->SetFillMode( fillStyle == wxODDEVEN_RULE ? FillModeAlternate : FillModeWinding);
1253 m_context->FillPath( ((wxGDIPlusBrushData*)m_brush.GetRefData())->GetGDIPlusBrush() ,
1254 (GraphicsPath*) path.GetNativePath());
1255 }
1256 }
1257
1258 bool wxGDIPlusContext::SetAntialiasMode(wxAntialiasMode antialias)
1259 {
1260 if (m_antialias == antialias)
1261 return true;
1262
1263 m_antialias = antialias;
1264
1265 SmoothingMode antialiasMode;
1266 switch (antialias)
1267 {
1268 case wxANTIALIAS_DEFAULT:
1269 antialiasMode = SmoothingModeHighQuality;
1270 break;
1271 case wxANTIALIAS_NONE:
1272 antialiasMode = SmoothingModeNone;
1273 break;
1274 default:
1275 return false;
1276 }
1277 m_context->SetSmoothingMode(antialiasMode);
1278 return true;
1279 }
1280
1281 bool wxGDIPlusContext::SetCompositionMode(wxCompositionMode op)
1282 {
1283 if ( m_composition == op )
1284 return true;
1285
1286 m_composition = op;
1287
1288 if (m_composition == wxCOMPOSITION_DEST)
1289 return true;
1290
1291 CompositingMode cop;
1292 switch (op)
1293 {
1294 case wxCOMPOSITION_SOURCE:
1295 cop = CompositingModeSourceCopy;
1296 break;
1297 case wxCOMPOSITION_OVER:
1298 cop = CompositingModeSourceOver;
1299 break;
1300 default:
1301 return false;
1302 }
1303
1304 m_context->SetCompositingMode(cop);
1305 return true;
1306 }
1307
1308 void wxGDIPlusContext::BeginLayer(wxDouble /* opacity */)
1309 {
1310 // TODO
1311 }
1312
1313 void wxGDIPlusContext::EndLayer()
1314 {
1315 // TODO
1316 }
1317
1318 void wxGDIPlusContext::Rotate( wxDouble angle )
1319 {
1320 m_context->RotateTransform( RadToDeg(angle) );
1321 }
1322
1323 void wxGDIPlusContext::Translate( wxDouble dx , wxDouble dy )
1324 {
1325 m_context->TranslateTransform( dx , dy );
1326 }
1327
1328 void wxGDIPlusContext::Scale( wxDouble xScale , wxDouble yScale )
1329 {
1330 m_context->ScaleTransform(xScale,yScale);
1331 }
1332
1333 void wxGDIPlusContext::PushState()
1334 {
1335 GraphicsState state = m_context->Save();
1336 m_stateStack.push(state);
1337 }
1338
1339 void wxGDIPlusContext::PopState()
1340 {
1341 GraphicsState state = m_stateStack.top();
1342 m_stateStack.pop();
1343 m_context->Restore(state);
1344 }
1345
1346 void wxGDIPlusContext::DrawBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
1347 {
1348 if (m_composition == wxCOMPOSITION_DEST)
1349 return;
1350
1351 Bitmap* image = static_cast<wxGDIPlusBitmapData*>(bmp.GetRefData())->GetGDIPlusBitmap();
1352 if ( image )
1353 {
1354 if( image->GetWidth() != (UINT) w || image->GetHeight() != (UINT) h )
1355 {
1356 Rect drawRect((REAL) x, (REAL)y, (REAL)w, (REAL)h);
1357 m_context->SetPixelOffsetMode( PixelOffsetModeNone );
1358 m_context->DrawImage(image, drawRect, 0 , 0 , image->GetWidth()-1, image->GetHeight()-1, UnitPixel ) ;
1359 m_context->SetPixelOffsetMode( PixelOffsetModeHalf );
1360 }
1361 else
1362 m_context->DrawImage(image,(REAL) x,(REAL) y,(REAL) w,(REAL) h) ;
1363 }
1364 }
1365
1366 void wxGDIPlusContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
1367 {
1368 wxGraphicsBitmap bitmap = GetRenderer()->CreateBitmap(bmp);
1369 DrawBitmap(bitmap, x, y, w, h);
1370 }
1371
1372 void wxGDIPlusContext::DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
1373 {
1374 if (m_composition == wxCOMPOSITION_DEST)
1375 return;
1376
1377 // the built-in conversion fails when there is alpha in the HICON (eg XP style icons), we can only
1378 // find out by looking at the bitmap data whether there really was alpha in it
1379 HICON hIcon = (HICON)icon.GetHICON();
1380 ICONINFO iconInfo ;
1381 // IconInfo creates the bitmaps for color and mask, we must dispose of them after use
1382 if (!GetIconInfo(hIcon,&iconInfo))
1383 return;
1384
1385 Bitmap interim(iconInfo.hbmColor,NULL);
1386
1387 Bitmap* image = NULL ;
1388
1389 // if it's not 32 bit, it doesn't have an alpha channel, note that since the conversion doesn't
1390 // work correctly, asking IsAlphaPixelFormat at this point fails as well
1391 if( GetPixelFormatSize(interim.GetPixelFormat())!= 32 )
1392 {
1393 image = Bitmap::FromHICON(hIcon);
1394 }
1395 else
1396 {
1397 size_t width = interim.GetWidth();
1398 size_t height = interim.GetHeight();
1399 Rect bounds(0,0,width,height);
1400 BitmapData data ;
1401
1402 interim.LockBits(&bounds, ImageLockModeRead,
1403 interim.GetPixelFormat(),&data);
1404
1405 bool hasAlpha = false;
1406 for ( size_t y = 0 ; y < height && !hasAlpha ; ++y)
1407 {
1408 for( size_t x = 0 ; x < width && !hasAlpha; ++x)
1409 {
1410 ARGB *dest = (ARGB*)((BYTE*)data.Scan0 + data.Stride*y + x*4);
1411 if ( ( *dest & Color::AlphaMask ) != 0 )
1412 hasAlpha = true;
1413 }
1414 }
1415
1416 if ( hasAlpha )
1417 {
1418 image = new Bitmap(data.Width, data.Height, data.Stride,
1419 PixelFormat32bppARGB , (BYTE*) data.Scan0);
1420 }
1421 else
1422 {
1423 image = Bitmap::FromHICON(hIcon);
1424 }
1425
1426 interim.UnlockBits(&data);
1427 }
1428
1429 m_context->DrawImage(image,(REAL) x,(REAL) y,(REAL) w,(REAL) h) ;
1430
1431 delete image ;
1432 DeleteObject(iconInfo.hbmColor);
1433 DeleteObject(iconInfo.hbmMask);
1434 }
1435
1436 void wxGDIPlusContext::DoDrawFilledText(const wxString& str,
1437 wxDouble x, wxDouble y,
1438 const wxGraphicsBrush& brush)
1439 {
1440 if (m_composition == wxCOMPOSITION_DEST)
1441 return;
1442
1443 wxCHECK_RET( !m_font.IsNull(),
1444 wxT("wxGDIPlusContext::DrawText - no valid font set") );
1445
1446 if ( str.IsEmpty())
1447 return ;
1448
1449 wxGDIPlusFontData * const
1450 fontData = (wxGDIPlusFontData *)m_font.GetRefData();
1451 wxGDIPlusBrushData * const
1452 brushData = (wxGDIPlusBrushData *)brush.GetRefData();
1453
1454 m_context->DrawString
1455 (
1456 str.wc_str(*wxConvUI), // string to draw, always Unicode
1457 -1, // length: string is NUL-terminated
1458 fontData->GetGDIPlusFont(),
1459 PointF(x, y),
1460 StringFormat::GenericTypographic(),
1461 brushData ? brushData->GetGDIPlusBrush()
1462 : fontData->GetGDIPlusBrush()
1463 );
1464 }
1465
1466 void wxGDIPlusContext::GetTextExtent( const wxString &str, wxDouble *width, wxDouble *height,
1467 wxDouble *descent, wxDouble *externalLeading ) const
1468 {
1469 wxCHECK_RET( !m_font.IsNull(), wxT("wxGDIPlusContext::GetTextExtent - no valid font set") );
1470
1471 wxWCharBuffer s = str.wc_str( *wxConvUI );
1472 FontFamily ffamily ;
1473 Font* f = ((wxGDIPlusFontData*)m_font.GetRefData())->GetGDIPlusFont();
1474
1475 f->GetFamily(&ffamily) ;
1476
1477 REAL factorY = m_context->GetDpiY() / 72.0 ;
1478
1479 REAL rDescent = ffamily.GetCellDescent(FontStyleRegular) *
1480 f->GetSize() / ffamily.GetEmHeight(FontStyleRegular);
1481 REAL rAscent = ffamily.GetCellAscent(FontStyleRegular) *
1482 f->GetSize() / ffamily.GetEmHeight(FontStyleRegular);
1483 REAL rHeight = ffamily.GetLineSpacing(FontStyleRegular) *
1484 f->GetSize() / ffamily.GetEmHeight(FontStyleRegular);
1485
1486 if ( height )
1487 *height = rHeight * factorY;
1488 if ( descent )
1489 *descent = rDescent * factorY;
1490 if ( externalLeading )
1491 *externalLeading = (rHeight - rAscent - rDescent) * factorY;
1492 // measuring empty strings is not guaranteed, so do it by hand
1493 if ( str.IsEmpty())
1494 {
1495 if ( width )
1496 *width = 0 ;
1497 }
1498 else
1499 {
1500 RectF layoutRect(0,0, 100000.0f, 100000.0f);
1501 StringFormat strFormat( StringFormat::GenericTypographic() );
1502 strFormat.SetFormatFlags( StringFormatFlagsMeasureTrailingSpaces | strFormat.GetFormatFlags() );
1503
1504 RectF bounds ;
1505 m_context->MeasureString((const wchar_t *) s , wcslen(s) , f, layoutRect, &strFormat, &bounds ) ;
1506 if ( width )
1507 *width = bounds.Width;
1508 if ( height )
1509 *height = bounds.Height;
1510 }
1511 }
1512
1513 void wxGDIPlusContext::GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const
1514 {
1515 widths.Empty();
1516 widths.Add(0, text.length());
1517
1518 wxCHECK_RET( !m_font.IsNull(), wxT("wxGDIPlusContext::GetPartialTextExtents - no valid font set") );
1519
1520 if (text.empty())
1521 return;
1522
1523 Font* f = ((wxGDIPlusFontData*)m_font.GetRefData())->GetGDIPlusFont();
1524 wxWCharBuffer ws = text.wc_str( *wxConvUI );
1525 size_t len = wcslen( ws ) ;
1526 wxASSERT_MSG(text.length() == len , wxT("GetPartialTextExtents not yet implemented for multichar situations"));
1527
1528 RectF layoutRect(0,0, 100000.0f, 100000.0f);
1529 StringFormat strFormat( StringFormat::GenericTypographic() );
1530
1531 size_t startPosition = 0;
1532 size_t remainder = len;
1533 const size_t maxSpan = 32;
1534 CharacterRange* ranges = new CharacterRange[maxSpan] ;
1535 Region* regions = new Region[maxSpan];
1536
1537 while( remainder > 0 )
1538 {
1539 size_t span = wxMin( maxSpan, remainder );
1540
1541 for( size_t i = 0 ; i < span ; ++i)
1542 {
1543 ranges[i].First = 0 ;
1544 ranges[i].Length = startPosition+i+1 ;
1545 }
1546 strFormat.SetMeasurableCharacterRanges(span,ranges);
1547 strFormat.SetFormatFlags( StringFormatFlagsMeasureTrailingSpaces | strFormat.GetFormatFlags() );
1548 m_context->MeasureCharacterRanges(ws, -1 , f,layoutRect, &strFormat,span,regions) ;
1549
1550 RectF bbox ;
1551 for ( size_t i = 0 ; i < span ; ++i)
1552 {
1553 regions[i].GetBounds(&bbox,m_context);
1554 widths[startPosition+i] = bbox.Width;
1555 }
1556 remainder -= span;
1557 startPosition += span;
1558 }
1559
1560 delete[] ranges;
1561 delete[] regions;
1562 }
1563
1564 bool wxGDIPlusContext::ShouldOffset() const
1565 {
1566 int penwidth = 0 ;
1567 if ( !m_pen.IsNull() )
1568 {
1569 penwidth = (int)((wxGDIPlusPenData*)m_pen.GetRefData())->GetWidth();
1570 if ( penwidth == 0 )
1571 penwidth = 1;
1572 }
1573 return ( penwidth % 2 ) == 1;
1574 }
1575
1576 void* wxGDIPlusContext::GetNativeContext()
1577 {
1578 return m_context;
1579 }
1580
1581 // concatenates this transform with the current transform of this context
1582 void wxGDIPlusContext::ConcatTransform( const wxGraphicsMatrix& matrix )
1583 {
1584 m_context->MultiplyTransform((Matrix*) matrix.GetNativeMatrix());
1585 }
1586
1587 // sets the transform of this context
1588 void wxGDIPlusContext::SetTransform( const wxGraphicsMatrix& matrix )
1589 {
1590 m_context->SetTransform((Matrix*) matrix.GetNativeMatrix());
1591 }
1592
1593 // gets the matrix of this context
1594 wxGraphicsMatrix wxGDIPlusContext::GetTransform() const
1595 {
1596 wxGraphicsMatrix matrix = CreateMatrix();
1597 m_context->GetTransform((Matrix*) matrix.GetNativeMatrix());
1598 return matrix;
1599 }
1600
1601 void wxGDIPlusContext::GetSize( wxDouble* width, wxDouble *height )
1602 {
1603 *width = m_width;
1604 *height = m_height;
1605 }
1606 //-----------------------------------------------------------------------------
1607 // wxGDIPlusRenderer declaration
1608 //-----------------------------------------------------------------------------
1609
1610 class wxGDIPlusRenderer : public wxGraphicsRenderer
1611 {
1612 public :
1613 wxGDIPlusRenderer()
1614 {
1615 m_loaded = -1;
1616 m_gditoken = 0;
1617 }
1618
1619 virtual ~wxGDIPlusRenderer()
1620 {
1621 if ( m_loaded == 1 )
1622 {
1623 Unload();
1624 }
1625 }
1626
1627 // Context
1628
1629 virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc);
1630
1631 virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc);
1632
1633 virtual wxGraphicsContext * CreateContext( const wxPrinterDC& dc);
1634
1635 virtual wxGraphicsContext * CreateContext( const wxEnhMetaFileDC& dc);
1636
1637 virtual wxGraphicsContext * CreateContextFromNativeContext( void * context );
1638
1639 virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window );
1640
1641 virtual wxGraphicsContext * CreateContext( wxWindow* window );
1642
1643 virtual wxGraphicsContext * CreateMeasuringContext();
1644
1645 // Path
1646
1647 virtual wxGraphicsPath CreatePath();
1648
1649 // Matrix
1650
1651 virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
1652 wxDouble tx=0.0, wxDouble ty=0.0);
1653
1654
1655 virtual wxGraphicsPen CreatePen(const wxPen& pen) ;
1656
1657 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) ;
1658
1659 virtual wxGraphicsBrush
1660 CreateLinearGradientBrush(wxDouble x1, wxDouble y1,
1661 wxDouble x2, wxDouble y2,
1662 const wxGraphicsGradientStops& stops);
1663
1664 virtual wxGraphicsBrush
1665 CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
1666 wxDouble xc, wxDouble yc,
1667 wxDouble radius,
1668 const wxGraphicsGradientStops& stops);
1669 // sets the font
1670 virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) ;
1671
1672 // create a native bitmap representation
1673 virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap );
1674
1675 // create a graphics bitmap from a native bitmap
1676 virtual wxGraphicsBitmap CreateBitmapFromNativeBitmap( void* bitmap );
1677
1678 // create a subimage from a native image representation
1679 virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
1680
1681 protected :
1682 bool EnsureIsLoaded();
1683 void Load();
1684 void Unload();
1685 friend class wxGDIPlusRendererModule;
1686
1687 private :
1688 int m_loaded;
1689 ULONG_PTR m_gditoken;
1690
1691 DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusRenderer)
1692 } ;
1693
1694 //-----------------------------------------------------------------------------
1695 // wxGDIPlusRenderer implementation
1696 //-----------------------------------------------------------------------------
1697
1698 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRenderer,wxGraphicsRenderer)
1699
1700 static wxGDIPlusRenderer gs_GDIPlusRenderer;
1701
1702 wxGraphicsRenderer* wxGraphicsRenderer::GetDefaultRenderer()
1703 {
1704 return &gs_GDIPlusRenderer;
1705 }
1706
1707 bool wxGDIPlusRenderer::EnsureIsLoaded()
1708 {
1709 // load gdiplus.dll if not yet loaded, but don't bother doing it again
1710 // if we already tried and failed (we don't want to spend lot of time
1711 // returning NULL from wxGraphicsContext::Create(), which may be called
1712 // relatively frequently):
1713 if ( m_loaded == -1 )
1714 {
1715 Load();
1716 }
1717
1718 return m_loaded == 1;
1719 }
1720
1721 // call EnsureIsLoaded() and return returnOnFail value if it fails
1722 #define ENSURE_LOADED_OR_RETURN(returnOnFail) \
1723 if ( !EnsureIsLoaded() ) \
1724 return (returnOnFail)
1725
1726
1727 void wxGDIPlusRenderer::Load()
1728 {
1729 GdiplusStartupInput input;
1730 GdiplusStartupOutput output;
1731 if ( GdiplusStartup(&m_gditoken,&input,&output) == Gdiplus::Ok )
1732 {
1733 wxLogTrace("gdiplus", "successfully initialized GDI+");
1734 m_loaded = 1;
1735 }
1736 else
1737 {
1738 wxLogTrace("gdiplus", "failed to initialize GDI+, missing gdiplus.dll?");
1739 m_loaded = 0;
1740 }
1741 }
1742
1743 void wxGDIPlusRenderer::Unload()
1744 {
1745 if ( m_gditoken )
1746 {
1747 GdiplusShutdown(m_gditoken);
1748 m_gditoken = NULL;
1749 }
1750 m_loaded = -1; // next Load() will try again
1751 }
1752
1753 wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxWindowDC& dc)
1754 {
1755 ENSURE_LOADED_OR_RETURN(NULL);
1756 wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl );
1757 wxSize sz = dc.GetSize();
1758 return new wxGDIPlusContext(this,(HDC) msw->GetHDC(), sz.x, sz.y);
1759 }
1760
1761 wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxPrinterDC& dc)
1762 {
1763 ENSURE_LOADED_OR_RETURN(NULL);
1764 wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl );
1765 wxSize sz = dc.GetSize();
1766 return new wxGDIPlusContext(this,(HDC) msw->GetHDC(), sz.x, sz.y);
1767 }
1768
1769 wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxEnhMetaFileDC& dc)
1770 {
1771 ENSURE_LOADED_OR_RETURN(NULL);
1772 wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl );
1773 wxSize sz = dc.GetSize();
1774 return new wxGDIPlusContext(this,(HDC) msw->GetHDC(), sz.x, sz.y);
1775 }
1776
1777 wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxMemoryDC& dc)
1778 {
1779 ENSURE_LOADED_OR_RETURN(NULL);
1780 wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl );
1781 wxSize sz = dc.GetSize();
1782 return new wxGDIPlusContext(this,(HDC) msw->GetHDC(), sz.x, sz.y);
1783 }
1784
1785 wxGraphicsContext * wxGDIPlusRenderer::CreateMeasuringContext()
1786 {
1787 ENSURE_LOADED_OR_RETURN(NULL);
1788 return new wxGDIPlusMeasuringContext(this);
1789 }
1790
1791 wxGraphicsContext * wxGDIPlusRenderer::CreateContextFromNativeContext( void * context )
1792 {
1793 ENSURE_LOADED_OR_RETURN(NULL);
1794 return new wxGDIPlusContext(this,(Graphics*) context);
1795 }
1796
1797
1798 wxGraphicsContext * wxGDIPlusRenderer::CreateContextFromNativeWindow( void * window )
1799 {
1800 ENSURE_LOADED_OR_RETURN(NULL);
1801 return new wxGDIPlusContext(this,(HWND) window);
1802 }
1803
1804 wxGraphicsContext * wxGDIPlusRenderer::CreateContext( wxWindow* window )
1805 {
1806 ENSURE_LOADED_OR_RETURN(NULL);
1807 return new wxGDIPlusContext(this, (HWND) window->GetHWND() );
1808 }
1809
1810 // Path
1811
1812 wxGraphicsPath wxGDIPlusRenderer::CreatePath()
1813 {
1814 ENSURE_LOADED_OR_RETURN(wxNullGraphicsPath);
1815 wxGraphicsPath m;
1816 m.SetRefData( new wxGDIPlusPathData(this));
1817 return m;
1818 }
1819
1820
1821 // Matrix
1822
1823 wxGraphicsMatrix wxGDIPlusRenderer::CreateMatrix( wxDouble a, wxDouble b, wxDouble c, wxDouble d,
1824 wxDouble tx, wxDouble ty)
1825
1826 {
1827 ENSURE_LOADED_OR_RETURN(wxNullGraphicsMatrix);
1828 wxGraphicsMatrix m;
1829 wxGDIPlusMatrixData* data = new wxGDIPlusMatrixData( this );
1830 data->Set( a,b,c,d,tx,ty ) ;
1831 m.SetRefData(data);
1832 return m;
1833 }
1834
1835 wxGraphicsPen wxGDIPlusRenderer::CreatePen(const wxPen& pen)
1836 {
1837 ENSURE_LOADED_OR_RETURN(wxNullGraphicsPen);
1838 if ( !pen.Ok() || pen.GetStyle() == wxTRANSPARENT )
1839 return wxNullGraphicsPen;
1840 else
1841 {
1842 wxGraphicsPen p;
1843 p.SetRefData(new wxGDIPlusPenData( this, pen ));
1844 return p;
1845 }
1846 }
1847
1848 wxGraphicsBrush wxGDIPlusRenderer::CreateBrush(const wxBrush& brush )
1849 {
1850 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush);
1851 if ( !brush.Ok() || brush.GetStyle() == wxTRANSPARENT )
1852 return wxNullGraphicsBrush;
1853 else
1854 {
1855 wxGraphicsBrush p;
1856 p.SetRefData(new wxGDIPlusBrushData( this, brush ));
1857 return p;
1858 }
1859 }
1860
1861 wxGraphicsBrush
1862 wxGDIPlusRenderer::CreateLinearGradientBrush(wxDouble x1, wxDouble y1,
1863 wxDouble x2, wxDouble y2,
1864 const wxGraphicsGradientStops& stops)
1865 {
1866 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush);
1867 wxGraphicsBrush p;
1868 wxGDIPlusBrushData* d = new wxGDIPlusBrushData( this );
1869 d->CreateLinearGradientBrush(x1, y1, x2, y2, stops);
1870 p.SetRefData(d);
1871 return p;
1872 }
1873
1874 wxGraphicsBrush
1875 wxGDIPlusRenderer::CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
1876 wxDouble xc, wxDouble yc,
1877 wxDouble radius,
1878 const wxGraphicsGradientStops& stops)
1879 {
1880 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush);
1881 wxGraphicsBrush p;
1882 wxGDIPlusBrushData* d = new wxGDIPlusBrushData( this );
1883 d->CreateRadialGradientBrush(xo,yo,xc,yc,radius,stops);
1884 p.SetRefData(d);
1885 return p;
1886 }
1887
1888 // sets the font
1889 wxGraphicsFont wxGDIPlusRenderer::CreateFont( const wxFont &font , const wxColour &col )
1890 {
1891 ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont);
1892 if ( font.Ok() )
1893 {
1894 wxGraphicsFont p;
1895 p.SetRefData(new wxGDIPlusFontData( this , font, col ));
1896 return p;
1897 }
1898 else
1899 return wxNullGraphicsFont;
1900 }
1901
1902 wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmap( const wxBitmap &bitmap )
1903 {
1904 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);
1905 if ( bitmap.Ok() )
1906 {
1907 wxGraphicsBitmap p;
1908 p.SetRefData(new wxGDIPlusBitmapData( this , bitmap ));
1909 return p;
1910 }
1911 else
1912 return wxNullGraphicsBitmap;
1913 }
1914
1915 wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmapFromNativeBitmap( void *bitmap )
1916 {
1917 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);
1918 if ( bitmap != NULL )
1919 {
1920 wxGraphicsBitmap p;
1921 p.SetRefData(new wxGDIPlusBitmapData( this , (Bitmap*) bitmap ));
1922 return p;
1923 }
1924 else
1925 return wxNullGraphicsBitmap;
1926 }
1927
1928 wxGraphicsBitmap wxGDIPlusRenderer::CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
1929 {
1930 ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);
1931 Bitmap* image = static_cast<wxGDIPlusBitmapData*>(bitmap.GetRefData())->GetGDIPlusBitmap();
1932 if ( image )
1933 {
1934 wxGraphicsBitmap p;
1935 p.SetRefData(new wxGDIPlusBitmapData( this , image->Clone( (REAL) x , (REAL) y , (REAL) w , (REAL) h , PixelFormat32bppPARGB) ));
1936 return p;
1937 }
1938 else
1939 return wxNullGraphicsBitmap;
1940 }
1941
1942 // Shutdown GDI+ at app exit, before possible dll unload
1943 class wxGDIPlusRendererModule : public wxModule
1944 {
1945 public:
1946 virtual bool OnInit() { return true; }
1947 virtual void OnExit() { gs_GDIPlusRenderer.Unload(); }
1948
1949 private:
1950 DECLARE_DYNAMIC_CLASS(wxGDIPlusRendererModule)
1951 };
1952
1953 IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRendererModule, wxModule)
1954
1955 // ----------------------------------------------------------------------------
1956 // wxMSW-specific parts of wxGCDC
1957 // ----------------------------------------------------------------------------
1958
1959 WXHDC wxGCDC::AcquireHDC()
1960 {
1961 wxGraphicsContext * const gc = GetGraphicsContext();
1962 if ( !gc )
1963 return NULL;
1964
1965 Graphics * const g = static_cast<Graphics *>(gc->GetNativeContext());
1966 return g ? g->GetHDC() : NULL;
1967 }
1968
1969 void wxGCDC::ReleaseHDC(WXHDC hdc)
1970 {
1971 if ( !hdc )
1972 return;
1973
1974 wxGraphicsContext * const gc = GetGraphicsContext();
1975 wxCHECK_RET( gc, "can't release HDC because there is no wxGraphicsContext" );
1976
1977 Graphics * const g = static_cast<Graphics *>(gc->GetNativeContext());
1978 wxCHECK_RET( g, "can't release HDC because there is no Graphics" );
1979
1980 g->ReleaseHDC((HDC)hdc);
1981 }
1982
1983 #endif // wxUSE_GRAPHICS_CONTEXT