PageRenderTime 18ms CodeModel.GetById 13ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/src/wrappers/gtk/library/gtk_tree_model_filter.e

http://github.com/tybor/Liberty
Specman e | 315 lines | 118 code | 58 blank | 139 comment | 4 complexity | c9b5c2eaa1ae284a706b2eeba3b59634 MD5 | raw file
  1indexing
  2	description: "GtkTreeModelFilter - a GtkTreeModel which hides parts of an underlying tree model."
  3	copyright: "[
  4					Copyright (C) 2006 Paolo Redaelli, GTK+ team
  5					
  6					This library is free software; you can redistribute it and/or
  7					modify it under the terms of the GNU Lesser General Public License
  8					as published by the Free Software Foundation; either version 2.1 of
  9					the License, or (at your option) any later version.
 10					
 11					This library is distributed in the hopeOA that it will be useful, but
 12					WITHOUT ANY WARRANTY; without even the implied warranty of
 13					MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14					Lesser General Public License for more details.
 15
 16					You should have received a copy of the GNU Lesser General Public
 17					License along with this library; if not, write to the Free Software
 18					Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 19					02110-1301 USA
 20			]"
 21
 22class GTK_TREE_MODEL_FILTER
 23	-- Description: a GtkTreeModelFilter is a tree model which wraps
 24	-- another tree model, and can do the following things:
 25
 26	-- * Filter specific rows, based on data from a "visible column", a
 27	-- column storing booleans indicating whether the row should be
 28	-- filtered or not, or based on the return value of a "visible
 29	-- function", which gets a model, iter and user_data and returns a
 30	-- boolean indicating whether the row should be filtered or not.
 31
 32	-- * Modify the "appearance" of the model, using a modify
 33	-- function. This is extremely powerful and allows for just
 34	-- changing some values and also for creating a completely
 35	-- different model based on the given child model.
 36
 37	-- * Set a different root node, also known as a "virtual root". You
 38	-- can pass in a GtkTreePath indicating the root node for the
 39	-- filter at construction time.
 40
 41inherit
 42	GTK_TREE_MODEL 
 43	GTK_TREE_DRAG_SOURCE
 44
 45insert
 46	G_TYPES
 47
 48creation make, from_external_pointer
 49
 50feature {} -- Creation
 51	make (a_child_model: GTK_TREE_MODEL; a_root: GTK_TREE_PATH) is
 52			-- Creates a new GtkTreeModel with `a_child_model' and - if
 53			-- it is not Void - `a_root' as the virtual root.
 54		do
 55			from_external_pointer(gtk_tree_model_filter_new(handle,null_or(a_root)))
 56		end
 57
 58feature 
 59	-- TODO: gtk_tree_model_filter_set_visible_func ()
 60
 61	-- void        gtk_tree_model_filter_set_visible_func
 62	--                                             (GtkTreeModelFilter *filter,
 63	--                                              GtkTreeModelFilterVisibleFunc func,
 64	--                                              gpointer data,
 65	--                                              GtkDestroyNotify destroy);
 66
 67	-- Sets the visible function used when filtering the filter to be func. The function should return TRUE if the given row should be visible and FALSE otherwise.
 68
 69	-- If the condition calculated by the function changes over time (e.g. because it depends on some global parameters), you must call gtk_tree_model_filter_refilter() to keep the visibility information of the model uptodate.
 70
 71	-- filter : 	A GtkTreeModelFilter.
 72	-- func : 	A GtkTreeModelFilterVisibleFunc, the visible function.
 73	-- data : 	User data to pass to the visible function, or NULL.
 74	-- destroy : 	Destroy notifier of data, or NULL.
 75
 76	-- Since 2.4
 77
 78	-- TODO: gtk_tree_model_filter_set_modify_func ()
 79
 80	-- void        gtk_tree_model_filter_set_modify_func
 81	--                                             (GtkTreeModelFilter *filter,
 82	--                                              gint n_columns,
 83	--                                              GType *types,
 84	--                                              GtkTreeModelFilterModifyFunc func,
 85	--                                              gpointer data,
 86	--                                              GtkDestroyNotify destroy);
 87
 88	-- With the n_columns and types parameters, you give an array of column types for this model (which will be exposed to the parent model/view). The func, data and destroy parameters are for specifying the modify function. The modify function will get called for each data access, the goal of the modify function is to return the data which should be displayed at the location specified using the parameters of the modify function.
 89
 90	-- filter : 	A GtkTreeModelFilter.
 91	-- n_columns : 	The number of columns in the filter model.
 92	-- types : 	The GTypes of the columns.
 93	-- func : 	A GtkTreeModelFilterModifyFunc
 94	-- data : 	User data to pass to the modify function, or NULL.
 95	-- destroy : 	Destroy notifier of data, or NULL.
 96
 97	-- Since 2.4
 98
 99	set_visible_column (a_column: INTEGER) is
100			-- Sets `a_column' of the child_model to be the column where
101			-- filter should look for visibility information. A True
102			-- column value means that a row is visible, and False is
103			-- not.
104		require 
105			boolean_column: model.column_type(a_column) = g_type_boolean
106		do
107			gtk_tree_model_filter_set_visible_column(handle,a_column)
108		end
109
110	model: GTK_TREE_MODEL is
111			-- the child model of filter.
112		local factory: G_OBJECT_EXPANDED_FACTORY[GTK_TREE_MODEL]
113		do
114			Result := factory.wrapper(gtk_tree_model_filter_get_model(handle))
115		end
116	
117	iter_from_child_iter (a_child_iter: GTK_TREE_ITER): GTK_TREE_ITER is
118			-- An_iterator pointing to the row in filter that corresponds
119			-- to the row pointed at by `a_child_iter'.
120		require iter_not_void: a_child_iter /= Void
121		do
122			create Result.make
123			gtk_tree_model_filter_convert_child_iter_to_iter (handle, Result.handle, a_child_iter.handle)
124		end
125
126	to_child_iter (a_filter_iter: GTK_TEXT_ITER): GTK_TREE_ITER is
127			-- An iterator pointing to the row pointed to by
128			-- `a_filter_iter', a valid GtkTreeIter pointing to a row on
129			-- filter.
130		require 
131			iter_not_void: a_filter_iter /= Void
132			-- TODO: a_filter_iter.model = Current 
133		do
134			create Result.make
135			gtk_tree_model_filter_convert_iter_to_child_iter (handle, Result.handle, a_filter_iter.handle)
136		end
137
138	child_path_to_path (a_child_path: GTK_TREE_PATH): GTK_TREE_PATH is
139			-- cnverts `a_child_path' to a path relative to filter. That
140			-- is, `a_child_path' points to a path in the child
141			-- model. The Result path will point to the same row in the
142			-- filtered model. If `a_child_path' isn't a valid path on
143			-- the child model, then Void is returned.
144		require path_not_void: a_child_path /= Void
145		local path_ptr: POINTER
146		do
147			path_ptr:=gtk_tree_model_filter_convert_child_path_to_path(handle, a_child_path.handle)
148			if path_ptr.is_not_null then create Result.from_external_pointer(path_ptr) end
149		end
150
151	path_to_child_path (a_filter_path: GTK_TREE_PATH): GTK_TREE_PATH is	
152			-- Converts `a_filter_path' to a path on the child model of
153			-- filter. That is, `a_filter_path' points to a location in
154			-- filter. The Result path will point to the same location in
155			-- the model not being filtered. If `a_filter_path' does not
156			-- point to a location in the child model, Void is returned.
157		require path_not_void: a_filter_path /= Void
158		local path_ptr: POINTER
159		do
160			path_ptr:=gtk_tree_model_filter_convert_path_to_child_path(handle, a_filter_path.handle)
161			if path_ptr.is_not_null then create Result.from_external_pointer(path_ptr) end
162		end
163
164	refilter is
165			-- Emits ::row_changed for each row in the child model, which
166			-- causes the filter to re-evaluate whether a row is visible
167			-- or not.
168		do
169			gtk_tree_model_filter_refilter  (handle)
170		end
171
172	clear_cache is
173			-- This function should almost never be called. It clears the
174			-- filter of any cached iterators that haven't been reffed
175			-- with `ref_node'. This might be useful if the child model
176			-- being filtered is static (and doesn't change often) and
177			-- there has been a lot of unreffed access to nodes. As a
178			-- side effect of this function, all unreffed itters will be
179			-- invalid.
180		do
181			gtk_tree_model_filter_clear_cache(handle)
182		end
183
184feature -- TODO: Properties
185	-- The "child-model" property
186
187	--   "child-model"          GtkTreeModel          : Read / Write / Construct Only
188
189	-- The model for the filtermodel to filter.
190
191	-- TODO: how can a property be writable and at the same time
192	-- writable at construct time only? This question is valid for both
193	-- these properties. Paolo 2007-01-09
194	
195
196	-- The "virtual-root" property
197
198	--   "virtual-root"         GtkTreePath           : Read / Write / Construct Only
199
200	-- The virtual root (relative to the child model) for this filtermodel.
201
202feature {} -- Unwrapped features 
203-- GtkTreeModelFilterVisibleFunc ()
204
205	-- gboolean    (*GtkTreeModelFilterVisibleFunc)
206	--                                             (GtkTreeModel *model,
207	--                                              GtkTreeIter *iter,
208	--                                              gpointer data);
209
210	-- A function which decides whether the row indicated by iter is visible.
211	-- model : 	the child model of the GtkTreeModelFilter
212	-- iter : 	a GtkTreeIter pointing to the row in model whose visibility is determined
213	-- data : 	user data given to gtk_tree_model_filter_set_visible_func()
214	-- Returns : 	Whether the row indicated by iter is visible.
215	-- GtkTreeModelFilterModifyFunc ()
216
217	-- void        (*GtkTreeModelFilterModifyFunc) (GtkTreeModel *model,
218	--                                              GtkTreeIter *iter,
219	--                                              GValue *value,
220	--                                              gint column,
221	--                                              gpointer data);
222	
223	-- A function which calculates display values from raw values in the model. It must fill value with the display value for the column column in the row indicated by iter.
224	
225	-- Since this function is called for each data access, it's not a particularly efficient operation.
226	-- model : 	the GtkTreeModelFilter
227	-- iter : 	a GtkTreeIter pointing to the row whose display values are determined
228	-- value : 	A GValue which is already initialized for with the correct type for the column column.
229	-- column : 	the column whose display value is determined
230	-- data : 	user data given to gtk_tree_model_filter_set_modify_func()
231	
232feature -- size
233	struct_size: INTEGER is
234		external "C inline use <gtk/gtk.h>"
235		alias "sizeof(GtkTreeModelFilter)"
236		end
237
238feature {} -- External calls
239	-- TODO: wrap function pointer gboolean (*GtkTreeModelFilterVisibleFunc)
240	-- (GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
241
242	-- TODO: wrap funtion pointer void (*GtkTreeModelFilterModifyFunc)
243	-- (GtkTreeModel *model, GtkTreeIter *iter, GValue *value, gint
244	-- column, gpointer data);
245
246	gtk_tree_model_filter_new (a_child_model, a_root: POINTER): POINTER is
247			-- GtkTreeModel* gtk_tree_model_filter_new (GtkTreeModel
248			-- *child_model, GtkTreePath *root);
249		external "C use <gtk/gtk.h>"
250		end
251
252	gtk_tree_model_filter_set_visible_func (a_filter, a_gtktreemodelfiltervisiblefunc, some_data, a_gtkdestroynotify: POINTER) is
253			-- void gtk_tree_model_filter_set_visible_func
254			-- (GtkTreeModelFilter *filter, GtkTreeModelFilterVisibleFunc
255			-- func, gpointer data, GtkDestroyNotify destroy);
256	external "C use <gtk/gtk.h>"
257	end
258
259	gtk_tree_model_filter_set_modify_func (a_filter: POINTER; an_n_columns: INTEGER; some_gtypes, a_gtktreemodelfiltermodifyfunc, some_data, a_gtkdestroynotify: POINTER) is
260			-- void gtk_tree_model_filter_set_modify_func
261			-- (GtkTreeModelFilter *filter, gint n_columns, GType *types,
262			-- GtkTreeModelFilterModifyFunc func, gpointer data,
263			-- GtkDestroyNotify destroy);
264		external "C use <gtk/gtk.h>"
265		end
266	
267	gtk_tree_model_filter_set_visible_column (a_filter: POINTER; a_column: INTEGER) is
268			-- void gtk_tree_model_filter_set_visible_column
269			-- (GtkTreeModelFilter *filter, gint column);
270		external "C use <gtk/gtk.h>"
271		end
272
273	gtk_tree_model_filter_get_model (a_filter: POINTER): POINTER is
274			-- GtkTreeModel* gtk_tree_model_filter_get_model (GtkTreeModelFilter *filter);
275		external "C use <gtk/gtk.h>"
276		end
277
278	gtk_tree_model_filter_convert_child_iter_to_iter (a_filter, a_filter_iter, a_child_iter: POINTER) is
279			-- void gtk_tree_model_filter_convert_child_iter_to_iter
280			-- (GtkTreeModelFilter *filter, GtkTreeIter *filter_iter,
281			-- GtkTreeIter *child_iter);
282		external "C use <gtk/gtk.h>"
283		end
284
285	gtk_tree_model_filter_convert_iter_to_child_iter (a_filter, a_child_iter, a_filter_iter: POINTER) is
286			-- void gtk_tree_model_filter_convert_iter_to_child_iter
287			-- (GtkTreeModelFilter *filter, GtkTreeIter *child_iter,
288			-- GtkTreeIter *filter_iter);
289		external "C use <gtk/gtk.h>"
290		end
291	
292	gtk_tree_model_filter_convert_child_path_to_path (a_filter, a_child_path: POINTER): POINTER is
293			-- GtkTreePath*
294			-- gtk_tree_model_filter_convert_child_path_to_path
295			-- (GtkTreeModelFilter *filter, GtkTreePath *child_path);
296		external "C use <gtk/gtk.h>"
297		end
298	
299	gtk_tree_model_filter_convert_path_to_child_path (a_filter, a_filter_path: POINTER): POINTER is
300			-- GtkTreePath*
301			-- gtk_tree_model_filter_convert_path_to_child_path
302			-- (GtkTreeModelFilter *filter, GtkTreePath *filter_path);
303		external "C use <gtk/gtk.h>"
304		end
305	
306	gtk_tree_model_filter_refilter (a_filter: POINTER) is
307			-- void gtk_tree_model_filter_refilter (GtkTreeModelFilter *filter);
308		external "C use <gtk/gtk.h>"
309		end
310
311	gtk_tree_model_filter_clear_cache (a_filter: POINTER) is
312			-- void gtk_tree_model_filter_clear_cache (GtkTreeModelFilter *filter);
313		external "C use <gtk/gtk.h>"
314		end
315end -- class GTK_TREE_MODEL_FILTER