]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/graphics.cpp
move SendSizeEvent() down to wxWindow from wxFrame; added SendSizeEventToParent(...
[wxWidgets.git] / src / msw / graphics.cpp
index 15e3bd87d4738489b9cb781104eae32d44843389..9d8aac3fbd6973cb017b5bece3cde81698b13496 100644 (file)
     #include "wx/msw/wrapcdlg.h"
     #include "wx/image.h"
     #include "wx/window.h"
-    #include "wx/dc.h"
     #include "wx/utils.h"
     #include "wx/dialog.h"
     #include "wx/app.h"
     #include "wx/bitmap.h"
-    #include "wx/dcmemory.h"
     #include "wx/log.h"
     #include "wx/icon.h"
-    #include "wx/dcprint.h"
     #include "wx/module.h"
+    // include all dc types that are used as a param
+    #include "wx/dc.h"
+    #include "wx/dcclient.h"
+    #include "wx/dcmemory.h"
+    #include "wx/dcprint.h"
 #endif
 
 #include "wx/private/graphics.h"
@@ -1390,13 +1392,13 @@ class wxGDIPlusRenderer : public wxGraphicsRenderer
 public :
     wxGDIPlusRenderer()
     {
-        m_loaded = false;
+        m_loaded = -1;
         m_gditoken = 0;
     }
 
     virtual ~wxGDIPlusRenderer()
     {
-        if (m_loaded)
+        if ( m_loaded == 1 )
         {
             Unload();
         }
@@ -1408,6 +1410,8 @@ public :
 
     virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc);
 
+    virtual wxGraphicsContext * CreateContext( const wxPrinterDC& dc);
+    
     virtual wxGraphicsContext * CreateContextFromNativeContext( void * context );
 
     virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window );
@@ -1449,13 +1453,13 @@ public :
     virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h  );
 
 protected :
-    void EnsureIsLoaded();
+    bool EnsureIsLoaded();
     void Load();
     void Unload();
     friend class wxGDIPlusRendererModule;
 
 private :
-    bool m_loaded;
+    int m_loaded;
     ULONG_PTR m_gditoken;
 
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusRenderer)
@@ -1474,20 +1478,40 @@ wxGraphicsRenderer* wxGraphicsRenderer::GetDefaultRenderer()
     return &gs_GDIPlusRenderer;
 }
 
-void wxGDIPlusRenderer::EnsureIsLoaded()
+bool wxGDIPlusRenderer::EnsureIsLoaded()
 {
-    if (!m_loaded)
+    // load gdiplus.dll if not yet loaded, but don't bother doing it again
+    // if we already tried and failed (we don't want to spend lot of time
+    // returning NULL from wxGraphicsContext::Create(), which may be called
+    // relatively frequently):
+    if ( m_loaded == -1 )
     {
         Load();
     }
+
+    return m_loaded == 1;
 }
 
+// call EnsureIsLoaded() and return returnOnFail value if it fails
+#define ENSURE_LOADED_OR_RETURN(returnOnFail)  \
+    if ( !EnsureIsLoaded() )                   \
+        return (returnOnFail)
+
+
 void wxGDIPlusRenderer::Load()
 {
     GdiplusStartupInput input;
     GdiplusStartupOutput output;
-    GdiplusStartup(&m_gditoken,&input,&output);
-    m_loaded = true;
+    if ( GdiplusStartup(&m_gditoken,&input,&output) == Gdiplus::Ok )
+    {
+        wxLogTrace("gdiplus", "successfully initialized GDI+");
+        m_loaded = 1;
+    }
+    else
+    {
+        wxLogTrace("gdiplus", "failed to initialize GDI+, missing gdiplus.dll?");
+        m_loaded = 0;
+    }
 }
 
 void wxGDIPlusRenderer::Unload()
@@ -1497,45 +1521,52 @@ void wxGDIPlusRenderer::Unload()
         GdiplusShutdown(m_gditoken);
         m_gditoken = NULL;
     }
-    m_loaded = false;
+    m_loaded = -1; // next Load() will try again
 }
 
 wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxWindowDC& dc)
 {
-    EnsureIsLoaded();
+    ENSURE_LOADED_OR_RETURN(NULL);
+    wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl );
+    return new wxGDIPlusContext(this,(HDC) msw->GetHDC());
+}
+
+wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxPrinterDC& dc)
+{
+    ENSURE_LOADED_OR_RETURN(NULL);
     wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl );
     return new wxGDIPlusContext(this,(HDC) msw->GetHDC());
 }
 
 wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxMemoryDC& dc)
 {
-    EnsureIsLoaded();
+    ENSURE_LOADED_OR_RETURN(NULL);
     wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl );
     return new wxGDIPlusContext(this,(HDC) msw->GetHDC());
 }
 
 wxGraphicsContext * wxGDIPlusRenderer::CreateMeasuringContext()
 {
-    EnsureIsLoaded();
+    ENSURE_LOADED_OR_RETURN(NULL);
     return new wxGDIPlusMeasuringContext(this);
 }
 
 wxGraphicsContext * wxGDIPlusRenderer::CreateContextFromNativeContext( void * context )
 {
-    EnsureIsLoaded();
+    ENSURE_LOADED_OR_RETURN(NULL);
     return new wxGDIPlusContext(this,(Graphics*) context);
 }
 
 
 wxGraphicsContext * wxGDIPlusRenderer::CreateContextFromNativeWindow( void * window )
 {
-    EnsureIsLoaded();
+    ENSURE_LOADED_OR_RETURN(NULL);
     return new wxGDIPlusContext(this,(HWND) window);
 }
 
 wxGraphicsContext * wxGDIPlusRenderer::CreateContext( wxWindow* window )
 {
-    EnsureIsLoaded();
+    ENSURE_LOADED_OR_RETURN(NULL);
     return new wxGDIPlusContext(this, (HWND) window->GetHWND() );
 }
 
@@ -1543,7 +1574,7 @@ wxGraphicsContext * wxGDIPlusRenderer::CreateContext( wxWindow* window )
 
 wxGraphicsPath wxGDIPlusRenderer::CreatePath()
 {
-    EnsureIsLoaded();
+    ENSURE_LOADED_OR_RETURN(wxNullGraphicsPath);
     wxGraphicsPath m;
     m.SetRefData( new wxGDIPlusPathData(this));
     return m;
@@ -1556,7 +1587,7 @@ wxGraphicsMatrix wxGDIPlusRenderer::CreateMatrix( wxDouble a, wxDouble b, wxDoub
                                                            wxDouble tx, wxDouble ty)
 
 {
-    EnsureIsLoaded();
+    ENSURE_LOADED_OR_RETURN(wxNullGraphicsMatrix);
     wxGraphicsMatrix m;
     wxGDIPlusMatrixData* data = new wxGDIPlusMatrixData( this );
     data->Set( a,b,c,d,tx,ty ) ;
@@ -1566,7 +1597,7 @@ wxGraphicsMatrix wxGDIPlusRenderer::CreateMatrix( wxDouble a, wxDouble b, wxDoub
 
 wxGraphicsPen wxGDIPlusRenderer::CreatePen(const wxPen& pen)
 {
-    EnsureIsLoaded();
+    ENSURE_LOADED_OR_RETURN(wxNullGraphicsPen);
     if ( !pen.Ok() || pen.GetStyle() == wxTRANSPARENT )
         return wxNullGraphicsPen;
     else
@@ -1579,7 +1610,7 @@ wxGraphicsPen wxGDIPlusRenderer::CreatePen(const wxPen& pen)
 
 wxGraphicsBrush wxGDIPlusRenderer::CreateBrush(const wxBrush& brush )
 {
-    EnsureIsLoaded();
+    ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush);
     if ( !brush.Ok() || brush.GetStyle() == wxTRANSPARENT )
         return wxNullGraphicsBrush;
     else
@@ -1594,7 +1625,7 @@ wxGraphicsBrush wxGDIPlusRenderer::CreateBrush(const wxBrush& brush )
 wxGraphicsBrush wxGDIPlusRenderer::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
                                                                       const wxColour&c1, const wxColour&c2)
 {
-    EnsureIsLoaded();
+    ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush);
     wxGraphicsBrush p;
     wxGDIPlusBrushData* d = new wxGDIPlusBrushData( this );
     d->CreateLinearGradientBrush(x1, y1, x2, y2, c1, c2);
@@ -1607,7 +1638,7 @@ wxGraphicsBrush wxGDIPlusRenderer::CreateLinearGradientBrush( wxDouble x1, wxDou
 wxGraphicsBrush wxGDIPlusRenderer::CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
                                                                       const wxColour &oColor, const wxColour &cColor)
 {
-    EnsureIsLoaded();
+    ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush);
     wxGraphicsBrush p;
     wxGDIPlusBrushData* d = new wxGDIPlusBrushData( this );
     d->CreateRadialGradientBrush(xo,yo,xc,yc,radius,oColor,cColor);
@@ -1618,7 +1649,7 @@ wxGraphicsBrush wxGDIPlusRenderer::CreateRadialGradientBrush( wxDouble xo, wxDou
 // sets the font
 wxGraphicsFont wxGDIPlusRenderer::CreateFont( const wxFont &font , const wxColour &col )
 {
-    EnsureIsLoaded();
+    ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont);
     if ( font.Ok() )
     {
         wxGraphicsFont p;
@@ -1631,7 +1662,7 @@ wxGraphicsFont wxGDIPlusRenderer::CreateFont( const wxFont &font , const wxColou
 
 wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmap( const wxBitmap &bitmap )
 {
-    EnsureIsLoaded();
+    ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);
     if ( bitmap.Ok() )
     {
         wxGraphicsBitmap p;
@@ -1644,7 +1675,7 @@ wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmap( const wxBitmap &bitmap )
 
 wxGraphicsBitmap wxGDIPlusRenderer::CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h  )
 {
-    EnsureIsLoaded();
+    ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);
     Bitmap* image = static_cast<wxGDIPlusBitmapData*>(bitmap.GetRefData())->GetGDIPlusBitmap();
     if ( image )
     {