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  * Conversion parameters:
26  * inFile  = GtkTreeSelection.html
27  * outPack = gtk
28  * outFile = TreeSelection
29  * strct   = GtkTreeSelection
30  * realStrct=
31  * ctorStrct=
32  * clss    = TreeSelection
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_tree_selection_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * 	- gtk_tree_selection_get_selected_rows
45  * omit signals:
46  * imports:
47  * 	- gtk.TreeView
48  * 	- gtk.TreeModel
49  * 	- gtk.TreeModelIF
50  * 	- gtk.TreeIter
51  * 	- glib.ListG
52  * 	- gtk.TreePath
53  * structWrap:
54  * 	- GList* -> ListG
55  * 	- GtkTreeIter* -> TreeIter
56  * 	- GtkTreeModel* -> TreeModelIF
57  * 	- GtkTreePath* -> TreePath
58  * 	- GtkTreeView* -> TreeView
59  * module aliases:
60  * local aliases:
61  * overrides:
62  */
63 
64 module gtk.TreeSelection;
65 
66 public  import gtkc.gtktypes;
67 
68 private import gtkc.gtk;
69 private import glib.ConstructionException;
70 private import gobject.ObjectG;
71 
72 private import gobject.Signals;
73 public  import gtkc.gdktypes;
74 private import gtk.TreeView;
75 private import gtk.TreeModel;
76 private import gtk.TreeModelIF;
77 private import gtk.TreeIter;
78 private import glib.ListG;
79 private import gtk.TreePath;
80 
81 
82 private import gobject.ObjectG;
83 
84 /**
85  * The GtkTreeSelection object is a helper object to manage the selection
86  * for a GtkTreeView widget. The GtkTreeSelection object is
87  * automatically created when a new GtkTreeView widget is created, and
88  * cannot exist independentally of this widget. The primary reason the
89  * GtkTreeSelection objects exists is for cleanliness of code and API.
90  * That is, there is no conceptual reason all these functions could not be
91  * methods on the GtkTreeView widget instead of a separate function.
92  *
93  * The GtkTreeSelection object is gotten from a GtkTreeView by calling
94  * gtk_tree_view_get_selection(). It can be manipulated to check the
95  * selection status of the tree, as well as select and deselect individual
96  * rows. Selection is done completely view side. As a result, multiple
97  * views of the same model can have completely different selections.
98  * Additionally, you cannot change the selection of a row on the model that
99  * is not currently displayed by the view without expanding its parents
100  * first.
101  *
102  * One of the important things to remember when monitoring the selection of
103  * a view is that the "changed" signal is mostly a hint.
104  * That is, it may only emit one signal when a range of rows is selected.
105  * Additionally, it may on occasion emit a "changed" signal
106  * when nothing has happened (mostly as a result of programmers calling
107  * select_row on an already selected row).
108  */
109 public class TreeSelection : ObjectG
110 {
111 	
112 	/** the main Gtk struct */
113 	protected GtkTreeSelection* gtkTreeSelection;
114 	
115 	
116 	/** Get the main Gtk struct */
117 	public GtkTreeSelection* getTreeSelectionStruct()
118 	{
119 		return gtkTreeSelection;
120 	}
121 	
122 	
123 	/** the main Gtk struct as a void* */
124 	protected override void* getStruct()
125 	{
126 		return cast(void*)gtkTreeSelection;
127 	}
128 	
129 	/**
130 	 * Sets our main struct and passes it to the parent class
131 	 */
132 	public this (GtkTreeSelection* gtkTreeSelection)
133 	{
134 		super(cast(GObject*)gtkTreeSelection);
135 		this.gtkTreeSelection = gtkTreeSelection;
136 	}
137 	
138 	protected override void setStruct(GObject* obj)
139 	{
140 		super.setStruct(obj);
141 		gtkTreeSelection = cast(GtkTreeSelection*)obj;
142 	}
143 	
144 	/**
145 	 * Returns an TreeIter set to the currently selected node if selection
146 	 * is set to GTK_SELECTION_SINGLE or GTK_SELECTION_BROWSE.
147 	 * This function will not work if you use selection is GTK_SELECTION_MULTIPLE.
148 	 * Returns: A TreeIter for the selected node.
149 	 */
150 	public TreeIter getSelected()
151 	{
152 		TreeModelIF model;
153 		TreeIter iter = new TreeIter();
154 		
155 		if ( getSelected(model, iter) )
156 		{
157 			iter.setModel(model);
158 			return iter;
159 		}
160 		else
161 		{
162 			return null;
163 		}
164 	}
165 	
166 	/**
167 	 * Creates a list of path of all selected rows. Additionally, if you are
168 	 * planning on modifying the model after calling this function, you may
169 	 * want to convert the returned list into a list of GtkTreeRowReferences.
170 	 * To do this, you can use gtk_tree_row_reference_new().
171 	 * To free the return value, use:
172 	 * g_list_foreach (list, gtk_tree_path_free, NULL);
173 	 * g_list_free (list);
174 	 * Since 2.2
175 	 * Params:
176 	 *  model = A pointer to set to the GtkTreeModel, or NULL.
177 	 * Returns:
178 	 *  A GList containing a GtkTreePath for each selected row.
179 	 */
180 	TreePath[] getSelectedRows(out TreeModelIF model)
181 	{
182 		TreePath[] paths;
183 		GtkTreeModel* outmodel = null;
184 		GList* gList = gtk_tree_selection_get_selected_rows(gtkTreeSelection, &outmodel);
185 		if ( gList !is null )
186 		{
187 			ListG list = new ListG(gList);
188 			for ( int i=0 ; i<list.length() ; i++ )
189 			{
190 				paths ~= new TreePath(cast(GtkTreePath*)list.nthData(i));
191 			}
192 		}
193 		model = ObjectG.getDObject!(TreeModel, TreeModelIF)(outmodel);
194 		
195 		return paths;
196 	}
197 	
198 	/**
199 	 */
200 	int[string] connectedSignals;
201 	
202 	void delegate(TreeSelection)[] onChangedListeners;
203 	/**
204 	 * Emitted whenever the selection has (possibly) changed. Please note that
205 	 * this signal is mostly a hint. It may only be emitted once when a range
206 	 * of rows are selected, and it may occasionally be emitted when nothing
207 	 * has happened.
208 	 * See Also
209 	 * GtkTreeView, GtkTreeViewColumn, GtkTreeDnd, GtkTreeMode,
210 	 *  GtkTreeSortable, GtkTreeModelSort, GtkListStore, GtkTreeStore,
211 	 *  GtkCellRenderer, GtkCellEditable, GtkCellRendererPixbuf,
212 	 *  GtkCellRendererText, GtkCellRendererToggle
213 	 */
214 	void addOnChanged(void delegate(TreeSelection) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
215 	{
216 		if ( !("changed" in connectedSignals) )
217 		{
218 			Signals.connectData(
219 			getStruct(),
220 			"changed",
221 			cast(GCallback)&callBackChanged,
222 			cast(void*)this,
223 			null,
224 			connectFlags);
225 			connectedSignals["changed"] = 1;
226 		}
227 		onChangedListeners ~= dlg;
228 	}
229 	extern(C) static void callBackChanged(GtkTreeSelection* treeselectionStruct, TreeSelection _treeSelection)
230 	{
231 		foreach ( void delegate(TreeSelection) dlg ; _treeSelection.onChangedListeners )
232 		{
233 			dlg(_treeSelection);
234 		}
235 	}
236 	
237 	
238 	/**
239 	 * Sets the selection mode of the selection. If the previous type was
240 	 * GTK_SELECTION_MULTIPLE, then the anchor is kept selected, if it was
241 	 * previously selected.
242 	 * Params:
243 	 * type = The selection mode
244 	 */
245 	public void setMode(GtkSelectionMode type)
246 	{
247 		// void gtk_tree_selection_set_mode (GtkTreeSelection *selection,  GtkSelectionMode type);
248 		gtk_tree_selection_set_mode(gtkTreeSelection, type);
249 	}
250 	
251 	/**
252 	 * Gets the selection mode for selection. See
253 	 * gtk_tree_selection_set_mode().
254 	 * Returns: the current selection mode
255 	 */
256 	public GtkSelectionMode getMode()
257 	{
258 		// GtkSelectionMode gtk_tree_selection_get_mode (GtkTreeSelection *selection);
259 		return gtk_tree_selection_get_mode(gtkTreeSelection);
260 	}
261 	
262 	/**
263 	 * Sets the selection function.
264 	 * If set, this function is called before any node is selected or unselected,
265 	 * giving some control over which nodes are selected. The select function
266 	 * should return TRUE if the state of the node may be toggled, and FALSE
267 	 * if the state of the node should be left unchanged.
268 	 * Params:
269 	 * func = The selection function. May be NULL
270 	 * data = The selection function's data. May be NULL
271 	 * destroy = The destroy function for user data. May be NULL
272 	 */
273 	public void setSelectFunction(GtkTreeSelectionFunc func, void* data, GDestroyNotify destroy)
274 	{
275 		// void gtk_tree_selection_set_select_function  (GtkTreeSelection *selection,  GtkTreeSelectionFunc func,  gpointer data,  GDestroyNotify destroy);
276 		gtk_tree_selection_set_select_function(gtkTreeSelection, func, data, destroy);
277 	}
278 	
279 	/**
280 	 * Returns the current selection function.
281 	 * Since 2.14
282 	 * Returns: The function.
283 	 */
284 	public GtkTreeSelectionFunc getSelectFunction()
285 	{
286 		// GtkTreeSelectionFunc gtk_tree_selection_get_select_function  (GtkTreeSelection *selection);
287 		return gtk_tree_selection_get_select_function(gtkTreeSelection);
288 	}
289 	
290 	/**
291 	 * Returns the user data for the selection function.
292 	 * Returns: The user data.
293 	 */
294 	public void* getUserData()
295 	{
296 		// gpointer gtk_tree_selection_get_user_data (GtkTreeSelection *selection);
297 		return gtk_tree_selection_get_user_data(gtkTreeSelection);
298 	}
299 	
300 	/**
301 	 * Returns the tree view associated with selection.
302 	 * Returns: A GtkTreeView. [transfer none]
303 	 */
304 	public TreeView getTreeView()
305 	{
306 		// GtkTreeView * gtk_tree_selection_get_tree_view (GtkTreeSelection *selection);
307 		auto p = gtk_tree_selection_get_tree_view(gtkTreeSelection);
308 		
309 		if(p is null)
310 		{
311 			return null;
312 		}
313 		
314 		return ObjectG.getDObject!(TreeView)(cast(GtkTreeView*) p);
315 	}
316 	
317 	/**
318 	 * Sets iter to the currently selected node if selection is set to
319 	 * GTK_SELECTION_SINGLE or GTK_SELECTION_BROWSE. iter may be NULL if you
320 	 * just want to test if selection has any selected nodes. model is filled
321 	 * with the current model as a convenience. This function will not work if you
322 	 * use selection is GTK_SELECTION_MULTIPLE.
323 	 * Params:
324 	 * model = A pointer to set to the GtkTreeModel, or NULL. [out][allow-none][transfer none]
325 	 * iter = The GtkTreeIter, or NULL. [out][allow-none]
326 	 * Returns: TRUE, if there is a selected node.
327 	 */
328 	public int getSelected(out TreeModelIF model, TreeIter iter)
329 	{
330 		// gboolean gtk_tree_selection_get_selected (GtkTreeSelection *selection,  GtkTreeModel **model,  GtkTreeIter *iter);
331 		GtkTreeModel* outmodel = null;
332 		
333 		auto p = gtk_tree_selection_get_selected(gtkTreeSelection, &outmodel, (iter is null) ? null : iter.getTreeIterStruct());
334 		
335 		model = ObjectG.getDObject!(TreeModel, TreeModelIF)(outmodel);
336 		return p;
337 	}
338 	
339 	/**
340 	 * Calls a function for each selected node. Note that you cannot modify
341 	 * the tree or selection from within this function. As a result,
342 	 * gtk_tree_selection_get_selected_rows() might be more useful.
343 	 * Params:
344 	 * func = The function to call for each selected node. [scope call]
345 	 * data = user data to pass to the function.
346 	 */
347 	public void selectedForeach(GtkTreeSelectionForeachFunc func, void* data)
348 	{
349 		// void gtk_tree_selection_selected_foreach (GtkTreeSelection *selection,  GtkTreeSelectionForeachFunc func,  gpointer data);
350 		gtk_tree_selection_selected_foreach(gtkTreeSelection, func, data);
351 	}
352 	
353 	/**
354 	 * Returns the number of rows that have been selected in tree.
355 	 * Since 2.2
356 	 * Returns: The number of rows selected.
357 	 */
358 	public int countSelectedRows()
359 	{
360 		// gint gtk_tree_selection_count_selected_rows  (GtkTreeSelection *selection);
361 		return gtk_tree_selection_count_selected_rows(gtkTreeSelection);
362 	}
363 	
364 	/**
365 	 * Select the row at path.
366 	 * Params:
367 	 * path = The GtkTreePath to be selected.
368 	 */
369 	public void selectPath(TreePath path)
370 	{
371 		// void gtk_tree_selection_select_path (GtkTreeSelection *selection,  GtkTreePath *path);
372 		gtk_tree_selection_select_path(gtkTreeSelection, (path is null) ? null : path.getTreePathStruct());
373 	}
374 	
375 	/**
376 	 * Unselects the row at path.
377 	 * Params:
378 	 * path = The GtkTreePath to be unselected.
379 	 */
380 	public void unselectPath(TreePath path)
381 	{
382 		// void gtk_tree_selection_unselect_path (GtkTreeSelection *selection,  GtkTreePath *path);
383 		gtk_tree_selection_unselect_path(gtkTreeSelection, (path is null) ? null : path.getTreePathStruct());
384 	}
385 	
386 	/**
387 	 * Returns TRUE if the row pointed to by path is currently selected. If path
388 	 * does not point to a valid location, FALSE is returned
389 	 * Params:
390 	 * path = A GtkTreePath to check selection on.
391 	 * Returns: TRUE if path is selected.
392 	 */
393 	public int pathIsSelected(TreePath path)
394 	{
395 		// gboolean gtk_tree_selection_path_is_selected (GtkTreeSelection *selection,  GtkTreePath *path);
396 		return gtk_tree_selection_path_is_selected(gtkTreeSelection, (path is null) ? null : path.getTreePathStruct());
397 	}
398 	
399 	/**
400 	 * Selects the specified iterator.
401 	 * Params:
402 	 * iter = The GtkTreeIter to be selected.
403 	 */
404 	public void selectIter(TreeIter iter)
405 	{
406 		// void gtk_tree_selection_select_iter (GtkTreeSelection *selection,  GtkTreeIter *iter);
407 		gtk_tree_selection_select_iter(gtkTreeSelection, (iter is null) ? null : iter.getTreeIterStruct());
408 	}
409 	
410 	/**
411 	 * Unselects the specified iterator.
412 	 * Params:
413 	 * iter = The GtkTreeIter to be unselected.
414 	 */
415 	public void unselectIter(TreeIter iter)
416 	{
417 		// void gtk_tree_selection_unselect_iter (GtkTreeSelection *selection,  GtkTreeIter *iter);
418 		gtk_tree_selection_unselect_iter(gtkTreeSelection, (iter is null) ? null : iter.getTreeIterStruct());
419 	}
420 	
421 	/**
422 	 * Returns TRUE if the row at iter is currently selected.
423 	 * Params:
424 	 * iter = A valid GtkTreeIter
425 	 * Returns: TRUE, if iter is selected
426 	 */
427 	public int iterIsSelected(TreeIter iter)
428 	{
429 		// gboolean gtk_tree_selection_iter_is_selected (GtkTreeSelection *selection,  GtkTreeIter *iter);
430 		return gtk_tree_selection_iter_is_selected(gtkTreeSelection, (iter is null) ? null : iter.getTreeIterStruct());
431 	}
432 	
433 	/**
434 	 * Selects all the nodes. selection must be set to GTK_SELECTION_MULTIPLE
435 	 * mode.
436 	 */
437 	public void selectAll()
438 	{
439 		// void gtk_tree_selection_select_all (GtkTreeSelection *selection);
440 		gtk_tree_selection_select_all(gtkTreeSelection);
441 	}
442 	
443 	/**
444 	 * Unselects all the nodes.
445 	 */
446 	public void unselectAll()
447 	{
448 		// void gtk_tree_selection_unselect_all (GtkTreeSelection *selection);
449 		gtk_tree_selection_unselect_all(gtkTreeSelection);
450 	}
451 	
452 	/**
453 	 * Selects a range of nodes, determined by start_path and end_path inclusive.
454 	 * selection must be set to GTK_SELECTION_MULTIPLE mode.
455 	 * Params:
456 	 * startPath = The initial node of the range.
457 	 * endPath = The final node of the range.
458 	 */
459 	public void selectRange(TreePath startPath, TreePath endPath)
460 	{
461 		// void gtk_tree_selection_select_range (GtkTreeSelection *selection,  GtkTreePath *start_path,  GtkTreePath *end_path);
462 		gtk_tree_selection_select_range(gtkTreeSelection, (startPath is null) ? null : startPath.getTreePathStruct(), (endPath is null) ? null : endPath.getTreePathStruct());
463 	}
464 	
465 	/**
466 	 * Unselects a range of nodes, determined by start_path and end_path
467 	 * inclusive.
468 	 * Since 2.2
469 	 * Params:
470 	 * startPath = The initial node of the range.
471 	 * endPath = The initial node of the range.
472 	 */
473 	public void unselectRange(TreePath startPath, TreePath endPath)
474 	{
475 		// void gtk_tree_selection_unselect_range (GtkTreeSelection *selection,  GtkTreePath *start_path,  GtkTreePath *end_path);
476 		gtk_tree_selection_unselect_range(gtkTreeSelection, (startPath is null) ? null : startPath.getTreePathStruct(), (endPath is null) ? null : endPath.getTreePathStruct());
477 	}
478 }