Re: [gtk-list] Datalists in GtkTypes




Dominic Ludlam <dom@recoil.org> writes:
> 
> I would like to be able to associate arbitrary data
> with GtkTypes for the equivalent of static data members
> in C++ classes.  There is a nice system for adding data
> to GtkObjects, but not to the underlying types. Is there
> any exisiting way of doing this?
> 

You can just use g_dataset_* to associate data with any pointer
whatsoever (get the class struct with gtk_type_class()).

Concretely, something like:

void 
gtk_type_set_data (GtkType type, const gchar * key, gpointer data)
{
  gpointer klass = gtk_type_class (type);

  g_dataset_id_set_data_full (klass,
                              g_quark_from_string (key),
                              data, NULL);

}

gpointer 
gtk_type_get_data (GtkType type, const gchar * key)
{
  return g_dataset_id_get_data (gtk_type_class (type), 
                                g_quark_from_string (key));
}

Or something like that, perhaps the implementation needs refinement.

However if you're implementing your own GtkObject subclass, typically
you can just use fields in the class struct of static variables in the
.c file, which is more efficient and also typesafe.

Havoc





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