GNOME Bugzilla – Bug 81045
[PATCH] paragraph-background
Last modified: 2011-02-04 16:18:41 UTC
Currently, when you apply a background attribute to a portion of text that spans multiple lines (has \n's), only the area behind the text gets painted, but not the region between the end-of-line and the right/left edge of the widget. So GtkTextTag needs a new attribute, maybe called 'paragraph-background', that instructs GtkTextView to paint not only the background of the text, but also all the way to the margins.
*** Bug 95261 has been marked as a duplicate of this bug. ***
*** Bug 117411 has been marked as a duplicate of this bug. ***
Attached patch implements the paragraph-background property. Please comment. The patch has a bug where the actual background is painted on the *next* line. It uses the same principle as painting the selection background when the entire line is selected. So if somebody can help me identify the bug, i'd appreciate it.
Created attachment 38957 [details] [review] patch is against the gtk-2-6 branch
IMO, paragraph-background should be a per paragraph attribute rather than a text appearance flag. That would mean it only has effect if it set at the beginning of the paragraph, just like indentation, alignemt and other paragraph level attributes. Btw, I think that changing GtkTextAppearance the way you've done it is definitely not ABI safe, since it is a public struct after all. A while ago I wrote a patch (and forgot about it...) that implements both a paragraph-background property (works as explained above) and also bg-full-height/bg-full-width properties which are actually modifiers of the existing 'background' propertiy. 'bg-full-width' specifies that you want to extend the text background to the margins. It only has effect if it is set at the start/end of the current Pango layout line. That is useful for highlighting an arbitrary block of poossibly wrapped text (say a Lisp S-expression). See the the included test program for examples. It requires a small Pango patch in it's current form (maybe it could be easily avoided). Patches (against respective stable branches): http://www.inet.hr/~tojonjic/gtktextviewbg/
The patch is ABI safe. The new fields replace the padN fields (struct length stays the same). Other than that your patch is a lot more intrusive (why is the pango patch necessary? Pango already supports drawing text with a background color), i'll somebody more knowledgable about GtkTextView comment on which approach is better.
Of course Pango supports specifying a background color, but I needed a simple way to override the default way the background part is drawn. Anyway, the Pango patch is there to make background-full-height/width work, and is not needed at all for the `paragraph-background' part, so my big ugly patch could really be split.
Following patch set's the paragraph background color on the GtkTextLineDisplay (idea taken from Tomislav's patch). Only thing which i'm unsure about is how to deal with the GdkGC i create for the paragraph background. Does it need to be cached somehow etc. OK to commit?
Created attachment 39065 [details] [review] working patch again gtk-2-6 branch
Created attachment 45964 [details] [review] new patch I've modified Jeroens patch to store the paragraph background color in the GtkTextAttributes struct instead of in GtkTextAppearance, since we can't grow GtkTextAppearance ABI-compatible, and there is a padding pointer in GtkTextAttributes anyway.
Looks good. Thanks.
Has this been committed yet? If so, can't this bug be closed?
No, it hasn't. But it is on 2.8 API freeze, so still under consideration for 2.8
2005-06-10 Matthias Clasen <mclasen@redhat.com> Allow setting paragraph background. (#81045, Gustavo Carneiro, patch by Jeroen Zwartepoorte) * gtk/gtktextlayout.c (set_para_values): Propagate pg_bg_color to the display struct. (gtk_text_layout_free_line_display): Free it here. * gtk/gtktextdisplay.c (render_para): If pg_bg_color is set, draw a rectangle in that color behind the paragraph. * gtk/gtktexttag.c (gtk_text_tag_class_init): Add paragraph-background, paragraph-background-gdk and paragraph-background-set properties. (set_pg_bg_color): A setter for paragraph-background. * gtk/gtktextlayout.h (struct _GtkTextLineDisplay): Add pg_bg_color. * gtk/gtktexttag.h (struct _GtkTextAttributes): Add pg_bg_color. (struct _GtkTextTag): Add pg_bg_color_set.