]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkentry.c
Fix some typos. Closes bug #475400.
[~andy/gtk] / gtk / gtkentry.c
index b1c0af322d1bf04269ae0e898c549c1aa7115485..2ccdfad3d0276f7ec7d17e3f63c2584667d83ae3 100644 (file)
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* GTK - The GIMP Toolkit
  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  *
 #include <pango/pango.h>
 
 #include "gdk/gdkkeysyms.h"
-#include "gtkalias.h"
 #include "gtkbindings.h"
 #include "gtkcelleditable.h"
 #include "gtkclipboard.h"
 #include "gtkdnd.h"
 #include "gtkentry.h"
 #include "gtkimagemenuitem.h"
+#include "gtkimcontextsimple.h"
 #include "gtkimmulticontext.h"
 #include "gtkintl.h"
 #include "gtkmain.h"
 #include "gtkwindow.h"
 #include "gtktreeview.h"
 #include "gtktreeselection.h"
+#include "gtkprivate.h"
 #include "gtkentryprivate.h"
 #include "gtkcelllayout.h"
+#include "gtkalias.h"
 
 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
 
 #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))
@@ -75,6 +83,23 @@ struct _GtkEntryPrivate
 {
   gfloat xalign;
   gint insert_pos;
+  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 {
@@ -99,12 +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_XALIGN,
+  PROP_TRUNCATE_MULTILINE,
+  PROP_SHADOW_TYPE
 };
 
 static guint signals[LAST_SIGNAL] = { 0 };
@@ -116,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);
 
@@ -139,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,
@@ -278,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);
@@ -294,9 +320,11 @@ static gint         gtk_entry_move_logically           (GtkEntry       *entry,
                                                        gint            start,
                                                        gint            count);
 static gint         gtk_entry_move_forward_word        (GtkEntry       *entry,
-                                                       gint            start);
+                                                       gint            start,
+                                                        gboolean        allow_whitespace);
 static gint         gtk_entry_move_backward_word       (GtkEntry       *entry,
-                                                       gint            start);
+                                                       gint            start,
+                                                        gboolean        allow_whitespace);
 static void         gtk_entry_delete_whitespace        (GtkEntry       *entry);
 static void         gtk_entry_select_word              (GtkEntry       *entry);
 static void         gtk_entry_select_line              (GtkEntry       *entry);
@@ -314,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,
@@ -324,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);
@@ -349,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, "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,
@@ -433,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;
@@ -479,25 +467,29 @@ 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",
+                                   g_param_spec_int ("cursor-position",
                                                      P_("Cursor Position"),
                                                      P_("The current position of the insertion cursor in chars"),
                                                      0,
                                                      MAX_SIZE,
                                                      0,
-                                                     G_PARAM_READABLE));
+                                                     GTK_PARAM_READABLE));
   
   g_object_class_install_property (gobject_class,
                                    PROP_SELECTION_BOUND,
-                                   g_param_spec_int ("selection_bound",
+                                   g_param_spec_int ("selection-bound",
                                                      P_("Selection Bound"),
                                                      P_("The position of the opposite end of the selection from the cursor in chars"),
                                                      0,
                                                      MAX_SIZE,
                                                      0,
-                                                     G_PARAM_READABLE));
+                                                     GTK_PARAM_READABLE));
   
   g_object_class_install_property (gobject_class,
                                    PROP_EDITABLE,
@@ -505,67 +497,75 @@ gtk_entry_class_init (GtkEntryClass *class)
                                                         P_("Editable"),
                                                         P_("Whether the entry contents can be edited"),
                                                          TRUE,
-                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
+                                                        GTK_PARAM_READWRITE));
   
   g_object_class_install_property (gobject_class,
                                    PROP_MAX_LENGTH,
-                                   g_param_spec_int ("max_length",
+                                   g_param_spec_int ("max-length",
                                                      P_("Maximum length"),
                                                      P_("Maximum number of characters for this entry. Zero if no maximum"),
                                                      0,
                                                      MAX_SIZE,
                                                      0,
-                                                     G_PARAM_READABLE | G_PARAM_WRITABLE));
+                                                     GTK_PARAM_READWRITE));
   g_object_class_install_property (gobject_class,
                                    PROP_VISIBILITY,
                                    g_param_spec_boolean ("visibility",
                                                         P_("Visibility"),
                                                         P_("FALSE displays the \"invisible char\" instead of the actual text (password mode)"),
                                                          TRUE,
-                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
+                                                        GTK_PARAM_READWRITE));
 
   g_object_class_install_property (gobject_class,
                                    PROP_HAS_FRAME,
-                                   g_param_spec_boolean ("has_frame",
+                                   g_param_spec_boolean ("has-frame",
                                                         P_("Has Frame"),
                                                         P_("FALSE removes outside bevel from entry"),
                                                          TRUE,
-                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
+                                                        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",
+                                   g_param_spec_unichar ("invisible-char",
                                                         P_("Invisible character"),
                                                         P_("The character to use when masking entry contents (in \"password mode\")"),
                                                         '*',
-                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
+                                                        GTK_PARAM_READWRITE));
 
   g_object_class_install_property (gobject_class,
                                    PROP_ACTIVATES_DEFAULT,
-                                   g_param_spec_boolean ("activates_default",
+                                   g_param_spec_boolean ("activates-default",
                                                         P_("Activates default"),
                                                         P_("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed"),
                                                          FALSE,
-                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
+                                                        GTK_PARAM_READWRITE));
   g_object_class_install_property (gobject_class,
                                    PROP_WIDTH_CHARS,
-                                   g_param_spec_int ("width_chars",
+                                   g_param_spec_int ("width-chars",
                                                      P_("Width in chars"),
                                                      P_("Number of characters to leave space for in the entry"),
                                                      -1,
                                                      G_MAXINT,
                                                      -1,
-                                                     G_PARAM_READABLE | G_PARAM_WRITABLE));
+                                                     GTK_PARAM_READWRITE));
 
   g_object_class_install_property (gobject_class,
                                    PROP_SCROLL_OFFSET,
-                                   g_param_spec_int ("scroll_offset",
+                                   g_param_spec_int ("scroll-offset",
                                                      P_("Scroll offset"),
                                                      P_("Number of pixels of the entry scrolled off the screen to the left"),
                                                      0,
                                                      G_MAXINT,
                                                      0,
-                                                     G_PARAM_READABLE));
+                                                     GTK_PARAM_READABLE));
 
   g_object_class_install_property (gobject_class,
                                    PROP_TEXT,
@@ -573,7 +573,7 @@ gtk_entry_class_init (GtkEntryClass *class)
                                                        P_("Text"),
                                                        P_("The contents of the entry"),
                                                        "",
-                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
+                                                       GTK_PARAM_READWRITE));
 
   /**
    * GtkEntry:xalign:
@@ -591,10 +591,42 @@ gtk_entry_class_init (GtkEntryClass *class)
                                                       0.0,
                                                       1.0,
                                                       0.0,
-                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));
-  
+                                                      GTK_PARAM_READWRITE));
+
+  /**
+   * GtkEntry:truncate-multiline:
+   *
+   * When %TRUE, pasted multi-line text is truncated to the first line.
+   *
+   * Since: 2.10
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_TRUNCATE_MULTILINE,
+                                   g_param_spec_boolean ("truncate-multiline",
+                                                         P_("Truncate multiline"),
+                                                         P_("Whether to truncate multiline pastes to one line."),
+                                                         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 ("populate_popup",
+    g_signal_new (I_("populate_popup"),
                  G_OBJECT_CLASS_TYPE (gobject_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (GtkEntryClass, populate_popup),
@@ -606,7 +638,7 @@ gtk_entry_class_init (GtkEntryClass *class)
  /* Action signals */
   
   signals[ACTIVATE] =
-    g_signal_new ("activate",
+    g_signal_new (I_("activate"),
                  G_OBJECT_CLASS_TYPE (gobject_class),
                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                  G_STRUCT_OFFSET (GtkEntryClass, activate),
@@ -616,7 +648,7 @@ gtk_entry_class_init (GtkEntryClass *class)
   widget_class->activate_signal = signals[ACTIVATE];
 
   signals[MOVE_CURSOR] = 
-    g_signal_new ("move_cursor",
+    g_signal_new (I_("move_cursor"),
                  G_OBJECT_CLASS_TYPE (gobject_class),
                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                  G_STRUCT_OFFSET (GtkEntryClass, move_cursor),
@@ -628,7 +660,7 @@ gtk_entry_class_init (GtkEntryClass *class)
                  G_TYPE_BOOLEAN);
 
   signals[INSERT_AT_CURSOR] = 
-    g_signal_new ("insert_at_cursor",
+    g_signal_new (I_("insert_at_cursor"),
                  G_OBJECT_CLASS_TYPE (gobject_class),
                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                  G_STRUCT_OFFSET (GtkEntryClass, insert_at_cursor),
@@ -638,7 +670,7 @@ gtk_entry_class_init (GtkEntryClass *class)
                  G_TYPE_STRING);
 
   signals[DELETE_FROM_CURSOR] = 
-    g_signal_new ("delete_from_cursor",
+    g_signal_new (I_("delete_from_cursor"),
                  G_OBJECT_CLASS_TYPE (gobject_class),
                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                  G_STRUCT_OFFSET (GtkEntryClass, delete_from_cursor),
@@ -649,7 +681,7 @@ gtk_entry_class_init (GtkEntryClass *class)
                  G_TYPE_INT);
 
   signals[BACKSPACE] =
-    g_signal_new ("backspace",
+    g_signal_new (I_("backspace"),
                  G_OBJECT_CLASS_TYPE (gobject_class),
                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                  G_STRUCT_OFFSET (GtkEntryClass, backspace),
@@ -658,7 +690,7 @@ gtk_entry_class_init (GtkEntryClass *class)
                  G_TYPE_NONE, 0);
 
   signals[CUT_CLIPBOARD] =
-    g_signal_new ("cut_clipboard",
+    g_signal_new (I_("cut_clipboard"),
                  G_OBJECT_CLASS_TYPE (gobject_class),
                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                  G_STRUCT_OFFSET (GtkEntryClass, cut_clipboard),
@@ -667,7 +699,7 @@ gtk_entry_class_init (GtkEntryClass *class)
                  G_TYPE_NONE, 0);
 
   signals[COPY_CLIPBOARD] =
-    g_signal_new ("copy_clipboard",
+    g_signal_new (I_("copy_clipboard"),
                  G_OBJECT_CLASS_TYPE (gobject_class),
                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                  G_STRUCT_OFFSET (GtkEntryClass, copy_clipboard),
@@ -676,7 +708,7 @@ gtk_entry_class_init (GtkEntryClass *class)
                  G_TYPE_NONE, 0);
 
   signals[PASTE_CLIPBOARD] =
-    g_signal_new ("paste_clipboard",
+    g_signal_new (I_("paste_clipboard"),
                  G_OBJECT_CLASS_TYPE (gobject_class),
                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                  G_STRUCT_OFFSET (GtkEntryClass, paste_clipboard),
@@ -685,7 +717,7 @@ gtk_entry_class_init (GtkEntryClass *class)
                  G_TYPE_NONE, 0);
 
   signals[TOGGLE_OVERWRITE] =
-    g_signal_new ("toggle_overwrite",
+    g_signal_new (I_("toggle_overwrite"),
                  G_OBJECT_CLASS_TYPE (gobject_class),
                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                  G_STRUCT_OFFSET (GtkEntryClass, toggle_overwrite),
@@ -759,8 +791,30 @@ gtk_entry_class_init (GtkEntryClass *class)
                                 "move_cursor", 3,
                                 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
                                 G_TYPE_INT, 1,
-                               G_TYPE_BOOLEAN, TRUE);
+                               G_TYPE_BOOLEAN, TRUE);  
 
+  gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
+                                "move_cursor", 3,
+                                GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
+                                G_TYPE_INT, -1,
+                               G_TYPE_BOOLEAN, FALSE);
+  gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
+                                "move_cursor", 3,
+                                GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
+                                G_TYPE_INT, 1,
+                               G_TYPE_BOOLEAN, TRUE);  
+  /* Unselect all 
+   */
+  gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_CONTROL_MASK,
+                                "move_cursor", 3,
+                                GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
+                                G_TYPE_INT, 0,
+                               G_TYPE_BOOLEAN, FALSE);
+  gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
+                                "move_cursor", 3,
+                                GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
+                                G_TYPE_INT, 0,
+                               G_TYPE_BOOLEAN, FALSE);
 
   /* Activate
    */
@@ -824,11 +878,40 @@ 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,
-                                                      G_PARAM_READWRITE));
+                                                      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));
 }
@@ -859,6 +942,7 @@ gtk_entry_set_property (GObject         *object,
                         const GValue    *value,
                         GParamSpec      *pspec)
 {
+  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
   GtkEntry *entry = GTK_ENTRY (object);
 
   switch (prop_id)
@@ -871,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);
 
@@ -901,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;
@@ -921,6 +1009,14 @@ gtk_entry_set_property (GObject         *object,
       gtk_entry_set_alignment (entry, g_value_get_float (value));
       break;
 
+    case PROP_TRUNCATE_MULTILINE:
+      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:
     case PROP_CURSOR_POSITION:
     default:
@@ -935,6 +1031,7 @@ gtk_entry_get_property (GObject         *object,
                         GValue          *value,
                         GParamSpec      *pspec)
 {
+  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
   GtkEntry *entry = GTK_ENTRY (object);
 
   switch (prop_id)
@@ -957,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;
@@ -975,7 +1075,13 @@ gtk_entry_get_property (GObject         *object,
     case PROP_XALIGN:
       g_value_set_float (value, gtk_entry_get_alignment (entry));
       break;
-      
+    case PROP_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:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1001,6 +1107,8 @@ 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;
 
   gtk_drag_dest_set (GTK_WIDGET (entry),
@@ -1024,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.
  */
@@ -1042,16 +1190,28 @@ 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)
+    {
+      g_source_remove (entry->blink_timeout);
+      entry->blink_timeout = 0;
+    }
+
+  if (entry->recompute_idle)
+    {
+      g_source_remove (entry->recompute_idle);
+      entry->recompute_idle = 0;
+    }
+
   if (!entry->visible)
     {
       /* We want to trash the text here because the entry might be leaked.  */
       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
@@ -1082,20 +1242,18 @@ 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
 gtk_entry_realize (GtkWidget *widget)
 {
   GtkEntry *entry;
-  GtkEditable *editable;
   GdkWindowAttr attributes;
   gint attributes_mask;
 
   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
   entry = GTK_ENTRY (widget);
-  editable = GTK_EDITABLE (widget);
 
   attributes.window_type = GDK_WINDOW_CHILD;
   
@@ -1120,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);
 
@@ -1169,23 +1332,17 @@ 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);
 }
 
-static void
-get_borders (GtkEntry *entry,
-             gint     *xborder,
-             gint     *yborder)
+void
+_gtk_entry_get_borders (GtkEntry *entry,
+                       gint     *xborder,
+                       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)
     {
@@ -1198,10 +1355,10 @@ 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;
     }
 }
 
@@ -1212,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);
@@ -1223,23 +1381,21 @@ gtk_entry_size_request (GtkWidget      *widget,
   entry->ascent = pango_font_metrics_get_ascent (metrics);
   entry->descent = pango_font_metrics_get_descent (metrics);
   
-  get_borders (entry, &xborder, &yborder);
-  
-  xborder += INNER_BORDER;
-  yborder += INNER_BORDER;
-  
+  _gtk_entry_get_borders (entry, &xborder, &yborder);
+  _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);
 }
@@ -1251,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);
 
-  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;
 
@@ -1307,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)
@@ -1338,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);
     }
 }
@@ -1385,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;
@@ -1394,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;
@@ -1421,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;
@@ -1489,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))
@@ -1509,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
            {
@@ -1573,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:
@@ -1605,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)
     {
@@ -1648,6 +1843,27 @@ gtk_entry_button_release (GtkWidget      *widget,
   return TRUE;
 }
 
+static gchar *
+_gtk_entry_get_selected_text (GtkEntry *entry)
+{
+  GtkEditable *editable = GTK_EDITABLE (entry);
+  gint         start_text, end_text;
+  gchar       *text = NULL;
+
+  if (gtk_editable_get_selection_bounds (editable, &start_text, &end_text))
+    text = gtk_editable_get_chars (editable, start_text, end_text);
+
+  return text;
+}
+
+static void
+drag_begin_cb (GtkWidget      *widget,
+               GdkDragContext *context,
+               gpointer        data)
+{
+  g_signal_handlers_disconnect_by_func (widget, drag_begin_cb, NULL);
+}
+
 static gint
 gtk_entry_motion_notify (GtkWidget      *widget,
                         GdkEventMotion *event)
@@ -1671,31 +1887,49 @@ 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)
     {
       if (gtk_drag_check_threshold (widget,
-                                   entry->drag_start_x, entry->drag_start_y,
-                                   event->x + entry->scroll_offset, event->y))
-       {
-         GdkDragContext *context;
-         GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
-         guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
+                                    entry->drag_start_x, entry->drag_start_y,
+                                    event->x + entry->scroll_offset, event->y))
+        {
+          GdkDragContext *context;
+          GtkTargetList  *target_list = gtk_target_list_new (NULL, 0);
+          guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
+          gchar *text = NULL;
+          GdkPixmap *pixmap = NULL;
+
+          gtk_target_list_add_text_targets (target_list, 0);
 
-         gtk_target_list_add_text_targets (target_list);
+          if (entry->visible)
+            {
+              text = _gtk_entry_get_selected_text (entry);
+              pixmap = _gtk_text_util_create_drag_icon (widget, text, -1);
+            }
 
-         context = gtk_drag_begin (widget, target_list, actions,
-                         entry->button, (GdkEvent *)event);
+          context = gtk_drag_begin (widget, target_list, actions,
+                                    entry->button, (GdkEvent *)event);
+          
+          if (pixmap)
+            gtk_drag_set_icon_pixmap (context,
+                                      gdk_drawable_get_colormap (pixmap),
+                                      pixmap,
+                                      NULL,
+                                      -2, -2);
+          else
+            gtk_drag_set_icon_default (context);
+          
+          if (pixmap)
+            g_object_unref (pixmap);
+          g_free (text);
 
+          entry->in_drag = FALSE;
+          entry->button = 0;
          
-         entry->in_drag = FALSE;
-         entry->button = 0;
-         
-         gtk_target_list_unref (target_list);
-         gtk_drag_set_icon_default (context);
-       }
+          gtk_target_list_unref (target_list);
+        }
     }
   else
     {
@@ -1715,8 +1949,8 @@ gtk_entry_motion_notify (GtkWidget      *widget,
          gint old_min, old_max;
          gint pos, bound;
          
-         min = gtk_entry_move_backward_word (entry, tmp_pos);
-         max = gtk_entry_move_forward_word (entry, tmp_pos);
+         min = gtk_entry_move_backward_word (entry, tmp_pos, TRUE);
+         max = gtk_entry_move_forward_word (entry, tmp_pos, TRUE);
          
          pos = entry->current_pos;
          bound = entry->selection_bound;
@@ -1798,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)
@@ -1810,23 +2045,30 @@ gtk_entry_key_press (GtkWidget   *widget,
        }
     }
 
-  if (event->keyval == GDK_Return || event->keyval == GDK_ISO_Enter
-      || event->keyval == GDK_Escape)
+  if (event->keyval == GDK_Return || 
+      event->keyval == GDK_KP_Enter || 
+      event->keyval == GDK_ISO_Enter || 
+      event->keyval == GDK_Escape)
     {
       GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
-
+      
       if (completion && completion->priv->completion_timeout)
         {
           g_source_remove (completion->priv->completion_timeout);
           completion->priv->completion_timeout = 0;
         }
+
+      _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;
 }
 
@@ -1845,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
@@ -1866,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;
@@ -1905,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 
@@ -1924,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
@@ -1932,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))
@@ -2033,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)
 {
@@ -2074,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),
@@ -2101,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))
@@ -2158,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
@@ -2166,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;
     }
@@ -2239,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");
 }
 
@@ -2293,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");
     }
 }
@@ -2337,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)
     {
@@ -2351,11 +2654,10 @@ gtk_entry_move_cursor (GtkEntry       *entry,
            gint current_x = get_better_cursor_x (entry, entry->current_pos);
            gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
 
-           if (count < 0)
+           if (count <= 0)
              new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
-           else
+           else 
              new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
-
            break;
          }
        case GTK_MOVEMENT_LOGICAL_POSITIONS:
@@ -2386,23 +2688,48 @@ 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)
            {
-             new_pos = gtk_entry_move_forward_word (entry, new_pos);
+             new_pos = gtk_entry_move_forward_word (entry, new_pos, FALSE);
              count--;
            }
          while (count < 0)
            {
-             new_pos = gtk_entry_move_backward_word (entry, new_pos);
+             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:
@@ -2429,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);
@@ -2444,13 +2771,17 @@ 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;
-
-  if (entry->selection_bound != entry->current_pos)
+    {
+      gtk_widget_error_bell (GTK_WIDGET (entry));
+      return;
+    }
+
+  if (entry->selection_bound != entry->current_pos)
     {
       gtk_editable_delete_selection (editable);
       return;
@@ -2466,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);
-         end_pos = gtk_entry_move_forward_word (entry, end_pos);
+         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);
-         start_pos = gtk_entry_move_backward_word (entry, start_pos);
+         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);
+         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);
+         end_pos = gtk_entry_move_forward_word (entry, end_pos, FALSE);
          count--;
        }
       gtk_editable_delete_text (editable, start_pos, end_pos);
@@ -2505,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);
 }
 
@@ -2515,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->visible || !entry->text)
-    return;
+  if (!entry->editable || !entry->text)
+    {
+      gtk_widget_error_bell (GTK_WIDGET (entry));
+      return;
+    }
 
   if (entry->selection_bound != entry->current_pos)
     {
@@ -2536,7 +2873,7 @@ gtk_entry_backspace (GtkEntry *entry)
 
       pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
 
-      if (log_attrs[prev_pos].backspace_deletes_character)
+      if (log_attrs[entry->current_pos].backspace_deletes_character)
        {
          gchar *cluster_text;
          gchar *normalized_text;
@@ -2571,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);
 }
@@ -2604,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
@@ -2611,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
@@ -2630,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
@@ -2739,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);
@@ -2750,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
@@ -2771,7 +3126,7 @@ gtk_entry_set_positions (GtkEntry *entry,
       entry->current_pos = current_pos;
       changed = TRUE;
 
-      g_object_notify (G_OBJECT (entry), "cursor_position");
+      g_object_notify (G_OBJECT (entry), "cursor-position");
     }
 
   if (selection_bound != -1 &&
@@ -2780,13 +3135,16 @@ gtk_entry_set_positions (GtkEntry *entry,
       entry->selection_bound = selection_bound;
       changed = TRUE;
       
-      g_object_notify (G_OBJECT (entry), "selection_bound");
+      g_object_notify (G_OBJECT (entry), "selection-bound");
     }
 
   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
@@ -2833,8 +3191,6 @@ recompute_idle_func (gpointer data)
 {
   GtkEntry *entry;
 
-  GDK_THREADS_ENTER ();
-
   entry = GTK_ENTRY (data);
 
   entry->recompute_idle = 0;
@@ -2847,8 +3203,6 @@ recompute_idle_func (gpointer data)
       update_im_cursor_location (entry);
     }
 
-  GDK_THREADS_LEAVE ();
-
   return FALSE;
 }
 
@@ -2860,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); 
     }
 }
@@ -2883,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)
@@ -2897,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,
@@ -2921,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;
@@ -2968,14 +3331,17 @@ gtk_entry_create_layout (GtkEntry *entry,
            {
              GdkDisplay *display = gtk_widget_get_display (widget);
              GdkKeymap *keymap = gdk_keymap_get_for_display (display);
-             pango_dir = gdk_keymap_get_direction (keymap);
+             if (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_RTL)
+               pango_dir = PANGO_DIRECTION_RTL;
+             else
+               pango_dir = PANGO_DIRECTION_LTR;
            }
           else
            {
-             if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
-               pango_dir = PANGO_DIRECTION_LTR;
-             else
+             if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
                pango_dir = PANGO_DIRECTION_RTL;
+             else
+               pango_dir = PANGO_DIRECTION_LTR;
            }
         }
 
@@ -2994,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);
         }
@@ -3008,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);
       
@@ -3043,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 */
@@ -3067,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;
@@ -3087,6 +3502,7 @@ gtk_entry_draw_text (GtkEntry *entry)
   if (GTK_WIDGET_DRAWABLE (entry))
     {
       PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
+      cairo_t *cr;
       gint x, y;
       gint start_pos, end_pos;
       
@@ -3094,57 +3510,56 @@ gtk_entry_draw_text (GtkEntry *entry)
       
       get_layout_position (entry, &x, &y);
 
-      gdk_draw_layout (entry->text_area, widget->style->text_gc [widget->state],       
-                       x, y,
-                      layout);
-      
+      cr = gdk_cairo_create (entry->text_area);
+
+      cairo_move_to (cr, x, y);
+      gdk_cairo_set_source_color (cr, &widget->style->text [widget->state]);
+      pango_cairo_show_layout (cr, layout);
+
       if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
        {
          gint *ranges;
          gint n_ranges, i;
           PangoRectangle logical_rect;
-         GdkGC *selection_gc, *text_gc;
-         GdkRegion *clip_region;
+         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);
 
          if (GTK_WIDGET_HAS_FOCUS (entry))
            {
-             selection_gc = widget->style->base_gc [GTK_STATE_SELECTED];
-             text_gc = widget->style->text_gc [GTK_STATE_SELECTED];
+             selection_color = &widget->style->base [GTK_STATE_SELECTED];
+             text_color = &widget->style->text [GTK_STATE_SELECTED];
            }
          else
            {
-             selection_gc = widget->style->base_gc [GTK_STATE_ACTIVE];
-             text_gc = widget->style->text_gc [GTK_STATE_ACTIVE];
+             selection_color = &widget->style->base [GTK_STATE_ACTIVE];
+             text_color = &widget->style->text [GTK_STATE_ACTIVE];
            }
-         
-         clip_region = gdk_region_new ();
-         for (i = 0; i < n_ranges; ++i)
-           {
-             GdkRectangle rect;
 
-             rect.x = INNER_BORDER - entry->scroll_offset + ranges[2 * i];
-             rect.y = y;
-             rect.width = ranges[2 * i + 1];
-             rect.height = logical_rect.height;
-               
-             gdk_draw_rectangle (entry->text_area, selection_gc, TRUE,
-                                 rect.x, rect.y, rect.width, rect.height);
+          _gtk_entry_effective_inner_border (entry, &inner_border);
 
-             gdk_region_union_with_rect (clip_region, &rect);
-           }
+         for (i = 0; i < n_ranges; ++i)
+           cairo_rectangle (cr,
+                            inner_border.left - entry->scroll_offset + ranges[2 * i],
+                            y,
+                            ranges[2 * i + 1],
+                            logical_rect.height);
+
+         cairo_clip (cr);
          
-         gdk_gc_set_clip_region (text_gc, clip_region);
-         gdk_draw_layout (entry->text_area, text_gc, 
-                          x, y,
-                          layout);
-         gdk_gc_set_clip_region (text_gc, NULL);
+         gdk_cairo_set_source_color (cr, selection_color);
+         cairo_paint (cr);
+
+         cairo_move_to (cr, x, y);
+         gdk_cairo_set_source_color (cr, text_color);
+         pango_cairo_show_layout (cr, layout);
          
-         gdk_region_destroy (clip_region);
          g_free (ranges);
        }
+
+      cairo_destroy (cr);
     }
 }
 
@@ -3180,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;
+
+          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;
+          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)
     {
@@ -3261,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;
   
@@ -3269,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)
@@ -3346,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;
@@ -3355,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);
 
@@ -3391,7 +3863,7 @@ gtk_entry_adjust_scroll (GtkEntry *entry)
    * the right, when the scroll is at the utmost right. This
    * looks better to to me than confining the cursor inside the
    * border entirely, though it means that the cursor gets one
-   * pixel closer to the the edge of the widget on the right than
+   * pixel closer to the edge of the widget on the right than
    * on the left. This might need changing if one changed
    * INNER_BORDER from 2 to 1, as one would do on a
    * small-screen-real-estate display.
@@ -3427,7 +3899,39 @@ gtk_entry_adjust_scroll (GtkEntry *entry)
       entry->scroll_offset += weak_xoffset - text_area_width;
     }
 
-  g_object_notify (G_OBJECT (entry), "scroll_offset");
+  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
@@ -3531,7 +4035,8 @@ gtk_entry_move_logically (GtkEntry *entry,
 
 static gint
 gtk_entry_move_forward_word (GtkEntry *entry,
-                            gint      start)
+                            gint      start,
+                             gboolean  allow_whitespace)
 {
   gint new_pos = start;
 
@@ -3548,9 +4053,10 @@ gtk_entry_move_forward_word (GtkEntry *entry,
 
       pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
       
-      /* Find the next word end */
+      /* Find the next word boundary */
       new_pos++;
-      while (new_pos < n_attrs && !log_attrs[new_pos].is_word_end)
+      while (new_pos < n_attrs - 1 && !(log_attrs[new_pos].is_word_end ||
+                                        (log_attrs[new_pos].is_word_start && allow_whitespace)))
        new_pos++;
 
       g_free (log_attrs);
@@ -3562,7 +4068,8 @@ gtk_entry_move_forward_word (GtkEntry *entry,
 
 static gint
 gtk_entry_move_backward_word (GtkEntry *entry,
-                             gint      start)
+                             gint      start,
+                              gboolean  allow_whitespace)
 {
   gint new_pos = start;
 
@@ -3581,8 +4088,9 @@ gtk_entry_move_backward_word (GtkEntry *entry,
 
       new_pos = start - 1;
 
-      /* Find the previous word beginning */
-      while (new_pos > 0 && !log_attrs[new_pos].is_word_start)
+      /* Find the previous word boundary */
+      while (new_pos > 0 && !(log_attrs[new_pos].is_word_start || 
+                              (log_attrs[new_pos].is_word_end && allow_whitespace)))
        new_pos--;
 
       g_free (log_attrs);
@@ -3619,8 +4127,8 @@ gtk_entry_delete_whitespace (GtkEntry *entry)
 static void
 gtk_entry_select_word (GtkEntry *entry)
 {
-  gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos);
-  gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos);
+  gint start_pos = gtk_entry_move_backward_word (entry, entry->current_pos, TRUE);
+  gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
 
   gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
 }
@@ -3655,6 +4163,18 @@ gtk_entry_get_public_chars (GtkEntry *entry,
     }
 }
 
+static gint
+truncate_multiline (const gchar *text)
+{
+  gint length;
+
+  for (length = 0;
+       text[length] && text[length] != '\n' && text[length] != '\r';
+       length++);
+
+  return length;
+}
+
 static void
 paste_received (GtkClipboard *clipboard,
                const gchar  *text,
@@ -3676,23 +4196,40 @@ paste_received (GtkClipboard *clipboard,
   if (text)
     {
       gint pos, start, end;
-      GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
+      gint length = -1;
+      gboolean popup_completion;
+      GtkEntryCompletion *completion;
+
+      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, -1, &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);
     }
 
@@ -3779,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)
 {
@@ -3815,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)
@@ -3832,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)
@@ -3857,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)
@@ -3870,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)
@@ -3879,15 +4471,57 @@ 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)
 {
   g_return_if_fail (GTK_IS_ENTRY (entry));
 
-  entry->visible = visible ? TRUE : FALSE;
-  g_object_notify (G_OBJECT (entry), "visibility");
-  gtk_entry_recompute (entry);
+  visible = visible != FALSE;
+
+  if (entry->visible != visible)
+    {
+      if (GTK_WIDGET_HAS_FOCUS (entry) && !visible)
+       gtk_im_context_focus_out (entry->im_context);
+
+      g_object_unref (entry->im_context);
+
+      if (visible)
+        entry->im_context = gtk_im_multicontext_new ();
+      else
+        entry->im_context = gtk_im_context_simple_new ();
+      
+      g_signal_connect (entry->im_context, "commit",
+                       G_CALLBACK (gtk_entry_commit_cb), entry);
+      g_signal_connect (entry->im_context, "preedit_changed",
+                       G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
+      g_signal_connect (entry->im_context, "retrieve_surrounding",
+                       G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
+      g_signal_connect (entry->im_context, "delete_surrounding",
+                       G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
+
+      if (GTK_WIDGET_HAS_FOCUS (entry) && visible)
+       gtk_im_context_focus_in (entry->im_context); 
+
+      entry->visible = visible;
+
+      g_object_notify (G_OBJECT (entry), "visibility");
+      gtk_entry_recompute (entry);
+    }
 }
 
 /**
@@ -3919,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,
@@ -3931,7 +4564,7 @@ gtk_entry_set_invisible_char (GtkEntry *entry,
     return;
 
   entry->invisible_char = ch;
-  g_object_notify (G_OBJECT (entry), "invisible_char");
+  g_object_notify (G_OBJECT (entry), "invisible-char");
   gtk_entry_recompute (entry);  
 }
 
@@ -3940,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. 
@@ -3953,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)
@@ -3970,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.
  **/
@@ -3982,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,
@@ -3992,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.
@@ -4013,7 +4671,7 @@ gtk_entry_set_max_length (GtkEntry     *entry,
     gtk_editable_delete_text (GTK_EDITABLE (entry), max, -1);
   
   entry->text_max_length = max;
-  g_object_notify (G_OBJECT (entry), "max_length");
+  g_object_notify (G_OBJECT (entry), "max-length");
 }
 
 /**
@@ -4046,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,
@@ -4059,7 +4716,7 @@ gtk_entry_set_activates_default (GtkEntry *entry,
   if (setting != entry->activates_default)
     {
       entry->activates_default = setting;
-      g_object_notify (G_OBJECT (entry), "activates_default");
+      g_object_notify (G_OBJECT (entry), "activates-default");
     }
 }
 
@@ -4089,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,
@@ -4100,7 +4756,7 @@ gtk_entry_set_width_chars (GtkEntry *entry,
   if (entry->width_chars != n_chars)
     {
       entry->width_chars = n_chars;
-      g_object_notify (G_OBJECT (entry), "width_chars");
+      g_object_notify (G_OBJECT (entry), "width-chars");
       gtk_widget_queue_resize (GTK_WIDGET (entry));
     }
 }
@@ -4141,7 +4797,7 @@ gtk_entry_set_has_frame (GtkEntry *entry,
 
   gtk_widget_queue_resize (GTK_WIDGET (entry));
   entry->has_frame = setting;
-  g_object_notify (G_OBJECT (entry), "has_frame");
+  g_object_notify (G_OBJECT (entry), "has-frame");
 }
 
 /**
@@ -4160,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:
@@ -4168,8 +4876,8 @@ gtk_entry_get_has_frame (GtkEntry *entry)
  * Gets the #PangoLayout used to display the entry.
  * The layout is useful to e.g. convert text positions to
  * pixel positions, in combination with gtk_entry_get_layout_offsets().
- * The returned layout is owned by the entry so need not be
- * freed by the caller.
+ * The returned layout is owned by the entry and must not be 
+ * modified or freed by the caller.
  *
  * Keep in mind that the layout text may contain a preedit string, so
  * gtk_entry_layout_index_to_text_index() and
@@ -4284,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,
@@ -4395,7 +5102,7 @@ append_action_signal (GtkEntry     *entry,
 {
   GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
 
-  g_object_set_data (G_OBJECT (menuitem), "gtk-signal", (char *)signal);
+  g_object_set_data (G_OBJECT (menuitem), I_("gtk-signal"), (char *)signal);
   g_signal_connect (menuitem, "activate",
                    G_CALLBACK (activate_cb), entry);
 
@@ -4421,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)
@@ -4473,10 +5193,13 @@ popup_targets_received (GtkClipboard     *clipboard,
   
   if (GTK_WIDGET_REALIZED (entry))
     {
-      gboolean clipboard_contains_text = gtk_selection_data_targets_include_text (data);
+      gboolean clipboard_contains_text;
       GtkWidget *menuitem;
       GtkWidget *submenu;
+      gboolean show_input_method_menu;
+      gboolean show_unicode_menu;
       
+        clipboard_contains_text = gtk_selection_data_targets_include_text (data);
       if (entry->popup_menu)
        gtk_widget_destroy (entry->popup_menu);
       
@@ -4494,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);
@@ -4504,39 +5227,55 @@ popup_targets_received (GtkClipboard     *clipboard,
       gtk_widget_show (menuitem);
       gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
       
-      menuitem = gtk_menu_item_new_with_mnemonic (_("Select _All"));
+      menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
       g_signal_connect_swapped (menuitem, "activate",
                                G_CALLBACK (gtk_entry_select_all), entry);
       gtk_widget_show (menuitem);
       gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
       
-      menuitem = gtk_separator_menu_item_new ();
-      gtk_widget_show (menuitem);
-      gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
-      
-      menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
-      gtk_widget_set_sensitive (menuitem, entry->editable);      
-      gtk_widget_show (menuitem);
-      submenu = gtk_menu_new ();
-      gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
-      
-      gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
+      g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
+                    "gtk-show-input-method-menu", &show_input_method_menu,
+                    "gtk-show-unicode-menu", &show_unicode_menu,
+                    NULL);
+
+      if (!entry->visible)
+        show_input_method_menu = FALSE;
+
+      if (show_input_method_menu || show_unicode_menu)
+        {
+          menuitem = gtk_separator_menu_item_new ();
+          gtk_widget_show (menuitem);
+          gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
+        }
       
-      gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
-                                           GTK_MENU_SHELL (submenu));
+      if (show_input_method_menu)
+        {
+          menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
+          gtk_widget_set_sensitive (menuitem, entry->editable);      
+          gtk_widget_show (menuitem);
+          submenu = gtk_menu_new ();
+          gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
+          
+          gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
       
-      menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
-      gtk_widget_show (menuitem);
+          gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
+                                                GTK_MENU_SHELL (submenu));
+        }
       
-      submenu = gtk_menu_new ();
-      gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
-      gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);      
-
-      _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
-                                                    unichar_chosen_func,
-                                                    entry);
-      if (!entry->editable)
-        gtk_widget_set_sensitive (menuitem, FALSE);
+      if (show_unicode_menu)
+        {
+          menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
+          gtk_widget_set_sensitive (menuitem, entry->editable);      
+          gtk_widget_show (menuitem);
+          
+          submenu = gtk_menu_new ();
+          gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
+          gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);      
+          
+          _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
+                                                        unichar_chosen_func,
+                                                        entry);
+        }
       
       g_signal_emit (entry,
                     signals[POPULATE_POPUP],
@@ -4585,7 +5324,7 @@ gtk_entry_do_popup (GtkEntry       *entry,
     }
 
   gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
-                                 gdk_atom_intern ("TARGETS", FALSE),
+                                 gdk_atom_intern_static_string ("TARGETS"),
                                  popup_targets_received,
                                  info);
 }
@@ -4704,28 +5443,38 @@ gtk_entry_drag_data_received (GtkWidget        *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)
     {
       gint new_position;
       gint sel1, sel2;
+      gint length = -1;
+
+      if (entry->truncate_multiline)
+        length = truncate_multiline (str);
 
       new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
 
       if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
          new_position < sel1 || new_position > sel2)
        {
-         gtk_editable_insert_text (editable, str, -1, &new_position);
+         gtk_editable_insert_text (editable, str, length, &new_position);
        }
       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, -1, &sel1);
+         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
@@ -4733,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
@@ -4776,20 +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
@@ -4807,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)
 {
@@ -4838,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;
 }
@@ -4877,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
@@ -4908,29 +5689,40 @@ 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 (g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
+  if (completion->priv->filter_model &&
+      g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)), -1)
       >= completion->priv->minimum_key_length)
     {
       gint matches;
       gint actions;
       GtkTreeSelection *s;
+      gboolean popup_single;
 
       gtk_entry_completion_complete (completion);
       matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
@@ -4943,7 +5735,8 @@ gtk_entry_completion_timeout (gpointer data)
 
       actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
 
-      if (matches > 0 || actions > 0)
+      g_object_get (completion, "popup-single-match", &popup_single, NULL);
+      if ((matches > (popup_single ? 0: 1)) || actions > 0)
        { 
          if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
            _gtk_entry_completion_resize_popup (completion);
@@ -4956,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;
 }
 
@@ -5058,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)
         {
@@ -5066,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)
         {
@@ -5074,37 +5892,91 @@ 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;
     }
-  else if (event->keyval == GDK_ISO_Enter || 
+  else if (event->keyval == GDK_ISO_Enter ||
+           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)
@@ -5115,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;
@@ -5176,7 +6049,8 @@ gtk_entry_completion_changed (GtkWidget *entry,
     return;
 
   /* no need to normalize for this test */
-  if (! strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))))
+  if (completion->priv->minimum_key_length > 0 &&
+      strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
     {
       if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
         _gtk_entry_completion_popdown (completion);
@@ -5184,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);
 }
@@ -5194,6 +6068,7 @@ check_completion_callback (GtkEntryCompletion *completion)
 {
   completion->priv->check_completion_idle = NULL;
   
+  gtk_entry_completion_complete (completion);
   gtk_entry_completion_insert_prefix (completion);
 
   return FALSE;
@@ -5203,9 +6078,13 @@ static void
 clear_completion_callback (GtkEntry   *entry,
                           GParamSpec *pspec)
 {
-  GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
-
-  completion->priv->has_completion = FALSE;
+  if (pspec->name == I_("cursor-position") ||
+      pspec->name == I_("selection-bound"))
+    {
+      GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
+      
+      completion->priv->has_completion = FALSE;
+    }
 }
 
 static gboolean
@@ -5246,8 +6125,12 @@ completion_changed (GtkEntryCompletion *completion,
 {
   GtkEntry *entry = GTK_ENTRY (data);
 
-  disconnect_completion_signals (entry, completion);
-  connect_completion_signals (entry, completion);
+  if (pspec->name == I_("popup-completion") ||
+      pspec->name == I_("inline-completion"))
+    {
+      disconnect_completion_signals (entry, completion);
+      connect_completion_signals (entry, completion);
+    }
 }
 
 static void
@@ -5258,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, 
@@ -5290,29 +6179,27 @@ connect_completion_signals (GtkEntry           *entry,
       completion->priv->insert_text_id =
        g_signal_connect (entry, "insert_text",
                          G_CALLBACK (completion_insert_text_callback), completion);
-      g_signal_connect (entry, "notify::cursor-position",
-                       G_CALLBACK (clear_completion_callback), completion);
-      g_signal_connect (entry, "notify::selection-bound",
+      g_signal_connect (entry, "notify",
                        G_CALLBACK (clear_completion_callback), completion);
       g_signal_connect (entry, "activate",
                        G_CALLBACK (accept_completion_callback), completion);
       g_signal_connect (entry, "focus_out_event",
                        G_CALLBACK (accept_completion_callback), completion);
     }
-  g_signal_connect (completion, "notify::popup-completion",
-                   G_CALLBACK (completion_changed), entry);
-  g_signal_connect (completion, "notify::inline-completion",
+
+  g_signal_connect (completion, "notify",
                    G_CALLBACK (completion_changed), entry);
 }
 
 /**
  * gtk_entry_set_completion:
- * @entry: A #GtkEntry.
- * @completion: The #GtkEntryCompletion.
+ * @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
- * @completion using the #GtkEntryCompletion API.
+ * @completion using the #GtkEntryCompletion API. Completion is disabled if
+ * @completion is set to %NULL.
  *
  * Since: 2.4
  */
@@ -5349,7 +6236,7 @@ gtk_entry_set_completion (GtkEntry           *entry,
 
   if (!completion)
     {
-      g_object_set_data (G_OBJECT (entry), GTK_ENTRY_COMPLETION_KEY, NULL);
+      g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), NULL);
       return;
     }
 
@@ -5358,12 +6245,12 @@ gtk_entry_set_completion (GtkEntry           *entry,
 
   connect_completion_signals (entry, completion);    
   completion->priv->entry = GTK_WIDGET (entry);
-  g_object_set_data (G_OBJECT (entry), GTK_ENTRY_COMPLETION_KEY, completion);
+  g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
 }
 
 /**
  * gtk_entry_get_completion:
- * @entry: A #GtkEntry.
+ * @entry: A #GtkEntry
  *
  * Returns the auxiliary completion object currently in use by @entry.
  *
@@ -5383,3 +6270,59 @@ 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"