added new functions gimp_enum_menu_set_stock_prefix() and

2003-03-24  Sven Neumann  <sven@gimp.org>

	* app/widgets/gimpenummenu.[ch]: added new functions
	gimp_enum_menu_set_stock_prefix() and
	gimp_enum_option_menu_set_stock_prefix() that allow to
	conveniently add stock icons to enum menus.

	* app/tools/gimpcurvestool.c
	* app/tools/gimphistogramtool.c
	* app/tools/gimplevelstool.c: use the new functions here.
This commit is contained in:
Sven Neumann
2003-03-24 18:04:11 +00:00
committed by Sven Neumann
parent d48936b95a
commit 7f22c349db
6 changed files with 177 additions and 84 deletions

View File

@ -1,3 +1,14 @@
2003-03-24 Sven Neumann <sven@gimp.org>
* app/widgets/gimpenummenu.[ch]: added new functions
gimp_enum_menu_set_stock_prefix() and
gimp_enum_option_menu_set_stock_prefix() that allow to
conveniently add stock icons to enum menus.
* app/tools/gimpcurvestool.c
* app/tools/gimphistogramtool.c
* app/tools/gimplevelstool.c: use the new functions here.
2003-03-24 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpdock.c (gimp_dock_separator_drag_drop): don't

View File

@ -576,6 +576,7 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
GtkWidget *vbox;
GtkWidget *hbbox;
GtkWidget *frame;
GtkWidget *menu;
GtkWidget *table;
GtkWidget *button;
@ -598,11 +599,15 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
/* The option menu for selecting channels */
hbox = gtk_hbox_new (FALSE, 4);
c_tool->channel_menu = gimp_enum_option_menu_new (GIMP_TYPE_HISTOGRAM_CHANNEL,
G_CALLBACK (curves_channel_callback),
c_tool);
gtk_box_pack_start (GTK_BOX (hbox), c_tool->channel_menu, FALSE, FALSE, 0);
gtk_widget_show (c_tool->channel_menu);
menu = gimp_enum_option_menu_new (GIMP_TYPE_HISTOGRAM_CHANNEL,
G_CALLBACK (curves_channel_callback),
c_tool);
gimp_enum_option_menu_set_stock_prefix (GTK_OPTION_MENU (menu),
"gimp-channel");
gtk_box_pack_start (GTK_BOX (hbox), menu, FALSE, FALSE, 0);
gtk_widget_show (menu);
c_tool->channel_menu = menu;
button = gtk_button_new_with_mnemonic (_("R_eset Channel"));
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);

View File

@ -375,6 +375,8 @@ histogram_tool_dialog_new (GimpToolInfo *tool_info)
htd->channel_menu =
gimp_prop_enum_option_menu_new (G_OBJECT (htd->histogram_box->histogram),
"channel", 0, 0);
gimp_enum_option_menu_set_stock_prefix (GTK_OPTION_MENU (htd->channel_menu),
"gimp-channel");
gtk_box_pack_start (GTK_BOX (hbox), htd->channel_menu, FALSE, FALSE, 0);
gtk_widget_show (htd->channel_menu);

View File

@ -446,6 +446,7 @@ gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool)
GtkWidget *hbox;
GtkWidget *hbox2;
GtkWidget *label;
GtkWidget *menu;
GtkWidget *frame;
GtkWidget *channel_hbox;
GtkWidget *hbbox;
@ -474,13 +475,15 @@ gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool)
gtk_box_pack_start (GTK_BOX (channel_hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
l_tool->channel_menu =
gimp_enum_option_menu_new (GIMP_TYPE_HISTOGRAM_CHANNEL,
G_CALLBACK (levels_channel_callback),
l_tool);
gtk_box_pack_start (GTK_BOX (channel_hbox),
l_tool->channel_menu, FALSE, FALSE, 0);
gtk_widget_show (l_tool->channel_menu);
menu = gimp_enum_option_menu_new (GIMP_TYPE_HISTOGRAM_CHANNEL,
G_CALLBACK (levels_channel_callback),
l_tool);
gimp_enum_option_menu_set_stock_prefix (GTK_OPTION_MENU (menu),
"gimp-channel");
gtk_box_pack_start (GTK_BOX (channel_hbox), menu, FALSE, FALSE, 0);
gtk_widget_show (menu);
l_tool->channel_menu = menu;
button = gtk_button_new_with_mnemonic (_("R_eset Channel"));
gtk_box_pack_start (GTK_BOX (channel_hbox), button, FALSE, FALSE, 0);

View File

@ -158,7 +158,7 @@ gimp_enum_menu_new_with_range (GType enum_type,
if (value->value < minimum || value->value > maximum)
continue;
menu_item = gtk_menu_item_new_with_mnemonic (gettext (value->value_name));
menu_item = gtk_image_menu_item_new_with_mnemonic (gettext (value->value_name));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
gtk_widget_show (menu_item);
@ -223,7 +223,7 @@ gimp_enum_menu_new_with_values_valist (GType enum_type,
if (value)
{
menu_item =
gtk_menu_item_new_with_mnemonic (gettext (value->value_name));
gtk_image_menu_item_new_with_mnemonic (gettext (value->value_name));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
gtk_widget_show (menu_item);
@ -240,6 +240,49 @@ gimp_enum_menu_new_with_values_valist (GType enum_type,
return GTK_WIDGET (menu);
}
/**
* gimp_enum_menu_set_stock_prefix:
* @enum_menu: a #GimpEnumMenu
* @stock_prefix: the prefix of the group of stock ids to use.
*
* Adds stock icons to the items in @enum_menu. The stock_id for each
* icon is created by appending the enum_value's nick to the given
* @stock_prefix. If no such stock_id exists, no icon is displayed.
**/
void
gimp_enum_menu_set_stock_prefix (GimpEnumMenu *enum_menu,
const gchar *stock_prefix)
{
GtkWidget *image;
GEnumValue *enum_value;
GList *list;
gchar *stock_id;
gint value;
g_return_if_fail (GIMP_IS_ENUM_MENU (enum_menu));
g_return_if_fail (stock_prefix != NULL);
for (list = GTK_MENU_SHELL (enum_menu)->children; list; list = list->next)
{
GtkImageMenuItem *item = list->data;
value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item),
"gimp-item-data"));
enum_value = g_enum_get_value (enum_menu->enum_class, value);
if (!enum_value)
continue;
stock_id = g_strconcat (stock_prefix, "-", enum_value->value_nick, NULL);
image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU);
g_free (stock_id);
gtk_image_menu_item_set_image (item, image);
gtk_widget_show (image);
}
}
/**
* gimp_enum_option_menu_new:
* @enum_type: the #GType of an enum.
@ -337,6 +380,29 @@ gimp_enum_option_menu_new_with_values_valist (GType enum_type,
return option_menu;
}
/**
* gimp_enum_option_menu_set_stock_prefix:
* @option_menu: a #GtkOptionMenu created using gtk_enum_option_menu_new().
* @stock_prefix: the prefix of the group of stock ids to use.
*
* A convenience function that calls gimp_enum_menu_set_stock_prefix()
* with the enum menu used by @option_menu.
**/
void
gimp_enum_option_menu_set_stock_prefix (GtkOptionMenu *option_menu,
const gchar *stock_prefix)
{
GtkWidget *enum_menu;
g_return_if_fail (GTK_IS_OPTION_MENU (option_menu));
g_return_if_fail (stock_prefix != NULL);
enum_menu = gtk_option_menu_get_menu (option_menu);
if (enum_menu && GIMP_IS_ENUM_MENU (enum_menu))
gimp_enum_menu_set_stock_prefix (GIMP_ENUM_MENU (enum_menu), stock_prefix);
}
/**
* gimp_enum_radio_box_new:
* @enum_type: the #GType of an enum.

View File

@ -50,83 +50,89 @@ struct _GimpEnumMenu
GType gimp_enum_menu_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_enum_menu_new (GType enum_type,
GCallback callback,
gpointer callback_data);
GtkWidget * gimp_enum_menu_new_with_range (GType enum_type,
gint minimum,
gint maximum,
GCallback callback,
gpointer callback_data);
GtkWidget * gimp_enum_menu_new_with_values (GType enum_type,
GCallback callback,
gpointer callback_data,
gint n_values,
GtkWidget * gimp_enum_menu_new (GType enum_type,
GCallback callback,
gpointer callback_data);
GtkWidget * gimp_enum_menu_new_with_range (GType enum_type,
gint minimum,
gint maximum,
GCallback callback,
gpointer callback_data);
GtkWidget * gimp_enum_menu_new_with_values (GType enum_type,
GCallback callback,
gpointer callback_data,
gint n_values,
...);
GtkWidget * gimp_enum_menu_new_with_values_valist (GType enum_type,
GCallback callback,
gpointer callback_data,
gint n_values,
va_list args);
GtkWidget * gimp_enum_menu_new_with_values_valist (GType enum_type,
GCallback callback,
gpointer callback_data,
gint n_values,
va_list args);
GtkWidget * gimp_enum_option_menu_new (GType enum_type,
GCallback callback,
gpointer callback_data);
GtkWidget * gimp_enum_option_menu_new_with_range (GType enum_type,
gint minimum,
gint maximum,
GCallback callback,
gpointer callback_data);
GtkWidget * gimp_enum_option_menu_new_with_values (GType enum_type,
GCallback callback,
gpointer callback_data,
gint n_values,
void gimp_enum_menu_set_stock_prefix (GimpEnumMenu *enum_menu,
const gchar *stock_prefix);
GtkWidget * gimp_enum_option_menu_new (GType enum_type,
GCallback callback,
gpointer callback_data);
GtkWidget * gimp_enum_option_menu_new_with_range (GType enum_type,
gint minimum,
gint maximum,
GCallback callback,
gpointer callback_data);
GtkWidget * gimp_enum_option_menu_new_with_values (GType enum_type,
GCallback callback,
gpointer callback_data,
gint n_values,
...);
GtkWidget *
gimp_enum_option_menu_new_with_values_valist (GType enum_type,
GCallback callback,
gpointer callback_data,
gint n_values,
va_list args);
gimp_enum_option_menu_new_with_values_valist (GType enum_type,
GCallback callback,
gpointer callback_data,
gint n_values,
va_list args);
GtkWidget * gimp_enum_radio_box_new (GType enum_type,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
GtkWidget * gimp_enum_radio_box_new_with_range (GType enum_type,
gint minimum,
gint maximum,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
void gimp_enum_option_menu_set_stock_prefix (GtkOptionMenu *option_menu,
const gchar *stock_prefix);
GtkWidget * gimp_enum_radio_frame_new (GType enum_type,
GtkWidget *label_widget,
gint border_width,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
GtkWidget * gimp_enum_radio_frame_new_with_range (GType enum_type,
gint minimum,
gint maximum,
GtkWidget *label_widget,
gint border_width,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
GtkWidget * gimp_enum_radio_box_new (GType enum_type,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
GtkWidget * gimp_enum_radio_box_new_with_range (GType enum_type,
gint minimum,
gint maximum,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
GtkWidget * gimp_enum_stock_box_new (GType enum_type,
const gchar *stock_prefix,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
GtkWidget * gimp_enum_stock_box_new_with_range (GType enum_type,
gint minimum,
gint maximum,
const gchar *stock_prefix,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
GtkWidget * gimp_enum_radio_frame_new (GType enum_type,
GtkWidget *label_widget,
gint border_width,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
GtkWidget * gimp_enum_radio_frame_new_with_range (GType enum_type,
gint minimum,
gint maximum,
GtkWidget *label_widget,
gint border_width,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
GtkWidget * gimp_enum_stock_box_new (GType enum_type,
const gchar *stock_prefix,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
GtkWidget * gimp_enum_stock_box_new_with_range (GType enum_type,
gint minimum,
gint maximum,
const gchar *stock_prefix,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
#endif /* __GIMP_ENUM_MENU_H__ */