/* --- 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)
{
entry->changed = FALSE;
entry->locked = FALSE;
g_hash_table_insert (accel_entry_ht, entry, entry);
+
+ invoke_change_hooks (entry);
}
}
entry->accel_mods = accel_mods;
entry->changed = TRUE;
entry->locked = FALSE;
+
+ invoke_change_hooks (entry);
}
return TRUE;
}
entry->accel_key = accel_key;
entry->accel_mods = accel_mods;
entry->changed = TRUE;
+
+ invoke_change_hooks (entry);
}
return TRUE;
}
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);
*
* 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
* @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
**/
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);
+ }
+
+}
+