Re: [gtk-list] Can Widgets point to free-form data?




On Sat, 14 Aug 1999, John C Atkeson wrote:
>   
>   Can an instance of a widget carry around (a pointer to) a chunk 
> of free-form, user-defined data, in its "pocket"?  
>   

Sure, just:
 
  gtk_object_set_data(GTK_OBJECT(widget), "mydata", mypointer);

and then:

  gpointer mypointer = gtk_object_get_data(GTK_OBJECT(widget), "mydata");

Also convenient is:

 void 
 mydata_destroy(gpointer mydata)
 {
   /* do stuff to free mydata objet */
 }

 gtk_object_set_data_full(GTK_OBJECT(widget), "mydata", mypointer,
                          (GtkDestroyNotify)mydata_destroy);

Then when you set the "mydata" key to some other value, remove the
"mydata" key, or destroy the widget, mydata_destroy will be called on
mypointer.

Havoc




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