forked from AuroraMiddleware/gtk
accels: Remove GtkAccelGroup
This commit is contained in:
parent
7c4d8d49b6
commit
bb4fbe3d8f
@ -310,7 +310,6 @@ static const char *types[] =
|
||||
"GtkIconView ",
|
||||
"GtkCellRendererText ",
|
||||
"GtkContainer ",
|
||||
"GtkAccelGroup ",
|
||||
"GtkPaned ",
|
||||
"GtkPrintOperation ",
|
||||
"GtkPrintContext ",
|
||||
|
@ -341,6 +341,7 @@
|
||||
|
||||
<chapter>
|
||||
<title>Keyboard shortcuts</title>
|
||||
<xi:include href="xml/gtkaccelgroup.xml" />
|
||||
<xi:include href="xml/gtkshortcut.xml" />
|
||||
<xi:include href="xml/gtkshortcuttrigger.xml" />
|
||||
<xi:include href="xml/gtkshortcutaction.xml" />
|
||||
@ -361,7 +362,6 @@
|
||||
<title>GTK Core Reference</title>
|
||||
<xi:include href="xml/gtkmain.xml" />
|
||||
<xi:include href="xml/gtkfeatures.xml" />
|
||||
<xi:include href="xml/gtkaccelgroup.xml" />
|
||||
<xi:include href="xml/gtksettings.xml" />
|
||||
<xi:include href="xml/gtkenums.xml" />
|
||||
<xi:include href="xml/gtktesting.xml" />
|
||||
|
@ -53,21 +53,6 @@ gtk_about_dialog_get_type
|
||||
<SECTION>
|
||||
<FILE>gtkaccelgroup</FILE>
|
||||
<TITLE>Keyboard Accelerators</TITLE>
|
||||
GtkAccelGroup
|
||||
GtkAccelGroupClass
|
||||
gtk_accel_group_new
|
||||
GtkAccelFlags
|
||||
gtk_accel_group_connect
|
||||
GtkAccelGroupActivate
|
||||
GtkAccelGroupFindFunc
|
||||
gtk_accel_group_disconnect
|
||||
gtk_accel_group_disconnect_key
|
||||
gtk_accel_group_activate
|
||||
gtk_accel_group_from_accel_closure
|
||||
gtk_accel_groups_activate
|
||||
gtk_accel_groups_from_object
|
||||
gtk_accel_group_find
|
||||
GtkAccelKey
|
||||
gtk_accelerator_valid
|
||||
gtk_accelerator_parse
|
||||
gtk_accelerator_name
|
||||
@ -77,21 +62,6 @@ gtk_accelerator_name_with_keycode
|
||||
gtk_accelerator_get_label_with_keycode
|
||||
gtk_accelerator_set_default_mod_mask
|
||||
gtk_accelerator_get_default_mod_mask
|
||||
|
||||
<SUBSECTION Standard>
|
||||
GTK_TYPE_ACCEL_GROUP
|
||||
GTK_ACCEL_GROUP
|
||||
GTK_IS_ACCEL_GROUP
|
||||
GTK_ACCEL_GROUP_CLASS
|
||||
GTK_IS_ACCEL_GROUP_CLASS
|
||||
GTK_ACCEL_GROUP_GET_CLASS
|
||||
|
||||
<SUBSECTION Private>
|
||||
GTK_ACCEL_GROUP_GET_PRIVATE
|
||||
GtkAccelGroupPrivate
|
||||
GtkAccelGroupEntry
|
||||
gtk_accel_group_query
|
||||
gtk_accel_group_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
@ -99,10 +69,6 @@ gtk_accel_group_get_type
|
||||
<TITLE>GtkAccelLabel</TITLE>
|
||||
GtkAccelLabel
|
||||
gtk_accel_label_new
|
||||
gtk_accel_label_set_accel_closure
|
||||
gtk_accel_label_get_accel_closure
|
||||
gtk_accel_label_get_accel_widget
|
||||
gtk_accel_label_set_accel_widget
|
||||
gtk_accel_label_get_accel_width
|
||||
gtk_accel_label_set_accel
|
||||
gtk_accel_label_get_accel
|
||||
@ -4217,8 +4183,6 @@ gtk_window_new
|
||||
gtk_window_set_title
|
||||
gtk_window_set_resizable
|
||||
gtk_window_get_resizable
|
||||
gtk_window_add_accel_group
|
||||
gtk_window_remove_accel_group
|
||||
gtk_window_set_modal
|
||||
gtk_window_set_default_size
|
||||
gtk_window_set_hide_on_close
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include <gtk/gtkunixprint.h>
|
||||
|
||||
gtk_about_dialog_get_type
|
||||
gtk_accel_group_get_type
|
||||
gtk_accel_label_get_type
|
||||
gtk_accessible_get_type
|
||||
gtk_actionable_get_type
|
||||
|
@ -35,678 +35,18 @@
|
||||
|
||||
/**
|
||||
* SECTION:gtkaccelgroup
|
||||
* @Short_description: Groups of global keyboard accelerators for an
|
||||
* entire GtkWindow
|
||||
* @Title: Accelerator Groups
|
||||
* @See_also: gtk_window_add_accel_group(), gtk_accel_map_change_entry(),
|
||||
* gtk_label_new_with_mnemonic()
|
||||
* @Short_description: Utilities for accelerators
|
||||
* @Title: Keyboard Accelerators
|
||||
*
|
||||
* A #GtkAccelGroup represents a group of keyboard accelerators,
|
||||
* typically attached to a toplevel #GtkWindow (with
|
||||
* gtk_window_add_accel_group()).
|
||||
*
|
||||
* Note that “accelerators” are different from
|
||||
* “mnemonics”. Accelerators are shortcuts for
|
||||
* activating a menu item; they appear alongside the menu item they’re a
|
||||
* shortcut for. For example “Ctrl+Q” might appear alongside the “Quit”
|
||||
* menu item. Mnemonics are shortcuts for GUI elements such as text
|
||||
* entries or buttons; they appear as underlined characters. See
|
||||
* gtk_label_new_with_mnemonic(). Menu items can have both accelerators
|
||||
* and mnemonics, of course.
|
||||
* We have various utility functions to parse and generate
|
||||
* textual representations of keyboard accelerators.
|
||||
*/
|
||||
|
||||
/* --- prototypes --- */
|
||||
static void gtk_accel_group_finalize (GObject *object);
|
||||
static void accel_closure_invalidate (gpointer data,
|
||||
GClosure *closure);
|
||||
|
||||
|
||||
/* --- variables --- */
|
||||
static guint signal_accel_activate = 0;
|
||||
static guint signal_accel_changed = 0;
|
||||
static guint quark_acceleratable_groups = 0;
|
||||
static guint default_accel_mod_mask = 0;
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GtkAccelGroup, gtk_accel_group, G_TYPE_OBJECT)
|
||||
|
||||
|
||||
/* --- functions --- */
|
||||
static void
|
||||
gtk_accel_group_class_init (GtkAccelGroupClass *class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||
|
||||
quark_acceleratable_groups = g_quark_from_static_string ("gtk-acceleratable-accel-groups");
|
||||
|
||||
object_class->finalize = gtk_accel_group_finalize;
|
||||
|
||||
class->accel_changed = NULL;
|
||||
|
||||
/**
|
||||
* GtkAccelGroup::accel-activate:
|
||||
* @accel_group: the #GtkAccelGroup which received the signal
|
||||
* @acceleratable: the object on which the accelerator was activated
|
||||
* @keyval: the accelerator keyval
|
||||
* @modifier: the modifier combination of the accelerator
|
||||
*
|
||||
* The accel-activate signal is an implementation detail of
|
||||
* #GtkAccelGroup and not meant to be used by applications.
|
||||
*
|
||||
* Returns: %TRUE if the accelerator was activated
|
||||
*/
|
||||
signal_accel_activate =
|
||||
g_signal_new (I_("accel-activate"),
|
||||
G_OBJECT_CLASS_TYPE (class),
|
||||
G_SIGNAL_DETAILED,
|
||||
0,
|
||||
_gtk_boolean_handled_accumulator, NULL,
|
||||
_gtk_marshal_BOOLEAN__OBJECT_UINT_FLAGS,
|
||||
G_TYPE_BOOLEAN, 3,
|
||||
G_TYPE_OBJECT,
|
||||
G_TYPE_UINT,
|
||||
GDK_TYPE_MODIFIER_TYPE);
|
||||
/**
|
||||
* GtkAccelGroup::accel-changed:
|
||||
* @accel_group: the #GtkAccelGroup which received the signal
|
||||
* @keyval: the accelerator keyval
|
||||
* @modifier: the modifier combination of the accelerator
|
||||
* @accel_closure: the #GClosure of the accelerator
|
||||
*
|
||||
* The accel-changed signal is emitted when an entry
|
||||
* is added to or removed from the accel group.
|
||||
*
|
||||
* Widgets like #GtkAccelLabel which display an associated
|
||||
* accelerator should connect to this signal, and rebuild
|
||||
* their visual representation if the @accel_closure is theirs.
|
||||
*/
|
||||
signal_accel_changed =
|
||||
g_signal_new (I_("accel-changed"),
|
||||
G_OBJECT_CLASS_TYPE (class),
|
||||
G_SIGNAL_RUN_FIRST | G_SIGNAL_DETAILED,
|
||||
G_STRUCT_OFFSET (GtkAccelGroupClass, accel_changed),
|
||||
NULL, NULL,
|
||||
_gtk_marshal_VOID__UINT_FLAGS_BOXED,
|
||||
G_TYPE_NONE, 3,
|
||||
G_TYPE_UINT,
|
||||
GDK_TYPE_MODIFIER_TYPE,
|
||||
G_TYPE_CLOSURE);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_accel_group_finalize (GObject *object)
|
||||
{
|
||||
GtkAccelGroup *accel_group = GTK_ACCEL_GROUP (object);
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < accel_group->priv->n_accels; i++)
|
||||
{
|
||||
GtkAccelGroupEntry *entry = &accel_group->priv->priv_accels[i];
|
||||
|
||||
g_closure_remove_invalidate_notifier (entry->closure, accel_group, accel_closure_invalidate);
|
||||
|
||||
/* remove quick_accel_add() refcount */
|
||||
g_closure_unref (entry->closure);
|
||||
}
|
||||
|
||||
g_free (accel_group->priv->priv_accels);
|
||||
|
||||
G_OBJECT_CLASS (gtk_accel_group_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_accel_group_init (GtkAccelGroup *accel_group)
|
||||
{
|
||||
GtkAccelGroupPrivate *priv;
|
||||
|
||||
accel_group->priv = gtk_accel_group_get_instance_private (accel_group);
|
||||
priv = accel_group->priv;
|
||||
|
||||
priv->acceleratables = NULL;
|
||||
priv->n_accels = 0;
|
||||
priv->priv_accels = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_accel_group_new:
|
||||
*
|
||||
* Creates a new #GtkAccelGroup.
|
||||
*
|
||||
* Returns: a new #GtkAccelGroup object
|
||||
*/
|
||||
GtkAccelGroup*
|
||||
gtk_accel_group_new (void)
|
||||
{
|
||||
return g_object_new (GTK_TYPE_ACCEL_GROUP, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
accel_group_weak_ref_detach (GSList *free_list,
|
||||
GObject *stale_object)
|
||||
{
|
||||
GSList *slist;
|
||||
|
||||
for (slist = free_list; slist; slist = slist->next)
|
||||
{
|
||||
GtkAccelGroup *accel_group;
|
||||
|
||||
accel_group = slist->data;
|
||||
accel_group->priv->acceleratables = g_slist_remove (accel_group->priv->acceleratables, stale_object);
|
||||
g_object_unref (accel_group);
|
||||
}
|
||||
g_slist_free (free_list);
|
||||
g_object_set_qdata (stale_object, quark_acceleratable_groups, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
_gtk_accel_group_attach (GtkAccelGroup *accel_group,
|
||||
GObject *object)
|
||||
{
|
||||
GSList *slist;
|
||||
|
||||
g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
|
||||
g_return_if_fail (G_IS_OBJECT (object));
|
||||
g_return_if_fail (g_slist_find (accel_group->priv->acceleratables, object) == NULL);
|
||||
|
||||
g_object_ref (accel_group);
|
||||
accel_group->priv->acceleratables = g_slist_prepend (accel_group->priv->acceleratables, object);
|
||||
slist = g_object_get_qdata (object, quark_acceleratable_groups);
|
||||
if (slist)
|
||||
g_object_weak_unref (object,
|
||||
(GWeakNotify) accel_group_weak_ref_detach,
|
||||
slist);
|
||||
slist = g_slist_prepend (slist, accel_group);
|
||||
g_object_set_qdata (object, quark_acceleratable_groups, slist);
|
||||
g_object_weak_ref (object,
|
||||
(GWeakNotify) accel_group_weak_ref_detach,
|
||||
slist);
|
||||
}
|
||||
|
||||
void
|
||||
_gtk_accel_group_detach (GtkAccelGroup *accel_group,
|
||||
GObject *object)
|
||||
{
|
||||
GSList *slist;
|
||||
|
||||
g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
|
||||
g_return_if_fail (G_IS_OBJECT (object));
|
||||
g_return_if_fail (g_slist_find (accel_group->priv->acceleratables, object) != NULL);
|
||||
|
||||
accel_group->priv->acceleratables = g_slist_remove (accel_group->priv->acceleratables, object);
|
||||
slist = g_object_get_qdata (object, quark_acceleratable_groups);
|
||||
g_object_weak_unref (object,
|
||||
(GWeakNotify) accel_group_weak_ref_detach,
|
||||
slist);
|
||||
slist = g_slist_remove (slist, accel_group);
|
||||
g_object_set_qdata (object, quark_acceleratable_groups, slist);
|
||||
if (slist)
|
||||
g_object_weak_ref (object,
|
||||
(GWeakNotify) accel_group_weak_ref_detach,
|
||||
slist);
|
||||
g_object_unref (accel_group);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_accel_groups_from_object:
|
||||
* @object: a #GObject, usually a #GtkWindow
|
||||
*
|
||||
* Gets a list of all accel groups which are attached to @object.
|
||||
*
|
||||
* Returns: (element-type GtkAccelGroup) (transfer none): a list of
|
||||
* all accel groups which are attached to @object
|
||||
*/
|
||||
GSList*
|
||||
gtk_accel_groups_from_object (GObject *object)
|
||||
{
|
||||
g_return_val_if_fail (G_IS_OBJECT (object), NULL);
|
||||
|
||||
return g_object_get_qdata (object, quark_acceleratable_groups);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_accel_group_find:
|
||||
* @accel_group: a #GtkAccelGroup
|
||||
* @find_func: (scope call): a function to filter the entries
|
||||
* of @accel_group with
|
||||
* @data: data to pass to @find_func
|
||||
*
|
||||
* Finds the first entry in an accelerator group for which
|
||||
* @find_func returns %TRUE and returns its #GtkAccelKey.
|
||||
*
|
||||
* Returns: (transfer none): the key of the first entry passing
|
||||
* @find_func. The key is owned by GTK+ and must not be freed.
|
||||
*/
|
||||
GtkAccelKey*
|
||||
gtk_accel_group_find (GtkAccelGroup *accel_group,
|
||||
GtkAccelGroupFindFunc find_func,
|
||||
gpointer data)
|
||||
{
|
||||
GtkAccelKey *key = NULL;
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), NULL);
|
||||
g_return_val_if_fail (find_func != NULL, NULL);
|
||||
|
||||
g_object_ref (accel_group);
|
||||
for (i = 0; i < accel_group->priv->n_accels; i++)
|
||||
if (find_func (&accel_group->priv->priv_accels[i].key,
|
||||
accel_group->priv->priv_accels[i].closure,
|
||||
data))
|
||||
{
|
||||
key = &accel_group->priv->priv_accels[i].key;
|
||||
break;
|
||||
}
|
||||
g_object_unref (accel_group);
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
static void
|
||||
accel_closure_invalidate (gpointer data,
|
||||
GClosure *closure)
|
||||
{
|
||||
GtkAccelGroup *accel_group = GTK_ACCEL_GROUP (data);
|
||||
|
||||
gtk_accel_group_disconnect (accel_group, closure);
|
||||
}
|
||||
|
||||
static int
|
||||
bsearch_compare_accels (const void *d1,
|
||||
const void *d2)
|
||||
{
|
||||
const GtkAccelGroupEntry *entry1 = d1;
|
||||
const GtkAccelGroupEntry *entry2 = d2;
|
||||
|
||||
if (entry1->key.accel_key == entry2->key.accel_key)
|
||||
return entry1->key.accel_mods < entry2->key.accel_mods ? -1 : entry1->key.accel_mods > entry2->key.accel_mods;
|
||||
else
|
||||
return entry1->key.accel_key < entry2->key.accel_key ? -1 : 1;
|
||||
}
|
||||
|
||||
static void
|
||||
quick_accel_add (GtkAccelGroup *accel_group,
|
||||
guint accel_key,
|
||||
GdkModifierType accel_mods,
|
||||
GtkAccelFlags accel_flags,
|
||||
GClosure *closure)
|
||||
{
|
||||
guint pos, i = accel_group->priv->n_accels++;
|
||||
GtkAccelGroupEntry key;
|
||||
|
||||
/* find position */
|
||||
key.key.accel_key = accel_key;
|
||||
key.key.accel_mods = accel_mods;
|
||||
for (pos = 0; pos < i; pos++)
|
||||
if (bsearch_compare_accels (&key, accel_group->priv->priv_accels + pos) < 0)
|
||||
break;
|
||||
|
||||
/* insert at position, ref closure */
|
||||
accel_group->priv->priv_accels = g_renew (GtkAccelGroupEntry, accel_group->priv->priv_accels, accel_group->priv->n_accels);
|
||||
memmove (accel_group->priv->priv_accels + pos + 1, accel_group->priv->priv_accels + pos,
|
||||
(i - pos) * sizeof (accel_group->priv->priv_accels[0]));
|
||||
accel_group->priv->priv_accels[pos].key.accel_key = accel_key;
|
||||
accel_group->priv->priv_accels[pos].key.accel_mods = accel_mods;
|
||||
accel_group->priv->priv_accels[pos].key.accel_flags = accel_flags;
|
||||
accel_group->priv->priv_accels[pos].closure = g_closure_ref (closure);
|
||||
g_closure_sink (closure);
|
||||
|
||||
/* handle closure invalidation and reverse lookups */
|
||||
g_closure_add_invalidate_notifier (closure, accel_group, accel_closure_invalidate);
|
||||
|
||||
/* connect and notify changed */
|
||||
if (accel_key)
|
||||
{
|
||||
gchar *accel_name = gtk_accelerator_name (accel_key, accel_mods);
|
||||
GQuark accel_quark = g_quark_from_string (accel_name);
|
||||
|
||||
g_free (accel_name);
|
||||
|
||||
/* setup handler */
|
||||
g_signal_connect_closure_by_id (accel_group, signal_accel_activate, accel_quark, closure, FALSE);
|
||||
|
||||
/* and notify */
|
||||
g_signal_emit (accel_group, signal_accel_changed, accel_quark, accel_key, accel_mods, closure);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
quick_accel_remove (GtkAccelGroup *accel_group,
|
||||
guint pos)
|
||||
{
|
||||
GQuark accel_quark = 0;
|
||||
GtkAccelGroupEntry *entry = accel_group->priv->priv_accels + pos;
|
||||
guint accel_key = entry->key.accel_key;
|
||||
GdkModifierType accel_mods = entry->key.accel_mods;
|
||||
GClosure *closure = entry->closure;
|
||||
|
||||
/* quark for notification */
|
||||
if (accel_key)
|
||||
{
|
||||
gchar *accel_name = gtk_accelerator_name (accel_key, accel_mods);
|
||||
|
||||
accel_quark = g_quark_from_string (accel_name);
|
||||
g_free (accel_name);
|
||||
}
|
||||
|
||||
/* clean up closure invalidate notification and disconnect */
|
||||
g_closure_remove_invalidate_notifier (entry->closure, accel_group, accel_closure_invalidate);
|
||||
if (accel_quark)
|
||||
g_signal_handlers_disconnect_matched (accel_group,
|
||||
G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_CLOSURE,
|
||||
signal_accel_activate, accel_quark,
|
||||
closure, NULL, NULL);
|
||||
|
||||
/* physically remove */
|
||||
accel_group->priv->n_accels -= 1;
|
||||
memmove (entry, entry + 1,
|
||||
(accel_group->priv->n_accels - pos) * sizeof (accel_group->priv->priv_accels[0]));
|
||||
|
||||
/* and notify */
|
||||
if (accel_quark)
|
||||
g_signal_emit (accel_group, signal_accel_changed, accel_quark, accel_key, accel_mods, closure);
|
||||
|
||||
/* remove quick_accel_add() refcount */
|
||||
g_closure_unref (closure);
|
||||
}
|
||||
|
||||
static GtkAccelGroupEntry*
|
||||
quick_accel_find (GtkAccelGroup *accel_group,
|
||||
guint accel_key,
|
||||
GdkModifierType accel_mods,
|
||||
guint *count_p)
|
||||
{
|
||||
GtkAccelGroupEntry *entry;
|
||||
GtkAccelGroupEntry key;
|
||||
|
||||
*count_p = 0;
|
||||
|
||||
if (!accel_group->priv->n_accels)
|
||||
return NULL;
|
||||
|
||||
key.key.accel_key = accel_key;
|
||||
key.key.accel_mods = accel_mods;
|
||||
entry = bsearch (&key, accel_group->priv->priv_accels, accel_group->priv->n_accels,
|
||||
sizeof (accel_group->priv->priv_accels[0]), bsearch_compare_accels);
|
||||
|
||||
if (!entry)
|
||||
return NULL;
|
||||
|
||||
/* step back to the first member */
|
||||
for (; entry > accel_group->priv->priv_accels; entry--)
|
||||
if (entry[-1].key.accel_key != accel_key ||
|
||||
entry[-1].key.accel_mods != accel_mods)
|
||||
break;
|
||||
/* count equal members */
|
||||
for (; entry + *count_p < accel_group->priv->priv_accels + accel_group->priv->n_accels; (*count_p)++)
|
||||
if (entry[*count_p].key.accel_key != accel_key ||
|
||||
entry[*count_p].key.accel_mods != accel_mods)
|
||||
break;
|
||||
return entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_accel_group_connect:
|
||||
* @accel_group: the accelerator group to install an accelerator in
|
||||
* @accel_key: key value of the accelerator
|
||||
* @accel_mods: modifier combination of the accelerator
|
||||
* @accel_flags: a flag mask to configure this accelerator
|
||||
* @closure: closure to be executed upon accelerator activation
|
||||
*
|
||||
* Installs an accelerator in this group. When @accel_group is being
|
||||
* activated in response to a call to gtk_accel_groups_activate(),
|
||||
* @closure will be invoked if the @accel_key and @accel_mods from
|
||||
* gtk_accel_groups_activate() match those of this connection.
|
||||
*
|
||||
* The signature used for the @closure is that of #GtkAccelGroupActivate.
|
||||
*
|
||||
* Note that, due to implementation details, a single closure can
|
||||
* only be connected to one accelerator group.
|
||||
*/
|
||||
void
|
||||
gtk_accel_group_connect (GtkAccelGroup *accel_group,
|
||||
guint accel_key,
|
||||
GdkModifierType accel_mods,
|
||||
GtkAccelFlags accel_flags,
|
||||
GClosure *closure)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
|
||||
g_return_if_fail (closure != NULL);
|
||||
g_return_if_fail (accel_key > 0);
|
||||
g_return_if_fail (gtk_accel_group_from_accel_closure (closure) == NULL);
|
||||
|
||||
g_object_ref (accel_group);
|
||||
if (!closure->is_invalid)
|
||||
quick_accel_add (accel_group,
|
||||
gdk_keyval_to_lower (accel_key),
|
||||
accel_mods, accel_flags, closure);
|
||||
g_object_unref (accel_group);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_accel_group_disconnect:
|
||||
* @accel_group: the accelerator group to remove an accelerator from
|
||||
* @closure: (allow-none): the closure to remove from this accelerator
|
||||
* group, or %NULL to remove all closures
|
||||
*
|
||||
* Removes an accelerator previously installed through
|
||||
* gtk_accel_group_connect().
|
||||
*
|
||||
* Returns: %TRUE if the closure was found and got disconnected
|
||||
*/
|
||||
gboolean
|
||||
gtk_accel_group_disconnect (GtkAccelGroup *accel_group,
|
||||
GClosure *closure)
|
||||
{
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
|
||||
|
||||
for (i = 0; i < accel_group->priv->n_accels; i++)
|
||||
if (accel_group->priv->priv_accels[i].closure == closure)
|
||||
{
|
||||
g_object_ref (accel_group);
|
||||
quick_accel_remove (accel_group, i);
|
||||
g_object_unref (accel_group);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_accel_group_disconnect_key:
|
||||
* @accel_group: the accelerator group to install an accelerator in
|
||||
* @accel_key: key value of the accelerator
|
||||
* @accel_mods: modifier combination of the accelerator
|
||||
*
|
||||
* Removes an accelerator previously installed through
|
||||
* gtk_accel_group_connect().
|
||||
*
|
||||
* Returns: %TRUE if there was an accelerator which could be
|
||||
* removed, %FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
gtk_accel_group_disconnect_key (GtkAccelGroup *accel_group,
|
||||
guint accel_key,
|
||||
GdkModifierType accel_mods)
|
||||
{
|
||||
GtkAccelGroupEntry *entries;
|
||||
GSList *slist, *clist = NULL;
|
||||
gboolean removed_one = FALSE;
|
||||
guint n;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
|
||||
|
||||
g_object_ref (accel_group);
|
||||
|
||||
accel_key = gdk_keyval_to_lower (accel_key);
|
||||
entries = quick_accel_find (accel_group, accel_key, accel_mods, &n);
|
||||
while (n--)
|
||||
{
|
||||
GClosure *closure = g_closure_ref (entries[n].closure);
|
||||
|
||||
clist = g_slist_prepend (clist, closure);
|
||||
}
|
||||
|
||||
for (slist = clist; slist; slist = slist->next)
|
||||
{
|
||||
GClosure *closure = slist->data;
|
||||
|
||||
removed_one |= gtk_accel_group_disconnect (accel_group, closure);
|
||||
g_closure_unref (closure);
|
||||
}
|
||||
g_slist_free (clist);
|
||||
|
||||
g_object_unref (accel_group);
|
||||
|
||||
return removed_one;
|
||||
}
|
||||
|
||||
GSList*
|
||||
_gtk_accel_group_get_accelerables (GtkAccelGroup *accel_group)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), NULL);
|
||||
|
||||
return accel_group->priv->acceleratables;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_accel_group_query:
|
||||
* @accel_group: the accelerator group to query
|
||||
* @accel_key: key value of the accelerator
|
||||
* @accel_mods: modifier combination of the accelerator
|
||||
* @n_entries: (out) (optional): location to return the number
|
||||
* of entries found, or %NULL
|
||||
*
|
||||
* Queries an accelerator group for all entries matching @accel_key
|
||||
* and @accel_mods.
|
||||
*
|
||||
* Returns: (nullable) (transfer none) (array length=n_entries): an array of
|
||||
* @n_entries #GtkAccelGroupEntry elements, or %NULL. The array
|
||||
* is owned by GTK+ and must not be freed.
|
||||
*/
|
||||
GtkAccelGroupEntry*
|
||||
gtk_accel_group_query (GtkAccelGroup *accel_group,
|
||||
guint accel_key,
|
||||
GdkModifierType accel_mods,
|
||||
guint *n_entries)
|
||||
{
|
||||
GtkAccelGroupEntry *entries;
|
||||
guint n;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), NULL);
|
||||
|
||||
entries = quick_accel_find (accel_group, gdk_keyval_to_lower (accel_key), accel_mods, &n);
|
||||
|
||||
if (n_entries)
|
||||
*n_entries = entries ? n : 0;
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_accel_group_from_accel_closure:
|
||||
* @closure: a #GClosure
|
||||
*
|
||||
* Finds the #GtkAccelGroup to which @closure is connected;
|
||||
* see gtk_accel_group_connect().
|
||||
*
|
||||
* Returns: (nullable) (transfer none): the #GtkAccelGroup to which @closure
|
||||
* is connected, or %NULL
|
||||
*/
|
||||
GtkAccelGroup*
|
||||
gtk_accel_group_from_accel_closure (GClosure *closure)
|
||||
{
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (closure != NULL, NULL);
|
||||
|
||||
/* A few remarks on what we do here. in general, we need a way to
|
||||
* reverse lookup accel_groups from closures that are being used in
|
||||
* accel groups. this could be done e.g via a hashtable. it is however
|
||||
* cheaper (memory wise) to just use the invalidation notifier on the
|
||||
* closure itself (which we need to install anyway), that contains the
|
||||
* accel group as data which, besides needing to peek a bit at closure
|
||||
* internals, works just as good.
|
||||
*/
|
||||
for (i = 0; i < G_CLOSURE_N_NOTIFIERS (closure); i++)
|
||||
if (closure->notifiers[i].notify == accel_closure_invalidate)
|
||||
return closure->notifiers[i].data;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_accel_group_activate:
|
||||
* @accel_group: a #GtkAccelGroup
|
||||
* @accel_quark: the quark for the accelerator name
|
||||
* @acceleratable: the #GObject, usually a #GtkWindow, on which
|
||||
* to activate the accelerator
|
||||
* @accel_key: accelerator keyval from a key event
|
||||
* @accel_mods: keyboard state mask from a key event
|
||||
*
|
||||
* Finds the first accelerator in @accel_group that matches
|
||||
* @accel_key and @accel_mods, and activates it.
|
||||
*
|
||||
* Returns: %TRUE if an accelerator was activated and handled
|
||||
* this keypress
|
||||
*/
|
||||
gboolean
|
||||
gtk_accel_group_activate (GtkAccelGroup *accel_group,
|
||||
GQuark accel_quark,
|
||||
GObject *acceleratable,
|
||||
guint accel_key,
|
||||
GdkModifierType accel_mods)
|
||||
{
|
||||
gboolean was_handled;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
|
||||
g_return_val_if_fail (G_IS_OBJECT (acceleratable), FALSE);
|
||||
|
||||
was_handled = FALSE;
|
||||
g_signal_emit (accel_group, signal_accel_activate, accel_quark,
|
||||
acceleratable, accel_key, accel_mods, &was_handled);
|
||||
|
||||
return was_handled;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_accel_groups_activate:
|
||||
* @object: the #GObject, usually a #GtkWindow, on which
|
||||
* to activate the accelerator
|
||||
* @accel_key: accelerator keyval from a key event
|
||||
* @accel_mods: keyboard state mask from a key event
|
||||
*
|
||||
* Finds the first accelerator in any #GtkAccelGroup attached
|
||||
* to @object that matches @accel_key and @accel_mods, and
|
||||
* activates that accelerator.
|
||||
*
|
||||
* Returns: %TRUE if an accelerator was activated and handled
|
||||
* this keypress
|
||||
*/
|
||||
gboolean
|
||||
gtk_accel_groups_activate (GObject *object,
|
||||
guint accel_key,
|
||||
GdkModifierType accel_mods)
|
||||
{
|
||||
g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
|
||||
|
||||
if (gtk_accelerator_valid (accel_key, accel_mods))
|
||||
{
|
||||
gchar *accel_name;
|
||||
GQuark accel_quark;
|
||||
GSList *slist;
|
||||
|
||||
accel_name = gtk_accelerator_name (accel_key, (accel_mods & gtk_accelerator_get_default_mod_mask ()));
|
||||
accel_quark = g_quark_from_string (accel_name);
|
||||
g_free (accel_name);
|
||||
|
||||
for (slist = gtk_accel_groups_from_object (object); slist; slist = slist->next)
|
||||
if (gtk_accel_group_activate (slist->data, accel_quark, object, accel_key, accel_mods))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_accelerator_valid:
|
||||
* @keyval: a GDK keyval
|
||||
|
@ -36,149 +36,6 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
/* --- type macros --- */
|
||||
#define GTK_TYPE_ACCEL_GROUP (gtk_accel_group_get_type ())
|
||||
#define GTK_ACCEL_GROUP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GTK_TYPE_ACCEL_GROUP, GtkAccelGroup))
|
||||
#define GTK_ACCEL_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_ACCEL_GROUP, GtkAccelGroupClass))
|
||||
#define GTK_IS_ACCEL_GROUP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GTK_TYPE_ACCEL_GROUP))
|
||||
#define GTK_IS_ACCEL_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_ACCEL_GROUP))
|
||||
#define GTK_ACCEL_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_ACCEL_GROUP, GtkAccelGroupClass))
|
||||
|
||||
|
||||
/* --- accel flags --- */
|
||||
/**
|
||||
* GtkAccelFlags:
|
||||
* @GTK_ACCEL_VISIBLE: Accelerator is visible
|
||||
* @GTK_ACCEL_LOCKED: Accelerator not removable
|
||||
* @GTK_ACCEL_MASK: Mask
|
||||
*
|
||||
* Accelerator flags used with gtk_accel_group_connect().
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
GTK_ACCEL_VISIBLE = 1 << 0,
|
||||
GTK_ACCEL_LOCKED = 1 << 1,
|
||||
GTK_ACCEL_MASK = 0x07
|
||||
} GtkAccelFlags;
|
||||
|
||||
|
||||
/* --- typedefs & structures --- */
|
||||
typedef struct _GtkAccelGroup GtkAccelGroup;
|
||||
typedef struct _GtkAccelGroupClass GtkAccelGroupClass;
|
||||
typedef struct _GtkAccelGroupPrivate GtkAccelGroupPrivate;
|
||||
typedef struct _GtkAccelKey GtkAccelKey;
|
||||
typedef struct _GtkAccelGroupEntry GtkAccelGroupEntry;
|
||||
typedef gboolean (*GtkAccelGroupActivate) (GtkAccelGroup *accel_group,
|
||||
GObject *acceleratable,
|
||||
guint keyval,
|
||||
GdkModifierType modifier);
|
||||
|
||||
/**
|
||||
* GtkAccelGroupFindFunc:
|
||||
* @key:
|
||||
* @closure:
|
||||
* @data: (closure):
|
||||
*/
|
||||
typedef gboolean (*GtkAccelGroupFindFunc) (GtkAccelKey *key,
|
||||
GClosure *closure,
|
||||
gpointer data);
|
||||
|
||||
/**
|
||||
* GtkAccelGroup:
|
||||
*
|
||||
* An object representing and maintaining a group of accelerators.
|
||||
*/
|
||||
struct _GtkAccelGroup
|
||||
{
|
||||
GObject parent;
|
||||
GtkAccelGroupPrivate *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* GtkAccelGroupClass:
|
||||
* @parent_class: The parent class.
|
||||
* @accel_changed: Signal emitted when an entry is added to or removed
|
||||
* from the accel group.
|
||||
*/
|
||||
struct _GtkAccelGroupClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
/*< public >*/
|
||||
|
||||
void (*accel_changed) (GtkAccelGroup *accel_group,
|
||||
guint keyval,
|
||||
GdkModifierType modifier,
|
||||
GClosure *accel_closure);
|
||||
|
||||
/*< private >*/
|
||||
|
||||
/* Padding for future expansion */
|
||||
void (*_gtk_reserved1) (void);
|
||||
void (*_gtk_reserved2) (void);
|
||||
void (*_gtk_reserved3) (void);
|
||||
void (*_gtk_reserved4) (void);
|
||||
};
|
||||
|
||||
/**
|
||||
* GtkAccelKey:
|
||||
* @accel_key: The accelerator keyval
|
||||
* @accel_mods:The accelerator modifiers
|
||||
* @accel_flags: The accelerator flags
|
||||
*/
|
||||
struct _GtkAccelKey
|
||||
{
|
||||
guint accel_key;
|
||||
GdkModifierType accel_mods;
|
||||
guint accel_flags : 16;
|
||||
};
|
||||
|
||||
|
||||
/* -- Accelerator Groups --- */
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GType gtk_accel_group_get_type (void) G_GNUC_CONST;
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkAccelGroup* gtk_accel_group_new (void);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_accel_group_connect (GtkAccelGroup *accel_group,
|
||||
guint accel_key,
|
||||
GdkModifierType accel_mods,
|
||||
GtkAccelFlags accel_flags,
|
||||
GClosure *closure);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_accel_group_disconnect (GtkAccelGroup *accel_group,
|
||||
GClosure *closure);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_accel_group_disconnect_key (GtkAccelGroup *accel_group,
|
||||
guint accel_key,
|
||||
GdkModifierType accel_mods);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_accel_group_activate (GtkAccelGroup *accel_group,
|
||||
GQuark accel_quark,
|
||||
GObject *acceleratable,
|
||||
guint accel_key,
|
||||
GdkModifierType accel_mods);
|
||||
|
||||
|
||||
/* --- GtkActivatable glue --- */
|
||||
void _gtk_accel_group_attach (GtkAccelGroup *accel_group,
|
||||
GObject *object);
|
||||
void _gtk_accel_group_detach (GtkAccelGroup *accel_group,
|
||||
GObject *object);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_accel_groups_activate (GObject *object,
|
||||
guint accel_key,
|
||||
GdkModifierType accel_mods);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GSList* gtk_accel_groups_from_object (GObject *object);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkAccelKey* gtk_accel_group_find (GtkAccelGroup *accel_group,
|
||||
GtkAccelGroupFindFunc find_func,
|
||||
gpointer data);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkAccelGroup* gtk_accel_group_from_accel_closure (GClosure *closure);
|
||||
|
||||
|
||||
/* --- Accelerators--- */
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_accelerator_valid (guint keyval,
|
||||
@ -215,21 +72,6 @@ GDK_AVAILABLE_IN_ALL
|
||||
GdkModifierType
|
||||
gtk_accelerator_get_default_mod_mask (void);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkAccelGroupEntry* gtk_accel_group_query (GtkAccelGroup *accel_group,
|
||||
guint accel_key,
|
||||
GdkModifierType accel_mods,
|
||||
guint *n_entries);
|
||||
|
||||
struct _GtkAccelGroupEntry
|
||||
{
|
||||
GtkAccelKey key;
|
||||
GClosure *closure;
|
||||
GQuark accel_path_quark;
|
||||
};
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkAccelGroup, g_object_unref)
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_ACCEL_GROUP_H__ */
|
||||
|
@ -25,15 +25,6 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
struct _GtkAccelGroupPrivate
|
||||
{
|
||||
GSList *acceleratables;
|
||||
guint n_accels;
|
||||
GtkAccelGroupEntry *priv_accels;
|
||||
};
|
||||
|
||||
GSList* _gtk_accel_group_get_accelerables (GtkAccelGroup *accel_group);
|
||||
|
||||
void gtk_accelerator_print_label (GString *gstring,
|
||||
guint accelerator_key,
|
||||
GdkModifierType accelerator_mods);
|
||||
|
@ -68,7 +68,6 @@
|
||||
* set (see #GtkAccelFlags).
|
||||
* A #GtkAccelLabel can display multiple accelerators and even signal names,
|
||||
* though it is almost always used to display just one accelerator key.
|
||||
* ]|
|
||||
*
|
||||
* # CSS nodes
|
||||
*
|
||||
@ -84,8 +83,6 @@
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_ACCEL_CLOSURE,
|
||||
PROP_ACCEL_WIDGET,
|
||||
PROP_LABEL,
|
||||
PROP_USE_UNDERLINE,
|
||||
LAST_PROP
|
||||
@ -112,10 +109,6 @@ struct _GtkAccelLabelPrivate
|
||||
GtkWidget *text_label;
|
||||
GtkWidget *accel_label;
|
||||
|
||||
GtkWidget *accel_widget; /* done */
|
||||
GClosure *accel_closure; /* has set function */
|
||||
GtkAccelGroup *accel_group; /* set by set_accel_closure() */
|
||||
|
||||
guint accel_key; /* manual accel key specification if != 0 */
|
||||
GdkModifierType accel_mods;
|
||||
};
|
||||
@ -130,7 +123,6 @@ static void gtk_accel_label_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void gtk_accel_label_destroy (GtkWidget *widget);
|
||||
static void gtk_accel_label_finalize (GObject *object);
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GtkAccelLabel, gtk_accel_label, GTK_TYPE_WIDGET)
|
||||
@ -145,24 +137,8 @@ gtk_accel_label_class_init (GtkAccelLabelClass *class)
|
||||
gobject_class->set_property = gtk_accel_label_set_property;
|
||||
gobject_class->get_property = gtk_accel_label_get_property;
|
||||
|
||||
widget_class->destroy = gtk_accel_label_destroy;
|
||||
|
||||
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_ACCEL_LABEL);
|
||||
|
||||
props[PROP_ACCEL_CLOSURE] =
|
||||
g_param_spec_boxed ("accel-closure",
|
||||
P_("Accelerator Closure"),
|
||||
P_("The closure to be monitored for accelerator changes"),
|
||||
G_TYPE_CLOSURE,
|
||||
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
props[PROP_ACCEL_WIDGET] =
|
||||
g_param_spec_object ("accel-widget",
|
||||
P_("Accelerator Widget"),
|
||||
P_("The widget to be monitored for accelerator changes"),
|
||||
GTK_TYPE_WIDGET,
|
||||
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
props[PROP_LABEL] =
|
||||
g_param_spec_string ("label",
|
||||
P_("Label"),
|
||||
@ -195,12 +171,6 @@ gtk_accel_label_set_property (GObject *object,
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_ACCEL_CLOSURE:
|
||||
gtk_accel_label_set_accel_closure (accel_label, g_value_get_boxed (value));
|
||||
break;
|
||||
case PROP_ACCEL_WIDGET:
|
||||
gtk_accel_label_set_accel_widget (accel_label, g_value_get_object (value));
|
||||
break;
|
||||
case PROP_LABEL:
|
||||
gtk_accel_label_set_label (accel_label, g_value_get_string (value));
|
||||
break;
|
||||
@ -220,16 +190,9 @@ gtk_accel_label_get_property (GObject *object,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
|
||||
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_ACCEL_CLOSURE:
|
||||
g_value_set_boxed (value, priv->accel_closure);
|
||||
break;
|
||||
case PROP_ACCEL_WIDGET:
|
||||
g_value_set_object (value, priv->accel_widget);
|
||||
break;
|
||||
case PROP_LABEL:
|
||||
g_value_set_string (value, gtk_accel_label_get_label (accel_label));
|
||||
break;
|
||||
@ -247,10 +210,6 @@ gtk_accel_label_init (GtkAccelLabel *accel_label)
|
||||
{
|
||||
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
|
||||
|
||||
priv->accel_widget = NULL;
|
||||
priv->accel_closure = NULL;
|
||||
priv->accel_group = NULL;
|
||||
|
||||
priv->text_label = gtk_label_new ("");
|
||||
gtk_widget_set_hexpand (priv->text_label, TRUE);
|
||||
gtk_label_set_xalign (GTK_LABEL (priv->text_label), 0.0f);
|
||||
@ -283,17 +242,6 @@ gtk_accel_label_new (const gchar *string)
|
||||
return GTK_WIDGET (accel_label);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_accel_label_destroy (GtkWidget *widget)
|
||||
{
|
||||
GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
|
||||
|
||||
gtk_accel_label_set_accel_widget (accel_label, NULL);
|
||||
gtk_accel_label_set_accel_closure (accel_label, NULL);
|
||||
|
||||
GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->destroy (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_accel_label_finalize (GObject *object)
|
||||
{
|
||||
@ -306,26 +254,6 @@ gtk_accel_label_finalize (GObject *object)
|
||||
G_OBJECT_CLASS (gtk_accel_label_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_accel_label_get_accel_widget:
|
||||
* @accel_label: a #GtkAccelLabel
|
||||
*
|
||||
* Fetches the widget monitored by this accelerator label. See
|
||||
* gtk_accel_label_set_accel_widget().
|
||||
*
|
||||
* Returns: (nullable) (transfer none): the widget monitored by @accel_label,
|
||||
* or %NULL if it is not monitoring a widget.
|
||||
**/
|
||||
GtkWidget *
|
||||
gtk_accel_label_get_accel_widget (GtkAccelLabel *accel_label)
|
||||
{
|
||||
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
|
||||
|
||||
g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), NULL);
|
||||
|
||||
return priv->accel_widget;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_accel_label_get_accel_width:
|
||||
* @accel_label: a #GtkAccelLabel.
|
||||
@ -350,175 +278,6 @@ gtk_accel_label_get_accel_width (GtkAccelLabel *accel_label)
|
||||
return min;
|
||||
}
|
||||
|
||||
static void
|
||||
refetch_widget_accel_closure (GtkAccelLabel *accel_label)
|
||||
{
|
||||
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
|
||||
|
||||
g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
|
||||
g_return_if_fail (GTK_IS_WIDGET (priv->accel_widget));
|
||||
|
||||
gtk_accel_label_set_accel_closure (accel_label, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
accel_widget_weak_ref_cb (GtkAccelLabel *accel_label,
|
||||
GtkWidget *old_accel_widget)
|
||||
{
|
||||
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
|
||||
|
||||
g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
|
||||
g_return_if_fail (GTK_IS_WIDGET (priv->accel_widget));
|
||||
|
||||
g_signal_handlers_disconnect_by_func (priv->accel_widget,
|
||||
refetch_widget_accel_closure,
|
||||
accel_label);
|
||||
priv->accel_widget = NULL;
|
||||
g_object_notify_by_pspec (G_OBJECT (accel_label), props[PROP_ACCEL_WIDGET]);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_accel_label_set_accel_widget:
|
||||
* @accel_label: a #GtkAccelLabel
|
||||
* @accel_widget: (nullable): the widget to be monitored, or %NULL
|
||||
*
|
||||
* Sets the widget to be monitored by this accelerator label. Passing %NULL for
|
||||
* @accel_widget will dissociate @accel_label from its current widget, if any.
|
||||
*/
|
||||
void
|
||||
gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
|
||||
GtkWidget *accel_widget)
|
||||
{
|
||||
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
|
||||
|
||||
g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
|
||||
|
||||
if (accel_widget)
|
||||
g_return_if_fail (GTK_IS_WIDGET (accel_widget));
|
||||
|
||||
if (accel_widget != priv->accel_widget)
|
||||
{
|
||||
if (priv->accel_widget)
|
||||
{
|
||||
gtk_accel_label_set_accel_closure (accel_label, NULL);
|
||||
g_signal_handlers_disconnect_by_func (priv->accel_widget,
|
||||
refetch_widget_accel_closure,
|
||||
accel_label);
|
||||
g_object_weak_unref (G_OBJECT (priv->accel_widget),
|
||||
(GWeakNotify) accel_widget_weak_ref_cb, accel_label);
|
||||
}
|
||||
|
||||
priv->accel_widget = accel_widget;
|
||||
|
||||
if (priv->accel_widget)
|
||||
{
|
||||
g_object_weak_ref (G_OBJECT (priv->accel_widget),
|
||||
(GWeakNotify) accel_widget_weak_ref_cb, accel_label);
|
||||
g_signal_connect_object (priv->accel_widget, "accel-closures-changed",
|
||||
G_CALLBACK (refetch_widget_accel_closure),
|
||||
accel_label, G_CONNECT_SWAPPED);
|
||||
refetch_widget_accel_closure (accel_label);
|
||||
}
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (accel_label), props[PROP_ACCEL_WIDGET]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_accel_label_reset (GtkAccelLabel *accel_label)
|
||||
{
|
||||
gtk_accel_label_refetch (accel_label);
|
||||
}
|
||||
|
||||
static void
|
||||
check_accel_changed (GtkAccelGroup *accel_group,
|
||||
guint keyval,
|
||||
GdkModifierType modifier,
|
||||
GClosure *accel_closure,
|
||||
GtkAccelLabel *accel_label)
|
||||
{
|
||||
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
|
||||
|
||||
if (accel_closure == priv->accel_closure)
|
||||
gtk_accel_label_reset (accel_label);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_accel_label_set_accel_closure:
|
||||
* @accel_label: a #GtkAccelLabel
|
||||
* @accel_closure: (nullable): the closure to monitor for accelerator changes,
|
||||
* or %NULL
|
||||
*
|
||||
* Sets the closure to be monitored by this accelerator label. The closure
|
||||
* must be connected to an accelerator group; see gtk_accel_group_connect().
|
||||
* Passing %NULL for @accel_closure will dissociate @accel_label from its
|
||||
* current closure, if any.
|
||||
**/
|
||||
void
|
||||
gtk_accel_label_set_accel_closure (GtkAccelLabel *accel_label,
|
||||
GClosure *accel_closure)
|
||||
{
|
||||
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
|
||||
|
||||
g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
|
||||
|
||||
if (accel_closure)
|
||||
g_return_if_fail (gtk_accel_group_from_accel_closure (accel_closure) != NULL);
|
||||
|
||||
if (accel_closure != priv->accel_closure)
|
||||
{
|
||||
if (priv->accel_closure)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (priv->accel_group,
|
||||
check_accel_changed,
|
||||
accel_label);
|
||||
priv->accel_group = NULL;
|
||||
g_closure_unref (priv->accel_closure);
|
||||
}
|
||||
|
||||
priv->accel_closure = accel_closure;
|
||||
|
||||
if (priv->accel_closure)
|
||||
{
|
||||
g_closure_ref (priv->accel_closure);
|
||||
priv->accel_group = gtk_accel_group_from_accel_closure (accel_closure);
|
||||
g_signal_connect_object (priv->accel_group, "accel-changed", G_CALLBACK (check_accel_changed),
|
||||
accel_label, 0);
|
||||
}
|
||||
|
||||
gtk_accel_label_reset (accel_label);
|
||||
g_object_notify_by_pspec (G_OBJECT (accel_label), props[PROP_ACCEL_CLOSURE]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_accel_label_get_accel_closure:
|
||||
* @accel_label: a #GtkAccelLabel
|
||||
*
|
||||
* Fetches the closure monitored by this accelerator label. See
|
||||
* gtk_accel_label_set_accel_closure().
|
||||
*
|
||||
* Returns: (nullable) (transfer none): the closure monitored by @accel_label,
|
||||
* or %NULL if it is not monitoring a closure.
|
||||
*/
|
||||
GClosure *
|
||||
gtk_accel_label_get_accel_closure (GtkAccelLabel *accel_label)
|
||||
{
|
||||
GtkAccelLabelPrivate *priv = gtk_accel_label_get_instance_private (accel_label);
|
||||
|
||||
g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), NULL);
|
||||
|
||||
return priv->accel_closure;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
find_accel (GtkAccelKey *key,
|
||||
GClosure *closure,
|
||||
gpointer data)
|
||||
{
|
||||
return data == (gpointer) closure;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_accel_label_refetch:
|
||||
* @accel_label: a #GtkAccelLabel.
|
||||
@ -542,7 +301,7 @@ gtk_accel_label_refetch (GtkAccelLabel *accel_label)
|
||||
"gtk-enable-accels", &enable_accels,
|
||||
NULL);
|
||||
|
||||
if (enable_accels && (priv->accel_closure || priv->accel_key))
|
||||
if (enable_accels && priv->accel_key)
|
||||
{
|
||||
gboolean have_accel = FALSE;
|
||||
guint accel_key;
|
||||
@ -556,21 +315,6 @@ gtk_accel_label_refetch (GtkAccelLabel *accel_label)
|
||||
have_accel = TRUE;
|
||||
}
|
||||
|
||||
/* If we don't have a hardcoded value, check the accel group */
|
||||
if (!have_accel)
|
||||
{
|
||||
GtkAccelKey *key;
|
||||
|
||||
key = gtk_accel_group_find (priv->accel_group, find_accel, priv->accel_closure);
|
||||
|
||||
if (key && key->accel_flags & GTK_ACCEL_VISIBLE)
|
||||
{
|
||||
accel_key = key->accel_key;
|
||||
accel_mods = key->accel_mods;
|
||||
have_accel = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we found a key using either method, set it */
|
||||
if (have_accel)
|
||||
accel_string = gtk_accelerator_get_label (accel_key, accel_mods);
|
||||
@ -615,7 +359,7 @@ gtk_accel_label_set_accel (GtkAccelLabel *accel_label,
|
||||
priv->accel_key = accelerator_key;
|
||||
priv->accel_mods = accelerator_mods;
|
||||
|
||||
gtk_accel_label_reset (accel_label);
|
||||
gtk_accel_label_refetch (accel_label);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,18 +46,8 @@ GType gtk_accel_label_get_type (void) G_GNUC_CONST;
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkWidget *gtk_accel_label_new (const gchar *string);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkWidget *gtk_accel_label_get_accel_widget (GtkAccelLabel *accel_label);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
guint gtk_accel_label_get_accel_width (GtkAccelLabel *accel_label);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
|
||||
GtkWidget *accel_widget);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_accel_label_set_accel_closure (GtkAccelLabel *accel_label,
|
||||
GClosure *accel_closure);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GClosure * gtk_accel_label_get_accel_closure (GtkAccelLabel *accel_label);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_accel_label_refetch (GtkAccelLabel *accel_label);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_accel_label_set_accel (GtkAccelLabel *accel_label,
|
||||
|
@ -1646,14 +1646,11 @@ gtk_main_do_event (GdkEvent *event)
|
||||
current_events = g_list_prepend (current_events, event);
|
||||
|
||||
if (is_pointing_event (event))
|
||||
target_widget = handle_pointing_event (event);
|
||||
{
|
||||
target_widget = handle_pointing_event (event);
|
||||
}
|
||||
else if (is_key_event (event))
|
||||
{
|
||||
if (gdk_event_get_event_type (event) == GDK_KEY_PRESS &&
|
||||
GTK_IS_WINDOW (target_widget) &&
|
||||
gtk_window_activate_key (GTK_WINDOW (target_widget), event))
|
||||
goto cleanup;
|
||||
|
||||
target_widget = handle_key_event (event);
|
||||
}
|
||||
else if (is_focus_event (event))
|
||||
|
351
gtk/gtkwindow.c
351
gtk/gtkwindow.c
@ -494,7 +494,6 @@ static gboolean disable_startup_notification = FALSE;
|
||||
|
||||
static GQuark quark_gtk_window_key_hash = 0;
|
||||
static GQuark quark_gtk_window_icon_info = 0;
|
||||
static GQuark quark_gtk_buildable_accels = 0;
|
||||
|
||||
static GtkBuildableIface *parent_buildable_iface;
|
||||
|
||||
@ -517,19 +516,6 @@ static void gtk_window_buildable_set_buildable_property (GtkBuildable
|
||||
GtkBuilder *builder,
|
||||
const gchar *name,
|
||||
const GValue *value);
|
||||
static void gtk_window_buildable_parser_finished (GtkBuildable *buildable,
|
||||
GtkBuilder *builder);
|
||||
static gboolean gtk_window_buildable_custom_tag_start (GtkBuildable *buildable,
|
||||
GtkBuilder *builder,
|
||||
GObject *child,
|
||||
const gchar *tagname,
|
||||
GtkBuildableParser *parser,
|
||||
gpointer *data);
|
||||
static void gtk_window_buildable_custom_finished (GtkBuildable *buildable,
|
||||
GtkBuilder *builder,
|
||||
GObject *child,
|
||||
const gchar *tagname,
|
||||
gpointer user_data);
|
||||
|
||||
static void gtk_window_shortcut_manager_interface_init (GtkShortcutManagerInterface *iface);
|
||||
/* GtkRoot */
|
||||
@ -727,15 +713,11 @@ static void
|
||||
gtk_window_class_init (GtkWindowClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class;
|
||||
GtkContainerClass *container_class;
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
|
||||
|
||||
widget_class = (GtkWidgetClass*) klass;
|
||||
container_class = (GtkContainerClass*) klass;
|
||||
|
||||
quark_gtk_window_key_hash = g_quark_from_static_string ("gtk-window-key-hash");
|
||||
quark_gtk_window_icon_info = g_quark_from_static_string ("gtk-window-icon-info");
|
||||
quark_gtk_buildable_accels = g_quark_from_static_string ("gtk-window-buildable-accels");
|
||||
|
||||
if (toplevel_list == NULL)
|
||||
toplevel_list = g_list_store_new (GTK_TYPE_WIDGET);
|
||||
@ -1978,9 +1960,6 @@ gtk_window_buildable_interface_init (GtkBuildableIface *iface)
|
||||
{
|
||||
parent_buildable_iface = g_type_interface_peek_parent (iface);
|
||||
iface->set_buildable_property = gtk_window_buildable_set_buildable_property;
|
||||
iface->parser_finished = gtk_window_buildable_parser_finished;
|
||||
iface->custom_tag_start = gtk_window_buildable_custom_tag_start;
|
||||
iface->custom_finished = gtk_window_buildable_custom_finished;
|
||||
iface->add_child = gtk_window_buildable_add_child;
|
||||
}
|
||||
|
||||
@ -2013,168 +1992,6 @@ gtk_window_buildable_set_buildable_property (GtkBuildable *buildable,
|
||||
g_object_set_property (G_OBJECT (buildable), name, value);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
gchar *name;
|
||||
gint line;
|
||||
gint col;
|
||||
} ItemData;
|
||||
|
||||
static void
|
||||
item_data_free (gpointer data)
|
||||
{
|
||||
ItemData *item_data = data;
|
||||
|
||||
g_free (item_data->name);
|
||||
g_free (item_data);
|
||||
}
|
||||
|
||||
static void
|
||||
item_list_free (gpointer data)
|
||||
{
|
||||
GSList *list = data;
|
||||
|
||||
g_slist_free_full (list, item_data_free);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_window_buildable_parser_finished (GtkBuildable *buildable,
|
||||
GtkBuilder *builder)
|
||||
{
|
||||
GtkWindow *window = GTK_WINDOW (buildable);
|
||||
GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
|
||||
GObject *object;
|
||||
GSList *accels, *l;
|
||||
|
||||
if (priv->builder_visible)
|
||||
gtk_widget_show (GTK_WIDGET (buildable));
|
||||
|
||||
accels = g_object_get_qdata (G_OBJECT (buildable), quark_gtk_buildable_accels);
|
||||
for (l = accels; l; l = l->next)
|
||||
{
|
||||
ItemData *data = l->data;
|
||||
|
||||
object = _gtk_builder_lookup_object (builder, data->name, data->line, data->col);
|
||||
if (!object)
|
||||
continue;
|
||||
gtk_window_add_accel_group (GTK_WINDOW (buildable), GTK_ACCEL_GROUP (object));
|
||||
}
|
||||
|
||||
g_object_set_qdata (G_OBJECT (buildable), quark_gtk_buildable_accels, NULL);
|
||||
|
||||
parent_buildable_iface->parser_finished (buildable, builder);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GObject *object;
|
||||
GtkBuilder *builder;
|
||||
GSList *items;
|
||||
} GSListSubParserData;
|
||||
|
||||
static void
|
||||
window_start_element (GtkBuildableParseContext *context,
|
||||
const gchar *element_name,
|
||||
const gchar **names,
|
||||
const gchar **values,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
GSListSubParserData *data = (GSListSubParserData*)user_data;
|
||||
|
||||
if (strcmp (element_name, "group") == 0)
|
||||
{
|
||||
const gchar *name;
|
||||
ItemData *item_data;
|
||||
|
||||
if (!_gtk_builder_check_parent (data->builder, context, "accel-groups", error))
|
||||
return;
|
||||
|
||||
if (!g_markup_collect_attributes (element_name, names, values, error,
|
||||
G_MARKUP_COLLECT_STRING, "name", &name,
|
||||
G_MARKUP_COLLECT_INVALID))
|
||||
{
|
||||
_gtk_builder_prefix_error (data->builder, context, error);
|
||||
return;
|
||||
}
|
||||
|
||||
item_data = g_new (ItemData, 1);
|
||||
item_data->name = g_strdup (name);
|
||||
gtk_buildable_parse_context_get_position (context, &item_data->line, &item_data->col);
|
||||
data->items = g_slist_prepend (data->items, item_data);
|
||||
}
|
||||
else if (strcmp (element_name, "accel-groups") == 0)
|
||||
{
|
||||
if (!_gtk_builder_check_parent (data->builder, context, "object", error))
|
||||
return;
|
||||
|
||||
if (!g_markup_collect_attributes (element_name, names, values, error,
|
||||
G_MARKUP_COLLECT_INVALID, NULL, NULL,
|
||||
G_MARKUP_COLLECT_INVALID))
|
||||
_gtk_builder_prefix_error (data->builder, context, error);
|
||||
}
|
||||
else
|
||||
{
|
||||
_gtk_builder_error_unhandled_tag (data->builder, context,
|
||||
"GtkWindow", element_name,
|
||||
error);
|
||||
}
|
||||
}
|
||||
|
||||
static const GtkBuildableParser window_parser =
|
||||
{
|
||||
window_start_element
|
||||
};
|
||||
|
||||
static gboolean
|
||||
gtk_window_buildable_custom_tag_start (GtkBuildable *buildable,
|
||||
GtkBuilder *builder,
|
||||
GObject *child,
|
||||
const gchar *tagname,
|
||||
GtkBuildableParser *parser,
|
||||
gpointer *parser_data)
|
||||
{
|
||||
if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
|
||||
tagname, parser, parser_data))
|
||||
return TRUE;
|
||||
|
||||
if (strcmp (tagname, "accel-groups") == 0)
|
||||
{
|
||||
GSListSubParserData *data;
|
||||
|
||||
data = g_slice_new0 (GSListSubParserData);
|
||||
data->items = NULL;
|
||||
data->object = G_OBJECT (buildable);
|
||||
data->builder = builder;
|
||||
|
||||
*parser = window_parser;
|
||||
*parser_data = data;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_window_buildable_custom_finished (GtkBuildable *buildable,
|
||||
GtkBuilder *builder,
|
||||
GObject *child,
|
||||
const gchar *tagname,
|
||||
gpointer user_data)
|
||||
{
|
||||
parent_buildable_iface->custom_finished (buildable, builder, child,
|
||||
tagname, user_data);
|
||||
|
||||
if (strcmp (tagname, "accel-groups") == 0)
|
||||
{
|
||||
GSListSubParserData *data = (GSListSubParserData*)user_data;
|
||||
|
||||
g_object_set_qdata_full (G_OBJECT (buildable), quark_gtk_buildable_accels,
|
||||
data->items, (GDestroyNotify) item_list_free);
|
||||
|
||||
g_slice_free (GSListSubParserData, data);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_window_shortcut_manager_interface_init (GtkShortcutManagerInterface *iface)
|
||||
{
|
||||
@ -2511,50 +2328,6 @@ _gtk_window_notify_keys_changed (GtkWindow *window)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_window_add_accel_group:
|
||||
* @window: window to attach accelerator group to
|
||||
* @accel_group: a #GtkAccelGroup
|
||||
*
|
||||
* Associate @accel_group with @window, such that calling
|
||||
* gtk_accel_groups_activate() on @window will activate accelerators
|
||||
* in @accel_group.
|
||||
**/
|
||||
void
|
||||
gtk_window_add_accel_group (GtkWindow *window,
|
||||
GtkAccelGroup *accel_group)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_WINDOW (window));
|
||||
g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
|
||||
|
||||
_gtk_accel_group_attach (accel_group, G_OBJECT (window));
|
||||
g_signal_connect_object (accel_group, "accel-changed",
|
||||
G_CALLBACK (_gtk_window_notify_keys_changed),
|
||||
window, G_CONNECT_SWAPPED);
|
||||
_gtk_window_notify_keys_changed (window);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_window_remove_accel_group:
|
||||
* @window: a #GtkWindow
|
||||
* @accel_group: a #GtkAccelGroup
|
||||
*
|
||||
* Reverses the effects of gtk_window_add_accel_group().
|
||||
**/
|
||||
void
|
||||
gtk_window_remove_accel_group (GtkWindow *window,
|
||||
GtkAccelGroup *accel_group)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_WINDOW (window));
|
||||
g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
|
||||
|
||||
g_signal_handlers_disconnect_by_func (accel_group,
|
||||
_gtk_window_notify_keys_changed,
|
||||
window);
|
||||
_gtk_accel_group_detach (accel_group, G_OBJECT (window));
|
||||
_gtk_window_notify_keys_changed (window);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_window_get_focus:
|
||||
* @window: a #GtkWindow
|
||||
@ -7421,31 +7194,6 @@ gtk_window_activate_menubar (GtkWidget *widget,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_gtk_window_keys_foreach (GtkWindow *window,
|
||||
GtkWindowKeysForeachFunc func,
|
||||
gpointer func_data)
|
||||
{
|
||||
GSList *groups;
|
||||
|
||||
groups = gtk_accel_groups_from_object (G_OBJECT (window));
|
||||
while (groups)
|
||||
{
|
||||
GtkAccelGroup *group = groups->data;
|
||||
gint i;
|
||||
|
||||
for (i = 0; i < group->priv->n_accels; i++)
|
||||
{
|
||||
GtkAccelKey *key = &group->priv->priv_accels[i].key;
|
||||
|
||||
if (key->accel_key)
|
||||
(*func) (window, key->accel_key, key->accel_mods, func_data);
|
||||
}
|
||||
|
||||
groups = groups->next;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_window_keys_changed (GtkWindow *window)
|
||||
{
|
||||
@ -7467,33 +7215,6 @@ window_key_entry_destroy (gpointer data)
|
||||
g_slice_free (GtkWindowKeyEntry, data);
|
||||
}
|
||||
|
||||
static void
|
||||
add_to_key_hash (GtkWindow *window,
|
||||
guint keyval,
|
||||
GdkModifierType modifiers,
|
||||
gpointer data)
|
||||
{
|
||||
GtkKeyHash *key_hash = data;
|
||||
|
||||
GtkWindowKeyEntry *entry = g_slice_new (GtkWindowKeyEntry);
|
||||
|
||||
entry->keyval = keyval;
|
||||
entry->modifiers = modifiers;
|
||||
|
||||
/* GtkAccelGroup stores lowercased accelerators. To deal
|
||||
* with this, if <Shift> was specified, uppercase.
|
||||
*/
|
||||
if (modifiers & GDK_SHIFT_MASK)
|
||||
{
|
||||
if (keyval == GDK_KEY_Tab)
|
||||
keyval = GDK_KEY_ISO_Left_Tab;
|
||||
else
|
||||
keyval = gdk_keyval_to_upper (keyval);
|
||||
}
|
||||
|
||||
_gtk_key_hash_add_entry (key_hash, keyval, entry->modifiers, entry);
|
||||
}
|
||||
|
||||
static GtkKeyHash *
|
||||
gtk_window_get_key_hash (GtkWindow *window)
|
||||
{
|
||||
@ -7505,7 +7226,6 @@ gtk_window_get_key_hash (GtkWindow *window)
|
||||
|
||||
key_hash = _gtk_key_hash_new (gdk_display_get_keymap (priv->display),
|
||||
(GDestroyNotify)window_key_entry_destroy);
|
||||
_gtk_window_keys_foreach (window, add_to_key_hash, key_hash);
|
||||
g_object_set_qdata (G_OBJECT (window), quark_gtk_window_key_hash, key_hash);
|
||||
|
||||
return key_hash;
|
||||
@ -7522,73 +7242,6 @@ gtk_window_free_key_hash (GtkWindow *window)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_window_activate_key:
|
||||
* @window: a #GtkWindow
|
||||
* @event: a #GdkEvent
|
||||
*
|
||||
* Activates mnemonics and accelerators for this #GtkWindow. This is normally
|
||||
* called by the default ::key_press_event handler for toplevel windows,
|
||||
* however in some cases it may be useful to call this directly when
|
||||
* overriding the standard key handling for a toplevel window.
|
||||
*
|
||||
* Returns: %TRUE if a mnemonic or accelerator was found and activated.
|
||||
*/
|
||||
gboolean
|
||||
gtk_window_activate_key (GtkWindow *window,
|
||||
GdkEvent *event)
|
||||
{
|
||||
GtkKeyHash *key_hash;
|
||||
GtkWindowKeyEntry *found_entry = NULL;
|
||||
gboolean enable_accels;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
|
||||
g_return_val_if_fail (event != NULL, FALSE);
|
||||
|
||||
if (!(gdk_event_get_event_type (event) == GDK_KEY_PRESS ||
|
||||
gdk_event_get_event_type (event) == GDK_KEY_RELEASE))
|
||||
return FALSE;
|
||||
|
||||
key_hash = gtk_window_get_key_hash (window);
|
||||
|
||||
if (key_hash)
|
||||
{
|
||||
GSList *tmp_list;
|
||||
GSList *entries = _gtk_key_hash_lookup (key_hash,
|
||||
gdk_key_event_get_keycode (event),
|
||||
gdk_event_get_modifier_state (event),
|
||||
gtk_accelerator_get_default_mod_mask (),
|
||||
gdk_key_event_get_group (event));
|
||||
|
||||
g_object_get (gtk_widget_get_settings (GTK_WIDGET (window)),
|
||||
"gtk-enable-accels", &enable_accels,
|
||||
NULL);
|
||||
|
||||
for (tmp_list = entries; tmp_list; tmp_list = tmp_list->next)
|
||||
{
|
||||
GtkWindowKeyEntry *entry = tmp_list->data;
|
||||
if (enable_accels && !found_entry)
|
||||
{
|
||||
found_entry = entry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_slist_free (entries);
|
||||
}
|
||||
|
||||
if (found_entry)
|
||||
{
|
||||
if (enable_accels)
|
||||
{
|
||||
if (gtk_accel_groups_activate (G_OBJECT (window), found_entry->keyval, found_entry->modifiers))
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* _gtk_window_set_is_active:
|
||||
* @window: a #GtkWindow
|
||||
|
@ -97,12 +97,6 @@ GDK_AVAILABLE_IN_ALL
|
||||
void gtk_window_set_startup_id (GtkWindow *window,
|
||||
const gchar *startup_id);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_window_add_accel_group (GtkWindow *window,
|
||||
GtkAccelGroup *accel_group);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_window_remove_accel_group (GtkWindow *window,
|
||||
GtkAccelGroup *accel_group);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_window_set_focus (GtkWindow *window,
|
||||
GtkWidget *focus);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
|
@ -68,9 +68,6 @@ gboolean _gtk_window_query_nonaccels (GtkWindow *window,
|
||||
guint accel_key,
|
||||
GdkModifierType accel_mods);
|
||||
|
||||
gboolean gtk_window_activate_key (GtkWindow *window,
|
||||
GdkEvent *event);
|
||||
|
||||
void _gtk_window_schedule_mnemonics_visible (GtkWindow *window);
|
||||
|
||||
void _gtk_window_notify_keys_changed (GtkWindow *window);
|
||||
|
Loading…
Reference in New Issue
Block a user