Re: [gtk-list] gtk_foo_new() vs. gtk_foo_init()




Derek Simkowiak <dereks@kd-dev.com> writes:
> 	When creating a new object, what kind of initialization should
> take place in _new(), and what kind of initialization should take place in
> _init()?
>

init should create a valid object. _new() can do convenience things
based on the arguments to new().
 
> 	I was under the impression that the _new() function should do
> nothing more than 
> 
> GtkFoo*
> gtk_foo_new (void)
> {
>   return GTK_FOO (gtk_type_new (gtk_foo_get_type ()));
> }
> 

If _new() takes no arguments, this is always correct.
 
> 	But then I looked at (an admittedly old copy of) Havoc's
> FrootTkxtBuffer source.  He does all of his initialization in _new(), and
> his _init() is blank.
>

The newer copies partially fix this, and there's a comment in there
about how to fully fix it.

> Is the _init() reserved for X resources (GdkFonts/GdkWindows etc.) or some
> such thing?
>

X resources should be created in _realize().
 
> 	Is the _init() function even called on GtkObjects which are not
> widgets?  (Obviously, I assumed that they were.)
> 

Yes.

Havoc



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