[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Keeping Track of More Than One Window in an App
- From: Sean Nichols <SeanNi Attachmate com>
- To: "'GtkList'" <gtk-app-devel-list redhat com>
- Subject: Keeping Track of More Than One Window in an App
- Date: Wed, 23 Jun 1999 17:24:43 -0700
Greetings.
I tend to be a bit long-winded, so excuse me if this takes a while.
I have an app that I'm developing that consists of a number of windows
spun off a main window (which contains little more than a menubar and
toolbar). Unfortunately, I am having a bit of trouble getting the various
windows to talk to one another. As an example of what I'm talking about,
consider the following situation, which is one of the ones I've run up
against.
The "main" window has a menu with a bunch of checkbox-type menu options
below it, that turn some of the subwindows on and off. For example:
|-------------------------------------------------------------|
|_| Main Window |X|
|-------------------------------------------------------------|
|| File Edit |View | Help |
|---------------------------| |---------------------|
| | Subwin1 | |
|---------------------------| # Subwin2 |---------------------|
| Subwin3 |
|-----------|
And then 3 subwindows, that can be toggled on and off (using
gtk_widget_show(); / gtk_widget_hide();) via the View menu.
My problem is actually getting *at* the GtkWidget*s representing the 3
submenus (to use in the gtk_widget_x(); calls), since those GtkWidget*s are
local to the procedures that call them.
What I've resorted to, is building up a hierarchy of structs, like so:
<CODE>
deftype struct {
GtkWidget *window;
GtkWidget *menubar;
GtkWidget *menuitem;
GtkWidget *submenu;
GtkWidget *submenuitem;
-
-
-
GtkLabel *label;
} t_mainwin;
deftype struct {
GtkWidget *window;
-
-
-
GtkLabel *label;
} t_subwin1;
-
-
-
</CODE>
and then a "base" struct:
<CODE>
deftype struct {
t_mainwin mainwin;
t_subwin1 subwin1;
t_subwin2 subwin2;
t_subwin3 subwin3;
} t_windowbase;
</CODE>
of which I create a global instance:
<CODE>
t_windowbase gwindowbase;
</CODE>
which I can call from anywhere.
This means that in the callback to the menu above, for example, I can grab
the menu from the (global)base structure, and work my way down:
<CODE>
void win2_activate_callback( GtkWidget *togbutton, gpointer pData ) {
if (GTK_TOGGLE_BUTTON( togbutton )->active) {
gtk_widget_show( gwindowbase->subwin2->window );
} else {
gtk_widget_hide( gwindowbase->subwin2->window );
}
}
</CODE>
This works, except that it is simply wrong.
I tend to think that having so much stuff accessible globally is a Bad Thing
(TM). Anyone have any experience with this sort of thing/any way around it?
Thanks,
- Sean
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]