]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtktextview.c
Patch from Matthias Clasen (#54488)
[~andy/gtk] / gtk / gtktextview.c
index a62681ef6acc53dd2d75733b3d9d3d7021d841f8..c466304cefefa5f7ca5a47387d15dbb054872826 100644 (file)
 
 #include <string.h>
 
+#define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
 #include "gtkbindings.h"
 #include "gtkdnd.h"
+#include "gtkimagemenuitem.h"
 #include "gtkintl.h"
 #include "gtkmain.h"
+#include "gtkmarshalers.h"
 #include "gtkmenu.h"
 #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.
@@ -76,9 +83,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
@@ -89,6 +93,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;
@@ -103,6 +110,7 @@ enum
   SET_SCROLL_ADJUSTMENTS,
   POPULATE_POPUP,
   MOVE_CURSOR,
+  PAGE_HORIZONTALLY,
   SET_ANCHOR,
   INSERT_AT_CURSOR,
   DELETE_FROM_CURSOR,
@@ -110,6 +118,7 @@ enum
   COPY_CLIPBOARD,
   PASTE_CLIPBOARD,
   TOGGLE_OVERWRITE,
+  MOVE_FOCUS,
   LAST_SIGNAL
 };
 
@@ -171,6 +180,10 @@ static gint gtk_text_view_motion_event         (GtkWidget        *widget,
 static gint gtk_text_view_expose_event         (GtkWidget        *widget,
                                                 GdkEventExpose   *expose);
 static void gtk_text_view_draw_focus           (GtkWidget        *widget);
+static void gtk_text_view_grab_focus           (GtkWidget        *widget);
+static gboolean gtk_text_view_focus            (GtkWidget        *widget,
+                                                GtkDirectionType  direction);
+
 
 /* Source side drag signals */
 static void gtk_text_view_drag_begin       (GtkWidget        *widget,
@@ -210,15 +223,20 @@ 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 void gtk_text_view_move_cursor      (GtkTextView           *text_view,
-                                            GtkMovementStep        step,
-                                            gint                   count,
-                                            gboolean               extend_selection);
+static gboolean gtk_text_view_popup_menu         (GtkWidget     *widget);
+
+static void gtk_text_view_move_cursor       (GtkTextView           *text_view,
+                                             GtkMovementStep        step,
+                                             gint                   count,
+                                             gboolean               extend_selection);
+static void gtk_text_view_page_horizontally (GtkTextView          *text_view,
+                                             gint                  count,
+                                             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);
+static void gtk_text_view_scroll_hpages    (GtkTextView           *text_view,
+                                            gint                   count);
 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,
@@ -228,6 +246,8 @@ static void gtk_text_view_cut_clipboard    (GtkTextView           *text_view);
 static void gtk_text_view_copy_clipboard   (GtkTextView           *text_view);
 static void gtk_text_view_paste_clipboard  (GtkTextView           *text_view);
 static void gtk_text_view_toggle_overwrite (GtkTextView           *text_view);
+static void gtk_text_view_move_focus       (GtkTextView           *text_view,
+                                            GtkDirectionType       direction_type);
 static void gtk_text_view_unselect         (GtkTextView           *text_view);
 
 static void     gtk_text_view_validate_onscreen     (GtkTextView        *text_view);
@@ -253,13 +273,21 @@ static void     gtk_text_view_check_cursor_blink     (GtkTextView        *text_v
 static void     gtk_text_view_pend_cursor_blink      (GtkTextView        *text_view);
 static void     gtk_text_view_stop_cursor_blink      (GtkTextView        *text_view);
 
-static void gtk_text_view_value_changed           (GtkAdjustment *adj,
-                                                  GtkTextView   *view);
-static void gtk_text_view_commit_handler          (GtkIMContext  *context,
-                                                  const gchar   *str,
-                                                  GtkTextView   *text_view);
-static void gtk_text_view_preedit_changed_handler (GtkIMContext  *context,
-                                                  GtkTextView   *text_view);
+static void     gtk_text_view_value_changed                (GtkAdjustment *adj,
+                                                           GtkTextView   *view);
+static void     gtk_text_view_commit_handler               (GtkIMContext  *context,
+                                                           const gchar   *str,
+                                                           GtkTextView   *text_view);
+static void     gtk_text_view_commit_text                  (GtkTextView   *text_view,
+                                                            const gchar   *text);
+static void     gtk_text_view_preedit_changed_handler      (GtkIMContext  *context,
+                                                           GtkTextView   *text_view);
+static gboolean gtk_text_view_retrieve_surrounding_handler (GtkIMContext  *context,
+                                                           GtkTextView   *text_view);
+static gboolean gtk_text_view_delete_surrounding_handler   (GtkIMContext  *context,
+                                                           gint           offset,
+                                                           gint           n_chars,
+                                                           GtkTextView   *text_view);
 
 static void gtk_text_view_mark_set_handler       (GtkTextBuffer     *buffer,
                                                   const GtkTextIter *location,
@@ -285,8 +313,12 @@ 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 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);
 
 /* Container methods */
 static void gtk_text_view_add    (GtkContainer *container,
@@ -295,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. */
@@ -375,7 +407,6 @@ static GtkTargetEntry target_table[] = {
   { "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 }
 };
 
@@ -464,7 +495,9 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
   widget_class->focus_out_event = gtk_text_view_focus_out_event;
   widget_class->motion_notify_event = gtk_text_view_motion_event;
   widget_class->expose_event = gtk_text_view_expose_event;
-
+  widget_class->grab_focus = gtk_text_view_grab_focus;
+  widget_class->focus = gtk_text_view_focus;
+  
   widget_class->drag_begin = gtk_text_view_drag_begin;
   widget_class->drag_end = gtk_text_view_drag_end;
   widget_class->drag_data_get = gtk_text_view_drag_data_get;
@@ -482,6 +515,7 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
   container_class->forall = gtk_text_view_forall;
 
   klass->move_cursor = gtk_text_view_move_cursor;
+  klass->page_horizontally = gtk_text_view_page_horizontally;
   klass->set_anchor = gtk_text_view_set_anchor;
   klass->insert_at_cursor = gtk_text_view_insert_at_cursor;
   klass->delete_from_cursor = gtk_text_view_delete_from_cursor;
@@ -489,6 +523,7 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
   klass->copy_clipboard = gtk_text_view_copy_clipboard;
   klass->paste_clipboard = gtk_text_view_paste_clipboard;
   klass->toggle_overwrite = gtk_text_view_toggle_overwrite;
+  klass->move_focus = gtk_text_view_move_focus;
   klass->set_scroll_adjustments = gtk_text_view_set_scroll_adjustments;
 
   /*
@@ -598,18 +633,6 @@ 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
    */
@@ -619,15 +642,23 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
                     GTK_RUN_LAST | GTK_RUN_ACTION,
                     GTK_CLASS_TYPE (object_class),
                     GTK_SIGNAL_OFFSET (GtkTextViewClass, move_cursor),
-                    gtk_marshal_VOID__ENUM_INT_BOOLEAN,
+                    _gtk_marshal_VOID__ENUM_INT_BOOLEAN,
                     GTK_TYPE_NONE, 3, GTK_TYPE_MOVEMENT_STEP, GTK_TYPE_INT, GTK_TYPE_BOOL);
 
+  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);
+  
   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_marshal_VOID__VOID,
                     GTK_TYPE_NONE, 0);
 
   signals[INSERT_AT_CURSOR] =
@@ -635,7 +666,7 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
                     GTK_RUN_LAST | GTK_RUN_ACTION,
                     GTK_CLASS_TYPE (object_class),
                     GTK_SIGNAL_OFFSET (GtkTextViewClass, insert_at_cursor),
-                    gtk_marshal_VOID__STRING,
+                    _gtk_marshal_VOID__STRING,
                     GTK_TYPE_NONE, 1, GTK_TYPE_STRING);
 
   signals[DELETE_FROM_CURSOR] =
@@ -643,7 +674,7 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
                     GTK_RUN_LAST | GTK_RUN_ACTION,
                     GTK_CLASS_TYPE (object_class),
                     GTK_SIGNAL_OFFSET (GtkTextViewClass, delete_from_cursor),
-                    gtk_marshal_VOID__ENUM_INT,
+                    _gtk_marshal_VOID__ENUM_INT,
                     GTK_TYPE_NONE, 2, GTK_TYPE_DELETE_TYPE, GTK_TYPE_INT);
 
   signals[CUT_CLIPBOARD] =
@@ -651,7 +682,7 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
                     GTK_RUN_LAST | GTK_RUN_ACTION,
                     GTK_CLASS_TYPE (object_class),
                     GTK_SIGNAL_OFFSET (GtkTextViewClass, cut_clipboard),
-                    gtk_marshal_VOID__VOID,
+                    _gtk_marshal_VOID__VOID,
                     GTK_TYPE_NONE, 0);
 
   signals[COPY_CLIPBOARD] =
@@ -659,7 +690,7 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
                     GTK_RUN_LAST | GTK_RUN_ACTION,
                     GTK_CLASS_TYPE (object_class),
                     GTK_SIGNAL_OFFSET (GtkTextViewClass, copy_clipboard),
-                    gtk_marshal_VOID__VOID,
+                    _gtk_marshal_VOID__VOID,
                     GTK_TYPE_NONE, 0);
 
   signals[PASTE_CLIPBOARD] =
@@ -667,7 +698,7 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
                     GTK_RUN_LAST | GTK_RUN_ACTION,
                     GTK_CLASS_TYPE (object_class),
                     GTK_SIGNAL_OFFSET (GtkTextViewClass, paste_clipboard),
-                    gtk_marshal_VOID__VOID,
+                    _gtk_marshal_VOID__VOID,
                     GTK_TYPE_NONE, 0);
 
   signals[TOGGLE_OVERWRITE] =
@@ -675,15 +706,23 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
                     GTK_RUN_LAST | GTK_RUN_ACTION,
                     GTK_CLASS_TYPE (object_class),
                     GTK_SIGNAL_OFFSET (GtkTextViewClass, toggle_overwrite),
-                    gtk_marshal_VOID__VOID,
+                    _gtk_marshal_VOID__VOID,
                     GTK_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);
+  
   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_marshal_VOID__OBJECT_OBJECT,
                     GTK_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
   widget_class->set_scroll_adjustments_signal = signals[SET_SCROLL_ADJUSTMENTS];
 
@@ -692,7 +731,7 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
                     GTK_RUN_LAST,
                     GTK_CLASS_TYPE (object_class),
                     GTK_SIGNAL_OFFSET (GtkTextViewClass, populate_popup),
-                    gtk_marshal_VOID__OBJECT,
+                    _gtk_marshal_VOID__OBJECT,
                     GTK_TYPE_NONE, 1, GTK_TYPE_MENU);
   
   /*
@@ -700,7 +739,7 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
    */
 
   binding_set = gtk_binding_set_by_class (klass);
-
+  
   /* Moving the insertion point */
   add_move_binding (binding_set, GDK_Right, 0,
                     GTK_MOVEMENT_VISUAL_POSITIONS, 1);
@@ -714,12 +753,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);
 
@@ -732,7 +765,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);
 
@@ -745,12 +777,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);
 
@@ -763,18 +789,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);
 
@@ -810,12 +824,60 @@ 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,
+                                GTK_TYPE_INT, -1,
+                               GTK_TYPE_BOOL, FALSE);
+  gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
+                                "move_cursor", 3,
+                                GTK_TYPE_MOVEMENT_STEP, GTK_MOVEMENT_BUFFER_ENDS,
+                                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);
+  gtk_binding_entry_add_signal (binding_set, GDK_Page_Up, GDK_CONTROL_MASK,
+                                "page_horizontally", 2,
+                                GTK_TYPE_INT, -1,
+                                GTK_TYPE_BOOL, 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);
+
+  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);
+
+  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);
+
+  gtk_binding_entry_add_signal (binding_set, GDK_Page_Down, GDK_CONTROL_MASK,
+                                "page_horizontally", 2,
+                                GTK_TYPE_INT, 1,
+                                GTK_TYPE_BOOL, 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);
+
+  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);
+
+  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);
   
   /* Deleting text */
   gtk_binding_entry_add_signal (binding_set, GDK_Delete, 0,
@@ -828,11 +890,6 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
                                 GTK_TYPE_ENUM, GTK_DELETE_CHARS,
                                 GTK_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,
@@ -848,71 +905,45 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
                                 GTK_TYPE_ENUM, GTK_DELETE_WORD_ENDS,
                                 GTK_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);
-
   /* 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);
-
   gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK,
                                 "copy_clipboard", 0);
 
   gtk_binding_entry_add_signal (binding_set, GDK_v, GDK_CONTROL_MASK,
                                 "paste_clipboard", 0);
 
-  gtk_binding_entry_add_signal (binding_set, GDK_y, GDK_CONTROL_MASK,
-                                "paste_clipboard", 0);
-
   /* Overwrite */
   gtk_binding_entry_add_signal (binding_set, GDK_Insert, 0,
                                 "toggle_overwrite", 0);
   gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, 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);
+  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_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_KP_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
+                                "move_focus", 1,
+                                GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
 }
 
-void
+static void
 gtk_text_view_init (GtkTextView *text_view)
 {
   GtkWidget *widget;
@@ -948,9 +979,12 @@ gtk_text_view_init (GtkTextView *text_view)
 
   g_signal_connect (G_OBJECT (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_CALLBACK (gtk_text_view_preedit_changed_handler), text_view);
+  g_signal_connect (G_OBJECT (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_CALLBACK (gtk_text_view_delete_surrounding_handler), text_view);
 
   text_view->cursor_visible = TRUE;
 
@@ -961,6 +995,9 @@ gtk_text_view_init (GtkTextView *text_view)
   text_view->drag_start_y = -1;
 
   text_view->pending_place_cursor_button = 0;
+
+  /* We handle all our own redrawing */
+  gtk_widget_set_redraw_on_allocate (widget, FALSE);
 }
 
 /**
@@ -1089,9 +1126,12 @@ gtk_text_view_set_buffer (GtkTextView   *text_view,
        gtk_text_buffer_add_selection_clipboard (text_view->buffer,
                                                 gtk_clipboard_get (GDK_SELECTION_PRIMARY));
     }
-
+  
   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);
 }
 
 static GtkTextBuffer*
@@ -1299,6 +1339,11 @@ gtk_text_view_scroll_to_iter (GtkTextView   *text_view,
   gint scroll_inc;
   gint screen_xoffset, screen_yoffset;
   gint current_x_scroll, current_y_scroll;
+
+  /* FIXME why don't we do the validate-at-scroll-destination thing
+   * from flush_scroll in this function? I think it wasn't done before
+   * because changed_handler was screwed up, but I could be wrong.
+   */
   
   g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
   g_return_val_if_fail (iter != NULL, FALSE);
@@ -1310,12 +1355,6 @@ gtk_text_view_scroll_to_iter (GtkTextView   *text_view,
 
   DV(g_print(G_STRLOC"\n"));
   
-  if (!GTK_WIDGET_MAPPED (widget))
-    {
-      g_warning ("gtk_text_view_scroll_to_iter(): calling this function before showing the GtkTextView doesn't make sense, maybe try gtk_text_view_scroll_to_mark() instead");
-      return FALSE;
-    }
-  
   gtk_text_layout_get_iter_location (text_view->layout,
                                      iter,
                                      &rect);
@@ -1488,11 +1527,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;
 
@@ -1501,11 +1546,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"));
 
@@ -1557,8 +1608,9 @@ gtk_text_view_update_adjustments (GtkTextView *text_view)
   gint width = 0, height = 0;
 
   DV(g_print(">Updating adjustments ("G_STRLOC")\n"));
-  
-  gtk_text_layout_get_size (text_view->layout, &width, &height);
+
+  if (text_view->layout)
+    gtk_text_layout_get_size (text_view->layout, &width, &height);
 
   if (text_view->width != width || text_view->height != height)
     {
@@ -1601,6 +1653,24 @@ gtk_text_view_update_layout_width (GtkTextView *text_view)
                                     SCREEN_WIDTH (text_view));
 }
 
+static void
+gtk_text_view_update_im_spot_location (GtkTextView *text_view)
+{
+  GdkRectangle area;
+  gint cursor_x_pos, cursor_y_pos;
+
+  if (text_view->layout == NULL)
+    return;
+  
+  gtk_text_view_get_virtual_cursor_pos (text_view, &cursor_x_pos, &cursor_y_pos);
+
+  area.x = cursor_x_pos;
+  area.y = cursor_y_pos;
+  area.width = area.height = 0;
+
+  gtk_im_context_set_cursor_location (text_view->im_context, &area);
+}
+
 /**
  * gtk_text_view_scroll_to_mark:
  * @text_view: a #GtkTextView
@@ -1646,6 +1716,15 @@ gtk_text_view_scroll_to_mark (GtkTextView *text_view,
     gtk_text_view_flush_scroll (text_view);
 }
 
+/**
+ * gtk_text_view_scroll_mark_onscreen:
+ * @text_view: a #GtkTextView
+ * @mark: a mark in the buffer for @text_view
+ * 
+ * Scrolls @text_view the minimum distance such that @mark is contained
+ * within the visible area of the widget.
+ * 
+ **/
 void
 gtk_text_view_scroll_mark_onscreen (GtkTextView *text_view,
                                     GtkTextMark *mark)
@@ -1788,6 +1867,7 @@ gtk_text_view_set_editable (GtkTextView *text_view,
                             gboolean     setting)
 {
   g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
+  setting = setting != FALSE;
 
   if (text_view->editable != setting)
     {
@@ -1798,9 +1878,9 @@ gtk_text_view_set_editable (GtkTextView *text_view,
           text_view->layout->default_style->editable = text_view->editable;
           gtk_text_layout_default_style_changed (text_view->layout);
         }
-    }
 
-  g_object_notify (G_OBJECT (text_view), "editable");
+      g_object_notify (G_OBJECT (text_view), "editable");
+    }
 }
 
 /**
@@ -1820,6 +1900,15 @@ gtk_text_view_get_editable (GtkTextView *text_view)
   return text_view->editable;
 }
 
+/**
+ * gtk_text_view_set_pixels_above_lines:
+ * @text_view: a #GtkTextView
+ * @pixels_above_lines: pixels above paragraphs
+ * 
+ * Sets the default number of blank pixels above paragraphs in @text_view.
+ * Tags in the buffer for @text_view may override the defaults.
+ * 
+ **/
 void
 gtk_text_view_set_pixels_above_lines (GtkTextView *text_view,
                                       gint         pixels_above_lines)
@@ -1835,11 +1924,19 @@ gtk_text_view_set_pixels_above_lines (GtkTextView *text_view,
           text_view->layout->default_style->pixels_above_lines = pixels_above_lines;
           gtk_text_layout_default_style_changed (text_view->layout);
         }
-    }
 
-  g_object_notify (G_OBJECT (text_view), "pixels_above_lines");
+      g_object_notify (G_OBJECT (text_view), "pixels_above_lines");
+    }
 }
 
+/**
+ * gtk_text_view_get_pixels_above_lines:
+ * @text_view: a #GtkTextView
+ * 
+ * Gets the default number of pixels to put above paragraphs.
+ * 
+ * Return value: default number of pixels above paragraphs
+ **/
 gint
 gtk_text_view_get_pixels_above_lines (GtkTextView *text_view)
 {
@@ -1848,6 +1945,16 @@ gtk_text_view_get_pixels_above_lines (GtkTextView *text_view)
   return text_view->pixels_above_lines;
 }
 
+/**
+ * gtk_text_view_set_pixels_below_lines:
+ * @text_view: a #GtkTextView
+ * @pixels_below_lines: pixels below paragraphs 
+ *
+ * Sets the default number of pixels of blank space
+ * to put below paragraphs in @text_view. May be overridden
+ * by tags applied to @text_view's buffer. 
+ * 
+ **/
 void
 gtk_text_view_set_pixels_below_lines (GtkTextView *text_view,
                                       gint         pixels_below_lines)
@@ -1863,11 +1970,19 @@ gtk_text_view_set_pixels_below_lines (GtkTextView *text_view,
           text_view->layout->default_style->pixels_below_lines = pixels_below_lines;
           gtk_text_layout_default_style_changed (text_view->layout);
         }
-    }
 
-  g_object_notify (G_OBJECT (text_view), "pixels_below_lines");
+      g_object_notify (G_OBJECT (text_view), "pixels_below_lines");
+    }
 }
 
+/**
+ * gtk_text_view_get_pixels_below_lines:
+ * @text_view: a #GtkTextView
+ * 
+ * Gets the value set by gtk_text_view_set_pixels_below_lines().
+ * 
+ * Return value: default number of blank pixels below paragraphs
+ **/
 gint
 gtk_text_view_get_pixels_below_lines (GtkTextView *text_view)
 {
@@ -1876,6 +1991,16 @@ gtk_text_view_get_pixels_below_lines (GtkTextView *text_view)
   return text_view->pixels_below_lines;
 }
 
+/**
+ * gtk_text_view_set_pixels_inside_wrap:
+ * @text_view: a #GtkTextView
+ * @pixels_inside_wrap: default number of pixels between wrapped lines
+ *
+ * Sets the default number of pixels of blank space to leave between
+ * display/wrapped lines within a paragraph. May be overridden by
+ * tags in @text_view's buffer.
+ * 
+ **/
 void
 gtk_text_view_set_pixels_inside_wrap (GtkTextView *text_view,
                                       gint         pixels_inside_wrap)
@@ -1891,10 +2016,19 @@ gtk_text_view_set_pixels_inside_wrap (GtkTextView *text_view,
           text_view->layout->default_style->pixels_inside_wrap = pixels_inside_wrap;
           gtk_text_layout_default_style_changed (text_view->layout);
         }
+
+      g_object_notify (G_OBJECT (text_view), "pixels_inside_wrap");
     }
-  g_object_notify (G_OBJECT (text_view), "pixels_inside_wrap");
 }
 
+/**
+ * gtk_text_view_get_pixels_inside_wrap:
+ * @text_view: a #GtkTextView
+ * 
+ * Gets the value set by gtk_text_view_set_pixels_inside_wrap().
+ * 
+ * Return value: default number of pixels of blank space between wrapped lines
+ **/
 gint
 gtk_text_view_get_pixels_inside_wrap (GtkTextView *text_view)
 {
@@ -1903,26 +2037,44 @@ gtk_text_view_get_pixels_inside_wrap (GtkTextView *text_view)
   return text_view->pixels_inside_wrap;
 }
 
+/**
+ * gtk_text_view_set_justification:
+ * @text_view: a #GtkTextView
+ * @justification: justification
+ *
+ * Sets the default justification of text in @text_view.
+ * Tags in the view's buffer may override the default.
+ * 
+ **/
 void
 gtk_text_view_set_justification (GtkTextView     *text_view,
-                                 GtkJustification justify)
+                                 GtkJustification justification)
 {
   g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
 
-  if (text_view->justify != justify)
+  if (text_view->justify != justification)
     {
-      text_view->justify = justify;
+      text_view->justify = justification;
 
       if (text_view->layout)
         {
-          text_view->layout->default_style->justification = justify;
+          text_view->layout->default_style->justification = justification;
           gtk_text_layout_default_style_changed (text_view->layout);
         }
-    }
 
-  g_object_notify (G_OBJECT (text_view), "justification");
+      g_object_notify (G_OBJECT (text_view), "justification");
+    }
 }
 
+/**
+ * gtk_text_view_get_justification:
+ * @text_view: a #GtkTextView
+ * 
+ * Gets the default justification of paragraphs in @text_view.
+ * Tags in the buffer may override the default.
+ * 
+ * Return value: default justification
+ **/
 GtkJustification
 gtk_text_view_get_justification (GtkTextView *text_view)
 {
@@ -1931,6 +2083,15 @@ gtk_text_view_get_justification (GtkTextView *text_view)
   return text_view->justify;
 }
 
+/**
+ * gtk_text_view_set_left_margin:
+ * @text_view: a #GtkTextView
+ * @left_margin: left margin in pixels
+ * 
+ * Sets the default left margin for text in @text_view.
+ * Tags in the buffer may override the default.
+ * 
+ **/
 void
 gtk_text_view_set_left_margin (GtkTextView *text_view,
                                gint         left_margin)
@@ -1946,11 +2107,20 @@ gtk_text_view_set_left_margin (GtkTextView *text_view,
           text_view->layout->default_style->left_margin = left_margin;
           gtk_text_layout_default_style_changed (text_view->layout);
         }
-    }
 
-  g_object_notify (G_OBJECT (text_view), "left_margin");
+      g_object_notify (G_OBJECT (text_view), "left_margin");
+    }
 }
 
+/**
+ * gtk_text_view_get_left_margin:
+ * @text_view: a #GtkTextView
+ * 
+ * Gets the default left margin size of paragraphs in the @text_view.
+ * Tags in the buffer may override the default.
+ * 
+ * Return value: left margin in pixels
+ **/
 gint
 gtk_text_view_get_left_margin (GtkTextView *text_view)
 {
@@ -1959,6 +2129,15 @@ gtk_text_view_get_left_margin (GtkTextView *text_view)
   return text_view->left_margin;
 }
 
+/**
+ * gtk_text_view_set_right_margin:
+ * @text_view: a #GtkTextView
+ * @right_margin: right margin in pixels
+ *
+ * Sets the default right margin for text in the text view.
+ * Tags in the buffer may override the default.
+ * 
+ **/
 void
 gtk_text_view_set_right_margin (GtkTextView *text_view,
                                 gint         right_margin)
@@ -1974,11 +2153,20 @@ gtk_text_view_set_right_margin (GtkTextView *text_view,
           text_view->layout->default_style->right_margin = right_margin;
           gtk_text_layout_default_style_changed (text_view->layout);
         }
-    }
 
-  g_object_notify (G_OBJECT (text_view), "right_margin");
+      g_object_notify (G_OBJECT (text_view), "right_margin");
+    }
 }
 
+/**
+ * gtk_text_view_get_right_margin:
+ * @text_view: a #GtkTextView
+ * 
+ * Gets the default right margin for text in @text_view. Tags
+ * in the buffer may override the default.
+ * 
+ * Return value: right margin in pixels
+ **/
 gint
 gtk_text_view_get_right_margin (GtkTextView *text_view)
 {
@@ -1987,6 +2175,15 @@ gtk_text_view_get_right_margin (GtkTextView *text_view)
   return text_view->right_margin;
 }
 
+/**
+ * gtk_text_view_set_indent:
+ * @text_view: a #GtkTextView
+ * @indent: indentation in pixels
+ *
+ * Sets the default indentation for paragraphs in @text_view.
+ * Tags in the buffer may override the default.
+ * 
+ **/
 void
 gtk_text_view_set_indent (GtkTextView *text_view,
                           gint         indent)
@@ -2002,10 +2199,21 @@ gtk_text_view_set_indent (GtkTextView *text_view,
           text_view->layout->default_style->indent = indent;
           gtk_text_layout_default_style_changed (text_view->layout);
         }
+
+      g_object_notify (G_OBJECT (text_view), "indent");
     }
-  g_object_notify (G_OBJECT (text_view), "indent");
 }
 
+/**
+ * gtk_text_view_get_indent:
+ * @text_view: a #GtkTextView
+ * 
+ * Gets the default indentation of paragraphs in @text_view.
+ * Tags in the view's buffer may override the default.
+ * The indentation may be negative.
+ * 
+ * Return value: number of pixels of indentation
+ **/
 gint
 gtk_text_view_get_indent (GtkTextView *text_view)
 {
@@ -2014,6 +2222,15 @@ gtk_text_view_get_indent (GtkTextView *text_view)
   return text_view->indent;
 }
 
+/**
+ * gtk_text_view_set_tabs:
+ * @text_view: a #GtkTextView
+ * @tabs: tabs as a #PangoTabArray
+ *
+ * Sets the default tab stops for paragraphs in @text_view.
+ * Tags in the buffer may override the default.
+ * 
+ **/
 void
 gtk_text_view_set_tabs (GtkTextView   *text_view,
                         PangoTabArray *tabs)
@@ -2040,6 +2257,17 @@ gtk_text_view_set_tabs (GtkTextView   *text_view,
   g_object_notify (G_OBJECT (text_view), "tabs");
 }
 
+/**
+ * gtk_text_view_get_tabs:
+ * @text_view: a #GtkTextView
+ * 
+ * Gets the default tabs for @text_view. Tags in the buffer may
+ * override the defaults. The returned array will be %NULL if
+ * "standard" (8-space) tabs are used. Free the return value
+ * with pango_tab_array_free().
+ * 
+ * Return value: copy of default tab array, or %NULL if "standard" tabs are used; must be freed with pango_tab_array_free().
+ **/
 PangoTabArray*
 gtk_text_view_get_tabs (GtkTextView *text_view)
 {
@@ -2077,9 +2305,9 @@ gtk_text_view_set_cursor_visible    (GtkTextView   *text_view,
              gtk_text_view_check_cursor_blink (text_view);
             }
         }
-    }
 
-  g_object_notify (G_OBJECT (text_view), "cursor_visible");
+      g_object_notify (G_OBJECT (text_view), "cursor_visible");
+    }
 }
 
 /**
@@ -2128,6 +2356,23 @@ gtk_text_view_place_cursor_onscreen (GtkTextView *text_view)
     return FALSE;
 }
 
+static void
+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;
+    }
+
+  if (text_view->incremental_validate_idle != 0)
+    {
+      g_source_remove (text_view->incremental_validate_idle);
+      text_view->incremental_validate_idle = 0;
+    }
+}
+
 static void
 gtk_text_view_destroy (GtkObject *object)
 {
@@ -2138,8 +2383,9 @@ gtk_text_view_destroy (GtkObject *object)
 
   layout = text_view->layout;
   
-  gtk_text_view_destroy_layout (text_view);
+  gtk_text_view_remove_validate_idles (text_view);
   gtk_text_view_set_buffer (text_view, NULL);
+  gtk_text_view_destroy_layout (text_view);
 
   (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
 }
@@ -2235,7 +2481,7 @@ gtk_text_view_set_property (GObject         *object,
       break;
 
     case PROP_TABS:
-      gtk_text_view_set_tabs (text_view, g_value_get_object (value));
+      gtk_text_view_set_tabs (text_view, g_value_get_boxed (value));
       break;
 
     case PROP_CURSOR_VISIBLE:
@@ -2297,7 +2543,7 @@ gtk_text_view_get_property (GObject         *object,
       break;
 
     case PROP_TABS:
-      g_value_set_object (value, gtk_text_view_get_tabs (text_view));
+      g_value_set_boxed (value, text_view->tabs);
       break;
 
     case PROP_CURSOR_VISIBLE:
@@ -2317,16 +2563,20 @@ gtk_text_view_size_request (GtkWidget      *widget,
   GtkTextView *text_view;
   GSList *tmp_list;
   gint focus_edge_width;
+  gint focus_width;
   gboolean interior_focus;
   
   text_view = GTK_TEXT_VIEW (widget);
 
-  gtk_widget_style_get (widget, "interior_focus", &interior_focus, NULL);
+  gtk_widget_style_get (widget,
+                       "interior_focus", &interior_focus,
+                       "focus_line_width", &focus_width,
+                       NULL);
 
   if (interior_focus)
     focus_edge_width = 0;
   else
-    focus_edge_width = 1;
+    focus_edge_width = focus_width;
 
   if (text_view->layout)
     {
@@ -2354,6 +2604,9 @@ gtk_text_view_size_request (GtkWidget      *widget,
   if (text_view->bottom_window)
     requisition->height += text_view->bottom_window->requisition.height;
 
+  requisition->width += GTK_CONTAINER (text_view)->border_width * 2;
+  requisition->height += GTK_CONTAINER (text_view)->border_width * 2;
+  
   tmp_list = text_view->children;
   while (tmp_list != NULL)
     {
@@ -2364,10 +2617,13 @@ gtk_text_view_size_request (GtkWidget      *widget,
           GtkRequisition child_req;
           GtkRequisition old_req;
 
-          old_req = child->widget->requisition;
-
+          gtk_widget_get_child_requisition (child->widget, &old_req);
+          
           gtk_widget_size_request (child->widget, &child_req);
 
+          gtk_widget_get_child_requisition (child->widget, &child_req);
+
+          /* Invalidate layout lines if required */
           if (text_view->layout &&
               (old_req.width != child_req.width ||
                old_req.height != child_req.height))
@@ -2376,7 +2632,9 @@ gtk_text_view_size_request (GtkWidget      *widget,
         }
       else
         {
-
+          GtkRequisition child_req;
+          
+          gtk_widget_size_request (child->widget, &child_req);
         }
 
       tmp_list = g_slist_next (tmp_list);
@@ -2384,12 +2642,13 @@ gtk_text_view_size_request (GtkWidget      *widget,
 }
 
 static void
-gtk_text_view_update_child_allocation (GtkTextView      *text_view,
-                                       GtkTextViewChild *vc)
+gtk_text_view_compute_child_allocation (GtkTextView      *text_view,
+                                        GtkTextViewChild *vc,
+                                        GtkAllocation    *allocation)
 {
   gint buffer_y;
   GtkTextIter iter;
-  GtkAllocation allocation;
+  GtkRequisition req;
   
   gtk_text_buffer_get_iter_at_child_anchor (get_buffer (text_view),
                                             &iter,
@@ -2400,21 +2659,40 @@ gtk_text_view_update_child_allocation (GtkTextView      *text_view,
 
   buffer_y += vc->from_top_of_line;
 
-  allocation.x = vc->from_left_of_buffer;
-  allocation.y = buffer_y;
-  allocation.width = vc->widget->requisition.width;
-  allocation.height = vc->widget->requisition.height;
-  
-  gtk_widget_size_allocate (vc->widget, &allocation);
+  allocation->x = vc->from_left_of_buffer - text_view->xoffset;
+  allocation->y = buffer_y - text_view->yoffset;
+
+  gtk_widget_get_child_requisition (vc->widget, &req);
+  allocation->width = req.width;
+  allocation->height = req.height;
 }
 
 static void
-gtk_text_view_child_allocated (GtkTextLayout *layout,
-                               GtkWidget     *child,
-                               gint           x,
-                               gint           y,
-                               gpointer       data)
-{
+gtk_text_view_update_child_allocation (GtkTextView      *text_view,
+                                       GtkTextViewChild *vc)
+{
+  GtkAllocation allocation;
+
+  gtk_text_view_compute_child_allocation (text_view, vc, &allocation);
+  
+  gtk_widget_size_allocate (vc->widget, &allocation);
+
+#if 0
+  g_print ("allocation for %p allocated to %d,%d yoffset = %d\n",
+           vc->widget,
+           vc->widget->allocation.x,
+           vc->widget->allocation.y,
+           text_view->yoffset);
+#endif
+}
+
+static void
+gtk_text_view_child_allocated (GtkTextLayout *layout,
+                               GtkWidget     *child,
+                               gint           x,
+                               gint           y,
+                               gpointer       data)
+{
   GtkTextViewChild *vc = NULL;
   GtkTextView *text_view = data;
   
@@ -2424,11 +2702,11 @@ gtk_text_view_child_allocated (GtkTextLayout *layout,
    */
 
   vc = g_object_get_data (G_OBJECT (child),
-                            "gtk-text-view-child");
+                          "gtk-text-view-child");
 
   g_assert (vc != NULL);
 
-  g_print ("child allocated at %d,%d\n", x, y);
+  DV (g_print ("child allocated at %d,%d\n", x, y));
   
   vc->from_left_of_buffer = x;
   vc->from_top_of_line = y;
@@ -2437,7 +2715,7 @@ gtk_text_view_child_allocated (GtkTextLayout *layout,
 }
 
 static void
-gtk_text_view_validate_children (GtkTextView *text_view)
+gtk_text_view_allocate_children (GtkTextView *text_view)
 {
   GSList *tmp_list;
 
@@ -2464,7 +2742,20 @@ gtk_text_view_validate_children (GtkTextView *text_view)
         }
       else
         {
+          GtkAllocation allocation;          
+          GtkRequisition child_req;
+             
+          g_assert (child != NULL);
+          
+          allocation.x = child->x;
+          allocation.y = child->y;
 
+          gtk_widget_get_child_requisition (child->widget, &child_req);
+          
+          allocation.width = child_req.width;
+          allocation.height = child_req.height;
+          
+          gtk_widget_size_allocate (child->widget, &allocation);          
         }
 
       tmp_list = g_slist_next (tmp_list);
@@ -2487,11 +2778,17 @@ gtk_text_view_size_allocate (GtkWidget *widget,
   GdkRectangle top_rect;
   GdkRectangle bottom_rect;
   gint focus_edge_width;
+  gint focus_width;
   gboolean interior_focus;
+  gboolean size_changed;
   
   text_view = GTK_TEXT_VIEW (widget);
 
   DV(g_print(G_STRLOC"\n"));
+
+  size_changed =
+    widget->allocation.width != allocation->width ||
+    widget->allocation.height != allocation->height;
   
   widget->allocation = *allocation;
 
@@ -2506,26 +2803,29 @@ gtk_text_view_size_allocate (GtkWidget *widget,
    * windows get at least a 1x1 allocation.
    */
 
-  gtk_widget_style_get (widget, "interior_focus", &interior_focus, NULL);
+  gtk_widget_style_get (widget,
+                       "interior_focus", &interior_focus,
+                       "focus_line_width", &focus_width,
+                       NULL);
 
   if (interior_focus)
     focus_edge_width = 0;
   else
-    focus_edge_width = 1;
+    focus_edge_width = focus_width;
   
-  width = allocation->width - focus_edge_width * 2;
+  width = allocation->width - focus_edge_width * 2 - GTK_CONTAINER (text_view)->border_width * 2;
 
   if (text_view->left_window)
     left_rect.width = text_view->left_window->requisition.width;
   else
-    left_rect.width = 1;
+    left_rect.width = 0;
 
   width -= left_rect.width;
 
   if (text_view->right_window)
     right_rect.width = text_view->right_window->requisition.width;
   else
-    right_rect.width = 1;
+    right_rect.width = 0;
 
   width -= right_rect.width;
 
@@ -2535,19 +2835,19 @@ gtk_text_view_size_allocate (GtkWidget *widget,
   bottom_rect.width = text_rect.width;
 
 
-  height = allocation->height - focus_edge_width * 2;
+  height = allocation->height - focus_edge_width * 2 - GTK_CONTAINER (text_view)->border_width * 2;
 
   if (text_view->top_window)
     top_rect.height = text_view->top_window->requisition.height;
   else
-    top_rect.height = 1;
+    top_rect.height = 0;
 
   height -= top_rect.height;
 
   if (text_view->bottom_window)
     bottom_rect.height = text_view->bottom_window->requisition.height;
   else
-    bottom_rect.height = 1;
+    bottom_rect.height = 0;
 
   height -= bottom_rect.height;
 
@@ -2557,8 +2857,8 @@ gtk_text_view_size_allocate (GtkWidget *widget,
   right_rect.height = text_rect.height;
 
   /* Origins */
-  left_rect.x = focus_edge_width;
-  top_rect.y = focus_edge_width;
+  left_rect.x = focus_edge_width + GTK_CONTAINER (text_view)->border_width;
+  top_rect.y = focus_edge_width + GTK_CONTAINER (text_view)->border_width;
 
   text_rect.x = left_rect.x + left_rect.width;
   text_rect.y = top_rect.y + top_rect.height;
@@ -2593,8 +2893,8 @@ gtk_text_view_size_allocate (GtkWidget *widget,
 
   gtk_text_view_update_layout_width (text_view);
   
-  /* This is because validating children ends up size allocating them. */
-  gtk_text_view_validate_children (text_view);
+  /* Note that this will do some layout validation */
+  gtk_text_view_allocate_children (text_view);
 
   /* Now adjust the value of the adjustment to keep the cursor at the
    * same place in the buffer
@@ -2619,14 +2919,16 @@ gtk_text_view_size_allocate (GtkWidget *widget,
     }
 
   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");
 
   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);
@@ -2635,19 +2937,17 @@ gtk_text_view_size_allocate (GtkWidget *widget,
   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. 
-       */
+  /* 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);
 
-      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);
-    }
+  /* widget->window doesn't get auto-redrawn as the layout is computed, so has to
+   * be invalidated
+   */
+  if (size_changed && GTK_WIDGET_REALIZED (widget))
+    gdk_window_invalidate_rect (widget->window, NULL, FALSE);
 }
 
 static void
@@ -2695,23 +2995,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
@@ -2738,8 +3033,23 @@ first_validate_callback (gpointer data)
       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 ();
   
@@ -2772,17 +3082,13 @@ incremental_validate_callback (gpointer data)
 }
 
 static void
-invalidated_handler (GtkTextLayout *layout,
-                     gpointer       data)
-{
-  GtkTextView *text_view;
-
-  text_view = GTK_TEXT_VIEW (data);
+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"));
-  
   if (!text_view->first_validate_idle)
     {
       text_view->first_validate_idle = g_idle_add_full (GTK_PRIORITY_RESIZE - 2, first_validate_callback, text_view, NULL);
@@ -2799,17 +3105,29 @@ invalidated_handler (GtkTextLayout *layout,
 }
 
 static void
-changed_handler (GtkTextLayout *layout,
-                 gint           start_y,
-                 gint           old_height,
-                 gint           new_height,
-                 gpointer       data)
+invalidated_handler (GtkTextLayout *layout,
+                     gpointer       data)
+{
+  GtkTextView *text_view;
+
+  text_view = GTK_TEXT_VIEW (data);
+
+  DV (g_print ("Invalidating due to layout invalidate signal\n"));
+  gtk_text_view_invalidate (text_view);
+}
+
+static void
+changed_handler (GtkTextLayout     *layout,
+                 gint               start_y,
+                 gint               old_height,
+                 gint               new_height,
+                 gpointer           data)
 {
   GtkTextView *text_view;
   GtkWidget *widget;
   GdkRectangle visible_rect;
   GdkRectangle redraw_rect;
-
+  
   text_view = GTK_TEXT_VIEW (data);
   widget = GTK_WIDGET (data);
   
@@ -2852,6 +3170,8 @@ changed_handler (GtkTextLayout *layout,
           if (text_view->bottom_window)
             text_window_invalidate_rect (text_view->bottom_window,
                                          &redraw_rect);
+
+          gtk_text_view_update_im_spot_location (text_view);
         }
     }
   
@@ -2859,16 +3179,39 @@ changed_handler (GtkTextLayout *layout,
     {
       gboolean yoffset_changed = FALSE;
       GSList *tmp_list;
+      int new_first_para_top;
+      int old_first_para_top;
+      GtkTextIter first;
       
-      if (start_y + old_height <= text_view->yoffset - text_view->first_para_pixels)
+      /* If the bottom of the old area was above the top of the
+       * screen, we need to scroll to keep the current top of the
+       * screen in place.  Remember that first_para_pixels is the
+       * position of the top of the screen in coordinates relative to
+       * the first paragraph onscreen.
+       *
+       * In short we are adding the height delta of the portion of the
+       * changed region above first_para_mark to text_view->yoffset.
+       */
+      gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &first,
+                                        text_view->first_para_mark);
+
+      gtk_text_layout_get_line_yrange (layout, &first, &new_first_para_top, NULL);
+
+      old_first_para_top = text_view->yoffset - text_view->first_para_pixels;
+
+      if (new_first_para_top != old_first_para_top)
         {
-          text_view->yoffset += new_height - old_height;
+          text_view->yoffset += new_first_para_top - old_first_para_top;
+          
           get_vadjustment (text_view)->value = text_view->yoffset;
           yoffset_changed = TRUE;
         }
 
       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 */
 
@@ -2883,6 +3226,26 @@ changed_handler (GtkTextLayout *layout,
           tmp_list = g_slist_next (tmp_list);
         }
     }
+
+  {
+    GtkRequisition old_req;
+    GtkRequisition new_req;
+
+    old_req = widget->requisition;
+
+    /* Use this instead of gtk_widget_size_request wrapper
+     * to avoid the optimization which just returns widget->requisition
+     * if a resize hasn't been queued.
+     */
+    GTK_WIDGET_GET_CLASS (widget)->size_request (widget, &new_req);
+
+    if (old_req.width != new_req.width ||
+        old_req.height != new_req.height)
+      {
+        /* FIXME http://bugzilla.gnome.org/show_bug.cgi?id=72258 */
+        _gtk_size_group_queue_resize (widget);
+      }
+  }
 }
 
 static void
@@ -2894,7 +3257,7 @@ gtk_text_view_realize_cursor_gc (GtkTextView *text_view)
   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);
+  gtk_widget_style_get (GTK_WIDGET (text_view), "cursor-color", &cursor_color, NULL);
 
   if (!cursor_color)
     cursor_color = &red;
@@ -2909,6 +3272,7 @@ gtk_text_view_realize (GtkWidget *widget)
   GtkTextView *text_view;
   GdkWindowAttr attributes;
   gint attributes_mask;
+  GSList *tmp_list;
   
   text_view = GTK_TEXT_VIEW (widget);
   GTK_WIDGET_SET_FLAGS (text_view, GTK_REALIZED);
@@ -2960,6 +3324,16 @@ gtk_text_view_realize (GtkWidget *widget)
   if (text_view->buffer)
     gtk_text_buffer_add_selection_clipboard (text_view->buffer,
                                             gtk_clipboard_get (GDK_SELECTION_PRIMARY));
+
+  tmp_list = text_view->children;
+  while (tmp_list != NULL)
+    {
+      GtkTextViewChild *vc = tmp_list->data;
+      
+      text_view_child_set_parent_window (text_view, vc);
+      
+      tmp_list = tmp_list->next;
+    }
 }
 
 static void
@@ -2979,17 +3353,7 @@ gtk_text_view_unrealize (GtkWidget *widget)
       text_view->cursor_gc = NULL;
     }
 
-  if (text_view->first_validate_idle)
-    {
-      g_source_remove (text_view->first_validate_idle);
-      text_view->first_validate_idle = 0;
-    }
-
-  if (text_view->incremental_validate_idle)
-    {
-      g_source_remove (text_view->incremental_validate_idle);
-      text_view->incremental_validate_idle = 0;
-    }
+  gtk_text_view_remove_validate_idles (text_view);
 
   if (text_view->popup_menu)
     {
@@ -3070,6 +3434,45 @@ gtk_text_view_direction_changed (GtkWidget        *widget,
     }
 }
 
+
+static void
+set_invisible_cursor (GdkWindow *window)
+{
+  GdkBitmap *empty_bitmap;
+  GdkCursor *cursor;
+  GdkColor useless;
+  char invisible_cursor_bits[] = { 0x0 };      
+       
+  useless.red = useless.green = useless.blue = 0;
+  useless.pixel = 0;
+  
+  empty_bitmap = gdk_bitmap_create_from_data (window,
+                                             invisible_cursor_bits,
+                                             1, 1);
+  
+  cursor = gdk_cursor_new_from_pixmap (empty_bitmap,
+                                      empty_bitmap,
+                                      &useless,
+                                      &useless, 0, 0);
+  
+  gdk_window_set_cursor (window, cursor);
+  
+  gdk_cursor_unref (cursor);
+  
+  g_object_unref (empty_bitmap);
+}
+
+static void
+gtk_text_view_obscure_mouse_cursor (GtkTextView *text_view)
+{
+  if (text_view->mouse_cursor_obscured)
+    return;
+
+  set_invisible_cursor (text_view->text_window->bin_window);
+  
+  text_view->mouse_cursor_obscured = TRUE;  
+}
+
 /*
  * Events
  */
@@ -3205,6 +3608,7 @@ static gint
 gtk_text_view_key_press_event (GtkWidget *widget, GdkEventKey *event)
 {
   gboolean retval = FALSE;
+  gboolean obscure = FALSE;
   GtkTextView *text_view = GTK_TEXT_VIEW (widget);
   GtkTextMark *insert;
   GtkTextIter iter;
@@ -3219,6 +3623,7 @@ gtk_text_view_key_press_event (GtkWidget *widget, GdkEventKey *event)
       gtk_im_context_filter_keypress (text_view->im_context, event))
     {
       text_view->need_im_reset = TRUE;
+      obscure = TRUE;
       retval = TRUE;
     }
   else if (GTK_WIDGET_CLASS (parent_class)->key_press_event &&
@@ -3227,32 +3632,35 @@ gtk_text_view_key_press_event (GtkWidget *widget, GdkEventKey *event)
   else if (event->keyval == GDK_Return ||
            event->keyval == GDK_KP_Enter)
     {
-      gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), "\n", 1,
-                                                    text_view->editable);
-      DV(g_print (G_STRLOC": scrolling to mark\n"));
-      gtk_text_view_scroll_to_mark (text_view,
-                                    gtk_text_buffer_get_mark (get_buffer (text_view),
-                                                              "insert"),
-                                    0.0, FALSE, 0.0, 0.0);
+      gtk_text_view_commit_text (text_view, "\n");
+
+      obscure = TRUE;
       retval = TRUE;
     }
   /* 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))
     {
-      gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), "\t", 1,
-                                                    text_view->editable);
-      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),
-                                                                    "insert"));
+      /* If the text isn't editable, move the focus instead */
+      if (text_view->editable)
+       {
+         gtk_text_view_commit_text (text_view, "\t");
+         obscure = TRUE;
+       }
+      else
+       gtk_text_view_move_focus (text_view,
+                                 (event->state & GDK_SHIFT_MASK) ?
+                                 GTK_DIR_TAB_BACKWARD: GTK_DIR_TAB_FORWARD);
+
       retval = TRUE;
     }
   else
     retval = FALSE;
 
+  if (obscure)
+    gtk_text_view_obscure_mouse_cursor (text_view);
+  
   gtk_text_view_pend_cursor_blink (text_view);
 
   return retval;
@@ -3261,7 +3669,23 @@ gtk_text_view_key_press_event (GtkWidget *widget, GdkEventKey *event)
 static gint
 gtk_text_view_key_release_event (GtkWidget *widget, GdkEventKey *event)
 {
-  return FALSE;
+  GtkTextView *text_view = GTK_TEXT_VIEW (widget);
+  GtkTextMark *insert;
+  GtkTextIter iter;
+
+  if (text_view->layout == NULL || get_buffer (text_view) == NULL)
+    return FALSE;
+      
+  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) &&
+      gtk_im_context_filter_keypress (text_view->im_context, event))
+    {
+      text_view->need_im_reset = TRUE;
+      return TRUE;
+    }
+  else
+    return GTK_WIDGET_CLASS (parent_class)->key_release_event (widget, event);
 }
 
 static gint
@@ -3271,7 +3695,9 @@ gtk_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
 
   text_view = GTK_TEXT_VIEW (widget);
 
+  text_view->disable_scroll_on_focus = TRUE;
   gtk_widget_grab_focus (widget);
+  text_view->disable_scroll_on_focus = FALSE;
 
   if (event->window != text_view->text_window->bin_window)
     {
@@ -3344,8 +3770,8 @@ gtk_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
             event->type == GDK_3BUTTON_PRESS) &&
            event->button == 1)
     {
-      GtkTextIter start, end;
-
+      GtkTextIter start, end;      
+      
       /* End the selection drag, otherwise we'd clear the new
        * word/line selection on button release
        */
@@ -3391,12 +3817,28 @@ gtk_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
             }
         }
 
-      gtk_text_buffer_move_mark (get_buffer (text_view),
-                                 gtk_text_buffer_get_selection_bound (get_buffer (text_view)),
-                                 &start);
-      gtk_text_buffer_move_mark (get_buffer (text_view),
-                                 gtk_text_buffer_get_insert (get_buffer (text_view)),
-                                 &end);
+      if (event->state & GDK_SHIFT_MASK)
+        {
+          /* Take union of old and new selection */
+          GtkTextIter old_start, old_end;
+          
+          gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
+                                                &old_start, &old_end);
+
+          gtk_text_iter_order (&start, &old_start);
+          gtk_text_iter_order (&old_end, &end);
+
+          /* Now start is the first of the starts, and end is the
+           * last of the ends
+           */
+        }
+      
+      gtk_text_buffer_move_mark_by_name (get_buffer (text_view),
+                                         "selection_bound",
+                                         &start);
+      gtk_text_buffer_move_mark_by_name (get_buffer (text_view),
+                                         "insert",
+                                         &end);
 
       text_view->just_selected_element = TRUE;
       
@@ -3467,7 +3909,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"));
@@ -3494,7 +3935,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"));
@@ -3520,6 +3960,16 @@ gtk_text_view_motion_event (GtkWidget *widget, GdkEventMotion *event)
 {
   GtkTextView *text_view = GTK_TEXT_VIEW (widget);
 
+  if (text_view->mouse_cursor_obscured)
+    {
+      GdkCursor *cursor;
+      
+      cursor = gdk_cursor_new (GDK_XTERM);
+      gdk_window_set_cursor (text_view->text_window->bin_window, cursor);
+      gdk_cursor_unref (cursor);
+      text_view->mouse_cursor_obscured = FALSE;
+    }
+
   if (event->window == text_view->text_window->bin_window &&
       text_view->drag_start_x >= 0)
     {
@@ -3556,23 +4006,45 @@ gtk_text_view_motion_event (GtkWidget *widget, GdkEventMotion *event)
 }
 
 static void
-gtk_text_view_paint (GtkWidget *widget, GdkRectangle *area)
+gtk_text_view_paint (GtkWidget      *widget,
+                     GdkRectangle   *area,
+                     GdkEventExpose *event)
 {
   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 - may be a text widget bug.");
       G_BREAKPOINT ();
-      g_warning (G_STRLOC ": somehow some text lines were modified or scrolling occurred since the last validation of lines on the screen");
     }
   
 #if 0
@@ -3580,7 +4052,8 @@ gtk_text_view_paint (GtkWidget *widget, GdkRectangle *area)
           area->x, area->y,
           area->width, area->height);
 #endif
-  
+
+  child_exposes = NULL;
   gtk_text_layout_draw (text_view->layout,
                         widget,
                         text_view->text_window->bin_window,
@@ -3588,37 +4061,59 @@ gtk_text_view_paint (GtkWidget *widget, GdkRectangle *area)
                         text_view->xoffset,
                         text_view->yoffset,
                         area->x, area->y,
-                        area->width, area->height);
+                        area->width, area->height,
+                        &child_exposes);
+
+  tmp_list = child_exposes;
+  while (tmp_list != NULL)
+    {
+      GtkWidget *child = tmp_list->data;
+      
+      gtk_container_propagate_expose (GTK_CONTAINER (text_view),
+                                      child,
+                                      event);
+
+      g_object_unref (G_OBJECT (child));
+      
+      tmp_list = tmp_list->next;
+    }
+
+  g_list_free (child_exposes);
 }
 
 static gint
 gtk_text_view_expose_event (GtkWidget *widget, GdkEventExpose *event)
 {
-#if 0
-  {
-    GdkWindow *win = event->window;
-    GdkColor color = { 0, 0, 0, 65535 };
-    GdkGC *gc = gdk_gc_new (win);
-    gdk_gc_set_rgb_fg_color (gc, &color);
-    gdk_draw_rectangle (win,
-                        gc, TRUE,
-                        event->area.x, event->area.y,
-                        event->area.width, event->area.height);
-    gdk_gc_unref (gc);
-  }
-#endif
+  GSList *tmp_list;
   
   if (event->window == gtk_text_view_get_window (GTK_TEXT_VIEW (widget),
                                                  GTK_TEXT_WINDOW_TEXT))
     {
       DV(g_print (">Exposed ("G_STRLOC")\n"));
-      gtk_text_view_paint (widget, &event->area);
+      gtk_text_view_paint (widget, &event->area, event);
     }
 
   if (event->window == widget->window)
     gtk_text_view_draw_focus (widget);
 
-  return TRUE;
+  /* Propagate exposes to all children not in the buffer. */
+  tmp_list = GTK_TEXT_VIEW (widget)->children;
+  while (tmp_list != NULL)
+    {
+      GtkTextViewChild *vc = tmp_list->data;
+
+      /* propagate_expose checks that event->window matches
+       * child->window
+       */
+      if (vc->type != GTK_TEXT_WINDOW_TEXT)
+        gtk_container_propagate_expose (GTK_CONTAINER (widget),
+                                        vc->widget,
+                                        event);
+      
+      tmp_list = tmp_list->next;
+    }
+  
+  return FALSE;
 }
 
 static void
@@ -3627,17 +4122,19 @@ gtk_text_view_draw_focus (GtkWidget *widget)
   gboolean interior_focus;
 
   /* We clear the focus if we are in interior focus mode. */
-  gtk_widget_style_get (widget, "interior_focus", &interior_focus, NULL);
+  gtk_widget_style_get (widget,
+                       "interior_focus", &interior_focus,
+                       NULL);
   
   if (GTK_WIDGET_DRAWABLE (widget))
     {
       if (GTK_WIDGET_HAS_FOCUS (widget) && !interior_focus)
         {          
-          gtk_paint_focus (widget->style, widget->window,
+          gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget), 
                            NULL, widget, "textview",
                            0, 0,
-                           widget->allocation.width - 1,
-                           widget->allocation.height - 1);
+                           widget->allocation.width,
+                           widget->allocation.height);
         }
       else
         {
@@ -3646,6 +4143,34 @@ gtk_text_view_draw_focus (GtkWidget *widget)
     }
 }
 
+static void
+gtk_text_view_grab_focus (GtkWidget *widget)
+{
+  GtkTextView *text_view;
+
+  text_view = GTK_TEXT_VIEW (widget);
+  
+  GTK_WIDGET_CLASS (parent_class)->grab_focus (widget);
+
+  if (!text_view->disable_scroll_on_focus)
+    gtk_text_view_scroll_mark_onscreen (text_view,
+                                        gtk_text_buffer_get_mark (get_buffer (text_view),
+                                                                  "insert"));
+}
+
+static gboolean
+gtk_text_view_focus (GtkWidget        *widget,
+                     GtkDirectionType  direction)
+{
+  GtkTextView *text_view;
+  GtkContainer *container;
+  
+  text_view = GTK_TEXT_VIEW (widget);
+  container = GTK_CONTAINER (widget);  
+  
+  return GTK_WIDGET_CLASS (parent_class)->focus (widget, direction);
+}
+
 /*
  * Container
  */
@@ -3708,13 +4233,15 @@ gtk_text_view_forall (GtkContainer *container,
 {
   GSList *iter;
   GtkTextView *text_view;
+  GSList *copy;
 
   g_return_if_fail (GTK_IS_TEXT_VIEW (container));
   g_return_if_fail (callback != NULL);
 
   text_view = GTK_TEXT_VIEW (container);
 
-  iter = text_view->children;
+  copy = g_slist_copy (text_view->children);
+  iter = copy;
 
   while (iter != NULL)
     {
@@ -3724,6 +4251,8 @@ gtk_text_view_forall (GtkContainer *container,
 
       iter = g_slist_next (iter);
     }
+
+  g_slist_free (copy);
 }
 
 #define CURSOR_ON_MULTIPLIER 0.66
@@ -3878,11 +4407,16 @@ gtk_text_view_move_iter_by_lines (GtkTextView *text_view,
     }
 }
 
+/* FIXME when we are unfrozen and can change GtkMovementStep,
+ * fix this
+ */
+#define PAGE_HORIZONTALLY_HACK_VALUE 57
+
 static void
-gtk_text_view_move_cursor (GtkTextView     *text_view,
-                           GtkMovementStep  step,
-                           gint             count,
-                           gboolean         extend_selection)
+gtk_text_view_move_cursor_internal (GtkTextView     *text_view,
+                                    GtkMovementStep  step,
+                                    gint             count,
+                                    gboolean         extend_selection)
 {
   GtkTextIter insert;
   GtkTextIter newplace;
@@ -3897,6 +4431,12 @@ gtk_text_view_move_cursor (GtkTextView     *text_view,
       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_pend_cursor_blink (text_view);
+      return;
+    }
 
   gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
                                     gtk_text_buffer_get_mark (get_buffer (text_view),
@@ -3940,15 +4480,40 @@ gtk_text_view_move_cursor (GtkTextView     *text_view,
       break;
 
     case GTK_MOVEMENT_PARAGRAPHS:
-      gtk_text_iter_forward_lines (&newplace, count);
-      gtk_text_iter_set_line_offset (&newplace, 0);
+      if (count > 0)
+        {
+          if (!gtk_text_iter_ends_line (&newplace))
+            {
+              gtk_text_iter_forward_to_line_end (&newplace);
+              --count;
+            }
+        }
+      else if (count < 0)
+        {
+          if (gtk_text_iter_get_line_offset (&newplace) > 0)
+            {
+              gtk_text_iter_set_line_offset (&newplace, 0);
+              ++count;
+            }
+        }
+
+      if (count != 0)
+        {
+          gtk_text_iter_forward_lines (&newplace, count);
+          gtk_text_iter_set_line_offset (&newplace, 0);
+        }
       break;
 
     case GTK_MOVEMENT_PARAGRAPH_ENDS:
       if (count > 0)
-        gtk_text_iter_forward_to_line_end (&newplace);
+        {
+          if (!gtk_text_iter_ends_line (&newplace))
+            gtk_text_iter_forward_to_line_end (&newplace);
+        }
       else if (count < 0)
-        gtk_text_iter_set_line_offset (&newplace, 0);
+        {
+          gtk_text_iter_set_line_offset (&newplace, 0);
+        }
       break;
 
     case GTK_MOVEMENT_BUFFER_ENDS:
@@ -3957,7 +4522,7 @@ gtk_text_view_move_cursor (GtkTextView     *text_view,
       else if (count < 0)
         gtk_text_buffer_get_iter_at_offset (get_buffer (text_view), &newplace, 0);
       break;
-
+      
     default:
       break;
     }
@@ -3986,6 +4551,24 @@ gtk_text_view_move_cursor (GtkTextView     *text_view,
   gtk_text_view_pend_cursor_blink (text_view);
 }
 
+static void
+gtk_text_view_move_cursor (GtkTextView     *text_view,
+                           GtkMovementStep  step,
+                           gint             count,
+                           gboolean         extend_selection)
+{
+  gtk_text_view_move_cursor_internal (text_view, step, count, extend_selection);
+}
+
+static void
+gtk_text_view_page_horizontally (GtkTextView     *text_view,
+                                 gint             count,
+                                 gboolean         extend_selection)
+{
+  gtk_text_view_move_cursor_internal (text_view, PAGE_HORIZONTALLY_HACK_VALUE,
+                                      count, extend_selection);
+}
+
 static void
 gtk_text_view_set_anchor (GtkTextView *text_view)
 {
@@ -3995,57 +4578,144 @@ gtk_text_view_set_anchor (GtkTextView *text_view)
                                     gtk_text_buffer_get_mark (get_buffer (text_view),
                                                               "insert"));
 
-  gtk_text_buffer_create_mark (get_buffer (text_view), "anchor", &insert, TRUE);
+  gtk_text_buffer_create_mark (get_buffer (text_view), "anchor", &insert, TRUE);
+}
+
+static void
+gtk_text_view_scroll_pages (GtkTextView *text_view,
+                            gint         count)
+{
+  gdouble newval;
+  gdouble oldval;
+  GtkAdjustment *adj;
+  gint cursor_x_pos, cursor_y_pos;
+  GtkTextIter new_insert;
+  GtkTextIter anchor;
+  gint y0, y1;
+
+  g_return_if_fail (text_view->vadjustment != NULL);
+
+  adj = text_view->vadjustment;
+
+  /* Validate the region that will be brought into view by the cursor motion
+   */
+  if (count < 0)
+    {
+      gtk_text_view_get_first_para_iter (text_view, &anchor);
+      y0 = adj->page_size;
+      y1 = adj->page_size + count * adj->page_increment;
+    }
+  else
+    {
+      gtk_text_view_get_first_para_iter (text_view, &anchor);
+      y0 = count * adj->page_increment + adj->page_size;
+      y1 = 0;
+    }
+
+  gtk_text_layout_validate_yrange (text_view->layout, &anchor, y0, y1);
+  /* FIXME do we need to update the adjustment ranges here? */
+
+  if (count < 0 && adj->value <= (adj->lower + 1e-12))
+    {
+      /* 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);
+    }
+  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);
+    }
+  else
+    {
+      gtk_text_view_get_virtual_cursor_pos (text_view, &cursor_x_pos, &cursor_y_pos);
+
+      newval = adj->value;
+      oldval = adj->value;
+  
+      newval += count * adj->page_increment;
+
+      set_adjustment_clamped (adj, newval);
+      cursor_y_pos += adj->value - oldval;
+
+      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);
+
+      gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, cursor_y_pos);
+    }
+  
+  /* Adjust to have the cursor _entirely_ onscreen, move_mark_onscreen
+   * only guarantees 1 pixel onscreen.
+   */
+  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),
+                                                                "insert"));
 }
 
 static void
-gtk_text_view_scroll_pages (GtkTextView *text_view,
-                            gint         count)
+gtk_text_view_scroll_hpages (GtkTextView *text_view,
+                             gint         count)
 {
   gdouble newval;
+  gdouble oldval;
   GtkAdjustment *adj;
   gint cursor_x_pos, cursor_y_pos;
   GtkTextIter new_insert;
-  GtkTextIter anchor;
-  gint y0, y1;
-
-  g_return_if_fail (text_view->vadjustment != NULL);
+  gint y, height;
+  
+  g_return_if_fail (text_view->hadjustment != NULL);
 
-  adj = text_view->vadjustment;
+  adj = text_view->hadjustment;
 
-  /* Validate the region that will be brought into view by the cursor motion
+  /* Validate the line that we're moving within.
    */
-  if (count < 0)
+  gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
+                                    &new_insert,
+                                    gtk_text_buffer_get_mark (get_buffer (text_view), "insert"));
+  gtk_text_layout_get_line_yrange (text_view->layout, &new_insert, &y, &height);
+  gtk_text_layout_validate_yrange (text_view->layout, &new_insert, y, y + height);
+  /* FIXME do we need to update the adjustment ranges here? */
+  
+  if (count < 0 && adj->value <= (adj->lower + 1e-12))
     {
-      gtk_text_view_get_first_para_iter (text_view, &anchor);
-      y0 = adj->page_size;
-      y1 = adj->page_size + count * adj->page_increment;
+      /* 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);
     }
-  else
+  else if (count > 0 && adj->value >= (adj->upper - adj->page_size - 1e-12))
     {
-      gtk_text_view_get_first_para_iter (text_view, &anchor);
-      y0 = count * adj->page_increment + adj->page_size;
-      y1 = 0;
+      /* 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);
     }
+  else
+    {
+      gtk_text_view_get_virtual_cursor_pos (text_view, &cursor_x_pos, &cursor_y_pos);
 
-  gtk_text_layout_validate_yrange (text_view->layout, &anchor, y0, y1);
-  /* FIXME do we need to update the adjustment ranges here? */
+      newval = adj->value;
+      oldval = adj->value;
   
-  gtk_text_view_get_virtual_cursor_pos (text_view, &cursor_x_pos, &cursor_y_pos);
-
-  newval = adj->value;
+      newval += count * adj->page_increment;
 
-  newval += count * adj->page_increment;
+      set_adjustment_clamped (adj, newval);
+      cursor_x_pos += adj->value - oldval;
 
-  cursor_y_pos += newval - adj->value;
-  set_adjustment_clamped (adj, newval);
+      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);
 
-  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);
-
-  gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, cursor_y_pos);
+      gtk_text_view_set_virtual_cursor_pos (text_view, cursor_x_pos, cursor_y_pos);
+    }
 
+  /*  FIXME for lines shorter than the overall widget width, this results in a
+   *  "bounce" effect as we scroll to the right of the widget, then scroll
+   *  back to get the end of the line onscreen.
+   *      http://bugzilla.gnome.org/show_bug.cgi?id=68963
+   */
+  
   /* Adjust to have the cursor _entirely_ onscreen, move_mark_onscreen
    * only guarantees 1 pixel onscreen.
    */
@@ -4255,6 +4925,19 @@ gtk_text_view_toggle_overwrite (GtkTextView *text_view)
   text_view->overwrite_mode = !text_view->overwrite_mode;
 }
 
+static void
+gtk_text_view_move_focus (GtkTextView     *text_view,
+                          GtkDirectionType direction_type)
+{
+  GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (text_view));
+
+  if (!GTK_WIDGET_TOPLEVEL (toplevel))
+    return;
+
+  /* Propagate to toplevel */
+  g_signal_emit_by_name (G_OBJECT (toplevel), "move_focus", direction_type);
+}
+
 /*
  * Selections
  */
@@ -4298,6 +4981,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,
@@ -4306,6 +4990,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
@@ -4387,14 +5074,45 @@ gtk_text_view_start_selection_drag (GtkTextView       *text_view,
                                     GdkEventButton    *button)
 {
   GtkTextIter newplace;
-
+  GtkTextBuffer *buffer;
+  
   g_return_if_fail (text_view->selection_drag_handler == 0);
 
   gtk_grab_add (GTK_WIDGET (text_view));
 
+  buffer = get_buffer (text_view);
+  
   newplace = *iter;
 
-  gtk_text_buffer_place_cursor (get_buffer (text_view), &newplace);
+  if (button->state & GDK_SHIFT_MASK)
+    {
+      /* Extend selection */
+      GtkTextIter start, end;
+
+      gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
+
+      if (gtk_text_iter_compare (&newplace, &start) <= 0)
+        {
+          gtk_text_buffer_move_mark_by_name (buffer, "insert",
+                                             &newplace);
+
+          gtk_text_buffer_move_mark_by_name (buffer, "selection_bound",
+                                             &end);
+        }
+      else if (gtk_text_iter_compare (&newplace, &end) >= 0)
+        {
+          gtk_text_buffer_move_mark_by_name (buffer, "insert",
+                                             &newplace);
+
+          gtk_text_buffer_move_mark_by_name (buffer, "selection_bound",
+                                             &start);
+        }
+    }
+  else
+    {
+      /* Replace selection */
+      gtk_text_buffer_place_cursor (buffer, &newplace);
+    }
 
   text_view->selection_drag_handler = gtk_signal_connect (GTK_OBJECT (text_view),
                                                           "motion_notify_event",
@@ -4568,7 +5286,7 @@ gtk_text_view_ensure_layout (GtkTextView *text_view)
  * Obtains a copy of the default text attributes. These are the
  * attributes used for text unless a tag overrides them.
  * You'd typically pass the default attributes in to
- * gtk_text_tag_get_attributes() in order to get the
+ * gtk_text_iter_get_attributes() in order to get the
  * attributes in effect at a given text position.
  *
  * The return value is a copy owned by the caller of this function,
@@ -4593,14 +5311,9 @@ gtk_text_view_destroy_layout (GtkTextView *text_view)
     {
       GSList *tmp_list;
 
-      if (text_view->incremental_validate_idle)
-        {
-          g_source_remove (text_view->incremental_validate_idle);
-          text_view->incremental_validate_idle = 0;
-        }
-
-      /* Remove layout from all anchored children */
+      gtk_text_view_remove_validate_idles (text_view);
       
+      /* Remove layout from all anchored children */
       tmp_list = text_view->children;
       while (tmp_list != NULL)
         {
@@ -4719,7 +5432,7 @@ gtk_text_view_drag_data_get (GtkWidget        *widget,
 
       if (str)
         {
-          gtk_selection_data_set_text (selection_data, str);
+          gtk_selection_data_set_text (selection_data, str, -1);
           g_free (str);
         }
     }
@@ -5046,7 +5759,7 @@ gtk_text_view_set_scroll_adjustments (GtkTextView   *text_view,
       text_view->hadjustment = hadj;
       g_object_ref (G_OBJECT (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);
@@ -5058,7 +5771,7 @@ gtk_text_view_set_scroll_adjustments (GtkTextView   *text_view,
       text_view->vadjustment = vadj;
       g_object_ref (G_OBJECT (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);
@@ -5077,10 +5790,16 @@ gtk_text_view_value_changed (GtkAdjustment *adj,
   gint line_top;
   gint dx = 0;
   gint dy = 0;
-
+  
+  /* Note that we oddly call this function with adj == NULL
+   * sometimes
+   */
+  
   text_view->onscreen_validated = FALSE;
 
-  DV(g_print(">Scroll offset changed, onscreen_validated = FALSE ("G_STRLOC")\n"));
+  DV(g_print(">Scroll offset changed %s/%g, onscreen_validated = FALSE ("G_STRLOC")\n",
+             adj == text_view->hadjustment ? "hadj" : adj == text_view->vadjustment ? "vadj" : "none",
+             adj ? adj->value : 0.0));
   
   if (adj == text_view->hadjustment)
     {
@@ -5102,30 +5821,59 @@ gtk_text_view_value_changed (GtkAdjustment *adj,
         }
     }
   
-  if (GTK_WIDGET_REALIZED (text_view) && (dx != 0 || dy != 0))
+  if (dx != 0 || dy != 0)
     {
-      if (dy != 0)
-        {
-          if (text_view->left_window)
-            text_window_scroll (text_view->left_window, 0, dy);
-          if (text_view->right_window)
-            text_window_scroll (text_view->right_window, 0, dy);
-        }
+      GSList *tmp_list;
 
-      if (dx != 0)
+      if (GTK_WIDGET_REALIZED (text_view))
         {
-          if (text_view->top_window)
-            text_window_scroll (text_view->top_window, dx, 0);
-          if (text_view->bottom_window)
-            text_window_scroll (text_view->bottom_window, dx, 0);
+          if (dy != 0)
+            {
+              if (text_view->left_window)
+                text_window_scroll (text_view->left_window, 0, dy);
+              if (text_view->right_window)
+                text_window_scroll (text_view->right_window, 0, dy);
+            }
+      
+          if (dx != 0)
+            {
+              if (text_view->top_window)
+                text_window_scroll (text_view->top_window, dx, 0);
+              if (text_view->bottom_window)
+                text_window_scroll (text_view->bottom_window, dx, 0);
+            }
+      
+          /* It looks nicer to scroll the main area last, because
+           * it takes a while, and making the side areas update
+           * afterward emphasizes the slowness of scrolling the
+           * main area.
+           */
+          text_window_scroll (text_view->text_window, dx, dy);
         }
-
-      /* It looks nicer to scroll the main area last, because
-       * it takes a while, and making the side areas update
-       * afterward emphasizes the slowness of scrolling the
-       * main area.
+      
+      /* Children are now "moved" in the text window, poke
+       * into widget->allocation for each child
        */
-      text_window_scroll (text_view->text_window, dx, dy);
+      tmp_list = text_view->children;
+      while (tmp_list != NULL)
+        {
+          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
+            }
+          
+          tmp_list = g_slist_next (tmp_list);
+        }
     }
 
   /* This could result in invalidation, which would install the
@@ -5141,10 +5889,12 @@ gtk_text_view_value_changed (GtkAdjustment *adj,
    * that, or shouldn't be.
    */
   gtk_text_view_validate_onscreen (text_view);
-
+  
   /* 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);
 
@@ -5166,6 +5916,8 @@ gtk_text_view_value_changed (GtkAdjustment *adj,
       g_source_remove (text_view->first_validate_idle);
       text_view->first_validate_idle = 0;
     }
+
+  gtk_text_view_update_im_spot_location (text_view);
   
   DV(g_print(">End scroll offset changed handler ("G_STRLOC")\n"));
 }
@@ -5174,6 +5926,13 @@ static void
 gtk_text_view_commit_handler (GtkIMContext  *context,
                               const gchar   *str,
                               GtkTextView   *text_view)
+{
+  gtk_text_view_commit_text (text_view, str);
+}
+
+static void
+gtk_text_view_commit_text (GtkTextView   *text_view,
+                           const gchar   *str)
 {
   gboolean had_selection;
   
@@ -5221,6 +5980,51 @@ gtk_text_view_preedit_changed_handler (GtkIMContext *context,
   g_free (str);
 }
 
+static gboolean
+gtk_text_view_retrieve_surrounding_handler (GtkIMContext  *context,
+                                           GtkTextView   *text_view)
+{
+  GtkTextIter start;
+  GtkTextIter end;
+  gint pos;
+  gchar *text;
+
+  gtk_text_buffer_get_iter_at_mark (text_view->buffer, &start,  
+                                   gtk_text_buffer_get_insert (text_view->buffer));
+  end = start;
+
+  pos = gtk_text_iter_get_line_index (&start);
+  gtk_text_iter_set_line_offset (&start, 0);
+  gtk_text_iter_forward_to_line_end (&end);
+
+  text = gtk_text_iter_get_slice (&start, &end);
+  gtk_im_context_set_surrounding (context, text, -1, pos);
+  g_free (text);
+
+  return TRUE;
+}
+
+static gboolean
+gtk_text_view_delete_surrounding_handler (GtkIMContext  *context,
+                                         gint           offset,
+                                         gint           n_chars,
+                                         GtkTextView   *text_view)
+{
+  GtkTextIter start;
+  GtkTextIter end;
+
+  gtk_text_buffer_get_iter_at_mark (text_view->buffer, &start,  
+                                   gtk_text_buffer_get_insert (text_view->buffer));
+  end = start;
+
+  gtk_text_iter_forward_chars (&start, offset);
+  gtk_text_iter_forward_chars (&end, offset + n_chars);
+
+  gtk_text_buffer_delete (text_view->buffer, &start, &end);
+
+  return TRUE;
+}
+
 static void
 gtk_text_view_mark_set_handler (GtkTextBuffer     *buffer,
                                 const GtkTextIter *location,
@@ -5234,6 +6038,7 @@ gtk_text_view_mark_set_handler (GtkTextBuffer     *buffer,
     {
       text_view->virtual_cursor_x = -1;
       text_view->virtual_cursor_y = -1;
+      gtk_text_view_update_im_spot_location (text_view);
       need_reset = TRUE;
     }
   else if (mark == gtk_text_buffer_get_selection_bound (buffer))
@@ -5310,11 +6115,11 @@ activate_cb (GtkWidget   *menuitem,
 static void
 append_action_signal (GtkTextView  *text_view,
                      GtkWidget    *menu,
-                     const gchar  *label,
+                     const gchar  *stock_id,
                      const gchar  *signal,
                       gboolean      sensitive)
 {
-  GtkWidget *menuitem = gtk_menu_item_new_with_label (label);
+  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",
@@ -5403,6 +6208,33 @@ typedef struct
   guint time;
 } PopupInfo;
 
+static gboolean
+range_contains_editable_text (const GtkTextIter *start,
+                              const GtkTextIter *end,
+                              gboolean default_editability)
+{
+  GtkTextIter iter = *start;
+
+  while (gtk_text_iter_compare (&iter, end) < 0)
+    {
+      if (gtk_text_iter_editable (&iter, default_editability))
+        return TRUE;
+      
+      gtk_text_iter_forward_to_tag_toggle (&iter, NULL);
+    }
+
+  return FALSE;
+}                             
+
+static void
+unichar_chosen_func (const char *text,
+                     gpointer    data)
+{
+  GtkTextView *text_view = GTK_TEXT_VIEW (data);
+
+  gtk_text_view_commit_text (text_view, text);
+}
+
 static void
 popup_targets_received (GtkClipboard     *clipboard,
                        GtkSelectionData *data,
@@ -5422,7 +6254,8 @@ popup_targets_received (GtkClipboard     *clipboard,
       gboolean have_selection;
       gboolean can_insert;
       GtkTextIter iter;
-
+      GtkTextIter sel_start, sel_end;
+      
       if (text_view->popup_menu)
        gtk_widget_destroy (text_view->popup_menu);
 
@@ -5433,7 +6266,7 @@ popup_targets_received (GtkClipboard     *clipboard,
                                 popup_menu_detach);
       
       have_selection = gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
-                                                            NULL, NULL);
+                                                             &sel_start, &sel_end);
       
       gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
                                        &iter,
@@ -5441,18 +6274,20 @@ popup_targets_received (GtkClipboard     *clipboard,
       
       can_insert = gtk_text_iter_can_insert (&iter, text_view->editable);
       
-      append_action_signal (text_view, text_view->popup_menu, _("Cut"), "cut_clipboard",
-                           have_selection);
-      append_action_signal (text_view, text_view->popup_menu, _("Copy"), "copy_clipboard",
+      append_action_signal (text_view, text_view->popup_menu, GTK_STOCK_CUT, "cut_clipboard",
+                           have_selection &&
+                            range_contains_editable_text (&sel_start, &sel_end,
+                                                          text_view->editable));
+      append_action_signal (text_view, text_view->popup_menu, GTK_STOCK_COPY, "copy_clipboard",
                            have_selection);
-      append_action_signal (text_view, text_view->popup_menu, _("Paste"), "paste_clipboard",
+      append_action_signal (text_view, text_view->popup_menu, GTK_STOCK_PASTE, "paste_clipboard",
                            can_insert && clipboard_contains_text);
       
       menuitem = gtk_separator_menu_item_new ();
       gtk_widget_show (menuitem);
       gtk_menu_shell_append (GTK_MENU_SHELL (text_view->popup_menu), menuitem);
       
-      menuitem = gtk_menu_item_new_with_label (_("Input Methods"));
+      menuitem = gtk_menu_item_new_with_mnemonic (_("Input _Methods"));
       gtk_widget_show (menuitem);
       submenu = gtk_menu_new ();
       gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
@@ -5460,6 +6295,18 @@ popup_targets_received (GtkClipboard     *clipboard,
       
       gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (text_view->im_context),
                                            GTK_MENU_SHELL (submenu));
+
+      menuitem = gtk_menu_item_new_with_mnemonic (_("_Insert Unicode control character"));
+      gtk_widget_show (menuitem);
+      gtk_widget_set_sensitive (menuitem, can_insert);
+      
+      submenu = gtk_menu_new ();
+      gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
+      gtk_menu_shell_append (GTK_MENU_SHELL (text_view->popup_menu), menuitem);      
+
+      _gtk_text_util_append_special_char_menuitems (GTK_MENU_SHELL (submenu),
+                                                    unichar_chosen_func,
+                                                    text_view);
       
       gtk_signal_emit (GTK_OBJECT (text_view),
                       signals[POPULATE_POPUP],
@@ -5470,9 +6317,12 @@ popup_targets_received (GtkClipboard     *clipboard,
                        NULL, NULL,
                        info->button, info->time);
       else
-       gtk_menu_popup (GTK_MENU (text_view->popup_menu), NULL, NULL,
-                       popup_position_func, text_view,
-                       0, gtk_get_current_event_time ());
+       {
+         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));
+       }
     }
 
   g_object_unref (text_view);
@@ -5508,10 +6358,11 @@ gtk_text_view_do_popup (GtkTextView    *text_view,
                                  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 */
@@ -5602,7 +6453,7 @@ text_window_realize (GtkTextWindow *win,
       /* I-beam cursor */
       cursor = gdk_cursor_new (GDK_XTERM);
       gdk_window_set_cursor (win->bin_window, cursor);
-      gdk_cursor_destroy (cursor);
+      gdk_cursor_unref (cursor);
 
       gtk_im_context_set_client_window (GTK_TEXT_VIEW (win->widget)->im_context,
                                         win->window);
@@ -5671,7 +6522,7 @@ text_window_scroll        (GtkTextWindow *win,
     }
 }
 
-void
+static void
 text_window_invalidate_rect (GtkTextWindow *win,
                              GdkRectangle  *rect)
 {
@@ -5807,11 +6658,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;
 }
 
 /**
@@ -5833,7 +6687,7 @@ gtk_text_view_get_window_type (GtkTextView *text_view,
   GtkTextWindow *win;
 
   g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
-  g_return_val_if_fail (GDK_IS_WINDOW (text_view), 0);
+  g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
 
   if (window == GTK_WIDGET (text_view)->window)
     return GTK_TEXT_WINDOW_WIDGET;
@@ -5855,29 +6709,17 @@ buffer_to_widget (GtkTextView      *text_view,
                   gint              buffer_y,
                   gint             *window_x,
                   gint             *window_y)
-{
-  gint focus_edge_width;
-  gboolean interior_focus;
-  
-  gtk_widget_style_get (GTK_WIDGET (text_view), "interior_focus", &interior_focus, NULL);
-
-  if (interior_focus)
-    focus_edge_width = 0;
-  else
-    focus_edge_width = 1;
-  
+{  
   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;
     }
 }
 
@@ -6005,13 +6847,17 @@ widget_to_buffer (GtkTextView *text_view,
 {
   gint focus_edge_width;
   gboolean interior_focus;
+  gint focus_width;
   
-  gtk_widget_style_get (GTK_WIDGET (text_view), "interior_focus", &interior_focus, NULL);
+  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 = 1;
+    focus_edge_width = focus_width;
   
   if (buffer_x)
     {
@@ -6175,6 +7021,8 @@ set_window_width (GtkTextView      *text_view,
         {
           if ((*winp)->requisition.width == width)
             return;
+
+          (*winp)->requisition.width = width;
         }
 
       gtk_widget_queue_resize (GTK_WIDGET (text_view));
@@ -6213,6 +7061,8 @@ set_window_height (GtkTextView      *text_view,
         {
           if ((*winp)->requisition.height == height)
             return;
+
+          (*winp)->requisition.height = height;
         }
 
       gtk_widget_queue_resize (GTK_WIDGET (text_view));
@@ -6227,8 +7077,11 @@ set_window_height (GtkTextView      *text_view,
  *
  * Sets the width of %GTK_TEXT_WINDOW_LEFT or %GTK_TEXT_WINDOW_RIGHT,
  * or the height of %GTK_TEXT_WINDOW_TOP or %GTK_TEXT_WINDOW_BOTTOM.
- * Automatically destroys the corresponding window if the size is set to 0,
- * and creates the window if the size is set to non-zero.
+ * Automatically destroys the corresponding window if the size is set
+ * to 0, and creates the window if the size is set to non-zero.  This
+ * function can only be used for the "border windows," it doesn't work
+ * with #GTK_TEXT_WINDOW_WIDGET, #GTK_TEXT_WINDOW_TEXT, or
+ * #GTK_TEXT_WINDOW_PRIVATE.
  **/
 void
 gtk_text_view_set_border_window_size (GtkTextView      *text_view,
@@ -6238,8 +7091,6 @@ gtk_text_view_set_border_window_size (GtkTextView      *text_view,
 {
   g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
   g_return_if_fail (size >= 0);
-  g_return_if_fail (type != GTK_TEXT_WINDOW_WIDGET);
-  g_return_if_fail (type != GTK_TEXT_WINDOW_TEXT);
 
   switch (type)
     {
@@ -6264,7 +7115,7 @@ gtk_text_view_set_border_window_size (GtkTextView      *text_view,
       break;
 
     default:
-      g_warning ("Can only set size of left/right/top/bottom border windows with gtk_text_view_set_border_window_size in %s\n", G_STRLOC);
+      g_warning ("Can only set size of left/right/top/bottom border windows with gtk_text_view_set_border_window_size()");
       break;
     }
 }
@@ -6284,25 +7135,27 @@ gtk_text_view_get_border_window_size (GtkTextView       *text_view,
                                      GtkTextWindowType  type)
 {
   g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
-  g_return_val_if_fail (type != GTK_TEXT_WINDOW_WIDGET, 0);
-  g_return_val_if_fail (type != GTK_TEXT_WINDOW_TEXT, 0);
   
   switch (type)
     {
     case GTK_TEXT_WINDOW_LEFT:
-      return text_view->left_window->requisition.width;
+      if (text_view->left_window)
+        return text_view->left_window->requisition.width;
       
     case GTK_TEXT_WINDOW_RIGHT:
-      return text_view->right_window->requisition.width;
+      if (text_view->right_window)
+        return text_view->right_window->requisition.width;
       
     case GTK_TEXT_WINDOW_TOP:
-      return text_view->top_window->requisition.height;
+      if (text_view->top_window)
+        return text_view->top_window->requisition.height;
 
     case GTK_TEXT_WINDOW_BOTTOM:
-      return text_view->bottom_window->requisition.height;
+      if (text_view->bottom_window)
+        return text_view->bottom_window->requisition.height;
       
     default:
-      g_warning ("Can only get size of left/right/top/bottom border windows with gtk_text_view_get_border_window_size in %s\n", G_STRLOC);
+      g_warning ("Can only get size of left/right/top/bottom border windows with gtk_text_view_get_border_window_size()");
       break;
     }
 
@@ -6362,6 +7215,10 @@ text_view_child_new_window (GtkWidget          *child,
   vc->x = x;
   vc->y = y;
 
+  g_object_set_data (G_OBJECT (child),
+                     "gtk-text-view-child",
+                     vc);
+  
   return vc;
 }
 
@@ -6412,6 +7269,15 @@ add_child (GtkTextView      *text_view,
   gtk_widget_set_parent (vc->widget, GTK_WIDGET (text_view));
 }
 
+/**
+ * gtk_text_view_add_child_at_anchor:
+ * @text_view: a #GtkTextView
+ * @child: a #GtkWidget
+ * @anchor: a #GtkTextChildAnchor in the #GtkTextBuffer for @text_view
+ * 
+ * Adds a child widget in the text buffer, at the given @anchor.
+ * 
+ **/
 void
 gtk_text_view_add_child_at_anchor (GtkTextView          *text_view,
                                    GtkWidget            *child,
@@ -6430,8 +7296,37 @@ gtk_text_view_add_child_at_anchor (GtkTextView          *text_view,
                                      text_view->layout);
 
   add_child (text_view, vc);
+
+  g_assert (vc->widget == child);
+  g_assert (gtk_widget_get_parent (child) == GTK_WIDGET (text_view));
 }
 
+/**
+ * gtk_text_view_add_child_in_window:
+ * @text_view: a #GtkTextView
+ * @child: a #GtkWidget
+ * @which_window: which window the child should appear in
+ * @xpos: X position of child in window coordinates
+ * @ypos: Y position of child in window coordinates
+ *
+ * Adds a child at fixed coordinates in one of the text widget's
+ * windows.  The window must have nonzero size (see
+ * gtk_text_view_set_border_window_size()).  Note that the child
+ * coordinates are given relative to the #GdkWindow in question, and
+ * that these coordinates have no sane relationship to scrolling. When
+ * placing a child in #GTK_TEXT_WINDOW_WIDGET, scrolling is
+ * irrelevant, the child floats above all scrollable areas. But when
+ * placing a child in one of the scrollable windows (border windows or
+ * text window), you'll need to compute the child's correct position
+ * in buffer coordinates any time scrolling occurs or buffer changes
+ * occur, and then call gtk_text_view_move_child() to update the
+ * child's position. Unfortunately there's no good way to detect that
+ * scrolling has occurred, using the current API; a possible hack
+ * would be to update all child positions when the scroll adjustments
+ * change or the text buffer changes. See bug 64518 on
+ * bugzilla.gnome.org for status of fixing this issue.
+ *
+ **/
 void
 gtk_text_view_add_child_in_window (GtkTextView          *text_view,
                                    GtkWidget            *child,
@@ -6443,16 +7338,27 @@ gtk_text_view_add_child_in_window (GtkTextView          *text_view,
 
   g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
   g_return_if_fail (GTK_IS_WIDGET (child));
-  g_return_if_fail (xpos >= 0);
-  g_return_if_fail (ypos >= 0);
   g_return_if_fail (child->parent == NULL);
 
   vc = text_view_child_new_window (child, which_window,
                                    xpos, ypos);
 
   add_child (text_view, vc);
+
+  g_assert (vc->widget == child);
+  g_assert (gtk_widget_get_parent (child) == GTK_WIDGET (text_view));
 }
 
+/**
+ * gtk_text_view_move_child:
+ * @text_view: a #GtkTextView
+ * @child: child widget already added to the text view
+ * @xpos: new X position in window coordinates
+ * @ypos: new Y position in window coordinates
+ *
+ * Updates the position of a child, as for gtk_text_view_add_child_in_window().
+ * 
+ **/
 void
 gtk_text_view_move_child          (GtkTextView          *text_view,
                                    GtkWidget            *child,
@@ -6463,8 +7369,6 @@ gtk_text_view_move_child          (GtkTextView          *text_view,
 
   g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
   g_return_if_fail (GTK_IS_WIDGET (child));
-  g_return_if_fail (xpos >= 0);
-  g_return_if_fail (ypos >= 0);
   g_return_if_fail (child->parent == (GtkWidget*) text_view);
 
   vc = g_object_get_data (G_OBJECT (child),
@@ -6472,6 +7376,10 @@ gtk_text_view_move_child          (GtkTextView          *text_view,
 
   g_assert (vc != NULL);
 
+  if (vc->x == xpos &&
+      vc->y == ypos)
+    return;
+  
   vc->x = xpos;
   vc->y = ypos;
 
@@ -6480,9 +7388,24 @@ gtk_text_view_move_child          (GtkTextView          *text_view,
 }
 
 
-
 /* Iterator operations */
 
+/**
+ * gtk_text_view_forward_display_line:
+ * @text_view: a #GtkTextView
+ * @iter: a #GtkTextIter
+ * 
+ * Moves the given @iter forward by one display (wrapped) line.  A
+ * display line is different from a paragraph. Paragraphs are
+ * separated by newlines or other paragraph separator characters.
+ * Display lines are created by line-wrapping a paragraph.  If
+ * wrapping is turned off, display lines and paragraphs will be the
+ * same. Display lines are divided differently for each view, since
+ * they depend on the view's width; paragraphs are the same in all
+ * views, since they depend on the contents of the #GtkTextBuffer.
+ * 
+ * Return value: %TRUE if @iter was moved and is not on the end iterator
+ **/
 gboolean
 gtk_text_view_forward_display_line (GtkTextView *text_view,
                                     GtkTextIter *iter)
@@ -6495,6 +7418,22 @@ gtk_text_view_forward_display_line (GtkTextView *text_view,
   return gtk_text_layout_move_iter_to_next_line (text_view->layout, iter);
 }
 
+/**
+ * gtk_text_view_backward_display_line:
+ * @text_view: a #GtkTextView
+ * @iter: a #GtkTextIter
+ * 
+ * Moves the given @iter backward by one display (wrapped) line.  A
+ * display line is different from a paragraph. Paragraphs are
+ * separated by newlines or other paragraph separator characters.
+ * Display lines are created by line-wrapping a paragraph.  If
+ * wrapping is turned off, display lines and paragraphs will be the
+ * same. Display lines are divided differently for each view, since
+ * they depend on the view's width; paragraphs are the same in all
+ * views, since they depend on the contents of the #GtkTextBuffer.
+ * 
+ * Return value: %TRUE if @iter was moved and is not on the end iterator
+ **/
 gboolean
 gtk_text_view_backward_display_line (GtkTextView *text_view,
                                      GtkTextIter *iter)
@@ -6507,6 +7446,22 @@ gtk_text_view_backward_display_line (GtkTextView *text_view,
   return gtk_text_layout_move_iter_to_previous_line (text_view->layout, iter);
 }
 
+/**
+ * gtk_text_view_forward_display_line_end:
+ * @text_view: a #GtkTextView
+ * @iter: a #GtkTextIter
+ * 
+ * Moves the given @iter forward to the next display line end.  A
+ * display line is different from a paragraph. Paragraphs are
+ * separated by newlines or other paragraph separator characters.
+ * Display lines are created by line-wrapping a paragraph.  If
+ * wrapping is turned off, display lines and paragraphs will be the
+ * same. Display lines are divided differently for each view, since
+ * they depend on the view's width; paragraphs are the same in all
+ * views, since they depend on the contents of the #GtkTextBuffer.
+ * 
+ * Return value: %TRUE if @iter was moved and is not on the end iterator
+ **/
 gboolean
 gtk_text_view_forward_display_line_end (GtkTextView *text_view,
                                         GtkTextIter *iter)
@@ -6519,6 +7474,22 @@ gtk_text_view_forward_display_line_end (GtkTextView *text_view,
   return gtk_text_layout_move_iter_to_line_end (text_view->layout, iter, 1);
 }
 
+/**
+ * gtk_text_view_backward_display_line_start:
+ * @text_view: a #GtkTextView
+ * @iter: a #GtkTextIter
+ * 
+ * Moves the given @iter backward to the next display line start.  A
+ * display line is different from a paragraph. Paragraphs are
+ * separated by newlines or other paragraph separator characters.
+ * Display lines are created by line-wrapping a paragraph.  If
+ * wrapping is turned off, display lines and paragraphs will be the
+ * same. Display lines are divided differently for each view, since
+ * they depend on the view's width; paragraphs are the same in all
+ * views, since they depend on the contents of the #GtkTextBuffer.
+ * 
+ * Return value: %TRUE if @iter was moved and is not on the end iterator
+ **/
 gboolean
 gtk_text_view_backward_display_line_start (GtkTextView *text_view,
                                            GtkTextIter *iter)
@@ -6531,6 +7502,17 @@ gtk_text_view_backward_display_line_start (GtkTextView *text_view,
   return gtk_text_layout_move_iter_to_line_end (text_view->layout, iter, -1);
 }
 
+/**
+ * gtk_text_view_starts_display_line:
+ * @text_view: a #GtkTextView
+ * @iter: a #GtkTextIter
+ * 
+ * Determines whether @iter is at the start of a display line.
+ * See gtk_text_view_forward_display_line() for an explanation of
+ * display lines vs. paragraphs.
+ * 
+ * Return value: %TRUE if @iter begins a wrapped line
+ **/
 gboolean
 gtk_text_view_starts_display_line (GtkTextView       *text_view,
                                    const GtkTextIter *iter)
@@ -6543,6 +7525,18 @@ gtk_text_view_starts_display_line (GtkTextView       *text_view,
   return gtk_text_layout_iter_starts_line (text_view->layout, iter);
 }
 
+/**
+ * gtk_text_view_move_visually:
+ * @text_view: a #GtkTextView
+ * @iter: a #GtkTextIter
+ * @count: number of lines to move
+ * 
+ * Moves @iter up or down by @count display (wrapped) lines.
+ * See gtk_text_view_forward_display_line() for an explanation of
+ * display lines vs. paragraphs.
+ * 
+ * Return value: %TRUE if @iter moved and is not on the end iterator
+ **/
 gboolean
 gtk_text_view_move_visually (GtkTextView *text_view,
                              GtkTextIter *iter,