summaryrefslogtreecommitdiff
path: root/gtk/gtktextdisplay.c
diff options
context:
space:
mode:
authorPaolo Borelli <pborelli@gnome.org>2011-11-26 23:48:10 +0100
committerPaolo Borelli <pborelli@gnome.org>2011-12-01 01:22:39 +0100
commit0bff1af7a20948a7275a4e9e1fa3fac903a422f8 (patch)
treec49ef37d2d3fdf1ce6c19beeb78204f46f666351 /gtk/gtktextdisplay.c
parentb3f850e6b9b12143b3286e129cbe17ca60351d7d (diff)
downloadgtk+-0bff1af7a20948a7275a4e9e1fa3fac903a422f8.tar.gz
Rework GtkTextView cursor code.
Move the handling of primary/secondary cursors to gtktextdisplay, which makes code simpler and more consistent to how GtkLabel and GtkEntry draw cursors, which is useful in preparation to further refactoring. https://bugzilla.gnome.org/show_bug.cgi?id=640317
Diffstat (limited to 'gtk/gtktextdisplay.c')
-rw-r--r--gtk/gtktextdisplay.c86
1 files changed, 44 insertions, 42 deletions
diff --git a/gtk/gtktextdisplay.c b/gtk/gtktextdisplay.c
index 360f515d50..6911dae0ee 100644
--- a/gtk/gtktextdisplay.c
+++ b/gtk/gtktextdisplay.c
@@ -822,7 +822,6 @@ gtk_text_layout_draw (GtkTextLayout *layout,
GList **widgets)
{
gint offset_y;
- GSList *cursor_list;
GtkTextRenderer *text_renderer;
GtkTextIter selection_start, selection_end;
gboolean have_selection;
@@ -862,8 +861,6 @@ gtk_text_layout_draw (GtkTextLayout *layout,
GtkTextLineDisplay *line_display;
gint selection_start_index = -1;
gint selection_end_index = -1;
- gboolean have_strong;
- gboolean have_weak;
GtkTextLine *line = tmp_list->data;
@@ -905,47 +902,52 @@ gtk_text_layout_draw (GtkTextLayout *layout,
selection_start_index, selection_end_index);
/* We paint the cursors last, because they overlap another chunk
- and need to appear on top. */
-
- have_strong = FALSE;
- have_weak = FALSE;
-
- cursor_list = line_display->cursors;
- while (cursor_list)
- {
- GtkTextCursorDisplay *cursor = cursor_list->data;
- if (cursor->is_strong)
- have_strong = TRUE;
- else
- have_weak = TRUE;
-
- cursor_list = cursor_list->next;
- }
-
- cursor_list = line_display->cursors;
- while (cursor_list)
+ * and need to appear on top.
+ */
+ if (line_display->cursors != NULL)
{
- GtkTextCursorDisplay *cursor = cursor_list->data;
- GtkTextDirection dir;
- GdkRectangle cursor_location;
-
- dir = line_display->direction;
- if (have_strong && have_weak)
- {
- if (!cursor->is_strong)
- dir = (dir == GTK_TEXT_DIR_RTL) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
- }
-
- cursor_location.x = line_display->x_offset + cursor->x;
- cursor_location.y = line_display->top_margin + cursor->y;
- cursor_location.width = 0;
- cursor_location.height = cursor->height;
+ int i;
- gtk_draw_insertion_cursor (widget, cr, &cursor_location,
- cursor->is_strong,
- dir, have_strong && have_weak);
-
- cursor_list = cursor_list->next;
+ for (i = 0; i < line_display->cursors->len; i++)
+ {
+ int index;
+ PangoRectangle strong_pos, weak_pos;
+ GdkRectangle cursor_location;
+
+ index = g_array_index(line_display->cursors, int, i);
+ pango_layout_get_cursor_pos (line_display->layout, index, &strong_pos, &weak_pos);
+
+ cursor_location.x = line_display->x_offset + PANGO_PIXELS (strong_pos.x);
+ cursor_location.y = line_display->top_margin + PANGO_PIXELS (strong_pos.y);
+ cursor_location.width = 0;
+ cursor_location.height = PANGO_PIXELS (strong_pos.height);
+
+ if (layout->cursor_direction == GTK_TEXT_DIR_NONE ||
+ line_display->direction == layout->cursor_direction)
+ {
+ gtk_draw_insertion_cursor (widget, cr,
+ &cursor_location, TRUE, line_display->direction,
+ layout->cursor_direction != GTK_TEXT_DIR_NONE);
+ }
+
+ if ((strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y) &&
+ (layout->cursor_direction == GTK_TEXT_DIR_NONE ||
+ line_display->direction != layout->cursor_direction))
+ {
+ GtkTextDirection dir;
+
+ dir = (line_display->direction == GTK_TEXT_DIR_RTL) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
+
+ cursor_location.x = line_display->x_offset + PANGO_PIXELS (weak_pos.x);
+ cursor_location.y = line_display->top_margin + PANGO_PIXELS (weak_pos.y);
+ cursor_location.width = 0;
+ cursor_location.height = PANGO_PIXELS (weak_pos.height);
+
+ gtk_draw_insertion_cursor (widget, cr,
+ &cursor_location, FALSE, dir,
+ TRUE);
+ }
+ }
}
} /* line_display->height > 0 */