PageRenderTime 27ms CodeModel.GetById 17ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/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
  1indexing
  2	description: "GtkEntryCompletion -- Completion functionality for GtkEntry"
  3	copyright: "[
  4					Copyright (C) 2006 eiffel-libraries team, GTK+ team
  5					
  6					This library is free software; you can redistribute it and/or
  7					modify it under the terms of the GNU Lesser General Public License
  8					as published by the Free Software Foundation; either version 2.1 of
  9					the License, or (at your option) any later version.
 10					
 11					This library is distributed in the hope that it will be useful, but
 12					WITHOUT ANY WARRANTY; without even the implied warranty of
 13					MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14					Lesser General Public License for more details.
 15
 16					You should have received a copy of the GNU Lesser General Public
 17					License along with this library; if not, write to the Free Software
 18					Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 19					02110-1301 USA
 20				]"
 21
 22class GTK_ENTRY_COMPLETION
 23	-- GtkEntryCompletion is an auxiliary object to be used in conjunction with
 24	-- GtkEntry to provide the completion functionality. It implements the
 25	-- GtkCellLayout interface, to allow the user to add extra cells to the
 26	-- GtkTreeView with completion matches.
 27	
 28	-- "Completion functionality" means that when the user modifies the text in
 29	-- the entry, GtkEntryCompletion checks which rows in the model match the
 30	-- current content of the entry, and displays a list of matches. By default,
 31	-- the matching is done by comparing the entry text case-insensitively
 32	-- against the text columqn of the model (see `set_text_column'), but this
 33	-- can be overridden with a custom match function (see `set_match_func').
 34
 35	-- When the user selects a completion, the content of the entry is
 36	-- updated. By default, the content of the entry is replaced by the
 37	-- text column of the model, but this can be overridden by connecting
 38	-- to the ::match-selected signal and updating the entry in the signal
 39	-- handler. Note that you should return TRUE from the signal handler
 40	-- to suppress the default behaviour.  To add completion functionality
 41	-- to an entry, use gtk_entry_set_completion().
 42
 43	-- In addition to regular completion matches, which will be inserted
 44	-- into the entry when they are selected, GtkEntryCompletion also
 45	-- allows to display "actions" in the popup window. Their appearance
 46	-- is similar to menuitems, to differentiate them clearly from
 47	-- completion strings. When an action is selected, the
 48	-- ::action-activated signal is emitted.
 49
 50inherit
 51	G_OBJECT
 52	GTK_CELL_LAYOUT
 53	G_SIGNALS
 54
 55insert
 56	GTK_ENTRY_COMPLETION_EXTERNALS
 57	G_OBJECT_FACTORY [GTK_TREE_MODEL]
 58
 59creation make, from_external_pointer
 60
 61feature {} -- Creation
 62	
 63	make is
 64			-- Creates a new GtkEntryCompletion object.
 65		do
 66			from_external_pointer (gtk_entry_completion_new)
 67		end
 68	
 69feature
 70	entry: GTK_ENTRY is
 71			-- the entry completion has been attached to.
 72		local factory: G_OBJECT_EXPANDED_FACTORY[GTK_ENTRY]
 73		do
 74			Result := factory.wrapper (gtk_entry_completion_get_entry (handle))
 75		end
 76	
 77	set_model (a_model: GTK_TREE_MODEL) is
 78			-- Sets `a_model' for a GtkEntryCompletion. If completion 
 79			-- already has a model set, it will remove it before setting
 80			-- the new model.      
 81		require
 82			valid_model: a_model /= Void
 83		do
 84			gtk_entry_completion_set_model (handle, a_model.handle)
 85		end
 86
 87	unset_model is
 88			-- Unsets the model for GtkEntryCompletion. 
 89		do
 90			gtk_entry_completion_set_model (handle, default_pointer)
 91		end
 92
 93	model: GTK_TREE_MODEL is
 94			-- the model the GtkEntryCompletion is using as data source
 95		require
 96			is_model_set
 97		do
 98			Result := wrapper (gtk_entry_completion_get_model (handle))
 99		end
100	
101	is_model_set: BOOLEAN is
102			-- Is the model of GtkEntryCompletion set?
103		do
104			Result := (gtk_entry_completion_get_model (handle)).is_not_null
105		end
106
107	-- TODO: set_match_func ()
108
109	-- void gtk_entry_completion_set_match_func (GtkEntryCompletion
110	-- *completion, -- GtkEntryCompletionMatchFunc func, -- gpointer
111	-- func_data, -- GDestroyNotify func_notify);
112	
113	-- 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.
114	
115	-- completion : 	A GtkEntryCompletion.
116	-- func : 	The GtkEntryCompletionMatchFunc to use.
117	-- func_data : 	The user data for func.
118	-- func_notify : 	Destroy notifier for func_data.
119
120
121	set_minimum_key_length (a_length: INTEGER) is
122			-- Requires the length of the search key for completion to be
123			-- at least `a_length'. This is useful for long lists, where
124			-- completing using a small key takes a lot of time and will
125			-- come up with meaningless results anyway (ie, a too large
126			-- dataset).
127		do
128			gtk_entry_completion_set_minimum_key_length (handle, a_length)
129		end
130
131	minimum_key_length: INTEGER is
132			-- the minimum key length as set for completion.
133		do
134			Result := gtk_entry_completion_get_minimum_key_length (handle)
135		end
136
137	complete is
138			-- Requests a completion operation, or in other words a
139			-- refiltering of the current list with completions, using
140			-- the current key. The completion list view will be updated
141			-- accordingly.
142		do
143			gtk_entry_completion_complete (handle)
144		end
145
146
147	insert_prefix is
148			-- Requests a prefix insertion.
149		do
150			gtk_entry_completion_insert_prefix (handle)
151		end
152
153	insert_action_text (an_index: INTEGER; a_text: STRING) is
154			-- Inserts an action in completion's action item list at
155			-- position index_ with text text. If you want the action
156			-- item to have markup, use
157			-- gtk_entry_completion_insert_action_markup().
158		require
159			valid_text: a_text /= Void
160		do
161			gtk_entry_completion_insert_action_text (handle, an_index,a_text.to_external)
162		end
163
164	set_text_column (a_column: INTEGER) is
165			-- Convenience function for setting up the most used case of this code:
166			-- a completion list with just strings.
167			-- This function will set up completion to have a list displaying all (and just)
168			-- strings in the completion list, and to get those strings from column
169			-- in the model of completion.
170			-- This functions creates and adds a GtkCellRendererText for the selected column.
171			-- If you need to set the text column, but don't want the cell renderer,
172			-- use g_object_set() to set the ::text_column property directly.
173		do
174			gtk_entry_completion_set_text_column (handle, a_column)
175		end
176
177	text_column: INTEGER is
178			-- Returns the column in the model of completion to get
179			-- strings from.
180		do
181			Result := gtk_entry_completion_get_text_column (handle)
182		end
183
184	set_inline_completion (a_boolean: BOOLEAN) is
185			-- Sets whether the common prefix of the possible completions
186			-- should be automatically inserted in the entry.
187		do
188			gtk_entry_completion_set_inline_completion (handle, a_boolean.to_integer)
189		end
190
191	inline_completion: BOOLEAN is
192			-- Returns whether the common prefix of the possible completions
193			-- should be automatically inserted in the entry.
194		do
195			Result := gtk_entry_completion_get_inline_completion (handle).to_boolean
196		end
197
198	-- Since 2.4
199	-- gtk_entry_completion_insert_action_markup ()
200
201	-- void        gtk_entry_completion_insert_action_markup
202	--                                             (GtkEntryCompletion *completion,
203	--                                              gint index_,
204	--                                              const gchar *markup);
205
206	-- Inserts an action in completion's action item list at position index_ with markup markup.
207
208	-- completion : 	A GtkEntryCompletion.
209	-- index_ : 	The index of the item to insert.
210	-- markup : 	Markup of the item to insert.
211
212	-- Since 2.4
213	-- gtk_entry_completion_delete_action ()
214
215	-- void        gtk_entry_completion_delete_action
216	--                                             (GtkEntryCompletion *completion,
217	--                                              gint index_);
218
219	-- Deletes the action at index_ from completion's action list.
220
221	-- completion : 	A GtkEntryCompletion.
222	-- index_ : 	The index of the item to Delete.
223
224	set_popup_completion (a_boolean: BOOLEAN) is
225			-- Sets whether the completions should be presented in a popup window.
226		do
227			gtk_entry_completion_set_popup_completion (handle, a_boolean.to_integer)
228		end
229
230	popup_completion: BOOLEAN is
231			-- Returns whether the completions should be presented in a popup window.
232		do
233			Result := gtk_entry_completion_get_popup_completion (handle).to_boolean
234		end
235
236	set_popup_set_width (a_boolean: BOOLEAN) is
237			-- Sets whether the completion popup window will be resized to
238			-- be the same width as the entry.
239		do
240			gtk_entry_completion_set_popup_set_width (handle, a_boolean.to_integer)
241		end
242
243	popup_set_width: BOOLEAN is
244			-- Returns whether the completion popup window will be resized
245			-- to the width of the entry.
246		do
247			Result := gtk_entry_completion_get_popup_set_width (handle).to_boolean
248		end
249
250	set_popup_single_match (a_boolean: BOOLEAN) is
251			-- Sets whether the completion popup window will appear even if
252			-- there is only a single match.
253			-- You may want to set this to FALSE if you are using inline completion.
254		do
255			gtk_entry_completion_set_popup_single_match (handle, a_boolean.to_integer)
256		end
257
258	popup_single_match: BOOLEAN is
259			-- Returns whether the completion popup window will appear even if
260			-- there is only a single match.
261		do
262			Result := gtk_entry_completion_get_popup_single_match (handle).to_boolean
263		end
264
265
266	-- Since 2.8
267	-- Property Details
268	-- The "inline-completion" property
269
270	--   "inline-completion"    gboolean              : Read / Write
271
272	-- 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.
273
274	-- Default value: FALSE
275
276	-- Since 2.6
277	-- The "minimum-key-length" property
278
279	--   "minimum-key-length"   gint                  : Read / Write
280
281	-- Minimum length of the search key in order to look up matches.
282
283	-- Allowed values: >= 0
284
285	-- Default value: 1
286	-- The "model" property
287
288	--   "model"                GtkTreeModel          : Read / Write
289
290	-- The model to find matches in.
291	-- The "popup-completion" property
292
293	--   "popup-completion"     gboolean              : Read / Write
294
295	-- Determines whether the possible completions should be shown in a popup window.
296
297	-- Default value: TRUE
298
299	-- Since 2.6
300	-- The "popup-set-width" property
301
302	--   "popup-set-width"      gboolean              : Read / Write
303
304	-- Determines whether the completions popup window will be resized to the width of the entry.
305
306	-- Default value: TRUE
307
308	-- Since 2.8
309	-- The "popup-single-match" property
310
311	--   "popup-single-match"   gboolean              : Read / Write
312
313	-- 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.
314
315	-- Default value: TRUE
316
317	-- Since 2.8
318	-- The "text-column" property
319
320	--   "text-column"          gint                  : Read / Write
321
322	-- The column of the model containing the strings.
323
324	-- Allowed values: >= -1
325
326	-- Default value: -1
327
328	-- Since 2.6
329	-- Signal Details
330	-- The "action-activated" signal
331
332	-- void        user_function                  (GtkEntryCompletion *widget,
333	--                                             gint index,
334	--                                             gpointer user_data);
335
336	-- Gets emitted when an action is activated.
337
338	-- widget : 	the object which received the signal
339	-- index : 	the index of the activated action
340	-- user_data : 	user data set when the signal handler was connected.
341
342	-- Since 2.4
343	-- The "insert-prefix" signal
344
345	-- gboolean    user_function                  (GtkEntryCompletion *widget,
346	--                                             gchar *prefix,
347	--                                             gpointer user_data);
348
349	-- 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.
350
351	-- 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 '/'.
352
353	-- widget : 	the object which received the signal
354	-- prefix : 	the common prefix of all possible completions
355	-- user_data : 	user data set when the signal handler was connected.
356	-- Returns : 	TRUE if the signal has been handled
357
358
359
360feature -- The "match-selected" signal
361
362	match_selected_signal_name: STRING is "match-selected"
363
364	on_match_selected is
365			-- Built-in clicked signal handler; empty by design; redefine it.
366		do
367		end
368
369	enable_on_match_selected is
370			-- Connects "match-selected" signal to `on_match_selected' feature.
371
372			-- Emitted when the button has been activated (pressed and released).
373
374			-- Gets emitted when a match from the list is selected.
375			-- The default behaviour is to replace the contents of the entry
376			-- with the contents of the text column in the row pointed to by iter.
377		do
378			connect (Current, match_selected_signal_name, $on_match_selected)
379		end
380
381	connect_agent_to_match_selected_signal (a_function: FUNCTION [ANY, TUPLE [GTK_TREE_MODEL, GTK_TREE_ITER, GTK_ENTRY_COMPLETION], BOOLEAN]) is
382			-- widget : 	 the object which received the signal
383			-- model : 	the GtkTreeModel containing the matches
384			-- iter : 	a GtkTreeIter positioned at the selected match
385		require valid_function: a_function /= Void
386		local match_selected_callback: MATCH_SELECTED_CALLBACK
387		do
388			create match_selected_callback.make
389			match_selected_callback.connect (Current, a_function)
390		end
391
392
393
394	-- Since 2.4
395
396
397	-- Details
398	-- GtkEntryCompletion
399
400	-- typedef struct _GtkEntryCompletion GtkEntryCompletion;
401
402	-- The GtkEntryCompletion struct contains only private data.
403	-- GtkEntryCompletionMatchFunc ()
404
405	-- gboolean    (*GtkEntryCompletionMatchFunc)  (GtkEntryCompletion *completion,
406	--                                              const gchar *key,
407	--                                              GtkTreeIter *iter,
408	--                                              gpointer user_data);
409
410	-- 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 ())).
411	-- completion : 	the GtkEntryCompletion
412	-- key : 	the string to match, normalized and case-folded
413	-- iter : 	a GtkTreeIter indicating the row to match
414	-- user_data : 	user data given to gtk_entry_completion_set_match_func()
415	-- Returns : 	TRUE if iter should be displayed as a possible completion for key
416
417feature
418	struct_size: INTEGER is
419		external "C inline use <gtk/gtk.h>"
420		alias "sizeof(GtkEntryCompletion)"
421		end
422
423end -- class GTK_ENTRY_COMPLETION