/src/wrappers/gtk/library/gtk_tree_model_sort.e

http://github.com/tybor/Liberty · Specman e · 264 lines · 33 code · 61 blank · 170 comment · 2 complexity · 523357a3ffb9fcf4e0d93da8337fee82 MD5 · raw file

  1. indexing
  2. description: "GtkTreeModelSort -- a GtkTreeModel which makes an underlying tree model sortable."
  3. copyright: "[
  4. Copyright (C) 2007 $EWLC_developer, $original_copyright_holder
  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 hope 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_SORT
  19. -- The GtkTreeModelSort is a model which implements the
  20. -- GtkTreeSortable interface. It does not hold any data itself, but
  21. -- rather is created with a child model and proxies its data. It
  22. -- has identical column types to this child model, and the changes
  23. -- in the child are propagated. The primary purpose of this model
  24. -- is to provide a way to sort a different model without modifying
  25. -- it. Note that the sort function used by GtkTreeModelSort is not
  26. -- guaranteed to be stable.
  27. -- The use of this is best demonstrated through an example. In the
  28. -- following sample code we create two GtkTreeView widgets each
  29. -- with a view of the same data. As the model is wrapped here by a
  30. -- GtkTreeModelSort, the two GtkTreeViews can each sort their view
  31. -- of the data without affecting the other. By contrast, if we
  32. -- simply put the same model in each widget, then sorting the first
  33. -- would sort the second.
  34. -- (TODO: Eiffelize) Example 3. Using a GtkTreeModelSort
  35. -- {
  36. -- GtkTreeView *tree_view1;
  37. -- GtkTreeView *tree_view2;
  38. -- GtkTreeModel *sort_model1;
  39. -- GtkTreeModel *sort_model2;
  40. -- GtkTreeModel *child_model;
  41. -- /* get the child model */
  42. -- child_model = get_my_model();
  43. -- /* Create the first tree */
  44. -- sort_model1 = gtk_tree_model_sort_new_with_model (child_model);
  45. -- tree_view1 = gtk_tree_view_new_with_model (sort_model1);
  46. -- /* Create the second tree */
  47. -- sort_model2 = gtk_tree_model_sort_new_with_model (child_model);
  48. -- tree_view2 = gtk_tree_view_new_with_model (sort_model2);
  49. -- /* Now we can sort the two models independently */
  50. -- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model1),
  51. -- COLUMN_1, GTK_SORT_ASCENDING);
  52. -- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model2),
  53. -- COLUMN_1, GTK_SORT_DESCENDING);
  54. -- }
  55. -- To demonstrate how to access the underlying child model from the
  56. -- sort model, the next example will be a callback for the
  57. -- GtkTreeSelection "changed" signal. In this callback, we get a
  58. -- string from COLUMN_1 of the model. We then modify the string,
  59. -- find the same selected row on the child model, and change the
  60. -- row there.
  61. -- (TODO: Eiffelize) Example 4. Accessing the child model of in a selection changed callback
  62. -- void
  63. -- selection_changed (GtkTreeSelection *selection, gpointer data)
  64. -- {
  65. -- GtkTreeModel *sort_model = NULL;
  66. -- GtkTreeModel *child_model;
  67. -- GtkTreeIter sort_iter;
  68. -- GtkTreeIter child_iter;
  69. -- char *some_data = NULL;
  70. -- char *modified_data;
  71. -- /* Get the current selected row and the model. */
  72. -- if (! gtk_tree_selection_get_selected (selection,
  73. -- &sort_model,
  74. -- &sort_iter))
  75. -- return;
  76. -- /* Look up the current value on the selected row and get a new value
  77. -- * to change it to.
  78. -- */
  79. -- gtk_tree_model_get (GTK_TREE_MODEL (sort_model), &sort_iter,
  80. -- COLUMN_1, &some_data,
  81. -- -1);
  82. -- modified_data = change_the_data (some_data);
  83. -- g_free (some_data);
  84. -- /* Get an iterator on the child model, instead of the sort model. */
  85. -- gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (sort_model),
  86. -- &child_iter,
  87. -- &sort_iter);
  88. -- /* Get the child model and change the value of the row. In this
  89. -- * example, the child model is a GtkListStore. It could be any other
  90. -- * type of model, though.
  91. -- */
  92. -- child_model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model));
  93. -- gtk_list_store_set (GTK_LIST_STORE (child_model), &child_iter,
  94. -- COLUMN_1, &modified_data,
  95. -- -1);
  96. -- g_free (modified_data);
  97. -- }
  98. inherit
  99. G_OBJECT
  100. GTK_TREE_MODEL
  101. GTK_TREE_DRAG_SOURCE
  102. GTK_TREE_SORTABLE
  103. creation from_external_pointer
  104. feature {}
  105. -- gtk_tree_model_sort_new_with_model ()
  106. -- GtkTreeModel* gtk_tree_model_sort_new_with_model
  107. -- (GtkTreeModel *child_model);
  108. -- Creates a new GtkTreeModel, with child_model as the child model.
  109. -- child_model : A GtkTreeModel
  110. -- Returns : A new GtkTreeModel.
  111. -- gtk_tree_model_sort_get_model ()
  112. -- GtkTreeModel* gtk_tree_model_sort_get_model (GtkTreeModelSort *tree_model);
  113. -- Returns the model the GtkTreeModelSort is sorting.
  114. -- tree_model : a GtkTreeModelSort
  115. -- Returns : the "child model" being sorted
  116. -- gtk_tree_model_sort_convert_child_path_to_path ()
  117. -- GtkTreePath* gtk_tree_model_sort_convert_child_path_to_path
  118. -- (GtkTreeModelSort *tree_model_sort,
  119. -- GtkTreePath *child_path);
  120. -- Converts child_path to a path relative to tree_model_sort. That is, child_path points to a path in the child model. The returned path will point to the same row in the sorted model. If child_path isn't a valid path on the child model, then NULL is returned.
  121. -- tree_model_sort : A GtkTreeModelSort
  122. -- child_path : A GtkTreePath to convert
  123. -- Returns : A newly allocated GtkTreePath, or NULL
  124. -- gtk_tree_model_sort_convert_child_iter_to_iter ()
  125. -- void gtk_tree_model_sort_convert_child_iter_to_iter
  126. -- (GtkTreeModelSort *tree_model_sort,
  127. -- GtkTreeIter *sort_iter,
  128. -- GtkTreeIter *child_iter);
  129. -- Sets sort_iter to point to the row in tree_model_sort that corresponds to the row pointed at by child_iter.
  130. -- tree_model_sort : A GtkTreeModelSort
  131. -- sort_iter : An uninitialized GtkTreeIter.
  132. -- child_iter : A valid GtkTreeIter pointing to a row on the child model
  133. -- gtk_tree_model_sort_convert_path_to_child_path ()
  134. -- GtkTreePath* gtk_tree_model_sort_convert_path_to_child_path
  135. -- (GtkTreeModelSort *tree_model_sort,
  136. -- GtkTreePath *sorted_path);
  137. -- Converts sorted_path to a path on the child model of tree_model_sort. That is, sorted_path points to a location in tree_model_sort. The returned path will point to the same location in the model not being sorted. If sorted_path does not point to a location in the child model, NULL is returned.
  138. -- tree_model_sort : A GtkTreeModelSort
  139. -- sorted_path : A GtkTreePath to convert
  140. -- Returns : A newly allocated GtkTreePath, or NULL
  141. -- gtk_tree_model_sort_convert_iter_to_child_iter ()
  142. -- void gtk_tree_model_sort_convert_iter_to_child_iter
  143. -- (GtkTreeModelSort *tree_model_sort,
  144. -- GtkTreeIter *child_iter,
  145. -- GtkTreeIter *sorted_iter);
  146. -- Sets child_iter to point to the row pointed to by sorted_iter.
  147. -- tree_model_sort : A GtkTreeModelSort
  148. -- child_iter : An uninitialized GtkTreeIter
  149. -- sorted_iter : A valid GtkTreeIter pointing to a row on tree_model_sort.
  150. -- gtk_tree_model_sort_reset_default_sort_func ()
  151. -- void gtk_tree_model_sort_reset_default_sort_func
  152. -- (GtkTreeModelSort *tree_model_sort);
  153. -- This resets the default sort function to be in the 'unsorted' state. That is, it is in the same order as the child model. It will re-sort the model to be in the same order as the child model only if the GtkTreeModelSort is in 'unsorted' state.
  154. -- tree_model_sort : A GtkTreeModelSort
  155. -- gtk_tree_model_sort_clear_cache ()
  156. -- void gtk_tree_model_sort_clear_cache (GtkTreeModelSort *tree_model_sort);
  157. -- This function should almost never be called. It clears the tree_model_sort of any cached iterators that haven't been reffed with gtk_tree_model_ref_node(). This might be useful if the child model being sorted is static (and doesn't change often) and there has been a lot of unreffed access to nodes. As a side effect of this function, all unreffed iters will be invalid.
  158. -- tree_model_sort : A GtkTreeModelSort
  159. -- gtk_tree_model_sort_iter_is_valid ()
  160. -- gboolean gtk_tree_model_sort_iter_is_valid
  161. -- (GtkTreeModelSort *tree_model_sort,
  162. -- GtkTreeIter *iter);
  163. -- Warning
  164. -- This function is slow. Only use it for debugging and/or testing purposes.
  165. -- Checks if the given iter is a valid iter for this GtkTreeModelSort.
  166. -- tree_model_sort : A GtkTreeModelSort.
  167. -- iter : A GtkTreeIter.
  168. -- Returns : TRUE if the iter is valid, FALSE if the iter is invalid.
  169. feature -- "model" properties
  170. -- "model" GtkTreeModel : Read / Write / Construct Only
  171. -- The model for the TreeModelSort to sort.
  172. feature {} -- External calls
  173. -- #include <gtk/gtk.h>
  174. -- GtkTreeModelSort;
  175. -- GtkTreeModel* gtk_tree_model_sort_new_with_model
  176. -- (GtkTreeModel *child_model);
  177. -- GtkTreeModel* gtk_tree_model_sort_get_model (GtkTreeModelSort *tree_model);
  178. -- GtkTreePath* gtk_tree_model_sort_convert_child_path_to_path
  179. -- (GtkTreeModelSort *tree_model_sort,
  180. -- GtkTreePath *child_path);
  181. -- void gtk_tree_model_sort_convert_child_iter_to_iter
  182. -- (GtkTreeModelSort *tree_model_sort,
  183. -- GtkTreeIter *sort_iter,
  184. -- GtkTreeIter *child_iter);
  185. -- GtkTreePath* gtk_tree_model_sort_convert_path_to_child_path
  186. -- (GtkTreeModelSort *tree_model_sort,
  187. -- GtkTreePath *sorted_path);
  188. -- void gtk_tree_model_sort_convert_iter_to_child_iter
  189. -- (GtkTreeModelSort *tree_model_sort,
  190. -- GtkTreeIter *child_iter,
  191. -- GtkTreeIter *sorted_iter);
  192. -- void gtk_tree_model_sort_reset_default_sort_func
  193. -- (GtkTreeModelSort *tree_model_sort);
  194. -- void gtk_tree_model_sort_clear_cache (GtkTreeModelSort *tree_model_sort);
  195. -- gboolean gtk_tree_model_sort_iter_is_valid
  196. -- (GtkTreeModelSort *tree_model_sort,
  197. -- GtkTreeIter *iter);
  198. feature -- size
  199. struct_size: INTEGER is
  200. external "C inline use <gtk/gtk.h>"
  201. alias "sizeof(GtkTreeModel)"
  202. end
  203. end -- class GTK_TREE_MODEL_SORT