Re: [gtk-list] Re: C++ and Gtk
- From: Brian Stempel <stempel oneimage com>
- To: gtk-list redhat com
- cc: nathan lanfear st hmc edu
- Subject: Re: [gtk-list] Re: C++ and Gtk
- Date: Wed, 27 May 1998 08:16:38 -0600 (MDT)
> > only real minus (which IMHO isn't really that big of a deal) is the small
> > amount of casting to get from a generic callback pointer to, say, your
> > object instance. To be honest, I haven't done that much with gtk, but I
> > have done
> Could you give an example of how you might actually go about doing this?
> I've got a lot of C++ code that I want to keep and I'd also like to keep
> using the straight gtk+ API.
So, for instance, the code might look like:
class MyObject
{
// Class declarations...
void myMethod ();
void myOtherMethod ();
static void signalHandler(GtkWidget *widget, MyObject *data);
}
void MyObject::myMethod()
{
gtk_signal_connect(GTK_OBJECT(someWidget), "someSignal",
GTK_SIGNAL_FUNC(signalHandler), this);
}
void MyObject::signalHandler(GtkWidget *, MyObject *data)
{
MyObject &myObject = *data;
myObject.myOtherMethod();
}
The idea is that you receive the signal data as a pointer-to-instance,
and then make a reference from that. You could just as easily receive
the data as a pointer-to-instance, and then just use the -> operator,
rather than the . operator, but I prefer the above syntax, and I *believe*
it's slightly more efficient that way.
BTW, the code above is derived from the method using Motif, and not tested,
so hopefully I didn't make any silly mistakes.
Brian
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]