1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module atk.ObjectAtk;
26 
27 private import atk.RelationSet;
28 private import atk.StateSet;
29 private import atk.c.functions;
30 public  import atk.c.types;
31 private import glib.Str;
32 private import gobject.ObjectG;
33 private import gobject.Signals;
34 public  import gtkc.atktypes;
35 private import std.algorithm;
36 
37 
38 /**
39  * This class is the primary class for accessibility support via the
40  * Accessibility ToolKit (ATK).  Objects which are instances of
41  * #AtkObject (or instances of AtkObject-derived types) are queried
42  * for properties which relate basic (and generic) properties of a UI
43  * component such as name and description.  Instances of #AtkObject
44  * may also be queried as to whether they implement other ATK
45  * interfaces (e.g. #AtkAction, #AtkComponent, etc.), as appropriate
46  * to the role which a given UI component plays in a user interface.
47  * 
48  * All UI components in an application which provide useful
49  * information or services to the user must provide corresponding
50  * #AtkObject instances on request (in GTK+, for instance, usually on
51  * a call to #gtk_widget_get_accessible ()), either via ATK support
52  * built into the toolkit for the widget class or ancestor class, or
53  * in the case of custom widgets, if the inherited #AtkObject
54  * implementation is insufficient, via instances of a new #AtkObject
55  * subclass.
56  * 
57  * See also: #AtkObjectFactory, #AtkRegistry.  (GTK+ users see also
58  * #GtkAccessible).
59  */
60 public class ObjectAtk : ObjectG
61 {
62 	/** the main Gtk struct */
63 	protected AtkObject* atkObject;
64 
65 	/** Get the main Gtk struct */
66 	public AtkObject* getObjectAtkStruct(bool transferOwnership = false)
67 	{
68 		if (transferOwnership)
69 			ownedRef = false;
70 		return atkObject;
71 	}
72 
73 	/** the main Gtk struct as a void* */
74 	protected override void* getStruct()
75 	{
76 		return cast(void*)atkObject;
77 	}
78 
79 	/**
80 	 * Sets our main struct and passes it to the parent class.
81 	 */
82 	public this (AtkObject* atkObject, bool ownedRef = false)
83 	{
84 		this.atkObject = atkObject;
85 		super(cast(GObject*)atkObject, ownedRef);
86 	}
87 
88 
89 	/** */
90 	public static GType getType()
91 	{
92 		return atk_object_get_type();
93 	}
94 
95 	/**
96 	 * Adds a relationship of the specified type with the specified target.
97 	 *
98 	 * Params:
99 	 *     relationship = The #AtkRelationType of the relation
100 	 *     target = The #AtkObject which is to be the target of the relation.
101 	 *
102 	 * Returns: TRUE if the relationship is added.
103 	 */
104 	public bool addRelationship(AtkRelationType relationship, ObjectAtk target)
105 	{
106 		return atk_object_add_relationship(atkObject, relationship, (target is null) ? null : target.getObjectAtkStruct()) != 0;
107 	}
108 
109 	/**
110 	 * Calls @handler on property changes.
111 	 *
112 	 * Deprecated: Connect directly to #AtkObject::property-change or
113 	 * the relevant #GObject::notify signal for each desired property.
114 	 *
115 	 * Params:
116 	 *     handler = a function to be called when a property changes its value
117 	 *
118 	 * Returns: a #guint which is the handler id used in
119 	 *     atk_object_remove_property_change_handler()
120 	 */
121 	public uint connectPropertyChangeHandler(AtkPropertyChangeHandler* handler)
122 	{
123 		return atk_object_connect_property_change_handler(atkObject, handler);
124 	}
125 
126 	/**
127 	 * Gets the accessible id of the accessible.
128 	 *
129 	 * Returns: a character string representing the accessible id of the object, or
130 	 *     NULL if no such string was set.
131 	 *
132 	 * Since: 2.34
133 	 */
134 	public string getAccessibleId()
135 	{
136 		return Str.toString(atk_object_get_accessible_id(atkObject));
137 	}
138 
139 	/**
140 	 * Get a list of properties applied to this object as a whole, as an #AtkAttributeSet consisting of
141 	 * name-value pairs. As such these attributes may be considered weakly-typed properties or annotations,
142 	 * as distinct from strongly-typed object data available via other get/set methods.
143 	 * Not all objects have explicit "name-value pair" #AtkAttributeSet properties.
144 	 *
145 	 * Returns: an #AtkAttributeSet consisting of all
146 	 *     explicit properties/annotations applied to the object, or an empty
147 	 *     set if the object has no name-value pair attributes assigned to
148 	 *     it. This #atkattributeset should be freed by a call to
149 	 *     atk_attribute_set_free().
150 	 *
151 	 * Since: 1.12
152 	 */
153 	public AtkAttributeSet* getAttributes()
154 	{
155 		return atk_object_get_attributes(atkObject);
156 	}
157 
158 	/**
159 	 * Gets the accessible description of the accessible.
160 	 *
161 	 * Returns: a character string representing the accessible description
162 	 *     of the accessible.
163 	 */
164 	public string getDescription()
165 	{
166 		return Str.toString(atk_object_get_description(atkObject));
167 	}
168 
169 	/**
170 	 * Gets the 0-based index of this accessible in its parent; returns -1 if the
171 	 * accessible does not have an accessible parent.
172 	 *
173 	 * Returns: an integer which is the index of the accessible in its parent
174 	 */
175 	public int getIndexInParent()
176 	{
177 		return atk_object_get_index_in_parent(atkObject);
178 	}
179 
180 	/**
181 	 * Gets the layer of the accessible.
182 	 *
183 	 * Deprecated: Use atk_component_get_layer instead.
184 	 *
185 	 * Returns: an #AtkLayer which is the layer of the accessible
186 	 */
187 	public AtkLayer getLayer()
188 	{
189 		return atk_object_get_layer(atkObject);
190 	}
191 
192 	/**
193 	 * Gets the zorder of the accessible. The value G_MININT will be returned
194 	 * if the layer of the accessible is not ATK_LAYER_MDI.
195 	 *
196 	 * Deprecated: Use atk_component_get_mdi_zorder instead.
197 	 *
198 	 * Returns: a gint which is the zorder of the accessible, i.e. the depth at
199 	 *     which the component is shown in relation to other components in the same
200 	 *     container.
201 	 */
202 	public int getMdiZorder()
203 	{
204 		return atk_object_get_mdi_zorder(atkObject);
205 	}
206 
207 	/**
208 	 * Gets the number of accessible children of the accessible.
209 	 *
210 	 * Returns: an integer representing the number of accessible children
211 	 *     of the accessible.
212 	 */
213 	public int getNAccessibleChildren()
214 	{
215 		return atk_object_get_n_accessible_children(atkObject);
216 	}
217 
218 	/**
219 	 * Gets the accessible name of the accessible.
220 	 *
221 	 * Returns: a character string representing the accessible name of the object.
222 	 */
223 	public string getName()
224 	{
225 		return Str.toString(atk_object_get_name(atkObject));
226 	}
227 
228 	/**
229 	 * Gets a UTF-8 string indicating the POSIX-style LC_MESSAGES locale
230 	 * of @accessible.
231 	 *
232 	 * Returns: a UTF-8 string indicating the POSIX-style LC_MESSAGES
233 	 *     locale of @accessible.
234 	 *
235 	 * Since: 2.8
236 	 */
237 	public string getObjectLocale()
238 	{
239 		return Str.toString(atk_object_get_object_locale(atkObject));
240 	}
241 
242 	/**
243 	 * Gets the accessible parent of the accessible. By default this is
244 	 * the one assigned with atk_object_set_parent(), but it is assumed
245 	 * that ATK implementors have ways to get the parent of the object
246 	 * without the need of assigning it manually with
247 	 * atk_object_set_parent(), and will return it with this method.
248 	 *
249 	 * If you are only interested on the parent assigned with
250 	 * atk_object_set_parent(), use atk_object_peek_parent().
251 	 *
252 	 * Returns: an #AtkObject representing the accessible
253 	 *     parent of the accessible
254 	 */
255 	public ObjectAtk getParent()
256 	{
257 		auto __p = atk_object_get_parent(atkObject);
258 
259 		if(__p is null)
260 		{
261 			return null;
262 		}
263 
264 		return ObjectG.getDObject!(ObjectAtk)(cast(AtkObject*) __p);
265 	}
266 
267 	/**
268 	 * Gets the role of the accessible.
269 	 *
270 	 * Returns: an #AtkRole which is the role of the accessible
271 	 */
272 	public AtkRole getRole()
273 	{
274 		return atk_object_get_role(atkObject);
275 	}
276 
277 	/**
278 	 * This function is called when implementing subclasses of #AtkObject.
279 	 * It does initialization required for the new object. It is intended
280 	 * that this function should called only in the ..._new() functions used
281 	 * to create an instance of a subclass of #AtkObject
282 	 *
283 	 * Params:
284 	 *     data = a #gpointer which identifies the object for which the AtkObject was created.
285 	 */
286 	public void initialize(void* data)
287 	{
288 		atk_object_initialize(atkObject, data);
289 	}
290 
291 	/**
292 	 * Emits a state-change signal for the specified state.
293 	 *
294 	 * Note that as a general rule when the state of an existing object changes,
295 	 * emitting a notification is expected.
296 	 *
297 	 * Params:
298 	 *     state = an #AtkState whose state is changed
299 	 *     value = a gboolean which indicates whether the state is being set on or off
300 	 */
301 	public void notifyStateChange(AtkState state, bool value)
302 	{
303 		atk_object_notify_state_change(atkObject, state, value);
304 	}
305 
306 	/**
307 	 * Gets the accessible parent of the accessible, if it has been
308 	 * manually assigned with atk_object_set_parent. Otherwise, this
309 	 * function returns %NULL.
310 	 *
311 	 * This method is intended as an utility for ATK implementors, and not
312 	 * to be exposed to accessible tools. See atk_object_get_parent() for
313 	 * further reference.
314 	 *
315 	 * Returns: an #AtkObject representing the accessible
316 	 *     parent of the accessible if assigned
317 	 */
318 	public ObjectAtk peekParent()
319 	{
320 		auto __p = atk_object_peek_parent(atkObject);
321 
322 		if(__p is null)
323 		{
324 			return null;
325 		}
326 
327 		return ObjectG.getDObject!(ObjectAtk)(cast(AtkObject*) __p);
328 	}
329 
330 	/**
331 	 * Gets a reference to the specified accessible child of the object.
332 	 * The accessible children are 0-based so the first accessible child is
333 	 * at index 0, the second at index 1 and so on.
334 	 *
335 	 * Params:
336 	 *     i = a gint representing the position of the child, starting from 0
337 	 *
338 	 * Returns: an #AtkObject representing the specified
339 	 *     accessible child of the accessible.
340 	 */
341 	public ObjectAtk refAccessibleChild(int i)
342 	{
343 		auto __p = atk_object_ref_accessible_child(atkObject, i);
344 
345 		if(__p is null)
346 		{
347 			return null;
348 		}
349 
350 		return ObjectG.getDObject!(ObjectAtk)(cast(AtkObject*) __p, true);
351 	}
352 
353 	/**
354 	 * Gets the #AtkRelationSet associated with the object.
355 	 *
356 	 * Returns: an #AtkRelationSet representing the relation set
357 	 *     of the object.
358 	 */
359 	public RelationSet refRelationSet()
360 	{
361 		auto __p = atk_object_ref_relation_set(atkObject);
362 
363 		if(__p is null)
364 		{
365 			return null;
366 		}
367 
368 		return ObjectG.getDObject!(RelationSet)(cast(AtkRelationSet*) __p, true);
369 	}
370 
371 	/**
372 	 * Gets a reference to the state set of the accessible; the caller must
373 	 * unreference it when it is no longer needed.
374 	 *
375 	 * Returns: a reference to an #AtkStateSet which is the state
376 	 *     set of the accessible
377 	 */
378 	public StateSet refStateSet()
379 	{
380 		auto __p = atk_object_ref_state_set(atkObject);
381 
382 		if(__p is null)
383 		{
384 			return null;
385 		}
386 
387 		return ObjectG.getDObject!(StateSet)(cast(AtkStateSet*) __p, true);
388 	}
389 
390 	/**
391 	 * Removes a property change handler.
392 	 *
393 	 * Deprecated: See atk_object_connect_property_change_handler()
394 	 *
395 	 * Params:
396 	 *     handlerId = a guint which identifies the handler to be removed.
397 	 */
398 	public void removePropertyChangeHandler(uint handlerId)
399 	{
400 		atk_object_remove_property_change_handler(atkObject, handlerId);
401 	}
402 
403 	/**
404 	 * Removes a relationship of the specified type with the specified target.
405 	 *
406 	 * Params:
407 	 *     relationship = The #AtkRelationType of the relation
408 	 *     target = The #AtkObject which is the target of the relation to be removed.
409 	 *
410 	 * Returns: TRUE if the relationship is removed.
411 	 */
412 	public bool removeRelationship(AtkRelationType relationship, ObjectAtk target)
413 	{
414 		return atk_object_remove_relationship(atkObject, relationship, (target is null) ? null : target.getObjectAtkStruct()) != 0;
415 	}
416 
417 	/**
418 	 * Sets the accessible ID of the accessible.  This is not meant to be presented
419 	 * to the user, but to be an ID which is stable over application development.
420 	 * Typically, this is the gtkbuilder ID. Such an ID will be available for
421 	 * instance to identify a given well-known accessible object for tailored screen
422 	 * reading, or for automatic regression testing.
423 	 *
424 	 * Params:
425 	 *     name = a character string to be set as the accessible id
426 	 *
427 	 * Since: 2.34
428 	 */
429 	public void setAccessibleId(string name)
430 	{
431 		atk_object_set_accessible_id(atkObject, Str.toStringz(name));
432 	}
433 
434 	/**
435 	 * Sets the accessible description of the accessible. You can't set
436 	 * the description to NULL. This is reserved for the initial value. In
437 	 * this aspect NULL is similar to ATK_ROLE_UNKNOWN. If you want to set
438 	 * the name to a empty value you can use "".
439 	 *
440 	 * Params:
441 	 *     description = a character string to be set as the accessible description
442 	 */
443 	public void setDescription(string description)
444 	{
445 		atk_object_set_description(atkObject, Str.toStringz(description));
446 	}
447 
448 	/**
449 	 * Sets the accessible name of the accessible. You can't set the name
450 	 * to NULL. This is reserved for the initial value. In this aspect
451 	 * NULL is similar to ATK_ROLE_UNKNOWN. If you want to set the name to
452 	 * a empty value you can use "".
453 	 *
454 	 * Params:
455 	 *     name = a character string to be set as the accessible name
456 	 */
457 	public void setName(string name)
458 	{
459 		atk_object_set_name(atkObject, Str.toStringz(name));
460 	}
461 
462 	/**
463 	 * Sets the accessible parent of the accessible. @parent can be NULL.
464 	 *
465 	 * Params:
466 	 *     parent = an #AtkObject to be set as the accessible parent
467 	 */
468 	public void setParent(ObjectAtk parent)
469 	{
470 		atk_object_set_parent(atkObject, (parent is null) ? null : parent.getObjectAtkStruct());
471 	}
472 
473 	/**
474 	 * Sets the role of the accessible.
475 	 *
476 	 * Params:
477 	 *     role = an #AtkRole to be set as the role
478 	 */
479 	public void setRole(AtkRole role)
480 	{
481 		atk_object_set_role(atkObject, role);
482 	}
483 
484 	/**
485 	 * The "active-descendant-changed" signal is emitted by an object
486 	 * which has the state ATK_STATE_MANAGES_DESCENDANTS when the focus
487 	 * object in the object changes. For instance, a table will emit the
488 	 * signal when the cell in the table which has focus changes.
489 	 *
490 	 * Params:
491 	 *     arg1 = the newly focused object.
492 	 */
493 	gulong addOnActiveDescendantChanged(void delegate(ObjectAtk, ObjectAtk) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
494 	{
495 		return Signals.connect(this, "active-descendant-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
496 	}
497 
498 	/**
499 	 * The signal "children-changed" is emitted when a child is added or
500 	 * removed form an object. It supports two details: "add" and
501 	 * "remove"
502 	 *
503 	 * Params:
504 	 *     arg1 = The index of the added or removed child. The value can be
505 	 *         -1. This is used if the value is not known by the implementor
506 	 *         when the child is added/removed or irrelevant.
507 	 *     arg2 = A gpointer to the child AtkObject which was added or
508 	 *         removed. If the child was removed, it is possible that it is not
509 	 *         available for the implementor. In that case this pointer can be
510 	 *         NULL.
511 	 */
512 	gulong addOnChildrenChanged(void delegate(uint, ObjectAtk, ObjectAtk) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
513 	{
514 		return Signals.connect(this, "children-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
515 	}
516 
517 	/**
518 	 * The signal "focus-event" is emitted when an object gained or lost
519 	 * focus.
520 	 *
521 	 * Deprecated: Use the #AtkObject::state-change signal instead.
522 	 *
523 	 * Params:
524 	 *     arg1 = a boolean value which indicates whether the object gained
525 	 *         or lost focus.
526 	 */
527 	gulong addOnFocus(void delegate(bool, ObjectAtk) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
528 	{
529 		return Signals.connect(this, "focus-event", dlg, connectFlags ^ ConnectFlags.SWAPPED);
530 	}
531 
532 	/**
533 	 * The signal "property-change" is emitted when an object's property
534 	 * value changes. @arg1 contains an #AtkPropertyValues with the name
535 	 * and the new value of the property whose value has changed. Note
536 	 * that, as with GObject notify, getting this signal does not
537 	 * guarantee that the value of the property has actually changed; it
538 	 * may also be emitted when the setter of the property is called to
539 	 * reinstate the previous value.
540 	 *
541 	 * Toolkit implementor note: ATK implementors should use
542 	 * g_object_notify() to emit property-changed
543 	 * notifications. #AtkObject::property-changed is needed by the
544 	 * implementation of atk_add_global_event_listener() because GObject
545 	 * notify doesn't support emission hooks.
546 	 *
547 	 * Params:
548 	 *     arg1 = an #AtkPropertyValues containing the new
549 	 *         value of the property which changed.
550 	 */
551 	gulong addOnPropertyChange(void delegate(void*, ObjectAtk) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
552 	{
553 		return Signals.connect(this, "property-change", dlg, connectFlags ^ ConnectFlags.SWAPPED);
554 	}
555 
556 	/**
557 	 * The "state-change" signal is emitted when an object's state
558 	 * changes.  The detail value identifies the state type which has
559 	 * changed.
560 	 *
561 	 * Params:
562 	 *     arg1 = The name of the state which has changed
563 	 *     arg2 = A boolean which indicates whether the state has been set or unset.
564 	 */
565 	gulong addOnStateChange(void delegate(string, bool, ObjectAtk) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
566 	{
567 		return Signals.connect(this, "state-change", dlg, connectFlags ^ ConnectFlags.SWAPPED);
568 	}
569 
570 	/**
571 	 * The "visible-data-changed" signal is emitted when the visual
572 	 * appearance of the object changed.
573 	 */
574 	gulong addOnVisibleDataChanged(void delegate(ObjectAtk) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
575 	{
576 		return Signals.connect(this, "visible-data-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
577 	}
578 
579 	/**
580 	 * Get the #AtkRole type corresponding to a rolew name.
581 	 *
582 	 * Params:
583 	 *     name = a string which is the (non-localized) name of an ATK role.
584 	 *
585 	 * Returns: the #AtkRole enumerated type corresponding to the specified name,
586 	 *     or #ATK_ROLE_INVALID if no matching role is found.
587 	 */
588 	public static AtkRole roleForName(string name)
589 	{
590 		return atk_role_for_name(Str.toStringz(name));
591 	}
592 
593 	/**
594 	 * Gets the localized description string describing the #AtkRole @role.
595 	 *
596 	 * Params:
597 	 *     role = The #AtkRole whose localized name is required
598 	 *
599 	 * Returns: the localized string describing the AtkRole
600 	 */
601 	public static string roleGetLocalizedName(AtkRole role)
602 	{
603 		return Str.toString(atk_role_get_localized_name(role));
604 	}
605 
606 	/**
607 	 * Gets the description string describing the #AtkRole @role.
608 	 *
609 	 * Params:
610 	 *     role = The #AtkRole whose name is required
611 	 *
612 	 * Returns: the string describing the AtkRole
613 	 */
614 	public static string roleGetName(AtkRole role)
615 	{
616 		return Str.toString(atk_role_get_name(role));
617 	}
618 
619 	/**
620 	 * Registers the role specified by @name. @name must be a meaningful
621 	 * name. So it should not be empty, or consisting on whitespaces.
622 	 *
623 	 * Deprecated: Since 2.12. If your application/toolkit doesn't find a
624 	 * suitable role for a specific object defined at #AtkRole, please
625 	 * submit a bug in order to add a new role to the specification.
626 	 *
627 	 * Params:
628 	 *     name = a character string describing the new role.
629 	 *
630 	 * Returns: an #AtkRole for the new role if added
631 	 *     properly. ATK_ROLE_INVALID in case of error.
632 	 */
633 	public static AtkRole roleRegister(string name)
634 	{
635 		return atk_role_register(Str.toStringz(name));
636 	}
637 }