diff --git a/ChangeLog b/ChangeLog index 6c49ca7e3..a62438cd4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +Mon Apr 22 19:24:29 2002 Kristian Rietveld + + This commit adds stock icon functionality to GtkCellRendererPixbuf + which is totally cool. + + * gtk/gtkcellrendererpixbuf.h: add some fields + + * gtk/gtkcellrendererpixbuf.c: add finalize method, add some + properties, add some stock icon rendering code. + + * demos/gtk-demo/stock_browser.c: modified to use the stock + icon stuff in the cellrendererpixbuf instead of its own stock icon + rendering code. + 2002-04-21 Alexander Larsson * gdk/x11/gdkwindow-x11.c (gdk_window_reparent): diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 6c49ca7e3..a62438cd4 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,17 @@ +Mon Apr 22 19:24:29 2002 Kristian Rietveld + + This commit adds stock icon functionality to GtkCellRendererPixbuf + which is totally cool. + + * gtk/gtkcellrendererpixbuf.h: add some fields + + * gtk/gtkcellrendererpixbuf.c: add finalize method, add some + properties, add some stock icon rendering code. + + * demos/gtk-demo/stock_browser.c: modified to use the stock + icon stuff in the cellrendererpixbuf instead of its own stock icon + rendering code. + 2002-04-21 Alexander Larsson * gdk/x11/gdkwindow-x11.c (gdk_window_reparent): diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 6c49ca7e3..a62438cd4 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,17 @@ +Mon Apr 22 19:24:29 2002 Kristian Rietveld + + This commit adds stock icon functionality to GtkCellRendererPixbuf + which is totally cool. + + * gtk/gtkcellrendererpixbuf.h: add some fields + + * gtk/gtkcellrendererpixbuf.c: add finalize method, add some + properties, add some stock icon rendering code. + + * demos/gtk-demo/stock_browser.c: modified to use the stock + icon stuff in the cellrendererpixbuf instead of its own stock icon + rendering code. + 2002-04-21 Alexander Larsson * gdk/x11/gdkwindow-x11.c (gdk_window_reparent): diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 6c49ca7e3..a62438cd4 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,17 @@ +Mon Apr 22 19:24:29 2002 Kristian Rietveld + + This commit adds stock icon functionality to GtkCellRendererPixbuf + which is totally cool. + + * gtk/gtkcellrendererpixbuf.h: add some fields + + * gtk/gtkcellrendererpixbuf.c: add finalize method, add some + properties, add some stock icon rendering code. + + * demos/gtk-demo/stock_browser.c: modified to use the stock + icon stuff in the cellrendererpixbuf instead of its own stock icon + rendering code. + 2002-04-21 Alexander Larsson * gdk/x11/gdkwindow-x11.c (gdk_window_reparent): diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 6c49ca7e3..a62438cd4 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,17 @@ +Mon Apr 22 19:24:29 2002 Kristian Rietveld + + This commit adds stock icon functionality to GtkCellRendererPixbuf + which is totally cool. + + * gtk/gtkcellrendererpixbuf.h: add some fields + + * gtk/gtkcellrendererpixbuf.c: add finalize method, add some + properties, add some stock icon rendering code. + + * demos/gtk-demo/stock_browser.c: modified to use the stock + icon stuff in the cellrendererpixbuf instead of its own stock icon + rendering code. + 2002-04-21 Alexander Larsson * gdk/x11/gdkwindow-x11.c (gdk_window_reparent): diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 6c49ca7e3..a62438cd4 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,17 @@ +Mon Apr 22 19:24:29 2002 Kristian Rietveld + + This commit adds stock icon functionality to GtkCellRendererPixbuf + which is totally cool. + + * gtk/gtkcellrendererpixbuf.h: add some fields + + * gtk/gtkcellrendererpixbuf.c: add finalize method, add some + properties, add some stock icon rendering code. + + * demos/gtk-demo/stock_browser.c: modified to use the stock + icon stuff in the cellrendererpixbuf instead of its own stock icon + rendering code. + 2002-04-21 Alexander Larsson * gdk/x11/gdkwindow-x11.c (gdk_window_reparent): diff --git a/demos/gtk-demo/stock_browser.c b/demos/gtk-demo/stock_browser.c index 7457c5f17..61417f3fe 100644 --- a/demos/gtk-demo/stock_browser.c +++ b/demos/gtk-demo/stock_browser.c @@ -121,7 +121,7 @@ create_model (void) GSList *ids; GSList *tmp_list; - store = gtk_list_store_new (1, STOCK_ITEM_INFO_TYPE); + store = gtk_list_store_new (2, STOCK_ITEM_INFO_TYPE, G_TYPE_STRING); ids = gtk_stock_list_ids (); ids = g_slist_sort (ids, (GCompareFunc) strcmp); @@ -210,7 +210,7 @@ create_model (void) info.macro = id_to_macro (info.id); gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, &info, -1); + gtk_list_store_set (store, &iter, 0, &info, 1, info.id, -1); g_free (info.macro); g_free (info.accel_str); @@ -339,26 +339,6 @@ macro_set_func_text (GtkTreeViewColumn *tree_column, stock_item_info_free (info); } -static void -macro_set_func_pixbuf (GtkTreeViewColumn *tree_column, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - gpointer data) -{ - StockItemInfo *info; - - gtk_tree_model_get (model, iter, - 0, &info, - -1); - - g_object_set (GTK_CELL_RENDERER (cell), - "pixbuf", info->small_icon, - NULL); - - stock_item_info_free (info); -} - static void id_set_func (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, @@ -467,8 +447,8 @@ do_stock_browser (void) gtk_tree_view_column_pack_start (column, cell_renderer, FALSE); - gtk_tree_view_column_set_cell_data_func (column, cell_renderer, - macro_set_func_pixbuf, NULL, NULL); + gtk_tree_view_column_set_attributes (column, cell_renderer, + "stock_id", 1, NULL); cell_renderer = gtk_cell_renderer_text_new (); gtk_tree_view_column_pack_start (column, cell_renderer, @@ -480,7 +460,6 @@ do_stock_browser (void) column); cell_renderer = gtk_cell_renderer_text_new (); - gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (treeview), -1, "Label", @@ -489,6 +468,7 @@ do_stock_browser (void) NULL, NULL); + cell_renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (treeview), -1, "Accel", @@ -497,6 +477,7 @@ do_stock_browser (void) NULL, NULL); + cell_renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (treeview), -1, "ID", diff --git a/gtk/gtkcellrendererpixbuf.c b/gtk/gtkcellrendererpixbuf.c index 45b93aec1..4db396c15 100644 --- a/gtk/gtkcellrendererpixbuf.c +++ b/gtk/gtkcellrendererpixbuf.c @@ -31,6 +31,9 @@ static void gtk_cell_renderer_pixbuf_set_property (GObject * GParamSpec *pspec); static void gtk_cell_renderer_pixbuf_init (GtkCellRendererPixbuf *celltext); static void gtk_cell_renderer_pixbuf_class_init (GtkCellRendererPixbufClass *class); +static void gtk_cell_renderer_pixbuf_finalize (GObject *object); +static void gtk_cell_renderer_pixbuf_create_stock_pixbuf (GtkCellRendererPixbuf *cellpixbuf, + GtkWidget *widget); static void gtk_cell_renderer_pixbuf_get_size (GtkCellRenderer *cell, GtkWidget *widget, GdkRectangle *rectangle, @@ -51,9 +54,14 @@ enum { PROP_ZERO, PROP_PIXBUF, PROP_PIXBUF_EXPANDER_OPEN, - PROP_PIXBUF_EXPANDER_CLOSED + PROP_PIXBUF_EXPANDER_CLOSED, + PROP_STOCK_ID, + PROP_STOCK_SIZE, + PROP_STOCK_DETAIL }; +static gpointer parent_class; + GtkType gtk_cell_renderer_pixbuf_get_type (void) @@ -84,6 +92,7 @@ gtk_cell_renderer_pixbuf_get_type (void) static void gtk_cell_renderer_pixbuf_init (GtkCellRendererPixbuf *cellpixbuf) { + cellpixbuf->stock_size = GTK_ICON_SIZE_MENU; } static void @@ -92,6 +101,10 @@ gtk_cell_renderer_pixbuf_class_init (GtkCellRendererPixbufClass *class) GObjectClass *object_class = G_OBJECT_CLASS (class); GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class); + parent_class = g_type_class_peek_parent (class); + + object_class->finalize = gtk_cell_renderer_pixbuf_finalize; + object_class->get_property = gtk_cell_renderer_pixbuf_get_property; object_class->set_property = gtk_cell_renderer_pixbuf_set_property; @@ -124,6 +137,49 @@ gtk_cell_renderer_pixbuf_class_init (GtkCellRendererPixbufClass *class) GDK_TYPE_PIXBUF, G_PARAM_READABLE | G_PARAM_WRITABLE)); + + g_object_class_install_property (object_class, + PROP_STOCK_ID, + g_param_spec_string ("stock_id", + _("Stock ID"), + _("The stock ID of the stock icon to render"), + NULL, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_STOCK_SIZE, + g_param_spec_enum ("stock_size", + _("Size"), + _("The size of the rendered icon"), + GTK_TYPE_ICON_SIZE, + GTK_ICON_SIZE_MENU, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_STOCK_DETAIL, + g_param_spec_string ("stock_detail", + _("Detail"), + _("Render detail to pass to the theme engine"), + NULL, + G_PARAM_READWRITE)); + +} + +static void +gtk_cell_renderer_pixbuf_finalize (GObject *object) +{ + GtkCellRendererPixbuf *cellpixbuf = GTK_CELL_RENDERER_PIXBUF (object); + + if (cellpixbuf->pixbuf && cellpixbuf->stock_id) + g_object_unref (cellpixbuf->pixbuf); + + if (cellpixbuf->stock_id) + g_free (cellpixbuf->stock_id); + + if (cellpixbuf->stock_detail) + g_free (cellpixbuf->stock_detail); + + (* G_OBJECT_CLASS (parent_class)->finalize) (object); } static void @@ -148,6 +204,15 @@ gtk_cell_renderer_pixbuf_get_property (GObject *object, g_value_set_object (value, cellpixbuf->pixbuf_expander_closed ? G_OBJECT (cellpixbuf->pixbuf_expander_closed) : NULL); break; + case PROP_STOCK_ID: + g_value_set_string (value, cellpixbuf->stock_id); + break; + case PROP_STOCK_SIZE: + g_value_set_enum (value, cellpixbuf->stock_size); + break; + case PROP_STOCK_DETAIL: + g_value_set_string (value, cellpixbuf->stock_detail); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; @@ -190,10 +255,32 @@ gtk_cell_renderer_pixbuf_set_property (GObject *object, g_object_unref (G_OBJECT (cellpixbuf->pixbuf_expander_closed)); cellpixbuf->pixbuf_expander_closed = pixbuf; break; + case PROP_STOCK_ID: + if (cellpixbuf->stock_id) + g_free (cellpixbuf->stock_id); + cellpixbuf->stock_id = g_strdup (g_value_get_string (value)); + g_object_notify (G_OBJECT (object), "stock_id"); + break; + case PROP_STOCK_SIZE: + cellpixbuf->stock_size = g_value_get_enum (value); + g_object_notify (G_OBJECT (object), "stock_size"); + break; + case PROP_STOCK_DETAIL: + if (cellpixbuf->stock_detail) + g_free (cellpixbuf->stock_detail); + cellpixbuf->stock_detail = g_strdup (g_value_get_string (value)); + g_object_notify (G_OBJECT (object), "stock_detail"); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; } + + if (cellpixbuf->pixbuf && cellpixbuf->stock_id) + { + g_object_unref (cellpixbuf->pixbuf); + cellpixbuf->pixbuf = NULL; + } } /** @@ -215,6 +302,19 @@ gtk_cell_renderer_pixbuf_new (void) return GTK_CELL_RENDERER (gtk_type_new (gtk_cell_renderer_pixbuf_get_type ())); } +static void +gtk_cell_renderer_pixbuf_create_stock_pixbuf (GtkCellRendererPixbuf *cellpixbuf, + GtkWidget *widget) +{ + if (cellpixbuf->pixbuf) + g_object_unref (G_OBJECT (cellpixbuf->pixbuf)); + + cellpixbuf->pixbuf = gtk_widget_render_icon (widget, + cellpixbuf->stock_id, + cellpixbuf->stock_size, + cellpixbuf->stock_detail); +} + static void gtk_cell_renderer_pixbuf_get_size (GtkCellRenderer *cell, GtkWidget *widget, @@ -230,6 +330,9 @@ gtk_cell_renderer_pixbuf_get_size (GtkCellRenderer *cell, gint calc_width; gint calc_height; + if (!cellpixbuf->pixbuf && cellpixbuf->stock_id) + gtk_cell_renderer_pixbuf_create_stock_pixbuf (cellpixbuf, widget); + if (cellpixbuf->pixbuf) { pixbuf_width = gdk_pixbuf_get_width (cellpixbuf->pixbuf); @@ -287,6 +390,7 @@ gtk_cell_renderer_pixbuf_render (GtkCellRenderer *cell, GdkPixbuf *pixbuf; GdkRectangle pix_rect; GdkRectangle draw_rect; + gboolean stock_pixbuf = FALSE; pixbuf = cellpixbuf->pixbuf; if (cell->is_expander) @@ -299,14 +403,19 @@ gtk_cell_renderer_pixbuf_render (GtkCellRenderer *cell, pixbuf = cellpixbuf->pixbuf_expander_closed; } - if (!pixbuf) + if (!pixbuf && !cellpixbuf->stock_id) return; + else if (!pixbuf && cellpixbuf->stock_id) + stock_pixbuf = TRUE; gtk_cell_renderer_pixbuf_get_size (cell, widget, cell_area, &pix_rect.x, &pix_rect.y, &pix_rect.width, &pix_rect.height); + + if (stock_pixbuf) + pixbuf = cellpixbuf->pixbuf; pix_rect.x += cell_area->x; pix_rect.y += cell_area->y; diff --git a/gtk/gtkcellrendererpixbuf.h b/gtk/gtkcellrendererpixbuf.h index 433bca50b..d41aae900 100644 --- a/gtk/gtkcellrendererpixbuf.h +++ b/gtk/gtkcellrendererpixbuf.h @@ -41,9 +41,14 @@ struct _GtkCellRendererPixbuf { GtkCellRenderer parent; + /*< private >*/ GdkPixbuf *pixbuf; GdkPixbuf *pixbuf_expander_open; GdkPixbuf *pixbuf_expander_closed; + + gchar *stock_id; + GtkIconSize stock_size; + gchar *stock_detail; }; struct _GtkCellRendererPixbufClass