simplify code so it always returns the same object

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73099 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Paul Cornett
2012-12-02 05:48:24 +00:00
parent 46421f2471
commit ba49d2acf9

View File

@@ -2437,7 +2437,6 @@ wxGraphicsContext * wxCairoRenderer::CreateContext( const wxPrinterDC& dc)
#if wxUSE_ENH_METAFILE #if wxUSE_ENH_METAFILE
wxGraphicsContext * wxCairoRenderer::CreateContext( const wxEnhMetaFileDC& WXUNUSED(dc) ) wxGraphicsContext * wxCairoRenderer::CreateContext( const wxEnhMetaFileDC& WXUNUSED(dc) )
{ {
ENSURE_LOADED_OR_RETURN(NULL);
return NULL; return NULL;
} }
#endif #endif
@@ -2456,7 +2455,6 @@ wxGraphicsContext * wxCairoRenderer::CreateContextFromNativeContext( void * cont
wxGraphicsContext * wxCairoRenderer::CreateContextFromNativeWindow( void * window ) wxGraphicsContext * wxCairoRenderer::CreateContextFromNativeWindow( void * window )
{ {
ENSURE_LOADED_OR_RETURN(NULL);
#ifdef __WXGTK__ #ifdef __WXGTK__
return new wxCairoContext(this, static_cast<GdkWindow*>(window)); return new wxCairoContext(this, static_cast<GdkWindow*>(window));
#else #else
@@ -2468,13 +2466,13 @@ wxGraphicsContext * wxCairoRenderer::CreateContextFromNativeWindow( void * windo
#if wxUSE_IMAGE #if wxUSE_IMAGE
wxGraphicsContext * wxCairoRenderer::CreateContextFromImage(wxImage& image) wxGraphicsContext * wxCairoRenderer::CreateContextFromImage(wxImage& image)
{ {
ENSURE_LOADED_OR_RETURN(NULL);
return new wxCairoImageContext(this, image); return new wxCairoImageContext(this, image);
} }
#endif // wxUSE_IMAGE #endif // wxUSE_IMAGE
wxGraphicsContext * wxCairoRenderer::CreateMeasuringContext() wxGraphicsContext * wxCairoRenderer::CreateMeasuringContext()
{ {
ENSURE_LOADED_OR_RETURN(NULL);
#ifdef __WXGTK__ #ifdef __WXGTK__
return CreateContextFromNativeWindow(gdk_get_default_root_window()); return CreateContextFromNativeWindow(gdk_get_default_root_window());
#else #else
@@ -2493,8 +2491,8 @@ wxGraphicsContext * wxCairoRenderer::CreateContext( wxWindow* window )
wxGraphicsPath wxCairoRenderer::CreatePath() wxGraphicsPath wxCairoRenderer::CreatePath()
{ {
ENSURE_LOADED_OR_RETURN(wxNullGraphicsPath);
wxGraphicsPath path; wxGraphicsPath path;
ENSURE_LOADED_OR_RETURN(path);
path.SetRefData( new wxCairoPathData(this) ); path.SetRefData( new wxCairoPathData(this) );
return path; return path;
} }
@@ -2506,8 +2504,8 @@ wxGraphicsMatrix wxCairoRenderer::CreateMatrix( wxDouble a, wxDouble b, wxDouble
wxDouble tx, wxDouble ty) wxDouble tx, wxDouble ty)
{ {
ENSURE_LOADED_OR_RETURN(wxNullGraphicsMatrix);
wxGraphicsMatrix m; wxGraphicsMatrix m;
ENSURE_LOADED_OR_RETURN(m);
wxCairoMatrixData* data = new wxCairoMatrixData( this ); wxCairoMatrixData* data = new wxCairoMatrixData( this );
data->Set( a,b,c,d,tx,ty ) ; data->Set( a,b,c,d,tx,ty ) ;
m.SetRefData(data); m.SetRefData(data);
@@ -2516,28 +2514,24 @@ wxGraphicsMatrix wxCairoRenderer::CreateMatrix( wxDouble a, wxDouble b, wxDouble
wxGraphicsPen wxCairoRenderer::CreatePen(const wxPen& pen) wxGraphicsPen wxCairoRenderer::CreatePen(const wxPen& pen)
{ {
ENSURE_LOADED_OR_RETURN(wxNullGraphicsPen); wxGraphicsPen p;
if ( !pen.IsOk() || pen.GetStyle() == wxPENSTYLE_TRANSPARENT ) ENSURE_LOADED_OR_RETURN(p);
return wxNullGraphicsPen; if (pen.IsOk() && pen.GetStyle() == wxPENSTYLE_TRANSPARENT)
else
{ {
wxGraphicsPen p;
p.SetRefData(new wxCairoPenData( this, pen )); p.SetRefData(new wxCairoPenData( this, pen ));
return p;
} }
return p;
} }
wxGraphicsBrush wxCairoRenderer::CreateBrush(const wxBrush& brush ) wxGraphicsBrush wxCairoRenderer::CreateBrush(const wxBrush& brush )
{ {
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush); wxGraphicsBrush p;
if ( !brush.IsOk() || brush.GetStyle() == wxBRUSHSTYLE_TRANSPARENT ) ENSURE_LOADED_OR_RETURN(p);
return wxNullGraphicsBrush; if (brush.IsOk() && brush.GetStyle() == wxBRUSHSTYLE_TRANSPARENT)
else
{ {
wxGraphicsBrush p;
p.SetRefData(new wxCairoBrushData( this, brush )); p.SetRefData(new wxCairoBrushData( this, brush ));
return p;
} }
return p;
} }
wxGraphicsBrush wxGraphicsBrush
@@ -2545,8 +2539,8 @@ wxCairoRenderer::CreateLinearGradientBrush(wxDouble x1, wxDouble y1,
wxDouble x2, wxDouble y2, wxDouble x2, wxDouble y2,
const wxGraphicsGradientStops& stops) const wxGraphicsGradientStops& stops)
{ {
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush);
wxGraphicsBrush p; wxGraphicsBrush p;
ENSURE_LOADED_OR_RETURN(p);
wxCairoBrushData* d = new wxCairoBrushData( this ); wxCairoBrushData* d = new wxCairoBrushData( this );
d->CreateLinearGradientBrush(x1, y1, x2, y2, stops); d->CreateLinearGradientBrush(x1, y1, x2, y2, stops);
p.SetRefData(d); p.SetRefData(d);
@@ -2558,8 +2552,8 @@ wxCairoRenderer::CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
wxDouble xc, wxDouble yc, wxDouble r, wxDouble xc, wxDouble yc, wxDouble r,
const wxGraphicsGradientStops& stops) const wxGraphicsGradientStops& stops)
{ {
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush);
wxGraphicsBrush p; wxGraphicsBrush p;
ENSURE_LOADED_OR_RETURN(p);
wxCairoBrushData* d = new wxCairoBrushData( this ); wxCairoBrushData* d = new wxCairoBrushData( this );
d->CreateRadialGradientBrush(xo, yo, xc, yc, r, stops); d->CreateRadialGradientBrush(xo, yo, xc, yc, r, stops);
p.SetRefData(d); p.SetRefData(d);
@@ -2568,15 +2562,13 @@ wxCairoRenderer::CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
wxGraphicsFont wxCairoRenderer::CreateFont( const wxFont &font , const wxColour &col ) wxGraphicsFont wxCairoRenderer::CreateFont( const wxFont &font , const wxColour &col )
{ {
ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont); wxGraphicsFont p;
ENSURE_LOADED_OR_RETURN(p);
if ( font.IsOk() ) if ( font.IsOk() )
{ {
wxGraphicsFont p;
p.SetRefData(new wxCairoFontData( this , font, col )); p.SetRefData(new wxCairoFontData( this , font, col ));
return p;
} }
else return p;
return wxNullGraphicsFont;
} }
wxGraphicsFont wxGraphicsFont
@@ -2585,24 +2577,21 @@ wxCairoRenderer::CreateFont(double sizeInPixels,
int flags, int flags,
const wxColour& col) const wxColour& col)
{ {
ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont);
wxGraphicsFont font; wxGraphicsFont font;
ENSURE_LOADED_OR_RETURN(font);
font.SetRefData(new wxCairoFontData(this, sizeInPixels, facename, flags, col)); font.SetRefData(new wxCairoFontData(this, sizeInPixels, facename, flags, col));
return font; return font;
} }
wxGraphicsBitmap wxCairoRenderer::CreateBitmap( const wxBitmap& bmp ) wxGraphicsBitmap wxCairoRenderer::CreateBitmap( const wxBitmap& bmp )
{ {
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap); wxGraphicsBitmap p;
ENSURE_LOADED_OR_RETURN(p);
if ( bmp.IsOk() ) if ( bmp.IsOk() )
{ {
wxGraphicsBitmap p;
p.SetRefData(new wxCairoBitmapData( this , bmp )); p.SetRefData(new wxCairoBitmapData( this , bmp ));
return p;
} }
else return p;
return wxNullGraphicsBitmap;
} }
#if wxUSE_IMAGE #if wxUSE_IMAGE
@@ -2623,12 +2612,15 @@ wxGraphicsBitmap wxCairoRenderer::CreateBitmapFromImage(const wxImage& image)
wxImage wxCairoRenderer::CreateImageFromBitmap(const wxGraphicsBitmap& bmp) wxImage wxCairoRenderer::CreateImageFromBitmap(const wxGraphicsBitmap& bmp)
{ {
ENSURE_LOADED_OR_RETURN(wxNullImage); wxImage image;
ENSURE_LOADED_OR_RETURN(image);
const wxCairoBitmapData* const const wxCairoBitmapData* const
data = static_cast<wxCairoBitmapData*>(bmp.GetGraphicsData()); data = static_cast<wxCairoBitmapData*>(bmp.GetGraphicsData());
if (data)
image = data->ConvertToImage();
return data ? data->ConvertToImage() : wxNullImage; return image;
} }
#endif // wxUSE_IMAGE #endif // wxUSE_IMAGE
@@ -2636,15 +2628,13 @@ wxImage wxCairoRenderer::CreateImageFromBitmap(const wxGraphicsBitmap& bmp)
wxGraphicsBitmap wxCairoRenderer::CreateBitmapFromNativeBitmap( void* bitmap ) wxGraphicsBitmap wxCairoRenderer::CreateBitmapFromNativeBitmap( void* bitmap )
{ {
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap); wxGraphicsBitmap p;
ENSURE_LOADED_OR_RETURN(p);
if ( bitmap != NULL ) if ( bitmap != NULL )
{ {
wxGraphicsBitmap p;
p.SetRefData(new wxCairoBitmapData( this , (cairo_surface_t*) bitmap )); p.SetRefData(new wxCairoBitmapData( this , (cairo_surface_t*) bitmap ));
return p;
} }
else return p;
return wxNullGraphicsBitmap;
} }
wxGraphicsBitmap wxGraphicsBitmap
@@ -2654,9 +2644,9 @@ wxCairoRenderer::CreateSubBitmap(const wxGraphicsBitmap& WXUNUSED(bitmap),
wxDouble WXUNUSED(w), wxDouble WXUNUSED(w),
wxDouble WXUNUSED(h)) wxDouble WXUNUSED(h))
{ {
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap); wxGraphicsBitmap p;
wxFAIL_MSG("wxCairoRenderer::CreateSubBitmap is not implemented."); wxFAIL_MSG("wxCairoRenderer::CreateSubBitmap is not implemented.");
return wxNullGraphicsBitmap; return p;
} }
wxGraphicsRenderer* wxGraphicsRenderer::GetCairoRenderer() wxGraphicsRenderer* wxGraphicsRenderer::GetCairoRenderer()