+ m_bitmap = image;
+}
+
+wxGDIPlusBitmapData::~wxGDIPlusBitmapData()
+{
+ delete m_bitmap;
+ delete m_helper;
+}
+
+//-----------------------------------------------------------------------------
+// wxGDIPlusPath implementation
+//-----------------------------------------------------------------------------
+
+wxGDIPlusPathData::wxGDIPlusPathData(wxGraphicsRenderer* renderer, GraphicsPath* path ) : wxGraphicsPathData(renderer)
+{
+ if ( path )
+ m_path = path;
+ else
+ m_path = new GraphicsPath();
+}
+
+wxGDIPlusPathData::~wxGDIPlusPathData()
+{
+ delete m_path;
+}
+
+wxGraphicsObjectRefData* wxGDIPlusPathData::Clone() const
+{
+ return new wxGDIPlusPathData( GetRenderer() , m_path->Clone());
+}
+
+//
+// The Primitives
+//
+
+void wxGDIPlusPathData::MoveToPoint( wxDouble x , wxDouble y )
+{
+ m_path->StartFigure();
+ m_path->AddLine((REAL) x,(REAL) y,(REAL) x,(REAL) y);
+}
+
+void wxGDIPlusPathData::AddLineToPoint( wxDouble x , wxDouble y )
+{
+ m_path->AddLine((REAL) x,(REAL) y,(REAL) x,(REAL) y);
+}
+
+void wxGDIPlusPathData::CloseSubpath()
+{
+ m_path->CloseFigure();
+}
+
+void wxGDIPlusPathData::AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y )
+{
+ PointF c1(cx1,cy1);
+ PointF c2(cx2,cy2);
+ PointF end(x,y);
+ PointF start;
+ m_path->GetLastPoint(&start);
+ m_path->AddBezier(start,c1,c2,end);
+}
+
+// gets the last point of the current path, (0,0) if not yet set
+void wxGDIPlusPathData::GetCurrentPoint( wxDouble* x, wxDouble* y) const
+{
+ PointF start;
+ m_path->GetLastPoint(&start);
+ *x = start.X ;
+ *y = start.Y ;
+}
+
+void wxGDIPlusPathData::AddArc( wxDouble x, wxDouble y, wxDouble r, double startAngle, double endAngle, bool clockwise )
+{
+ double sweepAngle = endAngle - startAngle ;
+ if( fabs(sweepAngle) >= 2*M_PI)
+ {
+ sweepAngle = 2 * M_PI;
+ }
+ else
+ {
+ if ( clockwise )
+ {
+ if( sweepAngle < 0 )
+ sweepAngle += 2 * M_PI;
+ }
+ else
+ {
+ if( sweepAngle > 0 )
+ sweepAngle -= 2 * M_PI;
+
+ }
+ }
+ m_path->AddArc((REAL) (x-r),(REAL) (y-r),(REAL) (2*r),(REAL) (2*r),RadToDeg(startAngle),RadToDeg(sweepAngle));
+}
+
+void wxGDIPlusPathData::AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
+{
+ m_path->AddRectangle(RectF(x,y,w,h));
+}
+
+void wxGDIPlusPathData::AddPath( const wxGraphicsPathData* path )
+{
+ m_path->AddPath( (GraphicsPath*) path->GetNativePath(), FALSE);
+}
+
+
+// transforms each point of this path by the matrix
+void wxGDIPlusPathData::Transform( const wxGraphicsMatrixData* matrix )
+{
+ m_path->Transform( (Matrix*) matrix->GetNativeMatrix() );
+}
+
+// gets the bounding box enclosing all points (possibly including control points)
+void wxGDIPlusPathData::GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h) const
+{
+ RectF bounds;
+ m_path->GetBounds( &bounds, NULL, NULL) ;
+ *x = bounds.X;
+ *y = bounds.Y;
+ *w = bounds.Width;
+ *h = bounds.Height;
+}
+
+bool wxGDIPlusPathData::Contains( wxDouble x, wxDouble y, int fillStyle ) const
+{
+ m_path->SetFillMode( fillStyle == wxODDEVEN_RULE ? FillModeAlternate : FillModeWinding);
+ return m_path->IsVisible( (FLOAT) x,(FLOAT) y) == TRUE ;
+}
+
+//-----------------------------------------------------------------------------
+// wxGDIPlusMatrixData implementation
+//-----------------------------------------------------------------------------
+
+wxGDIPlusMatrixData::wxGDIPlusMatrixData(wxGraphicsRenderer* renderer, Matrix* matrix )
+ : wxGraphicsMatrixData(renderer)
+{
+ if ( matrix )
+ m_matrix = matrix ;
+ else
+ m_matrix = new Matrix();
+}
+
+wxGDIPlusMatrixData::~wxGDIPlusMatrixData()
+{
+ delete m_matrix;
+}
+
+wxGraphicsObjectRefData *wxGDIPlusMatrixData::Clone() const
+{
+ return new wxGDIPlusMatrixData( GetRenderer(), m_matrix->Clone());
+}
+
+// concatenates the matrix
+void wxGDIPlusMatrixData::Concat( const wxGraphicsMatrixData *t )
+{
+ m_matrix->Multiply( (Matrix*) t->GetNativeMatrix());
+}
+
+// sets the matrix to the respective values
+void wxGDIPlusMatrixData::Set(wxDouble a, wxDouble b, wxDouble c, wxDouble d,
+ wxDouble tx, wxDouble ty)
+{
+ m_matrix->SetElements(a,b,c,d,tx,ty);
+}
+
+// gets the component valuess of the matrix
+void wxGDIPlusMatrixData::Get(wxDouble* a, wxDouble* b, wxDouble* c,
+ wxDouble* d, wxDouble* tx, wxDouble* ty) const
+{
+ REAL elements[6];
+ m_matrix->GetElements(elements);
+ if (a) *a = elements[0];
+ if (b) *b = elements[1];
+ if (c) *c = elements[2];
+ if (d) *d = elements[3];
+ if (tx) *tx= elements[4];
+ if (ty) *ty= elements[5];
+}
+
+// makes this the inverse matrix
+void wxGDIPlusMatrixData::Invert()
+{
+ m_matrix->Invert();
+}
+
+// returns true if the elements of the transformation matrix are equal ?
+bool wxGDIPlusMatrixData::IsEqual( const wxGraphicsMatrixData* t) const
+{
+ return m_matrix->Equals((Matrix*) t->GetNativeMatrix())== TRUE ;
+}
+
+// return true if this is the identity matrix
+bool wxGDIPlusMatrixData::IsIdentity() const
+{
+ return m_matrix->IsIdentity() == TRUE ;
+}
+
+//
+// transformation
+//
+
+// add the translation to this matrix
+void wxGDIPlusMatrixData::Translate( wxDouble dx , wxDouble dy )
+{
+ m_matrix->Translate(dx,dy);
+}
+
+// add the scale to this matrix
+void wxGDIPlusMatrixData::Scale( wxDouble xScale , wxDouble yScale )
+{
+ m_matrix->Scale(xScale,yScale);
+}
+
+// add the rotation to this matrix (radians)
+void wxGDIPlusMatrixData::Rotate( wxDouble angle )
+{
+ m_matrix->Rotate( angle );
+}
+
+//
+// apply the transforms
+//
+
+// applies that matrix to the point
+void wxGDIPlusMatrixData::TransformPoint( wxDouble *x, wxDouble *y ) const
+{
+ PointF pt(*x,*y);
+ m_matrix->TransformPoints(&pt);
+ *x = pt.X;
+ *y = pt.Y;
+}
+
+// applies the matrix except for translations
+void wxGDIPlusMatrixData::TransformDistance( wxDouble *dx, wxDouble *dy ) const
+{
+ PointF pt(*dx,*dy);
+ m_matrix->TransformVectors(&pt);
+ *dx = pt.X;
+ *dy = pt.Y;
+}
+
+// returns the native representation
+void * wxGDIPlusMatrixData::GetNativeMatrix() const
+{
+ return m_matrix;
+}
+
+//-----------------------------------------------------------------------------
+// wxGDIPlusContext implementation
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusContext,wxGraphicsContext)
+IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusMeasuringContext,wxGDIPlusContext)
+
+class wxGDIPlusOffsetHelper
+{
+public :
+ wxGDIPlusOffsetHelper( Graphics* gr , bool offset )
+ {
+ m_gr = gr;
+ m_offset = offset;
+ if ( m_offset )
+ m_gr->TranslateTransform( 0.5, 0.5 );
+ }
+ ~wxGDIPlusOffsetHelper( )
+ {
+ if ( m_offset )
+ m_gr->TranslateTransform( -0.5, -0.5 );
+ }
+public :
+ Graphics* m_gr;
+ bool m_offset;
+} ;
+
+wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, HDC hdc )
+ : wxGraphicsContext(renderer)
+{
+ Init();
+ m_context = new Graphics( hdc);
+ SetDefaults();
+}
+
+wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, HWND hwnd )
+ : wxGraphicsContext(renderer)
+{
+ Init();
+ m_context = new Graphics( hwnd);
+ SetDefaults();
+}
+
+wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, Graphics* gr )
+ : wxGraphicsContext(renderer)
+{
+ Init();
+ m_context = gr;
+ SetDefaults();
+}
+
+wxGDIPlusContext::wxGDIPlusContext() : wxGraphicsContext(NULL)
+{
+ Init();
+}
+
+void wxGDIPlusContext::Init()
+{
+ m_context = NULL;
+ m_state1 = 0;
+ m_state2= 0;
+}
+
+void wxGDIPlusContext::SetDefaults()
+{
+ m_context->SetTextRenderingHint(TextRenderingHintSystemDefault);
+ m_context->SetPixelOffsetMode(PixelOffsetModeHalf);
+ m_context->SetSmoothingMode(SmoothingModeHighQuality);
+ m_state1 = m_context->Save();
+ m_state2 = m_context->Save();
+}
+
+wxGDIPlusContext::~wxGDIPlusContext()
+{
+ if ( m_context )
+ {
+ m_context->Restore( m_state2 );
+ m_context->Restore( m_state1 );
+ delete m_context;
+ }
+}
+
+
+void wxGDIPlusContext::Clip( const wxRegion ®ion )
+{
+ Region rgn((HRGN)region.GetHRGN());
+ m_context->SetClip(&rgn,CombineModeIntersect);
+}
+
+void wxGDIPlusContext::Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
+{
+ m_context->SetClip(RectF(x,y,w,h),CombineModeIntersect);
+}
+
+void wxGDIPlusContext::ResetClip()
+{
+ m_context->ResetClip();
+}
+
+void wxGDIPlusContext::StrokeLines( size_t n, const wxPoint2DDouble *points)
+{
+ if ( !m_pen.IsNull() )
+ {
+ wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() );
+ Point *cpoints = new Point[n];
+ for (size_t i = 0; i < n; i++)
+ {
+ cpoints[i].X = (int)(points[i].m_x );
+ cpoints[i].Y = (int)(points[i].m_y );
+
+ } // for (size_t i = 0; i < n; i++)
+ m_context->DrawLines( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , cpoints , n ) ;
+ delete[] cpoints;
+ }
+}
+
+void wxGDIPlusContext::DrawLines( size_t n, const wxPoint2DDouble *points, int WXUNUSED(fillStyle) )
+{
+ wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() );
+ Point *cpoints = new Point[n];
+ for (size_t i = 0; i < n; i++)
+ {
+ cpoints[i].X = (int)(points[i].m_x );
+ cpoints[i].Y = (int)(points[i].m_y );
+
+ } // for (int i = 0; i < n; i++)
+ if ( !m_brush.IsNull() )
+ m_context->FillPolygon( ((wxGDIPlusBrushData*)m_brush.GetRefData())->GetGDIPlusBrush() , cpoints , n ) ;
+ if ( !m_pen.IsNull() )
+ m_context->DrawLines( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , cpoints , n ) ;
+ delete[] cpoints;
+}
+
+void wxGDIPlusContext::StrokePath( const wxGraphicsPath& path )
+{
+ if ( !m_pen.IsNull() )
+ {
+ wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() );
+ m_context->DrawPath( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , (GraphicsPath*) path.GetNativePath() );
+ }
+}
+
+void wxGDIPlusContext::FillPath( const wxGraphicsPath& path , int fillStyle )
+{
+ if ( !m_brush.IsNull() )
+ {
+ wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() );
+ ((GraphicsPath*) path.GetNativePath())->SetFillMode( fillStyle == wxODDEVEN_RULE ? FillModeAlternate : FillModeWinding);
+ m_context->FillPath( ((wxGDIPlusBrushData*)m_brush.GetRefData())->GetGDIPlusBrush() ,
+ (GraphicsPath*) path.GetNativePath());
+ }
+}
+
+void wxGDIPlusContext::Rotate( wxDouble angle )
+{
+ m_context->RotateTransform( RadToDeg(angle) );
+}
+
+void wxGDIPlusContext::Translate( wxDouble dx , wxDouble dy )
+{
+ m_context->TranslateTransform( dx , dy );