1 /* gtkentrycompletion.c
2 * Copyright (C) 2003 Kristian Rietveld <kris@gtk.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 #include "gtkentrycompletion.h"
22 #include "gtkentryprivate.h"
23 #include "gtkcelllayout.h"
26 #include "gtkcellrenderertext.h"
28 #include "gtktreeselection.h"
29 #include "gtktreeview.h"
30 #include "gtkscrolledwindow.h"
32 #include "gtkwindow.h"
35 #include "gtksignal.h"
36 #include "gtkmarshalers.h"
38 #include "gtkprivate.h"
59 PROP_MINIMUM_KEY_LENGTH,
61 PROP_INLINE_COMPLETION,
62 PROP_POPUP_COMPLETION,
64 PROP_POPUP_SINGLE_MATCH,
68 #define GTK_ENTRY_COMPLETION_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY_COMPLETION, GtkEntryCompletionPrivate))
70 static void gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface);
71 static void gtk_entry_completion_set_property (GObject *object,
75 static void gtk_entry_completion_get_property (GObject *object,
79 static void gtk_entry_completion_finalize (GObject *object);
81 static void gtk_entry_completion_pack_start (GtkCellLayout *cell_layout,
82 GtkCellRenderer *cell,
84 static void gtk_entry_completion_pack_end (GtkCellLayout *cell_layout,
85 GtkCellRenderer *cell,
87 static void gtk_entry_completion_clear (GtkCellLayout *cell_layout);
88 static void gtk_entry_completion_add_attribute (GtkCellLayout *cell_layout,
89 GtkCellRenderer *cell,
90 const char *attribute,
92 static void gtk_entry_completion_set_cell_data_func (GtkCellLayout *cell_layout,
93 GtkCellRenderer *cell,
94 GtkCellLayoutDataFunc func,
96 GDestroyNotify destroy);
97 static void gtk_entry_completion_clear_attributes (GtkCellLayout *cell_layout,
98 GtkCellRenderer *cell);
99 static void gtk_entry_completion_reorder (GtkCellLayout *cell_layout,
100 GtkCellRenderer *cell,
103 static gboolean gtk_entry_completion_visible_func (GtkTreeModel *model,
106 static gboolean gtk_entry_completion_popup_key_event (GtkWidget *widget,
109 static gboolean gtk_entry_completion_popup_button_press (GtkWidget *widget,
110 GdkEventButton *event,
112 static gboolean gtk_entry_completion_list_button_press (GtkWidget *widget,
113 GdkEventButton *event,
115 static gboolean gtk_entry_completion_action_button_press (GtkWidget *widget,
116 GdkEventButton *event,
118 static void gtk_entry_completion_selection_changed (GtkTreeSelection *selection,
120 static gboolean gtk_entry_completion_list_enter_notify (GtkWidget *widget,
121 GdkEventCrossing *event,
123 static gboolean gtk_entry_completion_list_motion_notify (GtkWidget *widget,
124 GdkEventMotion *event,
126 static void gtk_entry_completion_insert_action (GtkEntryCompletion *completion,
130 static void gtk_entry_completion_action_data_func (GtkTreeViewColumn *tree_column,
131 GtkCellRenderer *cell,
136 static gboolean gtk_entry_completion_match_selected (GtkEntryCompletion *completion,
139 static gboolean gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion,
140 const gchar *prefix);
141 static gboolean gtk_entry_completion_cursor_on_match (GtkEntryCompletion *completion,
144 static gboolean gtk_entry_completion_insert_completion (GtkEntryCompletion *completion,
147 static void gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
150 static guint entry_completion_signals[LAST_SIGNAL] = { 0 };
153 static void gtk_entry_completion_buildable_init (GtkBuildableIface *iface);
155 G_DEFINE_TYPE_WITH_CODE (GtkEntryCompletion, gtk_entry_completion, G_TYPE_OBJECT,
156 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
157 gtk_entry_completion_cell_layout_init)
158 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
159 gtk_entry_completion_buildable_init))
163 gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
165 GObjectClass *object_class;
167 object_class = (GObjectClass *)klass;
169 object_class->set_property = gtk_entry_completion_set_property;
170 object_class->get_property = gtk_entry_completion_get_property;
171 object_class->finalize = gtk_entry_completion_finalize;
173 klass->match_selected = gtk_entry_completion_match_selected;
174 klass->insert_prefix = gtk_entry_completion_real_insert_prefix;
175 klass->cursor_on_match = gtk_entry_completion_cursor_on_match;
178 * GtkEntryCompletion::insert-prefix:
179 * @widget: the object which received the signal
180 * @prefix: the common prefix of all possible completions
182 * Gets emitted when the inline autocompletion is triggered.
183 * The default behaviour is to make the entry display the
184 * whole prefix and select the newly inserted part.
186 * Applications may connect to this signal in order to insert only a
187 * smaller part of the @prefix into the entry - e.g. the entry used in
188 * the #GtkFileChooser inserts only the part of the prefix up to the
191 * Return value: %TRUE if the signal has been handled
195 entry_completion_signals[INSERT_PREFIX] =
196 g_signal_new (I_("insert_prefix"),
197 G_TYPE_FROM_CLASS (klass),
199 G_STRUCT_OFFSET (GtkEntryCompletionClass, insert_prefix),
200 _gtk_boolean_handled_accumulator, NULL,
201 _gtk_marshal_BOOLEAN__STRING,
206 * GtkEntryCompletion::match-selected:
207 * @widget: the object which received the signal
208 * @model: the #GtkTreeModel containing the matches
209 * @iter: a #GtkTreeIter positioned at the selected match
211 * Gets emitted when a match from the list is selected.
212 * The default behaviour is to replace the contents of the
213 * entry with the contents of the text column in the row
214 * pointed to by @iter.
216 * Return value: %TRUE if the signal has been handled
220 entry_completion_signals[MATCH_SELECTED] =
221 g_signal_new (I_("match_selected"),
222 G_TYPE_FROM_CLASS (klass),
224 G_STRUCT_OFFSET (GtkEntryCompletionClass, match_selected),
225 _gtk_boolean_handled_accumulator, NULL,
226 _gtk_marshal_BOOLEAN__OBJECT_BOXED,
231 * GtkEntryCompletion::cursor-on-match:
232 * @widget: the object which received the signal
233 * @model: the #GtkTreeModel containing the matches
234 * @iter: a #GtkTreeIter positioned at the selected match
236 * Gets emitted when a match from the cursor is on a match
237 * of the list.The default behaviour is to replace the contents
238 * of the entry with the contents of the text column in the row
239 * pointed to by @iter.
241 * Return value: %TRUE if the signal has been handled
246 entry_completion_signals[CURSOR_ON_MATCH] =
247 g_signal_new (I_("cursor_on_match"),
248 G_TYPE_FROM_CLASS (klass),
250 G_STRUCT_OFFSET (GtkEntryCompletionClass, cursor_on_match),
251 _gtk_boolean_handled_accumulator, NULL,
252 _gtk_marshal_BOOLEAN__OBJECT_BOXED,
258 * GtkEntryCompletion::action-activated:
259 * @widget: the object which received the signal
260 * @index: the index of the activated action
262 * Gets emitted when an action is activated.
266 entry_completion_signals[ACTION_ACTIVATED] =
267 g_signal_new (I_("action_activated"),
268 G_TYPE_FROM_CLASS (klass),
270 G_STRUCT_OFFSET (GtkEntryCompletionClass, action_activated),
272 _gtk_marshal_NONE__INT,
276 g_object_class_install_property (object_class,
278 g_param_spec_object ("model",
279 P_("Completion Model"),
280 P_("The model to find matches in"),
282 GTK_PARAM_READWRITE));
283 g_object_class_install_property (object_class,
284 PROP_MINIMUM_KEY_LENGTH,
285 g_param_spec_int ("minimum-key-length",
286 P_("Minimum Key Length"),
287 P_("Minimum length of the search key in order to look up matches"),
291 GTK_PARAM_READWRITE));
293 * GtkEntryCompletion:text-column:
295 * The column of the model containing the strings.
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 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
674 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
676 gtk_tree_view_column_pack_start (priv->column, cell, expand);
680 gtk_entry_completion_pack_end (GtkCellLayout *cell_layout,
681 GtkCellRenderer *cell,
684 GtkEntryCompletionPrivate *priv;
686 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
688 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
690 gtk_tree_view_column_pack_end (priv->column, cell, expand);
694 gtk_entry_completion_clear (GtkCellLayout *cell_layout)
696 GtkEntryCompletionPrivate *priv;
698 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
700 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
702 gtk_tree_view_column_clear (priv->column);
706 gtk_entry_completion_add_attribute (GtkCellLayout *cell_layout,
707 GtkCellRenderer *cell,
708 const gchar *attribute,
711 GtkEntryCompletionPrivate *priv;
713 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
715 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
717 gtk_tree_view_column_add_attribute (priv->column, cell, attribute, column);
721 gtk_entry_completion_set_cell_data_func (GtkCellLayout *cell_layout,
722 GtkCellRenderer *cell,
723 GtkCellLayoutDataFunc func,
725 GDestroyNotify destroy)
727 GtkEntryCompletionPrivate *priv;
729 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
731 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
733 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->column),
734 cell, func, func_data, destroy);
738 gtk_entry_completion_clear_attributes (GtkCellLayout *cell_layout,
739 GtkCellRenderer *cell)
741 GtkEntryCompletionPrivate *priv;
743 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
745 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
747 gtk_tree_view_column_clear_attributes (priv->column, cell);
751 gtk_entry_completion_reorder (GtkCellLayout *cell_layout,
752 GtkCellRenderer *cell,
755 GtkEntryCompletionPrivate *priv;
757 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
759 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
761 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->column), cell, position);
764 /* all those callbacks */
766 gtk_entry_completion_default_completion_func (GtkEntryCompletion *completion,
772 gchar *normalized_string;
773 gchar *case_normalized_string;
775 gboolean ret = FALSE;
779 model = gtk_tree_model_filter_get_model (completion->priv->filter_model);
781 g_return_val_if_fail (gtk_tree_model_get_column_type (model, completion->priv->text_column) == G_TYPE_STRING,
784 gtk_tree_model_get (model, iter,
785 completion->priv->text_column, &item,
790 normalized_string = g_utf8_normalize (item, -1, G_NORMALIZE_ALL);
791 case_normalized_string = g_utf8_casefold (normalized_string, -1);
793 if (!strncmp (key, case_normalized_string, strlen (key)))
797 g_free (normalized_string);
798 g_free (case_normalized_string);
805 gtk_entry_completion_visible_func (GtkTreeModel *model,
809 gboolean ret = FALSE;
811 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
813 if (!completion->priv->case_normalized_key)
816 if (completion->priv->match_func)
817 ret = (* completion->priv->match_func) (completion,
818 completion->priv->case_normalized_key,
820 completion->priv->match_data);
821 else if (completion->priv->text_column >= 0)
822 ret = gtk_entry_completion_default_completion_func (completion,
823 completion->priv->case_normalized_key,
831 gtk_entry_completion_popup_key_event (GtkWidget *widget,
835 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
837 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
840 /* propagate event to the entry */
841 gtk_widget_event (completion->priv->entry, (GdkEvent *)event);
847 gtk_entry_completion_popup_button_press (GtkWidget *widget,
848 GdkEventButton *event,
851 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
853 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
856 /* if we come here, it's usually time to popdown */
857 _gtk_entry_completion_popdown (completion);
863 gtk_entry_completion_list_button_press (GtkWidget *widget,
864 GdkEventButton *event,
867 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
868 GtkTreePath *path = NULL;
870 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
873 if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
875 &path, NULL, NULL, NULL))
880 gtk_tree_model_get_iter (GTK_TREE_MODEL (completion->priv->filter_model),
882 gtk_tree_path_free (path);
884 g_signal_handler_block (completion->priv->entry,
885 completion->priv->changed_id);
886 g_signal_emit (completion, entry_completion_signals[MATCH_SELECTED],
887 0, GTK_TREE_MODEL (completion->priv->filter_model),
889 g_signal_handler_unblock (completion->priv->entry,
890 completion->priv->changed_id);
892 _gtk_entry_completion_popdown (completion);
901 gtk_entry_completion_action_button_press (GtkWidget *widget,
902 GdkEventButton *event,
905 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
906 GtkTreePath *path = NULL;
908 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
911 _gtk_entry_reset_im_context (GTK_ENTRY (completion->priv->entry));
913 if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
915 &path, NULL, NULL, NULL))
917 g_signal_emit (completion, entry_completion_signals[ACTION_ACTIVATED],
918 0, gtk_tree_path_get_indices (path)[0]);
919 gtk_tree_path_free (path);
921 _gtk_entry_completion_popdown (completion);
929 gtk_entry_completion_action_data_func (GtkTreeViewColumn *tree_column,
930 GtkCellRenderer *cell,
935 gchar *string = NULL;
938 gtk_tree_model_get (model, iter,
961 gtk_entry_completion_selection_changed (GtkTreeSelection *selection,
964 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
966 if (completion->priv->first_sel_changed)
968 completion->priv->first_sel_changed = FALSE;
969 if (gtk_widget_is_focus (completion->priv->tree_view))
970 gtk_tree_selection_unselect_all (selection);
977 * gtk_entry_completion_new:
979 * Creates a new #GtkEntryCompletion object.
981 * Return value: A newly created #GtkEntryCompletion object.
986 gtk_entry_completion_new (void)
988 GtkEntryCompletion *completion;
990 completion = g_object_new (GTK_TYPE_ENTRY_COMPLETION, NULL);
996 * gtk_entry_completion_get_entry:
997 * @completion: A #GtkEntryCompletion.
999 * Gets the entry @completion has been attached to.
1001 * Return value: The entry @completion has been attached to.
1006 gtk_entry_completion_get_entry (GtkEntryCompletion *completion)
1008 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
1010 return completion->priv->entry;
1014 * gtk_entry_completion_set_model:
1015 * @completion: A #GtkEntryCompletion.
1016 * @model: The #GtkTreeModel.
1018 * Sets the model for a #GtkEntryCompletion. If @completion already has
1019 * a model set, it will remove it before setting the new model.
1020 * If model is %NULL, then it will unset the model.
1025 gtk_entry_completion_set_model (GtkEntryCompletion *completion,
1026 GtkTreeModel *model)
1028 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1029 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
1033 gtk_tree_view_set_model (GTK_TREE_VIEW (completion->priv->tree_view),
1035 _gtk_entry_completion_popdown (completion);
1036 completion->priv->filter_model = NULL;
1040 /* code will unref the old filter model (if any) */
1041 completion->priv->filter_model =
1042 GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (model, NULL));
1043 gtk_tree_model_filter_set_visible_func (completion->priv->filter_model,
1044 gtk_entry_completion_visible_func,
1048 gtk_tree_view_set_model (GTK_TREE_VIEW (completion->priv->tree_view),
1049 GTK_TREE_MODEL (completion->priv->filter_model));
1050 g_object_unref (completion->priv->filter_model);
1052 g_object_notify (G_OBJECT (completion), "model");
1054 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
1055 _gtk_entry_completion_resize_popup (completion);
1059 * gtk_entry_completion_get_model:
1060 * @completion: A #GtkEntryCompletion.
1062 * Returns the model the #GtkEntryCompletion is using as data source.
1063 * Returns %NULL if the model is unset.
1065 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
1070 gtk_entry_completion_get_model (GtkEntryCompletion *completion)
1072 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
1074 if (!completion->priv->filter_model)
1077 return gtk_tree_model_filter_get_model (completion->priv->filter_model);
1081 * gtk_entry_completion_set_match_func:
1082 * @completion: A #GtkEntryCompletion.
1083 * @func: The #GtkEntryCompletionMatchFunc to use.
1084 * @func_data: The user data for @func.
1085 * @func_notify: Destroy notifier for @func_data.
1087 * Sets the match function for @completion to be @func. The match function
1088 * is used to determine if a row should or should not be in the completion
1094 gtk_entry_completion_set_match_func (GtkEntryCompletion *completion,
1095 GtkEntryCompletionMatchFunc func,
1097 GDestroyNotify func_notify)
1099 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1101 if (completion->priv->match_notify)
1102 (* completion->priv->match_notify) (completion->priv->match_data);
1104 completion->priv->match_func = func;
1105 completion->priv->match_data = func_data;
1106 completion->priv->match_notify = func_notify;
1110 * gtk_entry_completion_set_minimum_key_length:
1111 * @completion: A #GtkEntryCompletion.
1112 * @length: The minimum length of the key in order to start completing.
1114 * Requires the length of the search key for @completion to be at least
1115 * @length. This is useful for long lists, where completing using a small
1116 * key takes a lot of time and will come up with meaningless results anyway
1117 * (ie, a too large dataset).
1122 gtk_entry_completion_set_minimum_key_length (GtkEntryCompletion *completion,
1125 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1126 g_return_if_fail (length >= 0);
1128 if (completion->priv->minimum_key_length != length)
1130 completion->priv->minimum_key_length = length;
1132 g_object_notify (G_OBJECT (completion), "minimum-key-length");
1137 * gtk_entry_completion_get_minimum_key_length:
1138 * @completion: A #GtkEntryCompletion.
1140 * Returns the minimum key length as set for @completion.
1142 * Return value: The currently used minimum key length.
1147 gtk_entry_completion_get_minimum_key_length (GtkEntryCompletion *completion)
1149 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), 0);
1151 return completion->priv->minimum_key_length;
1155 * gtk_entry_completion_complete:
1156 * @completion: A #GtkEntryCompletion.
1158 * Requests a completion operation, or in other words a refiltering of the
1159 * current list with completions, using the current key. The completion list
1160 * view will be updated accordingly.
1165 gtk_entry_completion_complete (GtkEntryCompletion *completion)
1169 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1171 if (!completion->priv->filter_model)
1174 g_free (completion->priv->case_normalized_key);
1176 tmp = g_utf8_normalize (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)),
1177 -1, G_NORMALIZE_ALL);
1178 completion->priv->case_normalized_key = g_utf8_casefold (tmp, -1);
1181 gtk_tree_model_filter_refilter (completion->priv->filter_model);
1183 if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
1184 _gtk_entry_completion_resize_popup (completion);
1188 gtk_entry_completion_insert_action (GtkEntryCompletion *completion,
1190 const gchar *string,
1195 gtk_list_store_insert (completion->priv->actions, &iter, index);
1196 gtk_list_store_set (completion->priv->actions, &iter,
1201 if (!completion->priv->action_view->parent)
1203 GtkTreePath *path = gtk_tree_path_new_from_indices (0, -1);
1205 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
1207 gtk_tree_path_free (path);
1209 gtk_box_pack_start (GTK_BOX (completion->priv->vbox),
1210 completion->priv->action_view, FALSE, FALSE, 0);
1211 gtk_widget_show (completion->priv->action_view);
1216 * gtk_entry_completion_insert_action_text:
1217 * @completion: A #GtkEntryCompletion.
1218 * @index_: The index of the item to insert.
1219 * @text: Text of the item to insert.
1221 * Inserts an action in @completion's action item list at position @index_
1222 * with text @text. If you want the action item to have markup, use
1223 * gtk_entry_completion_insert_action_markup().
1228 gtk_entry_completion_insert_action_text (GtkEntryCompletion *completion,
1232 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1233 g_return_if_fail (text != NULL);
1235 gtk_entry_completion_insert_action (completion, index_, text, FALSE);
1239 * gtk_entry_completion_insert_action_markup:
1240 * @completion: A #GtkEntryCompletion.
1241 * @index_: The index of the item to insert.
1242 * @markup: Markup of the item to insert.
1244 * Inserts an action in @completion's action item list at position @index_
1245 * with markup @markup.
1250 gtk_entry_completion_insert_action_markup (GtkEntryCompletion *completion,
1252 const gchar *markup)
1254 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1255 g_return_if_fail (markup != NULL);
1257 gtk_entry_completion_insert_action (completion, index_, markup, TRUE);
1261 * gtk_entry_completion_delete_action:
1262 * @completion: A #GtkEntryCompletion.
1263 * @index_: The index of the item to Delete.
1265 * Deletes the action at @index_ from @completion's action list.
1270 gtk_entry_completion_delete_action (GtkEntryCompletion *completion,
1275 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1276 g_return_if_fail (index_ >= 0);
1278 gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (completion->priv->actions),
1279 &iter, NULL, index_);
1280 gtk_list_store_remove (completion->priv->actions, &iter);
1284 * gtk_entry_completion_set_text_column:
1285 * @completion: A #GtkEntryCompletion.
1286 * @column: The column in the model of @completion to get strings from.
1288 * Convenience function for setting up the most used case of this code: a
1289 * completion list with just strings. This function will set up @completion
1290 * to have a list displaying all (and just) strings in the completion list,
1291 * and to get those strings from @column in the model of @completion.
1293 * This functions creates and adds a #GtkCellRendererText for the selected
1294 * column. If you need to set the text column, but don't want the cell
1295 * renderer, use g_object_set() to set the ::text_column property directly.
1300 gtk_entry_completion_set_text_column (GtkEntryCompletion *completion,
1303 GtkCellRenderer *cell;
1305 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1306 g_return_if_fail (column >= 0);
1308 completion->priv->text_column = column;
1310 cell = gtk_cell_renderer_text_new ();
1311 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion),
1313 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (completion),
1317 g_object_notify (G_OBJECT (completion), "text-column");
1321 * gtk_entry_completion_get_text_column:
1322 * @completion: a #GtkEntryCompletion
1324 * Returns the column in the model of @completion to get strings from.
1326 * Return value: the column containing the strings
1331 gtk_entry_completion_get_text_column (GtkEntryCompletion *completion)
1333 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), -1);
1335 return completion->priv->text_column;
1341 gtk_entry_completion_list_enter_notify (GtkWidget *widget,
1342 GdkEventCrossing *event,
1345 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
1347 return completion->priv->ignore_enter;
1351 gtk_entry_completion_list_motion_notify (GtkWidget *widget,
1352 GdkEventMotion *event,
1355 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
1357 completion->priv->ignore_enter = FALSE;
1363 /* some nasty size requisition */
1365 _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
1368 gint matches, items, height, x_border, y_border;
1371 gint vertical_separator;
1372 GdkRectangle monitor;
1373 GtkRequisition popup_req;
1374 GtkRequisition entry_req;
1379 if (!completion->priv->entry->window)
1382 gdk_window_get_origin (completion->priv->entry->window, &x, &y);
1383 _gtk_entry_get_borders (GTK_ENTRY (completion->priv->entry), &x_border, &y_border);
1385 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
1387 items = MIN (matches, 15);
1389 gtk_tree_view_column_cell_get_size (completion->priv->column, NULL,
1390 NULL, NULL, NULL, &height);
1392 gtk_widget_style_get (GTK_WIDGET (completion->priv->tree_view),
1393 "vertical-separator", &vertical_separator,
1396 height += vertical_separator;
1398 gtk_widget_realize (completion->priv->tree_view);
1401 gtk_widget_hide (completion->priv->scrolled_window);
1403 gtk_widget_show (completion->priv->scrolled_window);
1405 screen = gtk_widget_get_screen (GTK_WIDGET (completion->priv->entry));
1406 monitor_num = gdk_screen_get_monitor_at_window (screen,
1407 GTK_WIDGET (completion->priv->entry)->window);
1408 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1410 if (completion->priv->popup_set_width)
1411 width = MIN (completion->priv->entry->allocation.width, monitor.width) - 2 * x_border;
1415 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (completion->priv->tree_view));
1416 gtk_widget_set_size_request (completion->priv->tree_view, width, items * height);
1418 /* default on no match */
1419 completion->priv->current_selected = -1;
1421 items = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
1425 gtk_widget_show (completion->priv->action_view);
1426 gtk_widget_set_size_request (completion->priv->action_view, width, -1);
1429 gtk_widget_hide (completion->priv->action_view);
1431 gtk_widget_size_request (completion->priv->popup_window, &popup_req);
1432 gtk_widget_size_request (completion->priv->entry, &entry_req);
1436 else if (x + popup_req.width > monitor.x + monitor.width)
1437 x = monitor.x + monitor.width - popup_req.width;
1439 if (y + entry_req.height + popup_req.height <= monitor.y + monitor.height ||
1440 y - monitor.y < (monitor.y + monitor.height) - (y + entry_req.height))
1442 y += entry_req.height;
1447 y -= popup_req.height;
1453 path = gtk_tree_path_new_from_indices (above ? matches - 1 : 0, -1);
1454 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (completion->priv->tree_view), path,
1455 NULL, FALSE, 0.0, 0.0);
1456 gtk_tree_path_free (path);
1459 gtk_window_move (GTK_WINDOW (completion->priv->popup_window), x, y);
1465 _gtk_entry_completion_popup (GtkEntryCompletion *completion)
1467 GtkTreeViewColumn *column;
1469 GtkWidget *toplevel;
1471 if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
1474 if (!GTK_WIDGET_MAPPED (completion->priv->entry))
1477 if (!GTK_WIDGET_HAS_FOCUS (completion->priv->entry))
1480 completion->priv->ignore_enter = TRUE;
1482 column = gtk_tree_view_get_column (GTK_TREE_VIEW (completion->priv->action_view), 0);
1483 renderers = gtk_tree_view_column_get_cell_renderers (column);
1484 gtk_widget_ensure_style (completion->priv->tree_view);
1485 g_object_set (GTK_CELL_RENDERER (renderers->data), "cell-background-gdk",
1486 &completion->priv->tree_view->style->bg[GTK_STATE_NORMAL],
1488 g_list_free (renderers);
1490 gtk_widget_show_all (completion->priv->vbox);
1492 _gtk_entry_completion_resize_popup (completion);
1494 toplevel = gtk_widget_get_toplevel (completion->priv->entry);
1495 if (GTK_IS_WINDOW (toplevel))
1496 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1497 GTK_WINDOW (completion->priv->popup_window));
1499 /* prevent the first row being focused */
1500 gtk_widget_grab_focus (completion->priv->tree_view);
1502 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
1503 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
1506 gtk_widget_show (completion->priv->popup_window);
1508 gtk_grab_add (completion->priv->popup_window);
1509 gdk_pointer_grab (completion->priv->popup_window->window, TRUE,
1510 GDK_BUTTON_PRESS_MASK |
1511 GDK_BUTTON_RELEASE_MASK |
1512 GDK_POINTER_MOTION_MASK,
1513 NULL, NULL, GDK_CURRENT_TIME);
1517 _gtk_entry_completion_popdown (GtkEntryCompletion *completion)
1519 if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
1522 completion->priv->ignore_enter = FALSE;
1524 gdk_pointer_ungrab (GDK_CURRENT_TIME);
1525 gtk_grab_remove (completion->priv->popup_window);
1527 gtk_widget_hide (completion->priv->popup_window);
1531 gtk_entry_completion_match_selected (GtkEntryCompletion *completion,
1532 GtkTreeModel *model,
1537 gtk_tree_model_get (model, iter, completion->priv->text_column, &str, -1);
1538 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), str ? str : "");
1540 /* move cursor to the end */
1541 gtk_editable_set_position (GTK_EDITABLE (completion->priv->entry), -1);
1549 gtk_entry_completion_cursor_on_match (GtkEntryCompletion *completion,
1550 GtkTreeModel *model,
1553 gtk_entry_completion_insert_completion (completion, model, iter);
1559 gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion)
1562 gchar *prefix = NULL;
1566 if (completion->priv->text_column < 0)
1569 key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry));
1571 valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (completion->priv->filter_model),
1578 gtk_tree_model_get (GTK_TREE_MODEL (completion->priv->filter_model),
1579 &iter, completion->priv->text_column, &text,
1582 if (text && g_str_has_prefix (text, key))
1585 prefix = g_strdup (text);
1591 while (*p && *p == *q)
1601 /* strip a partial multibyte character */
1602 q = g_utf8_find_prev_char (prefix, p);
1603 switch (g_utf8_get_char_validated (q, p - q))
1615 valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (completion->priv->filter_model),
1624 gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion,
1625 const gchar *prefix)
1633 prefix_len = g_utf8_strlen (prefix, -1);
1635 key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry));
1636 key_len = g_utf8_strlen (key, -1);
1638 if (completion->priv->completion_prefix == NULL)
1639 completion->priv->completion_prefix = g_strdup (key);
1641 if (prefix_len > key_len)
1643 gint pos = prefix_len;
1645 gtk_editable_insert_text (GTK_EDITABLE (completion->priv->entry),
1646 prefix + strlen (key), -1, &pos);
1647 gtk_editable_select_region (GTK_EDITABLE (completion->priv->entry),
1648 key_len, prefix_len);
1650 completion->priv->has_completion = TRUE;
1658 * gtk_entry_completion_get_completion_prefix:
1659 * @completion: a #GtkEntryCompletion
1661 * Get the original text entered by the user that triggered
1662 * the completion or %NULL if there's no completion ongoing.
1664 * Returns: the prefix for the current completion
1669 gtk_entry_completion_get_completion_prefix (GtkEntryCompletion *completion)
1671 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
1673 return completion->priv->completion_prefix;
1677 gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
1680 GtkEntryCompletionPrivate *priv = completion->priv;
1683 priv = completion->priv;
1685 if (priv->changed_id > 0)
1686 g_signal_handler_block (priv->entry, priv->changed_id);
1688 if (priv->insert_text_id > 0)
1689 g_signal_handler_block (priv->entry, priv->insert_text_id);
1691 if (completion->priv->completion_prefix == NULL)
1692 completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry)));
1694 gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
1696 len = strlen (priv->completion_prefix);
1697 gtk_editable_select_region (GTK_EDITABLE (priv->entry), len, -1);
1699 if (priv->changed_id > 0)
1700 g_signal_handler_unblock (priv->entry, priv->changed_id);
1702 if (priv->insert_text_id > 0)
1703 g_signal_handler_unblock (priv->entry, priv->insert_text_id);
1707 gtk_entry_completion_insert_completion (GtkEntryCompletion *completion,
1708 GtkTreeModel *model,
1713 if (completion->priv->text_column < 0)
1716 gtk_tree_model_get (model, iter,
1717 completion->priv->text_column, &str,
1720 gtk_entry_completion_insert_completion_text (completion, str);
1728 * gtk_entry_completion_insert_prefix:
1729 * @completion: a #GtkEntryCompletion
1731 * Requests a prefix insertion.
1737 gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion)
1742 if (completion->priv->insert_text_id > 0)
1743 g_signal_handler_block (completion->priv->entry,
1744 completion->priv->insert_text_id);
1746 prefix = gtk_entry_completion_compute_prefix (completion);
1749 g_signal_emit (completion, entry_completion_signals[INSERT_PREFIX],
1754 if (completion->priv->insert_text_id > 0)
1755 g_signal_handler_unblock (completion->priv->entry,
1756 completion->priv->insert_text_id);
1760 * gtk_entry_completion_set_inline_completion:
1761 * @completion: a #GtkEntryCompletion
1762 * @inline_completion: %TRUE to do inline completion
1764 * Sets whether the common prefix of the possible completions should
1765 * be automatically inserted in the entry.
1770 gtk_entry_completion_set_inline_completion (GtkEntryCompletion *completion,
1771 gboolean inline_completion)
1773 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1775 inline_completion = inline_completion != FALSE;
1777 if (completion->priv->inline_completion != inline_completion)
1779 completion->priv->inline_completion = inline_completion;
1781 g_object_notify (G_OBJECT (completion), "inline-completion");
1786 * gtk_entry_completion_get_inline_completion:
1787 * @completion: a #GtkEntryCompletion
1789 * Returns whether the common prefix of the possible completions should
1790 * be automatically inserted in the entry.
1792 * Return value: %TRUE if inline completion is turned on
1797 gtk_entry_completion_get_inline_completion (GtkEntryCompletion *completion)
1799 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), FALSE);
1801 return completion->priv->inline_completion;
1805 * gtk_entry_completion_set_popup_completion:
1806 * @completion: a #GtkEntryCompletion
1807 * @popup_completion: %TRUE to do popup completion
1809 * Sets whether the completions should be presented in a popup window.
1814 gtk_entry_completion_set_popup_completion (GtkEntryCompletion *completion,
1815 gboolean popup_completion)
1817 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1819 popup_completion = popup_completion != FALSE;
1821 if (completion->priv->popup_completion != popup_completion)
1823 completion->priv->popup_completion = popup_completion;
1825 g_object_notify (G_OBJECT (completion), "popup-completion");
1831 * gtk_entry_completion_get_popup_completion:
1832 * @completion: a #GtkEntryCompletion
1834 * Returns whether the completions should be presented in a popup window.
1836 * Return value: %TRUE if popup completion is turned on
1841 gtk_entry_completion_get_popup_completion (GtkEntryCompletion *completion)
1843 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1845 return completion->priv->popup_completion;
1849 * gtk_entry_completion_set_popup_set_width:
1850 * @completion: a #GtkEntryCompletion
1851 * @popup_set_width: %TRUE to make the width of the popup the same as the entry
1853 * Sets whether the completion popup window will be resized to be the same
1854 * width as the entry.
1859 gtk_entry_completion_set_popup_set_width (GtkEntryCompletion *completion,
1860 gboolean popup_set_width)
1862 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1864 popup_set_width = popup_set_width != FALSE;
1866 if (completion->priv->popup_set_width != popup_set_width)
1868 completion->priv->popup_set_width = popup_set_width;
1870 g_object_notify (G_OBJECT (completion), "popup-set-width");
1875 * gtk_entry_completion_get_popup_set_width:
1876 * @completion: a #GtkEntryCompletion
1878 * Returns whether the completion popup window will be resized to the
1879 * width of the entry.
1881 * Return value: %TRUE if the popup window will be resized to the width of
1887 gtk_entry_completion_get_popup_set_width (GtkEntryCompletion *completion)
1889 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1891 return completion->priv->popup_set_width;
1896 * gtk_entry_completion_set_popup_single_match:
1897 * @completion: a #GtkEntryCompletion
1898 * @popup_single_match: %TRUE if the popup should appear even for a single
1901 * Sets whether the completion popup window will appear even if there is
1902 * only a single match. You may want to set this to %FALSE if you
1903 * are using <link linkend="GtkEntryCompletion--inline-completion">inline
1904 * completion</link>.
1909 gtk_entry_completion_set_popup_single_match (GtkEntryCompletion *completion,
1910 gboolean popup_single_match)
1912 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1914 popup_single_match = popup_single_match != FALSE;
1916 if (completion->priv->popup_single_match != popup_single_match)
1918 completion->priv->popup_single_match = popup_single_match;
1920 g_object_notify (G_OBJECT (completion), "popup-single-match");
1925 * gtk_entry_completion_get_popup_single_match:
1926 * @completion: a #GtkEntryCompletion
1928 * Returns whether the completion popup window will appear even if there is
1929 * only a single match.
1931 * Return value: %TRUE if the popup window will appear regardless of the
1932 * number of matches.
1937 gtk_entry_completion_get_popup_single_match (GtkEntryCompletion *completion)
1939 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1941 return completion->priv->popup_single_match;
1945 * gtk_entry_completion_set_inline_selection:
1946 * @completion: a #GtkEntryCompletion
1947 * @inline_selection: %TRUE to do inline selection
1949 * Sets whether it is possible to cycle through the possible completions
1955 gtk_entry_completion_set_inline_selection (GtkEntryCompletion *completion,
1956 gboolean inline_selection)
1958 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1960 inline_selection = inline_selection != FALSE;
1962 if (completion->priv->inline_selection != inline_selection)
1964 completion->priv->inline_selection = inline_selection;
1966 g_object_notify (G_OBJECT (completion), "inline-selection");
1971 * gtk_entry_completion_get_inline_selection:
1972 * @completion: a #GtkEntryCompletion
1974 * Returns %TRUE if inline-selection mode is turned on.
1976 * Returns: %TRUE if inline-selection mode is on
1981 gtk_entry_completion_get_inline_selection (GtkEntryCompletion *completion)
1983 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), FALSE);
1985 return completion->priv->inline_selection;
1988 #define __GTK_ENTRY_COMPLETION_C__
1989 #include "gtkaliasdef.c"