]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtktextview.c
Turn off DEBUG_VALIDATION_AND_SCROLLING that got turned on in an
[~andy/gtk] / gtk / gtktextview.c
index 08f016f5de5fb7371179c3de4891ab30391aa714..b378265c7bfb6a703ef79ebb655f91b47a6c5fe1 100644 (file)
 #include "gtkmenuitem.h"
 #include "gtkseparatormenuitem.h"
 #include "gtksettings.h"
-#include "gtksignal.h"
 #include "gtkstock.h"
 #include "gtktextdisplay.h"
 #include "gtktextview.h"
 #include "gtkimmulticontext.h"
 #include "gdk/gdkkeysyms.h"
+#include "gtksizegroup.h"          /* FIXME http://bugzilla.gnome.org/show_bug.cgi?id=72258 */
 #include "gtktextutil.h"
 #include "gtkwindow.h"
-#include <string.h>
 
 /* How scrolling, validation, exposes, etc. work.
  *
@@ -82,9 +81,6 @@
  *
  */
 
-#define SCREEN_WIDTH(widget) text_window_get_width (GTK_TEXT_VIEW (widget)->text_window)
-#define SCREEN_HEIGHT(widget) text_window_get_height (GTK_TEXT_VIEW (widget)->text_window)
-
 #if 0
 #define DEBUG_VALIDATION_AND_SCROLLING
 #endif
@@ -95,6 +91,9 @@
 #define DV(x)
 #endif
 
+#define SCREEN_WIDTH(widget) text_window_get_width (GTK_TEXT_VIEW (widget)->text_window)
+#define SCREEN_HEIGHT(widget) text_window_get_height (GTK_TEXT_VIEW (widget)->text_window)
+
 struct _GtkTextPendingScroll
 {
   GtkTextMark   *mark;
@@ -222,7 +221,7 @@ static void     gtk_text_view_drag_data_received (GtkWidget        *widget,
 static void gtk_text_view_set_scroll_adjustments (GtkTextView   *text_view,
                                                   GtkAdjustment *hadj,
                                                   GtkAdjustment *vadj);
-static void gtk_text_view_popup_menu             (GtkWidget     *widget);
+static gboolean gtk_text_view_popup_menu         (GtkWidget     *widget);
 
 static void gtk_text_view_move_cursor       (GtkTextView           *text_view,
                                              GtkMovementStep        step,
@@ -233,9 +232,11 @@ static void gtk_text_view_page_horizontally (GtkTextView          *text_view,
                                              gboolean              extend_selection);
 static void gtk_text_view_set_anchor       (GtkTextView           *text_view);
 static void gtk_text_view_scroll_pages     (GtkTextView           *text_view,
-                                            gint                   count);
+                                            gint                   count,
+                                            gboolean               extend_selection);
 static void gtk_text_view_scroll_hpages    (GtkTextView           *text_view,
-                                            gint                   count);
+                                            gint                   count,
+                                            gboolean               extend_selection);
 static void gtk_text_view_insert_at_cursor (GtkTextView           *text_view,
                                             const gchar           *str);
 static void gtk_text_view_delete_from_cursor (GtkTextView           *text_view,
@@ -312,9 +313,10 @@ static void gtk_text_view_queue_scroll           (GtkTextView   *text_view,
                                                   gdouble        xalign,
                                                   gdouble        yalign);
 
-static gboolean gtk_text_view_flush_scroll       (GtkTextView *text_view);
-static void     gtk_text_view_update_adjustments (GtkTextView *text_view);
-static void     gtk_text_view_invalidate         (GtkTextView *text_view);
+static gboolean gtk_text_view_flush_scroll         (GtkTextView *text_view);
+static void     gtk_text_view_update_adjustments   (GtkTextView *text_view);
+static void     gtk_text_view_invalidate           (GtkTextView *text_view);
+static void     gtk_text_view_flush_first_validate (GtkTextView *text_view);
 
 static void gtk_text_view_update_im_spot_location (GtkTextView *text_view);
 
@@ -325,7 +327,7 @@ static void gtk_text_view_remove (GtkContainer *container,
                                   GtkWidget    *child);
 static void gtk_text_view_forall (GtkContainer *container,
                                   gboolean      include_internals,
-                                  GtkCallback   callback,
+                                 GtkCallback   callback,
                                   gpointer      callback_data);
 
 /* FIXME probably need the focus methods. */
@@ -386,8 +388,6 @@ static void           text_window_invalidate_rect (GtkTextWindow     *win,
 
 static gint           text_window_get_width       (GtkTextWindow     *win);
 static gint           text_window_get_height      (GtkTextWindow     *win);
-static void           text_window_get_allocation  (GtkTextWindow     *win,
-                                                   GdkRectangle      *rect);
 
 
 enum
@@ -399,39 +399,40 @@ enum
   TARGET_TEXT_BUFFER_CONTENTS
 };
 
-static GtkTargetEntry target_table[] = {
+static const GtkTargetEntry target_table[] = {
   { "GTK_TEXT_BUFFER_CONTENTS", GTK_TARGET_SAME_APP,
     TARGET_TEXT_BUFFER_CONTENTS },
   { "UTF8_STRING", 0, TARGET_UTF8_STRING },
   { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT },
   { "TEXT", 0, TARGET_TEXT },
-  { "text/plain", 0, TARGET_STRING },
   { "STRING",     0, TARGET_STRING }
 };
 
 static GtkContainerClass *parent_class = NULL;
 static guint signals[LAST_SIGNAL] = { 0 };
 
-GtkType
+GType
 gtk_text_view_get_type (void)
 {
-  static GtkType our_type = 0;
+  static GType our_type = 0;
 
   if (our_type == 0)
     {
-      static const GtkTypeInfo our_info =
+      static const GTypeInfo our_info =
       {
-        "GtkTextView",
-        sizeof (GtkTextView),
-        sizeof (GtkTextViewClass),
-        (GtkClassInitFunc) gtk_text_view_class_init,
-        (GtkObjectInitFunc) gtk_text_view_init,
-        /* reserved_1 */ NULL,
-        /* reserved_2 */ NULL,
-        (GtkClassInitFunc) NULL
+       sizeof (GtkTextViewClass),
+       NULL,           /* base_init */
+       NULL,           /* base_finalize */
+       (GClassInitFunc) gtk_text_view_class_init,
+       NULL,           /* class_finalize */
+       NULL,           /* class_data */
+       sizeof (GtkTextView),
+       0,              /* n_preallocs */
+       (GInstanceInitFunc) gtk_text_view_init,
       };
 
-      our_type = gtk_type_unique (GTK_TYPE_CONTAINER, &our_info);
+      our_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkTextView",
+                                        &our_info, 0);
     }
 
   return our_type;
@@ -448,16 +449,16 @@ add_move_binding (GtkBindingSet  *binding_set,
 
   gtk_binding_entry_add_signal (binding_set, keyval, modmask,
                                 "move_cursor", 3,
-                                GTK_TYPE_ENUM, step,
-                                GTK_TYPE_INT, count,
-                                GTK_TYPE_BOOL, FALSE);
+                                G_TYPE_ENUM, step,
+                                G_TYPE_INT, count,
+                                G_TYPE_BOOLEAN, FALSE);
 
   /* Selection-extending version */
   gtk_binding_entry_add_signal (binding_set, keyval, modmask | GDK_SHIFT_MASK,
                                 "move_cursor", 3,
-                                GTK_TYPE_ENUM, step,
-                                GTK_TYPE_INT, count,
-                                GTK_TYPE_BOOL, TRUE);
+                                G_TYPE_ENUM, step,
+                                G_TYPE_INT, count,
+                                G_TYPE_BOOLEAN, TRUE);
 }
 
 static void
@@ -469,7 +470,7 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
   GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
   GtkBindingSet *binding_set;
 
-  parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
+  parent_class = g_type_class_peek_parent (klass);
 
   /* Default handlers and virtual methods
    */
@@ -632,118 +633,130 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
                                                         G_PARAM_READWRITE));
 
   
-  /*
-   * Style properties
-   */
-
-  gtk_widget_class_install_style_property (widget_class,
-                                          g_param_spec_boxed ("cursor_color",
-                                                              _("Cursor color"),
-                                                              _("Color with which to draw insertion cursor"),
-                                                              GDK_TYPE_COLOR,
-                                                              G_PARAM_READABLE));
-
-
   /*
    * Signals
    */
 
   signals[MOVE_CURSOR] =
-    gtk_signal_new ("move_cursor",
-                    GTK_RUN_LAST | GTK_RUN_ACTION,
-                    GTK_CLASS_TYPE (object_class),
-                    GTK_SIGNAL_OFFSET (GtkTextViewClass, move_cursor),
-                    _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
-                    GTK_TYPE_NONE, 3, GTK_TYPE_MOVEMENT_STEP, GTK_TYPE_INT, GTK_TYPE_BOOL);
+    g_signal_new ("move_cursor",
+                 G_OBJECT_CLASS_TYPE (gobject_class),
+                 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                 G_STRUCT_OFFSET (GtkTextViewClass, move_cursor),
+                 NULL, NULL,
+                 _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
+                 G_TYPE_NONE, 3,
+                 GTK_TYPE_MOVEMENT_STEP,
+                 G_TYPE_INT,
+                 G_TYPE_BOOLEAN);
 
   signals[PAGE_HORIZONTALLY] =
-    gtk_signal_new ("page_horizontally",
-                    GTK_RUN_LAST | GTK_RUN_ACTION,
-                    GTK_CLASS_TYPE (object_class),
-                    GTK_SIGNAL_OFFSET (GtkTextViewClass, page_horizontally),
-                    _gtk_marshal_VOID__INT_BOOLEAN,
-                    GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_BOOL);
+    g_signal_new ("page_horizontally",
+                 G_OBJECT_CLASS_TYPE (gobject_class),
+                 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                 G_STRUCT_OFFSET (GtkTextViewClass, page_horizontally),
+                 NULL, NULL,
+                 _gtk_marshal_VOID__INT_BOOLEAN,
+                 G_TYPE_NONE, 2,
+                 G_TYPE_INT,
+                 G_TYPE_BOOLEAN);
   
   signals[SET_ANCHOR] =
-    gtk_signal_new ("set_anchor",
-                    GTK_RUN_LAST | GTK_RUN_ACTION,
-                    GTK_CLASS_TYPE (object_class),
-                    GTK_SIGNAL_OFFSET (GtkTextViewClass, set_anchor),
-                    _gtk_marshal_VOID__VOID,
-                    GTK_TYPE_NONE, 0);
+    g_signal_new ("set_anchor",
+                 G_OBJECT_CLASS_TYPE (gobject_class),
+                 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                 G_STRUCT_OFFSET (GtkTextViewClass, set_anchor),
+                 NULL, NULL,
+                 _gtk_marshal_VOID__VOID,
+                 G_TYPE_NONE, 0);
 
   signals[INSERT_AT_CURSOR] =
-    gtk_signal_new ("insert_at_cursor",
-                    GTK_RUN_LAST | GTK_RUN_ACTION,
-                    GTK_CLASS_TYPE (object_class),
-                    GTK_SIGNAL_OFFSET (GtkTextViewClass, insert_at_cursor),
-                    _gtk_marshal_VOID__STRING,
-                    GTK_TYPE_NONE, 1, GTK_TYPE_STRING);
+    g_signal_new ("insert_at_cursor",
+                 G_OBJECT_CLASS_TYPE (gobject_class),
+                 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                 G_STRUCT_OFFSET (GtkTextViewClass, insert_at_cursor),
+                 NULL, NULL,
+                 _gtk_marshal_VOID__STRING,
+                 G_TYPE_NONE, 1,
+                 G_TYPE_STRING);
 
   signals[DELETE_FROM_CURSOR] =
-    gtk_signal_new ("delete_from_cursor",
-                    GTK_RUN_LAST | GTK_RUN_ACTION,
-                    GTK_CLASS_TYPE (object_class),
-                    GTK_SIGNAL_OFFSET (GtkTextViewClass, delete_from_cursor),
-                    _gtk_marshal_VOID__ENUM_INT,
-                    GTK_TYPE_NONE, 2, GTK_TYPE_DELETE_TYPE, GTK_TYPE_INT);
+    g_signal_new ("delete_from_cursor",
+                 G_OBJECT_CLASS_TYPE (gobject_class),
+                 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                 G_STRUCT_OFFSET (GtkTextViewClass, delete_from_cursor),
+                 NULL, NULL,
+                 _gtk_marshal_VOID__ENUM_INT,
+                 G_TYPE_NONE, 2,
+                 GTK_TYPE_DELETE_TYPE,
+                 G_TYPE_INT);
 
   signals[CUT_CLIPBOARD] =
-    gtk_signal_new ("cut_clipboard",
-                    GTK_RUN_LAST | GTK_RUN_ACTION,
-                    GTK_CLASS_TYPE (object_class),
-                    GTK_SIGNAL_OFFSET (GtkTextViewClass, cut_clipboard),
-                    _gtk_marshal_VOID__VOID,
-                    GTK_TYPE_NONE, 0);
+    g_signal_new ("cut_clipboard",
+                 G_OBJECT_CLASS_TYPE (gobject_class),
+                 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                 G_STRUCT_OFFSET (GtkTextViewClass, cut_clipboard),
+                 NULL, NULL,
+                 _gtk_marshal_VOID__VOID,
+                 G_TYPE_NONE, 0);
 
   signals[COPY_CLIPBOARD] =
-    gtk_signal_new ("copy_clipboard",
-                    GTK_RUN_LAST | GTK_RUN_ACTION,
-                    GTK_CLASS_TYPE (object_class),
-                    GTK_SIGNAL_OFFSET (GtkTextViewClass, copy_clipboard),
-                    _gtk_marshal_VOID__VOID,
-                    GTK_TYPE_NONE, 0);
+    g_signal_new ("copy_clipboard",
+                 G_OBJECT_CLASS_TYPE (gobject_class),
+                 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                 G_STRUCT_OFFSET (GtkTextViewClass, copy_clipboard),
+                 NULL, NULL,
+                 _gtk_marshal_VOID__VOID,
+                 G_TYPE_NONE, 0);
 
   signals[PASTE_CLIPBOARD] =
-    gtk_signal_new ("paste_clipboard",
-                    GTK_RUN_LAST | GTK_RUN_ACTION,
-                    GTK_CLASS_TYPE (object_class),
-                    GTK_SIGNAL_OFFSET (GtkTextViewClass, paste_clipboard),
-                    _gtk_marshal_VOID__VOID,
-                    GTK_TYPE_NONE, 0);
+    g_signal_new ("paste_clipboard",
+                 G_OBJECT_CLASS_TYPE (gobject_class),
+                 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                 G_STRUCT_OFFSET (GtkTextViewClass, paste_clipboard),
+                 NULL, NULL,
+                 _gtk_marshal_VOID__VOID,
+                 G_TYPE_NONE, 0);
 
   signals[TOGGLE_OVERWRITE] =
-    gtk_signal_new ("toggle_overwrite",
-                    GTK_RUN_LAST | GTK_RUN_ACTION,
-                    GTK_CLASS_TYPE (object_class),
-                    GTK_SIGNAL_OFFSET (GtkTextViewClass, toggle_overwrite),
-                    _gtk_marshal_VOID__VOID,
-                    GTK_TYPE_NONE, 0);
+    g_signal_new ("toggle_overwrite",
+                 G_OBJECT_CLASS_TYPE (gobject_class),
+                 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                 G_STRUCT_OFFSET (GtkTextViewClass, toggle_overwrite),
+                 NULL, NULL,
+                 _gtk_marshal_VOID__VOID,
+                 G_TYPE_NONE, 0);
 
   signals[MOVE_FOCUS] =
-    gtk_signal_new ("move_focus",
-                    GTK_RUN_LAST | GTK_RUN_ACTION,
-                    GTK_CLASS_TYPE (object_class),
-                    GTK_SIGNAL_OFFSET (GtkTextViewClass, move_focus),
-                    _gtk_marshal_VOID__ENUM,
-                    GTK_TYPE_NONE, 1, GTK_TYPE_DIRECTION_TYPE);
+    g_signal_new ("move_focus",
+                 G_OBJECT_CLASS_TYPE (gobject_class),
+                 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                 G_STRUCT_OFFSET (GtkTextViewClass, move_focus),
+                 NULL, NULL,
+                 _gtk_marshal_VOID__ENUM,
+                 G_TYPE_NONE, 1,
+                 GTK_TYPE_DIRECTION_TYPE);
   
   signals[SET_SCROLL_ADJUSTMENTS] =
-    gtk_signal_new ("set_scroll_adjustments",
-                    GTK_RUN_LAST,
-                    GTK_CLASS_TYPE (object_class),
-                    GTK_SIGNAL_OFFSET (GtkTextViewClass, set_scroll_adjustments),
-                    _gtk_marshal_VOID__OBJECT_OBJECT,
-                    GTK_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
+    g_signal_new ("set_scroll_adjustments",
+                 G_OBJECT_CLASS_TYPE (gobject_class),
+                 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                 G_STRUCT_OFFSET (GtkTextViewClass, set_scroll_adjustments),
+                 NULL, NULL,
+                 _gtk_marshal_VOID__OBJECT_OBJECT,
+                 G_TYPE_NONE, 2,
+                 GTK_TYPE_ADJUSTMENT,
+                 GTK_TYPE_ADJUSTMENT);
   widget_class->set_scroll_adjustments_signal = signals[SET_SCROLL_ADJUSTMENTS];
 
   signals[POPULATE_POPUP] =
-    gtk_signal_new ("populate_popup",
-                    GTK_RUN_LAST,
-                    GTK_CLASS_TYPE (object_class),
-                    GTK_SIGNAL_OFFSET (GtkTextViewClass, populate_popup),
-                    _gtk_marshal_VOID__OBJECT,
-                    GTK_TYPE_NONE, 1, GTK_TYPE_MENU);
+    g_signal_new ("populate_popup",
+                 G_OBJECT_CLASS_TYPE (gobject_class),
+                 G_SIGNAL_RUN_LAST,
+                 G_STRUCT_OFFSET (GtkTextViewClass, populate_popup),
+                 NULL, NULL,
+                 _gtk_marshal_VOID__OBJECT,
+                 G_TYPE_NONE, 1,
+                 GTK_TYPE_MENU);
   
   /*
    * Key bindings
@@ -764,12 +777,6 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
   add_move_binding (binding_set, GDK_KP_Left, 0,
                     GTK_MOVEMENT_VISUAL_POSITIONS, -1);
   
-  add_move_binding (binding_set, GDK_f, GDK_CONTROL_MASK,
-                    GTK_MOVEMENT_LOGICAL_POSITIONS, 1);
-
-  add_move_binding (binding_set, GDK_b, GDK_CONTROL_MASK,
-                    GTK_MOVEMENT_LOGICAL_POSITIONS, -1);
-
   add_move_binding (binding_set, GDK_Right, GDK_CONTROL_MASK,
                     GTK_MOVEMENT_WORDS, 1);
 
@@ -782,7 +789,6 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
   add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK,
                     GTK_MOVEMENT_WORDS, 1);
   
-  /* Eventually we want to move by display lines, not paragraphs */
   add_move_binding (binding_set, GDK_Up, 0,
                     GTK_MOVEMENT_DISPLAY_LINES, -1);
 
@@ -795,12 +801,6 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
   add_move_binding (binding_set, GDK_KP_Down, 0,
                     GTK_MOVEMENT_DISPLAY_LINES, 1);
   
-  add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
-                    GTK_MOVEMENT_DISPLAY_LINES, -1);
-
-  add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
-                    GTK_MOVEMENT_DISPLAY_LINES, 1);
-
   add_move_binding (binding_set, GDK_Up, GDK_CONTROL_MASK,
                     GTK_MOVEMENT_PARAGRAPHS, -1);
 
@@ -813,18 +813,6 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
   add_move_binding (binding_set, GDK_KP_Down, GDK_CONTROL_MASK,
                     GTK_MOVEMENT_PARAGRAPHS, 1);
   
-  add_move_binding (binding_set, GDK_a, GDK_CONTROL_MASK,
-                    GTK_MOVEMENT_PARAGRAPH_ENDS, -1);
-
-  add_move_binding (binding_set, GDK_e, GDK_CONTROL_MASK,
-                    GTK_MOVEMENT_PARAGRAPH_ENDS, 1);
-
-  add_move_binding (binding_set, GDK_f, GDK_MOD1_MASK,
-                    GTK_MOVEMENT_WORDS, 1);
-
-  add_move_binding (binding_set, GDK_b, GDK_MOD1_MASK,
-                    GTK_MOVEMENT_WORDS, -1);
-
   add_move_binding (binding_set, GDK_Home, 0,
                     GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
 
@@ -861,166 +849,133 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
   add_move_binding (binding_set, GDK_KP_Page_Down, 0,
                     GTK_MOVEMENT_PAGES, 1);
 
+  /* Select all
+   */
+  gtk_binding_entry_add_signal (binding_set, GDK_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,
+                               "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_Page_Up, GDK_CONTROL_MASK,
-                                "page_horizontally", 2,
-                                GTK_TYPE_INT, -1,
-                                GTK_TYPE_BOOL, FALSE);
+                               "page_horizontally", 2,
+                               G_TYPE_INT, -1,
+                               G_TYPE_BOOLEAN, FALSE);
 
   gtk_binding_entry_add_signal (binding_set, GDK_Page_Up, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
-                                "page_horizontally", 2,
-                                GTK_TYPE_INT, -1,
-                                GTK_TYPE_BOOL, TRUE);
+                               "page_horizontally", 2,
+                               G_TYPE_INT, -1,
+                               G_TYPE_BOOLEAN, TRUE);
 
   gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Up, GDK_CONTROL_MASK,
-                                "page_horizontally", 2,
-                                GTK_TYPE_INT, -1,
-                                GTK_TYPE_BOOL, FALSE);
+                               "page_horizontally", 2,
+                               G_TYPE_INT, -1,
+                               G_TYPE_BOOLEAN, FALSE);
 
   gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Up, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
-                                "page_horizontally", 2,
-                                GTK_TYPE_INT, -1,
-                                GTK_TYPE_BOOL, TRUE);
+                               "page_horizontally", 2,
+                               G_TYPE_INT, -1,
+                               G_TYPE_BOOLEAN, TRUE);
 
   gtk_binding_entry_add_signal (binding_set, GDK_Page_Down, GDK_CONTROL_MASK,
-                                "page_horizontally", 2,
-                                GTK_TYPE_INT, 1,
-                                GTK_TYPE_BOOL, FALSE);
+                               "page_horizontally", 2,
+                               G_TYPE_INT, 1,
+                               G_TYPE_BOOLEAN, FALSE);
 
   gtk_binding_entry_add_signal (binding_set, GDK_Page_Down, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
-                                "page_horizontally", 2,
-                                GTK_TYPE_INT, 1,
-                                GTK_TYPE_BOOL, TRUE);
+                               "page_horizontally", 2,
+                               G_TYPE_INT, 1,
+                               G_TYPE_BOOLEAN, TRUE);
 
   gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Down, GDK_CONTROL_MASK,
-                                "page_horizontally", 2,
-                                GTK_TYPE_INT, 1,
-                                GTK_TYPE_BOOL, FALSE);
+                               "page_horizontally", 2,
+                               G_TYPE_INT, 1,
+                               G_TYPE_BOOLEAN, FALSE);
 
   gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Down, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
-                                "page_horizontally", 2,
-                                GTK_TYPE_INT, 1,
-                                GTK_TYPE_BOOL, TRUE);
-  
-  /* Setting the cut/paste/copy anchor */
-  gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
-                                "set_anchor", 0);
-  gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_CONTROL_MASK,
-                                "set_anchor", 0);
+                               "page_horizontally", 2,
+                               G_TYPE_INT, 1,
+                               G_TYPE_BOOLEAN, TRUE);
   
   /* Deleting text */
   gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0,
-                                "delete_from_cursor", 2,
-                                GTK_TYPE_ENUM, GTK_DELETE_CHARS,
-                                GTK_TYPE_INT, 1);
+                               "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,
-                                "delete_from_cursor", 2,
-                                GTK_TYPE_ENUM, GTK_DELETE_CHARS,
-                                GTK_TYPE_INT, 1);
+                               "delete_from_cursor", 2,
+                               G_TYPE_ENUM, GTK_DELETE_CHARS,
+                               G_TYPE_INT, 1);
   
-  gtk_binding_entry_add_signal (binding_set, GDK_d, GDK_CONTROL_MASK,
-                                "delete_from_cursor", 2,
-                                GTK_TYPE_ENUM, GTK_DELETE_CHARS,
-                                GTK_TYPE_INT, 1);
-
   gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0,
-                                "delete_from_cursor", 2,
-                                GTK_TYPE_ENUM, GTK_DELETE_CHARS,
-                                GTK_TYPE_INT, -1);
+                               "delete_from_cursor", 2,
+                               G_TYPE_ENUM, GTK_DELETE_CHARS,
+                               G_TYPE_INT, -1);
+
+  /* Make this do the same as Backspace, to help with mis-typing */
+  gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_SHIFT_MASK,
+                               "delete_from_cursor", 2,
+                               G_TYPE_ENUM, GTK_DELETE_CHARS,
+                               G_TYPE_INT, -1);
 
   gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_CONTROL_MASK,
-                                "delete_from_cursor", 2,
-                                GTK_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
-                                GTK_TYPE_INT, 1);
+                               "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,
-                                "delete_from_cursor", 2,
-                                GTK_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
-                                GTK_TYPE_INT, 1);
+                               "delete_from_cursor", 2,
+                               G_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
+                               G_TYPE_INT, 1);
   
-  gtk_binding_entry_add_signal (binding_set, GDK_d, GDK_MOD1_MASK,
-                                "delete_from_cursor", 2,
-                                GTK_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
-                                GTK_TYPE_INT, 1);
-
   gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, GDK_CONTROL_MASK,
-                                "delete_from_cursor", 2,
-                                GTK_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
-                                GTK_TYPE_INT, -1);
-
-  gtk_binding_entry_add_signal (binding_set, GDK_k, GDK_CONTROL_MASK,
-                                "delete_from_cursor", 2,
-                                GTK_TYPE_ENUM, GTK_DELETE_PARAGRAPH_ENDS,
-                                GTK_TYPE_INT, 1);
-
-  gtk_binding_entry_add_signal (binding_set, GDK_u, GDK_CONTROL_MASK,
-                                "delete_from_cursor", 2,
-                                GTK_TYPE_ENUM, GTK_DELETE_PARAGRAPHS,
-                                GTK_TYPE_INT, 1);
-
-  gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_MOD1_MASK,
-                                "delete_from_cursor", 2,
-                                GTK_TYPE_ENUM, GTK_DELETE_WHITESPACE,
-                                GTK_TYPE_INT, 1);
-  gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_MOD1_MASK,
-                                "delete_from_cursor", 2,
-                                GTK_TYPE_ENUM, GTK_DELETE_WHITESPACE,
-                                GTK_TYPE_INT, 1);
-  gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_MOD1_MASK,
-                                "insert_at_cursor", 1,
-                                GTK_TYPE_STRING, " ");
-  gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_MOD1_MASK,
-                                "insert_at_cursor", 1,
-                                GTK_TYPE_STRING, " ");
-  
-  gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_MOD1_MASK,
-                                "delete_from_cursor", 2,
-                                GTK_TYPE_ENUM, GTK_DELETE_WHITESPACE,
-                                GTK_TYPE_INT, 1);
+                               "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,
-                                "cut_clipboard", 0);
-
-  gtk_binding_entry_add_signal (binding_set, GDK_w, GDK_CONTROL_MASK,
-                                "cut_clipboard", 0);
-
+                               "cut_clipboard", 0);
   gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK,
-                                "copy_clipboard", 0);
-
+                               "copy_clipboard", 0);
   gtk_binding_entry_add_signal (binding_set, GDK_v, GDK_CONTROL_MASK,
-                                "paste_clipboard", 0);
+                               "paste_clipboard", 0);
 
-  gtk_binding_entry_add_signal (binding_set, GDK_y, GDK_CONTROL_MASK,
-                                "paste_clipboard", 0);
+  gtk_binding_entry_add_signal (binding_set, GDK_Delete, GDK_SHIFT_MASK,
+                               "cut_clipboard", 0);
+  gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_CONTROL_MASK,
+                               "copy_clipboard", 0);
+  gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK,
+                               "paste_clipboard", 0);
 
   /* Overwrite */
   gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0,
-                                "toggle_overwrite", 0);
+                               "toggle_overwrite", 0);
   gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 0,
-                                "toggle_overwrite", 0);
+                               "toggle_overwrite", 0);
 
   /* Control-tab focus motion */
   gtk_binding_entry_add_signal (binding_set, GDK_Tab, GDK_CONTROL_MASK,
-                                "move_focus", 1,
-                                GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
+                               "move_focus", 1,
+                               GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
   gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, GDK_CONTROL_MASK,
-                                "move_focus", 1,
-                                GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
-  gtk_binding_entry_add_signal (binding_set, GDK_ISO_Left_Tab, GDK_CONTROL_MASK,
-                                "move_focus", 1,
-                                GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
+                               "move_focus", 1,
+                               GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
   
   gtk_binding_entry_add_signal (binding_set, GDK_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
-                                "move_focus", 1,
-                                GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
+                               "move_focus", 1,
+                               GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
   gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
-                                "move_focus", 1,
-                                GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
-  gtk_binding_entry_add_signal (binding_set, GDK_ISO_Left_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
-                                "move_focus", 1,
-                                GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
+                               "move_focus", 1,
+                               GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
 }
 
 static void
@@ -1057,13 +1012,13 @@ gtk_text_view_init (GtkTextView *text_view)
    */
   text_view->im_context = gtk_im_multicontext_new ();
 
-  g_signal_connect (G_OBJECT (text_view->im_context), "commit",
+  g_signal_connect (text_view->im_context, "commit",
                     G_CALLBACK (gtk_text_view_commit_handler), text_view);
-  g_signal_connect (G_OBJECT (text_view->im_context), "preedit_changed",
+  g_signal_connect (text_view->im_context, "preedit_changed",
                    G_CALLBACK (gtk_text_view_preedit_changed_handler), text_view);
-  g_signal_connect (G_OBJECT (text_view->im_context), "retrieve_surrounding",
+  g_signal_connect (text_view->im_context, "retrieve_surrounding",
                    G_CALLBACK (gtk_text_view_retrieve_surrounding_handler), text_view);
-  g_signal_connect (G_OBJECT (text_view->im_context), "delete_surrounding",
+  g_signal_connect (text_view->im_context, "delete_surrounding",
                    G_CALLBACK (gtk_text_view_delete_surrounding_handler), text_view);
 
   text_view->cursor_visible = TRUE;
@@ -1093,7 +1048,7 @@ gtk_text_view_init (GtkTextView *text_view)
 GtkWidget*
 gtk_text_view_new (void)
 {
-  return GTK_WIDGET (gtk_type_new (gtk_text_view_get_type ()));
+  return g_object_new (GTK_TYPE_TEXT_VIEW, NULL);
 }
 
 /**
@@ -1166,14 +1121,18 @@ gtk_text_view_set_buffer (GtkTextView   *text_view,
 
       g_slist_free (copy);
 
-      g_signal_handlers_disconnect_by_func (G_OBJECT (text_view->buffer),
-                                            gtk_text_view_mark_set_handler, text_view);
-      g_object_unref (G_OBJECT (text_view->buffer));
+      g_signal_handlers_disconnect_by_func (text_view->buffer,
+                                           gtk_text_view_mark_set_handler,
+                                           text_view);
+      g_object_unref (text_view->buffer);
       text_view->dnd_mark = NULL;
 
       if (GTK_WIDGET_REALIZED (text_view))
-       gtk_text_buffer_remove_selection_clipboard (text_view->buffer,
-                                                   gtk_clipboard_get (GDK_SELECTION_PRIMARY));
+       {
+         GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
+                                                             GDK_SELECTION_PRIMARY);
+         gtk_text_buffer_remove_selection_clipboard (text_view->buffer, clipboard);
+       }
     }
 
   text_view->buffer = buffer;
@@ -1182,7 +1141,7 @@ gtk_text_view_set_buffer (GtkTextView   *text_view,
     {
       GtkTextIter start;
 
-      g_object_ref (G_OBJECT (buffer));
+      g_object_ref (buffer);
 
       if (text_view->layout)
         gtk_text_layout_set_buffer (text_view->layout, buffer);
@@ -1199,17 +1158,21 @@ gtk_text_view_set_buffer (GtkTextView   *text_view,
 
       text_view->first_para_pixels = 0;
 
-      g_signal_connect (G_OBJECT (text_view->buffer), "mark_set",
+      g_signal_connect (text_view->buffer, "mark_set",
                        G_CALLBACK (gtk_text_view_mark_set_handler), text_view);
 
       if (GTK_WIDGET_REALIZED (text_view))
-       gtk_text_buffer_add_selection_clipboard (text_view->buffer,
-                                                gtk_clipboard_get (GDK_SELECTION_PRIMARY));
+       {
+         GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
+                                                             GDK_SELECTION_PRIMARY);
+         gtk_text_buffer_add_selection_clipboard (text_view->buffer, clipboard);
+       }
     }
   
   if (GTK_WIDGET_VISIBLE (text_view))
     gtk_widget_queue_draw (GTK_WIDGET (text_view));
-  
+
+  DV(g_print ("Invalidating due to set_buffer\n"));
   gtk_text_view_invalidate (text_view);
 }
 
@@ -1221,7 +1184,7 @@ get_buffer (GtkTextView *text_view)
       GtkTextBuffer *b;
       b = gtk_text_buffer_new (NULL);
       gtk_text_view_set_buffer (text_view, b);
-      g_object_unref (G_OBJECT (b));
+      g_object_unref (b);
     }
 
   return text_view->buffer;
@@ -1267,8 +1230,9 @@ gtk_text_view_get_iter_at_location (GtkTextView *text_view,
 {
   g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
   g_return_if_fail (iter != NULL);
-  g_return_if_fail (text_view->layout != NULL);
 
+  gtk_text_view_ensure_layout (text_view);
+  
   gtk_text_layout_get_iter_at_pixel (text_view->layout,
                                      iter,
                                      x,
@@ -1295,6 +1259,8 @@ gtk_text_view_get_iter_location (GtkTextView       *text_view,
   g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
   g_return_if_fail (gtk_text_iter_get_buffer (iter) == get_buffer (text_view));
 
+  gtk_text_view_ensure_layout (text_view);
+  
   gtk_text_layout_get_iter_location (text_view->layout, iter, location);
 }
 
@@ -1319,6 +1285,8 @@ gtk_text_view_get_line_yrange (GtkTextView       *text_view,
   g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
   g_return_if_fail (gtk_text_iter_get_buffer (iter) == get_buffer (text_view));
 
+  gtk_text_view_ensure_layout (text_view);
+  
   gtk_text_layout_get_line_yrange (text_view->layout,
                                    iter,
                                    y,
@@ -1346,6 +1314,8 @@ gtk_text_view_get_line_at_y (GtkTextView *text_view,
 {
   g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
 
+  gtk_text_view_ensure_layout (text_view);
+  
   gtk_text_layout_get_line_at_y (text_view->layout,
                                  target_iter,
                                  y,
@@ -1561,10 +1531,20 @@ free_pending_scroll (GtkTextPendingScroll *scroll)
   if (!gtk_text_mark_get_deleted (scroll->mark))
     gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (scroll->mark),
                                  scroll->mark);
-  g_object_unref (G_OBJECT (scroll->mark));
+  g_object_unref (scroll->mark);
   g_free (scroll);
 }
 
+static void
+cancel_pending_scroll (GtkTextView *text_view)
+{
+  if (text_view->pending_scroll)
+    {
+      free_pending_scroll (text_view->pending_scroll);
+      text_view->pending_scroll = NULL;
+    }
+}
+    
 static void
 gtk_text_view_queue_scroll (GtkTextView   *text_view,
                             GtkTextMark   *mark,
@@ -1592,10 +1572,9 @@ gtk_text_view_queue_scroll (GtkTextView   *text_view,
                                               &iter,
                                               gtk_text_mark_get_left_gravity (mark));
 
-  g_object_ref (G_OBJECT (scroll->mark));
+  g_object_ref (scroll->mark);
   
-  if (text_view->pending_scroll)
-    free_pending_scroll (text_view->pending_scroll);
+  cancel_pending_scroll (text_view);
 
   text_view->pending_scroll = scroll;
 }
@@ -1606,11 +1585,17 @@ gtk_text_view_flush_scroll (GtkTextView *text_view)
   GtkTextIter iter;
   GtkTextPendingScroll *scroll;
   gboolean retval;
+  GtkWidget *widget;
+
+  widget = GTK_WIDGET (text_view);
   
   DV(g_print(G_STRLOC"\n"));
   
   if (text_view->pending_scroll == NULL)
-    return FALSE;
+    {
+      DV (g_print ("in flush scroll, no pending scroll\n"));
+      return FALSE;
+    }
 
   scroll = text_view->pending_scroll;
 
@@ -1619,11 +1604,17 @@ gtk_text_view_flush_scroll (GtkTextView *text_view)
   
   gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, scroll->mark);
 
-  /* Validate arbitrary area around the scroll destination, so the adjustment
-   * can meaningfully point into that area
+  /* Validate area around the scroll destination, so the adjustment
+   * can meaningfully point into that area. We must validate
+   * enough area to be sure that after we scroll, everything onscreen
+   * is valid; otherwise, validation will maintain the first para
+   * in one place, but may push the target iter off the bottom of
+   * the screen.
    */
   DV(g_print (">Validating scroll destination ("G_STRLOC")\n"));
-  gtk_text_layout_validate_yrange (text_view->layout, &iter, -300, 300);
+  gtk_text_layout_validate_yrange (text_view->layout, &iter,
+                                   - (widget->allocation.height * 2),
+                                   widget->allocation.height * 2);
   
   DV(g_print (">Done validating scroll destination ("G_STRLOC")\n"));
 
@@ -1658,13 +1649,13 @@ gtk_text_view_set_adjustment_upper (GtkAdjustment *adj, gdouble upper)
           value_changed = TRUE;
         }
 
-      gtk_signal_emit_by_name (GTK_OBJECT (adj), "changed");
+      gtk_adjustment_changed (adj);
       DV(g_print(">Changed adj upper to %g ("G_STRLOC")\n", upper));
       
       if (value_changed)
         {
           DV(g_print(">Changed adj value because upper decreased ("G_STRLOC")\n"));
-          gtk_signal_emit_by_name (GTK_OBJECT (adj), "value_changed");
+         gtk_adjustment_value_changed (adj);
         }
     }
 }
@@ -1704,8 +1695,8 @@ gtk_text_view_update_adjustments (GtkTextView *text_view)
       text_view->vadjustment->page_increment =
         SCREEN_HEIGHT (text_view) * 0.9;
 
-      gtk_signal_emit_by_name (GTK_OBJECT (get_hadjustment (text_view)), "changed");
-      gtk_signal_emit_by_name (GTK_OBJECT (get_hadjustment (text_view)), "changed");
+      gtk_adjustment_changed (get_hadjustment (text_view));
+      gtk_adjustment_changed (get_vadjustment (text_view));
     }
 }
 
@@ -2428,6 +2419,7 @@ gtk_text_view_remove_validate_idles (GtkTextView *text_view)
 {
   if (text_view->first_validate_idle != 0)
     {
+      DV (g_print ("Removing first validate idle: %s\n", G_STRLOC));
       g_source_remove (text_view->first_validate_idle);
       text_view->first_validate_idle = 0;
     }
@@ -2468,16 +2460,15 @@ gtk_text_view_finalize (GObject *object)
   gtk_text_view_destroy_layout (text_view);
   gtk_text_view_set_buffer (text_view, NULL);
   
-  if (text_view->pending_scroll)
-    {
-      free_pending_scroll (text_view->pending_scroll);
-      text_view->pending_scroll = NULL;
-    }
+  cancel_pending_scroll (text_view);
+
+  if (text_view->tabs)
+    pango_tab_array_free (text_view->tabs);
   
   if (text_view->hadjustment)
-    g_object_unref (G_OBJECT (text_view->hadjustment));
+    g_object_unref (text_view->hadjustment);
   if (text_view->vadjustment)
-    g_object_unref (G_OBJECT (text_view->vadjustment));
+    g_object_unref (text_view->vadjustment);
 
   text_window_free (text_view->text_window);
 
@@ -2493,8 +2484,8 @@ gtk_text_view_finalize (GObject *object)
   if (text_view->bottom_window)
     text_window_free (text_view->bottom_window);
 
-  g_object_unref (G_OBJECT (text_view->im_context));
-
+  g_object_unref (text_view->im_context);
+  
   (* G_OBJECT_CLASS (parent_class)->finalize) (object);
 }
 
@@ -2980,40 +2971,34 @@ gtk_text_view_size_allocate (GtkWidget *widget,
 
   if (y != text_view->yoffset)
     {
-      vadj->value = text_view->yoffset = y;
+      vadj->value = y;
       yoffset_changed = TRUE;
     }
 
   text_view->hadjustment->page_size = SCREEN_WIDTH (text_view);
-  text_view->hadjustment->page_increment = SCREEN_WIDTH (text_view) / 2;
+  text_view->hadjustment->page_increment = SCREEN_WIDTH (text_view) * 0.9;
+  text_view->hadjustment->step_increment = SCREEN_WIDTH (text_view) * 0.1;
   text_view->hadjustment->lower = 0;
   text_view->hadjustment->upper = MAX (SCREEN_WIDTH (text_view),
                                        text_view->width);
-  gtk_signal_emit_by_name (GTK_OBJECT (text_view->hadjustment), "changed");
+  gtk_adjustment_changed (text_view->hadjustment);
 
   text_view->vadjustment->page_size = SCREEN_HEIGHT (text_view);
-  text_view->vadjustment->page_increment = SCREEN_HEIGHT (text_view) / 2;
+  text_view->vadjustment->page_increment = SCREEN_HEIGHT (text_view) * 0.9;
+  text_view->vadjustment->step_increment = SCREEN_HEIGHT (text_view) * 0.1;
   text_view->vadjustment->lower = 0;
   text_view->vadjustment->upper = MAX (SCREEN_HEIGHT (text_view),
                                        text_view->height);
-  gtk_signal_emit_by_name (GTK_OBJECT (text_view->vadjustment), "changed");
+  gtk_adjustment_changed (text_view->vadjustment);
 
   if (yoffset_changed)
     gtk_adjustment_value_changed (vadj);
 
-  if (text_view->first_validate_idle != 0)
-    {
-      /* The GTK resize loop processes all the pending exposes right
-       * after doing the resize stuff, so the idle sizer won't have a
-       * chance to run. So we do the work here. 
-       */
-
-      g_source_remove (text_view->first_validate_idle);
-      text_view->first_validate_idle = 0;
-      
-      if (!gtk_text_view_flush_scroll (text_view))
-        gtk_text_view_validate_onscreen (text_view);
-    }
+  /* The GTK resize loop processes all the pending exposes right
+   * after doing the resize stuff, so the idle sizer won't have a
+   * chance to run. So we do the work here. 
+   */
+  gtk_text_view_flush_first_validate (text_view);
 
   /* widget->window doesn't get auto-redrawn as the layout is computed, so has to
    * be invalidated
@@ -3067,23 +3052,18 @@ gtk_text_view_validate_onscreen (GtkTextView *text_view)
   g_assert (text_view->onscreen_validated);
 }
 
-static gboolean
-first_validate_callback (gpointer data)
+static void
+gtk_text_view_flush_first_validate (GtkTextView *text_view)
 {
-  GtkTextView *text_view = data;
-
-  GDK_THREADS_ENTER ();
-  
-  /* Note that some of this code is duplicated at the end of size_allocate,
-   * keep in sync with that.
-   */
-  
-  DV(g_print(G_STRLOC"\n"));
+  if (text_view->first_validate_idle == 0)
+    return;
 
   /* Do this first, which means that if an "invalidate"
    * occurs during any of this process, a new first_validate_callback
    * will be installed, and we'll start again.
    */
+  DV (g_print ("removing first validate in %s\n", G_STRLOC));
+  g_source_remove (text_view->first_validate_idle);
   text_view->first_validate_idle = 0;
   
   /* be sure we have up-to-date screen size set on the
@@ -3100,18 +3080,36 @@ first_validate_callback (gpointer data)
     }
   else
     {
-      /* scroll to any marks, if that's pending. This can
-       * jump us to the validation codepath used for scrolling
-       * onscreen, if so we bail out.
+      /* scroll to any marks, if that's pending. This can jump us to
+       * the validation codepath used for scrolling onscreen, if so we
+       * bail out.  It won't jump if already in that codepath since
+       * value_changed is not recursive, so also validate if
+       * necessary.
        */
-      if (!gtk_text_view_flush_scroll (text_view))
+      if (!gtk_text_view_flush_scroll (text_view) ||
+          !text_view->onscreen_validated)
        gtk_text_view_validate_onscreen (text_view);
       
       DV(g_print(">Leaving first validate idle ("G_STRLOC")\n"));
       
       g_assert (text_view->onscreen_validated);
-      
     }
+}
+
+static gboolean
+first_validate_callback (gpointer data)
+{
+  GtkTextView *text_view = data;
+
+  GDK_THREADS_ENTER ();
+  
+  /* Note that some of this code is duplicated at the end of size_allocate,
+   * keep in sync with that.
+   */
+  
+  DV(g_print(G_STRLOC"\n"));
+
+  gtk_text_view_flush_first_validate (text_view);
   
   GDK_THREADS_LEAVE ();
   
@@ -3145,10 +3143,15 @@ incremental_validate_callback (gpointer data)
 
 static void
 gtk_text_view_invalidate (GtkTextView *text_view)
-{
+{  
+  DV (g_print (">Invalidate, onscreen_validated = %d now FALSE ("G_STRLOC")\n",
+               text_view->onscreen_validated));
+
   text_view->onscreen_validated = FALSE;
-  
-  DV(g_print(">Invalidate, onscreen_validated = FALSE ("G_STRLOC")\n"));
+
+  /* We'll invalidate when the layout is created */
+  if (text_view->layout == NULL)
+    return;
   
   if (!text_view->first_validate_idle)
     {
@@ -3173,6 +3176,7 @@ invalidated_handler (GtkTextLayout *layout,
 
   text_view = GTK_TEXT_VIEW (data);
 
+  DV (g_print ("Invalidating due to layout invalidate signal\n"));
   gtk_text_view_invalidate (text_view);
 }
 
@@ -3203,9 +3207,11 @@ changed_handler (GtkTextLayout     *layout,
 
       if (old_height == new_height)
         redraw_rect.height = old_height;
-      else
+      else if (start_y + old_height > visible_rect.y)
         redraw_rect.height = MAX (0, visible_rect.y + visible_rect.height - start_y);
-
+      else
+        redraw_rect.height = 0;
+       
       if (gdk_rectangle_intersect (&redraw_rect, &visible_rect, &redraw_rect))
         {
           /* text_window_invalidate_rect() takes buffer coordinates */
@@ -3268,7 +3274,10 @@ changed_handler (GtkTextLayout     *layout,
         }
 
       if (yoffset_changed)
-        gtk_adjustment_value_changed (get_vadjustment (text_view));
+        {
+          DV(g_print ("Changing scroll position (%s)\n", G_STRLOC));
+          gtk_adjustment_value_changed (get_vadjustment (text_view));
+        }
 
       /* FIXME be smarter about which anchored widgets we update */
 
@@ -3298,28 +3307,13 @@ changed_handler (GtkTextLayout     *layout,
 
     if (old_req.width != new_req.width ||
         old_req.height != new_req.height)
-      gtk_widget_queue_resize (widget);
+      {
+        /* FIXME http://bugzilla.gnome.org/show_bug.cgi?id=72258 */
+        _gtk_size_group_queue_resize (widget);
+      }
   }
 }
 
-static void
-gtk_text_view_realize_cursor_gc (GtkTextView *text_view)
-{
-  GdkColor *cursor_color;
-  GdkColor red = { 0, 0xffff, 0x0000, 0x0000 };
-  
-  if (text_view->cursor_gc)
-    gdk_gc_unref (text_view->cursor_gc);
-
-  gtk_widget_style_get (GTK_WIDGET (text_view), "cursor_color", &cursor_color, NULL);
-
-  if (!cursor_color)
-    cursor_color = &red;
-
-  text_view->cursor_gc = gdk_gc_new (text_view->text_window->bin_window);
-  gdk_gc_set_rgb_fg_color (text_view->cursor_gc, cursor_color);
-}
-
 static void
 gtk_text_view_realize (GtkWidget *widget)
 {
@@ -3371,13 +3365,14 @@ gtk_text_view_realize (GtkWidget *widget)
     text_window_realize (text_view->bottom_window,
                          widget->window);
 
-  gtk_text_view_realize_cursor_gc (text_view);
-
   gtk_text_view_ensure_layout (text_view);
 
   if (text_view->buffer)
-    gtk_text_buffer_add_selection_clipboard (text_view->buffer,
-                                            gtk_clipboard_get (GDK_SELECTION_PRIMARY));
+    {
+      GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
+                                                         GDK_SELECTION_PRIMARY);
+      gtk_text_buffer_add_selection_clipboard (text_view->buffer, clipboard);
+    }
 
   tmp_list = text_view->children;
   while (tmp_list != NULL)
@@ -3398,13 +3393,10 @@ gtk_text_view_unrealize (GtkWidget *widget)
   text_view = GTK_TEXT_VIEW (widget);
 
   if (text_view->buffer)
-    gtk_text_buffer_remove_selection_clipboard (text_view->buffer,
-                                               gtk_clipboard_get (GDK_SELECTION_PRIMARY));
-
-  if (text_view->cursor_gc)
     {
-      gdk_gc_unref (text_view->cursor_gc);
-      text_view->cursor_gc = NULL;
+      GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
+                                                         GDK_SELECTION_PRIMARY);
+      gtk_text_buffer_remove_selection_clipboard (text_view->buffer, clipboard);
     }
 
   gtk_text_view_remove_validate_idles (text_view);
@@ -3462,8 +3454,6 @@ gtk_text_view_style_set (GtkWidget *widget,
       if (text_view->bottom_window)
         gdk_window_set_background (text_view->bottom_window->bin_window,
                                    &widget->style->bg[GTK_WIDGET_STATE (widget)]);
-      
-      gtk_text_view_realize_cursor_gc (text_view);
     }
 
   if (text_view->layout && previous_style)
@@ -3666,6 +3656,7 @@ gtk_text_view_key_press_event (GtkWidget *widget, GdkEventKey *event)
   GtkTextView *text_view = GTK_TEXT_VIEW (widget);
   GtkTextMark *insert;
   GtkTextIter iter;
+  gboolean can_insert;
   
   if (text_view->layout == NULL ||
       get_buffer (text_view) == NULL)
@@ -3673,19 +3664,26 @@ gtk_text_view_key_press_event (GtkWidget *widget, GdkEventKey *event)
 
   insert = gtk_text_buffer_get_insert (get_buffer (text_view));
   gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, insert);
-  if (gtk_text_iter_can_insert (&iter, text_view->editable) &&
+  can_insert = gtk_text_iter_can_insert (&iter, text_view->editable);
+  if (can_insert &&
       gtk_im_context_filter_keypress (text_view->im_context, event))
     {
       text_view->need_im_reset = TRUE;
       obscure = TRUE;
       retval = TRUE;
     }
+  /* Binding set */
   else if (GTK_WIDGET_CLASS (parent_class)->key_press_event &&
           GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event))
     retval = TRUE;
-  else if (event->keyval == GDK_Return ||
-           event->keyval == GDK_KP_Enter)
+  /* use overall editability not can_insert, more predictable for users */
+  else if (text_view->editable &&
+           (event->keyval == GDK_Return ||
+            event->keyval == GDK_KP_Enter))
     {
+      /* this won't actually insert the newline if the cursor isn't
+       * editable
+       */
       gtk_text_view_commit_text (text_view, "\n");
 
       obscure = TRUE;
@@ -3693,11 +3691,12 @@ gtk_text_view_key_press_event (GtkWidget *widget, GdkEventKey *event)
     }
   /* Pass through Tab as literal tab, unless Control is held down */
   else if ((event->keyval == GDK_Tab ||
-            event->keyval == GDK_KP_Tab ||
-            event->keyval == GDK_ISO_Left_Tab) &&
+            event->keyval == GDK_KP_Tab) &&
            !(event->state & GDK_CONTROL_MASK))
     {
-      /* If the text isn't editable, move the focus instead */
+      /* If the text widget isn't editable overall, move the focus
+       * instead
+       */
       if (text_view->editable)
        {
          gtk_text_view_commit_text (text_view, "\t");
@@ -3811,7 +3810,7 @@ gtk_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
                                              event->y + text_view->yoffset);
 
           gtk_text_buffer_paste_clipboard (get_buffer (text_view),
-                                          gtk_clipboard_get (GDK_SELECTION_PRIMARY),
+                                          gtk_widget_get_clipboard (widget, GDK_SELECTION_PRIMARY),
                                           &iter,
                                           text_view->editable);
           return TRUE;
@@ -3964,7 +3963,6 @@ gtk_text_view_focus_in_event (GtkWidget *widget, GdkEventFocus *event)
 {
   GtkTextView *text_view = GTK_TEXT_VIEW (widget);
 
-  GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
   gtk_widget_queue_draw (widget);
 
   DV(g_print (G_STRLOC": focus_in_event\n"));
@@ -3975,7 +3973,7 @@ gtk_text_view_focus_in_event (GtkWidget *widget, GdkEventFocus *event)
       gtk_text_view_check_cursor_blink (text_view);
     }
 
-  g_signal_connect (gdk_keymap_get_default (),
+  g_signal_connect (gdk_keymap_get_for_display (gtk_widget_get_display (widget)),
                    "direction_changed",
                    G_CALLBACK (keymap_direction_changed), text_view);
   gtk_text_view_check_keymap_direction (text_view);
@@ -3991,7 +3989,6 @@ gtk_text_view_focus_out_event (GtkWidget *widget, GdkEventFocus *event)
 {
   GtkTextView *text_view = GTK_TEXT_VIEW (widget);
 
-  GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
   gtk_widget_queue_draw (widget);
 
   DV(g_print (G_STRLOC": focus_out_event\n"));
@@ -4002,9 +3999,9 @@ gtk_text_view_focus_out_event (GtkWidget *widget, GdkEventFocus *event)
       gtk_text_view_check_cursor_blink (text_view);
     }
 
-  g_signal_handlers_disconnect_by_func (gdk_keymap_get_default (),
-                                        keymap_direction_changed,
-                                        text_view);
+  g_signal_handlers_disconnect_by_func (gdk_keymap_get_for_display (gtk_widget_get_display (widget)),
+                                       keymap_direction_changed,
+                                       text_view);
 
   text_view->need_im_reset = TRUE;
   gtk_im_context_focus_out (GTK_TEXT_VIEW (widget)->im_context);
@@ -4021,7 +4018,8 @@ gtk_text_view_motion_event (GtkWidget *widget, GdkEventMotion *event)
     {
       GdkCursor *cursor;
       
-      cursor = gdk_cursor_new (GDK_XTERM);
+      cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
+                                          GDK_XTERM);
       gdk_window_set_cursor (text_view->text_window->bin_window, cursor);
       gdk_cursor_unref (cursor);
       text_view->mouse_cursor_obscured = FALSE;
@@ -4070,20 +4068,38 @@ gtk_text_view_paint (GtkWidget      *widget,
   GtkTextView *text_view;
   GList *child_exposes;
   GList *tmp_list;
+  GdkRegion *updates;
   
   text_view = GTK_TEXT_VIEW (widget);
 
   g_return_if_fail (text_view->layout != NULL);
   g_return_if_fail (text_view->xoffset >= 0);
   g_return_if_fail (text_view->yoffset >= 0);
-  
-  DV (g_print (G_STRLOC": first_validate_idle: %d\n",
-               text_view->first_validate_idle));
+
+  while (text_view->first_validate_idle != 0)
+    {
+      DV (g_print (G_STRLOC": first_validate_idle: %d\n",
+                   text_view->first_validate_idle));
+      gtk_text_view_flush_first_validate (text_view);
+    }
+
+  /* More regions could have become invalid in the above loop */
+  updates = gdk_window_get_update_area (text_view->text_window->bin_window);
+  if (updates)
+    {
+      GdkRectangle rect;
+      
+      gdk_region_get_clipbox (updates, &rect);
+
+      gdk_rectangle_union (area, &rect, area);
+      
+      gdk_region_destroy (updates);
+    }
   
   if (!text_view->onscreen_validated)
     {
-      g_warning (G_STRLOC ": somehow some text lines were modified or scrolling occurred since the last validation of lines on the screen - this is a known bug, no need to report.");
-      G_BREAKPOINT ();
+      g_warning (G_STRLOC ": somehow some text lines were modified or scrolling occurred since the last validation of lines on the screen - may be a text widget bug.");
+      g_assert_not_reached ();
     }
   
 #if 0
@@ -4096,7 +4112,7 @@ gtk_text_view_paint (GtkWidget      *widget,
   gtk_text_layout_draw (text_view->layout,
                         widget,
                         text_view->text_window->bin_window,
-                       text_view->cursor_gc,
+                       NULL,
                         text_view->xoffset,
                         text_view->yoffset,
                         area->x, area->y,
@@ -4112,7 +4128,7 @@ gtk_text_view_paint (GtkWidget      *widget,
                                       child,
                                       event);
 
-      g_object_unref (G_OBJECT (child));
+      g_object_unref (child);
       
       tmp_list = tmp_list->next;
     }
@@ -4203,11 +4219,29 @@ gtk_text_view_focus (GtkWidget        *widget,
 {
   GtkTextView *text_view;
   GtkContainer *container;
+  gboolean result;
   
   text_view = GTK_TEXT_VIEW (widget);
   container = GTK_CONTAINER (widget);  
-  
-  return GTK_WIDGET_CLASS (parent_class)->focus (widget, direction);
+
+  if (!gtk_widget_is_focus (widget) &&
+      container->focus_child == NULL)
+    {
+      gtk_widget_grab_focus (widget);
+      return TRUE;
+    }
+  else
+    {
+      /*
+       * Unset CAN_FOCUS flag so that gtk_container_focus() allows
+       * children to get the focus
+       */
+      GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS); 
+      result = GTK_WIDGET_CLASS (parent_class)->focus (widget, direction);
+      GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS); 
+
+      return result;
+    }
 }
 
 /*
@@ -4446,6 +4480,20 @@ gtk_text_view_move_iter_by_lines (GtkTextView *text_view,
     }
 }
 
+static void
+move_cursor (GtkTextView       *text_view,
+             const GtkTextIter *new_location,
+             gboolean           extend_selection)
+{
+  if (extend_selection)
+    gtk_text_buffer_move_mark_by_name (get_buffer (text_view),
+                                       "insert",
+                                       new_location);
+  else
+    gtk_text_buffer_place_cursor (get_buffer (text_view),
+                                  new_location);
+}
+
 /* FIXME when we are unfrozen and can change GtkMovementStep,
  * fix this
  */
@@ -4466,13 +4514,13 @@ gtk_text_view_move_cursor_internal (GtkTextView     *text_view,
 
   if (step == GTK_MOVEMENT_PAGES)
     {
-      gtk_text_view_scroll_pages (text_view, count);
+      gtk_text_view_scroll_pages (text_view, count, extend_selection);
       gtk_text_view_pend_cursor_blink (text_view);
       return;
     }
   else if (step == PAGE_HORIZONTALLY_HACK_VALUE)
     {
-      gtk_text_view_scroll_hpages (text_view, count);
+      gtk_text_view_scroll_hpages (text_view, count, extend_selection);
       gtk_text_view_pend_cursor_blink (text_view);
       return;
     }
@@ -4568,13 +4616,7 @@ gtk_text_view_move_cursor_internal (GtkTextView     *text_view,
 
   if (!gtk_text_iter_equal (&insert, &newplace))
     {
-      if (extend_selection)
-        gtk_text_buffer_move_mark (get_buffer (text_view),
-                                   gtk_text_buffer_get_mark (get_buffer (text_view),
-                                                             "insert"),
-                                   &newplace);
-      else
-        gtk_text_buffer_place_cursor (get_buffer (text_view), &newplace);
+      move_cursor (text_view, &newplace, extend_selection);
 
       DV(g_print (G_STRLOC": scrolling onscreen\n"));
       gtk_text_view_scroll_mark_onscreen (text_view,
@@ -4622,7 +4664,8 @@ gtk_text_view_set_anchor (GtkTextView *text_view)
 
 static void
 gtk_text_view_scroll_pages (GtkTextView *text_view,
-                            gint         count)
+                            gint         count,
+                            gboolean     extend_selection)
 {
   gdouble newval;
   gdouble oldval;
@@ -4634,6 +4677,8 @@ gtk_text_view_scroll_pages (GtkTextView *text_view,
 
   g_return_if_fail (text_view->vadjustment != NULL);
 
+  cancel_pending_scroll (text_view);
+  
   adj = text_view->vadjustment;
 
   /* Validate the region that will be brought into view by the cursor motion
@@ -4658,13 +4703,13 @@ gtk_text_view_scroll_pages (GtkTextView *text_view,
     {
       /* already at top, just be sure we are at offset 0 */
       gtk_text_buffer_get_start_iter (get_buffer (text_view), &new_insert);
-      gtk_text_buffer_place_cursor (get_buffer (text_view), &new_insert);
+      move_cursor (text_view, &new_insert, extend_selection);
     }
   else if (count > 0 && adj->value >= (adj->upper - adj->page_size - 1e-12))
     {
       /* already at bottom, just be sure we are at the end */
       gtk_text_buffer_get_end_iter (get_buffer (text_view), &new_insert);
-      gtk_text_buffer_place_cursor (get_buffer (text_view), &new_insert);
+      move_cursor (text_view, &new_insert, extend_selection);
     }
   else
     {
@@ -4680,7 +4725,7 @@ gtk_text_view_scroll_pages (GtkTextView *text_view,
 
       gtk_text_layout_get_iter_at_pixel (text_view->layout, &new_insert, cursor_x_pos, cursor_y_pos);
       clamp_iter_onscreen (text_view, &new_insert);
-      gtk_text_buffer_place_cursor (get_buffer (text_view), &new_insert);
+      move_cursor (text_view, &new_insert, extend_selection);
 
       gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, cursor_y_pos);
     }
@@ -4696,7 +4741,8 @@ gtk_text_view_scroll_pages (GtkTextView *text_view,
 
 static void
 gtk_text_view_scroll_hpages (GtkTextView *text_view,
-                             gint         count)
+                             gint         count,
+                             gboolean     extend_selection)
 {
   gdouble newval;
   gdouble oldval;
@@ -4704,10 +4750,11 @@ gtk_text_view_scroll_hpages (GtkTextView *text_view,
   gint cursor_x_pos, cursor_y_pos;
   GtkTextIter new_insert;
   gint y, height;
-  gint x, width;
   
   g_return_if_fail (text_view->hadjustment != NULL);
 
+  cancel_pending_scroll (text_view);
+  
   adj = text_view->hadjustment;
 
   /* Validate the line that we're moving within.
@@ -4723,13 +4770,13 @@ gtk_text_view_scroll_hpages (GtkTextView *text_view,
     {
       /* already at far left, just be sure we are at offset 0 */
       gtk_text_iter_set_line_offset (&new_insert, 0);
-      gtk_text_buffer_place_cursor (get_buffer (text_view), &new_insert);
+      move_cursor (text_view, &new_insert, extend_selection);
     }
   else if (count > 0 && adj->value >= (adj->upper - adj->page_size - 1e-12))
     {
       /* already at far right, just be sure we are at the end */
       gtk_text_iter_forward_to_line_end (&new_insert);
-      gtk_text_buffer_place_cursor (get_buffer (text_view), &new_insert);
+      move_cursor (text_view, &new_insert, extend_selection);
     }
   else
     {
@@ -4745,7 +4792,7 @@ gtk_text_view_scroll_hpages (GtkTextView *text_view,
 
       gtk_text_layout_get_iter_at_pixel (text_view->layout, &new_insert, cursor_x_pos, cursor_y_pos);
       clamp_iter_onscreen (text_view, &new_insert);
-      gtk_text_buffer_place_cursor (get_buffer (text_view), &new_insert);
+      move_cursor (text_view, &new_insert, extend_selection);
 
       gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, cursor_y_pos);
     }
@@ -4926,8 +4973,11 @@ gtk_text_view_delete_from_cursor (GtkTextView   *text_view,
 static void
 gtk_text_view_cut_clipboard (GtkTextView *text_view)
 {
+  GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
+                                                     GDK_SELECTION_CLIPBOARD);
+  
   gtk_text_buffer_cut_clipboard (get_buffer (text_view),
-                                gtk_clipboard_get (GDK_SELECTION_CLIPBOARD),
+                                clipboard,
                                 text_view->editable);
   DV(g_print (G_STRLOC": scrolling onscreen\n"));
   gtk_text_view_scroll_mark_onscreen (text_view,
@@ -4938,8 +4988,11 @@ gtk_text_view_cut_clipboard (GtkTextView *text_view)
 static void
 gtk_text_view_copy_clipboard (GtkTextView *text_view)
 {
+  GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
+                                                     GDK_SELECTION_CLIPBOARD);
+  
   gtk_text_buffer_copy_clipboard (get_buffer (text_view),
-                                 gtk_clipboard_get (GDK_SELECTION_CLIPBOARD));
+                                 clipboard);
   DV(g_print (G_STRLOC": scrolling onscreen\n"));
   gtk_text_view_scroll_mark_onscreen (text_view,
                                       gtk_text_buffer_get_mark (get_buffer (text_view),
@@ -4949,8 +5002,11 @@ gtk_text_view_copy_clipboard (GtkTextView *text_view)
 static void
 gtk_text_view_paste_clipboard (GtkTextView *text_view)
 {
+  GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
+                                                     GDK_SELECTION_CLIPBOARD);
+  
   gtk_text_buffer_paste_clipboard (get_buffer (text_view),
-                                  gtk_clipboard_get (GDK_SELECTION_CLIPBOARD),
+                                  clipboard,
                                   NULL,
                                   text_view->editable);
   DV(g_print (G_STRLOC": scrolling onscreen\n"));
@@ -4969,17 +5025,13 @@ static void
 gtk_text_view_move_focus (GtkTextView     *text_view,
                           GtkDirectionType direction_type)
 {
-  GtkWidget *toplevel;
+  GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (text_view));
 
-  toplevel =
-    gtk_widget_get_ancestor (GTK_WIDGET (text_view), GTK_TYPE_WINDOW);
-
-  if (toplevel == NULL)
+  if (!GTK_WIDGET_TOPLEVEL (toplevel))
     return;
 
   /* Propagate to toplevel */
-  g_signal_emit_by_name (G_OBJECT (toplevel), "move_focus",
-                         direction_type);
+  g_signal_emit_by_name (toplevel, "move_focus", direction_type);
 }
 
 /*
@@ -5025,6 +5077,7 @@ move_mark_to_pointer_and_scroll (GtkTextView *text_view,
     GtkTextMark *mark =
       gtk_text_buffer_get_mark (get_buffer (text_view), mark_name);
 
+    /* This may invalidate the layout */
     DV(g_print (G_STRLOC": move mark\n"));
     gtk_text_buffer_move_mark (get_buffer (text_view),
                                mark,
@@ -5033,6 +5086,9 @@ move_mark_to_pointer_and_scroll (GtkTextView *text_view,
     DV(g_print (G_STRLOC": scrolling onscreen\n"));
     gtk_text_view_scroll_mark_onscreen (text_view, mark);
   }
+
+  DV (g_print ("first validate idle leaving %s is %d\n",
+               G_STRLOC, text_view->first_validate_idle));
 }
 
 static gint
@@ -5154,10 +5210,10 @@ gtk_text_view_start_selection_drag (GtkTextView       *text_view,
       gtk_text_buffer_place_cursor (buffer, &newplace);
     }
 
-  text_view->selection_drag_handler = gtk_signal_connect (GTK_OBJECT (text_view),
-                                                          "motion_notify_event",
-                                                          GTK_SIGNAL_FUNC (selection_motion_event_handler),
-                                                          NULL);
+  text_view->selection_drag_handler = g_signal_connect (text_view,
+                                                        "motion_notify_event",
+                                                        G_CALLBACK (selection_motion_event_handler),
+                                                        NULL);
 }
 
 /* returns whether we were really dragging */
@@ -5167,7 +5223,7 @@ gtk_text_view_end_selection_drag (GtkTextView *text_view, GdkEventButton *event)
   if (text_view->selection_drag_handler == 0)
     return FALSE;
 
-  gtk_signal_disconnect (GTK_OBJECT (text_view), text_view->selection_drag_handler);
+  g_signal_handler_disconnect (text_view, text_view->selection_drag_handler);
   text_view->selection_drag_handler = 0;
 
   if (text_view->scroll_timeout != 0)
@@ -5216,10 +5272,15 @@ gtk_text_view_check_keymap_direction (GtkTextView *text_view)
                    "gtk-split-cursor", &split_cursor,
                    NULL);
       if (split_cursor)
-       new_dir = GTK_TEXT_DIR_NONE;
+       {
+         new_dir = GTK_TEXT_DIR_NONE;
+       }
       else
-       new_dir = (gdk_keymap_get_direction (gdk_keymap_get_default ()) == PANGO_DIRECTION_LTR) ?
-         GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
+       {
+         GdkKeymap *keymap = gdk_keymap_get_for_display (gtk_widget_get_display (GTK_WIDGET (text_view)));
+         new_dir = (gdk_keymap_get_direction (keymap) == PANGO_DIRECTION_LTR) ?
+           GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
+       }
       
       if (text_view->layout->cursor_direction != new_dir)
        gtk_text_layout_set_cursor_direction (text_view->layout, new_dir);
@@ -5243,17 +5304,17 @@ gtk_text_view_ensure_layout (GtkTextView *text_view)
       
       text_view->layout = gtk_text_layout_new ();
 
-      g_signal_connect (G_OBJECT (text_view->layout),
+      g_signal_connect (text_view->layout,
                        "invalidated",
                        G_CALLBACK (invalidated_handler),
                        text_view);
 
-      g_signal_connect (G_OBJECT (text_view->layout),
+      g_signal_connect (text_view->layout,
                        "changed",
                        G_CALLBACK (changed_handler),
                        text_view);
 
-      g_signal_connect (G_OBJECT (text_view->layout),
+      g_signal_connect (text_view->layout,
                        "allocate_child",
                        G_CALLBACK (gtk_text_view_child_allocated),
                        text_view);
@@ -5273,8 +5334,8 @@ gtk_text_view_ensure_layout (GtkTextView *text_view)
 
       gtk_text_layout_set_contexts (text_view->layout, ltr_context, rtl_context);
 
-      g_object_unref (G_OBJECT (ltr_context));
-      g_object_unref (G_OBJECT (rtl_context));
+      g_object_unref (ltr_context);
+      g_object_unref (rtl_context);
 
       gtk_text_view_check_keymap_direction (text_view);
 
@@ -5316,6 +5377,8 @@ gtk_text_view_ensure_layout (GtkTextView *text_view)
 
           tmp_list = g_slist_next (tmp_list);
         }
+
+      gtk_text_view_invalidate (text_view);
     }
 }
 
@@ -5352,6 +5415,13 @@ gtk_text_view_destroy_layout (GtkTextView *text_view)
       GSList *tmp_list;
 
       gtk_text_view_remove_validate_idles (text_view);
+
+      g_signal_handlers_disconnect_by_func (text_view->layout,
+                                           invalidated_handler,
+                                           text_view);
+      g_signal_handlers_disconnect_by_func (text_view->layout,
+                                           changed_handler, 
+                                           text_view);
       
       /* Remove layout from all anchored children */
       tmp_list = text_view->children;
@@ -5371,11 +5441,7 @@ gtk_text_view_destroy_layout (GtkTextView *text_view)
       gtk_text_view_stop_cursor_blink (text_view);
       gtk_text_view_end_selection_drag (text_view, NULL);
 
-      g_signal_handlers_disconnect_by_func (G_OBJECT (text_view->layout),
-                                            invalidated_handler, text_view);
-      g_signal_handlers_disconnect_by_func (G_OBJECT (text_view->layout),
-                                            changed_handler, text_view);
-      g_object_unref (G_OBJECT (text_view->layout));
+      g_object_unref (text_view->layout);
       text_view->layout = NULL;
     }
 }
@@ -5548,7 +5614,8 @@ gtk_text_view_drag_motion (GtkWidget        *widget,
     }                                 
   else if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
                                             &start, &end) &&
-           gtk_text_iter_in_range (&newplace, &start, &end))
+           gtk_text_iter_compare (&newplace, &start) >= 0 &&
+           gtk_text_iter_compare (&newplace, &end) <= 0)
     {
       /* We're inside the selection. */
     }
@@ -5784,37 +5851,41 @@ gtk_text_view_set_scroll_adjustments (GtkTextView   *text_view,
 
   if (text_view->hadjustment && (text_view->hadjustment != hadj))
     {
-      gtk_signal_disconnect_by_data (GTK_OBJECT (text_view->hadjustment), text_view);
-      g_object_unref (G_OBJECT (text_view->hadjustment));
+      g_signal_handlers_disconnect_by_func (text_view->hadjustment,
+                                           gtk_text_view_value_changed,
+                                           text_view);
+      g_object_unref (text_view->hadjustment);
     }
 
   if (text_view->vadjustment && (text_view->vadjustment != vadj))
     {
-      gtk_signal_disconnect_by_data (GTK_OBJECT (text_view->vadjustment), text_view);
-      g_object_unref (G_OBJECT (text_view->vadjustment));
+      g_signal_handlers_disconnect_by_func (text_view->vadjustment,
+                                           gtk_text_view_value_changed,
+                                           text_view);
+      g_object_unref (text_view->vadjustment);
     }
 
   if (text_view->hadjustment != hadj)
     {
       text_view->hadjustment = hadj;
-      g_object_ref (G_OBJECT (text_view->hadjustment));
+      g_object_ref (text_view->hadjustment);
       gtk_object_sink (GTK_OBJECT (text_view->hadjustment));
       
-      gtk_signal_connect (GTK_OBJECT (text_view->hadjustment), "value_changed",
-                          (GtkSignalFunc) gtk_text_view_value_changed,
-                          text_view);
+      g_signal_connect (text_view->hadjustment, "value_changed",
+                        G_CALLBACK (gtk_text_view_value_changed),
+                       text_view);
       need_adjust = TRUE;
     }
 
   if (text_view->vadjustment != vadj)
     {
       text_view->vadjustment = vadj;
-      g_object_ref (G_OBJECT (text_view->vadjustment));
+      g_object_ref (text_view->vadjustment);
       gtk_object_sink (GTK_OBJECT (text_view->vadjustment));
       
-      gtk_signal_connect (GTK_OBJECT (text_view->vadjustment), "value_changed",
-                          (GtkSignalFunc) gtk_text_view_value_changed,
-                          text_view);
+      g_signal_connect (text_view->vadjustment, "value_changed",
+                        G_CALLBACK (gtk_text_view_value_changed),
+                       text_view);
       need_adjust = TRUE;
     }
 
@@ -5822,6 +5893,77 @@ gtk_text_view_set_scroll_adjustments (GtkTextView   *text_view,
     gtk_text_view_value_changed (NULL, text_view);
 }
 
+/* FIXME this adjust_allocation is a big cut-and-paste from
+ * GtkCList, needs to be some "official" way to do this
+ * factored out.
+ */
+typedef struct
+{
+  GdkWindow *window;
+  int dx;
+  int dy;
+} ScrollData;
+
+/* The window to which widget->window is relative */
+#define ALLOCATION_WINDOW(widget)              \
+   (GTK_WIDGET_NO_WINDOW (widget) ?            \
+    (widget)->window :                          \
+     gdk_window_get_parent ((widget)->window))
+
+static void
+adjust_allocation_recurse (GtkWidget *widget,
+                          gpointer   data)
+{
+  ScrollData *scroll_data = data;
+
+  /* Need to really size allocate instead of just poking
+   * into widget->allocation if the widget is not realized.
+   * FIXME someone figure out why this was.
+   */
+  if (!GTK_WIDGET_REALIZED (widget))
+    {
+      if (GTK_WIDGET_VISIBLE (widget))
+       {
+         GdkRectangle tmp_rectangle = widget->allocation;
+         tmp_rectangle.x += scroll_data->dx;
+          tmp_rectangle.y += scroll_data->dy;
+          
+         gtk_widget_size_allocate (widget, &tmp_rectangle);
+       }
+    }
+  else
+    {
+      if (ALLOCATION_WINDOW (widget) == scroll_data->window)
+       {
+         widget->allocation.x += scroll_data->dx;
+          widget->allocation.y += scroll_data->dy;
+          
+         if (GTK_IS_CONTAINER (widget))
+           gtk_container_forall (GTK_CONTAINER (widget),
+                                 adjust_allocation_recurse,
+                                 data);
+       }
+    }
+}
+
+static void
+adjust_allocation (GtkWidget *widget,
+                  int        dx,
+                   int        dy)
+{
+  ScrollData scroll_data;
+
+  if (GTK_WIDGET_REALIZED (widget))
+    scroll_data.window = ALLOCATION_WINDOW (widget);
+  else
+    scroll_data.window = NULL;
+    
+  scroll_data.dx = dx;
+  scroll_data.dy = dy;
+  
+  adjust_allocation_recurse (widget, &scroll_data);
+}
+            
 static void
 gtk_text_view_value_changed (GtkAdjustment *adj,
                              GtkTextView   *text_view)
@@ -5900,17 +6042,7 @@ gtk_text_view_value_changed (GtkAdjustment *adj,
           GtkTextViewChild *child = tmp_list->data;
           
           if (child->anchor)
-            {              
-              child->widget->allocation.x -= dx;
-              child->widget->allocation.y -= dy;
-
-#if 0
-              g_print ("allocation for %p tweaked to %d,%d\n",
-                       child->widget,
-                       child->widget->allocation.x,
-                       child->widget->allocation.y);
-#endif
-            }
+            adjust_allocation (child->widget, dx, dy);
           
           tmp_list = g_slist_next (tmp_list);
         }
@@ -5933,6 +6065,8 @@ gtk_text_view_value_changed (GtkAdjustment *adj,
   /* process exposes */
   if (GTK_WIDGET_REALIZED (text_view))
     {
+      DV (g_print ("Processing updates (%s)\n", G_STRLOC));
+      
       if (text_view->left_window)
         gdk_window_process_updates (text_view->left_window->bin_window, TRUE);
 
@@ -5990,7 +6124,16 @@ gtk_text_view_commit_text (GtkTextView   *text_view,
   else
     {
       if (!had_selection && text_view->overwrite_mode)
-        gtk_text_view_delete_from_cursor (text_view, GTK_DELETE_CHARS, 1);
+       {
+         GtkTextIter insert;
+         
+         gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
+                                           &insert,
+                                           gtk_text_buffer_get_mark (get_buffer (text_view),
+                                                                     "insert"));
+         if (!gtk_text_iter_ends_line (&insert))
+           gtk_text_view_delete_from_cursor (text_view, GTK_DELETE_CHARS, 1);
+       }
       gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), str, -1,
                                                     text_view->editable);
     }
@@ -6147,7 +6290,7 @@ activate_cb (GtkWidget   *menuitem,
             GtkTextView *text_view)
 {
   const gchar *signal = g_object_get_data (G_OBJECT (menuitem), "gtk-signal");
-  gtk_signal_emit_by_name (GTK_OBJECT (text_view), signal);
+  g_signal_emit_by_name (text_view, signal);
 }
 
 static void
@@ -6160,8 +6303,8 @@ append_action_signal (GtkTextView  *text_view,
   GtkWidget *menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
 
   g_object_set_data (G_OBJECT (menuitem), "gtk-signal", (char *)signal);
-  gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
-                     GTK_SIGNAL_FUNC (activate_cb), text_view);
+  g_signal_connect (menuitem, "activate",
+                   G_CALLBACK (activate_cb), text_view);
 
   gtk_widget_set_sensitive (menuitem, sensitive);
   
@@ -6190,11 +6333,14 @@ popup_position_func (GtkMenu   *menu,
   gint root_x, root_y;
   GtkTextIter iter;
   GtkRequisition req;      
+  GdkScreen *screen;
   
   text_view = GTK_TEXT_VIEW (user_data);
   widget = GTK_WIDGET (text_view);
   
   g_return_if_fail (GTK_WIDGET_REALIZED (text_view));
+  
+  screen = gtk_widget_get_screen (widget);
 
   gdk_window_get_origin (widget->window, &root_x, &root_y);
 
@@ -6235,8 +6381,8 @@ popup_position_func (GtkMenu   *menu,
   *x = CLAMP (*x, root_x, (root_x + widget->allocation.width));
   *y = CLAMP (*y, root_y, (root_y + widget->allocation.height));
 
-  *x = CLAMP (*x, 0, MAX (0, gdk_screen_width () - req.width));
-  *y = CLAMP (*y, 0, MAX (0, gdk_screen_height () - req.height));
+  *x = CLAMP (*x, 0, MAX (0, gdk_screen_get_width (screen) - req.width));
+  *y = CLAMP (*y, 0, MAX (0, gdk_screen_get_height (screen) - req.height));
 }
 
 typedef struct
@@ -6346,9 +6492,10 @@ popup_targets_received (GtkClipboard     *clipboard,
                                                     unichar_chosen_func,
                                                     text_view);
       
-      gtk_signal_emit (GTK_OBJECT (text_view),
-                      signals[POPULATE_POPUP],
-                      text_view->popup_menu);
+      g_signal_emit (text_view,
+                    signals[POPULATE_POPUP],
+                    0,
+                    text_view->popup_menu);
       
       if (info->button)
        gtk_menu_popup (GTK_MENU (text_view->popup_menu), NULL, NULL,
@@ -6359,7 +6506,7 @@ popup_targets_received (GtkClipboard     *clipboard,
          gtk_menu_popup (GTK_MENU (text_view->popup_menu), NULL, NULL,
                          popup_position_func, text_view,
                          0, gtk_get_current_event_time ());
-         _gtk_menu_shell_select_first (GTK_MENU_SHELL (text_view->popup_menu));
+         gtk_menu_shell_select_first (GTK_MENU_SHELL (text_view->popup_menu), FALSE);
        }
     }
 
@@ -6373,6 +6520,9 @@ gtk_text_view_do_popup (GtkTextView    *text_view,
 {
   PopupInfo *info = g_new (PopupInfo, 1);
 
+  /* should not need this, see http://bugzilla.gnome.org/show_bug.cgi?id=74620 */
+  gtk_text_view_end_selection_drag (text_view, event);
+  
   /* In order to know what entries we should make sensitive, we
    * ask for the current targets of the clipboard, and when
    * we get them, then we actually pop up the menu.
@@ -6390,16 +6540,18 @@ gtk_text_view_do_popup (GtkTextView    *text_view,
       info->time = gtk_get_current_event_time ();
     }
 
-  gtk_clipboard_request_contents (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD),
+  gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (text_view),
+                                                           GDK_SELECTION_CLIPBOARD),
                                  gdk_atom_intern ("TARGETS", FALSE),
                                  popup_targets_received,
                                  info);
 }
 
-static void
+static gboolean
 gtk_text_view_popup_menu (GtkWidget *widget)
 {
   gtk_text_view_do_popup (GTK_TEXT_VIEW (widget), NULL);  
+  return TRUE;
 }
 
 /* Child GdkWindows */
@@ -6488,7 +6640,8 @@ text_window_realize (GtkTextWindow *win,
   if (win->type == GTK_TEXT_WINDOW_TEXT)
     {
       /* I-beam cursor */
-      cursor = gdk_cursor_new (GDK_XTERM);
+      cursor = gdk_cursor_new_for_display (gdk_drawable_get_display (parent),
+                                          GDK_XTERM);
       gdk_window_set_cursor (win->bin_window, cursor);
       gdk_cursor_unref (cursor);
 
@@ -6610,7 +6763,7 @@ text_window_invalidate_rect (GtkTextWindow *win,
     gdk_draw_rectangle (win->bin_window,
                         gc, TRUE, window_rect.x, window_rect.y,
                         window_rect.width, window_rect.height);
-    gdk_gc_unref (gc);
+    g_object_unref (gc);
   }
 #endif
 }
@@ -6627,13 +6780,6 @@ text_window_get_height (GtkTextWindow *win)
   return win->allocation.height;
 }
 
-static void
-text_window_get_allocation (GtkTextWindow *win,
-                            GdkRectangle  *rect)
-{
-  *rect = win->allocation;
-}
-
 /* Windows */
 
 
@@ -6695,11 +6841,14 @@ gtk_text_view_get_window (GtkTextView *text_view,
         return NULL;
       break;
 
-    default:
-      g_warning ("%s: Unknown GtkTextWindowType", G_STRLOC);
+    case GTK_TEXT_WINDOW_PRIVATE:
+      g_warning ("%s: You can't get GTK_TEXT_WINDOW_PRIVATE, it has \"PRIVATE\" in the name because it is private.", G_GNUC_FUNCTION);
       return NULL;
       break;
     }
+
+  g_warning ("%s: Unknown GtkTextWindowType", G_GNUC_FUNCTION);
+  return NULL;
 }
 
 /**
@@ -6743,33 +6892,17 @@ buffer_to_widget (GtkTextView      *text_view,
                   gint              buffer_y,
                   gint             *window_x,
                   gint             *window_y)
-{
-  gint focus_edge_width;
-  gboolean interior_focus;
-  gint focus_width;
-  
-  gtk_widget_style_get (GTK_WIDGET (text_view),
-                       "interior_focus", &interior_focus,
-                       "focus_line_width", &focus_width,
-                       NULL);
-
-  if (interior_focus)
-    focus_edge_width = 0;
-  else
-    focus_edge_width = focus_width;
-  
+{  
   if (window_x)
     {
-      *window_x = buffer_x - text_view->xoffset + focus_edge_width;
-      if (text_view->left_window)
-        *window_x += text_view->left_window->allocation.width;
+      *window_x = buffer_x - text_view->xoffset;
+      *window_x += text_view->text_window->allocation.x;
     }
 
   if (window_y)
     {
-      *window_y = buffer_y - text_view->yoffset + focus_edge_width;
-      if (text_view->top_window)
-        *window_y += text_view->top_window->allocation.height;
+      *window_y = buffer_y - text_view->yoffset;
+      *window_y += text_view->text_window->allocation.y;
     }
 }
 
@@ -6816,14 +6949,17 @@ buffer_to_text_window (GtkTextView   *text_view,
 /**
  * gtk_text_view_buffer_to_window_coords:
  * @text_view: a #GtkTextView
- * @win: a #GtkTextWindowType
+ * @win: a #GtkTextWindowType except #GTK_TEXT_WINDOW_PRIVATE
  * @buffer_x: buffer x coordinate
  * @buffer_y: buffer y coordinate
  * @window_x: window x coordinate return location
  * @window_y: window y coordinate return location
  *
  * Converts coordinate (@buffer_x, @buffer_y) to coordinates for the window
- * @win, and stores the result in (@window_x, @window_y).
+ * @win, and stores the result in (@window_x, @window_y). 
+ *
+ * Note that you can't convert coordinates for a nonexisting window (see 
+ * gtk_text_view_set_border_window_size()).
  **/
 void
 gtk_text_view_buffer_to_window_coords (GtkTextView      *text_view,
@@ -6894,33 +7030,17 @@ widget_to_buffer (GtkTextView *text_view,
                   gint         widget_y,
                   gint        *buffer_x,
                   gint        *buffer_y)
-{
-  gint focus_edge_width;
-  gboolean interior_focus;
-  gint focus_width;
-  
-  gtk_widget_style_get (GTK_WIDGET (text_view),
-                       "interior_focus", &interior_focus,
-                       "focus_line_width", &focus_width,
-                       NULL);
-
-  if (interior_focus)
-    focus_edge_width = 0;
-  else
-    focus_edge_width = focus_width;
-  
+{  
   if (buffer_x)
     {
-      *buffer_x = widget_x - focus_edge_width + text_view->xoffset;
-      if (text_view->left_window)
-        *buffer_x -= text_view->left_window->allocation.width;
+      *buffer_x = widget_x + text_view->xoffset;
+      *buffer_x -= text_view->text_window->allocation.x;
     }
 
   if (buffer_y)
     {
-      *buffer_y = widget_y - focus_edge_width + text_view->yoffset;
-      if (text_view->top_window)
-        *buffer_y -= text_view->top_window->allocation.height;
+      *buffer_y = widget_y + text_view->yoffset;
+      *buffer_y -= text_view->text_window->allocation.y;
     }
 }
 
@@ -6969,7 +7089,7 @@ text_window_to_buffer (GtkTextView   *text_view,
 /**
  * gtk_text_view_window_to_buffer_coords:
  * @text_view: a #GtkTextView
- * @win: a #GtkTextWindowType
+ * @win: a #GtkTextWindowType except #GTK_TEXT_WINDOW_PRIVATE
  * @window_x: window x coordinate
  * @window_y: window y coordinate
  * @buffer_x: buffer x coordinate return location
@@ -6977,6 +7097,9 @@ text_window_to_buffer (GtkTextView   *text_view,
  *
  * Converts coordinates on the window identified by @win to buffer
  * coordinates, storing the result in (@buffer_x,@buffer_y).
+ *
+ * Note that you can't convert coordinates for a nonexisting window (see 
+ * gtk_text_view_set_border_window_size()).
  **/
 void
 gtk_text_view_window_to_buffer_coords (GtkTextView      *text_view,
@@ -7225,14 +7348,15 @@ text_view_child_new_anchored (GtkWidget          *child,
 
   vc = g_new (GtkTextViewChild, 1);
 
+  vc->type = GTK_TEXT_WINDOW_PRIVATE;
   vc->widget = child;
   vc->anchor = anchor;
 
   vc->from_top_of_line = 0;
   vc->from_left_of_buffer = 0;
   
-  g_object_ref (G_OBJECT (vc->widget));
-  g_object_ref (G_OBJECT (vc->anchor));
+  g_object_ref (vc->widget);
+  g_object_ref (vc->anchor);
 
   g_object_set_data (G_OBJECT (child),
                      "gtk-text-view-child",
@@ -7258,8 +7382,8 @@ text_view_child_new_window (GtkWidget          *child,
 
   vc->from_top_of_line = 0;
   vc->from_left_of_buffer = 0;
-  
-  g_object_ref (G_OBJECT (vc->widget));
+  g_object_ref (vc->widget);
 
   vc->type = type;
   vc->x = x;
@@ -7282,10 +7406,10 @@ text_view_child_free (GtkTextViewChild *child)
     {
       gtk_text_child_anchor_unregister_child (child->anchor,
                                               child->widget);
-      g_object_unref (G_OBJECT (child->anchor));
+      g_object_unref (child->anchor);
     }
 
-  g_object_unref (G_OBJECT (child->widget));
+  g_object_unref (child->widget);
 
   g_free (child);
 }