]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtktextlayout.c
When in split cursor mode, always add the cursor as both strong and weak
[~andy/gtk] / gtk / gtktextlayout.c
index 018a33aea8d2a7edf157793b51bc59abf749f02b..b92e85cc8f16abdd9cd88ccb7e09bdf7be8706fd 100644 (file)
@@ -78,6 +78,7 @@
 
 #define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
 #include "gtksignal.h"
+#include "gtkmarshalers.h"
 #include "gtktextlayout.h"
 #include "gtktextbtree.h"
 #include "gtktextiterprivate.h"
@@ -85,9 +86,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-static GtkTextLineData    *gtk_text_line_data_new                 (GtkTextLayout     *layout,
-                                                                   GtkTextLine       *line);
-
 static GtkTextLineData *gtk_text_layout_real_wrap (GtkTextLayout *layout,
                                                    GtkTextLine *line,
                                                    /* may be NULL */
@@ -179,7 +177,7 @@ gtk_text_layout_class_init (GtkTextLayoutClass *klass)
                   G_SIGNAL_RUN_LAST,
                   G_STRUCT_OFFSET (GtkTextLayoutClass, invalidated),
                   NULL, NULL,
-                  gtk_marshal_VOID__VOID,
+                  _gtk_marshal_VOID__VOID,
                   GTK_TYPE_NONE,
                   0);
 
@@ -189,7 +187,7 @@ gtk_text_layout_class_init (GtkTextLayoutClass *klass)
                   G_SIGNAL_RUN_LAST,
                   G_STRUCT_OFFSET (GtkTextLayoutClass, changed),
                   NULL, NULL,
-                  gtk_marshal_VOID__INT_INT_INT,
+                  _gtk_marshal_VOID__INT_INT_INT,
                   GTK_TYPE_NONE,
                   3,
                   GTK_TYPE_INT,
@@ -202,7 +200,7 @@ gtk_text_layout_class_init (GtkTextLayoutClass *klass)
                   G_SIGNAL_RUN_LAST,
                   G_STRUCT_OFFSET (GtkTextLayoutClass, allocate_child),
                   NULL, NULL,
-                  gtk_marshal_VOID__OBJECT_INT_INT,
+                  _gtk_marshal_VOID__OBJECT_INT_INT,
                   GTK_TYPE_NONE,
                   3,
                   GTK_TYPE_OBJECT,
@@ -210,7 +208,7 @@ gtk_text_layout_class_init (GtkTextLayoutClass *klass)
                   GTK_TYPE_INT);
 }
 
-void
+static void
 gtk_text_layout_init (GtkTextLayout *text_layout)
 {
   text_layout->cursor_visible = TRUE;
@@ -295,6 +293,7 @@ gtk_text_layout_default_style_changed (GtkTextLayout *layout)
 {
   g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
 
+  DV (g_print ("invalidating all due to default style change (%s)\n", G_STRLOC));
   gtk_text_layout_invalidate_all (layout);
 }
 
@@ -337,6 +336,7 @@ gtk_text_layout_set_contexts (GtkTextLayout *layout,
   layout->rtl_context = rtl_context;
   g_object_ref (G_OBJECT (rtl_context));
 
+  DV (g_print ("invalidating all due to new pango contexts (%s)\n", G_STRLOC));
   gtk_text_layout_invalidate_all (layout);
 }
 
@@ -393,6 +393,7 @@ gtk_text_layout_set_screen_width (GtkTextLayout *layout, gint width)
 
   layout->screen_width = width;
 
+  DV (g_print ("invalidating all due to new screen width (%s)\n", G_STRLOC));
   gtk_text_layout_invalidate_all (layout);
 }
 
@@ -750,7 +751,7 @@ gtk_text_layout_real_free_line_data (GtkTextLayout     *layout,
  *
  * Check if there are any invalid regions in a #GtkTextLayout's buffer
  *
- * Return value: #TRUE if any invalid regions were found
+ * Return value: %TRUE if any invalid regions were found
  **/
 gboolean
 gtk_text_layout_is_valid (GtkTextLayout *layout)
@@ -921,10 +922,11 @@ gtk_text_layout_real_wrap (GtkTextLayout   *layout,
   GtkTextLineDisplay *display;
 
   g_return_val_if_fail (GTK_IS_TEXT_LAYOUT (layout), NULL);
-
+  g_return_val_if_fail (line != NULL, NULL);
+  
   if (line_data == NULL)
     {
-      line_data = gtk_text_line_data_new (layout, line);
+      line_data = _gtk_text_line_data_new (layout, line);
       _gtk_text_line_add_data (line, line_data);
     }
 
@@ -1456,7 +1458,7 @@ add_cursor (GtkTextLayout      *layout,
       cursor->y = PANGO_PIXELS (strong_pos.y);
       cursor->height = PANGO_PIXELS (strong_pos.height);
       cursor->is_strong = TRUE;
-      cursor->is_weak = FALSE;
+      cursor->is_weak = (layout->cursor_direction == GTK_TEXT_DIR_NONE) ? FALSE : TRUE;
       display->cursors = g_slist_prepend (display->cursors, cursor);
     }
   
@@ -1471,7 +1473,7 @@ add_cursor (GtkTextLayout      *layout,
          cursor->x = PANGO_PIXELS (weak_pos.x);
          cursor->y = PANGO_PIXELS (weak_pos.y);
          cursor->height = PANGO_PIXELS (weak_pos.height);
-         cursor->is_strong = FALSE;
+         cursor->is_strong = (layout->cursor_direction == GTK_TEXT_DIR_NONE) ? FALSE : TRUE;
          cursor->is_weak = TRUE;
          display->cursors = g_slist_prepend (display->cursors, cursor);
        }
@@ -2035,24 +2037,6 @@ line_display_index_to_iter (GtkTextLayout      *layout,
   gtk_text_iter_forward_chars (iter, trailing);
 }
 
-/* FIXME: This really doesn't belong in this file ... */
-static GtkTextLineData*
-gtk_text_line_data_new (GtkTextLayout *layout,
-                        GtkTextLine   *line)
-{
-  GtkTextLineData *line_data;
-
-  line_data = g_new (GtkTextLineData, 1);
-
-  line_data->view_id = layout;
-  line_data->next = NULL;
-  line_data->width = 0;
-  line_data->height = 0;
-  line_data->valid = FALSE;
-
-  return line_data;
-}
-
 static void
 get_line_at_y (GtkTextLayout *layout,
                gint           y,
@@ -2248,6 +2232,45 @@ gtk_text_layout_get_line_yrange (GtkTextLayout     *layout,
     }
 }
 
+/**
+ * _gtk_text_layout_get_line_xrange:
+ * @layout: a #GtkTextLayout
+ * @iter:   a #GtkTextIter
+ * @x:      location to store the top of the paragraph in pixels,
+ *          or %NULL.
+ * @width  location to store the height of the paragraph in pixels,
+ *          or %NULL.
+ *
+ * Find the range of X coordinates for the paragraph containing
+ * the given iter. Private for 2.0 due to API freeze, could
+ * be made public for 2.2.
+ **/
+void
+_gtk_text_layout_get_line_xrange (GtkTextLayout     *layout,
+                                  const GtkTextIter *iter,
+                                  gint              *x,
+                                  gint              *width)
+{
+  GtkTextLine *line;
+
+  g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
+  g_return_if_fail (_gtk_text_iter_get_btree (iter) == _gtk_text_buffer_get_btree (layout->buffer));
+
+  line = _gtk_text_iter_get_text_line (iter);
+
+  if (x)
+    *x = 0; /* FIXME This is wrong; should represent the first available cursor position */
+  
+  if (width)
+    {
+      GtkTextLineData *line_data = _gtk_text_line_get_data (line, layout);
+      if (line_data)
+        *width = line_data->width;
+      else
+        *width = 0;
+    }
+}
+
 void
 gtk_text_layout_get_iter_location (GtkTextLayout     *layout,
                                    const GtkTextIter *iter,
@@ -2407,6 +2430,7 @@ find_display_line_above (GtkTextLayout *layout,
           if (tmp_top < y)
             {
               found_line = line;
+             pango_layout_iter_free (layout_iter);
               goto done;
             }
         }