Commit 8ea259bb authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

app/widgets/gimpenumstore.[ch] let the pixbuf renderer take care of

2004-04-20  Sven Neumann  <sven@gimp.org>

	* app/widgets/gimpenumstore.[ch]
	* app/widgets/gimpenumcombobox.c: let the pixbuf renderer take care
	of rendering the pixbuf from the stock_id.
parent f80eaff9
2004-04-20 Sven Neumann <sven@gimp.org>
* app/widgets/gimpenumstore.[ch]
* app/widgets/gimpenumcombobox.c: let the pixbuf renderer take care
of rendering the pixbuf from the stock_id.
2004-04-20 Sven Neumann <sven@gimp.org>
* libgimpwidgets/gimpmemsizeentry.c
......
......@@ -112,13 +112,15 @@ gimp_enum_combo_box_new_with_model (GimpEnumStore *enum_store)
"model", enum_store,
NULL);
cell = gtk_cell_renderer_pixbuf_new ();
cell = g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF,
"stock_size", GTK_ICON_SIZE_MENU,
NULL);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
"pixbuf", GIMP_ENUM_STORE_ICON,
"stock_id", GIMP_ENUM_STORE_ICON,
NULL);
cell = gtk_cell_renderer_text_new ();
cell = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, NULL);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
"text", GIMP_ENUM_STORE_LABEL,
......@@ -208,9 +210,7 @@ gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box,
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
gimp_enum_store_set_icons (GIMP_ENUM_STORE (model),
GTK_WIDGET (combo_box),
stock_prefix, GTK_ICON_SIZE_MENU);
gimp_enum_store_set_stock_prefix (GIMP_ENUM_STORE (model), stock_prefix);
}
/**
......
......@@ -89,7 +89,7 @@ gimp_enum_store_init (GimpEnumStore *enum_store)
{
G_TYPE_INT, /* GIMP_ENUM_STORE_VALUE */
G_TYPE_STRING, /* GIMP_ENUM_STORE_LABEL */
GDK_TYPE_PIXBUF, /* GIMP_ENUM_STORE_ICON */
G_TYPE_STRING, /* GIMP_ENUM_STORE_ICON */
G_TYPE_POINTER /* GIMP_ENUM_STORE_USER_DATA */
};
......@@ -299,32 +299,23 @@ gimp_enum_store_lookup_by_value (GtkTreeModel *model,
}
/**
* gimp_enum_store_set_icons:
* gimp_enum_store_set_stock_prefix:
* @store: a #GimpEnumStore
* @widget: the widget used to create the icon pixbufs
* @stock_prefix: a prefix to create icon stock ID from enum values
* @size: the size to create the icons in
*
* Creates a stock ID for each enum value in the @store by appending
* the value's nick to the given @stock_prefix inserting a hyphen
* between them. If an icon is registered for the resulting stock ID,
* it is rendered by @widget (which should be the @combo_box using
* this @store as it's model). The rendered pixbuf is then added to
* the @store in the %GIMP_ENUM_STORE_PIXBUF column.
* between them.
**/
void
gimp_enum_store_set_icons (GimpEnumStore *store,
GtkWidget *widget,
const gchar *stock_prefix,
GtkIconSize size)
gimp_enum_store_set_stock_prefix (GimpEnumStore *store,
const gchar *stock_prefix)
{
GtkTreeModel *model;
GtkTreeIter iter;
gboolean iter_valid;
g_return_if_fail (GIMP_IS_ENUM_STORE (store));
g_return_if_fail (stock_prefix == NULL || GTK_IS_WIDGET (widget));
g_return_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1);
model = GTK_TREE_MODEL (store);
......@@ -332,12 +323,11 @@ gimp_enum_store_set_icons (GimpEnumStore *store,
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, &iter))
{
GdkPixbuf *pixbuf = NULL;
gchar *stock_id = NULL;
if (stock_prefix)
{
GEnumValue *enum_value;
gchar *stock_id;
gint value;
gtk_tree_model_get (model, &iter,
......@@ -349,17 +339,13 @@ gimp_enum_store_set_icons (GimpEnumStore *store,
stock_id = g_strconcat (stock_prefix, "-",
enum_value->value_nick,
NULL);
pixbuf = gtk_widget_render_icon (widget, stock_id, size, NULL);
g_free (stock_id);
}
gtk_list_store_set (GTK_LIST_STORE (store), &iter,
GIMP_ENUM_STORE_ICON, pixbuf,
GIMP_ENUM_STORE_ICON, stock_id,
-1);
if (pixbuf)
g_object_unref (pixbuf);
if (stock_id)
g_free (stock_id);
}
}
......@@ -75,10 +75,8 @@ gboolean gimp_enum_store_lookup_by_value (GtkTreeModel *model,
gint value,
GtkTreeIter *iter);
void gimp_enum_store_set_icons (GimpEnumStore *store,
GtkWidget *widget,
const gchar *stock_prefix,
GtkIconSize size);
void gimp_enum_store_set_stock_prefix (GimpEnumStore *store,
const gchar *stock_prefix);
#endif /* __GIMP_ENUM_STORE_H__ */
......@@ -112,13 +112,15 @@ gimp_enum_combo_box_new_with_model (GimpEnumStore *enum_store)
"model", enum_store,
NULL);
cell = gtk_cell_renderer_pixbuf_new ();
cell = g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF,
"stock_size", GTK_ICON_SIZE_MENU,
NULL);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
"pixbuf", GIMP_ENUM_STORE_ICON,
"stock_id", GIMP_ENUM_STORE_ICON,
NULL);
cell = gtk_cell_renderer_text_new ();
cell = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, NULL);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
"text", GIMP_ENUM_STORE_LABEL,
......@@ -208,9 +210,7 @@ gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box,
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
gimp_enum_store_set_icons (GIMP_ENUM_STORE (model),
GTK_WIDGET (combo_box),
stock_prefix, GTK_ICON_SIZE_MENU);
gimp_enum_store_set_stock_prefix (GIMP_ENUM_STORE (model), stock_prefix);
}
/**
......
......@@ -89,7 +89,7 @@ gimp_enum_store_init (GimpEnumStore *enum_store)
{
G_TYPE_INT, /* GIMP_ENUM_STORE_VALUE */
G_TYPE_STRING, /* GIMP_ENUM_STORE_LABEL */
GDK_TYPE_PIXBUF, /* GIMP_ENUM_STORE_ICON */
G_TYPE_STRING, /* GIMP_ENUM_STORE_ICON */
G_TYPE_POINTER /* GIMP_ENUM_STORE_USER_DATA */
};
......@@ -299,32 +299,23 @@ gimp_enum_store_lookup_by_value (GtkTreeModel *model,
}
/**
* gimp_enum_store_set_icons:
* gimp_enum_store_set_stock_prefix:
* @store: a #GimpEnumStore
* @widget: the widget used to create the icon pixbufs
* @stock_prefix: a prefix to create icon stock ID from enum values
* @size: the size to create the icons in
*
* Creates a stock ID for each enum value in the @store by appending
* the value's nick to the given @stock_prefix inserting a hyphen
* between them. If an icon is registered for the resulting stock ID,
* it is rendered by @widget (which should be the @combo_box using
* this @store as it's model). The rendered pixbuf is then added to
* the @store in the %GIMP_ENUM_STORE_PIXBUF column.
* between them.
**/
void
gimp_enum_store_set_icons (GimpEnumStore *store,
GtkWidget *widget,
const gchar *stock_prefix,
GtkIconSize size)
gimp_enum_store_set_stock_prefix (GimpEnumStore *store,
const gchar *stock_prefix)
{
GtkTreeModel *model;
GtkTreeIter iter;
gboolean iter_valid;
g_return_if_fail (GIMP_IS_ENUM_STORE (store));
g_return_if_fail (stock_prefix == NULL || GTK_IS_WIDGET (widget));
g_return_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1);
model = GTK_TREE_MODEL (store);
......@@ -332,12 +323,11 @@ gimp_enum_store_set_icons (GimpEnumStore *store,
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, &iter))
{
GdkPixbuf *pixbuf = NULL;
gchar *stock_id = NULL;
if (stock_prefix)
{
GEnumValue *enum_value;
gchar *stock_id;
gint value;
gtk_tree_model_get (model, &iter,
......@@ -349,17 +339,13 @@ gimp_enum_store_set_icons (GimpEnumStore *store,
stock_id = g_strconcat (stock_prefix, "-",
enum_value->value_nick,
NULL);
pixbuf = gtk_widget_render_icon (widget, stock_id, size, NULL);
g_free (stock_id);
}
gtk_list_store_set (GTK_LIST_STORE (store), &iter,
GIMP_ENUM_STORE_ICON, pixbuf,
GIMP_ENUM_STORE_ICON, stock_id,
-1);
if (pixbuf)
g_object_unref (pixbuf);
if (stock_id)
g_free (stock_id);
}
}
......@@ -75,10 +75,8 @@ gboolean gimp_enum_store_lookup_by_value (GtkTreeModel *model,
gint value,
GtkTreeIter *iter);
void gimp_enum_store_set_icons (GimpEnumStore *store,
GtkWidget *widget,
const gchar *stock_prefix,
GtkIconSize size);
void gimp_enum_store_set_stock_prefix (GimpEnumStore *store,
const gchar *stock_prefix);
#endif /* __GIMP_ENUM_STORE_H__ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment