1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
/* -*-c-*- -------------- mixgtk_wm.c :
* Implementation of the functions declared in mixgtk_wm.h
* ------------------------------------------------------------------
* Last change: Time-stamp: "2001-06-24 14:36:18 jao"
* ------------------------------------------------------------------
* Copyright (C) 2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include "mixgtk_widgets.h"
#include "mixgtk_config.h"
#include "mixgtk_wm.h"
typedef struct window_info_t_
{
mixgtk_dialog_id_t dialog;
GtkWidget *widget;
GtkCheckMenuItem *menu;
const gchar *menu_name;
const gchar *config_key;
gboolean visible;
const gchar *toolbar_name;
} window_info_t_;
static window_info_t_ infos_[] = {
{MIXGTK_MIXVM_DIALOG, NULL, NULL, "mix_view", "MIX.view", FALSE, NULL},
{MIXGTK_MIXAL_DIALOG, NULL, NULL, "mixal_view", "MIXAL.view", FALSE,
"mixal_toolbar"},
{MIXGTK_DEVICES_DIALOG, NULL, NULL, "devices_view", "Devices.view",
FALSE, "devices_toolbar"}
};
static size_t INF_NO_ = sizeof (infos_) / sizeof (infos_[0]);
static gboolean split_ = FALSE;
static const gchar *TB_MENU_NAME_ = "show_toolbars";
static GtkCheckMenuItem *tb_menu_ = NULL;
static const gchar *VIEW_YES_ = "Yes";
static const gchar *VIEW_NO_ = "No";
/* flag marking that we are inside a restart process */
static gboolean restart_ = FALSE;
gboolean
mixgtk_wm_init (void)
{
split_ = mixgtk_config_is_split ();
if (split_)
{
gint i;
for (i = 0; i < INF_NO_; ++i)
{
const gchar *view = mixgtk_config_get (infos_[i].config_key);
infos_[i].visible = !view || !strcmp (VIEW_YES_, view);
if (!view) mixgtk_config_update (infos_[i].config_key, VIEW_YES_);
infos_[i].widget =
mixgtk_widget_factory_get_dialog (infos_[i].dialog);
g_return_val_if_fail (infos_[i].widget, FALSE);
infos_[i].menu = GTK_CHECK_MENU_ITEM
(mixgtk_widget_factory_get_child_by_name
(MIXGTK_MAIN, infos_[i].menu_name));
g_return_val_if_fail (infos_[i].menu, FALSE);
if (infos_[i].visible) gtk_widget_show (infos_[i].widget);
gtk_check_menu_item_set_active (infos_[i].menu, infos_[i].visible);
}
}
else
{
gint k;
for (k = 0; k < INF_NO_; ++k)
if (infos_[k].widget) gtk_widget_destroy (infos_[k].widget);
}
tb_menu_ = GTK_CHECK_MENU_ITEM
(mixgtk_widget_factory_get_child_by_name (MIXGTK_MAIN,
TB_MENU_NAME_));
g_return_val_if_fail (tb_menu_, FALSE);
gtk_check_menu_item_set_active (tb_menu_, mixgtk_config_show_toolbars ());
mixgtk_wm_show_toolbars (mixgtk_config_show_toolbars ());
return TRUE;
}
void
mixgtk_wm_show_window (mixgtk_window_id_t w)
{
g_return_if_fail (w < INF_NO_);
if (!infos_[w].visible)
{
infos_[w].visible = TRUE;
gtk_check_menu_item_set_active (infos_[w].menu, TRUE);
mixgtk_config_update (infos_[w].config_key, VIEW_YES_);
gtk_widget_show (infos_[w].widget);
}
}
void
mixgtk_wm_hide_window (mixgtk_window_id_t w)
{
g_return_if_fail (w < INF_NO_);
if (infos_[w].visible && !restart_)
{
infos_[w].visible = FALSE;
gtk_check_menu_item_set_active (infos_[w].menu, FALSE);
mixgtk_config_update (infos_[w].config_key, VIEW_NO_);
gtk_widget_hide (infos_[w].widget);
}
}
void
mixgtk_wm_show_toolbars (gboolean show)
{
static const gchar *MAIN_TB_NAME = "main_toolbar";
GtkWidget *toolbar =
mixgtk_widget_factory_get_child_by_name (MIXGTK_MAIN, MAIN_TB_NAME);
if (toolbar != NULL)
{
if (show) gtk_widget_show (toolbar);
else gtk_widget_hide (toolbar);
}
if (split_)
{
int k;
for (k = 0; k < INF_NO_; ++k)
{
if (infos_[k].toolbar_name != NULL)
{
GtkWidget *tb = mixgtk_widget_factory_get_child_by_name
(infos_[k].dialog, infos_[k].toolbar_name);
if (show && tb) gtk_widget_show (tb);
else if (tb) gtk_widget_hide (tb);
}
}
}
mixgtk_config_set_show_toolbars (show);
}
/* callbacks */
void
on_view_toggled (GtkCheckMenuItem *item)
{
if (!restart_)
{
gint k;
for (k = 0; k < INF_NO_; ++k)
if (item == infos_[k].menu) break;
g_return_if_fail (k < INF_NO_);
if (item->active)
mixgtk_wm_show_window (k);
else
mixgtk_wm_hide_window (k);
mixgtk_config_update (infos_[k].config_key,
(item->active)? VIEW_YES_ : VIEW_NO_);
infos_[k].visible = item->active;
}
}
void
on_one_window_activate ()
{
mixgtk_config_set_split (FALSE);
restart_ = TRUE;
gtk_widget_destroy (mixgtk_widget_factory_get_dialog (MIXGTK_MAIN));
}
void
on_split_windows_activate ()
{
mixgtk_config_set_split (TRUE);
restart_ = TRUE;
gtk_widget_destroy (mixgtk_widget_factory_get_dialog (MIXGTK_MAIN));
}
void
on_window_hide (GtkWidget *w)
{
gint k;
for (k = 0; k < INF_NO_; ++k)
if (w == infos_[k].widget) break;
g_return_if_fail (k < INF_NO_);
mixgtk_wm_hide_window (k);
}
void
on_main_window_destroy (GtkWidget *w, gpointer data)
{
if (restart_)
{
mixgtk_restart ();
restart_ = FALSE;
}
else gtk_main_quit ();
}
void
on_show_toolbars_toggled (GtkCheckMenuItem *item)
{
if (!restart_ && item->active != mixgtk_config_show_toolbars ())
mixgtk_wm_show_toolbars (item->active);
}
|