42
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2007 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 *******************************************************************************/
|
|
11 module dwt.accessibility.AccessibleObject;
|
|
12
|
|
13 import dwt.internal.accessibility.gtk.ATK;
|
|
14 import dwt.internal.gtk.OS;
|
|
15 import dwt.accessibility.Accessible;
|
|
16 import dwt.accessibility.AccessibleListener;
|
|
17 import dwt.accessibility.AccessibleControlListener;
|
|
18 import dwt.accessibility.AccessibleTextListener;
|
|
19 import dwt.accessibility.AccessibleEvent;
|
|
20 import dwt.accessibility.AccessibleControlEvent;
|
|
21 import dwt.accessibility.AccessibleTextEvent;
|
|
22 import dwt.accessibility.ACC;
|
|
23 import dwt.accessibility.AccessibleFactory;
|
|
24 import dwt.widgets.Display;
|
|
25 import dwt.dwthelper.Integer;
|
|
26 import tango.io.Stdout;
|
|
27 import tango.stdc.stringz;
|
|
28 import tango.text.Util;
|
|
29 import Math = tango.math.Math;
|
|
30
|
|
31 class AccessibleObject {
|
|
32 AtkObject* handle;
|
|
33 int /*long*/ parentType;
|
|
34 int index = -1, id = ACC.CHILDID_SELF;
|
|
35 Accessible accessible;
|
|
36 AccessibleObject parent;
|
|
37 AccessibleObject[AtkObject*] children;
|
|
38 /*
|
|
39 * a lightweight object does not correspond to a concrete gtk widget, but
|
|
40 * to a logical child of a widget (eg.- a CTabItem, which is simply drawn)
|
|
41 */
|
|
42 bool isLightweight = false;
|
|
43
|
|
44 static char[] actionNamePtr;
|
|
45 static char[] descriptionPtr;
|
|
46 static char[] keybindingPtr;
|
|
47 static char[] namePtr;
|
|
48 static AccessibleObject[AtkObject*] AccessibleObjects;
|
|
49 static const uint ATK_ACTION_TYPE;
|
|
50 static const uint ATK_COMPONENT_TYPE;
|
|
51 static const uint ATK_HYPERTEXT_TYPE;
|
|
52 static const uint ATK_SELECTION_TYPE;
|
|
53 static const uint ATK_TEXT_TYPE;
|
|
54 static const bool DEBUG;
|
|
55
|
|
56 static this(){
|
|
57 DEBUG = Display.DEBUG;
|
|
58 ATK_ACTION_TYPE = ATK.g_type_from_name ("AtkAction");
|
|
59 ATK_COMPONENT_TYPE = ATK.g_type_from_name ("AtkComponent");
|
|
60 ATK_HYPERTEXT_TYPE = ATK.g_type_from_name ("AtkHypertext");
|
|
61 ATK_SELECTION_TYPE = ATK.g_type_from_name ("AtkSelection");
|
|
62 ATK_TEXT_TYPE = ATK.g_type_from_name ("AtkText");
|
|
63 }
|
|
64
|
|
65 this (int /*long*/ type, GtkWidget* widget, Accessible accessible, int /*long*/ parentType, bool isLightweight) {
|
|
66 handle = cast(AtkObject*)ATK.g_object_new (type, null);
|
|
67 this.parentType = parentType;
|
|
68 ATK.atk_object_initialize (handle, widget);
|
|
69 this.accessible = accessible;
|
|
70 this.isLightweight = isLightweight;
|
|
71 AccessibleObjects[handle] = this;
|
|
72 if (DEBUG) Stdout.formatln("new AccessibleObject: {}", handle);
|
|
73 }
|
|
74
|
|
75 void addChild (AccessibleObject child) {
|
|
76 children[child.handle] = child;
|
|
77 child.setParent (this);
|
|
78 }
|
|
79
|
|
80 package static extern(C) char* atkAction_get_keybinding (void* obj, int index) {
|
|
81 auto atkObject = cast(AtkObject*)obj;
|
|
82 if (DEBUG) Stdout.formatln ("-->atkAction_get_keybinding");
|
|
83 AccessibleObject object = getAccessibleObject (atkObject);
|
|
84 if (object is null) return null;
|
|
85 char* parentResult;
|
|
86 if (ATK.g_type_is_a (object.parentType, ATK_ACTION_TYPE)) {
|
|
87 auto superType = cast(AtkActionIface*)ATK.g_type_interface_peek_parent (ATK.ATK_ACTION_GET_IFACE (object.handle));
|
|
88 AtkActionIface* actionIface = superType;
|
|
89 if (actionIface.get_keybinding !is null) {
|
|
90 parentResult = actionIface.get_keybinding( object.handle, index );
|
|
91 }
|
|
92 }
|
|
93 AccessibleListener[] listeners = object.getAccessibleListeners ();
|
|
94 if (listeners.length is 0) return parentResult;
|
|
95
|
|
96 AccessibleEvent event = new AccessibleEvent (object);
|
|
97 event.childID = object.id;
|
|
98 if (parentResult !is null) {
|
|
99 char[] res = fromUtf8z( parentResult );
|
|
100 event.result = res.dup;
|
|
101 }
|
|
102 for (int i = 0; i < listeners.length; i++) {
|
|
103 listeners [i].getKeyboardShortcut (event);
|
|
104 }
|
|
105 if (event.result is null) return parentResult;
|
|
106 if (keybindingPtr !is null ) OS.g_free (keybindingPtr.ptr);
|
|
107 char[] name = event.result.dup ~ \0;
|
|
108 char* p = cast(char*) OS.g_malloc (name.length);
|
|
109 keybindingPtr = p ? p[ 0 .. name.length ] : null;
|
|
110 return keybindingPtr.ptr;
|
|
111 }
|
|
112
|
|
113 package static extern(C) char* atkAction_get_name (void* obj, int index) {
|
|
114 auto atkObject = cast(AtkObject*)obj;
|
|
115 if (DEBUG) Stdout.formatln ("-->atkAction_get_name");
|
|
116 AccessibleObject object = getAccessibleObject (atkObject);
|
|
117 if (object is null) return null;
|
|
118 char* parentResult;
|
|
119 if (ATK.g_type_is_a (object.parentType, ATK_ACTION_TYPE)) {
|
|
120 auto actionIface = cast(AtkActionIface*)ATK.g_type_interface_peek_parent (ATK.ATK_ACTION_GET_IFACE (object.handle));
|
|
121 if (actionIface.get_name !is null) {
|
|
122 parentResult = actionIface.get_name( object.handle, index);
|
|
123 }
|
|
124 }
|
|
125 AccessibleControlListener[] listeners = object.getControlListeners ();
|
|
126 if (listeners.length is 0) return parentResult;
|
|
127
|
|
128 AccessibleControlEvent event = new AccessibleControlEvent (object);
|
|
129 event.childID = object.id;
|
|
130 if (parentResult !is null) {
|
|
131 char[] res = fromUtf8z( parentResult );
|
|
132 event.result = res.dup;
|
|
133 }
|
|
134 for (int i = 0; i < listeners.length; i++) {
|
|
135 listeners [i].getDefaultAction (event);
|
|
136 }
|
|
137 if (event.result is null) return parentResult;
|
|
138 if (actionNamePtr !is null) OS.g_free (actionNamePtr.ptr);
|
|
139
|
|
140 char[] name = event.result.dup ~ \0;
|
|
141 auto p = cast(char*)OS.g_malloc (name.length);
|
|
142 actionNamePtr = p ? p[ 0 .. name.length ] : null;
|
|
143 return actionNamePtr.ptr;
|
|
144 }
|
|
145
|
|
146 package static extern(C) void atkComponent_get_extents (void* obj, int* x, int* y, int* width, int* height, int coord_type) {
|
|
147 auto atkObject = cast(AtkObject*)obj;
|
|
148 if (DEBUG) Stdout.formatln ("-->atkComponent_get_extents");
|
|
149 AccessibleObject object = getAccessibleObject (atkObject);
|
|
150 if (object is null) return 0;
|
|
151 *x = 0;
|
|
152 *y = 0;
|
|
153 *width = 0;
|
|
154 *height = 0;
|
|
155 if (ATK.g_type_is_a (object.parentType, ATK_COMPONENT_TYPE)) {
|
|
156 auto componentIface = cast(AtkComponentIface*) ATK.g_type_interface_peek_parent (ATK.ATK_COMPONENT_GET_IFACE (object.handle));
|
|
157 if (componentIface.get_extents !is null) {
|
|
158 componentIface.get_extents( object.handle, x, y, width, height, coord_type);
|
|
159 }
|
|
160 }
|
|
161 AccessibleControlListener[] listeners = object.getControlListeners ();
|
|
162 if (listeners.length is 0) return 0;
|
|
163
|
|
164 int parentX = *x, parentY = *y;
|
|
165 int parentWidth = *width, parentHeight = *height;
|
|
166 AccessibleControlEvent event = new AccessibleControlEvent (object);
|
|
167 event.childID = object.id;
|
|
168 event.x = parentX; event.y = parentY;
|
|
169 event.width = parentWidth; event.height = parentHeight;
|
|
170 if (coord_type is ATK.ATK_XY_WINDOW) {
|
|
171 /* translate control -> display, for filling in event to be dispatched */
|
|
172 auto gtkAccessible = ATK.GTK_ACCESSIBLE (object.handle);
|
|
173 auto topLevel = ATK.gtk_widget_get_toplevel (gtkAccessible.widget);
|
|
174 auto window = OS.GTK_WIDGET_WINDOW (topLevel);
|
|
175 int topWindowX, topWindowY;
|
|
176 OS.gdk_window_get_origin (window, &topWindowX, &topWindowY);
|
|
177 event.x += topWindowX;
|
|
178 event.y += topWindowY;
|
|
179 }
|
|
180 for (int i = 0; i < listeners.length; i++) {
|
|
181 listeners [i].getLocation (event);
|
|
182 }
|
|
183 if (coord_type is ATK.ATK_XY_WINDOW) {
|
|
184 /* translate display -> control, for answering to the OS */
|
|
185 auto gtkAccessible = ATK.GTK_ACCESSIBLE (object.handle);
|
|
186 auto topLevel = ATK.gtk_widget_get_toplevel (gtkAccessible.widget);
|
|
187 auto window = OS.GTK_WIDGET_WINDOW (topLevel);
|
|
188 int topWindowX, topWindowY;
|
|
189 OS.gdk_window_get_origin (window, &topWindowX, &topWindowY);
|
|
190 event.x -= topWindowX;
|
|
191 event.y -= topWindowY;
|
|
192 }
|
|
193 *x = event.x;
|
|
194 *y = event.y;
|
|
195 *width = event.width;
|
|
196 *height = event.height;
|
|
197 //return 0;
|
|
198 }
|
|
199
|
|
200 package static extern(C) void atkComponent_get_position (void* obj, int* x, int* y, int coord_type) {
|
|
201 auto atkObject = cast(AtkObject*)obj;
|
|
202 if (DEBUG) Stdout.formatln ("-->atkComponent_get_position, object: {} x:{} y:{} coord:{}", atkObject, x, y, coord_type);
|
|
203 AccessibleObject object = getAccessibleObject (atkObject);
|
|
204 if (object is null) return 0;
|
|
205 *x=0;
|
|
206 *y=0;
|
|
207 if (ATK.g_type_is_a (object.parentType, ATK_COMPONENT_TYPE)) {
|
|
208 auto componentIface = cast(AtkComponentIface*)ATK.g_type_interface_peek_parent (ATK.ATK_COMPONENT_GET_IFACE (object.handle));
|
|
209 if (componentIface.get_extents !is null) {
|
|
210 componentIface.get_position( object.handle, x, y, coord_type);
|
|
211 }
|
|
212 }
|
|
213 AccessibleControlListener[] listeners = object.getControlListeners ();
|
|
214 if (listeners.length is 0) return 0;
|
|
215
|
|
216 int parentX, parentY;
|
|
217 parentX = *x;
|
|
218 parentY = *y;
|
|
219 AccessibleControlEvent event = new AccessibleControlEvent (object);
|
|
220 event.childID = object.id;
|
|
221 event.x = parentX; event.y = parentY;
|
|
222 if (coord_type is ATK.ATK_XY_WINDOW) {
|
|
223 /* translate control -> display, for filling in event to be dispatched */
|
|
224 auto gtkAccessible = ATK.GTK_ACCESSIBLE (object.handle);
|
|
225 auto topLevel = ATK.gtk_widget_get_toplevel (gtkAccessible.widget);
|
|
226 auto window = OS.GTK_WIDGET_WINDOW (topLevel);
|
|
227 int topWindowX, topWindowY;
|
|
228 OS.gdk_window_get_origin (window, &topWindowX, &topWindowY);
|
|
229 event.x += topWindowX;
|
|
230 event.y += topWindowY;
|
|
231 }
|
|
232 for (int i = 0; i < listeners.length; i++) {
|
|
233 listeners [i].getLocation (event);
|
|
234 }
|
|
235 if (coord_type is ATK.ATK_XY_WINDOW) {
|
|
236 /* translate display -> control, for answering to the OS */
|
|
237 auto gtkAccessible = ATK.GTK_ACCESSIBLE (object.handle);
|
|
238 auto topLevel = ATK.gtk_widget_get_toplevel (gtkAccessible.widget);
|
|
239 auto window = OS.GTK_WIDGET_WINDOW (topLevel);
|
|
240 int topWindowX, topWindowY;
|
|
241 OS.gdk_window_get_origin (window, &topWindowX, &topWindowY);
|
|
242 event.x -= topWindowX;
|
|
243 event.y -= topWindowY;
|
|
244 }
|
|
245 *x=event.x;
|
|
246 *y=event.y;
|
|
247 //return 0;
|
|
248 }
|
|
249
|
|
250 //PORTING_FIXME: what about the coord_type? componentIface.get_size( object.handle, width, height, coord_type);
|
|
251 //package static extern(C) void atkComponent_get_size (void* obj, int* width, int* height, int coord_type) {
|
|
252 package static extern(C) void atkComponent_get_size (void* obj, int* width, int* height) {
|
|
253 auto atkObject = cast(AtkObject*)obj;
|
|
254 if (DEBUG) Stdout.formatln ("-->atkComponent_get_size");
|
|
255 AccessibleObject object = getAccessibleObject (atkObject);
|
|
256 if (object is null) return 0;
|
|
257 *width=0;
|
|
258 *height=0;
|
|
259 if (ATK.g_type_is_a (object.parentType, ATK_COMPONENT_TYPE)) {
|
|
260 auto componentIface = cast(AtkComponentIface*)ATK.g_type_interface_peek_parent (ATK.ATK_COMPONENT_GET_IFACE (object.handle));
|
|
261 if (componentIface.get_extents !is null) {
|
|
262 //PORTING_FIXME: what about the coord_type? componentIface.get_size( object.handle, width, height, coord_type);
|
|
263 componentIface.get_size( object.handle, width, height);
|
|
264 }
|
|
265 }
|
|
266 AccessibleControlListener[] listeners = object.getControlListeners ();
|
|
267 if (listeners.length is 0) return 0;
|
|
268
|
|
269 int parentWidth, parentHeight;
|
|
270 parentWidth= *width;
|
|
271 parentHeight= *height;
|
|
272 AccessibleControlEvent event = new AccessibleControlEvent (object);
|
|
273 event.childID = object.id;
|
|
274 event.width = parentWidth; event.height = parentHeight;
|
|
275 for (int i = 0; i < listeners.length; i++) {
|
|
276 listeners [i].getLocation (event);
|
|
277 }
|
|
278 *width=event.width;
|
|
279 *height=event.height;
|
|
280 //return 0;
|
|
281 }
|
|
282
|
|
283 package static extern(C) AtkObject* atkComponent_ref_accessible_at_point (void* obj, int x, int y, int coord_type) {
|
|
284 auto atkObject = cast(AtkObject*)obj;
|
|
285 if (DEBUG) Stdout.formatln ("-->atkComponent_ref_accessible_at_point");
|
|
286 AccessibleObject object = getAccessibleObject (atkObject);
|
|
287 if (object is null) return null;
|
|
288 AtkObject* parentResult;
|
|
289 if (ATK.g_type_is_a (object.parentType, ATK_COMPONENT_TYPE)) {
|
|
290 auto componentIface = cast(AtkComponentIface*)ATK.g_type_interface_peek_parent (ATK.ATK_COMPONENT_GET_IFACE (object.handle));
|
|
291 if (componentIface.ref_accessible_at_point !is null) {
|
|
292 parentResult = componentIface.ref_accessible_at_point( object.handle, x, y, coord_type);
|
|
293 }
|
|
294 }
|
|
295 AccessibleControlListener[] listeners = object.getControlListeners ();
|
|
296 if (listeners.length is 0) return parentResult;
|
|
297
|
|
298 AccessibleControlEvent event = new AccessibleControlEvent (object);
|
|
299 event.childID = object.id;
|
|
300 event.x = x; event.y = y;
|
|
301 if (coord_type is ATK.ATK_XY_WINDOW) {
|
|
302 /* translate control -> display, for filling in the event to be dispatched */
|
|
303 auto gtkAccessible = ATK.GTK_ACCESSIBLE (object.handle);
|
|
304 auto topLevel = ATK.gtk_widget_get_toplevel (gtkAccessible.widget);
|
|
305 auto window = OS.GTK_WIDGET_WINDOW (topLevel);
|
|
306 int topWindowX, topWindowY;
|
|
307 OS.gdk_window_get_origin (window, &topWindowX, &topWindowY);
|
|
308 event.x += topWindowX;
|
|
309 event.y += topWindowY;
|
|
310 }
|
|
311 for (int i = 0; i < listeners.length; i++) {
|
|
312 listeners [i].getChildAtPoint (event);
|
|
313 }
|
|
314 if (event.childID is object.id) event.childID = ACC.CHILDID_SELF;
|
|
315 AccessibleObject accObj = object.getChildByID (event.childID);
|
|
316 if (accObj !is null) {
|
|
317 if (parentResult !is null) OS.g_object_unref (parentResult);
|
|
318 OS.g_object_ref (accObj.handle);
|
|
319 return accObj.handle;
|
|
320 }
|
|
321 return parentResult;
|
|
322 }
|
|
323
|
|
324 package static extern(C) AtkHyperlink* atkHypertext_get_link (void* obj, int link_index) {
|
|
325 auto atkObject = cast(AtkObject*)obj;
|
|
326 if (DEBUG) Stdout.formatln ("-->atkHypertext_get_link");
|
|
327 return null;
|
|
328 }
|
|
329
|
|
330 package static extern(C) int atkHypertext_get_n_links (void* obj) {
|
|
331 auto atkObject = cast(AtkObject*)obj;
|
|
332 if (DEBUG) Stdout.formatln ("-->atkHypertext_get_n_links");
|
|
333 return 0; /* read hyperlink's name */
|
|
334 }
|
|
335
|
|
336 package static extern(C) int atkHypertext_get_link_index (void* obj, int char_index) {
|
|
337 auto atkObject = cast(AtkObject*)obj;
|
|
338 if (DEBUG) Stdout.formatln ("-->atkHypertext_get_link_index");
|
|
339 return 0;
|
|
340 }
|
|
341
|
|
342 package static extern(C) char* atkObject_get_description (AtkObject* atkObject) {
|
|
343 if (DEBUG) Stdout.formatln ("-->atkObject_get_description");
|
|
344 AccessibleObject object = getAccessibleObject (atkObject);
|
|
345 if (object is null) return null;
|
|
346 char* parentResult;
|
|
347 auto objectClass = cast(AtkObjectClass*)ATK.g_type_class_peek (object.parentType);
|
|
348 if (objectClass.get_description !is null) {
|
|
349 parentResult = objectClass.get_description(object.handle);
|
|
350 }
|
|
351 AccessibleListener[] listeners = object.getAccessibleListeners ();
|
|
352 if (listeners.length is 0) return parentResult;
|
|
353
|
|
354 AccessibleEvent event = new AccessibleEvent (object);
|
|
355 event.childID = object.id;
|
|
356 if (parentResult !is null) {
|
|
357 event.result = fromUtf8z( parentResult ).dup;
|
|
358 }
|
|
359 for (int i = 0; i < listeners.length; i++) {
|
|
360 listeners [i].getDescription (event);
|
|
361 }
|
|
362 if (event.result is null) return parentResult;
|
|
363 if (descriptionPtr !is null) OS.g_free (descriptionPtr.ptr);
|
|
364
|
|
365 char[] name = event.result.dup ~ \0;
|
|
366 char* p = cast(char*)OS.g_malloc (name.length);
|
|
367 descriptionPtr = p ? p[ 0 .. name.length ] : null;
|
|
368 return descriptionPtr.ptr; }
|
|
369
|
|
370 package static extern(C) char* atkObject_get_name (AtkObject* atkObject) {
|
|
371 if (DEBUG) Stdout.formatln ("-->atkObject_get_name: {}", atkObject);
|
|
372 AccessibleObject object = getAccessibleObject (atkObject);
|
|
373 if (object is null) return null;
|
|
374 char* parentResult;
|
|
375 auto objectClass = cast(AtkObjectClass*)ATK.g_type_class_peek (object.parentType);
|
|
376 if (objectClass.get_name !is null) {
|
|
377 parentResult = objectClass.get_name( object.handle);
|
|
378 }
|
|
379 AccessibleListener[] listeners = object.getAccessibleListeners ();
|
|
380 if (listeners.length is 0) return parentResult;
|
|
381
|
|
382 AccessibleEvent event = new AccessibleEvent (object);
|
|
383 event.childID = object.id;
|
|
384 if (parentResult !is null) {
|
|
385 event.result = fromUtf8z( parentResult ).dup;
|
|
386 }
|
|
387 for (int i = 0; i < listeners.length; i++) {
|
|
388 listeners [i].getName (event);
|
|
389 }
|
|
390 if (event.result is null) return parentResult;
|
|
391 if (namePtr !is null) OS.g_free (namePtr.ptr);
|
|
392 char[] name = event.result.dup ~ \0;
|
|
393 char* p = cast(char*)OS.g_malloc (name.length);
|
|
394 namePtr = p ? p[ 0 .. name.length ] : null;
|
|
395 return namePtr.ptr;
|
|
396 }
|
|
397
|
|
398 package static extern(C) int atkObject_get_n_children (AtkObject* atkObject) {
|
|
399 if (DEBUG) Stdout.formatln ("-->atkObject_get_n_children: {}", atkObject);
|
|
400 AccessibleObject object = getAccessibleObject (atkObject);
|
|
401 if (object is null) return 0;
|
|
402 int /*long*/ parentResult = 0;
|
|
403 auto objectClass = cast(AtkObjectClass*)ATK.g_type_class_peek (object.parentType);
|
|
404 if (objectClass.get_n_children !is null) {
|
|
405 parentResult = objectClass.get_n_children( object.handle);
|
|
406 }
|
|
407 AccessibleControlListener[] listeners = object.getControlListeners ();
|
|
408 if (listeners.length is 0) return parentResult;
|
|
409
|
|
410 AccessibleControlEvent event = new AccessibleControlEvent (object);
|
|
411 event.childID = object.id;
|
|
412 event.detail = cast(int)/*64*/parentResult;
|
|
413 for (int i = 0; i < listeners.length; i++) {
|
|
414 listeners [i].getChildCount (event);
|
|
415 }
|
|
416 return event.detail;
|
|
417 }
|
|
418
|
|
419 package static extern(C) int atkObject_get_index_in_parent (AtkObject* atkObject) {
|
|
420 if (DEBUG) Stdout.formatln ("-->atkObjectCB_get_index_in_parent. ");
|
|
421 AccessibleObject object = getAccessibleObject (atkObject);
|
|
422 if (object is null) return 0;
|
|
423 if (object.index !is -1) return object.index;
|
|
424 auto objectClass = cast(AtkObjectClass*)ATK.g_type_class_peek (object.parentType);
|
|
425 if (objectClass.get_index_in_parent is null) return 0;
|
|
426 return objectClass.get_index_in_parent(object. handle);
|
|
427 }
|
|
428
|
|
429 package static extern(C) AtkObject* atkObject_get_parent (AtkObject* atkObject) {
|
|
430 if (DEBUG) Stdout.formatln ("-->atkObject_get_parent: {}", atkObject);
|
|
431 AccessibleObject object = getAccessibleObject (atkObject);
|
|
432 if (object is null) return null;
|
|
433 if (object.parent !is null) return object.parent.handle;
|
|
434 auto objectClass = cast(AtkObjectClass*)ATK.g_type_class_peek (object.parentType);
|
|
435 if (objectClass.get_parent is null) return null;
|
|
436 return objectClass.get_parent( object.handle);
|
|
437 }
|
|
438
|
|
439 package static extern(C) int atkObject_get_role (AtkObject* atkObject) {
|
|
440 if (DEBUG) Stdout.formatln ("-->atkObject_get_role: {}", atkObject);
|
|
441 AccessibleObject object = getAccessibleObject (atkObject);
|
|
442 if (object is null) return 0;
|
|
443 if (object.getAccessibleListeners ().length !is 0) {
|
|
444 AccessibleControlListener[] listeners = object.getControlListeners ();
|
|
445 AccessibleControlEvent event = new AccessibleControlEvent (object);
|
|
446 event.childID = object.id;
|
|
447 event.detail = -1;
|
|
448 for (int i = 0; i < listeners.length; i++) {
|
|
449 listeners [i].getRole (event);
|
|
450 }
|
|
451 if (event.detail !is -1) {
|
|
452 switch (event.detail) {
|
|
453 /* Convert from win32 role values to atk role values */
|
|
454 case ACC.ROLE_CHECKBUTTON: return ATK.ATK_ROLE_CHECK_BOX;
|
|
455 case ACC.ROLE_CLIENT_AREA: return ATK.ATK_ROLE_DRAWING_AREA;
|
|
456 case ACC.ROLE_COMBOBOX: return ATK.ATK_ROLE_COMBO_BOX;
|
|
457 case ACC.ROLE_DIALOG: return ATK.ATK_ROLE_DIALOG;
|
|
458 case ACC.ROLE_LABEL: return ATK.ATK_ROLE_LABEL;
|
|
459 case ACC.ROLE_LINK: return ATK.ATK_ROLE_TEXT;
|
|
460 case ACC.ROLE_LIST: return ATK.ATK_ROLE_LIST;
|
|
461 case ACC.ROLE_LISTITEM: return ATK.ATK_ROLE_LIST_ITEM;
|
|
462 case ACC.ROLE_MENU: return ATK.ATK_ROLE_MENU;
|
|
463 case ACC.ROLE_MENUBAR: return ATK.ATK_ROLE_MENU_BAR;
|
|
464 case ACC.ROLE_MENUITEM: return ATK.ATK_ROLE_MENU_ITEM;
|
|
465 case ACC.ROLE_PROGRESSBAR: return ATK.ATK_ROLE_PROGRESS_BAR;
|
|
466 case ACC.ROLE_PUSHBUTTON: return ATK.ATK_ROLE_PUSH_BUTTON;
|
|
467 case ACC.ROLE_SCROLLBAR: return ATK.ATK_ROLE_SCROLL_BAR;
|
|
468 case ACC.ROLE_SEPARATOR: return ATK.ATK_ROLE_SEPARATOR;
|
|
469 case ACC.ROLE_SLIDER: return ATK.ATK_ROLE_SLIDER;
|
|
470 case ACC.ROLE_TABLE: return ATK.ATK_ROLE_TABLE;
|
|
471 case ACC.ROLE_TABLECELL: return ATK.ATK_ROLE_TABLE_CELL;
|
|
472 case ACC.ROLE_TABLECOLUMNHEADER: return ATK.ATK_ROLE_TABLE_COLUMN_HEADER;
|
|
473 case ACC.ROLE_TABLEROWHEADER: return ATK.ATK_ROLE_TABLE_ROW_HEADER;
|
|
474 case ACC.ROLE_TABFOLDER: return ATK.ATK_ROLE_PAGE_TAB_LIST;
|
|
475 case ACC.ROLE_TABITEM: return ATK.ATK_ROLE_PAGE_TAB;
|
|
476 case ACC.ROLE_TEXT: return ATK.ATK_ROLE_TEXT;
|
|
477 case ACC.ROLE_TOOLBAR: return ATK.ATK_ROLE_TOOL_BAR;
|
|
478 case ACC.ROLE_TOOLTIP: return ATK.ATK_ROLE_TOOL_TIP;
|
|
479 case ACC.ROLE_TREE: return ATK.ATK_ROLE_TREE;
|
|
480 case ACC.ROLE_TREEITEM: return ATK.ATK_ROLE_LIST_ITEM;
|
|
481 case ACC.ROLE_RADIOBUTTON: return ATK.ATK_ROLE_RADIO_BUTTON;
|
|
482 case ACC.ROLE_WINDOW: return ATK.ATK_ROLE_WINDOW;
|
|
483 }
|
|
484 }
|
|
485 }
|
|
486 auto objectClass = cast(AtkObjectClass*)ATK.g_type_class_peek (object.parentType);
|
|
487 if (objectClass.get_role is null) return 0;
|
|
488 return objectClass.get_role( object.handle);
|
|
489 }
|
|
490
|
|
491 package static extern(C) AtkObject* atkObject_ref_child (AtkObject* atkObject, int /*long*/ index) {
|
|
492 if (DEBUG) Stdout.formatln ("-->atkObject_ref_child: {} of: {}", index, atkObject);
|
|
493 AccessibleObject object = getAccessibleObject (atkObject);
|
|
494 if (object is null) return null;
|
|
495 object.updateChildren ();
|
|
496 AccessibleObject accObject = object.getChildByIndex (cast(int)/*64*/index);
|
|
497 if (accObject !is null) {
|
|
498 OS.g_object_ref (accObject.handle);
|
|
499 return accObject.handle;
|
|
500 }
|
|
501 auto objectClass = cast(AtkObjectClass*)ATK.g_type_class_peek (object.parentType);
|
|
502 if (objectClass.ref_child is null) return null;
|
|
503 return objectClass.ref_child( object.handle, index);
|
|
504 }
|
|
505
|
|
506 package static extern(C) AtkStateSet * atkObject_ref_state_set (AtkObject* atkObject) {
|
|
507 if (DEBUG) Stdout.formatln ("-->atkObject_ref_state_set");
|
|
508 AccessibleObject object = getAccessibleObject (atkObject);
|
|
509 if (object is null) return null;
|
|
510 AtkStateSet* parentResult;
|
|
511 auto objectClass = cast(AtkObjectClass*)ATK.g_type_class_peek (object.parentType);
|
|
512 if (objectClass.ref_state_set !is null) {
|
|
513 parentResult = objectClass.ref_state_set( object.handle);
|
|
514 }
|
|
515 AccessibleControlListener[] listeners = object.getControlListeners ();
|
|
516 if (listeners.length is 0) return parentResult;
|
|
517
|
|
518 auto set = parentResult;
|
|
519 AccessibleControlEvent event = new AccessibleControlEvent (object);
|
|
520 event.childID = object.id;
|
|
521 event.detail = -1;
|
|
522 for (int i = 0; i < listeners.length; i++) {
|
|
523 listeners [i].getState (event);
|
|
524 }
|
|
525 if (event.detail !is -1) {
|
|
526 /* Convert from win32 state values to atk state values */
|
|
527 int state = event.detail;
|
|
528 if ((state & ACC.STATE_BUSY) !is 0) ATK.atk_state_set_add_state (set, ATK.ATK_STATE_BUSY);
|
|
529 if ((state & ACC.STATE_CHECKED) !is 0) ATK.atk_state_set_add_state (set, ATK.ATK_STATE_CHECKED);
|
|
530 if ((state & ACC.STATE_EXPANDED) !is 0) ATK.atk_state_set_add_state (set, ATK.ATK_STATE_EXPANDED);
|
|
531 if ((state & ACC.STATE_FOCUSABLE) !is 0) ATK.atk_state_set_add_state (set, ATK.ATK_STATE_FOCUSABLE);
|
|
532 if ((state & ACC.STATE_FOCUSED) !is 0) ATK.atk_state_set_add_state (set, ATK.ATK_STATE_FOCUSED);
|
|
533 if ((state & ACC.STATE_HOTTRACKED) !is 0) ATK.atk_state_set_add_state (set, ATK.ATK_STATE_ARMED);
|
|
534 if ((state & ACC.STATE_INVISIBLE) is 0) ATK.atk_state_set_add_state (set, ATK.ATK_STATE_VISIBLE);
|
|
535 if ((state & ACC.STATE_MULTISELECTABLE) !is 0) ATK.atk_state_set_add_state (set, ATK.ATK_STATE_MULTISELECTABLE);
|
|
536 if ((state & ACC.STATE_OFFSCREEN) is 0) ATK.atk_state_set_add_state (set, ATK.ATK_STATE_SHOWING);
|
|
537 if ((state & ACC.STATE_PRESSED) !is 0) ATK.atk_state_set_add_state (set, ATK.ATK_STATE_PRESSED);
|
|
538 if ((state & ACC.STATE_READONLY) is 0) ATK.atk_state_set_add_state (set, ATK.ATK_STATE_EDITABLE);
|
|
539 if ((state & ACC.STATE_SELECTABLE) !is 0) ATK.atk_state_set_add_state (set, ATK.ATK_STATE_SELECTABLE);
|
|
540 if ((state & ACC.STATE_SELECTED) !is 0) ATK.atk_state_set_add_state (set, ATK.ATK_STATE_SELECTED);
|
|
541 if ((state & ACC.STATE_SIZEABLE) !is 0) ATK.atk_state_set_add_state (set, ATK.ATK_STATE_RESIZABLE);
|
|
542 /* Note: STATE_COLLAPSED, STATE_LINKED and STATE_NORMAL have no ATK equivalents */
|
|
543 }
|
|
544 return set;
|
|
545 }
|
|
546
|
|
547 package static extern(C) int atkSelection_is_child_selected (void* obj, int index) {
|
|
548 auto atkObject = cast(AtkObject*)obj;
|
|
549 if (DEBUG) Stdout.formatln ("-->atkSelection_is_child_selected");
|
|
550 AccessibleObject object = getAccessibleObject (atkObject);
|
|
551 if (object is null) return 0;
|
|
552 int /*long*/ parentResult = 0;
|
|
553 if (ATK.g_type_is_a (object.parentType, ATK_SELECTION_TYPE)) {
|
|
554 auto selectionIface = cast(AtkSelectionIface*)ATK.g_type_interface_peek_parent (ATK.ATK_SELECTION_GET_IFACE (object.handle));
|
|
555 if (selectionIface.is_child_selected !is null) {
|
|
556 parentResult = selectionIface.is_child_selected( object.handle, index);
|
|
557 }
|
|
558 }
|
|
559 AccessibleControlListener[] listeners = object.getControlListeners ();
|
|
560 if (listeners.length is 0) return parentResult;
|
|
561
|
|
562 AccessibleControlEvent event = new AccessibleControlEvent (object);
|
|
563 event.childID = object.id;
|
|
564 for (int i = 0; i < listeners.length; i++) {
|
|
565 listeners [i].getSelection (event);
|
|
566 }
|
|
567 AccessibleObject accessibleObject = object.getChildByID (event.childID);
|
|
568 if (accessibleObject !is null) {
|
|
569 return accessibleObject.index is index ? 1 : 0;
|
|
570 }
|
|
571 return parentResult;
|
|
572 }
|
|
573
|
|
574 package static extern(C) AtkObject* atkSelection_ref_selection (void* obj, int index) {
|
|
575 auto atkObject = cast(AtkObject*)obj;
|
|
576 if (DEBUG) Stdout.formatln ("-->atkSelection_ref_selection");
|
|
577 AccessibleObject object = getAccessibleObject (atkObject);
|
|
578 if (object is null) return null;
|
|
579 AtkObject* parentResult;
|
|
580 if (ATK.g_type_is_a (object.parentType, ATK_SELECTION_TYPE)) {
|
|
581 auto selectionIface = cast(AtkSelectionIface*)ATK.g_type_interface_peek_parent (ATK.ATK_SELECTION_GET_IFACE (object.handle));
|
|
582 if (selectionIface.ref_selection !is null) {
|
|
583 parentResult = selectionIface.ref_selection( object.handle, index);
|
|
584 }
|
|
585 }
|
|
586 AccessibleControlListener[] listeners = object.getControlListeners ();
|
|
587 if (listeners.length is 0) return parentResult;
|
|
588
|
|
589 AccessibleControlEvent event = new AccessibleControlEvent (object);
|
|
590 event.childID = object.id;
|
|
591 for (int i = 0; i < listeners.length; i++) {
|
|
592 listeners [i].getSelection (event);
|
|
593 }
|
|
594 AccessibleObject accObj = object.getChildByID (event.childID);
|
|
595 if (accObj !is null) {
|
|
596 if (parentResult !is null) OS.g_object_unref (parentResult);
|
|
597 OS.g_object_ref (accObj.handle);
|
|
598 return accObj.handle;
|
|
599 }
|
|
600 return parentResult;
|
|
601 }
|
|
602
|
|
603 package static extern(C) int atkText_get_caret_offset (void* obj) {
|
|
604 auto atkObject = cast(AtkObject*)obj;
|
|
605 if (DEBUG) Stdout.formatln ("-->atkText_get_caret_offset");
|
|
606 AccessibleObject object = getAccessibleObject (atkObject);
|
|
607 if (object is null) return 0;
|
|
608 int /*long*/ parentResult = 0;
|
|
609 if (ATK.g_type_is_a (object.parentType, ATK_TEXT_TYPE)) {
|
|
610 auto textIface = cast(AtkTextIface*)ATK.g_type_interface_peek_parent (ATK.ATK_TEXT_GET_IFACE (object.handle));
|
|
611 if (textIface.get_caret_offset !is null) {
|
|
612 parentResult = textIface.get_caret_offset( object.handle);
|
|
613 }
|
|
614 }
|
|
615 AccessibleTextListener[] listeners = object.getTextListeners ();
|
|
616 if (listeners.length is 0) return parentResult;
|
|
617
|
|
618 AccessibleTextEvent event = new AccessibleTextEvent (object);
|
|
619 event.childID = object.id;
|
|
620 event.offset = cast(int)/*64*/parentResult;
|
|
621 for (int i = 0; i < listeners.length; i++) {
|
|
622 listeners [i].getCaretOffset (event);
|
|
623 }
|
|
624 return event.offset;
|
|
625 }
|
|
626
|
|
627 package static extern(C) uint atkText_get_character_at_offset (void* obj, int offset) {
|
|
628 auto atkObject = cast(AtkObject*)obj;
|
|
629 if (DEBUG) Stdout.formatln ("-->atkText_get_character_at_offset");
|
|
630 AccessibleObject object = getAccessibleObject (atkObject);
|
|
631 if (object is null) return 0;
|
|
632 char[] text = object.getText ();
|
|
633 if (text !is null) return text[cast(int)/*64*/offset ]; // TODO
|
|
634 if (ATK.g_type_is_a (object.parentType, ATK_TEXT_TYPE)) {
|
|
635 auto textIface = cast(AtkTextIface*)ATK.g_type_class_peek (object.parentType);
|
|
636 if (textIface.get_character_at_offset !is null) {
|
|
637 return textIface.get_character_at_offset( object.handle, offset);
|
|
638 }
|
|
639 }
|
|
640 return 0;
|
|
641 }
|
|
642
|
|
643 package static extern(C) int atkText_get_character_count (void* obj) {
|
|
644 auto atkObject = cast(AtkObject*)obj;
|
|
645 if (DEBUG) Stdout.formatln ("-->atkText_get_character_count");
|
|
646 AccessibleObject object = getAccessibleObject (atkObject);
|
|
647 if (object is null) return 0;
|
|
648 char[] text = object.getText ();
|
|
649 if (text !is null) return text.length;
|
|
650 if (ATK.g_type_is_a (object.parentType, ATK_TEXT_TYPE)) {
|
|
651 auto textIface = cast(AtkTextIface*)ATK.g_type_class_peek (object.parentType);
|
|
652 if (textIface.get_character_count !is null) {
|
|
653 return textIface.get_character_count( object.handle);
|
|
654 }
|
|
655 }
|
|
656 return 0;
|
|
657 }
|
|
658
|
|
659 package static extern(C) int atkText_get_n_selections (void* obj) {
|
|
660 auto atkObject = cast(AtkObject*)obj;
|
|
661 if (DEBUG) Stdout.formatln("-->atkText_get_n_selections");
|
|
662 AccessibleObject object = getAccessibleObject (atkObject);
|
|
663 if (object is null) return 0;
|
|
664 int /*long*/ parentResult = 0;
|
|
665 if (ATK.g_type_is_a (object.parentType, ATK_TEXT_TYPE)) {
|
|
666 auto textIface = cast(AtkTextIface*)ATK.g_type_interface_peek_parent (ATK.ATK_TEXT_GET_IFACE (object.handle));
|
|
667 if (textIface.get_n_selections !is null) {
|
|
668 parentResult = textIface.get_n_selections( object.handle);
|
|
669 }
|
|
670 }
|
|
671 AccessibleTextListener[] listeners = object.getTextListeners ();
|
|
672 if (listeners.length is 0) return parentResult;
|
|
673
|
|
674 AccessibleTextEvent event = new AccessibleTextEvent (object);
|
|
675 event.childID = object.id;
|
|
676 for (int i = 0; i < listeners.length; i++) {
|
|
677 listeners [i].getSelectionRange (event);
|
|
678 }
|
|
679 return event.length is 0 ? parentResult : 1;
|
|
680 }
|
|
681
|
|
682 package static extern(C) char* atkText_get_selection (void* obj, int selection_num, int* start_offset, int* end_offset) {
|
|
683 auto atkObject = cast(AtkObject*)obj;
|
|
684 if (DEBUG) Stdout.formatln ("-->atkText_get_selection");
|
|
685 AccessibleObject object = getAccessibleObject (atkObject);
|
|
686 if (object is null) return null;
|
|
687 *start_offset=0;
|
|
688 *end_offset=0;
|
|
689 if (ATK.g_type_is_a (object.parentType, ATK_TEXT_TYPE)) {
|
|
690 auto textIface = cast(AtkTextIface*)ATK.g_type_interface_peek_parent (ATK.ATK_TEXT_GET_IFACE (object.handle));
|
|
691 if (textIface.get_selection !is null) {
|
|
692 textIface.get_selection( object.handle, selection_num, start_offset, end_offset );
|
|
693 }
|
|
694 }
|
|
695 AccessibleTextListener[] listeners = object.getTextListeners ();
|
|
696 if (listeners.length is 0) return null;
|
|
697
|
|
698 AccessibleTextEvent event = new AccessibleTextEvent (object);
|
|
699 event.childID = object.id;
|
|
700 int parentStart;
|
|
701 int parentEnd;
|
|
702 parentStart= *start_offset;
|
|
703 parentEnd= *end_offset;
|
|
704 event.offset = parentStart;
|
|
705 event.length = parentEnd - parentStart;
|
|
706 for (int i = 0; i < listeners.length; i++) {
|
|
707 listeners [i].getSelectionRange (event);
|
|
708 }
|
|
709 *start_offset = event.offset;
|
|
710 *end_offset = event.offset + event.length;
|
|
711 return null;
|
|
712 }
|
|
713
|
|
714 package static extern(C) char* atkText_get_text (void* obj, int start_offset, int end_offset) {
|
|
715 auto atkObject = cast(AtkObject*)obj;
|
|
716 if (DEBUG) Stdout.formatln ("-->atkText_get_text: {},{}", start_offset, end_offset);
|
|
717 AccessibleObject object = getAccessibleObject (atkObject);
|
|
718 if (object is null) return null;
|
|
719 char[] text = object.getText ();
|
|
720 if (text.length > 0) {
|
|
721 if (end_offset is -1) {
|
|
722 end_offset = text.length ;
|
|
723 } else {
|
|
724 end_offset = Math.min (end_offset, text.length );
|
|
725 }
|
|
726 start_offset = Math.min (start_offset, end_offset);
|
|
727 text = text[ start_offset .. end_offset ];
|
|
728 auto result = cast(char*)OS.g_malloc (text.length+1);
|
|
729 result[ 0 .. text.length ] = text;
|
|
730 result[ text.length ] = '\0';
|
|
731 return result;
|
|
732 }
|
|
733 return null;
|
|
734 }
|
|
735
|
|
736 package static extern(C) char* atkText_get_text_after_offset (void* obj, int offset_value, int boundary_type, int* start_offset, int* end_offset) {
|
|
737 auto atkObject = cast(AtkObject*)obj;
|
|
738 if (DEBUG) Stdout.formatln ("-->atkText_get_text_after_offset");
|
|
739 AccessibleObject object = getAccessibleObject (atkObject);
|
|
740 if (object is null) return null;
|
|
741 int offset = cast(int)/*64*/offset_value;
|
|
742 char[] text = object.getText ();
|
|
743 if (text.length > 0) {
|
|
744 int length = text.length ;
|
|
745 offset = Math.min (offset, length - 1);
|
|
746 int startBounds = offset;
|
|
747 int endBounds = offset;
|
|
748 switch (cast(int)/*64*/boundary_type) {
|
|
749 case ATK.ATK_TEXT_BOUNDARY_CHAR: {
|
|
750 if (length > offset) endBounds++;
|
|
751 break;
|
|
752 }
|
|
753 case ATK.ATK_TEXT_BOUNDARY_WORD_START: {
|
|
754 int wordStart1 = nextIndexOfChar (text, " !?.\n", offset - 1);
|
|
755 if (wordStart1 is -1) {
|
|
756 startBounds = endBounds = length;
|
|
757 break;
|
|
758 }
|
|
759 wordStart1 = nextIndexOfNotChar (text, " !?.\n", wordStart1);
|
|
760 if (wordStart1 is length) {
|
|
761 startBounds = endBounds = length;
|
|
762 break;
|
|
763 }
|
|
764 startBounds = wordStart1;
|
|
765 int wordStart2 = nextIndexOfChar (text, " !?.\n", wordStart1);
|
|
766 if (wordStart2 is -1) {
|
|
767 endBounds = length;
|
|
768 break;
|
|
769 }
|
|
770 endBounds = nextIndexOfNotChar (text, " !?.\n", wordStart2);
|
|
771 break;
|
|
772 }
|
|
773 case ATK.ATK_TEXT_BOUNDARY_WORD_END: {
|
|
774 int previousWordEnd = previousIndexOfNotChar (text, " \n", offset);
|
|
775 if (previousWordEnd is -1 || previousWordEnd !is offset - 1) {
|
|
776 offset = nextIndexOfNotChar (text, " \n", offset);
|
|
777 }
|
|
778 if (offset is -1) {
|
|
779 startBounds = endBounds = length;
|
|
780 break;
|
|
781 }
|
|
782 int wordEnd1 = nextIndexOfChar (text, " !?.\n", cast(int)/*64*/offset);
|
|
783 if (wordEnd1 is -1) {
|
|
784 startBounds = endBounds = length;
|
|
785 break;
|
|
786 }
|
|
787 wordEnd1 = nextIndexOfNotChar (text, "!?.", wordEnd1);
|
|
788 if (wordEnd1 is length) {
|
|
789 startBounds = endBounds = length;
|
|
790 break;
|
|
791 }
|
|
792 startBounds = wordEnd1;
|
|
793 int wordEnd2 = nextIndexOfNotChar (text, " \n", wordEnd1);
|
|
794 if (wordEnd2 is length) {
|
|
795 startBounds = endBounds = length;
|
|
796 break;
|
|
797 }
|
|
798 wordEnd2 = nextIndexOfChar (text, " !?.\n", wordEnd2);
|
|
799 if (wordEnd2 is -1) {
|
|
800 endBounds = length;
|
|
801 break;
|
|
802 }
|
|
803 endBounds = nextIndexOfNotChar (text, "!?.", wordEnd2);
|
|
804 break;
|
|
805 }
|
|
806 case ATK.ATK_TEXT_BOUNDARY_SENTENCE_START: {
|
|
807 int previousSentenceEnd = previousIndexOfChar (text, "!?.", offset);
|
|
808 int previousText = previousIndexOfNotChar (text, " !?.\n", offset);
|
|
809 int sentenceStart1 = 0;
|
|
810 if (previousSentenceEnd >= previousText) {
|
|
811 sentenceStart1 = nextIndexOfNotChar (text, " !?.\n", offset);
|
|
812 } else {
|
|
813 sentenceStart1 = nextIndexOfChar (text, "!?.", offset);
|
|
814 if (sentenceStart1 is -1) {
|
|
815 startBounds = endBounds = length;
|
|
816 break;
|
|
817 }
|
|
818 sentenceStart1 = nextIndexOfNotChar (text, " !?.\n", sentenceStart1);
|
|
819 }
|
|
820 if (sentenceStart1 is length) {
|
|
821 startBounds = endBounds = length;
|
|
822 break;
|
|
823 }
|
|
824 startBounds = sentenceStart1;
|
|
825 int sentenceStart2 = nextIndexOfChar (text, "!?.", sentenceStart1);
|
|
826 if (sentenceStart2 is -1) {
|
|
827 endBounds = length;
|
|
828 break;
|
|
829 }
|
|
830 endBounds = nextIndexOfNotChar (text, " !?.\n", sentenceStart2);
|
|
831 break;
|
|
832 }
|
|
833 case ATK.ATK_TEXT_BOUNDARY_SENTENCE_END: {
|
|
834 int sentenceEnd1 = nextIndexOfChar (text, "!?.", offset);
|
|
835 if (sentenceEnd1 is -1) {
|
|
836 startBounds = endBounds = length;
|
|
837 break;
|
|
838 }
|
|
839 sentenceEnd1 = nextIndexOfNotChar (text, "!?.", sentenceEnd1);
|
|
840 if (sentenceEnd1 is length) {
|
|
841 startBounds = endBounds = length;
|
|
842 break;
|
|
843 }
|
|
844 startBounds = sentenceEnd1;
|
|
845 int sentenceEnd2 = nextIndexOfNotChar (text, " \n", sentenceEnd1);
|
|
846 if (sentenceEnd2 is length) {
|
|
847 startBounds = endBounds = length;
|
|
848 break;
|
|
849 }
|
|
850 sentenceEnd2 = nextIndexOfChar (text, "!?.", sentenceEnd2);
|
|
851 if (sentenceEnd2 is -1) {
|
|
852 endBounds = length;
|
|
853 break;
|
|
854 }
|
|
855 endBounds = nextIndexOfNotChar (text, "!?.", sentenceEnd2);
|
|
856 break;
|
|
857 }
|
|
858 case ATK.ATK_TEXT_BOUNDARY_LINE_START: {
|
|
859 int lineStart1 = locate( text, '\n' );
|
|
860 if( lineStart1 == text.length ) lineStart1 = -1;
|
|
861 if (lineStart1 is -1) {
|
|
862 startBounds = endBounds = length;
|
|
863 break;
|
|
864 }
|
|
865 lineStart1 = nextIndexOfNotChar (text, "\n", lineStart1);
|
|
866 if (lineStart1 is length) {
|
|
867 startBounds = endBounds = length;
|
|
868 break;
|
|
869 }
|
|
870 startBounds = lineStart1;
|
|
871 int lineStart2 = locate( text, '\n' );
|
|
872 if( lineStart2 == text.length ) lineStart2 = -1;
|
|
873 if (lineStart2 is -1) {
|
|
874 endBounds = length;
|
|
875 break;
|
|
876 }
|
|
877 lineStart2 = nextIndexOfNotChar (text, "\n", lineStart2);
|
|
878 endBounds = lineStart2;
|
|
879 break;
|
|
880 }
|
|
881 case ATK.ATK_TEXT_BOUNDARY_LINE_END: {
|
|
882 int lineEnd1 = nextIndexOfChar (text, "\n", offset);
|
|
883 if (lineEnd1 is -1) {
|
|
884 startBounds = endBounds = length;
|
|
885 break;
|
|
886 }
|
|
887 startBounds = lineEnd1;
|
|
888 if (startBounds is length) {
|
|
889 endBounds = length;
|
|
890 break;
|
|
891 }
|
|
892 int lineEnd2 = nextIndexOfChar (text, "\n", lineEnd1 + 1);
|
|
893 if (lineEnd2 is -1) {
|
|
894 endBounds = length;
|
|
895 break;
|
|
896 }
|
|
897 endBounds = lineEnd2;
|
|
898 break;
|
|
899 }
|
|
900 }
|
|
901 *start_offset=startBounds;
|
|
902 *end_offset=endBounds;
|
|
903 text = text[startBounds .. endBounds ];
|
|
904 auto result = cast(char*)OS.g_malloc (text.length+1);
|
|
905 result[ 0 .. text.length ] = text;
|
|
906 result[ text.length ] = '\0';
|
|
907 return result;
|
|
908 }
|
|
909 return null;
|
|
910 }
|
|
911
|
|
912 package static extern(C) char* atkText_get_text_at_offset (void* obj, int offset_value, int boundary_type, int* start_offset, int* end_offset) {
|
|
913 auto atkObject = cast(AtkObject*)obj;
|
|
914 if (DEBUG) Stdout.formatln ("-->atkText_get_text_at_offset: {} start: {} end: {}", offset_value, start_offset, end_offset);
|
|
915 AccessibleObject object = getAccessibleObject (atkObject);
|
|
916 if (object is null) return null;
|
|
917 int offset = offset_value;
|
|
918 char[] text = object.getText ();
|
|
919 if (text.length > 0) {
|
|
920 int length = text.length;
|
|
921 offset = Math.min (offset, length - 1);
|
|
922 int startBounds = offset;
|
|
923 int endBounds = offset;
|
|
924 switch (boundary_type) {
|
|
925 case ATK.ATK_TEXT_BOUNDARY_CHAR: {
|
|
926 if (length > offset) endBounds++;
|
|
927 break;
|
|
928 }
|
|
929 case ATK.ATK_TEXT_BOUNDARY_WORD_START: {
|
|
930 int wordStart1 = previousIndexOfNotChar (text, " !?.\n", offset);
|
|
931 if (wordStart1 is -1) {
|
|
932 startBounds = endBounds = 0;
|
|
933 break;
|
|
934 }
|
|
935 wordStart1 = previousIndexOfChar (text, " !?.\n", wordStart1) + 1;
|
|
936 if (wordStart1 is -1) {
|
|
937 startBounds = 0;
|
|
938 break;
|
|
939 }
|
|
940 startBounds = wordStart1;
|
|
941 int wordStart2 = nextIndexOfChar (text, " !?.\n", wordStart1);
|
|
942 endBounds = nextIndexOfNotChar (text, " !?.\n", wordStart2);
|
|
943 break;
|
|
944 }
|
|
945 case ATK.ATK_TEXT_BOUNDARY_WORD_END: {
|
|
946 int wordEnd1 = previousIndexOfNotChar (text, "!?.", offset + 1);
|
|
947 wordEnd1 = previousIndexOfChar (text, " !?.\n", wordEnd1);
|
|
948 wordEnd1 = previousIndexOfNotChar (text, " \n", wordEnd1 + 1);
|
|
949 if (wordEnd1 is -1) {
|
|
950 startBounds = endBounds = 0;
|
|
951 break;
|
|
952 }
|
|
953 startBounds = wordEnd1 + 1;
|
|
954 int wordEnd2 = nextIndexOfNotChar (text, " \n", startBounds);
|
|
955 if (wordEnd2 is length) {
|
|
956 endBounds = startBounds;
|
|
957 break;
|
|
958 }
|
|
959 wordEnd2 = nextIndexOfChar (text, " !?.\n", wordEnd2);
|
|
960 if (wordEnd2 is -1) {
|
|
961 endBounds = startBounds;
|
|
962 break;
|
|
963 }
|
|
964 endBounds = nextIndexOfNotChar (text, "!?.", wordEnd2);
|
|
965 break;
|
|
966 }
|
|
967 case ATK.ATK_TEXT_BOUNDARY_SENTENCE_START: {
|
|
968 int sentenceStart1 = previousIndexOfNotChar (text, " !?.\n", offset + 1);
|
|
969 if (sentenceStart1 is -1) {
|
|
970 startBounds = endBounds = 0;
|
|
971 break;
|
|
972 }
|
|
973 sentenceStart1 = previousIndexOfChar (text, "!?.", sentenceStart1) + 1;
|
|
974 startBounds = nextIndexOfNotChar (text, " \n", sentenceStart1);
|
|
975 int sentenceStart2 = nextIndexOfChar (text, "!?.", startBounds);
|
|
976 endBounds = nextIndexOfNotChar (text, " !?.\n", sentenceStart2);
|
|
977 break;
|
|
978 }
|
|
979 case ATK.ATK_TEXT_BOUNDARY_SENTENCE_END: {
|
|
980 int sentenceEnd1 = previousIndexOfNotChar (text, "!?.", offset + 1);
|
|
981 sentenceEnd1 = previousIndexOfChar (text, "!?.", sentenceEnd1);
|
|
982 sentenceEnd1 = previousIndexOfNotChar (text, " \n", sentenceEnd1 + 1);
|
|
983 if (sentenceEnd1 is -1) {
|
|
984 startBounds = endBounds = 0;
|
|
985 break;
|
|
986 }
|
|
987 startBounds = sentenceEnd1 + 1;
|
|
988 int sentenceEnd2 = nextIndexOfNotChar (text, " \n", startBounds);
|
|
989 if (sentenceEnd2 is length) {
|
|
990 endBounds = startBounds;
|
|
991 break;
|
|
992 }
|
|
993 sentenceEnd2 = nextIndexOfChar (text, "!?.", sentenceEnd2);
|
|
994 if (sentenceEnd2 is -1) {
|
|
995 endBounds = startBounds;
|
|
996 break;
|
|
997 }
|
|
998 endBounds = nextIndexOfNotChar (text, "!?.", sentenceEnd2);
|
|
999 break;
|
|
1000 }
|
|
1001 case ATK.ATK_TEXT_BOUNDARY_LINE_START: {
|
|
1002 startBounds = previousIndexOfChar (text, "\n", offset) + 1;
|
|
1003 int lineEnd2 = nextIndexOfChar (text, "\n", startBounds);
|
|
1004 if (lineEnd2 < length) lineEnd2++;
|
|
1005 endBounds = lineEnd2;
|
|
1006 break;
|
|
1007 }
|
|
1008 case ATK.ATK_TEXT_BOUNDARY_LINE_END: {
|
|
1009 int lineEnd1 = previousIndexOfChar (text, "\n", offset);
|
|
1010 if (lineEnd1 is -1) {
|
|
1011 startBounds = endBounds = 0;
|
|
1012 break;
|
|
1013 }
|
|
1014 startBounds = lineEnd1;
|
|
1015 endBounds = nextIndexOfChar (text, "\n", lineEnd1 + 1);
|
|
1016 }
|
|
1017 }
|
|
1018 *start_offset=startBounds;
|
|
1019 *end_offset=endBounds;
|
|
1020 text = text[startBounds .. endBounds];
|
|
1021 auto result = cast(char*) OS.g_malloc (text.length+1);
|
|
1022 result[ 0 .. text.length ] = text;
|
|
1023 result[ text.length ] = '\0';
|
|
1024 return result;
|
|
1025 }
|
|
1026 return null;
|
|
1027 }
|
|
1028
|
|
1029 package static extern(C) char* atkText_get_text_before_offset (void* obj, int offset_value, int boundary_type, int* start_offset, int* end_offset) {
|
|
1030 auto atkObject = cast(AtkObject*)obj;
|
|
1031 if (DEBUG) Stdout.formatln ("-->atkText_get_text_before_offset");
|
|
1032 AccessibleObject object = getAccessibleObject (atkObject);
|
|
1033 if (object is null) return null;
|
|
1034 int offset = offset_value;
|
|
1035 char[] text = object.getText ();
|
|
1036 if (text.length > 0) {
|
|
1037 int length = text.length;
|
|
1038 offset = Math.min (offset, length - 1);
|
|
1039 int startBounds = offset;
|
|
1040 int endBounds = offset;
|
|
1041 switch (boundary_type) {
|
|
1042 case ATK.ATK_TEXT_BOUNDARY_CHAR: {
|
|
1043 if (length >= offset && offset > 0) startBounds--;
|
|
1044 break;
|
|
1045 }
|
|
1046 case ATK.ATK_TEXT_BOUNDARY_WORD_START: {
|
|
1047 int wordStart1 = previousIndexOfChar (text, " !?.\n", offset - 1);
|
|
1048 if (wordStart1 is -1) {
|
|
1049 startBounds = endBounds = 0;
|
|
1050 break;
|
|
1051 }
|
|
1052 int wordStart2 = previousIndexOfNotChar (text, " !?.\n", wordStart1);
|
|
1053 if (wordStart2 is -1) {
|
|
1054 startBounds = endBounds = 0;
|
|
1055 break;
|
|
1056 }
|
|
1057 endBounds = wordStart1 + 1;
|
|
1058 startBounds = previousIndexOfChar (text, " !?.\n", wordStart2) + 1;
|
|
1059 break;
|
|
1060 }
|
|
1061 case ATK.ATK_TEXT_BOUNDARY_WORD_END: {
|
|
1062 int wordEnd1 =previousIndexOfChar (text, " !?.\n", offset);
|
|
1063 if (wordEnd1 is -1) {
|
|
1064 startBounds = endBounds = 0;
|
|
1065 break;
|
|
1066 }
|
|
1067 wordEnd1 = previousIndexOfNotChar (text, " \n", wordEnd1 + 1);
|
|
1068 if (wordEnd1 is -1) {
|
|
1069 startBounds = endBounds = 0;
|
|
1070 break;
|
|
1071 }
|
|
1072 endBounds = wordEnd1 + 1;
|
|
1073 int wordEnd2 = previousIndexOfNotChar (text, " !?.\n", endBounds);
|
|
1074 wordEnd2 = previousIndexOfChar (text, " !?.\n", wordEnd2);
|
|
1075 if (wordEnd2 is -1) {
|
|
1076 startBounds = 0;
|
|
1077 break;
|
|
1078 }
|
|
1079 startBounds = previousIndexOfNotChar (text, " \n", wordEnd2 + 1) + 1;
|
|
1080 break;
|
|
1081 }
|
|
1082 case ATK.ATK_TEXT_BOUNDARY_SENTENCE_START: {
|
|
1083 int sentenceStart1 = previousIndexOfChar (text, "!?.", offset);
|
|
1084 if (sentenceStart1 is -1) {
|
|
1085 startBounds = endBounds = 0;
|
|
1086 break;
|
|
1087 }
|
|
1088 int sentenceStart2 = previousIndexOfNotChar (text, "!?.", sentenceStart1);
|
|
1089 if (sentenceStart2 is -1) {
|
|
1090 startBounds = endBounds = 0;
|
|
1091 break;
|
|
1092 }
|
|
1093 endBounds = sentenceStart1 + 1;
|
|
1094 startBounds = previousIndexOfChar (text, "!?.", sentenceStart2) + 1;
|
|
1095 break;
|
|
1096 }
|
|
1097 case ATK.ATK_TEXT_BOUNDARY_SENTENCE_END: {
|
|
1098 int sentenceEnd1 = previousIndexOfChar (text, "!?.", offset);
|
|
1099 if (sentenceEnd1 is -1) {
|
|
1100 startBounds = endBounds = 0;
|
|
1101 break;
|
|
1102 }
|
|
1103 sentenceEnd1 = previousIndexOfNotChar (text, " \n", sentenceEnd1 + 1);
|
|
1104 if (sentenceEnd1 is -1) {
|
|
1105 startBounds = endBounds = 0;
|
|
1106 break;
|
|
1107 }
|
|
1108 endBounds = sentenceEnd1 + 1;
|
|
1109 int sentenceEnd2 = previousIndexOfNotChar (text, "!?.", endBounds);
|
|
1110 sentenceEnd2 = previousIndexOfChar (text, "!?.", sentenceEnd2);
|
|
1111 if (sentenceEnd2 is -1) {
|
|
1112 startBounds = 0;
|
|
1113 break;
|
|
1114 }
|
|
1115 startBounds = previousIndexOfNotChar (text, " \n", sentenceEnd2 + 1) + 1;
|
|
1116 break;
|
|
1117 }
|
|
1118 case ATK.ATK_TEXT_BOUNDARY_LINE_START: {
|
|
1119 int lineStart1 = previousIndexOfChar (text, "\n", offset);
|
|
1120 if (lineStart1 is -1) {
|
|
1121 startBounds = endBounds = 0;
|
|
1122 break;
|
|
1123 }
|
|
1124 endBounds = lineStart1 + 1;
|
|
1125 startBounds = previousIndexOfChar (text, "\n", lineStart1) + 1;
|
|
1126 break;
|
|
1127 }
|
|
1128 case ATK.ATK_TEXT_BOUNDARY_LINE_END: {
|
|
1129 int lineEnd1 = previousIndexOfChar (text, "\n", offset);
|
|
1130 if (lineEnd1 is -1) {
|
|
1131 startBounds = endBounds = 0;
|
|
1132 break;
|
|
1133 }
|
|
1134 endBounds = lineEnd1;
|
|
1135 startBounds = previousIndexOfChar (text, "\n", lineEnd1);
|
|
1136 if (startBounds is -1) startBounds = 0;
|
|
1137 break;
|
|
1138 }
|
|
1139 }
|
|
1140 *start_offset=startBounds;
|
|
1141 *end_offset=endBounds;
|
|
1142 text = text[startBounds .. endBounds];
|
|
1143 auto result = cast(char*)OS.g_malloc (text.length+1);
|
|
1144 result[ 0 .. text.length ] = text;
|
|
1145 result[ text.length ] = '\0';
|
|
1146 return result;
|
|
1147 }
|
|
1148 return null;
|
|
1149 }
|
|
1150
|
|
1151 AccessibleListener[] getAccessibleListeners () {
|
|
1152 if (accessible is null) return new AccessibleListener [0];
|
|
1153 AccessibleListener[] result = accessible.getAccessibleListeners ();
|
|
1154 return result !is null ? result : new AccessibleListener [0];
|
|
1155 }
|
|
1156
|
|
1157 static AccessibleObject getAccessibleObject (AtkObject* atkObject) {
|
|
1158 return AccessibleObjects[atkObject];
|
|
1159 }
|
|
1160
|
|
1161 AccessibleObject getChildByHandle (AtkObject* handle) {
|
|
1162 return children[handle];
|
|
1163 }
|
|
1164
|
|
1165 AccessibleObject getChildByID (int childId) {
|
|
1166 if (childId is ACC.CHILDID_SELF) return this;
|
|
1167 foreach( object; children ){
|
|
1168 if (object.id is childId) return object;
|
|
1169 }
|
|
1170 return null;
|
|
1171 }
|
|
1172
|
|
1173 AccessibleObject getChildByIndex (int childIndex) {
|
|
1174 foreach( object; children ){
|
|
1175 if (object.index is childIndex) return object;
|
|
1176 }
|
|
1177 return null;
|
|
1178 }
|
|
1179
|
|
1180 AccessibleControlListener[] getControlListeners () {
|
|
1181 if (accessible is null) return new AccessibleControlListener [0];
|
|
1182 AccessibleControlListener[] result = accessible.getControlListeners ();
|
|
1183 return result !is null ? result : new AccessibleControlListener [0];
|
|
1184 }
|
|
1185
|
|
1186 char[] getText () {
|
|
1187 char* parentResult;
|
|
1188 char[] parentText = ""; //$NON-NLS-1$
|
|
1189 if (ATK.g_type_is_a (parentType, ATK_TEXT_TYPE)) {
|
|
1190 auto textIface = cast(AtkTextIface*)ATK.g_type_interface_peek_parent (ATK.ATK_TEXT_GET_IFACE (handle));
|
|
1191 int /*long*/ characterCount = 0;
|
|
1192 if (textIface.get_character_count !is null) {
|
|
1193 characterCount = textIface.get_character_count( handle);
|
|
1194 }
|
|
1195 if (characterCount > 0 && textIface.get_text !is null) {
|
|
1196 parentResult = textIface.get_text( handle, 0, characterCount);
|
|
1197 if (parentResult !is null) {
|
|
1198 parentText = fromUtf8z( parentResult ).dup;
|
|
1199 }
|
|
1200 }
|
|
1201 }
|
|
1202 AccessibleControlListener[] controlListeners = getControlListeners ();
|
|
1203 if (controlListeners.length is 0) return parentText;
|
|
1204 AccessibleControlEvent event = new AccessibleControlEvent (this);
|
|
1205 event.childID = id;
|
|
1206 event.result = parentText;
|
|
1207 for (int i = 0; i < controlListeners.length; i++) {
|
|
1208 controlListeners [i].getValue (event);
|
|
1209 }
|
|
1210 return event.result;
|
|
1211 }
|
|
1212
|
|
1213 AccessibleTextListener[] getTextListeners () {
|
|
1214 if (accessible is null) return new AccessibleTextListener [0];
|
|
1215 AccessibleTextListener[] result = accessible.getTextListeners ();
|
|
1216 return result !is null ? result : new AccessibleTextListener [0];
|
|
1217 }
|
|
1218
|
|
1219 private static extern(C) void gObjectClass_finalize (GObject* atkObject) {
|
|
1220 auto superType = ATK.g_type_class_peek_parent (ATK.G_OBJECT_GET_CLASS (cast(GTypeInstance*)atkObject));
|
|
1221 auto objectClassStruct = cast(GObjectClass*)ATK.G_OBJECT_CLASS (cast(GTypeClass*)superType);
|
|
1222 objectClassStruct.finalize(atkObject);
|
|
1223 AccessibleObject object = getAccessibleObject (cast(AtkObject*)atkObject);
|
|
1224 if (object !is null) {
|
|
1225 AccessibleObjects.remove (cast(AtkObject*)atkObject);
|
|
1226 object.release ();
|
|
1227 }
|
|
1228 }
|
|
1229
|
|
1230 static int nextIndexOfChar (char[] string, char[] searchChars, int startIndex) {
|
|
1231 int result = string.length;
|
|
1232 for (int i = 0; i < searchChars.length; i++) {
|
|
1233 char current = searchChars[i];
|
|
1234 int index = locate( string, current, startIndex );
|
|
1235 if (index !is string.length ) result = Math.min (result, index);
|
|
1236 }
|
|
1237 return result;
|
|
1238 }
|
|
1239
|
|
1240 static int nextIndexOfNotChar (char[] string, char[] searchChars, int startIndex) {
|
|
1241 int length = string.length;
|
|
1242 int index = startIndex;
|
|
1243 while (index < length) {
|
|
1244 char current = string[index];
|
|
1245 if ( !contains( searchChars, current)) break;
|
|
1246 index++;
|
|
1247 }
|
|
1248 return index;
|
|
1249 }
|
|
1250
|
|
1251 static int previousIndexOfChar (char[] string, char[] searchChars, int startIndex) {
|
|
1252 int result = -1;
|
|
1253 if (startIndex < 0) return result;
|
|
1254 string = string[0 .. startIndex];
|
|
1255 for (int i = 0; i < searchChars.length ; i++) {
|
|
1256 char current = searchChars[i];
|
|
1257 int index = locatePrior( string, current);
|
|
1258 if (index !is string.length ) result = Math.max (result, index);
|
|
1259 }
|
|
1260 return result;
|
|
1261 }
|
|
1262
|
|
1263 static int previousIndexOfNotChar (char[] string, char[] searchChars, int startIndex) {
|
|
1264 if (startIndex < 0) return -1;
|
|
1265 int index = startIndex - 1;
|
|
1266 while (index >= 0) {
|
|
1267 char current = string[index];
|
|
1268 if ( !contains(searchChars, current)) break;
|
|
1269 index--;
|
|
1270 }
|
|
1271 return index;
|
|
1272 }
|
|
1273
|
|
1274 void release () {
|
|
1275 if (DEBUG) Stdout.formatln("AccessibleObject.release: {}", handle);
|
|
1276 accessible = null;
|
|
1277 foreach( child; children ){
|
|
1278 if (child.isLightweight) OS.g_object_unref (child.handle);
|
|
1279 }
|
|
1280 if (parent !is null) parent.removeChild (this, false);
|
|
1281 }
|
|
1282
|
|
1283 void removeChild (AccessibleObject child, bool unref) {
|
|
1284 children.remove (child.handle);
|
|
1285 if (unref && child.isLightweight) OS.g_object_unref (child.handle);
|
|
1286 }
|
|
1287
|
|
1288 void selectionChanged () {
|
|
1289 OS.g_signal_emit_by_name0 (handle, ATK.selection_changed.ptr);
|
|
1290 }
|
|
1291
|
|
1292 void setFocus (int childID) {
|
|
1293 updateChildren ();
|
|
1294 AccessibleObject accObject = getChildByID (childID);
|
|
1295 if (accObject !is null) {
|
|
1296 ATK.atk_focus_tracker_notify (accObject.handle);
|
|
1297 }
|
|
1298 }
|
|
1299
|
|
1300 void setParent (AccessibleObject parent) {
|
|
1301 this.parent = parent;
|
|
1302 }
|
|
1303
|
|
1304 void textCaretMoved(int index) {
|
|
1305 OS.g_signal_emit_by_name1 (handle, ATK.text_caret_moved.ptr, index);
|
|
1306 }
|
|
1307
|
|
1308 void textChanged(int type, int startIndex, int length) {
|
|
1309 if (type is ACC.TEXT_DELETE) {
|
|
1310 OS.g_signal_emit_by_name2 (handle, ATK.text_changed_delete.ptr, startIndex, length);
|
|
1311 } else {
|
|
1312 OS.g_signal_emit_by_name2 (handle, ATK.text_changed_insert.ptr, startIndex, length);
|
|
1313 }
|
|
1314 }
|
|
1315
|
|
1316 void textSelectionChanged() {
|
|
1317 OS.g_signal_emit_by_name0 (handle, ATK.text_selection_changed.ptr);
|
|
1318 }
|
|
1319
|
|
1320 void updateChildren () {
|
|
1321 if (isLightweight) return;
|
|
1322 AccessibleControlListener[] listeners = getControlListeners ();
|
|
1323 if (listeners.length is 0) return;
|
|
1324
|
|
1325 AccessibleControlEvent event = new AccessibleControlEvent (this);
|
|
1326 for (int i = 0; i < listeners.length; i++) {
|
|
1327 listeners [i].getChildren (event);
|
|
1328 }
|
|
1329 if (event.children !is null && event.children.length > 0) {
|
|
1330 AtkObject*[] idsToKeep = new AtkObject*[]( children.length );
|
|
1331 idsToKeep.length = 0;
|
|
1332 if ( null !is (cast(Integer)event.children[0] )) {
|
|
1333 /* an array of child id's (Integers) was answered */
|
|
1334 auto parentType = AccessibleFactory.getDefaultParentType ();
|
|
1335 for (int i = 0; i < event.children.length; i++) {
|
|
1336 AccessibleObject object = getChildByIndex (i);
|
|
1337 if (object is null) {
|
|
1338 auto childType = AccessibleFactory.getChildType (accessible, i);
|
|
1339 object = new AccessibleObject (childType, null, accessible, parentType, true);
|
|
1340 AccessibleObjects[object.handle] = object;
|
|
1341 addChild (object);
|
|
1342 object.index = i;
|
|
1343 }
|
|
1344 if( auto intChild = cast(Integer)event.children[i] ){
|
|
1345 object.id = intChild.intValue ();
|
|
1346 }
|
|
1347 else {
|
|
1348 /* a non-ID value was given so don't set the ID */
|
|
1349 }
|
|
1350 idsToKeep ~= object.handle;
|
|
1351 }
|
|
1352 } else {
|
|
1353 /* an array of Accessible children was answered */
|
|
1354 int childIndex = 0;
|
|
1355 for (int i = 0; i < event.children.length; i++) {
|
|
1356 AccessibleObject object = null;
|
|
1357 if( auto accChild = cast(Accessible)event.children[i] ){
|
|
1358 object = accChild.accessibleObject;
|
|
1359 } else {
|
|
1360 /* a non-Accessible value was given so nothing to do here */
|
|
1361 }
|
|
1362 if (object !is null) {
|
|
1363 object.index = childIndex++;
|
|
1364 idsToKeep ~= object.handle;
|
|
1365 }
|
|
1366 }
|
|
1367 }
|
|
1368 /* remove old children that were not provided as children anymore */
|
|
1369 foreach( id; children.keys ){
|
|
1370 if ( !tango.core.Array.contains( idsToKeep, id )) {
|
|
1371 AccessibleObject object = cast(AccessibleObject) children[id];
|
|
1372 removeChild (object, true);
|
|
1373 }
|
|
1374 }
|
|
1375 }
|
|
1376 }
|
|
1377 }
|