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 75 private import gtk.TreeView; 76 private import gtk.TreeModel; 77 private import gtk.TreeModelIF; 78 private import gtk.TreeIter; 79 private import glib.ListG; 80 private import gtk.TreePath; 81 82 83 84 private import gobject.ObjectG; 85 86 /** 87 * The GtkTreeSelection object is a helper object to manage the selection 88 * for a GtkTreeView widget. The GtkTreeSelection object is 89 * automatically created when a new GtkTreeView widget is created, and 90 * cannot exist independentally of this widget. The primary reason the 91 * GtkTreeSelection objects exists is for cleanliness of code and API. 92 * That is, there is no conceptual reason all these functions could not be 93 * methods on the GtkTreeView widget instead of a separate function. 94 * 95 * The GtkTreeSelection object is gotten from a GtkTreeView by calling 96 * gtk_tree_view_get_selection(). It can be manipulated to check the 97 * selection status of the tree, as well as select and deselect individual 98 * rows. Selection is done completely view side. As a result, multiple 99 * views of the same model can have completely different selections. 100 * Additionally, you cannot change the selection of a row on the model that 101 * is not currently displayed by the view without expanding its parents 102 * first. 103 * 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. 106 * That is, it may only emit one signal when a range of rows is selected. 107 * Additionally, it may on occasion emit a "changed" signal 108 * when nothing has happened (mostly as a result of programmers calling 109 * select_row on an already selected row). 110 */ 111 public class TreeSelection : ObjectG 112 { 113 114 /** the main Gtk struct */ 115 protected GtkTreeSelection* gtkTreeSelection; 116 117 118 public GtkTreeSelection* getTreeSelectionStruct() 119 { 120 return gtkTreeSelection; 121 } 122 123 124 /** the main Gtk struct as a void* */ 125 protected override void* getStruct() 126 { 127 return cast(void*)gtkTreeSelection; 128 } 129 130 /** 131 * Sets our main struct and passes it to the parent class 132 */ 133 public this (GtkTreeSelection* gtkTreeSelection) 134 { 135 super(cast(GObject*)gtkTreeSelection); 136 this.gtkTreeSelection = gtkTreeSelection; 137 } 138 139 protected override void setStruct(GObject* obj) 140 { 141 super.setStruct(obj); 142 gtkTreeSelection = cast(GtkTreeSelection*)obj; 143 } 144 145 /** 146 * Returns an TreeIter set to the currently selected node if selection 147 * is set to GTK_SELECTION_SINGLE or GTK_SELECTION_BROWSE. 148 * This function will not work if you use selection is GTK_SELECTION_MULTIPLE. 149 * Returns: A TreeIter for the selected node. 150 */ 151 public TreeIter getSelected() 152 { 153 TreeModelIF model; 154 TreeIter iter = new TreeIter(); 155 156 if ( getSelected(model, iter) ) 157 { 158 iter.setModel(model); 159 return iter; 160 } 161 else 162 { 163 return null; 164 } 165 } 166 167 /** 168 * Creates a list of path of all selected rows. Additionally, if you are 169 * planning on modifying the model after calling this function, you may 170 * want to convert the returned list into a list of GtkTreeRowReferences. 171 * To do this, you can use gtk_tree_row_reference_new(). 172 * To free the return value, use: 173 * g_list_foreach (list, gtk_tree_path_free, NULL); 174 * g_list_free (list); 175 * Since 2.2 176 * Params: 177 * model = A pointer to set to the GtkTreeModel, or NULL. 178 * Returns: 179 * A GList containing a GtkTreePath for each selected row. 180 */ 181 TreePath[] getSelectedRows(out TreeModelIF model) 182 { 183 TreePath[] paths; 184 GtkTreeModel* outmodel = null; 185 GList* gList = gtk_tree_selection_get_selected_rows(gtkTreeSelection, &outmodel); 186 if ( gList !is null ) 187 { 188 ListG list = new ListG(gList); 189 for ( int i=0 ; i<list.length() ; i++ ) 190 { 191 paths ~= new TreePath(cast(GtkTreePath*)list.nthData(i)); 192 } 193 } 194 model = ObjectG.getDObject!(TreeModel, TreeModelIF)(outmodel); 195 196 return paths; 197 } 198 199 /** 200 */ 201 int[string] connectedSignals; 202 203 void delegate(TreeSelection)[] onChangedListeners; 204 /** 205 * Emitted whenever the selection has (possibly) changed. Please note that 206 * this signal is mostly a hint. It may only be emitted once when a range 207 * of rows are selected, and it may occasionally be emitted when nothing 208 * has happened. 209 * See Also 210 * GtkTreeView, GtkTreeViewColumn, GtkTreeDnd, GtkTreeMode, 211 * GtkTreeSortable, GtkTreeModelSort, GtkListStore, GtkTreeStore, 212 * GtkCellRenderer, GtkCellEditable, GtkCellRendererPixbuf, 213 * GtkCellRendererText, GtkCellRendererToggle 214 */ 215 void addOnChanged(void delegate(TreeSelection) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 216 { 217 if ( !("changed" in connectedSignals) ) 218 { 219 Signals.connectData( 220 getStruct(), 221 "changed", 222 cast(GCallback)&callBackChanged, 223 cast(void*)this, 224 null, 225 connectFlags); 226 connectedSignals["changed"] = 1; 227 } 228 onChangedListeners ~= dlg; 229 } 230 extern(C) static void callBackChanged(GtkTreeSelection* treeselectionStruct, TreeSelection _treeSelection) 231 { 232 foreach ( void delegate(TreeSelection) dlg ; _treeSelection.onChangedListeners ) 233 { 234 dlg(_treeSelection); 235 } 236 } 237 238 239 /** 240 * Sets the selection mode of the selection. If the previous type was 241 * GTK_SELECTION_MULTIPLE, then the anchor is kept selected, if it was 242 * previously selected. 243 * Params: 244 * type = The selection mode 245 */ 246 public void setMode(GtkSelectionMode type) 247 { 248 // void gtk_tree_selection_set_mode (GtkTreeSelection *selection, GtkSelectionMode type); 249 gtk_tree_selection_set_mode(gtkTreeSelection, type); 250 } 251 252 /** 253 * Gets the selection mode for selection. See 254 * gtk_tree_selection_set_mode(). 255 * Returns: the current selection mode 256 */ 257 public GtkSelectionMode getMode() 258 { 259 // GtkSelectionMode gtk_tree_selection_get_mode (GtkTreeSelection *selection); 260 return gtk_tree_selection_get_mode(gtkTreeSelection); 261 } 262 263 /** 264 * Sets the selection function. 265 * If set, this function is called before any node is selected or unselected, 266 * giving some control over which nodes are selected. The select function 267 * should return TRUE if the state of the node may be toggled, and FALSE 268 * if the state of the node should be left unchanged. 269 * Params: 270 * func = The selection function. May be NULL 271 * data = The selection function's data. May be NULL 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 * Params: 471 * startPath = The initial node of the range. 472 * endPath = The initial node of the range. 473 */ 474 public void unselectRange(TreePath startPath, TreePath endPath) 475 { 476 // void gtk_tree_selection_unselect_range (GtkTreeSelection *selection, GtkTreePath *start_path, GtkTreePath *end_path); 477 gtk_tree_selection_unselect_range(gtkTreeSelection, (startPath is null) ? null : startPath.getTreePathStruct(), (endPath is null) ? null : endPath.getTreePathStruct()); 478 } 479 }