Re: [gtk-list] Re: GTK questions



On Tue, 20 Jul 1999, Havoc Pennington wrote:

> 
> On Tue, 20 Jul 1999, David Orme wrote:
> > 1) How do you add a *new* signal to an object at runtime?
> 
> (All signals are added at runtime - I assume you mean "after the class
> initialization function.") It looks like you can do it the same way you
> add signals in the class init function, but I doubt this particular code
> path is well-tested so it might not work too well. I'm not sure if it's
> officially supported or not.

signal creation is indeed well tested ;)
but gtk_signal_new() and gtk_object_class_add_signals() should indeed not
be called from outside an object implementation. however, we do support
user defined signals (i.e. signals introduced by an object user and not
the object implementation), and the API call for that was IMHO not that
unobvious ;)

guint   gtk_object_class_user_signal_new  (GtkObjectClass     *klass,
                                           const gchar        *name,
                                           GtkSignalRunType    signal_flags,
                                           GtkSignalMarshaller marshaller,
                                           GtkType             return_val,
                                           guint               nparams,
                                           ...);

to give a fishy example:

static guint signal_id = 0;

signal_id = gtk_object_class_user_signal_new (gtk_type_class (GTK_TYPE_BUTTON),
                                              "blub",
                                              GTK_RUN_ACTION,
                                              gtk_signal_default_marshaller,
                                              GTK_TYPE_NONE /* `void' return.*/ ,
                                              0 /* No extra arguments */);

then you create a button and do:

gtk_signal_connect (GTK_OBJECT (button),
                    "blub",
                    GTK_SIGNAL_FUNC (printf),
                    "blub\n");
gtk_signal_emit_by_name (GTK_OBJECT (button), "blub");
gtk_signal_emit (GTK_OBJECT (button), signal_id);

this will give you:

blub
blub


> > 2) Is there a way you can enumerate the signals that a GTK+ object
> > supports at runtime?
> > 
> 
> I guess you could get the signals from object->klass->signals (and
> object->klass->nsignals) then gtk_signal_query() each one...
> maybe there's a better way.

nope, that's the preferred way. however, take care to never store pointers
into the object->klass->signals array, because the signal id array is
actually relocatable data.

> 
> Havoc
> 

---
ciaoTJ



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