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.
This commit is contained in:
committed by
Manish Singh
parent
1f39967c57
commit
4961608004
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_radio_group_set_active:
|
||||
* @radio_button: Pointer to a #GtkRadioButton.
|
||||
|
||||
Reference in New Issue
Block a user