|
|
0fe339 |
diff --git a/gtk/gtkcellrendereraccel.c b/gtk/gtkcellrendereraccel.c
|
|
|
0fe339 |
index 32f385e..8ea1d86 100644
|
|
|
0fe339 |
--- a/gtk/gtkcellrendereraccel.c
|
|
|
0fe339 |
+++ b/gtk/gtkcellrendereraccel.c
|
|
|
0fe339 |
@@ -35,16 +35,14 @@
|
|
|
0fe339 |
* @Short_description: Renders a keyboard accelerator in a cell
|
|
|
0fe339 |
* @Title: GtkCellRendererAccel
|
|
|
0fe339 |
*
|
|
|
0fe339 |
- * #GtkCellRendererAccel displays a keyboard accelerator (i.e. a
|
|
|
0fe339 |
- * key combination like <keycombo><keycap>Control</keycap><keycap>a</keycap></keycombo>.
|
|
|
0fe339 |
- * If the cell renderer is editable, the accelerator can be changed by
|
|
|
0fe339 |
- * simply typing the new combination.
|
|
|
0fe339 |
+ * #GtkCellRendererAccel displays a keyboard accelerator (i.e. a key
|
|
|
0fe339 |
+ * combination like `Control + a`). If the cell renderer is editable,
|
|
|
0fe339 |
+ * the accelerator can be changed by simply typing the new combination.
|
|
|
0fe339 |
*
|
|
|
0fe339 |
* The #GtkCellRendererAccel cell renderer was added in GTK+ 2.10.
|
|
|
0fe339 |
*/
|
|
|
0fe339 |
|
|
|
0fe339 |
|
|
|
0fe339 |
-
|
|
|
0fe339 |
static void gtk_cell_renderer_accel_get_property (GObject *object,
|
|
|
0fe339 |
guint param_id,
|
|
|
0fe339 |
GValue *value,
|
|
|
0fe339 |
@@ -70,6 +68,9 @@ static gchar *convert_keysym_state_to_string (GtkCellRendererAccel *accel,
|
|
|
0fe339 |
guint keysym,
|
|
|
0fe339 |
GdkModifierType mask,
|
|
|
0fe339 |
guint keycode);
|
|
|
0fe339 |
+static GtkWidget *gtk_cell_editable_event_box_new (GtkCellRenderer *cell,
|
|
|
0fe339 |
+ GtkCellRendererAccelMode mode,
|
|
|
0fe339 |
+ const gchar *path);
|
|
|
0fe339 |
|
|
|
0fe339 |
enum {
|
|
|
0fe339 |
ACCEL_EDITED,
|
|
|
0fe339 |
@@ -78,42 +79,35 @@ enum {
|
|
|
0fe339 |
};
|
|
|
0fe339 |
|
|
|
0fe339 |
enum {
|
|
|
0fe339 |
- PROP_0,
|
|
|
0fe339 |
- PROP_ACCEL_KEY,
|
|
|
0fe339 |
+ PROP_ACCEL_KEY = 1,
|
|
|
0fe339 |
PROP_ACCEL_MODS,
|
|
|
0fe339 |
PROP_KEYCODE,
|
|
|
0fe339 |
PROP_ACCEL_MODE
|
|
|
0fe339 |
};
|
|
|
0fe339 |
|
|
|
0fe339 |
+static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
0fe339 |
+
|
|
|
0fe339 |
struct _GtkCellRendererAccelPrivate
|
|
|
0fe339 |
{
|
|
|
0fe339 |
- GtkWidget *edit_widget;
|
|
|
0fe339 |
- GtkWidget *grab_widget;
|
|
|
0fe339 |
GtkWidget *sizing_label;
|
|
|
0fe339 |
|
|
|
0fe339 |
- GdkDevice *grab_keyboard;
|
|
|
0fe339 |
- GdkDevice *grab_pointer;
|
|
|
0fe339 |
-
|
|
|
0fe339 |
GtkCellRendererAccelMode accel_mode;
|
|
|
0fe339 |
-
|
|
|
0fe339 |
GdkModifierType accel_mods;
|
|
|
0fe339 |
-
|
|
|
0fe339 |
guint accel_key;
|
|
|
0fe339 |
guint keycode;
|
|
|
0fe339 |
-};
|
|
|
0fe339 |
|
|
|
0fe339 |
-static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
0fe339 |
+ GdkDevice *grab_keyboard;
|
|
|
0fe339 |
+ GdkDevice *grab_pointer;
|
|
|
0fe339 |
+};
|
|
|
0fe339 |
|
|
|
0fe339 |
G_DEFINE_TYPE (GtkCellRendererAccel, gtk_cell_renderer_accel, GTK_TYPE_CELL_RENDERER_TEXT)
|
|
|
0fe339 |
|
|
|
0fe339 |
static void
|
|
|
0fe339 |
gtk_cell_renderer_accel_init (GtkCellRendererAccel *cell_accel)
|
|
|
0fe339 |
{
|
|
|
0fe339 |
gchar *text;
|
|
|
0fe339 |
|
|
|
0fe339 |
- cell_accel->priv = G_TYPE_INSTANCE_GET_PRIVATE (cell_accel,
|
|
|
0fe339 |
- GTK_TYPE_CELL_RENDERER_ACCEL,
|
|
|
0fe339 |
- GtkCellRendererAccelPrivate);
|
|
|
0fe339 |
+ cell_accel->priv = G_TYPE_INSTANCE_GET_PRIVATE (cell_accel, GTK_TYPE_CELL_RENDERER_ACCEL, GtkCellRendererAccelPrivate);
|
|
|
0fe339 |
|
|
|
0fe339 |
text = convert_keysym_state_to_string (cell_accel, 0, 0, 0);
|
|
|
0fe339 |
g_object_set (cell_accel, "text", text, NULL);
|
|
|
0fe339 |
@@ -150,7 +144,7 @@ gtk_cell_renderer_accel_class_init (GtkCellRendererAccelClass *cell_accel_class)
|
|
|
0fe339 |
0,
|
|
|
0fe339 |
G_MAXINT,
|
|
|
0fe339 |
0,
|
|
|
0fe339 |
- GTK_PARAM_READWRITE));
|
|
|
0fe339 |
+ GTK_PARAM_READWRITE));
|
|
|
0fe339 |
|
|
|
0fe339 |
/**
|
|
|
0fe339 |
* GtkCellRendererAccel:accel-mods:
|
|
|
0fe339 |
@@ -166,7 +160,7 @@ gtk_cell_renderer_accel_class_init (GtkCellRendererAccelClass *cell_accel_class)
|
|
|
0fe339 |
P_("The modifier mask of the accelerator"),
|
|
|
0fe339 |
GDK_TYPE_MODIFIER_TYPE,
|
|
|
0fe339 |
0,
|
|
|
0fe339 |
- GTK_PARAM_READWRITE));
|
|
|
0fe339 |
+ GTK_PARAM_READWRITE));
|
|
|
0fe339 |
|
|
|
0fe339 |
/**
|
|
|
0fe339 |
* GtkCellRendererAccel:keycode:
|
|
|
0fe339 |
@@ -185,7 +179,7 @@ gtk_cell_renderer_accel_class_init (GtkCellRendererAccelClass *cell_accel_class)
|
|
|
0fe339 |
0,
|
|
|
0fe339 |
G_MAXINT,
|
|
|
0fe339 |
0,
|
|
|
0fe339 |
- GTK_PARAM_READWRITE));
|
|
|
0fe339 |
+ GTK_PARAM_READWRITE));
|
|
|
0fe339 |
|
|
|
0fe339 |
/**
|
|
|
0fe339 |
* GtkCellRendererAccel:accel-mode:
|
|
|
0fe339 |
@@ -204,7 +198,7 @@ gtk_cell_renderer_accel_class_init (GtkCellRendererAccelClass *cell_accel_class)
|
|
|
0fe339 |
P_("The type of accelerators"),
|
|
|
0fe339 |
GTK_TYPE_CELL_RENDERER_ACCEL_MODE,
|
|
|
0fe339 |
GTK_CELL_RENDERER_ACCEL_MODE_GTK,
|
|
|
0fe339 |
- GTK_PARAM_READWRITE));
|
|
|
0fe339 |
+ GTK_PARAM_READWRITE));
|
|
|
0fe339 |
|
|
|
0fe339 |
/**
|
|
|
0fe339 |
* GtkCellRendererAccel::accel-edited:
|
|
|
0fe339 |
@@ -307,10 +297,10 @@ convert_keysym_state_to_string (GtkCellRendererAccel *accel,
|
|
|
0fe339 |
}
|
|
|
0fe339 |
|
|
|
0fe339 |
static void
|
|
|
0fe339 |
-gtk_cell_renderer_accel_get_property (GObject *object,
|
|
|
0fe339 |
- guint param_id,
|
|
|
0fe339 |
- GValue *value,
|
|
|
0fe339 |
- GParamSpec *pspec)
|
|
|
0fe339 |
+gtk_cell_renderer_accel_get_property (GObject *object,
|
|
|
0fe339 |
+ guint param_id,
|
|
|
0fe339 |
+ GValue *value,
|
|
|
0fe339 |
+ GParamSpec *pspec)
|
|
|
0fe339 |
{
|
|
|
0fe339 |
GtkCellRendererAccelPrivate *priv = GTK_CELL_RENDERER_ACCEL (object)->priv;
|
|
|
0fe339 |
|
|
|
0fe339 |
@@ -338,10 +328,10 @@ gtk_cell_renderer_accel_get_property (GObject *object,
|
|
|
0fe339 |
}
|
|
|
0fe339 |
|
|
|
0fe339 |
static void
|
|
|
0fe339 |
-gtk_cell_renderer_accel_set_property (GObject *object,
|
|
|
0fe339 |
- guint param_id,
|
|
|
0fe339 |
- const GValue *value,
|
|
|
0fe339 |
- GParamSpec *pspec)
|
|
|
0fe339 |
+gtk_cell_renderer_accel_set_property (GObject *object,
|
|
|
0fe339 |
+ guint param_id,
|
|
|
0fe339 |
+ const GValue *value,
|
|
|
0fe339 |
+ GParamSpec *pspec)
|
|
|
0fe339 |
{
|
|
|
0fe339 |
GtkCellRendererAccel *accel = GTK_CELL_RENDERER_ACCEL (object);
|
|
|
0fe339 |
GtkCellRendererAccelPrivate *priv = accel->priv;
|
|
|
0fe339 |
@@ -357,6 +347,7 @@ gtk_cell_renderer_accel_set_property (GObject *object,
|
|
|
0fe339 |
{
|
|
|
0fe339 |
priv->accel_key = accel_key;
|
|
|
0fe339 |
changed = TRUE;
|
|
|
0fe339 |
+ g_object_notify (object, "accel-key");
|
|
|
0fe339 |
}
|
|
|
0fe339 |
}
|
|
|
0fe339 |
break;
|
|
|
0fe339 |
@@ -369,6 +360,7 @@ gtk_cell_renderer_accel_set_property (GObject *object,
|
|
|
0fe339 |
{
|
|
|
0fe339 |
priv->accel_mods = accel_mods;
|
|
|
0fe339 |
changed = TRUE;
|
|
|
0fe339 |
+ g_object_notify (object, "accel-mods");
|
|
|
0fe339 |
}
|
|
|
0fe339 |
}
|
|
|
0fe339 |
break;
|
|
|
0fe339 |
@@ -380,12 +372,17 @@ gtk_cell_renderer_accel_set_property (GObject *object,
|
|
|
0fe339 |
{
|
|
|
0fe339 |
priv->keycode = keycode;
|
|
|
0fe339 |
changed = TRUE;
|
|
|
0fe339 |
+ g_object_notify (object, "keycode");
|
|
|
0fe339 |
}
|
|
|
0fe339 |
}
|
|
|
0fe339 |
break;
|
|
|
0fe339 |
|
|
|
0fe339 |
case PROP_ACCEL_MODE:
|
|
|
0fe339 |
- priv->accel_mode = g_value_get_enum (value);
|
|
|
0fe339 |
+ if (priv->accel_mode != g_value_get_enum (value))
|
|
|
0fe339 |
+ {
|
|
|
0fe339 |
+ priv->accel_mode = g_value_get_enum (value);
|
|
|
0fe339 |
+ g_object_notify (object, "accel-mode");
|
|
|
0fe339 |
+ }
|
|
|
0fe339 |
break;
|
|
|
0fe339 |
|
|
|
0fe339 |
default:
|
|
|
0fe339 |
@@ -403,10 +402,10 @@ gtk_cell_renderer_accel_set_property (GObject *object,
|
|
|
0fe339 |
}
|
|
|
0fe339 |
|
|
|
0fe339 |
static void
|
|
|
0fe339 |
-gtk_cell_renderer_accel_get_preferred_width (GtkCellRenderer *cell,
|
|
|
0fe339 |
- GtkWidget *widget,
|
|
|
0fe339 |
- gint *minimum_size,
|
|
|
0fe339 |
- gint *natural_size)
|
|
|
0fe339 |
+gtk_cell_renderer_accel_get_preferred_width (GtkCellRenderer *cell,
|
|
|
0fe339 |
+ GtkWidget *widget,
|
|
|
0fe339 |
+ gint *minimum_size,
|
|
|
0fe339 |
+ gint *natural_size)
|
|
|
0fe339 |
|
|
|
0fe339 |
{
|
|
|
0fe339 |
GtkCellRendererAccelPrivate *priv = GTK_CELL_RENDERER_ACCEL (cell)->priv;
|
|
|
0fe339 |
@@ -427,16 +424,165 @@ gtk_cell_renderer_accel_get_preferred_width (GtkCellRenderer *cell,
|
|
|
0fe339 |
*natural_size = MAX (*natural_size, nat_req.width);
|
|
|
0fe339 |
}
|
|
|
0fe339 |
|
|
|
0fe339 |
-static gboolean
|
|
|
0fe339 |
-grab_key_callback (GtkWidget *widget,
|
|
|
0fe339 |
- GdkEventKey *event,
|
|
|
0fe339 |
- GtkCellRendererAccel *accel)
|
|
|
0fe339 |
+static GtkCellEditable *
|
|
|
0fe339 |
+gtk_cell_renderer_accel_start_editing (GtkCellRenderer *cell,
|
|
|
0fe339 |
+ GdkEvent *event,
|
|
|
0fe339 |
+ GtkWidget *widget,
|
|
|
0fe339 |
+ const gchar *path,
|
|
|
0fe339 |
+ const GdkRectangle *background_area,
|
|
|
0fe339 |
+ const GdkRectangle *cell_area,
|
|
|
0fe339 |
+ GtkCellRendererState flags)
|
|
|
0fe339 |
+{
|
|
|
0fe339 |
+ GtkCellRendererAccelPrivate *priv;
|
|
|
0fe339 |
+ GtkCellRendererText *celltext;
|
|
|
0fe339 |
+ GtkCellRendererAccel *accel;
|
|
|
0fe339 |
+ GtkStyleContext *context;
|
|
|
0fe339 |
+ GdkRGBA color;
|
|
|
0fe339 |
+ GtkWidget *label;
|
|
|
0fe339 |
+ GtkWidget *eventbox;
|
|
|
0fe339 |
+ gboolean editable;
|
|
|
0fe339 |
+ GdkDevice *device, *keyboard, *pointer;
|
|
|
0fe339 |
+ guint32 timestamp;
|
|
|
0fe339 |
+ GdkWindow *window;
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ celltext = GTK_CELL_RENDERER_TEXT (cell);
|
|
|
0fe339 |
+ accel = GTK_CELL_RENDERER_ACCEL (cell);
|
|
|
0fe339 |
+ priv = accel->priv;
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ /* If the cell isn't editable we return NULL. */
|
|
|
0fe339 |
+ g_object_get (celltext, "editable", &editable, NULL);
|
|
|
0fe339 |
+ if (!editable)
|
|
|
0fe339 |
+ return NULL;
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ window = gtk_widget_get_window (gtk_widget_get_toplevel (widget));
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ if (event)
|
|
|
0fe339 |
+ device = gdk_event_get_device (event);
|
|
|
0fe339 |
+ else
|
|
|
0fe339 |
+ device = gtk_get_current_event_device ();
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ if (!device || !window)
|
|
|
0fe339 |
+ return NULL;
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
|
|
|
0fe339 |
+ {
|
|
|
0fe339 |
+ keyboard = device;
|
|
|
0fe339 |
+ pointer = gdk_device_get_associated_device (device);
|
|
|
0fe339 |
+ }
|
|
|
0fe339 |
+ else
|
|
|
0fe339 |
+ {
|
|
|
0fe339 |
+ pointer = device;
|
|
|
0fe339 |
+ keyboard = gdk_device_get_associated_device (device);
|
|
|
0fe339 |
+ }
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ timestamp = gdk_event_get_time (event);
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ if (gdk_device_grab (keyboard, window,
|
|
|
0fe339 |
+ GDK_OWNERSHIP_WINDOW, FALSE,
|
|
|
0fe339 |
+ GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
|
|
|
0fe339 |
+ NULL, timestamp) != GDK_GRAB_SUCCESS)
|
|
|
0fe339 |
+ return NULL;
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ if (gdk_device_grab (pointer, window,
|
|
|
0fe339 |
+ GDK_OWNERSHIP_WINDOW, FALSE,
|
|
|
0fe339 |
+ GDK_BUTTON_PRESS_MASK,
|
|
|
0fe339 |
+ NULL, timestamp) != GDK_GRAB_SUCCESS)
|
|
|
0fe339 |
+ {
|
|
|
0fe339 |
+ gdk_device_ungrab (keyboard, timestamp);
|
|
|
0fe339 |
+ return NULL;
|
|
|
0fe339 |
+ }
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ priv->grab_keyboard = keyboard;
|
|
|
0fe339 |
+ priv->grab_pointer = pointer;
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ eventbox = gtk_cell_editable_event_box_new (cell, priv->accel_mode, path);
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ label = gtk_label_new (NULL);
|
|
|
0fe339 |
+ gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
0fe339 |
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ context = gtk_widget_get_style_context (widget);
|
|
|
0fe339 |
+ gtk_style_context_get_background_color (context, GTK_STATE_FLAG_SELECTED, &color;;
|
|
|
0fe339 |
+ gtk_widget_override_background_color (eventbox, 0, &color;;
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ gtk_style_context_get_color (context, GTK_STATE_FLAG_SELECTED, &color;;
|
|
|
0fe339 |
+ gtk_widget_override_color (label, 0, &color;;
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ /* This label is displayed in a treeview cell displaying
|
|
|
0fe339 |
+ * an accelerator when the cell is clicked to change the
|
|
|
0fe339 |
+ * acelerator.
|
|
|
0fe339 |
+ */
|
|
|
0fe339 |
+ gtk_label_set_text (GTK_LABEL (label), _("New accelerator…"));
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ gtk_container_add (GTK_CONTAINER (eventbox), label);
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ gtk_widget_show_all (eventbox);
|
|
|
0fe339 |
+ gtk_grab_add (eventbox);
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ return GTK_CELL_EDITABLE (eventbox);
|
|
|
0fe339 |
+}
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+static void
|
|
|
0fe339 |
+gtk_cell_renderer_accel_ungrab (GtkCellRendererAccel *accel)
|
|
|
0fe339 |
{
|
|
|
0fe339 |
GtkCellRendererAccelPrivate *priv = accel->priv;
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ if (priv->grab_keyboard)
|
|
|
0fe339 |
+ {
|
|
|
0fe339 |
+ gdk_device_ungrab (priv->grab_keyboard, GDK_CURRENT_TIME);
|
|
|
0fe339 |
+ gdk_device_ungrab (priv->grab_pointer, GDK_CURRENT_TIME);
|
|
|
0fe339 |
+ priv->grab_keyboard = NULL;
|
|
|
0fe339 |
+ priv->grab_pointer = NULL;
|
|
|
0fe339 |
+ }
|
|
|
0fe339 |
+}
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+/* --------------------------------- */
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+typedef struct _GtkCellEditableEventBox GtkCellEditableEventBox;
|
|
|
0fe339 |
+typedef GtkEventBoxClass GtkCellEditableEventBoxClass;
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+struct _GtkCellEditableEventBox
|
|
|
0fe339 |
+{
|
|
|
0fe339 |
+ GtkEventBox box;
|
|
|
0fe339 |
+ gboolean editing_canceled;
|
|
|
0fe339 |
+ GtkCellRendererAccelMode accel_mode;
|
|
|
0fe339 |
+ gchar *path;
|
|
|
0fe339 |
+ GtkCellRenderer *cell;
|
|
|
0fe339 |
+};
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+enum {
|
|
|
0fe339 |
+ PROP_EDITING_CANCELED = 1,
|
|
|
0fe339 |
+ PROP_MODE,
|
|
|
0fe339 |
+ PROP_PATH
|
|
|
0fe339 |
+};
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+G_GNUC_INTERNAL GType gtk_cell_editable_event_box_get_type (void);
|
|
|
0fe339 |
+static void gtk_cell_editable_event_box_cell_editable_init (GtkCellEditableIface *iface);
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+G_DEFINE_TYPE_WITH_CODE (GtkCellEditableEventBox, gtk_cell_editable_event_box, GTK_TYPE_EVENT_BOX,
|
|
|
0fe339 |
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE, gtk_cell_editable_event_box_cell_editable_init))
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+static void
|
|
|
0fe339 |
+gtk_cell_editable_event_box_start_editing (GtkCellEditable *cell_editable,
|
|
|
0fe339 |
+ GdkEvent *event)
|
|
|
0fe339 |
+{
|
|
|
0fe339 |
+ /* do nothing, because we are pointless */
|
|
|
0fe339 |
+}
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+static void
|
|
|
0fe339 |
+gtk_cell_editable_event_box_cell_editable_init (GtkCellEditableIface *iface)
|
|
|
0fe339 |
+{
|
|
|
0fe339 |
+ iface->start_editing = gtk_cell_editable_event_box_start_editing;
|
|
|
0fe339 |
+}
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+static gboolean
|
|
|
0fe339 |
+gtk_cell_editable_event_box_key_press_event (GtkWidget *widget,
|
|
|
0fe339 |
+ GdkEventKey *event)
|
|
|
0fe339 |
+{
|
|
|
0fe339 |
+ GtkCellEditableEventBox *box = (GtkCellEditableEventBox*)widget;
|
|
|
0fe339 |
GdkModifierType accel_mods = 0;
|
|
|
0fe339 |
guint accel_key;
|
|
|
0fe339 |
guint keyval;
|
|
|
0fe339 |
- gchar *path;
|
|
|
0fe339 |
gboolean edited;
|
|
|
0fe339 |
gboolean cleared;
|
|
|
0fe339 |
GdkModifierType consumed_modifiers;
|
|
|
0fe339 |
@@ -479,7 +625,7 @@ grab_key_callback (GtkWidget *widget,
|
|
|
0fe339 |
|
|
|
0fe339 |
/* Filter consumed modifiers
|
|
|
0fe339 |
*/
|
|
|
0fe339 |
- if (priv->accel_mode == GTK_CELL_RENDERER_ACCEL_MODE_GTK)
|
|
|
0fe339 |
+ if (box->accel_mode == GTK_CELL_RENDERER_ACCEL_MODE_GTK)
|
|
|
0fe339 |
accel_mods &= ~consumed_modifiers;
|
|
|
0fe339 |
|
|
|
0fe339 |
/* Put shift back if it changed the case of the key, not otherwise.
|
|
|
0fe339 |
@@ -491,105 +637,51 @@ grab_key_callback (GtkWidget *widget,
|
|
|
0fe339 |
{
|
|
|
0fe339 |
switch (keyval)
|
|
|
0fe339 |
{
|
|
|
0fe339 |
- case GDK_KEY_Escape:
|
|
|
0fe339 |
- goto out; /* cancel */
|
|
|
0fe339 |
case GDK_KEY_BackSpace:
|
|
|
0fe339 |
- /* clear the accelerator on Backspace */
|
|
|
0fe339 |
cleared = TRUE;
|
|
|
0fe339 |
+ /* fall thru */
|
|
|
0fe339 |
+ case GDK_KEY_Escape:
|
|
|
0fe339 |
goto out;
|
|
|
0fe339 |
default:
|
|
|
0fe339 |
break;
|
|
|
0fe339 |
}
|
|
|
0fe339 |
}
|
|
|
0fe339 |
|
|
|
0fe339 |
- if (priv->accel_mode == GTK_CELL_RENDERER_ACCEL_MODE_GTK)
|
|
|
0fe339 |
+ if (box->accel_mode == GTK_CELL_RENDERER_ACCEL_MODE_GTK &&
|
|
|
0fe339 |
+ !gtk_accelerator_valid (accel_key, accel_mods))
|
|
|
0fe339 |
{
|
|
|
0fe339 |
- if (!gtk_accelerator_valid (accel_key, accel_mods))
|
|
|
0fe339 |
- {
|
|
|
0fe339 |
- gtk_widget_error_bell (widget);
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- return TRUE;
|
|
|
0fe339 |
- }
|
|
|
0fe339 |
+ gtk_widget_error_bell (widget);
|
|
|
0fe339 |
+ return TRUE;
|
|
|
0fe339 |
}
|
|
|
0fe339 |
|
|
|
0fe339 |
edited = TRUE;
|
|
|
0fe339 |
|
|
|
0fe339 |
out:
|
|
|
0fe339 |
- gtk_device_grab_remove (priv->grab_widget, priv->grab_pointer);
|
|
|
0fe339 |
- gdk_device_ungrab (priv->grab_keyboard, event->time);
|
|
|
0fe339 |
- gdk_device_ungrab (priv->grab_pointer, event->time);
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- path = g_strdup (g_object_get_data (G_OBJECT (priv->edit_widget), "gtk-cell-renderer-text"));
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (priv->edit_widget));
|
|
|
0fe339 |
- gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (priv->edit_widget));
|
|
|
0fe339 |
- priv->edit_widget = NULL;
|
|
|
0fe339 |
- priv->grab_widget = NULL;
|
|
|
0fe339 |
- priv->grab_keyboard = NULL;
|
|
|
0fe339 |
- priv->grab_pointer = NULL;
|
|
|
0fe339 |
+ gtk_grab_remove (widget);
|
|
|
0fe339 |
+ gtk_cell_renderer_accel_ungrab (GTK_CELL_RENDERER_ACCEL (box->cell));
|
|
|
0fe339 |
+ gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (widget));
|
|
|
0fe339 |
+ gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (widget));
|
|
|
0fe339 |
|
|
|
0fe339 |
if (edited)
|
|
|
0fe339 |
- g_signal_emit (accel, signals[ACCEL_EDITED], 0, path,
|
|
|
0fe339 |
+ g_signal_emit (box->cell, signals[ACCEL_EDITED], 0, box->path,
|
|
|
0fe339 |
accel_key, accel_mods, event->hardware_keycode);
|
|
|
0fe339 |
else if (cleared)
|
|
|
0fe339 |
- g_signal_emit (accel, signals[ACCEL_CLEARED], 0, path);
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- g_free (path);
|
|
|
0fe339 |
+ g_signal_emit (box->cell, signals[ACCEL_CLEARED], 0, box->path);
|
|
|
0fe339 |
|
|
|
0fe339 |
return TRUE;
|
|
|
0fe339 |
}
|
|
|
0fe339 |
|
|
|
0fe339 |
static void
|
|
|
0fe339 |
-ungrab_stuff (GtkWidget *widget,
|
|
|
0fe339 |
- GtkCellRendererAccel *accel)
|
|
|
0fe339 |
-{
|
|
|
0fe339 |
- GtkCellRendererAccelPrivate *priv = accel->priv;
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- gtk_device_grab_remove (priv->grab_widget, priv->grab_pointer);
|
|
|
0fe339 |
- gdk_device_ungrab (priv->grab_keyboard, GDK_CURRENT_TIME);
|
|
|
0fe339 |
- gdk_device_ungrab (priv->grab_pointer, GDK_CURRENT_TIME);
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- priv->grab_keyboard = NULL;
|
|
|
0fe339 |
- priv->grab_pointer = NULL;
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- g_signal_handlers_disconnect_by_func (priv->grab_widget,
|
|
|
0fe339 |
- G_CALLBACK (grab_key_callback),
|
|
|
0fe339 |
- accel);
|
|
|
0fe339 |
-}
|
|
|
0fe339 |
-
|
|
|
0fe339 |
-static void
|
|
|
0fe339 |
-_gtk_cell_editable_event_box_start_editing (GtkCellEditable *cell_editable,
|
|
|
0fe339 |
- GdkEvent *event)
|
|
|
0fe339 |
+gtk_cell_editable_event_box_unrealize (GtkWidget *widget)
|
|
|
0fe339 |
{
|
|
|
0fe339 |
- /* do nothing, because we are pointless */
|
|
|
0fe339 |
-}
|
|
|
0fe339 |
+ GtkCellEditableEventBox *box = (GtkCellEditableEventBox*)widget;
|
|
|
0fe339 |
|
|
|
0fe339 |
-static void
|
|
|
0fe339 |
-_gtk_cell_editable_event_box_cell_editable_init (GtkCellEditableIface *iface)
|
|
|
0fe339 |
-{
|
|
|
0fe339 |
- iface->start_editing = _gtk_cell_editable_event_box_start_editing;
|
|
|
0fe339 |
+ gtk_grab_remove (widget);
|
|
|
0fe339 |
+ gtk_cell_renderer_accel_ungrab (GTK_CELL_RENDERER_ACCEL (box->cell));
|
|
|
0fe339 |
+
|
|
|
0fe339 |
+ GTK_WIDGET_CLASS (gtk_cell_editable_event_box_parent_class)->unrealize (widget);
|
|
|
0fe339 |
}
|
|
|
0fe339 |
|
|
|
0fe339 |
-typedef struct _GtkCellEditableEventBox GtkCellEditableEventBox;
|
|
|
0fe339 |
-typedef GtkEventBoxClass GtkCellEditableEventBoxClass;
|
|
|
0fe339 |
-
|
|
|
0fe339 |
-struct _GtkCellEditableEventBox
|
|
|
0fe339 |
-{
|
|
|
0fe339 |
- GtkEventBox box;
|
|
|
0fe339 |
- gboolean editing_canceled;
|
|
|
0fe339 |
-};
|
|
|
0fe339 |
-
|
|
|
0fe339 |
-GType _gtk_cell_editable_event_box_get_type (void);
|
|
|
0fe339 |
-
|
|
|
0fe339 |
-G_DEFINE_TYPE_WITH_CODE (GtkCellEditableEventBox, _gtk_cell_editable_event_box, GTK_TYPE_EVENT_BOX, { \
|
|
|
0fe339 |
- G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE, _gtk_cell_editable_event_box_cell_editable_init) \
|
|
|
0fe339 |
- })
|
|
|
0fe339 |
-
|
|
|
0fe339 |
-enum {
|
|
|
0fe339 |
- PROP_ZERO,
|
|
|
0fe339 |
- PROP_EDITING_CANCELED
|
|
|
0fe339 |
-};
|
|
|
0fe339 |
-
|
|
|
0fe339 |
static void
|
|
|
0fe339 |
gtk_cell_editable_event_box_set_property (GObject *object,
|
|
|
0fe339 |
guint prop_id,
|
|
|
0fe339 |
@@ -603,6 +695,12 @@ gtk_cell_editable_event_box_set_property (GObject *object,
|
|
|
0fe339 |
case PROP_EDITING_CANCELED:
|
|
|
0fe339 |
box->editing_canceled = g_value_get_boolean (value);
|
|
|
0fe339 |
break;
|
|
|
0fe339 |
+ case PROP_MODE:
|
|
|
0fe339 |
+ box->accel_mode = g_value_get_enum (value);
|
|
|
0fe339 |
+ break;
|
|
|
0fe339 |
+ case PROP_PATH:
|
|
|
0fe339 |
+ box->path = g_value_dup_string (value);
|
|
|
0fe339 |
+ break;
|
|
|
0fe339 |
default:
|
|
|
0fe339 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
0fe339 |
break;
|
|
|
0fe339 |
@@ -622,6 +720,12 @@ gtk_cell_editable_event_box_get_property (GObject *object,
|
|
|
0fe339 |
case PROP_EDITING_CANCELED:
|
|
|
0fe339 |
g_value_set_boolean (value, box->editing_canceled);
|
|
|
0fe339 |
break;
|
|
|
0fe339 |
+ case PROP_MODE:
|
|
|
0fe339 |
+ g_value_set_enum (value, box->accel_mode);
|
|
|
0fe339 |
+ break;
|
|
|
0fe339 |
+ case PROP_PATH:
|
|
|
0fe339 |
+ g_value_set_string (value, box->path);
|
|
|
0fe339 |
+ break;
|
|
|
0fe339 |
default:
|
|
|
0fe339 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
0fe339 |
break;
|
|
|
0fe339 |
@@ -629,134 +733,61 @@ gtk_cell_editable_event_box_get_property (GObject *object,
|
|
|
0fe339 |
}
|
|
|
0fe339 |
|
|
|
0fe339 |
static void
|
|
|
0fe339 |
-_gtk_cell_editable_event_box_class_init (GtkCellEditableEventBoxClass *class)
|
|
|
0fe339 |
+gtk_cell_editable_event_box_finalize (GObject *object)
|
|
|
0fe339 |
{
|
|
|
0fe339 |
- GObjectClass *gobject_class = G_OBJECT_CLASS (class);
|
|
|
0fe339 |
+ GtkCellEditableEventBox *box = (GtkCellEditableEventBox*)object;
|
|
|
0fe339 |
|
|
|
0fe339 |
- gobject_class->set_property = gtk_cell_editable_event_box_set_property;
|
|
|
0fe339 |
- gobject_class->get_property = gtk_cell_editable_event_box_get_property;
|
|
|
0fe339 |
+ g_free (box->path);
|
|
|
0fe339 |
|
|
|
0fe339 |
- g_object_class_override_property (gobject_class,
|
|
|
0fe339 |
- PROP_EDITING_CANCELED,
|
|
|
0fe339 |
- "editing-canceled");
|
|
|
0fe339 |
+ G_OBJECT_CLASS (gtk_cell_editable_event_box_parent_class)->finalize (object);
|
|
|
0fe339 |
}
|
|
|
0fe339 |
|
|
|
0fe339 |
static void
|
|
|
0fe339 |
-_gtk_cell_editable_event_box_init (GtkCellEditableEventBox *box)
|
|
|
0fe339 |
-{
|
|
|
0fe339 |
-}
|
|
|
0fe339 |
-
|
|
|
0fe339 |
-static GtkCellEditable *
|
|
|
0fe339 |
-gtk_cell_renderer_accel_start_editing (GtkCellRenderer *cell,
|
|
|
0fe339 |
- GdkEvent *event,
|
|
|
0fe339 |
- GtkWidget *widget,
|
|
|
0fe339 |
- const gchar *path,
|
|
|
0fe339 |
- const GdkRectangle *background_area,
|
|
|
0fe339 |
- const GdkRectangle *cell_area,
|
|
|
0fe339 |
- GtkCellRendererState flags)
|
|
|
0fe339 |
+gtk_cell_editable_event_box_class_init (GtkCellEditableEventBoxClass *class)
|
|
|
0fe339 |
{
|
|
|
0fe339 |
- GtkCellRendererAccelPrivate *priv;
|
|
|
0fe339 |
- GtkCellRendererText *celltext;
|
|
|
0fe339 |
- GtkCellRendererAccel *accel;
|
|
|
0fe339 |
- GtkStyleContext *context;
|
|
|
0fe339 |
- GdkRGBA color;
|
|
|
0fe339 |
- GtkWidget *label;
|
|
|
0fe339 |
- GtkWidget *eventbox;
|
|
|
0fe339 |
- GdkDevice *device, *keyb, *pointer;
|
|
|
0fe339 |
- GdkWindow *window;
|
|
|
0fe339 |
- gboolean editable;
|
|
|
0fe339 |
- guint32 time;
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- celltext = GTK_CELL_RENDERER_TEXT (cell);
|
|
|
0fe339 |
- accel = GTK_CELL_RENDERER_ACCEL (cell);
|
|
|
0fe339 |
- priv = accel->priv;
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- /* If the cell isn't editable we return NULL. */
|
|
|
0fe339 |
- g_object_get (celltext, "editable", &editable, NULL);
|
|
|
0fe339 |
- if (editable == FALSE)
|
|
|
0fe339 |
- return NULL;
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- window = gtk_widget_get_window (widget);
|
|
|
0fe339 |
- context = gtk_widget_get_style_context (widget);
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- g_return_val_if_fail (window != NULL, NULL);
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- if (event)
|
|
|
0fe339 |
- device = gdk_event_get_device (event);
|
|
|
0fe339 |
- else
|
|
|
0fe339 |
- device = gtk_get_current_event_device ();
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- if (!device)
|
|
|
0fe339 |
- return NULL;
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
|
|
|
0fe339 |
- {
|
|
|
0fe339 |
- keyb = device;
|
|
|
0fe339 |
- pointer = gdk_device_get_associated_device (device);
|
|
|
0fe339 |
- }
|
|
|
0fe339 |
- else
|
|
|
0fe339 |
- {
|
|
|
0fe339 |
- pointer = device;
|
|
|
0fe339 |
- keyb = gdk_device_get_associated_device (device);
|
|
|
0fe339 |
- }
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- time = gdk_event_get_time (event);
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- if (gdk_device_grab (keyb, window,
|
|
|
0fe339 |
- GDK_OWNERSHIP_WINDOW, FALSE,
|
|
|
0fe339 |
- GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
|
|
|
0fe339 |
- NULL, time) != GDK_GRAB_SUCCESS)
|
|
|
0fe339 |
- return NULL;
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- if (gdk_device_grab (pointer, window,
|
|
|
0fe339 |
- GDK_OWNERSHIP_WINDOW, FALSE,
|
|
|
0fe339 |
- GDK_BUTTON_PRESS_MASK,
|
|
|
0fe339 |
- NULL, time) != GDK_GRAB_SUCCESS)
|
|
|
0fe339 |
- {
|
|
|
0fe339 |
- gdk_device_ungrab (keyb, time);
|
|
|
0fe339 |
- return NULL;
|
|
|
0fe339 |
- }
|
|
|
0fe339 |
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
0fe339 |
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
|
|
0fe339 |
|
|
|
0fe339 |
- priv->grab_keyboard = keyb;
|
|
|
0fe339 |
- priv->grab_pointer = pointer;
|
|
|
0fe339 |
- priv->grab_widget = widget;
|
|
|
0fe339 |
+ object_class->finalize = gtk_cell_editable_event_box_finalize;
|
|
|
0fe339 |
+ object_class->set_property = gtk_cell_editable_event_box_set_property;
|
|
|
0fe339 |
+ object_class->get_property = gtk_cell_editable_event_box_get_property;
|
|
|
0fe339 |
|
|
|
0fe339 |
- g_signal_connect (G_OBJECT (widget), "key-press-event",
|
|
|
0fe339 |
- G_CALLBACK (grab_key_callback),
|
|
|
0fe339 |
- accel);
|
|
|
0fe339 |
+ widget_class->key_press_event = gtk_cell_editable_event_box_key_press_event;
|
|
|
0fe339 |
+ widget_class->unrealize = gtk_cell_editable_event_box_unrealize;
|
|
|
0fe339 |
|
|
|
0fe339 |
- eventbox = g_object_new (_gtk_cell_editable_event_box_get_type (), NULL);
|
|
|
0fe339 |
- priv->edit_widget = eventbox;
|
|
|
0fe339 |
- g_object_add_weak_pointer (G_OBJECT (priv->edit_widget),
|
|
|
0fe339 |
- (gpointer) &priv->edit_widget);
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- label = gtk_label_new (NULL);
|
|
|
0fe339 |
- gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
0fe339 |
- gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
|
|
|
0fe339 |
+ g_object_class_override_property (object_class,
|
|
|
0fe339 |
+ PROP_EDITING_CANCELED,
|
|
|
0fe339 |
+ "editing-canceled");
|
|
|
0fe339 |
|
|
|
0fe339 |
- gtk_style_context_get_background_color (context, GTK_STATE_FLAG_SELECTED, &color;;
|
|
|
0fe339 |
- gtk_widget_override_background_color (eventbox, 0, &color;;
|
|
|
0fe339 |
+ g_object_class_install_property (object_class, PROP_MODE,
|
|
|
0fe339 |
+ g_param_spec_enum ("accel-mode", NULL, NULL,
|
|
|
0fe339 |
+ GTK_TYPE_CELL_RENDERER_ACCEL_MODE,
|
|
|
0fe339 |
+ GTK_CELL_RENDERER_ACCEL_MODE_GTK,
|
|
|
0fe339 |
+ GTK_PARAM_READWRITE));
|
|
|
0fe339 |
|
|
|
0fe339 |
- gtk_style_context_get_color (context, GTK_STATE_FLAG_SELECTED, &color;;
|
|
|
0fe339 |
- gtk_widget_override_color (label, 0, &color;;
|
|
|
0fe339 |
+ g_object_class_install_property (object_class, PROP_PATH,
|
|
|
0fe339 |
+ g_param_spec_string ("path", NULL, NULL,
|
|
|
0fe339 |
+ NULL, GTK_PARAM_READWRITE));
|
|
|
0fe339 |
+}
|
|
|
0fe339 |
|
|
|
0fe339 |
- /* This label is displayed in a treeview cell displaying
|
|
|
0fe339 |
- * an accelerator when the cell is clicked to change the
|
|
|
0fe339 |
- * acelerator.
|
|
|
0fe339 |
- */
|
|
|
0fe339 |
- gtk_label_set_text (GTK_LABEL (label), _("New accelerator…"));
|
|
|
0fe339 |
+static void
|
|
|
0fe339 |
+gtk_cell_editable_event_box_init (GtkCellEditableEventBox *box)
|
|
|
0fe339 |
+{
|
|
|
0fe339 |
+ gtk_widget_set_can_focus (GTK_WIDGET (box), TRUE);
|
|
|
0fe339 |
+}
|
|
|
0fe339 |
|
|
|
0fe339 |
- gtk_container_add (GTK_CONTAINER (eventbox), label);
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- g_object_set_data_full (G_OBJECT (priv->edit_widget), "gtk-cell-renderer-text",
|
|
|
0fe339 |
- g_strdup (path), g_free);
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- gtk_widget_show_all (priv->edit_widget);
|
|
|
0fe339 |
+static GtkWidget *
|
|
|
0fe339 |
+gtk_cell_editable_event_box_new (GtkCellRenderer *cell,
|
|
|
0fe339 |
+ GtkCellRendererAccelMode mode,
|
|
|
0fe339 |
+ const gchar *path)
|
|
|
0fe339 |
+{
|
|
|
0fe339 |
+ GtkCellEditableEventBox *box;
|
|
|
0fe339 |
|
|
|
0fe339 |
- gtk_device_grab_add (priv->grab_widget, pointer, TRUE);
|
|
|
0fe339 |
+ box = g_object_new (gtk_cell_editable_event_box_get_type (),
|
|
|
0fe339 |
+ "accel-mode", mode,
|
|
|
0fe339 |
+ "path", path,
|
|
|
0fe339 |
+ NULL);
|
|
|
0fe339 |
+ box->cell = cell;
|
|
|
0fe339 |
|
|
|
0fe339 |
- g_signal_connect (priv->edit_widget, "unrealize",
|
|
|
0fe339 |
- G_CALLBACK (ungrab_stuff), accel);
|
|
|
0fe339 |
-
|
|
|
0fe339 |
- return GTK_CELL_EDITABLE (priv->edit_widget);
|
|
|
0fe339 |
+ return GTK_WIDGET (box);
|
|
|
0fe339 |
}
|