778
vte_terminal_accessible_destroyed (GtkWidget *widget,
779
GtkAccessible *accessible)
781
gtk_accessible_set_widget (accessible, NULL);
782
atk_object_notify_state_change (ATK_OBJECT (accessible), ATK_STATE_DEFUNCT, TRUE);
786
focus_cb (GtkWidget *widget,
787
GdkEventFocus *event)
789
AtkObject* accessible;
793
accessible = gtk_widget_get_accessible (widget);
795
atk_object_notify_state_change (accessible, ATK_STATE_FOCUSED, event->in);
800
notify_cb (GObject *obj,
803
GtkWidget* widget = GTK_WIDGET (obj);
804
AtkObject* atk_obj = gtk_widget_get_accessible (widget);
808
if (strcmp (pspec->name, "has-focus") == 0)
810
* We use focus-in-event and focus-out-event signals to catch
811
* focus changes so we ignore this.
814
else if (strcmp (pspec->name, "visible") == 0) {
815
state = ATK_STATE_VISIBLE;
816
value = gtk_widget_get_visible (widget);
817
} else if (strcmp (pspec->name, "sensitive") == 0) {
818
state = ATK_STATE_SENSITIVE;
819
value = gtk_widget_get_sensitive (widget);
823
atk_object_notify_state_change (atk_obj, state, value);
824
if (state == ATK_STATE_SENSITIVE)
825
atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, value);
828
/* Translate GtkWidget::size-allocate to AtkComponent::bounds-changed */
830
size_allocate_cb (GtkWidget *widget,
831
GtkAllocation *allocation)
833
AtkObject* accessible;
836
accessible = gtk_widget_get_accessible (widget);
837
rect.x = allocation->x;
838
rect.y = allocation->y;
839
rect.width = allocation->width;
840
rect.height = allocation->height;
841
g_signal_emit_by_name (accessible, "bounds_changed", &rect);
844
/* Translate GtkWidget mapped state into AtkObject showing */
846
map_cb (GtkWidget *widget)
848
AtkObject *accessible;
850
accessible = gtk_widget_get_accessible (widget);
851
atk_object_notify_state_change (accessible, ATK_STATE_SHOWING,
852
gtk_widget_get_mapped (widget));
775
857
vte_terminal_initialize (AtkObject *obj, gpointer data)
777
859
VteTerminal *terminal;
1978
2103
action->get_keybinding = vte_terminal_accessible_action_get_keybinding;
1979
2104
action->set_description = vte_terminal_accessible_action_set_description;
2107
static const gchar *
2108
vte_terminal_accessible_get_description (AtkObject *accessible)
2112
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2116
if (accessible->description)
2117
return accessible->description;
2119
return gtk_widget_get_tooltip_text (widget);
2123
vte_terminal_accessible_get_parent (AtkObject *accessible)
2126
GtkWidget *widget, *parent_widget;
2128
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2132
parent = accessible->accessible_parent;
2136
parent_widget = gtk_widget_get_parent (widget);
2137
if (parent_widget == NULL)
2140
/* For a widget whose parent is a GtkNoteBook, we return the
2141
* accessible object corresponding the GtkNotebookPage containing
2142
* the widget as the accessible parent.
2144
if (GTK_IS_NOTEBOOK (parent_widget)) {
2147
GtkNotebook *notebook;
2150
notebook = GTK_NOTEBOOK (parent_widget);
2152
child = gtk_notebook_get_nth_page (notebook, page_num);
2155
if (child == widget) {
2156
parent = gtk_widget_get_accessible (parent_widget);
2157
parent = atk_object_ref_accessible_child (parent, page_num);
2158
g_object_unref (parent);
2164
parent = gtk_widget_get_accessible (parent_widget);
2169
vte_terminal_accessible_all_parents_visible (GtkWidget *widget)
2171
GtkWidget *iter_parent = NULL;
2172
gboolean result = TRUE;
2174
for (iter_parent = gtk_widget_get_parent (widget); iter_parent;
2175
iter_parent = gtk_widget_get_parent (iter_parent)) {
2176
if (!gtk_widget_get_visible (iter_parent)) {
2186
vte_terminal_accessible_on_screen (GtkWidget *widget)
2188
GtkAllocation allocation;
2189
GtkWidget *viewport;
2190
gboolean return_value;
2192
gtk_widget_get_allocation (widget, &allocation);
2194
viewport = gtk_widget_get_ancestor (widget, GTK_TYPE_VIEWPORT);
2196
GtkAllocation viewport_allocation;
2197
GtkAdjustment *adjustment;
2198
GdkRectangle visible_rect;
2200
gtk_widget_get_allocation (viewport, &viewport_allocation);
2202
#if GTK_CHECK_VERSION (3, 0, 0)
2203
adjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (viewport));
2204
visible_rect.y = gtk_adjustment_get_value (adjustment);
2205
adjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (viewport));
2207
adjustment = gtk_viewport_get_vadjustment (viewport);
2208
visible_rect.y = gtk_adjustment_get_value (adjustment);
2209
adjustment = gtk_viewport_get_hadjustment (viewport);
2211
visible_rect.x = gtk_adjustment_get_value (adjustment);
2212
visible_rect.width = viewport_allocation.width;
2213
visible_rect.height = viewport_allocation.height;
2215
if (((allocation.x + allocation.width) < visible_rect.x) ||
2216
((allocation.y + allocation.height) < visible_rect.y) ||
2217
(allocation.x > (visible_rect.x + visible_rect.width)) ||
2218
(allocation.y > (visible_rect.y + visible_rect.height)))
2219
return_value = FALSE;
2221
return_value = TRUE;
2223
/* Check whether the widget has been placed off the screen.
2224
* The widget may be MAPPED as when toolbar items do not
2225
* fit on the toolbar.
2227
if (allocation.x + allocation.width <= 0 &&
2228
allocation.y + allocation.height <= 0)
2229
return_value = FALSE;
2231
return_value = TRUE;
2234
return return_value;
2237
static AtkStateSet *
2238
vte_terminal_accessible_ref_state_set (AtkObject *accessible)
2241
AtkStateSet *state_set;
2243
state_set = ATK_OBJECT_CLASS (vte_terminal_accessible_parent_class)->ref_state_set (accessible);
2245
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2247
atk_state_set_add_state (state_set, ATK_STATE_DEFUNCT);
2249
if (gtk_widget_is_sensitive (widget)) {
2250
atk_state_set_add_state (state_set, ATK_STATE_SENSITIVE);
2251
atk_state_set_add_state (state_set, ATK_STATE_ENABLED);
2254
if (gtk_widget_get_can_focus (widget)) {
2255
atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE);
2258
* We do not currently generate notifications when an ATK object
2259
* corresponding to a GtkWidget changes visibility by being scrolled
2260
* on or off the screen. The testcase for this is the main window
2261
* of the testgtk application in which a set of buttons in a GtkVBox
2262
* is in a scrolled window with a viewport.
2264
* To generate the notifications we would need to do the following:
2265
* 1) Find the GtkViewport among the ancestors of the objects
2266
* 2) Create an accessible for the viewport
2267
* 3) Connect to the value-changed signal on the viewport
2268
* 4) When the signal is received we need to traverse the children
2269
* of the viewport and check whether the children are visible or not
2270
* visible; we may want to restrict this to the widgets for which
2271
* accessible objects have been created.
2272
* 5) We probably need to store a variable on_screen in the
2273
* GtkWidgetAccessible data structure so we can determine whether
2274
* the value has changed.
2276
if (gtk_widget_get_visible (widget)) {
2277
atk_state_set_add_state (state_set, ATK_STATE_VISIBLE);
2278
if (vte_terminal_accessible_on_screen (widget) &&
2279
gtk_widget_get_mapped (widget) &&
2280
vte_terminal_accessible_all_parents_visible (widget))
2281
atk_state_set_add_state (state_set, ATK_STATE_SHOWING);
2284
if (gtk_widget_has_focus (widget)) {
2285
AtkObject *focus_obj;
2287
focus_obj = g_object_get_data (G_OBJECT (accessible), "gail-focus-object");
2288
if (focus_obj == NULL)
2289
atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
2292
if (gtk_widget_has_default (widget))
2293
atk_state_set_add_state (state_set, ATK_STATE_DEFAULT);
2299
vte_terminal_accessible_get_index_in_parent (AtkObject *accessible)
2302
GtkWidget *parent_widget;
2306
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2311
if (accessible->accessible_parent) {
2314
parent = accessible->accessible_parent;
2316
if (atk_object_get_role (parent) == ATK_ROLE_PAGE_TAB)
2320
gboolean found = FALSE;
2322
n_children = atk_object_get_n_accessible_children (parent);
2323
for (i = 0; i < n_children; i++) {
2326
child = atk_object_ref_accessible_child (parent, i);
2327
if (child == accessible)
2330
g_object_unref (child);
2337
if (!GTK_IS_WIDGET (widget))
2339
parent_widget = gtk_widget_get_parent (widget);
2340
if (!GTK_IS_CONTAINER (parent_widget))
2343
children = gtk_container_get_children (GTK_CONTAINER (parent_widget));
2345
index = g_list_index (children, widget);
2346
g_list_free (children);
2350
static AtkAttributeSet *
2351
vte_terminal_accessible_get_attributes (AtkObject *obj)
2353
AtkAttributeSet *attributes;
2354
AtkAttribute *toolkit;
2356
toolkit = g_new (AtkAttribute, 1);
2357
toolkit->name = g_strdup ("toolkit");
2358
toolkit->value = g_strdup ("gtk");
2360
attributes = g_slist_append (NULL, toolkit);
1982
vte_terminal_accessible_class_init(gpointer *klass)
2366
vte_terminal_accessible_class_init(VteTerminalAccessibleClass *klass)
1984
2368
GObjectClass *gobject_class;
1985
2369
AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
1991
2375
class->initialize = vte_terminal_initialize;
1992
2376
/* Override the finalize method. */
1993
2377
gobject_class->finalize = vte_terminal_accessible_finalize;
2379
/* everything below copied from gtkwidgetaccessible.c */
2380
class->get_description = vte_terminal_accessible_get_description;
2381
class->get_parent = vte_terminal_accessible_get_parent;
2382
class->ref_state_set = vte_terminal_accessible_ref_state_set;
2383
class->get_index_in_parent = vte_terminal_accessible_get_index_in_parent;
2384
class->get_attributes = vte_terminal_accessible_get_attributes;
1997
vte_terminal_accessible_get_type(void)
2388
vte_terminal_accessible_init (VteTerminalAccessible *terminal)
1999
static GType terminal_accessible_type = 0;
2001
if (G_UNLIKELY (terminal_accessible_type == 0)) {
2002
AtkRegistry *registry;
2003
AtkObjectFactory *factory;
2004
GType parent_type, parent_accessible_type;
2005
GTypeQuery type_info;
2007
GInterfaceInfo text = {
2008
vte_terminal_accessible_text_init,
2012
GInterfaceInfo component = {
2013
vte_terminal_accessible_component_init,
2017
GInterfaceInfo action = {
2018
vte_terminal_accessible_action_init,
2022
GTypeInfo terminal_accessible_info = {
2024
(GBaseInitFunc)NULL,
2025
(GBaseFinalizeFunc)NULL,
2027
(GClassInitFunc)vte_terminal_accessible_class_init,
2028
(GClassFinalizeFunc)NULL,
2029
(gconstpointer)NULL,
2033
(GInstanceInitFunc) NULL,
2035
(GTypeValueTable*)NULL,
2038
/* Find the Atk object used for the parent (GtkWidget) type. */
2039
parent_type = g_type_parent(VTE_TYPE_TERMINAL);
2040
factory = atk_registry_get_factory(atk_get_default_registry(),
2042
parent_accessible_type = atk_object_factory_get_accessible_type(factory);
2043
if (!g_type_is_a(parent_accessible_type, GTK_TYPE_ACCESSIBLE)) {
2045
g_warning("Accessibility (%s) is not derived from "
2046
"%s (GTK_MODULES=gail not set?), "
2047
"deriving from %s instead.\n",
2048
g_type_name(parent_accessible_type),
2049
g_type_name(GTK_TYPE_ACCESSIBLE),
2050
g_type_name(GTK_TYPE_ACCESSIBLE));
2053
parent_accessible_type = GTK_TYPE_ACCESSIBLE;
2056
/* Find the size of the parent type's objects. */
2057
g_type_query(parent_accessible_type, &type_info);
2058
terminal_accessible_info.class_size = type_info.class_size;
2059
terminal_accessible_info.instance_size = type_info.instance_size;
2060
/* Register the class with the GObject type system. */
2061
terminal_accessible_type = g_type_register_static(parent_accessible_type,
2062
"VteTerminalAccessible",
2063
&terminal_accessible_info,
2066
/* Add a text interface to this object class. */
2067
g_type_add_interface_static(terminal_accessible_type,
2070
/* Add a component interface to this object class. */
2071
g_type_add_interface_static(terminal_accessible_type,
2074
/* Add an action interface to this object class. */
2075
g_type_add_interface_static(terminal_accessible_type,
2079
/* Associate the terminal and its peer factory in the
2080
* Atk type registry. */
2081
registry = atk_get_default_registry();
2082
atk_registry_set_factory_type(registry,
2084
VTE_TYPE_TERMINAL_ACCESSIBLE_FACTORY);
2087
return terminal_accessible_type;
2392
G_DEFINE_TYPE_WITH_CODE (VteTerminalAccessible, vte_terminal_accessible, GTK_TYPE_ACCESSIBLE,
2393
G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT, vte_terminal_accessible_text_init)
2394
G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, vte_terminal_accessible_component_init)
2395
G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, vte_terminal_accessible_action_init))
2090
2397
/* Create an accessible peer for the object. */
2091
2398
static AtkObject *
2092
2399
vte_terminal_accessible_factory_create_accessible(GObject *obj)