]> Pileus Git - ~andy/gtk/blob - gtk/gtkentrycompletion.c
Merge branch 'windows_list'
[~andy/gtk] / gtk / gtkentrycompletion.c
1 /* gtkentrycompletion.c
2  * Copyright (C) 2003  Kristian Rietveld  <kris@gtk.org>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "config.h"
21 #include "gtkentrycompletion.h"
22 #include "gtkentryprivate.h"
23 #include "gtkcelllayout.h"
24
25 #include "gtkintl.h"
26 #include "gtkcellrenderertext.h"
27 #include "gtkframe.h"
28 #include "gtktreeselection.h"
29 #include "gtktreeview.h"
30 #include "gtkscrolledwindow.h"
31 #include "gtkvbox.h"
32 #include "gtkwindow.h"
33 #include "gtkentry.h"
34 #include "gtkmain.h"
35 #include "gtkmarshalers.h"
36
37 #include "gtkprivate.h"
38
39 #include <string.h>
40
41
42 /* signals */
43 enum
44 {
45   INSERT_PREFIX,
46   MATCH_SELECTED,
47   ACTION_ACTIVATED,
48   CURSOR_ON_MATCH,
49   LAST_SIGNAL
50 };
51
52 /* properties */
53 enum
54 {
55   PROP_0,
56   PROP_MODEL,
57   PROP_MINIMUM_KEY_LENGTH,
58   PROP_TEXT_COLUMN,
59   PROP_INLINE_COMPLETION,
60   PROP_POPUP_COMPLETION,
61   PROP_POPUP_SET_WIDTH,
62   PROP_POPUP_SINGLE_MATCH,
63   PROP_INLINE_SELECTION
64 };
65
66
67 static void                                                             gtk_entry_completion_cell_layout_init    (GtkCellLayoutIface      *iface);
68 static void     gtk_entry_completion_set_property        (GObject      *object,
69                                                           guint         prop_id,
70                                                           const GValue *value,
71                                                           GParamSpec   *pspec);
72 static void     gtk_entry_completion_get_property        (GObject      *object,
73                                                           guint         prop_id,
74                                                           GValue       *value,
75                                                           GParamSpec   *pspec);
76 static void                                                             gtk_entry_completion_finalize            (GObject                 *object);
77
78 static void     gtk_entry_completion_pack_start          (GtkCellLayout         *cell_layout,
79                                                           GtkCellRenderer       *cell,
80                                                           gboolean               expand);
81 static void     gtk_entry_completion_pack_end            (GtkCellLayout         *cell_layout,
82                                                           GtkCellRenderer       *cell,
83                                                           gboolean               expand);
84 static void                                                                      gtk_entry_completion_clear               (GtkCellLayout           *cell_layout);
85 static void     gtk_entry_completion_add_attribute       (GtkCellLayout         *cell_layout,
86                                                           GtkCellRenderer       *cell,
87                                                           const char            *attribute,
88                                                           gint                   column);
89 static void     gtk_entry_completion_set_cell_data_func  (GtkCellLayout         *cell_layout,
90                                                           GtkCellRenderer       *cell,
91                                                           GtkCellLayoutDataFunc  func,
92                                                           gpointer               func_data,
93                                                           GDestroyNotify         destroy);
94 static void     gtk_entry_completion_clear_attributes    (GtkCellLayout         *cell_layout,
95                                                           GtkCellRenderer       *cell);
96 static void     gtk_entry_completion_reorder             (GtkCellLayout         *cell_layout,
97                                                           GtkCellRenderer       *cell,
98                                                           gint                   position);
99 static GList *  gtk_entry_completion_get_cells           (GtkCellLayout         *cell_layout);
100
101 static gboolean gtk_entry_completion_visible_func        (GtkTreeModel       *model,
102                                                           GtkTreeIter        *iter,
103                                                           gpointer            data);
104 static gboolean gtk_entry_completion_popup_key_event     (GtkWidget          *widget,
105                                                           GdkEventKey        *event,
106                                                           gpointer            user_data);
107 static gboolean gtk_entry_completion_popup_button_press  (GtkWidget          *widget,
108                                                           GdkEventButton     *event,
109                                                           gpointer            user_data);
110 static gboolean gtk_entry_completion_list_button_press   (GtkWidget          *widget,
111                                                           GdkEventButton     *event,
112                                                           gpointer            user_data);
113 static gboolean gtk_entry_completion_action_button_press (GtkWidget          *widget,
114                                                           GdkEventButton     *event,
115                                                           gpointer            user_data);
116 static void     gtk_entry_completion_selection_changed   (GtkTreeSelection   *selection,
117                                                           gpointer            data);
118 static gboolean gtk_entry_completion_list_enter_notify   (GtkWidget          *widget,
119                                                           GdkEventCrossing   *event,
120                                                           gpointer            data);
121 static gboolean gtk_entry_completion_list_motion_notify  (GtkWidget          *widget,
122                                                           GdkEventMotion     *event,
123                                                           gpointer            data);
124 static void     gtk_entry_completion_insert_action       (GtkEntryCompletion *completion,
125                                                           gint                index,
126                                                           const gchar        *string,
127                                                           gboolean            markup);
128 static void     gtk_entry_completion_action_data_func    (GtkTreeViewColumn  *tree_column,
129                                                           GtkCellRenderer    *cell,
130                                                           GtkTreeModel       *model,
131                                                           GtkTreeIter        *iter,
132                                                           gpointer            data);
133
134 static gboolean gtk_entry_completion_match_selected      (GtkEntryCompletion *completion,
135                                                           GtkTreeModel       *model,
136                                                           GtkTreeIter        *iter);
137 static gboolean gtk_entry_completion_real_insert_prefix  (GtkEntryCompletion *completion,
138                                                           const gchar        *prefix);
139 static gboolean gtk_entry_completion_cursor_on_match     (GtkEntryCompletion *completion,
140                                                           GtkTreeModel       *model,
141                                                           GtkTreeIter        *iter);
142 static gboolean gtk_entry_completion_insert_completion   (GtkEntryCompletion *completion,
143                                                           GtkTreeModel       *model,
144                                                           GtkTreeIter        *iter);
145 static void     gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
146                                                              const gchar *text);
147
148 static guint entry_completion_signals[LAST_SIGNAL] = { 0 };
149
150 /* GtkBuildable */
151 static void     gtk_entry_completion_buildable_init      (GtkBuildableIface  *iface);
152
153 G_DEFINE_TYPE_WITH_CODE (GtkEntryCompletion, gtk_entry_completion, G_TYPE_OBJECT,
154                          G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
155                                                 gtk_entry_completion_cell_layout_init)
156                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
157                                                 gtk_entry_completion_buildable_init))
158
159
160 static void
161 gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
162 {
163   GObjectClass *object_class;
164
165   object_class = (GObjectClass *)klass;
166
167   object_class->set_property = gtk_entry_completion_set_property;
168   object_class->get_property = gtk_entry_completion_get_property;
169   object_class->finalize = gtk_entry_completion_finalize;
170
171   klass->match_selected = gtk_entry_completion_match_selected;
172   klass->insert_prefix = gtk_entry_completion_real_insert_prefix;
173   klass->cursor_on_match = gtk_entry_completion_cursor_on_match;
174
175   /**
176    * GtkEntryCompletion::insert-prefix:
177    * @widget: the object which received the signal
178    * @prefix: the common prefix of all possible completions
179    *
180    * Gets emitted when the inline autocompletion is triggered.
181    * The default behaviour is to make the entry display the
182    * whole prefix and select the newly inserted part.
183    *
184    * Applications may connect to this signal in order to insert only a
185    * smaller part of the @prefix into the entry - e.g. the entry used in
186    * the #GtkFileChooser inserts only the part of the prefix up to the
187    * next '/'.
188    *
189    * Return value: %TRUE if the signal has been handled
190    *
191    * Since: 2.6
192    */
193   entry_completion_signals[INSERT_PREFIX] =
194     g_signal_new (I_("insert-prefix"),
195                   G_TYPE_FROM_CLASS (klass),
196                   G_SIGNAL_RUN_LAST,
197                   G_STRUCT_OFFSET (GtkEntryCompletionClass, insert_prefix),
198                   _gtk_boolean_handled_accumulator, NULL,
199                   _gtk_marshal_BOOLEAN__STRING,
200                   G_TYPE_BOOLEAN, 1,
201                   G_TYPE_STRING);
202
203   /**
204    * GtkEntryCompletion::match-selected:
205    * @widget: the object which received the signal
206    * @model: the #GtkTreeModel containing the matches
207    * @iter: a #GtkTreeIter positioned at the selected match
208    *
209    * Gets emitted when a match from the list is selected.
210    * The default behaviour is to replace the contents of the
211    * entry with the contents of the text column in the row
212    * pointed to by @iter.
213    *
214    * Return value: %TRUE if the signal has been handled
215    *
216    * Since: 2.4
217    */
218   entry_completion_signals[MATCH_SELECTED] =
219     g_signal_new (I_("match-selected"),
220                   G_TYPE_FROM_CLASS (klass),
221                   G_SIGNAL_RUN_LAST,
222                   G_STRUCT_OFFSET (GtkEntryCompletionClass, match_selected),
223                   _gtk_boolean_handled_accumulator, NULL,
224                   _gtk_marshal_BOOLEAN__OBJECT_BOXED,
225                   G_TYPE_BOOLEAN, 2,
226                   GTK_TYPE_TREE_MODEL,
227                   GTK_TYPE_TREE_ITER);
228
229   /**
230    * GtkEntryCompletion::cursor-on-match:
231    * @widget: the object which received the signal
232    * @model: the #GtkTreeModel containing the matches
233    * @iter: a #GtkTreeIter positioned at the selected match
234    *
235    * Gets emitted when a match from the cursor is on a match
236    * of the list. The default behaviour is to replace the contents
237    * of the entry with the contents of the text column in the row
238    * pointed to by @iter.
239    *
240    * Return value: %TRUE if the signal has been handled
241    *
242    * Since: 2.12
243    */
244   entry_completion_signals[CURSOR_ON_MATCH] =
245     g_signal_new (I_("cursor-on-match"),
246                   G_TYPE_FROM_CLASS (klass),
247                   G_SIGNAL_RUN_LAST,
248                   G_STRUCT_OFFSET (GtkEntryCompletionClass, cursor_on_match),
249                   _gtk_boolean_handled_accumulator, NULL,
250                   _gtk_marshal_BOOLEAN__OBJECT_BOXED,
251                   G_TYPE_BOOLEAN, 2,
252                   GTK_TYPE_TREE_MODEL,
253                   GTK_TYPE_TREE_ITER);
254
255   /**
256    * GtkEntryCompletion::action-activated:
257    * @widget: the object which received the signal
258    * @index: the index of the activated action
259    *
260    * Gets emitted when an action is activated.
261    * 
262    * Since: 2.4
263    */
264   entry_completion_signals[ACTION_ACTIVATED] =
265     g_signal_new (I_("action-activated"),
266                   G_TYPE_FROM_CLASS (klass),
267                   G_SIGNAL_RUN_LAST,
268                   G_STRUCT_OFFSET (GtkEntryCompletionClass, action_activated),
269                   NULL, NULL,
270                   _gtk_marshal_VOID__INT,
271                   G_TYPE_NONE, 1,
272                   G_TYPE_INT);
273
274   g_object_class_install_property (object_class,
275                                    PROP_MODEL,
276                                    g_param_spec_object ("model",
277                                                         P_("Completion Model"),
278                                                         P_("The model to find matches in"),
279                                                         GTK_TYPE_TREE_MODEL,
280                                                         GTK_PARAM_READWRITE));
281   g_object_class_install_property (object_class,
282                                    PROP_MINIMUM_KEY_LENGTH,
283                                    g_param_spec_int ("minimum-key-length",
284                                                      P_("Minimum Key Length"),
285                                                      P_("Minimum length of the search key in order to look up matches"),
286                                                      0,
287                                                      G_MAXINT,
288                                                      1,
289                                                      GTK_PARAM_READWRITE));
290   /**
291    * GtkEntryCompletion:text-column:
292    *
293    * The column of the model containing the strings.
294    * Note that the strings must be UTF-8.
295    *
296    * Since: 2.6
297    */
298   g_object_class_install_property (object_class,
299                                    PROP_TEXT_COLUMN,
300                                    g_param_spec_int ("text-column",
301                                                      P_("Text column"),
302                                                      P_("The column of the model containing the strings."),
303                                                      -1,
304                                                      G_MAXINT,
305                                                      -1,
306                                                      GTK_PARAM_READWRITE));
307
308   /**
309    * GtkEntryCompletion:inline-completion:
310    * 
311    * Determines whether the common prefix of the possible completions 
312    * should be inserted automatically in the entry. Note that this
313    * requires text-column to be set, even if you are using a custom
314    * match function.
315    *
316    * Since: 2.6
317    **/
318   g_object_class_install_property (object_class,
319                                    PROP_INLINE_COMPLETION,
320                                    g_param_spec_boolean ("inline-completion",
321                                                          P_("Inline completion"),
322                                                          P_("Whether the common prefix should be inserted automatically"),
323                                                          FALSE,
324                                                          GTK_PARAM_READWRITE));
325   /**
326    * GtkEntryCompletion:popup-completion:
327    * 
328    * Determines whether the possible completions should be 
329    * shown in a popup window. 
330    *
331    * Since: 2.6
332    **/
333   g_object_class_install_property (object_class,
334                                    PROP_POPUP_COMPLETION,
335                                    g_param_spec_boolean ("popup-completion",
336                                                          P_("Popup completion"),
337                                                          P_("Whether the completions should be shown in a popup window"),
338                                                          TRUE,
339                                                          GTK_PARAM_READWRITE));
340
341   /**
342    * GtkEntryCompletion:popup-set-width:
343    * 
344    * Determines whether the completions popup window will be
345    * resized to the width of the entry.
346    *
347    * Since: 2.8
348    */
349   g_object_class_install_property (object_class,
350                                    PROP_POPUP_SET_WIDTH,
351                                    g_param_spec_boolean ("popup-set-width",
352                                                          P_("Popup set width"),
353                                                          P_("If TRUE, the popup window will have the same size as the entry"),
354                                                          TRUE,
355                                                          GTK_PARAM_READWRITE));
356
357   /**
358    * GtkEntryCompletion:popup-single-match:
359    * 
360    * Determines whether the completions popup window will shown
361    * for a single possible completion. You probably want to set
362    * this to %FALSE if you are using 
363    * <link linkend="GtkEntryCompletion--inline-completion">inline 
364    * completion</link>.
365    *
366    * Since: 2.8
367    */
368   g_object_class_install_property (object_class,
369                                    PROP_POPUP_SINGLE_MATCH,
370                                    g_param_spec_boolean ("popup-single-match",
371                                                          P_("Popup single match"),
372                                                          P_("If TRUE, the popup window will appear for a single match."),
373                                                          TRUE,
374                                                          GTK_PARAM_READWRITE));
375   /**
376    * GtkEntryCompletion:inline-selection:
377    * 
378    * Determines whether the possible completions on the popup
379    * will appear in the entry as you navigate through them.
380    
381    * Since: 2.12
382    */
383   g_object_class_install_property (object_class,
384                                    PROP_INLINE_SELECTION,
385                                    g_param_spec_boolean ("inline-selection",
386                                                          P_("Inline selection"),
387                                                          P_("Your description here"),
388                                                          FALSE,
389                                                          GTK_PARAM_READWRITE));
390
391   g_type_class_add_private (object_class, sizeof (GtkEntryCompletionPrivate));
392 }
393
394 static void
395 gtk_entry_completion_buildable_init (GtkBuildableIface *iface)
396 {
397   iface->add_child = _gtk_cell_layout_buildable_add_child;
398   iface->custom_tag_start = _gtk_cell_layout_buildable_custom_tag_start;
399   iface->custom_tag_end = _gtk_cell_layout_buildable_custom_tag_end;
400 }
401
402 static void
403 gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface)
404 {
405   iface->pack_start = gtk_entry_completion_pack_start;
406   iface->pack_end = gtk_entry_completion_pack_end;
407   iface->clear = gtk_entry_completion_clear;
408   iface->add_attribute = gtk_entry_completion_add_attribute;
409   iface->set_cell_data_func = gtk_entry_completion_set_cell_data_func;
410   iface->clear_attributes = gtk_entry_completion_clear_attributes;
411   iface->reorder = gtk_entry_completion_reorder;
412   iface->get_cells = gtk_entry_completion_get_cells;
413 }
414
415 static void
416 gtk_entry_completion_init (GtkEntryCompletion *completion)
417 {
418   GtkCellRenderer *cell;
419   GtkTreeSelection *sel;
420   GtkEntryCompletionPrivate *priv;
421   GtkWidget *popup_frame;
422
423   /* yes, also priv, need to keep the code readable */
424   completion->priv = G_TYPE_INSTANCE_GET_PRIVATE (completion,
425                                                   GTK_TYPE_ENTRY_COMPLETION,
426                                                   GtkEntryCompletionPrivate);
427   priv = completion->priv;
428
429   priv->minimum_key_length = 1;
430   priv->text_column = -1;
431   priv->has_completion = FALSE;
432   priv->inline_completion = FALSE;
433   priv->popup_completion = TRUE;
434   priv->popup_set_width = TRUE;
435   priv->popup_single_match = TRUE;
436   priv->inline_selection = FALSE;
437
438   /* completions */
439   priv->filter_model = NULL;
440
441   priv->tree_view = gtk_tree_view_new ();
442   g_signal_connect (priv->tree_view, "button-press-event",
443                     G_CALLBACK (gtk_entry_completion_list_button_press),
444                     completion);
445   g_signal_connect (priv->tree_view, "enter-notify-event",
446                     G_CALLBACK (gtk_entry_completion_list_enter_notify),
447                     completion);
448   g_signal_connect (priv->tree_view, "motion-notify-event",
449                     G_CALLBACK (gtk_entry_completion_list_motion_notify),
450                     completion);
451
452   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
453   gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->tree_view), TRUE);
454
455   sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
456   gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE);
457   gtk_tree_selection_unselect_all (sel);
458   g_signal_connect (sel, "changed",
459                     G_CALLBACK (gtk_entry_completion_selection_changed),
460                     completion);
461   priv->first_sel_changed = TRUE;
462
463   priv->column = gtk_tree_view_column_new ();
464   gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), priv->column);
465
466   priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
467   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
468                                   GTK_POLICY_NEVER,
469                                   GTK_POLICY_AUTOMATIC);
470   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window),
471                                        GTK_SHADOW_NONE);
472
473   /* a nasty hack to get the completions treeview to size nicely */
474   gtk_widget_set_size_request (gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (priv->scrolled_window)),
475                                -1, 0);
476
477   /* actions */
478   priv->actions = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
479
480   priv->action_view =
481     gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->actions));
482   g_object_ref_sink (priv->action_view);
483   g_signal_connect (priv->action_view, "button-press-event",
484                     G_CALLBACK (gtk_entry_completion_action_button_press),
485                     completion);
486   g_signal_connect (priv->action_view, "enter-notify-event",
487                     G_CALLBACK (gtk_entry_completion_list_enter_notify),
488                     completion);
489   g_signal_connect (priv->action_view, "motion-notify-event",
490                     G_CALLBACK (gtk_entry_completion_list_motion_notify),
491                     completion);
492   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->action_view), FALSE);
493   gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->action_view), TRUE);
494
495   sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->action_view));
496   gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE);
497   gtk_tree_selection_unselect_all (sel);
498
499   cell = gtk_cell_renderer_text_new ();
500   gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (priv->action_view),
501                                               0, "",
502                                               cell,
503                                               gtk_entry_completion_action_data_func,
504                                               NULL,
505                                               NULL);
506
507   /* pack it all */
508   priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
509   gtk_window_set_resizable (GTK_WINDOW (priv->popup_window), FALSE);
510   gtk_window_set_type_hint (GTK_WINDOW(priv->popup_window),
511                             GDK_WINDOW_TYPE_HINT_COMBO);
512   g_signal_connect (priv->popup_window, "key-press-event",
513                     G_CALLBACK (gtk_entry_completion_popup_key_event),
514                     completion);
515   g_signal_connect (priv->popup_window, "key-release-event",
516                     G_CALLBACK (gtk_entry_completion_popup_key_event),
517                     completion);
518   g_signal_connect (priv->popup_window, "button-press-event",
519                     G_CALLBACK (gtk_entry_completion_popup_button_press),
520                     completion);
521
522   popup_frame = gtk_frame_new (NULL);
523   gtk_frame_set_shadow_type (GTK_FRAME (popup_frame),
524                              GTK_SHADOW_ETCHED_IN);
525   gtk_widget_show (popup_frame);
526   gtk_container_add (GTK_CONTAINER (priv->popup_window), popup_frame);
527   
528   priv->vbox = gtk_vbox_new (FALSE, 0);
529   gtk_container_add (GTK_CONTAINER (popup_frame), priv->vbox);
530
531   gtk_container_add (GTK_CONTAINER (priv->scrolled_window), priv->tree_view);
532   gtk_box_pack_start (GTK_BOX (priv->vbox), priv->scrolled_window,
533                       TRUE, TRUE, 0);
534
535   /* we don't want to see the action treeview when no actions have
536    * been inserted, so we pack the action treeview after the first
537    * action has been added
538    */
539 }
540
541 static void
542 gtk_entry_completion_set_property (GObject      *object,
543                                    guint         prop_id,
544                                    const GValue *value,
545                                    GParamSpec   *pspec)
546 {
547   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
548   GtkEntryCompletionPrivate *priv = completion->priv;
549
550   switch (prop_id)
551     {
552       case PROP_MODEL:
553         gtk_entry_completion_set_model (completion,
554                                         g_value_get_object (value));
555         break;
556
557       case PROP_MINIMUM_KEY_LENGTH:
558         gtk_entry_completion_set_minimum_key_length (completion,
559                                                      g_value_get_int (value));
560         break;
561
562       case PROP_TEXT_COLUMN:
563         priv->text_column = g_value_get_int (value);
564         break;
565
566       case PROP_INLINE_COMPLETION:
567         priv->inline_completion = g_value_get_boolean (value);
568         break;
569
570       case PROP_POPUP_COMPLETION:
571         priv->popup_completion = g_value_get_boolean (value);
572         break;
573
574       case PROP_POPUP_SET_WIDTH:
575         priv->popup_set_width = g_value_get_boolean (value);
576         break;
577
578       case PROP_POPUP_SINGLE_MATCH:
579         priv->popup_single_match = g_value_get_boolean (value);
580         break;
581
582       case PROP_INLINE_SELECTION:
583         priv->inline_selection = g_value_get_boolean (value);
584         break;
585       
586       default:
587         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
588         break;
589     }
590 }
591
592 static void
593 gtk_entry_completion_get_property (GObject    *object,
594                                    guint       prop_id,
595                                    GValue     *value,
596                                    GParamSpec *pspec)
597 {
598   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
599
600   switch (prop_id)
601     {
602       case PROP_MODEL:
603         g_value_set_object (value,
604                             gtk_entry_completion_get_model (completion));
605         break;
606
607       case PROP_MINIMUM_KEY_LENGTH:
608         g_value_set_int (value, gtk_entry_completion_get_minimum_key_length (completion));
609         break;
610
611       case PROP_TEXT_COLUMN:
612         g_value_set_int (value, gtk_entry_completion_get_text_column (completion));
613         break;
614
615       case PROP_INLINE_COMPLETION:
616         g_value_set_boolean (value, gtk_entry_completion_get_inline_completion (completion));
617         break;
618
619       case PROP_POPUP_COMPLETION:
620         g_value_set_boolean (value, gtk_entry_completion_get_popup_completion (completion));
621         break;
622
623       case PROP_POPUP_SET_WIDTH:
624         g_value_set_boolean (value, gtk_entry_completion_get_popup_set_width (completion));
625         break;
626
627       case PROP_POPUP_SINGLE_MATCH:
628         g_value_set_boolean (value, gtk_entry_completion_get_popup_single_match (completion));
629         break;
630
631       case PROP_INLINE_SELECTION:
632         g_value_set_boolean (value, gtk_entry_completion_get_inline_selection (completion));
633         break;
634
635       default:
636         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
637         break;
638     }
639 }
640
641 static void
642 gtk_entry_completion_finalize (GObject *object)
643 {
644   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
645   GtkEntryCompletionPrivate *priv = completion->priv;
646
647   if (priv->tree_view)
648     gtk_widget_destroy (priv->tree_view);
649
650   if (priv->entry)
651     gtk_entry_set_completion (GTK_ENTRY (priv->entry), NULL);
652
653   if (priv->actions)
654     g_object_unref (priv->actions);
655   if (priv->action_view)
656     g_object_unref (priv->action_view);
657
658   g_free (priv->case_normalized_key);
659   g_free (priv->completion_prefix);
660
661   if (priv->popup_window)
662     gtk_widget_destroy (priv->popup_window);
663
664   if (priv->match_notify)
665     (* priv->match_notify) (priv->match_data);
666
667   G_OBJECT_CLASS (gtk_entry_completion_parent_class)->finalize (object);
668 }
669
670 /* implement cell layout interface */
671 static void
672 gtk_entry_completion_pack_start (GtkCellLayout   *cell_layout,
673                                  GtkCellRenderer *cell,
674                                  gboolean         expand)
675 {
676   GtkEntryCompletionPrivate *priv;
677
678   priv = GTK_ENTRY_COMPLETION (cell_layout)->priv;
679
680   gtk_tree_view_column_pack_start (priv->column, cell, expand);
681 }
682
683 static void
684 gtk_entry_completion_pack_end (GtkCellLayout   *cell_layout,
685                                GtkCellRenderer *cell,
686                                gboolean         expand)
687 {
688   GtkEntryCompletionPrivate *priv;
689
690   priv = GTK_ENTRY_COMPLETION (cell_layout)->priv;
691
692   gtk_tree_view_column_pack_end (priv->column, cell, expand);
693 }
694
695 static void
696 gtk_entry_completion_clear (GtkCellLayout *cell_layout)
697 {
698   GtkEntryCompletionPrivate *priv;
699
700   priv = GTK_ENTRY_COMPLETION (cell_layout)->priv;
701
702   gtk_tree_view_column_clear (priv->column);
703 }
704
705 static void
706 gtk_entry_completion_add_attribute (GtkCellLayout   *cell_layout,
707                                     GtkCellRenderer *cell,
708                                     const gchar     *attribute,
709                                     gint             column)
710 {
711   GtkEntryCompletionPrivate *priv;
712
713   priv = GTK_ENTRY_COMPLETION  (cell_layout)->priv;
714
715   gtk_tree_view_column_add_attribute (priv->column, cell, attribute, column);
716 }
717
718 static void
719 gtk_entry_completion_set_cell_data_func (GtkCellLayout          *cell_layout,
720                                          GtkCellRenderer        *cell,
721                                          GtkCellLayoutDataFunc   func,
722                                          gpointer                func_data,
723                                          GDestroyNotify          destroy)
724 {
725   GtkEntryCompletionPrivate *priv;
726
727   priv = GTK_ENTRY_COMPLETION (cell_layout)->priv;
728
729   gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->column),
730                                       cell, func, func_data, destroy);
731 }
732
733 static void
734 gtk_entry_completion_clear_attributes (GtkCellLayout   *cell_layout,
735                                        GtkCellRenderer *cell)
736 {
737   GtkEntryCompletionPrivate *priv;
738
739   priv = GTK_ENTRY_COMPLETION (cell_layout)->priv;
740
741   gtk_tree_view_column_clear_attributes (priv->column, cell);
742 }
743
744 static void
745 gtk_entry_completion_reorder (GtkCellLayout   *cell_layout,
746                               GtkCellRenderer *cell,
747                               gint             position)
748 {
749   GtkEntryCompletionPrivate *priv;
750
751   priv = GTK_ENTRY_COMPLETION (cell_layout)->priv;
752
753   gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->column), cell, position);
754 }
755
756 static GList *
757 gtk_entry_completion_get_cells (GtkCellLayout *cell_layout)
758 {
759   GtkEntryCompletionPrivate *priv;
760
761   priv = GTK_ENTRY_COMPLETION (cell_layout)->priv;
762
763   return gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (priv->column));
764 }
765
766 /* all those callbacks */
767 static gboolean
768 gtk_entry_completion_default_completion_func (GtkEntryCompletion *completion,
769                                               const gchar        *key,
770                                               GtkTreeIter        *iter,
771                                               gpointer            user_data)
772 {
773   gchar *item = NULL;
774   gchar *normalized_string;
775   gchar *case_normalized_string;
776
777   gboolean ret = FALSE;
778
779   GtkTreeModel *model;
780
781   model = gtk_tree_model_filter_get_model (completion->priv->filter_model);
782
783   g_return_val_if_fail (gtk_tree_model_get_column_type (model, completion->priv->text_column) == G_TYPE_STRING, 
784                         FALSE);
785
786   gtk_tree_model_get (model, iter,
787                       completion->priv->text_column, &item,
788                       -1);
789
790   if (item != NULL)
791     {
792       normalized_string = g_utf8_normalize (item, -1, G_NORMALIZE_ALL);
793       case_normalized_string = g_utf8_casefold (normalized_string, -1);
794       
795       if (!strncmp (key, case_normalized_string, strlen (key)))
796         ret = TRUE;
797       
798       g_free (item);
799       g_free (normalized_string);
800       g_free (case_normalized_string);
801     }
802
803   return ret;
804 }
805
806 static gboolean
807 gtk_entry_completion_visible_func (GtkTreeModel *model,
808                                    GtkTreeIter  *iter,
809                                    gpointer      data)
810 {
811   gboolean ret = FALSE;
812
813   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
814
815   if (!completion->priv->case_normalized_key)
816     return ret;
817
818   if (completion->priv->match_func)
819     ret = (* completion->priv->match_func) (completion,
820                                             completion->priv->case_normalized_key,
821                                             iter,
822                                             completion->priv->match_data);
823   else if (completion->priv->text_column >= 0)
824     ret = gtk_entry_completion_default_completion_func (completion,
825                                                         completion->priv->case_normalized_key,
826                                                         iter,
827                                                         NULL);
828
829   return ret;
830 }
831
832 static gboolean
833 gtk_entry_completion_popup_key_event (GtkWidget   *widget,
834                                       GdkEventKey *event,
835                                       gpointer     user_data)
836 {
837   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
838
839   if (!gtk_widget_get_mapped (completion->priv->popup_window))
840     return FALSE;
841
842   /* propagate event to the entry */
843   gtk_widget_event (completion->priv->entry, (GdkEvent *)event);
844
845   return TRUE;
846 }
847
848 static gboolean
849 gtk_entry_completion_popup_button_press (GtkWidget      *widget,
850                                          GdkEventButton *event,
851                                          gpointer        user_data)
852 {
853   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
854
855   if (!gtk_widget_get_mapped (completion->priv->popup_window))
856     return FALSE;
857
858   /* if we come here, it's usually time to popdown */
859   _gtk_entry_completion_popdown (completion);
860
861   return TRUE;
862 }
863
864 static gboolean
865 gtk_entry_completion_list_button_press (GtkWidget      *widget,
866                                         GdkEventButton *event,
867                                         gpointer        user_data)
868 {
869   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
870   GtkTreePath *path = NULL;
871
872   if (!gtk_widget_get_mapped (completion->priv->popup_window))
873     return FALSE;
874
875   if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
876                                      event->x, event->y,
877                                      &path, NULL, NULL, NULL))
878     {
879       GtkTreeIter iter;
880       gboolean entry_set;
881       GtkTreeModel *model;
882       GtkTreeIter child_iter;
883
884       gtk_tree_model_get_iter (GTK_TREE_MODEL (completion->priv->filter_model),
885                                &iter, path);
886       gtk_tree_path_free (path);
887       gtk_tree_model_filter_convert_iter_to_child_iter (completion->priv->filter_model,
888                                                         &child_iter,
889                                                         &iter);
890       model = gtk_tree_model_filter_get_model (completion->priv->filter_model);
891
892       g_signal_handler_block (completion->priv->entry,
893                               completion->priv->changed_id);
894       g_signal_emit (completion, entry_completion_signals[MATCH_SELECTED],
895                      0, model, &child_iter, &entry_set);
896       g_signal_handler_unblock (completion->priv->entry,
897                                 completion->priv->changed_id);
898
899       _gtk_entry_completion_popdown (completion);
900
901       return TRUE;
902     }
903
904   return FALSE;
905 }
906
907 static gboolean
908 gtk_entry_completion_action_button_press (GtkWidget      *widget,
909                                           GdkEventButton *event,
910                                           gpointer        user_data)
911 {
912   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
913   GtkTreePath *path = NULL;
914
915   if (!gtk_widget_get_mapped (completion->priv->popup_window))
916     return FALSE;
917
918   _gtk_entry_reset_im_context (GTK_ENTRY (completion->priv->entry));
919
920   if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
921                                      event->x, event->y,
922                                      &path, NULL, NULL, NULL))
923     {
924       g_signal_emit (completion, entry_completion_signals[ACTION_ACTIVATED],
925                      0, gtk_tree_path_get_indices (path)[0]);
926       gtk_tree_path_free (path);
927
928       _gtk_entry_completion_popdown (completion);
929       return TRUE;
930     }
931
932   return FALSE;
933 }
934
935 static void
936 gtk_entry_completion_action_data_func (GtkTreeViewColumn *tree_column,
937                                        GtkCellRenderer   *cell,
938                                        GtkTreeModel      *model,
939                                        GtkTreeIter       *iter,
940                                        gpointer           data)
941 {
942   gchar *string = NULL;
943   gboolean markup;
944
945   gtk_tree_model_get (model, iter,
946                       0, &string,
947                       1, &markup,
948                       -1);
949
950   if (!string)
951     return;
952
953   if (markup)
954     g_object_set (cell,
955                   "text", NULL,
956                   "markup", string,
957                   NULL);
958   else
959     g_object_set (cell,
960                   "markup", NULL,
961                   "text", string,
962                   NULL);
963
964   g_free (string);
965 }
966
967 static void
968 gtk_entry_completion_selection_changed (GtkTreeSelection *selection,
969                                         gpointer          data)
970 {
971   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
972
973   if (completion->priv->first_sel_changed)
974     {
975       completion->priv->first_sel_changed = FALSE;
976       if (gtk_widget_is_focus (completion->priv->tree_view))
977         gtk_tree_selection_unselect_all (selection);
978     }
979 }
980
981 /* public API */
982
983 /**
984  * gtk_entry_completion_new:
985  *
986  * Creates a new #GtkEntryCompletion object.
987  *
988  * Return value: A newly created #GtkEntryCompletion object.
989  *
990  * Since: 2.4
991  */
992 GtkEntryCompletion *
993 gtk_entry_completion_new (void)
994 {
995   GtkEntryCompletion *completion;
996
997   completion = g_object_new (GTK_TYPE_ENTRY_COMPLETION, NULL);
998
999   return completion;
1000 }
1001
1002 /**
1003  * gtk_entry_completion_get_entry:
1004  * @completion: A #GtkEntryCompletion.
1005  *
1006  * Gets the entry @completion has been attached to.
1007  *
1008  * Return value: The entry @completion has been attached to.
1009  *
1010  * Since: 2.4
1011  */
1012 GtkWidget *
1013 gtk_entry_completion_get_entry (GtkEntryCompletion *completion)
1014 {
1015   g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
1016
1017   return completion->priv->entry;
1018 }
1019
1020 /**
1021  * gtk_entry_completion_set_model:
1022  * @completion: A #GtkEntryCompletion.
1023  * @model: (allow-none): The #GtkTreeModel.
1024  *
1025  * Sets the model for a #GtkEntryCompletion. If @completion already has
1026  * a model set, it will remove it before setting the new model.
1027  * If model is %NULL, then it will unset the model.
1028  *
1029  * Since: 2.4
1030  */
1031 void
1032 gtk_entry_completion_set_model (GtkEntryCompletion *completion,
1033                                 GtkTreeModel       *model)
1034 {
1035   g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1036   g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
1037
1038   if (!model)
1039     {
1040       gtk_tree_view_set_model (GTK_TREE_VIEW (completion->priv->tree_view),
1041                                NULL);
1042       _gtk_entry_completion_popdown (completion);
1043       completion->priv->filter_model = NULL;
1044       return;
1045     }
1046      
1047   /* code will unref the old filter model (if any) */
1048   completion->priv->filter_model =
1049     GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (model, NULL));
1050   gtk_tree_model_filter_set_visible_func (completion->priv->filter_model,
1051                                           gtk_entry_completion_visible_func,
1052                                           completion,
1053                                           NULL);
1054
1055   gtk_tree_view_set_model (GTK_TREE_VIEW (completion->priv->tree_view),
1056                            GTK_TREE_MODEL (completion->priv->filter_model));
1057   g_object_unref (completion->priv->filter_model);
1058
1059   g_object_notify (G_OBJECT (completion), "model");
1060
1061   if (gtk_widget_get_visible (completion->priv->popup_window))
1062     _gtk_entry_completion_resize_popup (completion);
1063 }
1064
1065 /**
1066  * gtk_entry_completion_get_model:
1067  * @completion: A #GtkEntryCompletion.
1068  *
1069  * Returns the model the #GtkEntryCompletion is using as data source.
1070  * Returns %NULL if the model is unset.
1071  *
1072  * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
1073  *
1074  * Since: 2.4
1075  */
1076 GtkTreeModel *
1077 gtk_entry_completion_get_model (GtkEntryCompletion *completion)
1078 {
1079   g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
1080
1081   if (!completion->priv->filter_model)
1082     return NULL;
1083   
1084   return gtk_tree_model_filter_get_model (completion->priv->filter_model);
1085 }
1086
1087 /**
1088  * gtk_entry_completion_set_match_func:
1089  * @completion: A #GtkEntryCompletion.
1090  * @func: The #GtkEntryCompletionMatchFunc to use.
1091  * @func_data: The user data for @func.
1092  * @func_notify: Destroy notifier for @func_data.
1093  *
1094  * Sets the match function for @completion to be @func. The match function
1095  * is used to determine if a row should or should not be in the completion
1096  * list.
1097  *
1098  * Since: 2.4
1099  */
1100 void
1101 gtk_entry_completion_set_match_func (GtkEntryCompletion          *completion,
1102                                      GtkEntryCompletionMatchFunc  func,
1103                                      gpointer                     func_data,
1104                                      GDestroyNotify               func_notify)
1105 {
1106   g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1107
1108   if (completion->priv->match_notify)
1109     (* completion->priv->match_notify) (completion->priv->match_data);
1110
1111   completion->priv->match_func = func;
1112   completion->priv->match_data = func_data;
1113   completion->priv->match_notify = func_notify;
1114 }
1115
1116 /**
1117  * gtk_entry_completion_set_minimum_key_length:
1118  * @completion: A #GtkEntryCompletion.
1119  * @length: The minimum length of the key in order to start completing.
1120  *
1121  * Requires the length of the search key for @completion to be at least
1122  * @length. This is useful for long lists, where completing using a small
1123  * key takes a lot of time and will come up with meaningless results anyway
1124  * (ie, a too large dataset).
1125  *
1126  * Since: 2.4
1127  */
1128 void
1129 gtk_entry_completion_set_minimum_key_length (GtkEntryCompletion *completion,
1130                                              gint                length)
1131 {
1132   g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1133   g_return_if_fail (length >= 0);
1134
1135   if (completion->priv->minimum_key_length != length)
1136     {
1137       completion->priv->minimum_key_length = length;
1138      
1139       g_object_notify (G_OBJECT (completion), "minimum-key-length");
1140     }
1141 }
1142
1143 /**
1144  * gtk_entry_completion_get_minimum_key_length:
1145  * @completion: A #GtkEntryCompletion.
1146  *
1147  * Returns the minimum key length as set for @completion.
1148  *
1149  * Return value: The currently used minimum key length.
1150  *
1151  * Since: 2.4
1152  */
1153 gint
1154 gtk_entry_completion_get_minimum_key_length (GtkEntryCompletion *completion)
1155 {
1156   g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), 0);
1157
1158   return completion->priv->minimum_key_length;
1159 }
1160
1161 /**
1162  * gtk_entry_completion_complete:
1163  * @completion: A #GtkEntryCompletion.
1164  *
1165  * Requests a completion operation, or in other words a refiltering of the
1166  * current list with completions, using the current key. The completion list
1167  * view will be updated accordingly.
1168  *
1169  * Since: 2.4
1170  */
1171 void
1172 gtk_entry_completion_complete (GtkEntryCompletion *completion)
1173 {
1174   gchar *tmp;
1175
1176   g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1177
1178   if (!completion->priv->filter_model)
1179     return;
1180   
1181   g_free (completion->priv->case_normalized_key);
1182
1183   tmp = g_utf8_normalize (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)),
1184                           -1, G_NORMALIZE_ALL);
1185   completion->priv->case_normalized_key = g_utf8_casefold (tmp, -1);
1186   g_free (tmp);
1187
1188   gtk_tree_model_filter_refilter (completion->priv->filter_model);
1189
1190   if (gtk_widget_get_visible (completion->priv->popup_window))
1191     _gtk_entry_completion_resize_popup (completion);
1192 }
1193
1194 static void
1195 gtk_entry_completion_insert_action (GtkEntryCompletion *completion,
1196                                     gint                index,
1197                                     const gchar        *string,
1198                                     gboolean            markup)
1199 {
1200   GtkTreeIter iter;
1201
1202   gtk_list_store_insert (completion->priv->actions, &iter, index);
1203   gtk_list_store_set (completion->priv->actions, &iter,
1204                       0, string,
1205                       1, markup,
1206                       -1);
1207
1208   if (!completion->priv->action_view->parent)
1209     {
1210       GtkTreePath *path = gtk_tree_path_new_from_indices (0, -1);
1211
1212       gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
1213                                 path, NULL, FALSE);
1214       gtk_tree_path_free (path);
1215
1216       gtk_box_pack_start (GTK_BOX (completion->priv->vbox),
1217                           completion->priv->action_view, FALSE, FALSE, 0);
1218       gtk_widget_show (completion->priv->action_view);
1219     }
1220 }
1221
1222 /**
1223  * gtk_entry_completion_insert_action_text:
1224  * @completion: A #GtkEntryCompletion.
1225  * @index_: The index of the item to insert.
1226  * @text: Text of the item to insert.
1227  *
1228  * Inserts an action in @completion's action item list at position @index_
1229  * with text @text. If you want the action item to have markup, use
1230  * gtk_entry_completion_insert_action_markup().
1231  *
1232  * Since: 2.4
1233  */
1234 void
1235 gtk_entry_completion_insert_action_text (GtkEntryCompletion *completion,
1236                                          gint                index_,
1237                                          const gchar        *text)
1238 {
1239   g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1240   g_return_if_fail (text != NULL);
1241
1242   gtk_entry_completion_insert_action (completion, index_, text, FALSE);
1243 }
1244
1245 /**
1246  * gtk_entry_completion_insert_action_markup:
1247  * @completion: A #GtkEntryCompletion.
1248  * @index_: The index of the item to insert.
1249  * @markup: Markup of the item to insert.
1250  *
1251  * Inserts an action in @completion's action item list at position @index_
1252  * with markup @markup.
1253  *
1254  * Since: 2.4
1255  */
1256 void
1257 gtk_entry_completion_insert_action_markup (GtkEntryCompletion *completion,
1258                                            gint                index_,
1259                                            const gchar        *markup)
1260 {
1261   g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1262   g_return_if_fail (markup != NULL);
1263
1264   gtk_entry_completion_insert_action (completion, index_, markup, TRUE);
1265 }
1266
1267 /**
1268  * gtk_entry_completion_delete_action:
1269  * @completion: A #GtkEntryCompletion.
1270  * @index_: The index of the item to Delete.
1271  *
1272  * Deletes the action at @index_ from @completion's action list.
1273  *
1274  * Since: 2.4
1275  */
1276 void
1277 gtk_entry_completion_delete_action (GtkEntryCompletion *completion,
1278                                     gint                index_)
1279 {
1280   GtkTreeIter iter;
1281
1282   g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1283   g_return_if_fail (index_ >= 0);
1284
1285   gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (completion->priv->actions),
1286                                  &iter, NULL, index_);
1287   gtk_list_store_remove (completion->priv->actions, &iter);
1288 }
1289
1290 /**
1291  * gtk_entry_completion_set_text_column:
1292  * @completion: A #GtkEntryCompletion.
1293  * @column: The column in the model of @completion to get strings from.
1294  *
1295  * Convenience function for setting up the most used case of this code: a
1296  * completion list with just strings. This function will set up @completion
1297  * to have a list displaying all (and just) strings in the completion list,
1298  * and to get those strings from @column in the model of @completion.
1299  *
1300  * This functions creates and adds a #GtkCellRendererText for the selected 
1301  * column. If you need to set the text column, but don't want the cell 
1302  * renderer, use g_object_set() to set the ::text_column property directly.
1303  * 
1304  * Since: 2.4
1305  */
1306 void
1307 gtk_entry_completion_set_text_column (GtkEntryCompletion *completion,
1308                                       gint                column)
1309 {
1310   GtkCellRenderer *cell;
1311
1312   g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1313   g_return_if_fail (column >= 0);
1314
1315   completion->priv->text_column = column;
1316
1317   cell = gtk_cell_renderer_text_new ();
1318   gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion),
1319                               cell, TRUE);
1320   gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (completion),
1321                                  cell,
1322                                  "text", column);
1323
1324   g_object_notify (G_OBJECT (completion), "text-column");
1325 }
1326
1327 /**
1328  * gtk_entry_completion_get_text_column:
1329  * @completion: a #GtkEntryCompletion
1330  * 
1331  * Returns the column in the model of @completion to get strings from.
1332  * 
1333  * Return value: the column containing the strings
1334  *
1335  * Since: 2.6
1336  **/
1337 gint
1338 gtk_entry_completion_get_text_column (GtkEntryCompletion *completion)
1339 {
1340   g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), -1);
1341
1342   return completion->priv->text_column;  
1343 }
1344
1345 /* private */
1346
1347 static gboolean
1348 gtk_entry_completion_list_enter_notify (GtkWidget        *widget,
1349                                         GdkEventCrossing *event,
1350                                         gpointer          data)
1351 {
1352   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
1353   
1354   return completion->priv->ignore_enter;
1355 }
1356
1357 static gboolean
1358 gtk_entry_completion_list_motion_notify (GtkWidget      *widget,
1359                                          GdkEventMotion *event,
1360                                          gpointer        data)
1361 {
1362   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
1363
1364   completion->priv->ignore_enter = FALSE;
1365   
1366   return FALSE;
1367 }
1368
1369
1370 /* some nasty size requisition */
1371 gboolean
1372 _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
1373 {
1374   gint x, y;
1375   gint matches, actions, items, height, x_border, y_border;
1376   GdkScreen *screen;
1377   gint monitor_num;
1378   gint vertical_separator;
1379   GdkRectangle monitor;
1380   GtkRequisition popup_req;
1381   GtkRequisition entry_req;
1382   GtkTreePath *path;
1383   gboolean above;
1384   gint width;
1385   GtkTreeViewColumn *action_column;
1386   gint action_height;
1387
1388   if (!completion->priv->entry->window)
1389     return FALSE;
1390
1391   gdk_window_get_origin (completion->priv->entry->window, &x, &y);
1392   _gtk_entry_get_borders (GTK_ENTRY (completion->priv->entry), &x_border, &y_border);
1393
1394   matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
1395   actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
1396   action_column  = gtk_tree_view_get_column (GTK_TREE_VIEW (completion->priv->action_view), 0);
1397
1398   gtk_tree_view_column_cell_get_size (completion->priv->column, NULL,
1399                                       NULL, NULL, NULL, &height);
1400   gtk_tree_view_column_cell_get_size (action_column, NULL,
1401                                       NULL, NULL, NULL, &action_height);
1402
1403   gtk_widget_style_get (GTK_WIDGET (completion->priv->tree_view),
1404                         "vertical-separator", &vertical_separator,
1405                         NULL);
1406
1407   height += vertical_separator;
1408   
1409   gtk_widget_realize (completion->priv->tree_view);
1410
1411   screen = gtk_widget_get_screen (GTK_WIDGET (completion->priv->entry));
1412   monitor_num = gdk_screen_get_monitor_at_window (screen, 
1413                                                   GTK_WIDGET (completion->priv->entry)->window);
1414   gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1415
1416   
1417
1418   if (y > monitor.height / 2)
1419     items = MIN (matches, (((monitor.y + y) - (actions * action_height)) / height) - 1);
1420   else
1421     items = MIN (matches, (((monitor.height - y) - (actions * action_height)) / height) - 1);
1422
1423   if (items <= 0)
1424     gtk_widget_hide (completion->priv->scrolled_window);
1425   else
1426     gtk_widget_show (completion->priv->scrolled_window);
1427
1428   if (completion->priv->popup_set_width)
1429     width = MIN (completion->priv->entry->allocation.width, monitor.width) - 2 * x_border;
1430   else
1431     width = -1;
1432
1433   gtk_tree_view_columns_autosize (GTK_TREE_VIEW (completion->priv->tree_view));
1434   gtk_widget_set_size_request (completion->priv->tree_view, width, items * height);
1435
1436   if (actions)
1437     {
1438       gtk_widget_show (completion->priv->action_view);
1439       gtk_widget_set_size_request (completion->priv->action_view, width, -1);
1440     }
1441   else
1442     gtk_widget_hide (completion->priv->action_view);
1443
1444   gtk_widget_size_request (completion->priv->popup_window, &popup_req);
1445   gtk_widget_size_request (completion->priv->entry, &entry_req);
1446   
1447   if (x < monitor.x)
1448     x = monitor.x;
1449   else if (x + popup_req.width > monitor.x + monitor.width)
1450     x = monitor.x + monitor.width - popup_req.width;
1451   
1452   if (y + entry_req.height + popup_req.height <= monitor.y + monitor.height ||
1453       y - monitor.y < (monitor.y + monitor.height) - (y + entry_req.height))
1454     {
1455       y += entry_req.height;
1456       above = FALSE;
1457     }
1458   else
1459     {
1460       y -= popup_req.height;
1461       above = TRUE;
1462     }
1463   
1464   if (matches > 0) 
1465     {
1466       path = gtk_tree_path_new_from_indices (above ? matches - 1 : 0, -1);
1467       gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (completion->priv->tree_view), path, 
1468                                     NULL, FALSE, 0.0, 0.0);
1469       gtk_tree_path_free (path);
1470     }
1471
1472   gtk_window_move (GTK_WINDOW (completion->priv->popup_window), x, y);
1473
1474   return above;
1475 }
1476
1477 void
1478 _gtk_entry_completion_popup (GtkEntryCompletion *completion,
1479                              GdkDevice          *device)
1480 {
1481   GtkTreeViewColumn *column;
1482   GList *renderers;
1483   GtkWidget *toplevel;
1484
1485   if (gtk_widget_get_mapped (completion->priv->popup_window))
1486     return;
1487
1488   if (!gtk_widget_get_mapped (completion->priv->entry))
1489     return;
1490
1491   if (!gtk_widget_has_focus (completion->priv->entry))
1492     return;
1493
1494   if (completion->priv->grab_device)
1495     return;
1496
1497   completion->priv->ignore_enter = TRUE;
1498     
1499   column = gtk_tree_view_get_column (GTK_TREE_VIEW (completion->priv->action_view), 0);
1500   renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
1501   gtk_widget_ensure_style (completion->priv->tree_view);
1502   g_object_set (GTK_CELL_RENDERER (renderers->data), "cell-background-gdk",
1503                 &completion->priv->tree_view->style->bg[GTK_STATE_NORMAL],
1504                 NULL);
1505   g_list_free (renderers);
1506
1507   gtk_widget_show_all (completion->priv->vbox);
1508
1509   /* default on no match */
1510   completion->priv->current_selected = -1;
1511
1512   _gtk_entry_completion_resize_popup (completion);
1513
1514   toplevel = gtk_widget_get_toplevel (completion->priv->entry);
1515   if (GTK_IS_WINDOW (toplevel))
1516     gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)), 
1517                                  GTK_WINDOW (completion->priv->popup_window));
1518
1519   /* prevent the first row being focused */
1520   gtk_widget_grab_focus (completion->priv->tree_view);
1521
1522   gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
1523   gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
1524
1525   gtk_window_set_screen (GTK_WINDOW (completion->priv->popup_window),
1526                          gtk_widget_get_screen (completion->priv->entry));
1527
1528   gtk_widget_show (completion->priv->popup_window);
1529
1530   gtk_device_grab_add (completion->priv->popup_window, device, TRUE);
1531   gdk_device_grab (device, completion->priv->popup_window->window,
1532                    GDK_OWNERSHIP_WINDOW, TRUE,
1533                    GDK_BUTTON_PRESS_MASK |
1534                    GDK_BUTTON_RELEASE_MASK |
1535                    GDK_POINTER_MOTION_MASK,
1536                    NULL, GDK_CURRENT_TIME);
1537
1538   completion->priv->grab_device = device;
1539 }
1540
1541 void
1542 _gtk_entry_completion_popdown (GtkEntryCompletion *completion)
1543 {
1544   if (!gtk_widget_get_mapped (completion->priv->popup_window))
1545     return;
1546
1547   completion->priv->ignore_enter = FALSE;
1548
1549   if (completion->priv->grab_device)
1550     {
1551       gdk_device_ungrab (completion->priv->grab_device, GDK_CURRENT_TIME);
1552       gtk_device_grab_remove (completion->priv->popup_window,
1553                               completion->priv->grab_device);
1554       completion->priv->grab_device = NULL;
1555     }
1556
1557   gtk_widget_hide (completion->priv->popup_window);
1558 }
1559
1560 static gboolean 
1561 gtk_entry_completion_match_selected (GtkEntryCompletion *completion,
1562                                      GtkTreeModel       *model,
1563                                      GtkTreeIter        *iter)
1564 {
1565   gchar *str = NULL;
1566
1567   gtk_tree_model_get (model, iter, completion->priv->text_column, &str, -1);
1568   gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), str ? str : "");
1569   
1570   /* move cursor to the end */
1571   gtk_editable_set_position (GTK_EDITABLE (completion->priv->entry), -1);
1572   
1573   g_free (str);
1574
1575   return TRUE;
1576 }
1577
1578 static gboolean
1579 gtk_entry_completion_cursor_on_match (GtkEntryCompletion *completion,
1580                                       GtkTreeModel       *model,
1581                                       GtkTreeIter        *iter)
1582 {
1583   gtk_entry_completion_insert_completion (completion, model, iter);
1584
1585   return TRUE;
1586 }
1587
1588 static gchar *
1589 gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion)
1590 {
1591   GtkTreeIter iter;
1592   gchar *prefix = NULL;
1593   gboolean valid;
1594   const gchar *key;
1595
1596   if (completion->priv->text_column < 0)
1597     return NULL;
1598
1599   key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry));
1600
1601   valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (completion->priv->filter_model),
1602                                          &iter);
1603   
1604   while (valid)
1605     {
1606       gchar *text;
1607       
1608       gtk_tree_model_get (GTK_TREE_MODEL (completion->priv->filter_model),
1609                           &iter, completion->priv->text_column, &text,
1610                           -1);
1611
1612       if (text && g_str_has_prefix (text, key))
1613         {
1614           if (!prefix)
1615             prefix = g_strdup (text);
1616           else
1617             {
1618               gchar *p = prefix;
1619               gchar *q = text;
1620               
1621               while (*p && *p == *q)
1622                 {
1623                   p++;
1624                   q++;
1625                 }
1626               
1627               *p = '\0';
1628               
1629               if (p > prefix)
1630                 {
1631                   /* strip a partial multibyte character */
1632                   q = g_utf8_find_prev_char (prefix, p);
1633                   switch (g_utf8_get_char_validated (q, p - q))
1634                     {
1635                     case (gunichar)-2:
1636                     case (gunichar)-1:
1637                       *q = 0;
1638                     default: ;
1639                     }
1640                 }
1641             }
1642         }
1643       
1644       g_free (text);
1645       valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (completion->priv->filter_model),
1646                                         &iter);
1647     }
1648
1649   return prefix;
1650 }
1651
1652
1653 static gboolean
1654 gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion,
1655                                          const gchar        *prefix)
1656 {
1657   if (prefix)
1658     {
1659       gint key_len;
1660       gint prefix_len;
1661       const gchar *key;
1662
1663       prefix_len = g_utf8_strlen (prefix, -1);
1664
1665       key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry));
1666       key_len = g_utf8_strlen (key, -1);
1667
1668       if (prefix_len > key_len)
1669         {
1670           gint pos = prefix_len;
1671
1672           gtk_editable_insert_text (GTK_EDITABLE (completion->priv->entry),
1673                                     prefix + strlen (key), -1, &pos);
1674           gtk_editable_select_region (GTK_EDITABLE (completion->priv->entry),
1675                                       key_len, prefix_len);
1676
1677           completion->priv->has_completion = TRUE;
1678         }
1679     }
1680
1681   return TRUE;
1682 }
1683
1684 /**
1685  * gtk_entry_completion_get_completion_prefix:
1686  * @completion: a #GtkEntryCompletion
1687  * 
1688  * Get the original text entered by the user that triggered
1689  * the completion or %NULL if there's no completion ongoing.
1690  * 
1691  * Returns: the prefix for the current completion
1692  * 
1693  * Since: 2.12
1694  **/
1695 const gchar*
1696 gtk_entry_completion_get_completion_prefix (GtkEntryCompletion *completion)
1697 {
1698   g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
1699
1700   return completion->priv->completion_prefix;
1701 }
1702
1703 static void
1704 gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
1705                                              const gchar *text)
1706 {
1707   GtkEntryCompletionPrivate *priv = completion->priv;
1708   gint len;
1709
1710   priv = completion->priv;
1711
1712   if (priv->changed_id > 0)
1713     g_signal_handler_block (priv->entry, priv->changed_id);
1714
1715   if (priv->insert_text_id > 0)
1716     g_signal_handler_block (priv->entry, priv->insert_text_id);
1717
1718   gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
1719
1720   len = strlen (priv->completion_prefix);
1721   gtk_editable_select_region (GTK_EDITABLE (priv->entry), len, -1);
1722
1723   if (priv->changed_id > 0)
1724     g_signal_handler_unblock (priv->entry, priv->changed_id);
1725
1726   if (priv->insert_text_id > 0)
1727     g_signal_handler_unblock (priv->entry, priv->insert_text_id);
1728 }
1729
1730 static gboolean
1731 gtk_entry_completion_insert_completion (GtkEntryCompletion *completion,
1732                                         GtkTreeModel       *model,
1733                                         GtkTreeIter        *iter)
1734 {
1735   gchar *str = NULL;
1736
1737   if (completion->priv->text_column < 0)
1738     return FALSE;
1739
1740   gtk_tree_model_get (model, iter,
1741                       completion->priv->text_column, &str,
1742                       -1);
1743
1744   gtk_entry_completion_insert_completion_text (completion, str);
1745
1746   g_free (str);
1747
1748   return TRUE;
1749 }
1750
1751 /**
1752  * gtk_entry_completion_insert_prefix:
1753  * @completion: a #GtkEntryCompletion
1754  * 
1755  * Requests a prefix insertion. 
1756  * 
1757  * Since: 2.6
1758  **/
1759
1760 void
1761 gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion)
1762 {
1763   gboolean done;
1764   gchar *prefix;
1765
1766   if (completion->priv->insert_text_id > 0)
1767     g_signal_handler_block (completion->priv->entry,
1768                             completion->priv->insert_text_id);
1769
1770   prefix = gtk_entry_completion_compute_prefix (completion);
1771   if (prefix)
1772     {
1773       g_signal_emit (completion, entry_completion_signals[INSERT_PREFIX],
1774                      0, prefix, &done);
1775       g_free (prefix);
1776     }
1777
1778   if (completion->priv->insert_text_id > 0)
1779     g_signal_handler_unblock (completion->priv->entry,
1780                               completion->priv->insert_text_id);
1781 }
1782
1783 /**
1784  * gtk_entry_completion_set_inline_completion:
1785  * @completion: a #GtkEntryCompletion
1786  * @inline_completion: %TRUE to do inline completion
1787  * 
1788  * Sets whether the common prefix of the possible completions should
1789  * be automatically inserted in the entry.
1790  * 
1791  * Since: 2.6
1792  **/
1793 void 
1794 gtk_entry_completion_set_inline_completion (GtkEntryCompletion *completion,
1795                                             gboolean            inline_completion)
1796 {
1797   g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1798   
1799   inline_completion = inline_completion != FALSE;
1800
1801   if (completion->priv->inline_completion != inline_completion)
1802     {
1803       completion->priv->inline_completion = inline_completion;
1804
1805       g_object_notify (G_OBJECT (completion), "inline-completion");
1806     }
1807 }
1808
1809 /**
1810  * gtk_entry_completion_get_inline_completion:
1811  * @completion: a #GtkEntryCompletion
1812  * 
1813  * Returns whether the common prefix of the possible completions should
1814  * be automatically inserted in the entry.
1815  * 
1816  * Return value: %TRUE if inline completion is turned on
1817  * 
1818  * Since: 2.6
1819  **/
1820 gboolean
1821 gtk_entry_completion_get_inline_completion (GtkEntryCompletion *completion)
1822 {
1823   g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), FALSE);
1824   
1825   return completion->priv->inline_completion;
1826 }
1827
1828 /**
1829  * gtk_entry_completion_set_popup_completion:
1830  * @completion: a #GtkEntryCompletion
1831  * @popup_completion: %TRUE to do popup completion
1832  * 
1833  * Sets whether the completions should be presented in a popup window.
1834  * 
1835  * Since: 2.6
1836  **/
1837 void 
1838 gtk_entry_completion_set_popup_completion (GtkEntryCompletion *completion,
1839                                            gboolean            popup_completion)
1840 {
1841   g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1842   
1843   popup_completion = popup_completion != FALSE;
1844
1845   if (completion->priv->popup_completion != popup_completion)
1846     {
1847       completion->priv->popup_completion = popup_completion;
1848
1849       g_object_notify (G_OBJECT (completion), "popup-completion");
1850     }
1851 }
1852
1853
1854 /**
1855  * gtk_entry_completion_get_popup_completion:
1856  * @completion: a #GtkEntryCompletion
1857  * 
1858  * Returns whether the completions should be presented in a popup window.
1859  * 
1860  * Return value: %TRUE if popup completion is turned on
1861  * 
1862  * Since: 2.6
1863  **/
1864 gboolean
1865 gtk_entry_completion_get_popup_completion (GtkEntryCompletion *completion)
1866 {
1867   g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1868   
1869   return completion->priv->popup_completion;
1870 }
1871
1872 /**
1873  * gtk_entry_completion_set_popup_set_width:
1874  * @completion: a #GtkEntryCompletion
1875  * @popup_set_width: %TRUE to make the width of the popup the same as the entry
1876  *
1877  * Sets whether the completion popup window will be resized to be the same
1878  * width as the entry.
1879  *
1880  * Since: 2.8
1881  */
1882 void 
1883 gtk_entry_completion_set_popup_set_width (GtkEntryCompletion *completion,
1884                                           gboolean            popup_set_width)
1885 {
1886   g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1887   
1888   popup_set_width = popup_set_width != FALSE;
1889
1890   if (completion->priv->popup_set_width != popup_set_width)
1891     {
1892       completion->priv->popup_set_width = popup_set_width;
1893
1894       g_object_notify (G_OBJECT (completion), "popup-set-width");
1895     }
1896 }
1897
1898 /**
1899  * gtk_entry_completion_get_popup_set_width:
1900  * @completion: a #GtkEntryCompletion
1901  * 
1902  * Returns whether the  completion popup window will be resized to the 
1903  * width of the entry.
1904  * 
1905  * Return value: %TRUE if the popup window will be resized to the width of 
1906  *   the entry
1907  * 
1908  * Since: 2.8
1909  **/
1910 gboolean
1911 gtk_entry_completion_get_popup_set_width (GtkEntryCompletion *completion)
1912 {
1913   g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1914   
1915   return completion->priv->popup_set_width;
1916 }
1917
1918
1919 /**
1920  * gtk_entry_completion_set_popup_single_match:
1921  * @completion: a #GtkEntryCompletion
1922  * @popup_single_match: %TRUE if the popup should appear even for a single
1923  *   match
1924  *
1925  * Sets whether the completion popup window will appear even if there is
1926  * only a single match. You may want to set this to %FALSE if you
1927  * are using <link linkend="GtkEntryCompletion--inline-completion">inline
1928  * completion</link>.
1929  *
1930  * Since: 2.8
1931  */
1932 void 
1933 gtk_entry_completion_set_popup_single_match (GtkEntryCompletion *completion,
1934                                              gboolean            popup_single_match)
1935 {
1936   g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1937   
1938   popup_single_match = popup_single_match != FALSE;
1939
1940   if (completion->priv->popup_single_match != popup_single_match)
1941     {
1942       completion->priv->popup_single_match = popup_single_match;
1943
1944       g_object_notify (G_OBJECT (completion), "popup-single-match");
1945     }
1946 }
1947
1948 /**
1949  * gtk_entry_completion_get_popup_single_match:
1950  * @completion: a #GtkEntryCompletion
1951  * 
1952  * Returns whether the completion popup window will appear even if there is
1953  * only a single match. 
1954  * 
1955  * Return value: %TRUE if the popup window will appear regardless of the
1956  *    number of matches.
1957  * 
1958  * Since: 2.8
1959  **/
1960 gboolean
1961 gtk_entry_completion_get_popup_single_match (GtkEntryCompletion *completion)
1962 {
1963   g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
1964   
1965   return completion->priv->popup_single_match;
1966 }
1967
1968 /**
1969  * gtk_entry_completion_set_inline_selection:
1970  * @completion: a #GtkEntryCompletion
1971  * @inline_selection: %TRUE to do inline selection
1972  * 
1973  * Sets whether it is possible to cycle through the possible completions
1974  * inside the entry.
1975  * 
1976  * Since: 2.12
1977  **/
1978 void
1979 gtk_entry_completion_set_inline_selection (GtkEntryCompletion *completion,
1980                                            gboolean inline_selection)
1981 {
1982   g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
1983
1984   inline_selection = inline_selection != FALSE;
1985
1986   if (completion->priv->inline_selection != inline_selection)
1987     {
1988       completion->priv->inline_selection = inline_selection;
1989
1990       g_object_notify (G_OBJECT (completion), "inline-selection");
1991     }
1992 }
1993
1994 /**
1995  * gtk_entry_completion_get_inline_selection:
1996  * @completion: a #GtkEntryCompletion
1997  *
1998  * Returns %TRUE if inline-selection mode is turned on.
1999  *
2000  * Returns: %TRUE if inline-selection mode is on
2001  *
2002  * Since: 2.12
2003  **/
2004 gboolean
2005 gtk_entry_completion_get_inline_selection (GtkEntryCompletion *completion)
2006 {
2007   g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), FALSE);
2008
2009   return completion->priv->inline_selection;
2010 }