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 "gtkmarshalers.h"
37 #include "gtkprivate.h"
58 PROP_MINIMUM_KEY_LENGTH,
60 PROP_INLINE_COMPLETION,
61 PROP_POPUP_COMPLETION,
63 PROP_POPUP_SINGLE_MATCH,
67 #define GTK_ENTRY_COMPLETION_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY_COMPLETION, GtkEntryCompletionPrivate))
69 static void gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface);
70 static void gtk_entry_completion_set_property (GObject *object,
74 static void gtk_entry_completion_get_property (GObject *object,
78 static void gtk_entry_completion_finalize (GObject *object);
80 static void gtk_entry_completion_pack_start (GtkCellLayout *cell_layout,
81 GtkCellRenderer *cell,
83 static void gtk_entry_completion_pack_end (GtkCellLayout *cell_layout,
84 GtkCellRenderer *cell,
86 static void gtk_entry_completion_clear (GtkCellLayout *cell_layout);
87 static void gtk_entry_completion_add_attribute (GtkCellLayout *cell_layout,
88 GtkCellRenderer *cell,
89 const char *attribute,
91 static void gtk_entry_completion_set_cell_data_func (GtkCellLayout *cell_layout,
92 GtkCellRenderer *cell,
93 GtkCellLayoutDataFunc func,
95 GDestroyNotify destroy);
96 static void gtk_entry_completion_clear_attributes (GtkCellLayout *cell_layout,
97 GtkCellRenderer *cell);
98 static void gtk_entry_completion_reorder (GtkCellLayout *cell_layout,
99 GtkCellRenderer *cell,
102 static gboolean gtk_entry_completion_visible_func (GtkTreeModel *model,
105 static gboolean gtk_entry_completion_popup_key_event (GtkWidget *widget,
108 static gboolean gtk_entry_completion_popup_button_press (GtkWidget *widget,
109 GdkEventButton *event,
111 static gboolean gtk_entry_completion_list_button_press (GtkWidget *widget,
112 GdkEventButton *event,
114 static gboolean gtk_entry_completion_action_button_press (GtkWidget *widget,
115 GdkEventButton *event,
117 static void gtk_entry_completion_selection_changed (GtkTreeSelection *selection,
119 static gboolean gtk_entry_completion_list_enter_notify (GtkWidget *widget,
120 GdkEventCrossing *event,
122 static gboolean gtk_entry_completion_list_motion_notify (GtkWidget *widget,
123 GdkEventMotion *event,
125 static void gtk_entry_completion_insert_action (GtkEntryCompletion *completion,
129 static void gtk_entry_completion_action_data_func (GtkTreeViewColumn *tree_column,
130 GtkCellRenderer *cell,
135 static gboolean gtk_entry_completion_match_selected (GtkEntryCompletion *completion,
138 static gboolean gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion,
139 const gchar *prefix);
140 static gboolean gtk_entry_completion_cursor_on_match (GtkEntryCompletion *completion,
143 static gboolean gtk_entry_completion_insert_completion (GtkEntryCompletion *completion,
146 static void gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
149 static guint entry_completion_signals[LAST_SIGNAL] = { 0 };
152 static void gtk_entry_completion_buildable_init (GtkBuildableIface *iface);
154 G_DEFINE_TYPE_WITH_CODE (GtkEntryCompletion, gtk_entry_completion, G_TYPE_OBJECT,
155 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
156 gtk_entry_completion_cell_layout_init)
157 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
158 gtk_entry_completion_buildable_init))
162 gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
164 GObjectClass *object_class;
166 object_class = (GObjectClass *)klass;
168 object_class->set_property = gtk_entry_completion_set_property;
169 object_class->get_property = gtk_entry_completion_get_property;
170 object_class->finalize = gtk_entry_completion_finalize;
172 klass->match_selected = gtk_entry_completion_match_selected;
173 klass->insert_prefix = gtk_entry_completion_real_insert_prefix;
174 klass->cursor_on_match = gtk_entry_completion_cursor_on_match;
177 * GtkEntryCompletion::insert-prefix:
178 * @widget: the object which received the signal
179 * @prefix: the common prefix of all possible completions
181 * Gets emitted when the inline autocompletion is triggered.
182 * The default behaviour is to make the entry display the
183 * whole prefix and select the newly inserted part.
185 * Applications may connect to this signal in order to insert only a
186 * smaller part of the @prefix into the entry - e.g. the entry used in
187 * the #GtkFileChooser inserts only the part of the prefix up to the
190 * Return value: %TRUE if the signal has been handled
194 entry_completion_signals[INSERT_PREFIX] =
195 g_signal_new (I_("insert_prefix"),
196 G_TYPE_FROM_CLASS (klass),
198 G_STRUCT_OFFSET (GtkEntryCompletionClass, insert_prefix),
199 _gtk_boolean_handled_accumulator, NULL,
200 _gtk_marshal_BOOLEAN__STRING,
205 * GtkEntryCompletion::match-selected:
206 * @widget: the object which received the signal
207 * @model: the #GtkTreeModel containing the matches
208 * @iter: a #GtkTreeIter positioned at the selected match
210 * Gets emitted when a match from the list is selected.
211 * The default behaviour is to replace the contents of the
212 * entry with the contents of the text column in the row
213 * pointed to by @iter.
215 * Return value: %TRUE if the signal has been handled
219 entry_completion_signals[MATCH_SELECTED] =
220 g_signal_new (I_("match_selected"),
221 G_TYPE_FROM_CLASS (klass),
223 G_STRUCT_OFFSET (GtkEntryCompletionClass, match_selected),
224 _gtk_boolean_handled_accumulator, NULL,
225 _gtk_marshal_BOOLEAN__OBJECT_BOXED,
230 * GtkEntryCompletion::cursor-on-match:
231 * @widget: the object which received the signal
232 * @model: the #GtkTreeModel containing the matches
233 * @iter: a #GtkTreeIter positioned at the selected match
235 * Gets emitted when a match from the cursor is on a match
236 * of the list.The default behaviour is to replace the contents
237 * of the entry with the contents of the text column in the row
238 * pointed to by @iter.
240 * Return value: %TRUE if the signal has been handled
245 entry_completion_signals[CURSOR_ON_MATCH] =
246 g_signal_new (I_("cursor_on_match"),
247 G_TYPE_FROM_CLASS (klass),
249 G_STRUCT_OFFSET (GtkEntryCompletionClass, cursor_on_match),
250 _gtk_boolean_handled_accumulator, NULL,
251 _gtk_marshal_BOOLEAN__OBJECT_BOXED,
257 * GtkEntryCompletion::action-activated:
258 * @widget: the object which received the signal
259 * @index: the index of the activated action
261 * Gets emitted when an action is activated.
265 entry_completion_signals[ACTION_ACTIVATED] =
266 g_signal_new (I_("action_activated"),
267 G_TYPE_FROM_CLASS (klass),
269 G_STRUCT_OFFSET (GtkEntryCompletionClass, action_activated),
271 _gtk_marshal_NONE__INT,
275 g_object_class_install_property (object_class,
277 g_param_spec_object ("model",
278 P_("Completion Model"),
279 P_("The model to find matches in"),
281 GTK_PARAM_READWRITE));
282 g_object_class_install_property (object_class,
283 PROP_MINIMUM_KEY_LENGTH,
284 g_param_spec_int ("minimum-key-length",
285 P_("Minimum Key Length"),
286 P_("Minimum length of the search key in order to look up matches"),
290 GTK_PARAM_READWRITE));
292 * GtkEntryCompletion:text-column:
294 * The column of the model containing the strings.
295 * Note that the strings must be UTF-8.
299 g_object_class_install_property (object_class,
301 g_param_spec_int ("text-column",
303 P_("The column of the model containing the strings."),
307 GTK_PARAM_READWRITE));
310 * GtkEntryCompletion:inline-completion:
312 * Determines whether the common prefix of the possible completions
313 * should be inserted automatically in the entry. Note that this
314 * requires text-column to be set, even if you are using a custom
319 g_object_class_install_property (object_class,
320 PROP_INLINE_COMPLETION,
321 g_param_spec_boolean ("inline-completion",
322 P_("Inline completion"),
323 P_("Whether the common prefix should be inserted automatically"),
325 GTK_PARAM_READWRITE));
327 * GtkEntryCompletion:popup-completion:
329 * Determines whether the possible completions should be
330 * shown in a popup window.
334 g_object_class_install_property (object_class,
335 PROP_POPUP_COMPLETION,
336 g_param_spec_boolean ("popup-completion",
337 P_("Popup completion"),
338 P_("Whether the completions should be shown in a popup window"),
340 GTK_PARAM_READWRITE));
343 * GtkEntryCompletion:popup-set-width:
345 * Determines whether the completions popup window will be
346 * resized to the width of the entry.
350 g_object_class_install_property (object_class,
351 PROP_POPUP_SET_WIDTH,
352 g_param_spec_boolean ("popup-set-width",
353 P_("Popup set width"),
354 P_("If TRUE, the popup window will have the same size as the entry"),
356 GTK_PARAM_READWRITE));
359 * GtkEntryCompletion:popup-single-match:
361 * Determines whether the completions popup window will shown
362 * for a single possible completion. You probably want to set
363 * this to %FALSE if you are using
364 * <link linkend="GtkEntryCompletion--inline-completion">inline
369 g_object_class_install_property (object_class,
370 PROP_POPUP_SINGLE_MATCH,
371 g_param_spec_boolean ("popup-single-match",
372 P_("Popup single match"),
373 P_("If TRUE, the popup window will appear for a single match."),
375 GTK_PARAM_READWRITE));
377 * GtkEntryCompletion:inline-selection:
379 * Determines whether the possible completions on the popup
380 * will appear in the entry as you navigate through them.
384 g_object_class_install_property (object_class,
385 PROP_INLINE_SELECTION,
386 g_param_spec_boolean ("inline-selection",
387 P_("Inline selection"),
388 P_("Your description here"),
390 GTK_PARAM_READWRITE));
392 g_type_class_add_private (object_class, sizeof (GtkEntryCompletionPrivate));
396 gtk_entry_completion_buildable_init (GtkBuildableIface *iface)
398 iface->add_child = _gtk_cell_layout_buildable_add_child;
399 iface->custom_tag_start = _gtk_cell_layout_buildable_custom_tag_start;
400 iface->custom_tag_end = _gtk_cell_layout_buildable_custom_tag_end;
404 gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface)
406 iface->pack_start = gtk_entry_completion_pack_start;
407 iface->pack_end = gtk_entry_completion_pack_end;
408 iface->clear = gtk_entry_completion_clear;
409 iface->add_attribute = gtk_entry_completion_add_attribute;
410 iface->set_cell_data_func = gtk_entry_completion_set_cell_data_func;
411 iface->clear_attributes = gtk_entry_completion_clear_attributes;
412 iface->reorder = gtk_entry_completion_reorder;
416 gtk_entry_completion_init (GtkEntryCompletion *completion)
418 GtkCellRenderer *cell;
419 GtkTreeSelection *sel;
420 GtkEntryCompletionPrivate *priv;
421 GtkWidget *popup_frame;
423 /* yes, also priv, need to keep the code readable */
424 priv = completion->priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (completion);
426 priv->minimum_key_length = 1;
427 priv->text_column = -1;
428 priv->has_completion = FALSE;
429 priv->inline_completion = FALSE;
430 priv->popup_completion = TRUE;
431 priv->popup_set_width = TRUE;
432 priv->popup_single_match = TRUE;
433 priv->inline_selection = FALSE;
436 priv->filter_model = NULL;
438 priv->tree_view = gtk_tree_view_new ();
439 g_signal_connect (priv->tree_view, "button_press_event",
440 G_CALLBACK (gtk_entry_completion_list_button_press),
442 g_signal_connect (priv->tree_view, "enter_notify_event",
443 G_CALLBACK (gtk_entry_completion_list_enter_notify),
445 g_signal_connect (priv->tree_view, "motion_notify_event",
446 G_CALLBACK (gtk_entry_completion_list_motion_notify),
449 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
450 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->tree_view), TRUE);
452 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
453 gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE);
454 gtk_tree_selection_unselect_all (sel);
455 g_signal_connect (sel, "changed",
456 G_CALLBACK (gtk_entry_completion_selection_changed),
458 priv->first_sel_changed = TRUE;
460 priv->column = gtk_tree_view_column_new ();
461 gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), priv->column);
463 priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
464 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
466 GTK_POLICY_AUTOMATIC);
467 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window),
470 /* a nasty hack to get the completions treeview to size nicely */
471 gtk_widget_set_size_request (GTK_SCROLLED_WINDOW (priv->scrolled_window)->vscrollbar, -1, 0);
474 priv->actions = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
477 gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->actions));
478 g_object_ref_sink (priv->action_view);
479 g_signal_connect (priv->action_view, "button_press_event",
480 G_CALLBACK (gtk_entry_completion_action_button_press),
482 g_signal_connect (priv->action_view, "enter_notify_event",
483 G_CALLBACK (gtk_entry_completion_list_enter_notify),
485 g_signal_connect (priv->action_view, "motion_notify_event",
486 G_CALLBACK (gtk_entry_completion_list_motion_notify),
488 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->action_view), FALSE);
489 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->action_view), TRUE);
491 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->action_view));
492 gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE);
493 gtk_tree_selection_unselect_all (sel);
495 cell = gtk_cell_renderer_text_new ();
496 gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (priv->action_view),
499 gtk_entry_completion_action_data_func,
504 priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
505 gtk_window_set_resizable (GTK_WINDOW (priv->popup_window), FALSE);
506 g_signal_connect (priv->popup_window, "key_press_event",
507 G_CALLBACK (gtk_entry_completion_popup_key_event),
509 g_signal_connect (priv->popup_window, "key_release_event",
510 G_CALLBACK (gtk_entry_completion_popup_key_event),
512 g_signal_connect (priv->popup_window, "button_press_event",
513 G_CALLBACK (gtk_entry_completion_popup_button_press),
516 popup_frame = gtk_frame_new (NULL);
517 gtk_frame_set_shadow_type (GTK_FRAME (popup_frame),
518 GTK_SHADOW_ETCHED_IN);
519 gtk_widget_show (popup_frame);
520 gtk_container_add (GTK_CONTAINER (priv->popup_window), popup_frame);
522 priv->vbox = gtk_vbox_new (FALSE, 0);
523 gtk_container_add (GTK_CONTAINER (popup_frame), priv->vbox);
525 gtk_container_add (GTK_CONTAINER (priv->scrolled_window), priv->tree_view);
526 gtk_box_pack_start (GTK_BOX (priv->vbox), priv->scrolled_window,
529 /* we don't want to see the action treeview when no actions have
530 * been inserted, so we pack the action treeview after the first
531 * action has been added
536 gtk_entry_completion_set_property (GObject *object,
541 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
542 GtkEntryCompletionPrivate *priv = completion->priv;
547 gtk_entry_completion_set_model (completion,
548 g_value_get_object (value));
551 case PROP_MINIMUM_KEY_LENGTH:
552 gtk_entry_completion_set_minimum_key_length (completion,
553 g_value_get_int (value));
556 case PROP_TEXT_COLUMN:
557 priv->text_column = g_value_get_int (value);
560 case PROP_INLINE_COMPLETION:
561 priv->inline_completion = g_value_get_boolean (value);
564 case PROP_POPUP_COMPLETION:
565 priv->popup_completion = g_value_get_boolean (value);
568 case PROP_POPUP_SET_WIDTH:
569 priv->popup_set_width = g_value_get_boolean (value);
572 case PROP_POPUP_SINGLE_MATCH:
573 priv->popup_single_match = g_value_get_boolean (value);
576 case PROP_INLINE_SELECTION:
577 priv->inline_selection = g_value_get_boolean (value);
581 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
587 gtk_entry_completion_get_property (GObject *object,
592 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
597 g_value_set_object (value,
598 gtk_entry_completion_get_model (completion));
601 case PROP_MINIMUM_KEY_LENGTH:
602 g_value_set_int (value, gtk_entry_completion_get_minimum_key_length (completion));
605 case PROP_TEXT_COLUMN:
606 g_value_set_int (value, gtk_entry_completion_get_text_column (completion));
609 case PROP_INLINE_COMPLETION:
610 g_value_set_boolean (value, gtk_entry_completion_get_inline_completion (completion));
613 case PROP_POPUP_COMPLETION:
614 g_value_set_boolean (value, gtk_entry_completion_get_popup_completion (completion));
617 case PROP_POPUP_SET_WIDTH:
618 g_value_set_boolean (value, gtk_entry_completion_get_popup_set_width (completion));
621 case PROP_POPUP_SINGLE_MATCH:
622 g_value_set_boolean (value, gtk_entry_completion_get_popup_single_match (completion));
625 case PROP_INLINE_SELECTION:
626 g_value_set_boolean (value, gtk_entry_completion_get_inline_selection (completion));
630 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
636 gtk_entry_completion_finalize (GObject *object)
638 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
639 GtkEntryCompletionPrivate *priv = completion->priv;
642 gtk_widget_destroy (priv->tree_view);
645 gtk_entry_set_completion (GTK_ENTRY (priv->entry), NULL);
648 g_object_unref (priv->actions);
649 if (priv->action_view)
650 g_object_unref (priv->action_view);
652 g_free (priv->case_normalized_key);
653 g_free (priv->completion_prefix);
655 if (priv->popup_window)
656 gtk_widget_destroy (priv->popup_window);
658 if (priv->match_notify)
659 (* priv->match_notify) (priv->match_data);
661 G_OBJECT_CLASS (gtk_entry_completion_parent_class)->finalize (object);
664 /* implement cell layout interface */
666 gtk_entry_completion_pack_start (GtkCellLayout *cell_layout,
667 GtkCellRenderer *cell,
670 GtkEntryCompletionPrivate *priv;
672 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
674 gtk_tree_view_column_pack_start (priv->column, cell, expand);
678 gtk_entry_completion_pack_end (GtkCellLayout *cell_layout,
679 GtkCellRenderer *cell,
682 GtkEntryCompletionPrivate *priv;
684 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
686 gtk_tree_view_column_pack_end (priv->column, cell, expand);
690 gtk_entry_completion_clear (GtkCellLayout *cell_layout)
692 GtkEntryCompletionPrivate *priv;
694 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
696 gtk_tree_view_column_clear (priv->column);
700 gtk_entry_completion_add_attribute (GtkCellLayout *cell_layout,
701 GtkCellRenderer *cell,
702 const gchar *attribute,
705 GtkEntryCompletionPrivate *priv;
707 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
709 gtk_tree_view_column_add_attribute (priv->column, cell, attribute, column);
713 gtk_entry_completion_set_cell_data_func (GtkCellLayout *cell_layout,
714 GtkCellRenderer *cell,
715 GtkCellLayoutDataFunc func,
717 GDestroyNotify destroy)
719 GtkEntryCompletionPrivate *priv;
721 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
723 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->column),
724 cell, func, func_data, destroy);
728 gtk_entry_completion_clear_attributes (GtkCellLayout *cell_layout,
729 GtkCellRenderer *cell)
731 GtkEntryCompletionPrivate *priv;
733 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
735 gtk_tree_view_column_clear_attributes (priv->column, cell);
739 gtk_entry_completion_reorder (GtkCellLayout *cell_layout,
740 GtkCellRenderer *cell,
743 GtkEntryCompletionPrivate *priv;
745 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
747 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->column), cell, position);
750 /* all those callbacks */
752 gtk_entry_completion_default_completion_func (GtkEntryCompletion *completion,
758 gchar *normalized_string;
759 gchar *case_normalized_string;
761 gboolean ret = FALSE;
765 model = gtk_tree_model_filter_get_model (completion->priv->filter_model);
767 g_return_val_if_fail (gtk_tree_model_get_column_type (model, completion->priv->text_column) == G_TYPE_STRING,
770 gtk_tree_model_get (model, iter,
771 completion->priv->text_column, &item,
776 normalized_string = g_utf8_normalize (item, -1, G_NORMALIZE_ALL);
777 case_normalized_string = g_utf8_casefold (normalized_string, -1);
779 if (!strncmp (key, case_normalized_string, strlen (key)))
783 g_free (normalized_string);
784 g_free (case_normalized_string);
791 gtk_entry_completion_visible_func (GtkTreeModel *model,
795 gboolean ret = FALSE;
797 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
799 if (!completion->priv->case_normalized_key)
802 if (completion->priv->match_func)
803 ret = (* completion->priv->match_func) (completion,
804 completion->priv->case_normalized_key,
806 completion->priv->match_data);
807 else if (completion->priv->text_column >= 0)
808 ret = gtk_entry_completion_default_completion_func (completion,
809 completion->priv->case_normalized_key,
817 gtk_entry_completion_popup_key_event (GtkWidget *widget,
821 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
823 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
826 /* propagate event to the entry */
827 gtk_widget_event (completion->priv->entry, (GdkEvent *)event);
833 gtk_entry_completion_popup_button_press (GtkWidget *widget,
834 GdkEventButton *event,
837 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
839 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
842 /* if we come here, it's usually time to popdown */
843 _gtk_entry_completion_popdown (completion);
849 gtk_entry_completion_list_button_press (GtkWidget *widget,
850 GdkEventButton *event,
853 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
854 GtkTreePath *path = NULL;
856 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
859 if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
861 &path, NULL, NULL, NULL))
866 gtk_tree_model_get_iter (GTK_TREE_MODEL (completion->priv->filter_model),
868 gtk_tree_path_free (path);
870 g_signal_handler_block (completion->priv->entry,
871 completion->priv->changed_id);
872 g_signal_emit (completion, entry_completion_signals[MATCH_SELECTED],
873 0, GTK_TREE_MODEL (completion->priv->filter_model),
875 g_signal_handler_unblock (completion->priv->entry,
876 completion->priv->changed_id);
878 _gtk_entry_completion_popdown (completion);
887 gtk_entry_completion_action_button_press (GtkWidget *widget,
888 GdkEventButton *event,
891 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
892 GtkTreePath *path = NULL;
894 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
897 _gtk_entry_reset_im_context (GTK_ENTRY (completion->priv->entry));
899 if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
901 &path, NULL, NULL, NULL))
903 g_signal_emit (completion, entry_completion_signals[ACTION_ACTIVATED],
904 0, gtk_tree_path_get_indices (path)[0]);
905 gtk_tree_path_free (path);
907 _gtk_entry_completion_popdown (completion);
915 gtk_entry_completion_action_data_func (GtkTreeViewColumn *tree_column,
916 GtkCellRenderer *cell,
921 gchar *string = NULL;
924 gtk_tree_model_get (model, iter,
947 gtk_entry_completion_selection_changed (GtkTreeSelection *selection,
950 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
952 if (completion->priv->first_sel_changed)
954 completion->priv->first_sel_changed = FALSE;
955 if (gtk_widget_is_focus (completion->priv->tree_view))
956 gtk_tree_selection_unselect_all (selection);
963 * gtk_entry_completion_new:
965 * Creates a new #GtkEntryCompletion object.
967 * Return value: A newly created #GtkEntryCompletion object.
972 gtk_entry_completion_new (void)
974 GtkEntryCompletion *completion;
976 completion = g_object_new (GTK_TYPE_ENTRY_COMPLETION, NULL);
982 * gtk_entry_completion_get_entry:
983 * @completion: A #GtkEntryCompletion.
985 * Gets the entry @completion has been attached to.
987 * Return value: The entry @completion has been attached to.
992 gtk_entry_completion_get_entry (GtkEntryCompletion *completion)
994 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
996 return completion->priv->entry;
1000 * gtk_entry_completion_set_model:
1001 * @completion: A #GtkEntryCompletion.
1002 * @model: The #GtkTreeModel.
1004 * Sets the model for a #GtkEntryCompletion. If @completion already has
1005 * a model set, it will remove it before setting the new model.
1006 * If model is %NULL, then it will unset the model.
1011 gtk_entry_completion_set_model (GtkEntryCompletion *completion,
1012 GtkTreeModel *model)
1014 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1015 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
1019 gtk_tree_view_set_model (GTK_TREE_VIEW (completion->priv->tree_view),
1021 _gtk_entry_completion_popdown (completion);
1022 completion->priv->filter_model = NULL;
1026 /* code will unref the old filter model (if any) */
1027 completion->priv->filter_model =
1028 GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (model, NULL));
1029 gtk_tree_model_filter_set_visible_func (completion->priv->filter_model,
1030 gtk_entry_completion_visible_func,
1034 gtk_tree_view_set_model (GTK_TREE_VIEW (completion->priv->tree_view),
1035 GTK_TREE_MODEL (completion->priv->filter_model));
1036 g_object_unref (completion->priv->filter_model);
1038 g_object_notify (G_OBJECT (completion), "model");
1040 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
1041 _gtk_entry_completion_resize_popup (completion);
1045 * gtk_entry_completion_get_model:
1046 * @completion: A #GtkEntryCompletion.
1048 * Returns the model the #GtkEntryCompletion is using as data source.
1049 * Returns %NULL if the model is unset.
1051 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
1056 gtk_entry_completion_get_model (GtkEntryCompletion *completion)
1058 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
1060 if (!completion->priv->filter_model)
1063 return gtk_tree_model_filter_get_model (completion->priv->filter_model);
1067 * gtk_entry_completion_set_match_func:
1068 * @completion: A #GtkEntryCompletion.
1069 * @func: The #GtkEntryCompletionMatchFunc to use.
1070 * @func_data: The user data for @func.
1071 * @func_notify: Destroy notifier for @func_data.
1073 * Sets the match function for @completion to be @func. The match function
1074 * is used to determine if a row should or should not be in the completion
1080 gtk_entry_completion_set_match_func (GtkEntryCompletion *completion,
1081 GtkEntryCompletionMatchFunc func,
1083 GDestroyNotify func_notify)
1085 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1087 if (completion->priv->match_notify)
1088 (* completion->priv->match_notify) (completion->priv->match_data);
1090 completion->priv->match_func = func;
1091 completion->priv->match_data = func_data;
1092 completion->priv->match_notify = func_notify;
1096 * gtk_entry_completion_set_minimum_key_length:
1097 * @completion: A #GtkEntryCompletion.
1098 * @length: The minimum length of the key in order to start completing.
1100 * Requires the length of the search key for @completion to be at least
1101 * @length. This is useful for long lists, where completing using a small
1102 * key takes a lot of time and will come up with meaningless results anyway
1103 * (ie, a too large dataset).
1108 gtk_entry_completion_set_minimum_key_length (GtkEntryCompletion *completion,
1111 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1112 g_return_if_fail (length >= 0);
1114 if (completion->priv->minimum_key_length != length)
1116 completion->priv->minimum_key_length = length;
1118 g_object_notify (G_OBJECT (completion), "minimum-key-length");
1123 * gtk_entry_completion_get_minimum_key_length:
1124 * @completion: A #GtkEntryCompletion.
1126 * Returns the minimum key length as set for @completion.
1128 * Return value: The currently used minimum key length.
1133 gtk_entry_completion_get_minimum_key_length (GtkEntryCompletion *completion)
1135 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), 0);
1137 return completion->priv->minimum_key_length;
1141 * gtk_entry_completion_complete:
1142 * @completion: A #GtkEntryCompletion.
1144 * Requests a completion operation, or in other words a refiltering of the
1145 * current list with completions, using the current key. The completion list
1146 * view will be updated accordingly.
1151 gtk_entry_completion_complete (GtkEntryCompletion *completion)
1155 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1157 if (!completion->priv->filter_model)
1160 g_free (completion->priv->case_normalized_key);
1162 tmp = g_utf8_normalize (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)),
1163 -1, G_NORMALIZE_ALL);
1164 completion->priv->case_normalized_key = g_utf8_casefold (tmp, -1);
1167 gtk_tree_model_filter_refilter (completion->priv->filter_model);
1169 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
1170 _gtk_entry_completion_resize_popup (completion);
1174 gtk_entry_completion_insert_action (GtkEntryCompletion *completion,
1176 const gchar *string,
1181 gtk_list_store_insert (completion->priv->actions, &iter, index);
1182 gtk_list_store_set (completion->priv->actions, &iter,
1187 if (!completion->priv->action_view->parent)
1189 GtkTreePath *path = gtk_tree_path_new_from_indices (0, -1);
1191 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
1193 gtk_tree_path_free (path);
1195 gtk_box_pack_start (GTK_BOX (completion->priv->vbox),
1196 completion->priv->action_view, FALSE, FALSE, 0);
1197 gtk_widget_show (completion->priv->action_view);
1202 * gtk_entry_completion_insert_action_text:
1203 * @completion: A #GtkEntryCompletion.
1204 * @index_: The index of the item to insert.
1205 * @text: Text of the item to insert.
1207 * Inserts an action in @completion's action item list at position @index_
1208 * with text @text. If you want the action item to have markup, use
1209 * gtk_entry_completion_insert_action_markup().
1214 gtk_entry_completion_insert_action_text (GtkEntryCompletion *completion,
1218 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1219 g_return_if_fail (text != NULL);
1221 gtk_entry_completion_insert_action (completion, index_, text, FALSE);
1225 * gtk_entry_completion_insert_action_markup:
1226 * @completion: A #GtkEntryCompletion.
1227 * @index_: The index of the item to insert.
1228 * @markup: Markup of the item to insert.
1230 * Inserts an action in @completion's action item list at position @index_
1231 * with markup @markup.
1236 gtk_entry_completion_insert_action_markup (GtkEntryCompletion *completion,
1238 const gchar *markup)
1240 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1241 g_return_if_fail (markup != NULL);
1243 gtk_entry_completion_insert_action (completion, index_, markup, TRUE);
1247 * gtk_entry_completion_delete_action:
1248 * @completion: A #GtkEntryCompletion.
1249 * @index_: The index of the item to Delete.
1251 * Deletes the action at @index_ from @completion's action list.
1256 gtk_entry_completion_delete_action (GtkEntryCompletion *completion,
1261 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1262 g_return_if_fail (index_ >= 0);
1264 gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (completion->priv->actions),
1265 &iter, NULL, index_);
1266 gtk_list_store_remove (completion->priv->actions, &iter);
1270 * gtk_entry_completion_set_text_column:
1271 * @completion: A #GtkEntryCompletion.
1272 * @column: The column in the model of @completion to get strings from.
1274 * Convenience function for setting up the most used case of this code: a
1275 * completion list with just strings. This function will set up @completion
1276 * to have a list displaying all (and just) strings in the completion list,
1277 * and to get those strings from @column in the model of @completion.
1279 * This functions creates and adds a #GtkCellRendererText for the selected
1280 * column. If you need to set the text column, but don't want the cell
1281 * renderer, use g_object_set() to set the ::text_column property directly.
1286 gtk_entry_completion_set_text_column (GtkEntryCompletion *completion,
1289 GtkCellRenderer *cell;
1291 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1292 g_return_if_fail (column >= 0);
1294 completion->priv->text_column = column;
1296 cell = gtk_cell_renderer_text_new ();
1297 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion),
1299 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (completion),
1303 g_object_notify (G_OBJECT (completion), "text-column");
1307 * gtk_entry_completion_get_text_column:
1308 * @completion: a #GtkEntryCompletion
1310 * Returns the column in the model of @completion to get strings from.
1312 * Return value: the column containing the strings
1317 gtk_entry_completion_get_text_column (GtkEntryCompletion *completion)
1319 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), -1);
1321 return completion->priv->text_column;
1327 gtk_entry_completion_list_enter_notify (GtkWidget *widget,
1328 GdkEventCrossing *event,
1331 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
1333 return completion->priv->ignore_enter;
1337 gtk_entry_completion_list_motion_notify (GtkWidget *widget,
1338 GdkEventMotion *event,
1341 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
1343 completion->priv->ignore_enter = FALSE;
1349 /* some nasty size requisition */
1351 _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
1354 gint matches, items, height, x_border, y_border;
1357 gint vertical_separator;
1358 GdkRectangle monitor;
1359 GtkRequisition popup_req;
1360 GtkRequisition entry_req;
1365 if (!completion->priv->entry->window)
1368 gdk_window_get_origin (completion->priv->entry->window, &x, &y);
1369 _gtk_entry_get_borders (GTK_ENTRY (completion->priv->entry), &x_border, &y_border);
1371 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
1373 items = MIN (matches, 15);
1375 gtk_tree_view_column_cell_get_size (completion->priv->column, NULL,
1376 NULL, NULL, NULL, &height);
1378 gtk_widget_style_get (GTK_WIDGET (completion->priv->tree_view),
1379 "vertical-separator", &vertical_separator,
1382 height += vertical_separator;
1384 gtk_widget_realize (completion->priv->tree_view);
1387 gtk_widget_hide (completion->priv->scrolled_window);
1389 gtk_widget_show (completion->priv->scrolled_window);
1391 screen = gtk_widget_get_screen (GTK_WIDGET (completion->priv->entry));
1392 monitor_num = gdk_screen_get_monitor_at_window (screen,
1393 GTK_WIDGET (completion->priv->entry)->window);
1394 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1396 if (completion->priv->popup_set_width)
1397 width = MIN (completion->priv->entry->allocation.width, monitor.width) - 2 * x_border;
1401 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (completion->priv->tree_view));
1402 gtk_widget_set_size_request (completion->priv->tree_view, width, items * height);
1404 /* default on no match */
1405 completion->priv->current_selected = -1;
1407 items = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
1411 gtk_widget_show (completion->priv->action_view);
1412 gtk_widget_set_size_request (completion->priv->action_view, width, -1);
1415 gtk_widget_hide (completion->priv->action_view);
1417 gtk_widget_size_request (completion->priv->popup_window, &popup_req);
1418 gtk_widget_size_request (completion->priv->entry, &entry_req);
1422 else if (x + popup_req.width > monitor.x + monitor.width)
1423 x = monitor.x + monitor.width - popup_req.width;
1425 if (y + entry_req.height + popup_req.height <= monitor.y + monitor.height ||
1426 y - monitor.y < (monitor.y + monitor.height) - (y + entry_req.height))
1428 y += entry_req.height;
1433 y -= popup_req.height;
1439 path = gtk_tree_path_new_from_indices (above ? matches - 1 : 0, -1);
1440 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (completion->priv->tree_view), path,
1441 NULL, FALSE, 0.0, 0.0);
1442 gtk_tree_path_free (path);
1445 gtk_window_move (GTK_WINDOW (completion->priv->popup_window), x, y);
1451 _gtk_entry_completion_popup (GtkEntryCompletion *completion)
1453 GtkTreeViewColumn *column;
1455 GtkWidget *toplevel;
1457 if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
1460 if (!GTK_WIDGET_MAPPED (completion->priv->entry))
1463 if (!GTK_WIDGET_HAS_FOCUS (completion->priv->entry))
1466 completion->priv->ignore_enter = TRUE;
1468 column = gtk_tree_view_get_column (GTK_TREE_VIEW (completion->priv->action_view), 0);
1469 renderers = gtk_tree_view_column_get_cell_renderers (column);
1470 gtk_widget_ensure_style (completion->priv->tree_view);
1471 g_object_set (GTK_CELL_RENDERER (renderers->data), "cell-background-gdk",
1472 &completion->priv->tree_view->style->bg[GTK_STATE_NORMAL],
1474 g_list_free (renderers);
1476 gtk_widget_show_all (completion->priv->vbox);
1478 _gtk_entry_completion_resize_popup (completion);
1480 toplevel = gtk_widget_get_toplevel (completion->priv->entry);
1481 if (GTK_IS_WINDOW (toplevel))
1482 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1483 GTK_WINDOW (completion->priv->popup_window));
1485 /* prevent the first row being focused */
1486 gtk_widget_grab_focus (completion->priv->tree_view);
1488 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
1489 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
1492 gtk_widget_show (completion->priv->popup_window);
1494 gtk_grab_add (completion->priv->popup_window);
1495 gdk_pointer_grab (completion->priv->popup_window->window, TRUE,
1496 GDK_BUTTON_PRESS_MASK |
1497 GDK_BUTTON_RELEASE_MASK |
1498 GDK_POINTER_MOTION_MASK,
1499 NULL, NULL, GDK_CURRENT_TIME);
1503 _gtk_entry_completion_popdown (GtkEntryCompletion *completion)
1505 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
1508 completion->priv->ignore_enter = FALSE;
1510 gdk_pointer_ungrab (GDK_CURRENT_TIME);
1511 gtk_grab_remove (completion->priv->popup_window);
1513 gtk_widget_hide (completion->priv->popup_window);
1517 gtk_entry_completion_match_selected (GtkEntryCompletion *completion,
1518 GtkTreeModel *model,
1523 gtk_tree_model_get (model, iter, completion->priv->text_column, &str, -1);
1524 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), str ? str : "");
1526 /* move cursor to the end */
1527 gtk_editable_set_position (GTK_EDITABLE (completion->priv->entry), -1);
1535 gtk_entry_completion_cursor_on_match (GtkEntryCompletion *completion,
1536 GtkTreeModel *model,
1539 gtk_entry_completion_insert_completion (completion, model, iter);
1545 gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion)
1548 gchar *prefix = NULL;
1552 if (completion->priv->text_column < 0)
1555 key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry));
1557 valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (completion->priv->filter_model),
1564 gtk_tree_model_get (GTK_TREE_MODEL (completion->priv->filter_model),
1565 &iter, completion->priv->text_column, &text,
1568 if (text && g_str_has_prefix (text, key))
1571 prefix = g_strdup (text);
1577 while (*p && *p == *q)
1587 /* strip a partial multibyte character */
1588 q = g_utf8_find_prev_char (prefix, p);
1589 switch (g_utf8_get_char_validated (q, p - q))
1601 valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (completion->priv->filter_model),
1610 gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion,
1611 const gchar *prefix)
1619 prefix_len = g_utf8_strlen (prefix, -1);
1621 key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry));
1622 key_len = g_utf8_strlen (key, -1);
1624 if (prefix_len > key_len)
1626 gint pos = prefix_len;
1628 gtk_editable_insert_text (GTK_EDITABLE (completion->priv->entry),
1629 prefix + strlen (key), -1, &pos);
1630 gtk_editable_select_region (GTK_EDITABLE (completion->priv->entry),
1631 key_len, prefix_len);
1633 completion->priv->has_completion = TRUE;
1641 * gtk_entry_completion_get_completion_prefix:
1642 * @completion: a #GtkEntryCompletion
1644 * Get the original text entered by the user that triggered
1645 * the completion or %NULL if there's no completion ongoing.
1647 * Returns: the prefix for the current completion
1652 gtk_entry_completion_get_completion_prefix (GtkEntryCompletion *completion)
1654 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
1656 return completion->priv->completion_prefix;
1660 gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
1663 GtkEntryCompletionPrivate *priv = completion->priv;
1666 priv = completion->priv;
1668 if (priv->changed_id > 0)
1669 g_signal_handler_block (priv->entry, priv->changed_id);
1671 if (priv->insert_text_id > 0)
1672 g_signal_handler_block (priv->entry, priv->insert_text_id);
1674 gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
1676 len = strlen (priv->completion_prefix);
1677 gtk_editable_select_region (GTK_EDITABLE (priv->entry), len, -1);
1679 if (priv->changed_id > 0)
1680 g_signal_handler_unblock (priv->entry, priv->changed_id);
1682 if (priv->insert_text_id > 0)
1683 g_signal_handler_unblock (priv->entry, priv->insert_text_id);
1687 gtk_entry_completion_insert_completion (GtkEntryCompletion *completion,
1688 GtkTreeModel *model,
1693 if (completion->priv->text_column < 0)
1696 gtk_tree_model_get (model, iter,
1697 completion->priv->text_column, &str,
1700 gtk_entry_completion_insert_completion_text (completion, str);
1708 * gtk_entry_completion_insert_prefix:
1709 * @completion: a #GtkEntryCompletion
1711 * Requests a prefix insertion.
1717 gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion)
1722 if (completion->priv->insert_text_id > 0)
1723 g_signal_handler_block (completion->priv->entry,
1724 completion->priv->insert_text_id);
1726 prefix = gtk_entry_completion_compute_prefix (completion);
1729 g_signal_emit (completion, entry_completion_signals[INSERT_PREFIX],
1734 if (completion->priv->insert_text_id > 0)
1735 g_signal_handler_unblock (completion->priv->entry,
1736 completion->priv->insert_text_id);
1740 * gtk_entry_completion_set_inline_completion:
1741 * @completion: a #GtkEntryCompletion
1742 * @inline_completion: %TRUE to do inline completion
1744 * Sets whether the common prefix of the possible completions should
1745 * be automatically inserted in the entry.
1750 gtk_entry_completion_set_inline_completion (GtkEntryCompletion *completion,
1751 gboolean inline_completion)
1753 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1755 inline_completion = inline_completion != FALSE;
1757 if (completion->priv->inline_completion != inline_completion)
1759 completion->priv->inline_completion = inline_completion;
1761 g_object_notify (G_OBJECT (completion), "inline-completion");
1766 * gtk_entry_completion_get_inline_completion:
1767 * @completion: a #GtkEntryCompletion
1769 * Returns whether the common prefix of the possible completions should
1770 * be automatically inserted in the entry.
1772 * Return value: %TRUE if inline completion is turned on
1777 gtk_entry_completion_get_inline_completion (GtkEntryCompletion *completion)
1779 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), FALSE);
1781 return completion->priv->inline_completion;
1785 * gtk_entry_completion_set_popup_completion:
1786 * @completion: a #GtkEntryCompletion
1787 * @popup_completion: %TRUE to do popup completion
1789 * Sets whether the completions should be presented in a popup window.
1794 gtk_entry_completion_set_popup_completion (GtkEntryCompletion *completion,
1795 gboolean popup_completion)
1797 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1799 popup_completion = popup_completion != FALSE;
1801 if (completion->priv->popup_completion != popup_completion)
1803 completion->priv->popup_completion = popup_completion;
1805 g_object_notify (G_OBJECT (completion), "popup-completion");
1811 * gtk_entry_completion_get_popup_completion:
1812 * @completion: a #GtkEntryCompletion
1814 * Returns whether the completions should be presented in a popup window.
1816 * Return value: %TRUE if popup completion is turned on
1821 gtk_entry_completion_get_popup_completion (GtkEntryCompletion *completion)
1823 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1825 return completion->priv->popup_completion;
1829 * gtk_entry_completion_set_popup_set_width:
1830 * @completion: a #GtkEntryCompletion
1831 * @popup_set_width: %TRUE to make the width of the popup the same as the entry
1833 * Sets whether the completion popup window will be resized to be the same
1834 * width as the entry.
1839 gtk_entry_completion_set_popup_set_width (GtkEntryCompletion *completion,
1840 gboolean popup_set_width)
1842 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1844 popup_set_width = popup_set_width != FALSE;
1846 if (completion->priv->popup_set_width != popup_set_width)
1848 completion->priv->popup_set_width = popup_set_width;
1850 g_object_notify (G_OBJECT (completion), "popup-set-width");
1855 * gtk_entry_completion_get_popup_set_width:
1856 * @completion: a #GtkEntryCompletion
1858 * Returns whether the completion popup window will be resized to the
1859 * width of the entry.
1861 * Return value: %TRUE if the popup window will be resized to the width of
1867 gtk_entry_completion_get_popup_set_width (GtkEntryCompletion *completion)
1869 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1871 return completion->priv->popup_set_width;
1876 * gtk_entry_completion_set_popup_single_match:
1877 * @completion: a #GtkEntryCompletion
1878 * @popup_single_match: %TRUE if the popup should appear even for a single
1881 * Sets whether the completion popup window will appear even if there is
1882 * only a single match. You may want to set this to %FALSE if you
1883 * are using <link linkend="GtkEntryCompletion--inline-completion">inline
1884 * completion</link>.
1889 gtk_entry_completion_set_popup_single_match (GtkEntryCompletion *completion,
1890 gboolean popup_single_match)
1892 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1894 popup_single_match = popup_single_match != FALSE;
1896 if (completion->priv->popup_single_match != popup_single_match)
1898 completion->priv->popup_single_match = popup_single_match;
1900 g_object_notify (G_OBJECT (completion), "popup-single-match");
1905 * gtk_entry_completion_get_popup_single_match:
1906 * @completion: a #GtkEntryCompletion
1908 * Returns whether the completion popup window will appear even if there is
1909 * only a single match.
1911 * Return value: %TRUE if the popup window will appear regardless of the
1912 * number of matches.
1917 gtk_entry_completion_get_popup_single_match (GtkEntryCompletion *completion)
1919 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1921 return completion->priv->popup_single_match;
1925 * gtk_entry_completion_set_inline_selection:
1926 * @completion: a #GtkEntryCompletion
1927 * @inline_selection: %TRUE to do inline selection
1929 * Sets whether it is possible to cycle through the possible completions
1935 gtk_entry_completion_set_inline_selection (GtkEntryCompletion *completion,
1936 gboolean inline_selection)
1938 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1940 inline_selection = inline_selection != FALSE;
1942 if (completion->priv->inline_selection != inline_selection)
1944 completion->priv->inline_selection = inline_selection;
1946 g_object_notify (G_OBJECT (completion), "inline-selection");
1951 * gtk_entry_completion_get_inline_selection:
1952 * @completion: a #GtkEntryCompletion
1954 * Returns %TRUE if inline-selection mode is turned on.
1956 * Returns: %TRUE if inline-selection mode is on
1961 gtk_entry_completion_get_inline_selection (GtkEntryCompletion *completion)
1963 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), FALSE);
1965 return completion->priv->inline_selection;
1968 #define __GTK_ENTRY_COMPLETION_C__
1969 #include "gtkaliasdef.c"