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