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