/src/wrappers/gtk/library/gtk_entry_completion.e

http://github.com/tybor/Liberty · Specman e · 423 lines · 141 code · 103 blank · 179 comment · 2 complexity · 141af37cc4c469e01888852cef2924d3 MD5 · raw file

  1. indexing
  2. description: "GtkEntryCompletion -- Completion functionality for GtkEntry"
  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_ENTRY_COMPLETION
  19. -- GtkEntryCompletion is an auxiliary object to be used in conjunction with
  20. -- GtkEntry to provide the completion functionality. It implements the
  21. -- GtkCellLayout interface, to allow the user to add extra cells to the
  22. -- GtkTreeView with completion matches.
  23. -- "Completion functionality" means that when the user modifies the text in
  24. -- the entry, GtkEntryCompletion checks which rows in the model match the
  25. -- current content of the entry, and displays a list of matches. By default,
  26. -- the matching is done by comparing the entry text case-insensitively
  27. -- against the text columqn of the model (see `set_text_column'), but this
  28. -- can be overridden with a custom match function (see `set_match_func').
  29. -- When the user selects a completion, the content of the entry is
  30. -- updated. By default, the content of the entry is replaced by the
  31. -- text column of the model, but this can be overridden by connecting
  32. -- to the ::match-selected signal and updating the entry in the signal
  33. -- handler. Note that you should return TRUE from the signal handler
  34. -- to suppress the default behaviour. To add completion functionality
  35. -- to an entry, use gtk_entry_set_completion().
  36. -- In addition to regular completion matches, which will be inserted
  37. -- into the entry when they are selected, GtkEntryCompletion also
  38. -- allows to display "actions" in the popup window. Their appearance
  39. -- is similar to menuitems, to differentiate them clearly from
  40. -- completion strings. When an action is selected, the
  41. -- ::action-activated signal is emitted.
  42. inherit
  43. G_OBJECT
  44. GTK_CELL_LAYOUT
  45. G_SIGNALS
  46. insert
  47. GTK_ENTRY_COMPLETION_EXTERNALS
  48. G_OBJECT_FACTORY [GTK_TREE_MODEL]
  49. creation make, from_external_pointer
  50. feature {} -- Creation
  51. make is
  52. -- Creates a new GtkEntryCompletion object.
  53. do
  54. from_external_pointer (gtk_entry_completion_new)
  55. end
  56. feature
  57. entry: GTK_ENTRY is
  58. -- the entry completion has been attached to.
  59. local factory: G_OBJECT_EXPANDED_FACTORY[GTK_ENTRY]
  60. do
  61. Result := factory.wrapper (gtk_entry_completion_get_entry (handle))
  62. end
  63. set_model (a_model: GTK_TREE_MODEL) is
  64. -- Sets `a_model' for a GtkEntryCompletion. If completion
  65. -- already has a model set, it will remove it before setting
  66. -- the new model.
  67. require
  68. valid_model: a_model /= Void
  69. do
  70. gtk_entry_completion_set_model (handle, a_model.handle)
  71. end
  72. unset_model is
  73. -- Unsets the model for GtkEntryCompletion.
  74. do
  75. gtk_entry_completion_set_model (handle, default_pointer)
  76. end
  77. model: GTK_TREE_MODEL is
  78. -- the model the GtkEntryCompletion is using as data source
  79. require
  80. is_model_set
  81. do
  82. Result := wrapper (gtk_entry_completion_get_model (handle))
  83. end
  84. is_model_set: BOOLEAN is
  85. -- Is the model of GtkEntryCompletion set?
  86. do
  87. Result := (gtk_entry_completion_get_model (handle)).is_not_null
  88. end
  89. -- TODO: set_match_func ()
  90. -- void gtk_entry_completion_set_match_func (GtkEntryCompletion
  91. -- *completion, -- GtkEntryCompletionMatchFunc func, -- gpointer
  92. -- func_data, -- GDestroyNotify func_notify);
  93. -- Sets the match function for completion to be func. The match function is used to determine if a row should or should not be in the completion list.
  94. -- completion : A GtkEntryCompletion.
  95. -- func : The GtkEntryCompletionMatchFunc to use.
  96. -- func_data : The user data for func.
  97. -- func_notify : Destroy notifier for func_data.
  98. set_minimum_key_length (a_length: INTEGER) is
  99. -- Requires the length of the search key for completion to be
  100. -- at least `a_length'. This is useful for long lists, where
  101. -- completing using a small key takes a lot of time and will
  102. -- come up with meaningless results anyway (ie, a too large
  103. -- dataset).
  104. do
  105. gtk_entry_completion_set_minimum_key_length (handle, a_length)
  106. end
  107. minimum_key_length: INTEGER is
  108. -- the minimum key length as set for completion.
  109. do
  110. Result := gtk_entry_completion_get_minimum_key_length (handle)
  111. end
  112. complete is
  113. -- Requests a completion operation, or in other words a
  114. -- refiltering of the current list with completions, using
  115. -- the current key. The completion list view will be updated
  116. -- accordingly.
  117. do
  118. gtk_entry_completion_complete (handle)
  119. end
  120. insert_prefix is
  121. -- Requests a prefix insertion.
  122. do
  123. gtk_entry_completion_insert_prefix (handle)
  124. end
  125. insert_action_text (an_index: INTEGER; a_text: STRING) is
  126. -- Inserts an action in completion's action item list at
  127. -- position index_ with text text. If you want the action
  128. -- item to have markup, use
  129. -- gtk_entry_completion_insert_action_markup().
  130. require
  131. valid_text: a_text /= Void
  132. do
  133. gtk_entry_completion_insert_action_text (handle, an_index,a_text.to_external)
  134. end
  135. set_text_column (a_column: INTEGER) is
  136. -- Convenience function for setting up the most used case of this code:
  137. -- a completion list with just strings.
  138. -- This function will set up completion to have a list displaying all (and just)
  139. -- strings in the completion list, and to get those strings from column
  140. -- in the model of completion.
  141. -- This functions creates and adds a GtkCellRendererText for the selected column.
  142. -- If you need to set the text column, but don't want the cell renderer,
  143. -- use g_object_set() to set the ::text_column property directly.
  144. do
  145. gtk_entry_completion_set_text_column (handle, a_column)
  146. end
  147. text_column: INTEGER is
  148. -- Returns the column in the model of completion to get
  149. -- strings from.
  150. do
  151. Result := gtk_entry_completion_get_text_column (handle)
  152. end
  153. set_inline_completion (a_boolean: BOOLEAN) is
  154. -- Sets whether the common prefix of the possible completions
  155. -- should be automatically inserted in the entry.
  156. do
  157. gtk_entry_completion_set_inline_completion (handle, a_boolean.to_integer)
  158. end
  159. inline_completion: BOOLEAN is
  160. -- Returns whether the common prefix of the possible completions
  161. -- should be automatically inserted in the entry.
  162. do
  163. Result := gtk_entry_completion_get_inline_completion (handle).to_boolean
  164. end
  165. -- Since 2.4
  166. -- gtk_entry_completion_insert_action_markup ()
  167. -- void gtk_entry_completion_insert_action_markup
  168. -- (GtkEntryCompletion *completion,
  169. -- gint index_,
  170. -- const gchar *markup);
  171. -- Inserts an action in completion's action item list at position index_ with markup markup.
  172. -- completion : A GtkEntryCompletion.
  173. -- index_ : The index of the item to insert.
  174. -- markup : Markup of the item to insert.
  175. -- Since 2.4
  176. -- gtk_entry_completion_delete_action ()
  177. -- void gtk_entry_completion_delete_action
  178. -- (GtkEntryCompletion *completion,
  179. -- gint index_);
  180. -- Deletes the action at index_ from completion's action list.
  181. -- completion : A GtkEntryCompletion.
  182. -- index_ : The index of the item to Delete.
  183. set_popup_completion (a_boolean: BOOLEAN) is
  184. -- Sets whether the completions should be presented in a popup window.
  185. do
  186. gtk_entry_completion_set_popup_completion (handle, a_boolean.to_integer)
  187. end
  188. popup_completion: BOOLEAN is
  189. -- Returns whether the completions should be presented in a popup window.
  190. do
  191. Result := gtk_entry_completion_get_popup_completion (handle).to_boolean
  192. end
  193. set_popup_set_width (a_boolean: BOOLEAN) is
  194. -- Sets whether the completion popup window will be resized to
  195. -- be the same width as the entry.
  196. do
  197. gtk_entry_completion_set_popup_set_width (handle, a_boolean.to_integer)
  198. end
  199. popup_set_width: BOOLEAN is
  200. -- Returns whether the completion popup window will be resized
  201. -- to the width of the entry.
  202. do
  203. Result := gtk_entry_completion_get_popup_set_width (handle).to_boolean
  204. end
  205. set_popup_single_match (a_boolean: BOOLEAN) is
  206. -- Sets whether the completion popup window will appear even if
  207. -- there is only a single match.
  208. -- You may want to set this to FALSE if you are using inline completion.
  209. do
  210. gtk_entry_completion_set_popup_single_match (handle, a_boolean.to_integer)
  211. end
  212. popup_single_match: BOOLEAN is
  213. -- Returns whether the completion popup window will appear even if
  214. -- there is only a single match.
  215. do
  216. Result := gtk_entry_completion_get_popup_single_match (handle).to_boolean
  217. end
  218. -- Since 2.8
  219. -- Property Details
  220. -- The "inline-completion" property
  221. -- "inline-completion" gboolean : Read / Write
  222. -- Determines whether the common prefix of the possible completions should be inserted automatically in the entry. Note that this requires text-column to be set, even if you are using a custom match function.
  223. -- Default value: FALSE
  224. -- Since 2.6
  225. -- The "minimum-key-length" property
  226. -- "minimum-key-length" gint : Read / Write
  227. -- Minimum length of the search key in order to look up matches.
  228. -- Allowed values: >= 0
  229. -- Default value: 1
  230. -- The "model" property
  231. -- "model" GtkTreeModel : Read / Write
  232. -- The model to find matches in.
  233. -- The "popup-completion" property
  234. -- "popup-completion" gboolean : Read / Write
  235. -- Determines whether the possible completions should be shown in a popup window.
  236. -- Default value: TRUE
  237. -- Since 2.6
  238. -- The "popup-set-width" property
  239. -- "popup-set-width" gboolean : Read / Write
  240. -- Determines whether the completions popup window will be resized to the width of the entry.
  241. -- Default value: TRUE
  242. -- Since 2.8
  243. -- The "popup-single-match" property
  244. -- "popup-single-match" gboolean : Read / Write
  245. -- Determines whether the completions popup window will shown for a single possible completion. You probably want to set this to FALSE if you are using inline completion.
  246. -- Default value: TRUE
  247. -- Since 2.8
  248. -- The "text-column" property
  249. -- "text-column" gint : Read / Write
  250. -- The column of the model containing the strings.
  251. -- Allowed values: >= -1
  252. -- Default value: -1
  253. -- Since 2.6
  254. -- Signal Details
  255. -- The "action-activated" signal
  256. -- void user_function (GtkEntryCompletion *widget,
  257. -- gint index,
  258. -- gpointer user_data);
  259. -- Gets emitted when an action is activated.
  260. -- widget : the object which received the signal
  261. -- index : the index of the activated action
  262. -- user_data : user data set when the signal handler was connected.
  263. -- Since 2.4
  264. -- The "insert-prefix" signal
  265. -- gboolean user_function (GtkEntryCompletion *widget,
  266. -- gchar *prefix,
  267. -- gpointer user_data);
  268. -- Gets emitted when the inline autocompletion is triggered. The default behaviour is to make the entry display the whole prefix and select the newly inserted part.
  269. -- Applications may connect to this signal in order to insert only a smaller part of the prefix into the entry - e.g. the entry used in the GtkFileChooser inserts only the part of the prefix up to the next '/'.
  270. -- widget : the object which received the signal
  271. -- prefix : the common prefix of all possible completions
  272. -- user_data : user data set when the signal handler was connected.
  273. -- Returns : TRUE if the signal has been handled
  274. feature -- The "match-selected" signal
  275. match_selected_signal_name: STRING is "match-selected"
  276. on_match_selected is
  277. -- Built-in clicked signal handler; empty by design; redefine it.
  278. do
  279. end
  280. enable_on_match_selected is
  281. -- Connects "match-selected" signal to `on_match_selected' feature.
  282. -- Emitted when the button has been activated (pressed and released).
  283. -- Gets emitted when a match from the list is selected.
  284. -- The default behaviour is to replace the contents of the entry
  285. -- with the contents of the text column in the row pointed to by iter.
  286. do
  287. connect (Current, match_selected_signal_name, $on_match_selected)
  288. end
  289. connect_agent_to_match_selected_signal (a_function: FUNCTION [ANY, TUPLE [GTK_TREE_MODEL, GTK_TREE_ITER, GTK_ENTRY_COMPLETION], BOOLEAN]) is
  290. -- widget : the object which received the signal
  291. -- model : the GtkTreeModel containing the matches
  292. -- iter : a GtkTreeIter positioned at the selected match
  293. require valid_function: a_function /= Void
  294. local match_selected_callback: MATCH_SELECTED_CALLBACK
  295. do
  296. create match_selected_callback.make
  297. match_selected_callback.connect (Current, a_function)
  298. end
  299. -- Since 2.4
  300. -- Details
  301. -- GtkEntryCompletion
  302. -- typedef struct _GtkEntryCompletion GtkEntryCompletion;
  303. -- The GtkEntryCompletion struct contains only private data.
  304. -- GtkEntryCompletionMatchFunc ()
  305. -- gboolean (*GtkEntryCompletionMatchFunc) (GtkEntryCompletion *completion,
  306. -- const gchar *key,
  307. -- GtkTreeIter *iter,
  308. -- gpointer user_data);
  309. -- A function which decides whether the row indicated by iter matches a given key, and should be displayed as a possible completion for key. Note that key is normalized and case-folded (see g_utf8_normalize() and g_utf8_casefold()). If this is not appropriate, match functions have access to the unmodified key via gtk_entry_get_text (GTK_ENTRY (gtk_entry_completion_get_entry ())).
  310. -- completion : the GtkEntryCompletion
  311. -- key : the string to match, normalized and case-folded
  312. -- iter : a GtkTreeIter indicating the row to match
  313. -- user_data : user data given to gtk_entry_completion_set_match_func()
  314. -- Returns : TRUE if iter should be displayed as a possible completion for key
  315. feature
  316. struct_size: INTEGER is
  317. external "C inline use <gtk/gtk.h>"
  318. alias "sizeof(GtkEntryCompletion)"
  319. end
  320. end -- class GTK_ENTRY_COMPLETION