Sync with hiro's cvs 10 to 17.
[claws.git] / src / gtkstext.c
index a24f202b3226dda25d3a84e9ec4c16ec7e9b0c1d..11bdd6098f71aca89ce903db87e49e045f876ae2 100644 (file)
  * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
  * file for a list of people on the GTK+ Team.  See the ChangeLog
  * files for a list of changes.  These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
  */
 
 /*
- * Modified by the Sylpheed Team and others 2001. Interesting 
+ * Modified by the Sylpheed Team and others 2001. Interesting
  * parts are marked using comment block following this one.
- * This modification is based on the GtkSText of GTK 1.2.8
+ * This modification is based on the GtkText of GTK 1.2.10
  */
 
-/* SYLPHEED: 
- * comment here 
+/* SYLPHEED:
+ * comment here
  */
 
 #ifdef HAVE_CONFIG_H
@@ -47,7 +47,9 @@
 #include <gtk/gtksignal.h>
 #include <gtkstext.h>
 
-/* SYLPHEED: 
+#include "compose.h"
+
+/* SYLPHEED:
  * compile time settings 
  */
 #define INITIAL_BUFFER_SIZE      1024
@@ -429,7 +431,7 @@ static void gtk_stext_set_position  (GtkEditable       *editable,
 /* SYLPHEED:
  * cursor timer
  */
-static void gtk_stext_enable_blink      (GtkSText *text);
+static void gtk_stext_enable_blink  (GtkSText *text);
 static void gtk_stext_disable_blink (GtkSText *text);
 
 /* #define DEBUG_GTK_STEXT */
@@ -495,7 +497,8 @@ static const GtkTextFunction control_keys[26] =
 {
   (GtkTextFunction)gtk_stext_move_beginning_of_line,    /* a */
   (GtkTextFunction)gtk_stext_move_backward_character,   /* b */
-  (GtkTextFunction)gtk_editable_copy_clipboard,        /* c */
+  NULL,                                                      /* c */
+/*  (GtkTextFunction)gtk_editable_copy_clipboard,        /* c */
   (GtkTextFunction)gtk_stext_delete_forward_character,  /* d */
   (GtkTextFunction)gtk_stext_move_end_of_line,          /* e */
   (GtkTextFunction)gtk_stext_move_forward_character,    /* f */
@@ -514,9 +517,11 @@ static const GtkTextFunction control_keys[26] =
   NULL,                                                /* s */
   NULL,                                                /* t */
   (GtkTextFunction)gtk_stext_delete_line,               /* u */
-  (GtkTextFunction)gtk_editable_paste_clipboard,       /* v */
+  NULL,                                                      /* v */
+/*  (GtkTextFunction)gtk_editable_paste_clipboard,       /* v */
   (GtkTextFunction)gtk_stext_delete_backward_word,      /* w */
-  (GtkTextFunction)gtk_editable_cut_clipboard,         /* x */
+  NULL,                                                     /* x */
+/*  (GtkTextFunction)gtk_editable_cut_clipboard,         /* x */
   NULL,                                                /* y */
   NULL,                                                /* z */
 };
@@ -782,15 +787,15 @@ gtk_stext_init (GtkSText *text)
   /* SYLPHEED:
    * timer for blinking cursor
    */
-  text->cursor_visible                   = FALSE;              /* don't know whether gtktext stores this somewhere */ 
-  text->cursor_timer_on                          = TRUE;
-  text->cursor_off_ms                    = 500;
-  text->cursor_on_ms                     = 500;
-  text->cursor_timer_id                          = 0;
+  text->cursor_visible = FALSE;                /* don't know whether gtktext stores this somewhere */
+  text->cursor_timer_on = TRUE;
+  text->cursor_off_ms = 500;
+  text->cursor_on_ms = 500;
+  text->cursor_timer_id = 0;
   text->cursor_idle_time_timer_id = 0;
-  text->wrap_rmargin                     = 0;
-  text->cursor_type                              = STEXT_CURSOR_LINE; 
-  text->persist_column                   = 0;
+  text->wrap_rmargin = 0;
+  text->cursor_type = GTK_STEXT_CURSOR_LINE; 
+  text->persist_column = 0;
   
   init_properties (text);
   
@@ -815,6 +820,13 @@ gtk_stext_new (GtkAdjustment *hadj,
                         "vadjustment", vadj,
                         NULL);
 
+  /* SYLPHEED:
+   * force widget name to be GtkText so it silently adapts
+   * the GtkText widget's style... 
+   */
+  gtk_widget_set_name(text, "GtkText");                        
+  gtk_widget_ensure_style(text);
+
   return text;
 }
 
@@ -999,6 +1011,15 @@ gtk_stext_thaw (GtkSText *text)
   draw_cursor (text, FALSE);
 }
 
+/* SYLPHEED */
+void
+gtk_stext_compact_buffer (GtkSText    *text)
+{
+  g_return_if_fail (text != NULL);
+  g_return_if_fail (GTK_IS_STEXT (text));
+  move_gap (text, gtk_stext_get_length(text));
+}
+
 void
 gtk_stext_insert (GtkSText    *text,
                 GdkFont    *font,
@@ -1307,10 +1328,10 @@ gtk_stext_destroy (GtkObject *object)
     }
 
   /* SYLPHEED:
-   * cursor timer 
+   * cursor timer
    */
-  gtk_stext_disable_blink(text);   
-  
+  gtk_stext_disable_blink (text);
+
   GTK_OBJECT_CLASS(parent_class)->destroy (object);
 }
 
@@ -2136,9 +2157,7 @@ gtk_stext_key_press (GtkWidget   *widget,
          break;
        case GDK_Page_Up:   scroll_int (text, -text->vadj->page_increment); break;
        case GDK_Page_Down: scroll_int (text, +text->vadj->page_increment); break;
-       case GDK_Up:        
-               scroll_int (text, -KEY_SCROLL_PIXELS); 
-               break;
+       case GDK_Up:        scroll_int (text, -KEY_SCROLL_PIXELS); break;
        case GDK_Down:      scroll_int (text, +KEY_SCROLL_PIXELS); break;
        case GDK_Return:
          if (event->state & GDK_CONTROL_MASK)
@@ -2173,15 +2192,17 @@ gtk_stext_key_press (GtkWidget   *widget,
            }
          
          extend_start = (text->point.index == editable->selection_start_pos);
-         gtk_stext_disable_blink(text);
+         /* SYLPHEED: cursor */
+         gtk_stext_disable_blink (text);
+       }
+      else
+       {
+         gtk_stext_enable_blink (text);
        }
 
        /* SYLPHEED:
         * cursor
         */
-       if (!extend_selection)  
-               gtk_stext_enable_blink(text);
-               
        if (event->keyval != GDK_Up && event->keyval != GDK_Down) {
                reset_persist_col_pos(text);
        }
@@ -2189,8 +2210,17 @@ gtk_stext_key_press (GtkWidget   *widget,
       switch (event->keyval)
        {
        case GDK_Home:
-         if (event->state & GDK_CONTROL_MASK)
-           move_cursor_buffer_ver (text, -1);
+         if (event->state & GDK_CONTROL_MASK) {
+               if (text->wrap_rmargin == 0) {
+                       /* SYLPHEED: old behaviour */
+                       move_cursor_buffer_ver (text, -1);
+               }
+               else {
+                       /* SYLPHEED: contrived, but "trusty" */
+                       move_cursor_buffer_ver(text, -1);
+                       move_cursor_to_display_row_start(text);
+               }
+         }     
          else {
                if (text->wrap_rmargin > 0) {
                        /* SYLPHEED: line start */
@@ -2202,8 +2232,17 @@ gtk_stext_key_press (GtkWidget   *widget,
          }     
          break;
        case GDK_End:
-         if (event->state & GDK_CONTROL_MASK)
-           move_cursor_buffer_ver (text, +1);
+         if (event->state & GDK_CONTROL_MASK) {
+               /* SYLPHEED: a little bit contrived... */
+               if (text->wrap_rmargin == 0) {
+                       /* old behaviour */
+                       move_cursor_buffer_ver (text, +1);
+               }
+               else {
+                       move_cursor_buffer_ver(text, +1);
+                       move_cursor_to_display_row_end(text);
+               }
+         }             
          else {
                if (text->wrap_rmargin > 0) {
                        /* SYLPHEED: line end */
@@ -2231,7 +2270,7 @@ gtk_stext_key_press (GtkWidget   *widget,
                break;
        case GDK_Down:      
                move_cursor_to_display_row_down(text);
-//             move_cursor_ver (text, +1); 
+/*             move_cursor_ver (text, +1);  */
                break;
        case GDK_Left:
          if (event->state & GDK_CONTROL_MASK)
@@ -2271,19 +2310,15 @@ gtk_stext_key_press (GtkWidget   *widget,
            }
          break;
        case GDK_Delete:
-               {
-                       if (event->state & GDK_CONTROL_MASK) {
-                               gtk_stext_delete_forward_word (text);
-                       }       
-                       else if (event->state & GDK_SHIFT_MASK)
-                       {
-                               extend_selection = FALSE;
-                               gtk_editable_cut_clipboard (editable);
-                       }
-                       else {
-                               gtk_stext_delete_forward_character (text);
-                       }       
-               }               
+         if (event->state & GDK_CONTROL_MASK)
+           gtk_stext_delete_forward_word (text);
+         else if (event->state & GDK_SHIFT_MASK)
+           {
+             extend_selection = FALSE;
+             gtk_editable_cut_clipboard (editable);
+           }
+         else
+           gtk_stext_delete_forward_character (text);
          break;
        case GDK_Tab:
          position = text->point.index;
@@ -2397,8 +2432,9 @@ gtk_stext_focus_in (GtkWidget     *widget,
 #endif
   
   draw_cursor (GTK_STEXT(widget), TRUE);
+  /* SYLPHEED: cursor */
   GTK_STEXT(widget)->cursor_visible = TRUE;
-  gtk_stext_enable_blink(GTK_STEXT(widget));
+  gtk_stext_enable_blink (GTK_STEXT(widget));
   
   return FALSE;
 }
@@ -4219,9 +4255,9 @@ static void move_cursor_to_display_row_start(GtkSText *text)
 }
 
 /* dumb */
-static gboolean range_intersect(gint x1, gint x2, gint y1, gint y2)
+static gboolean range_intersect(guint x1, guint x2, guint y1, guint y2)
 {
-       gint tmp;
+       guint tmp;
        if (x1 > x2) { tmp = x1; x1 = x2; x2 = tmp; }
        if (y1 > y2) { tmp = y1; y1 = y2; y1 = tmp; }
        if (y1 < x1) { tmp = x1; x1 = y1; y1 = tmp; tmp = x2; x2 = y2; y2 = tmp; }
@@ -4314,6 +4350,19 @@ typedef struct {
        LineParams   lp;
 } fdrf; 
 
+#if defined(AHX_DEBUG)
+static void print_line(GtkSText *text, guint start, guint end)
+{
+       gchar *buf = alloca(2048), *walk = buf;
+
+       memset(buf, 0, 2048);
+       for (; start <= end; start++) {
+               *walk++ = GTK_STEXT_INDEX(text, start);
+       }               
+       XDEBUG( ("%s", buf) );  
+}
+#endif
+
 static gint forward_display_row_fetcher(GtkSText *text,
                                                                                LineParams *lp,
                                                                                fdrf       *data)
@@ -4323,6 +4372,7 @@ static gint forward_display_row_fetcher(GtkSText *text,
                                __FILE__, __LINE__, data->start, data->end, lp->start.index, lp->end.index) );
                data->lp = *lp;
                data->completed = TRUE;
+               print_line(text, lp->start.index, lp->end.index);
                return TRUE;
        }
        else if (range_intersect(data->start, data->end, lp->start.index, lp->end.index)) {
@@ -4609,9 +4659,8 @@ static void
 gtk_stext_kill_word (GtkEditable *editable,
                    gint         direction)
 {
-  if (editable->selection_start_pos != editable->selection_end_pos) {
+  if (editable->selection_start_pos != editable->selection_end_pos)
     gtk_editable_delete_selection (editable);
-  }    
   else
     {
       gint old_pos = editable->current_pos;
@@ -5064,7 +5113,10 @@ find_line_params (GtkSText* text,
        max_display_pixels = text->wrap_rmargin * ch_width; 
   }    
   
-  if (GTK_EDITABLE (text)->editable || !text->word_wrap)
+  /* SYLPHEED - we don't draw ugly word wrapping thing 
+   * if our wrap margin is set */
+  if (!text->wrap_rmargin &&
+      ((GTK_EDITABLE (text)->editable || !text->word_wrap)))
     max_display_pixels -= LINE_WRAP_ROOM;
   
   lp.wraps             = 0;
@@ -5164,6 +5216,16 @@ find_line_params (GtkSText* text,
                      /* If whole line is one word, revert to char wrapping */
                      if (lp.end.index == lp.start.index)
                        {
+                         /* SYLPHEED: don't wrap URLs */
+                          if (gtkut_stext_is_uri_string(text, lp.end.index,
+                                        gtk_stext_get_length(text)))
+                            {
+                             lp.end = saved_mark;
+                             lp.displayable_chars = saved_characters + 1;
+                              lp.wraps = 0;
+                              goto no_url_wrap;
+                            }
+
                          lp.end = saved_mark;
                          lp.displayable_chars = saved_characters;
                          decrement_mark (&lp.end);
@@ -5186,6 +5248,7 @@ find_line_params (GtkSText* text,
          lp.displayable_chars += 1;
        }
       
+no_url_wrap:
       lp.font_ascent = MAX (font->ascent, lp.font_ascent);
       lp.font_descent = MAX (font->descent, lp.font_descent);
       lp.pixel_width  += ch_width;
@@ -5399,7 +5462,7 @@ draw_line (GtkSText* text,
                pixel_width = gdk_text_width_wc (gc_values.font,
                                                 buffer.wc, len);
              else
-             pixel_width = gdk_text_width (gc_values.font,
+               pixel_width = gdk_text_width (gc_values.font,
                                              buffer.ch, len);
            }
          else
@@ -5555,60 +5618,72 @@ undraw_cursor (GtkSText* text, gint absolute)
       GTK_WIDGET_DRAWABLE (text) && text->line_start_cache)
     {
       GdkFont* font;
-         gint pixel_width, pixel_height;
-         GdkGC *gc;
+      gint pixel_width;
+      gint pixel_height;
       
       g_assert(text->cursor_mark.property);
 
-         gc = gdk_gc_new(text->text_area);
-         g_assert(gc);
-         gdk_gc_copy(gc, text->gc);
-
       font = MARK_CURRENT_FONT(text, &text->cursor_mark);
 
-         /* SYLPHEED:
-          * changed the cursor to a real block (TM)
-          */
-         if (text->cursor_type == STEXT_CURSOR_BLOCK) { 
-                 if (text->use_wchar)
-                       pixel_width = gdk_char_width_wc(font, text->cursor_char);               
-                 else
-                       pixel_width = gdk_char_width(font, text->cursor_char);
-                 pixel_width -= 1;
-                 pixel_height = LINE_HEIGHT(CACHE_DATA(text->current_line));
-
-                 draw_bg_rect (text, &text->cursor_mark,
-                                               text->cursor_pos_x,
-                                               text->cursor_pos_y - (pixel_height + 1),
-                                               pixel_width + 1, 
-                                               pixel_height + 1,
-                                               FALSE);
-        }      
-        else {
-             draw_bg_rect (text, &text->cursor_mark,
-                               text->cursor_pos_x - 1,
-                                           text->cursor_pos_y - text->cursor_char_offset - font->ascent,
-                                               2, font->descent + font->ascent + 1, FALSE);
-                                                                                         
-        }
-      
+      /* SYLPHEED:
+       * changed the cursor to a real block (TM)
+       */
+      if (text->cursor_type == GTK_STEXT_CURSOR_BLOCK)
+       {
+         if (text->cursor_char)
+           {
+             if (text->use_wchar)
+               pixel_width = gdk_char_width_wc (font, text->cursor_char);
+             else
+               pixel_width = gdk_char_width (font, (guchar)text->cursor_char);
+           }
+         else
+           {
+               pixel_width = gdk_char_width (font, 'W');
+           }
+
+         pixel_height = LINE_HEIGHT(CACHE_DATA(text->current_line));
+
+         draw_bg_rect (text, &text->cursor_mark,
+                       text->cursor_pos_x,
+                       text->cursor_pos_y - (pixel_height + 1),
+                       pixel_width,
+                       pixel_height + 1,
+                       FALSE);
+       }
+      else
+       {
+         draw_bg_rect (text, &text->cursor_mark, 
+                       text->cursor_pos_x,
+                       text->cursor_pos_y - text->cursor_char_offset - font->ascent,
+                       2, font->descent + font->ascent + 1, FALSE);
+       }
+
       if (text->cursor_char)
        {
          if (font->type == GDK_FONT_FONT)
            gdk_gc_set_font (text->gc, font);
-
+         
          gdk_gc_set_foreground (text->gc, MARK_CURRENT_FORE (text, &text->cursor_mark));
-
-         gdk_draw_text_wc (text->text_area, font,
-                        text->gc,
-                        text->cursor_pos_x,
-                        text->cursor_pos_y - text->cursor_char_offset,
-                        &text->cursor_char,
-                        1);
+         
+          if (text->use_wchar)
+           gdk_draw_text_wc (text->text_area, font,
+                             text->gc,
+                             text->cursor_pos_x,
+                             text->cursor_pos_y - text->cursor_char_offset,
+                             &text->cursor_char,
+                             1);
+         else
+           {
+             guchar ch = text->cursor_char;
+             gdk_draw_text (text->text_area, font,
+                            text->gc,
+                            text->cursor_pos_x,
+                            text->cursor_pos_y - text->cursor_char_offset,
+                            (gchar *)&ch,
+                            1);         
+           }
        }
-
-       gdk_gc_copy(text->gc, gc);
-       gdk_gc_unref(gc);
     }
 }
 
@@ -5640,7 +5715,6 @@ static void
 draw_cursor (GtkSText* text, gint absolute)
 {
   GtkEditable *editable = (GtkEditable *)text;
-  gint pixel_width, pixel_height;
   
   TDEBUG (("in draw_cursor\n"));
   
@@ -5653,46 +5727,51 @@ draw_cursor (GtkSText* text, gint absolute)
       GTK_WIDGET_DRAWABLE (text) && text->line_start_cache)
     {
       GdkFont* font;
-         GdkGC*          gc;
+      gint pixel_width;
+      gint pixel_height;
       
       g_assert (text->cursor_mark.property);
 
-         gc = gdk_gc_new(text->text_area);
-         g_assert (gc);
-         gdk_gc_copy(gc, text->gc);
-         font = MARK_CURRENT_FONT (text, &text->cursor_mark);
-         if (text->cursor_type == STEXT_CURSOR_BLOCK) {
-                 /* SYLPHEED:
-                  * changed the cursor to a real block (TM)
-                  */
-                 if (text->use_wchar) {
-                       pixel_width = gdk_char_width_wc(font, text->cursor_char);               
-                 }
-                 else {
-                       pixel_width = gdk_char_width(font, text->cursor_char);
-                 }
-                 pixel_width -= 1;
-
-                 pixel_height = LINE_HEIGHT(CACHE_DATA(text->current_line));
-                 gdk_gc_set_foreground (text->gc, &GTK_WIDGET (text)->style->text[GTK_STATE_NORMAL]);
-                 gdk_gc_set_function(text->gc, GDK_INVERT);
-                 gdk_draw_rectangle(text->text_area, text->gc, TRUE, 
-                                                        text->cursor_pos_x, 
-                                                        text->cursor_pos_y - pixel_height,
-                                                        pixel_width, 
-                                                        pixel_height);
-         }
-         else {
-               gdk_gc_set_line_attributes(text->gc, 2, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER);
-               gdk_gc_set_foreground(text->gc, &GTK_WIDGET (text)->style->text[GTK_STATE_NORMAL]);
-           gdk_draw_line(text->text_area, text->gc, text->cursor_pos_x,
-                             text->cursor_pos_y + font->descent - text->cursor_char_offset,
-                                         text->cursor_pos_x,
-                                         text->cursor_pos_y - text->cursor_char_offset - font->ascent );
-                                                                                                  
-         }
-         gdk_gc_copy(text->gc, gc);                                            
-         gdk_gc_unref(gc);
+      font = MARK_CURRENT_FONT (text, &text->cursor_mark);
+
+      /* SYLPHEED:
+       * change the cursor to a real block (TM)
+       */
+      if (text->cursor_type == GTK_STEXT_CURSOR_BLOCK)
+       {
+         if (text->cursor_char)
+           {
+             if (text->use_wchar)
+               pixel_width = gdk_char_width_wc (font, text->cursor_char);
+             else
+               pixel_width = gdk_char_width (font, (guchar)text->cursor_char);
+           }
+         else
+           {
+               pixel_width = gdk_char_width (font, 'W');
+           }
+
+         pixel_height = LINE_HEIGHT(CACHE_DATA(text->current_line));
+
+         gdk_gc_set_foreground (text->gc, &GTK_WIDGET (text)->style->text[GTK_STATE_NORMAL]);
+         gdk_gc_set_function (text->gc, GDK_INVERT);
+         gdk_draw_rectangle (text->text_area, text->gc, TRUE,
+                             text->cursor_pos_x,
+                             text->cursor_pos_y - pixel_height,
+                             pixel_width,
+                             pixel_height);
+         gdk_gc_set_function (text->gc, GDK_COPY);
+       }
+      else
+       {
+         gdk_gc_set_line_attributes(text->gc, 2, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER);
+         gdk_gc_set_foreground (text->gc, &GTK_WIDGET (text)->style->text[GTK_STATE_NORMAL]);
+
+         gdk_draw_line (text->text_area, text->gc, text->cursor_pos_x + 1,
+                        text->cursor_pos_y + font->descent - text->cursor_char_offset,
+                        text->cursor_pos_x + 1,
+                        text->cursor_pos_y - text->cursor_char_offset - font->ascent);
+       }
     }
 }
 
@@ -5943,82 +6022,109 @@ gtk_stext_set_selection  (GtkEditable   *editable,
  * cursor timer
  */
 
-static gint stext_blink_timer_proc(GtkSText *text)
+static gint
+stext_blink_timer_proc (GtkSText *text)
 {
-       if (text->cursor_state_on) {
-               text->cursor_state_on = FALSE;
-               undraw_cursor(text, TRUE);
-               /* kill this timer... */
-               gtk_timeout_remove(text->cursor_timer_id);
-               text->cursor_timer_id = gtk_timeout_add(text->cursor_off_ms, (GtkFunction) stext_blink_timer_proc, (gpointer) text); 
-       }
-       else {
-               text->cursor_state_on = TRUE;
-               draw_cursor(text, TRUE);
-               /* kill this timer... */
-               gtk_timeout_remove(text->cursor_timer_id);
-               text->cursor_timer_id = gtk_timeout_add(text->cursor_on_ms, (GtkFunction) stext_blink_timer_proc, (gpointer) text);
-       }
-       return TRUE;
+  if (text->cursor_state_on)
+    {
+      text->cursor_state_on = FALSE;
+      undraw_cursor (text, TRUE);
+      /* kill this timer... */
+      gtk_timeout_remove (text->cursor_timer_id);
+      text->cursor_timer_id = gtk_timeout_add (text->cursor_off_ms,
+                                              (GtkFunction) stext_blink_timer_proc,
+                                              (gpointer) text);
+    }
+  else
+    {
+      text->cursor_state_on = TRUE;
+      draw_cursor (text, TRUE);
+      /* kill this timer... */
+      gtk_timeout_remove (text->cursor_timer_id);
+      text->cursor_timer_id = gtk_timeout_add (text->cursor_on_ms,
+                                              (GtkFunction) stext_blink_timer_proc,
+                                              (gpointer) text);
+    }
+
+  return TRUE;
 }
 
-static gint stext_idle_timer_proc(GtkSText *text) 
+static gint
+stext_idle_timer_proc (GtkSText *text)
 {
-       /* make sure the cursor timer is off */
-       if (text->cursor_timer_id) {
-               gtk_timeout_remove(text->cursor_timer_id);
-               text->cursor_timer_id = 0;
-       }
-       /* assuming it's always on when calling this function ... */
-       text->cursor_state_on = TRUE;
-       text->cursor_timer_id = gtk_timeout_add(text->cursor_on_ms, (GtkFunction) stext_blink_timer_proc, (gpointer) text); 
-       /* make sure we kill the timer (could perhaps make this function return FALSE (not documented in
-        * the current docs). should check the source. */
-       gtk_idle_remove( text->cursor_idle_time_timer_id ); 
-       text->cursor_idle_time_timer_id = 0;
-       return TRUE;
+  /* make sure the cursor timer is off */
+  if (text->cursor_timer_id)
+    {
+      gtk_timeout_remove (text->cursor_timer_id);
+      text->cursor_timer_id = 0;
+    }
+
+  /* assuming it's always on when calling this function ... */
+  text->cursor_state_on = TRUE;
+  text->cursor_timer_id = gtk_timeout_add (text->cursor_on_ms,
+                                          (GtkFunction) stext_blink_timer_proc,
+                                          (gpointer) text);
+  /* make sure we kill the timer (could perhaps make this function return
+     FALSE (not documented in the current docs). should check the source. */
+  gtk_idle_remove (text->cursor_idle_time_timer_id);
+  text->cursor_idle_time_timer_id = 0;
+
+  return TRUE;
 }
 
-static void gtk_stext_enable_blink      (GtkSText *text)
+static void
+gtk_stext_enable_blink (GtkSText *text)
 {
-       if (text->cursor_timer_on) { 
-               gtk_stext_disable_blink(text);
-               text->cursor_idle_time_timer_id = gtk_idle_add((GtkFunction) stext_idle_timer_proc, (gpointer) text);
-       }
+  if (text->cursor_timer_on)
+    {
+      gtk_stext_disable_blink (text);
+      text->cursor_idle_time_timer_id = gtk_idle_add ((GtkFunction) stext_idle_timer_proc,
+                                                     (gpointer) text);
+    }
 }
 
-static void gtk_stext_disable_blink (GtkSText *text)
+static void
+gtk_stext_disable_blink (GtkSText *text)
 {
-       if (text->cursor_timer_on) {
-               if (text->cursor_idle_time_timer_id) {
-                       gtk_idle_remove( text->cursor_idle_time_timer_id );
-                       text->cursor_idle_time_timer_id = 0;
-               }
-               if (text->cursor_timer_id) {
-                       gtk_timeout_remove( text->cursor_timer_id );
-                       text->cursor_timer_id = 0;
-               }
-               draw_cursor(text, TRUE);
-       }               
+  if (text->cursor_timer_on)
+    {
+      if (text->cursor_idle_time_timer_id)
+       {
+         gtk_idle_remove (text->cursor_idle_time_timer_id);
+         text->cursor_idle_time_timer_id = 0;
+       }
+      if (text->cursor_timer_id)
+       {
+         gtk_timeout_remove (text->cursor_timer_id);
+         text->cursor_timer_id = 0;
+       }
+      draw_cursor(text, TRUE);
+    }
 }
 
-void gtk_stext_set_blink(GtkSText *text, gboolean blinkin_on)
+void
+gtk_stext_set_blink (GtkSText *text, gboolean blinking_on)
 {
-       if (text->cursor_timer_on != blinkin_on) {
-               if (text->cursor_timer_on) {
-                       /* text widget already created? */
-                       if (text->cursor_visible) {
-                               gtk_stext_disable_blink(text);
-                       }                               
-                       text->cursor_timer_on = FALSE;
-               }
-               else {
-                       if (text->cursor_visible) {
-                               gtk_stext_enable_blink(text);
-                       }
-                       text->cursor_timer_on = TRUE;
-               }
+  if (text->cursor_timer_on != blinking_on)
+    {
+      if (text->cursor_timer_on)
+       {
+         /* text widget already created? */
+         if (text->cursor_visible)
+           {
+             gtk_stext_disable_blink (text);
+           }
+           text->cursor_timer_on = FALSE;
        }
+      else
+       {
+         if (text->cursor_visible)
+           {
+             gtk_stext_enable_blink (text);
+           }
+           text->cursor_timer_on = TRUE;
+       }
+    }
 }