Re: [gtk-list] Re: Gtk--: (resend) recent changes with GTK_OBJECT _CONSTRUCTED ??

On 17 Mar 1999, Tero Pulkkinen wrote:

> timj wrote:
> > since calling gtk_object_default_construct() is mandatory after
> > gtk_type_new().  (for objects that don't require default
> > construction, the call is actually pretty cheap).
> hmmm, gtk_object_default_construct() is mandatory? Does it matter
> where you call it? Should one call it immediately after gtk_type_new()?

well, gtk objects should be constructed as soon as possible, so you best
call gtk_object_default_construct() at the end of the c++ constructor, or
you just use gtk_object_new() in the beginning. the object argument system
should be comprehensive enough (by now) to cover all neccessary construction
arguments required by the different widgets, so there is actually no real need
to use gtk_type_new().
if you for some reason need to defer completion of the construction, you
should at least make sure that objects are fully constructed when you
- add them to a parent,
- realize them (usually this only happens when the widget already has a parent)
- destroy them.

certain functions that the object (widget) API introduces may also require
the object to be fully constructed.

> What happens if you accidentally call it twice? :) (placing call to it to
> Gtk_Object's constructor will sometimes call it for already constructed
> object => doesnt sound too nice --> maybe we must place call to it near
> each gtk_type_new() - and thus it needs changes to every gtk-- widget...)

gtk_object_default_construct() only assures that an object is constructed,
and if that's not the case, it'll provide default values for an obejct's
construction arguments, thus it's internals are simply:

gtk_object_default_construct (GtkObject *object)
  g_return_if_fail (object != NULL);
  g_return_if_fail (GTK_IS_OBJECT (object));

      /* do magic default initialization with NULL, 0 or 0.0 arguments here

      if (!GTK_OBJECT_CONSTRUCTED (object))
        gtk_object_constructed (object);

gtk_object_constructed() is an internal function and mainly assures that
the GTK_CONSTRUCTED flag is set on the object, gtk_<SOME-WIDGET>_construct()
functions call it at their end.

thus you can savely call gtk_object_default_construct() as many times as you
want, or even conditionalize its invokation like:

    gtk_object_default_construct (object);

but as i said before, the preferred way to create an object/widget is calling
gtk_object_new() or gtk_widget_new() and simply pass any construction arguments
to those functions, they'll automatically default construct object's at their

> -- 
> -- Tero Pulkkinen -- --


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]