[Gtk-sharp-list] Problems having a TreeView inside a ScrolledWindow and using a custom Fixed

Tiago Lima tiago.lima@vianw.pt
Wed, 14 Jan 2004 17:27:38 +0000


--Boundary-00=_KwXBA9sebjGUrUt
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi,

I'am writing a custom "Fixed" just like a vbox (I guess)... but it appears 
I'am forgetting something because the example originates an infinite cycle... 
If i use a VBox instead of MyFixed it works fine. But I dont want to use the 
"same child length" VBox does... (How can i do it with VBox ?)
The problem only appears when I have a TreeView inside a ScrolledWindow... If 
i remove the scrolled window and use the treeview it works fine.
Why ? Could this be a bug?

Thanks in advance,
	Tiago Lima

--Boundary-00=_KwXBA9sebjGUrUt
Content-Type: all/C# File;
  name="Example7.cs"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="Example7.cs"

using System;

using Gtk;
using GtkSharp;

// COMPILE: mcs -r:gtk-sharp.dll -r:glib-sharp.dll -r:gdk-sharp.dll Example7.cs

//
// A simple Bin class: a simple container that adds padding.
//
public class MyFixed : Fixed
{
	static GLib.GType type;

	static MyFixed()
	{
	    //
	    // Register the type on the static constructor, so it is
		// available on the instance constructors
		//
		type = RegisterGType(typeof(MyFixed));
	}

	public MyFixed()
	 : base(type)
	{
		// Participate in size negotiation
		SizeRequested += new SizeRequestedHandler (OnSizeRequested);
		SizeAllocated += new SizeAllocatedHandler (OnSizeAllocated);
	}

	//
	// Invoked to query our size
	//
	void OnSizeRequested(object o, SizeRequestedArgs args)
	{
		for(int i = 0; i < Children.Count; i++)
		{
			int width = args.Requisition.width;
			int height = args.Requisition.height;

			((Widget)Children[i]).GetSizeRequest(out width, out height);

			if (width == -1 || height == -1)
				width = height = 0;

			System.Console.WriteLine("Requesting size: " + width + ", " + height);

			SetSizeRequest(width, height);
		}
	}
	//
	// Invoked to propagate our size
	//
	void OnSizeAllocated(object o, SizeAllocatedArgs args)
	{
		Gdk.Rectangle allocation = args.Allocation;

		int x = allocation.x;
		int width = allocation.width / Children.Count;

		for(int i = 0; i < Children.Count; i++)
		{
			Gdk.Rectangle childAllocation = new Gdk.Rectangle(x, allocation.y, width, allocation.height);
			((Widget)Children[i]).SizeAllocate(childAllocation);
			x += width;
		}
	}
}

public class Y
{
	public static void Main()
	{
		Application.Init();

		Window w = new Window("Hello");
		w.Resize(200, 200);

		ScrolledWindow scrolled = new ScrolledWindow();
		TreeStore _rootStore = new TreeStore(typeof(string));

		TreeView treeView = new Gtk.TreeView(_rootStore);
		scrolled.Add(treeView);

		treeView.HeadersVisible = false;
		treeView.AppendColumn("Nodes", new CellRendererText(), "text", 0);

		_rootStore.AppendValues("a");
		_rootStore.AppendValues("b");
		_rootStore.AppendValues("c");

		MyFixed myfixed = new MyFixed();
		myfixed.Add(scrolled);
		w.Add(myfixed);

		w.ShowAll ();

		Application.Run();
	}
}

--Boundary-00=_KwXBA9sebjGUrUt--