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