After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 81045 - [PATCH] paragraph-background
[PATCH] paragraph-background
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkTextView
unspecified
Other other
: Normal enhancement
: ---
Assigned To: gtk-bugs
gtk-bugs
: 95261 117411 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2002-05-07 14:28 UTC by Gustavo Carneiro
Modified: 2011-02-04 16:18 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch is against the gtk-2-6 branch (11.47 KB, patch)
2005-03-20 11:35 UTC, Jeroen Zwartepoorte
none Details | Review
working patch again gtk-2-6 branch (13.08 KB, patch)
2005-03-22 12:53 UTC, Jeroen Zwartepoorte
none Details | Review
new patch (11.12 KB, patch)
2005-05-03 04:30 UTC, Matthias Clasen
none Details | Review

Description Gustavo Carneiro 2002-05-07 14:28:57 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.
Comment 1 Owen Taylor 2002-10-09 12:40:17 UTC
*** Bug 95261 has been marked as a duplicate of this bug. ***
Comment 2 Havoc Pennington 2003-07-14 20:20:57 UTC
*** Bug 117411 has been marked as a duplicate of this bug. ***
Comment 3 Jeroen Zwartepoorte 2005-03-20 11:33:49 UTC
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.
Comment 4 Jeroen Zwartepoorte 2005-03-20 11:35:02 UTC
Created attachment 38957 [details] [review]
patch is against the gtk-2-6 branch
Comment 5 Tomislav Jonjic 2005-03-21 09:16:14 UTC
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/
Comment 6 Jeroen Zwartepoorte 2005-03-21 09:40:53 UTC
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.
Comment 7 Tomislav Jonjic 2005-03-21 11:50:20 UTC
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.
Comment 8 Jeroen Zwartepoorte 2005-03-22 12:53:08 UTC
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?
Comment 9 Jeroen Zwartepoorte 2005-03-22 12:53:47 UTC
Created attachment 39065 [details] [review]
working patch again gtk-2-6 branch
Comment 10 Matthias Clasen 2005-05-03 04:30:12 UTC
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.
Comment 11 Jeroen Zwartepoorte 2005-05-03 06:33:29 UTC
Looks good. Thanks.
Comment 12 Jeroen Zwartepoorte 2005-06-08 16:16:00 UTC
Has this been committed yet? If so, can't this bug be closed?
Comment 13 Matthias Clasen 2005-06-08 16:21:26 UTC
No, it hasn't. But it is on 2.8 API freeze, so still under consideration for 2.8
Comment 14 Matthias Clasen 2005-06-10 20:05:16 UTC
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.