install a "key-press-event" handler and reset the entry when the Escape
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. svn path=/trunk/; revision=25552
This commit is contained in:

committed by
Sven Neumann

parent
1b332ec856
commit
89e4fdbc44
@ -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 @@ enum
|
||||
};
|
||||
|
||||
|
||||
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_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);
|
||||
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 @@ gimp_scale_combo_box_init (GimpScaleComboBox *combo_box)
|
||||
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 @@ gimp_scale_combo_box_parse_text (const gchar *text,
|
||||
}
|
||||
|
||||
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 @@ gimp_scale_combo_box_entry_activate (GtkEntry *entry,
|
||||
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,
|
||||
|
Reference in New Issue
Block a user