]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkentry.c
GtkBubbleWindow: allocate CSS borders and paddings
[~andy/gtk] / gtk / gtkentry.c
index f0fd92c1db5ba301f81b35bbac5dafb57775c86d..159120473c8a323d598478645894c51c5ee1e856 100644 (file)
@@ -16,9 +16,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
 #include <math.h>
 #include <string.h>
 
-#include "gdk/gdkkeysyms.h"
-#include "gtkalignment.h"
 #include "gtkbindings.h"
 #include "gtkcelleditable.h"
 #include "gtkclipboard.h"
 #include "gtkdnd.h"
 #include "gtkentry.h"
 #include "gtkentrybuffer.h"
+#include "gtkiconhelperprivate.h"
 #include "gtkimagemenuitem.h"
 #include "gtkimcontextsimple.h"
 #include "gtkimmulticontext.h"
 #include "gtkwindow.h"
 #include "gtktreeview.h"
 #include "gtktreeselection.h"
+#include "gtktypebuiltins.h"
 #include "gtkprivate.h"
 #include "gtkentryprivate.h"
 #include "gtkcelllayout.h"
 #include "gtktooltip.h"
 #include "gtkiconfactory.h"
 #include "gtkicontheme.h"
-#include "gtkalias.h"
+#include "gtkwidgetprivate.h"
+#include "gtkstylecontextprivate.h"
+#include "gtktexthandleprivate.h"
+#include "gtkbubblewindowprivate.h"
+#include "gtktoolbar.h"
+
+#include "a11y/gtkentryaccessible.h"
+
+/**
+ * SECTION:gtkentry
+ * @Short_description: A single line text entry field
+ * @Title: GtkEntry
+ * @See_also: #GtkTextView, #GtkEntryCompletion
+ *
+ * The #GtkEntry widget is a single line text entry
+ * widget. A fairly large set of key bindings are supported
+ * by default. If the entered text is longer than the allocation
+ * of the widget, the widget will scroll so that the cursor
+ * position is visible.
+ *
+ * When using an entry for passwords and other sensitive information,
+ * it can be put into "password mode" using gtk_entry_set_visibility().
+ * In this mode, entered text is displayed using a 'invisible' character.
+ * By default, GTK+ picks the best invisible character that is available
+ * in the current font, but it can be changed with
+ * gtk_entry_set_invisible_char(). Since 2.16, GTK+ displays a warning
+ * when Caps Lock or input methods might interfere with entering text in
+ * a password entry. The warning can be turned off with the
+ * #GtkEntry:caps-lock-warning property.
+ *
+ * Since 2.16, GtkEntry has the ability to display progress or activity
+ * information behind the text. To make an entry display such information,
+ * use gtk_entry_set_progress_fraction() or gtk_entry_set_progress_pulse_step().
+ *
+ * Additionally, GtkEntry can show icons at either side of the entry. These
+ * icons can be activatable by clicking, can be set up as drag source and
+ * can have tooltips. To add an icon, use gtk_entry_set_icon_from_gicon() or
+ * one of the various other functions that set an icon from a stock id, an
+ * icon name or a pixbuf. To trigger an action when the user clicks an icon,
+ * connect to the #GtkEntry::icon-press signal. To allow DND operations
+ * from an icon, use gtk_entry_set_icon_drag_source(). To set a tooltip on
+ * an icon, use gtk_entry_set_icon_tooltip_text() or the corresponding function
+ * for markup.
+ *
+ * Note that functionality or information that is only available by clicking
+ * on an icon in an entry may not be accessible at all to users which are not
+ * able to use a mouse or other pointing device. It is therefore recommended
+ * that any such functionality should also be available by other means, e.g.
+ * via the context menu of the entry.
+ */
+
 
 #define GTK_ENTRY_COMPLETION_KEY "gtk-entry-completion-key"
 
 #define MIN_ENTRY_WIDTH  150
 #define DRAW_TIMEOUT     20
-#define COMPLETION_TIMEOUT 300
 #define PASSWORD_HINT_MAX 8
 
 #define MAX_ICONS 2
@@ -86,11 +133,100 @@ static GQuark          quark_password_hint  = 0;
 static GQuark          quark_cursor_hadjustment = 0;
 static GQuark          quark_capslock_feedback = 0;
 
-typedef struct _GtkEntryPrivate GtkEntryPrivate;
+typedef struct _EntryIconInfo EntryIconInfo;
+typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
+typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
 
-#define GTK_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY, GtkEntryPrivate))
+struct _GtkEntryPrivate
+{
+  EntryIconInfo         *icons[MAX_ICONS];
+
+  GtkEntryBuffer        *buffer;
+  GtkIMContext          *im_context;
+  GtkWidget             *popup_menu;
+
+  GdkDevice             *device;
+
+  GdkWindow             *text_area;
+
+  PangoLayout           *cached_layout;
+  PangoAttrList         *attrs;
+
+  gchar        *im_module;
+
+  gdouble       progress_fraction;
+  gdouble       progress_pulse_fraction;
+  gdouble       progress_pulse_current;
+
+  gchar        *placeholder_text;
+
+  GtkBubbleWindow *bubble_window;
+  GtkTextHandle *text_handle;
+  GtkWidget     *selection_bubble;
+  guint          selection_bubble_timeout_id;
+
+  gfloat        xalign;
+
+  gint          ascent;                     /* font ascent in pango units  */
+  gint          current_pos;
+  gint          descent;                    /* font descent in pango units */
+  gint          dnd_position;               /* In chars, -1 == no DND cursor */
+  gint          drag_start_x;
+  gint          drag_start_y;
+  gint          focus_width;
+  gint          insert_pos;
+  gint          selection_bound;
+  gint          scroll_offset;
+  gint          start_x;
+  gint          start_y;
+  gint          width_chars;
+
+  gunichar      invisible_char;
+
+  guint         button;
+  guint         blink_time;                  /* time in msec the cursor has blinked since last user event */
+  guint         blink_timeout;
+  guint         recompute_idle;
+
+  guint16       x_text_size;                 /* allocated size, in bytes */
+  guint16       x_n_bytes;                   /* length in use, in bytes */
+
+  guint16       preedit_length;              /* length of preedit string, in bytes */
+  guint16      preedit_cursor;              /* offset of cursor within preedit string, in chars */
+
+  guint         shadow_type             : 4;
+  guint         editable                : 1;
+  guint         in_drag                 : 1;
+  guint         overwrite_mode          : 1;
+  guint         visible                 : 1;
+
+  guint         activates_default       : 1;
+  guint         cache_includes_preedit  : 1;
+  guint         caps_lock_warning       : 1;
+  guint         caps_lock_warning_shown : 1;
+  guint         change_count            : 8;
+  guint         cursor_visible          : 1;
+  guint         editing_canceled        : 1; /* Only used by GtkCellRendererText */
+  guint         has_frame               : 1;
+  guint         in_click                : 1; /* Flag so we don't select all when clicking in entry to focus in */
+  guint         is_cell_renderer        : 1;
+  guint         invisible_char_set      : 1;
+  guint         interior_focus          : 1;
+  guint         mouse_cursor_obscured   : 1;
+  guint         need_im_reset           : 1;
+  guint         progress_pulse_mode     : 1;
+  guint         progress_pulse_way_back : 1;
+  guint         real_changed            : 1;
+  guint         resolved_dir            : 4; /* PangoDirection */
+  guint         select_words            : 1;
+  guint         select_lines            : 1;
+  guint         truncate_multiline      : 1;
+  guint         cursor_handle_dragged   : 1;
+  guint         selection_handle_dragged : 1;
+  guint         populate_all            : 1;
+};
 
-typedef struct
+struct _EntryIconInfo
 {
   GdkWindow *window;
   gchar *tooltip;
@@ -100,59 +236,18 @@ typedef struct
   guint in_drag        : 1;
   guint pressed        : 1;
 
-  GtkImageType  storage_type;
-  GdkPixbuf    *pixbuf;
-  gchar        *stock_id;
-  gchar        *icon_name;
-  GIcon        *gicon;
+  GtkIconHelper *icon_helper;
 
   GtkTargetList *target_list;
   GdkDragAction actions;
-} EntryIconInfo;
-
-struct _GtkEntryPrivate 
-{
-  GtkEntryBuffer* buffer;
-
-  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 invisible_char_set      : 1;
-  guint caps_lock_warning       : 1;
-  guint caps_lock_warning_shown : 1;
-  guint change_count            : 8;
-  guint progress_pulse_mode     : 1;
-  guint progress_pulse_way_back : 1;
-
-  gint focus_width;
-  GtkShadowType shadow_type;
-
-  gdouble progress_fraction;
-  gdouble progress_pulse_fraction;
-  gdouble progress_pulse_current;
-
-  EntryIconInfo *icons[MAX_ICONS];
-  gint icon_margin;
-  gint start_x;
-  gint start_y;
-
-  gchar *im_module;
-
-  GdkDevice *completion_device;
 };
 
-typedef struct _GtkEntryPasswordHint GtkEntryPasswordHint;
-
 struct _GtkEntryPasswordHint
 {
   gint position;      /* Position (in text) of the last password hint */
   guint source_id;    /* Timeout source id */
 };
 
-typedef struct _GtkEntryCapslockFeedback GtkEntryCapslockFeedback;
-
 struct _GtkEntryCapslockFeedback
 {
   GtkWidget *entry;
@@ -220,10 +315,17 @@ enum {
   PROP_TOOLTIP_MARKUP_PRIMARY,
   PROP_TOOLTIP_MARKUP_SECONDARY,
   PROP_IM_MODULE,
-  PROP_EDITING_CANCELED
+  PROP_EDITING_CANCELED,
+  PROP_PLACEHOLDER_TEXT,
+  PROP_COMPLETION,
+  PROP_INPUT_PURPOSE,
+  PROP_INPUT_HINTS,
+  PROP_ATTRIBUTES,
+  PROP_POPULATE_ALL
 };
 
 static guint signals[LAST_SIGNAL] = { 0 };
+static gboolean test_touchscreen = FALSE;
 
 typedef enum {
   CURSOR_STANDARD,
@@ -237,9 +339,9 @@ typedef enum
   DISPLAY_BLANK         /* In invisible mode, nothing shown at all */
 } DisplayMode;
 
-/* GObject, GtkObject methods
+/* GObject methods
  */
-static void   gtk_entry_editable_init        (GtkEditableClass     *iface);
+static void   gtk_entry_editable_init        (GtkEditableInterface *iface);
 static void   gtk_entry_cell_editable_init   (GtkCellEditableIface *iface);
 static void   gtk_entry_set_property         (GObject          *object,
                                               guint             prop_id,
@@ -250,25 +352,31 @@ static void   gtk_entry_get_property         (GObject          *object,
                                               GValue           *value,
                                               GParamSpec       *pspec);
 static void   gtk_entry_finalize             (GObject          *object);
-static void   gtk_entry_destroy              (GtkObject        *object);
 static void   gtk_entry_dispose              (GObject          *object);
 
 /* GtkWidget methods
  */
+static void   gtk_entry_destroy              (GtkWidget        *widget);
 static void   gtk_entry_realize              (GtkWidget        *widget);
 static void   gtk_entry_unrealize            (GtkWidget        *widget);
 static void   gtk_entry_map                  (GtkWidget        *widget);
 static void   gtk_entry_unmap                (GtkWidget        *widget);
-static void   gtk_entry_size_request         (GtkWidget        *widget,
-                                             GtkRequisition   *requisition);
+static void   gtk_entry_get_preferred_width  (GtkWidget        *widget,
+                                              gint             *minimum,
+                                              gint             *natural);
+static void   gtk_entry_get_preferred_height (GtkWidget        *widget,
+                                              gint             *minimum,
+                                              gint             *natural);
 static void   gtk_entry_size_allocate        (GtkWidget        *widget,
                                              GtkAllocation    *allocation);
 static void   gtk_entry_draw_frame           (GtkWidget        *widget,
-                                              GdkEventExpose   *event);
+                                              GtkStyleContext  *context,
+                                              cairo_t          *cr);
 static void   gtk_entry_draw_progress        (GtkWidget        *widget,
-                                              GdkEventExpose   *event);
-static gint   gtk_entry_expose               (GtkWidget        *widget,
-                                             GdkEventExpose   *event);
+                                              GtkStyleContext  *context,
+                                              cairo_t          *cr);
+static gint   gtk_entry_draw                 (GtkWidget        *widget,
+                                              cairo_t          *cr);
 static gint   gtk_entry_button_press         (GtkWidget        *widget,
                                              GdkEventButton   *event);
 static gint   gtk_entry_button_release       (GtkWidget        *widget,
@@ -288,8 +396,7 @@ static gint   gtk_entry_focus_in             (GtkWidget        *widget,
 static gint   gtk_entry_focus_out            (GtkWidget        *widget,
                                              GdkEventFocus    *event);
 static void   gtk_entry_grab_focus           (GtkWidget        *widget);
-static void   gtk_entry_style_set            (GtkWidget        *widget,
-                                             GtkStyle         *previous_style);
+static void   gtk_entry_style_updated        (GtkWidget        *widget);
 static gboolean gtk_entry_query_tooltip      (GtkWidget        *widget,
                                               gint              x,
                                               gint              y,
@@ -297,8 +404,8 @@ static gboolean gtk_entry_query_tooltip      (GtkWidget        *widget,
                                               GtkTooltip       *tooltip);
 static void   gtk_entry_direction_changed    (GtkWidget        *widget,
                                              GtkTextDirection  previous_dir);
-static void   gtk_entry_state_changed        (GtkWidget        *widget,
-                                             GtkStateType      previous_state);
+static void   gtk_entry_state_flags_changed  (GtkWidget        *widget,
+                                             GtkStateFlags     previous_state);
 static void   gtk_entry_screen_changed       (GtkWidget        *widget,
                                              GdkScreen        *old_screen);
 
@@ -416,13 +523,14 @@ static void         gtk_entry_enter_text               (GtkEntry       *entry,
 static void         gtk_entry_set_positions            (GtkEntry       *entry,
                                                        gint            current_pos,
                                                        gint            selection_bound);
-static void         gtk_entry_draw_text                (GtkEntry       *entry);
+static void         gtk_entry_draw_text                (GtkEntry       *entry,
+                                                        cairo_t        *cr);
 static void         gtk_entry_draw_cursor              (GtkEntry       *entry,
+                                                        cairo_t        *cr,
                                                        CursorType      type);
 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_recompute                (GtkEntry       *entry);
 static gint         gtk_entry_find_position            (GtkEntry       *entry,
                                                        gint            x);
@@ -453,6 +561,8 @@ static void         gtk_entry_do_popup                 (GtkEntry       *entry,
                                                        GdkEventButton *event);
 static gboolean     gtk_entry_mnemonic_activate        (GtkWidget      *widget,
                                                        gboolean        group_cycling);
+static void         gtk_entry_grab_notify              (GtkWidget      *widget,
+                                                        gboolean        was_grabbed);
 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);
@@ -461,50 +571,45 @@ static void         gtk_entry_get_text_area_size       (GtkEntry       *entry,
                                                        gint           *y,
                                                        gint           *width,
                                                        gint           *height);
+static void         gtk_entry_get_frame_size           (GtkEntry       *entry,
+                                                       gint           *x,
+                                                       gint           *y,
+                                                       gint           *width,
+                                                       gint           *height);
 static void         get_text_area_size                 (GtkEntry       *entry,
                                                        gint           *x,
                                                        gint           *y,
                                                        gint           *width,
                                                        gint           *height);
-static void         get_widget_window_size             (GtkEntry       *entry,
+static void         get_frame_size                     (GtkEntry       *entry,
+                                                        gboolean        relative_to_window,
                                                        gint           *x,
                                                        gint           *y,
                                                        gint           *width,
                                                        gint           *height);
 static void         gtk_entry_move_adjustments         (GtkEntry             *entry);
-static void         gtk_entry_ensure_pixbuf            (GtkEntry             *entry,
+static GdkPixbuf *  gtk_entry_ensure_pixbuf            (GtkEntry             *entry,
                                                         GtkEntryIconPosition  icon_pos);
-
-
-/* Completion */
-static gint         gtk_entry_completion_timeout       (gpointer            data);
-static gboolean     gtk_entry_completion_key_press     (GtkWidget          *widget,
-                                                       GdkEventKey        *event,
-                                                       gpointer            user_data);
-static void         gtk_entry_completion_changed       (GtkWidget          *entry,
-                                                       gpointer            user_data);
-static gboolean     check_completion_callback          (GtkEntryCompletion *completion);
-static void         clear_completion_callback          (GtkEntry           *entry,
-                                                       GParamSpec         *pspec);
-static gboolean     accept_completion_callback         (GtkEntry           *entry);
-static void         completion_insert_text_callback    (GtkEntry           *entry,
-                                                       const gchar        *text,
-                                                       gint                length,
-                                                       gint                position,
-                                                       GtkEntryCompletion *completion);
-static void         completion_changed                 (GtkEntryCompletion *completion,
-                                                       GParamSpec         *pspec,
-                                                       gpointer            data);
-static void         disconnect_completion_signals      (GtkEntry           *entry,
-                                                       GtkEntryCompletion *completion);
-static void         connect_completion_signals         (GtkEntry           *entry,
-                                                       GtkEntryCompletion *completion);
+static void         gtk_entry_update_cached_style_values(GtkEntry      *entry);
+static gboolean     get_middle_click_paste             (GtkEntry *entry);
+
+/* GtkTextHandle handlers */
+static void         gtk_entry_handle_dragged           (GtkTextHandle         *handle,
+                                                        GtkTextHandlePosition  pos,
+                                                        gint                   x,
+                                                        gint                   y,
+                                                        GtkEntry              *entry);
+static void         gtk_entry_handle_drag_finished     (GtkTextHandle         *handle,
+                                                        GtkTextHandlePosition  pos,
+                                                        GtkEntry              *entry);
+
+static void         gtk_entry_selection_bubble_popup_set   (GtkEntry *entry);
+static void         gtk_entry_selection_bubble_popup_unset (GtkEntry *entry);
 
 static void         begin_change                       (GtkEntry *entry);
 static void         end_change                         (GtkEntry *entry);
 static void         emit_changed                       (GtkEntry *entry);
 
-
 static void         buffer_inserted_text               (GtkEntryBuffer *buffer, 
                                                         guint           position,
                                                         const gchar    *chars,
@@ -527,7 +632,6 @@ static void         buffer_connect_signals             (GtkEntry       *entry);
 static void         buffer_disconnect_signals          (GtkEntry       *entry);
 static GtkEntryBuffer *get_buffer                      (GtkEntry       *entry);
 
-
 G_DEFINE_TYPE_WITH_CODE (GtkEntry, gtk_entry, GTK_TYPE_WIDGET,
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
                                                 gtk_entry_editable_init)
@@ -562,24 +666,24 @@ gtk_entry_class_init (GtkEntryClass *class)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
   GtkWidgetClass *widget_class;
-  GtkObjectClass *gtk_object_class;
   GtkBindingSet *binding_set;
 
   widget_class = (GtkWidgetClass*) class;
-  gtk_object_class = (GtkObjectClass *)class;
 
   gobject_class->dispose = gtk_entry_dispose;
   gobject_class->finalize = gtk_entry_finalize;
   gobject_class->set_property = gtk_entry_set_property;
   gobject_class->get_property = gtk_entry_get_property;
 
+  widget_class->destroy = gtk_entry_destroy;
   widget_class->map = gtk_entry_map;
   widget_class->unmap = gtk_entry_unmap;
   widget_class->realize = gtk_entry_realize;
   widget_class->unrealize = gtk_entry_unrealize;
-  widget_class->size_request = gtk_entry_size_request;
+  widget_class->get_preferred_width = gtk_entry_get_preferred_width;
+  widget_class->get_preferred_height = gtk_entry_get_preferred_height;
   widget_class->size_allocate = gtk_entry_size_allocate;
-  widget_class->expose_event = gtk_entry_expose;
+  widget_class->draw = gtk_entry_draw;
   widget_class->enter_notify_event = gtk_entry_enter_notify;
   widget_class->leave_notify_event = gtk_entry_leave_notify;
   widget_class->button_press_event = gtk_entry_button_press;
@@ -590,14 +694,15 @@ gtk_entry_class_init (GtkEntryClass *class)
   widget_class->focus_in_event = gtk_entry_focus_in;
   widget_class->focus_out_event = gtk_entry_focus_out;
   widget_class->grab_focus = gtk_entry_grab_focus;
-  widget_class->style_set = gtk_entry_style_set;
+  widget_class->style_updated = gtk_entry_style_updated;
   widget_class->query_tooltip = gtk_entry_query_tooltip;
   widget_class->drag_begin = gtk_entry_drag_begin;
   widget_class->drag_end = gtk_entry_drag_end;
   widget_class->direction_changed = gtk_entry_direction_changed;
-  widget_class->state_changed = gtk_entry_state_changed;
+  widget_class->state_flags_changed = gtk_entry_state_flags_changed;
   widget_class->screen_changed = gtk_entry_screen_changed;
   widget_class->mnemonic_activate = gtk_entry_mnemonic_activate;
+  widget_class->grab_notify = gtk_entry_grab_notify;
 
   widget_class->drag_drop = gtk_entry_drag_drop;
   widget_class->drag_motion = gtk_entry_drag_motion;
@@ -608,8 +713,6 @@ gtk_entry_class_init (GtkEntryClass *class)
 
   widget_class->popup_menu = gtk_entry_popup_menu;
 
-  gtk_object_class->destroy = gtk_entry_destroy;
-
   class->move_cursor = gtk_entry_move_cursor;
   class->insert_at_cursor = gtk_entry_insert_at_cursor;
   class->delete_from_cursor = gtk_entry_delete_from_cursor;
@@ -620,6 +723,7 @@ gtk_entry_class_init (GtkEntryClass *class)
   class->toggle_overwrite = gtk_entry_toggle_overwrite;
   class->activate = gtk_entry_real_activate;
   class->get_text_area_size = gtk_entry_get_text_area_size;
+  class->get_frame_size = gtk_entry_get_frame_size;
   
   quark_inner_border = g_quark_from_static_string ("gtk-entry-inner-border");
   quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
@@ -691,13 +795,23 @@ gtk_entry_class_init (GtkEntryClass *class)
                                                          TRUE,
                                                         GTK_PARAM_READWRITE));
 
+  /**
+   * GtkEntry:inner-border:
+   *
+   * Sets the text area's border between the text and the frame.
+   *
+   * Deprecated: 3.4: Use the standard border and padding CSS properties
+   *   (through objects like #GtkStyleContext and #GtkCssProvider); the value
+   *   of this style property is ignored.
+   */
   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));
+                                                       GTK_PARAM_READWRITE |
+                                                       G_PARAM_DEPRECATED));
 
   g_object_class_install_property (gobject_class,
                                    PROP_INVISIBLE_CHAR,
@@ -833,13 +947,13 @@ gtk_entry_class_init (GtkEntryClass *class)
   g_object_class_install_property (gobject_class,
                                    PROP_INVISIBLE_CHAR_SET,
                                    g_param_spec_boolean ("invisible-char-set",
-                                                         P_("Invisible char set"),
-                                                         P_("Whether the invisible char has been set"),
+                                                         P_("Invisible character set"),
+                                                         P_("Whether the invisible character has been set"),
                                                          FALSE,
                                                          GTK_PARAM_READWRITE));
 
   /**
-   * GtkEntry:caps-lock-warning
+   * GtkEntry:caps-lock-warning:
    *
    * Whether password entries will show a warning when Caps Lock is on.
    *
@@ -893,6 +1007,22 @@ gtk_entry_class_init (GtkEntryClass *class)
                                                         GTK_PARAM_READWRITE));
 
   /**
+  * GtkEntry:placeholder-text:
+  *
+  * The text that will be displayed in the #GtkEntry when it is empty
+  * and unfocused.
+  *
+  * Since: 3.2
+  */
+ g_object_class_install_property (gobject_class,
+                                  PROP_PLACEHOLDER_TEXT,
+                                  g_param_spec_string ("placeholder-text",
+                                                       P_("Placeholder text"),
+                                                       P_("Show text in the entry when it's empty and unfocused"),
+                                                       NULL,
+                                                       GTK_PARAM_READWRITE));
+
+   /**
    * GtkEntry:primary-icon-pixbuf:
    *
    * A pixbuf to use as the primary icon for the entry.
@@ -1062,7 +1192,7 @@ gtk_entry_class_init (GtkEntryClass *class)
                                    g_param_spec_boolean ("primary-icon-activatable",
                                                          P_("Primary icon activatable"),
                                                          P_("Whether the primary icon is activatable"),
-                                                         FALSE,
+                                                         TRUE,
                                                          GTK_PARAM_READWRITE));
   
   /**
@@ -1083,7 +1213,7 @@ gtk_entry_class_init (GtkEntryClass *class)
                                    g_param_spec_boolean ("secondary-icon-activatable",
                                                          P_("Secondary icon activatable"),
                                                          P_("Whether the secondary icon is activatable"),
-                                                         FALSE,
+                                                         TRUE,
                                                          GTK_PARAM_READWRITE));
   
   
@@ -1223,6 +1353,93 @@ gtk_entry_class_init (GtkEntryClass *class)
                                                         NULL,
                                                         GTK_PARAM_READWRITE));
 
+  /**
+   * GtkEntry:completion:
+   *
+   * The auxiliary completion object to use with the entry.
+   *
+   * Since: 3.2
+   */     
+  g_object_class_install_property (gobject_class,
+                                   PROP_COMPLETION,
+                                   g_param_spec_object ("completion",
+                                                        P_("Completion"),
+                                                        P_("The auxiliary completion object"),
+                                                        GTK_TYPE_ENTRY_COMPLETION,
+                                                        GTK_PARAM_READWRITE));
+
+  /**
+   * GtkEntry:input-purpose:
+   *
+   * The purpose of this text field.
+   *
+   * This property can be used by on-screen keyboards and other input
+   * methods to adjust their behaviour.
+   *
+   * Note that setting the purpose to %GTK_INPUT_PURPOSE_PASSWORD or
+   * %GTK_INPUT_PURPOSE_PIN is independent from setting
+   * #GtkEntry:visibility.
+   *
+   * Since: 3.6
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_INPUT_PURPOSE,
+                                   g_param_spec_enum ("input-purpose",
+                                                      P_("Purpose"),
+                                                      P_("Purpose of the text field"),
+                                                      GTK_TYPE_INPUT_PURPOSE,
+                                                      GTK_INPUT_PURPOSE_FREE_FORM,
+                                                      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  /**
+   * GtkEntry:input-hints:
+   *
+   * Additional hints (beyond #GtkEntry:input-purpose) that
+   * allow input methods to fine-tune their behaviour.
+   *
+   * Since: 3.6
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_INPUT_HINTS,
+                                   g_param_spec_flags ("input-hints",
+                                                       P_("hints"),
+                                                       P_("Hints for the text field behaviour"),
+                                                       GTK_TYPE_INPUT_HINTS,
+                                                       GTK_INPUT_HINT_NONE,
+                                                       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  /**
+   * GtkEntry:attributes:
+   *
+   * A list of Pango attributes to apply to the text of the entry.
+   *
+   * This is mainly useful to change the size or weight of the text.
+   *
+   * Since: 3.6
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_ATTRIBUTES,
+                                   g_param_spec_boxed ("attributes",
+                                                       P_("Attributes"),
+                                                       P_("A list of style attributes to apply to the text of the label"),
+                                                       PANGO_TYPE_ATTR_LIST,
+                                                       GTK_PARAM_READWRITE));
+
+  /** GtkEntry:populate-all:
+   *
+   * If ::populate-all is %TRUE, the #GtkEntry::populate-popup
+   * signal is also emitted for touch popups.
+   *
+   * Since: 3.8
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_POPULATE_ALL,
+                                   g_param_spec_boolean ("populate-all",
+                                                         P_("Populate all"),
+                                                         P_("Whether to emit ::populate-popup for touch popups"),
+                                                         FALSE,
+                                                         GTK_PARAM_READWRITE));
+  
   /**
    * GtkEntry:icon-prelight:
    *
@@ -1244,20 +1461,25 @@ gtk_entry_class_init (GtkEntryClass *class)
    * The border around the progress bar in the entry.
    *
    * Since: 2.16
+   *
+   * Deprecated: 3.4: Use the standard margin CSS property (through objects
+   *   like #GtkStyleContext and #GtkCssProvider); the value of this style
+   *   property is ignored.
    */
   gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_boxed ("progress-border",
                                                                P_("Progress Border"),
                                                                P_("Border around the progress bar"),
                                                                GTK_TYPE_BORDER,
-                                                               GTK_PARAM_READABLE));
+                                                               GTK_PARAM_READABLE |
+                                                               G_PARAM_DEPRECATED));
   
   /**
    * GtkEntry:invisible-char:
    *
    * The invisible character is used when masking entry contents (in
    * \"password mode\")"). When it is not explicitly set with the
-   * #GtkEntry::invisible-char property, GTK+ determines the character
+   * #GtkEntry:invisible-char property, GTK+ determines the character
    * to use from a list of possible candidates, depending on availability
    * in the current font.
    *
@@ -1276,13 +1498,20 @@ gtk_entry_class_init (GtkEntryClass *class)
   /**
    * GtkEntry::populate-popup:
    * @entry: The entry on which the signal is emitted
-   * @menu: the menu that is being populated
+   * @popup: the container that is being populated
    *
-   * The ::populate-popup signal gets emitted before showing the 
-   * context menu of the entry. 
+   * The ::populate-popup signal gets emitted before showing the
+   * context menu of the entry.
    *
    * If you need to add items to the context menu, connect
-   * to this signal and append your menuitems to the @menu.
+   * to this signal and append your items to the @widget, which
+   * will be a #GtkMenu in this case.
+   *
+   * If #GtkEntry::populate-all is %TRUE, this signal will
+   * also be emitted to populate touch popups. In this case,
+   * @widget will be a different container, e.g. a #GtkToolbar.
+   * The signal handler should not make assumptions about the
+   * type of @widget.
    */
   signals[POPULATE_POPUP] =
     g_signal_new (I_("populate-popup"),
@@ -1292,7 +1521,7 @@ gtk_entry_class_init (GtkEntryClass *class)
                  NULL, NULL,
                  _gtk_marshal_VOID__OBJECT,
                  G_TYPE_NONE, 1,
-                 GTK_TYPE_MENU);
+                 GTK_TYPE_WIDGET);
   
  /* Action signals */
   
@@ -1300,12 +1529,13 @@ gtk_entry_class_init (GtkEntryClass *class)
    * GtkEntry::activate:
    * @entry: The entry on which the signal is emitted
    *
-   * A  <link linkend="keybinding-signals">keybinding signal</link>
-   * which gets emitted when the user activates the entry.
-   * 
-   * Applications should not connect to it, but may emit it with
-   * g_signal_emit_by_name() if they need to control activation 
-   * programmatically.
+   * The ::activate signal is emitted when the user hits
+   * the Enter key.
+   *
+   * While this signal is used as a
+   * <link linkend="keybinding-signals">keybinding signal</link>,
+   * it is also commonly used by applications to intercept
+   * activation of entries.
    *
    * The default bindings for this signal are all forms of the Enter key.
    */
@@ -1513,7 +1743,7 @@ gtk_entry_class_init (GtkEntryClass *class)
    * GtkEntry::icon-press:
    * @entry: The entry on which the signal is emitted
    * @icon_pos: The position of the clicked icon
-   * @event: the button press event
+   * @event: (type Gdk.EventButton): the button press event
    *
    * The ::icon-press signal is emitted when an activatable icon
    * is clicked.
@@ -1535,7 +1765,7 @@ gtk_entry_class_init (GtkEntryClass *class)
    * GtkEntry::icon-release:
    * @entry: The entry on which the signal is emitted
    * @icon_pos: The position of the clicked icon
-   * @event: the button release event
+   * @event: (type Gdk.EventButton): the button release event
    *
    * The ::icon-release signal is emitted on the button release from a
    * mouse click over an activatable icon.
@@ -1582,85 +1812,85 @@ gtk_entry_class_init (GtkEntryClass *class)
   binding_set = gtk_binding_set_by_class (class);
 
   /* Moving the insertion point */
-  add_move_binding (binding_set, GDK_Right, 0,
+  add_move_binding (binding_set, GDK_KEY_Right, 0,
                    GTK_MOVEMENT_VISUAL_POSITIONS, 1);
   
-  add_move_binding (binding_set, GDK_Left, 0,
+  add_move_binding (binding_set, GDK_KEY_Left, 0,
                    GTK_MOVEMENT_VISUAL_POSITIONS, -1);
 
-  add_move_binding (binding_set, GDK_KP_Right, 0,
+  add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
                    GTK_MOVEMENT_VISUAL_POSITIONS, 1);
   
-  add_move_binding (binding_set, GDK_KP_Left, 0,
+  add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
                    GTK_MOVEMENT_VISUAL_POSITIONS, -1);
   
-  add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK,
+  add_move_binding (binding_set, GDK_KEY_Right, GDK_CONTROL_MASK,
                    GTK_MOVEMENT_WORDS, 1);
 
-  add_move_binding (binding_set, GDK_Left, GDK_CONTROL_MASK,
+  add_move_binding (binding_set, GDK_KEY_Left, GDK_CONTROL_MASK,
                    GTK_MOVEMENT_WORDS, -1);
 
-  add_move_binding (binding_set, GDK_KP_Right, GDK_CONTROL_MASK,
+  add_move_binding (binding_set, GDK_KEY_KP_Right, GDK_CONTROL_MASK,
                    GTK_MOVEMENT_WORDS, 1);
 
-  add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
+  add_move_binding (binding_set, GDK_KEY_KP_Left, GDK_CONTROL_MASK,
                    GTK_MOVEMENT_WORDS, -1);
   
-  add_move_binding (binding_set, GDK_Home, 0,
+  add_move_binding (binding_set, GDK_KEY_Home, 0,
                    GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
 
-  add_move_binding (binding_set, GDK_End, 0,
+  add_move_binding (binding_set, GDK_KEY_End, 0,
                    GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
 
-  add_move_binding (binding_set, GDK_KP_Home, 0,
+  add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
                    GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
 
-  add_move_binding (binding_set, GDK_KP_End, 0,
+  add_move_binding (binding_set, GDK_KEY_KP_End, 0,
                    GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
   
-  add_move_binding (binding_set, GDK_Home, GDK_CONTROL_MASK,
+  add_move_binding (binding_set, GDK_KEY_Home, GDK_CONTROL_MASK,
                    GTK_MOVEMENT_BUFFER_ENDS, -1);
 
-  add_move_binding (binding_set, GDK_End, GDK_CONTROL_MASK,
+  add_move_binding (binding_set, GDK_KEY_End, GDK_CONTROL_MASK,
                    GTK_MOVEMENT_BUFFER_ENDS, 1);
 
-  add_move_binding (binding_set, GDK_KP_Home, GDK_CONTROL_MASK,
+  add_move_binding (binding_set, GDK_KEY_KP_Home, GDK_CONTROL_MASK,
                    GTK_MOVEMENT_BUFFER_ENDS, -1);
 
-  add_move_binding (binding_set, GDK_KP_End, GDK_CONTROL_MASK,
+  add_move_binding (binding_set, GDK_KEY_KP_End, GDK_CONTROL_MASK,
                    GTK_MOVEMENT_BUFFER_ENDS, 1);
 
   /* Select all
    */
-  gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, 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_a, GDK_CONTROL_MASK,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
                                 "move-cursor", 3,
                                 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
                                 G_TYPE_INT, 1,
                                G_TYPE_BOOLEAN, TRUE);  
 
-  gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_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,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_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,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_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,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
                                 "move-cursor", 3,
                                 GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_VISUAL_POSITIONS,
                                 G_TYPE_INT, 0,
@@ -1668,66 +1898,66 @@ gtk_entry_class_init (GtkEntryClass *class)
 
   /* Activate
    */
-  gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
                                "activate", 0);
-  gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
                                "activate", 0);
-  gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
                                "activate", 0);
   
   /* Deleting text */
-  gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, 0,
                                "delete-from-cursor", 2,
                                G_TYPE_ENUM, GTK_DELETE_CHARS,
                                G_TYPE_INT, 1);
 
-  gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, 0,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, 0,
                                "delete-from-cursor", 2,
                                G_TYPE_ENUM, GTK_DELETE_CHARS,
                                G_TYPE_INT, 1);
   
-  gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, 0,
                                "backspace", 0);
 
   /* Make this do the same as Backspace, to help with mis-typing */
-  gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_SHIFT_MASK,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_SHIFT_MASK,
                                "backspace", 0);
 
-  gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_CONTROL_MASK,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_CONTROL_MASK,
                                "delete-from-cursor", 2,
                                G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
                                G_TYPE_INT, 1);
 
-  gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_CONTROL_MASK,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Delete, GDK_CONTROL_MASK,
                                "delete-from-cursor", 2,
                                G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
                                G_TYPE_INT, 1);
   
-  gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_BackSpace, GDK_CONTROL_MASK,
                                "delete-from-cursor", 2,
                                G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
                                G_TYPE_INT, -1);
 
   /* Cut/copy/paste */
 
-  gtk_binding_entry_add_signal (binding_set, GDK_x, GDK_CONTROL_MASK,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_x, GDK_CONTROL_MASK,
                                "cut-clipboard", 0);
-  gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
                                "copy-clipboard", 0);
-  gtk_binding_entry_add_signal (binding_set, GDK_v, GDK_CONTROL_MASK,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_v, GDK_CONTROL_MASK,
                                "paste-clipboard", 0);
 
-  gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_SHIFT_MASK,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Delete, GDK_SHIFT_MASK,
                                "cut-clipboard", 0);
-  gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_CONTROL_MASK,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_CONTROL_MASK,
                                "copy-clipboard", 0);
-  gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, GDK_SHIFT_MASK,
                                "paste-clipboard", 0);
 
   /* Overwrite */
-  gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Insert, 0,
                                "toggle-overwrite", 0);
-  gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
                                "toggle-overwrite", 0);
 
   /**
@@ -1736,55 +1966,27 @@ gtk_entry_class_init (GtkEntryClass *class)
    * Sets the text area's border between the text and the frame.
    *
    * Since: 2.10
+   *
+   * Deprecated: 3.4: Use the standard border and padding CSS properties
+   *   (through objects like #GtkStyleContext and #GtkCssProvider); the value
+   *   of this style property is ignored.
    */
   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));
-
-   /**
-    * GtkEntry:state-hint:
-    *
-    * Indicates whether to pass a proper widget state when
-    * drawing the shadow and the widget background.
-    *
-    * Since: 2.16
-    */
-   gtk_widget_class_install_style_property (widget_class,
-                                            g_param_spec_boolean ("state-hint",
-                                                                  P_("State Hint"),
-                                                                  P_("Whether to pass a proper state when drawing shadow or background"),
-                                                                  FALSE,
-                                                                  GTK_PARAM_READABLE));
-
-   gtk_settings_install_property (g_param_spec_boolean ("gtk-entry-select-on-focus",
-                                                      P_("Select on focus"),
-                                                      P_("Whether to select the contents of an entry when it is focused"),
-                                                      TRUE,
-                                                      GTK_PARAM_READWRITE));
-
-  /**
-   * GtkSettings:gtk-entry-password-hint-timeout:
-   *
-   * How long to show the last input character in hidden
-   * entries. This value is in milliseconds. 0 disables showing the
-   * last char. 600 is a good value for enabling it.
-   *
-   * Since: 2.10
-   */
-  gtk_settings_install_property (g_param_spec_uint ("gtk-entry-password-hint-timeout",
-                                                    P_("Password Hint Timeout"),
-                                                    P_("How long to show the last input character in hidden entries"),
-                                                    0, G_MAXUINT, 0,
-                                                    GTK_PARAM_READWRITE));
+                                                               GTK_PARAM_READABLE |
+                                                               G_PARAM_DEPRECATED));
 
   g_type_class_add_private (gobject_class, sizeof (GtkEntryPrivate));
+  test_touchscreen = g_getenv ("GTK_TEST_TOUCHSCREEN") != NULL;
+
+  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
 }
 
 static void
-gtk_entry_editable_init (GtkEditableClass *iface)
+gtk_entry_editable_init (GtkEditableInterface *iface)
 {
   iface->do_insert_text = gtk_entry_insert_text;
   iface->do_delete_text = gtk_entry_delete_text;
@@ -1803,15 +2005,35 @@ gtk_entry_cell_editable_init (GtkCellEditableIface *iface)
   iface->start_editing = gtk_entry_start_editing;
 }
 
+/* for deprecated properties */
+static void
+gtk_entry_do_set_inner_border (GtkEntry *entry,
+                               const GtkBorder *border)
+{
+  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");
+}
+
+static const GtkBorder *
+gtk_entry_do_get_inner_border (GtkEntry *entry)
+{
+  return g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
+}
+
 static void
 gtk_entry_set_property (GObject         *object,
                         guint            prop_id,
                         const GValue    *value,
                         GParamSpec      *pspec)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
   GtkEntry *entry = GTK_ENTRY (object);
-  GtkWidget *widget;
+  GtkEntryPrivate *priv = entry->priv;
 
   switch (prop_id)
     {
@@ -1823,25 +2045,26 @@ gtk_entry_set_property (GObject         *object,
       {
         gboolean new_value = g_value_get_boolean (value);
 
-       if (new_value != entry->editable)
+        if (new_value != priv->editable)
          {
-            widget = GTK_WIDGET (entry);
+            GtkWidget *widget = GTK_WIDGET (entry);
+
            if (!new_value)
              {
-               _gtk_entry_reset_im_context (entry);
+               gtk_entry_reset_im_context (entry);
                if (gtk_widget_has_focus (widget))
-                 gtk_im_context_focus_out (entry->im_context);
+                 gtk_im_context_focus_out (priv->im_context);
 
-               entry->preedit_length = 0;
-               entry->preedit_cursor = 0;
+               priv->preedit_length = 0;
+               priv->preedit_cursor = 0;
              }
 
-           entry->editable = new_value;
+           priv->editable = new_value;
 
            if (new_value && gtk_widget_has_focus (widget))
-             gtk_im_context_focus_in (entry->im_context);
-           
-           gtk_entry_queue_draw (entry);
+             gtk_im_context_focus_in (priv->im_context);
+
+           gtk_widget_queue_draw (widget);
          }
       }
       break;
@@ -1859,7 +2082,7 @@ gtk_entry_set_property (GObject         *object,
       break;
 
     case PROP_INNER_BORDER:
-      gtk_entry_set_inner_border (entry, g_value_get_boxed (value));
+      gtk_entry_do_set_inner_border (entry, g_value_get_boxed (value));
       break;
 
     case PROP_INVISIBLE_CHAR:
@@ -1883,7 +2106,7 @@ gtk_entry_set_property (GObject         *object,
       break;
 
     case PROP_TRUNCATE_MULTILINE:
-      entry->truncate_multiline = g_value_get_boolean (value);
+      priv->truncate_multiline = g_value_get_boolean (value);
       break;
 
     case PROP_SHADOW_TYPE:
@@ -1913,6 +2136,10 @@ gtk_entry_set_property (GObject         *object,
       gtk_entry_set_progress_pulse_step (entry, g_value_get_double (value));
       break;
 
+    case PROP_PLACEHOLDER_TEXT:
+      gtk_entry_set_placeholder_text (entry, g_value_get_string (value));
+      break;
+
     case PROP_PIXBUF_PRIMARY:
       gtk_entry_set_icon_from_pixbuf (entry,
                                       GTK_ENTRY_ICON_PRIMARY,
@@ -2012,12 +2239,32 @@ gtk_entry_set_property (GObject         *object,
     case PROP_IM_MODULE:
       g_free (priv->im_module);
       priv->im_module = g_value_dup_string (value);
-      if (GTK_IS_IM_MULTICONTEXT (entry->im_context))
-        gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (entry->im_context), priv->im_module);
+      if (GTK_IS_IM_MULTICONTEXT (priv->im_context))
+        gtk_im_multicontext_set_context_id (GTK_IM_MULTICONTEXT (priv->im_context), priv->im_module);
       break;
 
     case PROP_EDITING_CANCELED:
-      entry->editing_canceled = g_value_get_boolean (value);
+      priv->editing_canceled = g_value_get_boolean (value);
+      break;
+
+    case PROP_COMPLETION:
+      gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (g_value_get_object (value)));
+      break;
+
+    case PROP_INPUT_PURPOSE:
+      gtk_entry_set_input_purpose (entry, g_value_get_enum (value));
+      break;
+
+    case PROP_INPUT_HINTS:
+      gtk_entry_set_input_hints (entry, g_value_get_flags (value));
+      break;
+
+    case PROP_ATTRIBUTES:
+      gtk_entry_set_attributes (entry, g_value_get_boxed (value));
+      break;
+
+    case PROP_POPULATE_ALL:
+      entry->priv->populate_all = g_value_get_boolean (value);
       break;
 
     case PROP_SCROLL_OFFSET:
@@ -2034,8 +2281,8 @@ gtk_entry_get_property (GObject         *object,
                         GValue          *value,
                         GParamSpec      *pspec)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (object);
   GtkEntry *entry = GTK_ENTRY (object);
+  GtkEntryPrivate *priv = entry->priv;
 
   switch (prop_id)
     {
@@ -2044,15 +2291,15 @@ gtk_entry_get_property (GObject         *object,
       break;
 
     case PROP_CURSOR_POSITION:
-      g_value_set_int (value, entry->current_pos);
+      g_value_set_int (value, priv->current_pos);
       break;
 
     case PROP_SELECTION_BOUND:
-      g_value_set_int (value, entry->selection_bound);
+      g_value_set_int (value, priv->selection_bound);
       break;
 
     case PROP_EDITABLE:
-      g_value_set_boolean (value, entry->editable);
+      g_value_set_boolean (value, priv->editable);
       break;
 
     case PROP_MAX_LENGTH:
@@ -2060,31 +2307,31 @@ gtk_entry_get_property (GObject         *object,
       break;
 
     case PROP_VISIBILITY:
-      g_value_set_boolean (value, entry->visible);
+      g_value_set_boolean (value, priv->visible);
       break;
 
     case PROP_HAS_FRAME:
-      g_value_set_boolean (value, entry->has_frame);
+      g_value_set_boolean (value, priv->has_frame);
       break;
 
     case PROP_INNER_BORDER:
-      g_value_set_boxed (value, gtk_entry_get_inner_border (entry));
+      g_value_set_boxed (value, gtk_entry_do_get_inner_border (entry));
       break;
 
     case PROP_INVISIBLE_CHAR:
-      g_value_set_uint (value, entry->invisible_char);
+      g_value_set_uint (value, priv->invisible_char);
       break;
 
     case PROP_ACTIVATES_DEFAULT:
-      g_value_set_boolean (value, entry->activates_default);
+      g_value_set_boolean (value, priv->activates_default);
       break;
 
     case PROP_WIDTH_CHARS:
-      g_value_set_int (value, entry->width_chars);
+      g_value_set_int (value, priv->width_chars);
       break;
 
     case PROP_SCROLL_OFFSET:
-      g_value_set_int (value, entry->scroll_offset);
+      g_value_set_int (value, priv->scroll_offset);
       break;
 
     case PROP_TEXT:
@@ -2096,7 +2343,7 @@ gtk_entry_get_property (GObject         *object,
       break;
 
     case PROP_TRUNCATE_MULTILINE:
-      g_value_set_boolean (value, entry->truncate_multiline);
+      g_value_set_boolean (value, priv->truncate_multiline);
       break;
 
     case PROP_SHADOW_TYPE:
@@ -2104,7 +2351,7 @@ gtk_entry_get_property (GObject         *object,
       break;
 
     case PROP_OVERWRITE_MODE:
-      g_value_set_boolean (value, entry->overwrite_mode);
+      g_value_set_boolean (value, priv->overwrite_mode);
       break;
 
     case PROP_TEXT_LENGTH:
@@ -2131,6 +2378,10 @@ gtk_entry_get_property (GObject         *object,
       g_value_set_double (value, priv->progress_pulse_fraction);
       break;
 
+    case PROP_PLACEHOLDER_TEXT:
+      g_value_set_string (value, gtk_entry_get_placeholder_text (entry));
+      break;
+
     case PROP_PIXBUF_PRIMARY:
       g_value_set_object (value,
                           gtk_entry_get_icon_pixbuf (entry,
@@ -2233,7 +2484,27 @@ gtk_entry_get_property (GObject         *object,
 
     case PROP_EDITING_CANCELED:
       g_value_set_boolean (value,
-                           entry->editing_canceled);
+                           priv->editing_canceled);
+      break;
+
+    case PROP_COMPLETION:
+      g_value_set_object (value, G_OBJECT (gtk_entry_get_completion (entry)));
+      break;
+
+    case PROP_INPUT_PURPOSE:
+      g_value_set_enum (value, gtk_entry_get_input_purpose (entry));
+      break;
+
+    case PROP_INPUT_HINTS:
+      g_value_set_flags (value, gtk_entry_get_input_hints (entry));
+      break;
+
+    case PROP_ATTRIBUTES:
+      g_value_set_boxed (value, priv->attrs);
+      break;
+
+    case PROP_POPULATE_ALL:
+      g_value_set_boolean (value, priv->populate_all);
       break;
 
     default:
@@ -2256,10 +2527,9 @@ find_invisible_char (GtkWidget *widget)
     0x273a  /* SIXTEEN POINTED ASTERISK */
   };
 
-  if (widget->style)
-    gtk_widget_style_get (widget,
-                          "invisible-char", &invisible_chars[0],
-                          NULL);
+  gtk_widget_style_get (widget,
+                        "invisible-char", &invisible_chars[0],
+                        NULL);
 
   layout = gtk_widget_create_pango_layout (widget, NULL);
 
@@ -2294,19 +2564,25 @@ find_invisible_char (GtkWidget *widget)
 static void
 gtk_entry_init (GtkEntry *entry)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkStyleContext *context;
+  GtkEntryPrivate *priv;
 
-  gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
+  entry->priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
+                                             GTK_TYPE_ENTRY,
+                                             GtkEntryPrivate);
+  priv = entry->priv;
 
-  entry->editable = TRUE;
-  entry->visible = TRUE;
-  entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
-  entry->dnd_position = -1;
-  entry->width_chars = -1;
-  entry->is_cell_renderer = FALSE;
-  entry->editing_canceled = FALSE;
-  entry->has_frame = TRUE;
-  entry->truncate_multiline = FALSE;
+  gtk_widget_set_can_focus (GTK_WIDGET (entry), TRUE);
+  gtk_widget_set_has_window (GTK_WIDGET (entry), FALSE);
+
+  priv->editable = TRUE;
+  priv->visible = TRUE;
+  priv->dnd_position = -1;
+  priv->width_chars = -1;
+  priv->is_cell_renderer = FALSE;
+  priv->editing_canceled = FALSE;
+  priv->has_frame = TRUE;
+  priv->truncate_multiline = FALSE;
   priv->shadow_type = GTK_SHADOW_IN;
   priv->xalign = 0.0;
   priv->caps_lock_warning = TRUE;
@@ -2323,39 +2599,95 @@ gtk_entry_init (GtkEntry *entry)
   /* This object is completely private. No external entity can gain a reference
    * to it; so we create it here and destroy it in finalize().
    */
-  entry->im_context = gtk_im_multicontext_new ();
-  
-  g_signal_connect (entry->im_context, "commit",
+  priv->im_context = gtk_im_multicontext_new ();
+
+  g_signal_connect (priv->im_context, "commit",
                    G_CALLBACK (gtk_entry_commit_cb), entry);
-  g_signal_connect (entry->im_context, "preedit-changed",
+  g_signal_connect (priv->im_context, "preedit-changed",
                    G_CALLBACK (gtk_entry_preedit_changed_cb), entry);
-  g_signal_connect (entry->im_context, "retrieve-surrounding",
+  g_signal_connect (priv->im_context, "retrieve-surrounding",
                    G_CALLBACK (gtk_entry_retrieve_surrounding_cb), entry);
-  g_signal_connect (entry->im_context, "delete-surrounding",
+  g_signal_connect (priv->im_context, "delete-surrounding",
                    G_CALLBACK (gtk_entry_delete_surrounding_cb), entry);
 
+  context = gtk_widget_get_style_context (GTK_WIDGET (entry));
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_ENTRY);
+
+  gtk_entry_update_cached_style_values (entry);
+
+  priv->text_handle = _gtk_text_handle_new (GTK_WIDGET (entry));
+  g_signal_connect (priv->text_handle, "handle-dragged",
+                    G_CALLBACK (gtk_entry_handle_dragged), entry);
+  g_signal_connect (priv->text_handle, "drag-finished",
+                    G_CALLBACK (gtk_entry_handle_drag_finished), entry);
+}
+
+static void
+gtk_entry_prepare_context_for_icon (GtkEntry             *entry,
+                                    GtkStyleContext      *context,
+                                    GtkEntryIconPosition  icon_pos)
+{
+  GtkEntryPrivate *priv = entry->priv;
+  EntryIconInfo *icon_info = priv->icons[icon_pos];
+  GtkWidget *widget;
+  GtkStateFlags state;
+
+  widget = GTK_WIDGET (entry);
+  state = gtk_widget_get_state_flags (widget);
+
+  state &= ~(GTK_STATE_FLAG_PRELIGHT);
+
+  if ((state & GTK_STATE_FLAG_INSENSITIVE) || icon_info->insensitive)
+    state |= GTK_STATE_FLAG_INSENSITIVE;
+  else if (icon_info->prelight)
+    state |= GTK_STATE_FLAG_PRELIGHT;
+
+  gtk_style_context_save (context);
+
+  gtk_style_context_set_state (context, state);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
+
+  if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL) 
+    {
+      if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
+      else
+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
+    }
+  else
+    {
+      if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
+      else
+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
+    }
 }
 
 static gint
 get_icon_width (GtkEntry             *entry,
                 GtkEntryIconPosition  icon_pos)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
   EntryIconInfo *icon_info = priv->icons[icon_pos];
-  GdkScreen *screen;
-  GtkSettings *settings;
-  gint menu_icon_width;
+  GtkStyleContext *context;
+  GtkBorder padding;
+  gint width;
 
-  if (!icon_info || icon_info->pixbuf == NULL)
+  if (!icon_info)
     return 0;
 
-  screen = gtk_widget_get_screen (GTK_WIDGET (entry));
-  settings = gtk_settings_get_for_screen (screen);
+  context = gtk_widget_get_style_context (GTK_WIDGET (entry));
+  gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
+  gtk_style_context_get_padding (context, 0, &padding);
+
+  _gtk_icon_helper_get_size (icon_info->icon_helper, context,
+                             &width, NULL);
+  gtk_style_context_restore (context);
 
-  gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
-                                     &menu_icon_width, NULL);
+  if (width > 0)
+    width += padding.left + padding.right;
 
-  return MAX (gdk_pixbuf_get_width (icon_info->pixbuf), menu_icon_width);
+  return width;
 }
 
 static void
@@ -2364,7 +2696,7 @@ get_icon_allocations (GtkEntry      *entry,
                       GtkAllocation *secondary)
 
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
   gint x, y, width, height;
 
   get_text_area_size (entry, &x, &y, &width, &height);
@@ -2375,14 +2707,10 @@ get_icon_allocations (GtkEntry      *entry,
   primary->y = y;
   primary->height = height;
   primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
-  if (primary->width > 0)
-    primary->width += 2 * priv->icon_margin;
 
   secondary->y = y;
   secondary->height = height;
   secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
-  if (secondary->width > 0)
-    secondary->width += 2 * priv->icon_margin;
 
   if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
     {
@@ -2400,77 +2728,84 @@ get_icon_allocations (GtkEntry      *entry,
 static void
 begin_change (GtkEntry *entry)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
 
   priv->change_count++;
+
+  g_object_freeze_notify (G_OBJECT (entry));
 }
 
 static void
 end_change (GtkEntry *entry)
 {
   GtkEditable *editable = GTK_EDITABLE (entry);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
+
   g_return_if_fail (priv->change_count > 0);
 
+  g_object_thaw_notify (G_OBJECT (entry));
+
   priv->change_count--;
 
   if (priv->change_count == 0)
     {
-       if (priv->real_changed) 
+       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);
+  GtkEntryPrivate *priv = entry->priv;
 
   if (priv->change_count == 0)
     g_signal_emit_by_name (editable, "changed");
-  else 
+  else
     priv->real_changed = TRUE;
 }
 
 static void
-gtk_entry_destroy (GtkObject *object)
+gtk_entry_destroy (GtkWidget *widget)
 {
-  GtkEntry *entry = GTK_ENTRY (object);
+  GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
 
-  entry->current_pos = entry->selection_bound = 0;
-  _gtk_entry_reset_im_context (entry);
+  priv->current_pos = priv->selection_bound = 0;
+  gtk_entry_reset_im_context (entry);
   gtk_entry_reset_layout (entry);
 
-  if (entry->blink_timeout)
+  if (priv->blink_timeout)
     {
-      g_source_remove (entry->blink_timeout);
-      entry->blink_timeout = 0;
+      g_source_remove (priv->blink_timeout);
+      priv->blink_timeout = 0;
     }
 
-  if (entry->recompute_idle)
+  if (priv->recompute_idle)
     {
-      g_source_remove (entry->recompute_idle);
-      entry->recompute_idle = 0;
+      g_source_remove (priv->recompute_idle);
+      priv->recompute_idle = 0;
     }
 
-  GTK_OBJECT_CLASS (gtk_entry_parent_class)->destroy (object);
+  GTK_WIDGET_CLASS (gtk_entry_parent_class)->destroy (widget);
 }
 
 static void
 gtk_entry_dispose (GObject *object)
 {
   GtkEntry *entry = GTK_ENTRY (object);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
+  GdkKeymap *keymap;
 
   gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
   gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_PRIMARY, NULL);
   gtk_entry_set_icon_from_pixbuf (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
   gtk_entry_set_icon_tooltip_markup (entry, GTK_ENTRY_ICON_SECONDARY, NULL);
+  gtk_entry_set_completion (entry, NULL);
 
   if (priv->buffer)
     {
@@ -2479,6 +2814,9 @@ gtk_entry_dispose (GObject *object)
       priv->buffer = NULL;
     }
 
+  keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (object)));
+  g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
+  g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
   G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
 }
 
@@ -2486,7 +2824,7 @@ static void
 gtk_entry_finalize (GObject *object)
 {
   GtkEntry *entry = GTK_ENTRY (object);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
   EntryIconInfo *icon_info = NULL;
   gint i;
 
@@ -2500,24 +2838,29 @@ gtk_entry_finalize (GObject *object)
               icon_info->target_list = NULL;
             }
 
+          g_clear_object (&icon_info->icon_helper);
+
           g_slice_free (EntryIconInfo, icon_info);
           priv->icons[i] = NULL;
         }
     }
 
-  gtk_entry_set_completion (entry, NULL);
+  if (priv->cached_layout)
+    g_object_unref (priv->cached_layout);
 
-  if (entry->cached_layout)
-    g_object_unref (entry->cached_layout);
+  g_object_unref (priv->im_context);
 
-  g_object_unref (entry->im_context);
+  if (priv->blink_timeout)
+    g_source_remove (priv->blink_timeout);
 
-  if (entry->blink_timeout)
-    g_source_remove (entry->blink_timeout);
+  if (priv->recompute_idle)
+    g_source_remove (priv->recompute_idle);
 
-  if (entry->recompute_idle)
-    g_source_remove (entry->recompute_idle);
+  if (priv->selection_bubble)
+    gtk_widget_destroy (priv->selection_bubble);
 
+  g_object_unref (priv->text_handle);
+  g_free (priv->placeholder_text);
   g_free (priv->im_module);
 
   G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
@@ -2526,19 +2869,21 @@ gtk_entry_finalize (GObject *object)
 static DisplayMode
 gtk_entry_get_display_mode (GtkEntry *entry)
 {
-  GtkEntryPrivate *priv;
-  if (entry->visible)
+  GtkEntryPrivate *priv = entry->priv;
+
+  if (priv->visible)
     return DISPLAY_NORMAL;
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
-  if (entry->invisible_char == 0 && priv->invisible_char_set)
+
+  if (priv->invisible_char == 0 && priv->invisible_char_set)
     return DISPLAY_BLANK;
+
   return DISPLAY_INVISIBLE;
 }
 
-static gchar*
-gtk_entry_get_display_text (GtkEntry *entry,
-                            gint      start_pos,
-                            gint      end_pos)
+gchar*
+_gtk_entry_get_display_text (GtkEntry *entry,
+                             gint      start_pos,
+                             gint      end_pos)
 {
   GtkEntryPasswordHint *password_hint;
   GtkEntryPrivate *priv;
@@ -2552,7 +2897,7 @@ gtk_entry_get_display_text (GtkEntry *entry,
   guint length;
   gint i;
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
   text = gtk_entry_buffer_get_text (get_buffer (entry));
   length = gtk_entry_buffer_get_length (get_buffer (entry));
 
@@ -2563,7 +2908,7 @@ gtk_entry_get_display_text (GtkEntry *entry,
 
   if (end_pos <= start_pos)
       return g_strdup ("");
-  else if (entry->visible)
+  else if (priv->visible)
     {
       start = g_utf8_offset_to_pointer (text, start_pos);
       end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
@@ -2574,10 +2919,10 @@ gtk_entry_get_display_text (GtkEntry *entry,
       str = g_string_sized_new (length * 2);
 
       /* Figure out what our invisible char is and encode it */
-      if (!entry->invisible_char)
+      if (!priv->invisible_char)
           invisible_char = priv->invisible_char_set ? ' ' : '*';
       else
-          invisible_char = entry->invisible_char;
+          invisible_char = priv->invisible_char;
       char_len = g_unichar_to_utf8 (invisible_char, char_str);
 
       /*
@@ -2602,13 +2947,13 @@ gtk_entry_get_display_text (GtkEntry *entry,
 
       return g_string_free (str, FALSE);
     }
-
 }
 
 static void
 update_cursors (GtkWidget *widget)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
+  GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
   EntryIconInfo *icon_info = NULL;
   GdkDisplay *display;
   GdkCursor *cursor;
@@ -2618,7 +2963,8 @@ update_cursors (GtkWidget *widget)
     {
       if ((icon_info = priv->icons[i]) != NULL)
         {
-          if (icon_info->pixbuf != NULL && icon_info->window != NULL)
+          if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) && 
+              icon_info->window != NULL)
             gdk_window_show_unraised (icon_info->window);
 
           /* The icon windows are not children of the visible entry window,
@@ -2633,7 +2979,7 @@ update_cursors (GtkWidget *widget)
               display = gtk_widget_get_display (widget);
               cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
               gdk_window_set_cursor (icon_info->window, cursor);
-              gdk_cursor_unref (cursor);
+              g_object_unref (cursor);
             }
           else
             {
@@ -2647,7 +2993,8 @@ static void
 realize_icon_info (GtkWidget            *widget, 
                    GtkEntryIconPosition  icon_pos)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
+  GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
   EntryIconInfo *icon_info = priv->icons[icon_pos];
   GdkWindowAttr attributes;
   gint attributes_mask;
@@ -2659,12 +3006,9 @@ realize_icon_info (GtkWidget            *widget,
   attributes.width = 1;
   attributes.height = 1;
   attributes.window_type = GDK_WINDOW_CHILD;
-  attributes.wclass = GDK_INPUT_OUTPUT;
-  attributes.visual = gtk_widget_get_visual (widget);
-  attributes.colormap = gtk_widget_get_colormap (widget);
+  attributes.wclass = GDK_INPUT_ONLY;
   attributes.event_mask = gtk_widget_get_events (widget);
-  attributes.event_mask |= (GDK_EXPOSURE_MASK |
-                                GDK_BUTTON_PRESS_MASK |
+  attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
                                 GDK_BUTTON_RELEASE_MASK |
                                 GDK_BUTTON1_MOTION_MASK |
                                 GDK_BUTTON3_MOTION_MASK |
@@ -2672,14 +3016,12 @@ realize_icon_info (GtkWidget            *widget,
                                 GDK_POINTER_MOTION_MASK |
                                 GDK_ENTER_NOTIFY_MASK |
                             GDK_LEAVE_NOTIFY_MASK);
-  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+  attributes_mask = GDK_WA_X | GDK_WA_Y;
 
-  icon_info->window = gdk_window_new (widget->window,
+  icon_info->window = gdk_window_new (gtk_widget_get_window (widget),
                                       &attributes,
                                       attributes_mask);
-  gdk_window_set_user_data (icon_info->window, widget);
-  gdk_window_set_background (icon_info->window,
-                             &widget->style->base[gtk_widget_get_state (widget)]);
+  gtk_widget_register_window (widget, icon_info->window);
 
   gtk_widget_queue_resize (widget);
 }
@@ -2688,7 +3030,8 @@ static EntryIconInfo*
 construct_icon_info (GtkWidget            *widget, 
                      GtkEntryIconPosition  icon_pos)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
+  GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
   EntryIconInfo *icon_info;
 
   g_return_val_if_fail (priv->icons[icon_pos] == NULL, NULL);
@@ -2696,6 +3039,9 @@ construct_icon_info (GtkWidget            *widget,
   icon_info = g_slice_new0 (EntryIconInfo);
   priv->icons[icon_pos] = icon_info;
 
+  icon_info->icon_helper = _gtk_icon_helper_new ();
+  _gtk_icon_helper_set_force_scale_pixbuf (icon_info->icon_helper, TRUE);
+
   if (gtk_widget_get_realized (widget))
     realize_icon_info (widget, icon_pos);
 
@@ -2705,47 +3051,52 @@ construct_icon_info (GtkWidget            *widget,
 static void
 gtk_entry_map (GtkWidget *widget)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
+  GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
   EntryIconInfo *icon_info = NULL;
   gint i;
 
-  if (gtk_widget_get_realized (widget) && !gtk_widget_get_mapped (widget))
-    {
-      GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
+  GTK_WIDGET_CLASS (gtk_entry_parent_class)->map (widget);
 
-      for (i = 0; i < MAX_ICONS; i++)
+  gdk_window_show (priv->text_area);
+
+  for (i = 0; i < MAX_ICONS; i++)
+    {
+      if ((icon_info = priv->icons[i]) != NULL)
         {
-          if ((icon_info = priv->icons[i]) != NULL)
-            {
-              if (icon_info->pixbuf != NULL && icon_info->window != NULL)
-                gdk_window_show (icon_info->window);
-            }
+          if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) &&
+              icon_info->window != NULL)
+            gdk_window_show (icon_info->window);
         }
-
-      update_cursors (widget);
     }
+
+  update_cursors (widget);
 }
 
 static void
 gtk_entry_unmap (GtkWidget *widget)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
+  GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
   EntryIconInfo *icon_info = NULL;
   gint i;
 
-  if (gtk_widget_get_mapped (widget))
+  _gtk_text_handle_set_mode (priv->text_handle,
+                             GTK_TEXT_HANDLE_MODE_NONE);
+
+  for (i = 0; i < MAX_ICONS; i++)
     {
-      for (i = 0; i < MAX_ICONS; i++)
+      if ((icon_info = priv->icons[i]) != NULL)
         {
-          if ((icon_info = priv->icons[i]) != NULL)
-            {
-              if (icon_info->pixbuf != NULL && icon_info->window != NULL)
-                gdk_window_hide (icon_info->window);
-            }
+          if (!_gtk_icon_helper_get_is_empty (icon_info->icon_helper) && 
+              icon_info->window != NULL)
+            gdk_window_hide (icon_info->window);
         }
-
-      GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
     }
+
+  gdk_window_hide (priv->text_area);
+
+  GTK_WIDGET_CLASS (gtk_entry_parent_class)->unmap (widget);
 }
 
 static void
@@ -2754,24 +3105,24 @@ gtk_entry_realize (GtkWidget *widget)
   GtkEntry *entry;
   GtkEntryPrivate *priv;
   EntryIconInfo *icon_info;
+  GdkWindow *window;
   GdkWindowAttr attributes;
   gint attributes_mask;
+  gint frame_x, frame_y;
   int i;
 
   gtk_widget_set_realized (widget, TRUE);
+  window = gtk_widget_get_parent_window (widget);
+  gtk_widget_set_window (widget, window);
+  g_object_ref (window);
+
   entry = GTK_ENTRY (widget);
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
 
   attributes.window_type = GDK_WINDOW_CHILD;
-  
-  get_widget_window_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
-
-  attributes.wclass = GDK_INPUT_OUTPUT;
-  attributes.visual = gtk_widget_get_visual (widget);
-  attributes.colormap = gtk_widget_get_colormap (widget);
+  attributes.wclass = GDK_INPUT_ONLY;
   attributes.event_mask = gtk_widget_get_events (widget);
-  attributes.event_mask |= (GDK_EXPOSURE_MASK |
-                           GDK_BUTTON_PRESS_MASK |
+  attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
                            GDK_BUTTON_RELEASE_MASK |
                            GDK_BUTTON1_MOTION_MASK |
                            GDK_BUTTON3_MOTION_MASK |
@@ -2779,38 +3130,34 @@ gtk_entry_realize (GtkWidget *widget)
                            GDK_POINTER_MOTION_MASK |
                             GDK_ENTER_NOTIFY_MASK |
                            GDK_LEAVE_NOTIFY_MASK);
-  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
-
-  widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
-  gdk_window_set_user_data (widget->window, entry);
+  attributes_mask = GDK_WA_X | GDK_WA_Y;
 
   get_text_area_size (entry, &attributes.x, &attributes.y, &attributes.width, &attributes.height);
+
+  get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
+  attributes.x += frame_x;
+  attributes.y += frame_y;
+
   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);
+  priv->text_area = gdk_window_new (gtk_widget_get_window (widget),
+                                    &attributes,
+                                    attributes_mask);
 
-  gdk_window_set_user_data (entry->text_area, entry);
+  gtk_widget_register_window (widget, priv->text_area);
 
   if (attributes_mask & GDK_WA_CURSOR)
-    gdk_cursor_unref (attributes.cursor);
-
-  widget->style = gtk_style_attach (widget->style, widget->window);
-
-  gdk_window_set_background (widget->window, &widget->style->base[gtk_widget_get_state (widget)]);
-  gdk_window_set_background (entry->text_area, &widget->style->base[gtk_widget_get_state (widget)]);
+    g_object_unref (attributes.cursor);
 
-  gdk_window_show (entry->text_area);
-
-  gtk_im_context_set_client_window (entry->im_context, entry->text_area);
+  gtk_im_context_set_client_window (priv->im_context, priv->text_area);
 
   gtk_entry_adjust_scroll (entry);
   gtk_entry_update_primary_selection (entry);
-
+  _gtk_text_handle_set_relative_to (priv->text_handle, priv->text_area);
 
   /* If the icon positions are already setup, create their windows.
    * Otherwise if they don't exist yet, then construct_icon_info()
@@ -2830,30 +3177,31 @@ static void
 gtk_entry_unrealize (GtkWidget *widget)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
   GtkClipboard *clipboard;
   EntryIconInfo *icon_info;
   gint i;
 
   gtk_entry_reset_layout (entry);
   
-  gtk_im_context_set_client_window (entry->im_context, NULL);
+  gtk_im_context_set_client_window (priv->im_context, NULL);
+  _gtk_text_handle_set_relative_to (priv->text_handle, NULL);
 
   clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY);
   if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
     gtk_clipboard_clear (clipboard);
   
-  if (entry->text_area)
+  if (priv->text_area)
     {
-      gdk_window_set_user_data (entry->text_area, NULL);
-      gdk_window_destroy (entry->text_area);
-      entry->text_area = NULL;
+      gtk_widget_unregister_window (widget, priv->text_area);
+      gdk_window_destroy (priv->text_area);
+      priv->text_area = NULL;
     }
 
-  if (entry->popup_menu)
+  if (priv->popup_menu)
     {
-      gtk_widget_destroy (entry->popup_menu);
-      entry->popup_menu = NULL;
+      gtk_widget_destroy (priv->popup_menu);
+      priv->popup_menu = NULL;
     }
 
   GTK_WIDGET_CLASS (gtk_entry_parent_class)->unrealize (widget);
@@ -2864,6 +3212,7 @@ gtk_entry_unrealize (GtkWidget *widget)
         {
           if (icon_info->window != NULL)
             {
+              gtk_widget_unregister_window (widget, icon_info->window);
               gdk_window_destroy (icon_info->window);
               icon_info->window = NULL;
             }
@@ -2873,91 +3222,133 @@ gtk_entry_unrealize (GtkWidget *widget)
 
 void
 _gtk_entry_get_borders (GtkEntry *entry,
-                       gint     *xborder,
-                       gint     *yborder)
+                        GtkBorder *border_out)
 {
+  GtkEntryPrivate *priv = entry->priv;
   GtkWidget *widget = GTK_WIDGET (entry);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
+  GtkBorder tmp = { 0, 0, 0, 0 };
+  GtkStyleContext *context;
 
-  if (entry->has_frame)
-    {
-      *xborder = widget->style->xthickness;
-      *yborder = widget->style->ythickness;
-    }
-  else
+  context = gtk_widget_get_style_context (widget);
+  gtk_style_context_get_padding (context, 0, &tmp);
+
+  if (priv->has_frame)
     {
-      *xborder = 0;
-      *yborder = 0;
+      GtkBorder border;
+
+      gtk_style_context_get_border (context, 0, &border);
+      tmp.top += border.top;
+      tmp.right += border.right;
+      tmp.bottom += border.bottom;
+      tmp.left += border.left;
     }
 
   if (!priv->interior_focus)
     {
-      *xborder += priv->focus_width;
-      *yborder += priv->focus_width;
+      tmp.top += priv->focus_width;
+      tmp.right += priv->focus_width;
+      tmp.bottom += priv->focus_width;
+      tmp.left += priv->focus_width;
     }
+
+  if (border_out != NULL)
+    *border_out = tmp;
 }
 
 static void
-gtk_entry_size_request (GtkWidget      *widget,
-                       GtkRequisition *requisition)
+gtk_entry_get_preferred_width (GtkWidget *widget,
+                               gint      *minimum,
+                               gint      *natural)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
   PangoFontMetrics *metrics;
-  gint xborder, yborder;
-  GtkBorder inner_border;
+  GtkBorder borders;
   PangoContext *context;
-  int icon_widths = 0;
-  int icon_width, i;
-  
-  gtk_widget_ensure_style (widget);
+  gint icon_widths = 0;
+  gint icon_width, i;
+  gint width;
+
   context = gtk_widget_get_pango_context (widget);
+
   metrics = pango_context_get_metrics (context,
-                                      widget->style->font_desc,
-                                      pango_context_get_language (context));
+                                       pango_context_get_font_description (context),
+                                       pango_context_get_language (context));
 
-  entry->ascent = pango_font_metrics_get_ascent (metrics);
-  entry->descent = pango_font_metrics_get_descent (metrics);
-  
-  _gtk_entry_get_borders (entry, &xborder, &yborder);
-  _gtk_entry_effective_inner_border (entry, &inner_border);
+  _gtk_entry_get_borders (entry, &borders);
 
-  if (entry->width_chars < 0)
-    requisition->width = MIN_ENTRY_WIDTH + xborder * 2 + inner_border.left + inner_border.right;
+  if (priv->width_chars < 0)
+    width = MIN_ENTRY_WIDTH + borders.left + borders.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 + inner_border.left + inner_border.right;
+
+      width = char_pixels * priv->width_chars + borders.left + borders.right;
     }
-    
-  requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2 + inner_border.top + inner_border.bottom;
 
   for (i = 0; i < MAX_ICONS; i++)
     {
       icon_width = get_icon_width (entry, i);
       if (icon_width > 0)
-        icon_widths += icon_width + 2 * priv->icon_margin;
+        icon_widths += icon_width;
     }
 
-  if (icon_widths > requisition->width)
-    requisition->width += icon_widths;
+  if (icon_widths > width)
+    width += icon_widths;
 
   pango_font_metrics_unref (metrics);
+
+  *minimum = width;
+  *natural = width;
 }
 
 static void
-place_windows (GtkEntry *entry)
+gtk_entry_get_preferred_height (GtkWidget *widget,
+                                gint      *minimum,
+                                gint      *natural)
 {
-  GtkWidget *widget = GTK_WIDGET (entry);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
-  gint x, y, width, height;
+  GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
+  PangoFontMetrics *metrics;
+  GtkBorder borders;
+  PangoContext *context;
+  gint height;
+  PangoLayout *layout;
+
+  layout = gtk_entry_ensure_layout (entry, TRUE);
+  context = gtk_widget_get_pango_context (widget);
+
+  metrics = pango_context_get_metrics (context,
+                                       pango_context_get_font_description (context),
+                                      pango_context_get_language (context));
+
+  priv->ascent = pango_font_metrics_get_ascent (metrics);
+  priv->descent = pango_font_metrics_get_descent (metrics);
+  pango_font_metrics_unref (metrics);
+
+  _gtk_entry_get_borders (entry, &borders);
+  pango_layout_get_pixel_size (layout, NULL, &height);
+
+  height += borders.top + borders.bottom;
+
+  *minimum = height;
+  *natural = height;
+}
+
+static void
+place_windows (GtkEntry *entry)
+{
+  GtkWidget *widget = GTK_WIDGET (entry);
+  GtkEntryPrivate *priv = entry->priv;
+  gint x, y, width, height;
+  gint frame_x, frame_y;
   GtkAllocation primary;
   GtkAllocation secondary;
   EntryIconInfo *icon_info = NULL;
 
+  get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
   get_text_area_size (entry, &x, &y, &width, &height);
   get_icon_allocations (entry, &primary, &secondary);
 
@@ -2970,6 +3361,13 @@ place_windows (GtkEntry *entry)
     x += primary.width;
   width -= primary.width + secondary.width;
 
+  x += frame_x;
+  y += frame_y;
+  primary.x += frame_x;
+  primary.y += frame_y;
+  secondary.x += frame_x;
+  secondary.y += frame_y;
+
   if ((icon_info = priv->icons[GTK_ENTRY_ICON_PRIMARY]) != NULL)
     gdk_window_move_resize (icon_info->window,
                             primary.x, primary.y,
@@ -2980,7 +3378,7 @@ place_windows (GtkEntry *entry)
                             secondary.x, secondary.y,
                             secondary.width, secondary.height);
 
-  gdk_window_move_resize (entry->text_area, x, y, width, height);
+  gdk_window_move_resize (priv->text_area, x, y, width, height);
 }
 
 static void
@@ -2990,34 +3388,39 @@ gtk_entry_get_text_area_size (GtkEntry *entry,
                              gint     *width,
                              gint     *height)
 {
+  GtkEntryPrivate *priv = entry->priv;
   GtkWidget *widget = GTK_WIDGET (entry);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
-  gint frame_height;
-  gint xborder, yborder;
+  GtkAllocation allocation;
   GtkRequisition requisition;
+  gint req_height;
+  gint frame_height;
+  GtkBorder borders;
+
+  gtk_widget_get_preferred_size (widget, &requisition, NULL);
+  req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
 
-  gtk_widget_get_child_requisition (widget, &requisition);
-  _gtk_entry_get_borders (entry, &xborder, &yborder);
+  gtk_widget_get_allocation (widget, &allocation);
+  _gtk_entry_get_borders (entry, &borders);
 
   if (gtk_widget_get_realized (widget))
-    gdk_drawable_get_size (widget->window, NULL, &frame_height);
+    get_frame_size (entry, TRUE, NULL, NULL, NULL, &frame_height);
   else
-    frame_height = requisition.height;
+    frame_height = req_height;
 
   if (gtk_widget_has_focus (widget) && !priv->interior_focus)
     frame_height -= 2 * priv->focus_width;
 
   if (x)
-    *x = xborder;
+    *x = borders.left;
 
   if (y)
-    *y = frame_height / 2 - (requisition.height - yborder * 2) / 2;
+    *y = floor ((frame_height - req_height) / 2) + borders.top;
 
   if (width)
-    *width = GTK_WIDGET (entry)->allocation.width - xborder * 2;
+    *width = allocation.width - borders.left - borders.right;
 
   if (height)
-    *height = requisition.height - yborder * 2;
+    *height = req_height - borders.top - borders.bottom;
 }
 
 static void
@@ -3039,64 +3442,77 @@ get_text_area_size (GtkEntry *entry,
 
 
 static void
-get_widget_window_size (GtkEntry *entry,
-                        gint     *x,
-                        gint     *y,
-                        gint     *width,
-                        gint     *height)
-{
+gtk_entry_get_frame_size (GtkEntry *entry,
+                          gint     *x,
+                          gint     *y,
+                          gint     *width,
+                          gint     *height)
+{
+  GtkEntryPrivate *priv = entry->priv;
+  GtkAllocation allocation;
   GtkRequisition requisition;
   GtkWidget *widget = GTK_WIDGET (entry);
-      
-  gtk_widget_get_child_requisition (widget, &requisition);
+  gint req_height;
+
+  gtk_widget_get_preferred_size (widget, &requisition, NULL);
+
+  req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom (widget);
+
+  gtk_widget_get_allocation (widget, &allocation);
 
   if (x)
-    *x = widget->allocation.x;
+    *x = allocation.x;
 
   if (y)
     {
-      if (entry->is_cell_renderer)
-       *y = widget->allocation.y;
+      if (priv->is_cell_renderer)
+        *y = 0;
       else
-       *y = widget->allocation.y + (widget->allocation.height - requisition.height) / 2;
+        *y = (allocation.height - req_height) / 2;
+
+      *y += allocation.y;
     }
 
   if (width)
-    *width = widget->allocation.width;
+    *width = allocation.width;
 
   if (height)
     {
-      if (entry->is_cell_renderer)
-       *height = widget->allocation.height;
+      if (priv->is_cell_renderer)
+        *height = allocation.height;
       else
-       *height = requisition.height;
+        *height = req_height;
     }
 }
 
-void
-_gtk_entry_effective_inner_border (GtkEntry  *entry,
-                                   GtkBorder *border)
+static void
+get_frame_size (GtkEntry *entry,
+                gboolean  relative_to_window,
+                gint     *x,
+                gint     *y,
+                gint     *width,
+                gint     *height)
 {
-  GtkBorder *tmp_border;
+  GtkEntryClass *class;
+  GtkWidget *widget = GTK_WIDGET (entry);
 
-  tmp_border = g_object_get_qdata (G_OBJECT (entry), quark_inner_border);
+  g_return_if_fail (GTK_IS_ENTRY (entry));
 
-  if (tmp_border)
-    {
-      *border = *tmp_border;
-      return;
-    }
+  class = GTK_ENTRY_GET_CLASS (entry);
 
-  gtk_widget_style_get (GTK_WIDGET (entry), "inner-border", &tmp_border, NULL);
+  if (class->get_frame_size)
+    class->get_frame_size (entry, x, y, width, height);
 
-  if (tmp_border)
+  if (!relative_to_window)
     {
-      *border = *tmp_border;
-      gtk_border_free (tmp_border);
-      return;
-    }
+      GtkAllocation allocation;
+      gtk_widget_get_allocation (widget, &allocation);
 
-  *border = default_inner_border;
+      if (x)
+        *x -= allocation.x;
+      if (y)
+        *y -= allocation.y;
+    }
 }
 
 static void
@@ -3104,88 +3520,31 @@ gtk_entry_size_allocate (GtkWidget     *widget,
                         GtkAllocation *allocation)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
-  
-  widget->allocation = *allocation;
-  
+
+  gtk_widget_set_allocation (widget, allocation);
+
   if (gtk_widget_get_realized (widget))
     {
-      /* We call gtk_widget_get_child_requisition, since we want (for
-       * backwards compatibility reasons) the realization here to
-       * be affected by the usize of the entry, if set
-       */
-      gint x, y, width, height;
       GtkEntryCompletion* completion;
 
-      get_widget_window_size (entry, &x, &y, &width, &height);
-      gdk_window_move_resize (widget->window, x, y, width, height);
-
       place_windows (entry);
       gtk_entry_recompute (entry);
 
       completion = gtk_entry_get_completion (entry);
-      if (completion && gtk_widget_get_mapped (completion->priv->popup_window))
+      if (completion)
         _gtk_entry_completion_resize_popup (completion);
     }
 }
 
-/* Kudos to the gnome-panel guys. */
-static void
-colorshift_pixbuf (GdkPixbuf *dest,
-                   GdkPixbuf *src,
-                   gint       shift)
-{
-  gint i, j;
-  gint width, height, has_alpha, src_rowstride, dest_rowstride;
-  guchar *target_pixels;
-  guchar *original_pixels;
-  guchar *pix_src;
-  guchar *pix_dest;
-  int val;
-  guchar r, g, b;
-
-  has_alpha       = gdk_pixbuf_get_has_alpha (src);
-  width           = gdk_pixbuf_get_width (src);
-  height          = gdk_pixbuf_get_height (src);
-  src_rowstride   = gdk_pixbuf_get_rowstride (src);
-  dest_rowstride  = gdk_pixbuf_get_rowstride (dest);
-  original_pixels = gdk_pixbuf_get_pixels (src);
-  target_pixels   = gdk_pixbuf_get_pixels (dest);
-
-  for (i = 0; i < height; i++)
-    {
-      pix_dest = target_pixels   + i * dest_rowstride;
-      pix_src  = original_pixels + i * src_rowstride;
-
-      for (j = 0; j < width; j++)
-        {
-          r = *(pix_src++);
-          g = *(pix_src++);
-          b = *(pix_src++);
-
-          val = r + shift;
-          *(pix_dest++) = CLAMP (val, 0, 255);
-
-          val = g + shift;
-          *(pix_dest++) = CLAMP (val, 0, 255);
-
-          val = b + shift;
-          *(pix_dest++) = CLAMP (val, 0, 255);
-
-          if (has_alpha)
-            *(pix_dest++) = *(pix_src++);
-        }
-    }
-}
-
 static gboolean
 should_prelight (GtkEntry             *entry,
                  GtkEntryIconPosition  icon_pos)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
   EntryIconInfo *icon_info = priv->icons[icon_pos];
   gboolean prelight;
 
-  if (!icon_info) 
+  if (!icon_info)
     return FALSE;
 
   if (icon_info->nonactivatable && icon_info->target_list == NULL)
@@ -3203,100 +3562,76 @@ should_prelight (GtkEntry             *entry,
 
 static void
 draw_icon (GtkWidget            *widget,
+           cairo_t              *cr,
            GtkEntryIconPosition  icon_pos)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
   EntryIconInfo *icon_info = priv->icons[icon_pos];
-  GdkPixbuf *pixbuf;
-  gint x, y, width, height;
+  gint x, y, width, height, pix_width, pix_height;
+  GtkStyleContext *context;
+  GtkBorder padding;
 
   if (!icon_info)
     return;
 
-  gtk_entry_ensure_pixbuf (entry, icon_pos);
-
-  if (icon_info->pixbuf == NULL)
-    return;
-
-  gdk_drawable_get_size (icon_info->window, &width, &height);
+  width = gdk_window_get_width (icon_info->window);
+  height = gdk_window_get_height (icon_info->window);
 
   /* size_allocate hasn't been called yet. These are the default values.
    */
   if (width == 1 || height == 1)
     return;
 
-  pixbuf = icon_info->pixbuf;
-  g_object_ref (pixbuf);
-
-  if (gdk_pixbuf_get_height (pixbuf) > height)
-    {
-      GdkPixbuf *temp_pixbuf;
-      gint scale;
-
-      scale = height - 2 * priv->icon_margin;
-      temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf, scale, scale,
-                                             GDK_INTERP_BILINEAR);
-      g_object_unref (pixbuf);
-      pixbuf = temp_pixbuf;
-    }
-
-  x = (width  - gdk_pixbuf_get_width (pixbuf)) / 2;
-  y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
-
-  if (!gtk_widget_is_sensitive (widget) ||
-      icon_info->insensitive)
-    {
-      GdkPixbuf *temp_pixbuf;
+  cairo_save (cr);
+  gtk_cairo_transform_to_window (cr, widget, icon_info->window);
 
-      temp_pixbuf = gdk_pixbuf_copy (pixbuf);
-      gdk_pixbuf_saturate_and_pixelate (pixbuf,
-                                        temp_pixbuf,
-                                        0.8f,
-                                        TRUE);
-      g_object_unref (pixbuf);
-      pixbuf = temp_pixbuf;
-    }
-  else if (icon_info->prelight)
-    {
-      GdkPixbuf *temp_pixbuf;
+  context = gtk_widget_get_style_context (widget);
+  gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
+  _gtk_icon_helper_get_size (icon_info->icon_helper, context,
+                             &pix_width, &pix_height);
+  gtk_style_context_get_padding (context, 0, &padding);
 
-      temp_pixbuf = gdk_pixbuf_copy (pixbuf);
-      colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
-      g_object_unref (pixbuf);
-      pixbuf = temp_pixbuf;
-    }
+  x = MAX (0, padding.left);
+  y = MAX (0, (height - pix_height) / 2);
 
-  gdk_draw_pixbuf (icon_info->window, widget->style->black_gc, pixbuf,
-                   0, 0, x, y, -1, -1,
-                   GDK_RGB_DITHER_NORMAL, 0, 0);
+  _gtk_icon_helper_draw (icon_info->icon_helper,
+                         context, cr,
+                         x, y);
 
-  g_object_unref (pixbuf);
+  gtk_style_context_restore (context);
+  cairo_restore (cr);
 }
 
 
 static void
-gtk_entry_draw_frame (GtkWidget      *widget,
-                      GdkEventExpose *event)
+gtk_entry_draw_frame (GtkWidget       *widget,
+                      GtkStyleContext *context,
+                      cairo_t         *cr)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
+  GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
   gint x = 0, y = 0, width, height;
-  gboolean state_hint;
-  GtkStateType state;
+  gint frame_x, frame_y;
 
-  gdk_drawable_get_size (widget->window, &width, &height);
+  cairo_save (cr);
+
+  get_frame_size (GTK_ENTRY (widget), FALSE, &frame_x, &frame_y, &width, &height);
+
+  cairo_translate (cr, frame_x, frame_y);
 
   /* Fix a problem with some themes which assume that entry->text_area's
-   * width equals widget->window's width */
+   * width equals widget->window's width
+   * http://bugzilla.gnome.org/show_bug.cgi?id=466000 */
   if (GTK_IS_SPIN_BUTTON (widget))
     {
-      gint xborder, yborder;
+      GtkBorder borders;
 
       gtk_entry_get_text_area_size (GTK_ENTRY (widget), &x, NULL, &width, NULL);
-      _gtk_entry_get_borders (GTK_ENTRY (widget), &xborder, &yborder);
+      _gtk_entry_get_borders (GTK_ENTRY (widget), &borders);
 
-      x -= xborder;
-      width += xborder * 2;
+      x -= borders.left;
+      width += borders.left + borders.right;
     }
 
   if (gtk_widget_has_focus (widget) && !priv->interior_focus)
@@ -3307,83 +3642,95 @@ gtk_entry_draw_frame (GtkWidget      *widget,
       height -= 2 * priv->focus_width;
     }
 
-  gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
-  if (state_hint)
-      state = gtk_widget_has_focus (widget) ?
-        GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
-  else
-      state = GTK_STATE_NORMAL;
-
-  gtk_paint_shadow (widget->style, widget->window,
-                    state, priv->shadow_type,
-                    &event->area, widget, "entry", x, y, width, height);
+  gtk_render_background (context, cr,
+                         x, y, width, height);
 
+  if (priv->has_frame)
+    gtk_render_frame (context, cr,
+                      x, y, width, height);
 
-  gtk_entry_draw_progress (widget, event);
+  gtk_entry_draw_progress (widget, context, cr);
 
-  if (gtk_widget_has_focus (widget) && !priv->interior_focus)
+  if (gtk_widget_has_visible_focus (widget) && !priv->interior_focus)
     {
       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_get_state (widget),
-                      &event->area, widget, "entry",
-                      0, 0, width, height);
+
+      gtk_render_focus (context, cr,
+                        0, 0, width, height);
     }
+
+  cairo_restore (cr);
 }
 
 static void
-gtk_entry_get_progress_border (GtkWidget *widget,
-                               GtkBorder *progress_border)
+gtk_entry_prepare_context_for_progress (GtkEntry *entry,
+                                        GtkStyleContext *context)
 {
-  GtkBorder *tmp_border;
+  GtkEntryPrivate *private = entry->priv;
 
-  gtk_widget_style_get (widget, "progress-border", &tmp_border, NULL);
-  if (tmp_border)
-    {
-      *progress_border = *tmp_border;
-      gtk_border_free (tmp_border);
-    }
-  else
-    {
-      progress_border->left = widget->style->xthickness;
-      progress_border->right = widget->style->xthickness;
-      progress_border->top = widget->style->ythickness;
-      progress_border->bottom = widget->style->ythickness;
-    }
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
+  if (private->progress_pulse_mode)
+    gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
 }
 
 static void
 get_progress_area (GtkWidget *widget,
-                  gint       *x,
-                  gint       *y,
-                  gint       *width,
-                  gint       *height)
+                   gint       *x,
+                   gint       *y,
+                   gint       *width,
+                   gint       *height)
 {
-  GtkEntryPrivate *private = GTK_ENTRY_GET_PRIVATE (widget);
   GtkEntry *entry = GTK_ENTRY (widget);
-  GtkBorder progress_border;
+  GtkEntryPrivate *private = entry->priv;
+  GtkStyleContext *context;
+  GtkBorder margin, border, entry_borders;
+  gint frame_width, text_area_width, text_area_height;
+
+  context = gtk_widget_get_style_context (widget);
+  _gtk_entry_get_borders (entry, &entry_borders);
+  get_text_area_size (entry,
+                      NULL, NULL,
+                      &text_area_width, &text_area_height);
+  get_frame_size (entry, FALSE,
+                  NULL, NULL,
+                  &frame_width, NULL);
 
-  gtk_entry_get_progress_border (widget, &progress_border);
+  *x = 0;
+  *y = 0;
+  *width = text_area_width + entry_borders.left + entry_borders.right;
+  *height = text_area_height + entry_borders.top + entry_borders.bottom;
 
-  *x = progress_border.left;
-  *y = progress_border.top;
+  /* if the text area got resized by a subclass, subtract the left/right
+   * border width, so that the progress bar won't extend over the resized
+   * text area.
+   */
+  if (frame_width > *width)
+    {
+      gtk_style_context_get_border (context, 0, &border);
+      if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
+        {
+          *x = (frame_width - *width) + border.left;
+          *width -= border.left;
+        }
+      else
+        {
+          *width -= border.right;
+        }
+    }
 
-  gdk_drawable_get_size (widget->window, width, height);
+  gtk_entry_prepare_context_for_progress (entry, context);
+  gtk_style_context_get_margin (context, 0, &margin);
 
-  *width -= progress_border.left + progress_border.right;
-  *height -= progress_border.top + progress_border.bottom;
+  gtk_style_context_restore (context);
 
-  if (gtk_widget_has_focus (widget) && !private->interior_focus)
-    {
-      *x += private->focus_width;
-      *y += private->focus_width;
-      *width -= 2 * private->focus_width;
-      *height -= 2 * private->focus_width;
-    }
+  *x += margin.left;
+  *y += margin.top;
+  *width -= margin.left + margin.right;
+  *height -= margin.top + margin.bottom;
 
   if (private->progress_pulse_mode)
     {
@@ -3417,106 +3764,67 @@ get_progress_area (GtkWidget *widget,
 }
 
 static void
-gtk_entry_draw_progress (GtkWidget      *widget,
-                         GdkEventExpose *event)
+gtk_entry_draw_progress (GtkWidget       *widget,
+                         GtkStyleContext *context,
+                         cairo_t         *cr)
 {
+  GtkEntry *entry = GTK_ENTRY (widget);
   gint x, y, width, height;
-  GtkStateType state;
 
   get_progress_area (widget, &x, &y, &width, &height);
 
   if ((width <= 0) || (height <= 0))
     return;
+  gtk_entry_prepare_context_for_progress (entry, context);
+  gtk_render_activity (context, cr,
+                       x, y, width, height);
 
-  if (event->window != widget->window)
-    {
-      gint pos_x, pos_y;
-
-      gdk_window_get_position (event->window, &pos_x, &pos_y);
-
-      x -= pos_x;
-      y -= pos_y;
-    }
-
-  state = GTK_STATE_SELECTED;
-  if (!gtk_widget_get_sensitive (widget))
-    state = GTK_STATE_INSENSITIVE;
-
-  gtk_paint_box (widget->style, event->window,
-                 state, GTK_SHADOW_OUT,
-                 &event->area, widget, "entry-progress",
-                 x, y,
-                 width, height);
+  gtk_style_context_restore (context);
 }
 
 static gint
-gtk_entry_expose (GtkWidget      *widget,
-                 GdkEventExpose *event)
+gtk_entry_draw (GtkWidget *widget,
+               cairo_t   *cr)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
-  gboolean state_hint;
-  GtkStateType state;
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
-
-  gtk_widget_style_get (widget, "state-hint", &state_hint, NULL);
-  if (state_hint)
-    state = gtk_widget_has_focus (widget) ?
-      GTK_STATE_ACTIVE : gtk_widget_get_state (widget);
-  else
-    state = gtk_widget_get_state(widget);
+  GtkStyleContext *context;
+  GtkEntryPrivate *priv = entry->priv;
+  int i;
 
-  if (widget->window == event->window)
-    {
-      gtk_entry_draw_frame (widget, event);
-    }
-  else if (entry->text_area == event->window)
+  if (gtk_cairo_should_draw_window (cr,
+                                    gtk_widget_get_window (widget)))
     {
-      gint width, height;
+      context = gtk_widget_get_style_context (widget);
 
-      gdk_drawable_get_size (entry->text_area, &width, &height);
+      /* Draw entry_bg, shadow, progress and focus */
+      gtk_entry_draw_frame (widget, context, cr);
 
-      gtk_paint_flat_box (widget->style, entry->text_area, 
-                         state, GTK_SHADOW_NONE,
-                         &event->area, widget, "entry_bg",
-                         0, 0, width, height);
+      /* Draw text and cursor */
+      cairo_save (cr);
 
-      gtk_entry_draw_progress (widget, event);
+      gtk_cairo_transform_to_window (cr, widget, priv->text_area);
 
-      if (entry->dnd_position != -1)
-       gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
-      
-      gtk_entry_draw_text (GTK_ENTRY (widget));
+      if (priv->dnd_position != -1)
+        gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_DND);
+
+      gtk_entry_draw_text (GTK_ENTRY (widget), cr);
 
       /* When no text is being displayed at all, don't show the cursor */
       if (gtk_entry_get_display_mode (entry) != DISPLAY_BLANK &&
-         gtk_widget_has_focus (widget) &&
-         entry->selection_bound == entry->current_pos && entry->cursor_visible) 
-        gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_STANDARD);
-    }
-  else
-    {
-      int i;
+          gtk_widget_has_focus (widget) &&
+          priv->selection_bound == priv->current_pos && priv->cursor_visible)
+        gtk_entry_draw_cursor (GTK_ENTRY (widget), cr, CURSOR_STANDARD);
+
+      cairo_restore (cr);
 
+      /* Draw icons */
       for (i = 0; i < MAX_ICONS; i++)
         {
           EntryIconInfo *icon_info = priv->icons[i];
 
-          if (icon_info != NULL && event->window == icon_info->window)
-            {
-              gint width, height;
-
-              gdk_drawable_get_size (icon_info->window, &width, &height);
-
-              gtk_paint_flat_box (widget->style, icon_info->window,
-                                  gtk_widget_get_state (widget), GTK_SHADOW_NONE,
-                                  NULL, widget, "entry_bg",
-                                  0, 0, width, height);
-
-              gtk_entry_draw_progress (widget, event);
-              draw_icon (widget, i);
-
-              break;
-            }
+          if (icon_info != NULL)
+            draw_icon (widget, cr, i);
         }
     }
 
@@ -3528,7 +3836,7 @@ gtk_entry_enter_notify (GtkWidget *widget,
                         GdkEventCrossing *event)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
   gint i;
 
   for (i = 0; i < MAX_ICONS; i++)
@@ -3555,7 +3863,7 @@ gtk_entry_leave_notify (GtkWidget        *widget,
                         GdkEventCrossing *event)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
   gint i;
 
   for (i = 0; i < MAX_ICONS; i++)
@@ -3644,19 +3952,122 @@ in_selection (GtkEntry *entry,
   g_free (ranges);
   return retval;
 }
-             
+
+static void
+gtk_entry_move_handle (GtkEntry              *entry,
+                       GtkTextHandlePosition  pos,
+                       gint                   x,
+                       gint                   y,
+                       gint                   height)
+{
+  GtkEntryPrivate *priv = entry->priv;
+
+  if (!_gtk_text_handle_get_is_dragged (priv->text_handle, pos) &&
+      (x < 0 || x > gdk_window_get_width (priv->text_area)))
+    {
+      /* Hide the handle if it's not being manipulated
+       * and fell outside of the visible text area.
+       */
+      _gtk_text_handle_set_visible (priv->text_handle, pos, FALSE);
+    }
+  else
+    {
+      GdkRectangle rect;
+
+      rect.x = CLAMP (x, 0, gdk_window_get_width (priv->text_area));
+      rect.y = y;
+      rect.width = 1;
+      rect.height = height;
+
+      _gtk_text_handle_set_visible (priv->text_handle, pos, TRUE);
+      _gtk_text_handle_set_position (priv->text_handle, pos, &rect);
+    }
+}
+
+static gint
+gtk_entry_get_selection_bound_location (GtkEntry *entry)
+{
+  GtkEntryPrivate *priv = entry->priv;
+  PangoLayout *layout;
+  PangoRectangle pos;
+  gint x;
+  const gchar *text;
+  gint index;
+
+  layout = gtk_entry_ensure_layout (entry, FALSE);
+  text = pango_layout_get_text (layout);
+  index = g_utf8_offset_to_pointer (text, priv->selection_bound) - text;
+  pango_layout_index_to_pos (layout, index, &pos);
+
+  if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
+    x = (pos.x + pos.width) / PANGO_SCALE;
+  else
+    x = pos.x / PANGO_SCALE;
+
+  return x;
+}
+
+static void
+gtk_entry_update_handles (GtkEntry          *entry,
+                          GtkTextHandleMode  mode)
+{
+  GtkEntryPrivate *priv = entry->priv;
+  gint strong_x, height;
+  gint cursor, bound;
+
+  _gtk_text_handle_set_mode (priv->text_handle, mode);
+
+  /* Wait for recomputation before repositioning */
+  if (priv->recompute_idle != 0)
+    return;
+
+  height = gdk_window_get_height (priv->text_area);
+
+  gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
+  cursor = strong_x - priv->scroll_offset;
+
+  if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
+    {
+      gint start, end;
+
+      bound = gtk_entry_get_selection_bound_location (entry) - priv->scroll_offset;
+
+      if (priv->selection_bound > priv->current_pos)
+        {
+          start = cursor;
+          end = bound;
+        }
+      else
+        {
+          start = bound;
+          end = cursor;
+        }
+
+      /* Update start selection bound */
+      gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_SELECTION_START,
+                             start, 0, height);
+      gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_SELECTION_END,
+                             end, 0, height);
+    }
+  else
+    gtk_entry_move_handle (entry, GTK_TEXT_HANDLE_POSITION_CURSOR,
+                           cursor, 0, height);
+}
+
 static gint
 gtk_entry_button_press (GtkWidget      *widget,
                        GdkEventButton *event)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
   GtkEditable *editable = GTK_EDITABLE (widget);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
   EntryIconInfo *icon_info = NULL;
   gint tmp_pos;
   gint sel_start, sel_end;
   gint i;
 
+  gtk_entry_selection_bubble_popup_unset (entry);
+
   for (i = 0; i < MAX_ICONS; i++)
     {
       icon_info = priv->icons[i];
@@ -3683,37 +4094,54 @@ gtk_entry_button_press (GtkWidget      *widget,
         }
     }
 
-  if (event->window != entry->text_area ||
-      (entry->button && event->button != entry->button))
+  if (event->window != priv->text_area ||
+      (priv->button && event->button != priv->button))
     return FALSE;
 
   gtk_entry_reset_blink_time (entry);
 
-  entry->button = event->button;
-  
+  priv->button = event->button;
+  priv->device = gdk_event_get_device ((GdkEvent *) event);
+
   if (!gtk_widget_has_focus (widget))
     {
-      entry->in_click = TRUE;
+      priv->in_click = TRUE;
       gtk_widget_grab_focus (widget);
-      entry->in_click = FALSE;
+      priv->in_click = FALSE;
     }
-  
-  tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
-    
-  if (event->button == 1)
+
+  tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
+
+  if (gdk_event_triggers_context_menu ((GdkEvent *) event))
+    {
+      gtk_entry_do_popup (entry, event);
+      priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
+      priv->device = NULL;
+
+      return TRUE;
+    }
+  else if (event->button == GDK_BUTTON_PRIMARY)
     {
       gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
-      
-      entry->select_words = FALSE;
-      entry->select_lines = FALSE;
+      gboolean is_touchscreen;
+      GdkDevice *source;
 
-      if (event->state & GDK_SHIFT_MASK)
+      source = gdk_event_get_source_device ((GdkEvent *) event);
+      is_touchscreen = test_touchscreen ||
+        gdk_device_get_source (source) == GDK_SOURCE_TOUCHSCREEN;
+
+      priv->select_words = FALSE;
+      priv->select_lines = FALSE;
+
+      if (event->state &
+          gtk_widget_get_modifier_mask (widget,
+                                        GDK_MODIFIER_INTENT_EXTEND_SELECTION))
        {
-         _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;
-         
+           sel_start = sel_end = priv->current_pos;
+
          if (tmp_pos > sel_start && tmp_pos < sel_end)
            {
              /* Truncate current selection, but keep it as big as possible */
@@ -3735,12 +4163,12 @@ gtk_entry_button_press (GtkWidget      *widget,
                  break;
                  
                case GDK_2BUTTON_PRESS:
-                 entry->select_words = TRUE;
+                 priv->select_words = TRUE;
                  gtk_entry_select_word (entry);
                  break;
                  
                case GDK_3BUTTON_PRESS:
-                 entry->select_lines = TRUE;
+                 priv->select_lines = TRUE;
                  gtk_entry_select_line (entry);
                  break;
 
@@ -3748,10 +4176,10 @@ gtk_entry_button_press (GtkWidget      *widget,
                  break;
                }
 
-             start = MIN (entry->current_pos, entry->selection_bound);
+             start = MIN (priv->current_pos, priv->selection_bound);
              start = MIN (sel_start, start);
              
-             end = MAX (entry->current_pos, entry->selection_bound);
+             end = MAX (priv->current_pos, priv->selection_bound);
              end = MAX (sel_end, end);
 
              if (tmp_pos == sel_start || tmp_pos == sel_end)
@@ -3769,37 +4197,47 @@ gtk_entry_button_press (GtkWidget      *widget,
        switch (event->type)
        {
        case GDK_BUTTON_PRESS:
-         if (in_selection (entry, event->x + entry->scroll_offset))
+         if (in_selection (entry, event->x + priv->scroll_offset))
            {
              /* Click inside the selection - we'll either start a drag, or
               * clear the selection
               */
-             entry->in_drag = TRUE;
-             entry->drag_start_x = event->x + entry->scroll_offset;
-             entry->drag_start_y = event->y;
+             priv->in_drag = TRUE;
+             priv->drag_start_x = event->x + priv->scroll_offset;
+             priv->drag_start_y = event->y;
            }
          else
-            gtk_editable_set_position (editable, tmp_pos);
+            {
+              gtk_editable_set_position (editable, tmp_pos);
+
+              if (is_touchscreen)
+                gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_CURSOR);
+            }
          break;
  
        case GDK_2BUTTON_PRESS:
          /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before 
           * receiving a GDK_2BUTTON_PRESS so we need to reset
-          * entry->in_drag which may have been set above
+           * priv->in_drag which may have been set above
            */
-         entry->in_drag = FALSE;
-         entry->select_words = TRUE;
+         priv->in_drag = FALSE;
+         priv->select_words = TRUE;
          gtk_entry_select_word (entry);
+
+          if (is_touchscreen)
+            gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_SELECTION);
          break;
        
        case GDK_3BUTTON_PRESS:
          /* We ALWAYS receive a GDK_BUTTON_PRESS immediately before
           * receiving a GDK_3BUTTON_PRESS so we need to reset
-          * entry->in_drag which may have been set above
+          * priv->in_drag which may have been set above
           */
-         entry->in_drag = FALSE;
-         entry->select_lines = TRUE;
+         priv->in_drag = FALSE;
+         priv->select_lines = TRUE;
          gtk_entry_select_line (entry);
+          if (is_touchscreen)
+            gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_SELECTION);
          break;
 
        default:
@@ -3808,9 +4246,11 @@ gtk_entry_button_press (GtkWidget      *widget,
 
       return TRUE;
     }
-  else if (event->button == 2 && event->type == GDK_BUTTON_PRESS)
+  else if (event->type == GDK_BUTTON_PRESS &&
+           event->button == GDK_BUTTON_MIDDLE &&
+           get_middle_click_paste (entry))
     {
-      if (entry->editable)
+      if (priv->editable)
         {
           priv->insert_pos = tmp_pos;
           gtk_entry_paste (entry, GDK_SELECTION_PRIMARY);
@@ -3821,13 +4261,6 @@ gtk_entry_button_press (GtkWidget      *widget,
           gtk_widget_error_bell (widget);
         }
     }
-  else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
-    {
-      gtk_entry_do_popup (entry, event);
-      entry->button = 0;       /* Don't wait for release, since the menu will gtk_grab_add */
-
-      return TRUE;
-    }
 
   return FALSE;
 }
@@ -3837,8 +4270,10 @@ gtk_entry_button_release (GtkWidget      *widget,
                          GdkEventButton *event)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
+  GtkEntryPrivate *priv = entry->priv;
   EntryIconInfo *icon_info = NULL;
+  gboolean is_touchscreen;
+  GdkDevice *source;
   gint i;
 
   for (i = 0; i < MAX_ICONS; i++)
@@ -3850,15 +4285,12 @@ gtk_entry_button_release (GtkWidget      *widget,
 
       if (event->window == icon_info->window)
         {
-          gint width, height;
-
-          gdk_drawable_get_size (icon_info->window, &width, &height);
-
           icon_info->pressed = FALSE;
 
           if (should_prelight (entry, i) &&
               event->x >= 0 && event->y >= 0 &&
-              event->x < width && event->y < height)
+              event->x < gdk_window_get_width (icon_info->window) &&
+              event->y < gdk_window_get_height (icon_info->window))
             {
               icon_info->prelight = TRUE;
               gtk_widget_queue_draw (widget);
@@ -3871,20 +4303,30 @@ gtk_entry_button_release (GtkWidget      *widget,
         }
     }
 
-  if (event->window != entry->text_area || entry->button != event->button)
+  if (event->window != priv->text_area || priv->button != event->button)
     return FALSE;
 
-  if (entry->in_drag)
+  source = gdk_event_get_source_device ((GdkEvent *) event);
+  is_touchscreen = (test_touchscreen ||
+                    gdk_device_get_source (source) == GDK_SOURCE_TOUCHSCREEN);
+
+  if (priv->in_drag)
     {
-      gint tmp_pos = gtk_entry_find_position (entry, entry->drag_start_x);
+      gint tmp_pos = gtk_entry_find_position (entry, priv->drag_start_x);
 
       gtk_editable_set_position (GTK_EDITABLE (entry), tmp_pos);
 
-      entry->in_drag = 0;
+      if (is_touchscreen)
+        gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_CURSOR);
+
+      priv->in_drag = 0;
     }
-  
-  entry->button = 0;
-  
+  else if (is_touchscreen)
+    gtk_entry_selection_bubble_popup_set (entry);
+
+  priv->button = 0;
+  priv->device = NULL;
+
   gtk_entry_update_primary_selection (entry);
              
   return TRUE;
@@ -3908,9 +4350,8 @@ gtk_entry_motion_notify (GtkWidget      *widget,
                         GdkEventMotion *event)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
   EntryIconInfo *icon_info = NULL;
-  GdkDragContext *context;
   gint tmp_pos;
   gint i;
 
@@ -3933,88 +4374,91 @@ gtk_entry_motion_notify (GtkWidget      *widget,
             {
               icon_info->in_drag = TRUE;
               icon_info->pressed = FALSE;
-              context = gtk_drag_begin (widget,
-                                        icon_info->target_list,
-                                        icon_info->actions,
-                                        1,
-                                        (GdkEvent*)event);
+              gtk_drag_begin (widget,
+                              icon_info->target_list,
+                              icon_info->actions,
+                              1,
+                              (GdkEvent*)event);
             }
 
           return TRUE;
         }
     }
 
-  if (entry->mouse_cursor_obscured)
+  if (priv->mouse_cursor_obscured)
     {
       GdkCursor *cursor;
-      
+
       cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
-      gdk_window_set_cursor (entry->text_area, cursor);
-      gdk_cursor_unref (cursor);
-      entry->mouse_cursor_obscured = FALSE;
+      gdk_window_set_cursor (priv->text_area, cursor);
+      g_object_unref (cursor);
+      priv->mouse_cursor_obscured = FALSE;
     }
 
-  if (event->window != entry->text_area || entry->button != 1)
+  if (event->window != priv->text_area || priv->button != GDK_BUTTON_PRIMARY)
     return FALSE;
 
-  if (entry->select_lines)
+  if (priv->select_lines)
     return TRUE;
 
   gdk_event_request_motions (event);
 
-  if (entry->in_drag)
+  if (priv->in_drag)
     {
       if (gtk_entry_get_display_mode (entry) == DISPLAY_NORMAL &&
           gtk_drag_check_threshold (widget,
-                                    entry->drag_start_x, entry->drag_start_y,
-                                    event->x + entry->scroll_offset, event->y))
+                                    priv->drag_start_x, priv->drag_start_y,
+                                    event->x + priv->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;
+          guint actions = priv->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY;
           gchar *text = NULL;
-          GdkPixmap *pixmap = NULL;
+          cairo_surface_t *surface;
 
           gtk_target_list_add_text_targets (target_list, 0);
 
           text = _gtk_entry_get_selected_text (entry);
-          pixmap = _gtk_text_util_create_drag_icon (widget, text, -1);
+          surface = _gtk_text_util_create_drag_icon (widget, text, -1);
 
           context = gtk_drag_begin (widget, target_list, actions,
-                                    entry->button, (GdkEvent *)event);
+                                    priv->button, (GdkEvent *)event);
           
-          if (pixmap)
-            gtk_drag_set_icon_pixmap (context,
-                                      gdk_drawable_get_colormap (pixmap),
-                                      pixmap,
-                                      NULL,
-                                      -2, -2);
+          if (surface)
+            gtk_drag_set_icon_surface (context, surface);
           else
             gtk_drag_set_icon_default (context);
           
-          if (pixmap)
-            g_object_unref (pixmap);
+          if (surface)
+            cairo_surface_destroy (surface);
           g_free (text);
 
-          entry->in_drag = FALSE;
-          entry->button = 0;
-         
+          priv->in_drag = FALSE;
+          priv->button = 0;
+          priv->device = NULL;
+
           gtk_target_list_unref (target_list);
         }
     }
   else
     {
-      gint height;
-      gdk_drawable_get_size (entry->text_area, NULL, &height);
+      GdkInputSource input_source;
+      GdkDevice *source;
+      guint length;
+
+      length = gtk_entry_buffer_get_length (get_buffer (entry));
 
       if (event->y < 0)
        tmp_pos = 0;
-      else if (event->y >= height)
-       tmp_pos = gtk_entry_buffer_get_length (get_buffer (entry));
+      else if (event->y >= gdk_window_get_height (priv->text_area))
+       tmp_pos = length;
       else
-       tmp_pos = gtk_entry_find_position (entry, event->x + entry->scroll_offset);
-      
-      if (entry->select_words) 
+       tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
+
+      source = gdk_event_get_source_device ((GdkEvent *) event);
+      input_source = gdk_device_get_source (source);
+
+      if (priv->select_words)
        {
          gint min, max;
          gint old_min, old_max;
@@ -4022,12 +4466,12 @@ gtk_entry_motion_notify (GtkWidget      *widget,
          
          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;
 
-         old_min = MIN(entry->current_pos, entry->selection_bound);
-         old_max = MAX(entry->current_pos, entry->selection_bound);
+         pos = priv->current_pos;
+         bound = priv->selection_bound;
+
+         old_min = MIN(priv->current_pos, priv->selection_bound);
+         old_max = MAX(priv->current_pos, priv->selection_bound);
          
          if (min < old_min)
            {
@@ -4041,21 +4485,28 @@ gtk_entry_motion_notify (GtkWidget      *widget,
            }
          else if (pos == old_min) 
            {
-             if (entry->current_pos != min)
+             if (priv->current_pos != min)
                pos = max;
            }
          else 
            {
-             if (entry->current_pos != max)
+             if (priv->current_pos != max)
                pos = min;
            }
-       
+
          gtk_entry_set_positions (entry, pos, bound);
        }
       else
         gtk_entry_set_positions (entry, tmp_pos, -1);
+
+      /* Update touch handles' position */
+      if (test_touchscreen || input_source == GDK_SOURCE_TOUCHSCREEN)
+        gtk_entry_update_handles (entry,
+                                  (priv->current_pos == priv->selection_bound) ?
+                                  GTK_TEXT_HANDLE_MODE_CURSOR :
+                                  GTK_TEXT_HANDLE_MODE_SELECTION);
     }
-      
+
   return TRUE;
 }
 
@@ -4065,23 +4516,25 @@ set_invisible_cursor (GdkWindow *window)
   GdkDisplay *display;
   GdkCursor *cursor;
 
-  display = gdk_drawable_get_display (window);
+  display = gdk_window_get_display (window);
   cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
 
   gdk_window_set_cursor (window, cursor);
 
-  gdk_cursor_unref (cursor);
+  g_object_unref (cursor);
 }
 
 static void
 gtk_entry_obscure_mouse_cursor (GtkEntry *entry)
 {
-  if (entry->mouse_cursor_obscured)
+  GtkEntryPrivate *priv = entry->priv;
+
+  if (priv->mouse_cursor_obscured)
     return;
 
-  set_invisible_cursor (entry->text_area);
-  
-  entry->mouse_cursor_obscured = TRUE;  
+  set_invisible_cursor (priv->text_area);
+
+  priv->mouse_cursor_obscured = TRUE;
 }
 
 static gint
@@ -4089,42 +4542,39 @@ gtk_entry_key_press (GtkWidget   *widget,
                     GdkEventKey *event)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
 
   gtk_entry_reset_blink_time (entry);
   gtk_entry_pend_cursor_blink (entry);
 
-  if (entry->editable)
+  gtk_entry_selection_bubble_popup_unset (entry);
+
+  if (!event->send_event)
+    _gtk_text_handle_set_mode (priv->text_handle,
+                               GTK_TEXT_HANDLE_MODE_NONE);
+
+  if (priv->editable)
     {
-      if (gtk_im_context_filter_keypress (entry->im_context, event))
+      if (gtk_im_context_filter_keypress (priv->im_context, event))
        {
          gtk_entry_obscure_mouse_cursor (entry);
-         entry->need_im_reset = TRUE;
+         priv->need_im_reset = TRUE;
          return TRUE;
        }
     }
 
-  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 (event->keyval == GDK_KEY_Return ||
+      event->keyval == GDK_KEY_KP_Enter ||
+      event->keyval == GDK_KEY_ISO_Enter ||
+      event->keyval == GDK_KEY_Escape)
+    gtk_entry_reset_im_context (entry);
 
   if (GTK_WIDGET_CLASS (gtk_entry_parent_class)->key_press_event (widget, event))
     /* Activate key bindings
      */
     return TRUE;
 
-  if (!entry->editable && event->length)
+  if (!priv->editable && event->length)
     gtk_widget_error_bell (widget);
 
   return FALSE;
@@ -4135,12 +4585,13 @@ gtk_entry_key_release (GtkWidget   *widget,
                       GdkEventKey *event)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
 
-  if (entry->editable)
+  if (priv->editable)
     {
-      if (gtk_im_context_filter_keypress (entry->im_context, event))
+      if (gtk_im_context_filter_keypress (priv->im_context, event))
        {
-         entry->need_im_reset = TRUE;
+         priv->need_im_reset = TRUE;
          return TRUE;
        }
     }
@@ -4153,16 +4604,17 @@ gtk_entry_focus_in (GtkWidget     *widget,
                    GdkEventFocus *event)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
   GdkKeymap *keymap;
 
   gtk_widget_queue_draw (widget);
 
   keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
 
-  if (entry->editable)
+  if (priv->editable)
     {
-      entry->need_im_reset = TRUE;
-      gtk_im_context_focus_in (entry->im_context);
+      priv->need_im_reset = TRUE;
+      gtk_im_context_focus_in (priv->im_context);
       keymap_state_changed (keymap, entry);
       g_signal_connect (keymap, "state-changed", 
                         G_CALLBACK (keymap_state_changed), entry);
@@ -4171,105 +4623,117 @@ gtk_entry_focus_in (GtkWidget     *widget,
   g_signal_connect (keymap, "direction-changed",
                    G_CALLBACK (keymap_direction_changed), entry);
 
-  gtk_entry_reset_blink_time (entry);
-  gtk_entry_check_cursor_blink (entry);
-
-  return FALSE;
-}
-
-static gint
+  if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
+      priv->placeholder_text != NULL)
+    {
+      gtk_entry_recompute (entry);
+    }
+  else
+    {
+      gtk_entry_reset_blink_time (entry);
+      gtk_entry_check_cursor_blink (entry);
+    }
+
+  return FALSE;
+}
+
+static gint
 gtk_entry_focus_out (GtkWidget     *widget,
                     GdkEventFocus *event)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
   GtkEntryCompletion *completion;
   GdkKeymap *keymap;
 
+  gtk_entry_selection_bubble_popup_unset (entry);
+  _gtk_text_handle_set_mode (priv->text_handle,
+                             GTK_TEXT_HANDLE_MODE_NONE);
+
   gtk_widget_queue_draw (widget);
 
   keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
 
-  if (entry->editable)
+  if (priv->editable)
     {
-      entry->need_im_reset = TRUE;
-      gtk_im_context_focus_out (entry->im_context);
+      priv->need_im_reset = TRUE;
+      gtk_im_context_focus_out (priv->im_context);
       remove_capslock_feedback (entry);
     }
 
-  gtk_entry_check_cursor_blink (entry);
-  
+  if (gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
+      priv->placeholder_text != NULL)
+    {
+      gtk_entry_recompute (entry);
+    }
+  else
+    {
+      gtk_entry_check_cursor_blink (entry);
+    }
+
   g_signal_handlers_disconnect_by_func (keymap, keymap_state_changed, entry);
   g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, entry);
 
   completion = gtk_entry_get_completion (entry);
   if (completion)
     _gtk_entry_completion_popdown (completion);
-  
+
   return FALSE;
 }
 
 static void
-gtk_entry_grab_focus (GtkWidget        *widget)
+gtk_entry_grab_focus (GtkWidget *widget)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
   gboolean select_on_focus;
-  
+
   GTK_WIDGET_CLASS (gtk_entry_parent_class)->grab_focus (widget);
 
-  if (entry->editable && !entry->in_click)
+  if (priv->editable && !priv->in_click)
     {
       g_object_get (gtk_widget_get_settings (widget),
                     "gtk-entry-select-on-focus",
                     &select_on_focus,
                     NULL);
-  
+
       if (select_on_focus)
         gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
     }
 }
 
-static void 
+static void
 gtk_entry_direction_changed (GtkWidget        *widget,
-                            GtkTextDirection  previous_dir)
+                             GtkTextDirection  previous_dir)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
 
   gtk_entry_recompute (entry);
-      
+
   GTK_WIDGET_CLASS (gtk_entry_parent_class)->direction_changed (widget, previous_dir);
 }
 
 static void
-gtk_entry_state_changed (GtkWidget      *widget,
-                        GtkStateType    previous_state)
+gtk_entry_state_flags_changed (GtkWidget     *widget,
+                               GtkStateFlags  previous_state)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
+  GtkEntryPrivate *priv = entry->priv;
   GdkCursor *cursor;
-  gint i;
-  
+
   if (gtk_widget_get_realized (widget))
     {
-      gdk_window_set_background (widget->window, &widget->style->base[gtk_widget_get_state (widget)]);
-      gdk_window_set_background (entry->text_area, &widget->style->base[gtk_widget_get_state (widget)]);
-      for (i = 0; i < MAX_ICONS; i++) 
-        {
-          EntryIconInfo *icon_info = priv->icons[i];
-          if (icon_info && icon_info->window)
-            gdk_window_set_background (icon_info->window, &widget->style->base[gtk_widget_get_state (widget)]);
-        }
-
       if (gtk_widget_is_sensitive (widget))
         cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget), GDK_XTERM);
-      else 
+      else
         cursor = NULL;
-      
-      gdk_window_set_cursor (entry->text_area, cursor);
+
+      gdk_window_set_cursor (priv->text_area, cursor);
 
       if (cursor)
-        gdk_cursor_unref (cursor);
+        g_object_unref (cursor);
 
-      entry->mouse_cursor_obscured = FALSE;
+      priv->mouse_cursor_obscured = FALSE;
 
       update_cursors (widget);
     }
@@ -4277,10 +4741,10 @@ gtk_entry_state_changed (GtkWidget      *widget,
   if (!gtk_widget_is_sensitive (widget))
     {
       /* Clear any selection */
-      gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);      
+      gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
     }
-  
-  gtk_widget_queue_draw (widget);
+
+  gtk_entry_update_cached_style_values (entry);
 }
 
 static void
@@ -4341,8 +4805,8 @@ gtk_entry_get_chars      (GtkEditable   *editable,
   start_pos = MIN (text_length, start_pos);
   end_pos = MIN (text_length, end_pos);
 
-  start_index = g_utf8_offset_to_pointer (text, start_pos) - entry->text;
-  end_index = g_utf8_offset_to_pointer (text, end_pos) - entry->text;
+  start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
+  end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
 
   return g_strndup (text + start_index, end_index - start_index);
 }
@@ -4352,6 +4816,7 @@ gtk_entry_real_set_position (GtkEditable *editable,
                             gint         position)
 {
   GtkEntry *entry = GTK_ENTRY (editable);
+  GtkEntryPrivate *priv = entry->priv;
 
   guint length;
 
@@ -4359,10 +4824,10 @@ gtk_entry_real_set_position (GtkEditable *editable,
   if (position < 0 || position > length)
     position = length;
 
-  if (position != entry->current_pos ||
-      position != entry->selection_bound)
+  if (position != priv->current_pos ||
+      position != priv->selection_bound)
     {
-      _gtk_entry_reset_im_context (entry);
+      gtk_entry_reset_im_context (entry);
       gtk_entry_set_positions (entry, position, position);
     }
 }
@@ -4370,7 +4835,10 @@ gtk_entry_real_set_position (GtkEditable *editable,
 static gint
 gtk_entry_get_position (GtkEditable *editable)
 {
-  return GTK_ENTRY (editable)->current_pos;
+  GtkEntry *entry = GTK_ENTRY (editable);
+  GtkEntryPrivate *priv = entry->priv;
+
+  return priv->current_pos;
 }
 
 static void
@@ -4386,8 +4854,8 @@ gtk_entry_set_selection_bounds (GtkEditable *editable,
     start = length;
   if (end < 0)
     end = length;
-  
-  _gtk_entry_reset_im_context (entry);
+
+  gtk_entry_reset_im_context (entry);
 
   gtk_entry_set_positions (entry,
                           MIN (end, length),
@@ -4402,84 +4870,66 @@ gtk_entry_get_selection_bounds (GtkEditable *editable,
                                gint        *end)
 {
   GtkEntry *entry = GTK_ENTRY (editable);
+  GtkEntryPrivate *priv = entry->priv;
 
-  *start = entry->selection_bound;
-  *end = entry->current_pos;
+  *start = priv->selection_bound;
+  *end = priv->current_pos;
 
-  return (entry->selection_bound != entry->current_pos);
+  return (priv->selection_bound != priv->current_pos);
 }
 
 static void
 icon_theme_changed (GtkEntry *entry)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
   gint i;
 
   for (i = 0; i < MAX_ICONS; i++)
     {
       EntryIconInfo *icon_info = priv->icons[i];
       if (icon_info != NULL) 
-        {
-          if (icon_info->storage_type == GTK_IMAGE_ICON_NAME)
-            gtk_entry_set_icon_from_icon_name (entry, i, icon_info->icon_name);
-          else if (icon_info->storage_type == GTK_IMAGE_STOCK)
-            gtk_entry_set_icon_from_stock (entry, i, icon_info->stock_id);
-          else if (icon_info->storage_type == GTK_IMAGE_GICON)
-            gtk_entry_set_icon_from_gicon (entry, i, icon_info->gicon);
-        }
+        _gtk_icon_helper_invalidate (icon_info->icon_helper);
     }
 
   gtk_widget_queue_draw (GTK_WIDGET (entry));
 }
 
 static void
-icon_margin_changed (GtkEntry *entry)
-{
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
-  GtkBorder border;
-
-  _gtk_entry_effective_inner_border (GTK_ENTRY (entry), &border);
-
-  priv->icon_margin = border.left;
-}
-
-static void 
-gtk_entry_style_set (GtkWidget *widget,
-                     GtkStyle  *previous_style)
+gtk_entry_update_cached_style_values (GtkEntry *entry)
 {
-  GtkEntry *entry = GTK_ENTRY (widget);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
   gint focus_width;
   gboolean interior_focus;
-  gint i;
 
-  gtk_widget_style_get (widget,
+  gtk_widget_style_get (GTK_WIDGET (entry),
                        "focus-line-width", &focus_width,
                        "interior-focus", &interior_focus,
                        NULL);
-
   priv->focus_width = focus_width;
   priv->interior_focus = interior_focus;
 
   if (!priv->invisible_char_set)
-    entry->invisible_char = find_invisible_char (GTK_WIDGET (entry));
-
-  gtk_entry_recompute (entry);
-
-  if (previous_style && gtk_widget_get_realized (widget))
     {
-      gdk_window_set_background (widget->window, &widget->style->base[gtk_widget_get_state (widget)]);
-      gdk_window_set_background (entry->text_area, &widget->style->base[gtk_widget_get_state (widget)]);
-      for (i = 0; i < MAX_ICONS; i++) 
+      gunichar ch = find_invisible_char (GTK_WIDGET (entry));
+
+      if (priv->invisible_char != ch)
         {
-          EntryIconInfo *icon_info = priv->icons[i];
-          if (icon_info && icon_info->window)
-            gdk_window_set_background (icon_info->window, &widget->style->base[gtk_widget_get_state (widget)]);
+          priv->invisible_char = ch;
+          g_object_notify (G_OBJECT (entry), "invisible-char");
         }
     }
+}
+
+static void 
+gtk_entry_style_updated (GtkWidget *widget)
+{
+  GtkEntry *entry = GTK_ENTRY (widget);
+
+  GTK_WIDGET_CLASS (gtk_entry_parent_class)->style_updated (widget);
+
+  gtk_entry_update_cached_style_values (entry);
 
   icon_theme_changed (entry);
-  icon_margin_changed (entry);
 }
 
 /* GtkCellEditable method implementations
@@ -4496,9 +4946,11 @@ gtk_cell_editable_key_press_event (GtkEntry    *entry,
                                   GdkEventKey *key_event,
                                   gpointer     data)
 {
-  if (key_event->keyval == GDK_Escape)
+  GtkEntryPrivate *priv = entry->priv;
+
+  if (key_event->keyval == GDK_KEY_Escape)
     {
-      entry->editing_canceled = TRUE;
+      priv->editing_canceled = TRUE;
       gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
       gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
 
@@ -4506,7 +4958,7 @@ gtk_cell_editable_key_press_event (GtkEntry    *entry,
     }
 
   /* override focus */
-  if (key_event->keyval == GDK_Up || key_event->keyval == GDK_Down)
+  if (key_event->keyval == GDK_KEY_Up || key_event->keyval == GDK_KEY_Down)
     {
       gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
       gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
@@ -4521,7 +4973,10 @@ static void
 gtk_entry_start_editing (GtkCellEditable *cell_editable,
                         GdkEvent        *event)
 {
-  GTK_ENTRY (cell_editable)->is_cell_renderer = TRUE;
+  GtkEntry *entry = GTK_ENTRY (cell_editable);
+  GtkEntryPrivate *priv = entry->priv;
+
+  priv->is_cell_renderer = TRUE;
 
   g_signal_connect (cell_editable, "activate",
                    G_CALLBACK (gtk_cell_editable_entry_activated), NULL);
@@ -4568,8 +5023,12 @@ gtk_entry_real_insert_text (GtkEditable *editable,
    * following signal handlers: buffer_inserted_text(), buffer_notify_display_text(),
    * buffer_notify_text(), buffer_notify_length()
    */
+  begin_change (GTK_ENTRY (editable));
+
   n_inserted = gtk_entry_buffer_insert_text (get_buffer (GTK_ENTRY (editable)), *position, new_text, n_chars);
 
+  end_change (GTK_ENTRY (editable));
+
   if (n_inserted != n_chars)
       gtk_widget_error_bell (GTK_WIDGET (editable));
 
@@ -4587,7 +5046,11 @@ gtk_entry_real_delete_text (GtkEditable *editable,
    * buffer_notify_text(), buffer_notify_length()
    */
 
+  begin_change (GTK_ENTRY (editable));
+
   gtk_entry_buffer_delete_text (get_buffer (GTK_ENTRY (editable)), start_pos, end_pos - start_pos);
+
+  end_change (GTK_ENTRY (editable));
 }
 
 /* GtkEntryBuffer signal handlers
@@ -4599,16 +5062,23 @@ buffer_inserted_text (GtkEntryBuffer *buffer,
                       guint           n_chars,
                       GtkEntry       *entry)
 {
+  GtkEntryPrivate *priv = entry->priv;
   guint password_hint_timeout;
+  guint current_pos;
+  gint selection_bound;
+
+  current_pos = priv->current_pos;
+  if (current_pos > position)
+    current_pos += n_chars;
 
-  if (entry->current_pos > position)
-    entry->current_pos += n_chars;
+  selection_bound = priv->selection_bound;
+  if (selection_bound > position)
+    selection_bound += n_chars;
 
-  if (entry->selection_bound > position)
-    entry->selection_bound += n_chars;
+  gtk_entry_set_positions (entry, current_pos, selection_bound);
 
   /* Calculate the password hint if it needs to be displayed. */
-  if (n_chars == 1 && !entry->visible)
+  if (n_chars == 1 && !priv->visible)
     {
       g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
                     "gtk-entry-password-hint-timeout", &password_hint_timeout,
@@ -4640,15 +5110,16 @@ buffer_deleted_text (GtkEntryBuffer *buffer,
                      guint           n_chars,
                      GtkEntry       *entry)
 {
+  GtkEntryPrivate *priv = entry->priv;
   guint end_pos = position + n_chars;
   gint selection_bound;
   guint current_pos;
 
-  current_pos = entry->current_pos;
+  current_pos = priv->current_pos;
   if (current_pos > position)
     current_pos -= MIN (current_pos, end_pos) - position;
 
-  selection_bound = entry->selection_bound;
+  selection_bound = priv->selection_bound;
   if (selection_bound > position)
     selection_bound -= MIN (selection_bound, end_pos) - position;
 
@@ -4658,7 +5129,7 @@ buffer_deleted_text (GtkEntryBuffer *buffer,
   gtk_entry_update_primary_selection (entry);
 
   /* Disable the password hint if one exists. */
-  if (!entry->visible)
+  if (!priv->visible)
     {
       GtkEntryPasswordHint *password_hint = g_object_get_qdata (G_OBJECT (entry),
                                                                 quark_password_hint);
@@ -4677,9 +5148,6 @@ buffer_notify_text (GtkEntryBuffer *buffer,
                     GParamSpec     *spec,
                     GtkEntry       *entry)
 {
-  /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
-  entry->text = (gchar*)gtk_entry_buffer_get_text (buffer);
-
   gtk_entry_recompute (entry);
   emit_changed (entry);
   g_object_notify (G_OBJECT (entry), "text");
@@ -4690,9 +5158,6 @@ buffer_notify_length (GtkEntryBuffer *buffer,
                       GParamSpec     *spec,
                       GtkEntry       *entry)
 {
-  /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
-  entry->text_length = gtk_entry_buffer_get_length (buffer);
-
   g_object_notify (G_OBJECT (entry), "text-length");
 }
 
@@ -4701,9 +5166,6 @@ buffer_notify_max_length (GtkEntryBuffer *buffer,
                           GParamSpec     *spec,
                           GtkEntry       *entry)
 {
-  /* COMPAT: Deprecated, not used. This struct field will be removed in GTK+ 3.x */
-  entry->text_max_length = gtk_entry_buffer_get_max_length (buffer);
-
   g_object_notify (G_OBJECT (entry), "max-length");
 }
 
@@ -4736,6 +5198,7 @@ static gint
 get_better_cursor_x (GtkEntry *entry,
                     gint      offset)
 {
+  GtkEntryPrivate *priv = entry->priv;
   GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
   PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
   gboolean split_cursor;
@@ -4755,7 +5218,7 @@ get_better_cursor_x (GtkEntry *entry,
   if (split_cursor)
     return strong_pos.x / PANGO_SCALE;
   else
-    return (keymap_direction == entry->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
+    return (keymap_direction == priv->resolved_dir) ? strong_pos.x / PANGO_SCALE : weak_pos.x / PANGO_SCALE;
 }
 
 static void
@@ -4764,12 +5227,12 @@ gtk_entry_move_cursor (GtkEntry       *entry,
                       gint            count,
                       gboolean        extend_selection)
 {
-  gint new_pos = entry->current_pos;
-  GtkEntryPrivate *priv;
+  GtkEntryPrivate *priv = entry->priv;
+  gint new_pos = priv->current_pos;
 
-  _gtk_entry_reset_im_context (entry);
+  gtk_entry_reset_im_context (entry);
 
-  if (entry->current_pos != entry->selection_bound && !extend_selection)
+  if (priv->current_pos != priv->selection_bound && !extend_selection)
     {
       /* If we have a current selection and aren't extending it, move to the
        * start/or end of the selection as appropriate
@@ -4778,26 +5241,25 @@ gtk_entry_move_cursor (GtkEntry       *entry,
        {
        case GTK_MOVEMENT_VISUAL_POSITIONS:
          {
-           gint current_x = get_better_cursor_x (entry, entry->current_pos);
-           gint bound_x = get_better_cursor_x (entry, entry->selection_bound);
+           gint current_x = get_better_cursor_x (entry, priv->current_pos);
+           gint bound_x = get_better_cursor_x (entry, priv->selection_bound);
 
            if (count <= 0)
-             new_pos = current_x < bound_x ? entry->current_pos : entry->selection_bound;
+             new_pos = current_x < bound_x ? priv->current_pos : priv->selection_bound;
            else 
-             new_pos = current_x > bound_x ? entry->current_pos : entry->selection_bound;
+             new_pos = current_x > bound_x ? priv->current_pos : priv->selection_bound;
            break;
          }
        case GTK_MOVEMENT_LOGICAL_POSITIONS:
        case GTK_MOVEMENT_WORDS:
          if (count < 0)
-           new_pos = MIN (entry->current_pos, entry->selection_bound);
+           new_pos = MIN (priv->current_pos, priv->selection_bound);
          else
-           new_pos = MAX (entry->current_pos, entry->selection_bound);
+           new_pos = MAX (priv->current_pos, priv->selection_bound);
          break;
        case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
        case GTK_MOVEMENT_PARAGRAPH_ENDS:
        case GTK_MOVEMENT_BUFFER_ENDS:
-         priv = GTK_ENTRY_GET_PRIVATE (entry);
          new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
          break;
        case GTK_MOVEMENT_DISPLAY_LINES:
@@ -4816,7 +5278,7 @@ 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 (priv->current_pos == new_pos)
             {
               if (!extend_selection)
                 {
@@ -4849,15 +5311,14 @@ gtk_entry_move_cursor (GtkEntry       *entry,
              new_pos = gtk_entry_move_backward_word (entry, new_pos, FALSE);
              count++;
            }
-          if (entry->current_pos == new_pos)
+          if (priv->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:
-         priv = GTK_ENTRY_GET_PRIVATE (entry);
          new_pos = count < 0 ? 0 : gtk_entry_buffer_get_length (get_buffer (entry));
-          if (entry->current_pos == new_pos)
+          if (priv->current_pos == new_pos)
             gtk_widget_error_bell (GTK_WIDGET (entry));
          break;
        case GTK_MOVEMENT_DISPLAY_LINES:
@@ -4869,7 +5330,7 @@ gtk_entry_move_cursor (GtkEntry       *entry,
     }
 
   if (extend_selection)
-    gtk_editable_select_region (GTK_EDITABLE (entry), entry->selection_bound, new_pos);
+    gtk_editable_select_region (GTK_EDITABLE (entry), priv->selection_bound, new_pos);
   else
     gtk_editable_set_position (GTK_EDITABLE (entry), new_pos);
   
@@ -4880,13 +5341,13 @@ static void
 gtk_entry_insert_at_cursor (GtkEntry    *entry,
                            const gchar *str)
 {
+  GtkEntryPrivate *priv = entry->priv;
   GtkEditable *editable = GTK_EDITABLE (entry);
-  gint pos = entry->current_pos;
+  gint pos = priv->current_pos;
 
-  if (entry->editable)
+  if (priv->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);
     }
@@ -4897,20 +5358,21 @@ gtk_entry_delete_from_cursor (GtkEntry       *entry,
                              GtkDeleteType   type,
                              gint            count)
 {
+  GtkEntryPrivate *priv = entry->priv;
   GtkEditable *editable = GTK_EDITABLE (entry);
-  gint start_pos = entry->current_pos;
-  gint end_pos = entry->current_pos;
+  gint start_pos = priv->current_pos;
+  gint end_pos = priv->current_pos;
   gint old_n_bytes = gtk_entry_buffer_get_bytes (get_buffer (entry));
-  
-  _gtk_entry_reset_im_context (entry);
 
-  if (!entry->editable)
+  gtk_entry_reset_im_context (entry);
+
+  if (!priv->editable)
     {
       gtk_widget_error_bell (GTK_WIDGET (entry));
       return;
     }
 
-  if (entry->selection_bound != entry->current_pos)
+  if (priv->selection_bound != priv->current_pos)
     {
       gtk_editable_delete_selection (editable);
       return;
@@ -4919,7 +5381,7 @@ gtk_entry_delete_from_cursor (GtkEntry       *entry,
   switch (type)
     {
     case GTK_DELETE_CHARS:
-      end_pos = gtk_entry_move_logically (entry, entry->current_pos, count);
+      end_pos = gtk_entry_move_logically (entry, priv->current_pos, count);
       gtk_editable_delete_text (editable, MIN (start_pos, end_pos), MAX (start_pos, end_pos));
       break;
     case GTK_DELETE_WORDS:
@@ -4953,9 +5415,9 @@ gtk_entry_delete_from_cursor (GtkEntry       *entry,
     case GTK_DELETE_DISPLAY_LINE_ENDS:
     case GTK_DELETE_PARAGRAPH_ENDS:
       if (count < 0)
-       gtk_editable_delete_text (editable, 0, entry->current_pos);
+       gtk_editable_delete_text (editable, 0, priv->current_pos);
       else
-       gtk_editable_delete_text (editable, entry->current_pos, -1);
+       gtk_editable_delete_text (editable, priv->current_pos, -1);
       break;
     case GTK_DELETE_DISPLAY_LINES:
     case GTK_DELETE_PARAGRAPHS:
@@ -4975,26 +5437,27 @@ gtk_entry_delete_from_cursor (GtkEntry       *entry,
 static void
 gtk_entry_backspace (GtkEntry *entry)
 {
+  GtkEntryPrivate *priv = entry->priv;
   GtkEditable *editable = GTK_EDITABLE (entry);
   gint prev_pos;
 
-  _gtk_entry_reset_im_context (entry);
+  gtk_entry_reset_im_context (entry);
 
-  if (!entry->editable)
+  if (!priv->editable)
     {
       gtk_widget_error_bell (GTK_WIDGET (entry));
       return;
     }
 
-  if (entry->selection_bound != entry->current_pos)
+  if (priv->selection_bound != priv->current_pos)
     {
       gtk_editable_delete_selection (editable);
       return;
     }
 
-  prev_pos = gtk_entry_move_logically (entry, entry->current_pos, -1);
+  prev_pos = gtk_entry_move_logically (entry, priv->current_pos, -1);
 
-  if (prev_pos < entry->current_pos)
+  if (prev_pos < priv->current_pos)
     {
       PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
       PangoLogAttr *log_attrs;
@@ -5003,23 +5466,23 @@ gtk_entry_backspace (GtkEntry *entry)
       pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
 
       /* Deleting parts of characters */
-      if (log_attrs[entry->current_pos].backspace_deletes_character)
+      if (log_attrs[priv->current_pos].backspace_deletes_character)
        {
          gchar *cluster_text;
          gchar *normalized_text;
           glong  len;
 
-         cluster_text = gtk_entry_get_display_text (entry, prev_pos,
-                                                    entry->current_pos);
+         cluster_text = _gtk_entry_get_display_text (entry, prev_pos,
+                                                      priv->current_pos);
          normalized_text = g_utf8_normalize (cluster_text,
                                              strlen (cluster_text),
                                              G_NORMALIZE_NFD);
           len = g_utf8_strlen (normalized_text, -1);
 
-          gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
+          gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
          if (len > 1)
            {
-             gint pos = entry->current_pos;
+             gint pos = priv->current_pos;
 
              gtk_editable_insert_text (editable, normalized_text,
                                        g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
@@ -5032,7 +5495,7 @@ gtk_entry_backspace (GtkEntry *entry)
        }
       else
        {
-          gtk_editable_delete_text (editable, prev_pos, entry->current_pos);
+          gtk_editable_delete_text (editable, prev_pos, priv->current_pos);
        }
       
       g_free (log_attrs);
@@ -5048,19 +5511,20 @@ gtk_entry_backspace (GtkEntry *entry)
 static void
 gtk_entry_copy_clipboard (GtkEntry *entry)
 {
+  GtkEntryPrivate *priv = entry->priv;
   GtkEditable *editable = GTK_EDITABLE (entry);
   gint start, end;
   gchar *str;
 
   if (gtk_editable_get_selection_bounds (editable, &start, &end))
     {
-      if (!entry->visible)
+      if (!priv->visible)
         {
           gtk_widget_error_bell (GTK_WIDGET (entry));
           return;
         }
 
-      str = gtk_entry_get_display_text (entry, start, end);
+      str = _gtk_entry_get_display_text (entry, start, end);
       gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (entry),
                                                        GDK_SELECTION_CLIPBOARD),
                              str, -1);
@@ -5071,10 +5535,11 @@ gtk_entry_copy_clipboard (GtkEntry *entry)
 static void
 gtk_entry_cut_clipboard (GtkEntry *entry)
 {
+  GtkEntryPrivate *priv = entry->priv;
   GtkEditable *editable = GTK_EDITABLE (entry);
   gint start, end;
 
-  if (!entry->visible)
+  if (!priv->visible)
     {
       gtk_widget_error_bell (GTK_WIDGET (entry));
       return;
@@ -5082,7 +5547,7 @@ gtk_entry_cut_clipboard (GtkEntry *entry)
 
   gtk_entry_copy_clipboard (entry);
 
-  if (entry->editable)
+  if (priv->editable)
     {
       if (gtk_editable_get_selection_bounds (editable, &start, &end))
        gtk_editable_delete_text (editable, start, end);
@@ -5091,13 +5556,17 @@ gtk_entry_cut_clipboard (GtkEntry *entry)
     {
       gtk_widget_error_bell (GTK_WIDGET (entry));
     }
+
+  gtk_entry_selection_bubble_popup_unset (entry);
 }
 
 static void
 gtk_entry_paste_clipboard (GtkEntry *entry)
 {
-  if (entry->editable)
-    gtk_entry_paste (entry, GDK_NONE);
+  GtkEntryPrivate *priv = entry->priv;
+
+  if (priv->editable)
+    gtk_entry_paste (entry, GDK_SELECTION_CLIPBOARD);
   else
     gtk_widget_error_bell (GTK_WIDGET (entry));
 }
@@ -5105,10 +5574,11 @@ gtk_entry_paste_clipboard (GtkEntry *entry)
 static void
 gtk_entry_delete_cb (GtkEntry *entry)
 {
+  GtkEntryPrivate *priv = entry->priv;
   GtkEditable *editable = GTK_EDITABLE (entry);
   gint start, end;
 
-  if (entry->editable)
+  if (priv->editable)
     {
       if (gtk_editable_get_selection_bounds (editable, &start, &end))
        gtk_editable_delete_text (editable, start, end);
@@ -5118,7 +5588,9 @@ gtk_entry_delete_cb (GtkEntry *entry)
 static void
 gtk_entry_toggle_overwrite (GtkEntry *entry)
 {
-  entry->overwrite_mode = !entry->overwrite_mode;
+  GtkEntryPrivate *priv = entry->priv;
+
+  priv->overwrite_mode = !priv->overwrite_mode;
   gtk_entry_pend_cursor_blink (entry);
   gtk_widget_queue_draw (GTK_WIDGET (entry));
 }
@@ -5132,24 +5604,29 @@ gtk_entry_select_all (GtkEntry *entry)
 static void
 gtk_entry_real_activate (GtkEntry *entry)
 {
+  GtkEntryPrivate *priv = entry->priv;
   GtkWindow *window;
+  GtkWidget *default_widget, *focus_widget;
   GtkWidget *toplevel;
   GtkWidget *widget;
 
   widget = GTK_WIDGET (entry);
 
-  if (entry->activates_default)
+  if (priv->activates_default)
     {
       toplevel = gtk_widget_get_toplevel (widget);
       if (GTK_IS_WINDOW (toplevel))
        {
          window = GTK_WINDOW (toplevel);
-      
-         if (window &&
-             widget != window->default_widget &&
-             !(widget == window->focus_widget &&
-               (!window->default_widget || !gtk_widget_get_sensitive (window->default_widget))))
-           gtk_window_activate_default (window);
+
+         if (window)
+            {
+              default_widget = gtk_window_get_default_widget (window);
+              focus_widget = gtk_window_get_focus (window);
+              if (widget != default_widget &&
+                  !(widget == focus_widget && (!default_widget || !gtk_widget_get_sensitive (default_widget))))
+               gtk_window_activate_default (window);
+            }
        }
     }
 }
@@ -5169,7 +5646,9 @@ gtk_entry_commit_cb (GtkIMContext *context,
                     const gchar  *str,
                     GtkEntry     *entry)
 {
-  if (entry->editable)
+  GtkEntryPrivate *priv = entry->priv;
+
+  if (priv->editable)
     gtk_entry_enter_text (entry, str);
 }
 
@@ -5177,18 +5656,20 @@ static void
 gtk_entry_preedit_changed_cb (GtkIMContext *context,
                              GtkEntry     *entry)
 {
-  if (entry->editable)
+  GtkEntryPrivate *priv = entry->priv;
+
+  if (priv->editable)
     {
       gchar *preedit_string;
       gint cursor_pos;
-      
-      gtk_im_context_get_preedit_string (entry->im_context,
+
+      gtk_im_context_get_preedit_string (priv->im_context,
                                          &preedit_string, NULL,
                                          &cursor_pos);
       g_signal_emit (entry, signals[PREEDIT_CHANGED], 0, preedit_string);
-      entry->preedit_length = strlen (preedit_string);
+      priv->preedit_length = strlen (preedit_string);
       cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
-      entry->preedit_cursor = cursor_pos;
+      priv->preedit_cursor = cursor_pos;
       g_free (preedit_string);
     
       gtk_entry_recompute (entry);
@@ -5197,14 +5678,15 @@ gtk_entry_preedit_changed_cb (GtkIMContext *context,
 
 static gboolean
 gtk_entry_retrieve_surrounding_cb (GtkIMContext *context,
-                              GtkEntry         *entry)
+                                   GtkEntry     *entry)
 {
+  GtkEntryPrivate *priv = entry->priv;
   gchar *text;
 
   /* XXXX ??? does this even make sense when text is not visible? Should we return FALSE? */
-  text = gtk_entry_get_display_text (entry, 0, -1);
+  text = _gtk_entry_get_display_text (entry, 0, -1);
   gtk_im_context_set_surrounding (context, text, strlen (text), /* Length in bytes */
-                                 g_utf8_offset_to_pointer (text, entry->current_pos) - text);
+                                 g_utf8_offset_to_pointer (text, priv->current_pos) - text);
   g_free (text);
 
   return TRUE;
@@ -5216,10 +5698,12 @@ gtk_entry_delete_surrounding_cb (GtkIMContext *slave,
                                 gint          n_chars,
                                 GtkEntry     *entry)
 {
-  if (entry->editable)
+  GtkEntryPrivate *priv = entry->priv;
+
+  if (priv->editable)
     gtk_editable_delete_text (GTK_EDITABLE (entry),
-                              entry->current_pos + offset,
-                              entry->current_pos + offset + n_chars);
+                              priv->current_pos + offset,
+                              priv->current_pos + offset + n_chars);
 
   return TRUE;
 }
@@ -5232,29 +5716,30 @@ static void
 gtk_entry_enter_text (GtkEntry       *entry,
                       const gchar    *str)
 {
+  GtkEntryPrivate *priv = entry->priv;
   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;
+  old_need_im_reset = priv->need_im_reset;
+  priv->need_im_reset = FALSE;
 
   if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
     gtk_editable_delete_selection (editable);
   else
     {
-      if (entry->overwrite_mode)
+      if (priv->overwrite_mode)
         gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
     }
 
-  tmp_pos = entry->current_pos;
+  tmp_pos = priv->current_pos;
   gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
   gtk_editable_set_position (editable, tmp_pos);
 
-  entry->need_im_reset = old_need_im_reset;
+  priv->need_im_reset = old_need_im_reset;
 }
 
-/* All changes to entry->current_pos and entry->selection_bound
+/* All changes to priv->current_pos and priv->selection_bound
  * should go through this function.
  */
 static void
@@ -5262,23 +5747,24 @@ gtk_entry_set_positions (GtkEntry *entry,
                         gint      current_pos,
                         gint      selection_bound)
 {
+  GtkEntryPrivate *priv = entry->priv;
   gboolean changed = FALSE;
 
   g_object_freeze_notify (G_OBJECT (entry));
   
   if (current_pos != -1 &&
-      entry->current_pos != current_pos)
+      priv->current_pos != current_pos)
     {
-      entry->current_pos = current_pos;
+      priv->current_pos = current_pos;
       changed = TRUE;
 
       g_object_notify (G_OBJECT (entry), "cursor-position");
     }
 
   if (selection_bound != -1 &&
-      entry->selection_bound != selection_bound)
+      priv->selection_bound != selection_bound)
     {
-      entry->selection_bound = selection_bound;
+      priv->selection_bound = selection_bound;
       changed = TRUE;
       
       g_object_notify (G_OBJECT (entry), "selection-bound");
@@ -5296,16 +5782,19 @@ gtk_entry_set_positions (GtkEntry *entry,
 static void
 gtk_entry_reset_layout (GtkEntry *entry)
 {
-  if (entry->cached_layout)
+  GtkEntryPrivate *priv = entry->priv;
+
+  if (priv->cached_layout)
     {
-      g_object_unref (entry->cached_layout);
-      entry->cached_layout = NULL;
+      g_object_unref (priv->cached_layout);
+      priv->cached_layout = NULL;
     }
 }
 
 static void
 update_im_cursor_location (GtkEntry *entry)
 {
+  GtkEntryPrivate *priv = entry->priv;
   GdkRectangle area;
   gint strong_x;
   gint strong_xoffset;
@@ -5314,7 +5803,7 @@ update_im_cursor_location (GtkEntry *entry)
   gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
   gtk_entry_get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
 
-  strong_xoffset = strong_x - entry->scroll_offset;
+  strong_xoffset = strong_x - priv->scroll_offset;
   if (strong_xoffset < 0)
     {
       strong_xoffset = 0;
@@ -5328,24 +5817,30 @@ update_im_cursor_location (GtkEntry *entry)
   area.width = 0;
   area.height = area_height;
 
-  gtk_im_context_set_cursor_location (entry->im_context, &area);
+  gtk_im_context_set_cursor_location (priv->im_context, &area);
 }
 
 static gboolean
 recompute_idle_func (gpointer data)
 {
-  GtkEntry *entry;
+  GtkEntry *entry = GTK_ENTRY (data);
+  GtkEntryPrivate *priv = entry->priv;
 
-  entry = GTK_ENTRY (data);
+  priv->recompute_idle = 0;
 
-  entry->recompute_idle = 0;
-  
   if (gtk_widget_has_screen (GTK_WIDGET (entry)))
     {
+      GtkTextHandleMode handle_mode;
+
       gtk_entry_adjust_scroll (entry);
-      gtk_entry_queue_draw (entry);
-      
+      gtk_widget_queue_draw (GTK_WIDGET (entry));
+
       update_im_cursor_location (entry);
+
+      handle_mode = _gtk_text_handle_get_mode (priv->text_handle);
+
+      if (handle_mode != GTK_TEXT_HANDLE_MODE_NONE)
+        gtk_entry_update_handles (entry, handle_mode);
     }
 
   return FALSE;
@@ -5354,23 +5849,56 @@ recompute_idle_func (gpointer data)
 static void
 gtk_entry_recompute (GtkEntry *entry)
 {
+  GtkEntryPrivate *priv = entry->priv;
+
   gtk_entry_reset_layout (entry);
   gtk_entry_check_cursor_blink (entry);
-  
-  if (!entry->recompute_idle)
+
+  if (!priv->recompute_idle)
     {
-      entry->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
+      priv->recompute_idle = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 15, /* between resize and redraw */
                                               recompute_idle_func, entry, NULL); 
     }
 }
 
+static void
+gtk_entry_get_placeholder_text_color (GtkEntry   *entry,
+                                      PangoColor *color)
+{
+  GtkWidget *widget = GTK_WIDGET (entry);
+  GtkStyleContext *context;
+  GdkRGBA fg = { 0.5, 0.5, 0.5 };
+
+  context = gtk_widget_get_style_context (widget);
+  gtk_style_context_lookup_color (context, "placeholder_text_color", &fg);
+
+  color->red = CLAMP (fg.red * 65535. + 0.5, 0, 65535);
+  color->green = CLAMP (fg.green * 65535. + 0.5, 0, 65535);
+  color->blue = CLAMP (fg.blue * 65535. + 0.5, 0, 65535);
+}
+
+static inline gboolean
+show_placeholder_text (GtkEntry *entry)
+{
+  GtkEntryPrivate *priv = entry->priv;
+
+  if (!gtk_widget_has_focus (GTK_WIDGET (entry)) &&
+      gtk_entry_buffer_get_bytes (get_buffer (entry)) == 0 &&
+      priv->placeholder_text != NULL)
+    return TRUE;
+
+  return FALSE;
+}
+
 static PangoLayout *
 gtk_entry_create_layout (GtkEntry *entry,
                         gboolean  include_preedit)
 {
+  GtkEntryPrivate *priv = entry->priv;
   GtkWidget *widget = GTK_WIDGET (entry);
-  PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL);
-  PangoAttrList *tmp_attrs = pango_attr_list_new ();
+  PangoLayout *layout;
+  PangoAttrList *tmp_attrs;
+  gboolean placeholder_layout;
 
   gchar *preedit_string = NULL;
   gint preedit_length = 0;
@@ -5379,30 +5907,43 @@ gtk_entry_create_layout (GtkEntry *entry,
   gchar *display;
   guint n_bytes;
 
+  layout = gtk_widget_create_pango_layout (widget, NULL);
   pango_layout_set_single_paragraph_mode (layout, TRUE);
 
-  display = gtk_entry_get_display_text (entry, 0, -1);
+  tmp_attrs = priv->attrs ? pango_attr_list_ref (priv->attrs)
+                          : pango_attr_list_new ();
+
+  placeholder_layout = show_placeholder_text (entry);
+  display = placeholder_layout ? g_strdup (priv->placeholder_text) : _gtk_entry_get_display_text (entry, 0, -1);
   n_bytes = strlen (display);
 
-  if (include_preedit)
+  if (!placeholder_layout && include_preedit)
     {
-      gtk_im_context_get_preedit_string (entry->im_context,
+      gtk_im_context_get_preedit_string (priv->im_context,
                                         &preedit_string, &preedit_attrs, NULL);
-      preedit_length = entry->preedit_length;
+      preedit_length = priv->preedit_length;
+    }
+  else if (placeholder_layout)
+    {
+      PangoColor color;
+      PangoAttribute *attr;
+
+      gtk_entry_get_placeholder_text_color (entry, &color);
+      attr = pango_attr_foreground_new (color.red, color.green, color.blue);
+      attr->start_index = 0;
+      attr->end_index = G_MAXINT;
+      pango_attr_list_insert (tmp_attrs, attr);
     }
 
   if (preedit_length)
     {
       GString *tmp_string = g_string_new (display);
-      gint cursor_index = g_utf8_offset_to_pointer (display, entry->current_pos) - display;
-      
+      gint cursor_index = g_utf8_offset_to_pointer (display, priv->current_pos) - display;
+
       g_string_insert (tmp_string, cursor_index, preedit_string);
-      
       pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
-      
       pango_attr_list_splice (tmp_attrs, preedit_attrs,
                              cursor_index, preedit_length);
-      
       g_string_free (tmp_string, TRUE);
     }
   else
@@ -5437,7 +5978,7 @@ gtk_entry_create_layout (GtkEntry *entry,
       pango_context_set_base_dir (gtk_widget_get_pango_context (widget),
                                  pango_dir);
 
-      entry->resolved_dir = pango_dir;
+      priv->resolved_dir = pango_dir;
 
       pango_layout_set_text (layout, display, n_bytes);
     }
@@ -5459,17 +6000,19 @@ static PangoLayout *
 gtk_entry_ensure_layout (GtkEntry *entry,
                          gboolean  include_preedit)
 {
-  if (entry->preedit_length > 0 &&
-      !include_preedit != !entry->cache_includes_preedit)
+  GtkEntryPrivate *priv = entry->priv;
+
+  if (priv->preedit_length > 0 &&
+      !include_preedit != !priv->cache_includes_preedit)
     gtk_entry_reset_layout (entry);
 
-  if (!entry->cached_layout)
+  if (!priv->cached_layout)
     {
-      entry->cached_layout = gtk_entry_create_layout (entry, include_preedit);
-      entry->cache_includes_preedit = include_preedit;
+      priv->cached_layout = gtk_entry_create_layout (entry, include_preedit);
+      priv->cache_includes_preedit = include_preedit;
     }
-  
-  return entry->cached_layout;
+
+  return priv->cached_layout;
 }
 
 static void
@@ -5477,27 +6020,25 @@ get_layout_position (GtkEntry *entry,
                      gint     *x,
                      gint     *y)
 {
+  GtkEntryPrivate *priv = entry->priv;
   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);
 
-  gtk_entry_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);
+  get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
+  area_height = PANGO_SCALE * area_height;
 
   line = pango_layout_get_lines_readonly (layout)->data;
   pango_layout_line_get_extents (line, NULL, &logical_rect);
   
   /* Align primarily for locale's ascent/descent */
-  y_pos = ((area_height - entry->ascent - entry->descent) / 2 + 
-           entry->ascent + logical_rect.y);
-  
+  y_pos = ((area_height - priv->ascent - priv->descent) / 2 +
+           priv->ascent + logical_rect.y);
+
   /* Now see if we need to adjust to fit in actual drawn string */
   if (logical_rect.height > area_height)
     y_pos = (area_height - logical_rect.height) / 2;
@@ -5506,18 +6047,21 @@ 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.top + y_pos / PANGO_SCALE;
+  y_pos = y_pos / PANGO_SCALE;
 
   if (x)
-    *x = inner_border.left - entry->scroll_offset;
+    *x = - priv->scroll_offset;
 
   if (y)
     *y = y_pos;
 }
 
 static void
-draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
+draw_text_with_color (GtkEntry *entry,
+                      cairo_t  *cr,
+                      GdkRGBA  *default_color)
 {
+  GtkEntryPrivate *priv = entry->priv;
   PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
   GtkWidget *widget;
   gint x, y;
@@ -5530,7 +6074,7 @@ draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
   get_layout_position (entry, &x, &y);
 
   cairo_move_to (cr, x, y);
-  gdk_cairo_set_source_color (cr, default_color);
+  gdk_cairo_set_source_rgba (cr, default_color);
   pango_cairo_show_layout (cr, layout);
 
   if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
@@ -5538,39 +6082,34 @@ draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
       gint *ranges;
       gint n_ranges, i;
       PangoRectangle logical_rect;
-      GdkColor *selection_color, *text_color;
-      GtkBorder inner_border;
+      GdkRGBA selection_color, text_color;
+      GtkStyleContext *context;
+      GtkStateFlags state;
 
+      context = gtk_widget_get_style_context (widget);
       pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
       gtk_entry_get_pixel_ranges (entry, &ranges, &n_ranges);
 
-      if (gtk_widget_has_focus (widget))
-        {
-          selection_color = &widget->style->base [GTK_STATE_SELECTED];
-          text_color = &widget->style->text [GTK_STATE_SELECTED];
-        }
-      else
-        {
-          selection_color = &widget->style->base [GTK_STATE_ACTIVE];
-         text_color = &widget->style->text [GTK_STATE_ACTIVE];
-        }
+      state = gtk_widget_get_state_flags (widget);
+      state |= GTK_STATE_FLAG_SELECTED;
 
-      _gtk_entry_effective_inner_border (entry, &inner_border);
+      gtk_style_context_get_background_color (context, state, &selection_color);
+      gtk_style_context_get_color (context, state, &text_color);
 
       for (i = 0; i < n_ranges; ++i)
         cairo_rectangle (cr,
-                        inner_border.left - entry->scroll_offset + ranges[2 * i],
+                         - priv->scroll_offset + ranges[2 * i],
                         y,
                         ranges[2 * i + 1],
                         logical_rect.height);
 
       cairo_clip (cr);
          
-      gdk_cairo_set_source_color (cr, selection_color);
+      gdk_cairo_set_source_rgba (cr, &selection_color);
       cairo_paint (cr);
 
       cairo_move_to (cr, x, y);
-      gdk_cairo_set_source_color (cr, text_color);
+      gdk_cairo_set_source_rgba (cr, &text_color);
       pango_cairo_show_layout (cr, layout);
   
       g_free (ranges);
@@ -5579,235 +6118,236 @@ draw_text_with_color (GtkEntry *entry, cairo_t *cr, GdkColor *default_color)
 }
 
 static void
-gtk_entry_draw_text (GtkEntry *entry)
+gtk_entry_draw_text (GtkEntry *entry,
+                     cairo_t  *cr)
 {
+  GtkEntryPrivate *priv = entry->priv;
   GtkWidget *widget = GTK_WIDGET (entry);
-  cairo_t *cr;
+  GtkStateFlags state = 0;
+  GdkRGBA text_color, bar_text_color;
+  GtkStyleContext *context;
+  gint width, height;
+  gint progress_x, progress_y, progress_width, progress_height;
+  gint clip_width, clip_height;
 
   /* Nothing to display at all */
   if (gtk_entry_get_display_mode (entry) == DISPLAY_BLANK)
     return;
-  
-  if (gtk_widget_is_drawable (widget))
-    {
-      GdkColor text_color, bar_text_color;
-      gint pos_x, pos_y;
-      gint width, height;
-      gint progress_x, progress_y, progress_width, progress_height;
-      GtkStateType state;
 
-      state = GTK_STATE_SELECTED;
-      if (!gtk_widget_get_sensitive (widget))
-        state = GTK_STATE_INSENSITIVE;
-      text_color = widget->style->text[widget->state];
-      bar_text_color = widget->style->fg[state];
+  state = gtk_widget_get_state_flags (widget);
+  context = gtk_widget_get_style_context (widget);
 
-      get_progress_area (widget,
-                         &progress_x, &progress_y,
-                         &progress_width, &progress_height);
+  gtk_style_context_get_color (context, state, &text_color);
 
-      cr = gdk_cairo_create (entry->text_area);
+  /* Get foreground color for progressbars */
+  gtk_entry_prepare_context_for_progress (entry, context);
+  gtk_style_context_get_color (context, state, &bar_text_color);
+  gtk_style_context_restore (context);
 
-      /* If the color is the same, or the progress area has a zero
-       * size, then we only need to draw once. */
-      if ((text_color.pixel == bar_text_color.pixel) ||
-          ((progress_width == 0) || (progress_height == 0)))
-        {
-          draw_text_with_color (entry, cr, &text_color);
-        }
-      else
-        {
-          gdk_drawable_get_size (entry->text_area, &width, &height);
+  get_progress_area (widget,
+                     &progress_x, &progress_y,
+                     &progress_width, &progress_height);
 
-          cairo_rectangle (cr, 0, 0, width, height);
-          cairo_clip (cr);
-          cairo_save (cr);
+  cairo_save (cr);
 
-          cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
-          cairo_rectangle (cr, 0, 0, width, height);
+  clip_width = gdk_window_get_width (priv->text_area);
+  clip_height = gdk_window_get_height (priv->text_area);
+  cairo_rectangle (cr, 0, 0, clip_width, clip_height);
+  cairo_clip (cr);
 
-          gdk_window_get_position (entry->text_area, &pos_x, &pos_y);
-          progress_x -= pos_x;
-          progress_y -= pos_y;
+  /* If the color is the same, or the progress area has a zero
+   * size, then we only need to draw once. */
+  if (gdk_rgba_equal (&text_color, &bar_text_color) ||
+      ((progress_width == 0) || (progress_height == 0)))
+    {
+      draw_text_with_color (entry, cr, &text_color);
+    }
+  else
+    {
+      int frame_x, frame_y, area_x, area_y;
 
-          cairo_rectangle (cr, progress_x, progress_y,
-                           progress_width, progress_height);
-          cairo_clip (cr);
-          cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
-      
-          draw_text_with_color (entry, cr, &text_color);
-          cairo_restore (cr);
+      width = gdk_window_get_width (priv->text_area);
+      height = gdk_window_get_height (priv->text_area);
 
-          cairo_rectangle (cr, progress_x, progress_y,
-                           progress_width, progress_height);
-          cairo_clip (cr);
+      cairo_save (cr);
 
-          draw_text_with_color (entry, cr, &bar_text_color);
-        }
+      cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
+      cairo_rectangle (cr, 0, 0, width, height);
 
-      cairo_destroy (cr);
-    }
-}
+      /* progres area is frame-relative, we need it text-area window
+       * relative */
+      get_frame_size (entry, TRUE, &frame_x, &frame_y, NULL, NULL);
+      gdk_window_get_position (priv->text_area, &area_x, &area_y);
+      progress_x += frame_x - area_x;
+      progress_y += frame_y - area_y;
 
-static void
-draw_insertion_cursor (GtkEntry      *entry,
-                      GdkRectangle  *cursor_location,
-                      gboolean       is_primary,
-                      PangoDirection direction,
-                      gboolean       draw_arrow)
-{
-  GtkWidget *widget = GTK_WIDGET (entry);
-  GtkTextDirection text_dir;
+      cairo_rectangle (cr, progress_x, progress_y,
+                       progress_width, progress_height);
+      cairo_clip (cr);
+      cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
+  
+      draw_text_with_color (entry, cr, &text_color);
+      cairo_restore (cr);
 
-  if (direction == PANGO_DIRECTION_LTR)
-    text_dir = GTK_TEXT_DIR_LTR;
-  else
-    text_dir = GTK_TEXT_DIR_RTL;
+      cairo_save (cr);
 
-  gtk_draw_insertion_cursor (widget, entry->text_area, NULL,
-                            cursor_location,
-                            is_primary, text_dir, draw_arrow);
+      cairo_rectangle (cr, progress_x, progress_y,
+                       progress_width, progress_height);
+      cairo_clip (cr);
+
+      draw_text_with_color (entry, cr, &bar_text_color);
+
+      cairo_restore (cr);
+    }
+
+  cairo_restore (cr);
 }
 
 static void
 gtk_entry_draw_cursor (GtkEntry  *entry,
+                       cairo_t   *cr,
                       CursorType type)
 {
+  GtkEntryPrivate *priv = entry->priv;
   GtkWidget *widget = GTK_WIDGET (entry);
-  GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
-  PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
-  
-  if (gtk_widget_is_drawable (widget))
-    {
-      GdkRectangle cursor_location;
-      gboolean split_cursor;
-      PangoRectangle cursor_rect;
-      GtkBorder inner_border;
-      gint xoffset;
-      gint text_area_height;
-      gint cursor_index;
-      gboolean block;
-      gboolean block_at_line_end;
-      PangoLayout *layout;
-      const char *text;
-
-      _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);
-
-      layout = gtk_entry_ensure_layout (entry, TRUE);
-      text = pango_layout_get_text (layout);
-      cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
-      if (!entry->overwrite_mode)
-        block = FALSE;
-      else
-        block = _gtk_text_util_get_block_cursor_location (layout,
-                                                          cursor_index, &cursor_rect, &block_at_line_end);
+  GtkStyleContext *context;
+  PangoRectangle cursor_rect;
+  gint cursor_index;
+  gboolean block;
+  gboolean block_at_line_end;
+  PangoLayout *layout;
+  const char *text;
+  gint x, y;
 
-      if (!block)
-        {
-          gint strong_x, weak_x;
-          PangoDirection dir1 = PANGO_DIRECTION_NEUTRAL;
-          PangoDirection dir2 = PANGO_DIRECTION_NEUTRAL;
-          gint x1 = 0;
-          gint x2 = 0;
+  context = gtk_widget_get_style_context (widget);
 
-          gtk_entry_get_cursor_locations (entry, type, &strong_x, &weak_x);
+  layout = gtk_entry_ensure_layout (entry, TRUE);
+  text = pango_layout_get_text (layout);
+  cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
+  get_layout_position (entry, &x, &y);
 
-          g_object_get (gtk_widget_get_settings (widget),
-                        "gtk-split-cursor", &split_cursor,
-                        NULL);
+  if (!priv->overwrite_mode)
+    block = FALSE;
+  else
+    block = _gtk_text_util_get_block_cursor_location (layout,
+                                                      cursor_index, &cursor_rect, &block_at_line_end);
 
-          dir1 = entry->resolved_dir;
-      
-          if (split_cursor)
-            {
-              x1 = strong_x;
+  if (!block)
+    {
+      gtk_render_insertion_cursor (context, cr,
+                                   x, y,
+                                   layout, cursor_index, priv->resolved_dir);
+    }
+  else /* overwrite_mode */
+    {
+      GdkRGBA cursor_color;
+      GdkRectangle rect;
 
-              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;
-            }
+      cairo_save (cr);
 
-          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;
+      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);
 
-          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);
-            }
-        }
-      else /* overwrite_mode */
+      _gtk_style_context_get_cursor_color (context, &cursor_color, NULL);
+      gdk_cairo_set_source_rgba (cr, &cursor_color);
+      gdk_cairo_rectangle (cr, &rect);
+      cairo_fill (cr);
+
+      if (!block_at_line_end)
         {
-          GdkColor cursor_color;
-          GdkRectangle rect;
-          cairo_t *cr;
-          gint x, y;
+          GtkStateFlags state;
+          GdkRGBA color;
+
+          state = gtk_widget_get_state_flags (widget);
+          gtk_style_context_get_background_color (context, state, &color);
 
-          get_layout_position (entry, &x, &y);
+          gdk_cairo_rectangle (cr, &rect);
+          cairo_clip (cr);
+          cairo_move_to (cr, x, y);
+          gdk_cairo_set_source_rgba (cr, &color);
+          pango_cairo_show_layout (cr, layout);
+        }
 
-          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);
+      cairo_restore (cr);
+    }
+}
 
-          cr = gdk_cairo_create (entry->text_area);
+static void
+gtk_entry_handle_dragged (GtkTextHandle         *handle,
+                          GtkTextHandlePosition  pos,
+                          gint                   x,
+                          gint                   y,
+                          GtkEntry              *entry)
+{
+  gint cursor_pos, selection_bound_pos, tmp_pos;
+  GtkEntryPrivate *priv = entry->priv;
+  GtkTextHandleMode mode;
+  gint *min, *max;
 
-          _gtk_widget_get_cursor_color (widget, &cursor_color);
-          gdk_cairo_set_source_color (cr, &cursor_color);
-          gdk_cairo_rectangle (cr, &rect);
-          cairo_fill (cr);
+  gtk_entry_selection_bubble_popup_unset (entry);
 
-          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);
-            }
+  cursor_pos = priv->current_pos;
+  selection_bound_pos = priv->selection_bound;
+  mode = _gtk_text_handle_get_mode (handle);
+  tmp_pos = gtk_entry_find_position (entry, x + priv->scroll_offset);
+
+  if (mode == GTK_TEXT_HANDLE_MODE_CURSOR ||
+      cursor_pos >= selection_bound_pos)
+    {
+      max = &cursor_pos;
+      min = &selection_bound_pos;
+    }
+  else
+    {
+      max = &selection_bound_pos;
+      min = &cursor_pos;
+    }
 
-          cairo_destroy (cr);
+  if (pos == GTK_TEXT_HANDLE_POSITION_SELECTION_END)
+    {
+      if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
+        {
+          gint min_pos;
+
+          min_pos = MAX (*min + 1, 0);
+          tmp_pos = MAX (tmp_pos, min_pos);
+        }
+
+      *max = tmp_pos;
+    }
+  else
+    {
+      if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
+        {
+          gint max_pos;
+
+          max_pos = *max - 1;
+          *min = MIN (tmp_pos, max_pos);
         }
     }
+
+  if (cursor_pos != priv->current_pos ||
+      selection_bound_pos != priv->selection_bound)
+    {
+      if (mode == GTK_TEXT_HANDLE_MODE_CURSOR)
+        gtk_entry_set_positions (entry, cursor_pos, cursor_pos);
+      else
+        gtk_entry_set_positions (entry, cursor_pos, selection_bound_pos);
+
+      gtk_entry_update_handles (entry, mode);
+    }
 }
 
 static void
-gtk_entry_queue_draw (GtkEntry *entry)
+gtk_entry_handle_drag_finished (GtkTextHandle         *handle,
+                                GtkTextHandlePosition  pos,
+                                GtkEntry              *entry)
 {
-  if (gtk_widget_is_drawable (GTK_WIDGET (entry)))
-    gdk_window_invalidate_rect (entry->text_area, NULL, FALSE);
+  gtk_entry_selection_bubble_popup_set (entry);
 }
 
-void
-_gtk_entry_reset_im_context (GtkEntry *entry)
-{
-  if (entry->need_im_reset)
-    {
-      entry->need_im_reset = FALSE;
-      gtk_im_context_reset (entry->im_context);
-    }
-}
 
 /**
  * gtk_entry_reset_im_context:
@@ -5823,15 +6363,21 @@ _gtk_entry_reset_im_context (GtkEntry *entry)
 void
 gtk_entry_reset_im_context (GtkEntry *entry)
 {
+  GtkEntryPrivate *priv = entry->priv;
+
   g_return_if_fail (GTK_IS_ENTRY (entry));
 
-  _gtk_entry_reset_im_context (entry);
+  if (priv->need_im_reset)
+    {
+      priv->need_im_reset = FALSE;
+      gtk_im_context_reset (priv->im_context);
+    }
 }
 
 /**
  * gtk_entry_im_context_filter_keypress:
  * @entry: a #GtkEntry
- * @event: the key event
+ * @event: (type Gdk.EventKey): the key event
  *
  * Allow the #GtkEntry input method to internally handle key press
  * and release events. If this function returns %TRUE, then no further
@@ -5852,16 +6398,26 @@ gboolean
 gtk_entry_im_context_filter_keypress (GtkEntry    *entry,
                                       GdkEventKey *event)
 {
+  GtkEntryPrivate *priv;
+
   g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
 
-  return gtk_im_context_filter_keypress (entry->im_context, event);
+  priv = entry->priv;
+
+  return gtk_im_context_filter_keypress (priv->im_context, event);
 }
 
+GtkIMContext*
+_gtk_entry_get_im_context (GtkEntry *entry)
+{
+  return entry->priv->im_context;
+}
 
 static gint
 gtk_entry_find_position (GtkEntry *entry,
                         gint      x)
 {
+  GtkEntryPrivate *priv = entry->priv;
   PangoLayout *layout;
   PangoLayoutLine *line;
   gint index;
@@ -5872,15 +6428,15 @@ gtk_entry_find_position (GtkEntry *entry,
   
   layout = gtk_entry_ensure_layout (entry, TRUE);
   text = pango_layout_get_text (layout);
-  cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
-  
+  cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
+
   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)
+  if (index >= cursor_index && priv->preedit_length)
     {
-      if (index >= cursor_index + entry->preedit_length)
-       index -= entry->preedit_length;
+      if (index >= cursor_index + priv->preedit_length)
+       index -= priv->preedit_length;
       else
        {
          index = cursor_index;
@@ -5900,6 +6456,7 @@ gtk_entry_get_cursor_locations (GtkEntry   *entry,
                                gint       *strong_x,
                                gint       *weak_x)
 {
+  GtkEntryPrivate *priv = entry->priv;
   DisplayMode mode = gtk_entry_get_display_mode (entry);
 
   /* Nothing to display at all, so no cursor is relevant */
@@ -5920,20 +6477,20 @@ gtk_entry_get_cursor_locations (GtkEntry   *entry,
   
       if (type == CURSOR_STANDARD)
        {
-         index = g_utf8_offset_to_pointer (text, entry->current_pos + entry->preedit_cursor) - text;
+         index = g_utf8_offset_to_pointer (text, priv->current_pos + priv->preedit_cursor) - text;
        }
       else /* type == CURSOR_DND */
        {
-         index = g_utf8_offset_to_pointer (text, entry->dnd_position) - text;
+         index = g_utf8_offset_to_pointer (text, priv->dnd_position) - text;
 
-         if (entry->dnd_position > entry->current_pos)
+         if (priv->dnd_position > priv->current_pos)
            {
              if (mode == DISPLAY_NORMAL)
-               index += entry->preedit_length;
+               index += priv->preedit_length;
              else
                {
                  gint preedit_len_chars = g_utf8_strlen (text, -1) - gtk_entry_buffer_get_length (get_buffer (entry));
-                 index += preedit_len_chars * g_unichar_to_utf8 (entry->invisible_char, NULL);
+                 index += preedit_len_chars * g_unichar_to_utf8 (priv->invisible_char, NULL);
                }
            }
        }
@@ -5948,27 +6505,42 @@ gtk_entry_get_cursor_locations (GtkEntry   *entry,
     }
 }
 
+static gboolean
+gtk_entry_get_is_selection_handle_dragged (GtkEntry *entry)
+{
+  GtkEntryPrivate *priv = entry->priv;
+  GtkTextHandlePosition pos;
+
+  if (_gtk_text_handle_get_mode (priv->text_handle) != GTK_TEXT_HANDLE_MODE_SELECTION)
+    return FALSE;
+
+  if (priv->current_pos >= priv->selection_bound)
+    pos = GTK_TEXT_HANDLE_POSITION_SELECTION_START;
+  else
+    pos = GTK_TEXT_HANDLE_POSITION_SELECTION_END;
+
+  return _gtk_text_handle_get_is_dragged (priv->text_handle, pos);
+}
+
 static void
 gtk_entry_adjust_scroll (GtkEntry *entry)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
   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;
   PangoLayout *layout;
   PangoLayoutLine *line;
   PangoRectangle logical_rect;
+  GtkTextHandleMode handle_mode;
 
   if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
     return;
 
-  _gtk_entry_effective_inner_border (entry, &inner_border);
+  text_area_width = gdk_window_get_width (priv->text_area);
 
-  gdk_drawable_get_size (entry->text_area, &text_area_width, NULL);
-  text_area_width -= inner_border.left + inner_border.right;
   if (text_area_width < 0)
     text_area_width = 0;
 
@@ -5979,7 +6551,7 @@ gtk_entry_adjust_scroll (GtkEntry *entry)
 
   /* Display as much text as we can */
 
-  if (entry->resolved_dir == PANGO_DIRECTION_LTR)
+  if (priv->resolved_dir == PANGO_DIRECTION_LTR)
       xalign = priv->xalign;
   else
       xalign = 1.0 - priv->xalign;
@@ -5997,75 +6569,97 @@ gtk_entry_adjust_scroll (GtkEntry *entry)
       max_offset = min_offset;
     }
 
-  entry->scroll_offset = CLAMP (entry->scroll_offset, min_offset, max_offset);
+  priv->scroll_offset = CLAMP (priv->scroll_offset, min_offset, max_offset);
 
-  /* And make sure cursors are on screen. Note that the cursor is
-   * actually drawn one pixel into the INNER_BORDER space on
-   * 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 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.
-   *
-   * We always make sure that the strong cursor is on screen, and
-   * put the weak cursor on screen if possible.
-   */
+  if (gtk_entry_get_is_selection_handle_dragged (entry))
+    {
+      /* The text handle corresponding to the selection bound is
+       * being dragged, ensure it stays onscreen even if we scroll
+       * cursors away, this is so both handles can cause content
+       * to scroll.
+       */
+      strong_x = weak_x = gtk_entry_get_selection_bound_location (entry);
+    }
+  else
+    {
+      /* And make sure cursors are on screen. Note that the cursor is
+       * actually drawn one pixel into the INNER_BORDER space on
+       * 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 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.
+       *
+       * We always make sure that the strong cursor is on screen, and
+       * put the weak cursor on screen if possible.
+       */
+      gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
+    }
 
-  gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, &weak_x);
-  
-  strong_xoffset = strong_x - entry->scroll_offset;
+  strong_xoffset = strong_x - priv->scroll_offset;
 
   if (strong_xoffset < 0)
     {
-      entry->scroll_offset += strong_xoffset;
+      priv->scroll_offset += strong_xoffset;
       strong_xoffset = 0;
     }
   else if (strong_xoffset > text_area_width)
     {
-      entry->scroll_offset += strong_xoffset - text_area_width;
+      priv->scroll_offset += strong_xoffset - text_area_width;
       strong_xoffset = text_area_width;
     }
 
-  weak_xoffset = weak_x - entry->scroll_offset;
+  weak_xoffset = weak_x - priv->scroll_offset;
 
   if (weak_xoffset < 0 && strong_xoffset - weak_xoffset <= text_area_width)
     {
-      entry->scroll_offset += weak_xoffset;
+      priv->scroll_offset += weak_xoffset;
     }
   else if (weak_xoffset > text_area_width &&
           strong_xoffset - (weak_xoffset - text_area_width) >= 0)
     {
-      entry->scroll_offset += weak_xoffset - text_area_width;
+      priv->scroll_offset += weak_xoffset - text_area_width;
     }
 
   g_object_notify (G_OBJECT (entry), "scroll-offset");
+
+  handle_mode = _gtk_text_handle_get_mode (priv->text_handle);
+
+  if (handle_mode != GTK_TEXT_HANDLE_MODE_NONE)
+    gtk_entry_update_handles (entry, handle_mode);
 }
 
 static void
 gtk_entry_move_adjustments (GtkEntry *entry)
 {
+  GtkWidget *widget = GTK_WIDGET (entry);
+  GtkAllocation allocation;
+  GtkAdjustment *adjustment;
   PangoContext *context;
   PangoFontMetrics *metrics;
-  gint x, layout_x, border_x, border_y;
+  GtkBorder borders;
+  gint x, layout_x;
   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_widget_get_allocation (widget, &allocation);
+
+  /* Cursor/char 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;
+  _gtk_entry_get_borders (entry, &borders);
+  x += allocation.x + layout_x + borders.left;
 
   /* 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,
+  context = gtk_widget_get_pango_context (widget);
+
+  metrics = pango_context_get_metrics (context,
+                                       pango_context_get_font_description (context),
                                       pango_context_get_language (context));
   char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
 
@@ -6080,6 +6674,7 @@ gtk_entry_move_visually (GtkEntry *entry,
                         gint      start,
                         gint      count)
 {
+  GtkEntryPrivate *priv = entry->priv;
   gint index;
   PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
   const gchar *text;
@@ -6105,7 +6700,7 @@ gtk_entry_move_visually (GtkEntry *entry,
          GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (entry)));
          PangoDirection keymap_direction = gdk_keymap_get_direction (keymap);
 
-         strong = keymap_direction == entry->resolved_dir;
+         strong = keymap_direction == priv->resolved_dir;
        }
       
       if (count > 0)
@@ -6249,6 +6844,7 @@ gtk_entry_move_backward_word (GtkEntry *entry,
 static void
 gtk_entry_delete_whitespace (GtkEntry *entry)
 {
+  GtkEntryPrivate *priv = entry->priv;
   PangoLayout *layout = gtk_entry_ensure_layout (entry, FALSE);
   PangoLogAttr *log_attrs;
   gint n_attrs;
@@ -6256,7 +6852,7 @@ gtk_entry_delete_whitespace (GtkEntry *entry)
 
   pango_layout_get_log_attrs (layout, &log_attrs, &n_attrs);
 
-  start = end = entry->current_pos;
+  start = end = priv->current_pos;
   
   while (start > 0 && log_attrs[start-1].is_white)
     start--;
@@ -6274,8 +6870,9 @@ 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, TRUE);
-  gint end_pos = gtk_entry_move_forward_word (entry, entry->current_pos, TRUE);
+  GtkEntryPrivate *priv = entry->priv;
+  gint start_pos = gtk_entry_move_backward_word (entry, priv->current_pos, TRUE);
+  gint end_pos = gtk_entry_move_forward_word (entry, priv->current_pos, TRUE);
 
   gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
 }
@@ -6305,9 +6902,9 @@ paste_received (GtkClipboard *clipboard,
 {
   GtkEntry *entry = GTK_ENTRY (data);
   GtkEditable *editable = GTK_EDITABLE (entry);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
-      
-  if (entry->button == 2)
+  GtkEntryPrivate *priv = entry->priv;
+
+  if (priv->button == GDK_BUTTON_MIDDLE)
     {
       gint pos, start, end;
       pos = priv->insert_pos;
@@ -6325,12 +6922,12 @@ paste_received (GtkClipboard *clipboard,
 
       completion = gtk_entry_get_completion (entry);
 
-      if (entry->truncate_multiline)
+      if (priv->truncate_multiline)
         length = truncate_multiline (text);
 
       /* only complete if the selection is at the end */
       popup_completion = (gtk_entry_buffer_get_length (get_buffer (entry)) ==
-                          MAX (entry->current_pos, entry->selection_bound));
+                          MAX (priv->current_pos, priv->selection_bound));
 
       if (completion)
        {
@@ -6342,14 +6939,12 @@ paste_received (GtkClipboard *clipboard,
        }
 
       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;
+      pos = priv->current_pos;
       gtk_editable_insert_text (editable, text, length, &pos);
       gtk_editable_set_position (editable, pos);
-      g_object_thaw_notify (G_OBJECT (entry));
       end_change (entry);
 
       if (completion &&
@@ -6380,7 +6975,7 @@ primary_get_cb (GtkClipboard     *clipboard,
   
   if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
     {
-      gchar *str = gtk_entry_get_display_text (entry, start, end);
+      gchar *str = _gtk_entry_get_display_text (entry, start, end);
       gtk_selection_data_set_text (selection_data, str, -1);
       g_free (str);
     }
@@ -6391,8 +6986,9 @@ primary_clear_cb (GtkClipboard *clipboard,
                  gpointer      data)
 {
   GtkEntry *entry = GTK_ENTRY (data);
+  GtkEntryPrivate *priv = entry->priv;
 
-  gtk_editable_select_region (GTK_EDITABLE (entry), entry->current_pos, entry->current_pos);
+  gtk_editable_select_region (GTK_EDITABLE (entry), priv->current_pos, priv->current_pos);
 }
 
 static void
@@ -6434,10 +7030,11 @@ static void
 gtk_entry_clear (GtkEntry             *entry,
                  GtkEntryIconPosition  icon_pos)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
   EntryIconInfo *icon_info = priv->icons[icon_pos];
+  GtkImageType storage_type;
 
-  if (!icon_info || icon_info->storage_type == GTK_IMAGE_EMPTY)
+  if (icon_info && _gtk_icon_helper_get_is_empty (icon_info->icon_helper))
     return;
 
   g_object_freeze_notify (G_OBJECT (entry));
@@ -6448,13 +7045,9 @@ gtk_entry_clear (GtkEntry             *entry,
   if (GDK_IS_WINDOW (icon_info->window))
     gdk_window_hide (icon_info->window);
 
-  if (icon_info->pixbuf)
-    {
-      g_object_unref (icon_info->pixbuf);
-      icon_info->pixbuf = NULL;
-    }
+  storage_type = _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
 
-  switch (icon_info->storage_type)
+  switch (storage_type)
     {
     case GTK_IMAGE_PIXBUF:
       g_object_notify (G_OBJECT (entry),
@@ -6462,25 +7055,16 @@ gtk_entry_clear (GtkEntry             *entry,
       break;
 
     case GTK_IMAGE_STOCK:
-      g_free (icon_info->stock_id);
-      icon_info->stock_id = NULL;
       g_object_notify (G_OBJECT (entry),
                        icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-stock" : "secondary-icon-stock");
       break;
 
     case GTK_IMAGE_ICON_NAME:
-      g_free (icon_info->icon_name);
-      icon_info->icon_name = NULL;
       g_object_notify (G_OBJECT (entry),
                        icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-name" : "secondary-icon-name");
       break;
 
     case GTK_IMAGE_GICON:
-      if (icon_info->gicon)
-        {
-          g_object_unref (icon_info->gicon);
-          icon_info->gicon = NULL;
-        }
       g_object_notify (G_OBJECT (entry),
                        icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-gicon" : "secondary-icon-gicon");
       break;
@@ -6490,125 +7074,34 @@ gtk_entry_clear (GtkEntry             *entry,
       break;
     }
 
-  icon_info->storage_type = GTK_IMAGE_EMPTY;
+  _gtk_icon_helper_clear (icon_info->icon_helper);
+
   g_object_notify (G_OBJECT (entry),
                    icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-storage-type" : "secondary-icon-storage-type");
 
   g_object_thaw_notify (G_OBJECT (entry));
 }
 
-static void
+static GdkPixbuf *
 gtk_entry_ensure_pixbuf (GtkEntry             *entry,
                          GtkEntryIconPosition  icon_pos)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
   EntryIconInfo *icon_info = priv->icons[icon_pos];
-  GtkIconInfo *info;
-  GtkIconTheme *icon_theme;
-  GtkSettings *settings;
-  GtkStateType state;
-  GtkWidget *widget;
-  GdkScreen *screen;
-  gint width, height;
-
-  if (!icon_info || icon_info->pixbuf)
-    return;
-
-  widget = GTK_WIDGET (entry);
-
-  switch (icon_info->storage_type)
-    {
-    case GTK_IMAGE_EMPTY:
-    case GTK_IMAGE_PIXBUF:
-      break;
-    case GTK_IMAGE_STOCK:
-      state = gtk_widget_get_state (widget);
-      gtk_widget_set_state (widget, GTK_STATE_NORMAL);
-      icon_info->pixbuf = gtk_widget_render_icon (widget,
-                                                  icon_info->stock_id,
-                                                  GTK_ICON_SIZE_MENU,
-                                                  NULL);
-      if (!icon_info->pixbuf)
-        icon_info->pixbuf = gtk_widget_render_icon (widget,
-                                                    GTK_STOCK_MISSING_IMAGE,
-                                                    GTK_ICON_SIZE_MENU,
-                                                    NULL);
-      gtk_widget_set_state (widget, state);
-      break;
+  GtkStyleContext *context;
+  GdkPixbuf *pix;
 
-    case GTK_IMAGE_ICON_NAME:
-      screen = gtk_widget_get_screen (widget);
-      if (screen)
-        {
-          icon_theme = gtk_icon_theme_get_for_screen (screen);
-          settings = gtk_settings_get_for_screen (screen);
-          
-          gtk_icon_size_lookup_for_settings (settings,
-                                             GTK_ICON_SIZE_MENU,
-                                             &width, &height);
-
-          icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
-                                                        icon_info->icon_name,
-                                                        MIN (width, height),
-                                                        0, NULL);
-
-          if (icon_info->pixbuf == NULL)
-            {
-              state = gtk_widget_get_state (widget);
-              gtk_widget_set_state (widget, GTK_STATE_NORMAL);
-              icon_info->pixbuf = gtk_widget_render_icon (widget,
-                                                          GTK_STOCK_MISSING_IMAGE,
-                                                          GTK_ICON_SIZE_MENU,
-                                                          NULL);
-              gtk_widget_set_state (widget, state);
-            }
-        }
-      break;
+  context = gtk_widget_get_style_context (GTK_WIDGET (entry));
+  gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
 
-    case GTK_IMAGE_GICON:
-      screen = gtk_widget_get_screen (widget);
-      if (screen)
-        {
-          icon_theme = gtk_icon_theme_get_for_screen (screen);
-          settings = gtk_settings_get_for_screen (screen);
-
-          gtk_icon_size_lookup_for_settings (settings,
-                                             GTK_ICON_SIZE_MENU,
-                                             &width, &height);
-
-          info = gtk_icon_theme_lookup_by_gicon (icon_theme,
-                                                 icon_info->gicon,
-                                                 MIN (width, height), 
-                                                 GTK_ICON_LOOKUP_USE_BUILTIN);
-          if (info)
-            {
-              icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
-              gtk_icon_info_free (info);
-            }
+  pix = _gtk_icon_helper_ensure_pixbuf (icon_info->icon_helper,
+                                        context);
 
-          if (icon_info->pixbuf == NULL)
-            {
-              state = gtk_widget_get_state (widget);
-              gtk_widget_set_state (widget, GTK_STATE_NORMAL);
-              icon_info->pixbuf = gtk_widget_render_icon (widget,
-                                                          GTK_STOCK_MISSING_IMAGE,
-                                                          GTK_ICON_SIZE_MENU,
-                                                          NULL);
-              gtk_widget_set_state (widget, state);
-            }
-        }
-      break;
+  gtk_style_context_restore (context);
 
-    default:
-      g_assert_not_reached ();
-      break;
-    }
-    
-  if (icon_info->pixbuf != NULL && icon_info->window != NULL)
-    gdk_window_show_unraised (icon_info->window);
+  return pix;
 }
 
-
 /* Public API
  */
 
@@ -6645,7 +7138,7 @@ gtk_entry_new_with_buffer (GtkEntryBuffer *buffer)
 static GtkEntryBuffer*
 get_buffer (GtkEntry *entry)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
 
   if (priv->buffer == NULL)
     {
@@ -6667,7 +7160,7 @@ get_buffer (GtkEntry *entry)
  *
  * Since: 2.18
  *
- * Returns: A #GtkEntryBuffer object.
+ * Returns: (transfer none): A #GtkEntryBuffer object.
  */
 GtkEntryBuffer*
 gtk_entry_get_buffer (GtkEntry *entry)
@@ -6695,7 +7188,8 @@ gtk_entry_set_buffer (GtkEntry       *entry,
   GObject *obj;
 
   g_return_if_fail (GTK_IS_ENTRY (entry));
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+
+  priv = entry->priv;
 
   if (buffer)
     {
@@ -6707,24 +7201,12 @@ gtk_entry_set_buffer (GtkEntry       *entry,
     {
       buffer_disconnect_signals (entry);
       g_object_unref (priv->buffer);
-
-      /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
-      entry->text = NULL;
-      entry->text_length = 0;
-      entry->text_max_length = 0;
     }
 
   priv->buffer = buffer;
 
   if (priv->buffer)
-    {
-       buffer_connect_signals (entry);
-
-      /* COMPAT: Deprecated. Not used. Setting these fields no longer necessary in GTK 3.x */
-      entry->text = (char*)gtk_entry_buffer_get_text (priv->buffer);
-      entry->text_length = gtk_entry_buffer_get_length (priv->buffer);
-      entry->text_max_length = gtk_entry_buffer_get_max_length (priv->buffer);
-    }
+     buffer_connect_signals (entry);
 
   obj = G_OBJECT (entry);
   g_object_freeze_notify (obj);
@@ -6742,28 +7224,51 @@ gtk_entry_set_buffer (GtkEntry       *entry,
 }
 
 /**
- * gtk_entry_get_text_window:
+ * gtk_entry_get_text_area:
  * @entry: a #GtkEntry
+ * @text_area: (out): Return location for the text area.
  *
- * Returns the #GdkWindow which contains the text. This function is
- * useful when drawing something to the entry in an expose-event
- * callback because it enables the callback to distinguish between
- * the text window and entry's icon windows.
+ * Gets the area where the entry's text is drawn. This function is
+ * useful when drawing something to the entry in a draw callback.
  *
- * See also gtk_entry_get_icon_window().
+ * If the entry is not realized, @text_area is filled with zeros.
  *
- * Return value: the entry's text window.
+ * See also gtk_entry_get_icon_area().
  *
- * Since: 2.20
+ * Since: 3.0
  **/
-GdkWindow *
-gtk_entry_get_text_window (GtkEntry *entry)
+void
+gtk_entry_get_text_area (GtkEntry     *entry,
+                         GdkRectangle *text_area)
 {
-  g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
+  GtkEntryPrivate *priv;
 
-  return entry->text_area;
-}
+  g_return_if_fail (GTK_IS_ENTRY (entry));
+  g_return_if_fail (text_area != NULL);
+
+  priv = entry->priv;
+
+  if (priv->text_area)
+    {
+      GtkAllocation allocation;
+      gint x, y;
 
+      gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
+      gdk_window_get_position (priv->text_area, &x, &y);
+
+      text_area->x = x - allocation.x;
+      text_area->y = y - allocation.y;
+      text_area->width = gdk_window_get_width (priv->text_area);
+      text_area->height = gdk_window_get_height (priv->text_area);
+    }
+  else
+    {
+      text_area->x = 0;
+      text_area->y = 0;
+      text_area->width = 0;
+      text_area->height = 0;
+    }
+}
 
 /**
  * gtk_entry_set_text:
@@ -6781,11 +7286,9 @@ gtk_entry_set_text (GtkEntry    *entry,
 {
   gint tmp_pos;
   GtkEntryCompletion *completion;
-  GtkEntryPrivate *priv;
 
   g_return_if_fail (GTK_IS_ENTRY (entry));
   g_return_if_fail (text != NULL);
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
 
   /* Actually setting the text will affect the cursor and selection;
    * if the contents don't actually change, this will look odd to the user.
@@ -6798,11 +7301,9 @@ gtk_entry_set_text (GtkEntry    *entry,
     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 && completion->priv->changed_id > 0)
@@ -6815,26 +7316,35 @@ gtk_entry_set_text (GtkEntry    *entry,
  * @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 
+ * 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.
  *
  * By default, GTK+ picks the best invisible character available
  * in the current font, but it can be changed with
  * gtk_entry_set_invisible_char().
+ *
+ * Note that you probably want to set #GtkEntry:input-purpose
+ * to %GTK_INPUT_PURPOSE_PASSWORD or %GTK_INPUT_PURPOSE_PIN to
+ * inform input methods about the purpose of this entry,
+ * in addition to setting visibility to %FALSE.
  */
 void
 gtk_entry_set_visibility (GtkEntry *entry,
                          gboolean visible)
 {
+  GtkEntryPrivate *priv;
+
   g_return_if_fail (GTK_IS_ENTRY (entry));
 
+  priv = entry->priv;
+
   visible = visible != FALSE;
 
-  if (entry->visible != visible)
+  if (priv->visible != visible)
     {
-      entry->visible = visible;
+      priv->visible = visible;
 
       g_object_notify (G_OBJECT (entry), "visibility");
       gtk_entry_recompute (entry);
@@ -6855,7 +7365,7 @@ gtk_entry_get_visibility (GtkEntry *entry)
 {
   g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
 
-  return entry->visible;
+  return entry->priv->visible;
 }
 
 /**
@@ -6879,7 +7389,7 @@ gtk_entry_set_invisible_char (GtkEntry *entry,
 
   g_return_if_fail (GTK_IS_ENTRY (entry));
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
 
   if (!priv->invisible_char_set)
     {
@@ -6887,10 +7397,10 @@ gtk_entry_set_invisible_char (GtkEntry *entry,
       g_object_notify (G_OBJECT (entry), "invisible-char-set");
     }
 
-  if (ch == entry->invisible_char)
+  if (ch == priv->invisible_char)
     return;
 
-  entry->invisible_char = ch;
+  priv->invisible_char = ch;
   g_object_notify (G_OBJECT (entry), "invisible-char");
   gtk_entry_recompute (entry);  
 }
@@ -6910,7 +7420,7 @@ gtk_entry_get_invisible_char (GtkEntry *entry)
 {
   g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
 
-  return entry->invisible_char;
+  return entry->priv->invisible_char;
 }
 
 /**
@@ -6931,7 +7441,7 @@ gtk_entry_unset_invisible_char (GtkEntry *entry)
 
   g_return_if_fail (GTK_IS_ENTRY (entry));
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
 
   if (!priv->invisible_char_set)
     return;
@@ -6939,9 +7449,9 @@ gtk_entry_unset_invisible_char (GtkEntry *entry)
   priv->invisible_char_set = FALSE;
   ch = find_invisible_char (GTK_WIDGET (entry));
 
-  if (entry->invisible_char != ch)
+  if (priv->invisible_char != ch)
     {
-      entry->invisible_char = ch;
+      priv->invisible_char = ch;
       g_object_notify (G_OBJECT (entry), "invisible-char");
     }
 
@@ -6962,9 +7472,11 @@ void
 gtk_entry_set_overwrite_mode (GtkEntry *entry,
                               gboolean  overwrite)
 {
+  GtkEntryPrivate *priv = entry->priv;
+
   g_return_if_fail (GTK_IS_ENTRY (entry));
-  
-  if (entry->overwrite_mode == overwrite) 
+
+  if (priv->overwrite_mode == overwrite)
     return;
   
   gtk_entry_toggle_overwrite (entry);
@@ -6987,7 +7499,7 @@ gtk_entry_get_overwrite_mode (GtkEntry *entry)
 {
   g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
 
-  return entry->overwrite_mode;
+  return entry->priv->overwrite_mode;
 }
 
 /**
@@ -7008,10 +7520,11 @@ gtk_entry_get_overwrite_mode (GtkEntry *entry)
  *      storage in the widget and must not be freed, modified or
  *      stored.
  **/
-G_CONST_RETURN gchar*
+const gchar*
 gtk_entry_get_text (GtkEntry *entry)
 {
   g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
+
   return gtk_entry_buffer_get_text (get_buffer (entry));
 }
 
@@ -7060,6 +7573,7 @@ gint
 gtk_entry_get_max_length (GtkEntry *entry)
 {
   g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
+
   return gtk_entry_buffer_get_max_length (get_buffer (entry));
 }
 
@@ -7085,6 +7599,7 @@ guint16
 gtk_entry_get_text_length (GtkEntry *entry)
 {
   g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
+
   return gtk_entry_buffer_get_length (get_buffer (entry));
 }
 
@@ -7100,18 +7615,23 @@ gtk_entry_get_text_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 #GtkWidget::activate signal.)
+ * the default handler for the #GtkEntry::activate signal.)
  **/
 void
 gtk_entry_set_activates_default (GtkEntry *entry,
                                  gboolean  setting)
 {
+  GtkEntryPrivate *priv;
+
   g_return_if_fail (GTK_IS_ENTRY (entry));
+
+  priv = entry->priv;
+
   setting = setting != FALSE;
 
-  if (setting != entry->activates_default)
+  if (setting != priv->activates_default)
     {
-      entry->activates_default = setting;
+      priv->activates_default = setting;
       g_object_notify (G_OBJECT (entry), "activates-default");
     }
 }
@@ -7129,7 +7649,7 @@ gtk_entry_get_activates_default (GtkEntry *entry)
 {
   g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
 
-  return entry->activates_default;
+  return entry->priv->activates_default;
 }
 
 /**
@@ -7147,11 +7667,15 @@ void
 gtk_entry_set_width_chars (GtkEntry *entry,
                            gint      n_chars)
 {
+  GtkEntryPrivate *priv;
+
   g_return_if_fail (GTK_IS_ENTRY (entry));
 
-  if (entry->width_chars != n_chars)
+  priv = entry->priv;
+
+  if (priv->width_chars != n_chars)
     {
-      entry->width_chars = n_chars;
+      priv->width_chars = n_chars;
       g_object_notify (G_OBJECT (entry), "width-chars");
       gtk_widget_queue_resize (GTK_WIDGET (entry));
     }
@@ -7170,7 +7694,7 @@ gtk_entry_get_width_chars (GtkEntry *entry)
 {
   g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
 
-  return entry->width_chars;
+  return entry->priv->width_chars;
 }
 
 /**
@@ -7184,15 +7708,19 @@ void
 gtk_entry_set_has_frame (GtkEntry *entry,
                          gboolean  setting)
 {
+  GtkEntryPrivate *priv;
+
   g_return_if_fail (GTK_IS_ENTRY (entry));
 
+  priv = entry->priv;
+
   setting = (setting != FALSE);
 
-  if (entry->has_frame == setting)
+  if (priv->has_frame == setting)
     return;
 
   gtk_widget_queue_resize (GTK_WIDGET (entry));
-  entry->has_frame = setting;
+  priv->has_frame = setting;
   g_object_notify (G_OBJECT (entry), "has-frame");
 }
 
@@ -7209,7 +7737,7 @@ gtk_entry_get_has_frame (GtkEntry *entry)
 {
   g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
 
-  return entry->has_frame;
+  return entry->priv->has_frame;
 }
 
 /**
@@ -7227,6 +7755,10 @@ gtk_entry_get_has_frame (GtkEntry *entry)
  * pixel-exact positioning of the entry is important.
  *
  * Since: 2.10
+ *
+ * Deprecated: 3.4: Use the standard border and padding CSS properties (through
+ *   objects like #GtkStyleContext and #GtkCssProvider); the value set with
+ *   this function is ignored by #GtkEntry.
  **/
 void
 gtk_entry_set_inner_border (GtkEntry        *entry,
@@ -7234,16 +7766,7 @@ gtk_entry_set_inner_border (GtkEntry        *entry,
 {
   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_do_set_inner_border (entry, border);
 }
 
 /**
@@ -7256,13 +7779,17 @@ gtk_entry_set_inner_border (GtkEntry        *entry,
  * Return value: (transfer none): the entry's #GtkBorder, or %NULL if none was set.
  *
  * Since: 2.10
+ *
+ * Deprecated: 3.4: Use the standard border and padding CSS properties (through
+ *   objects like #GtkStyleContext and #GtkCssProvider); the value returned by
+ *   this function is ignored by #GtkEntry.
  **/
-G_CONST_RETURN GtkBorder *
+const 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);
+  return gtk_entry_do_get_inner_border (entry);
 }
 
 /**
@@ -7311,20 +7838,23 @@ gint
 gtk_entry_layout_index_to_text_index (GtkEntry *entry,
                                       gint      layout_index)
 {
+  GtkEntryPrivate *priv;
   PangoLayout *layout;
   const gchar *text;
   gint cursor_index;
   
   g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
 
+  priv = entry->priv;
+
   layout = gtk_entry_ensure_layout (entry, TRUE);
   text = pango_layout_get_text (layout);
-  cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
-  
-  if (layout_index >= cursor_index && entry->preedit_length)
+  cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
+
+  if (layout_index >= cursor_index && priv->preedit_length)
     {
-      if (layout_index >= cursor_index + entry->preedit_length)
-       layout_index -= entry->preedit_length;
+      if (layout_index >= cursor_index + priv->preedit_length)
+       layout_index -= priv->preedit_length;
       else
         layout_index = cursor_index;
     }
@@ -7347,17 +7877,21 @@ gint
 gtk_entry_text_index_to_layout_index (GtkEntry *entry,
                                       gint      text_index)
 {
+  GtkEntryPrivate *priv;
   PangoLayout *layout;
   const gchar *text;
   gint cursor_index;
+
   g_return_val_if_fail (GTK_IS_ENTRY (entry), 0);
 
+  priv = entry->priv;
+
   layout = gtk_entry_ensure_layout (entry, TRUE);
   text = pango_layout_get_text (layout);
-  cursor_index = g_utf8_offset_to_pointer (text, entry->current_pos) - text;
-  
+  cursor_index = g_utf8_offset_to_pointer (text, priv->current_pos) - text;
+
   if (text_index > cursor_index)
-    text_index += entry->preedit_length;
+    text_index += priv->preedit_length;
 
   return text_index;
 }
@@ -7365,8 +7899,8 @@ gtk_entry_text_index_to_layout_index (GtkEntry *entry,
 /**
  * gtk_entry_get_layout_offsets:
  * @entry: a #GtkEntry
- * @x: (allow-none): location to store X offset of layout, or %NULL
- * @y: (allow-none): location to store Y offset of layout, or %NULL
+ * @x: (out) (allow-none): location to store X offset of layout, or %NULL
+ * @y: (out) (allow-none): location to store Y offset of layout, or %NULL
  *
  *
  * Obtains the position of the #PangoLayout used to render text
@@ -7428,10 +7962,10 @@ void
 gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
 {
   GtkEntryPrivate *priv;
-  
+
   g_return_if_fail (GTK_IS_ENTRY (entry));
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
 
   if (xalign < 0.0)
     xalign = 0.0;
@@ -7461,13 +7995,9 @@ gtk_entry_set_alignment (GtkEntry *entry, gfloat xalign)
 gfloat
 gtk_entry_get_alignment (GtkEntry *entry)
 {
-  GtkEntryPrivate *priv;
-  
   g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
-
-  return priv->xalign;
+  return entry->priv->xalign;
 }
 
 /**
@@ -7493,7 +8023,7 @@ gtk_entry_set_icon_from_pixbuf (GtkEntry             *entry,
   g_return_if_fail (GTK_IS_ENTRY (entry));
   g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
 
   if ((icon_info = priv->icons[icon_pos]) == NULL)
     icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
@@ -7507,8 +8037,9 @@ gtk_entry_set_icon_from_pixbuf (GtkEntry             *entry,
 
   if (pixbuf)
     {
-      icon_info->storage_type = GTK_IMAGE_PIXBUF;
-      icon_info->pixbuf = pixbuf;
+      _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
+      _gtk_icon_helper_set_icon_size (icon_info->icon_helper,
+                                      GTK_ICON_SIZE_MENU);
 
       if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
         {
@@ -7523,9 +8054,9 @@ gtk_entry_set_icon_from_pixbuf (GtkEntry             *entry,
 
       if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
           gdk_window_show_unraised (icon_info->window);
-    }
 
-  gtk_entry_ensure_pixbuf (entry, icon_pos);
+      g_object_unref (pixbuf);
+    }
   
   if (gtk_widget_get_visible (GTK_WIDGET (entry)))
     gtk_widget_queue_resize (GTK_WIDGET (entry));
@@ -7558,15 +8089,13 @@ gtk_entry_set_icon_from_stock (GtkEntry             *entry,
   g_return_if_fail (GTK_IS_ENTRY (entry));
   g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
 
   if ((icon_info = priv->icons[icon_pos]) == NULL)
     icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
 
   g_object_freeze_notify (G_OBJECT (entry));
 
-  gtk_widget_ensure_style (GTK_WIDGET (entry));
-
   /* need to dup before clearing */
   new_id = g_strdup (stock_id);
 
@@ -7574,8 +8103,7 @@ gtk_entry_set_icon_from_stock (GtkEntry             *entry,
 
   if (new_id != NULL)
     {
-      icon_info->storage_type = GTK_IMAGE_STOCK;
-      icon_info->stock_id = new_id;
+      _gtk_icon_helper_set_stock_id (icon_info->icon_helper, new_id, GTK_ICON_SIZE_MENU);
 
       if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
         {
@@ -7590,9 +8118,9 @@ gtk_entry_set_icon_from_stock (GtkEntry             *entry,
 
       if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
           gdk_window_show_unraised (icon_info->window);
-    }
 
-  gtk_entry_ensure_pixbuf (entry, icon_pos);
+      g_free (new_id);
+    }
 
   if (gtk_widget_get_visible (GTK_WIDGET (entry)))
     gtk_widget_queue_resize (GTK_WIDGET (entry));
@@ -7628,15 +8156,13 @@ gtk_entry_set_icon_from_icon_name (GtkEntry             *entry,
   g_return_if_fail (GTK_IS_ENTRY (entry));
   g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
 
   if ((icon_info = priv->icons[icon_pos]) == NULL)
     icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
 
   g_object_freeze_notify (G_OBJECT (entry));
 
-  gtk_widget_ensure_style (GTK_WIDGET (entry));
-
   /* need to dup before clearing */
   new_name = g_strdup (icon_name);
 
@@ -7644,8 +8170,7 @@ gtk_entry_set_icon_from_icon_name (GtkEntry             *entry,
 
   if (new_name != NULL)
     {
-      icon_info->storage_type = GTK_IMAGE_ICON_NAME;
-      icon_info->icon_name = new_name;
+      _gtk_icon_helper_set_icon_name (icon_info->icon_helper, new_name, GTK_ICON_SIZE_MENU);
 
       if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
         {
@@ -7660,9 +8185,9 @@ gtk_entry_set_icon_from_icon_name (GtkEntry             *entry,
 
       if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
           gdk_window_show_unraised (icon_info->window);
-    }
 
-  gtk_entry_ensure_pixbuf (entry, icon_pos);
+      g_free (new_name);
+    }
 
   if (gtk_widget_get_visible (GTK_WIDGET (entry)))
     gtk_widget_queue_resize (GTK_WIDGET (entry));
@@ -7696,7 +8221,7 @@ gtk_entry_set_icon_from_gicon (GtkEntry             *entry,
   g_return_if_fail (GTK_IS_ENTRY (entry));
   g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
 
   if ((icon_info = priv->icons[icon_pos]) == NULL)
     icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
@@ -7711,8 +8236,7 @@ gtk_entry_set_icon_from_gicon (GtkEntry             *entry,
 
   if (icon)
     {
-      icon_info->storage_type = GTK_IMAGE_GICON;
-      icon_info->gicon = icon;
+      _gtk_icon_helper_set_gicon (icon_info->icon_helper, icon, GTK_ICON_SIZE_MENU);
 
       if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
         {
@@ -7727,9 +8251,9 @@ gtk_entry_set_icon_from_gicon (GtkEntry             *entry,
 
       if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
           gdk_window_show_unraised (icon_info->window);
-    }
 
-  gtk_entry_ensure_pixbuf (entry, icon_pos);
+      g_object_unref (icon);
+    }
 
   if (gtk_widget_get_visible (GTK_WIDGET (entry)))
     gtk_widget_queue_resize (GTK_WIDGET (entry));
@@ -7758,7 +8282,7 @@ gtk_entry_set_icon_activatable (GtkEntry             *entry,
   g_return_if_fail (GTK_IS_ENTRY (entry));
   g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
 
   if ((icon_info = priv->icons[icon_pos]) == NULL)
     icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
@@ -7798,10 +8322,10 @@ gtk_entry_get_icon_activatable (GtkEntry             *entry,
   g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
   g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), FALSE);
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
   icon_info = priv->icons[icon_pos];
 
-  return (icon_info != NULL && !icon_info->nonactivatable);
+  return (!icon_info || !icon_info->nonactivatable);
 }
 
 /**
@@ -7815,7 +8339,8 @@ gtk_entry_get_icon_activatable (GtkEntry             *entry,
  * method will work regardless of whether the icon was set using a
  * #GdkPixbuf, a #GIcon, a stock item, or an icon name.
  *
- * Returns: A #GdkPixbuf, or %NULL if no icon is set for this position.
+ * Returns: (transfer none): A #GdkPixbuf, or %NULL if no icon is
+ *     set for this position.
  *
  * Since: 2.16
  */
@@ -7825,19 +8350,26 @@ gtk_entry_get_icon_pixbuf (GtkEntry             *entry,
 {
   GtkEntryPrivate *priv;
   EntryIconInfo *icon_info;
+  GdkPixbuf *pixbuf;
 
   g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
   g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
+
   icon_info = priv->icons[icon_pos];
 
   if (!icon_info)
     return NULL;
 
-  gtk_entry_ensure_pixbuf (entry, icon_pos);
+  /* HACK: unfortunately this is transfer none, so we need to return
+   * the icon helper's cache ref directly.
+   */
+  pixbuf = gtk_entry_ensure_pixbuf (entry, icon_pos);
+  if (pixbuf)
+    g_object_unref (pixbuf);
 
-  return icon_info->pixbuf;
+  return pixbuf;
 }
 
 /**
@@ -7849,8 +8381,8 @@ gtk_entry_get_icon_pixbuf (GtkEntry             *entry,
  * no icon or if the icon was set by some other method (e.g., by
  * stock, pixbuf, or icon name).
  *
- * Returns: A #GIcon, or %NULL if no icon is set or if the icon
- *          is not a #GIcon
+ * Returns: (transfer none): A #GIcon, or %NULL if no icon is set
+ *     or if the icon is not a #GIcon
  *
  * Since: 2.16
  */
@@ -7864,13 +8396,13 @@ gtk_entry_get_icon_gicon (GtkEntry             *entry,
   g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
   g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
   icon_info = priv->icons[icon_pos];
 
   if (!icon_info)
     return NULL;
 
-  return icon_info->storage_type == GTK_IMAGE_GICON ? icon_info->gicon : NULL;
+  return _gtk_icon_helper_peek_gicon (icon_info->icon_helper);
 }
 
 /**
@@ -7897,13 +8429,13 @@ gtk_entry_get_icon_stock (GtkEntry             *entry,
   g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
   g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
   icon_info = priv->icons[icon_pos];
 
   if (!icon_info)
     return NULL;
 
-  return icon_info->storage_type == GTK_IMAGE_STOCK ? icon_info->stock_id : NULL;
+  return _gtk_icon_helper_get_stock_id (icon_info->icon_helper);
 }
 
 /**
@@ -7930,13 +8462,13 @@ gtk_entry_get_icon_name (GtkEntry             *entry,
   g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
   g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
   icon_info = priv->icons[icon_pos];
 
   if (!icon_info)
     return NULL;
 
-  return icon_info->storage_type == GTK_IMAGE_ICON_NAME ? icon_info->icon_name : NULL;
+  return _gtk_icon_helper_get_icon_name (icon_info->icon_helper);
 }
 
 /**
@@ -7961,7 +8493,7 @@ gtk_entry_set_icon_sensitive (GtkEntry             *entry,
   g_return_if_fail (GTK_IS_ENTRY (entry));
   g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
 
   if ((icon_info = priv->icons[icon_pos]) == NULL)
     icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
@@ -8004,7 +8536,8 @@ gtk_entry_get_icon_sensitive (GtkEntry             *entry,
   g_return_val_if_fail (GTK_IS_ENTRY (entry), TRUE);
   g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), TRUE);
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
+
   icon_info = priv->icons[icon_pos];
 
   return (!icon_info || !icon_info->insensitive);
@@ -8034,13 +8567,14 @@ gtk_entry_get_icon_storage_type (GtkEntry             *entry,
   g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_IMAGE_EMPTY);
   g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), GTK_IMAGE_EMPTY);
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
+
   icon_info = priv->icons[icon_pos];
 
   if (!icon_info)
     return GTK_IMAGE_EMPTY;
 
-  return icon_info->storage_type;
+  return _gtk_icon_helper_get_storage_type (icon_info->icon_helper);
 }
 
 /**
@@ -8049,7 +8583,8 @@ gtk_entry_get_icon_storage_type (GtkEntry             *entry,
  * @x: the x coordinate of the position to find
  * @y: the y coordinate of the position to find
  *
- * Finds the icon at the given position and return its index.
+ * Finds the icon at the given position and return its index. The
+ * position's coordinates are relative to the @entry's top left corner.
  * If @x, @y doesn't lie inside an icon, -1 is returned.
  * This function is intended for use in a #GtkWidget::query-tooltip
  * signal handler.
@@ -8065,9 +8600,14 @@ gtk_entry_get_icon_at_pos (GtkEntry *entry,
 {
   GtkAllocation primary;
   GtkAllocation secondary;
+  gint frame_x, frame_y;
 
   g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
 
+  get_frame_size (entry, FALSE, &frame_x, &frame_y, NULL, NULL);
+  x -= frame_x;
+  y -= frame_y;
+
   get_icon_allocations (entry, &primary, &secondary);
 
   if (primary.x <= x && x < primary.x + primary.width &&
@@ -8083,7 +8623,7 @@ gtk_entry_get_icon_at_pos (GtkEntry *entry,
 
 /**
  * gtk_entry_set_icon_drag_source:
- * @entry: a #GtkIconEntry
+ * @entry: a #GtkEntry
  * @icon_pos: icon position
  * @target_list: the targets (data formats) in which the data can be provided
  * @actions: a bitmask of the allowed drag actions
@@ -8116,7 +8656,7 @@ gtk_entry_set_icon_drag_source (GtkEntry             *entry,
   g_return_if_fail (GTK_IS_ENTRY (entry));
   g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
 
   if ((icon_info = priv->icons[icon_pos]) == NULL)
     icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
@@ -8154,7 +8694,7 @@ gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
 
   g_return_val_if_fail (GTK_IS_ENTRY (entry), -1);
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
 
   for (i = 0; i < MAX_ICONS; i++)
     {
@@ -8169,38 +8709,56 @@ gtk_entry_get_current_icon_drag_source (GtkEntry *entry)
 }
 
 /**
- * gtk_entry_get_icon_window:
+ * gtk_entry_get_icon_area:
  * @entry: A #GtkEntry
  * @icon_pos: Icon position
+ * @icon_area: (out): Return location for the icon's area
  *
- * Returns the #GdkWindow which contains the entry's icon at
- * @icon_pos. This function is useful when drawing something to the
- * entry in an expose-event callback because it enables the callback
- * to distinguish between the text window and entry's icon windows.
+ * Gets the area where entry's icon at @icon_pos is drawn.
+ * This function is useful when drawing something to the
+ * entry in a draw callback.
  *
- * See also gtk_entry_get_text_window().
+ * If the entry is not realized or has no icon at the given position,
+ * @icon_area is filled with zeros.
  *
- * Return value: the entry's icon window at @icon_pos.
+ * See also gtk_entry_get_text_area()
  *
- * Since: 2.20
+ * Since: 3.0
  */
-GdkWindow  *
-gtk_entry_get_icon_window (GtkEntry             *entry,
-                           GtkEntryIconPosition  icon_pos)
+void
+gtk_entry_get_icon_area (GtkEntry             *entry,
+                         GtkEntryIconPosition  icon_pos,
+                         GdkRectangle         *icon_area)
 {
   GtkEntryPrivate *priv;
   EntryIconInfo *icon_info;
 
-  g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
+  g_return_if_fail (GTK_IS_ENTRY (entry));
+  g_return_if_fail (icon_area != NULL);
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
 
   icon_info = priv->icons[icon_pos];
 
   if (icon_info)
-    return icon_info->window;
+    {
+      GtkAllocation primary;
+      GtkAllocation secondary;
+
+      get_icon_allocations (entry, &primary, &secondary);
 
-  return NULL;
+      if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
+        *icon_area = primary;
+      else
+        *icon_area = secondary;
+    }
+  else
+    {
+      icon_area->x = 0;
+      icon_area->y = 0;
+      icon_area->width = 0;
+      icon_area->height = 0;
+    }
 }
 
 static void
@@ -8211,7 +8769,7 @@ ensure_has_tooltip (GtkEntry *entry)
   int i;
   gboolean has_tooltip = FALSE;
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
 
   for (i = 0; i < MAX_ICONS; i++)
     {
@@ -8252,7 +8810,8 @@ gtk_entry_get_icon_tooltip_text (GtkEntry             *entry,
   g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
   g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
+
   icon_info = priv->icons[icon_pos];
 
   if (!icon_info)
@@ -8292,10 +8851,10 @@ gtk_entry_set_icon_tooltip_text (GtkEntry             *entry,
   g_return_if_fail (GTK_IS_ENTRY (entry));
   g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
 
-  if (!(icon_info = priv->icons[icon_pos]))
-    icon_info = priv->icons[icon_pos];
+  if ((icon_info = priv->icons[icon_pos]) == NULL)
+    icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
 
   if (icon_info->tooltip)
     g_free (icon_info->tooltip);
@@ -8309,6 +8868,9 @@ gtk_entry_set_icon_tooltip_text (GtkEntry             *entry,
   icon_info->tooltip = tooltip ? g_markup_escape_text (tooltip, -1) : NULL;
 
   ensure_has_tooltip (entry);
+
+  g_object_notify (G_OBJECT (entry),
+                   icon_pos == GTK_ENTRY_ICON_PRIMARY ? "primary-icon-tooltip-text" : "secondary-icon-tooltip-text");
 }
 
 /**
@@ -8334,7 +8896,8 @@ gtk_entry_get_icon_tooltip_markup (GtkEntry             *entry,
   g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
   g_return_val_if_fail (IS_VALID_ICON_POSITION (icon_pos), NULL);
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
+
   icon_info = priv->icons[icon_pos];
 
   if (!icon_info)
@@ -8356,7 +8919,7 @@ gtk_entry_get_icon_tooltip_markup (GtkEntry             *entry,
  * Use %NULL for @tooltip to remove an existing tooltip.
  *
  * See also gtk_widget_set_tooltip_markup() and 
- * gtk_enty_set_icon_tooltip_text().
+ * gtk_entry_set_icon_tooltip_text().
  *
  * Since: 2.16
  */
@@ -8371,10 +8934,10 @@ gtk_entry_set_icon_tooltip_markup (GtkEntry             *entry,
   g_return_if_fail (GTK_IS_ENTRY (entry));
   g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));
 
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
 
-  if (!(icon_info = priv->icons[icon_pos]))
-    icon_info = priv->icons[icon_pos];
+  if ((icon_info = priv->icons[icon_pos]) == NULL)
+    icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);
 
   if (icon_info->tooltip)
     g_free (icon_info->tooltip);
@@ -8403,7 +8966,7 @@ gtk_entry_query_tooltip (GtkWidget  *widget,
   gint icon_pos;
 
   entry = GTK_ENTRY (widget);
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
 
   if (!keyboard_tip)
     {
@@ -8449,6 +9012,26 @@ gtk_entry_mnemonic_activate (GtkWidget *widget,
   return TRUE;
 }
 
+static void
+gtk_entry_grab_notify (GtkWidget *widget,
+                       gboolean   was_grabbed)
+{
+  GtkEntryPrivate *priv;
+
+  priv = GTK_ENTRY (widget)->priv;
+
+  if (priv->device &&
+      gtk_widget_device_is_shadowed (widget, priv->device))
+    {
+      /* Unset button so we don't expect
+       * a button release anymore
+       */
+      priv->button = 0;
+      priv->device = NULL;
+      priv->in_drag = FALSE;
+    }
+}
+
 static void
 append_action_signal (GtkEntry     *entry,
                      GtkWidget    *menu,
@@ -8472,7 +9055,10 @@ static void
 popup_menu_detach (GtkWidget *attach_widget,
                   GtkMenu   *menu)
 {
-  GTK_ENTRY (attach_widget)->popup_menu = NULL;
+  GtkEntry *entry_attach = GTK_ENTRY (attach_widget);
+  GtkEntryPrivate *priv_attach = entry_attach->priv;
+
+  priv_attach->popup_menu = NULL;
 }
 
 static void
@@ -8483,30 +9069,32 @@ popup_position_func (GtkMenu   *menu,
                      gpointer  user_data)
 {
   GtkEntry *entry = GTK_ENTRY (user_data);
+  GtkEntryPrivate *priv = entry->priv;
   GtkWidget *widget = GTK_WIDGET (entry);
   GdkScreen *screen;
   GtkRequisition menu_req;
   GdkRectangle monitor;
-  GtkBorder inner_border;
+  GtkBorder borders;
   gint monitor_num, strong_x, height;
  
   g_return_if_fail (gtk_widget_get_realized (widget));
 
-  gdk_window_get_origin (entry->text_area, x, y);
+  gdk_window_get_origin (priv->text_area, x, y);
 
   screen = gtk_widget_get_screen (widget);
-  monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
+  monitor_num = gdk_screen_get_monitor_at_window (screen, priv->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);
-  gtk_widget_size_request (entry->popup_menu, &menu_req);
-  gdk_drawable_get_size (entry->text_area, NULL, &height);
+  gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
+  gtk_widget_get_preferred_size (priv->popup_menu,
+                                 &menu_req, NULL);
+  height = gdk_window_get_height (priv->text_area);
   gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
-  _gtk_entry_effective_inner_border (entry, &inner_border);
+  _gtk_entry_get_borders (entry, &borders);
 
-  *x += inner_border.left + strong_x - entry->scroll_offset;
+  *x += borders.left + strong_x - priv->scroll_offset;
   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
     *x -= menu_req.width;
 
@@ -8527,8 +9115,9 @@ unichar_chosen_func (const char *text,
                      gpointer    data)
 {
   GtkEntry *entry = GTK_ENTRY (data);
+  GtkEntryPrivate *priv = entry->priv;
 
-  if (entry->editable)
+  if (priv->editable)
     gtk_entry_enter_text (entry, text);
 }
 
@@ -8537,6 +9126,7 @@ typedef struct
   GtkEntry *entry;
   gint button;
   guint time;
+  GdkDevice *device;
 } PopupInfo;
 
 static void
@@ -8546,7 +9136,8 @@ popup_targets_received (GtkClipboard     *clipboard,
 {
   PopupInfo *info = user_data;
   GtkEntry *entry = info->entry;
-  
+  GtkEntryPrivate *info_entry_priv = entry->priv;
+
   if (gtk_widget_get_realized (GTK_WIDGET (entry)))
     {
       DisplayMode mode;
@@ -8557,43 +9148,44 @@ popup_targets_received (GtkClipboard     *clipboard,
       gboolean show_unicode_menu;
       
       clipboard_contains_text = gtk_selection_data_targets_include_text (data);
-      if (entry->popup_menu)
-       gtk_widget_destroy (entry->popup_menu);
-      
-      entry->popup_menu = gtk_menu_new ();
-      
-      gtk_menu_attach_to_widget (GTK_MENU (entry->popup_menu),
+      if (info_entry_priv->popup_menu)
+       gtk_widget_destroy (info_entry_priv->popup_menu);
+
+      info_entry_priv->popup_menu = gtk_menu_new ();
+
+      gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu),
                                 GTK_WIDGET (entry),
                                 popup_menu_detach);
       
       mode = gtk_entry_get_display_mode (entry);
-      append_action_signal (entry, entry->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
-                           entry->editable && mode == DISPLAY_NORMAL &&
-                           entry->current_pos != entry->selection_bound);
+      append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_CUT, "cut-clipboard",
+                            info_entry_priv->editable && mode == DISPLAY_NORMAL &&
+                            info_entry_priv->current_pos != info_entry_priv->selection_bound);
 
-      append_action_signal (entry, entry->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
+      append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_COPY, "copy-clipboard",
                             mode == DISPLAY_NORMAL &&
-                            entry->current_pos != entry->selection_bound);
+                            info_entry_priv->current_pos != info_entry_priv->selection_bound);
 
-      append_action_signal (entry, entry->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
-                           entry->editable && clipboard_contains_text);
+      append_action_signal (entry, info_entry_priv->popup_menu, GTK_STOCK_PASTE, "paste-clipboard",
+                            info_entry_priv->editable && clipboard_contains_text);
 
       menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
-      gtk_widget_set_sensitive (menuitem, entry->editable && entry->current_pos != entry->selection_bound);
+      gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound);
       g_signal_connect_swapped (menuitem, "activate",
                                G_CALLBACK (gtk_entry_delete_cb), entry);
       gtk_widget_show (menuitem);
-      gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
+      gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
 
       menuitem = gtk_separator_menu_item_new ();
       gtk_widget_show (menuitem);
-      gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
+      gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
       
       menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
+      gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0);
       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);
+      gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
       
       g_object_get (gtk_widget_get_settings (GTK_WIDGET (entry)),
                     "gtk-show-input-method-menu", &show_input_method_menu,
@@ -8604,33 +9196,33 @@ popup_targets_received (GtkClipboard     *clipboard,
         {
           menuitem = gtk_separator_menu_item_new ();
           gtk_widget_show (menuitem);
-          gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
+          gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
         }
       
       if (show_input_method_menu)
         {
           menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
-          gtk_widget_set_sensitive (menuitem, entry->editable);      
+          gtk_widget_set_sensitive (menuitem, info_entry_priv->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_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context),
+
+          gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
+
+          gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (info_entry_priv->im_context),
                                                 GTK_MENU_SHELL (submenu));
         }
       
       if (show_unicode_menu)
         {
           menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode Control Character"));
-          gtk_widget_set_sensitive (menuitem, entry->editable);      
+          gtk_widget_set_sensitive (menuitem, info_entry_priv->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_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem);
+
           _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
                                                         unichar_chosen_func,
                                                         entry);
@@ -8639,19 +9231,19 @@ popup_targets_received (GtkClipboard     *clipboard,
       g_signal_emit (entry,
                     signals[POPULATE_POPUP],
                     0,
-                    entry->popup_menu);
-  
+                    info_entry_priv->popup_menu);
+
 
-      if (info->button)
-       gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
-                       NULL, NULL,
+      if (info->device)
+       gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu),
+                        info->device, NULL, NULL, NULL, NULL, NULL,
                        info->button, info->time);
       else
        {
-         gtk_menu_popup (GTK_MENU (entry->popup_menu), NULL, NULL,
+         gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL,
                          popup_position_func, entry,
-                         info->button, info->time);
-         gtk_menu_shell_select_first (GTK_MENU_SHELL (entry->popup_menu), FALSE);
+                         0, gtk_get_current_event_time ());
+         gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE);
        }
     }
 
@@ -8675,11 +9267,13 @@ gtk_entry_do_popup (GtkEntry       *entry,
     {
       info->button = event->button;
       info->time = event->time;
+      info->device = event->device;
     }
   else
     {
       info->button = 0;
       info->time = gtk_get_current_event_time ();
+      info->device = NULL;
     }
 
   gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
@@ -8696,67 +9290,205 @@ gtk_entry_popup_menu (GtkWidget *widget)
 }
 
 static void
-gtk_entry_drag_begin (GtkWidget      *widget,
-                      GdkDragContext *context)
+activate_bubble_cb (GtkWidget *item,
+                   GtkEntry  *entry)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
-  gint i;
-
-  for (i = 0; i < MAX_ICONS; i++)
-    {
-      EntryIconInfo *icon_info = priv->icons[i];
-      
-      if (icon_info != NULL)
-        {
-          if (icon_info->in_drag) 
-            {
-              switch (icon_info->storage_type)
-                {
-                case GTK_IMAGE_STOCK:
-                  gtk_drag_set_icon_stock (context, icon_info->stock_id, -2, -2);
-                  break;
-
-                case GTK_IMAGE_ICON_NAME:
-                  gtk_drag_set_icon_name (context, icon_info->icon_name, -2, -2);
-                  break;
-
-                  /* FIXME: No GIcon support for dnd icons */
-                case GTK_IMAGE_GICON:
-                case GTK_IMAGE_PIXBUF:
-                  gtk_drag_set_icon_pixbuf (context, icon_info->pixbuf, -2, -2);
-                  break;
-                default:
-                  g_assert_not_reached ();
-                }
-            }
-        }
-    }
+  const gchar *signal = g_object_get_data (G_OBJECT (item), "gtk-signal");
+  g_signal_emit_by_name (entry, signal);
+  _gtk_bubble_window_popdown (GTK_BUBBLE_WINDOW (entry->priv->selection_bubble));
 }
 
 static void
-gtk_entry_drag_end (GtkWidget      *widget,
-                    GdkDragContext *context)
+append_bubble_action (GtkEntry     *entry,
+                      GtkWidget    *toolbar,
+                      const gchar  *stock_id,
+                      const gchar  *signal,
+                      gboolean      sensitive)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
-  gint i;
-
-  for (i = 0; i < MAX_ICONS; i++)
-    {
-      EntryIconInfo *icon_info = priv->icons[i];
-
-      if (icon_info != NULL)
-        icon_info->in_drag = 0;
-    }
+  GtkToolItem *item = gtk_tool_button_new_from_stock (stock_id);
+  g_object_set_data (G_OBJECT (item), I_("gtk-signal"), (char *)signal);
+  g_signal_connect (item, "clicked", G_CALLBACK (activate_bubble_cb), entry);
+  gtk_widget_set_sensitive (GTK_WIDGET (item), sensitive);
+  gtk_widget_show (GTK_WIDGET (item));
+  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
 }
 
 static void
-gtk_entry_drag_leave (GtkWidget        *widget,
-                     GdkDragContext   *context,
-                     guint             time)
-{
+bubble_targets_received (GtkClipboard     *clipboard,
+                         GtkSelectionData *data,
+                         gpointer          user_data)
+{
+  GtkEntry *entry = user_data;
+  GtkEntryPrivate *priv = entry->priv;
+  cairo_rectangle_int_t rect;
+  GtkAllocation allocation;
+  gint start_x, end_x;
+  gboolean has_selection;
+  gboolean has_clipboard;
+  DisplayMode mode;
+  GtkWidget *toolbar;
+
+  has_selection = gtk_editable_get_selection_bounds (GTK_EDITABLE (entry),
+                                                     NULL, NULL);
+  if (!has_selection && !priv->editable)
+    {
+      priv->selection_bubble_timeout_id = 0;
+      return;
+    }
+
+  if (priv->selection_bubble)
+    gtk_widget_destroy (priv->selection_bubble);
+
+  priv->selection_bubble = _gtk_bubble_window_new ();
+  toolbar = GTK_WIDGET (gtk_toolbar_new ());
+  gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_TEXT);
+  gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), FALSE);
+  gtk_widget_show (toolbar);
+  gtk_container_add (GTK_CONTAINER (priv->selection_bubble), toolbar);
+
+  has_clipboard = gtk_selection_data_targets_include_text (data);
+  mode = gtk_entry_get_display_mode (entry);
+
+  append_bubble_action (entry, toolbar, GTK_STOCK_CUT, "cut-clipboard",
+                        priv->editable && has_selection && mode == DISPLAY_NORMAL);
+
+  append_bubble_action (entry, toolbar, GTK_STOCK_COPY, "copy-clipboard",
+                        has_selection && mode == DISPLAY_NORMAL);
+
+  append_bubble_action (entry, toolbar, GTK_STOCK_PASTE, "paste-clipboard",
+                        priv->editable && has_clipboard);
+
+  if (priv->populate_all)
+    g_signal_emit (entry, signals[POPULATE_POPUP], 0, toolbar);
+
+  gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
+
+  gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &start_x, NULL);
+
+  start_x -= priv->scroll_offset;
+  start_x = CLAMP (start_x, 0, gdk_window_get_width (priv->text_area));
+
+  rect.y = 0;
+  rect.height = gdk_window_get_height (priv->text_area);
+
+  if (has_selection)
+    {
+      end_x = gtk_entry_get_selection_bound_location (entry) - priv->scroll_offset;
+      end_x = CLAMP (end_x, 0, gdk_window_get_width (priv->text_area));
+
+      rect.x = MIN (start_x, end_x);
+      rect.width = MAX (start_x, end_x) - rect.x;
+    }
+  else
+    {
+      rect.x = start_x;
+      rect.width = 0;
+    }
+
+  _gtk_bubble_window_popup (GTK_BUBBLE_WINDOW (priv->selection_bubble),
+                            priv->text_area, &rect, GTK_POS_TOP);
+
+  priv->selection_bubble_timeout_id = 0;
+}
+
+static gboolean
+gtk_entry_selection_bubble_popup_cb (gpointer user_data)
+{
+  GtkEntry *entry = user_data;
+
+  gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD),
+                                  gdk_atom_intern_static_string ("TARGETS"),
+                                  bubble_targets_received,
+                                  entry);
+  return G_SOURCE_REMOVE;
+}
+
+static void
+gtk_entry_selection_bubble_popup_unset (GtkEntry *entry)
+{
+  GtkEntryPrivate *priv;
+
+  priv = entry->priv;
+
+  if (priv->selection_bubble)
+    _gtk_bubble_window_popdown (GTK_BUBBLE_WINDOW (priv->selection_bubble));
+
+  if (priv->selection_bubble_timeout_id)
+    {
+      g_source_remove (priv->selection_bubble_timeout_id);
+      priv->selection_bubble_timeout_id = 0;
+    }
+}
+
+static void
+gtk_entry_selection_bubble_popup_set (GtkEntry *entry)
+{
+  GtkEntryPrivate *priv;
+
+  priv = entry->priv;
+
+  if (priv->selection_bubble_timeout_id)
+    g_source_remove (priv->selection_bubble_timeout_id);
+
+  priv->selection_bubble_timeout_id =
+    gdk_threads_add_timeout (1000, gtk_entry_selection_bubble_popup_cb, entry);
+}
+
+static void
+gtk_entry_drag_begin (GtkWidget      *widget,
+                      GdkDragContext *context)
+{
+  GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
+  gint i;
+
+  for (i = 0; i < MAX_ICONS; i++)
+    {
+      EntryIconInfo *icon_info = priv->icons[i];
+      
+      if (icon_info != NULL)
+        {
+          if (icon_info->in_drag) 
+            {
+              GdkPixbuf *pix;
+
+              pix = _gtk_icon_helper_ensure_pixbuf
+                (icon_info->icon_helper,
+                 gtk_widget_get_style_context (GTK_WIDGET (entry)));
+              gtk_drag_set_icon_pixbuf (context, pix, -2, -2);
+
+              g_object_unref (pix);
+            }
+        }
+    }
+}
+
+static void
+gtk_entry_drag_end (GtkWidget      *widget,
+                    GdkDragContext *context)
+{
   GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
+  gint i;
 
-  entry->dnd_position = -1;
+  for (i = 0; i < MAX_ICONS; i++)
+    {
+      EntryIconInfo *icon_info = priv->icons[i];
+
+      if (icon_info != NULL)
+        icon_info->in_drag = 0;
+    }
+}
+
+static void
+gtk_entry_drag_leave (GtkWidget        *widget,
+                     GdkDragContext   *context,
+                     guint             time)
+{
+  GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
+
+  priv->dnd_position = -1;
   gtk_widget_queue_draw (widget);
 }
 
@@ -8768,9 +9500,10 @@ gtk_entry_drag_drop  (GtkWidget        *widget,
                      guint             time)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
   GdkAtom target = GDK_NONE;
-  
-  if (entry->editable)
+
+  if (priv->editable)
     target = gtk_drag_dest_find_target (widget, context, NULL);
 
   if (target != GDK_NONE)
@@ -8789,22 +9522,27 @@ gtk_entry_drag_motion (GtkWidget        *widget,
                       guint             time)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
+  GtkStyleContext *style_context;
   GtkWidget *source_widget;
   GdkDragAction suggested_action;
   gint new_position, old_position;
   gint sel1, sel2;
-  
-  x -= widget->style->xthickness;
-  y -= widget->style->ythickness;
-  
-  old_position = entry->dnd_position;
-  new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
+  GtkBorder padding;
+
+  style_context = gtk_widget_get_style_context (widget);
+  gtk_style_context_get_padding (style_context, 0, &padding);
+  x -= padding.left;
+  y -= padding.top;
 
-  if (entry->editable &&
+  old_position = priv->dnd_position;
+  new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
+
+  if (priv->editable &&
       gtk_drag_dest_find_target (widget, context, NULL) != GDK_NONE)
     {
       source_widget = gtk_drag_get_source_widget (context);
-      suggested_action = context->suggested_action;
+      suggested_action = gdk_drag_context_get_suggested_action (context);
 
       if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) ||
           new_position < sel1 || new_position > sel2)
@@ -8814,30 +9552,30 @@ gtk_entry_drag_motion (GtkWidget        *widget,
              /* Default to MOVE, unless the user has
               * pressed ctrl or alt to affect available actions
               */
-             if ((context->actions & GDK_ACTION_MOVE) != 0)
+             if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
                suggested_action = GDK_ACTION_MOVE;
            }
-              
-          entry->dnd_position = new_position;
+
+          priv->dnd_position = new_position;
         }
       else
         {
           if (source_widget == widget)
            suggested_action = 0;       /* Can't drop in selection where drag started */
-          
-          entry->dnd_position = -1;
+
+          priv->dnd_position = -1;
         }
     }
   else
     {
       /* Entry not editable, or no text */
       suggested_action = 0;
-      entry->dnd_position = -1;
+      priv->dnd_position = -1;
     }
   
   gdk_drag_status (context, suggested_action, time);
-  
-  if (entry->dnd_position != old_position)
+
+  if (priv->dnd_position != old_position)
     gtk_widget_queue_draw (widget);
 
   return TRUE;
@@ -8853,24 +9591,29 @@ gtk_entry_drag_data_received (GtkWidget        *widget,
                              guint             time)
 {
   GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
   GtkEditable *editable = GTK_EDITABLE (widget);
+  GtkStyleContext *style_context;
+  GtkBorder padding;
   gchar *str;
 
   str = (gchar *) gtk_selection_data_get_text (selection_data);
 
-  x -= widget->style->xthickness;
-  y -= widget->style->ythickness;
+  style_context = gtk_widget_get_style_context (widget);
+  gtk_style_context_get_padding (style_context, 0, &padding);
+  x -= padding.left;
+  y -= padding.top;
 
-  if (str && entry->editable)
+  if (str && priv->editable)
     {
       gint new_position;
       gint sel1, sel2;
       gint length = -1;
 
-      if (entry->truncate_multiline)
+      if (priv->truncate_multiline)
         length = truncate_multiline (str);
 
-      new_position = gtk_entry_find_position (entry, x + entry->scroll_offset);
+      new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
 
       if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
          new_position < sel1 || new_position > sel2)
@@ -8881,14 +9624,12 @@ gtk_entry_drag_data_received (GtkWidget        *widget,
        {
          /* Replacing selection */
           begin_change (entry);
-          g_object_freeze_notify (G_OBJECT (entry));
          gtk_editable_delete_text (editable, sel1, sel2);
          gtk_editable_insert_text (editable, str, length, &sel1);
-          g_object_thaw_notify (G_OBJECT (entry));
           end_change (entry);
        }
       
-      gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
+      gtk_drag_finish (context, TRUE, gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
     }
   else
     {
@@ -8906,12 +9647,12 @@ gtk_entry_drag_data_get (GtkWidget        *widget,
                         guint             info,
                         guint             time)
 {
+  GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
+  GtkEditable *editable = GTK_EDITABLE (widget);
   gint sel_start, sel_end;
   gint i;
 
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
-  GtkEditable *editable = GTK_EDITABLE (widget);
-
   /* If there is an icon drag going on, exit early. */
   for (i = 0; i < MAX_ICONS; i++)
     {
@@ -8926,7 +9667,7 @@ gtk_entry_drag_data_get (GtkWidget        *widget,
 
   if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
     {
-      gchar *str = gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
+      gchar *str = _gtk_entry_get_display_text (GTK_ENTRY (widget), sel_start, sel_end);
 
       gtk_selection_data_set_text (selection_data, str, -1);
       
@@ -8939,12 +9680,12 @@ static void
 gtk_entry_drag_data_delete (GtkWidget      *widget,
                            GdkDragContext *context)
 {
+  GtkEntry *entry = GTK_ENTRY (widget);
+  GtkEntryPrivate *priv = entry->priv;
+  GtkEditable *editable = GTK_EDITABLE (widget);
   gint sel_start, sel_end;
   gint i;
 
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (widget);
-  GtkEditable *editable = GTK_EDITABLE (widget);
-
   /* If there is an icon drag going on, exit early. */
   for (i = 0; i < MAX_ICONS; i++)
     {
@@ -8956,8 +9697,8 @@ gtk_entry_drag_data_delete (GtkWidget      *widget,
             return;
         }
     }
-  
-  if (GTK_ENTRY (widget)->editable &&
+
+  if (priv->editable &&
       gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end))
     gtk_editable_delete_text (editable, sel_start, sel_end);
 }
@@ -8976,9 +9717,11 @@ gtk_entry_drag_data_delete (GtkWidget      *widget,
 static gboolean
 cursor_blinks (GtkEntry *entry)
 {
+  GtkEntryPrivate *priv = entry->priv;
+
   if (gtk_widget_has_focus (GTK_WIDGET (entry)) &&
-      entry->editable &&
-      entry->selection_bound == entry->current_pos)
+      priv->editable &&
+      priv->selection_bound == priv->current_pos)
     {
       GtkSettings *settings;
       gboolean blink;
@@ -8992,6 +9735,18 @@ cursor_blinks (GtkEntry *entry)
     return FALSE;
 }
 
+static gboolean
+get_middle_click_paste (GtkEntry *entry)
+{
+  GtkSettings *settings;
+  gboolean paste;
+
+  settings = gtk_widget_get_settings (GTK_WIDGET (entry));
+  g_object_get (settings, "gtk-enable-primary-paste", &paste, NULL);
+
+  return paste;
+}
+
 static gint
 get_cursor_time (GtkEntry *entry)
 {
@@ -9017,14 +9772,15 @@ get_cursor_blink_timeout (GtkEntry *entry)
 static void
 show_cursor (GtkEntry *entry)
 {
+  GtkEntryPrivate *priv = entry->priv;
   GtkWidget *widget;
 
-  if (!entry->cursor_visible)
+  if (!priv->cursor_visible)
     {
-      entry->cursor_visible = TRUE;
+      priv->cursor_visible = TRUE;
 
       widget = GTK_WIDGET (entry);
-      if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
+      if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
        gtk_widget_queue_draw (widget);
     }
 }
@@ -9032,14 +9788,15 @@ show_cursor (GtkEntry *entry)
 static void
 hide_cursor (GtkEntry *entry)
 {
+  GtkEntryPrivate *priv = entry->priv;
   GtkWidget *widget;
 
-  if (entry->cursor_visible)
+  if (priv->cursor_visible)
     {
-      entry->cursor_visible = FALSE;
+      priv->cursor_visible = FALSE;
 
       widget = GTK_WIDGET (entry);
-      if (gtk_widget_has_focus (widget) && entry->selection_bound == entry->current_pos)
+      if (gtk_widget_has_focus (widget) && priv->selection_bound == priv->current_pos)
        gtk_widget_queue_draw (widget);
     }
 }
@@ -9055,7 +9812,7 @@ blink_cb (gpointer data)
   gint blink_timeout;
 
   entry = GTK_ENTRY (data);
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  priv = entry->priv;
  
   if (!gtk_widget_has_focus (GTK_WIDGET (entry)))
     {
@@ -9068,7 +9825,7 @@ blink_cb (gpointer data)
       return FALSE;
     }
   
-  g_assert (entry->selection_bound == entry->current_pos);
+  g_assert (priv->selection_bound == priv->current_pos);
   
   blink_timeout = get_cursor_blink_timeout (entry);
   if (priv->blink_time > 1000 * blink_timeout && 
@@ -9076,12 +9833,12 @@ blink_cb (gpointer data)
     {
       /* we've blinked enough without the user doing anything, stop blinking */
       show_cursor (entry);
-      entry->blink_timeout = 0;
+      priv->blink_timeout = 0;
     } 
-  else if (entry->cursor_visible)
+  else if (priv->cursor_visible)
     {
       hide_cursor (entry);
-      entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
+      priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
                                            blink_cb,
                                            entry);
     }
@@ -9089,7 +9846,7 @@ blink_cb (gpointer data)
     {
       show_cursor (entry);
       priv->blink_time += get_cursor_time (entry);
-      entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
+      priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
                                            blink_cb,
                                            entry);
     }
@@ -9101,559 +9858,53 @@ blink_cb (gpointer data)
 static void
 gtk_entry_check_cursor_blink (GtkEntry *entry)
 {
-  GtkEntryPrivate *priv; 
-  
-  priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
 
   if (cursor_blinks (entry))
     {
-      if (!entry->blink_timeout)
+      if (!priv->blink_timeout)
        {
          show_cursor (entry);
-         entry->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
+         priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
                                                blink_cb,
                                                entry);
        }
     }
   else
     {
-      if (entry->blink_timeout)  
-       { 
-         g_source_remove (entry->blink_timeout);
-         entry->blink_timeout = 0;
-       }
-      
-      entry->cursor_visible = TRUE;
-    }
-  
-}
-
-static void
-gtk_entry_pend_cursor_blink (GtkEntry *entry)
-{
-  if (cursor_blinks (entry))
-    {
-      if (entry->blink_timeout != 0)
-       g_source_remove (entry->blink_timeout);
-      
-      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);
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (completion->priv->entry);
-
-  completion->priv->completion_timeout = 0;
-
-  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);
-
-      gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
-
-      s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
-
-      gtk_tree_selection_unselect_all (s);
-
-      actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
-
-      g_object_get (completion, "popup-single-match", &popup_single, NULL);
-      if ((matches > (popup_single ? 0: 1)) || actions > 0)
-       { 
-         if (gtk_widget_get_visible (completion->priv->popup_window))
-           _gtk_entry_completion_resize_popup (completion);
-          else
-           _gtk_entry_completion_popup (completion, priv->completion_device);
-       }
-      else 
-       _gtk_entry_completion_popdown (completion);
-    }
-  else if (gtk_widget_get_visible (completion->priv->popup_window))
-    _gtk_entry_completion_popdown (completion);
-
-  return FALSE;
-}
-
-static inline gboolean
-keyval_is_cursor_move (guint keyval)
-{
-  if (keyval == GDK_Up || keyval == GDK_KP_Up)
-    return TRUE;
-
-  if (keyval == GDK_Down || keyval == GDK_KP_Down)
-    return TRUE;
-
-  if (keyval == GDK_Page_Up)
-    return TRUE;
-
-  if (keyval == GDK_Page_Down)
-    return TRUE;
-
-  return FALSE;
-}
-
-static gboolean
-gtk_entry_completion_key_press (GtkWidget   *widget,
-                                GdkEventKey *event,
-                                gpointer     user_data)
-{
-  gint matches, actions = 0;
-  GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
-
-  if (!gtk_widget_get_mapped (completion->priv->popup_window))
-    return FALSE;
-
-  matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
-
-  if (completion->priv->actions)
-    actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
-
-  if (keyval_is_cursor_move (event->keyval))
-    {
-      GtkTreePath *path = NULL;
-      
-      if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
-        {
-         if (completion->priv->current_selected < 0)
-           completion->priv->current_selected = matches + actions - 1;
-         else
-           completion->priv->current_selected--;
-        }
-      else if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
-        {
-          if (completion->priv->current_selected < matches + actions - 1)
-           completion->priv->current_selected++;
-         else
-            completion->priv->current_selected = -1;
-        }
-      else if (event->keyval == GDK_Page_Up)
-       {
-         if (completion->priv->current_selected < 0)
-           completion->priv->current_selected = matches + actions - 1;
-         else if (completion->priv->current_selected == 0)
-           completion->priv->current_selected = -1;
-         else if (completion->priv->current_selected < matches) 
-           {
-             completion->priv->current_selected -= 14;
-             if (completion->priv->current_selected < 0)
-               completion->priv->current_selected = 0;
-           }
-         else 
-           {
-             completion->priv->current_selected -= 14;
-             if (completion->priv->current_selected < matches - 1)
-               completion->priv->current_selected = matches - 1;
-           }
-       }
-      else if (event->keyval == GDK_Page_Down)
+      if (priv->blink_timeout)
        {
-         if (completion->priv->current_selected < 0)
-           completion->priv->current_selected = 0;
-         else if (completion->priv->current_selected < matches - 1)
-           {
-             completion->priv->current_selected += 14;
-             if (completion->priv->current_selected > matches - 1)
-               completion->priv->current_selected = matches - 1;
-           }
-         else if (completion->priv->current_selected == matches + actions - 1)
-           {
-             completion->priv->current_selected = -1;
-           }
-         else
-           {
-             completion->priv->current_selected += 14;
-             if (completion->priv->current_selected > matches + actions - 1)
-               completion->priv->current_selected = matches + actions - 1;
-           }
+         g_source_remove (priv->blink_timeout);
+         priv->blink_timeout = 0;
        }
 
-      if (completion->priv->current_selected < 0)
-        {
-          gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
-          gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
-
-          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)
-        {
-          gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view)));
-
-          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;
-              GtkTreeIter child_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;
-
-              gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, &iter);
-              model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
-              
-              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,
-                                     &child_iter, &entry_set);
-            }
-        }
-      else if (completion->priv->current_selected - matches >= 0)
-        {
-          gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
-
-          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;
+      priv->cursor_visible = TRUE;
     }
-  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);
-
-      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) 
-    {
-      GtkDirectionType dir = event->keyval == GDK_ISO_Left_Tab ? 
-       GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD;
-      
-      _gtk_entry_reset_im_context (GTK_ENTRY (widget));
-      _gtk_entry_completion_popdown (completion);
-
-      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 ||
-           event->keyval == GDK_KP_Enter ||
-          event->keyval == GDK_Return)
-    {
-      GtkTreeIter iter;
-      GtkTreeModel *model = NULL;
-      GtkTreeSelection *sel;
-      gboolean retval = TRUE;
-
-      _gtk_entry_reset_im_context (GTK_ENTRY (widget));
-      _gtk_entry_completion_popdown (completion);
-
-      if (completion->priv->current_selected < matches)
-        {
-          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))
-            {
-              g_signal_handler_block (widget, completion->priv->changed_id);
-              g_signal_emit_by_name (completion, "match-selected",
-                                     model, &iter, &entry_set);
-              g_signal_handler_unblock (widget, completion->priv->changed_id);
-
-              if (!entry_set)
-                {
-                  gchar *str = NULL;
-
-                  gtk_tree_model_get (model, &iter,
-                                      completion->priv->text_column, &str,
-                                      -1);
-
-                  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)
-        {
-          sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
-          if (gtk_tree_selection_get_selected (sel, &model, &iter))
-            {
-              GtkTreePath *path;
-
-              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);
-            }
-          else
-            retval = FALSE;
-        }
-
-      g_free (completion->priv->completion_prefix);
-      completion->priv->completion_prefix = NULL;
-
-      return retval;
-    }
-
-  return FALSE;
 }
 
 static void
-gtk_entry_completion_changed (GtkWidget *entry,
-                              gpointer   user_data)
-{
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
-  GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
-  GdkDevice *device;
-
-  /* (re)install completion timeout */
-  if (completion->priv->completion_timeout)
-    g_source_remove (completion->priv->completion_timeout);
-
-  if (!gtk_entry_get_text (GTK_ENTRY (entry)))
-    return;
-
-  /* no need to normalize for this test */
-  if (completion->priv->minimum_key_length > 0 &&
-      strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))) == 0)
-    {
-      if (gtk_widget_get_visible (completion->priv->popup_window))
-        _gtk_entry_completion_popdown (completion);
-      return;
-    }
-
-  device = gtk_get_current_event_device ();
-
-  if (device && device->source == GDK_SOURCE_KEYBOARD)
-    device = gdk_device_get_associated_device (device);
-
-  if (device)
-    priv->completion_device = device;
-
-  completion->priv->completion_timeout =
-    gdk_threads_add_timeout (COMPLETION_TIMEOUT,
-                   gtk_entry_completion_timeout,
-                   completion);
-}
-
-static gboolean
-check_completion_callback (GtkEntryCompletion *completion)
-{
-  completion->priv->check_completion_idle = NULL;
-  
-  gtk_entry_completion_complete (completion);
-  gtk_entry_completion_insert_prefix (completion);
-
-  return FALSE;
-}
-
-static void
-clear_completion_callback (GtkEntry   *entry,
-                          GParamSpec *pspec)
-{
-  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
-accept_completion_callback (GtkEntry *entry)
-{
-  GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
-
-  if (completion->priv->has_completion)
-    gtk_editable_set_position (GTK_EDITABLE (entry),
-                              gtk_entry_buffer_get_length (get_buffer (entry)));
-
-  return FALSE;
-}
-
-static void
-completion_insert_text_callback (GtkEntry           *entry,
-                                const gchar        *text,
-                                gint                length,
-                                gint                position,
-                                GtkEntryCompletion *completion)
-{
-  /* idle to update the selection based on the file list */
-  if (completion->priv->check_completion_idle == NULL)
-    {
-      completion->priv->check_completion_idle = g_idle_source_new ();
-      g_source_set_priority (completion->priv->check_completion_idle, G_PRIORITY_HIGH);
-      g_source_set_closure (completion->priv->check_completion_idle,
-                           g_cclosure_new_object (G_CALLBACK (check_completion_callback),
-                                                  G_OBJECT (completion)));
-      g_source_attach (completion->priv->check_completion_idle, NULL);
-    }
-}
-
-static void
-completion_changed (GtkEntryCompletion *completion,
-                   GParamSpec         *pspec,
-                   gpointer            data)
+gtk_entry_pend_cursor_blink (GtkEntry *entry)
 {
-  GtkEntry *entry = GTK_ENTRY (data);
+  GtkEntryPrivate *priv = entry->priv;
 
-  if (pspec->name == I_("popup-completion") ||
-      pspec->name == I_("inline-completion"))
+  if (cursor_blinks (entry))
     {
-      disconnect_completion_signals (entry, completion);
-      connect_completion_signals (entry, completion);
-    }
-}
+      if (priv->blink_timeout != 0)
+       g_source_remove (priv->blink_timeout);
 
-static void
-disconnect_completion_signals (GtkEntry           *entry,
-                              GtkEntryCompletion *completion)
-{
-  g_signal_handlers_disconnect_by_func (completion, 
-                                      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);
-      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);
-      completion->priv->insert_text_id = 0;
+      priv->blink_timeout = gdk_threads_add_timeout (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
+                                                     blink_cb,
+                                                     entry);
+      show_cursor (entry);
     }
-  g_signal_handlers_disconnect_by_func (entry, 
-                                       G_CALLBACK (completion_insert_text_callback), completion);
-  g_signal_handlers_disconnect_by_func (entry, 
-                                       G_CALLBACK (clear_completion_callback), completion);
-  g_signal_handlers_disconnect_by_func (entry, 
-                                       G_CALLBACK (accept_completion_callback), completion);
 }
 
 static void
-connect_completion_signals (GtkEntry           *entry,
-                           GtkEntryCompletion *completion)
+gtk_entry_reset_blink_time (GtkEntry *entry)
 {
-  if (completion->priv->popup_completion)
-    {
-      completion->priv->changed_id =
-       g_signal_connect (entry, "changed",
-                         G_CALLBACK (gtk_entry_completion_changed), completion);
-      g_signal_connect (entry, "key-press-event",
-                       G_CALLBACK (gtk_entry_completion_key_press), completion);
-    }
-  if (completion->priv->inline_completion)
-    {
-      completion->priv->insert_text_id =
-       g_signal_connect (entry, "insert-text",
-                         G_CALLBACK (completion_insert_text_callback), completion);
-      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);
-    }
+  GtkEntryPrivate *priv = entry->priv;
 
-  g_signal_connect (completion, "notify",
-                   G_CALLBACK (completion_changed), entry);
+  priv->blink_time = 0;
 }
 
 /**
@@ -9684,18 +9935,7 @@ gtk_entry_set_completion (GtkEntry           *entry,
   
   if (old)
     {
-      if (old->priv->completion_timeout)
-        {
-          g_source_remove (old->priv->completion_timeout);
-          old->priv->completion_timeout = 0;
-        }
-
-      if (gtk_widget_get_mapped (old->priv->popup_window))
-        _gtk_entry_completion_popdown (old);
-
-      disconnect_completion_signals (entry, old);
-      old->priv->entry = NULL;
-
+      _gtk_entry_completion_disconnect (old);
       g_object_unref (old);
     }
 
@@ -9708,9 +9948,11 @@ gtk_entry_set_completion (GtkEntry           *entry,
   /* hook into the entry */
   g_object_ref (completion);
 
-  connect_completion_signals (entry, completion);    
-  completion->priv->entry = GTK_WIDGET (entry);
+  _gtk_entry_completion_connect (completion, entry);
+
   g_object_set_data (G_OBJECT (entry), I_(GTK_ENTRY_COMPLETION_KEY), completion);
+
+  g_object_notify (G_OBJECT (entry), "completion");
 }
 
 /**
@@ -9719,7 +9961,8 @@ gtk_entry_set_completion (GtkEntry           *entry,
  *
  * Returns the auxiliary completion object currently in use by @entry.
  *
- * Return value: The auxiliary completion object currently in use by @entry.
+ * Return value: (transfer none): The auxiliary completion object currently
+ *     in use by @entry.
  *
  * Since: 2.4
  */
@@ -9813,7 +10056,7 @@ gtk_entry_set_progress_fraction (GtkEntry *entry,
   g_return_if_fail (GTK_IS_ENTRY (entry));
 
   widget = GTK_WIDGET (entry);
-  private = GTK_ENTRY_GET_PRIVATE (entry);
+  private = entry->priv;
 
   if (private->progress_pulse_mode)
     old_fraction = -1;
@@ -9855,13 +10098,9 @@ gtk_entry_set_progress_fraction (GtkEntry *entry,
 gdouble
 gtk_entry_get_progress_fraction (GtkEntry *entry)
 {
-  GtkEntryPrivate *private;
-
   g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
 
-  private = GTK_ENTRY_GET_PRIVATE (entry);
-
-  return private->progress_fraction;
+  return entry->priv->progress_fraction;
 }
 
 /**
@@ -9882,7 +10121,7 @@ gtk_entry_set_progress_pulse_step (GtkEntry *entry,
 
   g_return_if_fail (GTK_IS_ENTRY (entry));
 
-  private = GTK_ENTRY_GET_PRIVATE (entry);
+  private = entry->priv;
 
   fraction = CLAMP (fraction, 0.0, 1.0);
 
@@ -9909,13 +10148,9 @@ gtk_entry_set_progress_pulse_step (GtkEntry *entry,
 gdouble
 gtk_entry_get_progress_pulse_step (GtkEntry *entry)
 {
-  GtkEntryPrivate *private;
-
   g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
 
-  private = GTK_ENTRY_GET_PRIVATE (entry);
-
-  return private->progress_pulse_fraction;
+  return entry->priv->progress_pulse_fraction;
 }
 
 /**
@@ -9938,7 +10173,7 @@ gtk_entry_progress_pulse (GtkEntry *entry)
 
   g_return_if_fail (GTK_IS_ENTRY (entry));
 
-  private = GTK_ENTRY_GET_PRIVATE (entry);
+  private = entry->priv;
 
   if (private->progress_pulse_mode)
     {
@@ -9974,13 +10209,74 @@ gtk_entry_progress_pulse (GtkEntry *entry)
   gtk_widget_queue_draw (GTK_WIDGET (entry));
 }
 
+/**
+ * gtk_entry_set_placeholder_text:
+ * @entry: a #GtkEntry
+ * @text: a string to be displayed when @entry is empty an unfocused, or %NULL
+ *
+ * Sets text to be displayed in @entry when it is empty and unfocused.
+ * This can be used to give a visual hint of the expected contents of
+ * the #GtkEntry.
+ *
+ * Note that since the placeholder text gets removed when the entry
+ * received focus, using this feature is a bit problematic if the entry
+ * is given the initial focus in a window. Sometimes this can be
+ * worked around by delaying the initial focus setting until the
+ * first key event arrives.
+ *
+ * Since: 3.2
+ **/
+void
+gtk_entry_set_placeholder_text (GtkEntry    *entry,
+                                const gchar *text)
+{
+  GtkEntryPrivate *priv;
+
+  g_return_if_fail (GTK_IS_ENTRY (entry));
+
+  priv = entry->priv;
+
+  if (g_strcmp0 (priv->placeholder_text, text) == 0)
+    return;
+
+  g_free (priv->placeholder_text);
+  priv->placeholder_text = g_strdup (text);
+
+  gtk_entry_recompute (entry);
+
+  g_object_notify (G_OBJECT (entry), "placeholder-text");
+}
+
+/**
+ * gtk_entry_get_placeholder_text:
+ * @entry: a #GtkEntry
+ *
+ * Retrieves the text that will be displayed when @entry is empty and unfocused
+ *
+ * Returns: a pointer to the placeholder text as a string. This string points to internally allocated
+ * storage in the widget and must not be freed, modified or stored.
+ *
+ * Since: 3.2
+ **/
+const gchar *
+gtk_entry_get_placeholder_text (GtkEntry *entry)
+{
+  GtkEntryPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
+
+  priv = entry->priv;
+
+  return priv->placeholder_text;
+}
+
 /* Caps Lock warning for password entries */
 
 static void
 show_capslock_feedback (GtkEntry    *entry,
                         const gchar *text)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
 
   if (gtk_entry_get_icon_storage_type (entry, GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
     {
@@ -9998,7 +10294,7 @@ show_capslock_feedback (GtkEntry    *entry,
 static void
 remove_capslock_feedback (GtkEntry *entry)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
 
   if (priv->caps_lock_warning_shown)
     {
@@ -10011,17 +10307,12 @@ static void
 keymap_state_changed (GdkKeymap *keymap, 
                       GtkEntry  *entry)
 {
-  GtkEntryPrivate *priv = GTK_ENTRY_GET_PRIVATE (entry);
+  GtkEntryPrivate *priv = entry->priv;
   char *text = NULL;
 
   if (gtk_entry_get_display_mode (entry) != DISPLAY_NORMAL && priv->caps_lock_warning)
     { 
-      if (gdk_keymap_get_num_lock_state (keymap)
-          && gdk_keymap_get_caps_lock_state (keymap))
-        text = _("Caps Lock and Num Lock are on");
-      else if (gdk_keymap_get_num_lock_state (keymap))
-        text = _("Num Lock is on");
-      else if (gdk_keymap_get_caps_lock_state (keymap))
+      if (gdk_keymap_get_caps_lock_state (keymap))
         text = _("Caps Lock is on");
     }
 
@@ -10031,5 +10322,170 @@ keymap_state_changed (GdkKeymap *keymap,
     remove_capslock_feedback (entry);
 }
 
-#define __GTK_ENTRY_C__
-#include "gtkaliasdef.c"
+/*
+ * _gtk_entry_set_is_cell_renderer:
+ * @entry: a #GtkEntry
+ * @is_cell_renderer: new value
+ *
+ * This is a helper function for GtkComboBox. A GtkEntry in a GtkComboBox
+ * is supposed to behave like a GtkCellEditable when placed in a combo box.
+ *
+ * I.e take up its allocation and get GtkEntry->is_cell_renderer = TRUE.
+ *
+ */
+void
+_gtk_entry_set_is_cell_renderer (GtkEntry *entry,
+                                 gboolean  is_cell_renderer)
+{
+  entry->priv->is_cell_renderer = is_cell_renderer;
+}
+
+/**
+ * gtk_entry_set_input_purpose:
+ * @entry: a #GtkEntry
+ * @purpose: the purpose
+ *
+ * Sets the #GtkEntry:input-purpose property which
+ * can be used by on-screen keyboards and other input
+ * methods to adjust their behaviour.
+ *
+ * Since: 3.6
+ */
+void
+gtk_entry_set_input_purpose (GtkEntry        *entry,
+                             GtkInputPurpose  purpose)
+
+{
+  g_return_if_fail (GTK_IS_ENTRY (entry));
+
+  if (gtk_entry_get_input_purpose (entry) != purpose)
+    {
+      g_object_set (G_OBJECT (entry->priv->im_context),
+                    "input-purpose", purpose,
+                    NULL);
+
+      g_object_notify (G_OBJECT (entry), "input-purpose");
+    }
+}
+
+/**
+ * gtk_entry_get_input_purpose:
+ * @entry: a #GtkEntry
+ *
+ * Gets the value of the #GtkEntry:input-purpose property.
+ *
+ * Since: 3.6
+ */
+GtkInputPurpose
+gtk_entry_get_input_purpose (GtkEntry *entry)
+{
+  GtkInputPurpose purpose;
+
+  g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_PURPOSE_FREE_FORM);
+
+  g_object_get (G_OBJECT (entry->priv->im_context),
+                "input-purpose", &purpose,
+                NULL);
+
+  return purpose;
+}
+
+/**
+ * gtk_entry_set_input_hints:
+ * @entry: a #GtkEntry
+ * @hints: the hints
+ *
+ * Sets the #GtkEntry:input-hints property, which
+ * allows input methods to fine-tune their behaviour.
+ *
+ * Since: 3.6
+ */
+void
+gtk_entry_set_input_hints (GtkEntry      *entry,
+                           GtkInputHints  hints)
+
+{
+  g_return_if_fail (GTK_IS_ENTRY (entry));
+
+  if (gtk_entry_get_input_hints (entry) != hints)
+    {
+      g_object_set (G_OBJECT (entry->priv->im_context),
+                    "input-hints", hints,
+                    NULL);
+
+      g_object_notify (G_OBJECT (entry), "input-hints");
+    }
+}
+
+/**
+ * gtk_entry_get_input_hints:
+ * @entry: a #GtkEntry
+ *
+ * Gets the value of the #GtkEntry:input-hints property.
+ *
+ * Since: 3.6
+ */
+GtkInputHints
+gtk_entry_get_input_hints (GtkEntry *entry)
+{
+  GtkInputHints hints;
+
+  g_return_val_if_fail (GTK_IS_ENTRY (entry), GTK_INPUT_HINT_NONE);
+
+  g_object_get (G_OBJECT (entry->priv->im_context),
+                "input-hints", &hints,
+                NULL);
+
+  return hints;
+}
+
+/**
+ * gtk_entry_set_attributes:
+ * @entry: a #GtkEntry
+ * @attrs: a #PangoAttrList
+ *
+ * Sets a #PangoAttrList; the attributes in the list are applied to the
+ * entry text.
+ *
+ * Since: 3.6
+ */
+void
+gtk_entry_set_attributes (GtkEntry      *entry,
+                          PangoAttrList *attrs)
+{
+  GtkEntryPrivate *priv = entry->priv;
+  g_return_if_fail (GTK_IS_ENTRY (entry));
+
+  if (attrs)
+    pango_attr_list_ref (attrs);
+
+  if (priv->attrs)
+    pango_attr_list_unref (priv->attrs);
+  priv->attrs = attrs;
+
+  g_object_notify (G_OBJECT (entry), "attributes");
+
+  gtk_entry_recompute (entry);
+  gtk_widget_queue_resize (GTK_WIDGET (entry));
+}
+
+/**
+ * gtk_entry_get_attributes:
+ * @entry: a #GtkEntry
+ *
+ * Gets the attribute list that was set on the entry using
+ * gtk_entry_set_attributes(), if any.
+ *
+ * Return value: (transfer none): the attribute list, or %NULL
+ *     if none was set.
+ *
+ * Since: 3.6
+ */
+PangoAttrList *
+gtk_entry_get_attributes (GtkEntry *entry)
+{
+  g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
+
+  return entry->priv->attrs;
+}
+