From: Darren S. <ds...@us...> - 2004-12-20 21:54:47
|
Update of /cvsroot/xine/gnome-xine/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2917/src Modified Files: preferences.c Log Message: Allow Return/Enter to cause update of string items. Use GtkSpinButton for numeric items (replacing GtkEntry). Index: preferences.c =================================================================== RCS file: /cvsroot/xine/gnome-xine/src/preferences.c,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- preferences.c 14 Dec 2004 18:20:32 -0000 1.36 +++ preferences.c 20 Dec 2004 21:54:34 -0000 1.37 @@ -30,6 +30,7 @@ #include <X11/Xlib.h> #include <gtk/gtk.h> #include <gdk/gdk.h> +#include <gdk/gdkkeysyms.h> #include <glib.h> #include <stdio.h> #include <stdlib.h> @@ -177,30 +178,14 @@ return FALSE; } -static gboolean num_entry_cb (GtkEditable *editable, GdkEventFocus *even, - gpointer user_data) +static gboolean entry_keypress_cb (GtkEditable *widget, GdkEventKey *event, + gpointer data) { - xine_cfg_entry_t entry; - gchar *key = (gchar *) user_data; - gchar *str; - int num; - - if (update_lock) - return FALSE; - - logprintf ("preferences: num entry cb for key %s\n", key); - - if (!xine_config_lookup_entry (xine, key, &entry)) - return FALSE; - - str = gtk_editable_get_chars (editable, 0, -1); - if ( sscanf (str, "%d", &num) != 1 || num == entry.num_value) - return FALSE; - - logprintf ("preferences: updating entry to %d\n", num); - entry.num_value = num; - xine_config_update_entry (xine, &entry); - + if (event->keyval == GDK_Return || event->keyval == GDK_KP_Enter) + { + entry_cb (widget, NULL, data); + return TRUE; + } return FALSE; } @@ -227,10 +212,9 @@ xine_config_update_entry (xine, &entry); } -static void range_cb (GtkWidget* widget, gpointer data) { - +static void range_cb (GtkAdjustment *adj, const gchar *key) +{ xine_cfg_entry_t entry; - gchar *key = (gchar *) data; if (update_lock) return; @@ -238,11 +222,30 @@ logprintf ("preferences: range cb for key %s\n", key); if (!xine_config_lookup_entry (xine, key, &entry) || - entry.num_value == GTK_ADJUSTMENT(widget)->value) + entry.num_value == adj->value) + return; + + logprintf ("preferences: updating entry to %d\n", value); + entry.num_value = adj->value; + xine_config_update_entry (xine, &entry); +} + +static void spin_cb (GtkSpinButton *widget, const gchar *key) +{ + xine_cfg_entry_t entry; + int value; + + if (update_lock) + return; + + logprintf ("preferences: spin cb for key %s\n", key); + + value = gtk_spin_button_get_value_as_int (widget); + if (!xine_config_lookup_entry (xine, key, &entry) || + entry.num_value == value) return; - logprintf ("preferences: updating entry to %d\n", entry.num_value); - entry.num_value = GTK_ADJUSTMENT(widget)->value; + logprintf ("preferences: updating entry to %d\n", value); xine_config_update_entry (xine, &entry); } @@ -296,7 +299,9 @@ case XINE_CONFIG_TYPE_STRING: widget = gtk_entry_new(); - g_signal_connect (GTK_OBJECT(widget), "focus-out-event", + g_signal_connect (GTK_OBJECT(widget), "key-press-event", + G_CALLBACK(entry_keypress_cb), (gchar *)entry->key); + g_signal_connect (GTK_OBJECT(widget), "focus-out-event", G_CALLBACK(entry_cb), (gchar *)entry->key); gtk_entry_set_text (GTK_ENTRY(widget), entry->str_value); break; @@ -309,19 +314,21 @@ gtk_scale_set_draw_value (GTK_SCALE(widget), TRUE); gtk_scale_set_value_pos (GTK_SCALE(widget), GTK_POS_TOP); gtk_scale_set_digits (GTK_SCALE(widget), 0); - g_signal_connect (GTK_OBJECT (adj), "value-changed", + g_signal_connect (adj, "value-changed", G_CALLBACK (range_cb), (gchar *)entry->key); } break; case XINE_CONFIG_TYPE_NUM: { - char contents[20]; - widget = gtk_entry_new(); - snprintf (contents, sizeof (contents), "%i", entry->num_value); - g_signal_connect (GTK_OBJECT(widget), "focus-out-event", - G_CALLBACK(num_entry_cb), (gchar *)entry->key); - gtk_entry_set_text (GTK_ENTRY(widget), contents); + GtkObject *adj = gtk_adjustment_new (entry->num_value, 0, INT_MAX, + 1, 10, 0); + widget = gtk_spin_button_new (GTK_ADJUSTMENT(adj), 1, 0); + gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON(widget), + GTK_UPDATE_ALWAYS); + gtk_spin_button_set_numeric (GTK_SPIN_BUTTON(widget), TRUE); + g_signal_connect (GTK_OBJECT(widget), "value-changed", + G_CALLBACK(spin_cb), (gchar *)entry->key); } break; |