Re: Proposal: gtk_object to emmit reference changed signals
- From: Per Hedbor <per idonex se>
- To: gtk-devel-list redhat com
- Subject: Re: Proposal: gtk_object to emmit reference changed signals
- Date: 11 Nov 1999 05:00:51 +0100
Pike GTK uses gtk_object_set_data_full, with a free function that
frees the extra reference to the pike object.
Basically:
void my_destroy( struct object *o )
{
GtkObject *go = pgtk_get_gtk_object( o );
if(!go)
return;
pgtk_set_gtk_object( o, NULL );
free_object( o ); /* Free pike object */
}
void pgtk_init_object( struct object *o )
{
GtkObject *go = pgtk_get_gtk_object( o );
if(!go)
fatal("pgtk__init_object called on a non-pgtk object!\n");
ref_object( o ); /* Reference pike object */
gtk_object_set_data_full( go, "pike_object", (void*)o,
(void*)my_destroy );
}
Also, this makes it very easy to get the pike object associated with
the arguments in, as an example, signal functions, which makes it easy
to make your own widgets from pike.
You can inherit, say, GTK.Window in your own class, then redefine some
functions, and add your own code (especially, you often redefine the
constructor), then, when you receive this window object in a signal
call-back, it will be _your_ window object, not a the actual generic
Gtk-Window associated with it.
void pgtk_push_gtkobject_with_default_class(GtkObject *obj,
struct program *def_class)
{
struct object *o;
if(!obj)
{
push_int(0);
return;
}
if( (o=gtk_object_get_data(GTK_OBJECT(obj), "pike_object")) )
{
ref_push_object( o );
return;
}
/* All of this is here to avoid calling the constructor method
* in the class (since that would create a new instance of the
* associated GTK widget, which is not what we want)
*/
o = low_clone( def_class );
call_c_initializers( o );
pgtk_set_gtk_object( o, obj );
pgtk_init_object( o );
ref_push_object( o );
return;
}
I hope some of this helps.
--
Per Hedbor http://per.hedbor.org/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]