1 /* gtkentrycompletion.c
2 * Copyright (C) 2003 Kristian Rietveld <kris@gtk.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 #include "gtkentrycompletion.h"
22 #include "gtkentryprivate.h"
23 #include "gtkcelllayout.h"
26 #include "gtkcellrenderertext.h"
28 #include "gtktreeselection.h"
29 #include "gtktreeview.h"
30 #include "gtkscrolledwindow.h"
32 #include "gtkwindow.h"
35 #include "gtkmarshalers.h"
37 #include "gtkprivate.h"
58 PROP_MINIMUM_KEY_LENGTH,
60 PROP_INLINE_COMPLETION,
61 PROP_POPUP_COMPLETION,
63 PROP_POPUP_SINGLE_MATCH,
67 #define GTK_ENTRY_COMPLETION_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY_COMPLETION, GtkEntryCompletionPrivate))
69 static void gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface);
70 static void gtk_entry_completion_set_property (GObject *object,
74 static void gtk_entry_completion_get_property (GObject *object,
78 static void gtk_entry_completion_finalize (GObject *object);
80 static void gtk_entry_completion_pack_start (GtkCellLayout *cell_layout,
81 GtkCellRenderer *cell,
83 static void gtk_entry_completion_pack_end (GtkCellLayout *cell_layout,
84 GtkCellRenderer *cell,
86 static void gtk_entry_completion_clear (GtkCellLayout *cell_layout);
87 static void gtk_entry_completion_add_attribute (GtkCellLayout *cell_layout,
88 GtkCellRenderer *cell,
89 const char *attribute,
91 static void gtk_entry_completion_set_cell_data_func (GtkCellLayout *cell_layout,
92 GtkCellRenderer *cell,
93 GtkCellLayoutDataFunc func,
95 GDestroyNotify destroy);
96 static void gtk_entry_completion_clear_attributes (GtkCellLayout *cell_layout,
97 GtkCellRenderer *cell);
98 static void gtk_entry_completion_reorder (GtkCellLayout *cell_layout,
99 GtkCellRenderer *cell,
101 static GList * gtk_entry_completion_get_cells (GtkCellLayout *cell_layout);
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,
232 * GtkEntryCompletion::cursor-on-match:
233 * @widget: the object which received the signal
234 * @model: the #GtkTreeModel containing the matches
235 * @iter: a #GtkTreeIter positioned at the selected match
237 * Gets emitted when a match from the cursor is on a match
238 * of the list. The default behaviour is to replace the contents
239 * of the entry with the contents of the text column in the row
240 * pointed to by @iter.
242 * 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_VOID__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.
296 * Note that the strings must be UTF-8.
300 g_object_class_install_property (object_class,
302 g_param_spec_int ("text-column",
304 P_("The column of the model containing the strings."),
308 GTK_PARAM_READWRITE));
311 * GtkEntryCompletion:inline-completion:
313 * Determines whether the common prefix of the possible completions
314 * should be inserted automatically in the entry. Note that this
315 * requires text-column to be set, even if you are using a custom
320 g_object_class_install_property (object_class,
321 PROP_INLINE_COMPLETION,
322 g_param_spec_boolean ("inline-completion",
323 P_("Inline completion"),
324 P_("Whether the common prefix should be inserted automatically"),
326 GTK_PARAM_READWRITE));
328 * GtkEntryCompletion:popup-completion:
330 * Determines whether the possible completions should be
331 * shown in a popup window.
335 g_object_class_install_property (object_class,
336 PROP_POPUP_COMPLETION,
337 g_param_spec_boolean ("popup-completion",
338 P_("Popup completion"),
339 P_("Whether the completions should be shown in a popup window"),
341 GTK_PARAM_READWRITE));
344 * GtkEntryCompletion:popup-set-width:
346 * Determines whether the completions popup window will be
347 * resized to the width of the entry.
351 g_object_class_install_property (object_class,
352 PROP_POPUP_SET_WIDTH,
353 g_param_spec_boolean ("popup-set-width",
354 P_("Popup set width"),
355 P_("If TRUE, the popup window will have the same size as the entry"),
357 GTK_PARAM_READWRITE));
360 * GtkEntryCompletion:popup-single-match:
362 * Determines whether the completions popup window will shown
363 * for a single possible completion. You probably want to set
364 * this to %FALSE if you are using
365 * <link linkend="GtkEntryCompletion--inline-completion">inline
370 g_object_class_install_property (object_class,
371 PROP_POPUP_SINGLE_MATCH,
372 g_param_spec_boolean ("popup-single-match",
373 P_("Popup single match"),
374 P_("If TRUE, the popup window will appear for a single match."),
376 GTK_PARAM_READWRITE));
378 * GtkEntryCompletion:inline-selection:
380 * Determines whether the possible completions on the popup
381 * will appear in the entry as you navigate through them.
385 g_object_class_install_property (object_class,
386 PROP_INLINE_SELECTION,
387 g_param_spec_boolean ("inline-selection",
388 P_("Inline selection"),
389 P_("Your description here"),
391 GTK_PARAM_READWRITE));
393 g_type_class_add_private (object_class, sizeof (GtkEntryCompletionPrivate));
397 gtk_entry_completion_buildable_init (GtkBuildableIface *iface)
399 iface->add_child = _gtk_cell_layout_buildable_add_child;
400 iface->custom_tag_start = _gtk_cell_layout_buildable_custom_tag_start;
401 iface->custom_tag_end = _gtk_cell_layout_buildable_custom_tag_end;
405 gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface)
407 iface->pack_start = gtk_entry_completion_pack_start;
408 iface->pack_end = gtk_entry_completion_pack_end;
409 iface->clear = gtk_entry_completion_clear;
410 iface->add_attribute = gtk_entry_completion_add_attribute;
411 iface->set_cell_data_func = gtk_entry_completion_set_cell_data_func;
412 iface->clear_attributes = gtk_entry_completion_clear_attributes;
413 iface->reorder = gtk_entry_completion_reorder;
414 iface->get_cells = gtk_entry_completion_get_cells;
418 gtk_entry_completion_init (GtkEntryCompletion *completion)
420 GtkCellRenderer *cell;
421 GtkTreeSelection *sel;
422 GtkEntryCompletionPrivate *priv;
423 GtkWidget *popup_frame;
425 /* yes, also priv, need to keep the code readable */
426 priv = completion->priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (completion);
428 priv->minimum_key_length = 1;
429 priv->text_column = -1;
430 priv->has_completion = FALSE;
431 priv->inline_completion = FALSE;
432 priv->popup_completion = TRUE;
433 priv->popup_set_width = TRUE;
434 priv->popup_single_match = TRUE;
435 priv->inline_selection = FALSE;
438 priv->filter_model = NULL;
440 priv->tree_view = gtk_tree_view_new ();
441 g_signal_connect (priv->tree_view, "button-press-event",
442 G_CALLBACK (gtk_entry_completion_list_button_press),
444 g_signal_connect (priv->tree_view, "enter-notify-event",
445 G_CALLBACK (gtk_entry_completion_list_enter_notify),
447 g_signal_connect (priv->tree_view, "motion-notify-event",
448 G_CALLBACK (gtk_entry_completion_list_motion_notify),
451 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
452 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->tree_view), TRUE);
454 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
455 gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE);
456 gtk_tree_selection_unselect_all (sel);
457 g_signal_connect (sel, "changed",
458 G_CALLBACK (gtk_entry_completion_selection_changed),
460 priv->first_sel_changed = TRUE;
462 priv->column = gtk_tree_view_column_new ();
463 gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), priv->column);
465 priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
466 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
468 GTK_POLICY_AUTOMATIC);
469 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window),
472 /* a nasty hack to get the completions treeview to size nicely */
473 gtk_widget_set_size_request (GTK_SCROLLED_WINDOW (priv->scrolled_window)->vscrollbar, -1, 0);
476 priv->actions = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
479 gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->actions));
480 g_object_ref_sink (priv->action_view);
481 g_signal_connect (priv->action_view, "button-press-event",
482 G_CALLBACK (gtk_entry_completion_action_button_press),
484 g_signal_connect (priv->action_view, "enter-notify-event",
485 G_CALLBACK (gtk_entry_completion_list_enter_notify),
487 g_signal_connect (priv->action_view, "motion-notify-event",
488 G_CALLBACK (gtk_entry_completion_list_motion_notify),
490 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->action_view), FALSE);
491 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->action_view), TRUE);
493 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->action_view));
494 gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE);
495 gtk_tree_selection_unselect_all (sel);
497 cell = gtk_cell_renderer_text_new ();
498 gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (priv->action_view),
501 gtk_entry_completion_action_data_func,
506 priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
507 gtk_window_set_resizable (GTK_WINDOW (priv->popup_window), FALSE);
508 gtk_window_set_type_hint (GTK_WINDOW(priv->popup_window),
509 GDK_WINDOW_TYPE_HINT_COMBO);
510 g_signal_connect (priv->popup_window, "key-press-event",
511 G_CALLBACK (gtk_entry_completion_popup_key_event),
513 g_signal_connect (priv->popup_window, "key-release-event",
514 G_CALLBACK (gtk_entry_completion_popup_key_event),
516 g_signal_connect (priv->popup_window, "button-press-event",
517 G_CALLBACK (gtk_entry_completion_popup_button_press),
520 popup_frame = gtk_frame_new (NULL);
521 gtk_frame_set_shadow_type (GTK_FRAME (popup_frame),
522 GTK_SHADOW_ETCHED_IN);
523 gtk_widget_show (popup_frame);
524 gtk_container_add (GTK_CONTAINER (priv->popup_window), popup_frame);
526 priv->vbox = gtk_vbox_new (FALSE, 0);
527 gtk_container_add (GTK_CONTAINER (popup_frame), priv->vbox);
529 gtk_container_add (GTK_CONTAINER (priv->scrolled_window), priv->tree_view);
530 gtk_box_pack_start (GTK_BOX (priv->vbox), priv->scrolled_window,
533 /* we don't want to see the action treeview when no actions have
534 * been inserted, so we pack the action treeview after the first
535 * action has been added
540 gtk_entry_completion_set_property (GObject *object,
545 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
546 GtkEntryCompletionPrivate *priv = completion->priv;
551 gtk_entry_completion_set_model (completion,
552 g_value_get_object (value));
555 case PROP_MINIMUM_KEY_LENGTH:
556 gtk_entry_completion_set_minimum_key_length (completion,
557 g_value_get_int (value));
560 case PROP_TEXT_COLUMN:
561 priv->text_column = g_value_get_int (value);
564 case PROP_INLINE_COMPLETION:
565 priv->inline_completion = g_value_get_boolean (value);
568 case PROP_POPUP_COMPLETION:
569 priv->popup_completion = g_value_get_boolean (value);
572 case PROP_POPUP_SET_WIDTH:
573 priv->popup_set_width = g_value_get_boolean (value);
576 case PROP_POPUP_SINGLE_MATCH:
577 priv->popup_single_match = g_value_get_boolean (value);
580 case PROP_INLINE_SELECTION:
581 priv->inline_selection = g_value_get_boolean (value);
585 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
591 gtk_entry_completion_get_property (GObject *object,
596 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
601 g_value_set_object (value,
602 gtk_entry_completion_get_model (completion));
605 case PROP_MINIMUM_KEY_LENGTH:
606 g_value_set_int (value, gtk_entry_completion_get_minimum_key_length (completion));
609 case PROP_TEXT_COLUMN:
610 g_value_set_int (value, gtk_entry_completion_get_text_column (completion));
613 case PROP_INLINE_COMPLETION:
614 g_value_set_boolean (value, gtk_entry_completion_get_inline_completion (completion));
617 case PROP_POPUP_COMPLETION:
618 g_value_set_boolean (value, gtk_entry_completion_get_popup_completion (completion));
621 case PROP_POPUP_SET_WIDTH:
622 g_value_set_boolean (value, gtk_entry_completion_get_popup_set_width (completion));
625 case PROP_POPUP_SINGLE_MATCH:
626 g_value_set_boolean (value, gtk_entry_completion_get_popup_single_match (completion));
629 case PROP_INLINE_SELECTION:
630 g_value_set_boolean (value, gtk_entry_completion_get_inline_selection (completion));
634 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
640 gtk_entry_completion_finalize (GObject *object)
642 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
643 GtkEntryCompletionPrivate *priv = completion->priv;
646 gtk_widget_destroy (priv->tree_view);
649 gtk_entry_set_completion (GTK_ENTRY (priv->entry), NULL);
652 g_object_unref (priv->actions);
653 if (priv->action_view)
654 g_object_unref (priv->action_view);
656 g_free (priv->case_normalized_key);
657 g_free (priv->completion_prefix);
659 if (priv->popup_window)
660 gtk_widget_destroy (priv->popup_window);
662 if (priv->match_notify)
663 (* priv->match_notify) (priv->match_data);
665 G_OBJECT_CLASS (gtk_entry_completion_parent_class)->finalize (object);
668 /* implement cell layout interface */
670 gtk_entry_completion_pack_start (GtkCellLayout *cell_layout,
671 GtkCellRenderer *cell,
674 GtkEntryCompletionPrivate *priv;
676 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
678 gtk_tree_view_column_pack_start (priv->column, cell, expand);
682 gtk_entry_completion_pack_end (GtkCellLayout *cell_layout,
683 GtkCellRenderer *cell,
686 GtkEntryCompletionPrivate *priv;
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 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
700 gtk_tree_view_column_clear (priv->column);
704 gtk_entry_completion_add_attribute (GtkCellLayout *cell_layout,
705 GtkCellRenderer *cell,
706 const gchar *attribute,
709 GtkEntryCompletionPrivate *priv;
711 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
713 gtk_tree_view_column_add_attribute (priv->column, cell, attribute, column);
717 gtk_entry_completion_set_cell_data_func (GtkCellLayout *cell_layout,
718 GtkCellRenderer *cell,
719 GtkCellLayoutDataFunc func,
721 GDestroyNotify destroy)
723 GtkEntryCompletionPrivate *priv;
725 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
727 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->column),
728 cell, func, func_data, destroy);
732 gtk_entry_completion_clear_attributes (GtkCellLayout *cell_layout,
733 GtkCellRenderer *cell)
735 GtkEntryCompletionPrivate *priv;
737 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
739 gtk_tree_view_column_clear_attributes (priv->column, cell);
743 gtk_entry_completion_reorder (GtkCellLayout *cell_layout,
744 GtkCellRenderer *cell,
747 GtkEntryCompletionPrivate *priv;
749 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
751 gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->column), cell, position);
755 gtk_entry_completion_get_cells (GtkCellLayout *cell_layout)
757 GtkEntryCompletionPrivate *priv;
759 priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
761 return gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (priv->column));
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_get_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_get_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_get_mapped (completion->priv->popup_window))
873 if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
875 &path, NULL, NULL, NULL))
880 GtkTreeIter child_iter;
882 gtk_tree_model_get_iter (GTK_TREE_MODEL (completion->priv->filter_model),
884 gtk_tree_path_free (path);
885 gtk_tree_model_filter_convert_iter_to_child_iter (completion->priv->filter_model,
888 model = gtk_tree_model_filter_get_model (completion->priv->filter_model);
890 g_signal_handler_block (completion->priv->entry,
891 completion->priv->changed_id);
892 g_signal_emit (completion, entry_completion_signals[MATCH_SELECTED],
893 0, model, &child_iter, &entry_set);
894 g_signal_handler_unblock (completion->priv->entry,
895 completion->priv->changed_id);
897 _gtk_entry_completion_popdown (completion);
906 gtk_entry_completion_action_button_press (GtkWidget *widget,
907 GdkEventButton *event,
910 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
911 GtkTreePath *path = NULL;
913 if (!gtk_widget_get_mapped (completion->priv->popup_window))
916 _gtk_entry_reset_im_context (GTK_ENTRY (completion->priv->entry));
918 if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
920 &path, NULL, NULL, NULL))
922 g_signal_emit (completion, entry_completion_signals[ACTION_ACTIVATED],
923 0, gtk_tree_path_get_indices (path, NULL)[0]);
924 gtk_tree_path_free (path);
926 _gtk_entry_completion_popdown (completion);
934 gtk_entry_completion_action_data_func (GtkTreeViewColumn *tree_column,
935 GtkCellRenderer *cell,
940 gchar *string = NULL;
943 gtk_tree_model_get (model, iter,
966 gtk_entry_completion_selection_changed (GtkTreeSelection *selection,
969 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
971 if (completion->priv->first_sel_changed)
973 completion->priv->first_sel_changed = FALSE;
974 if (gtk_widget_is_focus (completion->priv->tree_view))
975 gtk_tree_selection_unselect_all (selection);
982 * gtk_entry_completion_new:
984 * Creates a new #GtkEntryCompletion object.
986 * Return value: A newly created #GtkEntryCompletion object.
991 gtk_entry_completion_new (void)
993 GtkEntryCompletion *completion;
995 completion = g_object_new (GTK_TYPE_ENTRY_COMPLETION, NULL);
1001 * gtk_entry_completion_get_entry:
1002 * @completion: A #GtkEntryCompletion.
1004 * Gets the entry @completion has been attached to.
1006 * Return value: The entry @completion has been attached to.
1011 gtk_entry_completion_get_entry (GtkEntryCompletion *completion)
1013 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
1015 return completion->priv->entry;
1019 * gtk_entry_completion_set_model:
1020 * @completion: A #GtkEntryCompletion.
1021 * @model: (allow-none): The #GtkTreeModel.
1023 * Sets the model for a #GtkEntryCompletion. If @completion already has
1024 * a model set, it will remove it before setting the new model.
1025 * If model is %NULL, then it will unset the model.
1030 gtk_entry_completion_set_model (GtkEntryCompletion *completion,
1031 GtkTreeModel *model)
1033 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1034 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
1038 gtk_tree_view_set_model (GTK_TREE_VIEW (completion->priv->tree_view),
1040 _gtk_entry_completion_popdown (completion);
1041 completion->priv->filter_model = NULL;
1045 /* code will unref the old filter model (if any) */
1046 completion->priv->filter_model =
1047 GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (model, NULL));
1048 gtk_tree_model_filter_set_visible_func (completion->priv->filter_model,
1049 gtk_entry_completion_visible_func,
1053 gtk_tree_view_set_model (GTK_TREE_VIEW (completion->priv->tree_view),
1054 GTK_TREE_MODEL (completion->priv->filter_model));
1055 g_object_unref (completion->priv->filter_model);
1057 g_object_notify (G_OBJECT (completion), "model");
1059 if (gtk_widget_get_visible (completion->priv->popup_window))
1060 _gtk_entry_completion_resize_popup (completion);
1064 * gtk_entry_completion_get_model:
1065 * @completion: A #GtkEntryCompletion.
1067 * Returns the model the #GtkEntryCompletion is using as data source.
1068 * Returns %NULL if the model is unset.
1070 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
1075 gtk_entry_completion_get_model (GtkEntryCompletion *completion)
1077 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
1079 if (!completion->priv->filter_model)
1082 return gtk_tree_model_filter_get_model (completion->priv->filter_model);
1086 * gtk_entry_completion_set_match_func:
1087 * @completion: A #GtkEntryCompletion.
1088 * @func: The #GtkEntryCompletionMatchFunc to use.
1089 * @func_data: The user data for @func.
1090 * @func_notify: Destroy notifier for @func_data.
1092 * Sets the match function for @completion to be @func. The match function
1093 * is used to determine if a row should or should not be in the completion
1099 gtk_entry_completion_set_match_func (GtkEntryCompletion *completion,
1100 GtkEntryCompletionMatchFunc func,
1102 GDestroyNotify func_notify)
1104 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1106 if (completion->priv->match_notify)
1107 (* completion->priv->match_notify) (completion->priv->match_data);
1109 completion->priv->match_func = func;
1110 completion->priv->match_data = func_data;
1111 completion->priv->match_notify = func_notify;
1115 * gtk_entry_completion_set_minimum_key_length:
1116 * @completion: A #GtkEntryCompletion.
1117 * @length: The minimum length of the key in order to start completing.
1119 * Requires the length of the search key for @completion to be at least
1120 * @length. This is useful for long lists, where completing using a small
1121 * key takes a lot of time and will come up with meaningless results anyway
1122 * (ie, a too large dataset).
1127 gtk_entry_completion_set_minimum_key_length (GtkEntryCompletion *completion,
1130 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1131 g_return_if_fail (length >= 0);
1133 if (completion->priv->minimum_key_length != length)
1135 completion->priv->minimum_key_length = length;
1137 g_object_notify (G_OBJECT (completion), "minimum-key-length");
1142 * gtk_entry_completion_get_minimum_key_length:
1143 * @completion: A #GtkEntryCompletion.
1145 * Returns the minimum key length as set for @completion.
1147 * Return value: The currently used minimum key length.
1152 gtk_entry_completion_get_minimum_key_length (GtkEntryCompletion *completion)
1154 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), 0);
1156 return completion->priv->minimum_key_length;
1160 * gtk_entry_completion_complete:
1161 * @completion: A #GtkEntryCompletion.
1163 * Requests a completion operation, or in other words a refiltering of the
1164 * current list with completions, using the current key. The completion list
1165 * view will be updated accordingly.
1170 gtk_entry_completion_complete (GtkEntryCompletion *completion)
1174 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1176 if (!completion->priv->filter_model)
1179 g_free (completion->priv->case_normalized_key);
1181 tmp = g_utf8_normalize (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)),
1182 -1, G_NORMALIZE_ALL);
1183 completion->priv->case_normalized_key = g_utf8_casefold (tmp, -1);
1186 gtk_tree_model_filter_refilter (completion->priv->filter_model);
1188 if (gtk_widget_get_visible (completion->priv->popup_window))
1189 _gtk_entry_completion_resize_popup (completion);
1193 gtk_entry_completion_insert_action (GtkEntryCompletion *completion,
1195 const gchar *string,
1200 gtk_list_store_insert (completion->priv->actions, &iter, index);
1201 gtk_list_store_set (completion->priv->actions, &iter,
1206 if (!completion->priv->action_view->parent)
1208 GtkTreePath *path = gtk_tree_path_new_from_indices (0, -1);
1210 gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
1212 gtk_tree_path_free (path);
1214 gtk_box_pack_start (GTK_BOX (completion->priv->vbox),
1215 completion->priv->action_view, FALSE, FALSE, 0);
1216 gtk_widget_show (completion->priv->action_view);
1221 * gtk_entry_completion_insert_action_text:
1222 * @completion: A #GtkEntryCompletion.
1223 * @index_: The index of the item to insert.
1224 * @text: Text of the item to insert.
1226 * Inserts an action in @completion's action item list at position @index_
1227 * with text @text. If you want the action item to have markup, use
1228 * gtk_entry_completion_insert_action_markup().
1233 gtk_entry_completion_insert_action_text (GtkEntryCompletion *completion,
1237 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1238 g_return_if_fail (text != NULL);
1240 gtk_entry_completion_insert_action (completion, index_, text, FALSE);
1244 * gtk_entry_completion_insert_action_markup:
1245 * @completion: A #GtkEntryCompletion.
1246 * @index_: The index of the item to insert.
1247 * @markup: Markup of the item to insert.
1249 * Inserts an action in @completion's action item list at position @index_
1250 * with markup @markup.
1255 gtk_entry_completion_insert_action_markup (GtkEntryCompletion *completion,
1257 const gchar *markup)
1259 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1260 g_return_if_fail (markup != NULL);
1262 gtk_entry_completion_insert_action (completion, index_, markup, TRUE);
1266 * gtk_entry_completion_delete_action:
1267 * @completion: A #GtkEntryCompletion.
1268 * @index_: The index of the item to Delete.
1270 * Deletes the action at @index_ from @completion's action list.
1275 gtk_entry_completion_delete_action (GtkEntryCompletion *completion,
1280 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1281 g_return_if_fail (index_ >= 0);
1283 gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (completion->priv->actions),
1284 &iter, NULL, index_);
1285 gtk_list_store_remove (completion->priv->actions, &iter);
1289 * gtk_entry_completion_set_text_column:
1290 * @completion: A #GtkEntryCompletion.
1291 * @column: The column in the model of @completion to get strings from.
1293 * Convenience function for setting up the most used case of this code: a
1294 * completion list with just strings. This function will set up @completion
1295 * to have a list displaying all (and just) strings in the completion list,
1296 * and to get those strings from @column in the model of @completion.
1298 * This functions creates and adds a #GtkCellRendererText for the selected
1299 * column. If you need to set the text column, but don't want the cell
1300 * renderer, use g_object_set() to set the ::text_column property directly.
1305 gtk_entry_completion_set_text_column (GtkEntryCompletion *completion,
1308 GtkCellRenderer *cell;
1310 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1311 g_return_if_fail (column >= 0);
1313 completion->priv->text_column = column;
1315 cell = gtk_cell_renderer_text_new ();
1316 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion),
1318 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (completion),
1322 g_object_notify (G_OBJECT (completion), "text-column");
1326 * gtk_entry_completion_get_text_column:
1327 * @completion: a #GtkEntryCompletion
1329 * Returns the column in the model of @completion to get strings from.
1331 * Return value: the column containing the strings
1336 gtk_entry_completion_get_text_column (GtkEntryCompletion *completion)
1338 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), -1);
1340 return completion->priv->text_column;
1346 gtk_entry_completion_list_enter_notify (GtkWidget *widget,
1347 GdkEventCrossing *event,
1350 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
1352 return completion->priv->ignore_enter;
1356 gtk_entry_completion_list_motion_notify (GtkWidget *widget,
1357 GdkEventMotion *event,
1360 GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
1362 completion->priv->ignore_enter = FALSE;
1368 /* some nasty size requisition */
1370 _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
1373 gint matches, actions, items, height, x_border, y_border;
1376 gint vertical_separator;
1377 GdkRectangle monitor;
1378 GtkRequisition popup_req;
1379 GtkRequisition entry_req;
1383 GtkTreeViewColumn *action_column;
1386 if (!completion->priv->entry->window)
1389 gdk_window_get_origin (completion->priv->entry->window, &x, &y);
1390 _gtk_entry_get_borders (GTK_ENTRY (completion->priv->entry), &x_border, &y_border);
1392 matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
1393 actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
1394 action_column = gtk_tree_view_get_column (GTK_TREE_VIEW (completion->priv->action_view), 0);
1396 gtk_tree_view_column_cell_get_size (completion->priv->column, NULL,
1397 NULL, NULL, NULL, &height);
1398 gtk_tree_view_column_cell_get_size (action_column, NULL,
1399 NULL, NULL, NULL, &action_height);
1401 gtk_widget_style_get (GTK_WIDGET (completion->priv->tree_view),
1402 "vertical-separator", &vertical_separator,
1405 height += vertical_separator;
1407 gtk_widget_realize (completion->priv->tree_view);
1409 screen = gtk_widget_get_screen (GTK_WIDGET (completion->priv->entry));
1410 monitor_num = gdk_screen_get_monitor_at_window (screen,
1411 GTK_WIDGET (completion->priv->entry)->window);
1412 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1416 if (y > monitor.height / 2)
1417 items = MIN (matches, (((monitor.y + y) - (actions * action_height)) / height) - 1);
1419 items = MIN (matches, (((monitor.height - y) - (actions * action_height)) / height) - 1);
1422 gtk_widget_hide (completion->priv->scrolled_window);
1424 gtk_widget_show (completion->priv->scrolled_window);
1426 if (completion->priv->popup_set_width)
1427 width = MIN (completion->priv->entry->allocation.width, monitor.width) - 2 * x_border;
1431 gtk_tree_view_columns_autosize (GTK_TREE_VIEW (completion->priv->tree_view));
1432 gtk_widget_set_size_request (completion->priv->tree_view, width, items * height);
1436 gtk_widget_show (completion->priv->action_view);
1437 gtk_widget_set_size_request (completion->priv->action_view, width, -1);
1440 gtk_widget_hide (completion->priv->action_view);
1442 gtk_widget_size_request (completion->priv->popup_window, &popup_req);
1443 gtk_widget_size_request (completion->priv->entry, &entry_req);
1447 else if (x + popup_req.width > monitor.x + monitor.width)
1448 x = monitor.x + monitor.width - popup_req.width;
1450 if (y + entry_req.height + popup_req.height <= monitor.y + monitor.height ||
1451 y - monitor.y < (monitor.y + monitor.height) - (y + entry_req.height))
1453 y += entry_req.height;
1458 y -= popup_req.height;
1464 path = gtk_tree_path_new_from_indices (above ? matches - 1 : 0, -1);
1465 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (completion->priv->tree_view), path,
1466 NULL, FALSE, 0.0, 0.0);
1467 gtk_tree_path_free (path);
1470 gtk_window_move (GTK_WINDOW (completion->priv->popup_window), x, y);
1476 _gtk_entry_completion_popup (GtkEntryCompletion *completion,
1479 GtkTreeViewColumn *column;
1481 GtkWidget *toplevel;
1483 if (gtk_widget_get_mapped (completion->priv->popup_window))
1486 if (!gtk_widget_get_mapped (completion->priv->entry))
1489 if (!gtk_widget_has_focus (completion->priv->entry))
1492 if (completion->priv->grab_device)
1495 completion->priv->ignore_enter = TRUE;
1497 column = gtk_tree_view_get_column (GTK_TREE_VIEW (completion->priv->action_view), 0);
1498 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
1499 gtk_widget_ensure_style (completion->priv->tree_view);
1500 g_object_set (GTK_CELL_RENDERER (renderers->data), "cell-background-gdk",
1501 &completion->priv->tree_view->style->bg[GTK_STATE_NORMAL],
1503 g_list_free (renderers);
1505 gtk_widget_show_all (completion->priv->vbox);
1507 /* default on no match */
1508 completion->priv->current_selected = -1;
1510 _gtk_entry_completion_resize_popup (completion);
1512 toplevel = gtk_widget_get_toplevel (completion->priv->entry);
1513 if (GTK_IS_WINDOW (toplevel))
1514 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
1515 GTK_WINDOW (completion->priv->popup_window));
1517 /* prevent the first row being focused */
1518 gtk_widget_grab_focus (completion->priv->tree_view);
1520 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
1521 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
1523 gtk_window_set_screen (GTK_WINDOW (completion->priv->popup_window),
1524 gtk_widget_get_screen (completion->priv->entry));
1526 gtk_widget_show (completion->priv->popup_window);
1528 gtk_device_grab_add (completion->priv->popup_window, device, TRUE);
1529 gdk_device_grab (device, completion->priv->popup_window->window,
1530 GDK_OWNERSHIP_WINDOW, TRUE,
1531 GDK_BUTTON_PRESS_MASK |
1532 GDK_BUTTON_RELEASE_MASK |
1533 GDK_POINTER_MOTION_MASK,
1534 NULL, GDK_CURRENT_TIME);
1536 completion->priv->grab_device = device;
1540 _gtk_entry_completion_popdown (GtkEntryCompletion *completion)
1542 if (!gtk_widget_get_mapped (completion->priv->popup_window))
1545 completion->priv->ignore_enter = FALSE;
1547 if (completion->priv->grab_device)
1549 gdk_device_ungrab (completion->priv->grab_device, GDK_CURRENT_TIME);
1550 gtk_device_grab_remove (completion->priv->popup_window,
1551 completion->priv->grab_device);
1552 completion->priv->grab_device = NULL;
1555 gtk_widget_hide (completion->priv->popup_window);
1559 gtk_entry_completion_match_selected (GtkEntryCompletion *completion,
1560 GtkTreeModel *model,
1565 gtk_tree_model_get (model, iter, completion->priv->text_column, &str, -1);
1566 gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), str ? str : "");
1568 /* move cursor to the end */
1569 gtk_editable_set_position (GTK_EDITABLE (completion->priv->entry), -1);
1577 gtk_entry_completion_cursor_on_match (GtkEntryCompletion *completion,
1578 GtkTreeModel *model,
1581 gtk_entry_completion_insert_completion (completion, model, iter);
1587 gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion)
1590 gchar *prefix = NULL;
1594 if (completion->priv->text_column < 0)
1597 key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry));
1599 valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (completion->priv->filter_model),
1606 gtk_tree_model_get (GTK_TREE_MODEL (completion->priv->filter_model),
1607 &iter, completion->priv->text_column, &text,
1610 if (text && g_str_has_prefix (text, key))
1613 prefix = g_strdup (text);
1619 while (*p && *p == *q)
1629 /* strip a partial multibyte character */
1630 q = g_utf8_find_prev_char (prefix, p);
1631 switch (g_utf8_get_char_validated (q, p - q))
1643 valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (completion->priv->filter_model),
1652 gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion,
1653 const gchar *prefix)
1661 prefix_len = g_utf8_strlen (prefix, -1);
1663 key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry));
1664 key_len = g_utf8_strlen (key, -1);
1666 if (prefix_len > key_len)
1668 gint pos = prefix_len;
1670 gtk_editable_insert_text (GTK_EDITABLE (completion->priv->entry),
1671 prefix + strlen (key), -1, &pos);
1672 gtk_editable_select_region (GTK_EDITABLE (completion->priv->entry),
1673 key_len, prefix_len);
1675 completion->priv->has_completion = TRUE;
1683 * gtk_entry_completion_get_completion_prefix:
1684 * @completion: a #GtkEntryCompletion
1686 * Get the original text entered by the user that triggered
1687 * the completion or %NULL if there's no completion ongoing.
1689 * Returns: the prefix for the current completion
1694 gtk_entry_completion_get_completion_prefix (GtkEntryCompletion *completion)
1696 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
1698 return completion->priv->completion_prefix;
1702 gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
1705 GtkEntryCompletionPrivate *priv = completion->priv;
1708 priv = completion->priv;
1710 if (priv->changed_id > 0)
1711 g_signal_handler_block (priv->entry, priv->changed_id);
1713 if (priv->insert_text_id > 0)
1714 g_signal_handler_block (priv->entry, priv->insert_text_id);
1716 gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
1718 len = strlen (priv->completion_prefix);
1719 gtk_editable_select_region (GTK_EDITABLE (priv->entry), len, -1);
1721 if (priv->changed_id > 0)
1722 g_signal_handler_unblock (priv->entry, priv->changed_id);
1724 if (priv->insert_text_id > 0)
1725 g_signal_handler_unblock (priv->entry, priv->insert_text_id);
1729 gtk_entry_completion_insert_completion (GtkEntryCompletion *completion,
1730 GtkTreeModel *model,
1735 if (completion->priv->text_column < 0)
1738 gtk_tree_model_get (model, iter,
1739 completion->priv->text_column, &str,
1742 gtk_entry_completion_insert_completion_text (completion, str);
1750 * gtk_entry_completion_insert_prefix:
1751 * @completion: a #GtkEntryCompletion
1753 * Requests a prefix insertion.
1759 gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion)
1764 if (completion->priv->insert_text_id > 0)
1765 g_signal_handler_block (completion->priv->entry,
1766 completion->priv->insert_text_id);
1768 prefix = gtk_entry_completion_compute_prefix (completion);
1771 g_signal_emit (completion, entry_completion_signals[INSERT_PREFIX],
1776 if (completion->priv->insert_text_id > 0)
1777 g_signal_handler_unblock (completion->priv->entry,
1778 completion->priv->insert_text_id);
1782 * gtk_entry_completion_set_inline_completion:
1783 * @completion: a #GtkEntryCompletion
1784 * @inline_completion: %TRUE to do inline completion
1786 * Sets whether the common prefix of the possible completions should
1787 * be automatically inserted in the entry.
1792 gtk_entry_completion_set_inline_completion (GtkEntryCompletion *completion,
1793 gboolean inline_completion)
1795 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1797 inline_completion = inline_completion != FALSE;
1799 if (completion->priv->inline_completion != inline_completion)
1801 completion->priv->inline_completion = inline_completion;
1803 g_object_notify (G_OBJECT (completion), "inline-completion");
1808 * gtk_entry_completion_get_inline_completion:
1809 * @completion: a #GtkEntryCompletion
1811 * Returns whether the common prefix of the possible completions should
1812 * be automatically inserted in the entry.
1814 * Return value: %TRUE if inline completion is turned on
1819 gtk_entry_completion_get_inline_completion (GtkEntryCompletion *completion)
1821 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), FALSE);
1823 return completion->priv->inline_completion;
1827 * gtk_entry_completion_set_popup_completion:
1828 * @completion: a #GtkEntryCompletion
1829 * @popup_completion: %TRUE to do popup completion
1831 * Sets whether the completions should be presented in a popup window.
1836 gtk_entry_completion_set_popup_completion (GtkEntryCompletion *completion,
1837 gboolean popup_completion)
1839 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1841 popup_completion = popup_completion != FALSE;
1843 if (completion->priv->popup_completion != popup_completion)
1845 completion->priv->popup_completion = popup_completion;
1847 g_object_notify (G_OBJECT (completion), "popup-completion");
1853 * gtk_entry_completion_get_popup_completion:
1854 * @completion: a #GtkEntryCompletion
1856 * Returns whether the completions should be presented in a popup window.
1858 * Return value: %TRUE if popup completion is turned on
1863 gtk_entry_completion_get_popup_completion (GtkEntryCompletion *completion)
1865 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1867 return completion->priv->popup_completion;
1871 * gtk_entry_completion_set_popup_set_width:
1872 * @completion: a #GtkEntryCompletion
1873 * @popup_set_width: %TRUE to make the width of the popup the same as the entry
1875 * Sets whether the completion popup window will be resized to be the same
1876 * width as the entry.
1881 gtk_entry_completion_set_popup_set_width (GtkEntryCompletion *completion,
1882 gboolean popup_set_width)
1884 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1886 popup_set_width = popup_set_width != FALSE;
1888 if (completion->priv->popup_set_width != popup_set_width)
1890 completion->priv->popup_set_width = popup_set_width;
1892 g_object_notify (G_OBJECT (completion), "popup-set-width");
1897 * gtk_entry_completion_get_popup_set_width:
1898 * @completion: a #GtkEntryCompletion
1900 * Returns whether the completion popup window will be resized to the
1901 * width of the entry.
1903 * Return value: %TRUE if the popup window will be resized to the width of
1909 gtk_entry_completion_get_popup_set_width (GtkEntryCompletion *completion)
1911 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1913 return completion->priv->popup_set_width;
1918 * gtk_entry_completion_set_popup_single_match:
1919 * @completion: a #GtkEntryCompletion
1920 * @popup_single_match: %TRUE if the popup should appear even for a single
1923 * Sets whether the completion popup window will appear even if there is
1924 * only a single match. You may want to set this to %FALSE if you
1925 * are using <link linkend="GtkEntryCompletion--inline-completion">inline
1926 * completion</link>.
1931 gtk_entry_completion_set_popup_single_match (GtkEntryCompletion *completion,
1932 gboolean popup_single_match)
1934 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1936 popup_single_match = popup_single_match != FALSE;
1938 if (completion->priv->popup_single_match != popup_single_match)
1940 completion->priv->popup_single_match = popup_single_match;
1942 g_object_notify (G_OBJECT (completion), "popup-single-match");
1947 * gtk_entry_completion_get_popup_single_match:
1948 * @completion: a #GtkEntryCompletion
1950 * Returns whether the completion popup window will appear even if there is
1951 * only a single match.
1953 * Return value: %TRUE if the popup window will appear regardless of the
1954 * number of matches.
1959 gtk_entry_completion_get_popup_single_match (GtkEntryCompletion *completion)
1961 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1963 return completion->priv->popup_single_match;
1967 * gtk_entry_completion_set_inline_selection:
1968 * @completion: a #GtkEntryCompletion
1969 * @inline_selection: %TRUE to do inline selection
1971 * Sets whether it is possible to cycle through the possible completions
1977 gtk_entry_completion_set_inline_selection (GtkEntryCompletion *completion,
1978 gboolean inline_selection)
1980 g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1982 inline_selection = inline_selection != FALSE;
1984 if (completion->priv->inline_selection != inline_selection)
1986 completion->priv->inline_selection = inline_selection;
1988 g_object_notify (G_OBJECT (completion), "inline-selection");
1993 * gtk_entry_completion_get_inline_selection:
1994 * @completion: a #GtkEntryCompletion
1996 * Returns %TRUE if inline-selection mode is turned on.
1998 * Returns: %TRUE if inline-selection mode is on
2003 gtk_entry_completion_get_inline_selection (GtkEntryCompletion *completion)
2005 g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), FALSE);
2007 return completion->priv->inline_selection;
2010 #define __GTK_ENTRY_COMPLETION_C__
2011 #include "gtkaliasdef.c"