On Sat, 2006-05-27 at 23:32 +0200, A. Pagaltzis wrote:
> * muppet <[EMAIL PROTECTED]> [2006-05-27 20:30]:
> > Your call to Gtk2::ToggleButton->new_from_stock() is resolving
> > to Gtk2::Button::new_from_stock(), because ToggleButton isa
> > Button, and there is no gtk_toggle_button_new_from_stock().
>
> GObject constructors are not inheritable?
No, because these are not "real" constructors, but just function proxies
for g_object_new().
For instance, gtk_button_new_from_stock() differs from gtk_button_new()
just because it sets the "use-stock" and "use-underline" properties:
return g_object_new (GTK_TYPE_BUTTON,
"label", stock_id,
"use-stock", TRUE,
"use-underline", TRUE,
NULL);
The Perl equivalent would be creating a function called
Gtk2::ToggleButton::new_from_stock() which sets the same properties:
package Gtk2::ToggleButton;
sub new_from_stock
{
my ($class, $stock_id) = @_;
return $class->new(label => $stock_id,
use_stock => TRUE,
use_underline => TRUE);
}
1;
This works because Glib::Object::new() _is_ inheritable in Perl.
The real constructor for a GObject is GObject::constructor, which is the
function in the GObjectClass vtable that actually creates the object;
it's overridden mostly in composite widgets, like the FileChooser, or if
you have come constructor and constructor-only properties that modifies
the behaviour of the object itself. For instance, the FileChooser
creates some widgets depending on the action you want it to perform
(open, save, choose directory); at initialisation time (when
some_object_init() is called in C or when INIT_INSTANCE is called in
Perl) properties are not set, while when GObject::constructor is invoked
the initialisation phase has already been completed and all the
properties passed on by g_object_new() have been set with the passed
values.
Unfortunately, GObject::constructor has no Perl counterpart: you can
control the initialisation of an Glib::Object but you can't control the
creation of the instance itself. I've had a look at the Glib::Object
creation flow, and the changes for supporting a CONSTRUCTOR function are
not trivial (maybe muppet or Torsten have some patch lying around so
I'll be shamed into a corner, though ;-)).
Ciao,
Emmanuele.
--
Emmanuele Bassi - <[EMAIL PROTECTED]>
Log: http://log.emmanuelebassi.net
_______________________________________________
gtk-perl-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list