aboutsummaryrefslogtreecommitdiff
path: root/libdbusmenu-gtk
diff options
context:
space:
mode:
authorLuke Yelavich <luke.yelavich@canonical.com>2012-01-31 18:32:11 +1100
committerLuke Yelavich <luke.yelavich@canonical.com>2012-01-31 18:32:11 +1100
commit1edc78050399e0e88f4ef8b59f66c649e4862b89 (patch)
tree6ff7cfd018ccc880023cd78020aa8d1ba407d0c3 /libdbusmenu-gtk
parent95e56adc0d86cfbbc67f04582a230076721276d1 (diff)
downloadlibdbusmenu-1edc78050399e0e88f4ef8b59f66c649e4862b89.tar.gz
libdbusmenu-1edc78050399e0e88f4ef8b59f66c649e4862b89.tar.bz2
libdbusmenu-1edc78050399e0e88f4ef8b59f66c649e4862b89.zip
When parsing an existing GTK menu hierarchy, we should also set the
DBUSMENU_MENU_ITEM_ACCESSIBLE_DESC property, if the accessible name for the menu differs from the text of the menu item label.
Diffstat (limited to 'libdbusmenu-gtk')
-rw-r--r--libdbusmenu-gtk/parser.c53
-rw-r--r--libdbusmenu-gtk/parser.h1
2 files changed, 54 insertions, 0 deletions
diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c
index 0ecfa1e..65a6b57 100644
--- a/libdbusmenu-gtk/parser.c
+++ b/libdbusmenu-gtk/parser.c
@@ -41,6 +41,7 @@ typedef struct _ParserData
GtkWidget *widget;
GtkWidget *shell;
GtkWidget *image;
+ AtkObject *accessible;
} ParserData;
typedef struct _RecurseContext
@@ -67,6 +68,9 @@ static void image_notify_cb (GtkWidget * widget,
static void action_notify_cb (GtkAction * action,
GParamSpec * pspec,
gpointer data);
+static void a11y_name_notify_cb (AtkObject * accessible,
+ GParamSpec * pspec,
+ gpointer data);
static void item_inserted_cb (GtkContainer * menu,
GtkWidget * widget,
#ifdef HAVE_GTK3
@@ -200,6 +204,12 @@ parse_data_free (gpointer data)
g_object_remove_weak_pointer(G_OBJECT(pdata->image), (gpointer*)&pdata->image);
}
+ if (pdata != NULL && pdata->accessible != NULL) {
+ g_signal_handlers_disconnect_matched(pdata->accessible, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,
+ 0, 0, NULL, G_CALLBACK(a11y_name_notify_cb), NULL);
+ g_object_remove_weak_pointer(G_OBJECT(pdata->accessible), (gpointer*)&pdata->accessible);
+ }
+
g_free(pdata);
return;
@@ -582,6 +592,27 @@ construct_dbusmenu_for_widget (GtkWidget * widget)
mi);
g_object_add_weak_pointer(G_OBJECT (label), (gpointer*)&pdata->label);
+ AtkObject *accessible = gtk_widget_get_accessible (widget);
+ if (accessible)
+ {
+ // Getting the accessible name of the Atk object retrieves the text
+ // of the menu item label, unless the application has set an alternate
+ // accessible name.
+ const gchar * label_text = gtk_label_get_text (GTK_LABEL (label));
+ const gchar * a11y_name = atk_object_get_name (accessible);
+ if (g_strcmp0 (a11y_name, label_text))
+ dbusmenu_menuitem_property_set (mi, "accessible-desc", a11y_name);
+
+ // An application may set an alternate accessible name in the future,
+ // so we had better watch out for it.
+ pdata->accessible = accessible;
+ g_signal_connect (G_OBJECT (accessible),
+ "accessible-name",
+ G_CALLBACK (a11y_name_notify_cb),
+ mi);
+ g_object_add_weak_pointer(G_OBJECT (accessible), (gpointer*)&pdata->accessible);
+ }
+
if (GTK_IS_ACTIVATABLE (widget))
{
GtkActivatable *activatable = GTK_ACTIVATABLE (widget);
@@ -948,6 +979,28 @@ action_notify_cb (GtkAction *action,
}
static void
+a11y_name_notify_cb (AtkObject *accessible,
+ GParamSpec *pspec,
+ gpointer data)
+{
+ DbusmenuMenuitem *item = (DbusmenuMenuitem *)data;
+ GtkWidget *widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
+ GtkWidget *label = find_menu_label (widget);
+ const gchar *label_text = gtk_label_get_text (GTK_LABEL (label));
+ const gchar *name = atk_object_get_name (accessible);
+
+ /* If an application sets the accessible name to NULL, then a subsequent
+ * call to get the accessible name from the Atk object should return the same
+ * string as the text of the menu item label, in which case, we want to clear
+ * the accessible description property of the dbusmenu item.
+ */
+ if (!g_strcmp0 (name, label_text))
+ dbusmenu_menuitem_property_set (item, "accessible-desc", NULL);
+ else
+ dbusmenu_menuitem_property_set (item, "accessible-desc", name);
+}
+
+static void
item_activated (DbusmenuMenuitem *item, guint timestamp, gpointer user_data)
{
GtkWidget *child;
diff --git a/libdbusmenu-gtk/parser.h b/libdbusmenu-gtk/parser.h
index 97fa9c6..191a8ac 100644
--- a/libdbusmenu-gtk/parser.h
+++ b/libdbusmenu-gtk/parser.h
@@ -31,6 +31,7 @@ License version 3 and version 2.1 along with this program. If not, see
#include <libdbusmenu-glib/menuitem.h>
#include <gtk/gtk.h>
+#include <atk/atk.h>
G_BEGIN_DECLS