From 85fe6cb2c414c57c174fee4cea7fcb05c617fc0e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 2 Jan 2011 23:30:02 -0500 Subject: [PATCH] Move GtkSpinButton docs inline ...and modernize the examples at the same time. This fixes a problem pointed out in bug 638193. --- docs/reference/gtk/tmpl/gtkspinbutton.sgml | 482 --------- gtk/gtkspinbutton.c | 1142 +++++++++++--------- gtk/gtkspinbutton.h | 38 +- 3 files changed, 669 insertions(+), 993 deletions(-) delete mode 100644 docs/reference/gtk/tmpl/gtkspinbutton.sgml diff --git a/docs/reference/gtk/tmpl/gtkspinbutton.sgml b/docs/reference/gtk/tmpl/gtkspinbutton.sgml deleted file mode 100644 index b6c899c5f3..0000000000 --- a/docs/reference/gtk/tmpl/gtkspinbutton.sgml +++ /dev/null @@ -1,482 +0,0 @@ - -GtkSpinButton - - -Retrieve an integer or floating-point number from the user - - - -A #GtkSpinButton is an ideal way to allow the user to set the value of some -attribute. Rather than having to directly type a number into a #GtkEntry, -#GtkSpinButton allows the user to click on one of two arrows to increment or -decrement the displayed value. A value can still be typed in, with the bonus -that it can be checked to ensure it is in a given range. - - -The main properties of a #GtkSpinButton are through a #GtkAdjustment. See the -#GtkAdjustment section for more details about an adjustment's properties. - - - -Using a <structname>GtkSpinButton</structname> to get an integer. - - -/* Provides a function to retrieve an integer value from a GtkSpinButton - * and creates a spin button to model percentage values. - */ - -gint grab_int_value (GtkSpinButton *a_spinner, gpointer user_data) { - return gtk_spin_button_get_value_as_int (a_spinner); -} - -void create_integer_spin_button (void) { - - GtkWidget *window, *spinner; - GtkAdjustment *spinner_adj; - - spinner_adj = gtk_adjustment_new (50.0, 0.0, 100.0, 1.0, 5.0, 5.0); - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_container_set_border_width (GTK_CONTAINER (window), 5); - - /* creates the spinner, with no decimal places */ - spinner = gtk_spin_button_new (spinner_adj, 1.0, 0); - gtk_container_add (GTK_CONTAINER (window), spinner); - - gtk_widget_show_all (window); - return; -} - - - - - - - -Using a <structname>GtkSpinButton</structname> to get a floating point value. - - -/* Provides a function to retrieve a floating point value from a - * GtkSpinButton, and creates a high precision spin button. - */ - -gfloat grab_int_value (GtkSpinButton *a_spinner, gpointer user_data) { - return gtk_spin_button_get_value (a_spinner); -} - -void create_floating_spin_button (void) { - - GtkWidget *window, *spinner; - GtkAdjustment *spinner_adj; - - spinner_adj = gtk_adjustment_new (2.500, 0.0, 5.0, 0.001, 0.1, 0.1); - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_container_set_border_width (GTK_CONTAINER (window), 5); - - /* creates the spinner, with three decimal places */ - spinner = gtk_spin_button_new (spinner_adj, 0.001, 3); - gtk_container_add (GTK_CONTAINER (window), spinner); - - gtk_widget_show_all (window); - return; -} - - - - - - - - - -#GtkEntry -retrieve text rather than numbers. - - - - - - - - - - - - -entry is the #GtkEntry part of the #GtkSpinButton -widget, and can be used accordingly. All other fields contain private data -and should only be modified using the functions below. - - - - - - - - -@spinbutton: the object which received the signal. -@arg1: - - - - - - -@spinbutton: the object which received the signal. -@arg1: -@Returns: - - - - - - -@spinbutton: the object which received the signal. -@Returns: - - - - - - -@spinbutton: the object which received the signal. - - - - - - -@spinbutton: the object which received the signal. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -the type of border that surrounds the arrows of a spin button. - - - - - - - - - -GTK_UPDATE_ALWAYS -When refreshing your #GtkSpinButton, the value is always displayed. - - -GTK_UPDATE_IF_VALID -When refreshing your #GtkSpinButton, the value is only displayed if it is valid within the bounds of the spin button's #GtkAdjustment. - - - - -@GTK_UPDATE_ALWAYS: -@GTK_UPDATE_IF_VALID: - - - - - - - - -GTK_SPIN_STEP_FORWARD, -GTK_SPIN_STEP_BACKWARD, -GTK_SPIN_PAGE_FORWARD, -GTK_SPIN_PAGE_BACKWARD -These values spin a #GtkSpinButton by the relevant values of the spin button's #GtkAdjustment. - - -GTK_SPIN_HOME, -GTK_SPIN_END -These set the spin button's value to the minimum or maxmimum possible values, (set by its #GtkAdjustment), respectively. - - -GTK_SPIN_USER_DEFINED -The programmer must specify the exact amount to spin the #GtkSpinButton. - - - - -@GTK_SPIN_STEP_FORWARD: -@GTK_SPIN_STEP_BACKWARD: -@GTK_SPIN_PAGE_FORWARD: -@GTK_SPIN_PAGE_BACKWARD: -@GTK_SPIN_HOME: -@GTK_SPIN_END: -@GTK_SPIN_USER_DEFINED: - - - - - - -@spin_button: -@adjustment: -@climb_rate: -@digits: - - - - -Creates a new #GtkSpinButton. - - -@adjustment: the #GtkAdjustment object that this spin button should use. -@climb_rate: specifies how much the spin button changes when an arrow is clicked on. -@digits: the number of decimal places to display. -@Returns: The new spin button as a #GtkWidget. - - - - - - - -@min: -@max: -@step: -@Returns: - - - - - - - -@spin_button: -@adjustment: - - - - - - - -@spin_button: -@Returns: - - - - - - - -@spin_button: -@digits: - - - - - - - -@spin_button: -@step: -@page: - - - - - - - -@spin_button: -@min: -@max: - - - - - - - -@spin_button: -@Returns: - - - - - - - -@spin_button: -@value: - - - - - - - -@spin_button: -@policy: - - - - - - - -@spin_button: -@numeric: - - - - - - - -@spin_button: -@direction: -@increment: - - - - - - - -@spin_button: -@wrap: - - - - - - - -@spin_button: -@snap_to_ticks: - - - - - - - -@spin_button: - - - - - - - -@spin_button: -@Returns: - - - - - - - -@spin_button: -@step: -@page: - - - - - - - -@spin_button: -@Returns: - - - - - - - -@spin_button: -@min: -@max: - - - - - - - -@spin_button: -@Returns: - - - - - - - -@spin_button: -@Returns: - - - - - - - -@spin_button: -@Returns: - - - - - - - -@spin_button: -@Returns: - - - - - - - - - diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c index 492aeae7be..3849ff9d4a 100644 --- a/gtk/gtkspinbutton.c +++ b/gtk/gtkspinbutton.c @@ -24,7 +24,7 @@ * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. + * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ #include "config.h" @@ -46,10 +46,99 @@ #define MIN_SPIN_BUTTON_WIDTH 30 #define MAX_TIMER_CALLS 5 #define EPSILON 1e-10 -#define MAX_DIGITS 20 +#define MAX_DIGITS 20 #define MIN_ARROW_WIDTH 6 +/** + * SECTION:gtkspinbutton + * @Title: GtkSpinButton + * @Short_description: Retrieve an integer or floating-point number from + * the user + * @See_also: #GtkEntry + * + * A #GtkSpinButton is an ideal way to allow the user to set the value of + * some attribute. Rather than having to directly type a number into a + * #GtkEntry, GtkSpinButton allows the user to click on one of two arrows + * to increment or decrement the displayed value. A value can still be + * typed in, with the bonus that it can be checked to ensure it is in a + * given range. + * + * The main properties of a GtkSpinButton are through an adjustment. + * See the #GtkAdjustment section for more details about an adjustment's + * properties. + * + * + * Using a GtkSpinButton to get an integer + * + * /* Provides a function to retrieve an integer value from a + * * GtkSpinButton and creates a spin button to model percentage + * * values. + * */ + * + * gint + * grab_int_value (GtkSpinButton *button, + * gpointer user_data) + * { + * return gtk_spin_button_get_value_as_int (button); + * } + * + * void + * create_integer_spin_button (void) + * { + * + * GtkWidget *window, *button; + * GtkAdjustment *adj; + * + * adj = gtk_adjustment_new (50.0, 0.0, 100.0, 1.0, 5.0, 0.0); + * + * window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + * gtk_container_set_border_width (GTK_CONTAINER (window), 5); + * + * /* creates the spinbutton, with no decimal places */ + * button = gtk_spin_button_new (adj, 1.0, 0); + * gtk_container_add (GTK_CONTAINER (window), button); + * + * gtk_widget_show_all (window); + * } + * + * + * + * + * Using a GtkSpinButton to get a floating point value + * + * /* Provides a function to retrieve a floating point value from a + * * GtkSpinButton, and creates a high precision spin button. + * */ + * + * gfloat + * grab_float_value (GtkSpinButton *button, + * gpointer user_data) + * { + * return gtk_spin_button_get_value (button); + * } + * + * void + * create_floating_spin_button (void) + * { + * GtkWidget *window, *button; + * GtkAdjustment *adj; + * + * adj = gtk_adjustment_new (2.500, 0.0, 5.0, 0.001, 0.1, 0.0); + * + * window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + * gtk_container_set_border_width (GTK_CONTAINER (window), 5); + * + * /* creates the spinbutton, with three decimal places */ + * button = gtk_spin_button_new (adj, 0.001, 3); + * gtk_container_add (GTK_CONTAINER (window), button); + * + * gtk_widget_show_all (window); + * } + * + * + */ + struct _GtkSpinButtonPrivate { GtkSpinButtonUpdatePolicy update_policy; @@ -99,13 +188,13 @@ enum static void gtk_spin_button_editable_init (GtkEditableInterface *iface); static void gtk_spin_button_finalize (GObject *object); static void gtk_spin_button_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); + guint prop_id, + const GValue *value, + GParamSpec *pspec); static void gtk_spin_button_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); + guint prop_id, + GValue *value, + GParamSpec *pspec); static void gtk_spin_button_destroy (GtkWidget *widget); static void gtk_spin_button_map (GtkWidget *widget); static void gtk_spin_button_unmap (GtkWidget *widget); @@ -116,57 +205,57 @@ static void gtk_spin_button_get_preferred_width (GtkWidget *widget, gint *natural); static void gtk_spin_button_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); + GtkAllocation *allocation); static gint gtk_spin_button_draw (GtkWidget *widget, cairo_t *cr); static gint gtk_spin_button_button_press (GtkWidget *widget, - GdkEventButton *event); + GdkEventButton *event); static gint gtk_spin_button_button_release (GtkWidget *widget, - GdkEventButton *event); + GdkEventButton *event); static gint gtk_spin_button_motion_notify (GtkWidget *widget, - GdkEventMotion *event); + GdkEventMotion *event); static gint gtk_spin_button_enter_notify (GtkWidget *widget, - GdkEventCrossing *event); + GdkEventCrossing *event); static gint gtk_spin_button_leave_notify (GtkWidget *widget, - GdkEventCrossing *event); + GdkEventCrossing *event); static gint gtk_spin_button_focus_out (GtkWidget *widget, - GdkEventFocus *event); + GdkEventFocus *event); static void gtk_spin_button_grab_notify (GtkWidget *widget, - gboolean was_grabbed); + gboolean was_grabbed); static void gtk_spin_button_state_flags_changed (GtkWidget *widget, GtkStateFlags previous_state); static void gtk_spin_button_style_updated (GtkWidget *widget); static void gtk_spin_button_draw_arrow (GtkSpinButton *spin_button, GtkStyleContext *context, - cairo_t *cr, - GtkArrowType arrow_type); + cairo_t *cr, + GtkArrowType arrow_type); static gboolean gtk_spin_button_timer (GtkSpinButton *spin_button); static void gtk_spin_button_stop_spinning (GtkSpinButton *spin); static void gtk_spin_button_value_changed (GtkAdjustment *adjustment, - GtkSpinButton *spin_button); + GtkSpinButton *spin_button); static gint gtk_spin_button_key_release (GtkWidget *widget, - GdkEventKey *event); + GdkEventKey *event); static gint gtk_spin_button_scroll (GtkWidget *widget, - GdkEventScroll *event); + GdkEventScroll *event); static void gtk_spin_button_activate (GtkEntry *entry); static void gtk_spin_button_get_text_area_size (GtkEntry *entry, - gint *x, - gint *y, - gint *width, - gint *height); + gint *x, + gint *y, + gint *width, + gint *height); static void gtk_spin_button_snap (GtkSpinButton *spin_button, - gdouble val); + gdouble val); static void gtk_spin_button_insert_text (GtkEditable *editable, - const gchar *new_text, - gint new_text_length, - gint *position); + const gchar *new_text, + gint new_text_length, + gint *position); static void gtk_spin_button_real_spin (GtkSpinButton *spin_button, - gdouble step); + gdouble step); static void gtk_spin_button_real_change_value (GtkSpinButton *spin, - GtkScrollType scroll); + GtkScrollType scroll); static gint gtk_spin_button_default_input (GtkSpinButton *spin_button, - gdouble *new_val); + gdouble *new_val); static gint gtk_spin_button_default_output (GtkSpinButton *spin_button); static gint spin_button_get_arrow_size (GtkSpinButton *spin_button); @@ -176,8 +265,8 @@ static guint spinbutton_signals[LAST_SIGNAL] = {0}; #define NO_ARROW 2 G_DEFINE_TYPE_WITH_CODE (GtkSpinButton, gtk_spin_button, GTK_TYPE_ENTRY, - G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, - gtk_spin_button_editable_init)) + G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, + gtk_spin_button_editable_init)) #define add_spin_binding(binding_set, keyval, mask, scroll) \ gtk_binding_entry_add_signal (binding_set, keyval, mask, \ @@ -230,92 +319,108 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class) P_("The adjustment that holds the value of the spin button"), GTK_TYPE_ADJUSTMENT, GTK_PARAM_READWRITE)); - + g_object_class_install_property (gobject_class, PROP_CLIMB_RATE, g_param_spec_double ("climb-rate", - P_("Climb Rate"), - P_("The acceleration rate when you hold down a button"), - 0.0, - G_MAXDOUBLE, - 0.0, - GTK_PARAM_READWRITE)); - + P_("Climb Rate"), + P_("The acceleration rate when you hold down a button"), + 0.0, + G_MAXDOUBLE, + 0.0, + GTK_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, PROP_DIGITS, g_param_spec_uint ("digits", - P_("Digits"), - P_("The number of decimal places to display"), - 0, - MAX_DIGITS, - 0, - GTK_PARAM_READWRITE)); - + P_("Digits"), + P_("The number of decimal places to display"), + 0, + MAX_DIGITS, + 0, + GTK_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, PROP_SNAP_TO_TICKS, g_param_spec_boolean ("snap-to-ticks", - P_("Snap to Ticks"), - P_("Whether erroneous values are automatically changed to a spin button's nearest step increment"), - FALSE, - GTK_PARAM_READWRITE)); - + P_("Snap to Ticks"), + P_("Whether erroneous values are automatically changed to a spin button's nearest step increment"), + FALSE, + GTK_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, PROP_NUMERIC, g_param_spec_boolean ("numeric", - P_("Numeric"), - P_("Whether non-numeric characters should be ignored"), - FALSE, - GTK_PARAM_READWRITE)); - + P_("Numeric"), + P_("Whether non-numeric characters should be ignored"), + FALSE, + GTK_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, PROP_WRAP, g_param_spec_boolean ("wrap", - P_("Wrap"), - P_("Whether a spin button should wrap upon reaching its limits"), - FALSE, - GTK_PARAM_READWRITE)); - + P_("Wrap"), + P_("Whether a spin button should wrap upon reaching its limits"), + FALSE, + GTK_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, PROP_UPDATE_POLICY, g_param_spec_enum ("update-policy", - P_("Update Policy"), - P_("Whether the spin button should update always, or only when the value is legal"), - GTK_TYPE_SPIN_BUTTON_UPDATE_POLICY, - GTK_UPDATE_ALWAYS, - GTK_PARAM_READWRITE)); - + P_("Update Policy"), + P_("Whether the spin button should update always, or only when the value is legal"), + GTK_TYPE_SPIN_BUTTON_UPDATE_POLICY, + GTK_UPDATE_ALWAYS, + GTK_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, PROP_VALUE, g_param_spec_double ("value", - P_("Value"), - P_("Reads the current value, or sets a new value"), - -G_MAXDOUBLE, - G_MAXDOUBLE, - 0.0, - GTK_PARAM_READWRITE)); - + P_("Value"), + P_("Reads the current value, or sets a new value"), + -G_MAXDOUBLE, + G_MAXDOUBLE, + 0.0, + GTK_PARAM_READWRITE)); + gtk_widget_class_install_style_property_parser (widget_class, - g_param_spec_enum ("shadow-type", - "Shadow Type", - P_("Style of bevel around the spin button"), - GTK_TYPE_SHADOW_TYPE, - GTK_SHADOW_IN, - GTK_PARAM_READABLE), - gtk_rc_property_parse_enum); + g_param_spec_enum ("shadow-type", + "Shadow Type", + P_("Style of bevel around the spin button"), + GTK_TYPE_SHADOW_TYPE, + GTK_SHADOW_IN, + GTK_PARAM_READABLE), + gtk_rc_property_parse_enum); + + /** + * GtkSpinButton::input: + * @spin_button: the object on which the signal was emitted + * @new_value: return location for the new value + * + * The ::input signal can be used to influence the conversion of + * the users input into a double value. The signal handler is + * expected to use gtk_entry_get_text() to retrieve the text of + * the entry and set @new_value to the new value. + * + * The default conversion uses g_strtod(). + * + * Returns: %TRUE for a successful conversion, %FALSE if the input + * was not handled, and %GTK_INPUT_ERROR if the conversion failed. + */ spinbutton_signals[INPUT] = g_signal_new (I_("input"), - G_TYPE_FROM_CLASS (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GtkSpinButtonClass, input), - NULL, NULL, - _gtk_marshal_INT__POINTER, - G_TYPE_INT, 1, - G_TYPE_POINTER); + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GtkSpinButtonClass, input), + NULL, NULL, + _gtk_marshal_INT__POINTER, + G_TYPE_INT, 1, + G_TYPE_POINTER); /** * GtkSpinButton::output: * @spin_button: the object which received the signal - * + * * The ::output signal can be used to change to formatting * of the value that is displayed in the spin buttons entry. * |[ @@ -327,36 +432,36 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class) * GtkAdjustment *adj; * gchar *text; * int value; - * + * * adj = gtk_spin_button_get_adjustment (spin); * value = (int)gtk_adjustment_get_value (adj); * text = g_strdup_printf ("%02d", value); * gtk_entry_set_text (GTK_ENTRY (spin), text); * g_free (text); - * + * * return TRUE; * } * ]| * - * Returns: %TRUE if the value has been displayed. + * Returns: %TRUE if the value has been displayed */ spinbutton_signals[OUTPUT] = g_signal_new (I_("output"), - G_TYPE_FROM_CLASS (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GtkSpinButtonClass, output), - _gtk_boolean_handled_accumulator, NULL, - _gtk_marshal_BOOLEAN__VOID, - G_TYPE_BOOLEAN, 0); + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GtkSpinButtonClass, output), + _gtk_boolean_handled_accumulator, NULL, + _gtk_marshal_BOOLEAN__VOID, + G_TYPE_BOOLEAN, 0); spinbutton_signals[VALUE_CHANGED] = g_signal_new (I_("value-changed"), - G_TYPE_FROM_CLASS (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GtkSpinButtonClass, value_changed), - NULL, NULL, - _gtk_marshal_VOID__VOID, - G_TYPE_NONE, 0); + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GtkSpinButtonClass, value_changed), + NULL, NULL, + _gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); /** * GtkSpinButton::wrapped: @@ -369,12 +474,12 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class) */ spinbutton_signals[WRAPPED] = g_signal_new (I_("wrapped"), - G_TYPE_FROM_CLASS (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GtkSpinButtonClass, wrapped), - NULL, NULL, - _gtk_marshal_VOID__VOID, - G_TYPE_NONE, 0); + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GtkSpinButtonClass, wrapped), + NULL, NULL, + _gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); /* Action signals */ spinbutton_signals[CHANGE_VALUE] = @@ -386,9 +491,9 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class) _gtk_marshal_VOID__ENUM, G_TYPE_NONE, 1, GTK_TYPE_SCROLL_TYPE); - + binding_set = gtk_binding_set_by_class (class); - + add_spin_binding (binding_set, GDK_KEY_Up, 0, GTK_SCROLL_STEP_UP); add_spin_binding (binding_set, GDK_KEY_KP_Up, 0, GTK_SCROLL_STEP_UP); add_spin_binding (binding_set, GDK_KEY_Down, 0, GTK_SCROLL_STEP_DOWN); @@ -409,9 +514,9 @@ gtk_spin_button_editable_init (GtkEditableInterface *iface) static void gtk_spin_button_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { GtkSpinButton *spin_button = GTK_SPIN_BUTTON (object); GtkSpinButtonPrivate *priv = spin_button->priv; @@ -423,20 +528,20 @@ gtk_spin_button_set_property (GObject *object, case PROP_ADJUSTMENT: adjustment = GTK_ADJUSTMENT (g_value_get_object (value)); if (!adjustment) - adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); gtk_spin_button_set_adjustment (spin_button, adjustment); break; case PROP_CLIMB_RATE: gtk_spin_button_configure (spin_button, - priv->adjustment, - g_value_get_double (value), - priv->digits); + priv->adjustment, + g_value_get_double (value), + priv->digits); break; case PROP_DIGITS: gtk_spin_button_configure (spin_button, - priv->adjustment, - priv->climb_rate, - g_value_get_uint (value)); + priv->adjustment, + priv->climb_rate, + g_value_get_uint (value)); break; case PROP_SNAP_TO_TICKS: gtk_spin_button_set_snap_to_ticks (spin_button, g_value_get_boolean (value)); @@ -461,9 +566,9 @@ gtk_spin_button_set_property (GObject *object, static void gtk_spin_button_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { GtkSpinButton *spin_button = GTK_SPIN_BUTTON (object); GtkSpinButtonPrivate *priv = spin_button->priv; @@ -538,7 +643,7 @@ static void gtk_spin_button_finalize (GObject *object) { gtk_spin_button_set_adjustment (GTK_SPIN_BUTTON (object), NULL); - + G_OBJECT_CLASS (gtk_spin_button_parent_class)->finalize (object); } @@ -599,15 +704,15 @@ gtk_spin_button_realize (GtkWidget *widget) gtk_widget_get_allocation (widget, &allocation); gtk_widget_set_events (widget, gtk_widget_get_events (widget) | - GDK_KEY_RELEASE_MASK); + GDK_KEY_RELEASE_MASK); GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->realize (widget); attributes.window_type = GDK_WINDOW_CHILD; attributes.wclass = GDK_INPUT_ONLY; attributes.visual = gtk_widget_get_visual (widget); attributes.event_mask = gtk_widget_get_events (widget); - attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK - | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK + attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK + | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK; attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL; @@ -657,10 +762,10 @@ compute_double_length (double val, int digits) a = 1; if (fabs (val) > 1.0) - a = floor (log10 (fabs (val))) + 1; + a = floor (log10 (fabs (val))) + 1; extra = 0; - + /* The dot: */ if (digits > 0) extra++; @@ -754,7 +859,7 @@ gtk_spin_button_get_preferred_width (GtkWidget *widget, static void gtk_spin_button_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) + GtkAllocation *allocation) { GtkSpinButton *spin = GTK_SPIN_BUTTON (widget); GtkSpinButtonPrivate *priv = spin->priv; @@ -793,10 +898,10 @@ gtk_spin_button_size_allocate (GtkWidget *widget, if (gtk_widget_get_realized (widget)) { gdk_window_move_resize (priv->panel, - panel_allocation.x, - panel_allocation.y, - panel_allocation.width, - panel_allocation.height); + panel_allocation.x, + panel_allocation.y, + panel_allocation.width, + panel_allocation.height); } gtk_widget_queue_draw (GTK_WIDGET (spin)); @@ -869,24 +974,24 @@ spin_button_at_limit (GtkSpinButton *spin_button, if (priv->adjustment->step_increment > 0) effective_arrow = arrow; else - effective_arrow = arrow == GTK_ARROW_UP ? GTK_ARROW_DOWN : GTK_ARROW_UP; - + effective_arrow = arrow == GTK_ARROW_UP ? GTK_ARROW_DOWN : GTK_ARROW_UP; + if (effective_arrow == GTK_ARROW_UP && (priv->adjustment->upper - priv->adjustment->value <= EPSILON)) return TRUE; - + if (effective_arrow == GTK_ARROW_DOWN && (priv->adjustment->value - priv->adjustment->lower <= EPSILON)) return TRUE; - + return FALSE; } static void gtk_spin_button_draw_arrow (GtkSpinButton *spin_button, GtkStyleContext *context, - cairo_t *cr, - GtkArrowType arrow_type) + cairo_t *cr, + GtkArrowType arrow_type) { GtkSpinButtonPrivate *priv; GtkJunctionSides junction; @@ -979,10 +1084,10 @@ gtk_spin_button_draw_arrow (GtkSpinButton *spin_button, w = width / 2; w -= w % 2 - 1; /* force odd */ h = (w + 1) / 2; - + x += (width - w) / 2; y += (height - h) / 2; - + height = h; width = w; @@ -994,7 +1099,7 @@ gtk_spin_button_draw_arrow (GtkSpinButton *spin_button, static gint gtk_spin_button_enter_notify (GtkWidget *widget, - GdkEventCrossing *event) + GdkEventCrossing *event) { GtkSpinButton *spin = GTK_SPIN_BUTTON (widget); GtkSpinButtonPrivate *priv = spin->priv; @@ -1012,9 +1117,9 @@ gtk_spin_button_enter_notify (GtkWidget *widget, gtk_widget_get_preferred_size (widget, &requisition, NULL); if (y <= requisition.height / 2) - priv->in_child = GTK_ARROW_UP; + priv->in_child = GTK_ARROW_UP; else - priv->in_child = GTK_ARROW_DOWN; + priv->in_child = GTK_ARROW_DOWN; gtk_widget_queue_draw (GTK_WIDGET (spin)); } @@ -1027,14 +1132,14 @@ gtk_spin_button_enter_notify (GtkWidget *widget, static gint gtk_spin_button_leave_notify (GtkWidget *widget, - GdkEventCrossing *event) + GdkEventCrossing *event) { GtkSpinButton *spin = GTK_SPIN_BUTTON (widget); GtkSpinButtonPrivate *priv = spin->priv; priv->in_child = NO_ARROW; gtk_widget_queue_draw (GTK_WIDGET (spin)); - + if (GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->leave_notify_event) return GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->leave_notify_event (widget, event); @@ -1043,7 +1148,7 @@ gtk_spin_button_leave_notify (GtkWidget *widget, static gint gtk_spin_button_focus_out (GtkWidget *widget, - GdkEventFocus *event) + GdkEventFocus *event) { if (gtk_editable_get_editable (GTK_EDITABLE (widget))) gtk_spin_button_update (GTK_SPIN_BUTTON (widget)); @@ -1053,7 +1158,7 @@ gtk_spin_button_focus_out (GtkWidget *widget, static void gtk_spin_button_grab_notify (GtkWidget *widget, - gboolean was_grabbed) + gboolean was_grabbed) { GtkSpinButton *spin = GTK_SPIN_BUTTON (widget); @@ -1072,7 +1177,7 @@ gtk_spin_button_state_flags_changed (GtkWidget *widget, if (!gtk_widget_is_sensitive (widget)) { - gtk_spin_button_stop_spinning (spin); + gtk_spin_button_stop_spinning (spin); gtk_widget_queue_draw (GTK_WIDGET (spin)); } } @@ -1097,7 +1202,7 @@ gtk_spin_button_style_updated (GtkWidget *widget) static gint gtk_spin_button_scroll (GtkWidget *widget, - GdkEventScroll *event) + GdkEventScroll *event) { GtkSpinButton *spin = GTK_SPIN_BUTTON (widget); GtkSpinButtonPrivate *priv = spin->priv; @@ -1105,14 +1210,14 @@ gtk_spin_button_scroll (GtkWidget *widget, if (event->direction == GDK_SCROLL_UP) { if (!gtk_widget_has_focus (widget)) - gtk_widget_grab_focus (widget); + gtk_widget_grab_focus (widget); gtk_spin_button_real_spin (spin, priv->adjustment->step_increment); } else if (event->direction == GDK_SCROLL_DOWN) { if (!gtk_widget_has_focus (widget)) - gtk_widget_grab_focus (widget); - gtk_spin_button_real_spin (spin, -priv->adjustment->step_increment); + gtk_widget_grab_focus (widget); + gtk_spin_button_real_spin (spin, -priv->adjustment->step_increment); } else return FALSE; @@ -1144,8 +1249,8 @@ gtk_spin_button_stop_spinning (GtkSpinButton *spin) static void start_spinning (GtkSpinButton *spin, - GtkArrowType click_child, - gdouble step) + GtkArrowType click_child, + gdouble step) { GtkSpinButtonPrivate *priv; @@ -1165,8 +1270,8 @@ start_spinning (GtkSpinButton *spin, priv->timer_step = step; priv->need_timer = TRUE; priv->timer = gdk_threads_add_timeout (timeout, - (GSourceFunc) gtk_spin_button_timer, - (gpointer) spin); + (GSourceFunc) gtk_spin_button_timer, + (gpointer) spin); } gtk_spin_button_real_spin (spin, click_child == GTK_ARROW_UP ? step : -step); @@ -1175,7 +1280,7 @@ start_spinning (GtkSpinButton *spin, static gint gtk_spin_button_button_press (GtkWidget *widget, - GdkEventButton *event) + GdkEventButton *event) { GtkSpinButton *spin = GTK_SPIN_BUTTON (widget); GtkSpinButtonPrivate *priv = spin->priv; @@ -1183,47 +1288,47 @@ gtk_spin_button_button_press (GtkWidget *widget, if (!priv->button) { if (event->window == priv->panel) - { - GtkRequisition requisition; + { + GtkRequisition requisition; - if (!gtk_widget_has_focus (widget)) - gtk_widget_grab_focus (widget); - priv->button = event->button; + if (!gtk_widget_has_focus (widget)) + gtk_widget_grab_focus (widget); + priv->button = event->button; if (gtk_editable_get_editable (GTK_EDITABLE (widget))) - gtk_spin_button_update (spin); - - gtk_widget_get_preferred_size (widget, &requisition, NULL); + gtk_spin_button_update (spin); - if (event->y <= requisition.height / 2) - { - if (event->button == 1) - start_spinning (spin, GTK_ARROW_UP, priv->adjustment->step_increment); - else if (event->button == 2) - start_spinning (spin, GTK_ARROW_UP, priv->adjustment->page_increment); - else - priv->click_child = GTK_ARROW_UP; - } - else - { - if (event->button == 1) - start_spinning (spin, GTK_ARROW_DOWN, priv->adjustment->step_increment); - else if (event->button == 2) - start_spinning (spin, GTK_ARROW_DOWN, priv->adjustment->page_increment); - else - priv->click_child = GTK_ARROW_DOWN; - } - return TRUE; - } + gtk_widget_get_preferred_size (widget, &requisition, NULL); + + if (event->y <= requisition.height / 2) + { + if (event->button == 1) + start_spinning (spin, GTK_ARROW_UP, priv->adjustment->step_increment); + else if (event->button == 2) + start_spinning (spin, GTK_ARROW_UP, priv->adjustment->page_increment); + else + priv->click_child = GTK_ARROW_UP; + } + else + { + if (event->button == 1) + start_spinning (spin, GTK_ARROW_DOWN, priv->adjustment->step_increment); + else if (event->button == 2) + start_spinning (spin, GTK_ARROW_DOWN, priv->adjustment->page_increment); + else + priv->click_child = GTK_ARROW_DOWN; + } + return TRUE; + } else - return GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->button_press_event (widget, event); + return GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->button_press_event (widget, event); } return FALSE; } static gint gtk_spin_button_button_release (GtkWidget *widget, - GdkEventButton *event) + GdkEventButton *event) { GtkSpinButton *spin = GTK_SPIN_BUTTON (widget); GtkSpinButtonPrivate *priv = spin->priv; @@ -1238,42 +1343,42 @@ gtk_spin_button_button_release (GtkWidget *widget, gtk_spin_button_stop_spinning (spin); if (event->button == 3) - { - GtkRequisition requisition; + { + GtkRequisition requisition; GtkStyleContext *context; GtkStateFlags state; GtkBorder padding; - gtk_widget_get_preferred_size (widget, &requisition, NULL); + gtk_widget_get_preferred_size (widget, &requisition, NULL); context = gtk_widget_get_style_context (widget); state = gtk_widget_get_state_flags (widget); gtk_style_context_get_padding (context, state, &padding); - if (event->y >= 0 && event->x >= 0 && - event->y <= requisition.height && - event->x <= arrow_size + padding.left + padding.right) - { - if (click_child == GTK_ARROW_UP && - event->y <= requisition.height / 2) - { - gdouble diff; + if (event->y >= 0 && event->x >= 0 && + event->y <= requisition.height && + event->x <= arrow_size + padding.left + padding.right) + { + if (click_child == GTK_ARROW_UP && + event->y <= requisition.height / 2) + { + gdouble diff; - diff = priv->adjustment->upper - priv->adjustment->value; - if (diff > EPSILON) - gtk_spin_button_real_spin (spin, diff); - } - else if (click_child == GTK_ARROW_DOWN && - event->y > requisition.height / 2) - { - gdouble diff; + diff = priv->adjustment->upper - priv->adjustment->value; + if (diff > EPSILON) + gtk_spin_button_real_spin (spin, diff); + } + else if (click_child == GTK_ARROW_DOWN && + event->y > requisition.height / 2) + { + gdouble diff; - diff = priv->adjustment->value - priv->adjustment->lower; - if (diff > EPSILON) - gtk_spin_button_real_spin (spin, -diff); - } - } - } + diff = priv->adjustment->value - priv->adjustment->lower; + if (diff > EPSILON) + gtk_spin_button_real_spin (spin, -diff); + } + } + } gtk_widget_queue_draw (GTK_WIDGET (spin)); return TRUE; @@ -1284,7 +1389,7 @@ gtk_spin_button_button_release (GtkWidget *widget, static gint gtk_spin_button_motion_notify (GtkWidget *widget, - GdkEventMotion *event) + GdkEventMotion *event) { GtkSpinButton *spin = GTK_SPIN_BUTTON (widget); GtkSpinButtonPrivate *priv = spin->priv; @@ -1302,21 +1407,21 @@ gtk_spin_button_motion_notify (GtkWidget *widget, gtk_widget_get_preferred_size (widget, &requisition, NULL); if (y <= requisition.height / 2 && - priv->in_child == GTK_ARROW_DOWN) - { - priv->in_child = GTK_ARROW_UP; - gtk_widget_queue_draw (GTK_WIDGET (spin)); - } + priv->in_child == GTK_ARROW_DOWN) + { + priv->in_child = GTK_ARROW_UP; + gtk_widget_queue_draw (GTK_WIDGET (spin)); + } else if (y > requisition.height / 2 && - priv->in_child == GTK_ARROW_UP) - { - priv->in_child = GTK_ARROW_DOWN; - gtk_widget_queue_draw (GTK_WIDGET (spin)); - } - + priv->in_child == GTK_ARROW_UP) + { + priv->in_child = GTK_ARROW_DOWN; + gtk_widget_queue_draw (GTK_WIDGET (spin)); + } + return FALSE; } - + return GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->motion_notify_event (widget, event); } @@ -1329,37 +1434,37 @@ gtk_spin_button_timer (GtkSpinButton *spin_button) if (priv->timer) { if (priv->click_child == GTK_ARROW_UP) - gtk_spin_button_real_spin (spin_button, priv->timer_step); + gtk_spin_button_real_spin (spin_button, priv->timer_step); else - gtk_spin_button_real_spin (spin_button, -priv->timer_step); + gtk_spin_button_real_spin (spin_button, -priv->timer_step); if (priv->need_timer) - { + { GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (spin_button)); guint timeout; g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL); - priv->need_timer = FALSE; - priv->timer = gdk_threads_add_timeout (timeout, - (GSourceFunc) gtk_spin_button_timer, - (gpointer) spin_button); - } - else - { - if (priv->climb_rate > 0.0 && priv->timer_step - < priv->adjustment->page_increment) - { - if (priv->timer_calls < MAX_TIMER_CALLS) - priv->timer_calls++; - else - { - priv->timer_calls = 0; - priv->timer_step += priv->climb_rate; - } - } - retval = TRUE; - } + priv->need_timer = FALSE; + priv->timer = gdk_threads_add_timeout (timeout, + (GSourceFunc) gtk_spin_button_timer, + (gpointer) spin_button); + } + else + { + if (priv->climb_rate > 0.0 && priv->timer_step + < priv->adjustment->page_increment) + { + if (priv->timer_calls < MAX_TIMER_CALLS) + priv->timer_calls++; + else + { + priv->timer_calls = 0; + priv->timer_step += priv->climb_rate; + } + } + retval = TRUE; + } } return retval; @@ -1367,7 +1472,7 @@ gtk_spin_button_timer (GtkSpinButton *spin_button) static void gtk_spin_button_value_changed (GtkAdjustment *adjustment, - GtkSpinButton *spin_button) + GtkSpinButton *spin_button) { gboolean return_val; @@ -1381,13 +1486,13 @@ gtk_spin_button_value_changed (GtkAdjustment *adjustment, g_signal_emit (spin_button, spinbutton_signals[VALUE_CHANGED], 0); gtk_widget_queue_draw (GTK_WIDGET (spin_button)); - + g_object_notify (G_OBJECT (spin_button), "value"); } static void gtk_spin_button_real_change_value (GtkSpinButton *spin, - GtkScrollType scroll) + GtkScrollType scroll) { GtkSpinButtonPrivate *priv = spin->priv; gdouble old_value; @@ -1413,69 +1518,69 @@ gtk_spin_button_real_change_value (GtkSpinButton *spin, gtk_spin_button_real_spin (spin, -priv->timer_step); if (priv->climb_rate > 0.0 && priv->timer_step - < priv->adjustment->page_increment) - { - if (priv->timer_calls < MAX_TIMER_CALLS) - priv->timer_calls++; - else - { - priv->timer_calls = 0; - priv->timer_step += priv->climb_rate; - } - } + < priv->adjustment->page_increment) + { + if (priv->timer_calls < MAX_TIMER_CALLS) + priv->timer_calls++; + else + { + priv->timer_calls = 0; + priv->timer_step += priv->climb_rate; + } + } break; - + case GTK_SCROLL_STEP_FORWARD: case GTK_SCROLL_STEP_UP: case GTK_SCROLL_STEP_RIGHT: gtk_spin_button_real_spin (spin, priv->timer_step); if (priv->climb_rate > 0.0 && priv->timer_step - < priv->adjustment->page_increment) - { - if (priv->timer_calls < MAX_TIMER_CALLS) - priv->timer_calls++; - else - { - priv->timer_calls = 0; - priv->timer_step += priv->climb_rate; - } - } + < priv->adjustment->page_increment) + { + if (priv->timer_calls < MAX_TIMER_CALLS) + priv->timer_calls++; + else + { + priv->timer_calls = 0; + priv->timer_step += priv->climb_rate; + } + } break; - + case GTK_SCROLL_PAGE_BACKWARD: case GTK_SCROLL_PAGE_DOWN: case GTK_SCROLL_PAGE_LEFT: gtk_spin_button_real_spin (spin, -priv->adjustment->page_increment); break; - + case GTK_SCROLL_PAGE_FORWARD: case GTK_SCROLL_PAGE_UP: case GTK_SCROLL_PAGE_RIGHT: gtk_spin_button_real_spin (spin, priv->adjustment->page_increment); break; - + case GTK_SCROLL_START: { - gdouble diff = priv->adjustment->value - priv->adjustment->lower; - if (diff > EPSILON) - gtk_spin_button_real_spin (spin, -diff); - break; + gdouble diff = priv->adjustment->value - priv->adjustment->lower; + if (diff > EPSILON) + gtk_spin_button_real_spin (spin, -diff); + break; } - + case GTK_SCROLL_END: { - gdouble diff = priv->adjustment->upper - priv->adjustment->value; - if (diff > EPSILON) - gtk_spin_button_real_spin (spin, diff); - break; + gdouble diff = priv->adjustment->upper - priv->adjustment->value; + if (diff > EPSILON) + gtk_spin_button_real_spin (spin, diff); + break; } - + default: g_warning ("Invalid scroll type %d for GtkSpinButton::change-value", scroll); break; } - + gtk_spin_button_update (spin); if (priv->adjustment->value == old_value) @@ -1484,7 +1589,7 @@ gtk_spin_button_real_change_value (GtkSpinButton *spin, static gint gtk_spin_button_key_release (GtkWidget *widget, - GdkEventKey *event) + GdkEventKey *event) { GtkSpinButton *spin = GTK_SPIN_BUTTON (widget); GtkSpinButtonPrivate *priv = spin->priv; @@ -1498,7 +1603,7 @@ gtk_spin_button_key_release (GtkWidget *widget, static void gtk_spin_button_snap (GtkSpinButton *spin_button, - gdouble val) + gdouble val) { GtkSpinButtonPrivate *priv = spin_button->priv; gdouble inc; @@ -1529,10 +1634,10 @@ gtk_spin_button_activate (GtkEntry *entry) static void gtk_spin_button_get_text_area_size (GtkEntry *entry, - gint *x, - gint *y, - gint *width, - gint *height) + gint *x, + gint *y, + gint *width, + gint *height) { GtkStyleContext *context; GtkStateFlags state; @@ -1560,9 +1665,9 @@ gtk_spin_button_get_text_area_size (GtkEntry *entry, static void gtk_spin_button_insert_text (GtkEditable *editable, - const gchar *new_text, - gint new_text_length, - gint *position) + const gchar *new_text, + gint new_text_length, + gint *position) { GtkEntry *entry = GTK_ENTRY (editable); GtkSpinButton *spin = GTK_SPIN_BUTTON (editable); @@ -1589,14 +1694,14 @@ gtk_spin_button_insert_text (GtkEditable *editable, lc = localeconv (); if (*(lc->negative_sign)) - neg_sign = *(lc->negative_sign); - else - neg_sign = '-'; + neg_sign = *(lc->negative_sign); + else + neg_sign = '-'; if (*(lc->positive_sign)) - pos_sign = *(lc->positive_sign); - else - pos_sign = '+'; + pos_sign = *(lc->positive_sign); + else + pos_sign = '+'; #ifdef G_OS_WIN32 /* Workaround for bug caused by some Windows application messing @@ -1615,60 +1720,60 @@ gtk_spin_button_insert_text (GtkEditable *editable, * digits... */ if (pos_sign >= '0' && pos_sign <= '9') - pos_sign = '+'; + pos_sign = '+'; #endif for (sign=0, i=0; idecimal_point)) - { - dotpos = i; - break; - } + if (entry_text[i] == *(lc->decimal_point)) + { + dotpos = i; + break; + } if (dotpos > -1 && *position > dotpos && - (gint)priv->digits - entry_length - + dotpos - new_text_length + 1 < 0) - return; + (gint)priv->digits - entry_length + + dotpos - new_text_length + 1 < 0) + return; for (i = 0; i < new_text_length; i++) - { - if (new_text[i] == neg_sign || new_text[i] == pos_sign) - { - if (sign || (*position) || i) - return; - sign = TRUE; - } - else if (new_text[i] == *(lc->decimal_point)) - { - if (!priv->digits || dotpos > -1 || - (new_text_length - 1 - i + entry_length - - *position > (gint)priv->digits)) - return; - dotpos = *position + i; - } - else if (new_text[i] < 0x30 || new_text[i] > 0x39) - return; - } + { + if (new_text[i] == neg_sign || new_text[i] == pos_sign) + { + if (sign || (*position) || i) + return; + sign = TRUE; + } + else if (new_text[i] == *(lc->decimal_point)) + { + if (!priv->digits || dotpos > -1 || + (new_text_length - 1 - i + entry_length + - *position > (gint)priv->digits)) + return; + dotpos = *position + i; + } + else if (new_text[i] < 0x30 || new_text[i] > 0x39) + return; + } } parent_editable_iface->insert_text (editable, new_text, - new_text_length, position); + new_text_length, position); } static void gtk_spin_button_real_spin (GtkSpinButton *spin_button, - gdouble increment) + gdouble increment) { GtkSpinButtonPrivate *priv = spin_button->priv; GtkAdjustment *adj; @@ -1682,32 +1787,32 @@ gtk_spin_button_real_spin (GtkSpinButton *spin_button, if (increment > 0) { if (priv->wrap) - { - if (fabs (adj->value - adj->upper) < EPSILON) - { - new_value = adj->lower; - wrapped = TRUE; - } - else if (new_value > adj->upper) - new_value = adj->upper; - } + { + if (fabs (adj->value - adj->upper) < EPSILON) + { + new_value = adj->lower; + wrapped = TRUE; + } + else if (new_value > adj->upper) + new_value = adj->upper; + } else - new_value = MIN (new_value, adj->upper); + new_value = MIN (new_value, adj->upper); } - else if (increment < 0) + else if (increment < 0) { if (priv->wrap) - { - if (fabs (adj->value - adj->lower) < EPSILON) - { - new_value = adj->upper; - wrapped = TRUE; - } - else if (new_value < adj->lower) - new_value = adj->lower; - } + { + if (fabs (adj->value - adj->lower) < EPSILON) + { + new_value = adj->upper; + wrapped = TRUE; + } + else if (new_value < adj->lower) + new_value = adj->lower; + } else - new_value = MAX (new_value, adj->lower); + new_value = MAX (new_value, adj->lower); } if (fabs (new_value - adj->value) > EPSILON) @@ -1721,7 +1826,7 @@ gtk_spin_button_real_spin (GtkSpinButton *spin_button, static gint gtk_spin_button_default_input (GtkSpinButton *spin_button, - gdouble *new_val) + gdouble *new_val) { gchar *err = NULL; @@ -1756,18 +1861,19 @@ gtk_spin_button_default_output (GtkSpinButton *spin_button) /** * gtk_spin_button_configure: * @spin_button: a #GtkSpinButton - * @adjustment: (allow-none): a #GtkAdjustment. - * @climb_rate: the new climb rate. - * @digits: the number of decimal places to display in the spin button. + * @adjustment: (allow-none): a #GtkAdjustment + * @climb_rate: the new climb rate + * @digits: the number of decimal places to display in the spin button * - * Changes the properties of an existing spin button. The adjustment, climb rate, - * and number of decimal places are all changed accordingly, after this function call. + * Changes the properties of an existing spin button. The adjustment, + * climb rate, and number of decimal places are all changed accordingly, + * after this function call. */ void -gtk_spin_button_configure (GtkSpinButton *spin_button, - GtkAdjustment *adjustment, - gdouble climb_rate, - guint digits) +gtk_spin_button_configure (GtkSpinButton *spin_button, + GtkAdjustment *adjustment, + gdouble climb_rate, + guint digits) { GtkSpinButtonPrivate *priv; @@ -1781,7 +1887,7 @@ gtk_spin_button_configure (GtkSpinButton *spin_button, adjustment = priv->adjustment; g_object_freeze_notify (G_OBJECT (spin_button)); - if (priv->digits != digits) + if (priv->digits != digits) { priv->digits = digits; g_object_notify (G_OBJECT (spin_button), "digits"); @@ -1797,10 +1903,22 @@ gtk_spin_button_configure (GtkSpinButton *spin_button, gtk_adjustment_value_changed (adjustment); } +/** + * gtk_spin_button_new: + * @adjustment: (allow-none): the #GtkAdjustment object that this spin + * button should use, or %NULL + * @climb_rate: specifies how much the spin button changes when an arrow + * is clicked on + * @digits: the number of decimal places to display + * + * Creates a new #GtkSpinButton. + * + * Returns: The new spin button as a #GtkWidget + */ GtkWidget * gtk_spin_button_new (GtkAdjustment *adjustment, - gdouble climb_rate, - guint digits) + gdouble climb_rate, + guint digits) { GtkSpinButton *spin; @@ -1819,23 +1937,23 @@ gtk_spin_button_new (GtkAdjustment *adjustment, * @min: Minimum allowable value * @max: Maximum allowable value * @step: Increment added or subtracted by spinning the widget - * - * This is a convenience constructor that allows creation of a numeric - * #GtkSpinButton without manually creating an adjustment. The value is + * + * This is a convenience constructor that allows creation of a numeric + * #GtkSpinButton without manually creating an adjustment. The value is * initially set to the minimum value and a page increment of 10 * @step - * is the default. The precision of the spin button is equivalent to the - * precision of @step. - * - * Note that the way in which the precision is derived works best if @step - * is a power of ten. If the resulting precision is not suitable for your + * is the default. The precision of the spin button is equivalent to the + * precision of @step. + * + * Note that the way in which the precision is derived works best if @step + * is a power of ten. If the resulting precision is not suitable for your * needs, use gtk_spin_button_set_digits() to correct it. - * - * Return value: The new spin button as a #GtkWidget. - **/ + * + * Return value: The new spin button as a #GtkWidget + */ GtkWidget * gtk_spin_button_new_with_range (gdouble min, - gdouble max, - gdouble step) + gdouble max, + gdouble step) { GtkAdjustment *adj; GtkSpinButton *spin; @@ -1863,8 +1981,9 @@ gtk_spin_button_new_with_range (gdouble min, return GTK_WIDGET (spin); } -/* Callback used when the spin button's adjustment changes. We need to redraw - * the arrows when the adjustment's range changes, and reevaluate our size request. +/* Callback used when the spin button's adjustment changes. + * We need to redraw the arrows when the adjustment's range + * changes, and reevaluate our size request. */ static void adjustment_changed_cb (GtkAdjustment *adjustment, gpointer data) @@ -1880,12 +1999,12 @@ adjustment_changed_cb (GtkAdjustment *adjustment, gpointer data) * gtk_spin_button_set_adjustment: * @spin_button: a #GtkSpinButton * @adjustment: a #GtkAdjustment to replace the existing adjustment - * + * * Replaces the #GtkAdjustment associated with @spin_button. - **/ + */ void gtk_spin_button_set_adjustment (GtkSpinButton *spin_button, - GtkAdjustment *adjustment) + GtkAdjustment *adjustment) { GtkSpinButtonPrivate *priv; @@ -1897,25 +2016,25 @@ gtk_spin_button_set_adjustment (GtkSpinButton *spin_button, { if (priv->adjustment) { - g_signal_handlers_disconnect_by_func (priv->adjustment, - gtk_spin_button_value_changed, - spin_button); - g_signal_handlers_disconnect_by_func (priv->adjustment, - adjustment_changed_cb, - spin_button); - g_object_unref (priv->adjustment); + g_signal_handlers_disconnect_by_func (priv->adjustment, + gtk_spin_button_value_changed, + spin_button); + g_signal_handlers_disconnect_by_func (priv->adjustment, + adjustment_changed_cb, + spin_button); + g_object_unref (priv->adjustment); } priv->adjustment = adjustment; if (adjustment) { - g_object_ref_sink (adjustment); - g_signal_connect (adjustment, "value-changed", - G_CALLBACK (gtk_spin_button_value_changed), - spin_button); - g_signal_connect (adjustment, "changed", - G_CALLBACK (adjustment_changed_cb), - spin_button); - priv->timer_step = priv->adjustment->step_increment; + g_object_ref_sink (adjustment); + g_signal_connect (adjustment, "value-changed", + G_CALLBACK (gtk_spin_button_value_changed), + spin_button); + g_signal_connect (adjustment, "changed", + G_CALLBACK (adjustment_changed_cb), + spin_button); + priv->timer_step = priv->adjustment->step_increment; } gtk_widget_queue_resize (GTK_WIDGET (spin_button)); @@ -1927,9 +2046,9 @@ gtk_spin_button_set_adjustment (GtkSpinButton *spin_button, /** * gtk_spin_button_get_adjustment: * @spin_button: a #GtkSpinButton - * + * * Get the adjustment associated with a #GtkSpinButton - * + * * Return value: (transfer none): the #GtkAdjustment of @spin_button **/ GtkAdjustment * @@ -1944,13 +2063,13 @@ gtk_spin_button_get_adjustment (GtkSpinButton *spin_button) * gtk_spin_button_set_digits: * @spin_button: a #GtkSpinButton * @digits: the number of digits after the decimal point to be displayed for the spin button's value - * + * * Set the precision to be displayed by @spin_button. Up to 20 digit precision * is allowed. **/ void gtk_spin_button_set_digits (GtkSpinButton *spin_button, - guint digits) + guint digits) { GtkSpinButtonPrivate *priv; @@ -1963,7 +2082,7 @@ gtk_spin_button_set_digits (GtkSpinButton *spin_button, priv->digits = digits; gtk_spin_button_value_changed (priv->adjustment, spin_button); g_object_notify (G_OBJECT (spin_button), "digits"); - + /* since lower/upper may have changed */ gtk_widget_queue_resize (GTK_WIDGET (spin_button)); } @@ -1990,14 +2109,14 @@ gtk_spin_button_get_digits (GtkSpinButton *spin_button) * @spin_button: a #GtkSpinButton * @step: increment applied for a button 1 press. * @page: increment applied for a button 2 press. - * - * Sets the step and page increments for spin_button. This affects how + * + * Sets the step and page increments for spin_button. This affects how * quickly the value changes when the spin button's arrows are activated. **/ void gtk_spin_button_set_increments (GtkSpinButton *spin_button, - gdouble step, - gdouble page) + gdouble step, + gdouble page) { GtkSpinButtonPrivate *priv; @@ -2020,8 +2139,8 @@ gtk_spin_button_set_increments (GtkSpinButton *spin_button, **/ void gtk_spin_button_get_increments (GtkSpinButton *spin_button, - gdouble *step, - gdouble *page) + gdouble *step, + gdouble *page) { GtkSpinButtonPrivate *priv; @@ -2040,13 +2159,13 @@ gtk_spin_button_get_increments (GtkSpinButton *spin_button, * @spin_button: a #GtkSpinButton * @min: minimum allowable value * @max: maximum allowable value - * - * Sets the minimum and maximum allowable values for @spin_button - **/ + * + * Sets the minimum and maximum allowable values for @spin_button. + */ void gtk_spin_button_set_range (GtkSpinButton *spin_button, - gdouble min, - gdouble max) + gdouble min, + gdouble max) { GtkSpinButtonPrivate *priv; gdouble value; @@ -2074,13 +2193,13 @@ gtk_spin_button_set_range (GtkSpinButton *spin_button, * @min: (allow-none): location to store minimum allowed value, or %NULL * @max: (allow-none): location to store maximum allowed value, or %NULL * - * Gets the range allowed for @spin_button. See - * gtk_spin_button_set_range(). - **/ + * Gets the range allowed for @spin_button. + * See gtk_spin_button_set_range(). + */ void gtk_spin_button_get_range (GtkSpinButton *spin_button, - gdouble *min, - gdouble *max) + gdouble *min, + gdouble *max) { GtkSpinButtonPrivate *priv; @@ -2097,11 +2216,11 @@ gtk_spin_button_get_range (GtkSpinButton *spin_button, /** * gtk_spin_button_get_value: * @spin_button: a #GtkSpinButton - * + * * Get the value in the @spin_button. - * + * * Return value: the value of @spin_button - **/ + */ gdouble gtk_spin_button_get_value (GtkSpinButton *spin_button) { @@ -2113,11 +2232,11 @@ gtk_spin_button_get_value (GtkSpinButton *spin_button) /** * gtk_spin_button_get_value_as_int: * @spin_button: a #GtkSpinButton - * + * * Get the value @spin_button represented as an integer. - * + * * Return value: the value of @spin_button - **/ + */ gint gtk_spin_button_get_value_as_int (GtkSpinButton *spin_button) { @@ -2139,12 +2258,12 @@ gtk_spin_button_get_value_as_int (GtkSpinButton *spin_button) * gtk_spin_button_set_value: * @spin_button: a #GtkSpinButton * @value: the new value - * - * Set the value of @spin_button. - **/ -void -gtk_spin_button_set_value (GtkSpinButton *spin_button, - gdouble value) + * + * Sets the value of @spin_button. + */ +void +gtk_spin_button_set_value (GtkSpinButton *spin_button, + gdouble value) { GtkSpinButtonPrivate *priv; @@ -2159,21 +2278,22 @@ gtk_spin_button_set_value (GtkSpinButton *spin_button, gint return_val = FALSE; g_signal_emit (spin_button, spinbutton_signals[OUTPUT], 0, &return_val); if (return_val == FALSE) - gtk_spin_button_default_output (spin_button); + gtk_spin_button_default_output (spin_button); } } /** * gtk_spin_button_set_update_policy: - * @spin_button: a #GtkSpinButton + * @spin_button: a #GtkSpinButton * @policy: a #GtkSpinButtonUpdatePolicy value - * - * Sets the update behavior of a spin button. This determines whether the - * spin button is always updated or only when a valid value is set. - **/ + * + * Sets the update behavior of a spin button. + * This determines wether the spin button is always updated + * or only when a valid value is set. + */ void gtk_spin_button_set_update_policy (GtkSpinButton *spin_button, - GtkSpinButtonUpdatePolicy policy) + GtkSpinButtonUpdatePolicy policy) { GtkSpinButtonPrivate *priv; @@ -2192,11 +2312,11 @@ gtk_spin_button_set_update_policy (GtkSpinButton *spin_button, * gtk_spin_button_get_update_policy: * @spin_button: a #GtkSpinButton * - * Gets the update behavior of a spin button. See - * gtk_spin_button_set_update_policy(). + * Gets the update behavior of a spin button. + * See gtk_spin_button_set_update_policy(). * * Return value: the current update policy - **/ + */ GtkSpinButtonUpdatePolicy gtk_spin_button_get_update_policy (GtkSpinButton *spin_button) { @@ -2207,15 +2327,15 @@ gtk_spin_button_get_update_policy (GtkSpinButton *spin_button) /** * gtk_spin_button_set_numeric: - * @spin_button: a #GtkSpinButton - * @numeric: flag indicating if only numeric entry is allowed. - * - * Sets the flag that determines if non-numeric text can be typed into - * the spin button. - **/ + * @spin_button: a #GtkSpinButton + * @numeric: flag indicating if only numeric entry is allowed + * + * Sets the flag that determines if non-numeric text can be typed + * into the spin button. + */ void -gtk_spin_button_set_numeric (GtkSpinButton *spin_button, - gboolean numeric) +gtk_spin_button_set_numeric (GtkSpinButton *spin_button, + gboolean numeric) { GtkSpinButtonPrivate *priv; @@ -2240,7 +2360,7 @@ gtk_spin_button_set_numeric (GtkSpinButton *spin_button, * See gtk_spin_button_set_numeric(). * * Return value: %TRUE if only numeric text can be entered - **/ + */ gboolean gtk_spin_button_get_numeric (GtkSpinButton *spin_button) { @@ -2251,15 +2371,16 @@ gtk_spin_button_get_numeric (GtkSpinButton *spin_button) /** * gtk_spin_button_set_wrap: - * @spin_button: a #GtkSpinButton - * @wrap: a flag indicating if wrapping behavior is performed. - * - * Sets the flag that determines if a spin button value wraps around to the - * opposite limit when the upper or lower limit of the range is exceeded. - **/ + * @spin_button: a #GtkSpinButton + * @wrap: a flag indicating if wrapping behavior is performed + * + * Sets the flag that determines if a spin button value wraps + * around to the opposite limit when the upper or lower limit + * of the range is exceeded. + */ void gtk_spin_button_set_wrap (GtkSpinButton *spin_button, - gboolean wrap) + gboolean wrap) { GtkSpinButtonPrivate *priv; @@ -2267,12 +2388,12 @@ gtk_spin_button_set_wrap (GtkSpinButton *spin_button, priv = spin_button->priv; - wrap = wrap != FALSE; + wrap = wrap != FALSE; if (priv->wrap != wrap) { - priv->wrap = (wrap != 0); - + priv->wrap = wrap; + g_object_notify (G_OBJECT (spin_button), "wrap"); } } @@ -2286,7 +2407,7 @@ gtk_spin_button_set_wrap (GtkSpinButton *spin_button, * exceeded. See gtk_spin_button_set_wrap(). * * Return value: %TRUE if the spin button wraps around - **/ + */ gboolean gtk_spin_button_get_wrap (GtkSpinButton *spin_button) { @@ -2315,15 +2436,16 @@ spin_button_get_arrow_size (GtkSpinButton *spin_button) /** * gtk_spin_button_set_snap_to_ticks: - * @spin_button: a #GtkSpinButton - * @snap_to_ticks: a flag indicating if invalid values should be corrected. - * - * Sets the policy as to whether values are corrected to the nearest step - * increment when a spin button is activated after providing an invalid value. - **/ + * @spin_button: a #GtkSpinButton + * @snap_to_ticks: a flag indicating if invalid values should be corrected + * + * Sets the policy as to whether values are corrected to the + * nearest step increment when a spin button is activated after + * providing an invalid value. + */ void gtk_spin_button_set_snap_to_ticks (GtkSpinButton *spin_button, - gboolean snap_to_ticks) + gboolean snap_to_ticks) { GtkSpinButtonPrivate *priv; guint new_val; @@ -2338,8 +2460,8 @@ gtk_spin_button_set_snap_to_ticks (GtkSpinButton *spin_button, { priv->snap_to_ticks = new_val; if (new_val && gtk_editable_get_editable (GTK_EDITABLE (spin_button))) - gtk_spin_button_update (spin_button); - + gtk_spin_button_update (spin_button); + g_object_notify (G_OBJECT (spin_button), "snap-to-ticks"); } } @@ -2348,11 +2470,11 @@ gtk_spin_button_set_snap_to_ticks (GtkSpinButton *spin_button, * gtk_spin_button_get_snap_to_ticks: * @spin_button: a #GtkSpinButton * - * Returns whether the values are corrected to the nearest step. See - * gtk_spin_button_set_snap_to_ticks(). + * Returns whether the values are corrected to the nearest step. + * See gtk_spin_button_set_snap_to_ticks(). * - * Return value: %TRUE if values are snapped to the nearest step. - **/ + * Return value: %TRUE if values are snapped to the nearest step + */ gboolean gtk_spin_button_get_snap_to_ticks (GtkSpinButton *spin_button) { @@ -2363,17 +2485,17 @@ gtk_spin_button_get_snap_to_ticks (GtkSpinButton *spin_button) /** * gtk_spin_button_spin: - * @spin_button: a #GtkSpinButton - * @direction: a #GtkSpinType indicating the direction to spin. - * @increment: step increment to apply in the specified direction. - * - * Increment or decrement a spin button's value in a specified direction - * by a specified amount. - **/ + * @spin_button: a #GtkSpinButton + * @direction: a #GtkSpinType indicating the direction to spin + * @increment: step increment to apply in the specified direction + * + * Increment or decrement a spin button's value in a specified + * direction by a specified amount. + */ void gtk_spin_button_spin (GtkSpinButton *spin_button, - GtkSpinType direction, - gdouble increment) + GtkSpinType direction, + gdouble increment) { GtkSpinButtonPrivate *priv; GtkAdjustment *adj; @@ -2391,7 +2513,7 @@ gtk_spin_button_spin (GtkSpinButton *spin_button, direction == GTK_SPIN_STEP_BACKWARD)) { if (direction == GTK_SPIN_STEP_BACKWARD && increment > 0) - increment = -increment; + increment = -increment; direction = GTK_SPIN_USER_DEFINED; } @@ -2421,20 +2543,20 @@ gtk_spin_button_spin (GtkSpinButton *spin_button, diff = adj->value - adj->lower; if (diff > EPSILON) - gtk_spin_button_real_spin (spin_button, -diff); + gtk_spin_button_real_spin (spin_button, -diff); break; case GTK_SPIN_END: diff = adj->upper - adj->value; if (diff > EPSILON) - gtk_spin_button_real_spin (spin_button, diff); + gtk_spin_button_real_spin (spin_button, diff); break; case GTK_SPIN_USER_DEFINED: if (increment != 0) - gtk_spin_button_real_spin (spin_button, increment); + gtk_spin_button_real_spin (spin_button, increment); break; default: @@ -2444,11 +2566,11 @@ gtk_spin_button_spin (GtkSpinButton *spin_button, /** * gtk_spin_button_update: - * @spin_button: a #GtkSpinButton - * + * @spin_button: a #GtkSpinButton + * * Manually force an update of the spin button. - **/ -void + */ +void gtk_spin_button_update (GtkSpinButton *spin_button) { GtkSpinButtonPrivate *priv; @@ -2475,14 +2597,14 @@ gtk_spin_button_update (GtkSpinButton *spin_button) if (priv->update_policy == GTK_UPDATE_ALWAYS) { if (val < priv->adjustment->lower) - val = priv->adjustment->lower; + val = priv->adjustment->lower; else if (val > priv->adjustment->upper) - val = priv->adjustment->upper; + val = priv->adjustment->upper; } - else if ((priv->update_policy == GTK_UPDATE_IF_VALID) && - (error || - val < priv->adjustment->lower || - val > priv->adjustment->upper)) + else if ((priv->update_policy == GTK_UPDATE_IF_VALID) && + (error || + val < priv->adjustment->lower || + val > priv->adjustment->upper)) { gtk_spin_button_value_changed (priv->adjustment, spin_button); return; diff --git a/gtk/gtkspinbutton.h b/gtk/gtkspinbutton.h index f061f29028..40a861503d 100644 --- a/gtk/gtkspinbutton.h +++ b/gtk/gtkspinbutton.h @@ -48,14 +48,45 @@ G_BEGIN_DECLS #define GTK_IS_SPIN_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SPIN_BUTTON)) #define GTK_SPIN_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_SPIN_BUTTON, GtkSpinButtonClass)) +/** + * GTK_INPUT_ERROR: + * + * Constant to return from a signal handler for the #GtkSpinButton::input + * signal in case of conversion failure. + */ #define GTK_INPUT_ERROR -1 +/** + * GtkSpinButtonUpdatePolicy: + * @GTK_UPDATE_ALWAYS: When refreshing your #GtkSpinButton, the value is + * always displayed + * @GTK_UPDATE_IF_VALID: When refreshing your #GtkSpinButton, the value is + * only displayed if it is valid within the bounds of the spin button's + * adjustment + * + * The spin button update policy determines whether the spin button displays + * values even if they are outside the bounds of its adjustment. + * See gtk_spin_button_set_update_policy(). + */ typedef enum { GTK_UPDATE_ALWAYS, GTK_UPDATE_IF_VALID } GtkSpinButtonUpdatePolicy; +/** + * GtkSpinType: + * @GTK_SPIN_STEP_FORWARD: Increment by the adjustments step increment. + * @GTK_SPIN_STEP_BACKWARD: Decrement by the adjustments step increment. + * @GTK_SPIN_PAGE_FORWARD: Increment by the adjustments page increment. + * @GTK_SPIN_PAGE_BACKWARD: Decrement by the adjustments page increment. + * @GTK_SPIN_HOME: Go to the adjustments lower bound. + * @GTK_SPIN_END: Go to the adjustments upper bound. + * @GTK_SPIN_USER_DEFINED: Change by a specified amount. + * + * The values of the GtkSpinType enumeration are used to specify the + * change to make in gtk_spin_button_spin(). + */ typedef enum { GTK_SPIN_STEP_FORWARD, @@ -72,7 +103,12 @@ typedef struct _GtkSpinButton GtkSpinButton; typedef struct _GtkSpinButtonPrivate GtkSpinButtonPrivate; typedef struct _GtkSpinButtonClass GtkSpinButtonClass; - +/** + * GtkSpinButton: + * + * The #GtkSpinButton struct contains only private data and should + * not be directly modified. + */ struct _GtkSpinButton { GtkEntry entry;