[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: bad coding?
- From: Havoc Pennington <rhp zirx pair com>
- To: gtk-app-devel-list redhat com
- Subject: Re: bad coding?
- Date: Thu, 3 Jun 1999 00:36:57 -0400 (EDT)
On Thu, 3 Jun 1999, Richard Tew wrote:
>
> 1) The callback is called with the widget the signal was connected to
> (the button), to close the window I do:
>
> gtk_widget_destroy (GTK_WIDGET (button -> parent -> parent));
>
> (knowing that the button is in a table thats in a window)
> Is there a better way to close the window?
>
Almost certainly - this will break as soon as you change the window
contents.
> 2) Before the window is destroyed/closed, I search through the list of
> widgets contained in the table and as I encounter a entry widget I nick
> its value.
>
> Is there a better way to get the values contained in entry widgets
> somewhere in the same table?
>
This is less fragile but still kind of a hack.
> I know I could just allocate a structure and pass everything I might need
> in callbacks,
This is one answer. Basically your question is how to pass pointers to
your callbacks.
Other options are gtk_object_set_data()/gtk_object_get_data(), global
variables, subclassing a widget and adding fields to it, C++ objects,
and global variables with accessor functions.
by the last I mean:
static Foo foo;
Foo*
myapp_get_the_foo()
{
return &foo;
}
then use the function rather than the variable directly.
I think the decision here is mostly a matter of style, all of them will
work. I'd suggest reading nice Gtk code like Gnumeric and copying it.
You don't have to understand the whole app to get the gist of how it does
this sort of thing.
Havoc
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]