To: lablgtk at kaba.or.jp Subject: reusing button class Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20010104162842A.wakita at is.titech.ac.jp> Date: Thu, 04 Jan 2001 16:28:42 +0900 From: Ken Wakita Lines: 45 I tried to define [image_button] class that contain an icon and an optional label. It was easy to implement a function that make a button with an icon. Then I tried to make a lablgtk style object-oriented class definition and I was in a trouble. Lablgtk style seems to require defining both the class and constructor function. However, initialization code by using low-level interface makes this difficult to do in a handy manner. So I pushed the iniitalization code in the initializer of the class definition and obtained attached below. Something wrong with this implementation? Ken Wakita class button ?label ?border_width ?width ?height ?packing ?show () = let obj = GtkButton.Button.create ?label () in object (self) inherit GButton.button_skel (GtkButton.Button.coerce obj) method connect = new GButton.button_signals obj method event = new GObj.event_ops obj initializer GtkBase.Container.set obj ?border_width ?width ?height; ignore (GObj.pack_return self ?packing ?show) end let button ?label ?border_width ?width ?height ?packing ?show () = new button ?label ?border_width ?width ?height ?packing ?show () class image_button ~file ?(label = "") ?border_width ?width ?height ?packing ?show () = let box = GPack.vbox () in object (self) inherit button ?border_width ?width ?height ?packing ?show () initializer let packing = self#add box#coerce; box#add in GMisc.pixmap (GDraw.pixmap_from_xpm ~window: box ~file ()) ~packing (); ignore (GMisc.label ~text: label ~packing ()) end let image_button ~file ?label ?border_width ?width ?height ?packing ?show () = new image_button ~file ?label ?border_width ?width ?height ?packing ?show ()