Index: gtk/gtkentry.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkentry.c,v
retrieving revision 1.284
diff -u -r1.284 gtkentry.c
--- gtk/gtkentry.c	21 Aug 2005 01:57:01 -0000	1.284
+++ gtk/gtkentry.c	24 Aug 2005 17:51:06 -0000
@@ -51,6 +51,7 @@
 #include "gtkwindow.h"
 #include "gtktreeview.h"
 #include "gtktreeselection.h"
+#include "gtktreeprivate.h"
 #include "gtkprivate.h"
 #include "gtkentryprivate.h"
 #include "gtkcelllayout.h"
@@ -4969,6 +4970,18 @@
     }
 }
 
+static void
+tree_view_unselect_all (GtkTreeView *tree_view)
+{
+  gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (tree_view));
+  
+  if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
+    {
+      gtk_tree_row_reference_free (tree_view->priv->cursor);
+      tree_view->priv->cursor = NULL;
+    }
+}
+
 /* completion */
 static gint
 gtk_entry_completion_timeout (gpointer data)
@@ -4991,11 +5004,8 @@
       gtk_entry_completion_complete (completion);
       matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
 
-      gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
-
-      s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
-
-      gtk_tree_selection_unselect_all (s);
+      tree_view_unselect_all (GTK_TREE_VIEW (completion->priv->tree_view));
+      tree_view_unselect_all (GTK_TREE_VIEW (completion->priv->action_view));
 
       actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
 
@@ -5113,8 +5123,8 @@
 
       if (completion->priv->current_selected < 0)
         {
-          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)));
+	  tree_view_unselect_all (GTK_TREE_VIEW (completion->priv->tree_view));
+	  tree_view_unselect_all (GTK_TREE_VIEW (completion->priv->action_view));
         }
       else if (completion->priv->current_selected < matches)
         {
Index: gtk/gtkentrycompletion.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkentrycompletion.c,v
retrieving revision 1.64
diff -u -r1.64 gtkentrycompletion.c
--- gtk/gtkentrycompletion.c	13 Jul 2005 11:57:10 -0000	1.64
+++ gtk/gtkentrycompletion.c	24 Aug 2005 17:51:16 -0000
@@ -27,6 +27,7 @@
 #include "gtkframe.h"
 #include "gtktreeselection.h"
 #include "gtktreeview.h"
+#include "gtktreeprivate.h"
 #include "gtkscrolledwindow.h"
 #include "gtkvbox.h"
 #include "gtkwindow.h"
@@ -1411,10 +1412,36 @@
   return above;
 }
 
+static void 
+send_focus_change (GtkWidget *widget, gboolean in)
+{
+  GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
+
+  g_object_ref (widget);
+
+  if (in)
+    GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
+  else
+    GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
+
+  fevent->focus_change.type = GDK_FOCUS_CHANGE;
+  fevent->focus_change.window = g_object_ref (widget->window);
+  fevent->focus_change.in = in;
+
+  gtk_widget_event (widget, fevent);
+
+  g_object_notify (G_OBJECT (widget), "has-focus");
+
+  g_object_unref (widget);
+  gdk_event_free (fevent);
+}
+
 void
 _gtk_entry_completion_popup (GtkEntryCompletion *completion)
 {
+  GtkTreeView *tree_view;
   GtkTreeViewColumn *column;
+  GtkTreeSelection *selection;
   GList *renderers;
 
   if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
@@ -1445,6 +1472,18 @@
                     GDK_BUTTON_RELEASE_MASK |
                     GDK_POINTER_MOTION_MASK,
                     NULL, NULL, GDK_CURRENT_TIME);
+
+  send_focus_change (completion->priv->popup_window, TRUE);
+  
+  tree_view = GTK_TREE_VIEW (completion->priv->tree_view);
+  selection = gtk_tree_view_get_selection (tree_view);
+  gtk_tree_selection_unselect_all (selection);
+
+  if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
+  {
+    gtk_tree_row_reference_free (tree_view->priv->cursor);
+    tree_view->priv->cursor = NULL;
+  }
 }
 
 void
