1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * GtkSpinButton widget for GTK+
5 * Copyright (C) 1998 Lars Hamann and Stefan Jeske
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
25 * file for a list of people on the GTK+ Team. See the ChangeLog
26 * files for a list of changes. These files are distributed with
27 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
38 #include "gtkbindings.h"
39 #include "gtkspinbutton.h"
40 #include "gtkentryprivate.h"
41 #include "gtkmainprivate.h"
42 #include "gtkmarshalers.h"
43 #include "gtksettings.h"
44 #include "gtkprivate.h"
46 #include "gtktypebuiltins.h"
48 #define MIN_SPIN_BUTTON_WIDTH 30
49 #define MAX_TIMER_CALLS 5
52 #define MIN_ARROW_WIDTH 6
56 * SECTION:gtkspinbutton
57 * @Title: GtkSpinButton
58 * @Short_description: Retrieve an integer or floating-point number from
60 * @See_also: #GtkEntry
62 * A #GtkSpinButton is an ideal way to allow the user to set the value of
63 * some attribute. Rather than having to directly type a number into a
64 * #GtkEntry, GtkSpinButton allows the user to click on one of two arrows
65 * to increment or decrement the displayed value. A value can still be
66 * typed in, with the bonus that it can be checked to ensure it is in a
69 * The main properties of a GtkSpinButton are through an adjustment.
70 * See the #GtkAdjustment section for more details about an adjustment's
74 * <title>Using a GtkSpinButton to get an integer</title>
76 * /* Provides a function to retrieve an integer value from a
77 * * GtkSpinButton and creates a spin button to model percentage
82 * grab_int_value (GtkSpinButton *button,
85 * return gtk_spin_button_get_value_as_int (button);
89 * create_integer_spin_button (void)
92 * GtkWidget *window, *button;
93 * GtkAdjustment *adjustment;
95 * adjustment = gtk_adjustment_new (50.0, 0.0, 100.0, 1.0, 5.0, 0.0);
97 * window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
98 * gtk_container_set_border_width (GTK_CONTAINER (window), 5);
100 * /* creates the spinbutton, with no decimal places */
101 * button = gtk_spin_button_new (adjustment, 1.0, 0);
102 * gtk_container_add (GTK_CONTAINER (window), button);
104 * gtk_widget_show_all (window);
110 * <title>Using a GtkSpinButton to get a floating point value</title>
112 * /* Provides a function to retrieve a floating point value from a
113 * * GtkSpinButton, and creates a high precision spin button.
117 * grab_float_value (GtkSpinButton *button,
118 * gpointer user_data)
120 * return gtk_spin_button_get_value (button);
124 * create_floating_spin_button (void)
126 * GtkWidget *window, *button;
127 * GtkAdjustment *adjustment;
129 * adjustment = gtk_adjustment_new (2.500, 0.0, 5.0, 0.001, 0.1, 0.0);
131 * window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
132 * gtk_container_set_border_width (GTK_CONTAINER (window), 5);
134 * /* creates the spinbutton, with three decimal places */
135 * button = gtk_spin_button_new (adjustment, 0.001, 3);
136 * gtk_container_add (GTK_CONTAINER (window), button);
138 * gtk_widget_show_all (window);
144 struct _GtkSpinButtonPrivate
146 GtkAdjustment *adjustment;
152 GtkSpinButtonUpdatePolicy update_policy;
158 guint click_child : 2; /* valid: GTK_ARROW_UP=0, GTK_ARROW_DOWN=1 or 2=NONE/BOTH */
161 guint need_timer : 1;
163 guint snap_to_ticks : 1;
164 guint timer_calls : 3;
191 static void gtk_spin_button_editable_init (GtkEditableInterface *iface);
192 static void gtk_spin_button_finalize (GObject *object);
193 static void gtk_spin_button_set_property (GObject *object,
197 static void gtk_spin_button_get_property (GObject *object,
201 static void gtk_spin_button_destroy (GtkWidget *widget);
202 static void gtk_spin_button_map (GtkWidget *widget);
203 static void gtk_spin_button_unmap (GtkWidget *widget);
204 static void gtk_spin_button_realize (GtkWidget *widget);
205 static void gtk_spin_button_unrealize (GtkWidget *widget);
206 static void gtk_spin_button_get_preferred_width (GtkWidget *widget,
210 static void gtk_spin_button_size_allocate (GtkWidget *widget,
211 GtkAllocation *allocation);
212 static gint gtk_spin_button_draw (GtkWidget *widget,
214 static gint gtk_spin_button_button_press (GtkWidget *widget,
215 GdkEventButton *event);
216 static gint gtk_spin_button_button_release (GtkWidget *widget,
217 GdkEventButton *event);
218 static gint gtk_spin_button_motion_notify (GtkWidget *widget,
219 GdkEventMotion *event);
220 static gint gtk_spin_button_enter_notify (GtkWidget *widget,
221 GdkEventCrossing *event);
222 static gint gtk_spin_button_leave_notify (GtkWidget *widget,
223 GdkEventCrossing *event);
224 static gint gtk_spin_button_focus_out (GtkWidget *widget,
225 GdkEventFocus *event);
226 static void gtk_spin_button_grab_notify (GtkWidget *widget,
227 gboolean was_grabbed);
228 static void gtk_spin_button_state_flags_changed (GtkWidget *widget,
229 GtkStateFlags previous_state);
230 static void gtk_spin_button_style_updated (GtkWidget *widget);
231 static void gtk_spin_button_draw_arrow (GtkSpinButton *spin_button,
232 GtkStyleContext *context,
234 GtkArrowType arrow_type);
235 static gboolean gtk_spin_button_timer (GtkSpinButton *spin_button);
236 static gboolean gtk_spin_button_stop_spinning (GtkSpinButton *spin);
237 static void gtk_spin_button_value_changed (GtkAdjustment *adjustment,
238 GtkSpinButton *spin_button);
239 static gint gtk_spin_button_key_release (GtkWidget *widget,
241 static gint gtk_spin_button_scroll (GtkWidget *widget,
242 GdkEventScroll *event);
243 static void gtk_spin_button_activate (GtkEntry *entry);
244 static void gtk_spin_button_get_text_area_size (GtkEntry *entry,
249 static void gtk_spin_button_snap (GtkSpinButton *spin_button,
251 static void gtk_spin_button_insert_text (GtkEditable *editable,
252 const gchar *new_text,
253 gint new_text_length,
255 static void gtk_spin_button_real_spin (GtkSpinButton *spin_button,
257 static void gtk_spin_button_real_change_value (GtkSpinButton *spin,
258 GtkScrollType scroll);
260 static gint gtk_spin_button_default_input (GtkSpinButton *spin_button,
262 static gint gtk_spin_button_default_output (GtkSpinButton *spin_button);
264 static gint spin_button_get_arrow_size (GtkSpinButton *spin_button);
266 static guint spinbutton_signals[LAST_SIGNAL] = {0};
270 G_DEFINE_TYPE_WITH_CODE (GtkSpinButton, gtk_spin_button, GTK_TYPE_ENTRY,
271 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
272 gtk_spin_button_editable_init))
274 #define add_spin_binding(binding_set, keyval, mask, scroll) \
275 gtk_binding_entry_add_signal (binding_set, keyval, mask, \
277 GTK_TYPE_SCROLL_TYPE, scroll)
280 gtk_spin_button_class_init (GtkSpinButtonClass *class)
282 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
283 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
284 GtkEntryClass *entry_class = GTK_ENTRY_CLASS (class);
285 GtkBindingSet *binding_set;
287 gobject_class->finalize = gtk_spin_button_finalize;
288 gobject_class->set_property = gtk_spin_button_set_property;
289 gobject_class->get_property = gtk_spin_button_get_property;
291 widget_class->destroy = gtk_spin_button_destroy;
292 widget_class->map = gtk_spin_button_map;
293 widget_class->unmap = gtk_spin_button_unmap;
294 widget_class->realize = gtk_spin_button_realize;
295 widget_class->unrealize = gtk_spin_button_unrealize;
296 widget_class->get_preferred_width = gtk_spin_button_get_preferred_width;
297 widget_class->size_allocate = gtk_spin_button_size_allocate;
298 widget_class->draw = gtk_spin_button_draw;
299 widget_class->scroll_event = gtk_spin_button_scroll;
300 widget_class->button_press_event = gtk_spin_button_button_press;
301 widget_class->button_release_event = gtk_spin_button_button_release;
302 widget_class->motion_notify_event = gtk_spin_button_motion_notify;
303 widget_class->key_release_event = gtk_spin_button_key_release;
304 widget_class->enter_notify_event = gtk_spin_button_enter_notify;
305 widget_class->leave_notify_event = gtk_spin_button_leave_notify;
306 widget_class->focus_out_event = gtk_spin_button_focus_out;
307 widget_class->grab_notify = gtk_spin_button_grab_notify;
308 widget_class->state_flags_changed = gtk_spin_button_state_flags_changed;
309 widget_class->style_updated = gtk_spin_button_style_updated;
311 entry_class->activate = gtk_spin_button_activate;
312 entry_class->get_text_area_size = gtk_spin_button_get_text_area_size;
315 class->output = NULL;
316 class->change_value = gtk_spin_button_real_change_value;
318 g_object_class_install_property (gobject_class,
320 g_param_spec_object ("adjustment",
322 P_("The adjustment that holds the value of the spin button"),
324 GTK_PARAM_READWRITE));
326 g_object_class_install_property (gobject_class,
328 g_param_spec_double ("climb-rate",
330 P_("The acceleration rate when you hold down a button"),
334 GTK_PARAM_READWRITE));
336 g_object_class_install_property (gobject_class,
338 g_param_spec_uint ("digits",
340 P_("The number of decimal places to display"),
344 GTK_PARAM_READWRITE));
346 g_object_class_install_property (gobject_class,
348 g_param_spec_boolean ("snap-to-ticks",
350 P_("Whether erroneous values are automatically changed to a spin button's nearest step increment"),
352 GTK_PARAM_READWRITE));
354 g_object_class_install_property (gobject_class,
356 g_param_spec_boolean ("numeric",
358 P_("Whether non-numeric characters should be ignored"),
360 GTK_PARAM_READWRITE));
362 g_object_class_install_property (gobject_class,
364 g_param_spec_boolean ("wrap",
366 P_("Whether a spin button should wrap upon reaching its limits"),
368 GTK_PARAM_READWRITE));
370 g_object_class_install_property (gobject_class,
372 g_param_spec_enum ("update-policy",
374 P_("Whether the spin button should update always, or only when the value is legal"),
375 GTK_TYPE_SPIN_BUTTON_UPDATE_POLICY,
377 GTK_PARAM_READWRITE));
379 g_object_class_install_property (gobject_class,
381 g_param_spec_double ("value",
383 P_("Reads the current value, or sets a new value"),
387 GTK_PARAM_READWRITE));
389 gtk_widget_class_install_style_property_parser (widget_class,
390 g_param_spec_enum ("shadow-type",
392 P_("Style of bevel around the spin button"),
393 GTK_TYPE_SHADOW_TYPE,
396 gtk_rc_property_parse_enum);
399 * GtkSpinButton::input:
400 * @spin_button: the object on which the signal was emitted
401 * @new_value: (out) (type double): return location for the new value
403 * The ::input signal can be used to influence the conversion of
404 * the users input into a double value. The signal handler is
405 * expected to use gtk_entry_get_text() to retrieve the text of
406 * the entry and set @new_value to the new value.
408 * The default conversion uses g_strtod().
410 * Returns: %TRUE for a successful conversion, %FALSE if the input
411 * was not handled, and %GTK_INPUT_ERROR if the conversion failed.
413 spinbutton_signals[INPUT] =
414 g_signal_new (I_("input"),
415 G_TYPE_FROM_CLASS (gobject_class),
417 G_STRUCT_OFFSET (GtkSpinButtonClass, input),
419 _gtk_marshal_INT__POINTER,
424 * GtkSpinButton::output:
425 * @spin_button: the object which received the signal
427 * The ::output signal can be used to change to formatting
428 * of the value that is displayed in the spin buttons entry.
430 * /* show leading zeros */
432 * on_output (GtkSpinButton *spin,
435 * GtkAdjustment *adjustment;
439 * adjustment = gtk_spin_button_get_adjustment (spin);
440 * value = (int)gtk_adjustment_get_value (adjustment);
441 * text = g_strdup_printf ("%02d", value);
442 * gtk_entry_set_text (GTK_ENTRY (spin), text);
449 * Returns: %TRUE if the value has been displayed
451 spinbutton_signals[OUTPUT] =
452 g_signal_new (I_("output"),
453 G_TYPE_FROM_CLASS (gobject_class),
455 G_STRUCT_OFFSET (GtkSpinButtonClass, output),
456 _gtk_boolean_handled_accumulator, NULL,
457 _gtk_marshal_BOOLEAN__VOID,
460 spinbutton_signals[VALUE_CHANGED] =
461 g_signal_new (I_("value-changed"),
462 G_TYPE_FROM_CLASS (gobject_class),
464 G_STRUCT_OFFSET (GtkSpinButtonClass, value_changed),
466 _gtk_marshal_VOID__VOID,
470 * GtkSpinButton::wrapped:
471 * @spinbutton: the object which received the signal
473 * The wrapped signal is emitted right after the spinbutton wraps
474 * from its maximum to minimum value or vice-versa.
478 spinbutton_signals[WRAPPED] =
479 g_signal_new (I_("wrapped"),
480 G_TYPE_FROM_CLASS (gobject_class),
482 G_STRUCT_OFFSET (GtkSpinButtonClass, wrapped),
484 _gtk_marshal_VOID__VOID,
488 spinbutton_signals[CHANGE_VALUE] =
489 g_signal_new (I_("change-value"),
490 G_TYPE_FROM_CLASS (gobject_class),
491 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
492 G_STRUCT_OFFSET (GtkSpinButtonClass, change_value),
494 _gtk_marshal_VOID__ENUM,
496 GTK_TYPE_SCROLL_TYPE);
498 binding_set = gtk_binding_set_by_class (class);
500 add_spin_binding (binding_set, GDK_KEY_Up, 0, GTK_SCROLL_STEP_UP);
501 add_spin_binding (binding_set, GDK_KEY_KP_Up, 0, GTK_SCROLL_STEP_UP);
502 add_spin_binding (binding_set, GDK_KEY_Down, 0, GTK_SCROLL_STEP_DOWN);
503 add_spin_binding (binding_set, GDK_KEY_KP_Down, 0, GTK_SCROLL_STEP_DOWN);
504 add_spin_binding (binding_set, GDK_KEY_Page_Up, 0, GTK_SCROLL_PAGE_UP);
505 add_spin_binding (binding_set, GDK_KEY_Page_Down, 0, GTK_SCROLL_PAGE_DOWN);
506 add_spin_binding (binding_set, GDK_KEY_Page_Up, GDK_CONTROL_MASK, GTK_SCROLL_END);
507 add_spin_binding (binding_set, GDK_KEY_Page_Down, GDK_CONTROL_MASK, GTK_SCROLL_START);
509 g_type_class_add_private (class, sizeof (GtkSpinButtonPrivate));
513 gtk_spin_button_editable_init (GtkEditableInterface *iface)
515 iface->insert_text = gtk_spin_button_insert_text;
519 gtk_spin_button_set_property (GObject *object,
524 GtkSpinButton *spin_button = GTK_SPIN_BUTTON (object);
525 GtkSpinButtonPrivate *priv = spin_button->priv;
529 GtkAdjustment *adjustment;
531 case PROP_ADJUSTMENT:
532 adjustment = GTK_ADJUSTMENT (g_value_get_object (value));
534 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
535 gtk_spin_button_set_adjustment (spin_button, adjustment);
537 case PROP_CLIMB_RATE:
538 gtk_spin_button_configure (spin_button,
540 g_value_get_double (value),
544 gtk_spin_button_configure (spin_button,
547 g_value_get_uint (value));
549 case PROP_SNAP_TO_TICKS:
550 gtk_spin_button_set_snap_to_ticks (spin_button, g_value_get_boolean (value));
553 gtk_spin_button_set_numeric (spin_button, g_value_get_boolean (value));
556 gtk_spin_button_set_wrap (spin_button, g_value_get_boolean (value));
558 case PROP_UPDATE_POLICY:
559 gtk_spin_button_set_update_policy (spin_button, g_value_get_enum (value));
562 gtk_spin_button_set_value (spin_button, g_value_get_double (value));
565 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
571 gtk_spin_button_get_property (GObject *object,
576 GtkSpinButton *spin_button = GTK_SPIN_BUTTON (object);
577 GtkSpinButtonPrivate *priv = spin_button->priv;
581 case PROP_ADJUSTMENT:
582 g_value_set_object (value, priv->adjustment);
584 case PROP_CLIMB_RATE:
585 g_value_set_double (value, priv->climb_rate);
588 g_value_set_uint (value, priv->digits);
590 case PROP_SNAP_TO_TICKS:
591 g_value_set_boolean (value, priv->snap_to_ticks);
594 g_value_set_boolean (value, priv->numeric);
597 g_value_set_boolean (value, priv->wrap);
599 case PROP_UPDATE_POLICY:
600 g_value_set_enum (value, priv->update_policy);
603 g_value_set_double (value, gtk_adjustment_get_value (priv->adjustment));
606 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
612 gtk_spin_button_init (GtkSpinButton *spin_button)
614 GtkSpinButtonPrivate *priv;
615 GtkStyleContext *context;
617 spin_button->priv = G_TYPE_INSTANCE_GET_PRIVATE (spin_button,
618 GTK_TYPE_SPIN_BUTTON,
619 GtkSpinButtonPrivate);
620 priv = spin_button->priv;
622 priv->adjustment = NULL;
625 priv->climb_rate = 0.0;
626 priv->timer_step = 0.0;
627 priv->update_policy = GTK_UPDATE_ALWAYS;
628 priv->in_child = NO_ARROW;
629 priv->click_child = NO_ARROW;
631 priv->need_timer = FALSE;
632 priv->timer_calls = 0;
634 priv->numeric = FALSE;
636 priv->snap_to_ticks = FALSE;
638 gtk_spin_button_set_adjustment (spin_button,
639 gtk_adjustment_new (0, 0, 0, 0, 0, 0));
641 context = gtk_widget_get_style_context (GTK_WIDGET (spin_button));
642 gtk_style_context_add_class (context, GTK_STYLE_CLASS_SPINBUTTON);
646 gtk_spin_button_finalize (GObject *object)
648 gtk_spin_button_set_adjustment (GTK_SPIN_BUTTON (object), NULL);
650 G_OBJECT_CLASS (gtk_spin_button_parent_class)->finalize (object);
654 gtk_spin_button_destroy (GtkWidget *widget)
656 gtk_spin_button_stop_spinning (GTK_SPIN_BUTTON (widget));
658 GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->destroy (widget);
662 gtk_spin_button_map (GtkWidget *widget)
664 GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
665 GtkSpinButtonPrivate *priv = spin_button->priv;
667 if (gtk_widget_get_realized (widget) && !gtk_widget_get_mapped (widget))
669 GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->map (widget);
670 gdk_window_show (priv->panel);
675 gtk_spin_button_unmap (GtkWidget *widget)
677 GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
678 GtkSpinButtonPrivate *priv = spin_button->priv;
680 if (gtk_widget_get_mapped (widget))
682 gtk_spin_button_stop_spinning (GTK_SPIN_BUTTON (widget));
684 gdk_window_hide (priv->panel);
685 GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->unmap (widget);
690 gtk_spin_button_realize (GtkWidget *widget)
692 GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
693 GtkSpinButtonPrivate *priv = spin_button->priv;
694 GtkStyleContext *context;
696 GtkAllocation allocation;
697 GtkRequisition requisition;
698 GdkWindowAttr attributes;
699 gint attributes_mask;
704 arrow_size = spin_button_get_arrow_size (spin_button);
706 gtk_widget_get_preferred_size (widget, &requisition, NULL);
707 gtk_widget_get_allocation (widget, &allocation);
709 gtk_widget_set_events (widget, gtk_widget_get_events (widget) |
710 GDK_KEY_RELEASE_MASK);
711 GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->realize (widget);
713 attributes.window_type = GDK_WINDOW_CHILD;
714 attributes.wclass = GDK_INPUT_ONLY;
715 attributes.visual = gtk_widget_get_visual (widget);
716 attributes.event_mask = gtk_widget_get_events (widget);
717 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK
718 | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK
719 | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK;
721 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
723 state = gtk_widget_get_state_flags (widget);
724 context = gtk_widget_get_style_context (widget);
725 gtk_style_context_get_padding (context, state, &padding);
727 attributes.x = allocation.x + allocation.width - arrow_size - (padding.left + padding.right);
728 attributes.y = allocation.y + (allocation.height - requisition.height) / 2;
729 attributes.width = arrow_size + padding.left + padding.right;
730 attributes.height = requisition.height;
732 priv->panel = gdk_window_new (gtk_widget_get_window (widget),
733 &attributes, attributes_mask);
734 gdk_window_set_user_data (priv->panel, widget);
737 g_signal_emit (spin_button, spinbutton_signals[OUTPUT], 0, &return_val);
738 if (return_val == FALSE)
739 gtk_spin_button_default_output (spin_button);
741 gtk_widget_queue_resize (GTK_WIDGET (spin_button));
745 gtk_spin_button_unrealize (GtkWidget *widget)
747 GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
748 GtkSpinButtonPrivate *priv = spin->priv;
750 GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->unrealize (widget);
754 gdk_window_set_user_data (priv->panel, NULL);
755 gdk_window_destroy (priv->panel);
761 compute_double_length (double val, int digits)
767 if (fabs (val) > 1.0)
768 a = floor (log10 (fabs (val))) + 1;
780 return a + digits + extra;
784 gtk_spin_button_get_preferred_width (GtkWidget *widget,
788 GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
789 GtkSpinButtonPrivate *priv = spin_button->priv;
790 GtkEntry *entry = GTK_ENTRY (widget);
791 GtkStyleContext *style_context;
795 style_context = gtk_widget_get_style_context (widget);
797 arrow_size = spin_button_get_arrow_size (spin_button);
799 GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->get_preferred_width (widget, minimum, natural);
801 if (gtk_entry_get_width_chars (entry) < 0)
803 PangoContext *context;
804 const PangoFontDescription *font_desc;
805 PangoFontMetrics *metrics;
811 gboolean interior_focus;
813 gint xborder, yborder;
814 GtkBorder inner_border;
816 gtk_widget_style_get (widget,
817 "interior-focus", &interior_focus,
818 "focus-line-width", &focus_width,
821 font_desc = gtk_style_context_get_font (style_context, 0);
823 context = gtk_widget_get_pango_context (widget);
824 metrics = pango_context_get_metrics (context, font_desc,
825 pango_context_get_language (context));
827 digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
828 digit_width = PANGO_SCALE *
829 ((digit_width + PANGO_SCALE - 1) / PANGO_SCALE);
831 pango_font_metrics_unref (metrics);
833 /* Get max of MIN_SPIN_BUTTON_WIDTH, size of upper, size of lower */
834 width = MIN_SPIN_BUTTON_WIDTH;
835 max_string_len = MAX (10, compute_double_length (1e9 * gtk_adjustment_get_step_increment (priv->adjustment),
838 string_len = compute_double_length (gtk_adjustment_get_upper (priv->adjustment),
840 w = PANGO_PIXELS (MIN (string_len, max_string_len) * digit_width);
841 width = MAX (width, w);
842 string_len = compute_double_length (gtk_adjustment_get_lower (priv->adjustment), priv->digits);
843 w = PANGO_PIXELS (MIN (string_len, max_string_len) * digit_width);
844 width = MAX (width, w);
846 _gtk_entry_get_borders (entry, &xborder, &yborder);
847 _gtk_entry_effective_inner_border (entry, &inner_border);
849 width += xborder * 2 + inner_border.left + inner_border.right;
855 gtk_style_context_get_padding (style_context,
856 gtk_widget_get_state_flags (widget),
859 *minimum += arrow_size + padding.left + padding.right;
860 *natural += arrow_size + padding.left + padding.right;
864 gtk_spin_button_size_allocate (GtkWidget *widget,
865 GtkAllocation *allocation)
867 GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
868 GtkSpinButtonPrivate *priv = spin->priv;
869 GtkAllocation panel_allocation;
870 GtkRequisition requisition;
871 GtkStyleContext *context;
877 arrow_size = spin_button_get_arrow_size (spin);
878 context = gtk_widget_get_style_context (widget);
879 state = gtk_widget_get_state_flags (widget);
881 gtk_style_context_get_padding (context, state, &padding);
882 panel_width = arrow_size + padding.left + padding.right;
884 gtk_widget_get_preferred_size (widget, &requisition, NULL);
886 gtk_widget_set_allocation (widget, allocation);
888 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
889 panel_allocation.x = allocation->x;
891 panel_allocation.x = allocation->x + allocation->width - panel_width;
893 panel_allocation.width = panel_width;
894 panel_allocation.height = MIN (requisition.height, allocation->height);
896 panel_allocation.y = allocation->y +
897 (allocation->height - requisition.height) / 2;
899 GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->size_allocate (widget, allocation);
901 if (gtk_widget_get_realized (widget))
903 gdk_window_move_resize (priv->panel,
906 panel_allocation.width,
907 panel_allocation.height);
910 gtk_widget_queue_draw (GTK_WIDGET (spin));
914 gtk_spin_button_draw (GtkWidget *widget,
917 GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
918 GtkSpinButtonPrivate *priv = spin->priv;
919 GtkStyleContext *context;
920 GtkStateFlags state = 0;
923 is_rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
924 context = gtk_widget_get_style_context (widget);
927 GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->draw (widget, cr);
930 state = gtk_widget_get_state_flags (widget);
932 gtk_style_context_save (context);
933 gtk_style_context_set_state (context, state);
934 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_ENTRY);
937 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_RIGHT);
939 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_LEFT);
941 gtk_cairo_transform_to_window (cr, widget, priv->panel);
943 if (gtk_entry_get_has_frame (GTK_ENTRY (widget)))
944 gtk_render_background (context, cr, 0, 0,
945 gdk_window_get_width (priv->panel),
946 gdk_window_get_height (priv->panel));
948 gtk_spin_button_draw_arrow (spin, context, cr, GTK_ARROW_UP);
949 gtk_spin_button_draw_arrow (spin, context, cr, GTK_ARROW_DOWN);
951 gtk_style_context_restore (context);
957 spin_button_at_limit (GtkSpinButton *spin_button,
960 GtkSpinButtonPrivate *priv = spin_button->priv;
961 GtkArrowType effective_arrow;
966 if (gtk_adjustment_get_step_increment (priv->adjustment) > 0)
967 effective_arrow = arrow;
969 effective_arrow = arrow == GTK_ARROW_UP ? GTK_ARROW_DOWN : GTK_ARROW_UP;
971 if (effective_arrow == GTK_ARROW_UP &&
972 (gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_value (priv->adjustment) <= EPSILON))
975 if (effective_arrow == GTK_ARROW_DOWN &&
976 (gtk_adjustment_get_value (priv->adjustment) - gtk_adjustment_get_lower (priv->adjustment) <= EPSILON))
983 gtk_spin_button_draw_arrow (GtkSpinButton *spin_button,
984 GtkStyleContext *context,
986 GtkArrowType arrow_type)
988 GtkSpinButtonPrivate *priv;
989 GtkJunctionSides junction;
994 gdouble size, width, height, x, y;
996 g_return_if_fail (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN);
998 gtk_style_context_save (context);
999 gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
1001 priv = spin_button->priv;
1002 widget = GTK_WIDGET (spin_button);
1003 junction = gtk_style_context_get_junction_sides (context);
1005 panel_height = gdk_window_get_height (priv->panel);
1007 if (spin_button_at_limit (spin_button, arrow_type))
1008 state = GTK_STATE_FLAG_INSENSITIVE;
1011 if (priv->click_child == arrow_type)
1012 state = GTK_STATE_ACTIVE;
1015 if (priv->in_child == arrow_type &&
1016 priv->click_child == NO_ARROW)
1017 state = GTK_STATE_FLAG_PRELIGHT;
1019 state = gtk_widget_get_state_flags (widget);
1023 /* first, draw the background and the frame */
1024 if (arrow_type == GTK_ARROW_UP)
1029 junction |= GTK_JUNCTION_BOTTOM;
1031 else if (arrow_type == GTK_ARROW_DOWN)
1034 y = panel_height / 2.0;
1036 junction |= GTK_JUNCTION_TOP;
1039 gtk_style_context_set_junction_sides (context, junction);
1040 gtk_style_context_set_state (context, state);
1042 height = panel_height / 2.0;
1043 width = gdk_window_get_width (priv->panel);
1044 gtk_render_background (context, cr,
1045 x, y, width, height);
1046 gtk_render_frame (context, cr,
1047 x, y, width, height);
1049 /* make the actual rendered arrow smaller than text size */
1050 size = spin_button_get_arrow_size (spin_button);
1051 size = MIN (size, width);
1054 x = (width - size) / 2.0;
1056 if (arrow_type == GTK_ARROW_UP)
1058 y = (height - size / 2.0) / 2.0;
1061 else if (arrow_type == GTK_ARROW_DOWN)
1063 y = height + ((height - size / 2.0) / 2.0) - size / 2.0;
1067 gtk_render_arrow (context, cr,
1070 gtk_style_context_restore (context);
1074 gtk_spin_button_enter_notify (GtkWidget *widget,
1075 GdkEventCrossing *event)
1077 GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
1078 GtkSpinButtonPrivate *priv = spin->priv;
1079 GtkRequisition requisition;
1081 if (event->window == priv->panel)
1087 device = gdk_event_get_device ((GdkEvent *) event);
1088 gdk_window_get_device_position (priv->panel, device, &x, &y, NULL);
1090 gtk_widget_get_preferred_size (widget, &requisition, NULL);
1092 if (y <= requisition.height / 2)
1093 priv->in_child = GTK_ARROW_UP;
1095 priv->in_child = GTK_ARROW_DOWN;
1097 gtk_widget_queue_draw (GTK_WIDGET (spin));
1100 return GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->enter_notify_event (widget, event);
1104 gtk_spin_button_leave_notify (GtkWidget *widget,
1105 GdkEventCrossing *event)
1107 GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
1108 GtkSpinButtonPrivate *priv = spin->priv;
1110 if (priv->in_child != NO_ARROW)
1112 priv->in_child = NO_ARROW;
1113 gtk_widget_queue_draw (GTK_WIDGET (spin));
1116 return GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->leave_notify_event (widget, event);
1120 gtk_spin_button_focus_out (GtkWidget *widget,
1121 GdkEventFocus *event)
1123 if (gtk_editable_get_editable (GTK_EDITABLE (widget)))
1124 gtk_spin_button_update (GTK_SPIN_BUTTON (widget));
1126 return GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->focus_out_event (widget, event);
1130 gtk_spin_button_grab_notify (GtkWidget *widget,
1131 gboolean was_grabbed)
1133 GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
1137 if (gtk_spin_button_stop_spinning (spin))
1138 gtk_widget_queue_draw (GTK_WIDGET (spin));
1143 gtk_spin_button_state_flags_changed (GtkWidget *widget,
1144 GtkStateFlags previous_state)
1146 GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
1148 if (!gtk_widget_is_sensitive (widget))
1150 if (gtk_spin_button_stop_spinning (spin))
1151 gtk_widget_queue_draw (GTK_WIDGET (spin));
1156 gtk_spin_button_style_updated (GtkWidget *widget)
1158 GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
1159 GtkSpinButtonPrivate *priv = spin->priv;
1161 if (gtk_widget_get_realized (widget))
1163 GtkStyleContext *context;
1165 context = gtk_widget_get_style_context (widget);
1166 gtk_style_context_set_background (context, priv->panel);
1169 GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->style_updated (widget);
1174 gtk_spin_button_scroll (GtkWidget *widget,
1175 GdkEventScroll *event)
1177 GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
1178 GtkSpinButtonPrivate *priv = spin->priv;
1180 if (event->direction == GDK_SCROLL_UP)
1182 if (!gtk_widget_has_focus (widget))
1183 gtk_widget_grab_focus (widget);
1184 gtk_spin_button_real_spin (spin, gtk_adjustment_get_step_increment (priv->adjustment));
1186 else if (event->direction == GDK_SCROLL_DOWN)
1188 if (!gtk_widget_has_focus (widget))
1189 gtk_widget_grab_focus (widget);
1190 gtk_spin_button_real_spin (spin, -gtk_adjustment_get_step_increment (priv->adjustment));
1199 gtk_spin_button_stop_spinning (GtkSpinButton *spin)
1201 GtkSpinButtonPrivate *priv = spin->priv;
1202 gboolean did_spin = FALSE;
1206 g_source_remove (priv->timer);
1208 priv->need_timer = FALSE;
1214 priv->timer_step = gtk_adjustment_get_step_increment (priv->adjustment);
1215 priv->timer_calls = 0;
1217 priv->click_child = NO_ARROW;
1223 start_spinning (GtkSpinButton *spin,
1224 GtkArrowType click_child,
1227 GtkSpinButtonPrivate *priv;
1229 g_return_if_fail (click_child == GTK_ARROW_UP || click_child == GTK_ARROW_DOWN);
1233 priv->click_child = click_child;
1237 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (spin));
1240 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
1242 priv->timer_step = step;
1243 priv->need_timer = TRUE;
1244 priv->timer = gdk_threads_add_timeout (timeout,
1245 (GSourceFunc) gtk_spin_button_timer,
1248 gtk_spin_button_real_spin (spin, click_child == GTK_ARROW_UP ? step : -step);
1250 gtk_widget_queue_draw (GTK_WIDGET (spin));
1254 gtk_spin_button_button_press (GtkWidget *widget,
1255 GdkEventButton *event)
1257 GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
1258 GtkSpinButtonPrivate *priv = spin->priv;
1262 if (event->window == priv->panel)
1264 GtkRequisition requisition;
1266 if (!gtk_widget_has_focus (widget))
1267 gtk_widget_grab_focus (widget);
1268 priv->button = event->button;
1270 if (gtk_editable_get_editable (GTK_EDITABLE (widget)))
1271 gtk_spin_button_update (spin);
1273 gtk_widget_get_preferred_size (widget, &requisition, NULL);
1275 if (event->y <= requisition.height / 2)
1277 if (event->button == 1)
1278 start_spinning (spin, GTK_ARROW_UP, gtk_adjustment_get_step_increment (priv->adjustment));
1279 else if (event->button == 2)
1280 start_spinning (spin, GTK_ARROW_UP, gtk_adjustment_get_page_increment (priv->adjustment));
1282 priv->click_child = GTK_ARROW_UP;
1286 if (event->button == 1)
1287 start_spinning (spin, GTK_ARROW_DOWN, gtk_adjustment_get_step_increment (priv->adjustment));
1288 else if (event->button == 2)
1289 start_spinning (spin, GTK_ARROW_DOWN, gtk_adjustment_get_page_increment (priv->adjustment));
1291 priv->click_child = GTK_ARROW_DOWN;
1296 return GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->button_press_event (widget, event);
1302 gtk_spin_button_button_release (GtkWidget *widget,
1303 GdkEventButton *event)
1305 GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
1306 GtkSpinButtonPrivate *priv = spin->priv;
1309 arrow_size = spin_button_get_arrow_size (spin);
1311 if (event->button == priv->button)
1313 int click_child = priv->click_child;
1315 gtk_spin_button_stop_spinning (spin);
1317 if (event->button == 3)
1319 GtkRequisition requisition;
1320 GtkStyleContext *context;
1321 GtkStateFlags state;
1324 gtk_widget_get_preferred_size (widget, &requisition, NULL);
1326 context = gtk_widget_get_style_context (widget);
1327 state = gtk_widget_get_state_flags (widget);
1328 gtk_style_context_get_padding (context, state, &padding);
1330 if (event->y >= 0 && event->x >= 0 &&
1331 event->y <= requisition.height &&
1332 event->x <= arrow_size + padding.left + padding.right)
1334 if (click_child == GTK_ARROW_UP &&
1335 event->y <= requisition.height / 2)
1339 diff = gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_value (priv->adjustment);
1341 gtk_spin_button_real_spin (spin, diff);
1343 else if (click_child == GTK_ARROW_DOWN &&
1344 event->y > requisition.height / 2)
1348 diff = gtk_adjustment_get_value (priv->adjustment) - gtk_adjustment_get_lower (priv->adjustment);
1350 gtk_spin_button_real_spin (spin, -diff);
1354 gtk_widget_queue_draw (GTK_WIDGET (spin));
1359 return GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->button_release_event (widget, event);
1363 gtk_spin_button_motion_notify (GtkWidget *widget,
1364 GdkEventMotion *event)
1366 GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
1367 GtkSpinButtonPrivate *priv = spin->priv;
1372 if (event->window == priv->panel)
1374 GtkRequisition requisition;
1377 gdk_event_request_motions (event);
1379 gtk_widget_get_preferred_size (widget, &requisition, NULL);
1381 if (y <= requisition.height / 2 &&
1382 priv->in_child == GTK_ARROW_DOWN)
1384 priv->in_child = GTK_ARROW_UP;
1385 gtk_widget_queue_draw (GTK_WIDGET (spin));
1387 else if (y > requisition.height / 2 &&
1388 priv->in_child == GTK_ARROW_UP)
1390 priv->in_child = GTK_ARROW_DOWN;
1391 gtk_widget_queue_draw (GTK_WIDGET (spin));
1397 return GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->motion_notify_event (widget, event);
1401 gtk_spin_button_timer (GtkSpinButton *spin_button)
1403 GtkSpinButtonPrivate *priv = spin_button->priv;
1404 gboolean retval = FALSE;
1408 if (priv->click_child == GTK_ARROW_UP)
1409 gtk_spin_button_real_spin (spin_button, priv->timer_step);
1411 gtk_spin_button_real_spin (spin_button, -priv->timer_step);
1413 if (priv->need_timer)
1415 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (spin_button));
1418 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
1420 priv->need_timer = FALSE;
1421 priv->timer = gdk_threads_add_timeout (timeout,
1422 (GSourceFunc) gtk_spin_button_timer,
1423 (gpointer) spin_button);
1427 if (priv->climb_rate > 0.0 && priv->timer_step
1428 < gtk_adjustment_get_page_increment (priv->adjustment))
1430 if (priv->timer_calls < MAX_TIMER_CALLS)
1431 priv->timer_calls++;
1434 priv->timer_calls = 0;
1435 priv->timer_step += priv->climb_rate;
1446 gtk_spin_button_value_changed (GtkAdjustment *adjustment,
1447 GtkSpinButton *spin_button)
1449 gboolean return_val;
1451 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
1454 g_signal_emit (spin_button, spinbutton_signals[OUTPUT], 0, &return_val);
1455 if (return_val == FALSE)
1456 gtk_spin_button_default_output (spin_button);
1458 g_signal_emit (spin_button, spinbutton_signals[VALUE_CHANGED], 0);
1460 gtk_widget_queue_draw (GTK_WIDGET (spin_button));
1462 g_object_notify (G_OBJECT (spin_button), "value");
1466 gtk_spin_button_real_change_value (GtkSpinButton *spin,
1467 GtkScrollType scroll)
1469 GtkSpinButtonPrivate *priv = spin->priv;
1472 /* When the key binding is activated, there may be an outstanding
1473 * value, so we first have to commit what is currently written in
1474 * the spin buttons text entry. See #106574
1476 gtk_spin_button_update (spin);
1478 old_value = gtk_adjustment_get_value (priv->adjustment);
1480 /* We don't test whether the entry is editable, since
1481 * this key binding conceptually corresponds to changing
1482 * the value with the buttons using the mouse, which
1483 * we allow for non-editable spin buttons.
1487 case GTK_SCROLL_STEP_BACKWARD:
1488 case GTK_SCROLL_STEP_DOWN:
1489 case GTK_SCROLL_STEP_LEFT:
1490 gtk_spin_button_real_spin (spin, -priv->timer_step);
1492 if (priv->climb_rate > 0.0 && priv->timer_step
1493 < gtk_adjustment_get_page_increment (priv->adjustment))
1495 if (priv->timer_calls < MAX_TIMER_CALLS)
1496 priv->timer_calls++;
1499 priv->timer_calls = 0;
1500 priv->timer_step += priv->climb_rate;
1505 case GTK_SCROLL_STEP_FORWARD:
1506 case GTK_SCROLL_STEP_UP:
1507 case GTK_SCROLL_STEP_RIGHT:
1508 gtk_spin_button_real_spin (spin, priv->timer_step);
1510 if (priv->climb_rate > 0.0 && priv->timer_step
1511 < gtk_adjustment_get_page_increment (priv->adjustment))
1513 if (priv->timer_calls < MAX_TIMER_CALLS)
1514 priv->timer_calls++;
1517 priv->timer_calls = 0;
1518 priv->timer_step += priv->climb_rate;
1523 case GTK_SCROLL_PAGE_BACKWARD:
1524 case GTK_SCROLL_PAGE_DOWN:
1525 case GTK_SCROLL_PAGE_LEFT:
1526 gtk_spin_button_real_spin (spin, -gtk_adjustment_get_page_increment (priv->adjustment));
1529 case GTK_SCROLL_PAGE_FORWARD:
1530 case GTK_SCROLL_PAGE_UP:
1531 case GTK_SCROLL_PAGE_RIGHT:
1532 gtk_spin_button_real_spin (spin, gtk_adjustment_get_page_increment (priv->adjustment));
1535 case GTK_SCROLL_START:
1537 gdouble diff = gtk_adjustment_get_value (priv->adjustment) - gtk_adjustment_get_lower (priv->adjustment);
1539 gtk_spin_button_real_spin (spin, -diff);
1543 case GTK_SCROLL_END:
1545 gdouble diff = gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_value (priv->adjustment);
1547 gtk_spin_button_real_spin (spin, diff);
1552 g_warning ("Invalid scroll type %d for GtkSpinButton::change-value", scroll);
1556 gtk_spin_button_update (spin);
1558 if (gtk_adjustment_get_value (priv->adjustment) == old_value)
1559 gtk_widget_error_bell (GTK_WIDGET (spin));
1563 gtk_spin_button_key_release (GtkWidget *widget,
1566 GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
1567 GtkSpinButtonPrivate *priv = spin->priv;
1569 /* We only get a release at the end of a key repeat run, so reset the timer_step */
1570 priv->timer_step = gtk_adjustment_get_step_increment (priv->adjustment);
1571 priv->timer_calls = 0;
1577 gtk_spin_button_snap (GtkSpinButton *spin_button,
1580 GtkSpinButtonPrivate *priv = spin_button->priv;
1584 inc = gtk_adjustment_get_step_increment (priv->adjustment);
1588 tmp = (val - gtk_adjustment_get_lower (priv->adjustment)) / inc;
1589 if (tmp - floor (tmp) < ceil (tmp) - tmp)
1590 val = gtk_adjustment_get_lower (priv->adjustment) + floor (tmp) * inc;
1592 val = gtk_adjustment_get_lower (priv->adjustment) + ceil (tmp) * inc;
1594 gtk_spin_button_set_value (spin_button, val);
1598 gtk_spin_button_activate (GtkEntry *entry)
1600 if (gtk_editable_get_editable (GTK_EDITABLE (entry)))
1601 gtk_spin_button_update (GTK_SPIN_BUTTON (entry));
1603 /* Chain up so that entry->activates_default is honored */
1604 GTK_ENTRY_CLASS (gtk_spin_button_parent_class)->activate (entry);
1608 gtk_spin_button_get_text_area_size (GtkEntry *entry,
1614 GtkStyleContext *context;
1615 GtkStateFlags state;
1621 GTK_ENTRY_CLASS (gtk_spin_button_parent_class)->get_text_area_size (entry, x, y, width, height);
1623 widget = GTK_WIDGET (entry);
1624 state = gtk_widget_get_state_flags (widget);
1625 context = gtk_widget_get_style_context (widget);
1626 gtk_style_context_get_padding (context, state, &padding);
1628 arrow_size = spin_button_get_arrow_size (GTK_SPIN_BUTTON (entry));
1629 panel_width = arrow_size + padding.left + padding.right;
1632 *width -= panel_width;
1634 if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL && x)
1639 gtk_spin_button_insert_text (GtkEditable *editable,
1640 const gchar *new_text,
1641 gint new_text_length,
1644 GtkEntry *entry = GTK_ENTRY (editable);
1645 GtkSpinButton *spin = GTK_SPIN_BUTTON (editable);
1646 GtkSpinButtonPrivate *priv = spin->priv;
1647 GtkEditableInterface *parent_editable_iface;
1649 parent_editable_iface = g_type_interface_peek (gtk_spin_button_parent_class,
1661 const gchar *entry_text;
1663 entry_length = gtk_entry_get_text_length (entry);
1664 entry_text = gtk_entry_get_text (entry);
1668 if (*(lc->negative_sign))
1669 neg_sign = *(lc->negative_sign);
1673 if (*(lc->positive_sign))
1674 pos_sign = *(lc->positive_sign);
1679 /* Workaround for bug caused by some Windows application messing
1680 * up the positive sign of the current locale, more specifically
1681 * HKEY_CURRENT_USER\Control Panel\International\sPositiveSign.
1682 * See bug #330743 and for instance
1683 * http://www.msnewsgroups.net/group/microsoft.public.dotnet.languages.csharp/topic36024.aspx
1685 * I don't know if the positive sign always gets bogusly set to
1686 * a digit when the above Registry value is corrupted as
1687 * described. (In my test case, it got set to "8", and in the
1688 * bug report above it presumably was set ot "0".) Probably it
1689 * might get set to almost anything? So how to distinguish a
1690 * bogus value from some correct one for some locale? That is
1691 * probably hard, but at least we should filter out the
1694 if (pos_sign >= '0' && pos_sign <= '9')
1698 for (sign=0, i=0; i<entry_length; i++)
1699 if ((entry_text[i] == neg_sign) ||
1700 (entry_text[i] == pos_sign))
1706 if (sign && !(*position))
1709 for (dotpos=-1, i=0; i<entry_length; i++)
1710 if (entry_text[i] == *(lc->decimal_point))
1716 if (dotpos > -1 && *position > dotpos &&
1717 (gint)priv->digits - entry_length
1718 + dotpos - new_text_length + 1 < 0)
1721 for (i = 0; i < new_text_length; i++)
1723 if (new_text[i] == neg_sign || new_text[i] == pos_sign)
1725 if (sign || (*position) || i)
1729 else if (new_text[i] == *(lc->decimal_point))
1731 if (!priv->digits || dotpos > -1 ||
1732 (new_text_length - 1 - i + entry_length
1733 - *position > (gint)priv->digits))
1735 dotpos = *position + i;
1737 else if (new_text[i] < 0x30 || new_text[i] > 0x39)
1742 parent_editable_iface->insert_text (editable, new_text,
1743 new_text_length, position);
1747 gtk_spin_button_real_spin (GtkSpinButton *spin_button,
1750 GtkSpinButtonPrivate *priv = spin_button->priv;
1751 GtkAdjustment *adjustment;
1752 gdouble new_value = 0.0;
1753 gboolean wrapped = FALSE;
1755 adjustment = priv->adjustment;
1757 new_value = gtk_adjustment_get_value (adjustment) + increment;
1763 if (fabs (gtk_adjustment_get_value (adjustment) - gtk_adjustment_get_upper (adjustment)) < EPSILON)
1765 new_value = gtk_adjustment_get_lower (adjustment);
1768 else if (new_value > gtk_adjustment_get_upper (adjustment))
1769 new_value = gtk_adjustment_get_upper (adjustment);
1772 new_value = MIN (new_value, gtk_adjustment_get_upper (adjustment));
1774 else if (increment < 0)
1778 if (fabs (gtk_adjustment_get_value (adjustment) - gtk_adjustment_get_lower (adjustment)) < EPSILON)
1780 new_value = gtk_adjustment_get_upper (adjustment);
1783 else if (new_value < gtk_adjustment_get_lower (adjustment))
1784 new_value = gtk_adjustment_get_lower (adjustment);
1787 new_value = MAX (new_value, gtk_adjustment_get_lower (adjustment));
1790 if (fabs (new_value - gtk_adjustment_get_value (adjustment)) > EPSILON)
1791 gtk_adjustment_set_value (adjustment, new_value);
1794 g_signal_emit (spin_button, spinbutton_signals[WRAPPED], 0);
1796 gtk_widget_queue_draw (GTK_WIDGET (spin_button));
1800 gtk_spin_button_default_input (GtkSpinButton *spin_button,
1805 *new_val = g_strtod (gtk_entry_get_text (GTK_ENTRY (spin_button)), &err);
1807 return GTK_INPUT_ERROR;
1813 gtk_spin_button_default_output (GtkSpinButton *spin_button)
1815 GtkSpinButtonPrivate *priv = spin_button->priv;
1817 gchar *buf = g_strdup_printf ("%0.*f", priv->digits, gtk_adjustment_get_value (priv->adjustment));
1819 if (strcmp (buf, gtk_entry_get_text (GTK_ENTRY (spin_button))))
1820 gtk_entry_set_text (GTK_ENTRY (spin_button), buf);
1826 /***********************************************************
1827 ***********************************************************
1828 *** Public interface ***
1829 ***********************************************************
1830 ***********************************************************/
1834 * gtk_spin_button_configure:
1835 * @spin_button: a #GtkSpinButton
1836 * @adjustment: (allow-none): a #GtkAdjustment
1837 * @climb_rate: the new climb rate
1838 * @digits: the number of decimal places to display in the spin button
1840 * Changes the properties of an existing spin button. The adjustment,
1841 * climb rate, and number of decimal places are all changed accordingly,
1842 * after this function call.
1845 gtk_spin_button_configure (GtkSpinButton *spin_button,
1846 GtkAdjustment *adjustment,
1850 GtkSpinButtonPrivate *priv;
1852 g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
1854 priv = spin_button->priv;
1857 gtk_spin_button_set_adjustment (spin_button, adjustment);
1859 adjustment = priv->adjustment;
1861 g_object_freeze_notify (G_OBJECT (spin_button));
1862 if (priv->digits != digits)
1864 priv->digits = digits;
1865 g_object_notify (G_OBJECT (spin_button), "digits");
1868 if (priv->climb_rate != climb_rate)
1870 priv->climb_rate = climb_rate;
1871 g_object_notify (G_OBJECT (spin_button), "climb-rate");
1873 g_object_thaw_notify (G_OBJECT (spin_button));
1875 gtk_adjustment_value_changed (adjustment);
1879 * gtk_spin_button_new:
1880 * @adjustment: (allow-none): the #GtkAdjustment object that this spin
1881 * button should use, or %NULL
1882 * @climb_rate: specifies how much the spin button changes when an arrow
1884 * @digits: the number of decimal places to display
1886 * Creates a new #GtkSpinButton.
1888 * Returns: The new spin button as a #GtkWidget
1891 gtk_spin_button_new (GtkAdjustment *adjustment,
1895 GtkSpinButton *spin;
1898 g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), NULL);
1900 spin = g_object_new (GTK_TYPE_SPIN_BUTTON, NULL);
1902 gtk_spin_button_configure (spin, adjustment, climb_rate, digits);
1904 return GTK_WIDGET (spin);
1908 * gtk_spin_button_new_with_range:
1909 * @min: Minimum allowable value
1910 * @max: Maximum allowable value
1911 * @step: Increment added or subtracted by spinning the widget
1913 * This is a convenience constructor that allows creation of a numeric
1914 * #GtkSpinButton without manually creating an adjustment. The value is
1915 * initially set to the minimum value and a page increment of 10 * @step
1916 * is the default. The precision of the spin button is equivalent to the
1917 * precision of @step.
1919 * Note that the way in which the precision is derived works best if @step
1920 * is a power of ten. If the resulting precision is not suitable for your
1921 * needs, use gtk_spin_button_set_digits() to correct it.
1923 * Return value: The new spin button as a #GtkWidget
1926 gtk_spin_button_new_with_range (gdouble min,
1930 GtkAdjustment *adjustment;
1931 GtkSpinButton *spin;
1934 g_return_val_if_fail (min <= max, NULL);
1935 g_return_val_if_fail (step != 0.0, NULL);
1937 spin = g_object_new (GTK_TYPE_SPIN_BUTTON, NULL);
1939 adjustment = gtk_adjustment_new (min, min, max, step, 10 * step, 0);
1941 if (fabs (step) >= 1.0 || step == 0.0)
1944 digits = abs ((gint) floor (log10 (fabs (step))));
1945 if (digits > MAX_DIGITS)
1946 digits = MAX_DIGITS;
1949 gtk_spin_button_configure (spin, adjustment, step, digits);
1951 gtk_spin_button_set_numeric (spin, TRUE);
1953 return GTK_WIDGET (spin);
1956 /* Callback used when the spin button's adjustment changes.
1957 * We need to redraw the arrows when the adjustment's range
1958 * changes, and reevaluate our size request.
1961 adjustment_changed_cb (GtkAdjustment *adjustment, gpointer data)
1963 GtkSpinButton *spin_button = GTK_SPIN_BUTTON (data);
1964 GtkSpinButtonPrivate *priv = spin_button->priv;
1966 priv->timer_step = gtk_adjustment_get_step_increment (priv->adjustment);
1967 gtk_widget_queue_resize (GTK_WIDGET (spin_button));
1971 * gtk_spin_button_set_adjustment:
1972 * @spin_button: a #GtkSpinButton
1973 * @adjustment: a #GtkAdjustment to replace the existing adjustment
1975 * Replaces the #GtkAdjustment associated with @spin_button.
1978 gtk_spin_button_set_adjustment (GtkSpinButton *spin_button,
1979 GtkAdjustment *adjustment)
1981 GtkSpinButtonPrivate *priv;
1983 g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
1985 priv = spin_button->priv;
1987 if (priv->adjustment != adjustment)
1989 if (priv->adjustment)
1991 g_signal_handlers_disconnect_by_func (priv->adjustment,
1992 gtk_spin_button_value_changed,
1994 g_signal_handlers_disconnect_by_func (priv->adjustment,
1995 adjustment_changed_cb,
1997 g_object_unref (priv->adjustment);
1999 priv->adjustment = adjustment;
2002 g_object_ref_sink (adjustment);
2003 g_signal_connect (adjustment, "value-changed",
2004 G_CALLBACK (gtk_spin_button_value_changed),
2006 g_signal_connect (adjustment, "changed",
2007 G_CALLBACK (adjustment_changed_cb),
2009 priv->timer_step = gtk_adjustment_get_step_increment (priv->adjustment);
2012 gtk_widget_queue_resize (GTK_WIDGET (spin_button));
2015 g_object_notify (G_OBJECT (spin_button), "adjustment");
2019 * gtk_spin_button_get_adjustment:
2020 * @spin_button: a #GtkSpinButton
2022 * Get the adjustment associated with a #GtkSpinButton
2024 * Return value: (transfer none): the #GtkAdjustment of @spin_button
2027 gtk_spin_button_get_adjustment (GtkSpinButton *spin_button)
2029 g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), NULL);
2031 return spin_button->priv->adjustment;
2035 * gtk_spin_button_set_digits:
2036 * @spin_button: a #GtkSpinButton
2037 * @digits: the number of digits after the decimal point to be displayed for the spin button's value
2039 * Set the precision to be displayed by @spin_button. Up to 20 digit precision
2043 gtk_spin_button_set_digits (GtkSpinButton *spin_button,
2046 GtkSpinButtonPrivate *priv;
2048 g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
2050 priv = spin_button->priv;
2052 if (priv->digits != digits)
2054 priv->digits = digits;
2055 gtk_spin_button_value_changed (priv->adjustment, spin_button);
2056 g_object_notify (G_OBJECT (spin_button), "digits");
2058 /* since lower/upper may have changed */
2059 gtk_widget_queue_resize (GTK_WIDGET (spin_button));
2064 * gtk_spin_button_get_digits:
2065 * @spin_button: a #GtkSpinButton
2067 * Fetches the precision of @spin_button. See gtk_spin_button_set_digits().
2069 * Returns: the current precision
2072 gtk_spin_button_get_digits (GtkSpinButton *spin_button)
2074 g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), 0);
2076 return spin_button->priv->digits;
2080 * gtk_spin_button_set_increments:
2081 * @spin_button: a #GtkSpinButton
2082 * @step: increment applied for a button 1 press.
2083 * @page: increment applied for a button 2 press.
2085 * Sets the step and page increments for spin_button. This affects how
2086 * quickly the value changes when the spin button's arrows are activated.
2089 gtk_spin_button_set_increments (GtkSpinButton *spin_button,
2093 GtkSpinButtonPrivate *priv;
2095 g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
2097 priv = spin_button->priv;
2099 gtk_adjustment_configure (priv->adjustment,
2100 gtk_adjustment_get_value (priv->adjustment),
2101 gtk_adjustment_get_lower (priv->adjustment),
2102 gtk_adjustment_get_upper (priv->adjustment),
2105 gtk_adjustment_get_page_size (priv->adjustment));
2109 * gtk_spin_button_get_increments:
2110 * @spin_button: a #GtkSpinButton
2111 * @step: (out) (allow-none): location to store step increment, or %NULL
2112 * @page: (out) (allow-none): location to store page increment, or %NULL
2114 * Gets the current step and page the increments used by @spin_button. See
2115 * gtk_spin_button_set_increments().
2118 gtk_spin_button_get_increments (GtkSpinButton *spin_button,
2122 GtkSpinButtonPrivate *priv;
2124 g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
2126 priv = spin_button->priv;
2129 *step = gtk_adjustment_get_step_increment (priv->adjustment);
2131 *page = gtk_adjustment_get_page_increment (priv->adjustment);
2135 * gtk_spin_button_set_range:
2136 * @spin_button: a #GtkSpinButton
2137 * @min: minimum allowable value
2138 * @max: maximum allowable value
2140 * Sets the minimum and maximum allowable values for @spin_button.
2143 gtk_spin_button_set_range (GtkSpinButton *spin_button,
2147 GtkAdjustment *adjustment;
2149 g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
2151 adjustment = spin_button->priv->adjustment;
2153 gtk_adjustment_configure (adjustment,
2154 CLAMP (gtk_adjustment_get_value (adjustment), min, max),
2157 gtk_adjustment_get_step_increment (adjustment),
2158 gtk_adjustment_get_page_increment (adjustment),
2159 gtk_adjustment_get_page_size (adjustment));
2163 * gtk_spin_button_get_range:
2164 * @spin_button: a #GtkSpinButton
2165 * @min: (out) (allow-none): location to store minimum allowed value, or %NULL
2166 * @max: (out) (allow-none): location to store maximum allowed value, or %NULL
2168 * Gets the range allowed for @spin_button.
2169 * See gtk_spin_button_set_range().
2172 gtk_spin_button_get_range (GtkSpinButton *spin_button,
2176 GtkSpinButtonPrivate *priv;
2178 g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
2180 priv = spin_button->priv;
2183 *min = gtk_adjustment_get_lower (priv->adjustment);
2185 *max = gtk_adjustment_get_upper (priv->adjustment);
2189 * gtk_spin_button_get_value:
2190 * @spin_button: a #GtkSpinButton
2192 * Get the value in the @spin_button.
2194 * Return value: the value of @spin_button
2197 gtk_spin_button_get_value (GtkSpinButton *spin_button)
2199 g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), 0.0);
2201 return gtk_adjustment_get_value (spin_button->priv->adjustment);
2205 * gtk_spin_button_get_value_as_int:
2206 * @spin_button: a #GtkSpinButton
2208 * Get the value @spin_button represented as an integer.
2210 * Return value: the value of @spin_button
2213 gtk_spin_button_get_value_as_int (GtkSpinButton *spin_button)
2215 GtkSpinButtonPrivate *priv;
2218 g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), 0);
2220 priv = spin_button->priv;
2222 val = gtk_adjustment_get_value (priv->adjustment);
2223 if (val - floor (val) < ceil (val) - val)
2230 * gtk_spin_button_set_value:
2231 * @spin_button: a #GtkSpinButton
2232 * @value: the new value
2234 * Sets the value of @spin_button.
2237 gtk_spin_button_set_value (GtkSpinButton *spin_button,
2240 GtkSpinButtonPrivate *priv;
2242 g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
2244 priv = spin_button->priv;
2246 if (fabs (value - gtk_adjustment_get_value (priv->adjustment)) > EPSILON)
2247 gtk_adjustment_set_value (priv->adjustment, value);
2250 gint return_val = FALSE;
2251 g_signal_emit (spin_button, spinbutton_signals[OUTPUT], 0, &return_val);
2252 if (return_val == FALSE)
2253 gtk_spin_button_default_output (spin_button);
2258 * gtk_spin_button_set_update_policy:
2259 * @spin_button: a #GtkSpinButton
2260 * @policy: a #GtkSpinButtonUpdatePolicy value
2262 * Sets the update behavior of a spin button.
2263 * This determines wether the spin button is always updated
2264 * or only when a valid value is set.
2267 gtk_spin_button_set_update_policy (GtkSpinButton *spin_button,
2268 GtkSpinButtonUpdatePolicy policy)
2270 GtkSpinButtonPrivate *priv;
2272 g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
2274 priv = spin_button->priv;
2276 if (priv->update_policy != policy)
2278 priv->update_policy = policy;
2279 g_object_notify (G_OBJECT (spin_button), "update-policy");
2284 * gtk_spin_button_get_update_policy:
2285 * @spin_button: a #GtkSpinButton
2287 * Gets the update behavior of a spin button.
2288 * See gtk_spin_button_set_update_policy().
2290 * Return value: the current update policy
2292 GtkSpinButtonUpdatePolicy
2293 gtk_spin_button_get_update_policy (GtkSpinButton *spin_button)
2295 g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), GTK_UPDATE_ALWAYS);
2297 return spin_button->priv->update_policy;
2301 * gtk_spin_button_set_numeric:
2302 * @spin_button: a #GtkSpinButton
2303 * @numeric: flag indicating if only numeric entry is allowed
2305 * Sets the flag that determines if non-numeric text can be typed
2306 * into the spin button.
2309 gtk_spin_button_set_numeric (GtkSpinButton *spin_button,
2312 GtkSpinButtonPrivate *priv;
2314 g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
2316 priv = spin_button->priv;
2318 numeric = numeric != FALSE;
2320 if (priv->numeric != numeric)
2322 priv->numeric = numeric;
2323 g_object_notify (G_OBJECT (spin_button), "numeric");
2328 * gtk_spin_button_get_numeric:
2329 * @spin_button: a #GtkSpinButton
2331 * Returns whether non-numeric text can be typed into the spin button.
2332 * See gtk_spin_button_set_numeric().
2334 * Return value: %TRUE if only numeric text can be entered
2337 gtk_spin_button_get_numeric (GtkSpinButton *spin_button)
2339 g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), FALSE);
2341 return spin_button->priv->numeric;
2345 * gtk_spin_button_set_wrap:
2346 * @spin_button: a #GtkSpinButton
2347 * @wrap: a flag indicating if wrapping behavior is performed
2349 * Sets the flag that determines if a spin button value wraps
2350 * around to the opposite limit when the upper or lower limit
2351 * of the range is exceeded.
2354 gtk_spin_button_set_wrap (GtkSpinButton *spin_button,
2357 GtkSpinButtonPrivate *priv;
2359 g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
2361 priv = spin_button->priv;
2363 wrap = wrap != FALSE;
2365 if (priv->wrap != wrap)
2369 g_object_notify (G_OBJECT (spin_button), "wrap");
2374 * gtk_spin_button_get_wrap:
2375 * @spin_button: a #GtkSpinButton
2377 * Returns whether the spin button's value wraps around to the
2378 * opposite limit when the upper or lower limit of the range is
2379 * exceeded. See gtk_spin_button_set_wrap().
2381 * Return value: %TRUE if the spin button wraps around
2384 gtk_spin_button_get_wrap (GtkSpinButton *spin_button)
2386 g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), FALSE);
2388 return spin_button->priv->wrap;
2392 spin_button_get_arrow_size (GtkSpinButton *spin_button)
2394 const PangoFontDescription *font_desc;
2395 GtkStyleContext *context;
2399 /* FIXME: use getter */
2400 context = gtk_widget_get_style_context (GTK_WIDGET (spin_button));
2401 font_desc = gtk_style_context_get_font (context, 0);
2403 size = pango_font_description_get_size (font_desc);
2404 arrow_size = MAX (PANGO_PIXELS (size), MIN_ARROW_WIDTH);
2406 return arrow_size - arrow_size % 2; /* force even */
2410 * gtk_spin_button_set_snap_to_ticks:
2411 * @spin_button: a #GtkSpinButton
2412 * @snap_to_ticks: a flag indicating if invalid values should be corrected
2414 * Sets the policy as to whether values are corrected to the
2415 * nearest step increment when a spin button is activated after
2416 * providing an invalid value.
2419 gtk_spin_button_set_snap_to_ticks (GtkSpinButton *spin_button,
2420 gboolean snap_to_ticks)
2422 GtkSpinButtonPrivate *priv;
2425 g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
2427 priv = spin_button->priv;
2429 new_val = (snap_to_ticks != 0);
2431 if (new_val != priv->snap_to_ticks)
2433 priv->snap_to_ticks = new_val;
2434 if (new_val && gtk_editable_get_editable (GTK_EDITABLE (spin_button)))
2435 gtk_spin_button_update (spin_button);
2437 g_object_notify (G_OBJECT (spin_button), "snap-to-ticks");
2442 * gtk_spin_button_get_snap_to_ticks:
2443 * @spin_button: a #GtkSpinButton
2445 * Returns whether the values are corrected to the nearest step.
2446 * See gtk_spin_button_set_snap_to_ticks().
2448 * Return value: %TRUE if values are snapped to the nearest step
2451 gtk_spin_button_get_snap_to_ticks (GtkSpinButton *spin_button)
2453 g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), FALSE);
2455 return spin_button->priv->snap_to_ticks;
2459 * gtk_spin_button_spin:
2460 * @spin_button: a #GtkSpinButton
2461 * @direction: a #GtkSpinType indicating the direction to spin
2462 * @increment: step increment to apply in the specified direction
2464 * Increment or decrement a spin button's value in a specified
2465 * direction by a specified amount.
2468 gtk_spin_button_spin (GtkSpinButton *spin_button,
2469 GtkSpinType direction,
2472 GtkSpinButtonPrivate *priv;
2473 GtkAdjustment *adjustment;
2476 g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
2478 priv = spin_button->priv;
2480 adjustment = priv->adjustment;
2482 /* for compatibility with the 1.0.x version of this function */
2483 if (increment != 0 && increment != gtk_adjustment_get_step_increment (adjustment) &&
2484 (direction == GTK_SPIN_STEP_FORWARD ||
2485 direction == GTK_SPIN_STEP_BACKWARD))
2487 if (direction == GTK_SPIN_STEP_BACKWARD && increment > 0)
2488 increment = -increment;
2489 direction = GTK_SPIN_USER_DEFINED;
2494 case GTK_SPIN_STEP_FORWARD:
2496 gtk_spin_button_real_spin (spin_button, gtk_adjustment_get_step_increment (adjustment));
2499 case GTK_SPIN_STEP_BACKWARD:
2501 gtk_spin_button_real_spin (spin_button, -gtk_adjustment_get_step_increment (adjustment));
2504 case GTK_SPIN_PAGE_FORWARD:
2506 gtk_spin_button_real_spin (spin_button, gtk_adjustment_get_page_increment (adjustment));
2509 case GTK_SPIN_PAGE_BACKWARD:
2511 gtk_spin_button_real_spin (spin_button, -gtk_adjustment_get_page_increment (adjustment));
2516 diff = gtk_adjustment_get_value (adjustment) - gtk_adjustment_get_lower (adjustment);
2518 gtk_spin_button_real_spin (spin_button, -diff);
2523 diff = gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_value (adjustment);
2525 gtk_spin_button_real_spin (spin_button, diff);
2528 case GTK_SPIN_USER_DEFINED:
2531 gtk_spin_button_real_spin (spin_button, increment);
2540 * gtk_spin_button_update:
2541 * @spin_button: a #GtkSpinButton
2543 * Manually force an update of the spin button.
2546 gtk_spin_button_update (GtkSpinButton *spin_button)
2548 GtkSpinButtonPrivate *priv;
2553 g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
2555 priv = spin_button->priv;
2558 g_signal_emit (spin_button, spinbutton_signals[INPUT], 0, &val, &return_val);
2559 if (return_val == FALSE)
2561 return_val = gtk_spin_button_default_input (spin_button, &val);
2562 error = (return_val == GTK_INPUT_ERROR);
2564 else if (return_val == GTK_INPUT_ERROR)
2567 gtk_widget_queue_draw (GTK_WIDGET (spin_button));
2569 if (priv->update_policy == GTK_UPDATE_ALWAYS)
2571 if (val < gtk_adjustment_get_lower (priv->adjustment))
2572 val = gtk_adjustment_get_lower (priv->adjustment);
2573 else if (val > gtk_adjustment_get_upper (priv->adjustment))
2574 val = gtk_adjustment_get_upper (priv->adjustment);
2576 else if ((priv->update_policy == GTK_UPDATE_IF_VALID) &&
2578 val < gtk_adjustment_get_lower (priv->adjustment) ||
2579 val > gtk_adjustment_get_upper (priv->adjustment)))
2581 gtk_spin_button_value_changed (priv->adjustment, spin_button);
2585 if (priv->snap_to_ticks)
2586 gtk_spin_button_snap (spin_button, val);
2588 gtk_spin_button_set_value (spin_button, val);
2592 _gtk_spin_button_get_panel (GtkSpinButton *spin_button)
2594 return spin_button->priv->panel;