GUI programming vs encapsulation



Hello list,

as my Glade/GTK project is growing larger, I find myself confronted with code organization issues. I have all my callbacks in a single file, but of course there are groups of related widgets that logically go together (say, the widgets inside a top-level dialog window). Also the widgets of one dialog only need to know about each other, but not about widgets in other windows.

The issue is how to separate these things logically other than just splitting up the source code in comment-separated chunks.

1. Separate source files for each dialog.
-> unpractical because this is a single Glade project, and Glade only writes single source files.

2. Storing information about widgets (i.e., pointers to widgets) inside the parent top-level widget using the G_OBJECT methods (g_object_set_data() and friends), and finding the widget with the lookup_widget() funcion supplied with Glade -> I somehow don't like it. I like mean, lean, and fast programs, and the mere thought that each push of a button or movement of a slider generates an avalanche of hash lookups gives me ulcers, and it litters the code with "magic" lookup key strings.

3. For each widget, declare a global pointer variable, a "create" and a "delete" callback. In the create callback I set the global variable to the pointer to the widget, and in the delete callback I set the global variable to NULL so that other parts of the program know that this widget doesn't exist any more. -> No encapsulation and more callbacks just to set/unset global variables.

Currently I'm using a mixture of 2. and 3. (depending on how I feel that day), but leaning towards 3. without much passion.

So how do you guys deal with this problem? I guess there is no real way out of having all the callbacks spread out in this "flat" fashion because from the C program's point of view there's no telling in what order they might be called. Is writing unwieldy spaghetti code a necessary part of GUI programming, or have I missed some important point?

Thanks,
--Daniel



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