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.TreeModelFilter; 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.c.functions; 37 public import gtk.c.types; 38 public import gtkc.gtktypes; 39 40 41 /** 42 * A #GtkTreeModelFilter is a tree model which wraps another tree model, 43 * and can do the following things: 44 * 45 * - Filter specific rows, based on data from a “visible column”, a column 46 * storing booleans indicating whether the row should be filtered or not, 47 * or based on the return value of a “visible function”, which gets a 48 * model, iter and user_data and returns a boolean indicating whether the 49 * row should be filtered or not. 50 * 51 * - Modify the “appearance” of the model, using a modify function. 52 * This is extremely powerful and allows for just changing some 53 * values and also for creating a completely different model based 54 * on the given child model. 55 * 56 * - Set a different root node, also known as a “virtual root”. You can pass 57 * in a #GtkTreePath indicating the root node for the filter at construction 58 * time. 59 * 60 * The basic API is similar to #GtkTreeModelSort. For an example on its usage, 61 * see the section on #GtkTreeModelSort. 62 * 63 * When using #GtkTreeModelFilter, it is important to realize that 64 * #GtkTreeModelFilter maintains an internal cache of all nodes which are 65 * visible in its clients. The cache is likely to be a subtree of the tree 66 * exposed by the child model. #GtkTreeModelFilter will not cache the entire 67 * child model when unnecessary to not compromise the caching mechanism 68 * that is exposed by the reference counting scheme. If the child model 69 * implements reference counting, unnecessary signals may not be emitted 70 * because of reference counting rule 3, see the #GtkTreeModel 71 * documentation. (Note that e.g. #GtkTreeStore does not implement 72 * reference counting and will always emit all signals, even when 73 * the receiving node is not visible). 74 * 75 * Because of this, limitations for possible visible functions do apply. 76 * In general, visible functions should only use data or properties from 77 * the node for which the visibility state must be determined, its siblings 78 * or its parents. Usually, having a dependency on the state of any child 79 * node is not possible, unless references are taken on these explicitly. 80 * When no such reference exists, no signals may be received for these child 81 * nodes (see reference couting rule number 3 in the #GtkTreeModel section). 82 * 83 * Determining the visibility state of a given node based on the state 84 * of its child nodes is a frequently occurring use case. Therefore, 85 * #GtkTreeModelFilter explicitly supports this. For example, when a node 86 * does not have any children, you might not want the node to be visible. 87 * As soon as the first row is added to the node’s child level (or the 88 * last row removed), the node’s visibility should be updated. 89 * 90 * This introduces a dependency from the node on its child nodes. In order 91 * to accommodate this, #GtkTreeModelFilter must make sure the necessary 92 * signals are received from the child model. This is achieved by building, 93 * for all nodes which are exposed as visible nodes to #GtkTreeModelFilter's 94 * clients, the child level (if any) and take a reference on the first node 95 * in this level. Furthermore, for every row-inserted, row-changed or 96 * row-deleted signal (also these which were not handled because the node 97 * was not cached), #GtkTreeModelFilter will check if the visibility state 98 * of any parent node has changed. 99 * 100 * Beware, however, that this explicit support is limited to these two 101 * cases. For example, if you want a node to be visible only if two nodes 102 * in a child’s child level (2 levels deeper) are visible, you are on your 103 * own. In this case, either rely on #GtkTreeStore to emit all signals 104 * because it does not implement reference counting, or for models that 105 * do implement reference counting, obtain references on these child levels 106 * yourself. 107 */ 108 public class TreeModelFilter : ObjectG, TreeDragSourceIF, TreeModelIF 109 { 110 /** the main Gtk struct */ 111 protected GtkTreeModelFilter* gtkTreeModelFilter; 112 113 /** Get the main Gtk struct */ 114 public GtkTreeModelFilter* getTreeModelFilterStruct(bool transferOwnership = false) 115 { 116 if (transferOwnership) 117 ownedRef = false; 118 return gtkTreeModelFilter; 119 } 120 121 /** the main Gtk struct as a void* */ 122 protected override void* getStruct() 123 { 124 return cast(void*)gtkTreeModelFilter; 125 } 126 127 /** 128 * Sets our main struct and passes it to the parent class. 129 */ 130 public this (GtkTreeModelFilter* gtkTreeModelFilter, bool ownedRef = false) 131 { 132 this.gtkTreeModelFilter = gtkTreeModelFilter; 133 super(cast(GObject*)gtkTreeModelFilter, ownedRef); 134 } 135 136 // add the TreeDragSource capabilities 137 mixin TreeDragSourceT!(GtkTreeModelFilter); 138 139 // add the TreeModel capabilities 140 mixin TreeModelT!(GtkTreeModelFilter); 141 142 143 /** */ 144 public static GType getType() 145 { 146 return gtk_tree_model_filter_get_type(); 147 } 148 149 /** 150 * This function should almost never be called. It clears the @filter 151 * of any cached iterators that haven’t been reffed with 152 * gtk_tree_model_ref_node(). This might be useful if the child model 153 * being filtered is static (and doesn’t change often) and there has been 154 * a lot of unreffed access to nodes. As a side effect of this function, 155 * all unreffed iters will be invalid. 156 * 157 * Since: 2.4 158 */ 159 public void clearCache() 160 { 161 gtk_tree_model_filter_clear_cache(gtkTreeModelFilter); 162 } 163 164 /** 165 * Sets @filter_iter to point to the row in @filter that corresponds to the 166 * row pointed at by @child_iter. If @filter_iter was not set, %FALSE is 167 * returned. 168 * 169 * Params: 170 * filterIter = An uninitialized #GtkTreeIter. 171 * childIter = A valid #GtkTreeIter pointing to a row on the child model. 172 * 173 * Returns: %TRUE, if @filter_iter was set, i.e. if @child_iter is a 174 * valid iterator pointing to a visible row in child model. 175 * 176 * Since: 2.4 177 */ 178 public bool convertChildIterToIter(out TreeIter filterIter, TreeIter childIter) 179 { 180 GtkTreeIter* outfilterIter = sliceNew!GtkTreeIter(); 181 182 auto p = gtk_tree_model_filter_convert_child_iter_to_iter(gtkTreeModelFilter, outfilterIter, (childIter is null) ? null : childIter.getTreeIterStruct()) != 0; 183 184 filterIter = ObjectG.getDObject!(TreeIter)(outfilterIter, true); 185 186 return p; 187 } 188 189 /** 190 * Converts @child_path to a path relative to @filter. That is, @child_path 191 * points to a path in the child model. The rerturned path will point to the 192 * same row in the filtered model. If @child_path isn’t a valid path on the 193 * child model or points to a row which is not visible in @filter, then %NULL 194 * is returned. 195 * 196 * Params: 197 * childPath = A #GtkTreePath to convert. 198 * 199 * Returns: A newly allocated #GtkTreePath, or %NULL. 200 * 201 * Since: 2.4 202 */ 203 public TreePath convertChildPathToPath(TreePath childPath) 204 { 205 auto p = gtk_tree_model_filter_convert_child_path_to_path(gtkTreeModelFilter, (childPath is null) ? null : childPath.getTreePathStruct()); 206 207 if(p is null) 208 { 209 return null; 210 } 211 212 return ObjectG.getDObject!(TreePath)(cast(GtkTreePath*) p, true); 213 } 214 215 /** 216 * Sets @child_iter to point to the row pointed to by @filter_iter. 217 * 218 * Params: 219 * childIter = An uninitialized #GtkTreeIter. 220 * filterIter = A valid #GtkTreeIter pointing to a row on @filter. 221 * 222 * Since: 2.4 223 */ 224 public void convertIterToChildIter(out TreeIter childIter, TreeIter filterIter) 225 { 226 GtkTreeIter* outchildIter = sliceNew!GtkTreeIter(); 227 228 gtk_tree_model_filter_convert_iter_to_child_iter(gtkTreeModelFilter, outchildIter, (filterIter is null) ? null : filterIter.getTreeIterStruct()); 229 230 childIter = ObjectG.getDObject!(TreeIter)(outchildIter, true); 231 } 232 233 /** 234 * Converts @filter_path to a path on the child model of @filter. That is, 235 * @filter_path points to a location in @filter. The returned path will 236 * point to the same location in the model not being filtered. If @filter_path 237 * does not point to a location in the child model, %NULL is returned. 238 * 239 * Params: 240 * filterPath = A #GtkTreePath to convert. 241 * 242 * Returns: A newly allocated #GtkTreePath, or %NULL. 243 * 244 * Since: 2.4 245 */ 246 public TreePath convertPathToChildPath(TreePath filterPath) 247 { 248 auto p = gtk_tree_model_filter_convert_path_to_child_path(gtkTreeModelFilter, (filterPath is null) ? null : filterPath.getTreePathStruct()); 249 250 if(p is null) 251 { 252 return null; 253 } 254 255 return ObjectG.getDObject!(TreePath)(cast(GtkTreePath*) p, true); 256 } 257 258 /** 259 * Returns a pointer to the child model of @filter. 260 * 261 * Returns: A pointer to a #GtkTreeModel. 262 * 263 * Since: 2.4 264 */ 265 public TreeModelIF getModel() 266 { 267 auto p = gtk_tree_model_filter_get_model(gtkTreeModelFilter); 268 269 if(p is null) 270 { 271 return null; 272 } 273 274 return ObjectG.getDObject!(TreeModelIF)(cast(GtkTreeModel*) p); 275 } 276 277 /** 278 * Emits ::row_changed for each row in the child model, which causes 279 * the filter to re-evaluate whether a row is visible or not. 280 * 281 * Since: 2.4 282 */ 283 public void refilter() 284 { 285 gtk_tree_model_filter_refilter(gtkTreeModelFilter); 286 } 287 288 /** 289 * With the @n_columns and @types parameters, you give an array of column 290 * types for this model (which will be exposed to the parent model/view). 291 * The @func, @data and @destroy parameters are for specifying the modify 292 * function. The modify function will get called for each 293 * data access, the goal of the modify function is to return the data which 294 * should be displayed at the location specified using the parameters of the 295 * modify function. 296 * 297 * Note that gtk_tree_model_filter_set_modify_func() 298 * can only be called once for a given filter model. 299 * 300 * Params: 301 * types = The #GTypes of the columns. 302 * func = A #GtkTreeModelFilterModifyFunc 303 * data = User data to pass to the modify function, or %NULL. 304 * destroy = Destroy notifier of @data, or %NULL. 305 * 306 * Since: 2.4 307 */ 308 public void setModifyFunc(GType[] types, GtkTreeModelFilterModifyFunc func, void* data, GDestroyNotify destroy) 309 { 310 gtk_tree_model_filter_set_modify_func(gtkTreeModelFilter, cast(int)types.length, types.ptr, func, data, destroy); 311 } 312 313 /** 314 * Sets @column of the child_model to be the column where @filter should 315 * look for visibility information. @columns should be a column of type 316 * %G_TYPE_BOOLEAN, where %TRUE means that a row is visible, and %FALSE 317 * if not. 318 * 319 * Note that gtk_tree_model_filter_set_visible_func() or 320 * gtk_tree_model_filter_set_visible_column() can only be called 321 * once for a given filter model. 322 * 323 * Params: 324 * column = A #gint which is the column containing the visible information 325 * 326 * Since: 2.4 327 */ 328 public void setVisibleColumn(int column) 329 { 330 gtk_tree_model_filter_set_visible_column(gtkTreeModelFilter, column); 331 } 332 333 /** 334 * Sets the visible function used when filtering the @filter to be @func. 335 * The function should return %TRUE if the given row should be visible and 336 * %FALSE otherwise. 337 * 338 * If the condition calculated by the function changes over time (e.g. 339 * because it depends on some global parameters), you must call 340 * gtk_tree_model_filter_refilter() to keep the visibility information 341 * of the model up-to-date. 342 * 343 * Note that @func is called whenever a row is inserted, when it may still 344 * be empty. The visible function should therefore take special care of empty 345 * rows, like in the example below. 346 * 347 * |[<!-- language="C" --> 348 * static gboolean 349 * visible_func (GtkTreeModel *model, 350 * GtkTreeIter *iter, 351 * gpointer data) 352 * { 353 * // Visible if row is non-empty and first column is “HI” 354 * gchar *str; 355 * gboolean visible = FALSE; 356 * 357 * gtk_tree_model_get (model, iter, 0, &str, -1); 358 * if (str && strcmp (str, "HI") == 0) 359 * visible = TRUE; 360 * g_free (str); 361 * 362 * return visible; 363 * } 364 * ]| 365 * 366 * Note that gtk_tree_model_filter_set_visible_func() or 367 * gtk_tree_model_filter_set_visible_column() can only be called 368 * once for a given filter model. 369 * 370 * Params: 371 * func = A #GtkTreeModelFilterVisibleFunc, the visible function 372 * data = User data to pass to the visible function, or %NULL 373 * destroy = Destroy notifier of @data, or %NULL 374 * 375 * Since: 2.4 376 */ 377 public void setVisibleFunc(GtkTreeModelFilterVisibleFunc func, void* data, GDestroyNotify destroy) 378 { 379 gtk_tree_model_filter_set_visible_func(gtkTreeModelFilter, func, data, destroy); 380 } 381 382 /** 383 * Creates a new #GtkTreeModel, with @child_model as the child_model 384 * and @root as the virtual root. 385 * 386 * Params: 387 * childModel = A #GtkTreeModel. 388 * root = A #GtkTreePath or %NULL. 389 * 390 * Returns: A new #GtkTreeModel. 391 * 392 * Since: 2.4 393 * 394 * Throws: ConstructionException GTK+ fails to create the object. 395 */ 396 public this(TreeModelIF childModel, TreePath root) 397 { 398 auto p = gtk_tree_model_filter_new((childModel is null) ? null : childModel.getTreeModelStruct(), (root is null) ? null : root.getTreePathStruct()); 399 400 if(p is null) 401 { 402 throw new ConstructionException("null returned by new"); 403 } 404 405 this(cast(GtkTreeModelFilter*) p, true); 406 } 407 }