diff options
author | Tim Janik <timj@gtk.org> | 1998-03-29 20:40:10 +0000 |
---|---|---|
committer | Tim Janik <timj@src.gnome.org> | 1998-03-29 20:40:10 +0000 |
commit | 2f5621e566bb02fb6e4f3592e95164cb9c50bc22 (patch) | |
tree | 9aa3807e48beb4688f0d726900f0f136cafbc026 /gtk/gtkspinbutton.c | |
parent | 93e1585614b72c684b4fa302f6ae2e6d5605e02e (diff) | |
download | gdk-pixbuf-2f5621e566bb02fb6e4f3592e95164cb9c50bc22.tar.gz |
Added wrapping capabilities to GtkSpinButton. New function :
Sun Mar 29 22:29:00 1998 Tim Janik <timj@gtk.org>
* gtk/gtkspinbutton.[ch] gtk/testgtk.c (gtk_spin_button_set_wrap):
Added wrapping capabilities to GtkSpinButton. New function :
gtk_spin_button_set_wrap (Lars Hamann and Stefan Jeske).
Diffstat (limited to 'gtk/gtkspinbutton.c')
-rw-r--r-- | gtk/gtkspinbutton.c | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c index 3f014e04b..f26fc22cc 100644 --- a/gtk/gtkspinbutton.c +++ b/gtk/gtkspinbutton.c @@ -162,6 +162,7 @@ gtk_spin_button_init (GtkSpinButton *spin_button) spin_button->timer_calls = 0; spin_button->digits = 0; spin_button->numeric = 0; + spin_button->wrap = 0; } void @@ -759,21 +760,41 @@ gtk_spin_button_spin (GtkSpinButton *spin_button, gfloat step) { gfloat new_value = 0.0; - + g_return_if_fail (spin_button != NULL); g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button)); if (direction == GTK_ARROW_UP) { - new_value = MIN (spin_button->adjustment->value + step, - spin_button->adjustment->upper); + new_value = spin_button->adjustment->value + step; + if (spin_button->wrap) + { + if (spin_button->adjustment->value == spin_button->adjustment->upper) + new_value = spin_button->adjustment->lower; + else if (new_value > spin_button->adjustment->upper) + new_value = spin_button->adjustment->upper; + } + else + { + new_value = MIN (new_value, spin_button->adjustment->upper); + } } else if (direction == GTK_ARROW_DOWN) { - new_value = MAX (spin_button->adjustment->value - step, - spin_button->adjustment->lower); + new_value = spin_button->adjustment->value - step; + if (spin_button->wrap) + { + if (spin_button->adjustment->value == spin_button->adjustment->lower) + new_value = spin_button->adjustment->upper; + else if (new_value < spin_button->adjustment->lower) + new_value = spin_button->adjustment->lower; + } + else + { + new_value = MAX (new_value, spin_button->adjustment->lower); + } } - + if (new_value != spin_button->adjustment->value) gtk_adjustment_set_value (spin_button->adjustment, new_value); } @@ -1100,3 +1121,13 @@ gtk_spin_button_insert_text (GtkEditable *editable, GTK_EDITABLE_CLASS (parent_class)->insert_text (editable, new_text, new_text_length, position); } + +void +gtk_spin_button_set_wrap (GtkSpinButton *spin_button, + gint wrap) +{ + g_return_if_fail (spin_button != NULL); + g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button)); + + spin_button->wrap = (wrap != 0); +} |