gimp r25552 - in trunk: . app/display



Author: neo
Date: Wed Apr 30 08:40:16 2008
New Revision: 25552
URL: http://svn.gnome.org/viewvc/gimp?rev=25552&view=rev

Log:
2008-04-30  Sven Neumann  <sven gimp org>

	* app/display/gimpscalecombobox.c: install a "key-press-event"
	handler and reset the entry when the Escape key is pressed.



Modified:
   trunk/ChangeLog
   trunk/app/display/gimpscalecombobox.c

Modified: trunk/app/display/gimpscalecombobox.c
==============================================================================
--- trunk/app/display/gimpscalecombobox.c	(original)
+++ trunk/app/display/gimpscalecombobox.c	Wed Apr 30 08:40:16 2008
@@ -24,6 +24,7 @@
 #include "stdlib.h"
 
 #include <gtk/gtk.h>
+#include "gdk/gdkkeysyms.h"
 
 #include "libgimpbase/gimpbase.h"
 #include "libgimpmath/gimpmath.h"
@@ -52,19 +53,22 @@
 };
 
 
-static void   gimp_scale_combo_box_finalize       (GObject           *object);
+static void      gimp_scale_combo_box_finalize        (GObject           *object);
 
-static void   gimp_scale_combo_box_style_set      (GtkWidget         *widget,
-                                                   GtkStyle          *prev_style);
+static void      gimp_scale_combo_box_style_set       (GtkWidget         *widget,
+                                                       GtkStyle          *prev_style);
 
-static void   gimp_scale_combo_box_changed        (GimpScaleComboBox *combo_box);
-static void   gimp_scale_combo_box_entry_activate (GtkEntry          *entry,
-                                                   GimpScaleComboBox *combo_box);
-
-static void   gimp_scale_combo_box_scale_iter_set (GtkListStore  *store,
-                                                   GtkTreeIter   *iter,
-                                                   gdouble        scale,
-                                                   gboolean       persistent);
+static void      gimp_scale_combo_box_changed         (GimpScaleComboBox *combo_box);
+static void      gimp_scale_combo_box_entry_activate  (GtkWidget         *entry,
+                                                       GimpScaleComboBox *combo_box);
+static gboolean  gimp_scale_combo_box_entry_key_press (GtkWidget         *entry,
+                                                       GdkEventKey       *event,
+                                                       GimpScaleComboBox *combo_box);
+
+static void      gimp_scale_combo_box_scale_iter_set  (GtkListStore      *store,
+                                                       GtkTreeIter       *iter,
+                                                       gdouble            scale,
+                                                       gboolean           persistent);
 
 
 G_DEFINE_TYPE (GimpScaleComboBox, gimp_scale_combo_box,
@@ -167,6 +171,9 @@
   g_signal_connect (entry, "activate",
                     G_CALLBACK (gimp_scale_combo_box_entry_activate),
                     combo_box);
+  g_signal_connect (entry, "key-press-event",
+                    G_CALLBACK (gimp_scale_combo_box_entry_key_press),
+                    combo_box);
 }
 
 static void
@@ -303,20 +310,21 @@
 }
 
 static void
-gimp_scale_combo_box_entry_activate (GtkEntry          *entry,
+gimp_scale_combo_box_entry_activate (GtkWidget         *entry,
                                      GimpScaleComboBox *combo_box)
 {
-  gdouble scale;
+  const gchar *text = gtk_entry_get_text (GTK_ENTRY (entry));
+  gdouble      scale;
 
-  if (gimp_scale_combo_box_parse_text (gtk_entry_get_text (entry), &scale) &&
-      scale >= 1.0 / 256.0 &&
+  if (gimp_scale_combo_box_parse_text (text, &scale) &&
+      scale >= 1.0 / 256.0                           &&
       scale <= 256.0)
     {
       gimp_scale_combo_box_set_scale (combo_box, scale);
     }
   else
     {
-      gtk_widget_error_bell (GTK_WIDGET (entry));
+      gtk_widget_error_bell (entry);
 
       gimp_scale_combo_box_set_scale (combo_box, combo_box->scale);
     }
@@ -324,6 +332,23 @@
   g_signal_emit (combo_box, scale_combo_box_signals[ENTRY_ACTIVATED], 0);
 }
 
+static gboolean
+gimp_scale_combo_box_entry_key_press (GtkWidget         *entry,
+                                      GdkEventKey       *event,
+                                      GimpScaleComboBox *combo_box)
+{
+  if (event->keyval == GDK_Escape)
+    {
+      gimp_scale_combo_box_set_scale (combo_box, combo_box->scale);
+
+      g_signal_emit (combo_box, scale_combo_box_signals[ENTRY_ACTIVATED], 0);
+
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
 static void
 gimp_scale_combo_box_scale_iter_set (GtkListStore *store,
                                      GtkTreeIter  *iter,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]