Re: Gtk object system



Piotr Zgórecki wrote:

I'm trying to understand the Gtk 1.2 object system and one

>

thing seems not quite clear to me.
Can one safely call a virtual method by making a simple

>

public wrapper, that calls directly that method ?


Hi Piotr, sure, I have lots of stubs like this:

gboolean
view_reset( View *view )
{
	ViewClass *klass = VIEW_CLASS( GTK_OBJECT( view )->klass );

	if( klass->reset )
		return( klass->reset( view ) );

	return( TRUE );
}

So view_reset() is a little wrapper that triggers the _reset() method of an instance of View.

This is handy (and quick) for abstract base classes where methods just perform computation (and no one particularly needs to know when it happens).

If the method represents some sort of event (model_changed(), or somesuch) which other objects need to know about, then it's better to do it as a signal so these other classes can hook into it.

This is just for your own classes and methods. If you're calling/triggering one of the gtk classes, you must use the interface that the function expects. If a method expects to be called from a signal, you risk program death if you call it directly.

John







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