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"
58 PROP_MINIMUM_KEY_LENGTH,
60 PROP_INLINE_COMPLETION,
61 PROP_POPUP_COMPLETION,
63 PROP_POPUP_SINGLE_MATCH
66 #define GTK_ENTRY_COMPLETION_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY_COMPLETION, GtkEntryCompletionPrivate))
68 static void gtk_entry_completion_class_init (GtkEntryCompletionClass *klass);
69 static void gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface);
70 static void gtk_entry_completion_init (GtkEntryCompletion *completion);
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_press (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);
142 static GObjectClass *parent_class = NULL;
143 static guint entry_completion_signals[LAST_SIGNAL] = { 0 };
147 gtk_entry_completion_get_type (void)
149 static GType entry_completion_type = 0;
151 if (!entry_completion_type)
153 static const GTypeInfo entry_completion_info =
155 sizeof (GtkEntryCompletionClass),
158 (GClassInitFunc) gtk_entry_completion_class_init,
161 sizeof (GtkEntryCompletion),
163 (GInstanceInitFunc) gtk_entry_completion_init
166 static const GInterfaceInfo cell_layout_info =
168 (GInterfaceInitFunc) gtk_entry_completion_cell_layout_init,
173 entry_completion_type =
174 g_type_register_static (G_TYPE_OBJECT, I_("GtkEntryCompletion"),
175 &entry_completion_info, 0);
177 g_type_add_interface_static (entry_completion_type,
178 GTK_TYPE_CELL_LAYOUT,
182 return entry_completion_type;
186 gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
188 GObjectClass *object_class;
190 parent_class = g_type_class_peek_parent (klass);
191 object_class = (GObjectClass *)klass;
193 object_class->set_property = gtk_entry_completion_set_property;
194 object_class->get_property = gtk_entry_completion_get_property;
195 object_class->finalize = gtk_entry_completion_finalize;
197 klass->match_selected = gtk_entry_completion_match_selected;
198 klass->insert_prefix = gtk_entry_completion_real_insert_prefix;
201 * GtkEntryCompletion::insert-prefix:
202 * @widget: the object which received the signal
203 * @prefix: the common prefix of all possible completions
205 * Gets emitted when the inline autocompletion is triggered.
206 * The default behaviour is to make the entry display the
207 * whole prefix and select the newly inserted part.
209 * Applications may connect to this signal in order to insert only a
210 * smaller part of the @prefix into the entry - e.g. the entry used in
211 * the #GtkFileChooser inserts only the part of the prefix up to the
214 * Return value: %TRUE if the signal has been handled
218 entry_completion_signals[INSERT_PREFIX] =
219 g_signal_new (I_("insert_prefix"),
220 G_TYPE_FROM_CLASS (klass),
222 G_STRUCT_OFFSET (GtkEntryCompletionClass, insert_prefix),
223 _gtk_boolean_handled_accumulator, NULL,
224 _gtk_marshal_BOOLEAN__STRING,
229 * GtkEntryCompletion::match-selected:
230 * @widget: the object which received the signal
231 * @model: the #GtkTreeModel containing the matches
232 * @iter: a #GtkTreeIter positioned at the selected match
234 * Gets emitted when a match from the list is selected.
235 * The default behaviour is to replace the contents of the
236 * entry with the contents of the text column in the row
237 * pointed to by @iter.
239 * Return value: %TRUE if the signal has been handled
243 entry_completion_signals[MATCH_SELECTED] =
244 g_signal_new (I_("match_selected"),
245 G_TYPE_FROM_CLASS (klass),
247 G_STRUCT_OFFSET (GtkEntryCompletionClass, match_selected),
248 _gtk_boolean_handled_accumulator, NULL,
249 _gtk_marshal_BOOLEAN__OBJECT_BOXED,
255 * GtkEntryCompletion::action-activated:
256 * @widget: the object which received the signal
257 * @index: the index of the activated action
259 * Gets emitted when an action is activated.
263 entry_completion_signals[ACTION_ACTIVATED] =
264 g_signal_new (I_("action_activated"),
265 G_TYPE_FROM_CLASS (klass),
267 G_STRUCT_OFFSET (GtkEntryCompletionClass, action_activated),
269 _gtk_marshal_NONE__INT,
273 g_object_class_install_property (object_class,
275 g_param_spec_object ("model",
276 P_("Completion Model"),
277 P_("The model to find matches in"),
279 GTK_PARAM_READWRITE));
280 g_object_class_install_property (object_class,
281 PROP_MINIMUM_KEY_LENGTH,
282 g_param_spec_int ("minimum-key-length",
283 P_("Minimum Key Length"),
284 P_("Minimum length of the search key in order to look up matches"),
288 GTK_PARAM_READWRITE));
290 * GtkEntryCompletion:text-column:
292 * The column of the model containing the strings.
296 g_object_class_install_property (object_class,
298 g_param_spec_int ("text-column",
300 P_("The column of the model containing the strings."),
304 GTK_PARAM_READWRITE));
307 * GtkEntryCompletion:inline-completion:
309 * Determines whether the common prefix of the possible completions
310 * should be inserted automatically in the entry. Note that this
311 * requires text-column to be set, even if you are using a custom
316 g_object_class_install_property (object_class,
317 PROP_INLINE_COMPLETION,
318 g_param_spec_boolean ("inline-completion",
319 P_("Inline completion"),
320 P_("Whether the common prefix should be inserted automatically"),
322 GTK_PARAM_READWRITE));
324 * GtkEntryCompletion:popup-completion:
326 * Determines whether the possible completions should be
327 * shown in a popup window.
331 g_object_class_install_property (object_class,
332 PROP_POPUP_COMPLETION,
333 g_param_spec_boolean ("popup-completion",
334 P_("Popup completion"),
335 P_("Whether the completions should be shown in a popup window"),
337 GTK_PARAM_READWRITE));
340 * GtkEntryCompletion:popup-set-width:
342 * Determines whether the completions popup window will be
343 * resized to the width of the entry.
347 g_object_class_install_property (object_class,
348 PROP_POPUP_SET_WIDTH,
349 g_param_spec_boolean ("popup-set-width",
350 P_("Popup set width"),
351 P_("If TRUE, the popup window will have the same size as the entry"),
353 GTK_PARAM_READWRITE));
356 * GtkEntryCompletion:popup-single-match:
358 * Determines whether the completions popup window will shown
359 * for a single possible completion. You probably want to set
360 * this to %FALSE if you are using
361 * <link linkend="GtkEntryCompletion--inline-completion">inline
366 g_object_class_install_property (object_class,
367 PROP_POPUP_SINGLE_MATCH,
368 g_param_spec_boolean ("popup-single-match",
369 P_("Popup single match"),
370 P_("If TRUE, the popup window will appear for a single match."),
372 GTK_PARAM_READWRITE));
374 g_type_class_add_private (object_class, sizeof (GtkEntryCompletionPrivate));
378 gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface)
380 iface->pack_start = gtk_entry_completion_pack_start;
381 iface->pack_end = gtk_entry_completion_pack_end;
382 iface->clear = gtk_entry_completion_clear;
383 iface->add_attribute = gtk_entry_completion_add_attribute;
384 iface->set_cell_data_func = gtk_entry_completion_set_cell_data_func;
385 iface->clear_attributes = gtk_entry_completion_clear_attributes;
386 iface->reorder = gtk_entry_completion_reorder;
390 gtk_entry_completion_init (GtkEntryCompletion *completion)
392 GtkCellRenderer *cell;
393 GtkTreeSelection *sel;
394 GtkEntryCompletionPrivate *priv;
395 GtkWidget *popup_frame;
397 /* yes, also priv, need to keep the code readable */
398 priv = completion->priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (completion);
400 priv->minimum_key_length = 1;
401 priv->text_column = -1;
402 priv->has_completion = FALSE;
403 priv->inline_completion = FALSE;
404 priv->popup_completion = TRUE;
405 priv->popup_set_width = TRUE;
406 priv->popup_single_match = TRUE;
409 priv->filter_model = NULL;
411 priv->tree_view = gtk_tree_view_new ();
412 g_signal_connect (priv->tree_view, "button_press_event",
413 G_CALLBACK (gtk_entry_completion_list_button_press),
415 g_signal_connect (priv->tree_view, "enter_notify_event",
416 G_CALLBACK (gtk_entry_completion_list_enter_notify),
418 g_signal_connect (priv->tree_view, "motion_notify_event",
419 G_CALLBACK (gtk_entry_completion_list_motion_notify),
421 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
422 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->tree_view), TRUE);
424 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
425 gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE);
426 gtk_tree_selection_unselect_all (sel);
427 g_signal_connect (sel, "changed",
428 G_CALLBACK (gtk_entry_completion_selection_changed),
430 priv->first_sel_changed = TRUE;
432 priv->column = gtk_tree_view_column_new ();
433 gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), priv->column);
435 priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
436 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
438 GTK_POLICY_AUTOMATIC);
439 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window),
442 /* a nasty hack to get the completions treeview to size nicely */
443 gtk_widget_set_size_request (GTK_SCROLLED_WINDOW (priv->scrolled_window)->vscrollbar, -1, 0);
446 priv->actions = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
449 gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->actions));
450 g_signal_connect (priv->action_view, "button_press_event",
451 G_CALLBACK (gtk_entry_completion_action_button_press),
453 g_signal_connect (priv->action_view, "enter_notify_event",
454 G_CALLBACK (gtk_entry_completion_list_enter_notify),
456 g_signal_connect (priv->action_view, "motion_notify_event",
457 G_CALLBACK (gtk_entry_completion_list_motion_notify),
459 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->action_view), FALSE);
460 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->action_view), TRUE);
462 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->action_view));
463 gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE);
464 gtk_tree_selection_unselect_all (sel);
466 cell = gtk_cell_renderer_text_new ();
467 gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (priv->action_view),
470 gtk_entry_completion_action_data_func,
475 priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
476 gtk_window_set_resizable (GTK_WINDOW (priv->popup_window), FALSE);
477 g_signal_connect (priv->popup_window, "key_press_event",
478 G_CALLBACK (gtk_entry_completion_popup_key_press),
480 g_signal_connect (priv->popup_window, "button_press_event",
481 G_CALLBACK (gtk_entry_completion_popup_button_press),
484 popup_frame = gtk_frame_new (NULL);
485 gtk_frame_set_shadow_type (GTK_FRAME (popup_frame),
486 GTK_SHADOW_ETCHED_IN);
487 gtk_widget_show (popup_frame);
488 gtk_container_add (GTK_CONTAINER (priv->popup_window), popup_frame);
490 priv->vbox = gtk_vbox_new (FALSE, 0);
491 gtk_container_add (GTK_CONTAINER (popup_frame), priv->vbox);
493 gtk_container_add (GTK_CONTAINER (priv->scrolled_window), priv->tree_view);
494 gtk_box_pack_start (GTK_BOX (priv->vbox), priv->scrolled_window,
497 /* we don't want to see the action treeview when no actions have
498 * been inserted, so we pack the action treeview after the first
499 * action has been added
504 gtk_entry_completion_set_property (GObject *object,
509 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
510 GtkEntryCompletionPrivate *priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (completion);
515 gtk_entry_completion_set_model (completion,
516 g_value_get_object (value));
519 case PROP_MINIMUM_KEY_LENGTH:
520 gtk_entry_completion_set_minimum_key_length (completion,
521 g_value_get_int (value));
524 case PROP_TEXT_COLUMN:
525 priv->text_column = g_value_get_int (value);
528 case PROP_INLINE_COMPLETION:
529 priv->inline_completion = g_value_get_boolean (value);
532 case PROP_POPUP_COMPLETION:
533 priv->popup_completion = g_value_get_boolean (value);
536 case PROP_POPUP_SET_WIDTH:
537 priv->popup_set_width = g_value_get_boolean (value);
540 case PROP_POPUP_SINGLE_MATCH:
541 priv->popup_single_match = g_value_get_boolean (value);
545 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
551 gtk_entry_completion_get_property (GObject *object,
556 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
561 g_value_set_object (value,
562 gtk_entry_completion_get_model (completion));
565 case PROP_MINIMUM_KEY_LENGTH:
566 g_value_set_int (value, gtk_entry_completion_get_minimum_key_length (completion));
569 case PROP_TEXT_COLUMN:
570 g_value_set_int (value, gtk_entry_completion_get_text_column (completion));
573 case PROP_INLINE_COMPLETION:
574 g_value_set_boolean (value, gtk_entry_completion_get_inline_completion (completion));
577 case PROP_POPUP_COMPLETION:
578 g_value_set_boolean (value, gtk_entry_completion_get_popup_completion (completion));
581 case PROP_POPUP_SET_WIDTH:
582 g_value_set_boolean (value, gtk_entry_completion_get_popup_set_width (completion));
585 case PROP_POPUP_SINGLE_MATCH:
586 g_value_set_boolean (value, gtk_entry_completion_get_popup_single_match (completion));
590 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
596 gtk_entry_completion_finalize (GObject *object)
598 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
600 if (completion->priv->tree_view)
601 gtk_widget_destroy (completion->priv->tree_view);
603 if (completion->priv->entry)
604 gtk_entry_set_completion (GTK_ENTRY (completion->priv->entry), NULL);
606 if (completion->priv->actions)
607 g_object_unref (completion->priv->actions);
609 if (completion->priv->case_normalized_key)
610 g_free (completion->priv->case_normalized_key);
612 if (completion->priv->popup_window)
613 gtk_widget_destroy (completion->priv->popup_window);
615 G_OBJECT_CLASS (parent_class)->finalize (object);
618 /* implement cell layout interface */
620 gtk_entry_completion_pack_start (GtkCellLayout *cell_layout,
621 GtkCellRenderer *cell,
624 GtkEntryCompletionPrivate *priv;
626 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
628 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
630 gtk_tree_view_column_pack_start (priv->column, cell, expand);
634 gtk_entry_completion_pack_end (GtkCellLayout *cell_layout,
635 GtkCellRenderer *cell,
638 GtkEntryCompletionPrivate *priv;
640 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
642 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
644 gtk_tree_view_column_pack_end (priv->column, cell, expand);
648 gtk_entry_completion_clear (GtkCellLayout *cell_layout)
650 GtkEntryCompletionPrivate *priv;
652 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
654 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
656 gtk_tree_view_column_clear (priv->column);
660 gtk_entry_completion_add_attribute (GtkCellLayout *cell_layout,
661 GtkCellRenderer *cell,
662 const gchar *attribute,
665 GtkEntryCompletionPrivate *priv;
667 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
669 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
671 gtk_tree_view_column_add_attribute (priv->column, cell, attribute, column);
675 gtk_entry_completion_set_cell_data_func (GtkCellLayout *cell_layout,
676 GtkCellRenderer *cell,
677 GtkCellLayoutDataFunc func,
679 GDestroyNotify destroy)
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_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->column),
688 cell, func, func_data, destroy);
692 gtk_entry_completion_clear_attributes (GtkCellLayout *cell_layout,
693 GtkCellRenderer *cell)
695 GtkEntryCompletionPrivate *priv;
697 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
699 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
701 gtk_tree_view_column_clear_attributes (priv->column, cell);
705 gtk_entry_completion_reorder (GtkCellLayout *cell_layout,
706 GtkCellRenderer *cell,
709 GtkEntryCompletionPrivate *priv;
711 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
713 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
715 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->column), cell, position);
718 /* all those callbacks */
720 gtk_entry_completion_default_completion_func (GtkEntryCompletion *completion,
726 gchar *normalized_string;
727 gchar *case_normalized_string;
729 gboolean ret = FALSE;
733 model = gtk_tree_model_filter_get_model (completion->priv->filter_model);
735 g_return_val_if_fail (gtk_tree_model_get_column_type (model, completion->priv->text_column) == G_TYPE_STRING,
738 gtk_tree_model_get (model, iter,
739 completion->priv->text_column, &item,
744 normalized_string = g_utf8_normalize (item, -1, G_NORMALIZE_ALL);
745 case_normalized_string = g_utf8_casefold (normalized_string, -1);
747 if (!strncmp (key, case_normalized_string, strlen (key)))
751 g_free (normalized_string);
752 g_free (case_normalized_string);
759 gtk_entry_completion_visible_func (GtkTreeModel *model,
763 gboolean ret = FALSE;
765 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
767 if (!completion->priv->case_normalized_key)
770 if (completion->priv->match_func)
771 ret = (* completion->priv->match_func) (completion,
772 completion->priv->case_normalized_key,
774 completion->priv->match_data);
775 else if (completion->priv->text_column >= 0)
776 ret = gtk_entry_completion_default_completion_func (completion,
777 completion->priv->case_normalized_key,
785 gtk_entry_completion_popup_key_press (GtkWidget *widget,
789 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
791 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
794 /* propagate event to the entry */
795 gtk_widget_event (completion->priv->entry, (GdkEvent *)event);
801 gtk_entry_completion_popup_button_press (GtkWidget *widget,
802 GdkEventButton *event,
805 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
807 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
810 /* if we come here, it's usually time to popdown */
811 _gtk_entry_completion_popdown (completion);
817 gtk_entry_completion_list_button_press (GtkWidget *widget,
818 GdkEventButton *event,
821 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
822 GtkTreePath *path = NULL;
824 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
827 if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
829 &path, NULL, NULL, NULL))
834 gtk_tree_model_get_iter (GTK_TREE_MODEL (completion->priv->filter_model),
836 gtk_tree_path_free (path);
838 g_signal_handler_block (completion->priv->entry,
839 completion->priv->changed_id);
840 g_signal_emit (completion, entry_completion_signals[MATCH_SELECTED],
841 0, GTK_TREE_MODEL (completion->priv->filter_model),
843 g_signal_handler_unblock (completion->priv->entry,
844 completion->priv->changed_id);
846 _gtk_entry_completion_popdown (completion);
855 gtk_entry_completion_action_button_press (GtkWidget *widget,
856 GdkEventButton *event,
859 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
860 GtkTreePath *path = NULL;
862 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
865 if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
867 &path, NULL, NULL, NULL))
869 g_signal_emit (completion, entry_completion_signals[ACTION_ACTIVATED],
870 0, gtk_tree_path_get_indices (path)[0]);
871 gtk_tree_path_free (path);
873 _gtk_entry_completion_popdown (completion);
881 gtk_entry_completion_action_data_func (GtkTreeViewColumn *tree_column,
882 GtkCellRenderer *cell,
887 gchar *string = NULL;
890 gtk_tree_model_get (model, iter,
913 gtk_entry_completion_selection_changed (GtkTreeSelection *selection,
916 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
918 if (completion->priv->first_sel_changed)
920 completion->priv->first_sel_changed = FALSE;
921 if (gtk_widget_is_focus (completion->priv->tree_view))
922 gtk_tree_selection_unselect_all (selection);
929 * gtk_entry_completion_new:
931 * Creates a new #GtkEntryCompletion object.
933 * Return value: A newly created #GtkEntryCompletion object.
938 gtk_entry_completion_new (void)
940 GtkEntryCompletion *completion;
942 completion = g_object_new (GTK_TYPE_ENTRY_COMPLETION, NULL);
948 * gtk_entry_completion_get_entry:
949 * @completion: A #GtkEntryCompletion.
951 * Gets the entry @completion has been attached to.
953 * Return value: The entry @completion has been attached to.
958 gtk_entry_completion_get_entry (GtkEntryCompletion *completion)
960 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
962 return completion->priv->entry;
966 * gtk_entry_completion_set_model:
967 * @completion: A #GtkEntryCompletion.
968 * @model: The #GtkTreeModel.
970 * Sets the model for a #GtkEntryCompletion. If @completion already has
971 * a model set, it will remove it before setting the new model.
972 * If model is %NULL, then it will unset the model.
977 gtk_entry_completion_set_model (GtkEntryCompletion *completion,
980 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
981 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
985 gtk_tree_view_set_model (GTK_TREE_VIEW (completion->priv->tree_view),
987 _gtk_entry_completion_popdown (completion);
988 completion->priv->filter_model = NULL;
992 /* code will unref the old filter model (if any) */
993 completion->priv->filter_model =
994 GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (model, NULL));
995 gtk_tree_model_filter_set_visible_func (completion->priv->filter_model,
996 gtk_entry_completion_visible_func,
1000 gtk_tree_view_set_model (GTK_TREE_VIEW (completion->priv->tree_view),
1001 GTK_TREE_MODEL (completion->priv->filter_model));
1002 g_object_unref (completion->priv->filter_model);
1004 g_object_notify (G_OBJECT (completion), "model");
1006 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
1007 _gtk_entry_completion_resize_popup (completion);
1011 * gtk_entry_completion_get_model:
1012 * @completion: A #GtkEntryCompletion.
1014 * Returns the model the #GtkEntryCompletion is using as data source.
1015 * Returns %NULL if the model is unset.
1017 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
1022 gtk_entry_completion_get_model (GtkEntryCompletion *completion)
1024 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
1026 if (!completion->priv->filter_model)
1029 return gtk_tree_model_filter_get_model (completion->priv->filter_model);
1033 * gtk_entry_completion_set_match_func:
1034 * @completion: A #GtkEntryCompletion.
1035 * @func: The #GtkEntryCompletionMatchFunc to use.
1036 * @func_data: The user data for @func.
1037 * @func_notify: Destroy notifier for @func_data.
1039 * Sets the match function for @completion to be @func. The match function
1040 * is used to determine if a row should or should not be in the completion
1046 gtk_entry_completion_set_match_func (GtkEntryCompletion *completion,
1047 GtkEntryCompletionMatchFunc func,
1049 GDestroyNotify func_notify)
1051 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1053 if (completion->priv->match_notify)
1054 (* completion->priv->match_notify) (completion->priv->match_data);
1056 completion->priv->match_func = func;
1057 completion->priv->match_data = func_data;
1058 completion->priv->match_notify = func_notify;
1062 * gtk_entry_completion_set_minimum_key_length:
1063 * @completion: A #GtkEntryCompletion.
1064 * @length: The minimum length of the key in order to start completing.
1066 * Requires the length of the search key for @completion to be at least
1067 * @length. This is useful for long lists, where completing using a small
1068 * key takes a lot of time and will come up with meaningless results anyway
1069 * (ie, a too large dataset).
1074 gtk_entry_completion_set_minimum_key_length (GtkEntryCompletion *completion,
1077 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1078 g_return_if_fail (length >= 0);
1080 if (completion->priv->minimum_key_length != length)
1082 completion->priv->minimum_key_length = length;
1084 g_object_notify (G_OBJECT (completion), "minimum-key-length");
1089 * gtk_entry_completion_get_minimum_key_length:
1090 * @completion: A #GtkEntryCompletion.
1092 * Returns the minimum key length as set for @completion.
1094 * Return value: The currently used minimum key length.
1099 gtk_entry_completion_get_minimum_key_length (GtkEntryCompletion *completion)
1101 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), 0);
1103 return completion->priv->minimum_key_length;
1107 * gtk_entry_completion_complete:
1108 * @completion: A #GtkEntryCompletion.
1110 * Requests a completion operation, or in other words a refiltering of the
1111 * current list with completions, using the current key. The completion list
1112 * view will be updated accordingly.
1117 gtk_entry_completion_complete (GtkEntryCompletion *completion)
1121 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1123 if (!completion->priv->filter_model)
1126 if (completion->priv->case_normalized_key)
1127 g_free (completion->priv->case_normalized_key);
1129 tmp = g_utf8_normalize (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)),
1130 -1, G_NORMALIZE_ALL);
1131 completion->priv->case_normalized_key = g_utf8_casefold (tmp, -1);
1134 gtk_tree_model_filter_refilter (completion->priv->filter_model);
1136 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
1137 _gtk_entry_completion_resize_popup (completion);
1141 gtk_entry_completion_insert_action (GtkEntryCompletion *completion,
1143 const gchar *string,
1148 gtk_list_store_insert (completion->priv->actions, &iter, index);
1149 gtk_list_store_set (completion->priv->actions, &iter,
1154 if (!completion->priv->action_view->parent)
1156 GtkTreePath *path = gtk_tree_path_new_from_indices (0, -1);
1158 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
1160 gtk_tree_path_free (path);
1162 gtk_box_pack_start (GTK_BOX (completion->priv->vbox),
1163 completion->priv->action_view, FALSE, FALSE, 0);
1164 gtk_widget_show (completion->priv->action_view);
1169 * gtk_entry_completion_insert_action_text:
1170 * @completion: A #GtkEntryCompletion.
1171 * @index_: The index of the item to insert.
1172 * @text: Text of the item to insert.
1174 * Inserts an action in @completion's action item list at position @index_
1175 * with text @text. If you want the action item to have markup, use
1176 * gtk_entry_completion_insert_action_markup().
1181 gtk_entry_completion_insert_action_text (GtkEntryCompletion *completion,
1185 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1186 g_return_if_fail (text != NULL);
1188 gtk_entry_completion_insert_action (completion, index_, text, FALSE);
1192 * gtk_entry_completion_insert_action_markup:
1193 * @completion: A #GtkEntryCompletion.
1194 * @index_: The index of the item to insert.
1195 * @markup: Markup of the item to insert.
1197 * Inserts an action in @completion's action item list at position @index_
1198 * with markup @markup.
1203 gtk_entry_completion_insert_action_markup (GtkEntryCompletion *completion,
1205 const gchar *markup)
1207 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1208 g_return_if_fail (markup != NULL);
1210 gtk_entry_completion_insert_action (completion, index_, markup, TRUE);
1214 * gtk_entry_completion_delete_action:
1215 * @completion: A #GtkEntryCompletion.
1216 * @index_: The index of the item to Delete.
1218 * Deletes the action at @index_ from @completion's action list.
1223 gtk_entry_completion_delete_action (GtkEntryCompletion *completion,
1228 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1229 g_return_if_fail (index_ >= 0);
1231 gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (completion->priv->actions),
1232 &iter, NULL, index_);
1233 gtk_list_store_remove (completion->priv->actions, &iter);
1237 * gtk_entry_completion_set_text_column:
1238 * @completion: A #GtkEntryCompletion.
1239 * @column: The column in the model of @completion to get strings from.
1241 * Convenience function for setting up the most used case of this code: a
1242 * completion list with just strings. This function will set up @completion
1243 * to have a list displaying all (and just) strings in the completion list,
1244 * and to get those strings from @column in the model of @completion.
1246 * This functions creates and adds a #GtkCellRendererText for the selected
1247 * column. If you need to set the text column, but don't want the cell
1248 * renderer, use g_object_set() to set the ::text_column property directly.
1253 gtk_entry_completion_set_text_column (GtkEntryCompletion *completion,
1256 GtkCellRenderer *cell;
1258 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1259 g_return_if_fail (column >= 0);
1261 completion->priv->text_column = column;
1263 cell = gtk_cell_renderer_text_new ();
1264 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion),
1266 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (completion),
1270 g_object_notify (G_OBJECT (completion), "text-column");
1274 * gtk_entry_completion_get_text_column:
1275 * @completion: a #GtkEntryCompletion
1277 * Returns the column in the model of @completion to get strings from.
1279 * Return value: the column containing the strings
1284 gtk_entry_completion_get_text_column (GtkEntryCompletion *completion)
1286 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), -1);
1288 return completion->priv->text_column;
1294 gtk_entry_completion_list_enter_notify (GtkWidget *widget,
1295 GdkEventCrossing *event,
1298 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
1300 return completion->priv->ignore_enter;
1304 gtk_entry_completion_list_motion_notify (GtkWidget *widget,
1305 GdkEventMotion *event,
1308 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
1310 completion->priv->ignore_enter = FALSE;
1316 /* some nasty size requisition */
1318 _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
1321 gint matches, items, height, x_border, y_border;
1324 gint vertical_separator;
1325 GdkRectangle monitor;
1326 GtkRequisition popup_req;
1327 GtkRequisition entry_req;
1332 if (!completion->priv->entry->window)
1335 gdk_window_get_origin (completion->priv->entry->window, &x, &y);
1336 _gtk_entry_get_borders (GTK_ENTRY (completion->priv->entry), &x_border, &y_border);
1338 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
1340 items = MIN (matches, 15);
1342 gtk_tree_view_column_cell_get_size (completion->priv->column, NULL,
1343 NULL, NULL, NULL, &height);
1345 gtk_widget_style_get (GTK_WIDGET (completion->priv->tree_view),
1346 "vertical-separator", &vertical_separator,
1349 height += vertical_separator;
1352 gtk_widget_hide (completion->priv->scrolled_window);
1354 gtk_widget_show (completion->priv->scrolled_window);
1356 screen = gtk_widget_get_screen (GTK_WIDGET (completion->priv->entry));
1357 monitor_num = gdk_screen_get_monitor_at_window (screen,
1358 GTK_WIDGET (completion->priv->entry)->window);
1359 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1361 if (completion->priv->popup_set_width)
1362 width = MIN (completion->priv->entry->allocation.width, monitor.width) - 2 * x_border;
1366 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (completion->priv->tree_view));
1367 gtk_widget_set_size_request (completion->priv->tree_view, width, items * height);
1369 /* default on no match */
1370 completion->priv->current_selected = -1;
1372 items = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
1376 gtk_widget_show (completion->priv->action_view);
1377 gtk_widget_set_size_request (completion->priv->action_view, width, -1);
1380 gtk_widget_hide (completion->priv->action_view);
1382 gtk_widget_size_request (completion->priv->popup_window, &popup_req);
1383 gtk_widget_size_request (completion->priv->entry, &entry_req);
1387 else if (x + popup_req.width > monitor.x + monitor.width)
1388 x = monitor.x + monitor.width - popup_req.width;
1390 if (y + entry_req.height + popup_req.height <= monitor.y + monitor.height ||
1391 y - monitor.y < (monitor.y + monitor.height) - (y + entry_req.height))
1393 y += entry_req.height;
1398 y -= popup_req.height;
1404 path = gtk_tree_path_new_from_indices (above ? matches - 1 : 0, -1);
1405 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (completion->priv->tree_view), path,
1406 NULL, FALSE, 0.0, 0.0);
1407 gtk_tree_path_free (path);
1410 gtk_window_move (GTK_WINDOW (completion->priv->popup_window), x, y);
1416 _gtk_entry_completion_popup (GtkEntryCompletion *completion)
1418 GtkTreeViewColumn *column;
1420 GtkWidget *toplevel;
1422 if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
1425 if (!GTK_WIDGET_MAPPED (completion->priv->entry))
1428 if (!GTK_WIDGET_HAS_FOCUS (completion->priv->entry))
1431 completion->priv->ignore_enter = TRUE;
1433 column = gtk_tree_view_get_column (GTK_TREE_VIEW (completion->priv->action_view), 0);
1434 renderers = gtk_tree_view_column_get_cell_renderers (column);
1435 gtk_widget_ensure_style (completion->priv->tree_view);
1436 g_object_set (GTK_CELL_RENDERER (renderers->data), "cell-background-gdk",
1437 &completion->priv->tree_view->style->bg[GTK_STATE_NORMAL],
1439 g_list_free (renderers);
1441 gtk_widget_show_all (completion->priv->vbox);
1443 _gtk_entry_completion_resize_popup (completion);
1445 toplevel = gtk_widget_get_toplevel (completion->priv->entry);
1446 if (GTK_IS_WINDOW (toplevel))
1447 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1448 GTK_WINDOW (completion->priv->popup_window));
1450 /* prevent the first row being focused */
1451 gtk_widget_grab_focus (completion->priv->tree_view);
1453 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
1454 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
1457 gtk_widget_show (completion->priv->popup_window);
1459 gtk_grab_add (completion->priv->popup_window);
1460 gdk_pointer_grab (completion->priv->popup_window->window, TRUE,
1461 GDK_BUTTON_PRESS_MASK |
1462 GDK_BUTTON_RELEASE_MASK |
1463 GDK_POINTER_MOTION_MASK,
1464 NULL, NULL, GDK_CURRENT_TIME);
1468 _gtk_entry_completion_popdown (GtkEntryCompletion *completion)
1470 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
1473 completion->priv->ignore_enter = FALSE;
1475 gdk_pointer_ungrab (GDK_CURRENT_TIME);
1476 gtk_grab_remove (completion->priv->popup_window);
1478 gtk_widget_hide (completion->priv->popup_window);
1482 gtk_entry_completion_match_selected (GtkEntryCompletion *completion,
1483 GtkTreeModel *model,
1488 gtk_tree_model_get (model, iter, completion->priv->text_column, &str, -1);
1489 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), str);
1491 /* move cursor to the end */
1492 gtk_editable_set_position (GTK_EDITABLE (completion->priv->entry), -1);
1501 gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion)
1504 gchar *prefix = NULL;
1508 if (completion->priv->text_column < 0)
1511 key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry));
1513 valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (completion->priv->filter_model),
1520 gtk_tree_model_get (GTK_TREE_MODEL (completion->priv->filter_model),
1521 &iter, completion->priv->text_column, &text,
1524 if (g_str_has_prefix (text, key))
1527 prefix = g_strdup (text);
1531 const gchar *q = text;
1533 while (*p && *p == *q)
1544 valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (completion->priv->filter_model),
1553 gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion,
1554 const gchar *prefix)
1562 prefix_len = g_utf8_strlen (prefix, -1);
1564 key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry));
1565 key_len = g_utf8_strlen (key, -1);
1567 if (prefix_len > key_len)
1569 gint pos = prefix_len;
1571 gtk_editable_insert_text (GTK_EDITABLE (completion->priv->entry),
1572 prefix + strlen (key), -1, &pos);
1573 gtk_editable_select_region (GTK_EDITABLE (completion->priv->entry),
1574 key_len, prefix_len);
1576 completion->priv->has_completion = TRUE;
1584 * gtk_entry_completion_insert_prefix:
1585 * @completion: a #GtkEntryCompletion
1587 * Requests a prefix insertion.
1592 gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion)
1597 g_signal_handler_block (completion->priv->entry,
1598 completion->priv->insert_text_id);
1599 prefix = gtk_entry_completion_compute_prefix (completion);
1602 g_signal_emit (completion, entry_completion_signals[INSERT_PREFIX],
1606 g_signal_handler_unblock (completion->priv->entry,
1607 completion->priv->insert_text_id);
1611 * gtk_entry_completion_set_inline_completion:
1612 * @completion: a #GtkEntryCompletion
1613 * @inline_completion: %TRUE to do inline completion
1615 * Sets whether the common prefix of the possible completions should
1616 * be automatically inserted in the entry.
1621 gtk_entry_completion_set_inline_completion (GtkEntryCompletion *completion,
1622 gboolean inline_completion)
1624 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1626 inline_completion = inline_completion != FALSE;
1628 if (completion->priv->inline_completion != inline_completion)
1630 completion->priv->inline_completion = inline_completion;
1632 g_object_notify (G_OBJECT (completion), "inline-completion");
1638 * gtk_entry_completion_get_inline_completion:
1639 * @completion: a #GtkEntryCompletion
1641 * Returns whether the common prefix of the possible completions should
1642 * be automatically inserted in the entry.
1644 * Return value: %TRUE if inline completion is turned on
1649 gtk_entry_completion_get_inline_completion (GtkEntryCompletion *completion)
1651 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), FALSE);
1653 return completion->priv->inline_completion;
1657 * gtk_entry_completion_set_popup_completion:
1658 * @completion: a #GtkEntryCompletion
1659 * @popup_completion: %TRUE to do popup completion
1661 * Sets whether the completions should be presented in a popup window.
1666 gtk_entry_completion_set_popup_completion (GtkEntryCompletion *completion,
1667 gboolean popup_completion)
1669 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1671 popup_completion = popup_completion != FALSE;
1673 if (completion->priv->popup_completion != popup_completion)
1675 completion->priv->popup_completion = popup_completion;
1677 g_object_notify (G_OBJECT (completion), "popup-completion");
1683 * gtk_entry_completion_get_popup_completion:
1684 * @completion: a #GtkEntryCompletion
1686 * Returns whether the completions should be presented in a popup window.
1688 * Return value: %TRUE if popup completion is turned on
1693 gtk_entry_completion_get_popup_completion (GtkEntryCompletion *completion)
1695 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1697 return completion->priv->popup_completion;
1701 * gtk_entry_completion_set_popup_set_width:
1702 * @completion: a #GtkEntryCompletion
1703 * @popup_set_width: %TRUE to make the width of the popup the same as the entry
1705 * Sets whether the completion popup window will be resized to be the same
1706 * width as the entry.
1711 gtk_entry_completion_set_popup_set_width (GtkEntryCompletion *completion,
1712 gboolean popup_set_width)
1714 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1716 popup_set_width = popup_set_width != FALSE;
1718 if (completion->priv->popup_set_width != popup_set_width)
1720 completion->priv->popup_set_width = popup_set_width;
1722 g_object_notify (G_OBJECT (completion), "popup-set-width");
1727 * gtk_entry_completion_get_popup_set_width:
1728 * @completion: a #GtkEntryCompletion
1730 * Returns whether the completion popup window will be resized to the
1731 * width of the entry.
1733 * Return value: %TRUE if the popup window will be resized to the width of
1739 gtk_entry_completion_get_popup_set_width (GtkEntryCompletion *completion)
1741 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1743 return completion->priv->popup_set_width;
1748 * gtk_entry_completion_set_popup_single_match:
1749 * @completion: a #GtkEntryCompletion
1750 * @popup_single_match: %TRUE if the popup should appear even for a single
1753 * Sets whether the completion popup window will appear even if there is
1754 * only a single match. You may want to set this to %FALSE if you
1755 * are using <link linkend="GtkEntryCompletion--inline-completion">inline
1756 * completion</link>.
1761 gtk_entry_completion_set_popup_single_match (GtkEntryCompletion *completion,
1762 gboolean popup_single_match)
1764 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1766 popup_single_match = popup_single_match != FALSE;
1768 if (completion->priv->popup_single_match != popup_single_match)
1770 completion->priv->popup_single_match = popup_single_match;
1772 g_object_notify (G_OBJECT (completion), "popup-single-match");
1777 * gtk_entry_completion_get_popup_single_match:
1778 * @completion: a #GtkEntryCompletion
1780 * Returns whether the completion popup window will appear even if there is
1781 * only a single match.
1783 * Return value: %TRUE if the popup window will appear regardless of the
1784 * number of matches.
1789 gtk_entry_completion_get_popup_single_match (GtkEntryCompletion *completion)
1791 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1793 return completion->priv->popup_single_match;
1797 #define __GTK_ENTRY_COMPLETION_C__
1798 #include "gtkaliasdef.c"