gnome-commander r1687 - branches/gcmd-1-3/src
- From: epiotr svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-commander r1687 - branches/gcmd-1-3/src
- Date: Fri, 4 Apr 2008 20:34:08 +0100 (BST)
Author: epiotr
Date: Fri Apr 4 20:34:07 2008
New Revision: 1687
URL: http://svn.gnome.org/viewvc/gnome-commander?rev=1687&view=rev
Log:
EggCellRendererKeys: remove superfluous code
Removed:
branches/gcmd-1-3/src/eggaccelerators.cc
branches/gcmd-1-3/src/eggaccelerators.h
Modified:
branches/gcmd-1-3/src/Makefile.am
branches/gcmd-1-3/src/eggcellrendererkeys.cc
branches/gcmd-1-3/src/eggcellrendererkeys.h
Modified: branches/gcmd-1-3/src/Makefile.am
==============================================================================
--- branches/gcmd-1-3/src/Makefile.am (original)
+++ branches/gcmd-1-3/src/Makefile.am Fri Apr 4 20:34:07 2008
@@ -17,7 +17,6 @@
cap.cc cap.h \
dict.h \
dirlist.h dirlist.cc \
- eggaccelerators.h eggaccelerators.cc \
eggcellrendererkeys.h eggcellrendererkeys.cc \
filter.h filter.cc \
gnome-cmd-about-plugin.h gnome-cmd-about-plugin.cc \
Modified: branches/gcmd-1-3/src/eggcellrendererkeys.cc
==============================================================================
--- branches/gcmd-1-3/src/eggcellrendererkeys.cc (original)
+++ branches/gcmd-1-3/src/eggcellrendererkeys.cc Fri Apr 4 20:34:07 2008
@@ -114,11 +114,9 @@
static void egg_cell_renderer_keys_init (EggCellRendererKeys *cell_keys)
{
- cell_keys->accel_mode = EGG_CELL_RENDERER_KEYS_MODE_GTK;
+ cell_keys->accel_mode = GTK_CELL_RENDERER_ACCEL_MODE_GTK;
}
-/* FIXME setup stuff to generate this */
-/* VOID:STRING,UINT,FLAGS,UINT */
static void
marshal_VOID__STRING_UINT_FLAGS_UINT (GClosure *closure,
GValue *return_value,
@@ -231,9 +229,106 @@
}
-static gchar *convert_keysym_state_to_string (guint keysym, EggVirtualModifierType mask)
+inline gchar *convert_keysym_state_to_string (guint accel_key, GdkModifierType accel_mods)
{
- return keysym == 0 ? g_strdup (_("Disabled")) : egg_virtual_accelerator_name (keysym, mask);
+ if (accel_key == 0)
+ return g_strdup (_("Disabled"));
+
+ static const gchar text_shift[] = "Shift+";
+ static const gchar text_control[] = "Ctrl+";
+ static const gchar text_mod1[] = "Alt+";
+ static const gchar text_mod2[] = "Mod2+";
+ static const gchar text_mod3[] = "Mod3+";
+ static const gchar text_mod4[] = "Mod4+";
+ static const gchar text_mod5[] = "Mod5+";
+ static const gchar text_meta[] = "Meta+";
+ static const gchar text_super[] = "Super+";
+ static const gchar text_hyper[] = "Hyper+";
+
+ gchar *keyval_name = gdk_keyval_name (gdk_keyval_to_upper (accel_key));
+ if (!keyval_name)
+ keyval_name = "";
+
+ guint l = strlen (keyval_name);
+
+ if (accel_mods & GDK_SHIFT_MASK)
+ l += sizeof(text_shift)-1;
+ if (accel_mods & GDK_CONTROL_MASK)
+ l += sizeof(text_control)-1;
+ if (accel_mods & GDK_MOD1_MASK)
+ l += sizeof(text_mod1)-1;
+ if (accel_mods & GDK_MOD2_MASK)
+ l += sizeof(text_mod2)-1;
+ if (accel_mods & GDK_MOD3_MASK)
+ l += sizeof(text_mod3)-1;
+ if (accel_mods & GDK_MOD4_MASK)
+ l += sizeof(text_mod4)-1;
+ if (accel_mods & GDK_MOD5_MASK)
+ l += sizeof(text_mod5)-1;
+ if (accel_mods & GDK_META_MASK)
+ l += sizeof(text_meta)-1;
+ if (accel_mods & GDK_HYPER_MASK)
+ l += sizeof(text_hyper)-1;
+ if (accel_mods & GDK_SUPER_MASK)
+ l += sizeof(text_super)-1;
+
+ gchar *accelerator = g_new (gchar, l+1);
+ gchar *s = accelerator;
+
+ if (accel_mods & GDK_SHIFT_MASK)
+ {
+ strcpy (s, text_shift);
+ s += sizeof(text_shift)-1;
+ }
+ if (accel_mods & GDK_CONTROL_MASK)
+ {
+ strcpy (s, text_control);
+ s += sizeof(text_control)-1;
+ }
+ if (accel_mods & GDK_MOD1_MASK)
+ {
+ strcpy (s, text_mod1);
+ s += sizeof(text_mod1)-1;
+ }
+ if (accel_mods & GDK_MOD2_MASK)
+ {
+ strcpy (s, text_mod2);
+ s += sizeof(text_mod2)-1;
+ }
+ if (accel_mods & GDK_MOD3_MASK)
+ {
+ strcpy (s, text_mod3);
+ s += sizeof(text_mod3)-1;
+ }
+ if (accel_mods & GDK_MOD4_MASK)
+ {
+ strcpy (s, text_mod4);
+ s += sizeof(text_mod4)-1;
+ }
+ if (accel_mods & GDK_MOD5_MASK)
+ {
+ strcpy (s, text_mod5);
+ s += sizeof(text_mod5)-1;
+ }
+ if (accel_mods & GDK_META_MASK)
+ {
+ strcpy (s, text_meta);
+ s += sizeof(text_meta)-1;
+ }
+ if (accel_mods & GDK_HYPER_MASK)
+ {
+ strcpy (s, text_hyper);
+ s += sizeof(text_hyper)-1;
+ }
+ if (accel_mods & GDK_SUPER_MASK)
+ {
+ strcpy (s, text_super);
+ s += sizeof(text_super)-1;
+ }
+
+ strcpy (s, keyval_name);
+
+ return accelerator;
}
@@ -277,15 +372,16 @@
break;
case PROP_ACCEL_MASK:
- egg_cell_renderer_keys_set_accelerator (keys, keys->accel_key, (EggVirtualModifierType) g_value_get_flags (value));
+ egg_cell_renderer_keys_set_accelerator (keys, keys->accel_key, (GdkModifierType) g_value_get_flags (value));
break;
case PROP_ACCEL_MODE:
- egg_cell_renderer_keys_set_accel_mode (keys, (EggCellRendererKeysMode) g_value_get_int (value));
+ egg_cell_renderer_keys_set_accel_mode (keys, (GtkCellRendererAccelMode) g_value_get_int (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
}
}
@@ -336,15 +432,9 @@
}
-// FIXME: Currently we don't differentiate between a 'bogus' key (like tab in GTK mode) and a removed key.
static gboolean grab_key_callback (GtkWidget *widget, GdkEventKey *event, void *data)
{
- char *path;
- guint upper;
- GdkModifierType ignored_modifiers;
-
EggCellRendererKeys *keys = EGG_CELL_RENDERER_KEYS (data);
- guint accel_mods = 0;
if (is_modifier (event->hardware_keycode))
return TRUE;
@@ -352,62 +442,64 @@
gboolean edited = FALSE;
guint consumed_modifiers = 0;
- gdk_keymap_translate_keyboard_state (gdk_keymap_get_default (),
+ GdkDisplay *display = gtk_widget_get_display (widget);
+
+ gdk_keymap_translate_keyboard_state (gdk_keymap_get_for_display (display),
event->hardware_keycode,
(GdkModifierType) event->state,
event->group,
NULL, NULL, NULL, (GdkModifierType *) &consumed_modifiers);
- upper = event->keyval;
- guint accel_keyval = gdk_keyval_to_lower (upper);
- if (accel_keyval == GDK_ISO_Left_Tab)
- accel_keyval = GDK_Tab;
+ guint accel_key = gdk_keyval_to_lower (event->keyval);
+ guint accel_mods = 0;
+
+ if (accel_key == GDK_ISO_Left_Tab)
+ accel_key = GDK_Tab;
+
+ accel_mods = event->state & gtk_accelerator_get_default_mod_mask ();
+ // filter consumed modifiers
+ if (keys->accel_mode == GTK_CELL_RENDERER_ACCEL_MODE_GTK)
+ accel_mods &= ~consumed_modifiers;
// Put shift back if it changed the case of the key, not otherwise.
- if (upper != accel_keyval && (consumed_modifiers & GDK_SHIFT_MASK))
- consumed_modifiers &= ~(GDK_SHIFT_MASK);
+ if (accel_key != event->keyval)
+ accel_mods |= GDK_SHIFT_MASK;
- egg_keymap_resolve_virtual_modifiers (gdk_keymap_get_default (),
- EggVirtualModifierType (EGG_VIRTUAL_NUM_LOCK_MASK | EGG_VIRTUAL_SCROLL_LOCK_MASK),
- &ignored_modifiers);
-
- /* filter consumed/ignored modifiers */
-
- if (keys->accel_mode == EGG_CELL_RENDERER_KEYS_MODE_GTK)
- accel_mods = event->state & ~(consumed_modifiers | ignored_modifiers);
- else if (keys->accel_mode == EGG_CELL_RENDERER_KEYS_MODE_X)
- accel_mods = event->state & ~(ignored_modifiers);
- else
- g_assert_not_reached ();
+ if (accel_mods == 0)
+ {
+ switch (event->keyval)
+ {
+ case GDK_Escape:
+ accel_key = 0;
+ accel_mods = 0;
- if (accel_mods == 0 && accel_keyval == GDK_Escape)
- goto out; /* cancel */
+ goto out; // cancel
- /* clear the accelerator on Backspace */
- if (keys->edit_key!=0 && accel_mods==0 && accel_keyval==GDK_BackSpace)
- accel_keyval = 0;
+ default:
+ break;
+ }
+ }
- if (keys->accel_mode == EGG_CELL_RENDERER_KEYS_MODE_GTK)
+ if (keys->accel_mode == GTK_CELL_RENDERER_ACCEL_MODE_GTK)
{
- if (!gtk_accelerator_valid (accel_keyval, (GdkModifierType) accel_mods))
+ if (accel_key != GDK_Tab && !gtk_accelerator_valid (accel_key, (GdkModifierType) accel_mods))
{
- accel_keyval = 0;
- accel_mods = 0;
- }
+ // gtk_widget_error_bell (widget); // FIXME: since 2.12, uncomment when dependency is met
- /* Remove modifiers like super and hyper, as GTK+ ignores them. */
- accel_mods &= GDK_MODIFIER_MASK;
+ return TRUE;
+ }
}
edited = TRUE;
- out:
- path = g_strdup ((gchar *) g_object_get_data (G_OBJECT (keys->edit_widget), EGG_CELL_RENDERER_TEXT_PATH));
- gdk_keyboard_ungrab (event->time);
- gdk_pointer_ungrab (event->time);
+ out:
+ gdk_display_keyboard_ungrab (display, event->time);
+ gdk_display_pointer_ungrab (display, event->time);
+
+ char *path = g_strdup ((gchar *) g_object_get_data (G_OBJECT (keys->edit_widget), EGG_CELL_RENDERER_TEXT_PATH));
gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (keys->edit_widget));
gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (keys->edit_widget));
@@ -415,7 +507,7 @@
keys->grab_widget = NULL;
if (edited)
- g_signal_emit_by_name (G_OBJECT (keys), "accel-edited", path, accel_keyval, accel_mods, event->hardware_keycode);
+ g_signal_emit_by_name (G_OBJECT (keys), "accel-edited", path, accel_key, accel_mods, event->hardware_keycode);
g_free (path);
@@ -425,10 +517,12 @@
static void ungrab_stuff (GtkWidget *widget, gpointer data)
{
- EggCellRendererKeys *keys = EGG_CELL_RENDERER_KEYS (data);
+ GdkDisplay *display = gtk_widget_get_display (widget);
+
+ gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
+ gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
- gdk_keyboard_ungrab (GDK_CURRENT_TIME);
- gdk_pointer_ungrab (GDK_CURRENT_TIME);
+ EggCellRendererKeys *keys = EGG_CELL_RENDERER_KEYS (data);
g_signal_handlers_disconnect_by_func (G_OBJECT (keys->grab_widget), (gpointer) G_CALLBACK (grab_key_callback), data);
}
@@ -526,10 +620,7 @@
gtk_widget_modify_fg (label, GTK_STATE_NORMAL, &widget->style->fg[GTK_STATE_SELECTED]);
- if (keys->accel_key != 0)
- gtk_label_set_text (GTK_LABEL (label), _("Type a new accelerator"));
- else
- gtk_label_set_text (GTK_LABEL (label), _("Type a new accelerator"));
+ gtk_label_set_text (GTK_LABEL (label), _("New accelerator..."));
gtk_container_add (GTK_CONTAINER (eventbox), label);
@@ -545,7 +636,7 @@
}
-void egg_cell_renderer_keys_set_accelerator (EggCellRendererKeys *keys, guint keyval, EggVirtualModifierType mask)
+void egg_cell_renderer_keys_set_accelerator (EggCellRendererKeys *keys, guint keyval, GdkModifierType mask)
{
g_return_if_fail (EGG_IS_CELL_RENDERER_KEYS (keys));
@@ -563,7 +654,6 @@
if (mask != keys->accel_mask)
{
keys->accel_mask = mask;
-
g_object_notify (G_OBJECT (keys), "accel-mods");
changed = TRUE;
}
@@ -582,7 +672,7 @@
}
-void egg_cell_renderer_keys_get_accelerator (EggCellRendererKeys *keys, guint *keyval, EggVirtualModifierType *mask)
+void egg_cell_renderer_keys_get_accelerator (EggCellRendererKeys *keys, guint *keyval, GdkModifierType *mask)
{
g_return_if_fail (EGG_IS_CELL_RENDERER_KEYS (keys));
@@ -594,10 +684,10 @@
}
-void egg_cell_renderer_keys_set_accel_mode (EggCellRendererKeys *keys, EggCellRendererKeysMode accel_mode)
+void egg_cell_renderer_keys_set_accel_mode (EggCellRendererKeys *keys, GtkCellRendererAccelMode accel_mode)
{
g_return_if_fail (EGG_IS_CELL_RENDERER_KEYS (keys));
keys->accel_mode = accel_mode;
- g_object_notify (G_OBJECT (keys), "accel_mode");
+ g_object_notify (G_OBJECT (keys), "accel-mode");
}
Modified: branches/gcmd-1-3/src/eggcellrendererkeys.h
==============================================================================
--- branches/gcmd-1-3/src/eggcellrendererkeys.h (original)
+++ branches/gcmd-1-3/src/eggcellrendererkeys.h Fri Apr 4 20:34:07 2008
@@ -53,23 +53,16 @@
typedef struct _EggCellRendererKeysClass EggCellRendererKeysClass;
-typedef enum
-{
- EGG_CELL_RENDERER_KEYS_MODE_GTK,
- EGG_CELL_RENDERER_KEYS_MODE_X,
-} EggCellRendererKeysMode;
-
-
struct _EggCellRendererKeys
{
GtkCellRendererText parent;
guint accel_key;
- EggVirtualModifierType accel_mask;
+ GdkModifierType accel_mask;
GtkWidget *edit_widget;
GtkWidget *grab_widget;
guint edit_key;
GtkWidget *sizing_label;
- EggCellRendererKeysMode accel_mode;
+ GtkCellRendererAccelMode accel_mode;
};
struct _EggCellRendererKeysClass
@@ -79,15 +72,15 @@
void (* keys_edited) (EggCellRendererKeys *keys,
const char *path_string,
guint keyval,
- EggVirtualModifierType mask,
+ GdkModifierType mask,
guint hardware_keycode);
};
GType egg_cell_renderer_keys_get_type (void);
GtkCellRenderer *egg_cell_renderer_keys_new (void);
-void egg_cell_renderer_keys_set_accelerator (EggCellRendererKeys *keys, guint keyval, EggVirtualModifierType mask);
-void egg_cell_renderer_keys_get_accelerator (EggCellRendererKeys *keys, guint *keyval, EggVirtualModifierType *mask);
-void egg_cell_renderer_keys_set_accel_mode (EggCellRendererKeys *keys, EggCellRendererKeysMode accel_mode);
+void egg_cell_renderer_keys_set_accelerator (EggCellRendererKeys *keys, guint keyval, GdkModifierType mask);
+void egg_cell_renderer_keys_get_accelerator (EggCellRendererKeys *keys, guint *keyval, GdkModifierType *mask);
+void egg_cell_renderer_keys_set_accel_mode (EggCellRendererKeys *keys, GtkCellRendererAccelMode accel_mode);
#endif // __GTK_CELL_RENDERER_KEYS_H__
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]