/src/wrappers/gtk/library/gtk_tree_selection.e

http://github.com/tybor/Liberty · Specman e · 358 lines · 165 code · 56 blank · 137 comment · 3 complexity · 4c6c1f27112ba206ed7174a9f7cf754b MD5 · raw file

  1. indexing
  2. description: "GtkTreeSelection - The selection object for 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_SELECTION
  19. -- The GtkTreeSelection object is a helper object to manage the
  20. -- selection for a GtkTreeView widget. The GtkTreeSelection object
  21. -- is automatically created when a new GtkTreeView widget is
  22. -- created, and cannot exist independentally of this widget. The
  23. -- primary reason the GtkTreeSelection objects exists is for
  24. -- cleanliness of code and API. That is, there is no conceptual
  25. -- reason all these functions could not be methods on the
  26. -- GtkTreeView widget instead of a separate function.
  27. -- A GTK_TREE_SELECTION object is obtained from a GTK_TREE_VIEW by
  28. -- calling `selection'. It can be manipulated to check the
  29. -- selection status of the tree, as well as select and deselect
  30. -- individual rows. Selection is done completely view side. As a
  31. -- result, multiple views of the same model can have completely
  32. -- different selections. Additionally, you cannot change the
  33. -- selection of a row on the model that is not currently displayed
  34. -- by the view without expanding its parents first.
  35. -- One of the important things to remember when monitoring the
  36. -- selection of a view is that the "changed" signal is mostly a
  37. -- hint. That is, it may only emit one signal when a range of rows
  38. -- is selected. Additionally, it may on occasion emit a "changed"
  39. -- signal when nothing has happened (mostly as a result of
  40. -- programmers calling select_row on an already selected row).
  41. inherit
  42. G_OBJECT
  43. insert
  44. G_SIGNALS
  45. GTK_TREE_SELECTION_EXTERNALS
  46. creation from_external_pointer
  47. feature -- selection mode
  48. set_single_mode is
  49. -- Set selection mode to single. Zero or one element may be
  50. -- selected.If the previous type was GTK_SELECTION_MULTIPLE,
  51. -- then the anchor is kept selected, if it was previously
  52. -- selected.
  53. do
  54. gtk_tree_selection_set_mode (handle, gtk_selection_single)
  55. end
  56. is_mode_single: BOOLEAN is
  57. -- Is selection mode single?
  58. do
  59. Result := (gtk_tree_selection_get_mode (handle) = gtk_selection_single )
  60. end
  61. set_browse_mode is
  62. -- Set selection mode to browse. Exactly one element is
  63. -- selected. In some circumstances, such as initially or
  64. -- during a search operation, it's possible for no element to
  65. -- be selected with GTK_SELECTION_BROWSE. What is really
  66. -- enforced is that the user can't deselect a currently
  67. -- selected element except by selecting another element. If
  68. -- the previous type was GTK_SELECTION_MULTIPLE, then the
  69. -- anchor is kept selected, if it was previously selected.
  70. do
  71. gtk_tree_selection_set_mode (handle, gtk_selection_browse)
  72. end
  73. is_mode_browse: BOOLEAN is
  74. -- Is selection mode browse?
  75. do
  76. Result := (gtk_tree_selection_get_mode (handle) = gtk_selection_browse )
  77. end
  78. set_multiple_mode is
  79. -- Set selection mode to multiple. Any number of elements may
  80. -- be selected. Clicks toggle the state of an item. Any
  81. -- number of elements may be selected. The Ctrl key may be
  82. -- used to enlarge the selection, and Shift key to select
  83. -- between the focus and the child pointed to. Some widgets
  84. -- may also allow Click-drag to select a range of
  85. -- elements. If the previous type was GTK_SELECTION_MULTIPLE,
  86. -- then the anchor is kept selected, if it was previously
  87. -- selected.
  88. do
  89. gtk_tree_selection_set_mode (handle, gtk_selection_multiple)
  90. end
  91. is_mode_multiple: BOOLEAN is
  92. -- Is selection mode multiple?
  93. do
  94. Result := (gtk_tree_selection_get_mode (handle) = gtk_selection_multiple)
  95. end
  96. set_select_function (a_function: FUNCTION[ANY,TUPLE[GTK_TREE_SELECTION, GTK_TREE_MODEL, GTK_TREE_PATH, BOOLEAN],BOOLEAN]) is
  97. -- Sets the selection function. If set, this function is
  98. -- called before any node is selected or unselected, giving
  99. -- some control over which nodes are selected. The select
  100. -- function should return TRUE if the state of the node may
  101. -- be toggled, and FALSE if the state of the node should be
  102. -- left unchanged.
  103. local select_callback: GTK_TREE_SELECT_FUNCTION
  104. do
  105. create select_callback.make (Current, a_function)
  106. end
  107. -- Note: not wrapping gtk_tree_selection_get_user_data, since it is not useful.
  108. -- gpointer gtk_tree_selection_get_user_data (GtkTreeSelection
  109. -- *selection); Returns the user data for the selection
  110. -- function. selection : A GtkTreeSelection. Returns : The user
  111. -- data.
  112. feature -- View
  113. tree_view: GTK_TREE_VIEW is
  114. -- the tree view associated with selection.
  115. local factory: G_OBJECT_EXPANDED_FACTORY[GTK_TREE_VIEW]
  116. do
  117. Result :=factory.wrapper (gtk_tree_selection_get_tree_view (handle))
  118. ensure result_not_void: Result/=Void
  119. end
  120. is_node_selected: BOOLEAN is
  121. -- Is there a selected node?
  122. require not_multiple: not is_mode_multiple
  123. do
  124. Result:=(gtk_tree_selection_get_selected (handle, default_pointer, default_pointer)).to_boolean
  125. end
  126. feature -- selections
  127. selected: GTK_TREE_ITER is
  128. -- the currently selected node if selection is set to
  129. -- `gtk_selection_single' or `gtk_selection_browse'.
  130. require not_multiple: not is_mode_multiple
  131. local discarded_result: INTEGER
  132. do
  133. create Result.make
  134. discarded_result := gtk_tree_selection_get_selected (handle, default_pointer, Result.handle)
  135. end
  136. -- TODO: gtk_tree_selection_selected_foreach ()
  137. -- void gtk_tree_selection_selected_foreach
  138. -- (GtkTreeSelection *selection,
  139. -- GtkTreeSelectionForeachFunc func,
  140. -- gpointer data);
  141. -- Calls a function for each selected node. Note that you cannot modify the tree or selection from within this function. As a result, gtk_tree_selection_get_selected_rows() might be more useful.
  142. -- selection : A GtkTreeSelection.
  143. -- func : The function to call for each selected node.
  144. -- data : user data to pass to the function.
  145. selected_rows: G_LIST [GTK_TREE_PATH] is
  146. -- A (newly allocated) list of paths of all selected
  147. -- rows. TODO: Eiffellize this Additionally, if you are
  148. -- planning on modifying the model after calling this
  149. -- function, you may want to convert the returned list into a
  150. -- list of GtkTreeRowReferences. To do this, you can use
  151. -- gtk_tree_row_reference_new().
  152. do
  153. create {GTK_TREE_PATH_LIST} Result.from_external_pointer
  154. (gtk_tree_selection_get_selected_rows(handle,default_pointer))
  155. -- To free the return value, use:
  156. -- g_list_foreach (list, gtk_tree_path_free, NULL);
  157. -- g_list_free (list);
  158. -- selection : A GtkTreeSelection.
  159. -- model : A pointer to set to the GtkTreeModel, or NULL.
  160. -- Returns : A GList containing a GtkTreePath for each selected row.
  161. end
  162. selected_rows_count: INTEGER is
  163. -- the number of rows that have been selected in tree.
  164. do
  165. Result := gtk_tree_selection_count_selected_rows (handle)
  166. end
  167. select_path (a_path: GTK_TREE_PATH) is
  168. -- Select the row at `a_path'.
  169. require path_not_void: a_path/=Void
  170. do
  171. gtk_tree_selection_select_path (handle, a_path.handle)
  172. ensure selected: is_path_selected (a_path)
  173. end
  174. unselect_path (a_path: GTK_TREE_PATH) is
  175. -- Unselect the row at `a_path'.
  176. require path_not_void: a_path/=Void
  177. do
  178. gtk_tree_selection_unselect_path (handle, a_path.handle)
  179. ensure unselected: not is_path_selected (a_path)
  180. end
  181. is_path_selected (a_path: GTK_TREE_PATH): BOOLEAN is
  182. -- Is the row pointed to by `a_path' currently selected?
  183. -- False if `a_path' does not point to a valid location.
  184. do
  185. Result:=(gtk_tree_selection_path_is_selected(handle,a_path.handle)).to_boolean
  186. end
  187. select_iter (an_iter: GTK_TREE_ITER) is
  188. -- Selects the specified iterator (`an_iter').
  189. require iterator_not_void: an_iter/=Void
  190. do
  191. gtk_tree_selection_select_iter (handle, an_iter.handle)
  192. ensure selected: is_iter_selected(an_iter)
  193. end
  194. unselect_iter (an_iter: GTK_TREE_ITER) is
  195. -- Unselects the specified iterator (`an_iter').
  196. require iterator_not_void: an_iter/=Void
  197. do
  198. gtk_tree_selection_unselect_iter (handle, an_iter.handle)
  199. ensure unselected: not is_iter_selected(an_iter)
  200. end
  201. is_iter_selected (an_iter: GTK_TREE_ITER): BOOLEAN is
  202. -- Is the row at `an_iter' currently selected?
  203. require iterator_not_void: an_iter/=Void
  204. do
  205. Result:=(gtk_tree_selection_iter_is_selected(handle,an_iter.handle)).to_boolean
  206. end
  207. select_all is
  208. -- Selects all the nodes. selection must be set to GTK_SELECTION_MULTIPLE mode.
  209. require multiple_mode: is_mode_multiple
  210. do
  211. gtk_tree_selection_select_all (handle)
  212. end
  213. unselect_all is
  214. -- Unselects all the nodes.
  215. do
  216. gtk_tree_selection_unselect_all (handle)
  217. end
  218. select_range (a_start,an_end: GTK_TREE_PATH) is
  219. -- Selects a range of nodes, determined by `a_start' and
  220. -- `an_end' paths inclusive. Selection must be set to
  221. -- GTK_SELECTION_MULTIPLE mode.
  222. -- `a_start' : The initial node of the range.
  223. -- `an_end' : The final node of the range.
  224. require
  225. multiple_mode: is_mode_multiple
  226. valid_start: a_start /= Void
  227. valid_end: an_end /= Void
  228. do
  229. gtk_tree_selection_select_range (handle, a_start.handle, an_end.handle)
  230. end
  231. unselect_range (a_start,an_end: GTK_TREE_PATH) is
  232. -- Unselects a range of nodes, determined by `a_start' and
  233. -- `an_end' paths inclusive. Selection must be set to
  234. -- GTK_SELECTION_MULTIPLE mode.
  235. -- `a_start' : The initial node of the range.
  236. -- `an_end' : The final node of the range.
  237. require
  238. multiple_mode: is_mode_multiple
  239. valid_start: a_start /= Void
  240. valid_end: an_end /= Void
  241. do
  242. gtk_tree_selection_unselect_range (handle, a_start.handle, an_end.handle)
  243. end
  244. feature -- The "changed" signal
  245. changed_signal_name: STRING is "changed"
  246. on_changed is
  247. -- Built-in changed signal handler; empty by design; redefine it.
  248. do
  249. end
  250. enable_on_changed is
  251. -- Connects "changed" signal to `on_changed' feature.
  252. do
  253. connect (Current, changed_signal_name, $on_changed)
  254. end
  255. connect_to_changed_signal (a_procedure: PROCEDURE [ANY, TUPLE[GTK_TREE_SELECTION]]) is
  256. require
  257. valid_procedure: a_procedure /= Void
  258. local
  259. changed_callback: CHANGED_TREE_SELECTION_CALLBACK
  260. do
  261. create changed_callback.make
  262. changed_callback.connect (Current, a_procedure)
  263. end
  264. -- void user_function (GtkTreeSelection *treeselection,
  265. -- gpointer user_data);
  266. -- Emitted whenever the selection has (possibly) changed. Please note that this signal is mostly a hint. It may only be emitted once when a range of rows are selected, and it may occasionally be emitted when nothing has happened.
  267. -- treeselection : the object which received the signal.
  268. -- user_data : user data set when the signal handler was connected.
  269. -- See Also
  270. -- GtkTreeView, GtkTreeViewColumn, GtkTreeDnd, GtkTreeMode, GtkTreeSortable,
  271. -- GtkTreeModelSort, GtkListStore, GtkTreeStore, GtkCellRenderer, GtkCellEditable,
  272. -- GtkCellRendererPixbuf, GtkCellRendererText, GtkCellRendererToggle
  273. -- TODO: Unwrapped
  274. -- GtkTreeSelectionFunc ()
  275. -- gboolean (*GtkTreeSelectionFunc) (GtkTreeSelection *selection,
  276. -- GtkTreeModel *model,
  277. -- GtkTreePath *path,
  278. -- gboolean path_currently_selected,
  279. -- gpointer data);
  280. -- A function used by gtk_tree_selection_set_select_function() to filter whether or not a row may be selected. It is called whenever a row's state might change. A return value of TRUE indicates to selection that it is okay to change the selection.
  281. -- selection : A GtkTreeSelection
  282. -- model : A GtkTreeModel being viewed
  283. -- path : The GtkTreePath of the row in question
  284. -- path_currently_selected : TRUE, if the path is currently selected
  285. -- data : user data
  286. -- Returns : TRUE, if the selection state of the row can be toggled
  287. -- GtkTreeSelectionForeachFunc ()
  288. -- void (*GtkTreeSelectionForeachFunc) (GtkTreeModel *model,
  289. -- GtkTreePath *path,
  290. -- GtkTreeIter *iter,
  291. -- gpointer data);
  292. -- A function used by gtk_tree_selection_selected_foreach() to map all selected rows. It will be called on every selected row in the view.
  293. -- model : The GtkTreeModel being viewed
  294. -- path : The GtkTreePath of a selected row
  295. -- iter : A GtkTreeIter pointing to a selected row
  296. -- data : user data
  297. feature -- struct size
  298. struct_size: INTEGER is
  299. external "C inline use <gtk/gtk.h>"
  300. alias "sizeof(GtkTreeSelection)"
  301. end
  302. end