mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-17 23:10:22 +00:00
Rename and clean up gailutil
This commit is contained in:
parent
651241b685
commit
4cd806ff0c
@ -4,6 +4,7 @@ noinst_LTLIBRARIES = libgtka11y.la
|
|||||||
|
|
||||||
gtka11y_c_sources = \
|
gtka11y_c_sources = \
|
||||||
gtkaccessibility.c \
|
gtkaccessibility.c \
|
||||||
|
gtkaccessibilityutil.c \
|
||||||
gtkarrowaccessible.c \
|
gtkarrowaccessible.c \
|
||||||
gtkbooleancellaccessible.c \
|
gtkbooleancellaccessible.c \
|
||||||
gtkbuttonaccessible.c \
|
gtkbuttonaccessible.c \
|
||||||
@ -49,7 +50,6 @@ gtka11y_c_sources = \
|
|||||||
gtktreeviewaccessible.c \
|
gtktreeviewaccessible.c \
|
||||||
gtkwidgetaccessible.c \
|
gtkwidgetaccessible.c \
|
||||||
gtkwindowaccessible.c \
|
gtkwindowaccessible.c \
|
||||||
gailutil.c \
|
|
||||||
gailmisc.c
|
gailmisc.c
|
||||||
|
|
||||||
gail_private_h_sources = \
|
gail_private_h_sources = \
|
||||||
@ -105,7 +105,7 @@ gail_private_h_sources = \
|
|||||||
gtktextviewaccessibleprivate.h \
|
gtktextviewaccessibleprivate.h \
|
||||||
gtkwidgetaccessibleprivate.h \
|
gtkwidgetaccessibleprivate.h \
|
||||||
gtkaccessibility.h \
|
gtkaccessibility.h \
|
||||||
gailutil.h \
|
gtkaccessibilityutil.h \
|
||||||
gailmisc.h
|
gailmisc.h
|
||||||
|
|
||||||
libgtka11y_la_SOURCES = \
|
libgtka11y_la_SOURCES = \
|
||||||
|
@ -1,373 +0,0 @@
|
|||||||
/* GTK+ - accessibility implementations
|
|
||||||
* Copyright 2011, F123 Consulting & Mais Diferenças
|
|
||||||
* Copyright 2001, 2002, 2003 Sun Microsystems Inc.
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <gtk/gtk.h>
|
|
||||||
#include "gailutil.h"
|
|
||||||
#include "gtktoplevelaccessible.h"
|
|
||||||
#include "gtkwindowaccessible.h"
|
|
||||||
|
|
||||||
static GSList *key_listener_list = NULL;
|
|
||||||
|
|
||||||
typedef struct _GailKeyEventInfo GailKeyEventInfo;
|
|
||||||
|
|
||||||
struct _GailKeyEventInfo
|
|
||||||
{
|
|
||||||
AtkKeyEventStruct *key_event;
|
|
||||||
gpointer func_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
state_event_watcher (GSignalInvocationHint *hint,
|
|
||||||
guint n_param_values,
|
|
||||||
const GValue *param_values,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
GObject *object;
|
|
||||||
GtkWidget *widget;
|
|
||||||
AtkObject *atk_obj;
|
|
||||||
AtkObject *parent;
|
|
||||||
GdkEventWindowState *event;
|
|
||||||
gchar *signal_name;
|
|
||||||
|
|
||||||
object = g_value_get_object (param_values + 0);
|
|
||||||
if (!GTK_IS_WINDOW (object))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
event = g_value_get_boxed (param_values + 1);
|
|
||||||
if (event->type == GDK_WINDOW_STATE)
|
|
||||||
return FALSE;
|
|
||||||
widget = GTK_WIDGET (object);
|
|
||||||
|
|
||||||
if (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED)
|
|
||||||
signal_name = "maximize";
|
|
||||||
else if (event->new_window_state & GDK_WINDOW_STATE_ICONIFIED)
|
|
||||||
signal_name = "minimize";
|
|
||||||
else if (event->new_window_state == 0)
|
|
||||||
signal_name = "restore";
|
|
||||||
else
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
atk_obj = gtk_widget_get_accessible (widget);
|
|
||||||
if (GTK_IS_WINDOW_ACCESSIBLE (atk_obj))
|
|
||||||
{
|
|
||||||
parent = atk_object_get_parent (atk_obj);
|
|
||||||
if (parent == atk_get_root ())
|
|
||||||
g_signal_emit_by_name (atk_obj, signal_name);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
configure_event_watcher (GSignalInvocationHint *hint,
|
|
||||||
guint n_param_values,
|
|
||||||
const GValue *param_values,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
GtkAllocation allocation;
|
|
||||||
GObject *object;
|
|
||||||
GtkWidget *widget;
|
|
||||||
AtkObject *atk_obj;
|
|
||||||
AtkObject *parent;
|
|
||||||
GdkEvent *event;
|
|
||||||
gchar *signal_name;
|
|
||||||
|
|
||||||
object = g_value_get_object (param_values + 0);
|
|
||||||
if (!GTK_IS_WINDOW (object))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
event = g_value_get_boxed (param_values + 1);
|
|
||||||
if (event->type != GDK_CONFIGURE)
|
|
||||||
return FALSE;
|
|
||||||
widget = GTK_WIDGET (object);
|
|
||||||
gtk_widget_get_allocation (widget, &allocation);
|
|
||||||
if (allocation.x == ((GdkEventConfigure *)event)->x &&
|
|
||||||
allocation.y == ((GdkEventConfigure *)event)->y &&
|
|
||||||
allocation.width == ((GdkEventConfigure *)event)->width &&
|
|
||||||
allocation.height == ((GdkEventConfigure *)event)->height)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
if (allocation.width != ((GdkEventConfigure *)event)->width ||
|
|
||||||
allocation.height != ((GdkEventConfigure *)event)->height)
|
|
||||||
signal_name = "resize";
|
|
||||||
else
|
|
||||||
signal_name = "move";
|
|
||||||
|
|
||||||
atk_obj = gtk_widget_get_accessible (widget);
|
|
||||||
if (GTK_IS_WINDOW_ACCESSIBLE (atk_obj))
|
|
||||||
{
|
|
||||||
parent = atk_object_get_parent (atk_obj);
|
|
||||||
if (parent == atk_get_root ())
|
|
||||||
g_signal_emit_by_name (atk_obj, signal_name);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
window_focus (GtkWidget *widget,
|
|
||||||
GdkEventFocus *event)
|
|
||||||
{
|
|
||||||
AtkObject *atk_obj;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
|
|
||||||
|
|
||||||
atk_obj = gtk_widget_get_accessible (widget);
|
|
||||||
g_signal_emit_by_name (atk_obj, event->in ? "activate" : "deactivate");
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
window_added (AtkObject *atk_obj,
|
|
||||||
guint index,
|
|
||||||
AtkObject *child)
|
|
||||||
{
|
|
||||||
GtkWidget *widget;
|
|
||||||
|
|
||||||
if (!GTK_IS_WINDOW_ACCESSIBLE (child))
|
|
||||||
return;
|
|
||||||
|
|
||||||
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (child));
|
|
||||||
if (!widget)
|
|
||||||
return;
|
|
||||||
|
|
||||||
g_signal_connect (widget, "focus-in-event", (GCallback) window_focus, NULL);
|
|
||||||
g_signal_connect (widget, "focus-out-event", (GCallback) window_focus, NULL);
|
|
||||||
g_signal_emit_by_name (child, "create");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
window_removed (AtkObject *atk_obj,
|
|
||||||
guint index,
|
|
||||||
AtkObject *child)
|
|
||||||
{
|
|
||||||
GtkWidget *widget;
|
|
||||||
GtkWindow *window;
|
|
||||||
|
|
||||||
if (!GTK_IS_WINDOW_ACCESSIBLE (child))
|
|
||||||
return;
|
|
||||||
|
|
||||||
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (child));
|
|
||||||
if (!widget)
|
|
||||||
return;
|
|
||||||
|
|
||||||
window = GTK_WINDOW (widget);
|
|
||||||
/*
|
|
||||||
* Deactivate window if it is still focused and we are removing it. This
|
|
||||||
* can happen when a dialog displayed by gok is removed.
|
|
||||||
*/
|
|
||||||
if (gtk_window_is_active (window) &&
|
|
||||||
gtk_window_has_toplevel_focus (window))
|
|
||||||
g_signal_emit_by_name (child, "deactivate");
|
|
||||||
|
|
||||||
g_signal_handlers_disconnect_by_func (widget, (gpointer) window_focus, NULL);
|
|
||||||
g_signal_emit_by_name (child, "destroy");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
do_window_event_initialization (void)
|
|
||||||
{
|
|
||||||
AtkObject *root;
|
|
||||||
|
|
||||||
g_type_class_ref (GTK_TYPE_WINDOW_ACCESSIBLE);
|
|
||||||
g_signal_add_emission_hook (g_signal_lookup ("window-state-event", GTK_TYPE_WIDGET),
|
|
||||||
0, state_event_watcher, NULL, (GDestroyNotify) NULL);
|
|
||||||
g_signal_add_emission_hook (g_signal_lookup ("configure-event", GTK_TYPE_WIDGET),
|
|
||||||
0, configure_event_watcher, NULL, (GDestroyNotify) NULL);
|
|
||||||
|
|
||||||
root = atk_get_root ();
|
|
||||||
g_signal_connect (root, "children-changed::add",
|
|
||||||
(GCallback) window_added, NULL);
|
|
||||||
g_signal_connect (root, "children-changed::remove",
|
|
||||||
(GCallback) window_removed, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
undo_window_event_initialization (void)
|
|
||||||
{
|
|
||||||
AtkObject *root;
|
|
||||||
|
|
||||||
root = atk_get_root ();
|
|
||||||
|
|
||||||
g_signal_handlers_disconnect_by_func (root, (GCallback) window_added, NULL);
|
|
||||||
g_signal_handlers_disconnect_by_func (root, (GCallback) window_removed, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static AtkKeyEventStruct *
|
|
||||||
atk_key_event_from_gdk_event_key (GdkEventKey *key)
|
|
||||||
{
|
|
||||||
AtkKeyEventStruct *event = g_new0 (AtkKeyEventStruct, 1);
|
|
||||||
switch (key->type)
|
|
||||||
{
|
|
||||||
case GDK_KEY_PRESS:
|
|
||||||
event->type = ATK_KEY_EVENT_PRESS;
|
|
||||||
break;
|
|
||||||
case GDK_KEY_RELEASE:
|
|
||||||
event->type = ATK_KEY_EVENT_RELEASE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
g_assert_not_reached ();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
event->state = key->state;
|
|
||||||
event->keyval = key->keyval;
|
|
||||||
event->length = key->length;
|
|
||||||
if (key->string && key->string [0] &&
|
|
||||||
(key->state & GDK_CONTROL_MASK ||
|
|
||||||
g_unichar_isgraph (g_utf8_get_char (key->string))))
|
|
||||||
{
|
|
||||||
event->string = key->string;
|
|
||||||
}
|
|
||||||
else if (key->type == GDK_KEY_PRESS ||
|
|
||||||
key->type == GDK_KEY_RELEASE)
|
|
||||||
{
|
|
||||||
event->string = gdk_keyval_name (key->keyval);
|
|
||||||
}
|
|
||||||
event->keycode = key->hardware_keycode;
|
|
||||||
event->timestamp = key->time;
|
|
||||||
#ifdef GAIL_DEBUG
|
|
||||||
g_print ("GailKey:\tsym %u\n\tmods %x\n\tcode %u\n\ttime %lx\n",
|
|
||||||
(unsigned int) event->keyval,
|
|
||||||
(unsigned int) event->state,
|
|
||||||
(unsigned int) event->keycode,
|
|
||||||
(unsigned long int) event->timestamp);
|
|
||||||
#endif
|
|
||||||
return event;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
AtkKeySnoopFunc func;
|
|
||||||
gpointer data;
|
|
||||||
guint key;
|
|
||||||
} KeyEventListener;
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
_gail_util_key_snooper (GtkWidget *the_widget,
|
|
||||||
GdkEventKey *event)
|
|
||||||
{
|
|
||||||
GSList *l;
|
|
||||||
AtkKeyEventStruct *atk_event;
|
|
||||||
gboolean result;
|
|
||||||
|
|
||||||
atk_event = atk_key_event_from_gdk_event_key (event);
|
|
||||||
|
|
||||||
result = FALSE;
|
|
||||||
|
|
||||||
for (l = key_listener_list; l; l = l->next)
|
|
||||||
{
|
|
||||||
KeyEventListener *listener = l->data;
|
|
||||||
|
|
||||||
result |= listener->func (atk_event, listener->data);
|
|
||||||
}
|
|
||||||
g_free (atk_event);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static guint
|
|
||||||
gail_util_add_key_event_listener (AtkKeySnoopFunc listener_func,
|
|
||||||
gpointer listener_data)
|
|
||||||
{
|
|
||||||
static guint key = 0;
|
|
||||||
KeyEventListener *listener;
|
|
||||||
|
|
||||||
key++;
|
|
||||||
|
|
||||||
listener = g_slice_new0 (KeyEventListener);
|
|
||||||
listener->func = listener_func;
|
|
||||||
listener->data = listener_data;
|
|
||||||
listener->key = key;
|
|
||||||
|
|
||||||
key_listener_list = g_slist_append (key_listener_list, listener);
|
|
||||||
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gail_util_remove_key_event_listener (guint listener_key)
|
|
||||||
{
|
|
||||||
GSList *l;
|
|
||||||
|
|
||||||
for (l = key_listener_list; l; l = l->next)
|
|
||||||
{
|
|
||||||
KeyEventListener *listener = l->data;
|
|
||||||
|
|
||||||
if (listener->key == listener_key)
|
|
||||||
{
|
|
||||||
g_slice_free (KeyEventListener, listener);
|
|
||||||
key_listener_list = g_slist_delete_link (key_listener_list, l);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static AtkObject *
|
|
||||||
gail_util_get_root (void)
|
|
||||||
{
|
|
||||||
static AtkObject *root = NULL;
|
|
||||||
|
|
||||||
if (!root)
|
|
||||||
{
|
|
||||||
root = g_object_new (GTK_TYPE_TOPLEVEL_ACCESSIBLE, NULL);
|
|
||||||
atk_object_initialize (root, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
return root;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const gchar *
|
|
||||||
gail_util_get_toolkit_name (void)
|
|
||||||
{
|
|
||||||
return "gtk";
|
|
||||||
}
|
|
||||||
|
|
||||||
static const gchar *
|
|
||||||
gail_util_get_toolkit_version (void)
|
|
||||||
{
|
|
||||||
return GTK_VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
_gail_util_uninstall (void)
|
|
||||||
{
|
|
||||||
undo_window_event_initialization ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
_gail_util_install (void)
|
|
||||||
{
|
|
||||||
AtkUtilClass *atk_class = ATK_UTIL_CLASS (g_type_class_ref (ATK_TYPE_UTIL));
|
|
||||||
|
|
||||||
atk_class->add_key_event_listener = gail_util_add_key_event_listener;
|
|
||||||
atk_class->remove_key_event_listener = gail_util_remove_key_event_listener;
|
|
||||||
atk_class->get_root = gail_util_get_root;
|
|
||||||
atk_class->get_toolkit_name = gail_util_get_toolkit_name;
|
|
||||||
atk_class->get_toolkit_version = gail_util_get_toolkit_version;
|
|
||||||
|
|
||||||
do_window_event_initialization ();
|
|
||||||
}
|
|
@ -18,6 +18,8 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "gtkaccessibility.h"
|
#include "gtkaccessibility.h"
|
||||||
|
#include "gtkaccessibilityutil.h"
|
||||||
|
#include "gtkwindowaccessible.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -32,7 +34,6 @@
|
|||||||
#include <gtk/gtktogglebutton.h>
|
#include <gtk/gtktogglebutton.h>
|
||||||
#include <gtk/gtkcombobox.h>
|
#include <gtk/gtkcombobox.h>
|
||||||
#include <gtk/gtkaccessible.h>
|
#include <gtk/gtkaccessible.h>
|
||||||
#include "gailutil.h"
|
|
||||||
#include "gailmisc.h"
|
#include "gailmisc.h"
|
||||||
|
|
||||||
#ifdef GDK_WINDOWING_X11
|
#ifdef GDK_WINDOWING_X11
|
||||||
@ -797,6 +798,186 @@ gail_set_focus_object (AtkObject *focus_obj,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
state_event_watcher (GSignalInvocationHint *hint,
|
||||||
|
guint n_param_values,
|
||||||
|
const GValue *param_values,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
GObject *object;
|
||||||
|
GtkWidget *widget;
|
||||||
|
AtkObject *atk_obj;
|
||||||
|
AtkObject *parent;
|
||||||
|
GdkEventWindowState *event;
|
||||||
|
gchar *signal_name;
|
||||||
|
|
||||||
|
object = g_value_get_object (param_values + 0);
|
||||||
|
if (!GTK_IS_WINDOW (object))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
event = g_value_get_boxed (param_values + 1);
|
||||||
|
if (event->type == GDK_WINDOW_STATE)
|
||||||
|
return FALSE;
|
||||||
|
widget = GTK_WIDGET (object);
|
||||||
|
|
||||||
|
if (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED)
|
||||||
|
signal_name = "maximize";
|
||||||
|
else if (event->new_window_state & GDK_WINDOW_STATE_ICONIFIED)
|
||||||
|
signal_name = "minimize";
|
||||||
|
else if (event->new_window_state == 0)
|
||||||
|
signal_name = "restore";
|
||||||
|
else
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
atk_obj = gtk_widget_get_accessible (widget);
|
||||||
|
if (GTK_IS_WINDOW_ACCESSIBLE (atk_obj))
|
||||||
|
{
|
||||||
|
parent = atk_object_get_parent (atk_obj);
|
||||||
|
if (parent == atk_get_root ())
|
||||||
|
g_signal_emit_by_name (atk_obj, signal_name);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
configure_event_watcher (GSignalInvocationHint *hint,
|
||||||
|
guint n_param_values,
|
||||||
|
const GValue *param_values,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
GtkAllocation allocation;
|
||||||
|
GObject *object;
|
||||||
|
GtkWidget *widget;
|
||||||
|
AtkObject *atk_obj;
|
||||||
|
AtkObject *parent;
|
||||||
|
GdkEvent *event;
|
||||||
|
gchar *signal_name;
|
||||||
|
|
||||||
|
object = g_value_get_object (param_values + 0);
|
||||||
|
if (!GTK_IS_WINDOW (object))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
event = g_value_get_boxed (param_values + 1);
|
||||||
|
if (event->type != GDK_CONFIGURE)
|
||||||
|
return FALSE;
|
||||||
|
widget = GTK_WIDGET (object);
|
||||||
|
gtk_widget_get_allocation (widget, &allocation);
|
||||||
|
if (allocation.x == ((GdkEventConfigure *)event)->x &&
|
||||||
|
allocation.y == ((GdkEventConfigure *)event)->y &&
|
||||||
|
allocation.width == ((GdkEventConfigure *)event)->width &&
|
||||||
|
allocation.height == ((GdkEventConfigure *)event)->height)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
if (allocation.width != ((GdkEventConfigure *)event)->width ||
|
||||||
|
allocation.height != ((GdkEventConfigure *)event)->height)
|
||||||
|
signal_name = "resize";
|
||||||
|
else
|
||||||
|
signal_name = "move";
|
||||||
|
|
||||||
|
atk_obj = gtk_widget_get_accessible (widget);
|
||||||
|
if (GTK_IS_WINDOW_ACCESSIBLE (atk_obj))
|
||||||
|
{
|
||||||
|
parent = atk_object_get_parent (atk_obj);
|
||||||
|
if (parent == atk_get_root ())
|
||||||
|
g_signal_emit_by_name (atk_obj, signal_name);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
window_focus (GtkWidget *widget,
|
||||||
|
GdkEventFocus *event)
|
||||||
|
{
|
||||||
|
AtkObject *atk_obj;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
|
||||||
|
|
||||||
|
atk_obj = gtk_widget_get_accessible (widget);
|
||||||
|
g_signal_emit_by_name (atk_obj, event->in ? "activate" : "deactivate");
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
window_added (AtkObject *atk_obj,
|
||||||
|
guint index,
|
||||||
|
AtkObject *child)
|
||||||
|
{
|
||||||
|
GtkWidget *widget;
|
||||||
|
|
||||||
|
if (!GTK_IS_WINDOW_ACCESSIBLE (child))
|
||||||
|
return;
|
||||||
|
|
||||||
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (child));
|
||||||
|
if (!widget)
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_signal_connect (widget, "focus-in-event", (GCallback) window_focus, NULL);
|
||||||
|
g_signal_connect (widget, "focus-out-event", (GCallback) window_focus, NULL);
|
||||||
|
g_signal_emit_by_name (child, "create");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
window_removed (AtkObject *atk_obj,
|
||||||
|
guint index,
|
||||||
|
AtkObject *child)
|
||||||
|
{
|
||||||
|
GtkWidget *widget;
|
||||||
|
GtkWindow *window;
|
||||||
|
|
||||||
|
if (!GTK_IS_WINDOW_ACCESSIBLE (child))
|
||||||
|
return;
|
||||||
|
|
||||||
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (child));
|
||||||
|
if (!widget)
|
||||||
|
return;
|
||||||
|
|
||||||
|
window = GTK_WINDOW (widget);
|
||||||
|
/*
|
||||||
|
* Deactivate window if it is still focused and we are removing it. This
|
||||||
|
* can happen when a dialog displayed by gok is removed.
|
||||||
|
*/
|
||||||
|
if (gtk_window_is_active (window) && gtk_window_has_toplevel_focus (window))
|
||||||
|
g_signal_emit_by_name (child, "deactivate");
|
||||||
|
|
||||||
|
g_signal_handlers_disconnect_by_func (widget, (gpointer) window_focus, NULL);
|
||||||
|
g_signal_emit_by_name (child, "destroy");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
do_window_event_initialization (void)
|
||||||
|
{
|
||||||
|
AtkObject *root;
|
||||||
|
|
||||||
|
g_type_class_ref (GTK_TYPE_WINDOW_ACCESSIBLE);
|
||||||
|
g_signal_add_emission_hook (g_signal_lookup ("window-state-event", GTK_TYPE_WIDGET),
|
||||||
|
0, state_event_watcher, NULL, (GDestroyNotify) NULL);
|
||||||
|
g_signal_add_emission_hook (g_signal_lookup ("configure-event", GTK_TYPE_WIDGET),
|
||||||
|
0, configure_event_watcher, NULL, (GDestroyNotify) NULL);
|
||||||
|
|
||||||
|
root = atk_get_root ();
|
||||||
|
g_signal_connect (root, "children-changed::add", (GCallback) window_added, NULL);
|
||||||
|
g_signal_connect (root, "children-changed::remove", (GCallback) window_removed, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
undo_window_event_initialization (void)
|
||||||
|
{
|
||||||
|
AtkObject *root;
|
||||||
|
|
||||||
|
root = atk_get_root ();
|
||||||
|
|
||||||
|
g_signal_handlers_disconnect_by_func (root, (GCallback) window_added, NULL);
|
||||||
|
g_signal_handlers_disconnect_by_func (root, (GCallback) window_removed, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
_gtk_accessibility_shutdown (void)
|
_gtk_accessibility_shutdown (void)
|
||||||
{
|
{
|
||||||
@ -810,7 +991,8 @@ _gtk_accessibility_shutdown (void)
|
|||||||
#ifdef GDK_WINDOWING_X11
|
#ifdef GDK_WINDOWING_X11
|
||||||
atk_bridge_adaptor_cleanup ();
|
atk_bridge_adaptor_cleanup ();
|
||||||
#endif
|
#endif
|
||||||
_gail_util_uninstall ();
|
|
||||||
|
undo_window_event_initialization ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -825,7 +1007,9 @@ _gtk_accessibility_init (void)
|
|||||||
atk_focus_tracker_init (gail_focus_tracker_init);
|
atk_focus_tracker_init (gail_focus_tracker_init);
|
||||||
focus_tracker_id = atk_add_focus_tracker (gail_focus_tracker);
|
focus_tracker_id = atk_add_focus_tracker (gail_focus_tracker);
|
||||||
|
|
||||||
_gail_util_install ();
|
_gtk_accessibility_override_atk_util ();
|
||||||
|
do_window_event_initialization ();
|
||||||
|
|
||||||
#ifdef GDK_WINDOWING_X11
|
#ifdef GDK_WINDOWING_X11
|
||||||
atk_bridge_adaptor_init (NULL, NULL);
|
atk_bridge_adaptor_init (NULL, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,11 +19,15 @@
|
|||||||
#define __GTK_ACCESSIBILITY_H__
|
#define __GTK_ACCESSIBILITY_H__
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include "gtk/gtkwidget.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
void _gtk_accessibility_shutdown (void);
|
void _gtk_accessibility_shutdown (void);
|
||||||
void _gtk_accessibility_init (void);
|
void _gtk_accessibility_init (void);
|
||||||
|
|
||||||
|
gboolean _gtk_accessibility_key_snooper (GtkWidget *widget,
|
||||||
|
GdkEventKey *event);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
156
gtk/a11y/gtkaccessibilityutil.c
Normal file
156
gtk/a11y/gtkaccessibilityutil.c
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
/* GTK+ - accessibility implementations
|
||||||
|
* Copyright 2011, F123 Consulting & Mais Diferenças
|
||||||
|
* Copyright 2001, 2002, 2003 Sun Microsystems Inc.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include "gtkaccessibility.h"
|
||||||
|
#include "gtkaccessibilityutil.h"
|
||||||
|
#include "gtktoplevelaccessible.h"
|
||||||
|
|
||||||
|
static GSList *key_listener_list = NULL;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
AtkKeySnoopFunc func;
|
||||||
|
gpointer data;
|
||||||
|
guint key;
|
||||||
|
} KeyEventListener;
|
||||||
|
|
||||||
|
static guint
|
||||||
|
add_key_event_listener (AtkKeySnoopFunc listener_func,
|
||||||
|
gpointer listener_data)
|
||||||
|
{
|
||||||
|
static guint key = 0;
|
||||||
|
KeyEventListener *listener;
|
||||||
|
|
||||||
|
key++;
|
||||||
|
|
||||||
|
listener = g_slice_new0 (KeyEventListener);
|
||||||
|
listener->func = listener_func;
|
||||||
|
listener->data = listener_data;
|
||||||
|
listener->key = key;
|
||||||
|
|
||||||
|
key_listener_list = g_slist_append (key_listener_list, listener);
|
||||||
|
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
remove_key_event_listener (guint listener_key)
|
||||||
|
{
|
||||||
|
GSList *l;
|
||||||
|
|
||||||
|
for (l = key_listener_list; l; l = l->next)
|
||||||
|
{
|
||||||
|
KeyEventListener *listener = l->data;
|
||||||
|
|
||||||
|
if (listener->key == listener_key)
|
||||||
|
{
|
||||||
|
g_slice_free (KeyEventListener, listener);
|
||||||
|
key_listener_list = g_slist_delete_link (key_listener_list, l);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static AtkObject *
|
||||||
|
get_root (void)
|
||||||
|
{
|
||||||
|
static AtkObject *root = NULL;
|
||||||
|
|
||||||
|
if (!root)
|
||||||
|
{
|
||||||
|
root = g_object_new (GTK_TYPE_TOPLEVEL_ACCESSIBLE, NULL);
|
||||||
|
atk_object_initialize (root, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const gchar *
|
||||||
|
get_toolkit_name (void)
|
||||||
|
{
|
||||||
|
return "gtk";
|
||||||
|
}
|
||||||
|
|
||||||
|
static const gchar *
|
||||||
|
get_toolkit_version (void)
|
||||||
|
{
|
||||||
|
return GTK_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_gtk_accessibility_override_atk_util (void)
|
||||||
|
{
|
||||||
|
AtkUtilClass *atk_class = ATK_UTIL_CLASS (g_type_class_ref (ATK_TYPE_UTIL));
|
||||||
|
|
||||||
|
atk_class->add_key_event_listener = add_key_event_listener;
|
||||||
|
atk_class->remove_key_event_listener = remove_key_event_listener;
|
||||||
|
atk_class->get_root = get_root;
|
||||||
|
atk_class->get_toolkit_name = get_toolkit_name;
|
||||||
|
atk_class->get_toolkit_version = get_toolkit_version;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
atk_key_event_from_gdk_event_key (GdkEventKey *key,
|
||||||
|
AtkKeyEventStruct *event)
|
||||||
|
{
|
||||||
|
if (key->type == GDK_KEY_PRESS)
|
||||||
|
event->type = ATK_KEY_EVENT_PRESS;
|
||||||
|
else if (key->type == GDK_KEY_RELEASE)
|
||||||
|
event->type = ATK_KEY_EVENT_RELEASE;
|
||||||
|
else
|
||||||
|
g_assert_not_reached ();
|
||||||
|
|
||||||
|
event->state = key->state;
|
||||||
|
event->keyval = key->keyval;
|
||||||
|
event->length = key->length;
|
||||||
|
if (key->string && key->string[0] &&
|
||||||
|
(key->state & GDK_CONTROL_MASK ||
|
||||||
|
g_unichar_isgraph (g_utf8_get_char (key->string))))
|
||||||
|
event->string = key->string;
|
||||||
|
else
|
||||||
|
event->string = gdk_keyval_name (key->keyval);
|
||||||
|
|
||||||
|
event->keycode = key->hardware_keycode;
|
||||||
|
event->timestamp = key->time;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
_gtk_accessibility_key_snooper (GtkWidget *widget,
|
||||||
|
GdkEventKey *event)
|
||||||
|
{
|
||||||
|
GSList *l;
|
||||||
|
AtkKeyEventStruct atk_event;
|
||||||
|
gboolean result;
|
||||||
|
|
||||||
|
result = FALSE;
|
||||||
|
|
||||||
|
atk_key_event_from_gdk_event_key (event, &atk_event);
|
||||||
|
|
||||||
|
for (l = key_listener_list; l; l = l->next)
|
||||||
|
{
|
||||||
|
KeyEventListener *listener = l->data;
|
||||||
|
|
||||||
|
result |= listener->func (&atk_event, listener->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
@ -15,19 +15,15 @@
|
|||||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __GAIL_UTIL_H__
|
#ifndef __GTK_ACCESSIBILITY_UTIL_H__
|
||||||
#define __GAIL_UTIL_H__
|
#define __GTK_ACCESSIBILITY_UTIL_H__
|
||||||
|
|
||||||
#include <atk/atk.h>
|
#include <atk/atk.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
void _gail_util_install (void);
|
void _gtk_accessibility_override_atk_util (void);
|
||||||
void _gail_util_uninstall (void);
|
|
||||||
|
|
||||||
gboolean _gail_util_key_snooper (GtkWidget *the_widget,
|
|
||||||
GdkEventKey *event);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GAIL_UTIL_H__ */
|
#endif /* __GTK_ACCESSIBILITY_UTIL_H__ */
|
@ -129,7 +129,6 @@
|
|||||||
#include "gtkwindowprivate.h"
|
#include "gtkwindowprivate.h"
|
||||||
|
|
||||||
#include "a11y/gtkaccessibility.h"
|
#include "a11y/gtkaccessibility.h"
|
||||||
#include "a11y/gailutil.h"
|
|
||||||
|
|
||||||
/* Private type definitions
|
/* Private type definitions
|
||||||
*/
|
*/
|
||||||
@ -2241,7 +2240,7 @@ gtk_invoke_key_snoopers (GtkWidget *grab_widget,
|
|||||||
GSList *slist;
|
GSList *slist;
|
||||||
gint return_val = FALSE;
|
gint return_val = FALSE;
|
||||||
|
|
||||||
return_val = _gail_util_key_snooper (grab_widget, (GdkEventKey *) event);
|
return_val = _gtk_accessibility_key_snooper (grab_widget, (GdkEventKey *) event);
|
||||||
|
|
||||||
slist = key_snoopers;
|
slist = key_snoopers;
|
||||||
while (slist && !return_val)
|
while (slist && !return_val)
|
||||||
|
Loading…
Reference in New Issue
Block a user