1 /* gtkentrycompletion.c
2 * Copyright (C) 2003 Kristian Rietveld <kris@gtk.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 #include "gtkentrycompletion.h"
22 #include "gtkentryprivate.h"
23 #include "gtkcelllayout.h"
26 #include "gtkcellrenderertext.h"
28 #include "gtktreeselection.h"
29 #include "gtktreeview.h"
30 #include "gtkscrolledwindow.h"
32 #include "gtkwindow.h"
35 #include "gtksignal.h"
36 #include "gtkmarshalers.h"
38 #include "gtkprivate.h"
59 PROP_MINIMUM_KEY_LENGTH,
61 PROP_INLINE_COMPLETION,
62 PROP_POPUP_COMPLETION,
64 PROP_POPUP_SINGLE_MATCH,
68 #define GTK_ENTRY_COMPLETION_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY_COMPLETION, GtkEntryCompletionPrivate))
70 static void gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface);
71 static void gtk_entry_completion_set_property (GObject *object,
75 static void gtk_entry_completion_get_property (GObject *object,
79 static void gtk_entry_completion_finalize (GObject *object);
81 static void gtk_entry_completion_pack_start (GtkCellLayout *cell_layout,
82 GtkCellRenderer *cell,
84 static void gtk_entry_completion_pack_end (GtkCellLayout *cell_layout,
85 GtkCellRenderer *cell,
87 static void gtk_entry_completion_clear (GtkCellLayout *cell_layout);
88 static void gtk_entry_completion_add_attribute (GtkCellLayout *cell_layout,
89 GtkCellRenderer *cell,
90 const char *attribute,
92 static void gtk_entry_completion_set_cell_data_func (GtkCellLayout *cell_layout,
93 GtkCellRenderer *cell,
94 GtkCellLayoutDataFunc func,
96 GDestroyNotify destroy);
97 static void gtk_entry_completion_clear_attributes (GtkCellLayout *cell_layout,
98 GtkCellRenderer *cell);
99 static void gtk_entry_completion_reorder (GtkCellLayout *cell_layout,
100 GtkCellRenderer *cell,
103 static gboolean gtk_entry_completion_visible_func (GtkTreeModel *model,
106 static gboolean gtk_entry_completion_popup_key_event (GtkWidget *widget,
109 static gboolean gtk_entry_completion_popup_button_press (GtkWidget *widget,
110 GdkEventButton *event,
112 static gboolean gtk_entry_completion_list_button_press (GtkWidget *widget,
113 GdkEventButton *event,
115 static gboolean gtk_entry_completion_action_button_press (GtkWidget *widget,
116 GdkEventButton *event,
118 static void gtk_entry_completion_selection_changed (GtkTreeSelection *selection,
120 static gboolean gtk_entry_completion_list_enter_notify (GtkWidget *widget,
121 GdkEventCrossing *event,
123 static gboolean gtk_entry_completion_list_motion_notify (GtkWidget *widget,
124 GdkEventMotion *event,
126 static void gtk_entry_completion_insert_action (GtkEntryCompletion *completion,
130 static void gtk_entry_completion_action_data_func (GtkTreeViewColumn *tree_column,
131 GtkCellRenderer *cell,
136 static gboolean gtk_entry_completion_match_selected (GtkEntryCompletion *completion,
139 static gboolean gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion,
140 const gchar *prefix);
141 static gboolean gtk_entry_completion_cursor_on_match (GtkEntryCompletion *completion,
144 static gboolean gtk_entry_completion_insert_completion (GtkEntryCompletion *completion,
147 static void gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
150 static guint entry_completion_signals[LAST_SIGNAL] = { 0 };
152 G_DEFINE_TYPE_WITH_CODE (GtkEntryCompletion, gtk_entry_completion, G_TYPE_OBJECT,
153 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
154 gtk_entry_completion_cell_layout_init))
157 gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
159 GObjectClass *object_class;
161 object_class = (GObjectClass *)klass;
163 object_class->set_property = gtk_entry_completion_set_property;
164 object_class->get_property = gtk_entry_completion_get_property;
165 object_class->finalize = gtk_entry_completion_finalize;
167 klass->match_selected = gtk_entry_completion_match_selected;
168 klass->insert_prefix = gtk_entry_completion_real_insert_prefix;
169 klass->cursor_on_match = gtk_entry_completion_cursor_on_match;
172 * GtkEntryCompletion::insert-prefix:
173 * @widget: the object which received the signal
174 * @prefix: the common prefix of all possible completions
176 * Gets emitted when the inline autocompletion is triggered.
177 * The default behaviour is to make the entry display the
178 * whole prefix and select the newly inserted part.
180 * Applications may connect to this signal in order to insert only a
181 * smaller part of the @prefix into the entry - e.g. the entry used in
182 * the #GtkFileChooser inserts only the part of the prefix up to the
185 * Return value: %TRUE if the signal has been handled
189 entry_completion_signals[INSERT_PREFIX] =
190 g_signal_new (I_("insert_prefix"),
191 G_TYPE_FROM_CLASS (klass),
193 G_STRUCT_OFFSET (GtkEntryCompletionClass, insert_prefix),
194 _gtk_boolean_handled_accumulator, NULL,
195 _gtk_marshal_BOOLEAN__STRING,
200 * GtkEntryCompletion::match-selected:
201 * @widget: the object which received the signal
202 * @model: the #GtkTreeModel containing the matches
203 * @iter: a #GtkTreeIter positioned at the selected match
205 * Gets emitted when a match from the list is selected.
206 * The default behaviour is to replace the contents of the
207 * entry with the contents of the text column in the row
208 * pointed to by @iter.
210 * Return value: %TRUE if the signal has been handled
214 entry_completion_signals[MATCH_SELECTED] =
215 g_signal_new (I_("match_selected"),
216 G_TYPE_FROM_CLASS (klass),
218 G_STRUCT_OFFSET (GtkEntryCompletionClass, match_selected),
219 _gtk_boolean_handled_accumulator, NULL,
220 _gtk_marshal_BOOLEAN__OBJECT_BOXED,
225 * GtkEntryCompletion::cursor-on-match:
226 * @widget: the object which received the signal
227 * @model: the #GtkTreeModel containing the matches
228 * @iter: a #GtkTreeIter positioned at the selected match
230 * Gets emitted when a match from the cursor is on a match
231 * of the list.The default behaviour is to replace the contents
232 * of the entry with the contents of the text column in the row
233 * pointed to by @iter.
235 * Return value: %TRUE if the signal has been handled
240 entry_completion_signals[CURSOR_ON_MATCH] =
241 g_signal_new (I_("cursor_on_match"),
242 G_TYPE_FROM_CLASS (klass),
244 G_STRUCT_OFFSET (GtkEntryCompletionClass, cursor_on_match),
245 _gtk_boolean_handled_accumulator, NULL,
246 _gtk_marshal_BOOLEAN__OBJECT_BOXED,
252 * GtkEntryCompletion::action-activated:
253 * @widget: the object which received the signal
254 * @index: the index of the activated action
256 * Gets emitted when an action is activated.
260 entry_completion_signals[ACTION_ACTIVATED] =
261 g_signal_new (I_("action_activated"),
262 G_TYPE_FROM_CLASS (klass),
264 G_STRUCT_OFFSET (GtkEntryCompletionClass, action_activated),
266 _gtk_marshal_NONE__INT,
270 g_object_class_install_property (object_class,
272 g_param_spec_object ("model",
273 P_("Completion Model"),
274 P_("The model to find matches in"),
276 GTK_PARAM_READWRITE));
277 g_object_class_install_property (object_class,
278 PROP_MINIMUM_KEY_LENGTH,
279 g_param_spec_int ("minimum-key-length",
280 P_("Minimum Key Length"),
281 P_("Minimum length of the search key in order to look up matches"),
285 GTK_PARAM_READWRITE));
287 * GtkEntryCompletion:text-column:
289 * The column of the model containing the strings.
293 g_object_class_install_property (object_class,
295 g_param_spec_int ("text-column",
297 P_("The column of the model containing the strings."),
301 GTK_PARAM_READWRITE));
304 * GtkEntryCompletion:inline-completion:
306 * Determines whether the common prefix of the possible completions
307 * should be inserted automatically in the entry. Note that this
308 * requires text-column to be set, even if you are using a custom
313 g_object_class_install_property (object_class,
314 PROP_INLINE_COMPLETION,
315 g_param_spec_boolean ("inline-completion",
316 P_("Inline completion"),
317 P_("Whether the common prefix should be inserted automatically"),
319 GTK_PARAM_READWRITE));
321 * GtkEntryCompletion:popup-completion:
323 * Determines whether the possible completions should be
324 * shown in a popup window.
328 g_object_class_install_property (object_class,
329 PROP_POPUP_COMPLETION,
330 g_param_spec_boolean ("popup-completion",
331 P_("Popup completion"),
332 P_("Whether the completions should be shown in a popup window"),
334 GTK_PARAM_READWRITE));
337 * GtkEntryCompletion:popup-set-width:
339 * Determines whether the completions popup window will be
340 * resized to the width of the entry.
344 g_object_class_install_property (object_class,
345 PROP_POPUP_SET_WIDTH,
346 g_param_spec_boolean ("popup-set-width",
347 P_("Popup set width"),
348 P_("If TRUE, the popup window will have the same size as the entry"),
350 GTK_PARAM_READWRITE));
353 * GtkEntryCompletion:popup-single-match:
355 * Determines whether the completions popup window will shown
356 * for a single possible completion. You probably want to set
357 * this to %FALSE if you are using
358 * <link linkend="GtkEntryCompletion--inline-completion">inline
363 g_object_class_install_property (object_class,
364 PROP_POPUP_SINGLE_MATCH,
365 g_param_spec_boolean ("popup-single-match",
366 P_("Popup single match"),
367 P_("If TRUE, the popup window will appear for a single match."),
369 GTK_PARAM_READWRITE));
371 * GtkEntryCompletion:inline-selection:
373 * Determines whether the possible completions on the popup
374 * will appear in the entry as you navigate through them.
378 g_object_class_install_property (object_class,
379 PROP_INLINE_SELECTION,
380 g_param_spec_boolean ("inline-selection",
381 P_("Inline selection"),
382 P_("Your description here"),
384 GTK_PARAM_READWRITE));
386 g_type_class_add_private (object_class, sizeof (GtkEntryCompletionPrivate));
390 gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface)
392 iface->pack_start = gtk_entry_completion_pack_start;
393 iface->pack_end = gtk_entry_completion_pack_end;
394 iface->clear = gtk_entry_completion_clear;
395 iface->add_attribute = gtk_entry_completion_add_attribute;
396 iface->set_cell_data_func = gtk_entry_completion_set_cell_data_func;
397 iface->clear_attributes = gtk_entry_completion_clear_attributes;
398 iface->reorder = gtk_entry_completion_reorder;
402 gtk_entry_completion_init (GtkEntryCompletion *completion)
404 GtkCellRenderer *cell;
405 GtkTreeSelection *sel;
406 GtkEntryCompletionPrivate *priv;
407 GtkWidget *popup_frame;
409 /* yes, also priv, need to keep the code readable */
410 priv = completion->priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (completion);
412 priv->minimum_key_length = 1;
413 priv->text_column = -1;
414 priv->has_completion = FALSE;
415 priv->inline_completion = FALSE;
416 priv->popup_completion = TRUE;
417 priv->popup_set_width = TRUE;
418 priv->popup_single_match = TRUE;
419 priv->inline_selection = FALSE;
422 priv->filter_model = NULL;
424 priv->tree_view = gtk_tree_view_new ();
425 g_signal_connect (priv->tree_view, "button_press_event",
426 G_CALLBACK (gtk_entry_completion_list_button_press),
428 g_signal_connect (priv->tree_view, "enter_notify_event",
429 G_CALLBACK (gtk_entry_completion_list_enter_notify),
431 g_signal_connect (priv->tree_view, "motion_notify_event",
432 G_CALLBACK (gtk_entry_completion_list_motion_notify),
435 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
436 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->tree_view), TRUE);
438 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
439 gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE);
440 gtk_tree_selection_unselect_all (sel);
441 g_signal_connect (sel, "changed",
442 G_CALLBACK (gtk_entry_completion_selection_changed),
444 priv->first_sel_changed = TRUE;
446 priv->column = gtk_tree_view_column_new ();
447 gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), priv->column);
449 priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
450 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
452 GTK_POLICY_AUTOMATIC);
453 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window),
456 /* a nasty hack to get the completions treeview to size nicely */
457 gtk_widget_set_size_request (GTK_SCROLLED_WINDOW (priv->scrolled_window)->vscrollbar, -1, 0);
460 priv->actions = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
463 gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->actions));
464 g_object_ref_sink (priv->action_view);
465 g_signal_connect (priv->action_view, "button_press_event",
466 G_CALLBACK (gtk_entry_completion_action_button_press),
468 g_signal_connect (priv->action_view, "enter_notify_event",
469 G_CALLBACK (gtk_entry_completion_list_enter_notify),
471 g_signal_connect (priv->action_view, "motion_notify_event",
472 G_CALLBACK (gtk_entry_completion_list_motion_notify),
474 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->action_view), FALSE);
475 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->action_view), TRUE);
477 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->action_view));
478 gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE);
479 gtk_tree_selection_unselect_all (sel);
481 cell = gtk_cell_renderer_text_new ();
482 gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (priv->action_view),
485 gtk_entry_completion_action_data_func,
490 priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
491 gtk_window_set_resizable (GTK_WINDOW (priv->popup_window), FALSE);
492 g_signal_connect (priv->popup_window, "key_press_event",
493 G_CALLBACK (gtk_entry_completion_popup_key_event),
495 g_signal_connect (priv->popup_window, "key_release_event",
496 G_CALLBACK (gtk_entry_completion_popup_key_event),
498 g_signal_connect (priv->popup_window, "button_press_event",
499 G_CALLBACK (gtk_entry_completion_popup_button_press),
502 popup_frame = gtk_frame_new (NULL);
503 gtk_frame_set_shadow_type (GTK_FRAME (popup_frame),
504 GTK_SHADOW_ETCHED_IN);
505 gtk_widget_show (popup_frame);
506 gtk_container_add (GTK_CONTAINER (priv->popup_window), popup_frame);
508 priv->vbox = gtk_vbox_new (FALSE, 0);
509 gtk_container_add (GTK_CONTAINER (popup_frame), priv->vbox);
511 gtk_container_add (GTK_CONTAINER (priv->scrolled_window), priv->tree_view);
512 gtk_box_pack_start (GTK_BOX (priv->vbox), priv->scrolled_window,
515 /* we don't want to see the action treeview when no actions have
516 * been inserted, so we pack the action treeview after the first
517 * action has been added
522 gtk_entry_completion_set_property (GObject *object,
527 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
528 GtkEntryCompletionPrivate *priv = completion->priv;
533 gtk_entry_completion_set_model (completion,
534 g_value_get_object (value));
537 case PROP_MINIMUM_KEY_LENGTH:
538 gtk_entry_completion_set_minimum_key_length (completion,
539 g_value_get_int (value));
542 case PROP_TEXT_COLUMN:
543 priv->text_column = g_value_get_int (value);
546 case PROP_INLINE_COMPLETION:
547 priv->inline_completion = g_value_get_boolean (value);
550 case PROP_POPUP_COMPLETION:
551 priv->popup_completion = g_value_get_boolean (value);
554 case PROP_POPUP_SET_WIDTH:
555 priv->popup_set_width = g_value_get_boolean (value);
558 case PROP_POPUP_SINGLE_MATCH:
559 priv->popup_single_match = g_value_get_boolean (value);
562 case PROP_INLINE_SELECTION:
563 priv->inline_selection = g_value_get_boolean (value);
567 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
573 gtk_entry_completion_get_property (GObject *object,
578 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
583 g_value_set_object (value,
584 gtk_entry_completion_get_model (completion));
587 case PROP_MINIMUM_KEY_LENGTH:
588 g_value_set_int (value, gtk_entry_completion_get_minimum_key_length (completion));
591 case PROP_TEXT_COLUMN:
592 g_value_set_int (value, gtk_entry_completion_get_text_column (completion));
595 case PROP_INLINE_COMPLETION:
596 g_value_set_boolean (value, gtk_entry_completion_get_inline_completion (completion));
599 case PROP_POPUP_COMPLETION:
600 g_value_set_boolean (value, gtk_entry_completion_get_popup_completion (completion));
603 case PROP_POPUP_SET_WIDTH:
604 g_value_set_boolean (value, gtk_entry_completion_get_popup_set_width (completion));
607 case PROP_POPUP_SINGLE_MATCH:
608 g_value_set_boolean (value, gtk_entry_completion_get_popup_single_match (completion));
611 case PROP_INLINE_SELECTION:
612 g_value_set_boolean (value, gtk_entry_completion_get_inline_selection (completion));
616 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
622 gtk_entry_completion_finalize (GObject *object)
624 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
625 GtkEntryCompletionPrivate *priv = completion->priv;
628 gtk_widget_destroy (priv->tree_view);
631 gtk_entry_set_completion (GTK_ENTRY (priv->entry), NULL);
634 g_object_unref (priv->actions);
635 if (priv->action_view)
636 g_object_unref (priv->action_view);
638 g_free (priv->case_normalized_key);
640 if (priv->popup_window)
641 gtk_widget_destroy (priv->popup_window);
643 if (priv->match_notify)
644 (* priv->match_notify) (priv->match_data);
646 G_OBJECT_CLASS (gtk_entry_completion_parent_class)->finalize (object);
649 /* implement cell layout interface */
651 gtk_entry_completion_pack_start (GtkCellLayout *cell_layout,
652 GtkCellRenderer *cell,
655 GtkEntryCompletionPrivate *priv;
657 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
659 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
661 gtk_tree_view_column_pack_start (priv->column, cell, expand);
665 gtk_entry_completion_pack_end (GtkCellLayout *cell_layout,
666 GtkCellRenderer *cell,
669 GtkEntryCompletionPrivate *priv;
671 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
673 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
675 gtk_tree_view_column_pack_end (priv->column, cell, expand);
679 gtk_entry_completion_clear (GtkCellLayout *cell_layout)
681 GtkEntryCompletionPrivate *priv;
683 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
685 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
687 gtk_tree_view_column_clear (priv->column);
691 gtk_entry_completion_add_attribute (GtkCellLayout *cell_layout,
692 GtkCellRenderer *cell,
693 const gchar *attribute,
696 GtkEntryCompletionPrivate *priv;
698 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
700 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
702 gtk_tree_view_column_add_attribute (priv->column, cell, attribute, column);
706 gtk_entry_completion_set_cell_data_func (GtkCellLayout *cell_layout,
707 GtkCellRenderer *cell,
708 GtkCellLayoutDataFunc func,
710 GDestroyNotify destroy)
712 GtkEntryCompletionPrivate *priv;
714 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
716 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
718 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->column),
719 cell, func, func_data, destroy);
723 gtk_entry_completion_clear_attributes (GtkCellLayout *cell_layout,
724 GtkCellRenderer *cell)
726 GtkEntryCompletionPrivate *priv;
728 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
730 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
732 gtk_tree_view_column_clear_attributes (priv->column, cell);
736 gtk_entry_completion_reorder (GtkCellLayout *cell_layout,
737 GtkCellRenderer *cell,
740 GtkEntryCompletionPrivate *priv;
742 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
744 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
746 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->column), cell, position);
749 /* all those callbacks */
751 gtk_entry_completion_default_completion_func (GtkEntryCompletion *completion,
757 gchar *normalized_string;
758 gchar *case_normalized_string;
760 gboolean ret = FALSE;
764 model = gtk_tree_model_filter_get_model (completion->priv->filter_model);
766 g_return_val_if_fail (gtk_tree_model_get_column_type (model, completion->priv->text_column) == G_TYPE_STRING,
769 gtk_tree_model_get (model, iter,
770 completion->priv->text_column, &item,
775 normalized_string = g_utf8_normalize (item, -1, G_NORMALIZE_ALL);
776 case_normalized_string = g_utf8_casefold (normalized_string, -1);
778 if (!strncmp (key, case_normalized_string, strlen (key)))
782 g_free (normalized_string);
783 g_free (case_normalized_string);
790 gtk_entry_completion_visible_func (GtkTreeModel *model,
794 gboolean ret = FALSE;
796 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
798 if (!completion->priv->case_normalized_key)
801 if (completion->priv->match_func)
802 ret = (* completion->priv->match_func) (completion,
803 completion->priv->case_normalized_key,
805 completion->priv->match_data);
806 else if (completion->priv->text_column >= 0)
807 ret = gtk_entry_completion_default_completion_func (completion,
808 completion->priv->case_normalized_key,
816 gtk_entry_completion_popup_key_event (GtkWidget *widget,
820 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
822 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
825 /* propagate event to the entry */
826 gtk_widget_event (completion->priv->entry, (GdkEvent *)event);
832 gtk_entry_completion_popup_button_press (GtkWidget *widget,
833 GdkEventButton *event,
836 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
838 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
841 /* if we come here, it's usually time to popdown */
842 _gtk_entry_completion_popdown (completion);
848 gtk_entry_completion_list_button_press (GtkWidget *widget,
849 GdkEventButton *event,
852 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
853 GtkTreePath *path = NULL;
855 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
858 if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
860 &path, NULL, NULL, NULL))
865 gtk_tree_model_get_iter (GTK_TREE_MODEL (completion->priv->filter_model),
867 gtk_tree_path_free (path);
869 g_signal_handler_block (completion->priv->entry,
870 completion->priv->changed_id);
871 g_signal_emit (completion, entry_completion_signals[MATCH_SELECTED],
872 0, GTK_TREE_MODEL (completion->priv->filter_model),
874 g_signal_handler_unblock (completion->priv->entry,
875 completion->priv->changed_id);
877 _gtk_entry_completion_popdown (completion);
886 gtk_entry_completion_action_button_press (GtkWidget *widget,
887 GdkEventButton *event,
890 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
891 GtkTreePath *path = NULL;
893 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
896 _gtk_entry_reset_im_context (GTK_ENTRY (completion->priv->entry));
898 if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
900 &path, NULL, NULL, NULL))
902 g_signal_emit (completion, entry_completion_signals[ACTION_ACTIVATED],
903 0, gtk_tree_path_get_indices (path)[0]);
904 gtk_tree_path_free (path);
906 _gtk_entry_completion_popdown (completion);
914 gtk_entry_completion_action_data_func (GtkTreeViewColumn *tree_column,
915 GtkCellRenderer *cell,
920 gchar *string = NULL;
923 gtk_tree_model_get (model, iter,
946 gtk_entry_completion_selection_changed (GtkTreeSelection *selection,
949 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
951 if (completion->priv->first_sel_changed)
953 completion->priv->first_sel_changed = FALSE;
954 if (gtk_widget_is_focus (completion->priv->tree_view))
955 gtk_tree_selection_unselect_all (selection);
962 * gtk_entry_completion_new:
964 * Creates a new #GtkEntryCompletion object.
966 * Return value: A newly created #GtkEntryCompletion object.
971 gtk_entry_completion_new (void)
973 GtkEntryCompletion *completion;
975 completion = g_object_new (GTK_TYPE_ENTRY_COMPLETION, NULL);
981 * gtk_entry_completion_get_entry:
982 * @completion: A #GtkEntryCompletion.
984 * Gets the entry @completion has been attached to.
986 * Return value: The entry @completion has been attached to.
991 gtk_entry_completion_get_entry (GtkEntryCompletion *completion)
993 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
995 return completion->priv->entry;
999 * gtk_entry_completion_set_model:
1000 * @completion: A #GtkEntryCompletion.
1001 * @model: The #GtkTreeModel.
1003 * Sets the model for a #GtkEntryCompletion. If @completion already has
1004 * a model set, it will remove it before setting the new model.
1005 * If model is %NULL, then it will unset the model.
1010 gtk_entry_completion_set_model (GtkEntryCompletion *completion,
1011 GtkTreeModel *model)
1013 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1014 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
1018 gtk_tree_view_set_model (GTK_TREE_VIEW (completion->priv->tree_view),
1020 _gtk_entry_completion_popdown (completion);
1021 completion->priv->filter_model = NULL;
1025 /* code will unref the old filter model (if any) */
1026 completion->priv->filter_model =
1027 GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (model, NULL));
1028 gtk_tree_model_filter_set_visible_func (completion->priv->filter_model,
1029 gtk_entry_completion_visible_func,
1033 gtk_tree_view_set_model (GTK_TREE_VIEW (completion->priv->tree_view),
1034 GTK_TREE_MODEL (completion->priv->filter_model));
1035 g_object_unref (completion->priv->filter_model);
1037 g_object_notify (G_OBJECT (completion), "model");
1039 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
1040 _gtk_entry_completion_resize_popup (completion);
1044 * gtk_entry_completion_get_model:
1045 * @completion: A #GtkEntryCompletion.
1047 * Returns the model the #GtkEntryCompletion is using as data source.
1048 * Returns %NULL if the model is unset.
1050 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
1055 gtk_entry_completion_get_model (GtkEntryCompletion *completion)
1057 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
1059 if (!completion->priv->filter_model)
1062 return gtk_tree_model_filter_get_model (completion->priv->filter_model);
1066 * gtk_entry_completion_set_match_func:
1067 * @completion: A #GtkEntryCompletion.
1068 * @func: The #GtkEntryCompletionMatchFunc to use.
1069 * @func_data: The user data for @func.
1070 * @func_notify: Destroy notifier for @func_data.
1072 * Sets the match function for @completion to be @func. The match function
1073 * is used to determine if a row should or should not be in the completion
1079 gtk_entry_completion_set_match_func (GtkEntryCompletion *completion,
1080 GtkEntryCompletionMatchFunc func,
1082 GDestroyNotify func_notify)
1084 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1086 if (completion->priv->match_notify)
1087 (* completion->priv->match_notify) (completion->priv->match_data);
1089 completion->priv->match_func = func;
1090 completion->priv->match_data = func_data;
1091 completion->priv->match_notify = func_notify;
1095 * gtk_entry_completion_set_minimum_key_length:
1096 * @completion: A #GtkEntryCompletion.
1097 * @length: The minimum length of the key in order to start completing.
1099 * Requires the length of the search key for @completion to be at least
1100 * @length. This is useful for long lists, where completing using a small
1101 * key takes a lot of time and will come up with meaningless results anyway
1102 * (ie, a too large dataset).
1107 gtk_entry_completion_set_minimum_key_length (GtkEntryCompletion *completion,
1110 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1111 g_return_if_fail (length >= 0);
1113 if (completion->priv->minimum_key_length != length)
1115 completion->priv->minimum_key_length = length;
1117 g_object_notify (G_OBJECT (completion), "minimum-key-length");
1122 * gtk_entry_completion_get_minimum_key_length:
1123 * @completion: A #GtkEntryCompletion.
1125 * Returns the minimum key length as set for @completion.
1127 * Return value: The currently used minimum key length.
1132 gtk_entry_completion_get_minimum_key_length (GtkEntryCompletion *completion)
1134 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), 0);
1136 return completion->priv->minimum_key_length;
1140 * gtk_entry_completion_complete:
1141 * @completion: A #GtkEntryCompletion.
1143 * Requests a completion operation, or in other words a refiltering of the
1144 * current list with completions, using the current key. The completion list
1145 * view will be updated accordingly.
1150 gtk_entry_completion_complete (GtkEntryCompletion *completion)
1154 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1156 if (!completion->priv->filter_model)
1159 g_free (completion->priv->case_normalized_key);
1161 tmp = g_utf8_normalize (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)),
1162 -1, G_NORMALIZE_ALL);
1163 completion->priv->case_normalized_key = g_utf8_casefold (tmp, -1);
1166 gtk_tree_model_filter_refilter (completion->priv->filter_model);
1168 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
1169 _gtk_entry_completion_resize_popup (completion);
1173 gtk_entry_completion_insert_action (GtkEntryCompletion *completion,
1175 const gchar *string,
1180 gtk_list_store_insert (completion->priv->actions, &iter, index);
1181 gtk_list_store_set (completion->priv->actions, &iter,
1186 if (!completion->priv->action_view->parent)
1188 GtkTreePath *path = gtk_tree_path_new_from_indices (0, -1);
1190 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
1192 gtk_tree_path_free (path);
1194 gtk_box_pack_start (GTK_BOX (completion->priv->vbox),
1195 completion->priv->action_view, FALSE, FALSE, 0);
1196 gtk_widget_show (completion->priv->action_view);
1201 * gtk_entry_completion_insert_action_text:
1202 * @completion: A #GtkEntryCompletion.
1203 * @index_: The index of the item to insert.
1204 * @text: Text of the item to insert.
1206 * Inserts an action in @completion's action item list at position @index_
1207 * with text @text. If you want the action item to have markup, use
1208 * gtk_entry_completion_insert_action_markup().
1213 gtk_entry_completion_insert_action_text (GtkEntryCompletion *completion,
1217 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1218 g_return_if_fail (text != NULL);
1220 gtk_entry_completion_insert_action (completion, index_, text, FALSE);
1224 * gtk_entry_completion_insert_action_markup:
1225 * @completion: A #GtkEntryCompletion.
1226 * @index_: The index of the item to insert.
1227 * @markup: Markup of the item to insert.
1229 * Inserts an action in @completion's action item list at position @index_
1230 * with markup @markup.
1235 gtk_entry_completion_insert_action_markup (GtkEntryCompletion *completion,
1237 const gchar *markup)
1239 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1240 g_return_if_fail (markup != NULL);
1242 gtk_entry_completion_insert_action (completion, index_, markup, TRUE);
1246 * gtk_entry_completion_delete_action:
1247 * @completion: A #GtkEntryCompletion.
1248 * @index_: The index of the item to Delete.
1250 * Deletes the action at @index_ from @completion's action list.
1255 gtk_entry_completion_delete_action (GtkEntryCompletion *completion,
1260 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1261 g_return_if_fail (index_ >= 0);
1263 gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (completion->priv->actions),
1264 &iter, NULL, index_);
1265 gtk_list_store_remove (completion->priv->actions, &iter);
1269 * gtk_entry_completion_set_text_column:
1270 * @completion: A #GtkEntryCompletion.
1271 * @column: The column in the model of @completion to get strings from.
1273 * Convenience function for setting up the most used case of this code: a
1274 * completion list with just strings. This function will set up @completion
1275 * to have a list displaying all (and just) strings in the completion list,
1276 * and to get those strings from @column in the model of @completion.
1278 * This functions creates and adds a #GtkCellRendererText for the selected
1279 * column. If you need to set the text column, but don't want the cell
1280 * renderer, use g_object_set() to set the ::text_column property directly.
1285 gtk_entry_completion_set_text_column (GtkEntryCompletion *completion,
1288 GtkCellRenderer *cell;
1290 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1291 g_return_if_fail (column >= 0);
1293 completion->priv->text_column = column;
1295 cell = gtk_cell_renderer_text_new ();
1296 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion),
1298 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (completion),
1302 g_object_notify (G_OBJECT (completion), "text-column");
1306 * gtk_entry_completion_get_text_column:
1307 * @completion: a #GtkEntryCompletion
1309 * Returns the column in the model of @completion to get strings from.
1311 * Return value: the column containing the strings
1316 gtk_entry_completion_get_text_column (GtkEntryCompletion *completion)
1318 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), -1);
1320 return completion->priv->text_column;
1326 gtk_entry_completion_list_enter_notify (GtkWidget *widget,
1327 GdkEventCrossing *event,
1330 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
1332 return completion->priv->ignore_enter;
1336 gtk_entry_completion_list_motion_notify (GtkWidget *widget,
1337 GdkEventMotion *event,
1340 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
1342 completion->priv->ignore_enter = FALSE;
1348 /* some nasty size requisition */
1350 _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
1353 gint matches, items, height, x_border, y_border;
1356 gint vertical_separator;
1357 GdkRectangle monitor;
1358 GtkRequisition popup_req;
1359 GtkRequisition entry_req;
1364 if (!completion->priv->entry->window)
1367 gdk_window_get_origin (completion->priv->entry->window, &x, &y);
1368 _gtk_entry_get_borders (GTK_ENTRY (completion->priv->entry), &x_border, &y_border);
1370 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
1372 items = MIN (matches, 15);
1374 gtk_tree_view_column_cell_get_size (completion->priv->column, NULL,
1375 NULL, NULL, NULL, &height);
1377 gtk_widget_style_get (GTK_WIDGET (completion->priv->tree_view),
1378 "vertical-separator", &vertical_separator,
1381 height += vertical_separator;
1383 gtk_widget_realize (completion->priv->tree_view);
1386 gtk_widget_hide (completion->priv->scrolled_window);
1388 gtk_widget_show (completion->priv->scrolled_window);
1390 screen = gtk_widget_get_screen (GTK_WIDGET (completion->priv->entry));
1391 monitor_num = gdk_screen_get_monitor_at_window (screen,
1392 GTK_WIDGET (completion->priv->entry)->window);
1393 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1395 if (completion->priv->popup_set_width)
1396 width = MIN (completion->priv->entry->allocation.width, monitor.width) - 2 * x_border;
1400 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (completion->priv->tree_view));
1401 gtk_widget_set_size_request (completion->priv->tree_view, width, items * height);
1403 /* default on no match */
1404 completion->priv->current_selected = -1;
1406 items = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
1410 gtk_widget_show (completion->priv->action_view);
1411 gtk_widget_set_size_request (completion->priv->action_view, width, -1);
1414 gtk_widget_hide (completion->priv->action_view);
1416 gtk_widget_size_request (completion->priv->popup_window, &popup_req);
1417 gtk_widget_size_request (completion->priv->entry, &entry_req);
1421 else if (x + popup_req.width > monitor.x + monitor.width)
1422 x = monitor.x + monitor.width - popup_req.width;
1424 if (y + entry_req.height + popup_req.height <= monitor.y + monitor.height ||
1425 y - monitor.y < (monitor.y + monitor.height) - (y + entry_req.height))
1427 y += entry_req.height;
1432 y -= popup_req.height;
1438 path = gtk_tree_path_new_from_indices (above ? matches - 1 : 0, -1);
1439 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (completion->priv->tree_view), path,
1440 NULL, FALSE, 0.0, 0.0);
1441 gtk_tree_path_free (path);
1444 gtk_window_move (GTK_WINDOW (completion->priv->popup_window), x, y);
1450 _gtk_entry_completion_popup (GtkEntryCompletion *completion)
1452 GtkTreeViewColumn *column;
1454 GtkWidget *toplevel;
1456 if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
1459 if (!GTK_WIDGET_MAPPED (completion->priv->entry))
1462 if (!GTK_WIDGET_HAS_FOCUS (completion->priv->entry))
1465 completion->priv->ignore_enter = TRUE;
1467 column = gtk_tree_view_get_column (GTK_TREE_VIEW (completion->priv->action_view), 0);
1468 renderers = gtk_tree_view_column_get_cell_renderers (column);
1469 gtk_widget_ensure_style (completion->priv->tree_view);
1470 g_object_set (GTK_CELL_RENDERER (renderers->data), "cell-background-gdk",
1471 &completion->priv->tree_view->style->bg[GTK_STATE_NORMAL],
1473 g_list_free (renderers);
1475 gtk_widget_show_all (completion->priv->vbox);
1477 _gtk_entry_completion_resize_popup (completion);
1479 toplevel = gtk_widget_get_toplevel (completion->priv->entry);
1480 if (GTK_IS_WINDOW (toplevel))
1481 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1482 GTK_WINDOW (completion->priv->popup_window));
1484 /* prevent the first row being focused */
1485 gtk_widget_grab_focus (completion->priv->tree_view);
1487 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
1488 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
1491 gtk_widget_show (completion->priv->popup_window);
1493 gtk_grab_add (completion->priv->popup_window);
1494 gdk_pointer_grab (completion->priv->popup_window->window, TRUE,
1495 GDK_BUTTON_PRESS_MASK |
1496 GDK_BUTTON_RELEASE_MASK |
1497 GDK_POINTER_MOTION_MASK,
1498 NULL, NULL, GDK_CURRENT_TIME);
1502 _gtk_entry_completion_popdown (GtkEntryCompletion *completion)
1504 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
1507 completion->priv->ignore_enter = FALSE;
1509 gdk_pointer_ungrab (GDK_CURRENT_TIME);
1510 gtk_grab_remove (completion->priv->popup_window);
1512 gtk_widget_hide (completion->priv->popup_window);
1516 gtk_entry_completion_match_selected (GtkEntryCompletion *completion,
1517 GtkTreeModel *model,
1522 gtk_tree_model_get (model, iter, completion->priv->text_column, &str, -1);
1523 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), str ? str : "");
1525 /* move cursor to the end */
1526 gtk_editable_set_position (GTK_EDITABLE (completion->priv->entry), -1);
1534 gtk_entry_completion_cursor_on_match (GtkEntryCompletion *completion,
1535 GtkTreeModel *model,
1538 gtk_entry_completion_insert_completion (completion, model, iter);
1544 gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion)
1547 gchar *prefix = NULL;
1551 if (completion->priv->text_column < 0)
1554 key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry));
1556 valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (completion->priv->filter_model),
1563 gtk_tree_model_get (GTK_TREE_MODEL (completion->priv->filter_model),
1564 &iter, completion->priv->text_column, &text,
1567 if (text && g_str_has_prefix (text, key))
1570 prefix = g_strdup (text);
1576 while (*p && *p == *q)
1586 /* strip a partial multibyte character */
1587 q = g_utf8_find_prev_char (prefix, p);
1588 switch (g_utf8_get_char_validated (q, p - q))
1600 valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (completion->priv->filter_model),
1609 gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion,
1610 const gchar *prefix)
1618 prefix_len = g_utf8_strlen (prefix, -1);
1620 key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry));
1621 key_len = g_utf8_strlen (key, -1);
1623 if (prefix_len > key_len)
1625 gint pos = prefix_len;
1627 gtk_editable_insert_text (GTK_EDITABLE (completion->priv->entry),
1628 prefix + strlen (key), -1, &pos);
1629 gtk_editable_select_region (GTK_EDITABLE (completion->priv->entry),
1630 key_len, prefix_len);
1632 completion->priv->has_completion = TRUE;
1640 * gtk_entry_completion_get_completion_prefix:
1641 * @completion: a #GtkEntryCompletion
1643 * Get the original text entered by the user that triggered
1644 * the completion or NULL if there's no completion ongoing.
1650 gtk_entry_completion_get_completion_prefix (GtkEntryCompletion *completion)
1652 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
1654 return completion->priv->completion_prefix;
1658 gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
1661 GtkEntryCompletionPrivate *priv = completion->priv;
1665 priv = completion->priv;
1667 if (priv->changed_id > 0)
1669 g_signal_handler_block (priv->entry,
1673 if (priv->insert_text_id > 0)
1675 g_signal_handler_block (completion->priv->entry,
1676 completion->priv->insert_text_id);
1679 gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
1680 needle = g_strstr_len (text, -1, completion->priv->completion_prefix);
1683 len = g_utf8_strlen (text, -1) - g_utf8_strlen (needle, -1)
1684 + g_utf8_strlen (priv->completion_prefix, -1);
1685 gtk_editable_select_region (GTK_EDITABLE (priv->entry),
1689 if (priv->changed_id > 0)
1691 g_signal_handler_unblock (priv->entry,
1695 if (priv->insert_text_id > 0)
1697 g_signal_handler_unblock (priv->entry,
1698 priv->insert_text_id);
1703 gtk_entry_completion_insert_completion (GtkEntryCompletion *completion,
1704 GtkTreeModel *model,
1709 if (completion->priv->text_column < 0)
1712 gtk_tree_model_get (model, iter,
1713 completion->priv->text_column, &str,
1716 gtk_entry_completion_insert_completion_text (completion, str);
1724 * gtk_entry_completion_insert_prefix:
1725 * @completion: a #GtkEntryCompletion
1727 * Requests a prefix insertion.
1733 gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion)
1738 if (completion->priv->insert_text_id > 0)
1739 g_signal_handler_block (completion->priv->entry,
1740 completion->priv->insert_text_id);
1742 prefix = gtk_entry_completion_compute_prefix (completion);
1745 g_signal_emit (completion, entry_completion_signals[INSERT_PREFIX],
1750 if (completion->priv->insert_text_id > 0)
1751 g_signal_handler_unblock (completion->priv->entry,
1752 completion->priv->insert_text_id);
1756 * gtk_entry_completion_set_inline_completion:
1757 * @completion: a #GtkEntryCompletion
1758 * @inline_completion: %TRUE to do inline completion
1760 * Sets whether the common prefix of the possible completions should
1761 * be automatically inserted in the entry.
1766 gtk_entry_completion_set_inline_completion (GtkEntryCompletion *completion,
1767 gboolean inline_completion)
1769 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1771 inline_completion = inline_completion != FALSE;
1773 if (completion->priv->inline_completion != inline_completion)
1775 completion->priv->inline_completion = inline_completion;
1777 g_object_notify (G_OBJECT (completion), "inline-completion");
1782 * gtk_entry_completion_get_inline_completion:
1783 * @completion: a #GtkEntryCompletion
1785 * Returns whether the common prefix of the possible completions should
1786 * be automatically inserted in the entry.
1788 * Return value: %TRUE if inline completion is turned on
1793 gtk_entry_completion_get_inline_completion (GtkEntryCompletion *completion)
1795 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), FALSE);
1797 return completion->priv->inline_completion;
1801 * gtk_entry_completion_set_popup_completion:
1802 * @completion: a #GtkEntryCompletion
1803 * @popup_completion: %TRUE to do popup completion
1805 * Sets whether the completions should be presented in a popup window.
1810 gtk_entry_completion_set_popup_completion (GtkEntryCompletion *completion,
1811 gboolean popup_completion)
1813 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1815 popup_completion = popup_completion != FALSE;
1817 if (completion->priv->popup_completion != popup_completion)
1819 completion->priv->popup_completion = popup_completion;
1821 g_object_notify (G_OBJECT (completion), "popup-completion");
1827 * gtk_entry_completion_get_popup_completion:
1828 * @completion: a #GtkEntryCompletion
1830 * Returns whether the completions should be presented in a popup window.
1832 * Return value: %TRUE if popup completion is turned on
1837 gtk_entry_completion_get_popup_completion (GtkEntryCompletion *completion)
1839 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1841 return completion->priv->popup_completion;
1845 * gtk_entry_completion_set_popup_set_width:
1846 * @completion: a #GtkEntryCompletion
1847 * @popup_set_width: %TRUE to make the width of the popup the same as the entry
1849 * Sets whether the completion popup window will be resized to be the same
1850 * width as the entry.
1855 gtk_entry_completion_set_popup_set_width (GtkEntryCompletion *completion,
1856 gboolean popup_set_width)
1858 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1860 popup_set_width = popup_set_width != FALSE;
1862 if (completion->priv->popup_set_width != popup_set_width)
1864 completion->priv->popup_set_width = popup_set_width;
1866 g_object_notify (G_OBJECT (completion), "popup-set-width");
1871 * gtk_entry_completion_get_popup_set_width:
1872 * @completion: a #GtkEntryCompletion
1874 * Returns whether the completion popup window will be resized to the
1875 * width of the entry.
1877 * Return value: %TRUE if the popup window will be resized to the width of
1883 gtk_entry_completion_get_popup_set_width (GtkEntryCompletion *completion)
1885 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1887 return completion->priv->popup_set_width;
1892 * gtk_entry_completion_set_popup_single_match:
1893 * @completion: a #GtkEntryCompletion
1894 * @popup_single_match: %TRUE if the popup should appear even for a single
1897 * Sets whether the completion popup window will appear even if there is
1898 * only a single match. You may want to set this to %FALSE if you
1899 * are using <link linkend="GtkEntryCompletion--inline-completion">inline
1900 * completion</link>.
1905 gtk_entry_completion_set_popup_single_match (GtkEntryCompletion *completion,
1906 gboolean popup_single_match)
1908 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1910 popup_single_match = popup_single_match != FALSE;
1912 if (completion->priv->popup_single_match != popup_single_match)
1914 completion->priv->popup_single_match = popup_single_match;
1916 g_object_notify (G_OBJECT (completion), "popup-single-match");
1921 * gtk_entry_completion_get_popup_single_match:
1922 * @completion: a #GtkEntryCompletion
1924 * Returns whether the completion popup window will appear even if there is
1925 * only a single match.
1927 * Return value: %TRUE if the popup window will appear regardless of the
1928 * number of matches.
1933 gtk_entry_completion_get_popup_single_match (GtkEntryCompletion *completion)
1935 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1937 return completion->priv->popup_single_match;
1941 gtk_entry_completion_set_inline_selection (GtkEntryCompletion *completion,
1942 gboolean inline_selection)
1944 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1946 inline_selection = inline_selection != FALSE;
1948 if (completion->priv->inline_selection != inline_selection)
1950 completion->priv->inline_selection = inline_selection;
1952 g_object_notify (G_OBJECT (completion), "inline-selection");
1957 gtk_entry_completion_get_inline_selection (GtkEntryCompletion *completion)
1959 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), FALSE);
1961 return completion->priv->inline_selection;
1964 #define __GTK_ENTRY_COMPLETION_C__
1965 #include "gtkaliasdef.c"