diff options
author | Havoc Pennington <hp@pobox.com> | 2002-02-25 04:19:05 +0000 |
---|---|---|
committer | Havoc Pennington <hp@src.gnome.org> | 2002-02-25 04:19:05 +0000 |
commit | 8ddb92e4911f0f9304be211382b4e80258d7804b (patch) | |
tree | 40c503f9ac35f28487c7bd1d67944a82a7411c87 /gtk | |
parent | 3e7279cff4cb1cd940a9ad22a5abf5fd4b3bfa43 (diff) | |
download | gtk+-8ddb92e4911f0f9304be211382b4e80258d7804b.tar.gz |
change to pass in the cursor direction always, not just when we need an
2002-02-24 Havoc Pennington <hp@pobox.com>
* gtk/gtkstyle.c (_gtk_draw_insertion_cursor): change to pass in
the cursor direction always, not just when we need an arrow, so we
can flip the cursor around its axis for RTL. Resolves #72372
* gtk/gtkentry.c (gtk_entry_draw_cursor): update for
draw_insertion_cursor change
* gtk/gtklabel.c (gtk_label_draw_cursor): ditto
* gtk/gtktextdisplay.c (gtk_text_layout_draw): ditto
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkentry.c | 11 | ||||
-rw-r--r-- | gtk/gtklabel.c | 10 | ||||
-rw-r--r-- | gtk/gtkstyle.c | 74 | ||||
-rw-r--r-- | gtk/gtkstyle.h | 3 | ||||
-rw-r--r-- | gtk/gtktextdisplay.c | 9 |
5 files changed, 62 insertions, 45 deletions
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 5a847e9a88..3a4dcfbaa9 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -2701,6 +2701,8 @@ gtk_entry_draw_cursor (GtkEntry *entry, "gtk-split-cursor", &split_cursor, NULL); + dir1 = widget_direction; + if (split_cursor) { gc1 = entry->cursor_gc; @@ -2708,7 +2710,6 @@ gtk_entry_draw_cursor (GtkEntry *entry, if (weak_x != strong_x) { - dir1 = widget_direction; dir2 = (widget_direction == GTK_TEXT_DIR_LTR) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR; gc2 = widget->style->text_gc[GTK_STATE_NORMAL]; @@ -2731,13 +2732,15 @@ gtk_entry_draw_cursor (GtkEntry *entry, cursor_location.height = text_area_height - 2 * INNER_BORDER ; _gtk_draw_insertion_cursor (widget, entry->text_area, gc1, - &cursor_location, dir1); + &cursor_location, dir1, + dir2 != GTK_TEXT_DIR_NONE); - if (gc2) + if (dir2 != GTK_TEXT_DIR_NONE) { cursor_location.x = xoffset + x2; _gtk_draw_insertion_cursor (widget, entry->text_area, gc2, - &cursor_location, dir2); + &cursor_location, dir2, + TRUE); } } } diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index 5341d749f7..8538e458f7 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -1694,6 +1694,8 @@ gtk_label_draw_cursor (GtkLabel *label, gint xoffset, gint yoffset) "gtk-split-cursor", &split_cursor, NULL); + dir1 = widget_direction; + if (split_cursor) { gc1 = label->select_info->cursor_gc; @@ -1702,7 +1704,6 @@ gtk_label_draw_cursor (GtkLabel *label, gint xoffset, gint yoffset) if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y) { - dir1 = widget_direction; dir2 = (widget_direction == GTK_TEXT_DIR_LTR) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR; gc2 = widget->style->black_gc; @@ -1725,9 +1726,10 @@ gtk_label_draw_cursor (GtkLabel *label, gint xoffset, gint yoffset) cursor_location.height = PANGO_PIXELS (cursor1->height); _gtk_draw_insertion_cursor (widget, widget->window, gc1, - &cursor_location, dir1); + &cursor_location, dir1, + dir2 != GTK_TEXT_DIR_NONE); - if (gc2) + if (dir2 != GTK_TEXT_DIR_NONE) { cursor_location.x = xoffset + PANGO_PIXELS (cursor2->x); cursor_location.y = yoffset + PANGO_PIXELS (cursor2->y); @@ -1735,7 +1737,7 @@ gtk_label_draw_cursor (GtkLabel *label, gint xoffset, gint yoffset) cursor_location.height = PANGO_PIXELS (cursor2->height); _gtk_draw_insertion_cursor (widget, widget->window, gc2, - &cursor_location, dir2); + &cursor_location, dir2, TRUE); } } } diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c index eca446b3d0..beef9abb4d 100644 --- a/gtk/gtkstyle.c +++ b/gtk/gtkstyle.c @@ -5668,9 +5668,10 @@ gtk_style_set_font (GtkStyle *style, * @drawable: a #GdkDrawable * @gc: a #GdkGC * @location: location where to draw the cursor (@location->width is ignored) - * @dir: text direction for the cursor, used to decide whether to draw a - * directional arrow on the cursor and in what direction. Unless both - * strong and weak cursors are displayed, this should be %GTK_TEXT_DIR_NONE. + * @direction: whether the cursor is left-to-right or + * right-to-left. Should never be #GTK_TEXT_DIR_NONE + * @draw_arrow: %TRUE to draw a directional arrow on the + * cursor. Should be %FALSE unless the cursor is split. * * Draws a text caret on @drawable at @location. This is not a style function * but merely a convenience function for drawing the standard cursor shape. @@ -5680,48 +5681,61 @@ _gtk_draw_insertion_cursor (GtkWidget *widget, GdkDrawable *drawable, GdkGC *gc, GdkRectangle *location, - GtkTextDirection dir) + GtkTextDirection direction, + gboolean draw_arrow) { gint stem_width; gint arrow_width; gint x, y; gint i; gfloat cursor_aspect_ratio; - + gint offset; + + g_return_if_fail (direction != GTK_TEXT_DIR_NONE); + gtk_widget_style_get (widget, "cursor-aspect-ratio", &cursor_aspect_ratio, NULL); stem_width = location->height * cursor_aspect_ratio + 1; arrow_width = stem_width + 1; - + + /* put (stem_width % 2) on the proper side of the cursor */ + if (direction == GTK_TEXT_DIR_LTR) + offset = stem_width / 2; + else + offset = stem_width - stem_width / 2; + for (i = 0; i < stem_width; i++) gdk_draw_line (drawable, gc, - location->x + i - stem_width / 2, location->y, - location->x + i - stem_width / 2, location->y + location->height - 1); + location->x + i - offset, location->y, + location->x + i - offset, location->y + location->height - 1); - if (dir == GTK_TEXT_DIR_RTL) + if (draw_arrow) { - x = location->x - stem_width / 2 - 1; - y = location->y + location->height - arrow_width * 2 - arrow_width + 1; + if (direction == GTK_TEXT_DIR_RTL) + { + x = location->x - offset - 1; + y = location->y + location->height - arrow_width * 2 - arrow_width + 1; - for (i = 0; i < arrow_width; i++) - { - gdk_draw_line (drawable, gc, - x, y + i + 1, - x, y + 2 * arrow_width - i - 1); - x --; - } - } - else if (dir == GTK_TEXT_DIR_LTR) - { - x = location->x + stem_width - stem_width / 2; - y = location->y + location->height - arrow_width * 2 - arrow_width + 1; + for (i = 0; i < arrow_width; i++) + { + gdk_draw_line (drawable, gc, + x, y + i + 1, + x, y + 2 * arrow_width - i - 1); + x --; + } + } + else if (direction == GTK_TEXT_DIR_LTR) + { + x = location->x + stem_width - offset; + y = location->y + location->height - arrow_width * 2 - arrow_width + 1; - for (i = 0; i < arrow_width; i++) - { - gdk_draw_line (drawable, gc, - x, y + i + 1, - x, y + 2 * arrow_width - i - 1); - x++; - } + for (i = 0; i < arrow_width; i++) + { + gdk_draw_line (drawable, gc, + x, y + i + 1, + x, y + 2 * arrow_width - i - 1); + x++; + } + } } } diff --git a/gtk/gtkstyle.h b/gtk/gtkstyle.h index 9c3d60384e..02b8a6e27b 100644 --- a/gtk/gtkstyle.h +++ b/gtk/gtkstyle.h @@ -883,7 +883,8 @@ void _gtk_draw_insertion_cursor (GtkWidget *widget, GdkDrawable *drawable, GdkGC *gc, GdkRectangle *location, - GtkTextDirection dir); + GtkTextDirection direction, + gboolean draw_arrow); #ifdef __cplusplus } diff --git a/gtk/gtktextdisplay.c b/gtk/gtktextdisplay.c index b3acdab830..cfb5225d74 100644 --- a/gtk/gtktextdisplay.c +++ b/gtk/gtktextdisplay.c @@ -842,16 +842,12 @@ gtk_text_layout_draw (GtkTextLayout *layout, else gc = widget->style->text_gc[GTK_STATE_NORMAL]; + dir = line_display->direction; if (have_strong && have_weak) { - dir = line_display->direction; if (!cursor->is_strong) dir = (dir == GTK_TEXT_DIR_RTL) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL; } - else - { - dir = GTK_TEXT_DIR_NONE; - } cursor_location.x = line_display->x_offset + cursor->x - x_offset; cursor_location.y = current_y + line_display->top_margin + cursor->y; @@ -859,7 +855,8 @@ gtk_text_layout_draw (GtkTextLayout *layout, cursor_location.height = cursor->height; gdk_gc_set_clip_rectangle(gc, &clip); - _gtk_draw_insertion_cursor (widget, drawable, gc, &cursor_location, dir); + _gtk_draw_insertion_cursor (widget, drawable, gc, &cursor_location, + dir, have_strong && have_weak); gdk_gc_set_clip_rectangle (gc, NULL); cursor_list = cursor_list->next; |