1 /* gtktextdisplay.c - display layed-out text
3 * Copyright (c) 1992-1994 The Regents of the University of California.
4 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
5 * Copyright (c) 2000 Red Hat, Inc.
6 * Tk->Gtk port by Havoc Pennington
8 * This file can be used under your choice of two licenses, the LGPL
9 * and the original Tk license.
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free
25 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * Original Tk license:
29 * This software is copyrighted by the Regents of the University of
30 * California, Sun Microsystems, Inc., and other parties. The
31 * following terms apply to all files associated with the software
32 * unless explicitly disclaimed in individual files.
34 * The authors hereby grant permission to use, copy, modify,
35 * distribute, and license this software and its documentation for any
36 * purpose, provided that existing copyright notices are retained in
37 * all copies and that this notice is included verbatim in any
38 * distributions. No written agreement, license, or royalty fee is
39 * required for any of the authorized uses. Modifications to this
40 * software may be copyrighted by their authors and need not follow
41 * the licensing terms described here, provided that the new terms are
42 * clearly indicated on the first page of each file where they apply.
44 * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY
45 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
46 * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION,
47 * OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED
48 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
51 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
52 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
53 * NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
54 * AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
55 * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
57 * GOVERNMENT USE: If you are acquiring this software on behalf of the
58 * U.S. government, the Government shall have only "Restricted Rights"
59 * in the software and related documentation as defined in the Federal
60 * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
61 * are acquiring the software on behalf of the Department of Defense,
62 * the software shall be classified as "Commercial Computer Software"
63 * and the Government shall have only "Restricted Rights" as defined
64 * in Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the
65 * foregoing, the authors grant the U.S. Government and others acting
66 * in its behalf permission to use and distribute the software in
67 * accordance with the terms specified in this license.
71 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
72 * file for a list of people on the GTK+ Team. See the ChangeLog
73 * files for a list of changes. These files are distributed with
74 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
77 #define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
78 #include "gtktextdisplay.h"
79 /* DO NOT go putting private headers in here. This file should only
80 * use the semi-public headers, as with gtktextview.c.
83 #include <pango/pango.h>
85 typedef struct _GtkTextRenderState GtkTextRenderState;
87 struct _GtkTextRenderState
91 GtkTextAppearance *last_appearance;
92 GtkTextAppearance *last_bg_appearance;
95 GdkRectangle clip_rect;
98 static void get_item_properties (PangoItem *item,
99 GtkTextAppearance **appearance);
100 static GdkRegion *get_selected_clip (GtkTextRenderState *render_state,
102 PangoLayoutLine *line,
109 static GtkTextRenderState *
110 gtk_text_render_state_new (GtkWidget *widget,
111 GdkDrawable *drawable,
112 GdkRectangle *clip_rect)
114 GtkTextRenderState *state = g_new0 (GtkTextRenderState, 1);
116 state->widget = widget;
117 state->fg_gc = gdk_gc_new (drawable);
118 state->bg_gc = gdk_gc_new (drawable);
119 state->clip_rect = *clip_rect;
125 gtk_text_render_state_destroy (GtkTextRenderState *state)
127 g_object_unref (state->fg_gc);
128 g_object_unref (state->bg_gc);
134 gtk_text_render_state_set_color (GtkTextRenderState *state,
138 gdk_colormap_alloc_color (gtk_widget_get_colormap (state->widget), color, FALSE, TRUE);
139 gdk_gc_set_foreground (gc, color);
143 gtk_text_render_state_update (GtkTextRenderState *state,
144 GtkTextAppearance *new_appearance)
146 GdkScreen *screen = gtk_widget_get_screen (state->widget);
148 if (!state->last_appearance ||
149 !gdk_color_equal (&new_appearance->fg_color, &state->last_appearance->fg_color))
150 gtk_text_render_state_set_color (state, state->fg_gc, &new_appearance->fg_color);
152 if (!state->last_appearance ||
153 new_appearance->fg_stipple != state->last_appearance->fg_stipple)
155 if (new_appearance->fg_stipple)
157 if (screen == gdk_drawable_get_screen (new_appearance->fg_stipple))
159 gdk_gc_set_fill (state->fg_gc, GDK_STIPPLED);
160 gdk_gc_set_stipple (state->fg_gc, new_appearance->fg_stipple);
163 g_warning ("gtk_text_render_state_update:\n"
164 "The foreground stipple bitmap has been created on the wrong screen.\n"
165 "Ignoring the stipple bitmap information.");
169 gdk_gc_set_fill (state->fg_gc, GDK_SOLID);
173 if (new_appearance->draw_bg)
175 if (!state->last_bg_appearance ||
176 !gdk_color_equal (&new_appearance->bg_color, &state->last_bg_appearance->bg_color))
177 gtk_text_render_state_set_color (state, state->bg_gc, &new_appearance->bg_color);
179 if (!state->last_bg_appearance ||
180 new_appearance->bg_stipple != state->last_bg_appearance->bg_stipple)
182 if (new_appearance->bg_stipple)
184 if (screen == gdk_drawable_get_screen (new_appearance->bg_stipple))
186 gdk_gc_set_fill (state->bg_gc, GDK_STIPPLED);
187 gdk_gc_set_stipple (state->bg_gc, new_appearance->bg_stipple);
190 g_warning ("gtk_text_render_state_update:\n"
191 "The background stipple bitmap has been created on the wrong screen.\n"
192 "Ignoring the stipple bitmap information.");
197 gdk_gc_set_fill (state->bg_gc, GDK_SOLID);
201 state->last_bg_appearance = new_appearance;
204 state->last_appearance = new_appearance;
208 get_shape_extents (PangoLayoutRun *run,
209 PangoRectangle *ink_rect,
210 PangoRectangle *logical_rect)
212 GSList *tmp_list = run->item->analysis.extra_attrs;
216 PangoAttribute *attr = tmp_list->data;
218 if (attr->klass->type == PANGO_ATTR_SHAPE)
221 *logical_rect = ((PangoAttrShape *)attr)->logical_rect;
224 *ink_rect = ((PangoAttrShape *)attr)->ink_rect;
229 tmp_list = tmp_list->next;
232 g_assert_not_reached ();
236 render_layout_line (GdkDrawable *drawable,
237 GtkTextRenderState *render_state,
238 PangoLayoutLine *line,
239 GSList **shaped_pointer,
245 GSList *tmp_list = line->runs;
246 PangoRectangle overall_rect;
247 PangoRectangle logical_rect;
248 PangoRectangle ink_rect;
252 pango_layout_line_get_extents (line, NULL, &overall_rect);
256 PangoLayoutRun *run = tmp_list->data;
257 GtkTextAppearance *appearance;
259 gint shaped_width_pixels = 0;
260 gboolean need_ink = FALSE;
262 tmp_list = tmp_list->next;
264 get_item_properties (run->item, &appearance);
266 g_assert (appearance != NULL);
268 risen_y = y - PANGO_PIXELS (appearance->rise);
272 if (GTK_WIDGET_HAS_FOCUS (render_state->widget))
273 fg_gc = render_state->widget->style->text_gc[GTK_STATE_SELECTED];
275 fg_gc = render_state->widget->style->text_gc [GTK_STATE_ACTIVE];
279 gtk_text_render_state_update (render_state, appearance);
281 fg_gc = render_state->fg_gc;
284 if (appearance->underline != PANGO_UNDERLINE_NONE ||
285 appearance->strikethrough)
288 if (appearance->is_text)
291 pango_glyph_string_extents (run->glyphs, run->item->analysis.font,
292 &ink_rect, &logical_rect);
294 pango_glyph_string_extents (run->glyphs, run->item->analysis.font,
295 NULL, &logical_rect);
300 get_shape_extents (run, &ink_rect, &logical_rect);
302 get_shape_extents (run, NULL, &logical_rect);
305 if (appearance->draw_bg && !selected)
306 gdk_draw_rectangle (drawable, render_state->bg_gc, TRUE,
307 x + PANGO_PIXELS (x_off) + PANGO_PIXELS (logical_rect.x),
308 risen_y + PANGO_PIXELS (logical_rect.y),
309 PANGO_PIXELS (logical_rect.width),
310 PANGO_PIXELS (logical_rect.height));
312 if (appearance->is_text)
313 gdk_draw_glyphs (drawable, fg_gc,
314 run->item->analysis.font,
315 x + PANGO_PIXELS (x_off),
316 risen_y, run->glyphs);
319 GObject *shaped = (*shaped_pointer)->data;
321 *shaped_pointer = (*shaped_pointer)->next;
325 /* This happens if we have an empty widget anchor. Draw
326 * something empty-looking.
328 GdkRectangle shape_rect, draw_rect;
330 shape_rect.x = x + x_off / PANGO_SCALE;
331 shape_rect.y = risen_y - PANGO_PIXELS (logical_rect.height);
332 shape_rect.width = PANGO_PIXELS (logical_rect.width);
333 shape_rect.height = PANGO_PIXELS (logical_rect.height);
335 if (gdk_rectangle_intersect (&shape_rect, &render_state->clip_rect,
338 gdk_draw_rectangle (drawable, render_state->fg_gc,
339 FALSE, shape_rect.x, shape_rect.y,
340 shape_rect.width, shape_rect.height);
342 gdk_draw_line (drawable, render_state->fg_gc,
343 shape_rect.x, shape_rect.y,
344 shape_rect.x + shape_rect.width,
345 shape_rect.y + shape_rect.height);
347 gdk_draw_line (drawable, render_state->fg_gc,
348 shape_rect.x + shape_rect.width, shape_rect.y,
350 shape_rect.y + shape_rect.height);
353 shaped_width_pixels = shape_rect.width;
355 else if (GDK_IS_PIXBUF (shaped))
358 GdkRectangle pixbuf_rect, draw_rect;
361 pixbuf = GDK_PIXBUF (shaped);
363 width = gdk_pixbuf_get_width (pixbuf);
364 height = gdk_pixbuf_get_height (pixbuf);
366 pixbuf_rect.x = x + x_off / PANGO_SCALE;
367 pixbuf_rect.y = risen_y - height;
368 pixbuf_rect.width = width;
369 pixbuf_rect.height = height;
371 if (gdk_rectangle_intersect (&pixbuf_rect, &render_state->clip_rect,
374 GdkBitmap *mask = NULL;
376 if (gdk_pixbuf_get_has_alpha (pixbuf))
378 mask = gdk_pixmap_new (drawable,
379 gdk_pixbuf_get_width (pixbuf),
380 gdk_pixbuf_get_height (pixbuf),
383 gdk_pixbuf_render_threshold_alpha (pixbuf, mask,
385 gdk_pixbuf_get_width (pixbuf),
386 gdk_pixbuf_get_height (pixbuf),
393 gdk_gc_set_clip_mask (render_state->fg_gc, mask);
394 gdk_gc_set_clip_origin (render_state->fg_gc,
395 pixbuf_rect.x, pixbuf_rect.y);
398 gdk_draw_pixbuf (drawable,
401 draw_rect.x - pixbuf_rect.x,
402 draw_rect.y - pixbuf_rect.y,
403 draw_rect.x, draw_rect.y,
406 GDK_RGB_DITHER_NORMAL,
411 gdk_gc_set_clip_rectangle (render_state->fg_gc,
412 &render_state->clip_rect);
413 g_object_unref (mask);
417 shaped_width_pixels = width;
419 else if (GTK_IS_WIDGET (shaped))
423 widget = GTK_WIDGET (shaped);
425 shaped_width_pixels = widget->allocation.width;
429 g_object_ref (widget);
430 *widgets = g_list_prepend (*widgets, widget);
434 g_assert_not_reached (); /* not a pixbuf or widget */
437 switch (appearance->underline)
439 case PANGO_UNDERLINE_NONE:
441 case PANGO_UNDERLINE_DOUBLE:
443 gdk_draw_line (drawable, fg_gc,
444 x + (x_off + ink_rect.x) / PANGO_SCALE - 1,
446 x + (x_off + ink_rect.x + ink_rect.width) / PANGO_SCALE,
449 case PANGO_UNDERLINE_SINGLE:
451 gdk_draw_line (drawable, fg_gc,
452 x + (x_off + ink_rect.x) / PANGO_SCALE - 1,
454 x + (x_off + ink_rect.x + ink_rect.width) / PANGO_SCALE,
457 case PANGO_UNDERLINE_LOW:
459 gdk_draw_line (drawable, fg_gc,
460 x + (x_off + ink_rect.x) / PANGO_SCALE - 1,
461 risen_y + (ink_rect.y + ink_rect.height) / PANGO_SCALE + 1,
462 x + (x_off + ink_rect.x + ink_rect.width) / PANGO_SCALE,
463 risen_y + (ink_rect.y + ink_rect.height) / PANGO_SCALE + 1);
467 if (appearance->strikethrough)
469 gint strikethrough_y = risen_y + (0.3 * logical_rect.y) / PANGO_SCALE;
473 gdk_draw_line (drawable, fg_gc,
474 x + (x_off + ink_rect.x) / PANGO_SCALE - 1, strikethrough_y,
475 x + (x_off + ink_rect.x + ink_rect.width) / PANGO_SCALE, strikethrough_y);
478 if (appearance->is_text)
479 x_off += logical_rect.width;
481 x_off += shaped_width_pixels * PANGO_SCALE;
486 render_para (GdkDrawable *drawable,
487 GtkTextRenderState *render_state,
488 GtkTextLineDisplay *line_display,
489 /* Top-left corner of paragraph including all margins */
492 int selection_start_index,
493 int selection_end_index,
496 GSList *shaped_pointer = line_display->shaped_objects;
497 PangoLayout *layout = line_display->layout;
499 PangoLayoutIter *iter;
500 PangoRectangle layout_logical;
502 GdkGC *fg_gc, *bg_gc;
505 gboolean first = TRUE;
507 iter = pango_layout_get_iter (layout);
509 pango_layout_iter_get_layout_extents (iter, NULL, &layout_logical);
511 /* Adjust for margins */
513 layout_logical.x += line_display->x_offset * PANGO_SCALE;
514 layout_logical.y += line_display->top_margin * PANGO_SCALE;
516 screen_width = line_display->total_width;
518 if (GTK_WIDGET_HAS_FOCUS (render_state->widget))
519 state = GTK_STATE_SELECTED;
521 state = GTK_STATE_ACTIVE;
523 fg_gc = render_state->widget->style->text_gc [state];
524 bg_gc = render_state->widget->style->base_gc [state];
528 PangoLayoutLine *line = pango_layout_iter_get_line (iter);
529 int selection_y, selection_height;
531 PangoRectangle line_rect;
534 pango_layout_iter_get_line_extents (iter, NULL, &line_rect);
535 baseline = pango_layout_iter_get_baseline (iter);
536 pango_layout_iter_get_line_yrange (iter, &first_y, &last_y);
538 /* Adjust for margins */
540 line_rect.x += line_display->x_offset * PANGO_SCALE;
541 line_rect.y += line_display->top_margin * PANGO_SCALE;
542 baseline += line_display->top_margin * PANGO_SCALE;
544 /* Selection is the height of the line, plus top/bottom
545 * margin if we're the first/last line
547 selection_y = y + PANGO_PIXELS (first_y) + line_display->top_margin;
548 selection_height = PANGO_PIXELS (last_y) - PANGO_PIXELS (first_y);
552 selection_y -= line_display->top_margin;
553 selection_height += line_display->top_margin;
556 if (pango_layout_iter_at_last_line (iter))
557 selection_height += line_display->bottom_margin;
561 if (selection_start_index < byte_offset &&
562 selection_end_index > line->length + byte_offset) /* All selected */
564 gdk_draw_rectangle (drawable,
567 x + line_display->left_margin,
572 render_layout_line (drawable, render_state, line, &shaped_pointer,
573 x + PANGO_PIXELS (line_rect.x),
574 y + PANGO_PIXELS (baseline),
580 GSList *shaped_pointer_tmp = shaped_pointer;
582 render_layout_line (drawable, render_state,
583 line, &shaped_pointer,
584 x + PANGO_PIXELS (line_rect.x),
585 y + PANGO_PIXELS (baseline),
589 if (selection_start_index <= byte_offset + line->length &&
590 selection_end_index > byte_offset) /* Some selected */
592 GdkRegion *clip_region = get_selected_clip (render_state, layout, line,
593 x + line_display->x_offset,
596 selection_start_index, selection_end_index);
597 gdk_gc_set_clip_region (fg_gc, clip_region);
598 gdk_gc_set_clip_region (bg_gc, clip_region);
600 gdk_draw_rectangle (drawable,
603 x + PANGO_PIXELS (line_rect.x),
605 PANGO_PIXELS (line_rect.width),
608 render_layout_line (drawable, render_state, line, &shaped_pointer_tmp,
609 x + PANGO_PIXELS (line_rect.x),
610 y + PANGO_PIXELS (baseline),
614 gdk_gc_set_clip_region (fg_gc, NULL);
615 gdk_gc_set_clip_region (bg_gc, NULL);
617 gdk_region_destroy (clip_region);
619 /* Paint in the ends of the line */
620 if (line_rect.x > line_display->left_margin * PANGO_SCALE &&
621 ((line_display->direction == GTK_TEXT_DIR_LTR && selection_start_index < byte_offset) ||
622 (line_display->direction == GTK_TEXT_DIR_RTL && selection_end_index > byte_offset + line->length)))
624 gdk_draw_rectangle (drawable,
627 x + line_display->left_margin,
629 PANGO_PIXELS (line_rect.x) - line_display->left_margin,
633 if (line_rect.x + line_rect.width <
634 (screen_width + line_display->left_margin) * PANGO_SCALE &&
635 ((line_display->direction == GTK_TEXT_DIR_LTR && selection_end_index > byte_offset + line->length) ||
636 (line_display->direction == GTK_TEXT_DIR_RTL && selection_start_index < byte_offset)))
641 line_display->left_margin + screen_width -
642 PANGO_PIXELS (line_rect.x) - PANGO_PIXELS (line_rect.width);
644 gdk_draw_rectangle (drawable,
647 x + PANGO_PIXELS (line_rect.x) + PANGO_PIXELS (line_rect.width),
655 byte_offset += line->length;
657 while (pango_layout_iter_next_line (iter));
659 pango_layout_iter_free (iter);
663 get_selected_clip (GtkTextRenderState *render_state,
665 PangoLayoutLine *line,
674 GdkRegion *clip_region = gdk_region_new ();
675 GdkRegion *tmp_region;
677 pango_layout_line_get_x_ranges (line, start_index, end_index, &ranges, &n_ranges);
679 for (i=0; i < n_ranges; i++)
683 rect.x = x + PANGO_PIXELS (ranges[2*i]);
685 rect.width = PANGO_PIXELS (ranges[2*i + 1]) - PANGO_PIXELS (ranges[2*i]);
686 rect.height = height;
688 gdk_region_union_with_rect (clip_region, &rect);
691 tmp_region = gdk_region_rectangle (&render_state->clip_rect);
692 gdk_region_intersect (clip_region, tmp_region);
693 gdk_region_destroy (tmp_region);
700 get_item_properties (PangoItem *item,
701 GtkTextAppearance **appearance)
703 GSList *tmp_list = item->analysis.extra_attrs;
709 PangoAttribute *attr = tmp_list->data;
711 if (attr->klass->type == gtk_text_attr_appearance_type)
713 *appearance = &((GtkTextAttrAppearance *)attr)->appearance;
716 tmp_list = tmp_list->next;
721 gtk_text_layout_draw (GtkTextLayout *layout,
723 GdkDrawable *drawable,
725 /* Location of the drawable
726 in layout coordinates */
729 /* Region of the layout to
735 /* widgets to expose */
741 GtkTextRenderState *render_state;
742 GtkTextIter selection_start, selection_end;
743 gboolean have_selection = FALSE;
747 g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
748 g_return_if_fail (layout->default_style != NULL);
749 g_return_if_fail (layout->buffer != NULL);
750 g_return_if_fail (drawable != NULL);
751 g_return_if_fail (width >= 0);
752 g_return_if_fail (height >= 0);
754 if (width == 0 || height == 0)
757 line_list = gtk_text_layout_get_lines (layout, y + y_offset, y + y_offset + height, ¤t_y);
758 current_y -= y_offset;
760 if (line_list == NULL)
761 return; /* nothing on the screen */
766 clip.height = height;
768 render_state = gtk_text_render_state_new (widget, drawable, &clip);
770 gdk_gc_set_clip_rectangle (render_state->fg_gc, &clip);
771 gdk_gc_set_clip_rectangle (render_state->bg_gc, &clip);
773 gtk_text_layout_wrap_loop_start (layout);
775 if (gtk_text_buffer_get_selection_bounds (layout->buffer,
778 have_selection = TRUE;
780 tmp_list = line_list;
781 while (tmp_list != NULL)
783 GtkTextLineDisplay *line_display;
784 gint selection_start_index = -1;
785 gint selection_end_index = -1;
786 gboolean have_strong;
789 GtkTextLine *line = tmp_list->data;
791 line_display = gtk_text_layout_get_line_display (layout, line, FALSE);
793 if (line_display->height > 0)
795 g_assert (line_display->layout != NULL);
799 GtkTextIter line_start, line_end;
802 gtk_text_layout_get_iter_at_line (layout,
805 line_end = line_start;
806 gtk_text_iter_forward_to_line_end (&line_end);
807 byte_count = gtk_text_iter_get_line_index (&line_end);
809 if (gtk_text_iter_compare (&selection_start, &line_end) <= 0 &&
810 gtk_text_iter_compare (&selection_end, &line_start) >= 0)
812 if (gtk_text_iter_compare (&selection_start, &line_start) >= 0)
813 selection_start_index = gtk_text_iter_get_line_index (&selection_start);
815 selection_start_index = -1;
817 if (gtk_text_iter_compare (&selection_end, &line_end) <= 0)
818 selection_end_index = gtk_text_iter_get_line_index (&selection_end);
820 selection_end_index = byte_count;
824 render_para (drawable, render_state, line_display,
827 selection_start_index, selection_end_index,
830 /* We paint the cursors last, because they overlap another chunk
831 and need to appear on top. */
836 cursor_list = line_display->cursors;
839 GtkTextCursorDisplay *cursor = cursor_list->data;
840 if (cursor->is_strong)
845 cursor_list = cursor_list->next;
848 cursor_list = line_display->cursors;
851 GtkTextCursorDisplay *cursor = cursor_list->data;
852 GtkTextDirection dir;
853 GdkRectangle cursor_location;
856 dir = line_display->direction;
857 if (have_strong && have_weak)
859 if (!cursor->is_strong)
860 dir = (dir == GTK_TEXT_DIR_RTL) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
863 cursor_location.x = line_display->x_offset + cursor->x - x_offset;
864 cursor_location.y = current_y + line_display->top_margin + cursor->y;
865 cursor_location.width = 0;
866 cursor_location.height = cursor->height;
868 gc = _gtk_get_insertion_cursor_gc (widget, cursor->is_strong);
869 gdk_gc_set_clip_rectangle(gc, &clip);
870 _gtk_draw_insertion_cursor (widget, drawable, gc, &cursor_location,
871 dir, have_strong && have_weak);
872 gdk_gc_set_clip_rectangle (gc, NULL);
876 cursor_list = cursor_list->next;
878 } /* line_display->height > 0 */
880 current_y += line_display->height;
881 gtk_text_layout_free_line_display (layout, line_display);
882 render_state->last_appearance = NULL;
883 render_state->last_bg_appearance = NULL;
885 tmp_list = g_slist_next (tmp_list);
888 gtk_text_layout_wrap_loop_end (layout);
889 gtk_text_render_state_destroy (render_state);
891 g_slist_free (line_list);