forked from AuroraMiddleware/gtk
Added two new signals to GtkSpinButton, "input" and "output", to make the
* gtk/gtkspinbutton.[c,h] gtk/testgtk.c: Added two new signals to GtkSpinButton, "input" and "output", to make the output more flexible. The user has to provide a mapping between adjustment->value and the output string (and vice versa, if the spin button is editable). See testgtk for examples.
This commit is contained in:
parent
e84df313c4
commit
209f5d5cd4
@ -1,3 +1,11 @@
|
||||
Sun Feb 28 16:46:02 1999 Stefan Jeske <stefan@gtk.org>
|
||||
|
||||
* gtk/gtkspinbutton.[c,h] gtk/testgtk.c: Added two new signals to
|
||||
GtkSpinButton, "input" and "output", to make the output more flexible.
|
||||
The user has to provide a mapping between adjustment->value and the
|
||||
output string (and vice versa, if the spin button is editable).
|
||||
See testgtk for examples.
|
||||
|
||||
Sat Feb 27 01:18:47 1999 Tim Janik <timj@gtk.org>
|
||||
|
||||
* ChangeLog: moved old ChangeLog to ChangeLog.pre-1-2, and started
|
||||
|
@ -1,3 +1,11 @@
|
||||
Sun Feb 28 16:46:02 1999 Stefan Jeske <stefan@gtk.org>
|
||||
|
||||
* gtk/gtkspinbutton.[c,h] gtk/testgtk.c: Added two new signals to
|
||||
GtkSpinButton, "input" and "output", to make the output more flexible.
|
||||
The user has to provide a mapping between adjustment->value and the
|
||||
output string (and vice versa, if the spin button is editable).
|
||||
See testgtk for examples.
|
||||
|
||||
Sat Feb 27 01:18:47 1999 Tim Janik <timj@gtk.org>
|
||||
|
||||
* ChangeLog: moved old ChangeLog to ChangeLog.pre-1-2, and started
|
||||
|
@ -1,3 +1,11 @@
|
||||
Sun Feb 28 16:46:02 1999 Stefan Jeske <stefan@gtk.org>
|
||||
|
||||
* gtk/gtkspinbutton.[c,h] gtk/testgtk.c: Added two new signals to
|
||||
GtkSpinButton, "input" and "output", to make the output more flexible.
|
||||
The user has to provide a mapping between adjustment->value and the
|
||||
output string (and vice versa, if the spin button is editable).
|
||||
See testgtk for examples.
|
||||
|
||||
Sat Feb 27 01:18:47 1999 Tim Janik <timj@gtk.org>
|
||||
|
||||
* ChangeLog: moved old ChangeLog to ChangeLog.pre-1-2, and started
|
||||
|
@ -1,3 +1,11 @@
|
||||
Sun Feb 28 16:46:02 1999 Stefan Jeske <stefan@gtk.org>
|
||||
|
||||
* gtk/gtkspinbutton.[c,h] gtk/testgtk.c: Added two new signals to
|
||||
GtkSpinButton, "input" and "output", to make the output more flexible.
|
||||
The user has to provide a mapping between adjustment->value and the
|
||||
output string (and vice versa, if the spin button is editable).
|
||||
See testgtk for examples.
|
||||
|
||||
Sat Feb 27 01:18:47 1999 Tim Janik <timj@gtk.org>
|
||||
|
||||
* ChangeLog: moved old ChangeLog to ChangeLog.pre-1-2, and started
|
||||
|
@ -1,3 +1,11 @@
|
||||
Sun Feb 28 16:46:02 1999 Stefan Jeske <stefan@gtk.org>
|
||||
|
||||
* gtk/gtkspinbutton.[c,h] gtk/testgtk.c: Added two new signals to
|
||||
GtkSpinButton, "input" and "output", to make the output more flexible.
|
||||
The user has to provide a mapping between adjustment->value and the
|
||||
output string (and vice versa, if the spin button is editable).
|
||||
See testgtk for examples.
|
||||
|
||||
Sat Feb 27 01:18:47 1999 Tim Janik <timj@gtk.org>
|
||||
|
||||
* ChangeLog: moved old ChangeLog to ChangeLog.pre-1-2, and started
|
||||
|
@ -1,3 +1,11 @@
|
||||
Sun Feb 28 16:46:02 1999 Stefan Jeske <stefan@gtk.org>
|
||||
|
||||
* gtk/gtkspinbutton.[c,h] gtk/testgtk.c: Added two new signals to
|
||||
GtkSpinButton, "input" and "output", to make the output more flexible.
|
||||
The user has to provide a mapping between adjustment->value and the
|
||||
output string (and vice versa, if the spin button is editable).
|
||||
See testgtk for examples.
|
||||
|
||||
Sat Feb 27 01:18:47 1999 Tim Janik <timj@gtk.org>
|
||||
|
||||
* ChangeLog: moved old ChangeLog to ChangeLog.pre-1-2, and started
|
||||
|
@ -1,3 +1,11 @@
|
||||
Sun Feb 28 16:46:02 1999 Stefan Jeske <stefan@gtk.org>
|
||||
|
||||
* gtk/gtkspinbutton.[c,h] gtk/testgtk.c: Added two new signals to
|
||||
GtkSpinButton, "input" and "output", to make the output more flexible.
|
||||
The user has to provide a mapping between adjustment->value and the
|
||||
output string (and vice versa, if the spin button is editable).
|
||||
See testgtk for examples.
|
||||
|
||||
Sat Feb 27 01:18:47 1999 Tim Janik <timj@gtk.org>
|
||||
|
||||
* ChangeLog: moved old ChangeLog to ChangeLog.pre-1-2, and started
|
||||
|
@ -59,6 +59,13 @@ enum {
|
||||
ARG_VALUE
|
||||
};
|
||||
|
||||
/* Signals */
|
||||
enum
|
||||
{
|
||||
INPUT,
|
||||
OUTPUT,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static void gtk_spin_button_class_init (GtkSpinButtonClass *klass);
|
||||
static void gtk_spin_button_init (GtkSpinButton *spin_button);
|
||||
@ -113,9 +120,13 @@ static void gtk_spin_button_insert_text (GtkEditable *editable,
|
||||
gint *position);
|
||||
static void gtk_spin_button_real_spin (GtkSpinButton *spin_button,
|
||||
gfloat step);
|
||||
static gint gtk_spin_button_default_input (GtkSpinButton *spin_button,
|
||||
gfloat *new_val);
|
||||
static gint gtk_spin_button_default_output (GtkSpinButton *spin_button);
|
||||
|
||||
|
||||
static GtkEntryClass *parent_class = NULL;
|
||||
static guint spinbutton_signals[LAST_SIGNAL] = {0};
|
||||
|
||||
|
||||
GtkType
|
||||
@ -191,12 +202,29 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class)
|
||||
GTK_TYPE_FLOAT,
|
||||
GTK_ARG_READWRITE,
|
||||
ARG_VALUE);
|
||||
|
||||
|
||||
object_class->set_arg = gtk_spin_button_set_arg;
|
||||
object_class->get_arg = gtk_spin_button_get_arg;
|
||||
object_class->finalize = gtk_spin_button_finalize;
|
||||
|
||||
spinbutton_signals[INPUT] =
|
||||
gtk_signal_new ("input",
|
||||
GTK_RUN_LAST,
|
||||
object_class->type,
|
||||
GTK_SIGNAL_OFFSET (GtkSpinButtonClass, input),
|
||||
gtk_marshal_INT__POINTER,
|
||||
GTK_TYPE_INT, 1, GTK_TYPE_POINTER);
|
||||
|
||||
spinbutton_signals[OUTPUT] =
|
||||
gtk_signal_new ("output",
|
||||
GTK_RUN_LAST,
|
||||
object_class->type,
|
||||
GTK_SIGNAL_OFFSET (GtkSpinButtonClass, output),
|
||||
gtk_marshal_BOOL__NONE,
|
||||
GTK_TYPE_BOOL, 0);
|
||||
|
||||
gtk_object_class_add_signals (object_class, spinbutton_signals, LAST_SIGNAL);
|
||||
|
||||
widget_class->map = gtk_spin_button_map;
|
||||
widget_class->unmap = gtk_spin_button_unmap;
|
||||
widget_class->realize = gtk_spin_button_realize;
|
||||
@ -216,6 +244,9 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class)
|
||||
|
||||
editable_class->insert_text = gtk_spin_button_insert_text;
|
||||
editable_class->activate = gtk_spin_button_activate;
|
||||
|
||||
class->input = NULL;
|
||||
class->output = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -336,9 +367,8 @@ gtk_spin_button_init (GtkSpinButton *spin_button)
|
||||
spin_button->numeric = FALSE;
|
||||
spin_button->wrap = FALSE;
|
||||
spin_button->snap_to_ticks = FALSE;
|
||||
|
||||
gtk_spin_button_set_adjustment (spin_button,
|
||||
(GtkAdjustment*) gtk_adjustment_new (0, 0, 0, 0, 0, 0));
|
||||
(GtkAdjustment*) gtk_adjustment_new (0, 0, 0, 0, 0, 0));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -381,15 +411,16 @@ gtk_spin_button_unmap (GtkWidget *widget)
|
||||
static void
|
||||
gtk_spin_button_realize (GtkWidget *widget)
|
||||
{
|
||||
GtkSpinButton *spin;
|
||||
GtkSpinButton *spin_button;
|
||||
GdkWindowAttr attributes;
|
||||
gint attributes_mask;
|
||||
guint real_width;
|
||||
gint return_val;
|
||||
|
||||
g_return_if_fail (widget != NULL);
|
||||
g_return_if_fail (GTK_IS_SPIN_BUTTON (widget));
|
||||
|
||||
spin = GTK_SPIN_BUTTON (widget);
|
||||
spin_button = GTK_SPIN_BUTTON (widget);
|
||||
|
||||
real_width = widget->allocation.width;
|
||||
widget->allocation.width -= ARROW_SIZE + 2 * widget->style->klass->xthickness;
|
||||
@ -417,11 +448,17 @@ gtk_spin_button_realize (GtkWidget *widget)
|
||||
attributes.width = ARROW_SIZE + 2 * widget->style->klass->xthickness;
|
||||
attributes.height = widget->requisition.height;
|
||||
|
||||
spin->panel = gdk_window_new (gtk_widget_get_parent_window (widget),
|
||||
&attributes, attributes_mask);
|
||||
gdk_window_set_user_data (spin->panel, widget);
|
||||
spin_button->panel = gdk_window_new (gtk_widget_get_parent_window (widget),
|
||||
&attributes, attributes_mask);
|
||||
gdk_window_set_user_data (spin_button->panel, widget);
|
||||
|
||||
gtk_style_set_background (widget->style, spin->panel, GTK_STATE_NORMAL);
|
||||
gtk_style_set_background (widget->style, spin_button->panel, GTK_STATE_NORMAL);
|
||||
|
||||
return_val = FALSE;
|
||||
gtk_signal_emit (GTK_OBJECT (spin_button), spinbutton_signals[OUTPUT],
|
||||
&return_val);
|
||||
if (return_val == FALSE)
|
||||
gtk_spin_button_default_output (spin_button);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -957,13 +994,16 @@ static void
|
||||
gtk_spin_button_value_changed (GtkAdjustment *adjustment,
|
||||
GtkSpinButton *spin_button)
|
||||
{
|
||||
char buf[MAX_TEXT_LENGTH];
|
||||
gint return_val;
|
||||
|
||||
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);
|
||||
return_val = FALSE;
|
||||
gtk_signal_emit (GTK_OBJECT (spin_button), spinbutton_signals[OUTPUT],
|
||||
&return_val);
|
||||
if (return_val == FALSE)
|
||||
gtk_spin_button_default_output (spin_button);
|
||||
}
|
||||
|
||||
static gint
|
||||
@ -1112,57 +1152,11 @@ gtk_spin_button_snap (GtkSpinButton *spin_button,
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gtk_spin_button_update (GtkSpinButton *spin_button)
|
||||
{
|
||||
gfloat val;
|
||||
gchar *error = NULL;
|
||||
|
||||
g_return_if_fail (spin_button != NULL);
|
||||
g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
|
||||
|
||||
val = strtod (gtk_entry_get_text (GTK_ENTRY (spin_button)), &error);
|
||||
|
||||
if (spin_button->update_policy == GTK_UPDATE_ALWAYS)
|
||||
{
|
||||
if (val < spin_button->adjustment->lower)
|
||||
val = spin_button->adjustment->lower;
|
||||
else if (val > spin_button->adjustment->upper)
|
||||
val = spin_button->adjustment->upper;
|
||||
}
|
||||
else if ((spin_button->update_policy == GTK_UPDATE_IF_VALID) &&
|
||||
(*error ||
|
||||
val < spin_button->adjustment->lower ||
|
||||
val > spin_button->adjustment->upper))
|
||||
{
|
||||
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
|
||||
{
|
||||
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);
|
||||
}
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit (GTK_OBJECT (spin_button), spinbutton_signals[OUTPUT],
|
||||
&return_val);
|
||||
if (return_val == FALSE)
|
||||
gtk_spin_button_default_output (spin_button);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1306,6 +1300,30 @@ gtk_spin_button_real_spin (GtkSpinButton *spin_button,
|
||||
gtk_adjustment_set_value (adj, new_value);
|
||||
}
|
||||
|
||||
static gint
|
||||
gtk_spin_button_default_input (GtkSpinButton *spin_button,
|
||||
gfloat *new_val)
|
||||
{
|
||||
gchar *err = NULL;
|
||||
|
||||
*new_val = strtod (gtk_entry_get_text (GTK_ENTRY (spin_button)), &err);
|
||||
if (*err)
|
||||
return INPUT_ERROR;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gint
|
||||
gtk_spin_button_default_output (GtkSpinButton *spin_button)
|
||||
{
|
||||
gchar 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);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************
|
||||
***********************************************************
|
||||
@ -1438,12 +1456,11 @@ gtk_spin_button_set_value (GtkSpinButton *spin_button,
|
||||
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);
|
||||
gint return_val = FALSE;
|
||||
gtk_signal_emit (GTK_OBJECT (spin_button), spinbutton_signals[OUTPUT],
|
||||
&return_val);
|
||||
if (return_val == FALSE)
|
||||
gtk_spin_button_default_output (spin_button);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1506,14 +1523,8 @@ gtk_spin_button_set_snap_to_ticks (GtkSpinButton *spin_button,
|
||||
if (new_val != spin_button->snap_to_ticks)
|
||||
{
|
||||
spin_button->snap_to_ticks = new_val;
|
||||
if (new_val)
|
||||
{
|
||||
gchar *error = NULL;
|
||||
gfloat val;
|
||||
|
||||
val = strtod (gtk_entry_get_text (GTK_ENTRY (spin_button)), &error);
|
||||
gtk_spin_button_snap (spin_button, val);
|
||||
}
|
||||
if (new_val && GTK_EDITABLE (spin_button)->editable)
|
||||
gtk_spin_button_update (spin_button);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1586,3 +1597,57 @@ gtk_spin_button_spin (GtkSpinButton *spin_button,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gtk_spin_button_update (GtkSpinButton *spin_button)
|
||||
{
|
||||
gfloat val;
|
||||
gint error = 0;
|
||||
gint return_val;
|
||||
|
||||
g_return_if_fail (spin_button != NULL);
|
||||
g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
|
||||
|
||||
return_val = FALSE;
|
||||
gtk_signal_emit (GTK_OBJECT (spin_button), spinbutton_signals[INPUT],
|
||||
&val, &return_val);
|
||||
if (return_val == FALSE)
|
||||
{
|
||||
return_val = gtk_spin_button_default_input (spin_button, &val);
|
||||
error = (return_val == INPUT_ERROR);
|
||||
}
|
||||
else if (return_val == INPUT_ERROR)
|
||||
error = 1;
|
||||
|
||||
if (spin_button->update_policy == GTK_UPDATE_ALWAYS)
|
||||
{
|
||||
if (val < spin_button->adjustment->lower)
|
||||
val = spin_button->adjustment->lower;
|
||||
else if (val > spin_button->adjustment->upper)
|
||||
val = spin_button->adjustment->upper;
|
||||
}
|
||||
else if ((spin_button->update_policy == GTK_UPDATE_IF_VALID) &&
|
||||
(error ||
|
||||
val < spin_button->adjustment->lower ||
|
||||
val > spin_button->adjustment->upper))
|
||||
{
|
||||
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
|
||||
{
|
||||
if (fabs (val - spin_button->adjustment->value) > EPSILON)
|
||||
gtk_adjustment_set_value (spin_button->adjustment, val);
|
||||
else
|
||||
{
|
||||
return_val = FALSE;
|
||||
gtk_signal_emit (GTK_OBJECT (spin_button), spinbutton_signals[OUTPUT],
|
||||
&return_val);
|
||||
if (return_val == FALSE)
|
||||
gtk_spin_button_default_output (spin_button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ extern "C" {
|
||||
#define GTK_IS_SPIN_BUTTON(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_SPIN_BUTTON))
|
||||
#define GTK_IS_SPIN_BUTTON_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SPIN_BUTTON))
|
||||
|
||||
#define INPUT_ERROR -1
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@ -101,6 +102,10 @@ struct _GtkSpinButton
|
||||
struct _GtkSpinButtonClass
|
||||
{
|
||||
GtkEntryClass parent_class;
|
||||
|
||||
gint (*input) (GtkSpinButton *spin_button,
|
||||
gfloat *new_value);
|
||||
gint (*output) (GtkSpinButton *spin_button);
|
||||
};
|
||||
|
||||
|
||||
|
144
gtk/testgtk.c
144
gtk/testgtk.c
@ -2873,6 +2873,104 @@ get_value (GtkWidget *widget, gpointer data)
|
||||
gtk_label_set_text (label, buf);
|
||||
}
|
||||
|
||||
static gint
|
||||
spin_button_time_output_func (GtkSpinButton *spin_button)
|
||||
{
|
||||
static gchar buf[6];
|
||||
gfloat hours;
|
||||
gfloat minutes;
|
||||
|
||||
hours = spin_button->adjustment->value / 60.0;
|
||||
minutes = (fabs(floor (hours) - hours) < 1e-5) ? 0.0 : 30;
|
||||
sprintf (buf, "%02.0f:%02.0f", floor (hours), minutes);
|
||||
if (strcmp (buf, gtk_entry_get_text (GTK_ENTRY (spin_button))))
|
||||
gtk_entry_set_text (GTK_ENTRY (spin_button), buf);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gint
|
||||
spin_button_month_input_func (GtkSpinButton *spin_button,
|
||||
gfloat *new_val)
|
||||
{
|
||||
gint i;
|
||||
static gchar *month[12] = { "January", "February", "March", "April",
|
||||
"May", "June", "July", "August",
|
||||
"September", "October", "November", "December" };
|
||||
gchar *tmp1, *tmp2;
|
||||
gboolean found = FALSE;
|
||||
|
||||
for (i = 1; i <= 12; i++)
|
||||
{
|
||||
tmp1 = g_strdup (month[i-1]);
|
||||
g_strup (tmp1);
|
||||
tmp2 = g_strdup (gtk_entry_get_text (GTK_ENTRY (spin_button)));
|
||||
g_strup (tmp2);
|
||||
if (strstr (tmp1, tmp2) == tmp1)
|
||||
found = TRUE;
|
||||
g_free (tmp1);
|
||||
g_free (tmp2);
|
||||
if (found)
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
*new_val = 0.0;
|
||||
return INPUT_ERROR;
|
||||
}
|
||||
*new_val = (gfloat) i;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gint
|
||||
spin_button_month_output_func (GtkSpinButton *spin_button)
|
||||
{
|
||||
gint i;
|
||||
static gchar *month[12] = { "January", "February", "March", "April",
|
||||
"May", "June", "July", "August", "September",
|
||||
"October", "November", "December" };
|
||||
|
||||
for (i = 1; i <= 12; i++)
|
||||
if (fabs (spin_button->adjustment->value - (double)i) < 1e-5)
|
||||
{
|
||||
if (strcmp (month[i-1], gtk_entry_get_text (GTK_ENTRY (spin_button))))
|
||||
gtk_entry_set_text (GTK_ENTRY (spin_button), month[i-1]);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gint
|
||||
spin_button_hex_input_func (GtkSpinButton *spin_button,
|
||||
gfloat *new_val)
|
||||
{
|
||||
gchar *buf;
|
||||
gchar *err;
|
||||
gfloat res;
|
||||
|
||||
buf = gtk_entry_get_text (GTK_ENTRY (spin_button));
|
||||
res = (gfloat)(strtol(buf, &err, 16));
|
||||
*new_val = res;
|
||||
if (*err)
|
||||
return INPUT_ERROR;
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gint
|
||||
spin_button_hex_output_func (GtkSpinButton *spin_button)
|
||||
{
|
||||
static gchar buf[7];
|
||||
gint val;
|
||||
|
||||
val = (gint) spin_button->adjustment->value;
|
||||
if (fabs (val) < 1e-5)
|
||||
sprintf (buf, "0x00");
|
||||
else
|
||||
sprintf (buf, "0x%.2X", val);
|
||||
if (strcmp (buf, gtk_entry_get_text (GTK_ENTRY (spin_button))))
|
||||
gtk_entry_set_text (GTK_ENTRY (spin_button), buf);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
create_spins (void)
|
||||
{
|
||||
@ -2910,7 +3008,7 @@ create_spins (void)
|
||||
gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
|
||||
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
||||
|
||||
/* Day, month, year spinners */
|
||||
/* Time, month, hex spinners */
|
||||
|
||||
hbox = gtk_hbox_new (FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 5);
|
||||
@ -2918,16 +3016,19 @@ create_spins (void)
|
||||
vbox2 = gtk_vbox_new (FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 5);
|
||||
|
||||
label = gtk_label_new ("Day :");
|
||||
label = gtk_label_new ("Time :");
|
||||
gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, TRUE, 0);
|
||||
|
||||
adj = (GtkAdjustment *) gtk_adjustment_new (1.0, 1.0, 31.0, 1.0,
|
||||
5.0, 0.0);
|
||||
adj = (GtkAdjustment *) gtk_adjustment_new (0, 0, 1410, 30, 60, 0);
|
||||
spinner = gtk_spin_button_new (adj, 0, 0);
|
||||
gtk_editable_set_editable (GTK_EDITABLE (spinner), FALSE);
|
||||
gtk_signal_connect (GTK_OBJECT (spinner),
|
||||
"output",
|
||||
GTK_SIGNAL_FUNC (spin_button_time_output_func),
|
||||
NULL);
|
||||
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner), TRUE);
|
||||
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinner),
|
||||
GTK_SHADOW_OUT);
|
||||
gtk_widget_set_usize (spinner, 55, -1);
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), spinner, FALSE, TRUE, 0);
|
||||
|
||||
vbox2 = gtk_vbox_new (FALSE, 0);
|
||||
@ -2940,24 +3041,39 @@ create_spins (void)
|
||||
adj = (GtkAdjustment *) gtk_adjustment_new (1.0, 1.0, 12.0, 1.0,
|
||||
5.0, 0.0);
|
||||
spinner = gtk_spin_button_new (adj, 0, 0);
|
||||
gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (spinner),
|
||||
GTK_UPDATE_IF_VALID);
|
||||
gtk_signal_connect (GTK_OBJECT (spinner),
|
||||
"input",
|
||||
GTK_SIGNAL_FUNC (spin_button_month_input_func),
|
||||
NULL);
|
||||
gtk_signal_connect (GTK_OBJECT (spinner),
|
||||
"output",
|
||||
GTK_SIGNAL_FUNC (spin_button_month_output_func),
|
||||
NULL);
|
||||
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner), TRUE);
|
||||
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinner),
|
||||
GTK_SHADOW_ETCHED_IN);
|
||||
gtk_widget_set_usize (spinner, 85, -1);
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), spinner, FALSE, TRUE, 0);
|
||||
|
||||
vbox2 = gtk_vbox_new (FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 5);
|
||||
|
||||
label = gtk_label_new ("Year :");
|
||||
label = gtk_label_new ("Hex :");
|
||||
gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, TRUE, 0);
|
||||
|
||||
adj = (GtkAdjustment *) gtk_adjustment_new (1998.0, 0.0, 2100.0,
|
||||
1.0, 100.0, 0.0);
|
||||
adj = (GtkAdjustment *) gtk_adjustment_new (0, 0, 255, 1, 16, 0);
|
||||
spinner = gtk_spin_button_new (adj, 0, 0);
|
||||
gtk_editable_set_editable (GTK_EDITABLE (spinner), TRUE);
|
||||
gtk_signal_connect (GTK_OBJECT (spinner),
|
||||
"input",
|
||||
GTK_SIGNAL_FUNC (spin_button_hex_input_func),
|
||||
NULL);
|
||||
gtk_signal_connect (GTK_OBJECT (spinner),
|
||||
"output",
|
||||
GTK_SIGNAL_FUNC (spin_button_hex_output_func),
|
||||
NULL);
|
||||
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner), TRUE);
|
||||
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinner),
|
||||
GTK_SHADOW_IN);
|
||||
gtk_widget_set_usize (spinner, 55, 0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), spinner, FALSE, TRUE, 0);
|
||||
|
||||
@ -2994,7 +3110,6 @@ create_spins (void)
|
||||
|
||||
adj = (GtkAdjustment *) gtk_adjustment_new (2, 1, 5, 1, 1, 0);
|
||||
spinner2 = gtk_spin_button_new (adj, 0.0, 0);
|
||||
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner2), TRUE);
|
||||
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
|
||||
GTK_SIGNAL_FUNC (change_digits),
|
||||
(gpointer) spinner2);
|
||||
@ -3055,6 +3170,7 @@ create_spins (void)
|
||||
gtk_widget_destroy (window);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Cursors
|
||||
*/
|
||||
|
144
tests/testgtk.c
144
tests/testgtk.c
@ -2873,6 +2873,104 @@ get_value (GtkWidget *widget, gpointer data)
|
||||
gtk_label_set_text (label, buf);
|
||||
}
|
||||
|
||||
static gint
|
||||
spin_button_time_output_func (GtkSpinButton *spin_button)
|
||||
{
|
||||
static gchar buf[6];
|
||||
gfloat hours;
|
||||
gfloat minutes;
|
||||
|
||||
hours = spin_button->adjustment->value / 60.0;
|
||||
minutes = (fabs(floor (hours) - hours) < 1e-5) ? 0.0 : 30;
|
||||
sprintf (buf, "%02.0f:%02.0f", floor (hours), minutes);
|
||||
if (strcmp (buf, gtk_entry_get_text (GTK_ENTRY (spin_button))))
|
||||
gtk_entry_set_text (GTK_ENTRY (spin_button), buf);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gint
|
||||
spin_button_month_input_func (GtkSpinButton *spin_button,
|
||||
gfloat *new_val)
|
||||
{
|
||||
gint i;
|
||||
static gchar *month[12] = { "January", "February", "March", "April",
|
||||
"May", "June", "July", "August",
|
||||
"September", "October", "November", "December" };
|
||||
gchar *tmp1, *tmp2;
|
||||
gboolean found = FALSE;
|
||||
|
||||
for (i = 1; i <= 12; i++)
|
||||
{
|
||||
tmp1 = g_strdup (month[i-1]);
|
||||
g_strup (tmp1);
|
||||
tmp2 = g_strdup (gtk_entry_get_text (GTK_ENTRY (spin_button)));
|
||||
g_strup (tmp2);
|
||||
if (strstr (tmp1, tmp2) == tmp1)
|
||||
found = TRUE;
|
||||
g_free (tmp1);
|
||||
g_free (tmp2);
|
||||
if (found)
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
*new_val = 0.0;
|
||||
return INPUT_ERROR;
|
||||
}
|
||||
*new_val = (gfloat) i;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gint
|
||||
spin_button_month_output_func (GtkSpinButton *spin_button)
|
||||
{
|
||||
gint i;
|
||||
static gchar *month[12] = { "January", "February", "March", "April",
|
||||
"May", "June", "July", "August", "September",
|
||||
"October", "November", "December" };
|
||||
|
||||
for (i = 1; i <= 12; i++)
|
||||
if (fabs (spin_button->adjustment->value - (double)i) < 1e-5)
|
||||
{
|
||||
if (strcmp (month[i-1], gtk_entry_get_text (GTK_ENTRY (spin_button))))
|
||||
gtk_entry_set_text (GTK_ENTRY (spin_button), month[i-1]);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gint
|
||||
spin_button_hex_input_func (GtkSpinButton *spin_button,
|
||||
gfloat *new_val)
|
||||
{
|
||||
gchar *buf;
|
||||
gchar *err;
|
||||
gfloat res;
|
||||
|
||||
buf = gtk_entry_get_text (GTK_ENTRY (spin_button));
|
||||
res = (gfloat)(strtol(buf, &err, 16));
|
||||
*new_val = res;
|
||||
if (*err)
|
||||
return INPUT_ERROR;
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gint
|
||||
spin_button_hex_output_func (GtkSpinButton *spin_button)
|
||||
{
|
||||
static gchar buf[7];
|
||||
gint val;
|
||||
|
||||
val = (gint) spin_button->adjustment->value;
|
||||
if (fabs (val) < 1e-5)
|
||||
sprintf (buf, "0x00");
|
||||
else
|
||||
sprintf (buf, "0x%.2X", val);
|
||||
if (strcmp (buf, gtk_entry_get_text (GTK_ENTRY (spin_button))))
|
||||
gtk_entry_set_text (GTK_ENTRY (spin_button), buf);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
create_spins (void)
|
||||
{
|
||||
@ -2910,7 +3008,7 @@ create_spins (void)
|
||||
gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
|
||||
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
||||
|
||||
/* Day, month, year spinners */
|
||||
/* Time, month, hex spinners */
|
||||
|
||||
hbox = gtk_hbox_new (FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 5);
|
||||
@ -2918,16 +3016,19 @@ create_spins (void)
|
||||
vbox2 = gtk_vbox_new (FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 5);
|
||||
|
||||
label = gtk_label_new ("Day :");
|
||||
label = gtk_label_new ("Time :");
|
||||
gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, TRUE, 0);
|
||||
|
||||
adj = (GtkAdjustment *) gtk_adjustment_new (1.0, 1.0, 31.0, 1.0,
|
||||
5.0, 0.0);
|
||||
adj = (GtkAdjustment *) gtk_adjustment_new (0, 0, 1410, 30, 60, 0);
|
||||
spinner = gtk_spin_button_new (adj, 0, 0);
|
||||
gtk_editable_set_editable (GTK_EDITABLE (spinner), FALSE);
|
||||
gtk_signal_connect (GTK_OBJECT (spinner),
|
||||
"output",
|
||||
GTK_SIGNAL_FUNC (spin_button_time_output_func),
|
||||
NULL);
|
||||
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner), TRUE);
|
||||
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinner),
|
||||
GTK_SHADOW_OUT);
|
||||
gtk_widget_set_usize (spinner, 55, -1);
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), spinner, FALSE, TRUE, 0);
|
||||
|
||||
vbox2 = gtk_vbox_new (FALSE, 0);
|
||||
@ -2940,24 +3041,39 @@ create_spins (void)
|
||||
adj = (GtkAdjustment *) gtk_adjustment_new (1.0, 1.0, 12.0, 1.0,
|
||||
5.0, 0.0);
|
||||
spinner = gtk_spin_button_new (adj, 0, 0);
|
||||
gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (spinner),
|
||||
GTK_UPDATE_IF_VALID);
|
||||
gtk_signal_connect (GTK_OBJECT (spinner),
|
||||
"input",
|
||||
GTK_SIGNAL_FUNC (spin_button_month_input_func),
|
||||
NULL);
|
||||
gtk_signal_connect (GTK_OBJECT (spinner),
|
||||
"output",
|
||||
GTK_SIGNAL_FUNC (spin_button_month_output_func),
|
||||
NULL);
|
||||
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner), TRUE);
|
||||
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinner),
|
||||
GTK_SHADOW_ETCHED_IN);
|
||||
gtk_widget_set_usize (spinner, 85, -1);
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), spinner, FALSE, TRUE, 0);
|
||||
|
||||
vbox2 = gtk_vbox_new (FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 5);
|
||||
|
||||
label = gtk_label_new ("Year :");
|
||||
label = gtk_label_new ("Hex :");
|
||||
gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, TRUE, 0);
|
||||
|
||||
adj = (GtkAdjustment *) gtk_adjustment_new (1998.0, 0.0, 2100.0,
|
||||
1.0, 100.0, 0.0);
|
||||
adj = (GtkAdjustment *) gtk_adjustment_new (0, 0, 255, 1, 16, 0);
|
||||
spinner = gtk_spin_button_new (adj, 0, 0);
|
||||
gtk_editable_set_editable (GTK_EDITABLE (spinner), TRUE);
|
||||
gtk_signal_connect (GTK_OBJECT (spinner),
|
||||
"input",
|
||||
GTK_SIGNAL_FUNC (spin_button_hex_input_func),
|
||||
NULL);
|
||||
gtk_signal_connect (GTK_OBJECT (spinner),
|
||||
"output",
|
||||
GTK_SIGNAL_FUNC (spin_button_hex_output_func),
|
||||
NULL);
|
||||
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner), TRUE);
|
||||
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinner),
|
||||
GTK_SHADOW_IN);
|
||||
gtk_widget_set_usize (spinner, 55, 0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), spinner, FALSE, TRUE, 0);
|
||||
|
||||
@ -2994,7 +3110,6 @@ create_spins (void)
|
||||
|
||||
adj = (GtkAdjustment *) gtk_adjustment_new (2, 1, 5, 1, 1, 0);
|
||||
spinner2 = gtk_spin_button_new (adj, 0.0, 0);
|
||||
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner2), TRUE);
|
||||
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
|
||||
GTK_SIGNAL_FUNC (change_digits),
|
||||
(gpointer) spinner2);
|
||||
@ -3055,6 +3170,7 @@ create_spins (void)
|
||||
gtk_widget_destroy (window);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Cursors
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user