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.SelectionT;
26 
27 public  import atk.ObjectAtk;
28 public  import gobject.ObjectG;
29 public  import gobject.Signals;
30 public  import gtkc.atk;
31 public  import gtkc.atktypes;
32 public  import gtkc.gdktypes;
33 public  import std.algorithm;
34 
35 
36 /**
37  * #AtkSelection should be implemented by UI components with children
38  * which are exposed by #atk_object_ref_child and
39  * #atk_object_get_n_children, if the use of the parent UI component
40  * ordinarily involves selection of one or more of the objects
41  * corresponding to those #AtkObject children - for example,
42  * selectable lists.
43  * 
44  * Note that other types of "selection" (for instance text selection)
45  * are accomplished a other ATK interfaces - #AtkSelection is limited
46  * to the selection/deselection of children.
47  */
48 public template SelectionT(TStruct)
49 {
50 	/** Get the main Gtk struct */
51 	public AtkSelection* getSelectionStruct()
52 	{
53 		return cast(AtkSelection*)getStruct();
54 	}
55 
56 
57 	/**
58 	 * Adds the specified accessible child of the object to the
59 	 * object's selection.
60 	 *
61 	 * Params:
62 	 *     i = a #gint specifying the child index.
63 	 *
64 	 * Return: TRUE if success, FALSE otherwise.
65 	 */
66 	public bool addSelection(int i)
67 	{
68 		return atk_selection_add_selection(getSelectionStruct(), i) != 0;
69 	}
70 
71 	/**
72 	 * Clears the selection in the object so that no children in the object
73 	 * are selected.
74 	 *
75 	 * Return: TRUE if success, FALSE otherwise.
76 	 */
77 	public bool clearSelection()
78 	{
79 		return atk_selection_clear_selection(getSelectionStruct()) != 0;
80 	}
81 
82 	/**
83 	 * Gets the number of accessible children currently selected.
84 	 * Note: callers should not rely on %NULL or on a zero value for
85 	 * indication of whether AtkSelectionIface is implemented, they should
86 	 * use type checking/interface checking macros or the
87 	 * atk_get_accessible_value() convenience method.
88 	 *
89 	 * Return: a gint representing the number of items selected, or 0
90 	 *     if @selection does not implement this interface.
91 	 */
92 	public int getSelectionCount()
93 	{
94 		return atk_selection_get_selection_count(getSelectionStruct());
95 	}
96 
97 	/**
98 	 * Determines if the current child of this object is selected
99 	 * Note: callers should not rely on %NULL or on a zero value for
100 	 * indication of whether AtkSelectionIface is implemented, they should
101 	 * use type checking/interface checking macros or the
102 	 * atk_get_accessible_value() convenience method.
103 	 *
104 	 * Params:
105 	 *     i = a #gint specifying the child index.
106 	 *
107 	 * Return: a gboolean representing the specified child is selected, or 0
108 	 *     if @selection does not implement this interface.
109 	 */
110 	public bool isChildSelected(int i)
111 	{
112 		return atk_selection_is_child_selected(getSelectionStruct(), i) != 0;
113 	}
114 
115 	/**
116 	 * Gets a reference to the accessible object representing the specified
117 	 * selected child of the object.
118 	 * Note: callers should not rely on %NULL or on a zero value for
119 	 * indication of whether AtkSelectionIface is implemented, they should
120 	 * use type checking/interface checking macros or the
121 	 * atk_get_accessible_value() convenience method.
122 	 *
123 	 * Params:
124 	 *     i = a #gint specifying the index in the selection set.  (e.g. the
125 	 *         ith selection as opposed to the ith child).
126 	 *
127 	 * Return: an #AtkObject representing the
128 	 *     selected accessible, or %NULL if @selection does not implement this
129 	 *     interface.
130 	 */
131 	public ObjectAtk refSelection(int i)
132 	{
133 		auto p = atk_selection_ref_selection(getSelectionStruct(), i);
134 		
135 		if(p is null)
136 		{
137 			return null;
138 		}
139 		
140 		return ObjectG.getDObject!(ObjectAtk)(cast(AtkObject*) p, true);
141 	}
142 
143 	/**
144 	 * Removes the specified child of the object from the object's selection.
145 	 *
146 	 * Params:
147 	 *     i = a #gint specifying the index in the selection set.  (e.g. the
148 	 *         ith selection as opposed to the ith child).
149 	 *
150 	 * Return: TRUE if success, FALSE otherwise.
151 	 */
152 	public bool removeSelection(int i)
153 	{
154 		return atk_selection_remove_selection(getSelectionStruct(), i) != 0;
155 	}
156 
157 	/**
158 	 * Causes every child of the object to be selected if the object
159 	 * supports multiple selections.
160 	 *
161 	 * Return: TRUE if success, FALSE otherwise.
162 	 */
163 	public bool selectAllSelection()
164 	{
165 		return atk_selection_select_all_selection(getSelectionStruct()) != 0;
166 	}
167 
168 	protected class OnSelectionChangedDelegateWrapper
169 	{
170 		void delegate(SelectionIF) dlg;
171 		gulong handlerId;
172 		ConnectFlags flags;
173 		this(void delegate(SelectionIF) dlg, gulong handlerId, ConnectFlags flags)
174 		{
175 			this.dlg = dlg;
176 			this.handlerId = handlerId;
177 			this.flags = flags;
178 		}
179 	}
180 	protected OnSelectionChangedDelegateWrapper[] onSelectionChangedListeners;
181 
182 	/**
183 	 * The "selection-changed" signal is emitted by an object which
184 	 * implements AtkSelection interface when the selection changes.
185 	 */
186 	gulong addOnSelectionChanged(void delegate(SelectionIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
187 	{
188 		onSelectionChangedListeners ~= new OnSelectionChangedDelegateWrapper(dlg, 0, connectFlags);
189 		onSelectionChangedListeners[onSelectionChangedListeners.length - 1].handlerId = Signals.connectData(
190 			this,
191 			"selection-changed",
192 			cast(GCallback)&callBackSelectionChanged,
193 			cast(void*)onSelectionChangedListeners[onSelectionChangedListeners.length - 1],
194 			cast(GClosureNotify)&callBackSelectionChangedDestroy,
195 			connectFlags);
196 		return onSelectionChangedListeners[onSelectionChangedListeners.length - 1].handlerId;
197 	}
198 	
199 	extern(C) static void callBackSelectionChanged(AtkSelection* selectionStruct,OnSelectionChangedDelegateWrapper wrapper)
200 	{
201 		wrapper.dlg(wrapper.outer);
202 	}
203 	
204 	extern(C) static void callBackSelectionChangedDestroy(OnSelectionChangedDelegateWrapper wrapper, GClosure* closure)
205 	{
206 		wrapper.outer.internalRemoveOnSelectionChanged(wrapper);
207 	}
208 
209 	protected void internalRemoveOnSelectionChanged(OnSelectionChangedDelegateWrapper source)
210 	{
211 		foreach(index, wrapper; onSelectionChangedListeners)
212 		{
213 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
214 			{
215 				onSelectionChangedListeners[index] = null;
216 				onSelectionChangedListeners = std.algorithm.remove(onSelectionChangedListeners, index);
217 				break;
218 			}
219 		}
220 	}
221 	
222 }