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