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




On 16 Oct 1998, Tero Pulkkinen wrote:
> 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.
> 

And fast, typesafe signals. I guess that's part of callback support.
I use them for all sorts of non-GUI stuff; they're quite handy.

The main disadvantage of Gtk-- in my mind is compile time, and version
sync problems, where Gtk changes and Gtk-- does not, etc. You could avoid
most of that by using stable Gtk instead of 1.1.

With Gtk+, you can trivially create composite objects on the fly; just
write a function like:

GtkWidget* make_my_cool_dialog()
{
 GtkWidget* retval = gtk_dialog_new();
 // put stuff in the dialog
 // return the dialog
}

Of course, you probably want to do it as an object, so you can access
parts of the dialog. So:

class MyCoolDialog {

 GtkWidget* dialog();
 GtkEntry*  field_one();
 GtkMenu*   menu();

private:
  GtkWidget* dialog_;
  GtkMenu* menu_;
  GtkEntry* field_one_;
};

MyCoolDialog::MyCoolDialog()
{
 dialog_ = gtk_dialog_new();

 field_one_ = GTK_ENTRY(gtk_entry_new());

 gtk_box_pack_start(dialog->vbox, field_one_, true, true, 0);
}

It's not clear to me that this is any better than:

struct MyCoolDialog {
 GtkWidget* dialog;
 GtkEntry* field_one;
};

But the class lets you put more intelligence in there, like all the
handling for the various signals, so you could have methods like
get_entry_contents().

You are going to have to have static proxy callbacks which invoke methods
on your class, as Tero mentioned. This is all yucky. Gtk is also very bad
about not using const when it should, so you will occasionally get all
kinds of stupid warnings about passing const objects in to gpointers or
static strings in to char*.

Havoc




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