/src/wrappers/gtk/library/gtk_tree_store.e

http://github.com/tybor/Liberty · Specman e · 340 lines · 183 code · 35 blank · 122 comment · 9 complexity · b59c88c072770777db46f059ccdc7a4a MD5 · raw file

  1. indexing
  2. description: "GtkTreeStore -- A tree-like data structure that can be used with the GtkTreeView."
  3. copyright: "[
  4. Copyright (C) 2006 eiffel-libraries team, 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 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_STORE
  19. -- The GtkTreeStore object is a list model for use with a
  20. -- GtkTreeView widget. It implements the GtkTreeModel interface,
  21. -- and consequentialy, can use all of the methods available
  22. -- there. It also implements the GtkTreeSortable interface so it
  23. -- can be sorted by the view. Finally, it also implements the tree
  24. -- drag and drop interfaces.
  25. inherit
  26. GTK_TREE_MODEL
  27. GTK_TREE_SORTABLE
  28. GTK_TREE_DRAG_SOURCE
  29. GTK_TREE_DRAG_DEST
  30. insert
  31. GTK_STORE_SETTERS
  32. GTK_TREE_STORE_EXTERNALS
  33. creation make, from_external_pointer
  34. feature {} -- Creation
  35. make (some_columns: ARRAY[INTEGER]) is
  36. -- Creates a new tree store. `some_columns' is an array of integers; each
  37. -- integer is the G_TYPE of an actual column. Note that only types
  38. -- derived from standard GObject fundamental types are supported.
  39. require gtk_initialized: gtk.is_initialized
  40. do
  41. from_external_pointer (gtk_tree_store_newv (some_columns.count, some_columns.to_external))
  42. end
  43. feature -- Generic setter
  44. set_value (an_iterator: GTK_TREE_ITER; a_column: INTEGER; a_value: G_VALUE) is
  45. -- Sets the data in the cell specified by `an_iterator' and
  46. -- `a_column'. The type of `a_value' must be convertible to the type of
  47. -- the column.
  48. -- `an_iterator': A valid GtkTreeIter for the row being modified
  49. -- `a_column' : column number to modify
  50. -- `a_value' : new value for the cell
  51. require
  52. valid_iterator: an_iterator/=Void
  53. valid_value: a_value /= Void -- and then Eiffelize "The type of
  54. -- `a_value' must be convertible to the type of the column."
  55. do
  56. gtk_tree_store_set_value (handle, an_iterator.handle, a_column, a_value.handle)
  57. end
  58. is_last_iterator_valid: BOOLEAN
  59. -- Is the last iterator passed as an argument still valid?
  60. remove (an_iterator: GTK_TREE_ITER) is
  61. -- Removes the given row from the list store. After being removed,
  62. -- `an_iterator' is set to be the next valid row, or invalidated if it
  63. -- pointed to the last row in the list store; in this case
  64. -- `is_last_iterator_valid' will be False
  65. require
  66. valid_iterator: an_iterator/=Void
  67. do
  68. is_last_iterator_valid := gtk_tree_store_remove (handle,an_iterator.handle).to_boolean
  69. end
  70. put (an_iterator, a_parent: GTK_TREE_ITER; a_position: INTEGER) is
  71. -- Creates a new row at position. If `a_parent' is non-NULL,
  72. -- then the row will be made a child of parent. Otherwise,
  73. -- the row will be created at the toplevel. If `a_position' is
  74. -- larger than the number of rows at that level, then the
  75. -- new row will be inserted to the end of the list. `iter' will
  76. -- be changed to point to this new row. The row will be empty
  77. -- after this function is called. To fill in values, you need
  78. -- to call some of the set_* methods.
  79. require
  80. valid_iterator: an_iterator/=Void
  81. local
  82. parent_pointer: POINTER
  83. do
  84. if a_parent /= Void then parent_pointer := a_parent.handle end
  85. gtk_tree_store_insert (handle, an_iterator.handle, a_parent.handle, a_position)
  86. end
  87. put_before, insert_before (an_iterator, a_parent, a_sibling: GTK_TREE_ITER) is
  88. -- Inserts a new row before `a_sibling'. If `a_sibling' is Void,
  89. -- then the row will be appended to `a_parent''s children. If
  90. -- `a_parent' and `a_sibling' are Void, then the row will be
  91. -- appended to the toplevel. If both `a_sibling' and `a_parent'
  92. -- are set, then `a_parent' must be the parent of `a_sibling'.
  93. -- When `a_sibling' is set, `a_parent' is optional.
  94. --
  95. -- `an_iterator' will be changed to point to this new row.
  96. -- The row will be empty after this function is called.
  97. -- To fill in values, you need to call some of the set_* methods.
  98. require
  99. valid_iterator: an_iterator /= Void
  100. local
  101. parent_pointer, sibling_pointer: POINTER
  102. do
  103. if a_parent /= Void then parent_pointer := a_parent.handle end
  104. if a_sibling /= Void then sibling_pointer := a_sibling.handle end
  105. gtk_tree_store_insert_before (handle, an_iterator.handle,
  106. parent_pointer, sibling_pointer)
  107. end
  108. put_after, insert_after (an_iterator, a_parent, a_sibling: GTK_TREE_ITER) is
  109. -- Inserts a new row after `a_sibling'. If `a_sibling' is Void,
  110. -- then the row will be prepended to `a_parent''s children.
  111. -- If `a_parent' and `a_sibling' are Void, then the row will
  112. -- be prepended to the toplevel. If both `a_sibling' and
  113. -- `a_parent' are set, then `a_parent' must be the parent of
  114. -- `a_sibling'. When `a_sibling' is set, `a_parent' is optional.
  115. --
  116. -- `an_iterator' will be changed to point to this new row.
  117. -- The row will be empty after this function is called.
  118. -- To fill in values, you need to call some of the set_* methods.
  119. require
  120. valid_iterator: an_iterator /= Void
  121. local
  122. parent_pointer, sibling_pointer: POINTER
  123. do
  124. if a_parent /= Void then parent_pointer := a_parent.handle end
  125. if a_sibling /= Void then sibling_pointer := a_sibling.handle end
  126. gtk_tree_store_insert_after (handle, an_iterator.handle,
  127. parent_pointer, sibling_pointer)
  128. end
  129. insert_with_values (an_iterator, a_parent: GTK_TREE_ITER;
  130. a_position: INTEGER;
  131. some_columns: ARRAY[INTEGER];
  132. some_values: ARRAY[G_VALUE]) is
  133. -- Creates a new row at `a_position'. `an_iterator' will be
  134. -- changed to point to this new row. If `a_position' is larger
  135. -- than the number of rows on the list, then the new row will
  136. -- be appended to the list. The row will be filled with the
  137. -- values given to this function.
  138. -- Calling store.insert_with_values (iter, parent, position,
  139. -- cols, vals) has the same effect as calling
  140. -- store.put (iter, parent, position)
  141. -- store.set (iter, cols, vals);
  142. -- with the difference that the former will only emit a
  143. -- row_inserted signal, while the latter will emit
  144. -- row_inserted, row_changed and if the tree store is sorted,
  145. -- rows_reordered. Since emitting the rows_reordered signal
  146. -- repeatedly can affect the performance of the program,
  147. -- insert_with_values should generally be preferred when
  148. -- inserting rows in a sorted tree store.
  149. -- `some_columns' contains the column numbers; each column
  150. -- will be set with the corresponding value in `some_values'.
  151. require columns_n_equals_values_n: some_columns.count = some_values.count
  152. do
  153. not_yet_implemented
  154. -- TODO: some_values.to_external is an array of pointers to the Eiffel wrappers!!!
  155. gtk_tree_store_insert_with_valuesv (handle, an_iterator.handle,
  156. a_parent.handle,
  157. a_position,
  158. -- gint *columns an array of column numbers
  159. some_columns.to_external,
  160. -- GValue *values an array of GValues
  161. some_values.to_external,
  162. -- gint n_values the length of the
  163. -- columns and values arrays
  164. some_values.count
  165. )
  166. end
  167. add_first, prepend (an_iterator, a_parent: GTK_TREE_ITER) is
  168. -- Prepends a new row to tree store. If `a_parent' is non-Void,
  169. -- then it will prepend the new row before the first child of
  170. -- `a_parent', otherwise it will prepend a row to the top
  171. -- level. `an_iterator' will be changed to point to this new
  172. -- row. The row will be empty after this function is called.
  173. -- To fill in values, you need to call some set_* method.
  174. require valid_iterator: an_iterator /= Void
  175. local
  176. parent_pointer: POINTER
  177. do
  178. if a_parent /= Void then parent_pointer := a_parent.handle end
  179. gtk_tree_store_prepend (handle, an_iterator.handle, parent_pointer)
  180. end
  181. add_last, append (an_iterator, a_parent: GTK_TREE_ITER) is
  182. -- Appends a new row to tree store. If `a_parent' is non-Void,
  183. -- then it will append the new row after the last child of
  184. -- `a_parent', otherwise it will append a row to the top level.
  185. -- `an_iterator' will be changed to point to this new row. The row will
  186. -- be empty after this function is called. To fill in values,
  187. -- you need to call some `set_*' feature
  188. require iterator_not_void: an_iterator /= Void
  189. local
  190. parent_pointer: POINTER
  191. do
  192. if a_parent /= Void then parent_pointer := a_parent.handle end
  193. gtk_tree_store_append (handle, an_iterator.handle, parent_pointer)
  194. end
  195. is_ancestor(an_iterator, a_descendant: GTK_TREE_ITER): BOOLEAN is
  196. -- Returns True if `an_iterator' is an ancestor of `a_descendant'.
  197. -- That is, `an_iterator' is the parent (or grandparent or
  198. -- great-grandparent or ...) of `a_descendant).
  199. require
  200. valid_iterators: an_iterator /= Void and a_descendant /= Void
  201. do
  202. Result := gtk_tree_store_is_ancestor(handle, an_iterator.handle,
  203. a_descendant.handle).to_boolean
  204. end
  205. iter_depth(an_iterator: GTK_TREE_ITER): INTEGER is
  206. -- Returns the depth of `an_iterator'. This will be 0 for
  207. -- anything on the root level, 1 for anything down a level, etc.
  208. require
  209. valid_iterators: an_iterator /= Void
  210. do
  211. Result := gtk_tree_store_iter_depth(handle, an_iterator.handle)
  212. end
  213. clear is
  214. -- Removes all rows from the tree store.
  215. do
  216. gtk_tree_store_clear (handle)
  217. end
  218. is_iterator_valid (an_iterator: GTK_TREE_ITER): BOOLEAN is
  219. -- Is `an_iterator' valid for Current GtkTreeStore?
  220. --
  221. -- Warning: this query is slow. Only use it for debugging
  222. -- and/or testing purposes.
  223. require
  224. valid_iterator: an_iterator/=Void
  225. do
  226. Result:=(gtk_tree_store_iter_is_valid(handle,an_iterator.handle)).to_boolean
  227. end
  228. reorder (a_parent: GTK_TREE_ITER; a_new_order: ARRAY[INTEGER]) is
  229. -- Reorders the children of `a_parent' to follow the order
  230. -- indicated by `a_new_order'. Note that this function only
  231. -- works with unsorted stores.
  232. -- `a_new_order' is the array of integers
  233. -- mapping the new position of each child to its old position
  234. -- before the re-ordering, i.e. a_new_order.item(newpos) =
  235. -- oldpos.
  236. require
  237. unsorted_store: not is_sorted
  238. valid_order: a_new_order /= Void
  239. do
  240. gtk_tree_store_reorder (handle, a_parent.handle, a_new_order.to_external)
  241. end
  242. swap (a, b: GTK_TREE_ITER) is
  243. -- Swaps `a' and `b' in the same level of tree store.
  244. -- Note that this function only works with unsorted stores.
  245. require
  246. unsorted_store: not is_sorted
  247. valid_iterators: a /= Void and b /= Void
  248. do
  249. gtk_tree_store_swap (handle, a.handle, b.handle)
  250. end
  251. move_before (an_iterator, a_position: GTK_TREE_ITER) is
  252. -- Moves `an_iterator' in tree store to the position before
  253. -- `a_position'. `an_iterator' and `a_position' should be in
  254. -- the same level. Note that this function only works with
  255. -- unsorted stores.
  256. require
  257. unsorted_store: not is_sorted
  258. valid_iterator: an_iterator/=Void
  259. valid_position: a_position/=Void
  260. do
  261. gtk_tree_store_move_before (handle,an_iterator.handle, a_position.handle)
  262. end
  263. move_last (an_iterator: GTK_TREE_ITER) is
  264. -- Moves `an_iterator' in store to the end of the level. Note that this
  265. -- function only works with unsorted stores.
  266. require
  267. unsorted_store: not is_sorted
  268. valid_iterator: an_iterator /= Void
  269. do
  270. gtk_tree_store_move_before (handle, an_iterator.handle, default_pointer)
  271. end
  272. move_after (an_iterator, a_position: GTK_TREE_ITER) is
  273. -- Moves `an_iterator' in store to the position after
  274. -- `a_position'. Note that this function only works with unsorted stores.
  275. require
  276. unsorted_store: not is_sorted
  277. valid_iterator: an_iterator/=Void
  278. valid_position: a_position/=Void
  279. do
  280. gtk_tree_store_move_after (handle, an_iterator.handle, a_position.handle)
  281. end
  282. move_first (an_iterator: GTK_TREE_ITER) is
  283. -- Moves item pointed to by `an_iterator' to the start of the
  284. -- level. Note that this function only works with unsorted stores.
  285. require
  286. unsorted_store: not is_sorted
  287. valid_iterator: an_iterator/=Void
  288. do
  289. gtk_tree_store_move_after (handle, an_iterator.handle, default_pointer)
  290. end
  291. feature -- struct size
  292. struct_size: INTEGER is
  293. external "C inline use <gtk/gtk.h>"
  294. alias "sizeof(GtkTreeStore)"
  295. end
  296. -- TODO:
  297. -- -- GtkTreeStore;
  298. -- -- GtkTreeStore* gtk_tree_store_newv (gint n_columns,
  299. -- -- void gtk_tree_store_set (GtkTreeStore *tree_store,
  300. -- -- GtkTreeIter *iter,
  301. -- -- ...);
  302. -- -- void gtk_tree_store_set_valist (GtkTreeStore *tree_store,
  303. -- -- GtkTreeIter *iter,
  304. -- -- va_list var_args);
  305. end