#include "gtkaccelmap.h"
#include "gtkmarshalers.h"
-#include "gtkwindow.h" /* in lack of GtkAcceleratable */
+#include "gtkwindowprivate.h"
+#include "gtkintl.h"
+
+#include <glib/gstdio.h>
#include <string.h>
#include <errno.h>
#ifdef G_OS_WIN32
#include <io.h>
#endif
-#include <errno.h>
+
+
+/**
+ * SECTION:gtkaccelmap
+ * @Short_description: Loadable keyboard accelerator specifications
+ * @Title: Accelerator Maps
+ * @See_also: #GtkAccelGroup, #GtkAccelKey, #GtkUIManager, gtk_widget_set_accel_path(), gtk_menu_item_set_accel_path(), #GtkSettings:gtk-can-change-accels
+ *
+ * Accelerator maps are used to define runtime configurable accelerators.
+ * Functions for manipulating them are are usually used by higher level
+ * convenience mechanisms like #GtkUIManager and are thus considered
+ * "low-level". You'll want to use them if you're manually creating menus that
+ * should have user-configurable accelerators.
+ *
+ * Accelerator is uniquely defined by:
+ *
+ * <itemizedlist>
+ * <listitem><para>accelerator path</para></listitem>
+ * <listitem><para>accelerator key</para></listitem>
+ * <listitem><para>accelerator modifiers</para></listitem>
+ * </itemizedlist>
+ *
+ * The accelerator path must consist of
+ * "<WINDOWTYPE>/Category1/Category2/.../Action", where WINDOWTYPE
+ * should be a unique application-specific identifier that corresponds to the
+ * kind of window the accelerator is being used in, e.g. "Gimp-Image",
+ * "Abiword-Document" or "Gnumeric-Settings".
+ * The "Category1/.../Action" portion is most appropriately chosen by the action
+ * the accelerator triggers, i.e. for accelerators on menu items, choose the
+ * item's menu path, e.g. "File/Save As", "Image/View/Zoom" or
+ * "Edit/Select All". So a full valid accelerator path may look like:
+ * "<Gimp-Toolbox>/File/Dialogs/Tool Options...".
+ *
+ * All accelerators are stored inside one global #GtkAccelMap that can be
+ * obtained using gtk_accel_map_get(). See <link
+ * linkend="monitoring-changes">Monitoring changes</link> for additional
+ * details.
+ *
+ * <refsect2 id="manipulating-accelerators">
+ * <title>Manipulating accelerators</title>
+ * <para>
+ * New accelerators can be added using gtk_accel_map_add_entry(). To search for
+ * specific accelerator, use gtk_accel_map_lookup_entry(). Modifications of
+ * existing accelerators should be done using gtk_accel_map_change_entry().
+ *
+ * In order to avoid having some accelerators changed, they can be locked using
+ * gtk_accel_map_lock_path(). Unlocking is done using
+ * gtk_accel_map_unlock_path().
+ * </para>
+ * </refsect2>
+ * <refsect2 id="saving-and-loading">
+ * <title>Saving and loading accelerator maps</title>
+ * <para>
+ * Accelerator maps can be saved to and loaded from some external resource. For
+ * simple saving and loading from file, gtk_accel_map_save() and
+ * gtk_accel_map_load() are provided. Saving and loading can also be done by
+ * providing file descriptor to gtk_accel_map_save_fd() and
+ * gtk_accel_map_load_fd().
+ * </para>
+ * </refsect2>
+ * <refsect2 id="monitoring-changes">
+ * <title>Monitoring changes</title>
+ * <para>
+ * #GtkAccelMap object is only useful for monitoring changes of accelerators. By
+ * connecting to #GtkAccelMap::changed signal, one can monitor changes of all
+ * accelerators. It is also possible to monitor only single accelerator path by
+ * using it as a detail of the #GtkAccelMap::changed signal.
+ * </para>
+ * </refsect2>
+ */
/* --- structures --- */
guint accel_mods;
guint std_accel_key;
guint std_accel_mods;
- guint changed : 1;
- guint lock_count;
+ guint changed : 1;
+ guint lock_count : 15;
GSList *groups;
} AccelEntry;
accel_path[1] == '<' || accel_path[1] == '>' || !accel_path[1])
return FALSE;
p = strchr (accel_path, '>');
- if (!p || p[1] != '/')
+ if (!p || (p[1] != 0 && p[1] != '/'))
return FALSE;
return TRUE;
}
* with the canonical @accel_key and @accel_mods for this path.
* To change the accelerator during runtime programatically, use
* gtk_accel_map_change_entry().
- * The accelerator path must consist of "<WINDOWTYPE>/Category1/Category2/.../Action",
- * where <WINDOWTYPE> should be a unique application-specific identifier, that
- * corresponds to the kind of window the accelerator is being used in, e.g. "Gimp-Image",
- * "Abiword-Document" or "Gnumeric-Settings".
- * The Category1/.../Action portion is most appropriately chosen by the action the
- * accelerator triggers, i.e. for accelerators on menu items, choose the item's menu path,
- * e.g. "File/Save As", "Image/View/Zoom" or "Edit/Select All".
- * So a full valid accelerator path may look like:
- * "<Gimp-Toolbox>/File/Dialogs/Tool Options...".
+ *
+ * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
+ * pass a static string, you can save some memory by interning it first with
+ * g_intern_static_string().
*/
void
gtk_accel_map_add_entry (const gchar *accel_path,
}
else
{
- entry = g_new0 (AccelEntry, 1);
- entry->accel_path = g_quark_to_string (g_quark_from_string (accel_path));
+ entry = g_slice_new0 (AccelEntry);
+ entry->accel_path = g_intern_string (accel_path);
entry->std_accel_key = accel_key;
entry->std_accel_mods = accel_mods;
entry->accel_key = accel_key;
/**
* gtk_accel_map_lookup_entry:
- * @accel_path: a valid accelerator path
- * @key: the accelerator key to be filled in (optional)
- * @returns: %TRUE if @accel_path is known, %FALSE otherwise
+ * @accel_path: a valid accelerator path
+ * @key: (allow-none) (out): the accelerator key to be filled in (optional)
+ * @returns: %TRUE if @accel_path is known, %FALSE otherwise
*
* Looks up the accelerator entry for @accel_path and fills in @key.
*/
{
GtkAccelGroup *group = slist->data;
- for (node = group->acceleratables; node; node = node->next)
+ for (node = _gtk_accel_group_get_accelerables (group); node; node = node->next)
g_hash_table_insert (window_hm, node->data, node->data);
}
g_slist_free (group_list);
for (i = 0; i < n; i++)
{
seen_accel = TRUE;
- removable = !group->lock_count && !(ag_entry[i].key.accel_flags & GTK_ACCEL_LOCKED);
+ removable = !gtk_accel_group_get_is_locked (group) && !(ag_entry[i].key.accel_flags & GTK_ACCEL_LOCKED);
if (!removable)
goto break_loop_step5;
if (ag_entry[i].accel_path_quark)
- replace_list = g_slist_prepend (replace_list, GUINT_TO_POINTER (ag_entry->accel_path_quark));
+ replace_list = g_slist_prepend (replace_list, GUINT_TO_POINTER (ag_entry[i].accel_path_quark));
}
}
break_loop_step5:
if (change_accel && !simulate)
{
- guint old_accel_key, old_accel_mods;
-
/* ref accel groups */
for (slist = group_list; slist; slist = slist->next)
g_object_ref (slist->data);
internal_change_entry (g_quark_to_string (GPOINTER_TO_UINT (slist->data)), 0, 0, FALSE, FALSE);
/* 9) install new accelerator */
- old_accel_key = entry->accel_key;
- old_accel_mods = entry->accel_mods;
entry->accel_key = accel_key;
entry->accel_mods = accel_mods;
entry->changed = TRUE;
* conflicts. A change will only occur if all conflicts could be resolved (which
* might not be the case if conflicting accelerators are locked). Successful
* changes are indicated by a %TRUE return value.
+ *
+ * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
+ * pass a static string, you can save some memory by interning it first with
+ * g_intern_static_string().
*/
gboolean
gtk_accel_map_change_entry (const gchar *accel_path,
gchar *cpair_comment_single;
gpointer saved_symbol;
- g_return_if_fail (scanner != 0);
+ g_return_if_fail (scanner != NULL);
/* configure scanner */
skip_comment_single = scanner->config->skip_comment_single;
/**
* gtk_accel_map_load:
- * @file_name: a file containing accelerator specifications
+ * @file_name: (type filename): a file containing accelerator specifications,
+ * in the GLib file name encoding
*
* Parses a file previously saved with gtk_accel_map_save() for
* accelerator specifications, and propagates them accordingly.
if (!g_file_test (file_name, G_FILE_TEST_IS_REGULAR))
return;
- fd = open (file_name, O_RDONLY);
+ fd = g_open (file_name, O_RDONLY, 0);
if (fd < 0)
return;
/**
* gtk_accel_map_save:
- * @file_name: the file to contain accelerator specifications
+ * @file_name: (type filename): the name of the file to contain
+ * accelerator specifications, in the GLib file name encoding
*
* Saves current accelerator specifications (accelerator path, key
* and modifiers) to @file_name.
g_return_if_fail (file_name != NULL);
- fd = open (file_name, O_CREAT | O_TRUNC | O_WRONLY, 0644);
+ fd = g_open (file_name, O_CREAT | O_TRUNC | O_WRONLY, 0644);
if (fd < 0)
return;
/**
* gtk_accel_map_foreach:
- * @data: data to be passed into @foreach_func
- * @foreach_func: function to be executed for each accel map entry which
- * is not filtered out
+ * @data: (allow-none): data to be passed into @foreach_func
+ * @foreach_func: (scope call): function to be executed for each accel
+ * map entry which is not filtered out
*
* Loops over the entries in the accelerator map whose accel path
* doesn't match any of the filters added with gtk_accel_map_add_filter(),
/**
* gtk_accel_map_foreach_unfiltered:
* @data: data to be passed into @foreach_func
- * @foreach_func: function to be executed for each accel map entry
+ * @foreach_func: (scope call): function to be executed for each accel
+ * map entry
*
* Loops over all entries in the accelerator map, and execute
* @foreach_func on each. The signature of @foreach_func is that of
entry->lock_count -= 1;
}
-G_DEFINE_TYPE (GtkAccelMap, gtk_accel_map, G_TYPE_OBJECT);
+G_DEFINE_TYPE (GtkAccelMap, gtk_accel_map, G_TYPE_OBJECT)
static void
gtk_accel_map_class_init (GtkAccelMapClass *accel_map_class)
*
* Since: 2.4
*/
- accel_map_signals[CHANGED] = g_signal_new ("changed",
+ accel_map_signals[CHANGED] = g_signal_new (I_("changed"),
G_TYPE_FROM_CLASS (accel_map_class),
G_SIGNAL_DETAILED|G_SIGNAL_RUN_LAST,
0,
* map via the ::changed signal; it isn't a parameter to the
* other accelerator map functions.
*
- * Return value: the global #GtkAccelMap object
+ * Return value: (transfer none): the global #GtkAccelMap object
*
* Since: 2.4
**/