Date: Wed, 26 Jan 2005 16:11:37 +0900 (JST) Message-Id: <20050126.161137.39155935.garrigue at math.nagoya-u.ac.jp> To: robertr at rftp.com Cc: lablgtk at kaba.or.jp Subject: Re: writing your own widgets From: Jacques Garrigue In-Reply-To: <41F72663.5000602 at rftp.com> References: <41F6CB4C.8090509 at rftp.com> <20050126.131155.115913197.garrigue@math.nagoya-u.ac.jp> <41F72663.5000602@rftp.com> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit From: Robert Roessler > What I am after is probably more of a companion to Chapter 21 from the > original [gtk.org] tutorial... what is required (both in LablGTK and > C) to WRAP a already-functioning GTK+ widget? > > To cut to the chase (and hopefully make it easier to answer the > "right" question), I want to build a LablGTK wrapper for the Scintilla > edit control, which is already buildable as a GTK widget - and yes, I > am aware of the Sci-Lab project, but I would like to make something a > bit more minimalistic - and/or actually understand *why* all of those > classes and modules are present/needed to wrap an existing widget. Maybe a simple example is to look at ml_gtkbroken.c/gtkBroken.props/gtkBroken.ml/gBroken.ml in the lablgtk2 sources. I choose this file just because it interfaces only a small number of widgets (deprecated ones, but this is not relevant here). You have better concentrate on the Text widget there. Why so many files? They each have their role. ml_gtbroken.c contains the C wrappers for widget methods. It uses macros defined in wrappers.h to simplify the writing. gtkBroken.props contains widget properties and signals, as they are given in the Gtk reference manual. It is used to generate two files, using propcc: gtkBrokenProps.ml and ogtkBrokenProps.ml. gtkBroken.ml is the low level interface. It imports definitions from gtkBrokenProps.ml, and adds a few definitions that have to be written by hand. (In theory it is superfluous, but it is kept for flexibility.) gBroken.ml is the object-oriented interface. Each widget is wrapped using two classes: the widget class, which contains methods and properties, and the widget_signals class which contains signals. The constructor for the widget is defined as a function with optional arguments, Again, some definitions are imported from ogtkBroken.ml, by inheriting from the (partial) classes defined there. Additionally, if you need to use some C enumerations, you should use varcc to generate all the needed conversion functions and headers. As the Makefile rule says, it turns a xxx.var file into xxx.h, xxx.c, and yyyEnums.ml (if xxx.var contains `package "yyy"'). The trouble of course is that there is no documentation whatsoever about how you're supposed to write all of these. But taking the original sources as model should be informative enough in practice. If there is something you don't understand, let me know. Jacques