[Gtk-sharp-list] Creating a derivate class from GtkBin.

Miguel de Icaza miguel@ximian.com
14 Jul 2003 21:37:20 -0400


   Today the issue of deriving from GtkBin came out, and I did some
investigation about how to do this.  There are a few issues that came
out that are probably worth discussing.

   A sample is attached.

   The issues:

	* For classes that derive from an abstract C-GObject class, they
	  need to register a new GType and use their parent constructor
	  with the GType argument.

	* To initialize the type, you must do that in a static

	* In the case of Bin derivatives, for the class to do something
	  interesting (just like in C), you must hook up to various
	  events, in the particular case of Bin, you need to hook up
	  to SizeAllocated and set the size of your children (if you
	  want to participate in size negotiation, you should also hook
	  to SizeRequested).

    Basically, the only issue is that we might want to have this
information on the documentation.

using GtkSharp;

class MyBin : Bin {
	static GLib.Type type;
	static MyBin ()
		type = RegisterGType (typeof (MyBin));
	public MyBin () : base (type)
		SizeAllocate (new Gdk.Rectangle (0, 0, 100, 100));

		Added += new AddedHandler (MyAdded);

	void MyAdded (object o, AddedArgs args)
		args.Widget.SizeAllocate (new Gdk.Rectangle (10, 10, 90, 90));

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

		Window w = new Window ("Hello");
		MyBin x = new MyBin ();
		Button b = new Button ("Hola");
		w.Add (x);
		x.Add (b);

		w.ShowAll ();
		Application.Run ();