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