summaryrefslogtreecommitdiff
path: root/gtk/gtkaccelmap.c
diff options
context:
space:
mode:
authorMatthias Clasen <maclas@gmx.de>2004-01-07 20:44:07 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2004-01-07 20:44:07 +0000
commitc22143c9e06844ac654c5568363d2781e6114293 (patch)
tree59127f577855e9403ebff60e703d63b6912f843b /gtk/gtkaccelmap.c
parent77cbf47adfb2a62be19966e20b48eb31b34098f2 (diff)
downloadgtk+-c22143c9e06844ac654c5568363d2781e6114293.tar.gz
Fix grammar of docs.
Wed Jan 7 21:42:49 2004 Matthias Clasen <maclas@gmx.de> * gtk/gtkaccelmap.c (gtk_accel_map_lock_path): Fix grammar of docs.
Diffstat (limited to 'gtk/gtkaccelmap.c')
-rw-r--r--gtk/gtkaccelmap.c100
1 files changed, 96 insertions, 4 deletions
diff --git a/gtk/gtkaccelmap.c b/gtk/gtkaccelmap.c
index 4fcce87dce..086a636e02 100644
--- a/gtk/gtkaccelmap.c
+++ b/gtk/gtkaccelmap.c
@@ -51,9 +51,11 @@ typedef struct {
/* --- variables --- */
static GHashTable *accel_entry_ht = NULL; /* accel_path -> AccelEntry */
static GSList *accel_filters = NULL;
-
+static GHookList *change_hooks = NULL;
/* --- functions --- */
+static void invoke_change_hooks (AccelEntry *entry);
+
static guint
accel_entry_hash (gconstpointer key)
{
@@ -163,6 +165,8 @@ gtk_accel_map_add_entry (const gchar *accel_path,
entry->changed = FALSE;
entry->locked = FALSE;
g_hash_table_insert (accel_entry_ht, entry, entry);
+
+ invoke_change_hooks (entry);
}
}
@@ -243,6 +247,8 @@ internal_change_entry (const gchar *accel_path,
entry->accel_mods = accel_mods;
entry->changed = TRUE;
entry->locked = FALSE;
+
+ invoke_change_hooks (entry);
}
return TRUE;
}
@@ -266,6 +272,8 @@ internal_change_entry (const gchar *accel_path,
entry->accel_key = accel_key;
entry->accel_mods = accel_mods;
entry->changed = TRUE;
+
+ invoke_change_hooks (entry);
}
return TRUE;
}
@@ -370,12 +378,15 @@ internal_change_entry (const gchar *accel_path,
entry->accel_key = accel_key;
entry->accel_mods = accel_mods;
entry->changed = TRUE;
+
for (slist = group_list; slist; slist = slist->next)
_gtk_accel_group_reconnect (slist->data, g_quark_from_string (entry->accel_path));
/* unref accel groups */
for (slist = group_list; slist; slist = slist->next)
g_object_unref (slist->data);
+
+ invoke_change_hooks (entry);
}
g_slist_free (replace_list);
g_slist_free (group_list);
@@ -839,10 +850,10 @@ _gtk_accel_map_remove_group (const gchar *accel_path,
*
* Locks the given accelerator path.
*
- * Locking an accelerator path prevents its accelerator to be changed
+ * Locking an accelerator path prevents its accelerator from being changed
* during runtime. A locked accelerator path can be unlocked by
* gtk_accel_map_unlock_path(). Refer to gtk_accel_map_change_entry()
- * about runtime accelerator changes.
+ * for information about runtime accelerator changes.
*
* Note that locking of individual accelerator paths is independent from
* locking the #GtkAccelGroup containing them. For runtime accelerator
@@ -869,7 +880,7 @@ gtk_accel_map_lock_path (const gchar *accel_path)
* @accel_path: a valid accelerator path
*
* Unlocks the given accelerator path. Refer to gtk_accel_map_lock_path()
- * about accelerator path locking.
+ * for information about accelerator path locking.
*
* Since: 2.4
**/
@@ -885,3 +896,84 @@ gtk_accel_map_unlock_path (const gchar *accel_path)
if (entry)
entry->locked = FALSE;
}
+
+/**
+ * gtk_accel_map_add_change_hook:
+ * @hook_func: the function to be called
+ * @hook_data: data to pass as the first argument of @hook_func
+ * @data_destroy: destroy notify to be called if @hook_data is destroyed
+ *
+ * Adds a function to be called whenever an accel map entry is changed.
+ * The @accel_key and @accel_mods arguments passed to @hook_func are the new
+ * values.
+ *
+ * Returns: A numerical id which can be used to remove the change hook
+ * again with gtk_accel_map_remove_change_hook().
+ * Since: 2.4
+ */
+gulong
+gtk_accel_map_add_change_hook (GtkAccelMapForeach hook_func,
+ gpointer hook_data,
+ GDestroyNotify data_destroy)
+{
+ GHook *hook;
+
+ if (!change_hooks)
+ {
+ change_hooks = g_new (GHookList, 1);
+ g_hook_list_init (change_hooks, sizeof (GHook));
+ }
+
+ hook = g_hook_alloc (change_hooks);
+ hook->func = (gpointer)hook_func;
+ hook->data = hook_data;
+ hook->destroy = data_destroy;
+
+ g_hook_append (change_hooks, hook);
+
+ return hook->hook_id;
+}
+
+/**
+ * gtk_accel_map_remove_change_hook:
+ * @hook_id: an id returned by gtk_accel_map_add_change_hook()
+ *
+ * Removes a change hook previously added by gtk_accel_map_add_change_hook().
+ *
+ * Since: 2.4
+ */
+void
+gtk_accel_map_remove_change_hook (gulong hook_id)
+{
+ if (!g_hook_destroy (change_hooks, hook_id))
+ g_warning ("%s: GtkAccelMap had no hook (%lu) to remove", G_STRLOC, hook_id);
+}
+
+static void
+invoke_change_hooks (AccelEntry *entry)
+{
+ GHook *hook;
+
+ if (!change_hooks || !change_hooks->is_setup)
+ return;
+
+ hook = g_hook_first_valid (change_hooks, FALSE);
+ while (hook)
+ {
+ GtkAccelMapForeach func;
+ gboolean was_in_call;
+
+ func = (GtkAccelMapForeach) hook->func;
+
+ was_in_call = G_HOOK_IN_CALL (hook);
+ hook->flags |= G_HOOK_FLAG_IN_CALL;
+ func (hook->data, entry->accel_path, entry->accel_key,
+ entry->accel_mods, entry->changed);
+ if (!was_in_call)
+ hook->flags &= ~G_HOOK_FLAG_IN_CALL;
+
+ hook = g_hook_next_valid (change_hooks, hook, FALSE);
+ }
+
+}
+