From: Olivier Andrieu MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <16133.19612.766626.404102 at akasha.ijm.jussieu.fr> Date: Fri, 4 Jul 2003 11:45:00 +0200 To: lablgtk at kaba.or.jp Cc: Richard Jones Subject: Re: containers & subclasses of widgets In-Reply-To: <20030703144931.GA29657 at clipper.ens.fr> References: <20030703144222.GA15588 at redhat.com> <20030703144931.GA29657@clipper.ens.fr> Nicolas George [Thursday 3 July 2003] : > > Le quintidi 15 messidor, an CCXI, Richard Jones a écrit : > > I guess this comes down to the strange type system used by LablGtk. > > No, it has to do with static typing. The children of a container > are widgets, nothing more: they could be labels, input boxes, > images, anything. The static type system of Caml has no way to know > that they will be vboxes. > > You could use the dynamic type checking facilities of Gtk+ to > refine the widget into a vbox, but I believe this is a bad > style. If you need to do something to some widget, do not rely on > accessing it through its parents: store it in a variable with a > relevant name. This way you will have reliable static typing, and > your code will not break if you change the layout of your widgets. Another way is to use the memo class from GUtil module. It type is : ,---- | class ['a] memo : unit -> | object | constraint 'a = #widget | val tbl : (int, 'a) Hashtbl.t | method add : 'a -> unit | method find : widget -> 'a | method remove : widget -> unit | end `---- In your case, since all widgets in your table are vbox, you only need one memo object. Simply do a memo#add on your vbox before puting them in the table. Them you can do List.map memo#find table#children to get your vbox back. -- Olivier