Re: [gnomemm] Custom widget: creation function.
- From: Daniel Elstner <daniel elstner gmx net>
- To: newpincho yahoo es
- Cc: gnomemm-list gnome org
- Subject: Re: [gnomemm] Custom widget: creation function.
- Date: Thu, 17 Jun 2004 11:54:08 +0200
Am Mi, den 16.06.2004 um 19:32 Uhr +0200 schrieb Santi:
> I have made e gui with glade. It has a custom widget (clase name visor,
> class Custom and creation function CWidgetPropio).
>
> Where should I put the creation function? in wich class? I have tried
> lots of things (function in the same source file, in the same class that
> the main window, etc). I have also try with:
>
> tkWidget *custom_func(gchar *widget_name, gchar *string1, gchar
> *string2, gint int1, gint int2);
This should do the trick:
extern "C"
GtkWidget *custom_func(gchar *widget_name, gchar *string1, gchar
*string2, gint int1, gint int2);
Basically, you can put this function anywhere you want (except as method
into a class). But note that for extern "C" declarations C++ namespaces
are merely syntactic sugar. Thus it's a good idea to use some prefix,
such as the name of your application. Also be careful not to let any
exceptions escape from the function. The end result should look vaguely
like this:
extern "C"
GtkWidget* regexxer_create_file_tree(char*, char*, char*, int, int)
{
try
{
Gtk::Widget *const widget = new Regexxer::FileTree();
widget->show();
return Gtk::manage(widget)->gobj();
}
catch (...)
{
g_return_val_if_reached(0);
}
}
Note the explicit show() -- libglade seems to have trouble setting the
"visible" property on a widget returned by a custom creation function.
Cheers,
--Daniel
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]