Debian Codegraph @

gtk/a11y/gtkstackaccessible.c

raw
1 /* GTK+ - accessibility implementations
2 * Copyright (C) 2016 Timm Bäder <[email protected]>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "config.h"
19
20 #include <string.h>
21 #include <gtk/gtk.h>
22 #include "gtkstackaccessible.h"
23 #include "gtkwidgetprivate.h"
24
25
26 G_DEFINE_TYPE (GtkStackAccessible, gtk_stack_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE)
27
28 static AtkObject*
29 gtk_stack_accessible_ref_child (AtkObject *obj,
30 int i)
31 {
32 GtkWidget *stack = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
33 GtkWidget *visible_child;
34
35 if (stack == NULL)
36 return NULL;
37
38 if (i != 0)
39 return NULL;
40
41 visible_child = gtk_stack_get_visible_child (GTK_STACK (stack));
42
43 if (visible_child == NULL)
44 return NULL;
45
46 return g_object_ref (gtk_widget_get_accessible (visible_child));
47 }
48
49 static int
50 gtk_stack_accessible_get_n_children (AtkObject *obj)
51 {
52 GtkWidget *stack = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
53
54 if (stack == NULL)
55 return 0;
56
57 if (gtk_stack_get_visible_child (GTK_STACK (stack)))
58 return 1;
59
60 return 0;
61 }
62
63 static void
64 gtk_stack_accessible_class_init (GtkStackAccessibleClass *klass)
65 {
66 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
67 GtkContainerAccessibleClass *container_class = (GtkContainerAccessibleClass*)klass;
68
69 class->get_n_children = gtk_stack_accessible_get_n_children;
70 class->ref_child = gtk_stack_accessible_ref_child;
71 /*
72 * As we report the stack as having only the visible child,
73 * we are not interested in add and remove signals
74 */
75 container_class->add_gtk = NULL;
76 container_class->remove_gtk = NULL;
77 }
78
79 static void
80 gtk_stack_accessible_init (GtkStackAccessible *bar) {}
81
82
83 void
84 gtk_stack_accessible_update_visible_child (GtkStack *stack,
85 GtkWidget *old_visible_child,
86 GtkWidget *new_visible_child)
87 {
88 AtkObject *stack_accessible = _gtk_widget_peek_accessible (GTK_WIDGET (stack));
89
90 if (stack_accessible == NULL)
91 return;
92
93 if (old_visible_child)
94 {
95 AtkObject *accessible = gtk_widget_get_accessible (old_visible_child);
96 g_object_notify (G_OBJECT (accessible), "accessible-parent");
97 g_signal_emit_by_name (stack_accessible, "children-changed::remove", 0, accessible, NULL);
98 }
99
100 if (new_visible_child)
101 {
102 AtkObject *accessible = gtk_widget_get_accessible (new_visible_child);
103 g_object_notify (G_OBJECT (accessible), "accessible-parent");
104 g_signal_emit_by_name (stack_accessible, "children-changed::add", 0, accessible, NULL);
105 }
106 }
107
108
109