Commit 49616080 authored by Manish Singh's avatar Manish Singh Committed by Manish Singh

implementedgimp_int_option_menu_new and gimp_int_radio_group_new, which

2003-11-14  Manish Singh  <yosh@gimp.org>

	* libgimpwidgets/gimpwidgets.[ch]: implementedgimp_int_option_menu_new
	and gimp_int_radio_group_new, which are the same as
	gimp_option_menu_new2 and gimp_radio_group_new2, but they take
	integers as values to map instead of gpointers, which avoids casts
	in pretty much all uses of it in the tree.

	* app/gui/image-commands.c
	* app/gui/offset-dialog.c
	* app/widgets/gimppropwidgets.c
	* app/widgets/gimpwidgets-constructors.c
	* libgimpwidgets/gimpmemsizeentry.c
	* modules/cdisplay_colorblind.c
	* plug-ins/FractalExplorer/Dialogs.c
	* plug-ins/Lighting/lighting_ui.c
	* plug-ins/MapObject/mapobject_ui.c
	* plug-ins/common/AlienMap.c
	* plug-ins/common/AlienMap2.c
	* plug-ins/common/CML_explorer.c
	* plug-ins/common/align_layers.c
	* plug-ins/common/blinds.c
	* plug-ins/common/borderaverage.c
	* plug-ins/common/bumpmap.c
	* plug-ins/common/curve_bend.c
	* plug-ins/common/deinterlace.c
	* plug-ins/common/edge.c
	* plug-ins/common/emboss.c
	* plug-ins/common/fractaltrace.c
	* plug-ins/common/gif.c
	* plug-ins/common/hot.c
	* plug-ins/common/iwarp.c
	* plug-ins/common/jigsaw.c
	* plug-ins/common/jpeg.c
	* plug-ins/common/lic.c
	* plug-ins/common/mail.c
	* plug-ins/common/max_rgb.c
	* plug-ins/common/mblur.c
	* plug-ins/common/mng.c
	* plug-ins/common/mosaic.c
	* plug-ins/common/nlfilt.c
	* plug-ins/common/papertile.c
	* plug-ins/common/pnm.c
	* plug-ins/common/ps.c
	* plug-ins/common/psp.c
	* plug-ins/common/ripple.c
	* plug-ins/common/shift.c
	* plug-ins/common/sinus.c
	* plug-ins/common/sparkle.c
	* plug-ins/common/struc.c
	* plug-ins/common/sunras.c
	* plug-ins/common/tiff.c
	* plug-ins/common/waves.c
	* plug-ins/common/wind.c
	* plug-ins/fits/fits.c
	* plug-ins/flame/flame.c
	* plug-ins/gfig/gfig.c
	* plug-ins/gimpressionist/color.c
	* plug-ins/gimpressionist/orientmap.c
	* plug-ins/gimpressionist/placement.c
	* plug-ins/maze/maze_face.c
	* plug-ins/sgi/sgi.c: Use gimp_int_option_menu_new and
	gimp_int_radio_group_new.

	* plug-ins/common/CML_explorer.c: make function_graph_new take a
	gpointer *data instead of a gpointer data, and properly pass an
	int through it.

	* plug-ins/common/mng.c: mark menu strings for translation.

	* plug-ins/rcm/rcm.c: remove initialization for Success member
	in RcmParams, since it's gone now.
parent 1f39967c
2003-11-14 Manish Singh <yosh@gimp.org>
* libgimpwidgets/gimpwidgets.[ch]: implementedgimp_int_option_menu_new
and gimp_int_radio_group_new, which are the same as
gimp_option_menu_new2 and gimp_radio_group_new2, but they take
integers as values to map instead of gpointers, which avoids casts
in pretty much all uses of it in the tree.
* app/gui/image-commands.c
* app/gui/offset-dialog.c
* app/widgets/gimppropwidgets.c
* app/widgets/gimpwidgets-constructors.c
* libgimpwidgets/gimpmemsizeentry.c
* modules/cdisplay_colorblind.c
* plug-ins/FractalExplorer/Dialogs.c
* plug-ins/Lighting/lighting_ui.c
* plug-ins/MapObject/mapobject_ui.c
* plug-ins/common/AlienMap.c
* plug-ins/common/AlienMap2.c
* plug-ins/common/CML_explorer.c
* plug-ins/common/align_layers.c
* plug-ins/common/blinds.c
* plug-ins/common/borderaverage.c
* plug-ins/common/bumpmap.c
* plug-ins/common/curve_bend.c
* plug-ins/common/deinterlace.c
* plug-ins/common/edge.c
* plug-ins/common/emboss.c
* plug-ins/common/fractaltrace.c
* plug-ins/common/gif.c
* plug-ins/common/hot.c
* plug-ins/common/iwarp.c
* plug-ins/common/jigsaw.c
* plug-ins/common/jpeg.c
* plug-ins/common/lic.c
* plug-ins/common/mail.c
* plug-ins/common/max_rgb.c
* plug-ins/common/mblur.c
* plug-ins/common/mng.c
* plug-ins/common/mosaic.c
* plug-ins/common/nlfilt.c
* plug-ins/common/papertile.c
* plug-ins/common/pnm.c
* plug-ins/common/ps.c
* plug-ins/common/psp.c
* plug-ins/common/ripple.c
* plug-ins/common/shift.c
* plug-ins/common/sinus.c
* plug-ins/common/sparkle.c
* plug-ins/common/struc.c
* plug-ins/common/sunras.c
* plug-ins/common/tiff.c
* plug-ins/common/waves.c
* plug-ins/common/wind.c
* plug-ins/fits/fits.c
* plug-ins/flame/flame.c
* plug-ins/gfig/gfig.c
* plug-ins/gimpressionist/color.c
* plug-ins/gimpressionist/orientmap.c
* plug-ins/gimpressionist/placement.c
* plug-ins/maze/maze_face.c
* plug-ins/sgi/sgi.c: Use gimp_int_option_menu_new and
gimp_int_radio_group_new.
* plug-ins/common/CML_explorer.c: make function_graph_new take a
gpointer *data instead of a gpointer data, and properly pass an
int through it.
* plug-ins/common/mng.c: mark menu strings for translation.
* plug-ins/rcm/rcm.c: remove initialization for Success member
in RcmParams, since it's gone now.
2003-11-14 Sven Neumann <sven@gimp.org>
* app/widgets/gimpitemtreeview.c: introduced utility function
......@@ -408,24 +408,23 @@ image_layers_merge_query (GimpImage *gimage,
vbox);
frame =
gimp_radio_group_new2 (TRUE,
merge_visible ?
_("Final, Merged Layer should be:") :
_("Final, Anchored Layer should be:"),
G_CALLBACK (gimp_radio_button_update),
&options->merge_type,
GINT_TO_POINTER (options->merge_type),
gimp_int_radio_group_new (TRUE,
merge_visible ?
_("Final, Merged Layer should be:") :
_("Final, Anchored Layer should be:"),
G_CALLBACK (gimp_radio_button_update),
&options->merge_type, options->merge_type,
_("Expanded as necessary"),
GINT_TO_POINTER (GIMP_EXPAND_AS_NECESSARY), NULL,
_("Expanded as necessary"),
GIMP_EXPAND_AS_NECESSARY, NULL,
_("Clipped to image"),
GINT_TO_POINTER (GIMP_CLIP_TO_IMAGE), NULL,
_("Clipped to image"),
GIMP_CLIP_TO_IMAGE, NULL,
_("Clipped to bottom layer"),
GINT_TO_POINTER (GIMP_CLIP_TO_BOTTOM_LAYER), NULL,
_("Clipped to bottom layer"),
GIMP_CLIP_TO_BOTTOM_LAYER, NULL,
NULL);
NULL);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
......
......@@ -200,19 +200,17 @@ offset_dialog_create (GimpDrawable *drawable,
/* The fill options */
frame =
gimp_radio_group_new2 (TRUE, _("Fill Type"),
G_CALLBACK (gimp_radio_button_update),
&off_d->fill_type,
GINT_TO_POINTER (off_d->fill_type),
gimp_int_radio_group_new (TRUE, _("Fill Type"),
G_CALLBACK (gimp_radio_button_update),
&off_d->fill_type, off_d->fill_type,
_("_Background"),
GINT_TO_POINTER (GIMP_OFFSET_BACKGROUND), NULL,
_("_Background"),
GIMP_OFFSET_BACKGROUND, NULL,
_("_Transparent"),
GINT_TO_POINTER (GIMP_OFFSET_TRANSPARENT),
&radio_button,
_("_Transparent"),
GIMP_OFFSET_TRANSPARENT, &radio_button,
NULL);
NULL);
if (! gimp_drawable_has_alpha (drawable))
gtk_widget_set_sensitive (radio_button, FALSE);
......
......@@ -408,24 +408,23 @@ image_layers_merge_query (GimpImage *gimage,
vbox);
frame =
gimp_radio_group_new2 (TRUE,
merge_visible ?
_("Final, Merged Layer should be:") :
_("Final, Anchored Layer should be:"),
G_CALLBACK (gimp_radio_button_update),
&options->merge_type,
GINT_TO_POINTER (options->merge_type),
gimp_int_radio_group_new (TRUE,
merge_visible ?
_("Final, Merged Layer should be:") :
_("Final, Anchored Layer should be:"),
G_CALLBACK (gimp_radio_button_update),
&options->merge_type, options->merge_type,
_("Expanded as necessary"),
GINT_TO_POINTER (GIMP_EXPAND_AS_NECESSARY), NULL,
_("Expanded as necessary"),
GIMP_EXPAND_AS_NECESSARY, NULL,
_("Clipped to image"),
GINT_TO_POINTER (GIMP_CLIP_TO_IMAGE), NULL,
_("Clipped to image"),
GIMP_CLIP_TO_IMAGE, NULL,
_("Clipped to bottom layer"),
GINT_TO_POINTER (GIMP_CLIP_TO_BOTTOM_LAYER), NULL,
_("Clipped to bottom layer"),
GIMP_CLIP_TO_BOTTOM_LAYER, NULL,
NULL);
NULL);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
......
......@@ -200,19 +200,17 @@ offset_dialog_create (GimpDrawable *drawable,
/* The fill options */
frame =
gimp_radio_group_new2 (TRUE, _("Fill Type"),
G_CALLBACK (gimp_radio_button_update),
&off_d->fill_type,
GINT_TO_POINTER (off_d->fill_type),
gimp_int_radio_group_new (TRUE, _("Fill Type"),
G_CALLBACK (gimp_radio_button_update),
&off_d->fill_type, off_d->fill_type,
_("_Background"),
GINT_TO_POINTER (GIMP_OFFSET_BACKGROUND), NULL,
_("_Background"),
GIMP_OFFSET_BACKGROUND, NULL,
_("_Transparent"),
GINT_TO_POINTER (GIMP_OFFSET_TRANSPARENT),
&radio_button,
_("_Transparent"),
GIMP_OFFSET_TRANSPARENT, &radio_button,
NULL);
NULL);
if (! gimp_drawable_has_alpha (drawable))
gtk_widget_set_sensitive (radio_button, FALSE);
......
......@@ -312,15 +312,15 @@ gimp_prop_boolean_option_menu_new (GObject *config,
property_name, &value,
NULL);
menu = gimp_option_menu_new2 (FALSE,
G_CALLBACK (gimp_prop_option_menu_callback),
config,
GINT_TO_POINTER (value),
menu =
gimp_int_option_menu_new (FALSE,
G_CALLBACK (gimp_prop_option_menu_callback),
config, value,
true_text, GINT_TO_POINTER (TRUE), NULL,
false_text, GINT_TO_POINTER (FALSE), NULL,
true_text, TRUE, NULL,
false_text, FALSE, NULL,
NULL);
NULL);
set_param_spec (G_OBJECT (menu), menu, param_spec);
......@@ -540,15 +540,15 @@ gimp_prop_boolean_radio_frame_new (GObject *config,
property_name, &value,
NULL);
frame = gimp_radio_group_new2 (TRUE, title,
G_CALLBACK (gimp_prop_radio_button_callback),
config,
GINT_TO_POINTER (value),
frame =
gimp_int_radio_group_new (TRUE, title,
G_CALLBACK (gimp_prop_radio_button_callback),
config, value,
false_text, GINT_TO_POINTER (FALSE), &button,
true_text, GINT_TO_POINTER (TRUE), NULL,
false_text, FALSE, &button,
true_text, TRUE, NULL,
NULL);
NULL);
set_param_spec (G_OBJECT (GTK_BIN (frame)->child), NULL, param_spec);
......
......@@ -39,69 +39,69 @@ gimp_paint_mode_menu_new (GtkSignalFunc callback,
if (with_behind_mode)
{
menu = gimp_option_menu_new2
(FALSE, callback, data, (gpointer) initial,
menu = gimp_int_option_menu_new
(FALSE, callback, data, initial,
_("Normal"), (gpointer) GIMP_NORMAL_MODE, NULL,
_("Dissolve"), (gpointer) GIMP_DISSOLVE_MODE, NULL,
_("Behind"), (gpointer) GIMP_BEHIND_MODE, NULL,
_("Color Erase"), (gpointer) GIMP_COLOR_ERASE_MODE, NULL,
"---", (gpointer) NULL, NULL,
_("Multiply"), (gpointer) GIMP_MULTIPLY_MODE, NULL,
_("Divide"), (gpointer) GIMP_DIVIDE_MODE, NULL,
_("Screen"), (gpointer) GIMP_SCREEN_MODE, NULL,
_("Overlay"), (gpointer) GIMP_OVERLAY_MODE, NULL,
"---", (gpointer) NULL, NULL,
_("Dodge"), (gpointer) GIMP_DODGE_MODE, NULL,
_("Burn"), (gpointer) GIMP_BURN_MODE, NULL,
_("Hard Light"), (gpointer) GIMP_HARDLIGHT_MODE, NULL,
_("Soft Light"), (gpointer) GIMP_SOFTLIGHT_MODE, NULL,
_("Grain Extract"), (gpointer) GIMP_GRAIN_EXTRACT_MODE, NULL,
_("Grain Merge"), (gpointer) GIMP_GRAIN_MERGE_MODE, NULL,
"---", (gpointer) NULL, NULL,
_("Difference"), (gpointer) GIMP_DIFFERENCE_MODE, NULL,
_("Addition"), (gpointer) GIMP_ADDITION_MODE, NULL,
_("Subtract"), (gpointer) GIMP_SUBTRACT_MODE, NULL,
_("Darken Only"), (gpointer) GIMP_DARKEN_ONLY_MODE, NULL,
_("Lighten Only"), (gpointer) GIMP_LIGHTEN_ONLY_MODE, NULL,
"---", (gpointer) NULL, NULL,
_("Hue"), (gpointer) GIMP_HUE_MODE, NULL,
_("Saturation"), (gpointer) GIMP_SATURATION_MODE, NULL,
_("Color"), (gpointer) GIMP_COLOR_MODE, NULL,
_("Value"), (gpointer) GIMP_VALUE_MODE, NULL,
_("Normal"), GIMP_NORMAL_MODE, NULL,
_("Dissolve"), GIMP_DISSOLVE_MODE, NULL,
_("Behind"), GIMP_BEHIND_MODE, NULL,
_("Color Erase"), GIMP_COLOR_ERASE_MODE, NULL,
"---", 0, NULL,
_("Multiply"), GIMP_MULTIPLY_MODE, NULL,
_("Divide"), GIMP_DIVIDE_MODE, NULL,
_("Screen"), GIMP_SCREEN_MODE, NULL,
_("Overlay"), GIMP_OVERLAY_MODE, NULL,
"---", 0, NULL,
_("Dodge"), GIMP_DODGE_MODE, NULL,
_("Burn"), GIMP_BURN_MODE, NULL,
_("Hard Light"), GIMP_HARDLIGHT_MODE, NULL,
_("Soft Light"), GIMP_SOFTLIGHT_MODE, NULL,
_("Grain Extract"), GIMP_GRAIN_EXTRACT_MODE, NULL,
_("Grain Merge"), GIMP_GRAIN_MERGE_MODE, NULL,
"---", 0, NULL,
_("Difference"), GIMP_DIFFERENCE_MODE, NULL,
_("Addition"), GIMP_ADDITION_MODE, NULL,
_("Subtract"), GIMP_SUBTRACT_MODE, NULL,
_("Darken Only"), GIMP_DARKEN_ONLY_MODE, NULL,
_("Lighten Only"), GIMP_LIGHTEN_ONLY_MODE, NULL,
"---", 0, NULL,
_("Hue"), GIMP_HUE_MODE, NULL,
_("Saturation"), GIMP_SATURATION_MODE, NULL,
_("Color"), GIMP_COLOR_MODE, NULL,
_("Value"), GIMP_VALUE_MODE, NULL,
NULL);
}
else
{
menu = gimp_option_menu_new2
(FALSE, callback, data, (gpointer) initial,
menu = gimp_int_option_menu_new
(FALSE, callback, data, initial,
_("Normal"), (gpointer) GIMP_NORMAL_MODE, NULL,
_("Dissolve"), (gpointer) GIMP_DISSOLVE_MODE, NULL,
"---", (gpointer) NULL, NULL,
_("Multiply"), (gpointer) GIMP_MULTIPLY_MODE, NULL,
_("Divide"), (gpointer) GIMP_DIVIDE_MODE, NULL,
_("Screen"), (gpointer) GIMP_SCREEN_MODE, NULL,
_("Overlay"), (gpointer) GIMP_OVERLAY_MODE, NULL,
"---", (gpointer) NULL, NULL,
_("Dodge"), (gpointer) GIMP_DODGE_MODE, NULL,
_("Burn"), (gpointer) GIMP_BURN_MODE, NULL,
_("Hard Light"), (gpointer) GIMP_HARDLIGHT_MODE, NULL,
_("Soft Light"), (gpointer) GIMP_SOFTLIGHT_MODE, NULL,
_("Grain Extract"), (gpointer) GIMP_GRAIN_EXTRACT_MODE, NULL,
_("Grain Merge"), (gpointer) GIMP_GRAIN_MERGE_MODE, NULL,
"---", (gpointer) NULL, NULL,
_("Difference"), (gpointer) GIMP_DIFFERENCE_MODE, NULL,
_("Addition"), (gpointer) GIMP_ADDITION_MODE, NULL,
_("Subtract"), (gpointer) GIMP_SUBTRACT_MODE, NULL,
_("Darken Only"), (gpointer) GIMP_DARKEN_ONLY_MODE, NULL,
_("Lighten Only"), (gpointer) GIMP_LIGHTEN_ONLY_MODE, NULL,
"---", (gpointer) NULL, NULL,
_("Hue"), (gpointer) GIMP_HUE_MODE, NULL,
_("Saturation"), (gpointer) GIMP_SATURATION_MODE, NULL,
_("Color"), (gpointer) GIMP_COLOR_MODE, NULL,
_("Value"), (gpointer) GIMP_VALUE_MODE, NULL,
_("Normal"), GIMP_NORMAL_MODE, NULL,
_("Dissolve"), GIMP_DISSOLVE_MODE, NULL,
"---", 0, NULL,
_("Multiply"), GIMP_MULTIPLY_MODE, NULL,
_("Divide"), GIMP_DIVIDE_MODE, NULL,
_("Screen"), GIMP_SCREEN_MODE, NULL,
_("Overlay"), GIMP_OVERLAY_MODE, NULL,
"---", 0, NULL,
_("Dodge"), GIMP_DODGE_MODE, NULL,
_("Burn"), GIMP_BURN_MODE, NULL,
_("Hard Light"), GIMP_HARDLIGHT_MODE, NULL,
_("Soft Light"), GIMP_SOFTLIGHT_MODE, NULL,
_("Grain Extract"), GIMP_GRAIN_EXTRACT_MODE, NULL,
_("Grain Merge"), GIMP_GRAIN_MERGE_MODE, NULL,
"---", 0, NULL,
_("Difference"), GIMP_DIFFERENCE_MODE, NULL,
_("Addition"), GIMP_ADDITION_MODE, NULL,
_("Subtract"), GIMP_SUBTRACT_MODE, NULL,
_("Darken Only"), GIMP_DARKEN_ONLY_MODE, NULL,
_("Lighten Only"), GIMP_LIGHTEN_ONLY_MODE, NULL,
"---", 0, NULL,
_("Hue"), GIMP_HUE_MODE, NULL,
_("Saturation"), GIMP_SATURATION_MODE, NULL,
_("Color"), GIMP_COLOR_MODE, NULL,
_("Value"), GIMP_VALUE_MODE, NULL,
NULL);
}
......
......@@ -212,14 +212,13 @@ gimp_memsize_entry_new (guint64 value,
entry);
entry->menu =
gimp_option_menu_new2 (FALSE,
G_CALLBACK (gimp_memsize_entry_unit_callback),
entry,
GUINT_TO_POINTER (shift),
_("KiloBytes"), GUINT_TO_POINTER (10), NULL,
_("MegaBytes"), GUINT_TO_POINTER (20), NULL,
_("GigaBytes"), GUINT_TO_POINTER (30), NULL,
NULL);
gimp_int_option_menu_new (FALSE,
G_CALLBACK (gimp_memsize_entry_unit_callback),
entry, shift,
_("KiloBytes"), 10, NULL,
_("MegaBytes"), 20, NULL,
_("GigaBytes"), 30, NULL,
NULL);
gtk_box_pack_start (GTK_BOX (entry), entry->menu, FALSE, FALSE, 0);
gtk_widget_show (entry->menu);
......
......@@ -312,15 +312,15 @@ gimp_prop_boolean_option_menu_new (GObject *config,
property_name, &value,
NULL);
menu = gimp_option_menu_new2 (FALSE,
G_CALLBACK (gimp_prop_option_menu_callback),
config,
GINT_TO_POINTER (value),
menu =
gimp_int_option_menu_new (FALSE,
G_CALLBACK (gimp_prop_option_menu_callback),
config, value,
true_text, GINT_TO_POINTER (TRUE), NULL,
false_text, GINT_TO_POINTER (FALSE), NULL,
true_text, TRUE, NULL,
false_text, FALSE, NULL,
NULL);
NULL);
set_param_spec (G_OBJECT (menu), menu, param_spec);
......@@ -540,15 +540,15 @@ gimp_prop_boolean_radio_frame_new (GObject *config,
property_name, &value,
NULL);
frame = gimp_radio_group_new2 (TRUE, title,
G_CALLBACK (gimp_prop_radio_button_callback),
config,
GINT_TO_POINTER (value),
frame =
gimp_int_radio_group_new (TRUE, title,
G_CALLBACK (gimp_prop_radio_button_callback),
config, value,
false_text, GINT_TO_POINTER (FALSE), &button,
true_text, GINT_TO_POINTER (TRUE), NULL,
false_text, FALSE, &button,
true_text, TRUE, NULL,
NULL);
NULL);
set_param_spec (G_OBJECT (GTK_BIN (frame)->child), NULL, param_spec);
......
......@@ -263,6 +263,120 @@ gimp_option_menu_new2 (gboolean menu_only,
return menu;
}
/**
* gimp_int_option_menu_new:
* @menu_only: %TRUE if the function should return a #GtkMenu only.
* @menu_item_callback: The callback each menu item's "activate" signal will
* be connected with.
* @menu_item_callback_data:
* The data which will be passed to g_signal_connect().
* @initial: The @item_data of the initially selected menu item.
* @...: A %NULL-terminated @va_list describing the menu items.
*
* Convenience function to create a #GtkOptionMenu or a #GtkMenu. This
* function does the same thing as gimp_option_menu_new2(), but it takes
* integers as @item_data instead of pointers, since that is a very
* common case (mapping an enum to a menu).
*
* Returns: A #GtkOptionMenu or a #GtkMenu (depending on @menu_only).
**/
GtkWidget *
gimp_int_option_menu_new (gboolean menu_only,
GCallback menu_item_callback,
gpointer callback_data,
gint initial, /* item_data */
/* specify menu items as va_list:
* const gchar *label,
* gint item_data,
* GtkWidget **widget_ptr,
*/
...)
{
GtkWidget *menu;
GtkWidget *menuitem;
/* menu item variables */
const gchar *label;
gint item_data;
gpointer item_ptr;
GtkWidget **widget_ptr;
va_list args;
gint i;
gint initial_index;
menu = gtk_menu_new ();
/* create the menu items */
initial_index = 0;
va_start (args, initial);
label = va_arg (args, const gchar *);
for (i = 0; label; i++)
{
item_data = va_arg (args, gint);
widget_ptr = va_arg (args, GtkWidget **);
item_ptr = GINT_TO_POINTER (item_data);
if (strcmp (label, "---"))
{
menuitem = gtk_menu_item_new_with_label (label);
g_signal_connect (menuitem, "activate",
menu_item_callback,
callback_data);
if (item_data)
{
g_object_set_data (G_OBJECT (menuitem), "gimp-item-data",
item_ptr);
/* backward compat */
g_object_set_data (G_OBJECT (menuitem), "user_data", item_ptr);
}
}
else
{
menuitem = gtk_menu_item_new ();
gtk_widget_set_sensitive (menuitem, FALSE);
}
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
if (widget_ptr)
*widget_ptr = menuitem;
gtk_widget_show (menuitem);
/* remember the initial menu item */
if (item_data == initial)
initial_index = i;
label = va_arg (args, const gchar *);
}
va_end (args);
if (! menu_only)
{
GtkWidget *optionmenu;
optionmenu = gtk_option_menu_new ();
gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), menu);
/* select the initial menu item */
gtk_option_menu_set_history (GTK_OPTION_MENU (optionmenu), initial_index);
return optionmenu;
}
return menu;
}
/**
* gimp_option_menu_set_history:
* @option_menu: A #GtkOptionMenu as returned by gimp_option_menu_new() or
......@@ -553,6 +667,118 @@ gimp_radio_group_new2 (gboolean in_frame,
return vbox;
}
/**
* gimp_int_radio_group_new:
* @in_frame: %TRUE if you want a #GtkFrame around the
* radio button group.
* @frame_title: The title of the Frame or %NULL if you don't want
* a title.
* @radio_button_callback: The callback each button's "toggled" signal will
* be connected with.
* @radio_button_callback_data:
* The data which will be passed to g_signal_connect().
* @initial: The @item_data of the initially pressed radio button.
* @...: A %NULL-terminated @va_list describing
* the radio buttons.
*
* Convenience function to create a group of radio buttons embedded into
* a #GtkFrame or #GtkVbox. This function does the same thing as
* gimp_radio_group_new2(), but it takes integers as @item_data instead of
* pointers, since that is a very common case (mapping an enum to a radio
* group).
*
* Returns: A #GtkFrame or #GtkVbox (depending on @in_frame).
**/
GtkWidget *
gimp_int_radio_group_new (gboolean in_frame,
const gchar *frame_title,
GCallback radio_button_callback,
gpointer callback_data,
gint initial, /* item_data */
/* specify radio buttons as va_list:
* const gchar *label,
* gint item_data,
* GtkWidget **widget_ptr,
*/
...)
{
GtkWidget *vbox;
GtkWidget *button;
GSList *group;
/* radio button variables */
const gchar *label;
gint item_data;
gpointer item_ptr;
GtkWidget **widget_ptr;
va_list args;
vbox = gtk_vbox_new (FALSE, 1);
group = NULL;
/* create the radio buttons */
va_start (args, initial);
label = va_arg (args, const gchar *);
while (label)
{
item_data = va_arg (args, gint);
widget_ptr = va_arg (args, GtkWidget **);
item_ptr = GINT_TO_POINTER (item_data);
if (label != GINT_TO_POINTER (1))
button = gtk_radio_button_new_with_mnemonic (group, label);
else
button = gtk_radio_button_new (group);
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
if (item_data)
{
g_object_set_data (G_OBJECT (button), "gimp-item-data", item_ptr);
/* backward compatibility */
g_object_set_data (G_OBJECT (button), "user_data", item_ptr);
}
if (widget_ptr)
*widget_ptr = button;
if (initial == item_data)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
g_signal_connect (button, "toggled",
radio_button_callback,
callback_data);
gtk_widget_show (button);
label = va_arg (args, const gchar *);
}
va_end (args);
if (in_frame)
{
GtkWidget *frame;
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
frame = gtk_frame_new (frame_title);
gtk_container_add (GTK_CONTAINER (frame), vbox);
gtk_widget_show (vbox);
return frame;
}
return vbox;
}