use gimp_spin_button_new() which calls gtk_spin_button_set_numeric() for

2005-04-17  Sven Neumann  <sven@gimp.org>

	* libgimpwidgets/gimpsizeentry.c: use gimp_spin_button_new() which
	calls gtk_spin_button_set_numeric() for us. Part of a fix for bug
	#300935.

	* libgimpwidgets/gimpwidgets.c: improved the API docs for
	gimp_spin_button_new().

	* app/tools/gimpcolorbalancetool.c
	* app/tools/gimplevelstool.c
	* plug-ins/common/screenshot.c
	* plug-ins/ifscompose/ifscompose.c
	* plug-ins/rcm/rcm_dialog.c
	* plug-ins/script-fu/script-fu-interface.c
	* plug-ins/winsnap/winsnap.c: use gimp_spin_button_new().
This commit is contained in:
Sven Neumann
2005-04-17 15:28:28 +00:00
committed by Sven Neumann
parent ea67630394
commit b73e908ca5
10 changed files with 100 additions and 118 deletions

View File

@ -1,3 +1,20 @@
2005-04-17 Sven Neumann <sven@gimp.org>
* libgimpwidgets/gimpsizeentry.c: use gimp_spin_button_new() which
calls gtk_spin_button_set_numeric() for us. Part of a fix for bug
#300935.
* libgimpwidgets/gimpwidgets.c: improved the API docs for
gimp_spin_button_new().
* app/tools/gimpcolorbalancetool.c
* app/tools/gimplevelstool.c
* plug-ins/common/screenshot.c
* plug-ins/ifscompose/ifscompose.c
* plug-ins/rcm/rcm_dialog.c
* plug-ins/script-fu/script-fu-interface.c
* plug-ins/winsnap/winsnap.c: use gimp_spin_button_new().
2005-04-17 Sven Neumann <sven@gimp.org> 2005-04-17 Sven Neumann <sven@gimp.org>
* plug-ins/helpbrowser/dialog.c: set a busy cursor while loading a * plug-ins/helpbrowser/dialog.c: set a busy cursor while loading a

View File

@ -226,12 +226,10 @@ create_levels_scale (const gchar *left,
GtkWidget *table, GtkWidget *table,
gint col) gint col)
{ {
GtkWidget *label; GtkWidget *label;
GtkWidget *slider; GtkWidget *slider;
GtkWidget *spinbutton; GtkWidget *spinbutton;
GtkAdjustment *adj; GtkObject *adj;
adj = GTK_ADJUSTMENT (gtk_adjustment_new (0, -100.0, 100.0, 1.0, 10.0, 0.0));
label = gtk_label_new (left); label = gtk_label_new (left);
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
@ -239,7 +237,10 @@ create_levels_scale (const gchar *left,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0); GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label); gtk_widget_show (label);
slider = gtk_hscale_new (adj); spinbutton = gimp_spin_button_new (&adj,
0, -100.0, 100.0, 1.0, 10.0, 0.0, 1.0, 0);
slider = gtk_hscale_new (GTK_ADJUSTMENT (adj));
gtk_scale_set_draw_value (GTK_SCALE (slider), FALSE); gtk_scale_set_draw_value (GTK_SCALE (slider), FALSE);
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED); gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
gtk_widget_set_size_request (slider, 100, -1); gtk_widget_set_size_request (slider, 100, -1);
@ -252,12 +253,11 @@ create_levels_scale (const gchar *left,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0); GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label); gtk_widget_show (label);
spinbutton = gtk_spin_button_new (adj, 1.0, 0);
gtk_table_attach (GTK_TABLE (table), spinbutton, 3, 4, col, col + 1, gtk_table_attach (GTK_TABLE (table), spinbutton, 3, 4, col, col + 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0); GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (spinbutton); gtk_widget_show (spinbutton);
return adj; return GTK_ADJUSTMENT (adj);
} }
static void static void

View File

@ -518,28 +518,22 @@ gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool)
gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0);
gtk_widget_show (button); gtk_widget_show (button);
data = gtk_adjustment_new (0, 0, 255, 1, 10, 10); spinbutton = gimp_spin_button_new (&data, 0, 0, 255, 1, 10, 10, 0.5, 0);
tool->low_input = GTK_ADJUSTMENT (data);
spinbutton = gtk_spin_button_new (tool->low_input, 0.5, 0);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_box_pack_start (GTK_BOX (hbox2), spinbutton, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox2), spinbutton, FALSE, FALSE, 0);
gtk_widget_show (spinbutton); gtk_widget_show (spinbutton);
tool->low_input = GTK_ADJUSTMENT (data);
g_signal_connect (tool->low_input, "value_changed", g_signal_connect (tool->low_input, "value_changed",
G_CALLBACK (levels_low_input_adjustment_update), G_CALLBACK (levels_low_input_adjustment_update),
tool); tool);
/* input gamma spin */ /* input gamma spin */
data = gtk_adjustment_new (1, 0.1, 10, 0.01, 0.1, 1); spinbutton = gimp_spin_button_new (&data, 1, 0.1, 10, 0.01, 0.1, 1, 0.5, 2);
tool->gamma = GTK_ADJUSTMENT (data);
spinbutton = gtk_spin_button_new (tool->gamma, 0.5, 2);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, TRUE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), spinbutton, TRUE, FALSE, 0);
gimp_help_set_help_data (spinbutton, _("Gamma"), NULL); gimp_help_set_help_data (spinbutton, _("Gamma"), NULL);
gtk_widget_show (spinbutton); gtk_widget_show (spinbutton);
tool->gamma = GTK_ADJUSTMENT (data);
g_signal_connect (tool->gamma, "value_changed", g_signal_connect (tool->gamma, "value_changed",
G_CALLBACK (levels_gamma_adjustment_update), G_CALLBACK (levels_gamma_adjustment_update),
tool); tool);
@ -553,19 +547,15 @@ gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool)
gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0);
gtk_widget_show (button); gtk_widget_show (button);
data = gtk_adjustment_new (255, 0, 255, 1, 10, 10); spinbutton = gimp_spin_button_new (&data, 255, 0, 255, 1, 10, 10, 0.5, 0);
tool->high_input = GTK_ADJUSTMENT (data);
spinbutton = gtk_spin_button_new (tool->high_input, 0.5, 0);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_box_pack_start (GTK_BOX (hbox2), spinbutton, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox2), spinbutton, FALSE, FALSE, 0);
gtk_widget_show (spinbutton); gtk_widget_show (spinbutton);
tool->high_input = GTK_ADJUSTMENT (data);
g_signal_connect (tool->high_input, "value_changed", g_signal_connect (tool->high_input, "value_changed",
G_CALLBACK (levels_high_input_adjustment_update), G_CALLBACK (levels_high_input_adjustment_update),
tool); tool);
/* Output levels frame */ /* Output levels frame */
frame = gimp_frame_new (_("Output Levels")); frame = gimp_frame_new (_("Output Levels"));
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
@ -612,27 +602,21 @@ gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool)
gtk_widget_show (hbox); gtk_widget_show (hbox);
/* low output spin */ /* low output spin */
data = gtk_adjustment_new (0, 0, 255, 1, 10, 10); spinbutton = gimp_spin_button_new (&data, 0, 0, 255, 1, 10, 10, 0.5, 0);
tool->low_output = GTK_ADJUSTMENT (data);
spinbutton = gtk_spin_button_new (tool->low_output, 0.5, 0);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
gtk_widget_show (spinbutton); gtk_widget_show (spinbutton);
tool->low_output = GTK_ADJUSTMENT (data);
g_signal_connect (tool->low_output, "value_changed", g_signal_connect (tool->low_output, "value_changed",
G_CALLBACK (levels_low_output_adjustment_update), G_CALLBACK (levels_low_output_adjustment_update),
tool); tool);
/* high output spin */ /* high output spin */
data = gtk_adjustment_new (255, 0, 255, 1, 10, 10); spinbutton = gimp_spin_button_new (&data, 255, 0, 255, 1, 10, 10, 0.5, 0);
tool->high_output = GTK_ADJUSTMENT (data);
spinbutton = gtk_spin_button_new (tool->high_output, 0.5, 0);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_box_pack_end (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0); gtk_box_pack_end (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
gtk_widget_show (spinbutton); gtk_widget_show (spinbutton);
tool->high_output = GTK_ADJUSTMENT (data);
g_signal_connect (tool->high_output, "value_changed", g_signal_connect (tool->high_output, "value_changed",
G_CALLBACK (levels_high_output_adjustment_update), G_CALLBACK (levels_high_output_adjustment_update),
tool); tool);

View File

@ -291,6 +291,7 @@ gimp_size_entry_new (gint number_of_fields,
for (i = 0; i < number_of_fields; i++) for (i = 0; i < number_of_fields; i++)
{ {
GimpSizeEntryField *gsef; GimpSizeEntryField *gsef;
gint digits;
gsef = g_new0 (GimpSizeEntryField, 1); gsef = g_new0 (GimpSizeEntryField, 1);
gse->fields = g_slist_append (gse->fields, gsef); gse->fields = g_slist_append (gse->fields, gsef);
@ -311,15 +312,16 @@ gimp_size_entry_new (gint number_of_fields,
(update_policy == GIMP_SIZE_ENTRY_UPDATE_SIZE) ? 0 : 3; (update_policy == GIMP_SIZE_ENTRY_UPDATE_SIZE) ? 0 : 3;
gsef->stop_recursion = 0; gsef->stop_recursion = 0;
gsef->value_adjustment = gtk_adjustment_new (gsef->value, digits = ((unit == GIMP_UNIT_PIXEL) ?
gsef->min_value, gsef->refval_digits : ((unit == GIMP_UNIT_PERCENT) ?
gsef->max_value, 2 : GIMP_SIZE_ENTRY_DIGITS (unit)));
1.0, 10.0, 0.0);
gsef->value_spinbutton = gsef->value_spinbutton = gimp_spin_button_new (&gsef->value_adjustment,
gtk_spin_button_new (GTK_ADJUSTMENT (gsef->value_adjustment), 1.0, gsef->value,
(unit == GIMP_UNIT_PIXEL) ? gsef->refval_digits : gsef->min_value,
(unit == GIMP_UNIT_PERCENT) ? 2 : gsef->max_value,
GIMP_SIZE_ENTRY_DIGITS (unit)); 1.0, 10.0, 0.0,
1.0, digits);
if (spinbutton_width > 0) if (spinbutton_width > 0)
{ {
@ -342,14 +344,12 @@ gimp_size_entry_new (gint number_of_fields,
if (gse->show_refval) if (gse->show_refval)
{ {
gsef->refval_adjustment = gtk_adjustment_new (gsef->refval, gsef->refval_spinbutton =
gsef->min_refval, gimp_spin_button_new (&gsef->refval_adjustment,
gsef->max_refval, gsef->refval,
1.0, 10.0, 0.0); gsef->min_refval, gsef->max_refval,
gsef->refval_spinbutton = 1.0, 10.0, 0.0, 1.0, gsef->refval_digits);
gtk_spin_button_new (GTK_ADJUSTMENT (gsef->refval_adjustment),
1.0,
gsef->refval_digits);
gtk_widget_set_size_request (gsef->refval_spinbutton, gtk_widget_set_size_request (gsef->refval_spinbutton,
spinbutton_width, -1); spinbutton_width, -1);
gtk_table_attach_defaults (GTK_TABLE (gse), gsef->refval_spinbutton, gtk_table_attach_defaults (GTK_TABLE (gse), gsef->refval_spinbutton,

View File

@ -419,9 +419,10 @@ gimp_int_radio_group_set_active (GtkRadioButton *radio_button,
* @climb_rate: The spinbutton's climb rate. * @climb_rate: The spinbutton's climb rate.
* @digits: The spinbutton's number of decimal digits. * @digits: The spinbutton's number of decimal digits.
* *
* This function is a shortcut for gtk_adjustment_new() and a subsequent * This function is a shortcut for gtk_adjustment_new() and a
* gtk_spin_button_new() and does some more initialisation stuff like * subsequent gtk_spin_button_new(). It also calls
* setting a standard minimum horizontal size. * gtk_spin_button_set_numeric() so that non-numeric text cannot be
* entered.
* *
* Returns: A #GtkSpinbutton and it's #GtkAdjustment. * Returns: A #GtkSpinbutton and it's #GtkAdjustment.
**/ **/
@ -443,6 +444,7 @@ gimp_spin_button_new (GtkObject **adjustment, /* return value */
spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (*adjustment), spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (*adjustment),
climb_rate, digits); climb_rate, digits);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
return spinbutton; return spinbutton;

View File

@ -846,8 +846,8 @@ shoot_dialog (GdkScreen **screen)
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label); gtk_widget_show (label);
adj = gtk_adjustment_new (shootvals.select_delay, 0.0, 100.0, 1.0, 5.0, 0.0); spinner = gimp_spin_button_new (&adj, shootvals.select_delay,
spinner = gtk_spin_button_new (GTK_ADJUSTMENT (adj), 0, 0); 0.0, 100.0, 1.0, 5.0, 0.0, 0, 0);
gtk_box_pack_start (GTK_BOX (hbox), spinner, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), spinner, FALSE, FALSE, 0);
gtk_widget_show (spinner); gtk_widget_show (spinner);

View File

@ -247,8 +247,6 @@ static ValuePair *value_pair_create (gpointer data,
gboolean create_scale, gboolean create_scale,
ValuePairType type); ValuePairType type);
static void value_pair_update (ValuePair *value_pair); static void value_pair_update (ValuePair *value_pair);
static void value_pair_destroy_callback (GtkWidget *widget,
ValuePair *value_pair);
static void value_pair_scale_callback (GtkAdjustment *adjustment, static void value_pair_scale_callback (GtkAdjustment *adjustment,
ValuePair *value_pair); ValuePair *value_pair);
@ -2114,48 +2112,35 @@ value_pair_create (gpointer data,
value_pair->data.d = data; value_pair->data.d = data;
value_pair->type = type; value_pair->type = type;
value_pair->adjustment = value_pair->spin = gimp_spin_button_new (&value_pair->adjustment,
gtk_adjustment_new (1.0, lower, upper, 1.0, lower, upper,
(upper-lower) / 100, (upper-lower) / 10, (upper - lower) / 100,
0.0); (upper - lower) / 10,
/* We need to sink the adjustment, since we may not create a scale for 0.0, 1.0, 3);
* it, so nobody will assume the initial refcount gtk_widget_set_size_request (value_pair->spin, 72, -1);
*/
g_object_ref (value_pair->adjustment); g_signal_connect (value_pair->adjustment, "value_changed",
gtk_object_sink (value_pair->adjustment); G_CALLBACK (value_pair_scale_callback),
value_pair);
if (create_scale) if (create_scale)
{ {
value_pair->scale = value_pair->scale =
gtk_hscale_new (GTK_ADJUSTMENT (value_pair->adjustment)); gtk_hscale_new (GTK_ADJUSTMENT (value_pair->adjustment));
gtk_widget_ref (value_pair->scale);
if (type == VALUE_PAIR_INT) if (type == VALUE_PAIR_INT)
gtk_scale_set_digits (GTK_SCALE (value_pair->scale), 0); gtk_scale_set_digits (GTK_SCALE (value_pair->scale), 0);
else else
gtk_scale_set_digits (GTK_SCALE (value_pair->scale), 3); gtk_scale_set_digits (GTK_SCALE (value_pair->scale), 3);
gtk_scale_set_draw_value (GTK_SCALE (value_pair->scale), FALSE); gtk_scale_set_draw_value (GTK_SCALE (value_pair->scale), FALSE);
gtk_range_set_update_policy (GTK_RANGE (value_pair->scale), gtk_range_set_update_policy (GTK_RANGE (value_pair->scale),
GTK_UPDATE_DELAYED); GTK_UPDATE_DELAYED);
} }
else else
value_pair->scale = NULL; {
value_pair->scale = NULL;
/* We destroy the value pair when the spinbutton is destroyed, so }
* we don't need to hold a refcount on the entry
*/
value_pair->spin
= gtk_spin_button_new (GTK_ADJUSTMENT (value_pair->adjustment),
1.0, 3);
gtk_widget_set_size_request (value_pair->spin, 72, -1);
g_signal_connect (value_pair->spin, "destroy",
G_CALLBACK (value_pair_destroy_callback),
value_pair);
g_signal_connect (value_pair->adjustment, "value_changed",
G_CALLBACK (value_pair_scale_callback),
value_pair);
return value_pair; return value_pair;
} }
@ -2199,15 +2184,6 @@ value_pair_scale_callback (GtkAdjustment *adjustment,
val_changed_update (); val_changed_update ();
} }
static void
value_pair_destroy_callback (GtkWidget *widget,
ValuePair *value_pair)
{
if (value_pair->scale)
g_object_unref (value_pair->scale);
g_object_unref (value_pair->adjustment);
}
static void static void
design_op_update_callback (GtkRadioAction *action, design_op_update_callback (GtkRadioAction *action,
GtkRadioAction *current, GtkRadioAction *current,

View File

@ -551,6 +551,7 @@ rcm_create_gray (void)
0.0, 1.0, 0.0001, 0.001, 0.0); 0.0, 1.0, 0.0001, 0.001, 0.0);
entry = gtk_spin_button_new (adj, 0.01, 4); entry = gtk_spin_button_new (adj, 0.01, 4);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (entry), TRUE);
gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
gtk_widget_show (entry); gtk_widget_show (entry);

View File

@ -276,6 +276,7 @@ script_fu_interface (SFScript *script)
for (i = script->image_based ? 2 : 0; i < script->num_args; i++) for (i = script->image_based ? 2 : 0; i < script->num_args; i++)
{ {
GtkWidget *widget = NULL; GtkWidget *widget = NULL;
GtkObject *adj;
gchar *label_text; gchar *label_text;
gfloat label_yalign = 0.5; gfloat label_yalign = 0.5;
gint *ID_ptr = NULL; gint *ID_ptr = NULL;
@ -412,15 +413,16 @@ script_fu_interface (SFScript *script)
case SF_SPINNER: case SF_SPINNER:
left_align = TRUE; left_align = TRUE;
script->arg_values[i].sfa_adjustment.adj = (GtkAdjustment *) widget =
gtk_adjustment_new (script->arg_values[i].sfa_adjustment.value, gimp_spin_button_new (&adj,
script->arg_defaults[i].sfa_adjustment.lower, script->arg_values[i].sfa_adjustment.value,
script->arg_defaults[i].sfa_adjustment.upper, script->arg_defaults[i].sfa_adjustment.lower,
script->arg_defaults[i].sfa_adjustment.step, script->arg_defaults[i].sfa_adjustment.upper,
script->arg_defaults[i].sfa_adjustment.page, 0); script->arg_defaults[i].sfa_adjustment.step,
widget = gtk_spin_button_new (script->arg_values[i].sfa_adjustment.adj, script->arg_defaults[i].sfa_adjustment.page,
0, 0, 0,
script->arg_defaults[i].sfa_adjustment.digits); script->arg_defaults[i].sfa_adjustment.digits);
script->arg_values[i].sfa_adjustment.adj = GTK_ADJUSTMENT (adj);
break; break;
} }

View File

@ -838,15 +838,15 @@ snap_toggle_update (GtkWidget *widget,
static gboolean static gboolean
snap_dialog (void) snap_dialog (void)
{ {
GtkWidget *dialog; GtkWidget *dialog;
GtkWidget *vbox; GtkWidget *vbox;
GtkWidget *hbox; GtkWidget *hbox;
GtkWidget *label; GtkWidget *label;
GtkAdjustment *adj; GtkObject *adj;
GSList *radio_group = NULL; GSList *radio_group = NULL;
gint radio_pressed[2]; gint radio_pressed[2];
gint decorations; gint decorations;
gboolean run; gboolean run;
/* Set defaults */ /* Set defaults */
radio_pressed[0] = (winsnapvals.root == FALSE); radio_pressed[0] = (winsnapvals.root == FALSE);
@ -912,10 +912,10 @@ snap_dialog (void)
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label); gtk_widget_show (label);
adj = (GtkAdjustment *) gtk_adjustment_new ((gfloat) winsnapvals.delay, winsnapintf.delay_spinner = gimp_spin_button_new (&adj,
0.0, 100.0, winsnapvals.delay,
1.0, 5.0, 0.0); 0.0, 100.0,
winsnapintf.delay_spinner = gtk_spin_button_new (adj, 0, 0); 1.0, 5.0, 0.0, 0, 0);
gtk_box_pack_start (GTK_BOX (hbox), gtk_box_pack_start (GTK_BOX (hbox),
winsnapintf.delay_spinner, FALSE, FALSE, 0); winsnapintf.delay_spinner, FALSE, FALSE, 0);
gtk_widget_show (winsnapintf.delay_spinner); gtk_widget_show (winsnapintf.delay_spinner);