RE: [gtk-list] Re: Using C++ with Gtk



Thanks for the response.

Yes, Gtk-- looks very useful, and I will probably use that.  I do want to
check out all my options, though.

Regarding callbacks, there's a kludge that works.  You
define callbacks as static member functions which are passed the object
pointer (this) as data.  The static member functions are defined to cast the
data back from void* (gpointer) back to the appropriate type, and call an
appropriate (non-static) member function on the object.  You an create a
nifty template class to automate this.

Of course, it would make no sense to duplicate the entire Gtk widget
hierarchy this way -- you would be re-inventing Gtk--.  Instead, you would
have an application specific gui component hierarchy which happened to be
implemented (hidden mostly in the source files) in Gtk with C-style code.
For example, one could have a gui component hierarchy that looks like this:

View
	BoardView
		TicTacToeBoardView

Notice that this hierarchy bears no relationship to the Gtk hierarchy.  The
View base class could look something like this:

class View {
public:
	void show();
	void hide();

protected:
	GtkWidget* makeWidgetTree(GtkWidget* parent);

private:
	GtkWidget* baseWidget;
};


This approach doesn't appeal to purists, since it's an unholy mixture of C
and C++ coding styles (C++ in the interface, C in the implementation), but
it does have an advantage in that you can deal directly with Gtk without
going through a wrapper, and there's one less library to link in.


-----Original Message-----
From: Tero Pulkkinen [mailto:terop@students.cc.tut.fi]
Sent: Friday, October 16, 1998 2:51 PM
To: gtk-list@redhat.com
Subject: [gtk-list] Re: Using C++ with Gtk


smolitor@insight-tech.com (Stephen Molitor) writes:
> Is anyone out there coding in Gtk (not Gtk--), using C++?  I'm thinking of
> the approach described in the book "Object Oriented Programming with C++
and
> Motif," by Young.  Instead of creating a complete C++ wrapper around
Motif,
> Young describes how to create C++ components that encapsulate large chunks
> of Motif C code and widgets.  For example, one could create a tic-tac-toe
> board component (C++ class) that would encapsulate a bunch of Motif
widgets
> (usually as a single-rooted widget tree).

The only real problem with using C++ with gtk+ is using callbacks.
The problem comes from C++ nonstatic member function cannot be passed
to gtk+'s functions as callbacks. Support for callbacks properly and
support for C++ style inheritance is the main things why gtk-- is
useful.

--
-- Tero Pulkkinen -- terop@modeemi.cs.tut.fi --

--
To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null



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