[gnome-panel/gtk3] Add a gtkimage with the current pixbuf to button-widget



commit 0b8ace11087855d741cdeed97dc839db50319ae8
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Mon Jan 17 13:29:22 2011 +0100

    Add a gtkimage with the current pixbuf to button-widget
    
    We need to add a child to the button to get the right allocation of the
    pixbuf. When the button is created without a pixbuf,
    get_preferred_width/height are called the first time when the widget is
    allocated and 0x0 size is cached by gtksizerequest. Since the widget
    doesn't change its size when a pixbuf is set, gtk_widget_queue_resize()
    always uses the cached values instead of calling
    get_preferred_width_height() again. So the actual size, based on pixbuf
    size, is never used. We are overriding the draw() method, so having a
    child doesn't affect the widget rendering anyway.

 gnome-panel/button-widget.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
---
diff --git a/gnome-panel/button-widget.c b/gnome-panel/button-widget.c
index 5786b87..9621611 100644
--- a/gnome-panel/button-widget.c
+++ b/gnome-panel/button-widget.c
@@ -179,6 +179,17 @@ button_widget_reload_pixbuf (ButtonWidget *button)
 							(GtkIconSize) -1, NULL);
 			g_free (error);
 		}
+
+                /* We need to add a child to the button to get the right allocation of the pixbuf.
+                 * When the button is created without a pixbuf, get_preferred_width/height are
+                 * called the first time when the widget is allocated and 0x0 size is cached by
+                 * gtksizerequest. Since the widget doesn't change its size when a pixbuf is set,
+                 * gtk_widget_queue_resize() always uses the cached values instead of calling
+                 * get_preferred_width_height() again. So the actual size, based on pixbuf size,
+                 * is never used. We are overriding the draw() method, so having a child doesn't
+                 * affect the widget rendering anyway.
+                 */
+                gtk_button_set_image (GTK_BUTTON (button), gtk_image_new_from_pixbuf (button->priv->pixbuf));
 	}
 
 	button->priv->pixbuf_hc = make_hc_pixbuf (button->priv->pixbuf);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]