To: rich at annexia.org Cc: lablgtk at kaba.or.jp Subject: Re: Inherit my own widget from another In-Reply-To: <20030704155328.GB28782 at redhat.com> References: <20030704155328.GB28782 at redhat.com> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20030705110338P.garrigue at kurims.kyoto-u.ac.jp> Date: Sat, 05 Jul 2003 11:03:38 +0900 From: Jacques Garrigue Lines: 51 From: Richard Jones > I'm getting a bit lost trying to create my own widget. The widget > I want to create will have a drawing area & a scrollbar, contained > inside a vbox. It seemed a good idea, therefore, to inherit from > the box class. This is as far as I've got: > > open GObj > open GContainer > open GPack > > class graph obj = > object (self) > inherit box obj > val da = GMisc.drawing_area ~packing:self#add () > val drawable = da#misc#realize (); new GDraw.drawable da#misc#window > method test = "test" > end > > let graph ?homogeneous ?spacing ?border_width ?width ?height > ?packing ?show () = > let w = Box.create dir ?homogeneous ?spacing () in > Container.set w ?border_width ?width ?height; > pack_return (new graph w) ~packing ~show > > > There's a couple of problems here, not least the fact that it doesn't > compile (because the initialization of 'da' can't refer to 'self', > although it needs to). Also I'm having to copy in lines of code > directly from gPack.ml, which doesn't help with maintainability. Actually, inheriting to create a meta-widget is a bad idea: your widget is not a box in any useful meaning (you do not expect people to add stuff in it). Inheriting only from Gobj.widget and delegating is much better. class graph ?width ?height ?packing ?show () = let sw = Gbin.scrolled_window ?width ?height ?packing ?show () in let da = GMisc.drawing_area ~packing:sw#add () in object inherit widget sw#as_widget val drawable = lazy (new GDraw.drawable da#misc#window) method sw = sw method da = da method drawable = Lazy.force drawable method test = "test" end You see the idea? Jacques