From f98b4e6398985ecf095593d34370d777e478c75e Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Tue, 15 Jul 2003 02:34:04 +0000 Subject: [PATCH] Add example, and more explanations svn path=/trunk/gtk-sharp/; revision=16247 --- doc/en/Gtk/Bin.xml | 151 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 136 insertions(+), 15 deletions(-) diff --git a/doc/en/Gtk/Bin.xml b/doc/en/Gtk/Bin.xml index 48fd794d2..9062e8a3a 100644 --- a/doc/en/Gtk/Bin.xml +++ b/doc/en/Gtk/Bin.xml @@ -1,5 +1,6 @@ - + gtk-sharp 0.0.0.0 @@ -9,9 +10,140 @@ A container with just one child. - A Bin widget is a with just one child. It is used to create subclasses, since it provides common code needed for handling a single child . - Many GTK+ widgets are subclasses of Bin, including , , , , and . - To place a child widget inside this container, use the standard method. + + + A Bin widget is a with just one + child. It is used to create subclasses, since it provides + common code needed for handling a single child . + + + + Many GTK+ widgets are subclasses of Bin, including , , , , and + . + + + To place a child widget inside this container, use the + standard method. + + + For the widget to be useful, it should participate in size + negotiation and size allocation using the events and . + + + Since Gtk.Bin is an abstract class in C, it is necessary to + register a Type. Sample follows. + + + +using System; +using Gtk; +using GtkSharp; + +// +// A simple Bin class: a simple container that adds padding. +// +class MyPadder : Bin { + int pad = 50; + static GLib.Type type; + Widget child; + + static MyPadder () + { + // + // Register the type on the static constructor, so it is + // available on the instance constructors + // + type = RegisterGType (typeof (MyPadder)); + } + + public MyPadder () : base (type) + { + // To track our child widget. + Added += new AddedHandler (MyAdded); + + // Participate in size negotiation + SizeRequested += new SizeRequestedHandler (OnSizeRequested); + SizeAllocated += new SizeAllocatedHandler (OnSizeAllocated); + } + + // + // Invoked to query our size + // + void OnSizeRequested (object o, SizeRequestedArgs args) + { + if (child != null){ + int width = args.Requisition.width; + int height = args.Requisition.height; + + child.GetSizeRequest (out width, out height); + if (width == -1 || height == -1) + width = height = 80; + SetSizeRequest (width + pad * 2, height + pad * 2); + } + + } + + // + // Invoked to propagate our size + // + void OnSizeAllocated (object o, SizeAllocatedArgs args) + { + if (child != null){ + Gdk.Rectangle mine = args.Allocation; + Gdk.Rectangle his = mine; + + his.x += pad; + his.y += pad; + his.width -= pad * 2; + his.height -= pad * 2; + child.SizeAllocate (his); + } + } + + // + // Public property of the Padding widget + // + public int Pad { + get { + return pad; + } + + set { + pad = value; + QueueResize (); + } + } + + void MyAdded (object o, AddedArgs args) + { + child = args.Widget; + } +} + +class Y { + static void Main () + { + Application.Init (); + + Window w = new Window ("Hello"); + MyPadder x = new MyPadder (); + x.Pad = 100; + Button b = new Button ("Hola"); + w.Add (x); + x.Add (b); + + w.ShowAll (); + + Application.Run (); + } +} + + @@ -61,17 +193,6 @@ - - - Constructor - - - - Internal constructor - - - - Property