if gdiplus.dll cannot be loaded, return NULL from wxGraphicsContext::Create() instead of silently pretending to render the output, but do nothing
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54233 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1182,6 +1182,7 @@ void wxGDIPlusContext::DrawBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDo
|
|||||||
{
|
{
|
||||||
Rect drawRect((REAL) x, (REAL)y, (REAL)w, (REAL)h);
|
Rect drawRect((REAL) x, (REAL)y, (REAL)w, (REAL)h);
|
||||||
m_context->SetPixelOffsetMode( PixelOffsetModeNone );
|
m_context->SetPixelOffsetMode( PixelOffsetModeNone );
|
||||||
|
m_context->SetInterpolationMode(InterpolationModeHighQualityBicubic);
|
||||||
m_context->DrawImage(image, drawRect, 0 , 0 , image->GetWidth()-1, image->GetHeight()-1, UnitPixel ) ;
|
m_context->DrawImage(image, drawRect, 0 , 0 , image->GetWidth()-1, image->GetHeight()-1, UnitPixel ) ;
|
||||||
m_context->SetPixelOffsetMode( PixelOffsetModeHalf );
|
m_context->SetPixelOffsetMode( PixelOffsetModeHalf );
|
||||||
}
|
}
|
||||||
@@ -1390,13 +1391,13 @@ class wxGDIPlusRenderer : public wxGraphicsRenderer
|
|||||||
public :
|
public :
|
||||||
wxGDIPlusRenderer()
|
wxGDIPlusRenderer()
|
||||||
{
|
{
|
||||||
m_loaded = false;
|
m_loaded = -1;
|
||||||
m_gditoken = 0;
|
m_gditoken = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~wxGDIPlusRenderer()
|
virtual ~wxGDIPlusRenderer()
|
||||||
{
|
{
|
||||||
if (m_loaded)
|
if ( m_loaded == 1 )
|
||||||
{
|
{
|
||||||
Unload();
|
Unload();
|
||||||
}
|
}
|
||||||
@@ -1451,13 +1452,13 @@ public :
|
|||||||
virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
|
virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
void EnsureIsLoaded();
|
bool EnsureIsLoaded();
|
||||||
void Load();
|
void Load();
|
||||||
void Unload();
|
void Unload();
|
||||||
friend class wxGDIPlusRendererModule;
|
friend class wxGDIPlusRendererModule;
|
||||||
|
|
||||||
private :
|
private :
|
||||||
bool m_loaded;
|
int m_loaded;
|
||||||
ULONG_PTR m_gditoken;
|
ULONG_PTR m_gditoken;
|
||||||
|
|
||||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusRenderer)
|
DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusRenderer)
|
||||||
@@ -1476,20 +1477,40 @@ wxGraphicsRenderer* wxGraphicsRenderer::GetDefaultRenderer()
|
|||||||
return &gs_GDIPlusRenderer;
|
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();
|
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()
|
void wxGDIPlusRenderer::Load()
|
||||||
{
|
{
|
||||||
GdiplusStartupInput input;
|
GdiplusStartupInput input;
|
||||||
GdiplusStartupOutput output;
|
GdiplusStartupOutput output;
|
||||||
GdiplusStartup(&m_gditoken,&input,&output);
|
if ( GdiplusStartup(&m_gditoken,&input,&output) == Gdiplus::Ok )
|
||||||
m_loaded = true;
|
{
|
||||||
|
wxLogTrace("gdiplus", "successfully initialized GDI+");
|
||||||
|
m_loaded = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxLogTrace("gdiplus", "failed to initialize GDI+, missing gdiplus.dll?");
|
||||||
|
m_loaded = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGDIPlusRenderer::Unload()
|
void wxGDIPlusRenderer::Unload()
|
||||||
@@ -1499,52 +1520,52 @@ void wxGDIPlusRenderer::Unload()
|
|||||||
GdiplusShutdown(m_gditoken);
|
GdiplusShutdown(m_gditoken);
|
||||||
m_gditoken = NULL;
|
m_gditoken = NULL;
|
||||||
}
|
}
|
||||||
m_loaded = false;
|
m_loaded = -1; // next Load() will try again
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxWindowDC& dc)
|
wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxWindowDC& dc)
|
||||||
{
|
{
|
||||||
EnsureIsLoaded();
|
ENSURE_LOADED_OR_RETURN(NULL);
|
||||||
wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl );
|
wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl );
|
||||||
return new wxGDIPlusContext(this,(HDC) msw->GetHDC());
|
return new wxGDIPlusContext(this,(HDC) msw->GetHDC());
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxPrinterDC& dc)
|
wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxPrinterDC& dc)
|
||||||
{
|
{
|
||||||
EnsureIsLoaded();
|
ENSURE_LOADED_OR_RETURN(NULL);
|
||||||
wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl );
|
wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl );
|
||||||
return new wxGDIPlusContext(this,(HDC) msw->GetHDC());
|
return new wxGDIPlusContext(this,(HDC) msw->GetHDC());
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxMemoryDC& dc)
|
wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxMemoryDC& dc)
|
||||||
{
|
{
|
||||||
EnsureIsLoaded();
|
ENSURE_LOADED_OR_RETURN(NULL);
|
||||||
wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl );
|
wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl );
|
||||||
return new wxGDIPlusContext(this,(HDC) msw->GetHDC());
|
return new wxGDIPlusContext(this,(HDC) msw->GetHDC());
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGraphicsContext * wxGDIPlusRenderer::CreateMeasuringContext()
|
wxGraphicsContext * wxGDIPlusRenderer::CreateMeasuringContext()
|
||||||
{
|
{
|
||||||
EnsureIsLoaded();
|
ENSURE_LOADED_OR_RETURN(NULL);
|
||||||
return new wxGDIPlusMeasuringContext(this);
|
return new wxGDIPlusMeasuringContext(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGraphicsContext * wxGDIPlusRenderer::CreateContextFromNativeContext( void * context )
|
wxGraphicsContext * wxGDIPlusRenderer::CreateContextFromNativeContext( void * context )
|
||||||
{
|
{
|
||||||
EnsureIsLoaded();
|
ENSURE_LOADED_OR_RETURN(NULL);
|
||||||
return new wxGDIPlusContext(this,(Graphics*) context);
|
return new wxGDIPlusContext(this,(Graphics*) context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxGraphicsContext * wxGDIPlusRenderer::CreateContextFromNativeWindow( void * window )
|
wxGraphicsContext * wxGDIPlusRenderer::CreateContextFromNativeWindow( void * window )
|
||||||
{
|
{
|
||||||
EnsureIsLoaded();
|
ENSURE_LOADED_OR_RETURN(NULL);
|
||||||
return new wxGDIPlusContext(this,(HWND) window);
|
return new wxGDIPlusContext(this,(HWND) window);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGraphicsContext * wxGDIPlusRenderer::CreateContext( wxWindow* window )
|
wxGraphicsContext * wxGDIPlusRenderer::CreateContext( wxWindow* window )
|
||||||
{
|
{
|
||||||
EnsureIsLoaded();
|
ENSURE_LOADED_OR_RETURN(NULL);
|
||||||
return new wxGDIPlusContext(this, (HWND) window->GetHWND() );
|
return new wxGDIPlusContext(this, (HWND) window->GetHWND() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1552,7 +1573,7 @@ wxGraphicsContext * wxGDIPlusRenderer::CreateContext( wxWindow* window )
|
|||||||
|
|
||||||
wxGraphicsPath wxGDIPlusRenderer::CreatePath()
|
wxGraphicsPath wxGDIPlusRenderer::CreatePath()
|
||||||
{
|
{
|
||||||
EnsureIsLoaded();
|
ENSURE_LOADED_OR_RETURN(wxNullGraphicsPath);
|
||||||
wxGraphicsPath m;
|
wxGraphicsPath m;
|
||||||
m.SetRefData( new wxGDIPlusPathData(this));
|
m.SetRefData( new wxGDIPlusPathData(this));
|
||||||
return m;
|
return m;
|
||||||
@@ -1565,7 +1586,7 @@ wxGraphicsMatrix wxGDIPlusRenderer::CreateMatrix( wxDouble a, wxDouble b, wxDoub
|
|||||||
wxDouble tx, wxDouble ty)
|
wxDouble tx, wxDouble ty)
|
||||||
|
|
||||||
{
|
{
|
||||||
EnsureIsLoaded();
|
ENSURE_LOADED_OR_RETURN(wxNullGraphicsMatrix);
|
||||||
wxGraphicsMatrix m;
|
wxGraphicsMatrix m;
|
||||||
wxGDIPlusMatrixData* data = new wxGDIPlusMatrixData( this );
|
wxGDIPlusMatrixData* data = new wxGDIPlusMatrixData( this );
|
||||||
data->Set( a,b,c,d,tx,ty ) ;
|
data->Set( a,b,c,d,tx,ty ) ;
|
||||||
@@ -1575,7 +1596,7 @@ wxGraphicsMatrix wxGDIPlusRenderer::CreateMatrix( wxDouble a, wxDouble b, wxDoub
|
|||||||
|
|
||||||
wxGraphicsPen wxGDIPlusRenderer::CreatePen(const wxPen& pen)
|
wxGraphicsPen wxGDIPlusRenderer::CreatePen(const wxPen& pen)
|
||||||
{
|
{
|
||||||
EnsureIsLoaded();
|
ENSURE_LOADED_OR_RETURN(wxNullGraphicsPen);
|
||||||
if ( !pen.Ok() || pen.GetStyle() == wxTRANSPARENT )
|
if ( !pen.Ok() || pen.GetStyle() == wxTRANSPARENT )
|
||||||
return wxNullGraphicsPen;
|
return wxNullGraphicsPen;
|
||||||
else
|
else
|
||||||
@@ -1588,7 +1609,7 @@ wxGraphicsPen wxGDIPlusRenderer::CreatePen(const wxPen& pen)
|
|||||||
|
|
||||||
wxGraphicsBrush wxGDIPlusRenderer::CreateBrush(const wxBrush& brush )
|
wxGraphicsBrush wxGDIPlusRenderer::CreateBrush(const wxBrush& brush )
|
||||||
{
|
{
|
||||||
EnsureIsLoaded();
|
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush);
|
||||||
if ( !brush.Ok() || brush.GetStyle() == wxTRANSPARENT )
|
if ( !brush.Ok() || brush.GetStyle() == wxTRANSPARENT )
|
||||||
return wxNullGraphicsBrush;
|
return wxNullGraphicsBrush;
|
||||||
else
|
else
|
||||||
@@ -1603,7 +1624,7 @@ wxGraphicsBrush wxGDIPlusRenderer::CreateBrush(const wxBrush& brush )
|
|||||||
wxGraphicsBrush wxGDIPlusRenderer::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
|
wxGraphicsBrush wxGDIPlusRenderer::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
|
||||||
const wxColour&c1, const wxColour&c2)
|
const wxColour&c1, const wxColour&c2)
|
||||||
{
|
{
|
||||||
EnsureIsLoaded();
|
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush);
|
||||||
wxGraphicsBrush p;
|
wxGraphicsBrush p;
|
||||||
wxGDIPlusBrushData* d = new wxGDIPlusBrushData( this );
|
wxGDIPlusBrushData* d = new wxGDIPlusBrushData( this );
|
||||||
d->CreateLinearGradientBrush(x1, y1, x2, y2, c1, c2);
|
d->CreateLinearGradientBrush(x1, y1, x2, y2, c1, c2);
|
||||||
@@ -1616,7 +1637,7 @@ wxGraphicsBrush wxGDIPlusRenderer::CreateLinearGradientBrush( wxDouble x1, wxDou
|
|||||||
wxGraphicsBrush wxGDIPlusRenderer::CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
|
wxGraphicsBrush wxGDIPlusRenderer::CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
|
||||||
const wxColour &oColor, const wxColour &cColor)
|
const wxColour &oColor, const wxColour &cColor)
|
||||||
{
|
{
|
||||||
EnsureIsLoaded();
|
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush);
|
||||||
wxGraphicsBrush p;
|
wxGraphicsBrush p;
|
||||||
wxGDIPlusBrushData* d = new wxGDIPlusBrushData( this );
|
wxGDIPlusBrushData* d = new wxGDIPlusBrushData( this );
|
||||||
d->CreateRadialGradientBrush(xo,yo,xc,yc,radius,oColor,cColor);
|
d->CreateRadialGradientBrush(xo,yo,xc,yc,radius,oColor,cColor);
|
||||||
@@ -1627,7 +1648,7 @@ wxGraphicsBrush wxGDIPlusRenderer::CreateRadialGradientBrush( wxDouble xo, wxDou
|
|||||||
// sets the font
|
// sets the font
|
||||||
wxGraphicsFont wxGDIPlusRenderer::CreateFont( const wxFont &font , const wxColour &col )
|
wxGraphicsFont wxGDIPlusRenderer::CreateFont( const wxFont &font , const wxColour &col )
|
||||||
{
|
{
|
||||||
EnsureIsLoaded();
|
ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont);
|
||||||
if ( font.Ok() )
|
if ( font.Ok() )
|
||||||
{
|
{
|
||||||
wxGraphicsFont p;
|
wxGraphicsFont p;
|
||||||
@@ -1640,7 +1661,7 @@ wxGraphicsFont wxGDIPlusRenderer::CreateFont( const wxFont &font , const wxColou
|
|||||||
|
|
||||||
wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmap( const wxBitmap &bitmap )
|
wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmap( const wxBitmap &bitmap )
|
||||||
{
|
{
|
||||||
EnsureIsLoaded();
|
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);
|
||||||
if ( bitmap.Ok() )
|
if ( bitmap.Ok() )
|
||||||
{
|
{
|
||||||
wxGraphicsBitmap p;
|
wxGraphicsBitmap p;
|
||||||
@@ -1653,7 +1674,7 @@ wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmap( const wxBitmap &bitmap )
|
|||||||
|
|
||||||
wxGraphicsBitmap wxGDIPlusRenderer::CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
|
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();
|
Bitmap* image = static_cast<wxGDIPlusBitmapData*>(bitmap.GetRefData())->GetGDIPlusBitmap();
|
||||||
if ( image )
|
if ( image )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user