From 54195d23c25f085dc05f4a376ac638a690d8f7fa Mon Sep 17 00:00:00 2001
From: Paul Cornett <paulcor@bullseye.com>
Date: Sun, 25 Mar 2012 23:33:18 +0000
Subject: [PATCH] replace wxBitmap::SetPixbuf() with wxBitmap ctor taking
 pixbuf

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71006 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 include/wx/gtk/bitmap.h |  2 +-
 src/aui/tabartgtk.cpp   |  5 ++---
 src/gtk/artgtk.cpp      |  8 ++------
 src/gtk/bitmap.cpp      | 33 +++++++++++++--------------------
 src/gtk/bmpcbox.cpp     |  2 +-
 5 files changed, 19 insertions(+), 31 deletions(-)

diff --git a/include/wx/gtk/bitmap.h b/include/wx/gtk/bitmap.h
index 8bc0ab3207..c3245532de 100644
--- a/include/wx/gtk/bitmap.h
+++ b/include/wx/gtk/bitmap.h
@@ -68,6 +68,7 @@ public:
     wxBitmap( const wxImage& image, int depth = wxBITMAP_SCREEN_DEPTH )
         { (void)CreateFromImage(image, depth); }
 #endif // wxUSE_IMAGE
+    wxBitmap(GdkPixbuf* pixbuf);
     virtual ~wxBitmap();
 
     bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH);
@@ -108,7 +109,6 @@ public:
     void SetHeight( int height );
     void SetWidth( int width );
     void SetDepth( int depth );
-    void SetPixbuf(GdkPixbuf* pixbuf);
 
     GdkPixmap *GetPixmap() const;
     bool HasPixmap() const;
diff --git a/src/aui/tabartgtk.cpp b/src/aui/tabartgtk.cpp
index 7b3e6aa1f0..a7bc5e4551 100644
--- a/src/aui/tabartgtk.cpp
+++ b/src/aui/tabartgtk.cpp
@@ -4,7 +4,7 @@
 // Author:      Jens Lody and Teodor Petrov
 // Modified by:
 // Created:     2012-03-23
-// RCS-ID:      $Id:$
+// RCS-ID:      $Id$
 // Copyright:   (c) 2012 Jens Lody <jens@codeblocks.org>
 //                  and Teodor Petrov
 // Licence:     wxWindows licence
@@ -119,8 +119,7 @@ wxRect DrawCloseButton(wxDC& dc,
     int xthickness = style_button->xthickness;
     int ythickness = style_button->ythickness;
 
-    wxBitmap bmp;
-    bmp.SetPixbuf(gtk_widget_render_icon(widget, GTK_STOCK_CLOSE, GTK_ICON_SIZE_SMALL_TOOLBAR, "tab"));
+    wxBitmap bmp(gtk_widget_render_icon(widget, GTK_STOCK_CLOSE, GTK_ICON_SIZE_SMALL_TOOLBAR, "tab"));
 
     if(bmp.GetWidth() != s_CloseIconSize || bmp.GetHeight() != s_CloseIconSize)
     {
diff --git a/src/gtk/artgtk.cpp b/src/gtk/artgtk.cpp
index c438a72a76..c90d9609cb 100644
--- a/src/gtk/artgtk.cpp
+++ b/src/gtk/artgtk.cpp
@@ -259,7 +259,7 @@ wxIconBundle DoCreateIconBundle(const char *stockid,
             continue;
 
         wxIcon icon;
-        icon.SetPixbuf(pixbuf);
+        icon.CopyFromBitmap(wxBitmap(pixbuf));
         bundle.AddIcon(icon);
     }
 
@@ -296,11 +296,7 @@ wxBitmap wxGTK2ArtProvider::CreateBitmap(const wxArtID& id,
         }
     }
 
-    wxBitmap bmp;
-    if (pixbuf != NULL)
-        bmp.SetPixbuf(pixbuf);
-
-    return bmp;
+    return wxBitmap(pixbuf);
 }
 
 wxIconBundle
diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp
index 743e99c18a..4519ea932e 100644
--- a/src/gtk/bitmap.cpp
+++ b/src/gtk/bitmap.cpp
@@ -309,6 +309,18 @@ wxBitmap::wxBitmap(const char* const* bits)
     }
 }
 
+wxBitmap::wxBitmap(GdkPixbuf* pixbuf)
+{
+    if (pixbuf)
+    {
+        wxBitmapRefData* bmpData = new wxBitmapRefData(
+            gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf),
+            gdk_pixbuf_get_n_channels(pixbuf) * 8);
+        m_refData = bmpData;
+        bmpData->m_pixbuf = pixbuf;
+    }
+}
+
 wxBitmap::~wxBitmap()
 {
 }
@@ -679,10 +691,7 @@ bool wxBitmap::LoadFile( const wxString &name, wxBitmapType type )
     {
         wxUnusedVar(type); // The type is detected automatically by GDK.
 
-        UnRef();
-        GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file(name.fn_str(), NULL);
-        if (pixbuf)
-            SetPixbuf(pixbuf);
+        *this = wxBitmap(gdk_pixbuf_new_from_file(name.fn_str(), NULL));
     }
 
     return IsOk();
@@ -802,22 +811,6 @@ bool wxBitmap::HasPixbuf() const
     return M_BMPDATA->m_pixbuf != NULL;
 }
 
-void wxBitmap::SetPixbuf(GdkPixbuf* pixbuf)
-{
-    UnRef();
-
-    if (!pixbuf)
-        return;
-
-    int depth = -1;
-    if (gdk_pixbuf_get_has_alpha(pixbuf))
-        depth = 32;
-    m_refData = new wxBitmapRefData(
-        gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), depth);
-
-    M_BMPDATA->m_pixbuf = pixbuf;
-}
-
 void wxBitmap::PurgeOtherRepresentations(wxBitmap::Representation keep)
 {
     if (keep == Pixmap && HasPixbuf())
diff --git a/src/gtk/bmpcbox.cpp b/src/gtk/bmpcbox.cpp
index b625542b10..7ac3b0ecde 100644
--- a/src/gtk/bmpcbox.cpp
+++ b/src/gtk/bmpcbox.cpp
@@ -224,7 +224,7 @@ wxBitmap wxBitmapComboBox::GetItemBitmap(unsigned int n) const
         if ( pixbuf )
         {
             g_object_ref( pixbuf );
-            bitmap.SetPixbuf( pixbuf );
+            bitmap = wxBitmap(pixbuf);
         }
         g_value_unset( &value );
     }
-- 
2.47.2