Commit 8339ba7f authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

added more sanity checks.

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

	* app/widgets/gimpenumcombobox.c: added more sanity checks.

	* libgimpwidgets/gimpintcombobox.[ch]: added another GimpIntComboBox
	constructor: gimp_int_combo_box_new_array().

	* plug-ins/Lighting/lighting_ui.c
	* plug-ins/MapObject/mapobject_ui.c
	* plug-ins/common/CML_explorer.c: ported to GimpIntComboBox.
parent 9f3c7944
2004-04-20 Sven Neumann <sven@gimp.org>
* app/widgets/gimpenumcombobox.c: added more sanity checks.
* libgimpwidgets/gimpintcombobox.[ch]: added another GimpIntComboBox
constructor: gimp_int_combo_box_new_array().
* plug-ins/Lighting/lighting_ui.c
* plug-ins/MapObject/mapobject_ui.c
* plug-ins/common/CML_explorer.c: ported to GimpIntComboBox.
2004-04-20 Sven Neumann <sven@gimp.org>
* libgimpwidgets/Makefile.am
......
......@@ -176,6 +176,7 @@ gimp_enum_combo_box_get_active (GimpEnumComboBox *combo_box,
GtkTreeIter iter;
g_return_val_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo_box), &iter))
{
......@@ -242,6 +243,7 @@ gimp_enum_combo_box_set_visible (GimpEnumComboBox *combo_box,
GtkTreeModelFilter *filter;
g_return_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box));
g_return_if_fail (func != NULL);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
......
......@@ -166,6 +166,7 @@ GIMP_PIXMAP_GET_CLASS
GimpIntComboBox
gimp_int_combo_box_new
gimp_int_combo_box_new_valist
gimp_int_combo_box_new_array
gimp_int_combo_box_set_active
gimp_int_combo_box_get_active
<SUBSECTION Standard>
......
......@@ -9,19 +9,16 @@ GimpIntComboBox
</para>
<!-- ##### SECTION See_Also ##### -->
<para>
</para>
<!-- ##### STRUCT GimpIntComboBox ##### -->
<para>
</para>
@parent_instance:
<!-- ##### FUNCTION gimp_int_combo_box_new ##### -->
<para>
......@@ -45,6 +42,16 @@ GimpIntComboBox
@Returns:
<!-- ##### FUNCTION gimp_int_combo_box_new_array ##### -->
<para>
</para>
@n_values:
@labels:
@Returns:
<!-- ##### FUNCTION gimp_int_combo_box_set_active ##### -->
<para>
......
......@@ -176,6 +176,7 @@ gimp_enum_combo_box_get_active (GimpEnumComboBox *combo_box,
GtkTreeIter iter;
g_return_val_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo_box), &iter))
{
......@@ -242,6 +243,7 @@ gimp_enum_combo_box_set_visible (GimpEnumComboBox *combo_box,
GtkTreeModelFilter *filter;
g_return_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box));
g_return_if_fail (func != NULL);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
......
......@@ -21,6 +21,8 @@
#include "config.h"
#include <libintl.h>
#include <gtk/gtk.h>
#include "gimpwidgetstypes.h"
......@@ -94,11 +96,11 @@ gimp_int_combo_box_init (GimpIntComboBox *combo_box)
*
* Creates a GtkComboBox that has integer values associated with each
* item. The items to fill the combo box with are specified as a %NULL
* terminated list of label, value pairs.
* terminated list of label/value pairs.
*
* Return value: a new #GimpIntComboBox.
*
* Since: 2.2
* Since: GIMP 2.2
**/
GtkWidget *
gimp_int_combo_box_new (const gchar *first_label,
......@@ -108,6 +110,8 @@ gimp_int_combo_box_new (const gchar *first_label,
GtkWidget *combo_box;
va_list args;
g_return_val_if_fail (first_label != NULL, NULL);
va_start (args, first_value);
combo_box = gimp_int_combo_box_new_valist (first_label, first_value, args);
......@@ -123,12 +127,12 @@ gimp_int_combo_box_new (const gchar *first_label,
* @first_value: the value of the first item
* @values: a va_list with more values
*
* A variant of gimp_int_combo_box_new() that takes a va_list. Useful
* for language bindings.
* A variant of gimp_int_combo_box_new() that takes a va_list of
* label/value pairs. Probably only useful for language bindings.
*
* Return value: a new #GimpIntComboBox.
*
* Since: 2.2
* Since: GIMP 2.2
**/
GtkWidget *
gimp_int_combo_box_new_valist (const gchar *first_label,
......@@ -140,6 +144,8 @@ gimp_int_combo_box_new_valist (const gchar *first_label,
const gchar *label;
gint value;
g_return_val_if_fail (first_label != NULL, NULL);
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)));
......@@ -160,6 +166,50 @@ gimp_int_combo_box_new_valist (const gchar *first_label,
return combo_box;
}
/**
* gimp_int_combo_box_new_array:
* @n_values: the number of values
* @labels: an array of labels (array length must be @n_values)
*
* A variant of gimp_int_combo_box_new() that takes an array of labels.
* The array indices are used as values.
*
* Return value: a new #GimpIntComboBox.
*
* Since: GIMP 2.2
**/
GtkWidget *
gimp_int_combo_box_new_array (gint n_values,
const gchar *labels[])
{
GtkWidget *combo_box;
GtkListStore *store;
gint i;
g_return_val_if_fail (n_values > 0, NULL);
g_return_val_if_fail (labels != NULL, NULL);
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)));
for (i = 0; i < n_values; i++)
{
GtkTreeIter iter;
if (labels[i])
{
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, i,
GIMP_INT_STORE_LABEL, gettext (labels[i]),
-1);
}
}
return combo_box;
}
/**
* gimp_int_combo_box_set_active:
* @combo_box: a #GimpIntComboBox
......@@ -171,7 +221,7 @@ gimp_int_combo_box_new_valist (const gchar *first_label,
* Return value: %TRUE on success or %FALSE if there was no item for
* this value.
*
* Since: 2.2
* Since: GIMP 2.2
**/
gboolean
gimp_int_combo_box_set_active (GimpIntComboBox *combo_box,
......@@ -217,7 +267,7 @@ gimp_int_combo_box_set_active (GimpIntComboBox *combo_box,
* Return value: %TRUE if @value has been set or %FALSE if no item was
* active.
*
* Since: 2.2
* Since: GIMP 2.2
**/
gboolean
gimp_int_combo_box_get_active (GimpIntComboBox *combo_box,
......@@ -226,6 +276,7 @@ gimp_int_combo_box_get_active (GimpIntComboBox *combo_box,
GtkTreeIter iter;
g_return_val_if_fail (GIMP_IS_INT_COMBO_BOX (combo_box), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo_box), &iter))
{
......
......@@ -54,6 +54,8 @@ GtkWidget * gimp_int_combo_box_new (const gchar *first_label,
GtkWidget * gimp_int_combo_box_new_valist (const gchar *first_label,
gint first_value,
va_list values);
GtkWidget * gimp_int_combo_box_new_array (gint n_values,
const gchar *labels[]);
gboolean gimp_int_combo_box_set_active (GimpIntComboBox *combo_box,
gint value);
......
......@@ -197,7 +197,7 @@ static void
lightmenu_callback (GtkWidget *widget,
gpointer data)
{
gimp_menu_item_update (widget, data);
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), (gint *) data);
if (mapvals.lightsource.type == POINT_LIGHT)
{
......@@ -223,7 +223,7 @@ static void
mapmenu2_callback (GtkWidget *widget,
gpointer data)
{
gimp_menu_item_update (widget, data);
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), (gint *) data);
draw_preview_image (TRUE);
}
......@@ -321,9 +321,6 @@ create_options_page (void)
GtkWidget *frame;
GtkWidget *vbox;
GtkWidget *toggle;
GtkWidget *table;
/*GtkWidget *spinbutton;*/
GtkObject *adj;
page = gtk_vbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (page), 4);
......@@ -338,6 +335,7 @@ create_options_page (void)
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_container_add (GTK_CONTAINER (frame), vbox);
gtk_widget_show (vbox);
/*
toggle = gtk_check_button_new_with_label (_("Use Bump Mapping"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
......@@ -480,7 +478,7 @@ create_light_page (void)
GtkWidget *page;
GtkWidget *frame;
GtkWidget *table;
GtkWidget *optionmenu;
GtkWidget *combo;
GtkWidget *colorbutton;
GtkObject *adj;
......@@ -498,23 +496,22 @@ create_light_page (void)
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_widget_show (table);
optionmenu =
gimp_int_option_menu_new (FALSE,
G_CALLBACK (lightmenu_callback),
&mapvals.lightsource.type,
mapvals.lightsource.type,
combo = gimp_int_combo_box_new (_("None"), NO_LIGHT,
_("Directional"), DIRECTIONAL_LIGHT,
_("Point"), POINT_LIGHT,
/* _("Spot"), SPOT_LIGHT, */
NULL);
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo),
mapvals.lightsource.type);
_("None"), NO_LIGHT, NULL,
_("Directional"), DIRECTIONAL_LIGHT, NULL,
_("Point"), POINT_LIGHT, NULL,
/* _("Spot"), SPOT_LIGHT, NULL, */
g_signal_connect (combo, "changed",
G_CALLBACK (lightmenu_callback),
&mapvals.lightsource.type);
NULL);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("L_ight Type:"), 1.0, 0.5,
optionmenu, 1, TRUE);
_("L_ight Type:"), 1.0, 0.5, combo, 1, TRUE);
gimp_help_set_help_data (optionmenu, _("Type of light source to apply"), NULL);
gimp_help_set_help_data (combo, _("Type of light source to apply"), NULL);
colorbutton = gimp_color_button_new (_("Select Lightsource Color"),
64, 16,
......@@ -875,6 +872,7 @@ create_bump_page (void)
GtkWidget *toggle;
GtkWidget *frame;
GtkWidget *table;
GtkWidget *combo;
GtkWidget *optionmenu;
GtkWidget *menu;
GtkWidget *spinbutton;
......@@ -922,18 +920,20 @@ create_bump_page (void)
_("Bumpm_ap Image:"), 1.0, 0.5,
optionmenu, 1, TRUE);
optionmenu =
gimp_int_option_menu_new (FALSE,
G_CALLBACK (mapmenu2_callback),
&mapvals.bumpmaptype, mapvals.bumpmaptype,
_("Linear"), LINEAR_MAP, NULL,
_("Logarithmic"), LOGARITHMIC_MAP, NULL,
_("Sinusoidal"), SINUSOIDAL_MAP, NULL,
_("Spherical"), SPHERICAL_MAP, NULL,
NULL);
combo = gimp_int_combo_box_new (_("Linear"), LINEAR_MAP,
_("Logarithmic"), LOGARITHMIC_MAP,
_("Sinusoidal"), SINUSOIDAL_MAP,
_("Spherical"), SPHERICAL_MAP,
NULL);
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo),
mapvals.bumpmaptype);
g_signal_connect (combo, "changed",
G_CALLBACK (mapmenu2_callback),
&mapvals.bumpmaptype);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
_("Cu_rve:"), 1.0, 0.5,
optionmenu, 1, TRUE);
_("Cu_rve:"), 1.0, 0.5, combo, 1, TRUE);
spinbutton = gimp_spin_button_new (&adj, mapvals.bumpmax,
0, G_MAXFLOAT, 0.01, 0.1, 1.0, 0.0, 2);
......
......@@ -190,7 +190,7 @@ static void
lightmenu_callback (GtkWidget *widget,
gpointer data)
{
gimp_menu_item_update (widget, data);
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), (gint *) data);
if (mapvals.lightsource.type == POINT_LIGHT)
{
......@@ -217,7 +217,7 @@ static void
mapmenu_callback (GtkWidget *widget,
gpointer data)
{
gimp_menu_item_update (widget, data);
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), (gint *) data);
draw_preview_image (TRUE);
......@@ -518,7 +518,7 @@ create_options_page (void)
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *label;
GtkWidget *optionmenu;
GtkWidget *combo;
GtkWidget *toggle;
GtkWidget *table;
GtkWidget *spinbutton;
......@@ -546,21 +546,21 @@ create_options_page (void)
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
optionmenu =
gimp_int_option_menu_new (FALSE,
G_CALLBACK (mapmenu_callback),
&mapvals.maptype, mapvals.maptype,
combo = gimp_int_combo_box_new (_("Plane"), MAP_PLANE,
_("Sphere"), MAP_SPHERE,
_("Box"), MAP_BOX,
_("Cylinder"), MAP_CYLINDER,
NULL);
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo), mapvals.maptype);
_("Plane"), MAP_PLANE, NULL,
_("Sphere"), MAP_SPHERE, NULL,
_("Box"), MAP_BOX, NULL,
_("Cylinder"), MAP_CYLINDER, NULL,
g_signal_connect (combo, "changed",
G_CALLBACK (mapmenu_callback),
&mapvals.maptype);
NULL);
gtk_box_pack_start (GTK_BOX (hbox), optionmenu, FALSE, FALSE, 0);
gtk_widget_show (optionmenu);
gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0);
gtk_widget_show (combo);
gimp_help_set_help_data (optionmenu, _("Type of object to map to"), NULL);
gimp_help_set_help_data (combo, _("Type of object to map to"), NULL);
toggle = gtk_check_button_new_with_label (_("Transparent Background"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
......@@ -671,7 +671,7 @@ create_light_page (void)
GtkWidget *page;
GtkWidget *frame;
GtkWidget *table;
GtkWidget *optionmenu;
GtkWidget *combo;
GtkWidget *colorbutton;
GtkWidget *spinbutton;
GtkObject *adj;
......@@ -689,22 +689,22 @@ create_light_page (void)
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
gtk_container_add (GTK_CONTAINER (frame), table); gtk_widget_show (table);
optionmenu =
gimp_int_option_menu_new (FALSE,
G_CALLBACK (lightmenu_callback),
&mapvals.lightsource.type,
mapvals.lightsource.type,
combo = gimp_int_combo_box_new (_("Point Light"), POINT_LIGHT,
_("Directional Light"), DIRECTIONAL_LIGHT,
_("No Light"), NO_LIGHT,
NULL);
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo),
mapvals.lightsource.type);
_("Point Light"), POINT_LIGHT, NULL,
_("Directional Light"), DIRECTIONAL_LIGHT, NULL,
_("No Light"), NO_LIGHT, NULL,
g_signal_connect (combo, "changed",
G_CALLBACK (lightmenu_callback),
&mapvals.lightsource.type);
NULL);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Lightsource Type:"), 1.0, 0.5,
optionmenu, 1, TRUE);
combo, 1, TRUE);
gimp_help_set_help_data (optionmenu, _("Type of light source to apply"), NULL);
gimp_help_set_help_data (combo, _("Type of light source to apply"), NULL);
colorbutton = gimp_color_button_new (_("Select Lightsource Color"),
64, 16,
......
......@@ -125,10 +125,11 @@ enum
CML_DELTA,
CML_DELTA_STEP,
CML_SIN_CURVE,
CML_SIN_CURVE_STEP
CML_SIN_CURVE_STEP,
CML_NUM_VALUES
};
static gchar *function_names[] =
static const gchar *function_names[CML_NUM_VALUES] =
{
N_("Keep image's values"),
N_("Keep the first value"),
......@@ -161,10 +162,11 @@ enum
COMP_MIN_LINEAR_P1L,
COMP_MIN_LINEAR_P1U,
COMP_MIN_LINEAR_M1L,
COMP_MIN_LINEAR_M1U
COMP_MIN_LINEAR_M1U,
COMP_NUM_VALUES
};
static gchar *composition_names[] =
static const gchar *composition_names[COMP_NUM_VALUES] =
{
N_("None"),
N_("Max (x, -)"),
......@@ -194,10 +196,11 @@ enum
MULTIPLY_RANDOM0,
MULTIPLY_RANDOM1,
MULTIPLY_GRADIENT,
RAND_AND_P
RAND_AND_P,
ARRANGE_NUM_VALUES
};
static gchar *arrange_names[] =
static const gchar *arrange_names[ARRANGE_NUM_VALUES] =
{
N_("Standard"),
N_("Use average value"),
......@@ -216,10 +219,11 @@ enum
CML_INITIAL_RANDOM_INDEPENDENT = 6,
CML_INITIAL_RANDOM_SHARED,
CML_INITIAL_RANDOM_FROM_SEED,
CML_INITIAL_RANDOM_FROM_SEED_SHARED
CML_INITIAL_RANDOM_FROM_SEED_SHARED,
CML_INITIAL_NUM_VALUES
};
static gchar *initial_value_names[] =
static const gchar *initial_value_names[CML_INITIAL_NUM_VALUES] =
{
N_("All black"),
N_("All gray"),
......@@ -296,13 +300,21 @@ static CML_PARAM *channel_params[] =
&VALS.val
};
static gchar *channel_names[] =
static const gchar *channel_names[] =
{
N_("Hue"),
N_("Saturation"),
N_("Value")
};
static const gchar *load_channel_names[] =
{
N_("(None)"),
N_("Hue"),
N_("Saturation"),
N_("Value")
};
static void query (void);
static void run (const gchar *name,
gint nparams,
......@@ -1292,7 +1304,7 @@ CML_explorer_dialog (void)
{
GtkWidget *table;
GtkWidget *optionmenu;
GtkWidget *combo;
GtkWidget *frame;
GtkWidget *vbox;
GtkObject *adj;
......@@ -1312,47 +1324,20 @@ CML_explorer_dialog (void)
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_widget_show (table);
optionmenu =
gimp_int_option_menu_new
(FALSE, G_CALLBACK (CML_initial_value_menu_update),
&VALS.initial_value, VALS.initial_value,
gettext (initial_value_names[0]),
0, NULL,
gettext (initial_value_names[1]),
1, NULL,
gettext (initial_value_names[2]),
2, NULL,
gettext (initial_value_names[3]),
3, NULL,
gettext (initial_value_names[4]),
4, NULL,
gettext (initial_value_names[5]),
5, NULL,
gettext (initial_value_names[CML_INITIAL_RANDOM_INDEPENDENT]),
CML_INITIAL_RANDOM_INDEPENDENT, NULL,
gettext (initial_value_names[CML_INITIAL_RANDOM_SHARED]),
CML_INITIAL_RANDOM_SHARED, NULL,
combo = gimp_int_combo_box_new_array (CML_INITIAL_NUM_VALUES,
initial_value_names);
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo),
VALS.initial_value);
gettext (initial_value_names[CML_INITIAL_RANDOM_FROM_SEED]),
CML_INITIAL_RANDOM_FROM_SEED, NULL,
g_signal_connect (combo, "changed",
G_CALLBACK (CML_initial_value_menu_update),
&VALS.initial_value);
gettext (initial_value_names[CML_INITIAL_RANDOM_FROM_SEED_SHARED]),
CML_INITIAL_RANDOM_FROM_SEED_SHARED, NULL,
NULL);
CML_explorer_menu_entry_init (&widget_pointers[3][0],
optionmenu, &VALS.initial_value);
combo, &VALS.initial_value);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Initial Value:"), 1.0, 0.5,
optionmenu, 2, FALSE);
combo, 2, FALSE);
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
_("Zoom Scale:"), SCALE_WIDTH, 3,
......@@ -1417,10 +1402,11 @@ CML_explorer_dialog (void)
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox,
gtk_label_new_with_mnemonic (_("O_thers")));
}
{
GtkWidget *table;
GtkWidget *frame;
GtkWidget *optionmenu;
GtkWidget *combo;
GtkWidget *vbox;
vbox = gtk_vbox_new (FALSE, 4);
......@@ -1438,39 +1424,30 @@ CML_explorer_dialog (void)
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_widget_show (table);
optionmenu = gimp_int_option_menu_new (FALSE,
G_CALLBACK (gimp_menu_item_update),
&copy_source,
copy_source,
combo = gimp_int_combo_box_new_array (G_N_ELEMENTS (channel_names),
channel_names);
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo), copy_source);
gettext (channel_names[0]),
0, NULL,