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 gtk.TreeModelSort; 26 27 private import glib.ConstructionException; 28 private import glib.MemorySlice; 29 private import gobject.ObjectG; 30 private import gtk.TreeDragSourceIF; 31 private import gtk.TreeDragSourceT; 32 private import gtk.TreeIter; 33 private import gtk.TreeModelIF; 34 private import gtk.TreeModelT; 35 private import gtk.TreePath; 36 private import gtk.TreeSortableIF; 37 private import gtk.TreeSortableT; 38 private import gtk.c.functions; 39 public import gtk.c.types; 40 41 42 /** 43 * A GtkTreeModel which makes an underlying tree model sortable 44 * 45 * The #GtkTreeModelSort is a model which implements the #GtkTreeSortable 46 * interface. It does not hold any data itself, but rather is created with 47 * a child model and proxies its data. It has identical column types to 48 * this child model, and the changes in the child are propagated. The 49 * primary purpose of this model is to provide a way to sort a different 50 * model without modifying it. Note that the sort function used by 51 * #GtkTreeModelSort is not guaranteed to be stable. 52 * 53 * The use of this is best demonstrated through an example. In the 54 * following sample code we create two #GtkTreeView widgets each with a 55 * view of the same data. As the model is wrapped here by a 56 * #GtkTreeModelSort, the two #GtkTreeViews can each sort their 57 * view of the data without affecting the other. By contrast, if we 58 * simply put the same model in each widget, then sorting the first would 59 * sort the second. 60 * 61 * ## Using a #GtkTreeModelSort 62 * 63 * |[<!-- language="C" --> 64 * { 65 * GtkTreeView *tree_view1; 66 * GtkTreeView *tree_view2; 67 * GtkTreeModel *sort_model1; 68 * GtkTreeModel *sort_model2; 69 * GtkTreeModel *child_model; 70 * 71 * // get the child model 72 * child_model = get_my_model (); 73 * 74 * // Create the first tree 75 * sort_model1 = gtk_tree_model_sort_new_with_model (child_model); 76 * tree_view1 = gtk_tree_view_new_with_model (sort_model1); 77 * 78 * // Create the second tree 79 * sort_model2 = gtk_tree_model_sort_new_with_model (child_model); 80 * tree_view2 = gtk_tree_view_new_with_model (sort_model2); 81 * 82 * // Now we can sort the two models independently 83 * gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model1), 84 * COLUMN_1, GTK_SORT_ASCENDING); 85 * gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model2), 86 * COLUMN_1, GTK_SORT_DESCENDING); 87 * } 88 * ]| 89 * 90 * To demonstrate how to access the underlying child model from the sort 91 * model, the next example will be a callback for the #GtkTreeSelection 92 * #GtkTreeSelection::changed signal. In this callback, we get a string 93 * from COLUMN_1 of the model. We then modify the string, find the same 94 * selected row on the child model, and change the row there. 95 * 96 * ## Accessing the child model of in a selection changed callback 97 * 98 * |[<!-- language="C" --> 99 * void 100 * selection_changed (GtkTreeSelection *selection, gpointer data) 101 * { 102 * GtkTreeModel *sort_model = NULL; 103 * GtkTreeModel *child_model; 104 * GtkTreeIter sort_iter; 105 * GtkTreeIter child_iter; 106 * char *some_data = NULL; 107 * char *modified_data; 108 * 109 * // Get the current selected row and the model. 110 * if (! gtk_tree_selection_get_selected (selection, 111 * &sort_model, 112 * &sort_iter)) 113 * return; 114 * 115 * // Look up the current value on the selected row and get 116 * // a new value to change it to. 117 * gtk_tree_model_get (GTK_TREE_MODEL (sort_model), &sort_iter, 118 * COLUMN_1, &some_data, 119 * -1); 120 * 121 * modified_data = change_the_data (some_data); 122 * g_free (some_data); 123 * 124 * // Get an iterator on the child model, instead of the sort model. 125 * gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (sort_model), 126 * &child_iter, 127 * &sort_iter); 128 * 129 * // Get the child model and change the value of the row. In this 130 * // example, the child model is a GtkListStore. It could be any other 131 * // type of model, though. 132 * child_model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model)); 133 * gtk_list_store_set (GTK_LIST_STORE (child_model), &child_iter, 134 * COLUMN_1, &modified_data, 135 * -1); 136 * g_free (modified_data); 137 * } 138 * ]| 139 */ 140 public class TreeModelSort : ObjectG, TreeDragSourceIF, TreeModelIF, TreeSortableIF 141 { 142 /** the main Gtk struct */ 143 protected GtkTreeModelSort* gtkTreeModelSort; 144 145 /** Get the main Gtk struct */ 146 public GtkTreeModelSort* getTreeModelSortStruct(bool transferOwnership = false) 147 { 148 if (transferOwnership) 149 ownedRef = false; 150 return gtkTreeModelSort; 151 } 152 153 /** the main Gtk struct as a void* */ 154 protected override void* getStruct() 155 { 156 return cast(void*)gtkTreeModelSort; 157 } 158 159 /** 160 * Sets our main struct and passes it to the parent class. 161 */ 162 public this (GtkTreeModelSort* gtkTreeModelSort, bool ownedRef = false) 163 { 164 this.gtkTreeModelSort = gtkTreeModelSort; 165 super(cast(GObject*)gtkTreeModelSort, ownedRef); 166 } 167 168 // add the TreeDragSource capabilities 169 mixin TreeDragSourceT!(GtkTreeModelSort); 170 171 // add the TreeModel capabilities 172 mixin TreeModelT!(GtkTreeModelSort); 173 174 // add the TreeSortable capabilities 175 mixin TreeSortableT!(GtkTreeModelSort); 176 177 178 /** */ 179 public static GType getType() 180 { 181 return gtk_tree_model_sort_get_type(); 182 } 183 184 /** 185 * Creates a new #GtkTreeModelSort, with @child_model as the child model. 186 * 187 * Params: 188 * childModel = A #GtkTreeModel 189 * 190 * Returns: A new #GtkTreeModelSort. 191 * 192 * Throws: ConstructionException GTK+ fails to create the object. 193 */ 194 public this(TreeModelIF childModel) 195 { 196 auto __p = gtk_tree_model_sort_new_with_model((childModel is null) ? null : childModel.getTreeModelStruct()); 197 198 if(__p is null) 199 { 200 throw new ConstructionException("null returned by new_with_model"); 201 } 202 203 this(cast(GtkTreeModelSort*) __p, true); 204 } 205 206 /** 207 * This function should almost never be called. It clears the @tree_model_sort 208 * of any cached iterators that haven’t been reffed with 209 * gtk_tree_model_ref_node(). This might be useful if the child model being 210 * sorted is static (and doesn’t change often) and there has been a lot of 211 * unreffed access to nodes. As a side effect of this function, all unreffed 212 * iters will be invalid. 213 */ 214 public void clearCache() 215 { 216 gtk_tree_model_sort_clear_cache(gtkTreeModelSort); 217 } 218 219 /** 220 * Sets @sort_iter to point to the row in @tree_model_sort that corresponds to 221 * the row pointed at by @child_iter. If @sort_iter was not set, %FALSE 222 * is returned. Note: a boolean is only returned since 2.14. 223 * 224 * Params: 225 * sortIter = An uninitialized #GtkTreeIter. 226 * childIter = A valid #GtkTreeIter pointing to a row on the child model 227 * 228 * Returns: %TRUE, if @sort_iter was set, i.e. if @sort_iter is a 229 * valid iterator pointer to a visible row in the child model. 230 */ 231 public bool convertChildIterToIter(out TreeIter sortIter, TreeIter childIter) 232 { 233 GtkTreeIter* outsortIter = sliceNew!GtkTreeIter(); 234 235 auto __p = gtk_tree_model_sort_convert_child_iter_to_iter(gtkTreeModelSort, outsortIter, (childIter is null) ? null : childIter.getTreeIterStruct()) != 0; 236 237 sortIter = ObjectG.getDObject!(TreeIter)(outsortIter, true); 238 239 return __p; 240 } 241 242 /** 243 * Converts @child_path to a path relative to @tree_model_sort. That is, 244 * @child_path points to a path in the child model. The returned path will 245 * point to the same row in the sorted model. If @child_path isn’t a valid 246 * path on the child model, then %NULL is returned. 247 * 248 * Params: 249 * childPath = A #GtkTreePath to convert 250 * 251 * Returns: A newly allocated #GtkTreePath, or %NULL 252 */ 253 public TreePath convertChildPathToPath(TreePath childPath) 254 { 255 auto __p = gtk_tree_model_sort_convert_child_path_to_path(gtkTreeModelSort, (childPath is null) ? null : childPath.getTreePathStruct()); 256 257 if(__p is null) 258 { 259 return null; 260 } 261 262 return ObjectG.getDObject!(TreePath)(cast(GtkTreePath*) __p, true); 263 } 264 265 /** 266 * Sets @child_iter to point to the row pointed to by @sorted_iter. 267 * 268 * Params: 269 * childIter = An uninitialized #GtkTreeIter 270 * sortedIter = A valid #GtkTreeIter pointing to a row on @tree_model_sort. 271 */ 272 public void convertIterToChildIter(out TreeIter childIter, TreeIter sortedIter) 273 { 274 GtkTreeIter* outchildIter = sliceNew!GtkTreeIter(); 275 276 gtk_tree_model_sort_convert_iter_to_child_iter(gtkTreeModelSort, outchildIter, (sortedIter is null) ? null : sortedIter.getTreeIterStruct()); 277 278 childIter = ObjectG.getDObject!(TreeIter)(outchildIter, true); 279 } 280 281 /** 282 * Converts @sorted_path to a path on the child model of @tree_model_sort. 283 * That is, @sorted_path points to a location in @tree_model_sort. The 284 * returned path will point to the same location in the model not being 285 * sorted. If @sorted_path does not point to a location in the child model, 286 * %NULL is returned. 287 * 288 * Params: 289 * sortedPath = A #GtkTreePath to convert 290 * 291 * Returns: A newly allocated #GtkTreePath, or %NULL 292 */ 293 public TreePath convertPathToChildPath(TreePath sortedPath) 294 { 295 auto __p = gtk_tree_model_sort_convert_path_to_child_path(gtkTreeModelSort, (sortedPath is null) ? null : sortedPath.getTreePathStruct()); 296 297 if(__p is null) 298 { 299 return null; 300 } 301 302 return ObjectG.getDObject!(TreePath)(cast(GtkTreePath*) __p, true); 303 } 304 305 /** 306 * Returns the model the #GtkTreeModelSort is sorting. 307 * 308 * Returns: the "child model" being sorted 309 */ 310 public TreeModelIF getModel() 311 { 312 auto __p = gtk_tree_model_sort_get_model(gtkTreeModelSort); 313 314 if(__p is null) 315 { 316 return null; 317 } 318 319 return ObjectG.getDObject!(TreeModelIF)(cast(GtkTreeModel*) __p); 320 } 321 322 /** 323 * > This function is slow. Only use it for debugging and/or testing 324 * > purposes. 325 * 326 * Checks if the given iter is a valid iter for this #GtkTreeModelSort. 327 * 328 * Params: 329 * iter = A #GtkTreeIter. 330 * 331 * Returns: %TRUE if the iter is valid, %FALSE if the iter is invalid. 332 */ 333 public bool iterIsValid(TreeIter iter) 334 { 335 return gtk_tree_model_sort_iter_is_valid(gtkTreeModelSort, (iter is null) ? null : iter.getTreeIterStruct()) != 0; 336 } 337 338 /** 339 * This resets the default sort function to be in the “unsorted” state. That 340 * is, it is in the same order as the child model. It will re-sort the model 341 * to be in the same order as the child model only if the #GtkTreeModelSort 342 * is in “unsorted” state. 343 */ 344 public void resetDefaultSortFunc() 345 { 346 gtk_tree_model_sort_reset_default_sort_func(gtkTreeModelSort); 347 } 348 }