]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkentry.c
Fix some typos. Closes bug #475400.
[~andy/gtk] / gtk / gtkentry.c
index a8fa84dd97472087d82c484bfd4051ede4190ef1..2ccdfad3d0276f7ec7d17e3f63c2584667d83ae3 100644 (file)
@@ -61,8 +61,8 @@
 
 #define MIN_ENTRY_WIDTH  150
 #define DRAW_TIMEOUT     20
-#define INNER_BORDER     2
 #define COMPLETION_TIMEOUT 300
+#define PASSWORD_HINT_MAX 8
 
 /* Initial size of buffer, in bytes */
 #define MIN_SIZE 16
 /* Maximum size of text buffer, in bytes */
 #define MAX_SIZE G_MAXUSHORT
 
+static const GtkBorder default_inner_border = { 2, 2, 2, 2 };
+static GQuark          quark_inner_border   = 0;
+static GQuark          quark_password_hint  = 0;
+static GQuark          quark_cursor_hadjustment = 0;
+
 typedef struct _GtkEntryPrivate GtkEntryPrivate;
 
 #define GTK_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY, GtkEntryPrivate))
@@ -78,7 +83,23 @@ struct _GtkEntryPrivate
 {
   gfloat xalign;
   gint insert_pos;
-  gboolean truncate_multiline; /* when pasting multiline text */
+  guint blink_time;  /* time in msec the cursor has blinked since last user event */
+  guint interior_focus : 1;
+  guint real_changed   : 1;
+  guint change_count   : 8;
+
+  gint focus_width;
+  GtkShadowType shadow_type;
+};
+
+typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
+
+struct _GtkEntryPasswordHint
+{
+  gchar password_hint[PASSWORD_HINT_MAX];
+  guint password_hint_timeout_id;
+  gint  password_hint_length;
+  gint  password_hint_position;
 };
 
 enum {
@@ -103,13 +124,15 @@ enum {
   PROP_MAX_LENGTH,
   PROP_VISIBILITY,
   PROP_HAS_FRAME,
+  PROP_INNER_BORDER,
   PROP_INVISIBLE_CHAR,
   PROP_ACTIVATES_DEFAULT,
   PROP_WIDTH_CHARS,
   PROP_SCROLL_OFFSET,
   PROP_TEXT,
   PROP_XALIGN,
-  PROP_TRUNCATE_MULTILINE
+  PROP_TRUNCATE_MULTILINE,
+  PROP_SHADOW_TYPE
 };
 
 static guint signals[LAST_SIGNAL] = { 0 };
@@ -121,18 +144,16 @@ typedef enum {
 
 /* GObject, GtkObject methods
  */
-static void   gtk_entry_class_init           (GtkEntryClass        *klass);
 static void   gtk_entry_editable_init        (GtkEditableClass     *iface);
 static void   gtk_entry_cell_editable_init   (GtkCellEditableIface *iface);
-static void   gtk_entry_init                 (GtkEntry         *entry);
-static void   gtk_entry_set_property (GObject         *object,
-                                     guint            prop_id,
-                                     const GValue    *value,
-                                     GParamSpec      *pspec);
-static void   gtk_entry_get_property (GObject         *object,
-                                     guint            prop_id,
-                                     GValue          *value,
-                                     GParamSpec      *pspec);
+static void   gtk_entry_set_property         (GObject          *object,
+                                              guint             prop_id,
+                                              const GValue     *value,
+                                              GParamSpec       *pspec);
+static void   gtk_entry_get_property         (GObject          *object,
+                                              guint             prop_id,
+                                              GValue           *value,
+                                              GParamSpec       *pspec);
 static void   gtk_entry_finalize             (GObject          *object);
 static void   gtk_entry_destroy              (GtkObject        *object);
 
@@ -144,7 +165,8 @@ static void   gtk_entry_size_request         (GtkWidget        *widget,
                                              GtkRequisition   *requisition);
 static void   gtk_entry_size_allocate        (GtkWidget        *widget,
                                              GtkAllocation    *allocation);
-static void   gtk_entry_draw_frame           (GtkWidget        *widget);
+static void   gtk_entry_draw_frame           (GtkWidget        *widget,
+                                              GdkRectangle     *area);
 static gint   gtk_entry_expose               (GtkWidget        *widget,
                                              GdkEventExpose   *event);
 static gint   gtk_entry_button_press         (GtkWidget        *widget,
@@ -283,7 +305,6 @@ static PangoLayout *gtk_entry_ensure_layout            (GtkEntry       *entry,
                                                         gboolean        include_preedit);
 static void         gtk_entry_reset_layout             (GtkEntry       *entry);
 static void         gtk_entry_queue_draw               (GtkEntry       *entry);
-static void         gtk_entry_reset_im_context         (GtkEntry       *entry);
 static void         gtk_entry_recompute                (GtkEntry       *entry);
 static gint         gtk_entry_find_position            (GtkEntry       *entry,
                                                        gint            x);
@@ -321,6 +342,7 @@ static void         gtk_entry_state_changed            (GtkWidget      *widget,
                                                        GtkStateType    previous_state);
 static void         gtk_entry_check_cursor_blink       (GtkEntry       *entry);
 static void         gtk_entry_pend_cursor_blink        (GtkEntry       *entry);
+static void         gtk_entry_reset_blink_time         (GtkEntry       *entry);
 static void         get_text_area_size                 (GtkEntry       *entry,
                                                        gint           *x,
                                                        gint           *y,
@@ -331,6 +353,7 @@ static void         get_widget_window_size             (GtkEntry       *entry,
                                                        gint           *y,
                                                        gint           *width,
                                                        gint           *height);
+static void         gtk_entry_move_adjustments         (GtkEntry       *entry);
 
 /* Completion */
 static gint         gtk_entry_completion_timeout       (gpointer            data);
@@ -356,56 +379,15 @@ static void         disconnect_completion_signals      (GtkEntry           *entr
 static void         connect_completion_signals         (GtkEntry           *entry,
                                                        GtkEntryCompletion *completion);
 
+static void         begin_change                       (GtkEntry *entry);
+static void         end_change                         (GtkEntry *entry);
+static void         emit_changed                       (GtkEntry *entry);
 
-static GtkWidgetClass *parent_class = NULL;
-
-GType
-gtk_entry_get_type (void)
-{
-  static GType entry_type = 0;
-
-  if (!entry_type)
-    {
-      static const GTypeInfo entry_info =
-      {
-       sizeof (GtkEntryClass),
-       NULL,           /* base_init */
-       NULL,           /* base_finalize */
-       (GClassInitFunc) gtk_entry_class_init,
-       NULL,           /* class_finalize */
-       NULL,           /* class_data */
-       sizeof (GtkEntry),
-       0,              /* n_preallocs */
-       (GInstanceInitFunc) gtk_entry_init,
-      };
-      
-      static const GInterfaceInfo editable_info =
-      {
-       (GInterfaceInitFunc) gtk_entry_editable_init,    /* interface_init */
-       NULL,                                            /* interface_finalize */
-       NULL                                             /* interface_data */
-      };
-
-      static const GInterfaceInfo cell_editable_info =
-      {
-       (GInterfaceInitFunc) gtk_entry_cell_editable_init,    /* interface_init */
-       NULL,                                                 /* interface_finalize */
-       NULL                                                  /* interface_data */
-      };
-      
-      entry_type = g_type_register_static (GTK_TYPE_WIDGET, I_("GtkEntry"),
-                                          &entry_info, 0);
-
-      g_type_add_interface_static (entry_type,
-                                  GTK_TYPE_EDITABLE,
-                                  &editable_info);
-      g_type_add_interface_static (entry_type,
-                                  GTK_TYPE_CELL_EDITABLE,
-                                  &cell_editable_info);
-    }
-
-  return entry_type;
-}
+G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
+                                                gtk_entry_editable_init)
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
+                                                gtk_entry_cell_editable_init))
 
 static void
 add_move_binding (GtkBindingSet  *binding_set,
@@ -440,7 +422,6 @@ gtk_entry_class_init (GtkEntryClass *class)
 
   widget_class = (GtkWidgetClass*) class;
   gtk_object_class = (GtkObjectClass *)class;
-  parent_class = g_type_class_peek_parent (class);
 
   gobject_class->finalize = gtk_entry_finalize;
   gobject_class->set_property = gtk_entry_set_property;
@@ -486,6 +467,10 @@ gtk_entry_class_init (GtkEntryClass *class)
   class->toggle_overwrite = gtk_entry_toggle_overwrite;
   class->activate = gtk_entry_real_activate;
   
+  quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
+  quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
+  quark_cursor_hadjustment = g_quark_from_static_string ("gtk-hadjustment");
+
   g_object_class_install_property (gobject_class,
                                    PROP_CURSOR_POSITION,
                                    g_param_spec_int ("cursor-position",
@@ -539,6 +524,14 @@ gtk_entry_class_init (GtkEntryClass *class)
                                                          TRUE,
                                                         GTK_PARAM_READWRITE));
 
+  g_object_class_install_property (gobject_class,
+                                   PROP_INNER_BORDER,
+                                   g_param_spec_boxed ("inner-border",
+                                                       P_("Inner Border"),
+                                                       P_("Border between text and frame. Overrides the inner-border style property"),
+                                                       GTK_TYPE_BORDER,
+                                                       GTK_PARAM_READWRITE));
+
   g_object_class_install_property (gobject_class,
                                    PROP_INVISIBLE_CHAR,
                                    g_param_spec_unichar ("invisible-char",
@@ -615,6 +608,23 @@ gtk_entry_class_init (GtkEntryClass *class)
                                                          FALSE,
                                                          GTK_PARAM_READWRITE));
 
+  /**
+   * GtkEntry:shadow-type:
+   *
+   * Which kind of shadow to draw around the entry when 
+   * #GtkEntry:has-frame is set to %TRUE.
+   *
+   * Since: 2.12
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_SHADOW_TYPE,
+                                   g_param_spec_enum ("shadow-type",
+                                                      P_("Shadow type"),
+                                                      P_("Which kind of shadow to draw around the entry when has-frame is set"),
+                                                      GTK_TYPE_SHADOW_TYPE,
+                                                      GTK_SHADOW_IN,
+                                                      GTK_PARAM_READWRITE));
+
   signals[POPULATE_POPUP] =
     g_signal_new (I_("populate_popup"),
                  G_OBJECT_CLASS_TYPE (gobject_class),
@@ -868,12 +878,41 @@ gtk_entry_class_init (GtkEntryClass *class)
   gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0,
                                "toggle_overwrite", 0);
 
-  gtk_settings_install_property (g_param_spec_boolean ("gtk-entry-select-on-focus",
+  /**
+   * GtkEntry:inner-border:
+   *
+   * Sets the text area's border between the text and the frame.
+   *
+   * Since: 2.10
+   */
+  gtk_widget_class_install_style_property (widget_class,
+                                          g_param_spec_boxed ("inner-border",
+                                                               P_("Inner Border"),
+                                                               P_("Border between text and frame."),
+                                                               GTK_TYPE_BORDER,
+                                                               GTK_PARAM_READABLE));
+
+   gtk_settings_install_property (g_param_spec_boolean ("gtk-entry-select-on-focus",
                                                       P_("Select on focus"),
                                                       P_("Whether to select the contents of an entry when it is focused"),
                                                       TRUE,
                                                       GTK_PARAM_READWRITE));
 
+  /**
+   * GtkSettings:gtk-entry-password-hint-timeout:
+   *
+   * How long to show the last input character in hidden
+   * entries. This value is in milliseconds. 0 disables showing the
+   * last char. 600 is a good value for enabling it.
+   *
+   * Since: 2.10
+   */
+  gtk_settings_install_property (g_param_spec_uint ("gtk-entry-password-hint-timeout",
+                                                    P_("Password Hint Timeout"),
+                                                    P_("How long to show the last input character in hidden entries"),
+                                                    0, G_MAXUINT, 0,
+                                                    GTK_PARAM_READWRITE));
+
   g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
 }
 
@@ -903,8 +942,8 @@ gtk_entry_set_property (GObject         *object,
                         const GValue    *value,
                         GParamSpec      *pspec)
 {
+  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
   GtkEntry *entry = GTK_ENTRY (object);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
 
   switch (prop_id)
     {
@@ -916,7 +955,7 @@ gtk_entry_set_property (GObject         *object,
          {
            if (!new_value)
              {
-               gtk_entry_reset_im_context (entry);
+               _gtk_entry_reset_im_context (entry);
                if (GTK_WIDGET_HAS_FOCUS (entry))
                  gtk_im_context_focus_out (entry->im_context);
 
@@ -946,6 +985,10 @@ gtk_entry_set_property (GObject         *object,
       gtk_entry_set_has_frame (entry, g_value_get_boolean (value));
       break;
 
+    case PROP_INNER_BORDER:
+      gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
+      break;
+
     case PROP_INVISIBLE_CHAR:
       gtk_entry_set_invisible_char (entry, g_value_get_uint (value));
       break;
@@ -967,7 +1010,11 @@ gtk_entry_set_property (GObject         *object,
       break;
 
     case PROP_TRUNCATE_MULTILINE:
-      priv->truncate_multiline = g_value_get_boolean (value);
+      entry->truncate_multiline = g_value_get_boolean (value);
+      break;
+
+    case PROP_SHADOW_TYPE:
+      priv->shadow_type = g_value_get_enum (value);
       break;
 
     case PROP_SCROLL_OFFSET:
@@ -984,8 +1031,8 @@ gtk_entry_get_property (GObject         *object,
                         GValue          *value,
                         GParamSpec      *pspec)
 {
+  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
   GtkEntry *entry = GTK_ENTRY (object);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
 
   switch (prop_id)
     {
@@ -1007,6 +1054,9 @@ gtk_entry_get_property (GObject         *object,
     case PROP_HAS_FRAME:
       g_value_set_boolean (value, entry->has_frame);
       break;
+    case PROP_INNER_BORDER:
+      g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
+      break;
     case PROP_INVISIBLE_CHAR:
       g_value_set_uint (value, entry->invisible_char);
       break;
@@ -1026,7 +1076,10 @@ gtk_entry_get_property (GObject         *object,
       g_value_set_float (value, gtk_entry_get_alignment (entry));
       break;
     case PROP_TRUNCATE_MULTILINE:
-      g_value_set_boolean (value, priv->truncate_multiline);
+      g_value_set_boolean (value, entry->truncate_multiline);
+      break;
+    case PROP_SHADOW_TYPE:
+      g_value_set_enum (value, priv->shadow_type);
       break;
 
     default:
@@ -1054,8 +1107,9 @@ gtk_entry_init (GtkEntry *entry)
   entry->is_cell_renderer = FALSE;
   entry->editing_canceled = FALSE;
   entry->has_frame = TRUE;
+  entry->truncate_multiline = FALSE;
+  priv->shadow_type = GTK_SHADOW_IN;
   priv->xalign = 0.0;
-  priv->truncate_multiline = FALSE;
 
   gtk_drag_dest_set (GTK_WIDGET (entry),
                      GTK_DEST_DEFAULT_HIGHLIGHT,
@@ -1078,6 +1132,46 @@ gtk_entry_init (GtkEntry *entry)
                    G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
 }
 
+static void
+begin_change (GtkEntry *entry)
+{
+  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+
+  priv->change_count++;
+}
+
+static void
+end_change (GtkEntry *entry)
+{
+  GtkEditable *editable = GTK_EDITABLE (entry);
+  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  g_return_if_fail (priv->change_count > 0);
+
+  priv->change_count--;
+
+  if (priv->change_count == 0)
+    {
+       if (priv->real_changed) 
+         {
+           g_signal_emit_by_name (editable, "changed");
+           priv->real_changed = FALSE;
+         }
+    } 
+}
+
+static void
+emit_changed (GtkEntry *entry)
+{
+  GtkEditable *editable = GTK_EDITABLE (entry);
+  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+
+  if (priv->change_count == 0)
+    g_signal_emit_by_name (editable, "changed");
+  else 
+    priv->real_changed = TRUE;
+}
+
 /*
  * Overwrite a memory that might contain sensitive information.
  */
@@ -1096,7 +1190,7 @@ gtk_entry_destroy (GtkObject *object)
 
   entry->n_bytes = 0;
   entry->current_pos = entry->selection_bound = entry->text_length = 0;
-  gtk_entry_reset_im_context (entry);
+  _gtk_entry_reset_im_context (entry);
   gtk_entry_reset_layout (entry);
 
   if (entry->blink_timeout)
@@ -1117,7 +1211,7 @@ gtk_entry_destroy (GtkObject *object)
       trash_area (entry->text, strlen (entry->text));
     }
 
-  GTK_OBJECT_CLASS (parent_class)->destroy (object);
+  GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
 }
 
 static void
@@ -1148,7 +1242,7 @@ gtk_entry_finalize (GObject *object)
       entry->text = NULL;
     }
 
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
 }
 
 static void
@@ -1184,14 +1278,19 @@ gtk_entry_realize (GtkWidget *widget)
   gdk_window_set_user_data (widget->window, entry);
 
   get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
-
-  attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
-  attributes_mask |= GDK_WA_CURSOR;
+  if (GTK_WIDGET_IS_SENSITIVE (widget))
+    {
+      attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
+      attributes_mask |= GDK_WA_CURSOR;
+    }
 
   entry->text_area = gdk_window_new (widget->window, &attributes, attributes_mask);
+
   gdk_window_set_user_data (entry->text_area, entry);
 
-  gdk_cursor_unref (attributes.cursor);
+  if (attributes_mask & GDK_WA_CURSOR)
+    gdk_cursor_unref (attributes.cursor);
 
   widget->style = gtk_style_attach (widget->style, widget->window);
 
@@ -1233,8 +1332,8 @@ gtk_entry_unrealize (GtkWidget *widget)
       entry->popup_menu = NULL;
     }
 
-  if (GTK_WIDGET_CLASS (parent_class)->unrealize)
-    (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
+  if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize)
+    (* GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize) (widget);
 }
 
 void
@@ -1243,13 +1342,7 @@ _gtk_entry_get_borders (GtkEntry *entry,
                        gint     *yborder)
 {
   GtkWidget *widget = GTK_WIDGET (entry);
-  gint focus_width;
-  gboolean interior_focus;
-
-  gtk_widget_style_get (widget,
-                       "interior-focus", &interior_focus,
-                       "focus-line-width", &focus_width,
-                       NULL);
+  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
 
   if (entry->has_frame)
     {
@@ -1262,10 +1355,10 @@ _gtk_entry_get_borders (GtkEntry *entry,
       *yborder = 0;
     }
 
-  if (!interior_focus)
+  if (!priv->interior_focus)
     {
-      *xborder += focus_width;
-      *yborder += focus_width;
+      *xborder += priv->focus_width;
+      *yborder += priv->focus_width;
     }
 }
 
@@ -1276,6 +1369,7 @@ gtk_entry_size_request (GtkWidget      *widget,
   GtkEntry *entry = GTK_ENTRY (widget);
   PangoFontMetrics *metrics;
   gint xborder, yborder;
+  GtkBorder inner_border;
   PangoContext *context;
   
   gtk_widget_ensure_style (widget);
@@ -1288,22 +1382,20 @@ gtk_entry_size_request (GtkWidget      *widget,
   entry->descent = pango_font_metrics_get_descent (metrics);
   
   _gtk_entry_get_borders (entry, &xborder, &yborder);
-  
-  xborder += INNER_BORDER;
-  yborder += INNER_BORDER;
-  
+  _gtk_entry_effective_inner_border (entry, &inner_border);
+
   if (entry->width_chars < 0)
-    requisition->width = MIN_ENTRY_WIDTH + xborder * 2;
+    requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
   else
     {
       gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
       gint digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
       gint char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
       
-      requisition->width = char_pixels * entry->width_chars + xborder * 2;
+      requisition->width = char_pixels * entry->width_chars + xborder * 2 + inner_border.left + inner_border.right;
     }
     
-  requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2;
+  requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
 
   pango_font_metrics_unref (metrics);
 }
@@ -1315,20 +1407,29 @@ get_text_area_size (GtkEntry *entry,
                     gint     *width,
                     gint     *height)
 {
+  gint frame_height;
   gint xborder, yborder;
   GtkRequisition requisition;
   GtkWidget *widget = GTK_WIDGET (entry);
+  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
 
   gtk_widget_get_child_requisition (widget, &requisition);
-
   _gtk_entry_get_borders (entry, &xborder, &yborder);
 
+  if (GTK_WIDGET_REALIZED (widget))
+    gdk_drawable_get_size (widget->window, NULL, &frame_height);
+  else
+    frame_height = requisition.height;
+
+  if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
+      frame_height -= 2 * priv->focus_width;
+
   if (x)
     *x = xborder;
 
   if (y)
-    *y = yborder;
-  
+    *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
+
   if (width)
     *width = GTK_WIDGET (entry)->allocation.width - xborder * 2;
 
@@ -1371,6 +1472,32 @@ get_widget_window_size (GtkEntry *entry,
     }
 }
 
+void
+_gtk_entry_effective_inner_border (GtkEntry  *entry,
+                                   GtkBorder *border)
+{
+  GtkBorder *tmp_border;
+
+  tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
+
+  if (tmp_border)
+    {
+      *border = *tmp_border;
+      return;
+    }
+
+  gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
+
+  if (tmp_border)
+    {
+      *border = *tmp_border;
+      gtk_border_free (tmp_border);
+      return;
+    }
+
+  *border = default_inner_border;
+}
+
 static void
 gtk_entry_size_allocate (GtkWidget     *widget,
                         GtkAllocation *allocation)
@@ -1402,42 +1529,35 @@ gtk_entry_size_allocate (GtkWidget     *widget,
 }
 
 static void
-gtk_entry_draw_frame (GtkWidget *widget)
+gtk_entry_draw_frame (GtkWidget    *widget,
+                      GdkRectangle *area)
 {
-  gint x = 0, y = 0;
-  gint width, height;
-  gboolean interior_focus;
-  gint focus_width;
-  
-  gtk_widget_style_get (widget,
-                       "interior-focus", &interior_focus,
-                       "focus-line-width", &focus_width,
-                       NULL);
+  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
+  gint x = 0, y = 0, width, height;
   
   gdk_drawable_get_size (widget->window, &width, &height);
   
-  if (GTK_WIDGET_HAS_FOCUS (widget) && !interior_focus)
+  if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
     {
-      x += focus_width;
-      y += focus_width;
-      width -= 2 * focus_width;
-      height -= 2 * focus_width;
+      x += priv->focus_width;
+      y += priv->focus_width;
+      width -= 2 * priv->focus_width;
+      height -= 2 * priv->focus_width;
     }
 
   gtk_paint_shadow (widget->style, widget->window,
-                   GTK_STATE_NORMAL, GTK_SHADOW_IN,
-                   NULL, widget, "entry",
-                   x, y, width, height);
+                   GTK_STATE_NORMAL, priv->shadow_type,
+                   area, widget, "entry", x, y, width, height);
 
-  if (GTK_WIDGET_HAS_FOCUS (widget) && !interior_focus)
+  if (GTK_WIDGET_HAS_FOCUS (widget) && !priv->interior_focus)
     {
-      x -= focus_width;
-      y -= focus_width;
-      width += 2 * focus_width;
-      height += 2 * focus_width;
+      x -= priv->focus_width;
+      y -= priv->focus_width;
+      width += 2 * priv->focus_width;
+      height += 2 * priv->focus_width;
       
       gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget), 
-                      NULL, widget, "entry",
+                      area, widget, "entry",
                       0, 0, width, height);
     }
 }
@@ -1449,7 +1569,7 @@ gtk_entry_expose (GtkWidget      *widget,
   GtkEntry *entry = GTK_ENTRY (widget);
 
   if (widget->window == event->window)
-    gtk_entry_draw_frame (widget);
+    gtk_entry_draw_frame (widget, &event->area);
   else if (entry->text_area == event->window)
     {
       gint area_width, area_height;
@@ -1458,18 +1578,18 @@ gtk_entry_expose (GtkWidget      *widget,
 
       gtk_paint_flat_box (widget->style, entry->text_area, 
                          GTK_WIDGET_STATE(widget), GTK_SHADOW_NONE,
-                         NULL, widget, "entry_bg", 
+                         &event->area, widget, "entry_bg",
                          0, 0, area_width, area_height);
-      
-      if ((entry->visible || entry->invisible_char != 0) &&
-         GTK_WIDGET_HAS_FOCUS (widget) &&
-         entry->selection_bound == entry->current_pos && entry->cursor_visible)
-       gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
 
       if (entry->dnd_position != -1)
        gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
       
       gtk_entry_draw_text (GTK_ENTRY (widget));
+
+      if ((entry->visible || entry->invisible_char != 0) &&
+         GTK_WIDGET_HAS_FOCUS (widget) &&
+         entry->selection_bound == entry->current_pos && entry->cursor_visible)
+       gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
     }
 
   return FALSE;
@@ -1485,7 +1605,7 @@ gtk_entry_get_pixel_ranges (GtkEntry  *entry,
   if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_char, &end_char))
     {
       PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
-      PangoLayoutLine *line = pango_layout_get_lines (layout)->data;
+      PangoLayoutLine *line = pango_layout_get_lines_readonly (layout)->data;
       const char *text = pango_layout_get_text (layout);
       gint start_index = g_utf8_offset_to_pointer (text, start_char) - text;
       gint end_index = g_utf8_offset_to_pointer (text, end_char) - text;
@@ -1553,6 +1673,8 @@ gtk_entry_button_press (GtkWidget      *widget,
       (entry->button && event->button != entry->button))
     return FALSE;
 
+  gtk_entry_reset_blink_time (entry);
+
   entry->button = event->button;
   
   if (!GTK_WIDGET_HAS_FOCUS (widget))
@@ -1573,15 +1695,18 @@ gtk_entry_button_press (GtkWidget      *widget,
 
       if (event->state & GDK_SHIFT_MASK)
        {
-         gtk_entry_reset_im_context (entry);
+         _gtk_entry_reset_im_context (entry);
          
          if (!have_selection) /* select from the current position to the clicked position */
            sel_start = sel_end = entry->current_pos;
          
          if (tmp_pos > sel_start && tmp_pos < sel_end)
            {
-             /* Truncate current selection */
-             gtk_entry_set_positions (entry, tmp_pos, -1);
+             /* Truncate current selection, but keep it as big as possible */
+             if (tmp_pos - sel_start > sel_end - tmp_pos)
+               gtk_entry_set_positions (entry, sel_start, tmp_pos);
+             else
+               gtk_entry_set_positions (entry, tmp_pos, sel_end);
            }
          else
            {
@@ -1637,10 +1762,10 @@ gtk_entry_button_press (GtkWidget      *widget,
               */
              entry->in_drag = TRUE;
              entry->drag_start_x = event->x + entry->scroll_offset;
-             entry->drag_start_y = event->y + entry->scroll_offset;
+             entry->drag_start_y = event->y;
            }
          else
-           gtk_editable_set_position (editable, tmp_pos);
+            gtk_editable_set_position (editable, tmp_pos);
          break;
  
        case GDK_2BUTTON_PRESS:
@@ -1669,12 +1794,18 @@ gtk_entry_button_press (GtkWidget      *widget,
 
       return TRUE;
     }
-  else if (event->button == 2 && event->type == GDK_BUTTON_PRESS && entry->editable)
+  else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
     {
-      priv->insert_pos = tmp_pos;
-      gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
-
-      return TRUE;
+      if (entry->editable)
+        {
+          priv->insert_pos = tmp_pos;
+          gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
+          return TRUE;
+        }
+      else
+        {
+          gtk_widget_error_bell (widget);
+        }
     }
   else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
     {
@@ -1756,8 +1887,7 @@ gtk_entry_motion_notify (GtkWidget      *widget,
   if (entry->select_lines)
     return TRUE;
 
-  if (event->is_hint || (entry->text_area != event->window))
-    gdk_window_get_pointer (entry->text_area, NULL, NULL, NULL);
+  gdk_event_request_motions (event);
 
   if (entry->in_drag)
     {
@@ -1902,6 +2032,7 @@ gtk_entry_key_press (GtkWidget   *widget,
 {
   GtkEntry *entry = GTK_ENTRY (widget);
 
+  gtk_entry_reset_blink_time (entry);
   gtk_entry_pend_cursor_blink (entry);
 
   if (entry->editable)
@@ -1927,14 +2058,17 @@ gtk_entry_key_press (GtkWidget   *widget,
           completion->priv->completion_timeout = 0;
         }
 
-      gtk_entry_reset_im_context (entry);
+      _gtk_entry_reset_im_context (entry);
     }
 
-  if (GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event))
+  if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
     /* Activate key bindings
      */
     return TRUE;
 
+  if (!entry->editable && event->length)
+    gtk_widget_error_bell (widget);
+
   return FALSE;
 }
 
@@ -1953,7 +2087,7 @@ gtk_entry_key_release (GtkWidget   *widget,
        }
     }
 
-  return GTK_WIDGET_CLASS (parent_class)->key_release_event (widget, event);
+  return GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_release_event (widget, event);
 }
 
 static gint
@@ -1974,6 +2108,7 @@ gtk_entry_focus_in (GtkWidget     *widget,
                    "direction_changed",
                    G_CALLBACK (gtk_entry_keymap_direction_changed), entry);
 
+  gtk_entry_reset_blink_time (entry);
   gtk_entry_check_cursor_blink (entry);
 
   return FALSE;
@@ -2013,15 +2148,18 @@ gtk_entry_grab_focus (GtkWidget        *widget)
   GtkEntry *entry = GTK_ENTRY (widget);
   gboolean select_on_focus;
   
-  GTK_WIDGET_CLASS (parent_class)->grab_focus (widget);
+  GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
 
-  g_object_get (gtk_widget_get_settings (widget),
-               "gtk-entry-select-on-focus",
-               &select_on_focus,
-               NULL);
+  if (entry->editable && !entry->in_click)
+    {
+      g_object_get (gtk_widget_get_settings (widget),
+                    "gtk-entry-select-on-focus",
+                    &select_on_focus,
+                    NULL);
   
-  if (select_on_focus && entry->editable && !entry->in_click)
-    gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
+      if (select_on_focus)
+        gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
+    }
 }
 
 static void 
@@ -2032,7 +2170,7 @@ gtk_entry_direction_changed (GtkWidget        *widget,
 
   gtk_entry_recompute (entry);
       
-  GTK_WIDGET_CLASS (parent_class)->direction_changed (widget, previous_dir);
+  GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
 }
 
 static void
@@ -2040,11 +2178,24 @@ gtk_entry_state_changed (GtkWidget      *widget,
                         GtkStateType    previous_state)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
+  GdkCursor *cursor;
   
   if (GTK_WIDGET_REALIZED (widget))
     {
       gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
       gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
+
+      if (GTK_WIDGET_IS_SENSITIVE (widget))
+        cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
+      else 
+        cursor = NULL;
+      
+      gdk_window_set_cursor (entry->text_area, cursor);
+
+      if (cursor)
+        gdk_cursor_unref (cursor);
+
+      entry->mouse_cursor_obscured = FALSE;
     }
 
   if (!GTK_WIDGET_IS_SENSITIVE (widget))
@@ -2141,29 +2292,22 @@ gtk_entry_get_chars      (GtkEditable   *editable,
 }
 
 static void
-gtk_entry_set_position_internal (GtkEntry    *entry,
-                                gint         position,
-                                gboolean     reset_im)
+gtk_entry_real_set_position (GtkEditable *editable,
+                            gint         position)
 {
+  GtkEntry *entry = GTK_ENTRY (editable);
+
   if (position < 0 || position > entry->text_length)
     position = entry->text_length;
 
   if (position != entry->current_pos ||
       position != entry->selection_bound)
     {
-      if (reset_im)
-       gtk_entry_reset_im_context (entry);
+      _gtk_entry_reset_im_context (entry);
       gtk_entry_set_positions (entry, position, position);
     }
 }
 
-static void
-gtk_entry_real_set_position (GtkEditable *editable,
-                            gint         position)
-{
-  gtk_entry_set_position_internal (GTK_ENTRY (editable), position, TRUE);
-}
-
 static gint
 gtk_entry_get_position (GtkEditable *editable)
 {
@@ -2182,7 +2326,7 @@ gtk_entry_set_selection_bounds (GtkEditable *editable,
   if (end < 0)
     end = entry->text_length;
   
-  gtk_entry_reset_im_context (entry);
+  _gtk_entry_reset_im_context (entry);
 
   gtk_entry_set_positions (entry,
                           MIN (end, entry->text_length),
@@ -2209,7 +2353,18 @@ gtk_entry_style_set      (GtkWidget      *widget,
                         GtkStyle       *previous_style)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  gint focus_width;
+  gboolean interior_focus;
+
+  gtk_widget_style_get (widget,
+                       "focus-line-width", &focus_width,
+                       "interior-focus", &interior_focus,
+                       NULL);
 
+  priv->focus_width = focus_width;
+  priv->interior_focus = interior_focus;
+  
   gtk_entry_recompute (entry);
 
   if (previous_style && GTK_WIDGET_REALIZED (widget))
@@ -2266,6 +2421,15 @@ gtk_entry_start_editing (GtkCellEditable *cell_editable,
                    G_CALLBACK (gtk_cell_editable_key_press_event), NULL);
 }
 
+static void
+gtk_entry_password_hint_free (GtkEntryPasswordHint *password_hint)
+{
+  if (password_hint->password_hint_timeout_id)
+    g_source_remove (password_hint->password_hint_timeout_id);
+
+  g_free (password_hint);
+}
+
 /* Default signal handlers
  */
 static void
@@ -2274,18 +2438,17 @@ gtk_entry_real_insert_text (GtkEditable *editable,
                            gint         new_text_length,
                            gint        *position)
 {
+  GtkEntry *entry = GTK_ENTRY (editable);
   gint index;
   gint n_chars;
 
-  GtkEntry *entry = GTK_ENTRY (editable);
-
   if (new_text_length < 0)
     new_text_length = strlen (new_text);
 
   n_chars = g_utf8_strlen (new_text, new_text_length);
   if (entry->text_max_length > 0 && n_chars + entry->text_length > entry->text_max_length)
     {
-      gdk_display_beep (gtk_widget_get_display (GTK_WIDGET (entry)));
+      gtk_widget_error_bell (GTK_WIDGET (entry));
       n_chars = entry->text_max_length - entry->text_length;
       new_text_length = g_utf8_offset_to_pointer (new_text, n_chars) - new_text;
     }
@@ -2347,11 +2510,43 @@ gtk_entry_real_insert_text (GtkEditable *editable,
   if (entry->selection_bound > *position)
     entry->selection_bound += n_chars;
 
+  if (n_chars == 1 && !entry->visible && (new_text_length < PASSWORD_HINT_MAX))
+    {
+      guint password_hint_timeout;
+
+      g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
+                    "gtk-entry-password-hint-timeout", &password_hint_timeout,
+                    NULL);
+
+      if (password_hint_timeout > 0)
+        {
+          GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
+                                                                    quark_password_hint);
+
+          if (!password_hint)
+            {
+              password_hint = g_new0 (GtkEntryPasswordHint, 1);
+              g_object_set_qdata_full (G_OBJECT (entry), quark_password_hint,
+                                       password_hint,
+                                       (GDestroyNotify) gtk_entry_password_hint_free);
+            }
+
+          memset (&password_hint->password_hint, 0x0, PASSWORD_HINT_MAX);
+          password_hint->password_hint_length = new_text_length;
+          memcpy (&password_hint->password_hint, new_text, new_text_length);
+          password_hint->password_hint_position = *position + n_chars;
+       }
+    }
+  else
+    {
+      g_object_set_qdata (G_OBJECT (entry), quark_password_hint, NULL);
+    }
+
   *position += n_chars;
 
   gtk_entry_recompute (entry);
 
-  g_signal_emit_by_name (editable, "changed");
+  emit_changed (entry);
   g_object_notify (G_OBJECT (editable), "text");
 }
 
@@ -2401,7 +2596,7 @@ gtk_entry_real_delete_text (GtkEditable *editable,
       
       gtk_entry_recompute (entry);
 
-      g_signal_emit_by_name (editable, "changed");
+      emit_changed (entry);
       g_object_notify (G_OBJECT (editable), "text");
     }
 }
@@ -2445,7 +2640,7 @@ gtk_entry_move_cursor (GtkEntry       *entry,
 {
   gint new_pos = entry->current_pos;
 
-  gtk_entry_reset_im_context (entry);
+  _gtk_entry_reset_im_context (entry);
 
   if (entry->current_pos != entry->selection_bound && !extend_selection)
     {
@@ -2463,7 +2658,6 @@ gtk_entry_move_cursor (GtkEntry       *entry,
              new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
            else 
              new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
-
            break;
          }
        case GTK_MOVEMENT_LOGICAL_POSITIONS:
@@ -2494,6 +2688,27 @@ gtk_entry_move_cursor (GtkEntry       *entry,
          break;
        case GTK_MOVEMENT_VISUAL_POSITIONS:
          new_pos = gtk_entry_move_visually (entry, new_pos, count);
+          if (entry->current_pos == new_pos)
+            {
+              if (!extend_selection)
+                {
+                  if (!gtk_widget_keynav_failed (GTK_WIDGET (entry),
+                                                 count > 0 ?
+                                                 GTK_DIR_RIGHT : GTK_DIR_LEFT))
+                    {
+                      GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
+
+                      if (toplevel)
+                        gtk_widget_child_focus (toplevel,
+                                                count > 0 ?
+                                                GTK_DIR_RIGHT : GTK_DIR_LEFT);
+                    }
+                }
+              else
+                {
+                  gtk_widget_error_bell (GTK_WIDGET (entry));
+                }
+            }
          break;
        case GTK_MOVEMENT_WORDS:
          while (count > 0)
@@ -2506,11 +2721,15 @@ gtk_entry_move_cursor (GtkEntry       *entry,
              new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
              count++;
            }
+          if (entry->current_pos == new_pos)
+            gtk_widget_error_bell (GTK_WIDGET (entry));
          break;
        case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
        case GTK_MOVEMENT_PARAGRAPH_ENDS:
        case GTK_MOVEMENT_BUFFER_ENDS:
          new_pos = count < 0 ? 0 : entry->text_length;
+          if (entry->current_pos == new_pos)
+            gtk_widget_error_bell (GTK_WIDGET (entry));
          break;
        case GTK_MOVEMENT_DISPLAY_LINES:
        case GTK_MOVEMENT_PARAGRAPHS:
@@ -2537,7 +2756,7 @@ gtk_entry_insert_at_cursor (GtkEntry    *entry,
 
   if (entry->editable)
     {
-      gtk_entry_reset_im_context (entry);
+      _gtk_entry_reset_im_context (entry);
 
       gtk_editable_insert_text (editable, str, -1, &pos);
       gtk_editable_set_position (editable, pos);
@@ -2552,11 +2771,15 @@ gtk_entry_delete_from_cursor (GtkEntry       *entry,
   GtkEditable *editable = GTK_EDITABLE (entry);
   gint start_pos = entry->current_pos;
   gint end_pos = entry->current_pos;
+  gint old_n_bytes = entry->n_bytes;
   
-  gtk_entry_reset_im_context (entry);
+  _gtk_entry_reset_im_context (entry);
 
   if (!entry->editable)
-    return;
+    {
+      gtk_widget_error_bell (GTK_WIDGET (entry));
+      return;
+    }
 
   if (entry->selection_bound != entry->current_pos)
     {
@@ -2574,26 +2797,26 @@ gtk_entry_delete_from_cursor (GtkEntry       *entry,
       if (count < 0)
        {
          /* Move to end of current word, or if not on a word, end of previous word */
-         end_pos = gtk_entry_move_backward_word (entry, end_pos, TRUE);
-         end_pos = gtk_entry_move_forward_word (entry, end_pos, TRUE);
+         end_pos = gtk_entry_move_backward_word (entry, end_pos, FALSE);
+         end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
        }
       else if (count > 0)
        {
          /* Move to beginning of current word, or if not on a word, begining of next word */
-         start_pos = gtk_entry_move_forward_word (entry, start_pos, TRUE);
-         start_pos = gtk_entry_move_backward_word (entry, start_pos, TRUE);
+         start_pos = gtk_entry_move_forward_word (entry, start_pos, FALSE);
+         start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
        }
        
       /* Fall through */
     case GTK_DELETE_WORD_ENDS:
       while (count < 0)
        {
-         start_pos = gtk_entry_move_backward_word (entry, start_pos, TRUE);
+         start_pos = gtk_entry_move_backward_word (entry, start_pos, FALSE);
          count++;
        }
       while (count > 0)
        {
-         end_pos = gtk_entry_move_forward_word (entry, end_pos, TRUE);
+         end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
          count--;
        }
       gtk_editable_delete_text (editable, start_pos, end_pos);
@@ -2613,7 +2836,10 @@ gtk_entry_delete_from_cursor (GtkEntry       *entry,
       gtk_entry_delete_whitespace (entry);
       break;
     }
-  
+
+  if (entry->n_bytes == old_n_bytes)
+    gtk_widget_error_bell (GTK_WIDGET (entry));
+
   gtk_entry_pend_cursor_blink (entry);
 }
 
@@ -2623,10 +2849,13 @@ gtk_entry_backspace (GtkEntry *entry)
   GtkEditable *editable = GTK_EDITABLE (entry);
   gint prev_pos;
 
-  gtk_entry_reset_im_context (entry);
+  _gtk_entry_reset_im_context (entry);
 
   if (!entry->editable || !entry->text)
-    return;
+    {
+      gtk_widget_error_bell (GTK_WIDGET (entry));
+      return;
+    }
 
   if (entry->selection_bound != entry->current_pos)
     {
@@ -2679,6 +2908,10 @@ gtk_entry_backspace (GtkEntry *entry)
       
       g_free (log_attrs);
     }
+  else
+    {
+      gtk_widget_error_bell (GTK_WIDGET (entry));
+    }
 
   gtk_entry_pend_cursor_blink (entry);
 }
@@ -2712,6 +2945,10 @@ gtk_entry_cut_clipboard (GtkEntry *entry)
       if (gtk_editable_get_selection_bounds (editable, &start, &end))
        gtk_editable_delete_text (editable, start, end);
     }
+  else
+    {
+      gtk_widget_error_bell (GTK_WIDGET (entry));
+    }
 }
 
 static void
@@ -2719,6 +2956,8 @@ gtk_entry_paste_clipboard (GtkEntry *entry)
 {
   if (entry->editable)
     gtk_entry_paste (entry, GDK_NONE);
+  else
+    gtk_widget_error_bell (GTK_WIDGET (entry));
 }
 
 static void
@@ -2738,6 +2977,8 @@ static void
 gtk_entry_toggle_overwrite (GtkEntry *entry)
 {
   entry->overwrite_mode = !entry->overwrite_mode;
+  gtk_entry_pend_cursor_blink (entry);
+  gtk_widget_queue_draw (GTK_WIDGET (entry));
 }
 
 static void
@@ -2847,6 +3088,10 @@ gtk_entry_enter_text (GtkEntry       *entry,
 {
   GtkEditable *editable = GTK_EDITABLE (entry);
   gint tmp_pos;
+  gboolean old_need_im_reset;
+
+  old_need_im_reset = entry->need_im_reset;
+  entry->need_im_reset = FALSE;
 
   if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
     gtk_editable_delete_selection (editable);
@@ -2858,7 +3103,9 @@ gtk_entry_enter_text (GtkEntry       *entry,
 
   tmp_pos = entry->current_pos;
   gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
-  gtk_entry_set_position_internal (entry, tmp_pos, FALSE);
+  gtk_editable_set_position (editable, tmp_pos);
+
+  entry->need_im_reset = old_need_im_reset;
 }
 
 /* All changes to entry->current_pos and entry->selection_bound
@@ -2893,8 +3140,11 @@ gtk_entry_set_positions (GtkEntry *entry,
 
   g_object_thaw_notify (G_OBJECT (entry));
 
-  if (changed)
-    gtk_entry_recompute (entry);
+  if (changed) 
+    {
+      gtk_entry_move_adjustments (entry);
+      gtk_entry_recompute (entry);
+    }
 }
 
 static void
@@ -2941,8 +3191,6 @@ recompute_idle_func (gpointer data)
 {
   GtkEntry *entry;
 
-  GDK_THREADS_ENTER ();
-
   entry = GTK_ENTRY (data);
 
   entry->recompute_idle = 0;
@@ -2955,8 +3203,6 @@ recompute_idle_func (gpointer data)
       update_im_cursor_location (entry);
     }
 
-  GDK_THREADS_LEAVE ();
-
   return FALSE;
 }
 
@@ -2968,7 +3214,7 @@ gtk_entry_recompute (GtkEntry *entry)
   
   if (!entry->recompute_idle)
     {
-      entry->recompute_idle = g_idle_add_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
+      entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
                                               recompute_idle_func, entry, NULL); 
     }
 }
@@ -2991,7 +3237,16 @@ append_char (GString *str,
       ++i;
     }
 }
-     
+
+static gboolean
+gtk_entry_remove_password_hint (gpointer data)
+{
+  /* Force the string to be redrawn, but now without a visible character */
+  gtk_entry_recompute (GTK_ENTRY (data));
+
+  return FALSE;
+}
+
 static PangoLayout *
 gtk_entry_create_layout (GtkEntry *entry,
                         gboolean  include_preedit)
@@ -3005,7 +3260,7 @@ gtk_entry_create_layout (GtkEntry *entry,
   PangoAttrList *preedit_attrs = NULL;
 
   pango_layout_set_single_paragraph_mode (layout, TRUE);
-  
+
   if (include_preedit)
     {
       gtk_im_context_get_preedit_string (entry->im_context,
@@ -3029,7 +3284,7 @@ gtk_entry_create_layout (GtkEntry *entry,
           gint ch_len;
           gint preedit_len_chars;
           gunichar invisible_char;
-          
+
           ch_len = g_utf8_strlen (entry->text, entry->n_bytes);
           preedit_len_chars = g_utf8_strlen (preedit_string, -1);
           ch_len += preedit_len_chars;
@@ -3105,13 +3360,61 @@ gtk_entry_create_layout (GtkEntry *entry,
         {
           GString *str = g_string_new (NULL);
           gunichar invisible_char;
-          
+          guint password_hint_timeout;
+          GtkEntryPasswordHint *password_hint;
+
+          g_object_get (gtk_widget_get_settings (widget),
+                        "gtk-entry-password-hint-timeout", &password_hint_timeout,
+                        NULL);
+
           if (entry->invisible_char != 0)
             invisible_char = entry->invisible_char;
           else
             invisible_char = ' '; /* just pick a char */
-          
-          append_char (str, invisible_char, entry->text_length);
+
+          password_hint = g_object_get_qdata (G_OBJECT (entry),
+                                              quark_password_hint);
+
+          if (password_hint && password_hint->password_hint_timeout_id)
+            {
+              g_source_remove (password_hint->password_hint_timeout_id);
+              password_hint->password_hint_timeout_id = 0;
+            }
+
+          if (password_hint_timeout == 0 || password_hint == NULL ||
+              (password_hint && password_hint->password_hint_length == 0))
+            {
+              append_char (str, invisible_char, entry->text_length);
+            }
+          else if (password_hint)
+            {
+              /* Draw hidden characters upto the inserted position,
+               * then the real thing, pad up to full length
+               */
+              if (password_hint->password_hint_position > 1)
+                append_char (str, invisible_char,
+                             password_hint->password_hint_position - 1);
+
+              g_string_append_len (str, password_hint->password_hint,
+                                   password_hint->password_hint_length);
+
+              if (password_hint->password_hint_position < entry->text_length)
+                append_char (str, invisible_char,
+                             entry->text_length -
+                             password_hint->password_hint_position);
+
+              /* Now remove this last input character, don't need
+               * it anymore
+               */
+              memset (password_hint->password_hint, 0, PASSWORD_HINT_MAX);
+              password_hint->password_hint_length = 0;
+
+              password_hint->password_hint_timeout_id =
+                gdk_threads_add_timeout (password_hint_timeout,
+                               (GSourceFunc) gtk_entry_remove_password_hint,
+                               entry);
+            }
+
           pango_layout_set_text (layout, str->str, str->len);
           g_string_free (str, TRUE);
         }
@@ -3119,8 +3422,7 @@ gtk_entry_create_layout (GtkEntry *entry,
       
   pango_layout_set_attributes (layout, tmp_attrs);
 
-  if (preedit_string)
-    g_free (preedit_string);
+  g_free (preedit_string);
   if (preedit_attrs)
     pango_attr_list_unref (preedit_attrs);
       
@@ -3154,16 +3456,18 @@ get_layout_position (GtkEntry *entry,
   PangoLayout *layout;
   PangoRectangle logical_rect;
   gint area_width, area_height;
+  GtkBorder inner_border;
   gint y_pos;
   PangoLayoutLine *line;
   
   layout = gtk_entry_ensure_layout (entry, TRUE);
 
-  get_text_area_size (entry, NULL, NULL, &area_width, &area_height);      
-      
-  area_height = PANGO_SCALE * (area_height - 2 * INNER_BORDER);
-  
-  line = pango_layout_get_lines (layout)->data;
+  get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
+  _gtk_entry_effective_inner_border (entry, &inner_border);
+
+  area_height = PANGO_SCALE * (area_height - inner_border.top - inner_border.bottom);
+
+  line = pango_layout_get_lines_readonly (layout)->data;
   pango_layout_line_get_extents (line, NULL, &logical_rect);
   
   /* Align primarily for locale's ascent/descent */
@@ -3178,10 +3482,10 @@ get_layout_position (GtkEntry *entry,
   else if (y_pos + logical_rect.height > area_height)
     y_pos = area_height - logical_rect.height;
   
-  y_pos = INNER_BORDER + y_pos / PANGO_SCALE;
+  y_pos = inner_border.top + y_pos / PANGO_SCALE;
 
   if (x)
-    *x = INNER_BORDER - entry->scroll_offset;
+    *x = inner_border.left - entry->scroll_offset;
 
   if (y)
     *y = y_pos;
@@ -3218,6 +3522,7 @@ gtk_entry_draw_text (GtkEntry *entry)
          gint n_ranges, i;
           PangoRectangle logical_rect;
          GdkColor *selection_color, *text_color;
+          GtkBorder inner_border;
 
          pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
          gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
@@ -3233,9 +3538,11 @@ gtk_entry_draw_text (GtkEntry *entry)
              text_color = &widget->style->text [GTK_STATE_ACTIVE];
            }
 
+          _gtk_entry_effective_inner_border (entry, &inner_border);
+
          for (i = 0; i < n_ranges; ++i)
            cairo_rectangle (cr,
-                            INNER_BORDER - entry->scroll_offset + ranges[2 * i],
+                            inner_border.left - entry->scroll_offset + ranges[2 * i],
                             y,
                             ranges[2 * i + 1],
                             logical_rect.height);
@@ -3288,71 +3595,123 @@ gtk_entry_draw_cursor (GtkEntry  *entry,
       GtkWidget *widget = GTK_WIDGET (entry);
       GdkRectangle cursor_location;
       gboolean split_cursor;
-
-      gint xoffset = INNER_BORDER - entry->scroll_offset;
-      gint strong_x, weak_x;
+      PangoRectangle cursor_rect;
+      GtkBorder inner_border;
+      gint xoffset;
       gint text_area_height;
-      PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
-      PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
-      gint x1 = 0;
-      gint x2 = 0;
+      gint cursor_index;
+      gboolean block;
+      gboolean block_at_line_end;
+
+      _gtk_entry_effective_inner_border (entry, &inner_border);
+
+      xoffset = inner_border.left - entry->scroll_offset;
 
       gdk_drawable_get_size (entry->text_area, NULL, &text_area_height);
-      
-      gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
 
-      g_object_get (gtk_widget_get_settings (widget),
-                   "gtk-split-cursor", &split_cursor,
-                   NULL);
+      cursor_index = g_utf8_offset_to_pointer (entry->text, entry->current_pos + entry->preedit_cursor) - entry->text;
+      if (!entry->overwrite_mode)
+        block = FALSE;
+      else
+        block = _gtk_text_util_get_block_cursor_location (gtk_entry_ensure_layout (entry, TRUE),
+                                                          cursor_index, &cursor_rect, &block_at_line_end);
+
+      if (!block)
+        {
+          gint strong_x, weak_x;
+          PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
+          PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
+          gint x1 = 0;
+          gint x2 = 0;
 
-      dir1 = entry->resolved_dir;
+          gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
+
+          g_object_get (gtk_widget_get_settings (widget),
+                        "gtk-split-cursor", &split_cursor,
+                        NULL);
+
+          dir1 = entry->resolved_dir;
       
-      if (split_cursor)
-       {
-         x1 = strong_x;
+          if (split_cursor)
+            {
+              x1 = strong_x;
 
-         if (weak_x != strong_x)
-           {
-             dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
-             x2 = weak_x;
-           }
-       }
-      else
-       {
-         if (keymap_direction == entry->resolved_dir)
-           x1 = strong_x;
-         else
-           x1 = weak_x;
-       }
+              if (weak_x != strong_x)
+                {
+                  dir2 = (entry->resolved_dir == PANGO_DIRECTION_LTR) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR;
+                  x2 = weak_x;
+                }
+            }
+          else
+            {
+              if (keymap_direction == entry->resolved_dir)
+                x1 = strong_x;
+              else
+                x1 = weak_x;
+            }
 
-      cursor_location.x = xoffset + x1;
-      cursor_location.y = INNER_BORDER;
-      cursor_location.width = 0;
-      cursor_location.height = text_area_height - 2 * INNER_BORDER ;
+          cursor_location.x = xoffset + x1;
+          cursor_location.y = inner_border.top;
+          cursor_location.width = 0;
+          cursor_location.height = text_area_height - inner_border.top - inner_border.bottom;
 
-      draw_insertion_cursor (entry,
-                            &cursor_location, TRUE, dir1,
-                            dir2 != PANGO_DIRECTION_NEUTRAL);
+          draw_insertion_cursor (entry,
+                                 &cursor_location, TRUE, dir1,
+                                 dir2 != PANGO_DIRECTION_NEUTRAL);
       
-      if (dir2 != PANGO_DIRECTION_NEUTRAL)
-       {
-         cursor_location.x = xoffset + x2;
-         draw_insertion_cursor (entry,
-                                &cursor_location, FALSE, dir2,
-                                TRUE);
-       }
+          if (dir2 != PANGO_DIRECTION_NEUTRAL)
+            {
+              cursor_location.x = xoffset + x2;
+              draw_insertion_cursor (entry,
+                                     &cursor_location, FALSE, dir2,
+                                     TRUE);
+            }
+        }
+      else /* overwrite_mode */
+        {
+          PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
+          GdkColor cursor_color;
+          GdkRectangle rect;
+          cairo_t *cr;
+          gint x, y;
+
+          get_layout_position (entry, &x, &y);
+
+          rect.x = PANGO_PIXELS (cursor_rect.x) + x;
+          rect.y = PANGO_PIXELS (cursor_rect.y) + y;
+          rect.width = PANGO_PIXELS (cursor_rect.width);
+          rect.height = PANGO_PIXELS (cursor_rect.height);
+
+          cr = gdk_cairo_create (entry->text_area);
+
+          _gtk_widget_get_cursor_color (widget, &cursor_color);
+          gdk_cairo_set_source_color (cr, &cursor_color);
+          gdk_cairo_rectangle (cr, &rect);
+          cairo_fill (cr);
+
+          if (!block_at_line_end)
+            {
+              gdk_cairo_rectangle (cr, &rect);
+              cairo_clip (cr);
+              cairo_move_to (cr, x, y);
+              gdk_cairo_set_source_color (cr, &widget->style->base[widget->state]);
+              pango_cairo_show_layout (cr, layout);
+            }
+
+          cairo_destroy (cr);
+        }
     }
 }
 
 static void
 gtk_entry_queue_draw (GtkEntry *entry)
 {
-  if (GTK_WIDGET_REALIZED (entry))
+  if (GTK_WIDGET_DRAWABLE (entry))
     gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
 }
 
-static void
-gtk_entry_reset_im_context (GtkEntry *entry)
+void
+_gtk_entry_reset_im_context (GtkEntry *entry)
 {
   if (entry->need_im_reset)
     {
@@ -3369,7 +3728,7 @@ gtk_entry_find_position (GtkEntry *entry,
   PangoLayoutLine *line;
   gint index;
   gint pos;
-  gboolean trailing;
+  gint trailing;
   const gchar *text;
   gint cursor_index;
   
@@ -3377,7 +3736,7 @@ gtk_entry_find_position (GtkEntry *entry,
   text = pango_layout_get_text (layout);
   cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
   
-  line = pango_layout_get_lines (layout)->data;
+  line = pango_layout_get_lines_readonly (layout)->data;
   pango_layout_line_x_to_index (line, x * PANGO_SCALE, &index, &trailing);
 
   if (index >= cursor_index && entry->preedit_length)
@@ -3454,6 +3813,7 @@ gtk_entry_adjust_scroll (GtkEntry *entry)
   GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
   gint min_offset, max_offset;
   gint text_area_width, text_width;
+  GtkBorder inner_border;
   gint strong_x, weak_x;
   gint strong_xoffset, weak_xoffset;
   gfloat xalign;
@@ -3463,12 +3823,16 @@ gtk_entry_adjust_scroll (GtkEntry *entry)
 
   if (!GTK_WIDGET_REALIZED (entry))
     return;
-  
+
+  _gtk_entry_effective_inner_border (entry, &inner_border);
+
   gdk_drawable_get_size (entry->text_area, &text_area_width, NULL);
-  text_area_width -= 2 * INNER_BORDER;
+  text_area_width -= inner_border.left + inner_border.right;
+  if (text_area_width < 0)
+    text_area_width = 0;
 
   layout = gtk_entry_ensure_layout (entry, TRUE);
-  line = pango_layout_get_lines (layout)->data;
+  line = pango_layout_get_lines_readonly (layout)->data;
 
   pango_layout_line_get_extents (line, NULL, &logical_rect);
 
@@ -3538,6 +3902,38 @@ gtk_entry_adjust_scroll (GtkEntry *entry)
   g_object_notify (G_OBJECT (entry), "scroll-offset");
 }
 
+static void
+gtk_entry_move_adjustments (GtkEntry *entry)
+{
+  PangoContext *context;
+  PangoFontMetrics *metrics;
+  gint x, layout_x, border_x, border_y;
+  gint char_width;
+  GtkAdjustment *adjustment;
+
+  adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
+  if (!adjustment)
+    return;
+
+  /* Cursor position, layout offset, border width, and widget allocation */
+  gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
+  get_layout_position (entry, &layout_x, NULL);
+  _gtk_entry_get_borders (entry, &border_x, &border_y);
+  x += entry->widget.allocation.x + layout_x + border_x;
+
+  /* Approximate width of a char, so user can see what is ahead/behind */
+  context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
+  metrics = pango_context_get_metrics (context, 
+                                       entry->widget.style->font_desc,
+                                      pango_context_get_language (context));
+  char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
+
+  /* Scroll it */
+  gtk_adjustment_clamp_page (adjustment, 
+                            x - (char_width + 1),   /* one char + one pixel before */
+                            x + (char_width + 2));  /* one char + cursor + one pixel after */
+}
+
 static gint
 gtk_entry_move_visually (GtkEntry *entry,
                         gint      start,
@@ -3801,26 +4197,39 @@ paste_received (GtkClipboard *clipboard,
     {
       gint pos, start, end;
       gint length = -1;
-      GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
+      gboolean popup_completion;
+      GtkEntryCompletion *completion;
 
-      if (priv->truncate_multiline)
+      completion = gtk_entry_get_completion (entry);
+
+      if (entry->truncate_multiline)
         length = truncate_multiline (text);
 
+      /* only complete if the selection is at the end */
+      popup_completion = (entry->text_length == MAX (entry->current_pos, entry->selection_bound));
+
       if (completion)
        {
-         g_signal_handler_block (entry, completion->priv->changed_id);
          if (GTK_WIDGET_MAPPED (completion->priv->popup_window))
            _gtk_entry_completion_popdown (completion);
+
+          if (!popup_completion && completion->priv->changed_id > 0)
+            g_signal_handler_block (entry, completion->priv->changed_id);
        }
 
+      begin_change (entry);
+      g_object_freeze_notify (G_OBJECT (entry));
       if (gtk_editable_get_selection_bounds (editable, &start, &end))
         gtk_editable_delete_text (editable, start, end);
 
       pos = entry->current_pos;
       gtk_editable_insert_text (editable, text, length, &pos);
       gtk_editable_set_position (editable, pos);
+      g_object_thaw_notify (G_OBJECT (entry));
+      end_change (entry);
 
-      if (completion)
+      if (completion &&
+          !popup_completion && completion->priv->changed_id > 0)
        g_signal_handler_unblock (entry, completion->priv->changed_id);
     }
 
@@ -3907,6 +4316,13 @@ gtk_entry_update_primary_selection (GtkEntry *entry)
 /* Public API
  */
 
+/**
+ * gtk_entry_new:
+ *
+ * Creates a new entry.
+ *
+ * Return value: a new #GtkEntry.
+ */
 GtkWidget*
 gtk_entry_new (void)
 {
@@ -3943,6 +4359,14 @@ gtk_entry_new_with_max_length (gint max)
   return GTK_WIDGET (entry);
 }
 
+/**
+ * gtk_entry_set_text:
+ * @entry: a #GtkEntry
+ * @text: the new text
+ *
+ * Sets the text in the widget to the given
+ * value, replacing the current contents.
+ */
 void
 gtk_entry_set_text (GtkEntry    *entry,
                    const gchar *text)
@@ -3960,18 +4384,33 @@ gtk_entry_set_text (GtkEntry    *entry,
     return;
 
   completion = gtk_entry_get_completion (entry);
-  if (completion)
+  if (completion && completion->priv->changed_id > 0)
     g_signal_handler_block (entry, completion->priv->changed_id);
 
+  begin_change (entry);
+  g_object_freeze_notify (G_OBJECT (entry));
   gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
 
   tmp_pos = 0;
   gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos);
+  g_object_thaw_notify (G_OBJECT (entry));
+  end_change (entry);
 
-  if (completion)
+  if (completion && completion->priv->changed_id > 0)
     g_signal_handler_unblock (entry, completion->priv->changed_id);
 }
 
+/**
+ * gtk_entry_append_text:
+ * @entry: a #GtkEntry
+ * @text: the text to append
+ *
+ * Appends the given text to the contents of the widget.
+ *
+ * Deprecated: gtk_entry_append_text() is deprecated and should not
+ *   be used in newly-written code. Use gtk_editable_insert_text()
+ *   instead.
+ */
 void
 gtk_entry_append_text (GtkEntry *entry,
                       const gchar *text)
@@ -3985,6 +4424,17 @@ gtk_entry_append_text (GtkEntry *entry,
   gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
 }
 
+/**
+ * gtk_entry_prepend_text:
+ * @entry: a #GtkEntry
+ * @text: the text to prepend
+ *
+ * Prepends the given text to the contents of the widget.
+ *
+ * Deprecated: gtk_entry_prepend_text() is deprecated and should not
+ *    be used in newly-written code. Use gtk_editable_insert_text()
+ *    instead.
+ */
 void
 gtk_entry_prepend_text (GtkEntry *entry,
                        const gchar *text)
@@ -3998,6 +4448,20 @@ gtk_entry_prepend_text (GtkEntry *entry,
   gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &tmp_pos);
 }
 
+/**
+ * gtk_entry_set_position:
+ * @entry: a #GtkEntry
+ * @position:  the position of the cursor. The cursor is displayed
+ *    before the character with the given (base 0) index in the widget. 
+ *    The value must be less than or equal to the number of characters 
+ *    in the widget. A value of -1 indicates that the position should
+ *    be set after the last character in the entry. Note that this 
+ *    position is in characters, not in bytes.
+ *
+ * Sets the cursor position in an entry to the given value. 
+ *
+ * Deprecated: Use gtk_editable_set_position() instead.
+ */
 void
 gtk_entry_set_position (GtkEntry *entry,
                        gint       position)
@@ -4007,6 +4471,20 @@ gtk_entry_set_position (GtkEntry *entry,
   gtk_editable_set_position (GTK_EDITABLE (entry), position);
 }
 
+/**
+ * gtk_entry_set_visibility:
+ * @entry: a #GtkEntry
+ * @visible: %TRUE if the contents of the entry are displayed
+ *           as plaintext
+ *
+ * Sets whether the contents of the entry are visible or not. 
+ * When visibility is set to %FALSE, characters are displayed 
+ * as the invisible char, and will also appear that way when 
+ * the text in the entry widget is copied elsewhere.
+ *
+ * The default invisible char is the asterisk '*', but it can
+ * be changed with gtk_entry_set_invisible_char().
+ */
 void
 gtk_entry_set_visibility (GtkEntry *entry,
                          gboolean visible)
@@ -4075,7 +4553,6 @@ gtk_entry_get_visibility (GtkEntry *entry)
  * invisible char is an asterisk ('*').  If you set the invisible char
  * to 0, then the user will get no feedback at all; there will be
  * no text on the screen as they type.
- * 
  **/
 void
 gtk_entry_set_invisible_char (GtkEntry *entry,
@@ -4096,7 +4573,7 @@ gtk_entry_set_invisible_char (GtkEntry *entry,
  * @entry: a #GtkEntry
  *
  * Retrieves the character displayed in place of the real characters
- * for entries with visisbility set to false. See gtk_entry_set_invisible_char().
+ * for entries with visibility set to false. See gtk_entry_set_invisible_char().
  *
  * Return value: the current invisible char, or 0, if the entry does not
  *               show invisible text at all. 
@@ -4109,6 +4586,17 @@ gtk_entry_get_invisible_char (GtkEntry *entry)
   return entry->invisible_char;
 }
 
+/**
+ * gtk_entry_set_editable:
+ * @entry: a #GtkEntry
+ * @editable: %TRUE if the user is allowed to edit the text
+ *   in the widget
+ *
+ * Determines if the user can edit the text in the editable
+ * widget or not. 
+ *
+ * Deprecated: Use gtk_editable_set_editable() instead.
+ */
 void
 gtk_entry_set_editable (GtkEntry *entry,
                        gboolean  editable)
@@ -4126,7 +4614,7 @@ gtk_entry_set_editable (GtkEntry *entry,
  * See also gtk_editable_get_chars().
  *
  * Return value: a pointer to the contents of the widget as a
- *      string.  This string points to internally allocated
+ *      string. This string points to internally allocated
  *      storage in the widget and must not be freed, modified or
  *      stored.
  **/
@@ -4138,6 +4626,20 @@ gtk_entry_get_text (GtkEntry *entry)
   return entry->text;
 }
 
+/**
+ * gtk_entry_select_region:
+ * @entry: a #GtkEntry
+ * @start: the starting position
+ * @end: the end position
+ *
+ * Selects a region of text. The characters that are selected are 
+ * those characters at positions from @start_pos up to, but not 
+ * including @end_pos. If @end_pos is negative, then the the characters 
+ * selected will be those characters from @start_pos to the end of 
+ * the text. 
+ *
+ * Deprecated: Use gtk_editable_select_region() instead.
+ */
 void       
 gtk_entry_select_region  (GtkEntry       *entry,
                          gint            start,
@@ -4148,7 +4650,7 @@ gtk_entry_select_region  (GtkEntry       *entry,
 
 /**
  * gtk_entry_set_max_length:
- * @entry: a #GtkEntry.
+ * @entry: a #GtkEntry
  * @max: the maximum length of the entry, or 0 for no maximum.
  *   (other than the maximum length of entries.) The value passed in will
  *   be clamped to the range 0-65536.
@@ -4202,8 +4704,7 @@ gtk_entry_get_max_length (GtkEntry *entry)
  *
  * (For experts: if @setting is %TRUE, the entry calls
  * gtk_window_activate_default() on the window containing the entry, in
- * the default handler for the "activate" signal.)
- * 
+ * the default handler for the #GtkWidget::activate signal.)
  **/
 void
 gtk_entry_set_activates_default (GtkEntry *entry,
@@ -4245,7 +4746,6 @@ gtk_entry_get_activates_default (GtkEntry *entry)
  * <emphasis>request</emphasis>, the size can still be affected by
  * how you pack the widget into containers. If @n_chars is -1, the
  * size reverts to the default entry size.
- * 
  **/
 void
 gtk_entry_set_width_chars (GtkEntry *entry,
@@ -4316,6 +4816,58 @@ gtk_entry_get_has_frame (GtkEntry *entry)
   return entry->has_frame;
 }
 
+/**
+ * gtk_entry_set_inner_border:
+ * @entry: a #GtkEntry
+ * @border: a #GtkBorder, or %NULL
+ *
+ * Sets %entry's inner-border property to %border, or clears it if %NULL
+ * is passed. The inner-border is the area around the entry's text, but
+ * inside its frame.
+ *
+ * If set, this property overrides the inner-border style property.
+ * Overriding the style-provided border is useful when you want to do
+ * in-place editing of some text in a canvas or list widget, where
+ * pixel-exact positioning of the entry is important.
+ *
+ * Since: 2.10
+ **/
+void
+gtk_entry_set_inner_border (GtkEntry        *entry,
+                            const GtkBorder *border)
+{
+  g_return_if_fail (GTK_IS_ENTRY (entry));
+
+  gtk_widget_queue_resize (GTK_WIDGET (entry));
+
+  if (border)
+    g_object_set_qdata_full (G_OBJECT (entry), quark_inner_border,
+                             gtk_border_copy (border),
+                             (GDestroyNotify) gtk_border_free);
+  else
+    g_object_set_qdata (G_OBJECT (entry), quark_inner_border, NULL);
+
+  g_object_notify (G_OBJECT (entry), "inner-border");
+}
+
+/**
+ * gtk_entry_get_inner_border:
+ * @entry: a #GtkEntry
+ *
+ * This function returns the entry's #GtkEntry:inner-border property. See
+ * gtk_entry_set_inner_border() for more information.
+ *
+ * Return value: the entry's #GtkBorder, or %NULL if none was set.
+ *
+ * Since: 2.10
+ **/
+G_CONST_RETURN GtkBorder *
+gtk_entry_get_inner_border (GtkEntry *entry)
+{
+  g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
+
+  return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
+}
 
 /**
  * gtk_entry_get_layout:
@@ -4440,7 +4992,6 @@ gtk_entry_text_index_to_layout_index (GtkEntry *entry,
  * gtk_entry_layout_index_to_text_index() and
  * gtk_entry_text_index_to_layout_index() are needed to convert byte
  * indices in the layout to byte indices in the entry contents.
- * 
  **/
 void
 gtk_entry_get_layout_offsets (GtkEntry *entry,
@@ -4577,31 +5128,44 @@ popup_position_func (GtkMenu   *menu,
 {
   GtkEntry *entry = GTK_ENTRY (user_data);
   GtkWidget *widget = GTK_WIDGET (entry);
-  GdkScreen *screen = gtk_widget_get_screen (widget);
-  GtkRequisition req;
-  gint monitor_num;
+  GdkScreen *screen;
+  GtkRequisition menu_req;
   GdkRectangle monitor;
-  
+  GtkBorder inner_border;
+  gint monitor_num, strong_x, height;
   g_return_if_fail (GTK_WIDGET_REALIZED (entry));
 
-  gdk_window_get_origin (widget->window, x, y); 
-     
-  gtk_widget_size_request (entry->popup_menu, &req);
-  
-  *x += widget->allocation.width / 2;
-  *y += widget->allocation.height;
+  gdk_window_get_origin (entry->text_area, x, y);
 
-  monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
+  screen = gtk_widget_get_screen (widget);
+  monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
+  if (monitor_num < 0)
+    monitor_num = 0;
   gtk_menu_set_monitor (menu, monitor_num);
-  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
 
-  *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
-  *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
+  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+  gtk_widget_size_request (entry->popup_menu, &menu_req);
+  gdk_drawable_get_size (entry->text_area, NULL, &height);
+  gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
+  _gtk_entry_effective_inner_border (entry, &inner_border);
+
+  *x += inner_border.left + strong_x - entry->scroll_offset;
+  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+    *x -= menu_req.width;
+
+  if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
+    *y += height;
+  else if ((*y - menu_req.height) >= monitor.y)
+    *y -= menu_req.height;
+  else if (monitor.y + monitor.height - (*y + height) > *y)
+    *y += height;
+  else
+    *y -= menu_req.height;
 
   *push_in = FALSE;
 }
 
-
 static void
 unichar_chosen_func (const char *text,
                      gpointer    data)
@@ -4653,7 +5217,7 @@ popup_targets_received (GtkClipboard     *clipboard,
                            entry->editable && clipboard_contains_text);
       
       menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
-      gtk_widget_set_sensitive (menuitem, entry->current_pos != entry->selection_bound);
+      gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
       g_signal_connect_swapped (menuitem, "activate",
                                G_CALLBACK (gtk_entry_delete_cb), entry);
       gtk_widget_show (menuitem);
@@ -4876,11 +5440,13 @@ gtk_entry_drag_data_received (GtkWidget        *widget,
                              guint             time)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
   GtkEditable *editable = GTK_EDITABLE (widget);
   gchar *str;
 
-  str = gtk_selection_data_get_text (selection_data);
+  str = (gchar *) gtk_selection_data_get_text (selection_data);
+
+  x -= widget->style->xthickness;
+  y -= widget->style->ythickness;
 
   if (str && entry->editable)
     {
@@ -4888,7 +5454,7 @@ gtk_entry_drag_data_received (GtkWidget        *widget,
       gint sel1, sel2;
       gint length = -1;
 
-      if (priv->truncate_multiline)
+      if (entry->truncate_multiline)
         length = truncate_multiline (str);
 
       new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
@@ -4901,11 +5467,14 @@ gtk_entry_drag_data_received (GtkWidget        *widget,
       else
        {
          /* Replacing selection */
+          begin_change (entry);
+          g_object_freeze_notify (G_OBJECT (entry));
          gtk_editable_delete_text (editable, sel1, sel2);
          gtk_editable_insert_text (editable, str, length, &sel1);
+          g_object_thaw_notify (G_OBJECT (entry));
+          end_change (entry);
        }
       
-      g_free (str);
       gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
     }
   else
@@ -4913,6 +5482,8 @@ gtk_entry_drag_data_received (GtkWidget        *widget,
       /* Drag and drop didn't happen! */
       gtk_drag_finish (context, FALSE, FALSE, time);
     }
+
+  g_free (str);
 }
 
 static void
@@ -4956,21 +5527,24 @@ gtk_entry_drag_data_delete (GtkWidget      *widget,
  *  - the widget has focus
  */
 
-#define CURSOR_ON_MULTIPLIER 0.66
-#define CURSOR_OFF_MULTIPLIER 0.34
-#define CURSOR_PEND_MULTIPLIER 1.0
+#define CURSOR_ON_MULTIPLIER 2
+#define CURSOR_OFF_MULTIPLIER 1
+#define CURSOR_PEND_MULTIPLIER 3
+#define CURSOR_DIVIDER 3
 
 static gboolean
 cursor_blinks (GtkEntry *entry)
 {
-  GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
-  gboolean blink;
-
   if (GTK_WIDGET_HAS_FOCUS (entry) &&
       entry->editable &&
       entry->selection_bound == entry->current_pos)
     {
+      GtkSettings *settings;
+      gboolean blink;
+
+      settings = gtk_widget_get_settings (GTK_WIDGET (entry));
       g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
+
       return blink;
     }
   else
@@ -4988,6 +5562,17 @@ get_cursor_time (GtkEntry *entry)
   return time;
 }
 
+static gint
+get_cursor_blink_timeout (GtkEntry *entry)
+{
+  GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
+  gint timeout;
+
+  g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
+
+  return timeout;
+}
+
 static void
 show_cursor (GtkEntry *entry)
 {
@@ -5019,38 +5604,49 @@ static gint
 blink_cb (gpointer data)
 {
   GtkEntry *entry;
-
-  GDK_THREADS_ENTER ();
+  GtkEntryPrivate *priv; 
+  gint blink_timeout;
 
   entry = GTK_ENTRY (data);
-
+  priv = GTK_ENTRY_GET_PRIVATE (entry);
   if (!GTK_WIDGET_HAS_FOCUS (entry))
     {
       g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
                 "connect a handler to this signal, it must return\n"
                 "FALSE so the entry gets the event as well");
+
+      gtk_entry_check_cursor_blink (entry);
+
+      return FALSE;
     }
   
-  g_assert (GTK_WIDGET_HAS_FOCUS (entry));
   g_assert (entry->selection_bound == entry->current_pos);
-
-  if (entry->cursor_visible)
+  
+  blink_timeout = get_cursor_blink_timeout (entry);
+  if (priv->blink_time > 1000 * blink_timeout && 
+      blink_timeout < G_MAXINT/1000) 
+    {
+      /* we've blinked enough without the user doing anything, stop blinking */
+      show_cursor (entry);
+      entry->blink_timeout = 0;
+    } 
+  else if (entry->cursor_visible)
     {
       hide_cursor (entry);
-      entry->blink_timeout = g_timeout_add (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER,
+      entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
                                            blink_cb,
                                            entry);
     }
   else
     {
       show_cursor (entry);
-      entry->blink_timeout = g_timeout_add (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER,
+      priv->blink_time += get_cursor_time (entry);
+      entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
                                            blink_cb,
                                            entry);
     }
 
-  GDK_THREADS_LEAVE ();
-
   /* Remove ourselves */
   return FALSE;
 }
@@ -5058,14 +5654,18 @@ blink_cb (gpointer data)
 static void
 gtk_entry_check_cursor_blink (GtkEntry *entry)
 {
+  GtkEntryPrivate *priv; 
+  
+  priv = GTK_ENTRY_GET_PRIVATE (entry);
+
   if (cursor_blinks (entry))
     {
       if (!entry->blink_timeout)
        {
-         entry->blink_timeout = g_timeout_add (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER,
+         show_cursor (entry);
+         entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
                                                blink_cb,
                                                entry);
-         show_cursor (entry);
        }
     }
   else
@@ -5089,21 +5689,30 @@ gtk_entry_pend_cursor_blink (GtkEntry *entry)
       if (entry->blink_timeout != 0)
        g_source_remove (entry->blink_timeout);
       
-      entry->blink_timeout = g_timeout_add (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER,
+      entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
                                            blink_cb,
                                            entry);
       show_cursor (entry);
     }
 }
 
+static void
+gtk_entry_reset_blink_time (GtkEntry *entry)
+{
+  GtkEntryPrivate *priv; 
+  
+  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  
+  priv->blink_time = 0;
+}
+
+
 /* completion */
 static gint
 gtk_entry_completion_timeout (gpointer data)
 {
   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data);
 
-  GDK_THREADS_ENTER ();
-
   completion->priv->completion_timeout = 0;
 
   if (completion->priv->filter_model &&
@@ -5140,8 +5749,6 @@ gtk_entry_completion_timeout (gpointer data)
   else if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
     _gtk_entry_completion_popdown (completion);
 
-  GDK_THREADS_LEAVE ();
-
   return FALSE;
 }
 
@@ -5242,6 +5849,14 @@ gtk_entry_completion_key_press (GtkWidget   *widget,
         {
           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)));
+
+          if (completion->priv->inline_selection &&
+              completion->priv->completion_prefix)
+            {
+              gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), 
+                                  completion->priv->completion_prefix);
+              gtk_editable_set_position (GTK_EDITABLE (widget), -1);
+            }
         }
       else if (completion->priv->current_selected < matches)
         {
@@ -5250,6 +5865,25 @@ gtk_entry_completion_key_press (GtkWidget   *widget,
           path = gtk_tree_path_new_from_indices (completion->priv->current_selected, -1);
           gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view),
                                     path, NULL, FALSE);
+
+          if (completion->priv->inline_selection)
+            {
+
+              GtkTreeIter iter;
+              GtkTreeModel *model = NULL;
+              GtkTreeSelection *sel;
+              gboolean entry_set;
+
+              sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
+              if (!gtk_tree_selection_get_selected (sel, &model, &iter))
+                return FALSE;
+              
+              if (completion->priv->completion_prefix == NULL)
+                completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
+
+              g_signal_emit_by_name (completion, "cursor_on_match", model,
+                                     &iter, &entry_set);
+            }
         }
       else if (completion->priv->current_selected - matches >= 0)
         {
@@ -5258,31 +5892,81 @@ gtk_entry_completion_key_press (GtkWidget   *widget,
           path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
           gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->action_view),
                                     path, NULL, FALSE);
+
+          if (completion->priv->inline_selection &&
+              completion->priv->completion_prefix)
+            {
+              gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), 
+                                  completion->priv->completion_prefix);
+              gtk_editable_set_position (GTK_EDITABLE (widget), -1);
+            }
         }
 
       gtk_tree_path_free (path);
 
       return TRUE;
     }
-  else if (event->keyval == GDK_Escape) 
+  else if (event->keyval == GDK_Escape ||
+           event->keyval == GDK_Left ||
+           event->keyval == GDK_KP_Left ||
+           event->keyval == GDK_Right ||
+           event->keyval == GDK_KP_Right) 
     {
+      gboolean retval = TRUE;
+
+      _gtk_entry_reset_im_context (GTK_ENTRY (widget));
       _gtk_entry_completion_popdown (completion);
 
-      return TRUE;
+      if (completion->priv->current_selected < 0)
+        {
+          retval = FALSE;
+          goto keypress_completion_out;
+        }
+      else if (completion->priv->inline_selection)
+        {
+          /* Escape rejects the tentative completion */
+          if (event->keyval == GDK_Escape)
+            {
+              if (completion->priv->completion_prefix)
+                gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), 
+                                    completion->priv->completion_prefix);
+              else 
+                gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), "");
+            }
+
+          /* Move the cursor to the end for Right/Esc, to the
+             beginning for Left */
+          if (event->keyval == GDK_Right ||
+              event->keyval == GDK_KP_Right ||
+              event->keyval == GDK_Escape)
+            gtk_editable_set_position (GTK_EDITABLE (widget), -1);
+          else
+            gtk_editable_set_position (GTK_EDITABLE (widget), 0);
+        }
+
+keypress_completion_out:
+      if (completion->priv->inline_selection)
+        {
+          g_free (completion->priv->completion_prefix);
+          completion->priv->completion_prefix = NULL;
+        }
+
+      return retval;
     }
   else if (event->keyval == GDK_Tab || 
           event->keyval == GDK_KP_Tab ||
           event->keyval == GDK_ISO_Left_Tab) 
     {
-      GtkWidget *entry;
       GtkDirectionType dir = event->keyval == GDK_ISO_Left_Tab ? 
        GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
-
-      _gtk_entry_completion_popdown (completion);
       
-      entry = gtk_entry_completion_get_entry (completion);
+      _gtk_entry_reset_im_context (GTK_ENTRY (widget));
+      _gtk_entry_completion_popdown (completion);
 
-      gtk_widget_child_focus (gtk_widget_get_toplevel (entry), dir);
+      g_free (completion->priv->completion_prefix);
+      completion->priv->completion_prefix = NULL;
+
+      gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
 
       return TRUE;
     }
@@ -5290,6 +5974,9 @@ gtk_entry_completion_key_press (GtkWidget   *widget,
            event->keyval == GDK_KP_Enter ||
           event->keyval == GDK_Return)
     {
+      gboolean retval = TRUE;
+
+      _gtk_entry_reset_im_context (GTK_ENTRY (widget));
       _gtk_entry_completion_popdown (completion);
 
       if (completion->priv->current_selected < matches)
@@ -5300,48 +5987,49 @@ gtk_entry_completion_key_press (GtkWidget   *widget,
           gboolean entry_set;
 
           sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view));
-          if (!gtk_tree_selection_get_selected (sel, &model, &iter))
-            return FALSE;
-
-         g_signal_handler_block (completion->priv->entry,
-                                 completion->priv->changed_id);
-          g_signal_emit_by_name (completion, "match_selected",
-                                 model, &iter, &entry_set);
-         g_signal_handler_unblock (completion->priv->entry,
-                                   completion->priv->changed_id);
-
-          if (!entry_set)
+          if (gtk_tree_selection_get_selected (sel, &model, &iter))
             {
-              gchar *str = NULL;
-
-              gtk_tree_model_get (model, &iter,
-                                  completion->priv->text_column, &str,
-                                  -1);
-
               g_signal_handler_block (widget, completion->priv->changed_id);
-              gtk_entry_set_text (GTK_ENTRY (widget), str);
+              g_signal_emit_by_name (completion, "match_selected",
+                                     model, &iter, &entry_set);
               g_signal_handler_unblock (widget, completion->priv->changed_id);
 
-              /* move the cursor to the end */
-              gtk_editable_set_position (GTK_EDITABLE (widget), -1);
+              if (!entry_set)
+                {
+                  gchar *str = NULL;
 
-             g_free (str);
-            }
+                  gtk_tree_model_get (model, &iter,
+                                      completion->priv->text_column, &str,
+                                      -1);
 
-          return TRUE;
+                  gtk_entry_set_text (GTK_ENTRY (widget), str);
+
+                  /* move the cursor to the end */
+                  gtk_editable_set_position (GTK_EDITABLE (widget), -1);
+
+                  g_free (str);
+                }
+            }
+          else
+            retval = FALSE;
         }
       else if (completion->priv->current_selected - matches >= 0)
         {
           GtkTreePath *path;
 
+          _gtk_entry_reset_im_context (GTK_ENTRY (widget));
+
           path = gtk_tree_path_new_from_indices (completion->priv->current_selected - matches, -1);
 
           g_signal_emit_by_name (completion, "action_activated",
                                  gtk_tree_path_get_indices (path)[0]);
           gtk_tree_path_free (path);
-
-          return TRUE;
         }
+
+      g_free (completion->priv->completion_prefix);
+      completion->priv->completion_prefix = NULL;
+
+      return retval;
     }
 
   return FALSE;
@@ -5370,7 +6058,7 @@ gtk_entry_completion_changed (GtkWidget *entry,
     }
 
   completion->priv->completion_timeout =
-    g_timeout_add (COMPLETION_TIMEOUT,
+    gdk_threads_add_timeout (COMPLETION_TIMEOUT,
                    gtk_entry_completion_timeout,
                    completion);
 }
@@ -5453,12 +6141,18 @@ disconnect_completion_signals (GtkEntry           *entry,
                                       G_CALLBACK (completion_changed), entry);
   if (completion->priv->changed_id > 0 &&
       g_signal_handler_is_connected (entry, completion->priv->changed_id))
-    g_signal_handler_disconnect (entry, completion->priv->changed_id);
+    {
+      g_signal_handler_disconnect (entry, completion->priv->changed_id);
+      completion->priv->changed_id = 0;
+    }
   g_signal_handlers_disconnect_by_func (entry, 
                                        G_CALLBACK (gtk_entry_completion_key_press), completion);
   if (completion->priv->insert_text_id > 0 &&
       g_signal_handler_is_connected (entry, completion->priv->insert_text_id))
-    g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
+    {
+      g_signal_handler_disconnect (entry, completion->priv->insert_text_id);
+      completion->priv->insert_text_id = 0;
+    }
   g_signal_handlers_disconnect_by_func (entry, 
                                        G_CALLBACK (completion_insert_text_callback), completion);
   g_signal_handlers_disconnect_by_func (entry, 
@@ -5492,14 +6186,15 @@ connect_completion_signals (GtkEntry           *entry,
       g_signal_connect (entry, "focus_out_event",
                        G_CALLBACK (accept_completion_callback), completion);
     }
+
   g_signal_connect (completion, "notify",
                    G_CALLBACK (completion_changed), entry);
 }
 
 /**
  * gtk_entry_set_completion:
- * @entry: A #GtkEntry.
- * @completion: The #GtkEntryCompletion or %NULL.
+ * @entry: A #GtkEntry
+ * @completion: The #GtkEntryCompletion or %NULL
  *
  * Sets @completion to be the auxiliary completion object to use with @entry.
  * All further configuration of the completion mechanism is done on
@@ -5555,7 +6250,7 @@ gtk_entry_set_completion (GtkEntry           *entry,
 
 /**
  * gtk_entry_get_completion:
- * @entry: A #GtkEntry.
+ * @entry: A #GtkEntry
  *
  * Returns the auxiliary completion object currently in use by @entry.
  *
@@ -5576,5 +6271,58 @@ gtk_entry_get_completion (GtkEntry *entry)
   return completion;
 }
 
+/**
+ * gtk_entry_set_cursor_hadjustment:
+ * @entry: a #GtkEntry
+ * @adjustment: an adjustment which should be adjusted when the cursor 
+ *              is moved, or %NULL
+ *
+ * Hooks up an adjustment to the cursor position in an entry, so that when 
+ * the cursor is moved, the adjustment is scrolled to show that position. 
+ * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining 
+ * the adjustment.
+ *
+ * The adjustment has to be in pixel units and in the same coordinate system 
+ * as the entry. 
+ * 
+ * Since: 2.12
+ */
+void
+gtk_entry_set_cursor_hadjustment (GtkEntry      *entry,
+                                  GtkAdjustment *adjustment)
+{
+  g_return_if_fail (GTK_IS_ENTRY (entry));
+  if (adjustment)
+    g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+
+  if (adjustment)
+    g_object_ref (adjustment);
+
+  g_object_set_qdata_full (G_OBJECT (entry), 
+                           quark_cursor_hadjustment,
+                           adjustment, 
+                           g_object_unref);
+}
+
+/**
+ * gtk_entry_get_cursor_hadjustment:
+ * @entry: a #GtkEntry
+ *
+ * Retrieves the horizontal cursor adjustment for the entry. 
+ * See gtk_entry_set_cursor_hadjustment().
+ *
+ * Return value: the horizontal cursor adjustment, or %NULL 
+ *   if none has been set.
+ * 
+ * Since: 2.12
+ */
+GtkAdjustment*
+gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
+{
+  g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
+
+  return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
+}
+
 #define __GTK_ENTRY_C__
 #include "gtkaliasdef.c"