+ 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 );
+}
+
+void wxGDIPlusContext::Scale( wxDouble xScale , wxDouble yScale )
+{
+ m_context->ScaleTransform(xScale,yScale);
+}
+
+void wxGDIPlusContext::PushState()
+{
+ GraphicsState state = m_context->Save();
+ m_stateStack.push(state);
+}
+
+void wxGDIPlusContext::PopState()
+{
+ GraphicsState state = m_stateStack.top();
+ m_stateStack.pop();
+ m_context->Restore(state);
+}
+
+void wxGDIPlusContext::DrawBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
+{
+ Bitmap* image = static_cast<wxGDIPlusBitmapData*>(bmp.GetRefData())->GetGDIPlusBitmap();
+ if ( image )
+ {
+ if( image->GetWidth() != (UINT) w || image->GetHeight() != (UINT) h )
+ {
+ Rect drawRect((REAL) x, (REAL)y, (REAL)w, (REAL)h);
+ m_context->SetPixelOffsetMode( PixelOffsetModeNone );
+ m_context->DrawImage(image, drawRect, 0 , 0 , image->GetWidth()-1, image->GetHeight()-1, UnitPixel ) ;
+ m_context->SetPixelOffsetMode( PixelOffsetModeHalf );
+ }
+ else
+ m_context->DrawImage(image,(REAL) x,(REAL) y,(REAL) w,(REAL) h) ;
+ }
+}
+
+void wxGDIPlusContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
+{
+ wxGraphicsBitmap bitmap = GetRenderer()->CreateBitmap(bmp);
+ DrawBitmap(bitmap, x, y, w, h);
+}
+
+void wxGDIPlusContext::DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
+{
+ // the built-in conversion fails when there is alpha in the HICON (eg XP style icons), we can only
+ // find out by looking at the bitmap data whether there really was alpha in it