On 1/12/06, Julien Sobrier <[EMAIL PROTECTED]> wrote:
I just have 1 more question: when I try to put a button widget on top of
a text box, th button is actually displayed under the text box. How can
I control which widget is displayed on top of the other(s)?

Do you want to put a Button inside a TextView? If so, you can put arbitrary widgets inside the TextBuffer (e.g. within the text). Attached is a file from a project I have (http://mensagemweb.codigolivre.org.br/ -- only in pt_BR, sorry) that puts Arrow s inside the TextBuffer, besides other things. It may interest you, speacilly the AddItem method.

Thank you
Julien

Cya,
Felipe.

--
"Quem excele em empregar a força militar subjulga os exércitos dos outros
povos sem travar batalha, toma cidades fortificadas dos outros povos sem as
atacar e destrói os estados dos outros povos sem lutas prolongadas. Deve
lutar sob o Céu com o propósito primordial da 'preservação'. Desse modo suas
armas não se embotarão, e os ganhos poderão ser preservados. Essa é a
estratégia para planejar ofensivas."

  -- Sun Tzu, em "A arte da guerra"
/*  Copyright (C) 2005, 2006 Felipe Almeida Lessa
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

using System;
using Gtk;

namespace MensagemWeb.Windows {
	/// <summary>
	/// A customized TextBuffer designed to ease putting titles, subtitles,
	/// items and links on a TextView.
	/// WARNING: The only safe methods to use are the ones created or
	/// overriden on this class, all others may corrupt the state held
	/// on this class.
	/// </summary>
	public class RichTextBuffer : TextBuffer {
		// Persistent (non-anonymous) TextTags
		private TextTag boldTag;
		private TextTag titleTag;
		private TextTag subtitleTag;
		
		// Our TextView
		private TextView tv;
		
		// Our last iter
		private TextIter endIter;
		
		/// <summary>
		/// Creates a RichTextBuffer, a TextView and a ScrolledWindow.
		/// The TextView is non-editable and wrap words by default.
		/// </summary>
		public static Widget NewTextView(out RichTextBuffer buffer, out TextView tv) {
			tv = new TextView();
			buffer = new RichTextBuffer(tv);
			tv.LeftMargin = 4;
			tv.RightMargin = 4;
			tv.CursorVisible = false;
			tv.Editable = false;
			tv.Buffer = buffer;
			tv.WrapMode = WrapMode.WordChar;
			ScrolledWindow sw = new ScrolledWindow();
			sw.ShadowType = ShadowType.In;
			sw.Add(tv);
			return sw;
		}
		
		/// <summary>
		/// Creates a RichTextBuffer, a TextView and a ScrolledWindow.
		/// The TextView is not editable by default.
		/// </summary>
		public static Widget NewTextView(out RichTextBuffer buffer) {
			TextView tv;
			return NewTextView(out buffer, out tv);
		}
		
		/// <summary>
		/// Creates a new RichTextBuffer based on this TextView.
		/// </summary>
		public RichTextBuffer(TextView tv) : base(null) {
			this.tv = tv;
			CreateTextTagTable();
			
			TextIter start;
			this.GetBounds(out start, out endIter);
		}
		
		/// <summary>
		/// Clears this buffer.
		/// </summary>
		public new void Clear() {
			base.Clear();
			
			TextIter start;
			this.GetBounds(out start, out endIter);
		}
		
		/// <summary>
		/// Append text without any special tags to this buffer.
		/// </summary>
		public void AddText(string text) {
			Append(text);
		}
		
		/// <summary>
		/// Append bold text to this buffer.
		/// </summary>
		public void AddBoldText(string text) {
			Append(text, boldTag);
		}
		
		/// <summary>
		/// Append title text to this buffer.
		/// </summary>
		public void AddTitle(string text) {
			Append(text + "\n", titleTag);
		}
		
		/// <summary>
		/// Append subtitle text to this buffer.
		/// </summary>
		public void AddSubtitle(string text) {
			Append(text + "\n", subtitleTag);
		}
		
		/// <summary>
		/// Append an item to this buffer.
		/// </summary>
		public void AddItem(string text) {
			// TODO Do something better
			TextChildAnchor anchor = this.CreateChildAnchor(ref endIter);
			Alignment align = new Alignment(1, 1, 1, 1);
			align.LeftPadding = 10;
			align.RightPadding = 5;
			align.Add(new Arrow(ArrowType.Right, ShadowType.None));
			align.ShowAll(); // XXX Why is this causing warnings on UpdateWindow?
			tv.AddChildAtAnchor(align, anchor);
			Insert(ref endIter, text);
		}
		
		/// <summary>
		/// Append a link to the text that points to a website.
		/// </summary>
		public void AddLink(string text, string link) {
			// TODO Links should have a different cursor
			TextTag linkTag = new TextTag(null);
			linkTag.WrapMode = WrapMode.None;
			linkTag.Foreground = "blue";
			linkTag.Underline = Pango.Underline.Single;
			string link_ = link;
			linkTag.TextEvent += delegate (object o, TextEventArgs args) {
				if (args.Event.Type != Gdk.EventType.ButtonRelease)
					return;
				Util.OpenLink(link_);
			};
			TagTable.Add(linkTag);
			Append(text, linkTag);
		}
		
		/// <summary>
		/// Appends our website to this buffer.
		/// </summary>
		public void AddMensagemWebSite() {
			AddLink("mensagemweb.codigolivre.org.br", "http://mensagemweb.codigolivre.org.br/";);
		}
		
		/// <summary>
		/// Appends some text with some tags to this buffer.
		/// </summary>
		private void Append(string text, params TextTag[] tags) {
			if (tags.Length > 0)
				this.InsertWithTags(ref endIter, text, tags);
			else
				this.Insert(ref endIter, text);
		}
		
		/// <summary>
		/// Creates the persistents (non-anonymous) tags
		/// we're going to use.
		/// </summary>
		private void CreateTextTagTable() {
			titleTag = new TextTag("title");
			titleTag.Justification = Justification.Center;
			titleTag.PixelsBelowLines = 15;
			titleTag.Scale = 1.8;
			titleTag.Weight = Pango.Weight.Bold;
			
			subtitleTag = new TextTag("subtitle");
			subtitleTag.PixelsAboveLines = 15;
			subtitleTag.PixelsBelowLines = 8;
			subtitleTag.Scale = 1.2;
			subtitleTag.Weight = Pango.Weight.Bold;
			
			boldTag = new TextTag("bold");
			boldTag.Weight = Pango.Weight.Bold;
			
			TagTable.Add(boldTag);
			TagTable.Add(titleTag);
			TagTable.Add(subtitleTag);
		}
	}
}
_______________________________________________
Gtk-sharp-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Reply via email to