/src/wrappers/gtk/library/gtk_combo_box.e

http://github.com/tybor/Liberty · Specman e · 511 lines · 195 code · 114 blank · 202 comment · 4 complexity · 2d1978bfc8c4064d679bd3582a757b08 MD5 · raw file

  1. indexing
  2. description: "GtkComboBox -- A widget used to choose from a list of items."
  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_COMBO_BOX
  19. -- A GtkComboBox is a widget that allows the user to choose from a
  20. -- list of valid choices. The GtkComboBox displays the selected
  21. -- choice. When activated, the GtkComboBox displays a popup which
  22. -- allows the user to make a new choice. The style in which the
  23. -- selected value is displayed, and the style of the popup is
  24. -- determined by the current theme. It may be similar to a
  25. -- GtkOptionMenu, or similar to a Windows-style combo box.
  26. -- Unlike its predecessors GtkCombo and GtkOptionMenu, the
  27. -- GtkComboBox uses the model-view pattern; the list of valid
  28. -- choices is specified in the form of a tree model, and the
  29. -- display of the choices can be adapted to the data in the model
  30. -- by using cell renderers, as you would in a tree view. This is
  31. -- possible since GtkComboBox implements the GtkCellLayout
  32. -- interface. The tree model holding the valid choices is not
  33. -- restricted to a flat list, it can be a real tree, and the popup
  34. -- will reflect the tree structure.
  35. -- In addition to the model-view API, GtkComboBox offers a simple
  36. -- API which is suitable for text-only combo boxes, and hides the
  37. -- complexity of managing the data in a model. It consists of the
  38. -- functions `with_text', `append_text', `insert_text',
  39. -- `prepend_text', `remove_text' and `active_text'.
  40. inherit
  41. GTK_BIN
  42. GTK_CELL_EDITABLE
  43. GTK_CELL_LAYOUT
  44. undefine
  45. store_eiffel_wrapper
  46. end
  47. -- GtkComboBox also implements AtkImplementorIface interface.
  48. insert
  49. GTK_COMBO_BOX_EXTERNALS
  50. creation make, with_text_only, from_external_pointer
  51. feature {} -- Creation
  52. make is
  53. -- Creates a new empty GtkComboBox.
  54. do
  55. from_external_pointer (gtk_combo_box_new)
  56. is_text_only:=False
  57. ensure no_text_only: not is_text_only
  58. end
  59. with_model (a_model: GTK_TREE_MODEL) is
  60. -- Creates a new GtkComboBox with `a_model'.
  61. do
  62. from_external_pointer (gtk_combo_box_new_with_model (handle))
  63. is_text_only:=False
  64. ensure no_text_only: not is_text_only
  65. end
  66. feature -- Model-related features
  67. wrap_width: INTEGER is
  68. -- the wrap width which is used to determine the number of
  69. -- columns for the popup menu. If the wrap width is larger
  70. -- than 1, the combo box is in table mode.
  71. require no_simple_api: not is_text_only
  72. do
  73. Result:=gtk_combo_box_get_wrap_width (handle)
  74. end
  75. set_wrap_width (a_width: INTEGER) is
  76. -- Sets the wrap width of combo_box to be `a_width'. The wrap
  77. -- width is basically the preferred number of columns when
  78. -- you want the popup to be layed out in a table.
  79. require no_simple_api: not is_text_only
  80. do
  81. gtk_combo_box_set_wrap_width (handle, a_width)
  82. end
  83. row_span_column: INTEGER is
  84. -- the column with row span information for combo_box.
  85. require no_simple_api: not is_text_only
  86. do
  87. Result := gtk_combo_box_get_row_span_column (handle)
  88. end
  89. set_row_span_column (a_row_span: INTEGER) is
  90. -- Sets the column with row span information for combo_box to
  91. -- be row_span. The row span column contains integers which
  92. -- indicate how many rows an item should span.
  93. require no_simple_api: not is_text_only
  94. do
  95. gtk_combo_box_set_row_span_column (handle, a_row_span)
  96. end
  97. column_span_column: INTEGER is
  98. -- the column with column span information for combo_box.
  99. require no_simple_api: not is_text_only
  100. do
  101. Result:= gtk_combo_box_get_column_span_column (handle)
  102. end
  103. set_column_span_column (a_column_span: INTEGER) is
  104. -- Sets the column with column span information for combo_box
  105. -- to be column_span. The column span column contains
  106. -- integers which indicate how many columns an item should
  107. -- span.
  108. require no_simple_api: not is_text_only
  109. do
  110. gtk_combo_box_set_column_span_column (handle, a_column_span)
  111. end
  112. active_row: INTEGER is
  113. -- the index of the currently active item, or -1 if there's
  114. -- no active item. If the model is a non-flat treemodel, and
  115. -- the active item is not an immediate child of the root of
  116. -- the tree, this function returns the result of the C call
  117. -- "gtk_tree_path_get_indices (path)[0]", where path is the
  118. -- GtkTreePath of the active item.
  119. require no_simple_api: not is_text_only
  120. do
  121. Result := gtk_combo_box_get_active (handle)
  122. end
  123. active_column: INTEGER is
  124. obsolete "Renamed this feature to `active_row' which is a better name"
  125. do
  126. Result := active_row
  127. end
  128. set_active (an_index: INTEGER) is
  129. -- Sets the active item of combo_box to be the item at index.
  130. require no_simple_api: not is_text_only
  131. do
  132. gtk_combo_box_set_active (handle,an_index)
  133. end
  134. active_iter: GTK_TREE_ITER is
  135. -- An iterator pointing to the current active item, if it
  136. -- exists. Otherwise Void
  137. require no_simple_api: not is_text_only
  138. local gbool: INTEGER
  139. do
  140. create Result.make -- a newly allocated iterator
  141. gbool := gtk_combo_box_get_active_iter (handle, Result.handle)
  142. if gbool=0 then Result:=Void end
  143. end
  144. set_active_iter (an_iterator: GTK_TREE_ITER) is
  145. -- Sets the current active item to be the one referenced by
  146. -- `an_iterator' that must correspond to a path of depth one.
  147. require
  148. no_simple_api: not is_text_only
  149. -- TODO: an_iterator.depth = 1
  150. do
  151. gtk_combo_box_set_active_iter (handle, an_iterator.handle)
  152. end
  153. model: GTK_TREE_MODEL is
  154. -- the GtkTreeModel which is acting as data source for
  155. -- combo_box.
  156. require no_simple_api: not is_text_only
  157. local factory: G_OBJECT_EXPANDED_FACTORY [GTK_TREE_MODEL]
  158. do
  159. Result := factory.wrapper(gtk_combo_box_get_model (handle))
  160. end
  161. set_model (a_model: GTK_TREE_MODEL) is
  162. -- Sets the model used by combo_box to be model. Will unset a
  163. -- previously set model (if applicable). If model is NULL,
  164. -- then it will unset the model.
  165. -- Note that this function does not clear the cell renderers,
  166. -- you have to call `cell_layout_clear' yourself if you need
  167. -- to set up different cell renderers for the new model.
  168. require
  169. no_simple_api: not is_text_only
  170. model_not_void: a_model /= Void
  171. do
  172. gtk_combo_box_set_model (handle, a_model.handle)
  173. end
  174. unset_model is
  175. -- Unsets the model used by combo box.
  176. require no_simple_api: not is_text_only
  177. do
  178. gtk_combo_box_set_model (handle, default_pointer)
  179. end
  180. feature {} -- Simplified, text-only API creation
  181. with_text_only is
  182. -- Convenience constructor of a new text combo box, which
  183. -- will display only strings. If you use this function to
  184. -- create a text combo box, you should only manipulate its
  185. -- data source with the following convenience functions:
  186. -- `append_text', `insert_text', `prepend_text'' and
  187. -- `remove_text' as the "simple_api" preconditions state.
  188. do
  189. from_external_pointer (gtk_combo_box_new_text )
  190. is_text_only:=True
  191. ensure text_only: is_text_only
  192. end
  193. feature -- Simplified, text-only API
  194. is_text_only: BOOLEAN
  195. append_text (a_text: STRING) is
  196. -- Appends `a_text' to the list of strings stored in combo box.
  197. require
  198. simple_api: is_text_only
  199. text_not_void: a_text /= Void
  200. do
  201. gtk_combo_box_append_text (handle, a_text.to_external)
  202. end
  203. insert_text (a_text: STRING; a_position: INTEGER) is
  204. -- Inserts `a_text' at `a_position' in the list of strings
  205. -- stored in combo_box.
  206. require
  207. simple_api: is_text_only
  208. text_not_void: a_text /= Void
  209. do
  210. gtk_combo_box_insert_text (handle, a_position, a_text.to_external)
  211. end
  212. prepend_text (a_text: STRING) is
  213. -- Prepends `a_text' to the list of strings stored in combo box.
  214. require
  215. simple_api: is_text_only
  216. text_not_void: a_text /= Void
  217. do
  218. gtk_combo_box_prepend_text (handle, a_text.to_external)
  219. end
  220. remove_text (a_position: INTEGER) is
  221. -- Removes the string at `a_position' from combo box.
  222. require simple_api: is_text_only
  223. do
  224. gtk_combo_box_remove_text (handle, a_position)
  225. end
  226. active_text: STRING is
  227. -- The currently active string in combo_box or Void if none
  228. -- is selected.
  229. require simple_api: is_text_only
  230. local ptr: POINTER
  231. do
  232. ptr := gtk_combo_box_get_active_text (handle)
  233. -- Returns : a newly allocated string containing the
  234. -- currently active text.
  235. if ptr.is_not_null then create Result.from_external(ptr) end
  236. end
  237. feature -- For accessibility technologies
  238. popup is
  239. -- Pops up the menu or dropdown list of combo box. This
  240. -- function is mostly intended for use by accessibility
  241. -- technologies; applications should have little use for it.
  242. do
  243. gtk_combo_box_popup (handle)
  244. end
  245. popdown is
  246. -- Hides the menu or dropdown list of combo_box. This
  247. -- function is mostly intended for use by accessibility
  248. -- technologies; applications should have little use for it.
  249. do
  250. gtk_combo_box_popdown (handle)
  251. end
  252. -- TODO: popup_accessible_object: ATK_OBJECT is AtkObject*
  253. -- gtk_combo_box_get_popup_accessible (GtkComboBox *combo_box);
  254. -- Gets the accessible object corresponding to the combo box's
  255. -- popup. This function is mostly intended for use by accessibility
  256. -- technologies; applications should have little use for it.
  257. -- gtk_combo_box_get_row_separator_func ()
  258. -- GtkTreeViewRowSeparatorFunc gtk_combo_box_get_row_separator_func
  259. -- (GtkComboBox *combo_box);
  260. -- Returns the current row separator function.
  261. -- combo_box : a GtkComboBox
  262. -- Returns : the current row separator function.
  263. -- Since 2.6
  264. -- gtk_combo_box_set_row_separator_func ()
  265. -- void gtk_combo_box_set_row_separator_func
  266. -- (GtkComboBox *combo_box,
  267. -- GtkTreeViewRowSeparatorFunc func,
  268. -- gpointer data,
  269. -- GtkDestroyNotify destroy);
  270. -- Sets the row separator function, which is used to determine whether a row should be drawn as a separator. If the row separator function is NULL, no separators are drawn. This is the default value.
  271. -- combo_box : a GtkComboBox
  272. -- func : a GtkTreeViewRowSeparatorFunc
  273. -- data : user data to pass to func, or NULL
  274. -- destroy : destroy notifier for data, or NULL
  275. -- Since 2.6
  276. -- gtk_combo_box_set_add_tearoffs ()
  277. -- void gtk_combo_box_set_add_tearoffs (GtkComboBox *combo_box,
  278. -- gboolean add_tearoffs);
  279. -- Sets whether the popup menu should have a tearoff menu item.
  280. -- combo_box : a GtkComboBox
  281. -- add_tearoffs : TRUE to add tearoff menu items
  282. -- Since 2.6
  283. -- gtk_combo_box_get_add_tearoffs ()
  284. -- gboolean gtk_combo_box_get_add_tearoffs (GtkComboBox *combo_box);
  285. -- Gets the current value of the :add-tearoffs property.
  286. -- combo_box : a GtkComboBox
  287. -- Returns : the current value of the :add-tearoffs property.
  288. -- gtk_combo_box_set_focus_on_click ()
  289. -- void gtk_combo_box_set_focus_on_click
  290. -- (GtkComboBox *combo,
  291. -- gboolean focus_on_click);
  292. -- Sets whether the combo box will grab focus when it is clicked with the mouse. Making mouse clicks not grab focus is useful in places like toolbars where you don't want the keyboard focus removed from the main area of the application.
  293. -- combo : a GtkComboBox
  294. -- focus_on_click : whether the combo box grabs focus when clicked with the mouse
  295. -- Since 2.6
  296. -- gtk_combo_box_get_focus_on_click ()
  297. -- gboolean gtk_combo_box_get_focus_on_click
  298. -- (GtkComboBox *combo);
  299. -- Returns whether the combo box grabs focus when it is clicked with the mouse. See gtk_combo_box_set_focus_on_click().
  300. -- combo : a GtkComboBox
  301. -- Returns : TRUE if the combo box grabs focus when it is clicked with the mouse.
  302. -- Since 2.6
  303. feature -- Properties
  304. -- "active" gint : Read / Write
  305. -- "add-tearoffs" gboolean : Read / Write
  306. -- "column-span-column" gint : Read / Write
  307. -- "focus-on-click" gboolean : Read / Write
  308. -- "has-frame" gboolean : Read / Write
  309. -- "model" GtkTreeModel : Read / Write
  310. -- "row-span-column" gint : Read / Write
  311. -- "wrap-width" gint : Read / Write
  312. -- Style Properties
  313. -- "appears-as-list" gboolean : Read
  314. -- Property Details
  315. -- The "active" property
  316. -- "active" gint : Read / Write
  317. -- The item which is currently active. If the model is a non-flat treemodel, and the active item is not an immediate child of the root of the tree, this property has the value gtk_tree_path_get_indices (path)[0], where path is the GtkTreePath of the active item.
  318. -- Allowed values: >= -1
  319. -- Default value: -1
  320. -- Since 2.4
  321. -- The "add-tearoffs" property
  322. -- "add-tearoffs" gboolean : Read / Write
  323. -- The add-tearoffs property controls whether generated menus have tearoff menu items.
  324. -- Note that this only affects menu style combo boxes.
  325. -- Default value: FALSE
  326. -- Since 2.6
  327. -- The "column-span-column" property
  328. -- "column-span-column" gint : Read / Write
  329. -- If this is set to a non-negative value, it must be the index of a column of type G_TYPE_INT in the model.
  330. -- The values of that column are used to determine how many columns a value in the list will span.
  331. -- Allowed values: >= -1
  332. -- Default value: -1
  333. -- Since 2.4
  334. -- The "focus-on-click" property
  335. -- "focus-on-click" gboolean : Read / Write
  336. -- Whether the combo box grabs focus when it is clicked with the mouse.
  337. -- Default value: TRUE
  338. -- The "has-frame" property
  339. -- "has-frame" gboolean : Read / Write
  340. -- The has-frame property controls whether a frame is drawn around the entry.
  341. -- Default value: TRUE
  342. -- Since 2.6
  343. -- The "model" property
  344. -- "model" GtkTreeModel : Read / Write
  345. -- The model from which the combo box takes the values shown in the list.
  346. -- Since 2.4
  347. -- The "row-span-column" property
  348. -- "row-span-column" gint : Read / Write
  349. -- If this is set to a non-negative value, it must be the index of a column of type G_TYPE_INT in the model.
  350. -- The values of that column are used to determine how many rows a value in the list will span. Therefore, the values in the model column pointed to by this property must be greater than zero and not larger than wrap-width.
  351. -- Allowed values: >= -1
  352. -- Default value: -1
  353. -- Since 2.4
  354. -- The "wrap-width" property
  355. -- "wrap-width" gint : Read / Write
  356. -- If wrap-width is set to a positive value, the list will be displayed in multiple columns, the number of columns is determined by wrap-width.
  357. -- Allowed values: >= 0
  358. -- Default value: 0
  359. -- Since 2.4
  360. -- Style Property Details
  361. -- The "appears-as-list" style property
  362. -- "appears-as-list" gboolean : Read
  363. -- Whether dropdowns should look like lists rather than menus.
  364. -- Default value: FALSE
  365. feature -- The "changed" signal
  366. changed_signal_name: STRING is "changed"
  367. enable_on_changed is
  368. -- Connects "changed" signal to `on_changed' feature.
  369. do
  370. connect (Current, changed_signal_name, $on_changed)
  371. end
  372. on_changed is
  373. -- Built-in changed signal handler; empty by design; redefine it.
  374. -- The `changed' signal is emitted when the active item is changed.
  375. -- The can be due to the user selecting a different item from the list,
  376. -- or due to a call to gtk_combo_box_set_active_iter(). It will also be
  377. -- emitted while typing into a GtkComboBoxEntry, as well as when
  378. -- selecting an item from the GtkComboBoxEntry's list.
  379. do
  380. end
  381. connect_agent_to_changed_signal (a_procedure: PROCEDURE [ANY, TUPLE[GTK_COMBO_BOX]]) is
  382. -- widget : the object which received the signal
  383. -- user_data : user data set when the signal handler was connected.
  384. require
  385. valid_procedure: a_procedure /= Void
  386. local
  387. changed_callback: CHANGED_CALLBACK[like Current]
  388. do
  389. create changed_callback.make
  390. changed_callback.connect (Current, a_procedure)
  391. end
  392. feature -- size
  393. struct_size: INTEGER is
  394. external "C inline use <gtk/gtk.h>"
  395. alias "sizeof(GtkComboBox)"
  396. end
  397. end