]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkentrycompletion.c
Updated Norwegian bokmål translation
[~andy/gtk] / gtk / gtkentrycompletion.c
index d4c51b4f494f9b97aa79c5004c33d1012539420b..3bd43fb06997060120adbc7f3c17b831c8eb31b1 100644 (file)
@@ -17,7 +17,7 @@
  * Boston, MA 02111-1307, USA.
  */
 
-#include <config.h>
+#include "config.h"
 #include "gtkentrycompletion.h"
 #include "gtkentryprivate.h"
 #include "gtkcelllayout.h"
 #include "gtkwindow.h"
 #include "gtkentry.h"
 #include "gtkmain.h"
-#include "gtksignal.h"
 #include "gtkmarshalers.h"
 
 #include "gtkprivate.h"
-#include "gtkalias.h"
 
 #include <string.h>
 
@@ -47,6 +45,7 @@ enum
   INSERT_PREFIX,
   MATCH_SELECTED,
   ACTION_ACTIVATED,
+  CURSOR_ON_MATCH,
   LAST_SIGNAL
 };
 
@@ -60,88 +59,103 @@ enum
   PROP_INLINE_COMPLETION,
   PROP_POPUP_COMPLETION,
   PROP_POPUP_SET_WIDTH,
-  PROP_POPUP_SINGLE_MATCH
+  PROP_POPUP_SINGLE_MATCH,
+  PROP_INLINE_SELECTION
 };
 
-#define GTK_ENTRY_COMPLETION_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY_COMPLETION, GtkEntryCompletionPrivate))
-
-static void     gtk_entry_completion_cell_layout_init    (GtkCellLayoutIface      *iface);
-static void     gtk_entry_completion_set_property        (GObject                 *object,
-                                                          guint                    prop_id,
-                                                          const GValue            *value,
-                                                          GParamSpec              *pspec);
-static void     gtk_entry_completion_get_property        (GObject                 *object,
-                                                          guint                    prop_id,
-                                                          GValue                  *value,
-                                                          GParamSpec              *pspec);
-static void     gtk_entry_completion_finalize            (GObject                 *object);
-
-static void     gtk_entry_completion_pack_start          (GtkCellLayout           *cell_layout,
-                                                          GtkCellRenderer         *cell,
-                                                          gboolean                 expand);
-static void     gtk_entry_completion_pack_end            (GtkCellLayout           *cell_layout,
-                                                          GtkCellRenderer         *cell,
-                                                          gboolean                 expand);
-static void     gtk_entry_completion_clear               (GtkCellLayout           *cell_layout);
-static void     gtk_entry_completion_add_attribute       (GtkCellLayout           *cell_layout,
-                                                          GtkCellRenderer         *cell,
-                                                          const char              *attribute,
-                                                          gint                     column);
-static void     gtk_entry_completion_set_cell_data_func  (GtkCellLayout           *cell_layout,
-                                                          GtkCellRenderer         *cell,
-                                                          GtkCellLayoutDataFunc    func,
-                                                          gpointer                 func_data,
-                                                          GDestroyNotify           destroy);
-static void     gtk_entry_completion_clear_attributes    (GtkCellLayout           *cell_layout,
-                                                          GtkCellRenderer         *cell);
-static void     gtk_entry_completion_reorder             (GtkCellLayout           *cell_layout,
-                                                          GtkCellRenderer         *cell,
-                                                          gint                     position);
-
-static gboolean gtk_entry_completion_visible_func        (GtkTreeModel            *model,
-                                                          GtkTreeIter             *iter,
-                                                          gpointer                 data);
-static gboolean gtk_entry_completion_popup_key_event     (GtkWidget               *widget,
-                                                          GdkEventKey             *event,
-                                                          gpointer                 user_data);
-static gboolean gtk_entry_completion_popup_button_press  (GtkWidget               *widget,
-                                                          GdkEventButton          *event,
-                                                          gpointer                 user_data);
-static gboolean gtk_entry_completion_list_button_press   (GtkWidget               *widget,
-                                                          GdkEventButton          *event,
-                                                          gpointer                 user_data);
-static gboolean gtk_entry_completion_action_button_press (GtkWidget               *widget,
-                                                          GdkEventButton          *event,
-                                                          gpointer                 user_data);
-static void     gtk_entry_completion_selection_changed   (GtkTreeSelection        *selection,
-                                                          gpointer                 data);
-static gboolean        gtk_entry_completion_list_enter_notify   (GtkWidget               *widget,
-                                                         GdkEventCrossing        *event,
-                                                         gpointer                 data);
-static gboolean gtk_entry_completion_list_motion_notify         (GtkWidget               *widget,
-                                                         GdkEventMotion          *event,
-                                                         gpointer                 data);
-static void     gtk_entry_completion_insert_action       (GtkEntryCompletion      *completion,
-                                                          gint                     index,
-                                                          const gchar             *string,
-                                                          gboolean                 markup);
-static void     gtk_entry_completion_action_data_func    (GtkTreeViewColumn       *tree_column,
-                                                          GtkCellRenderer         *cell,
-                                                          GtkTreeModel            *model,
-                                                          GtkTreeIter             *iter,
-                                                          gpointer                 data);
+
+static void                                                             gtk_entry_completion_cell_layout_init    (GtkCellLayoutIface      *iface);
+static void     gtk_entry_completion_set_property        (GObject      *object,
+                                                          guint         prop_id,
+                                                          const GValue *value,
+                                                          GParamSpec   *pspec);
+static void     gtk_entry_completion_get_property        (GObject      *object,
+                                                          guint         prop_id,
+                                                          GValue       *value,
+                                                          GParamSpec   *pspec);
+static void                                                             gtk_entry_completion_finalize            (GObject                 *object);
+
+static void     gtk_entry_completion_pack_start          (GtkCellLayout         *cell_layout,
+                                                          GtkCellRenderer       *cell,
+                                                          gboolean               expand);
+static void     gtk_entry_completion_pack_end            (GtkCellLayout         *cell_layout,
+                                                          GtkCellRenderer       *cell,
+                                                          gboolean               expand);
+static void                                                                      gtk_entry_completion_clear               (GtkCellLayout           *cell_layout);
+static void     gtk_entry_completion_add_attribute       (GtkCellLayout         *cell_layout,
+                                                          GtkCellRenderer       *cell,
+                                                          const char            *attribute,
+                                                          gint                   column);
+static void     gtk_entry_completion_set_cell_data_func  (GtkCellLayout         *cell_layout,
+                                                          GtkCellRenderer       *cell,
+                                                          GtkCellLayoutDataFunc  func,
+                                                          gpointer               func_data,
+                                                          GDestroyNotify         destroy);
+static void     gtk_entry_completion_clear_attributes    (GtkCellLayout         *cell_layout,
+                                                          GtkCellRenderer       *cell);
+static void     gtk_entry_completion_reorder             (GtkCellLayout         *cell_layout,
+                                                          GtkCellRenderer       *cell,
+                                                          gint                   position);
+static GList *  gtk_entry_completion_get_cells           (GtkCellLayout         *cell_layout);
+
+static gboolean gtk_entry_completion_visible_func        (GtkTreeModel       *model,
+                                                          GtkTreeIter        *iter,
+                                                          gpointer            data);
+static gboolean gtk_entry_completion_popup_key_event     (GtkWidget          *widget,
+                                                          GdkEventKey        *event,
+                                                          gpointer            user_data);
+static gboolean gtk_entry_completion_popup_button_press  (GtkWidget          *widget,
+                                                          GdkEventButton     *event,
+                                                          gpointer            user_data);
+static gboolean gtk_entry_completion_list_button_press   (GtkWidget          *widget,
+                                                          GdkEventButton     *event,
+                                                          gpointer            user_data);
+static gboolean gtk_entry_completion_action_button_press (GtkWidget          *widget,
+                                                          GdkEventButton     *event,
+                                                          gpointer            user_data);
+static void     gtk_entry_completion_selection_changed   (GtkTreeSelection   *selection,
+                                                          gpointer            data);
+static gboolean        gtk_entry_completion_list_enter_notify   (GtkWidget          *widget,
+                                                         GdkEventCrossing   *event,
+                                                         gpointer            data);
+static gboolean gtk_entry_completion_list_motion_notify         (GtkWidget          *widget,
+                                                         GdkEventMotion     *event,
+                                                         gpointer            data);
+static void     gtk_entry_completion_insert_action       (GtkEntryCompletion *completion,
+                                                          gint                index,
+                                                          const gchar        *string,
+                                                          gboolean            markup);
+static void     gtk_entry_completion_action_data_func    (GtkTreeViewColumn  *tree_column,
+                                                          GtkCellRenderer    *cell,
+                                                          GtkTreeModel       *model,
+                                                          GtkTreeIter        *iter,
+                                                          gpointer            data);
 
 static gboolean gtk_entry_completion_match_selected      (GtkEntryCompletion *completion,
                                                          GtkTreeModel       *model,
                                                          GtkTreeIter        *iter);
 static gboolean gtk_entry_completion_real_insert_prefix  (GtkEntryCompletion *completion,
                                                          const gchar        *prefix);
+static gboolean gtk_entry_completion_cursor_on_match     (GtkEntryCompletion *completion,
+                                                         GtkTreeModel       *model,
+                                                         GtkTreeIter        *iter);
+static gboolean gtk_entry_completion_insert_completion   (GtkEntryCompletion *completion,
+                                                          GtkTreeModel       *model,
+                                                          GtkTreeIter        *iter);
+static void     gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
+                                                             const gchar *text);
 
 static guint entry_completion_signals[LAST_SIGNAL] = { 0 };
 
+/* GtkBuildable */
+static void     gtk_entry_completion_buildable_init      (GtkBuildableIface  *iface);
+
 G_DEFINE_TYPE_WITH_CODE (GtkEntryCompletion, gtk_entry_completion, G_TYPE_OBJECT,
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
-                                               gtk_entry_completion_cell_layout_init))
+                                               gtk_entry_completion_cell_layout_init)
+                        G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+                                               gtk_entry_completion_buildable_init))
+
 
 static void
 gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
@@ -156,27 +170,28 @@ gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
 
   klass->match_selected = gtk_entry_completion_match_selected;
   klass->insert_prefix = gtk_entry_completion_real_insert_prefix;
+  klass->cursor_on_match = gtk_entry_completion_cursor_on_match;
 
   /**
    * GtkEntryCompletion::insert-prefix:
    * @widget: the object which received the signal
    * @prefix: the common prefix of all possible completions
-   * 
-   * Gets emitted when the inline autocompletion is triggered. 
-   * The default behaviour is to make the entry display the 
+   *
+   * Gets emitted when the inline autocompletion is triggered.
+   * The default behaviour is to make the entry display the
    * whole prefix and select the newly inserted part.
    *
    * Applications may connect to this signal in order to insert only a
    * smaller part of the @prefix into the entry - e.g. the entry used in
-   * the #GtkFileChooser inserts only the part of the prefix up to the 
+   * the #GtkFileChooser inserts only the part of the prefix up to the
    * next '/'.
    *
    * Return value: %TRUE if the signal has been handled
-   * 
+   *
    * Since: 2.6
-   */ 
+   */
   entry_completion_signals[INSERT_PREFIX] =
-    g_signal_new (I_("insert_prefix"),
+    g_signal_new (I_("insert-prefix"),
                   G_TYPE_FROM_CLASS (klass),
                   G_SIGNAL_RUN_LAST,
                   G_STRUCT_OFFSET (GtkEntryCompletionClass, insert_prefix),
@@ -190,18 +205,18 @@ gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
    * @widget: the object which received the signal
    * @model: the #GtkTreeModel containing the matches
    * @iter: a #GtkTreeIter positioned at the selected match
-   * 
-   * Gets emitted when a match from the list is selected. 
-   * The default behaviour is to replace the contents of the 
-   * entry with the contents of the text column in the row 
+   *
+   * Gets emitted when a match from the list is selected.
+   * The default behaviour is to replace the contents of the
+   * entry with the contents of the text column in the row
    * pointed to by @iter.
    *
    * Return value: %TRUE if the signal has been handled
-   * 
+   *
    * Since: 2.4
-   */ 
+   */
   entry_completion_signals[MATCH_SELECTED] =
-    g_signal_new (I_("match_selected"),
+    g_signal_new (I_("match-selected"),
                   G_TYPE_FROM_CLASS (klass),
                   G_SIGNAL_RUN_LAST,
                   G_STRUCT_OFFSET (GtkEntryCompletionClass, match_selected),
@@ -210,7 +225,33 @@ gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
                   G_TYPE_BOOLEAN, 2,
                   GTK_TYPE_TREE_MODEL,
                   GTK_TYPE_TREE_ITER);
-                 
+
+  /**
+   * GtkEntryCompletion::cursor-on-match:
+   * @widget: the object which received the signal
+   * @model: the #GtkTreeModel containing the matches
+   * @iter: a #GtkTreeIter positioned at the selected match
+   *
+   * Gets emitted when a match from the cursor is on a match
+   * of the list. The default behaviour is to replace the contents
+   * of the entry with the contents of the text column in the row
+   * pointed to by @iter.
+   *
+   * Return value: %TRUE if the signal has been handled
+   *
+   * Since: 2.12
+   */
+  entry_completion_signals[CURSOR_ON_MATCH] =
+    g_signal_new (I_("cursor-on-match"),
+                 G_TYPE_FROM_CLASS (klass),
+                 G_SIGNAL_RUN_LAST,
+                 G_STRUCT_OFFSET (GtkEntryCompletionClass, cursor_on_match),
+                 _gtk_boolean_handled_accumulator, NULL,
+                 _gtk_marshal_BOOLEAN__OBJECT_BOXED,
+                 G_TYPE_BOOLEAN, 2,
+                 GTK_TYPE_TREE_MODEL,
+                 GTK_TYPE_TREE_ITER);
+
   /**
    * GtkEntryCompletion::action-activated:
    * @widget: the object which received the signal
@@ -221,12 +262,12 @@ gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
    * Since: 2.4
    */
   entry_completion_signals[ACTION_ACTIVATED] =
-    g_signal_new (I_("action_activated"),
+    g_signal_new (I_("action-activated"),
                   G_TYPE_FROM_CLASS (klass),
                   G_SIGNAL_RUN_LAST,
                   G_STRUCT_OFFSET (GtkEntryCompletionClass, action_activated),
                   NULL, NULL,
-                  _gtk_marshal_NONE__INT,
+                  _gtk_marshal_VOID__INT,
                   G_TYPE_NONE, 1,
                   G_TYPE_INT);
 
@@ -250,6 +291,7 @@ gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
    * GtkEntryCompletion:text-column:
    *
    * The column of the model containing the strings.
+   * Note that the strings must be UTF-8.
    *
    * Since: 2.6
    */
@@ -330,10 +372,33 @@ gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
                                                         P_("If TRUE, the popup window will appear for a single match."),
                                                         TRUE,
                                                         GTK_PARAM_READWRITE));
+  /**
+   * GtkEntryCompletion:inline-selection:
+   * 
+   * Determines whether the possible completions on the popup
+   * will appear in the entry as you navigate through them.
+   
+   * Since: 2.12
+   */
+  g_object_class_install_property (object_class,
+                                  PROP_INLINE_SELECTION,
+                                  g_param_spec_boolean ("inline-selection",
+                                                        P_("Inline selection"),
+                                                        P_("Your description here"),
+                                                        FALSE,
+                                                        GTK_PARAM_READWRITE));
 
   g_type_class_add_private (object_class, sizeof (GtkEntryCompletionPrivate));
 }
 
+static void
+gtk_entry_completion_buildable_init (GtkBuildableIface *iface)
+{
+  iface->add_child = _gtk_cell_layout_buildable_add_child;
+  iface->custom_tag_start = _gtk_cell_layout_buildable_custom_tag_start;
+  iface->custom_tag_end = _gtk_cell_layout_buildable_custom_tag_end;
+}
+
 static void
 gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface)
 {
@@ -344,6 +409,7 @@ gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface)
   iface->set_cell_data_func = gtk_entry_completion_set_cell_data_func;
   iface->clear_attributes = gtk_entry_completion_clear_attributes;
   iface->reorder = gtk_entry_completion_reorder;
+  iface->get_cells = gtk_entry_completion_get_cells;
 }
 
 static void
@@ -355,7 +421,10 @@ gtk_entry_completion_init (GtkEntryCompletion *completion)
   GtkWidget *popup_frame;
 
   /* yes, also priv, need to keep the code readable */
-  priv = completion->priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (completion);
+  completion->priv = G_TYPE_INSTANCE_GET_PRIVATE (completion,
+                                                  GTK_TYPE_ENTRY_COMPLETION,
+                                                  GtkEntryCompletionPrivate);
+  priv = completion->priv;
 
   priv->minimum_key_length = 1;
   priv->text_column = -1;
@@ -364,20 +433,22 @@ gtk_entry_completion_init (GtkEntryCompletion *completion)
   priv->popup_completion = TRUE;
   priv->popup_set_width = TRUE;
   priv->popup_single_match = TRUE;
+  priv->inline_selection = FALSE;
 
   /* completions */
   priv->filter_model = NULL;
 
   priv->tree_view = gtk_tree_view_new ();
-  g_signal_connect (priv->tree_view, "button_press_event",
+  g_signal_connect (priv->tree_view, "button-press-event",
                     G_CALLBACK (gtk_entry_completion_list_button_press),
                     completion);
-  g_signal_connect (priv->tree_view, "enter_notify_event",
+  g_signal_connect (priv->tree_view, "enter-notify-event",
                    G_CALLBACK (gtk_entry_completion_list_enter_notify),
                    completion);
-  g_signal_connect (priv->tree_view, "motion_notify_event",
+  g_signal_connect (priv->tree_view, "motion-notify-event",
                    G_CALLBACK (gtk_entry_completion_list_motion_notify),
                    completion);
+
   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
   gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (priv->tree_view), TRUE);
 
@@ -400,7 +471,8 @@ gtk_entry_completion_init (GtkEntryCompletion *completion)
                                        GTK_SHADOW_NONE);
 
   /* a nasty hack to get the completions treeview to size nicely */
-  gtk_widget_set_size_request (GTK_SCROLLED_WINDOW (priv->scrolled_window)->vscrollbar, -1, 0);
+  gtk_widget_set_size_request (gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (priv->scrolled_window)),
+                               -1, 0);
 
   /* actions */
   priv->actions = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
@@ -408,13 +480,13 @@ gtk_entry_completion_init (GtkEntryCompletion *completion)
   priv->action_view =
     gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->actions));
   g_object_ref_sink (priv->action_view);
-  g_signal_connect (priv->action_view, "button_press_event",
+  g_signal_connect (priv->action_view, "button-press-event",
                     G_CALLBACK (gtk_entry_completion_action_button_press),
                     completion);
-  g_signal_connect (priv->action_view, "enter_notify_event",
+  g_signal_connect (priv->action_view, "enter-notify-event",
                    G_CALLBACK (gtk_entry_completion_list_enter_notify),
                    completion);
-  g_signal_connect (priv->action_view, "motion_notify_event",
+  g_signal_connect (priv->action_view, "motion-notify-event",
                    G_CALLBACK (gtk_entry_completion_list_motion_notify),
                    completion);
   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->action_view), FALSE);
@@ -435,13 +507,15 @@ gtk_entry_completion_init (GtkEntryCompletion *completion)
   /* pack it all */
   priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
   gtk_window_set_resizable (GTK_WINDOW (priv->popup_window), FALSE);
-  g_signal_connect (priv->popup_window, "key_press_event",
+  gtk_window_set_type_hint (GTK_WINDOW(priv->popup_window),
+                            GDK_WINDOW_TYPE_HINT_COMBO);
+  g_signal_connect (priv->popup_window, "key-press-event",
                     G_CALLBACK (gtk_entry_completion_popup_key_event),
                     completion);
-  g_signal_connect (priv->popup_window, "key_release_event",
+  g_signal_connect (priv->popup_window, "key-release-event",
                     G_CALLBACK (gtk_entry_completion_popup_key_event),
                     completion);
-  g_signal_connect (priv->popup_window, "button_press_event",
+  g_signal_connect (priv->popup_window, "button-press-event",
                     G_CALLBACK (gtk_entry_completion_popup_button_press),
                     completion);
 
@@ -505,6 +579,10 @@ gtk_entry_completion_set_property (GObject      *object,
        priv->popup_single_match = g_value_get_boolean (value);
         break;
 
+      case PROP_INLINE_SELECTION:
+        priv->inline_selection = g_value_get_boolean (value);
+        break;
+      
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -550,6 +628,10 @@ gtk_entry_completion_get_property (GObject    *object,
         g_value_set_boolean (value, gtk_entry_completion_get_popup_single_match (completion));
         break;
 
+      case PROP_INLINE_SELECTION:
+        g_value_set_boolean (value, gtk_entry_completion_get_inline_selection (completion));
+        break;
+
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -574,6 +656,7 @@ gtk_entry_completion_finalize (GObject *object)
     g_object_unref (priv->action_view);
 
   g_free (priv->case_normalized_key);
+  g_free (priv->completion_prefix);
 
   if (priv->popup_window)
     gtk_widget_destroy (priv->popup_window);
@@ -592,9 +675,7 @@ gtk_entry_completion_pack_start (GtkCellLayout   *cell_layout,
 {
   GtkEntryCompletionPrivate *priv;
 
-  g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
-
-  priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
+  priv = GTK_ENTRY_COMPLETION (cell_layout)->priv;
 
   gtk_tree_view_column_pack_start (priv->column, cell, expand);
 }
@@ -606,9 +687,7 @@ gtk_entry_completion_pack_end (GtkCellLayout   *cell_layout,
 {
   GtkEntryCompletionPrivate *priv;
 
-  g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
-
-  priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
+  priv = GTK_ENTRY_COMPLETION (cell_layout)->priv;
 
   gtk_tree_view_column_pack_end (priv->column, cell, expand);
 }
@@ -618,9 +697,7 @@ gtk_entry_completion_clear (GtkCellLayout *cell_layout)
 {
   GtkEntryCompletionPrivate *priv;
 
-  g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
-
-  priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
+  priv = GTK_ENTRY_COMPLETION (cell_layout)->priv;
 
   gtk_tree_view_column_clear (priv->column);
 }
@@ -633,9 +710,7 @@ gtk_entry_completion_add_attribute (GtkCellLayout   *cell_layout,
 {
   GtkEntryCompletionPrivate *priv;
 
-  g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
-
-  priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
+  priv = GTK_ENTRY_COMPLETION  (cell_layout)->priv;
 
   gtk_tree_view_column_add_attribute (priv->column, cell, attribute, column);
 }
@@ -649,9 +724,7 @@ gtk_entry_completion_set_cell_data_func (GtkCellLayout          *cell_layout,
 {
   GtkEntryCompletionPrivate *priv;
 
-  g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
-
-  priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
+  priv = GTK_ENTRY_COMPLETION (cell_layout)->priv;
 
   gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->column),
                                       cell, func, func_data, destroy);
@@ -663,9 +736,7 @@ gtk_entry_completion_clear_attributes (GtkCellLayout   *cell_layout,
 {
   GtkEntryCompletionPrivate *priv;
 
-  g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
-
-  priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
+  priv = GTK_ENTRY_COMPLETION (cell_layout)->priv;
 
   gtk_tree_view_column_clear_attributes (priv->column, cell);
 }
@@ -677,13 +748,21 @@ gtk_entry_completion_reorder (GtkCellLayout   *cell_layout,
 {
   GtkEntryCompletionPrivate *priv;
 
-  g_return_if_fail (GTK_IS_ENTRY_COMPLETION (cell_layout));
-
-  priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (cell_layout);
+  priv = GTK_ENTRY_COMPLETION (cell_layout)->priv;
 
   gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->column), cell, position);
 }
 
+static GList *
+gtk_entry_completion_get_cells (GtkCellLayout *cell_layout)
+{
+  GtkEntryCompletionPrivate *priv;
+
+  priv = GTK_ENTRY_COMPLETION (cell_layout)->priv;
+
+  return gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (priv->column));
+}
+
 /* all those callbacks */
 static gboolean
 gtk_entry_completion_default_completion_func (GtkEntryCompletion *completion,
@@ -757,7 +836,7 @@ gtk_entry_completion_popup_key_event (GtkWidget   *widget,
 {
   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
 
-  if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
+  if (!gtk_widget_get_mapped (completion->priv->popup_window))
     return FALSE;
 
   /* propagate event to the entry */
@@ -773,7 +852,7 @@ gtk_entry_completion_popup_button_press (GtkWidget      *widget,
 {
   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
 
-  if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
+  if (!gtk_widget_get_mapped (completion->priv->popup_window))
     return FALSE;
 
   /* if we come here, it's usually time to popdown */
@@ -790,7 +869,7 @@ gtk_entry_completion_list_button_press (GtkWidget      *widget,
   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
   GtkTreePath *path = NULL;
 
-  if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
+  if (!gtk_widget_get_mapped (completion->priv->popup_window))
     return FALSE;
 
   if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
@@ -799,18 +878,23 @@ gtk_entry_completion_list_button_press (GtkWidget      *widget,
     {
       GtkTreeIter iter;
       gboolean entry_set;
+      GtkTreeModel *model;
+      GtkTreeIter child_iter;
 
       gtk_tree_model_get_iter (GTK_TREE_MODEL (completion->priv->filter_model),
                                &iter, path);
       gtk_tree_path_free (path);
+      gtk_tree_model_filter_convert_iter_to_child_iter (completion->priv->filter_model,
+                                                        &child_iter,
+                                                        &iter);
+      model = gtk_tree_model_filter_get_model (completion->priv->filter_model);
 
       g_signal_handler_block (completion->priv->entry,
-                             completion->priv->changed_id);
+                              completion->priv->changed_id);
       g_signal_emit (completion, entry_completion_signals[MATCH_SELECTED],
-                     0, GTK_TREE_MODEL (completion->priv->filter_model),
-                     &iter, &entry_set);
+                     0, model, &child_iter, &entry_set);
       g_signal_handler_unblock (completion->priv->entry,
-                               completion->priv->changed_id);
+                                completion->priv->changed_id);
 
       _gtk_entry_completion_popdown (completion);
 
@@ -828,7 +912,7 @@ gtk_entry_completion_action_button_press (GtkWidget      *widget,
   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
   GtkTreePath *path = NULL;
 
-  if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
+  if (!gtk_widget_get_mapped (completion->priv->popup_window))
     return FALSE;
 
   _gtk_entry_reset_im_context (GTK_ENTRY (completion->priv->entry));
@@ -936,7 +1020,7 @@ gtk_entry_completion_get_entry (GtkEntryCompletion *completion)
 /**
  * gtk_entry_completion_set_model:
  * @completion: A #GtkEntryCompletion.
- * @model: The #GtkTreeModel.
+ * @model: (allow-none): The #GtkTreeModel.
  *
  * Sets the model for a #GtkEntryCompletion. If @completion already has
  * a model set, it will remove it before setting the new model.
@@ -974,7 +1058,7 @@ gtk_entry_completion_set_model (GtkEntryCompletion *completion,
 
   g_object_notify (G_OBJECT (completion), "model");
 
-  if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
+  if (gtk_widget_get_visible (completion->priv->popup_window))
     _gtk_entry_completion_resize_popup (completion);
 }
 
@@ -1103,7 +1187,7 @@ gtk_entry_completion_complete (GtkEntryCompletion *completion)
 
   gtk_tree_model_filter_refilter (completion->priv->filter_model);
 
-  if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
+  if (gtk_widget_get_visible (completion->priv->popup_window))
     _gtk_entry_completion_resize_popup (completion);
 }
 
@@ -1277,7 +1361,7 @@ gtk_entry_completion_list_motion_notify (GtkWidget      *widget,
 {
   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
 
-  completion->priv->ignore_enter = FALSE; 
+  completion->priv->ignore_enter = FALSE;
   
   return FALSE;
 }
@@ -1288,7 +1372,7 @@ gboolean
 _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
 {
   gint x, y;
-  gint matches, items, height, x_border, y_border;
+  gint matches, actions, items, height, x_border, y_border;
   GdkScreen *screen;
   gint monitor_num;
   gint vertical_separator;
@@ -1298,6 +1382,8 @@ _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
   GtkTreePath *path;
   gboolean above;
   gint width;
+  GtkTreeViewColumn *action_column;
+  gint action_height;
 
   if (!completion->priv->entry->window)
     return FALSE;
@@ -1306,11 +1392,13 @@ _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
   _gtk_entry_get_borders (GTK_ENTRY (completion->priv->entry), &x_border, &y_border);
 
   matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
-
-  items = MIN (matches, 15);
+  actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
+  action_column  = gtk_tree_view_get_column (GTK_TREE_VIEW (completion->priv->action_view), 0);
 
   gtk_tree_view_column_cell_get_size (completion->priv->column, NULL,
                                       NULL, NULL, NULL, &height);
+  gtk_tree_view_column_cell_get_size (action_column, NULL,
+                                      NULL, NULL, NULL, &action_height);
 
   gtk_widget_style_get (GTK_WIDGET (completion->priv->tree_view),
                         "vertical-separator", &vertical_separator,
@@ -1320,16 +1408,23 @@ _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
   
   gtk_widget_realize (completion->priv->tree_view);
 
-  if (items <= 0)
-    gtk_widget_hide (completion->priv->scrolled_window);
-  else
-    gtk_widget_show (completion->priv->scrolled_window);
-
   screen = gtk_widget_get_screen (GTK_WIDGET (completion->priv->entry));
   monitor_num = gdk_screen_get_monitor_at_window (screen, 
                                                  GTK_WIDGET (completion->priv->entry)->window);
   gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
 
+  
+
+  if (y > monitor.height / 2)
+    items = MIN (matches, (((monitor.y + y) - (actions * action_height)) / height) - 1);
+  else
+    items = MIN (matches, (((monitor.height - y) - (actions * action_height)) / height) - 1);
+
+  if (items <= 0)
+    gtk_widget_hide (completion->priv->scrolled_window);
+  else
+    gtk_widget_show (completion->priv->scrolled_window);
+
   if (completion->priv->popup_set_width)
     width = MIN (completion->priv->entry->allocation.width, monitor.width) - 2 * x_border;
   else
@@ -1338,12 +1433,7 @@ _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
   gtk_tree_view_columns_autosize (GTK_TREE_VIEW (completion->priv->tree_view));
   gtk_widget_set_size_request (completion->priv->tree_view, width, items * height);
 
-  /* default on no match */
-  completion->priv->current_selected = -1;
-
-  items = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
-
-  if (items)
+  if (actions)
     {
       gtk_widget_show (completion->priv->action_view);
       gtk_widget_set_size_request (completion->priv->action_view, width, -1);
@@ -1385,25 +1475,29 @@ _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
 }
 
 void
-_gtk_entry_completion_popup (GtkEntryCompletion *completion)
+_gtk_entry_completion_popup (GtkEntryCompletion *completion,
+                             GdkDevice          *device)
 {
   GtkTreeViewColumn *column;
   GList *renderers;
   GtkWidget *toplevel;
 
-  if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
+  if (gtk_widget_get_mapped (completion->priv->popup_window))
+    return;
+
+  if (!gtk_widget_get_mapped (completion->priv->entry))
     return;
 
-  if (!GTK_WIDGET_MAPPED (completion->priv->entry))
+  if (!gtk_widget_has_focus (completion->priv->entry))
     return;
 
-  if (!GTK_WIDGET_HAS_FOCUS (completion->priv->entry))
+  if (completion->priv->grab_device)
     return;
 
   completion->priv->ignore_enter = TRUE;
     
   column = gtk_tree_view_get_column (GTK_TREE_VIEW (completion->priv->action_view), 0);
-  renderers = gtk_tree_view_column_get_cell_renderers (column);
+  renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
   gtk_widget_ensure_style (completion->priv->tree_view);
   g_object_set (GTK_CELL_RENDERER (renderers->data), "cell-background-gdk",
                 &completion->priv->tree_view->style->bg[GTK_STATE_NORMAL],
@@ -1412,6 +1506,9 @@ _gtk_entry_completion_popup (GtkEntryCompletion *completion)
 
   gtk_widget_show_all (completion->priv->vbox);
 
+  /* default on no match */
+  completion->priv->current_selected = -1;
+
   _gtk_entry_completion_resize_popup (completion);
 
   toplevel = gtk_widget_get_toplevel (completion->priv->entry);
@@ -1424,28 +1521,38 @@ _gtk_entry_completion_popup (GtkEntryCompletion *completion)
 
   gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
   gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
-  
+
+  gtk_window_set_screen (GTK_WINDOW (completion->priv->popup_window),
+                         gtk_widget_get_screen (completion->priv->entry));
 
   gtk_widget_show (completion->priv->popup_window);
-    
-  gtk_grab_add (completion->priv->popup_window);
-  gdk_pointer_grab (completion->priv->popup_window->window, TRUE,
-                    GDK_BUTTON_PRESS_MASK |
-                    GDK_BUTTON_RELEASE_MASK |
-                    GDK_POINTER_MOTION_MASK,
-                    NULL, NULL, GDK_CURRENT_TIME);
+
+  gtk_device_grab_add (completion->priv->popup_window, device, TRUE);
+  gdk_device_grab (device, completion->priv->popup_window->window,
+                   GDK_OWNERSHIP_WINDOW, TRUE,
+                   GDK_BUTTON_PRESS_MASK |
+                   GDK_BUTTON_RELEASE_MASK |
+                   GDK_POINTER_MOTION_MASK,
+                   NULL, GDK_CURRENT_TIME);
+
+  completion->priv->grab_device = device;
 }
 
 void
 _gtk_entry_completion_popdown (GtkEntryCompletion *completion)
 {
-  if (!GTK_WIDGET_MAPPED (completion->priv->popup_window))
+  if (!gtk_widget_get_mapped (completion->priv->popup_window))
     return;
 
   completion->priv->ignore_enter = FALSE;
-  
-  gdk_pointer_ungrab (GDK_CURRENT_TIME);
-  gtk_grab_remove (completion->priv->popup_window);
+
+  if (completion->priv->grab_device)
+    {
+      gdk_device_ungrab (completion->priv->grab_device, GDK_CURRENT_TIME);
+      gtk_device_grab_remove (completion->priv->popup_window,
+                              completion->priv->grab_device);
+      completion->priv->grab_device = NULL;
+    }
 
   gtk_widget_hide (completion->priv->popup_window);
 }
@@ -1468,6 +1575,15 @@ gtk_entry_completion_match_selected (GtkEntryCompletion *completion,
   return TRUE;
 }
 
+static gboolean
+gtk_entry_completion_cursor_on_match (GtkEntryCompletion *completion,
+                                     GtkTreeModel       *model,
+                                     GtkTreeIter        *iter)
+{
+  gtk_entry_completion_insert_completion (completion, model, iter);
+
+  return TRUE;
+}
 
 static gchar *
 gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion)
@@ -1500,7 +1616,7 @@ gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion)
          else
            {
              gchar *p = prefix;
-             const gchar *q = text;
+             gchar *q = text;
              
              while (*p && *p == *q)
                {
@@ -1509,6 +1625,19 @@ gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion)
                }
              
              *p = '\0';
+              
+              if (p > prefix)
+                {
+                  /* strip a partial multibyte character */
+                  q = g_utf8_find_prev_char (prefix, p);
+                  switch (g_utf8_get_char_validated (q, p - q))
+                    {
+                    case (gunichar)-2:
+                    case (gunichar)-1:
+                      *q = 0;
+                    default: ;
+                    }
+                }
            }
        }
       
@@ -1552,6 +1681,73 @@ gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion,
   return TRUE;
 }
 
+/**
+ * gtk_entry_completion_get_completion_prefix:
+ * @completion: a #GtkEntryCompletion
+ * 
+ * Get the original text entered by the user that triggered
+ * the completion or %NULL if there's no completion ongoing.
+ * 
+ * Returns: the prefix for the current completion
+ * 
+ * Since: 2.12
+ **/
+const gchar*
+gtk_entry_completion_get_completion_prefix (GtkEntryCompletion *completion)
+{
+  g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
+
+  return completion->priv->completion_prefix;
+}
+
+static void
+gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
+                                            const gchar *text)
+{
+  GtkEntryCompletionPrivate *priv = completion->priv;
+  gint len;
+
+  priv = completion->priv;
+
+  if (priv->changed_id > 0)
+    g_signal_handler_block (priv->entry, priv->changed_id);
+
+  if (priv->insert_text_id > 0)
+    g_signal_handler_block (priv->entry, priv->insert_text_id);
+
+  gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
+
+  len = strlen (priv->completion_prefix);
+  gtk_editable_select_region (GTK_EDITABLE (priv->entry), len, -1);
+
+  if (priv->changed_id > 0)
+    g_signal_handler_unblock (priv->entry, priv->changed_id);
+
+  if (priv->insert_text_id > 0)
+    g_signal_handler_unblock (priv->entry, priv->insert_text_id);
+}
+
+static gboolean
+gtk_entry_completion_insert_completion (GtkEntryCompletion *completion,
+                                       GtkTreeModel       *model,
+                                       GtkTreeIter        *iter)
+{
+  gchar *str = NULL;
+
+  if (completion->priv->text_column < 0)
+    return FALSE;
+
+  gtk_tree_model_get (model, iter,
+                     completion->priv->text_column, &str,
+                     -1);
+
+  gtk_entry_completion_insert_completion_text (completion, str);
+
+  g_free (str);
+
+  return TRUE;
+}
+
 /**
  * gtk_entry_completion_insert_prefix:
  * @completion: a #GtkEntryCompletion
@@ -1560,6 +1756,7 @@ gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion,
  * 
  * Since: 2.6
  **/
+
 void
 gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion)
 {
@@ -1609,7 +1806,6 @@ gtk_entry_completion_set_inline_completion (GtkEntryCompletion *completion,
     }
 }
 
-
 /**
  * gtk_entry_completion_get_inline_completion:
  * @completion: a #GtkEntryCompletion
@@ -1769,6 +1965,46 @@ gtk_entry_completion_get_popup_single_match (GtkEntryCompletion *completion)
   return completion->priv->popup_single_match;
 }
 
+/**
+ * gtk_entry_completion_set_inline_selection:
+ * @completion: a #GtkEntryCompletion
+ * @inline_selection: %TRUE to do inline selection
+ * 
+ * Sets whether it is possible to cycle through the possible completions
+ * inside the entry.
+ * 
+ * Since: 2.12
+ **/
+void
+gtk_entry_completion_set_inline_selection (GtkEntryCompletion *completion,
+                                          gboolean inline_selection)
+{
+  g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
+
+  inline_selection = inline_selection != FALSE;
+
+  if (completion->priv->inline_selection != inline_selection)
+    {
+      completion->priv->inline_selection = inline_selection;
 
-#define __GTK_ENTRY_COMPLETION_C__
-#include "gtkaliasdef.c"
+      g_object_notify (G_OBJECT (completion), "inline-selection");
+    }
+}
+
+/**
+ * gtk_entry_completion_get_inline_selection:
+ * @completion: a #GtkEntryCompletion
+ *
+ * Returns %TRUE if inline-selection mode is turned on.
+ *
+ * Returns: %TRUE if inline-selection mode is on
+ *
+ * Since: 2.12
+ **/
+gboolean
+gtk_entry_completion_get_inline_selection (GtkEntryCompletion *completion)
+{
+  g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), FALSE);
+
+  return completion->priv->inline_selection;
+}