So far, gtk2-perl lets you create new GObject types in "pure" Perl code. Some important widget types, however, are not plain GObjects. For example, if you want to create a custom GtkTreeModel or use a GtkTextView as the editor widget in a custom GtkCellRenderer, you need to be able to add a GInterface to the new GObject you've created in Perl, and then of course you'll need to be able to implement the functionality for those new methods. Attached are some patches to attempt to implement this. Basically, a new key/value pair in the arguments for Glib::Type->register_object (which is called by Glib::Object::Subclass) allows you to specify a list of package names under the key "interfaces", like this: use Glib::Object::Subclass Glib::Object::, interfaces => [qw/Gtk2::TreeModel Gtk2::TreeSortable/], ; For each interface type, the Perl-visible method add_interface is called. An equivalent syntax would be: use Glib::Object::Subclass Glib::Object::; Gtk2::TreeModel->add_interface (__PACKAGE__); Gtk2::TreeSortable->add_interface (__PACKAGE__); The add_interface function is responsible for setting up a GInterfaceInfo structure containing the proper function pointers, and actually adding that interface implementation to the target type. The reasoning here is that this completely decouples the infrastructure in Glib from the implementation of each interface's marshallers. The interface is implemented as a set of ALLCAPS functions that will be called on the object implementing the interface. The ALLCAPS convention has been chosen because that's the norm for things called indirectly from within Perl (e.g. TIEHASH or DESTROY). Also, these names will not be defined at runtime, as with GObject signals. The attached patches implement two GInterfaces, with examples: customlist.pl -- a port to Perl of the C example code from Tim-Phillip Muller's Gtk Tree View Tutorial. customrenderer.pl -- this adds the CellEditable interface to a normal TextView, so that the TextView may be used as the editor widget for a CellRendererText. this way, you get a multi-line edit box for multi-line text cells. There are some important problems with the TreeModel implementation -- namely, the semantics of the GtkTreeIter. The TreeIter is designed to be used on the stack, and contains a numeric stamp and tree generic pointers. You get no destruction notification, and thus i have had a devil of a time figuring out how to manage the lifetime of the SV* that i need to store within the GtkTreeIter in order for it to be useful. We do not get the option to override the boxed destroy function, nor do we get to implement a new type. Any ideas here would be greatly appreciated, as the current implementation simply leaks iters at an alarming rate.[*] So, please, try this stuff out, and tell me what you think. All patches are against HEAD of CVS as of 2003-Dec-15 00:10 -0500. Drop the examples into the examples directory to satisfy MANIFEST. [*] from what i can tell, pygtk's GenericTreeModel class also leaks iters like crazy to avoid crashes.
Attachment:
glib-interfaces.patch
Description: Text document
Attachment:
gtk2-interfaces.patch
Description: Text document
Attachment:
customlist.pl
Description: Text Data
Attachment:
customrenderer.pl
Description: Text Data