summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorStefan Jeske <stefan@src.gnome.org>1998-06-19 17:33:51 +0000
committerStefan Jeske <stefan@src.gnome.org>1998-06-19 17:33:51 +0000
commit1ae617e324572ab2d435e185dcd31b92090a0e6c (patch)
treee34deca5414123ea32899b5b9ef6490c2d6906d1 /gtk
parent5c68ecbc0f681cc119108bbd01bdf3ce67a14a6d (diff)
downloadgtk+-1ae617e324572ab2d435e185dcd31b92090a0e6c.tar.gz
- Bug fix for precision problem causing occasional double emission of
* gtk/gtkspinbutton.h gtk/gtkspinbutton.c gtk/testgtk.c: - Bug fix for precision problem causing occasional double emission of "value_changed" signal (hopefully works now). - API change (should be binary compatible) : new enum GtkSpinType; modified gtk_spin_button_spin to use it. Modified cursor example appropriately. To spin by something other than step_/page_increment, use gtk_spin_button_spin (spin, GTK_SPIN_USER_DEFINED, increment). - Made GTK_SHADOW_NONE the default. ;) - Fixed casting of GtkAdjustment* to GtkWidget* in gtk_spin_button_value_changed.
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkspinbutton.c520
-rw-r--r--gtk/gtkspinbutton.h20
-rw-r--r--gtk/testgtk.c7
3 files changed, 339 insertions, 208 deletions
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index 84c5a194d8..d2e60bd88c 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -37,6 +37,7 @@
#define SPIN_BUTTON_TIMER_DELAY 20
#define MAX_TEXT_LENGTH 256
#define MAX_TIMER_CALLS 5
+#define EPSILON 1e-5
static void gtk_spin_button_class_init (GtkSpinButtonClass *klass);
@@ -71,7 +72,7 @@ static gint gtk_spin_button_focus_out (GtkWidget *widget,
static void gtk_spin_button_draw_arrow (GtkSpinButton *spin_button,
guint arrow);
static gint gtk_spin_button_timer (GtkSpinButton *spin_button);
-static void gtk_spin_button_value_changed (GtkWidget *widget,
+static void gtk_spin_button_value_changed (GtkAdjustment *adjustment,
GtkSpinButton *spin_button);
static gint gtk_spin_button_key_press (GtkWidget *widget,
GdkEventKey *event);
@@ -83,11 +84,14 @@ static void gtk_spin_button_snap (GtkSpinButton *spin_button,
gfloat val);
static void gtk_spin_button_insert_text (GtkEditable *editable,
const gchar *new_text,
- gint new_text_length,
+ gint new_text_length,
gint *position);
+static void gtk_spin_button_real_spin (GtkSpinButton *spin_button,
+ guint direction,
+ gfloat step);
-static GtkWidgetClass *parent_class = NULL;
+static GtkEntryClass *parent_class = NULL;
guint
@@ -155,7 +159,7 @@ gtk_spin_button_init (GtkSpinButton *spin_button)
{
spin_button->adjustment = NULL;
spin_button->panel = NULL;
- spin_button->shadow_type = GTK_SHADOW_OUT;
+ spin_button->shadow_type = GTK_SHADOW_NONE;
spin_button->timer = 0;
spin_button->ev_time = 0;
spin_button->climb_rate = 0.0;
@@ -164,7 +168,7 @@ gtk_spin_button_init (GtkSpinButton *spin_button)
spin_button->in_child = 2;
spin_button->click_child = 2;
spin_button->button = 0;
- spin_button->need_timer = 0;
+ spin_button->need_timer = FALSE;
spin_button->timer_calls = 0;
spin_button->digits = 0;
spin_button->numeric = FALSE;
@@ -172,44 +176,6 @@ gtk_spin_button_init (GtkSpinButton *spin_button)
spin_button->snap_to_ticks = FALSE;
}
-void
-gtk_spin_button_construct (GtkSpinButton *spin_button,
- GtkAdjustment *adjustment,
- gfloat climb_rate,
- gint digits)
-{
- char buf[MAX_TEXT_LENGTH];
-
- g_return_if_fail (spin_button != NULL);
- g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
- g_return_if_fail (digits >= 0 && digits < 6);
-
- if (!adjustment)
- adjustment = (GtkAdjustment*) gtk_adjustment_new (0, 0, 0, 0, 0, 0);
-
- gtk_spin_button_set_adjustment (spin_button, adjustment);
- spin_button->digits = digits;
- sprintf (buf, "%0.*f", digits, adjustment->value);
- gtk_entry_set_text (GTK_ENTRY (spin_button), buf);
- spin_button->climb_rate = climb_rate;
-}
-
-GtkWidget *
-gtk_spin_button_new (GtkAdjustment *adjustment,
- gfloat climb_rate,
- gint digits)
-{
- GtkSpinButton *spin;
-
- g_return_val_if_fail (digits >= 0 && digits < 6, NULL);
-
- spin = gtk_type_new (gtk_spin_button_get_type ());
-
- gtk_spin_button_construct (spin, adjustment, climb_rate, digits);
-
- return GTK_WIDGET (spin);
-}
-
static void
gtk_spin_button_finalize (GtkObject *object)
{
@@ -585,8 +551,8 @@ gtk_spin_button_button_press (GtkWidget *widget,
spin->click_child = GTK_ARROW_UP;
if (event->button == 1)
{
- gtk_spin_button_spin (spin, spin->click_child,
- spin->adjustment->step_increment);
+ gtk_spin_button_real_spin (spin, spin->click_child,
+ spin->adjustment->step_increment);
if (!spin->timer)
{
spin->timer_step = spin->adjustment->step_increment;
@@ -598,8 +564,8 @@ gtk_spin_button_button_press (GtkWidget *widget,
}
else if (event->button == 2)
{
- gtk_spin_button_spin (spin, spin->click_child,
- spin->adjustment->page_increment);
+ gtk_spin_button_real_spin (spin, spin->click_child,
+ spin->adjustment->page_increment);
if (!spin->timer)
{
spin->timer_step = spin->adjustment->page_increment;
@@ -616,8 +582,8 @@ gtk_spin_button_button_press (GtkWidget *widget,
spin->click_child = GTK_ARROW_DOWN;
if (event->button == 1)
{
- gtk_spin_button_spin (spin, spin->click_child,
- spin->adjustment->step_increment);
+ gtk_spin_button_real_spin (spin, spin->click_child,
+ spin->adjustment->step_increment);
if (!spin->timer)
{
spin->timer_step = spin->adjustment->step_increment;
@@ -629,8 +595,8 @@ gtk_spin_button_button_press (GtkWidget *widget,
}
else if (event->button == 2)
{
- gtk_spin_button_spin (spin, spin->click_child,
- spin->adjustment->page_increment);
+ gtk_spin_button_real_spin (spin, spin->click_child,
+ spin->adjustment->page_increment);
if (!spin->timer)
{
spin->timer_step = spin->adjustment->page_increment;
@@ -754,18 +720,19 @@ gtk_spin_button_timer (GtkSpinButton *spin_button)
if (spin_button->timer)
{
- gtk_spin_button_spin (spin_button, spin_button->click_child,
- spin_button->timer_step);
-
- if (spin_button->need_timer) {
- spin_button->need_timer = FALSE;
- spin_button->timer = gtk_timeout_add
- (SPIN_BUTTON_TIMER_DELAY, (GtkFunction) gtk_spin_button_timer,
- (gpointer) spin_button);
- return FALSE;
- }
- else if (spin_button->climb_rate > 0.0 &&
- spin_button->timer_step < spin_button->adjustment->page_increment)
+ gtk_spin_button_real_spin (spin_button, spin_button->click_child,
+ spin_button->timer_step);
+
+ if (spin_button->need_timer)
+ {
+ spin_button->need_timer = FALSE;
+ spin_button->timer = gtk_timeout_add
+ (SPIN_BUTTON_TIMER_DELAY, (GtkFunction) gtk_spin_button_timer,
+ (gpointer) spin_button);
+ return FALSE;
+ }
+ else if (spin_button->climb_rate > 0.0 && spin_button->timer_step
+ < spin_button->adjustment->page_increment)
{
if (spin_button->timer_calls < MAX_TIMER_CALLS)
spin_button->timer_calls++;
@@ -774,64 +741,22 @@ gtk_spin_button_timer (GtkSpinButton *spin_button)
spin_button->timer_calls = 0;
spin_button->timer_step += spin_button->climb_rate;
}
- }
+ }
return TRUE;
}
return FALSE;
}
-void
-gtk_spin_button_spin (GtkSpinButton *spin_button,
- guint direction,
- 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 = 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 = 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);
-}
-
static void
-gtk_spin_button_value_changed (GtkWidget *widget,
+gtk_spin_button_value_changed (GtkAdjustment *adjustment,
GtkSpinButton *spin_button)
{
char buf[MAX_TEXT_LENGTH];
- g_return_if_fail (widget != NULL);
- g_return_if_fail (GTK_IS_ADJUSTMENT (widget));
-
- sprintf (buf, "%0.*f", spin_button->digits, spin_button->adjustment->value);
+ g_return_if_fail (adjustment != NULL);
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+ sprintf (buf, "%0.*f", spin_button->digits, adjustment->value);
gtk_entry_set_text (GTK_ENTRY (spin_button), buf);
}
@@ -845,6 +770,7 @@ gtk_spin_button_key_press (GtkWidget *widget,
g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (GTK_IS_SPIN_BUTTON (widget), FALSE);
+ g_return_val_if_fail (event != NULL, FALSE);
spin = GTK_SPIN_BUTTON (widget);
key = event->keyval;
@@ -858,6 +784,7 @@ gtk_spin_button_key_press (GtkWidget *widget,
switch (key)
{
case GDK_Up:
+
if (GTK_WIDGET_HAS_FOCUS (widget))
{
gtk_signal_emit_stop_by_name (GTK_OBJECT (widget),
@@ -865,7 +792,7 @@ gtk_spin_button_key_press (GtkWidget *widget,
if (!key_repeat)
spin->timer_step = spin->adjustment->step_increment;
- gtk_spin_button_spin (spin, GTK_ARROW_UP, spin->timer_step);
+ gtk_spin_button_real_spin (spin, GTK_ARROW_UP, spin->timer_step);
if (key_repeat)
{
@@ -884,7 +811,9 @@ gtk_spin_button_key_press (GtkWidget *widget,
return TRUE;
}
return FALSE;
+
case GDK_Down:
+
if (GTK_WIDGET_HAS_FOCUS (widget))
{
gtk_signal_emit_stop_by_name (GTK_OBJECT (widget),
@@ -892,7 +821,7 @@ gtk_spin_button_key_press (GtkWidget *widget,
if (!key_repeat)
spin->timer_step = spin->adjustment->step_increment;
- gtk_spin_button_spin (spin, GTK_ARROW_DOWN, spin->timer_step);
+ gtk_spin_button_real_spin (spin, GTK_ARROW_DOWN, spin->timer_step);
if (key_repeat)
{
@@ -911,23 +840,29 @@ gtk_spin_button_key_press (GtkWidget *widget,
return TRUE;
}
return FALSE;
+
case GDK_Page_Up:
+
if (event->state & GDK_CONTROL_MASK)
gtk_adjustment_set_value (spin->adjustment, spin->adjustment->upper);
else
- gtk_spin_button_spin (spin, GTK_ARROW_UP,
- spin->adjustment->page_increment);
+ gtk_spin_button_real_spin (spin, GTK_ARROW_UP,
+ spin->adjustment->page_increment);
return TRUE;
+
case GDK_Page_Down:
+
if (event->state & GDK_CONTROL_MASK)
gtk_adjustment_set_value (spin->adjustment, spin->adjustment->lower);
else
- gtk_spin_button_spin (spin, GTK_ARROW_DOWN,
- spin->adjustment->page_increment);
+ gtk_spin_button_real_spin (spin, GTK_ARROW_DOWN,
+ spin->adjustment->page_increment);
return TRUE;
+
default:
break;
}
+
return GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event);
}
@@ -959,7 +894,18 @@ gtk_spin_button_snap (GtkSpinButton *spin_button,
val = spin_button->adjustment->lower + floor (tmp) * inc;
else
val = spin_button->adjustment->lower + ceil (tmp) * inc;
- gtk_adjustment_set_value (spin_button->adjustment, val);
+
+ if (fabs (val - spin_button->adjustment->value) > EPSILON)
+ gtk_adjustment_set_value (spin_button->adjustment, val);
+ else
+ {
+ char buf[MAX_TEXT_LENGTH];
+
+ sprintf (buf, "%0.*f", spin_button->digits,
+ spin_button->adjustment->value);
+ if (strcmp (buf, gtk_entry_get_text (GTK_ENTRY (spin_button))))
+ gtk_entry_set_text (GTK_ENTRY (spin_button), buf);
+ }
}
static void
@@ -985,15 +931,26 @@ gtk_spin_button_update (GtkSpinButton *spin_button)
val < spin_button->adjustment->lower ||
val > spin_button->adjustment->upper))
{
- gtk_signal_emit_by_name (GTK_OBJECT (spin_button->adjustment),
- "value_changed");
+ gtk_spin_button_value_changed (spin_button->adjustment, spin_button);
return;
}
if (spin_button->snap_to_ticks)
gtk_spin_button_snap (spin_button, val);
else
- gtk_adjustment_set_value (spin_button->adjustment, val);
+ {
+ if (fabs (val - spin_button->adjustment->value) > EPSILON)
+ gtk_adjustment_set_value (spin_button->adjustment, val);
+ else
+ {
+ char buf[MAX_TEXT_LENGTH];
+
+ sprintf (buf, "%0.*f", spin_button->digits,
+ spin_button->adjustment->value);
+ if (strcmp (buf, gtk_entry_get_text (GTK_ENTRY (spin_button))))
+ gtk_entry_set_text (GTK_ENTRY (spin_button), buf);
+ }
+ }
}
static void
@@ -1006,6 +963,169 @@ gtk_spin_button_activate (GtkEditable *editable)
gtk_spin_button_update (GTK_SPIN_BUTTON (editable));
}
+static void
+gtk_spin_button_insert_text (GtkEditable *editable,
+ const gchar *new_text,
+ gint new_text_length,
+ gint *position)
+{
+ GtkEntry *entry;
+ GtkSpinButton *spin;
+
+ g_return_if_fail (editable != NULL);
+ g_return_if_fail (GTK_IS_SPIN_BUTTON (editable));
+
+ entry = GTK_ENTRY (editable);
+ spin = GTK_SPIN_BUTTON (editable);
+
+ if (spin->numeric)
+ {
+ struct lconv *lc;
+ gboolean sign;
+ gint dotpos = -1;
+ gint i;
+ gchar pos_sign;
+ gchar neg_sign;
+
+ lc = localeconv ();
+
+ if (*(lc->negative_sign))
+ neg_sign = *(lc->negative_sign);
+ else
+ neg_sign = '-';
+
+ if (*(lc->positive_sign))
+ pos_sign = *(lc->positive_sign);
+ else
+ pos_sign = '+';
+
+ sign = ((strchr (entry->text, neg_sign) != 0) ||
+ (strchr (entry->text, pos_sign) != 0));
+
+ if (sign && !(*position))
+ return;
+
+ dotpos = strchr (entry->text, *(lc->decimal_point)) - entry->text;
+
+ if (dotpos > -1 && *position > dotpos &&
+ spin->digits - entry->text_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 (!spin->digits || dotpos > -1 ||
+ (new_text_length - 1 - i + entry->text_length - *position >
+ spin->digits))
+ return;
+ dotpos = *position + i;
+ }
+ else if (new_text[i] < 0x30 || new_text[i] > 0x39)
+ return;
+ }
+ }
+
+ GTK_EDITABLE_CLASS (parent_class)->insert_text (editable, new_text,
+ new_text_length, position);
+}
+
+static void
+gtk_spin_button_real_spin (GtkSpinButton *spin_button,
+ guint direction,
+ gfloat step)
+{
+ GtkAdjustment *adj;
+ gfloat new_value = 0.0;
+
+ g_return_if_fail (spin_button != NULL);
+ g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
+
+ adj = spin_button->adjustment;
+
+ if (direction == GTK_ARROW_UP)
+ {
+ new_value = adj->value + step;
+ if (spin_button->wrap)
+ {
+ if (fabs (adj->value - adj->upper) < EPSILON)
+ new_value = adj->lower;
+ else if (new_value > adj->upper)
+ new_value = adj->upper;
+ }
+ else
+ new_value = MIN (new_value, adj->upper);
+ }
+ else if (direction == GTK_ARROW_DOWN)
+ {
+ new_value = adj->value - step;
+ if (spin_button->wrap)
+ {
+ if (fabs (adj->value - adj->lower) < EPSILON)
+ new_value = adj->upper;
+ else if (new_value < adj->lower)
+ new_value = adj->lower;
+ }
+ else
+ new_value = MAX (new_value, adj->lower);
+ }
+
+ if (fabs (new_value - adj->value) > EPSILON)
+ gtk_adjustment_set_value (adj, new_value);
+}
+
+
+/***********************************************************
+ ***********************************************************
+ *** Public interface ***
+ ***********************************************************
+ ***********************************************************/
+
+
+void
+gtk_spin_button_construct (GtkSpinButton *spin_button,
+ GtkAdjustment *adjustment,
+ gfloat climb_rate,
+ gint digits)
+{
+ char buf[MAX_TEXT_LENGTH];
+
+ g_return_if_fail (spin_button != NULL);
+ g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
+ g_return_if_fail (digits >= 0 && digits < 6);
+
+ if (!adjustment)
+ adjustment = (GtkAdjustment*) gtk_adjustment_new (0, 0, 0, 0, 0, 0);
+
+ gtk_spin_button_set_adjustment (spin_button, adjustment);
+ spin_button->digits = digits;
+ sprintf (buf, "%0.*f", digits, adjustment->value);
+ gtk_entry_set_text (GTK_ENTRY (spin_button), buf);
+ spin_button->climb_rate = climb_rate;
+}
+
+GtkWidget *
+gtk_spin_button_new (GtkAdjustment *adjustment,
+ gfloat climb_rate,
+ gint digits)
+{
+ GtkSpinButton *spin;
+
+ g_return_val_if_fail (digits >= 0 && digits < 6, NULL);
+
+ spin = gtk_type_new (gtk_spin_button_get_type ());
+
+ gtk_spin_button_construct (spin, adjustment, climb_rate, digits);
+
+ return GTK_WIDGET (spin);
+}
+
void
gtk_spin_button_set_adjustment (GtkSpinButton *spin_button,
GtkAdjustment *adjustment)
@@ -1026,10 +1146,9 @@ gtk_spin_button_set_adjustment (GtkSpinButton *spin_button,
{
gtk_object_ref (GTK_OBJECT (adjustment));
gtk_object_sink (GTK_OBJECT (adjustment));
- gtk_signal_connect
- (GTK_OBJECT (adjustment), "value_changed",
- (GtkSignalFunc) gtk_spin_button_value_changed,
- (gpointer) spin_button);
+ gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed",
+ (GtkSignalFunc) gtk_spin_button_value_changed,
+ (gpointer) spin_button);
}
}
}
@@ -1054,8 +1173,7 @@ gtk_spin_button_set_digits (GtkSpinButton *spin_button,
if (spin_button->digits != digits)
{
spin_button->digits = digits;
- gtk_signal_emit_by_name (GTK_OBJECT (spin_button->adjustment),
- "value_changed");
+ gtk_spin_button_value_changed (spin_button->adjustment, spin_button);
}
}
@@ -1090,8 +1208,17 @@ gtk_spin_button_set_value (GtkSpinButton *spin_button,
g_return_if_fail (spin_button != NULL);
g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
- if (spin_button->adjustment->value != value)
+ if (fabs (value - spin_button->adjustment->value) > EPSILON)
gtk_adjustment_set_value (spin_button->adjustment, value);
+ else
+ {
+ char buf[MAX_TEXT_LENGTH];
+
+ sprintf (buf, "%0.*f", spin_button->digits,
+ spin_button->adjustment->value);
+ if (strcmp (buf, gtk_entry_get_text (GTK_ENTRY (spin_button))))
+ gtk_entry_set_text (GTK_ENTRY (spin_button), buf);
+ }
}
void
@@ -1114,79 +1241,6 @@ gtk_spin_button_set_numeric (GtkSpinButton *spin_button,
spin_button->numeric = (numeric != 0);
}
-static void
-gtk_spin_button_insert_text (GtkEditable *editable,
- const gchar *new_text,
- gint new_text_length,
- gint *position)
-{
- GtkEntry *entry;
- GtkSpinButton *spin;
-
- g_return_if_fail (editable != NULL);
- g_return_if_fail (GTK_IS_SPIN_BUTTON (editable));
-
- entry = GTK_ENTRY (editable);
- spin = GTK_SPIN_BUTTON (editable);
-
- if (spin->numeric)
- {
- struct lconv *lc;
- gboolean sign;
- gint dotpos = -1;
- gint i;
- gchar pos_sign;
- gchar neg_sign;
-
- lc = localeconv ();
-
- if (*(lc->negative_sign))
- neg_sign = *(lc->negative_sign);
- else
- neg_sign = '-';
-
- if (*(lc->positive_sign))
- pos_sign = *(lc->positive_sign);
- else
- pos_sign = '+';
-
- sign = ((strchr (entry->text, neg_sign) != 0) ||
- (strchr (entry->text, pos_sign) != 0));
-
- if (sign && !(*position))
- return;
-
- dotpos = strchr (entry->text, *(lc->decimal_point)) - entry->text;
-
- if (dotpos > -1 && *position > dotpos &&
- spin->digits - entry->text_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 (!spin->digits || dotpos > -1 ||
- (new_text_length - 1 - i + entry->text_length - *position >
- spin->digits))
- return;
- dotpos = *position + i;
- }
- else if (new_text[i] < 0x30 || new_text[i] > 0x39)
- return;
- }
- }
-
- 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)
@@ -1236,3 +1290,69 @@ gtk_spin_button_set_snap_to_ticks (GtkSpinButton *spin_button,
}
}
}
+
+void
+gtk_spin_button_spin (GtkSpinButton *spin_button,
+ GtkSpinType direction,
+ gfloat increment)
+{
+ GtkAdjustment *adj;
+ gfloat diff;
+
+ g_return_if_fail (spin_button != NULL);
+ g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
+
+ adj = spin_button->adjustment;
+
+ switch (direction)
+ {
+ case GTK_SPIN_STEP_FORWARD:
+
+ gtk_spin_button_real_spin (spin_button, GTK_ARROW_UP,
+ adj->step_increment);
+ break;
+
+ case GTK_SPIN_STEP_BACKWARD:
+
+ gtk_spin_button_real_spin (spin_button, GTK_ARROW_DOWN,
+ adj->step_increment);
+ break;
+
+ case GTK_SPIN_PAGE_FORWARD:
+
+ gtk_spin_button_real_spin (spin_button, GTK_ARROW_UP,
+ adj->page_increment);
+ break;
+
+ case GTK_SPIN_PAGE_BACKWARD:
+
+ gtk_spin_button_real_spin (spin_button, GTK_ARROW_DOWN,
+ adj->page_increment);
+ break;
+
+ case GTK_SPIN_HOME:
+
+ diff = adj->value - adj->lower;
+ if (diff > EPSILON)
+ gtk_spin_button_real_spin (spin_button, GTK_ARROW_DOWN, diff);
+ break;
+
+ case GTK_SPIN_END:
+
+ diff = adj->upper - adj->value;
+ if (diff > EPSILON)
+ gtk_spin_button_real_spin (spin_button, GTK_ARROW_UP, diff);
+ break;
+
+ case GTK_SPIN_USER_DEFINED:
+
+ if (increment != 0)
+ gtk_spin_button_real_spin (spin_button, (increment < 0) ?
+ GTK_ARROW_DOWN : GTK_ARROW_UP,
+ increment);
+ break;
+
+ default:
+ break;
+ }
+}
diff --git a/gtk/gtkspinbutton.h b/gtk/gtkspinbutton.h
index 99f2995eef..ef50d76705 100644
--- a/gtk/gtkspinbutton.h
+++ b/gtk/gtkspinbutton.h
@@ -45,7 +45,18 @@ typedef enum
GTK_UPDATE_IF_VALID
} GtkSpinButtonUpdatePolicy;
-
+typedef enum
+{
+ 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
+} GtkSpinType;
+
+
typedef struct _GtkSpinButton GtkSpinButton;
typedef struct _GtkSpinButtonClass GtkSpinButtonClass;
@@ -83,6 +94,7 @@ struct _GtkSpinButtonClass
GtkEntryClass parent_class;
};
+
guint gtk_spin_button_get_type (void);
void gtk_spin_button_construct (GtkSpinButton *spin_button,
@@ -115,9 +127,9 @@ void gtk_spin_button_set_update_policy (GtkSpinButton *spin_button,
void gtk_spin_button_set_numeric (GtkSpinButton *spin_button,
gint numeric);
-void gtk_spin_button_spin (GtkSpinButton *spin_button,
- guint direction,
- gfloat step);
+void gtk_spin_button_spin (GtkSpinButton *spin_button,
+ GtkSpinType direction,
+ gfloat increment);
void gtk_spin_button_set_wrap (GtkSpinButton *spin_button,
gint wrap);
diff --git a/gtk/testgtk.c b/gtk/testgtk.c
index 2a98c46db0..955dd06a49 100644
--- a/gtk/testgtk.c
+++ b/gtk/testgtk.c
@@ -2510,7 +2510,7 @@ create_spins (void)
spinner = gtk_spin_button_new (adj, 0, 0);
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner), TRUE);
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinner),
- GTK_SHADOW_NONE);
+ GTK_SHADOW_OUT);
gtk_box_pack_start (GTK_BOX (vbox2), spinner, FALSE, TRUE, 0);
vbox2 = gtk_vbox_new (FALSE, 0);
@@ -2714,9 +2714,8 @@ cursor_event (GtkWidget *widget,
((event->button.button == 1) ||
(event->button.button == 3)))
{
- gtk_spin_button_spin (spinner,
- event->button.button == 1 ? GTK_ARROW_UP : GTK_ARROW_DOWN,
- spinner->adjustment->step_increment);
+ gtk_spin_button_spin (spinner, event->button.button == 1 ?
+ GTK_SPIN_STEP_FORWARD : GTK_SPIN_STEP_BACKWARD, 0);
return TRUE;
}