alternative to assert
[gtkD.git] / gtkD / src / gtk / TreeSelection.d
blobc49f28f94a0b19745106ada580efe8809a09208d
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = GtkTreeSelection.html
26 * outPack = gtk
27 * outFile = TreeSelection
28 * strct = GtkTreeSelection
29 * realStrct=
30 * ctorStrct=
31 * clss = TreeSelection
32 * interf =
33 * class Code: Yes
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gtk_tree_selection_
40 * - gtk_
41 * omit structs:
42 * omit prefixes:
43 * omit code:
44 * - gtk_tree_selection_get_selected
45 * - gtk_tree_selection_get_selected_rows
46 * imports:
47 * - gtk.TreeView
48 * - gtk.TreeIter
49 * - glib.ListG
50 * - gtk.TreePath
51 * - gtk.TreeModel
52 * - gtk.TreeIter
53 * structWrap:
54 * - GList* -> ListG
55 * - GtkTreeIter* -> TreeIter
56 * - GtkTreePath* -> TreePath
57 * - GtkTreeView* -> TreeView
58 * module aliases:
59 * local aliases:
62 module gtk.TreeSelection;
64 version(noAssert)
66 version(Tango)
68 import tango.io.Stdout; // use the tango loging?
72 private import gtkc.gtktypes;
74 private import gtkc.gtk;
77 private import gtk.TreeView;
78 private import gtk.TreeIter;
79 private import glib.ListG;
80 private import gtk.TreePath;
81 private import gtk.TreeModel;
82 private import gtk.TreeIter;
87 /**
88 * Description
89 * The GtkTreeSelection object is a helper object to manage the selection
90 * for a GtkTreeView widget. The GtkTreeSelection object is
91 * automatically created when a new GtkTreeView widget is created, and
92 * cannot exist independentally of this widget. The primary reason the
93 * GtkTreeSelection objects exists is for cleanliness of code and API.
94 * That is, there is no conceptual reason all these functions could not be
95 * methods on the GtkTreeView widget instead of a separate function.
96 * The GtkTreeSelection object is gotten from a GtkTreeView by calling
97 * gtk_tree_view_get_selection(). It can be manipulated to check the
98 * selection status of the tree, as well as select and deselect individual
99 * rows. Selection is done completely view side. As a result, multiple
100 * views of the same model can have completely different selections.
101 * Additionally, you cannot change the selection of a row on the model that
102 * is not currently displayed by the view without expanding its parents
103 * first.
104 * One of the important things to remember when monitoring the selection of
105 * a view is that the "changed" signal is mostly a hint. That is, it may
106 * only emit one signal when a range of rows is selected. Additionally, it
107 * may on occasion emit a "changed" signal when nothing has happened
108 * (mostly as a result of programmers calling select_row on an already
109 * selected row).
111 private import gobject.ObjectG;
112 public class TreeSelection : ObjectG
115 /** the main Gtk struct */
116 protected GtkTreeSelection* gtkTreeSelection;
119 public GtkTreeSelection* getTreeSelectionStruct()
121 return gtkTreeSelection;
125 /** the main Gtk struct as a void* */
126 protected void* getStruct()
128 return cast(void*)gtkTreeSelection;
132 * Sets our main struct and passes it to the parent class
134 public this (GtkTreeSelection* gtkTreeSelection)
136 version(noAssert)
138 if ( gtkTreeSelection is null )
140 int zero = 0;
141 version(Tango)
143 Stdout("struct gtkTreeSelection is null on constructor").newline;
145 else
147 printf("struct gtkTreeSelection is null on constructor");
149 zero = zero / zero;
152 else
154 assert(gtkTreeSelection !is null, "struct gtkTreeSelection is null on constructor");
156 super(cast(GObject*)gtkTreeSelection);
157 this.gtkTreeSelection = gtkTreeSelection;
161 * Sets iter to the currently selected node if selection is set to
162 * GTK_SELECTION_SINGLE or GTK_SELECTION_BROWSE. iter may be NULL if you
163 * just want to test if selection has any selected nodes. model is filled
164 * with the current model as a convenience. This function will not work if you
165 * use selection is GTK_SELECTION_MULTIPLE.
166 * selection:
167 * A GtkTreeSelection.
168 * model:
169 * A pointer to set to the GtkTreeModel, or NULL.
170 * iter:
171 * The GtkTreeIter, or NULL.
172 * Returns:
173 * TRUE, if there is a selected node.
175 int getSelected(TreeModel model, TreeIter iter)
177 GtkTreeModel* m = model.getTreeModelStruct();
178 return gtk_tree_selection_get_selected(gtkTreeSelection, &m, iter.getTreeIterStruct())==0 ? false : true;
182 * Creates a list of path of all selected rows. Additionally, if you are
183 * planning on modifying the model after calling this function, you may
184 * want to convert the returned list into a list of GtkTreeRowReferences.
185 * To do this, you can use gtk_tree_row_reference_new().
186 * To free the return value, use:
187 * g_list_foreach (list, gtk_tree_path_free, NULL);
188 * g_list_free (list);
189 * selection:
190 * A GtkTreeSelection.
191 * model:
192 * A pointer to set to the GtkTreeModel, or NULL.
193 * Returns:
194 * A GList containing a GtkTreePath for each selected row.
195 * Since 2.2
197 TreePath[] getSelectedRows(TreeModel model)
199 TreePath[] paths;
200 GtkTreeModel* m = model.getTreeModelStruct();
201 GList* gList = gtk_tree_selection_get_selected_rows(gtkTreeSelection, &m);
202 if ( gList !is null )
204 ListG list = new ListG(gList);
205 for ( int i=0 ; i<list.length() ; i++ )
207 paths ~= new TreePath(cast(GtkTreePath*)list.nthData(i));
210 return paths;
216 // imports for the signal processing
217 private import gobject.Signals;
218 private import gtkc.gdktypes;
219 int[char[]] connectedSignals;
221 void delegate(TreeSelection)[] onChangedListeners;
222 void addOnChanged(void delegate(TreeSelection) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
224 if ( !("changed" in connectedSignals) )
226 Signals.connectData(
227 getStruct(),
228 "changed",
229 cast(GCallback)&callBackChanged,
230 cast(void*)this,
231 null,
232 connectFlags);
233 connectedSignals["changed"] = 1;
235 onChangedListeners ~= dlg;
237 extern(C) static void callBackChanged(GtkTreeSelection* treeselectionStruct, TreeSelection treeSelection)
239 bool consumed = false;
241 foreach ( void delegate(TreeSelection) dlg ; treeSelection.onChangedListeners )
243 dlg(treeSelection);
246 return consumed;
254 * Sets the selection mode of the selection. If the previous type was
255 * GTK_SELECTION_MULTIPLE, then the anchor is kept selected, if it was
256 * previously selected.
257 * selection:
258 * A GtkTreeSelection.
259 * type:
260 * The selection mode
262 public void setMode(GtkSelectionMode type)
264 // void gtk_tree_selection_set_mode (GtkTreeSelection *selection, GtkSelectionMode type);
265 gtk_tree_selection_set_mode(gtkTreeSelection, type);
269 * Gets the selection mode for selection. See
270 * gtk_tree_selection_set_mode().
271 * selection:
272 * a GtkTreeSelection
273 * Returns:
274 * the current selection mode
276 public GtkSelectionMode getMode()
278 // GtkSelectionMode gtk_tree_selection_get_mode (GtkTreeSelection *selection);
279 return gtk_tree_selection_get_mode(gtkTreeSelection);
283 * Sets the selection function. If set, this function is called before any node
284 * is selected or unselected, giving some control over which nodes are selected.
285 * The select function should return TRUE if the state of the node may be toggled,
286 * and FALSE if the state of the node should be left unchanged.
287 * selection:
288 * A GtkTreeSelection.
289 * func:
290 * The selection function.
291 * data:
292 * The selection function's data.
293 * destroy:
294 * The destroy function for user data. May be NULL.
296 public void setSelectFunction(GtkTreeSelectionFunc func, void* data, GtkDestroyNotify destroy)
298 // void gtk_tree_selection_set_select_function (GtkTreeSelection *selection, GtkTreeSelectionFunc func, gpointer data, GtkDestroyNotify destroy);
299 gtk_tree_selection_set_select_function(gtkTreeSelection, func, data, destroy);
303 * Returns the user data for the selection function.
304 * selection:
305 * A GtkTreeSelection.
306 * Returns:
307 * The user data.
309 public void* getUserData()
311 // gpointer gtk_tree_selection_get_user_data (GtkTreeSelection *selection);
312 return gtk_tree_selection_get_user_data(gtkTreeSelection);
316 * Returns the tree view associated with selection.
317 * selection:
318 * A GtkTreeSelection
319 * Returns:
320 * A GtkTreeView
322 public TreeView getTreeView()
324 // GtkTreeView* gtk_tree_selection_get_tree_view (GtkTreeSelection *selection);
325 return new TreeView( gtk_tree_selection_get_tree_view(gtkTreeSelection) );
330 * Calls a function for each selected node. Note that you cannot modify
331 * the tree or selection from within this function. As a result,
332 * gtk_tree_selection_get_selected_rows() might be more useful.
333 * selection:
334 * A GtkTreeSelection.
335 * func:
336 * The function to call for each selected node.
337 * data:
338 * user data to pass to the function.
340 public void selectedForeach(GtkTreeSelectionForeachFunc func, void* data)
342 // void gtk_tree_selection_selected_foreach (GtkTreeSelection *selection, GtkTreeSelectionForeachFunc func, gpointer data);
343 gtk_tree_selection_selected_foreach(gtkTreeSelection, func, data);
348 * Returns the number of rows that have been selected in tree.
349 * selection:
350 * A GtkTreeSelection.
351 * Returns:
352 * The number of rows selected.
353 * Since 2.2
355 public int countSelectedRows()
357 // gint gtk_tree_selection_count_selected_rows (GtkTreeSelection *selection);
358 return gtk_tree_selection_count_selected_rows(gtkTreeSelection);
362 * Select the row at path.
363 * selection:
364 * A GtkTreeSelection.
365 * path:
366 * The GtkTreePath to be selected.
368 public void selectPath(TreePath path)
370 // void gtk_tree_selection_select_path (GtkTreeSelection *selection, GtkTreePath *path);
371 gtk_tree_selection_select_path(gtkTreeSelection, (path is null) ? null : path.getTreePathStruct());
375 * Unselects the row at path.
376 * selection:
377 * A GtkTreeSelection.
378 * path:
379 * The GtkTreePath to be unselected.
381 public void unselectPath(TreePath path)
383 // void gtk_tree_selection_unselect_path (GtkTreeSelection *selection, GtkTreePath *path);
384 gtk_tree_selection_unselect_path(gtkTreeSelection, (path is null) ? null : path.getTreePathStruct());
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 * selection:
391 * A GtkTreeSelection.
392 * path:
393 * A GtkTreePath to check selection on.
394 * Returns:
395 * TRUE if path is selected.
397 public int pathIsSelected(TreePath path)
399 // gboolean gtk_tree_selection_path_is_selected (GtkTreeSelection *selection, GtkTreePath *path);
400 return gtk_tree_selection_path_is_selected(gtkTreeSelection, (path is null) ? null : path.getTreePathStruct());
404 * Selects the specified iterator.
405 * selection:
406 * A GtkTreeSelection.
407 * iter:
408 * The GtkTreeIter to be selected.
410 public void selectIter(TreeIter iter)
412 // void gtk_tree_selection_select_iter (GtkTreeSelection *selection, GtkTreeIter *iter);
413 gtk_tree_selection_select_iter(gtkTreeSelection, (iter is null) ? null : iter.getTreeIterStruct());
417 * Unselects the specified iterator.
418 * selection:
419 * A GtkTreeSelection.
420 * iter:
421 * The GtkTreeIter to be unselected.
423 public void unselectIter(TreeIter iter)
425 // void gtk_tree_selection_unselect_iter (GtkTreeSelection *selection, GtkTreeIter *iter);
426 gtk_tree_selection_unselect_iter(gtkTreeSelection, (iter is null) ? null : iter.getTreeIterStruct());
430 * Returns TRUE if the row at iter is currently selected.
431 * selection:
432 * A GtkTreeSelection
433 * iter:
434 * A valid GtkTreeIter
435 * Returns:
436 * TRUE, if iter is selected
438 public int iterIsSelected(TreeIter iter)
440 // gboolean gtk_tree_selection_iter_is_selected (GtkTreeSelection *selection, GtkTreeIter *iter);
441 return gtk_tree_selection_iter_is_selected(gtkTreeSelection, (iter is null) ? null : iter.getTreeIterStruct());
445 * Selects all the nodes. selection must be set to GTK_SELECTION_MULTIPLE
446 * mode.
447 * selection:
448 * A GtkTreeSelection.
450 public void selectAll()
452 // void gtk_tree_selection_select_all (GtkTreeSelection *selection);
453 gtk_tree_selection_select_all(gtkTreeSelection);
457 * Unselects all the nodes.
458 * selection:
459 * A GtkTreeSelection.
461 public void unselectAll()
463 // void gtk_tree_selection_unselect_all (GtkTreeSelection *selection);
464 gtk_tree_selection_unselect_all(gtkTreeSelection);
468 * Selects a range of nodes, determined by start_path and end_path inclusive.
469 * selection must be set to GTK_SELECTION_MULTIPLE mode.
470 * selection:
471 * A GtkTreeSelection.
472 * start_path:
473 * The initial node of the range.
474 * end_path:
475 * The final node of the range.
477 public void selectRange(TreePath startPath, TreePath endPath)
479 // void gtk_tree_selection_select_range (GtkTreeSelection *selection, GtkTreePath *start_path, GtkTreePath *end_path);
480 gtk_tree_selection_select_range(gtkTreeSelection, (startPath is null) ? null : startPath.getTreePathStruct(), (endPath is null) ? null : endPath.getTreePathStruct());
484 * Unselects a range of nodes, determined by start_path and end_path
485 * inclusive.
486 * selection:
487 * A GtkTreeSelection.
488 * start_path:
489 * The initial node of the range.
490 * end_path:
491 * The initial node of the range.
492 * Since 2.2
493 * Signal Details
494 * The "changed" signal
495 * void user_function (GtkTreeSelection *treeselection,
496 * gpointer user_data) : Run First
497 * Emitted whenever the selection has (possibly) changed. Please note that
498 * this signal is mostly a hint. It may only be emitted once when a range
499 * of rows are selected, and it may occasionally be emitted when nothing
500 * has happened.
501 * treeselection:
502 * the object which received the signal.
503 * user_data:
504 * user data set when the signal handler was connected.
505 * See Also
506 * GtkTreeView, GtkTreeViewColumn, GtkTreeDnd, GtkTreeMode, GtkTreeSortable, GtkTreeModelSort, GtkListStore, GtkTreeStore, GtkCellRenderer, GtkCellEditable, GtkCellRendererPixbuf, GtkCellRendererText, GtkCellRendererToggle
508 public void unselectRange(TreePath startPath, TreePath endPath)
510 // void gtk_tree_selection_unselect_range (GtkTreeSelection *selection, GtkTreePath *start_path, GtkTreePath *end_path);
511 gtk_tree_selection_unselect_range(gtkTreeSelection, (startPath is null) ? null : startPath.getTreePathStruct(), (endPath is null) ? null : endPath.getTreePathStruct());