/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

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