From fc684792c6b050fbfeabbea92e302bc3469d7489 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 14 Dec 2010 18:43:32 +0000 Subject: [PATCH] Don't use implicit wxBitmapRefData copy ctor in wxGTK code. wxBitmapRefData didn't have a proper copy ctor but the code in wxGTK wxBitmap implementation used it nevertheless and then manually patched the newly copied object to avoid double pointer deletion and other unpleasantness. Make the code more obviously correct by not using (nor providing) copy ctor at all. There are no real changes otherwise. See #12768. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66372 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/bitmap.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index b26bafcff7..a50e8a8e26 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -231,6 +231,13 @@ public: int m_height; int m_bpp; bool m_alphaRequested; + +private: + // We don't provide a copy ctor as copying m_pixmap and m_pixbuf properly + // is expensive and we don't want to do it implicitly (and possibly + // accidentally). wxBitmap::CloneGDIRefData() which does need to do it does + // it explicitly itself. + wxDECLARE_NO_COPY_CLASS(wxBitmapRefData); }; wxBitmapRefData::wxBitmapRefData(int width, int height, int depth) @@ -606,10 +613,8 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const rect.y + h <= bmpData->m_height, ret, wxT("invalid bitmap region")); - wxBitmapRefData* newRef = new wxBitmapRefData(*bmpData); + wxBitmapRefData * const newRef = new wxBitmapRefData(w, h, bmpData->m_bpp); ret.m_refData = newRef; - newRef->m_width = w; - newRef->m_height = h; if (bmpData->m_pixbuf) { @@ -626,7 +631,6 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const newRef->m_pixmap, gc, bmpData->m_pixmap, rect.x, rect.y, 0, 0, w, h); g_object_unref(gc); } - newRef->m_mask = NULL; if (bmpData->m_mask && bmpData->m_mask->m_bitmap) { GdkPixmap* sub_mask = gdk_pixmap_new(bmpData->m_mask->m_bitmap, w, h, 1); @@ -861,7 +865,9 @@ wxGDIRefData* wxBitmap::CreateGDIRefData() const wxGDIRefData* wxBitmap::CloneGDIRefData(const wxGDIRefData* data) const { const wxBitmapRefData* oldRef = static_cast(data); - wxBitmapRefData* newRef = new wxBitmapRefData(*oldRef); + wxBitmapRefData * const newRef = new wxBitmapRefData(oldRef->m_width, + oldRef->m_height, + oldRef->m_bpp); if (oldRef->m_pixmap != NULL) { newRef->m_pixmap = gdk_pixmap_new( -- 2.45.2