[Gtk-sharp-list] TextBuffer and TextTags
Daniel Morgan
danielmorgan@verizon.net
Sat, 17 Jul 2004 21:39:05 -0400
Mono and GTK# Documentation can be found at:
http://www.go-mono.com/docs/
Again, take a look at how sqlsharpgtk does it.
http://cvs.hispalinux.es/cgi-bin/cvsweb/sqlsharpgtk/sqlsharpgtk/?cvsroot
=mono
This is for a text view that I log output:
ScrolledWindow CreateOutputResultsTextView ()
{
ScrolledWindow sw;
sw = new ScrolledWindow (
new Adjustment (0.0, 0.0, 0.0, 0.0, 0.0,
0.0),
new Adjustment (0.0, 0.0, 0.0, 0.0, 0.0,
0.0));
sw.HscrollbarPolicy = Gtk.PolicyType.Automatic;
sw.VscrollbarPolicy = Gtk.PolicyType.Automatic;
sw.ShadowType = Gtk.ShadowType.In;
textView = new TextView ();
buf = textView.Buffer;
textView.Editable = false;
textView.ModifyFont
(Pango.FontDescription.FromString ("courier new"));
sw.Add (textView);
return sw;
}
I'm not sure if it does the whole thing or just parts. Anyways, there
is the SqlEditorSharp widget that maybe some use.
Create your text tags. Put it into a TextTagTable. Add the
TextTagTable to your text buffer. Add the text buffer to the text view.
When you want to insert text, use something like InsertWithTags or
ApplyTag.
// widgets
private ScrolledWindow scroll;
private TextView sqlTextView;
private TextBuffer sqlTextBuffer;
private EditorTab tab = null;
// Constructors
public SqlEditorSharp() : base(false, 4) {
scroll = new ScrolledWindow (
new Adjustment (0.0, 0.0, 0.0, 0.0, 0.0,
0.0),
new Adjustment (0.0, 0.0, 0.0, 0.0, 0.0,
0.0));
scroll.HscrollbarPolicy =
Gtk.PolicyType.Automatic;
scroll.VscrollbarPolicy =
Gtk.PolicyType.Automatic;
scroll.ShadowType = Gtk.ShadowType.In;
this.PackStart (scroll, true, true, 0);
// default font famly for SQL editor
family = "courier";
// other default settings
use_hi_lighting = false;
// create text tag table
TextTagTable textTagTable = new TextTagTable ();
// anything else is normaltext
normaltext_tag = new TextTag ("normaltext");
normaltext_tag.Family = family;
normaltext_tag.Foreground = "black";
normaltext_tag.Style = Pango.Style.Normal;
textTagTable.Add (normaltext_tag);
// SQL Keywords - SELECT FROM WHERE, etc
sql_tag = new TextTag ("sql");
sql_tag.Family = family;
sql_tag.Foreground = "blue";
sql_tag.Style = Pango.Style.Normal;
textTagTable.Add (sql_tag);
[...]
// allow it to be edited
sqlTextView.Editable = true;
//line_last_changed = -1;
//last_freecomment_count = -1;
// attach OnTextChanged callback function
// to "changed" signal so we can do something
// when the text has changed in the buffer
sqlTextBuffer.Changed += new EventHandler
(OnTextChanged);
// add the TextView to the ScrolledWindow
scroll.Add (sqlTextView);
}
[...]
sqlTextBuffer.ApplyTag (sql_tag,
begin_iter, end_iter);
The GTK+ 2.0 Documentation serves as a good source of docs too.
http://developer.gnome.org/doc/API/2.0/gtk/TextWidget.html
Also, look at MonoDevelop or gsirc for example of how its done.
-----Original Message-----
From: gtk-sharp-list-admin@lists.ximian.com
[mailto:gtk-sharp-list-admin@lists.ximian.com] On Behalf Of Phil Durand
Sent: Saturday, July 17, 2004 6:56 PM
To: gtk-sharp-list
Subject: [Gtk-sharp-list] TextBuffer and TextTags
Since none of this stuff is documented, and I cant seem to be able to
figure out how to do this, I need to ask for help.
I'm trying to format text within a TextView. Things like bolding,
changing font etc, but for specific areas of the buffer, not for all the
textview.
I've found Buffer.InsertWithTags, which takes the text and the iter to
insert at, as well as a TextTag Array. Now how to insert tags in there
is beyond me, because I dont understand how the TextTag class works (if
this is in fact the tools to use to acomplish my task)
Could someone help me figure out how to insert tags within my text to
add bolding, font and color to parts of text that I insert? thanks for
any help
Phil
_______________________________________________
Gtk-sharp-list maillist - Gtk-sharp-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list