1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193 | /* CTK+ - accessibility implementations
* 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 <ctk/ctk.h>
#include "ctkscrolledwindowaccessible.h"
G_DEFINE_TYPE (CtkScrolledWindowAccessible, ctk_scrolled_window_accessible, CTK_TYPE_CONTAINER_ACCESSIBLE)
static void
visibility_changed (GObject *object,
GParamSpec *pspec,
gpointer user_data)
{
if (!g_strcmp0 (pspec->name, "visible"))
{
gint index;
gint n_children;
gboolean child_added = FALSE;
GList *children;
AtkObject *child;
CtkWidget *widget;
CtkScrolledWindow *scrolled_window;
CtkWidget *hscrollbar, *vscrollbar;
CtkAccessible *accessible = CTK_ACCESSIBLE (user_data);
widget = ctk_accessible_get_widget (user_data);
if (widget == NULL)
return;
scrolled_window = CTK_SCROLLED_WINDOW (widget);
children = ctk_container_get_children (CTK_CONTAINER (widget));
index = n_children = g_list_length (children);
g_list_free (children);
hscrollbar = ctk_scrolled_window_get_hscrollbar (scrolled_window);
vscrollbar = ctk_scrolled_window_get_vscrollbar (scrolled_window);
if ((gpointer) object == (gpointer) (hscrollbar))
{
if (ctk_scrolled_window_get_hscrollbar (scrolled_window))
child_added = TRUE;
child = ctk_widget_get_accessible (hscrollbar);
}
else if ((gpointer) object == (gpointer) (vscrollbar))
{
if (ctk_scrolled_window_get_vscrollbar (scrolled_window))
child_added = TRUE;
child = ctk_widget_get_accessible (vscrollbar);
if (ctk_scrolled_window_get_hscrollbar (scrolled_window))
index = n_children + 1;
}
else
{
g_assert_not_reached ();
return;
}
if (child_added)
g_signal_emit_by_name (accessible, "children-changed::add", index, child, NULL);
else
g_signal_emit_by_name (accessible, "children-changed::remove", index, child, NULL);
}
}
static void
ctk_scrolled_window_accessible_initialize (AtkObject *obj,
gpointer data)
{
CtkScrolledWindow *window;
ATK_OBJECT_CLASS (ctk_scrolled_window_accessible_parent_class)->initialize (obj, data);
window = CTK_SCROLLED_WINDOW (data);
g_signal_connect_object (ctk_scrolled_window_get_hscrollbar (window), "notify::visible",
G_CALLBACK (visibility_changed),
obj, 0);
g_signal_connect_object (ctk_scrolled_window_get_vscrollbar (window), "notify::visible",
G_CALLBACK (visibility_changed),
obj, 0);
obj->role = ATK_ROLE_SCROLL_PANE;
}
static gint
ctk_scrolled_window_accessible_get_n_children (AtkObject *object)
{
CtkWidget *widget;
CtkScrolledWindow *scrolled_window;
GList *children;
gint n_children;
widget = ctk_accessible_get_widget (CTK_ACCESSIBLE (object));
if (widget == NULL)
return 0;
scrolled_window = CTK_SCROLLED_WINDOW (widget);
children = ctk_container_get_children (CTK_CONTAINER (widget));
n_children = g_list_length (children);
g_list_free (children);
if (ctk_scrolled_window_get_hscrollbar (scrolled_window))
n_children++;
if (ctk_scrolled_window_get_vscrollbar (scrolled_window))
n_children++;
return n_children;
}
static AtkObject *
ctk_scrolled_window_accessible_ref_child (AtkObject *obj,
gint child)
{
CtkWidget *widget;
CtkScrolledWindow *scrolled_window;
CtkWidget *hscrollbar, *vscrollbar;
GList *children, *tmp_list;<--- The scope of the variable 'tmp_list' can be reduced. [+]The scope of the variable 'tmp_list' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
gint n_children;
AtkObject *accessible = NULL;
g_return_val_if_fail (child >= 0, NULL);
widget = ctk_accessible_get_widget (CTK_ACCESSIBLE (obj));
if (widget == NULL)
return NULL;
scrolled_window = CTK_SCROLLED_WINDOW (widget);
hscrollbar = ctk_scrolled_window_get_hscrollbar (scrolled_window);
vscrollbar = ctk_scrolled_window_get_vscrollbar (scrolled_window);
children = ctk_container_get_children (CTK_CONTAINER (widget));
n_children = g_list_length (children);
if (child == n_children)
{
if (ctk_scrolled_window_get_hscrollbar (scrolled_window))
accessible = ctk_widget_get_accessible (hscrollbar);
else if (ctk_scrolled_window_get_vscrollbar (scrolled_window))
accessible = ctk_widget_get_accessible (vscrollbar);
}
else if (child == n_children + 1 &&
ctk_scrolled_window_get_hscrollbar (scrolled_window) &&
ctk_scrolled_window_get_vscrollbar (scrolled_window))
accessible = ctk_widget_get_accessible (vscrollbar);
else if (child < n_children)
{
tmp_list = g_list_nth (children, child);
if (tmp_list)
accessible = ctk_widget_get_accessible (CTK_WIDGET (tmp_list->data));
}
g_list_free (children);
if (accessible)
g_object_ref (accessible);
return accessible;
}
static void
ctk_scrolled_window_accessible_class_init (CtkScrolledWindowAccessibleClass *klass)
{
AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
class->get_n_children = ctk_scrolled_window_accessible_get_n_children;
class->ref_child = ctk_scrolled_window_accessible_ref_child;
class->initialize = ctk_scrolled_window_accessible_initialize;
}
static void
ctk_scrolled_window_accessible_init (CtkScrolledWindowAccessible *window G_GNUC_UNUSED)
{
}
|