]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtktextsegment.c
GtkBubbleWindow: rework how drawing is done
[~andy/gtk] / gtk / gtktextsegment.c
index 33d10833174f21e6464831e5e267befc300720b5..d1493d69a41459207f954e7f84a27acfe2740747 100644 (file)
  *
  */
 
+#define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
+#include "config.h"
 #include "gtktextbtree.h"
 #include <string.h>
-#include <ctype.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include "gtktexttag.h"
@@ -97,13 +98,13 @@ gtk_text_line_segment_split (const GtkTextIter *iter)
   GtkTextLine *line;
   int count;
 
-  line = gtk_text_iter_get_text_line (iter);
-  tree = gtk_text_iter_get_btree (iter);
+  line = _gtk_text_iter_get_text_line (iter);
+  tree = _gtk_text_iter_get_btree (iter);
 
   count = gtk_text_iter_get_line_index (iter);
 
-  if (gtk_debug_flags & GTK_DEBUG_TEXT)
-    gtk_text_iter_check (iter);
+  if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
+    _gtk_text_iter_check (iter);
   
   prev = NULL;
   seg = line->segments;
@@ -121,7 +122,7 @@ gtk_text_line_segment_split (const GtkTextIter *iter)
               g_assert (count != seg->byte_count);
               g_assert (seg->byte_count > 0);
 
-              gtk_text_btree_segments_changed (tree);
+              _gtk_text_btree_segments_changed (tree);
 
               seg = (*seg->type->splitFunc)(seg, count);
 
@@ -172,12 +173,12 @@ char_segment_self_check (GtkTextLineSegment *seg)
 
   if (seg->byte_count <= 0)
     {
-      g_error ("char_segment_check_func: segment has size <= 0");
+      g_error ("segment has size <= 0");
     }
 
   if (strlen (seg->body.chars) != seg->byte_count)
     {
-      g_error ("char_segment_check_func: segment has wrong size");
+      g_error ("segment has wrong size");
     }
 
   if (g_utf8_strlen (seg->body.chars, seg->byte_count) != seg->char_count)
@@ -194,7 +195,7 @@ _gtk_char_segment_new (const gchar *text, guint len)
   g_assert (gtk_text_byte_begins_utf8_char (text));
 
   seg = g_malloc (CSEG_SIZE (len));
-  seg->type = &gtk_text_char_type;
+  seg->type = (GtkTextLineSegmentClass *)&gtk_text_char_type;
   seg->next = NULL;
   seg->byte_count = len;
   memcpy (seg->body.chars, text, len);
@@ -202,15 +203,19 @@ _gtk_char_segment_new (const gchar *text, guint len)
 
   seg->char_count = g_utf8_strlen (seg->body.chars, seg->byte_count);
 
-  if (gtk_debug_flags & GTK_DEBUG_TEXT)
+  if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
     char_segment_self_check (seg);
 
   return seg;
 }
 
 GtkTextLineSegment*
-_gtk_char_segment_new_from_two_strings (const gchar *text1, guint len1,
-                                        const gchar *text2, guint len2)
+_gtk_char_segment_new_from_two_strings (const gchar *text1, 
+                                       guint        len1, 
+                                       guint        chars1,
+                                        const gchar *text2, 
+                                       guint        len2, 
+                                       guint        chars2)
 {
   GtkTextLineSegment *seg;
 
@@ -225,11 +230,9 @@ _gtk_char_segment_new_from_two_strings (const gchar *text1, guint len1,
   memcpy (seg->body.chars + len1, text2, len2);
   seg->body.chars[len1+len2] = '\0';
 
-  /* In principle this function could probably take chars1 and chars2
-     as args, since it's typically used to merge two char segments */
-  seg->char_count = g_utf8_strlen (seg->body.chars, seg->byte_count);
+  seg->char_count = chars1 + chars2;
 
-  if (gtk_debug_flags & GTK_DEBUG_TEXT)
+  if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
     char_segment_self_check (seg);
 
   return seg;
@@ -260,7 +263,7 @@ char_segment_split_func (GtkTextLineSegment *seg, int index)
 
   g_assert (index < seg->byte_count);
 
-  if (gtk_debug_flags & GTK_DEBUG_TEXT)
+  if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
     {
       char_segment_self_check (seg);
     }
@@ -276,7 +279,7 @@ char_segment_split_func (GtkTextLineSegment *seg, int index)
   new1->next = new2;
   new2->next = seg->next;
 
-  if (gtk_debug_flags & GTK_DEBUG_TEXT)
+  if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
     {
       char_segment_self_check (new1);
       char_segment_self_check (new2);
@@ -294,6 +297,11 @@ char_segment_split_func (GtkTextLineSegment *seg, int index)
  *      This procedure merges adjacent character segments into
  *      a single character segment, if possible.
  *
+ * Arguments:
+ *      segPtr: Pointer to the first of two adjacent segments to
+ *              join.
+ *      line:   Line containing segments (not used).
+ *
  * Results:
  *      The return value is a pointer to the first segment in
  *      the (new) list of segments that used to start with segPtr.
@@ -306,15 +314,11 @@ char_segment_split_func (GtkTextLineSegment *seg, int index)
 
         /* ARGSUSED */
 static GtkTextLineSegment *
-char_segment_cleanup_func (segPtr, line)
-     GtkTextLineSegment *segPtr;           /* Pointer to first of two adjacent
-                                         * segments to join. */
-     GtkTextLine *line;                /* Line containing segments (not
-                                        * used). */
+char_segment_cleanup_func (GtkTextLineSegment *segPtr, GtkTextLine *line)
 {
   GtkTextLineSegment *segPtr2, *newPtr;
 
-  if (gtk_debug_flags & GTK_DEBUG_TEXT)
+  if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
     char_segment_self_check (segPtr);
 
   segPtr2 = segPtr->next;
@@ -324,12 +328,16 @@ char_segment_cleanup_func (segPtr, line)
     }
 
   newPtr =
-    _gtk_char_segment_new_from_two_strings (segPtr->body.chars, segPtr->byte_count,
-                                            segPtr2->body.chars, segPtr2->byte_count);
+    _gtk_char_segment_new_from_two_strings (segPtr->body.chars, 
+                                           segPtr->byte_count,
+                                           segPtr->char_count,
+                                            segPtr2->body.chars, 
+                                           segPtr2->byte_count,
+                                           segPtr2->char_count);
 
   newPtr->next = segPtr2->next;
 
-  if (gtk_debug_flags & GTK_DEBUG_TEXT)
+  if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
     char_segment_self_check (newPtr);
 
   g_free (segPtr);
@@ -344,6 +352,12 @@ char_segment_cleanup_func (segPtr, line)
  *
  *      This procedure is invoked to delete a character segment.
  *
+ * Arguments:
+ *      segPtr   : Segment to delete
+ *      line     : Line containing segment
+ *      treeGone : Non-zero means the entire tree is being
+ *                 deleted, so everything must get cleaned up.
+ *
  * Results:
  *      Always returns 0 to indicate that the segment was deleted.
  *
@@ -355,12 +369,7 @@ char_segment_cleanup_func (segPtr, line)
 
         /* ARGSUSED */
 static int
-char_segment_delete_func (segPtr, line, treeGone)
-     GtkTextLineSegment *segPtr;           /* Segment to delete. */
-     GtkTextLine *line;                /* Line containing segment. */
-     int treeGone;                      /* Non-zero means the entire tree is
-                                         * being deleted, so everything must
-                                         * get cleaned up. */
+char_segment_delete_func (GtkTextLineSegment *segPtr, GtkTextLine *line, int treeGone)
 {
   g_free ((char*) segPtr);
   return 0;
@@ -374,6 +383,10 @@ char_segment_delete_func (segPtr, line, treeGone)
  *      This procedure is invoked to perform consistency checks
  *      on character segments.
  *
+ * Arguments:
+ *      segPtr : Segment to check
+ *      line   : Line containing segment
+ *
  * Results:
  *      None.
  *
@@ -386,24 +399,15 @@ char_segment_delete_func (segPtr, line, treeGone)
 
         /* ARGSUSED */
 static void
-char_segment_check_func (segPtr, line)
-     GtkTextLineSegment *segPtr;           /* Segment to check. */
-     GtkTextLine *line;                /* Line containing segment. */
+char_segment_check_func (GtkTextLineSegment *segPtr, GtkTextLine *line)
 {
   char_segment_self_check (segPtr);
 
-  if (segPtr->next == NULL)
-    {
-      if (segPtr->body.chars[segPtr->byte_count-1] != '\n')
-        {
-          g_error ("char_segment_check_func: line doesn't end with newline");
-        }
-    }
-  else
+  if (segPtr->next != NULL)
     {
       if (segPtr->next->type == &gtk_text_char_type)
         {
-          g_error ("char_segment_check_func: adjacent character segments weren't merged");
+          g_error ("adjacent character segments weren't merged");
         }
     }
 }
@@ -435,6 +439,12 @@ _gtk_toggle_segment_new (GtkTextTagInfo *info, gboolean on)
  *
  *      This procedure is invoked to delete toggle segments.
  *
+ * Arguments:
+ *      segPtr   : Segment to check
+ *      line     : Line containing segment
+ *      treeGone : Non-zero means the entire tree is being
+ *                 deleted so everything must get cleaned up
+ *
  * Results:
  *      Returns 1 to indicate that the segment may not be deleted,
  *      unless the entire B-tree is going away.
@@ -448,12 +458,7 @@ _gtk_toggle_segment_new (GtkTextTagInfo *info, gboolean on)
  */
 
 static int
-toggle_segment_delete_func (segPtr, line, treeGone)
-     GtkTextLineSegment *segPtr;           /* Segment to check. */
-     GtkTextLine *line;                /* Line containing segment. */
-     int treeGone;                      /* Non-zero means the entire tree is
-                                         * being deleted, so everything must
-                                         * get cleaned up. */
+toggle_segment_delete_func (GtkTextLineSegment *segPtr, GtkTextLine *line, int treeGone)
 {
   if (treeGone)
     {
@@ -487,6 +492,10 @@ toggle_segment_delete_func (segPtr, line, treeGone)
  *      been modified in some way.  It's invoked after the
  *      modifications are complete.
  *
+ * Arguments:
+ *      segPtr : Segment to check
+ *      line   : Line that now contains segment
+ *
  * Results:
  *      The return value is the head segment in a new list
  *      that is to replace the tail of the line that used to
@@ -502,9 +511,7 @@ toggle_segment_delete_func (segPtr, line, treeGone)
  */
 
 static GtkTextLineSegment *
-toggle_segment_cleanup_func (segPtr, line)
-     GtkTextLineSegment *segPtr;   /* Segment to check. */
-     GtkTextLine *line;        /* Line that now contains segment. */
+toggle_segment_cleanup_func (GtkTextLineSegment *segPtr, GtkTextLine *line)
 {
   GtkTextLineSegment *segPtr2, *prevPtr;
   int counts;
@@ -562,6 +569,10 @@ toggle_segment_cleanup_func (segPtr, line)
  *      This procedure is invoked when a toggle segment is about
  *      to move from one line to another.
  *
+ * Arguments:
+ *      segPtr : Segment to check
+ *      line   : Line that used to contain segment
+ *
  * Results:
  *      None.
  *
@@ -572,9 +583,7 @@ toggle_segment_cleanup_func (segPtr, line)
  */
 
 static void
-toggle_segment_line_change_func (segPtr, line)
-     GtkTextLineSegment *segPtr;   /* Segment to check. */
-     GtkTextLine *line;        /* Line that used to contain segment. */
+toggle_segment_line_change_func (GtkTextLineSegment *segPtr, GtkTextLine *line)
 {
   if (segPtr->body.toggle.inNodeCounts)
     {
@@ -589,7 +598,7 @@ toggle_segment_line_change_func (segPtr, line)
  */
 
 
-GtkTextLineSegmentClass gtk_text_char_type = {
+const GtkTextLineSegmentClass gtk_text_char_type = {
   "character",                          /* name */
   0,                                            /* leftGravity */
   char_segment_split_func,                              /* splitFunc */
@@ -604,7 +613,7 @@ GtkTextLineSegmentClass gtk_text_char_type = {
  * range:
  */
 
-GtkTextLineSegmentClass gtk_text_toggle_on_type = {
+const GtkTextLineSegmentClass gtk_text_toggle_on_type = {
   "toggleOn",                                   /* name */
   0,                                            /* leftGravity */
   NULL,                 /* splitFunc */
@@ -619,7 +628,7 @@ GtkTextLineSegmentClass gtk_text_toggle_on_type = {
  * range:
  */
 
-GtkTextLineSegmentClass gtk_text_toggle_off_type = {
+const GtkTextLineSegmentClass gtk_text_toggle_off_type = {
   "toggleOff",                          /* name */
   1,                                            /* leftGravity */
   NULL,                 /* splitFunc */