This source file includes following definitions.
- get_hotkey
- dialog_switch_suspend
- dialog_switch_goto
- dialog_switch_resize
- dialog_switch_add
- dialog_switch_remove
- dialog_switch_num
- dialog_switch_next
- dialog_switch_prev
- dialog_switch_list
- dialog_switch_process_pending
- dialog_switch_got_winch
- dialog_switch_shutdown
- repaint_screen
- mc_refresh
- dialog_change_screen_size
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 #include <config.h>
34
35 #include "lib/global.h"
36 #include "lib/tty/tty.h"
37 #include "lib/tty/color.h"
38 #include "lib/widget.h"
39 #include "lib/event.h"
40
41
42
43 WDialog *filemanager = NULL;
44
45
46
47
48
49
50
51
52 static GList *mc_dialogs = NULL;
53
54 static GList *mc_current = NULL;
55
56 static gboolean dialog_switch_pending = FALSE;
57
58
59
60
61 static unsigned char
62 get_hotkey (int n)
63 {
64 return (n <= 9) ? '0' + n : 'a' + n - 10;
65 }
66
67
68
69 static void
70 dialog_switch_suspend (void *data, void *user_data)
71 {
72 (void) user_data;
73
74 if (data != mc_current->data)
75 widget_set_state (WIDGET (data), WST_SUSPENDED, TRUE);
76 }
77
78
79
80 static void
81 dialog_switch_goto (GList * dlg)
82 {
83 if (mc_current != dlg)
84 {
85 WDialog *old = DIALOG (mc_current->data);
86
87 mc_current = dlg;
88
89 if (old == filemanager)
90 {
91
92 dialog_switch_pending = TRUE;
93 dialog_switch_process_pending ();
94 }
95 else
96 {
97
98 widget_set_state (WIDGET (old), WST_SUSPENDED, TRUE);
99
100 if (DIALOG (dlg->data) != filemanager)
101
102
103 dialog_switch_pending = TRUE;
104 else
105 {
106
107 widget_set_state (WIDGET (filemanager), WST_ACTIVE, TRUE);
108 do_refresh ();
109 }
110 }
111 }
112 }
113
114
115
116 static void
117 dialog_switch_resize (WDialog * d)
118 {
119 if (widget_get_state (WIDGET (d), WST_ACTIVE))
120 send_message (d, NULL, MSG_RESIZE, 0, NULL);
121 else
122 GROUP (d)->winch_pending = TRUE;
123 }
124
125
126
127
128
129 void
130 dialog_switch_add (WDialog * h)
131 {
132 GList *dlg;
133
134 dlg = g_list_find (mc_dialogs, h);
135
136 if (dlg != NULL)
137 mc_current = dlg;
138 else
139 {
140 mc_dialogs = g_list_prepend (mc_dialogs, h);
141 mc_current = mc_dialogs;
142 }
143
144
145 g_list_foreach (mc_dialogs, dialog_switch_suspend, NULL);
146 }
147
148
149
150 void
151 dialog_switch_remove (WDialog * h)
152 {
153 GList *this;
154
155 if (DIALOG (mc_current->data) == h)
156 this = mc_current;
157 else
158 this = g_list_find (mc_dialogs, h);
159
160 mc_dialogs = g_list_delete_link (mc_dialogs, this);
161
162
163 if (top_dlg != NULL)
164 mc_current = g_list_find (mc_dialogs, DIALOG (top_dlg->data));
165 else
166 mc_current = mc_dialogs;
167
168
169 if (mc_current != NULL)
170 widget_set_state (WIDGET (mc_current->data), WST_ACTIVE, TRUE);
171 }
172
173
174
175 size_t
176 dialog_switch_num (void)
177 {
178 return g_list_length (mc_dialogs);
179 }
180
181
182
183 void
184 dialog_switch_next (void)
185 {
186 GList *next;
187
188 if (mc_global.midnight_shutdown || mc_current == NULL)
189 return;
190
191 next = g_list_next (mc_current);
192 if (next == NULL)
193 next = mc_dialogs;
194
195 dialog_switch_goto (next);
196 }
197
198
199
200 void
201 dialog_switch_prev (void)
202 {
203 GList *prev;
204
205 if (mc_global.midnight_shutdown || mc_current == NULL)
206 return;
207
208 prev = g_list_previous (mc_current);
209 if (prev == NULL)
210 prev = g_list_last (mc_dialogs);
211
212 dialog_switch_goto (prev);
213 }
214
215
216
217 void
218 dialog_switch_list (void)
219 {
220 const size_t dlg_num = g_list_length (mc_dialogs);
221 int lines, cols;
222 Listbox *listbox;
223 GList *h, *selected;
224 int i = 0;
225
226 if (mc_global.midnight_shutdown || mc_current == NULL)
227 return;
228
229 lines = MIN ((size_t) (LINES * 2 / 3), dlg_num);
230 cols = COLS * 2 / 3;
231
232 listbox = create_listbox_window (lines, cols, _("Screens"), "[Screen selector]");
233
234 for (h = mc_dialogs; h != NULL; h = g_list_next (h))
235 {
236 WDialog *dlg = DIALOG (h->data);
237 char *title;
238
239 if (dlg->get_title != NULL)
240 title = dlg->get_title (dlg, WIDGET (listbox->list)->rect.cols - 2);
241 else
242 title = g_strdup ("");
243
244 listbox_add_item (listbox->list, LISTBOX_APPEND_BEFORE, get_hotkey (i++), title, h, FALSE);
245
246 g_free (title);
247 }
248
249 selected = run_listbox_with_data (listbox, mc_current);
250 if (selected != NULL)
251 dialog_switch_goto (selected);
252 }
253
254
255
256 int
257 dialog_switch_process_pending (void)
258 {
259 int ret = 0;
260
261 while (dialog_switch_pending)
262 {
263 WDialog *h = DIALOG (mc_current->data);
264 Widget *wh = WIDGET (h);
265
266 dialog_switch_pending = FALSE;
267 widget_set_state (wh, WST_SUSPENDED, TRUE);
268 ret = dlg_run (h);
269 if (widget_get_state (wh, WST_CLOSED))
270 {
271 widget_destroy (wh);
272
273
274 if (mc_global.mc_run_mode == MC_RUN_FULL)
275 {
276 mc_current = g_list_find (mc_dialogs, filemanager);
277 mc_event_raise (MCEVENT_GROUP_FILEMANAGER, "update_panels", NULL);
278 }
279 }
280 }
281
282 repaint_screen ();
283
284 return ret;
285 }
286
287
288
289 void
290 dialog_switch_got_winch (void)
291 {
292 GList *dlg;
293
294 for (dlg = mc_dialogs; dlg != NULL; dlg = g_list_next (dlg))
295 if (dlg != mc_current)
296 GROUP (dlg->data)->winch_pending = TRUE;
297 }
298
299
300
301 void
302 dialog_switch_shutdown (void)
303 {
304 while (mc_dialogs != NULL)
305 {
306 WDialog *dlg = DIALOG (mc_dialogs->data);
307
308 dlg_run (dlg);
309 widget_destroy (WIDGET (dlg));
310 }
311 }
312
313
314
315 void
316 repaint_screen (void)
317 {
318 do_refresh ();
319 tty_refresh ();
320 }
321
322
323
324 void
325 mc_refresh (void)
326 {
327 #ifdef ENABLE_BACKGROUND
328 if (mc_global.we_are_background)
329 return;
330 #endif
331
332 if (!tty_got_winch ())
333 tty_refresh ();
334 else
335 {
336
337
338 dialog_change_screen_size ();
339 }
340 }
341
342
343
344 void
345 dialog_change_screen_size (void)
346 {
347 GList *d;
348
349 tty_flush_winch ();
350 tty_change_screen_size ();
351
352 #ifdef HAVE_SLANG
353 tty_keypad (TRUE);
354 tty_nodelay (FALSE);
355 #endif
356
357
358 dialog_switch_got_winch ();
359
360
361 for (d = g_list_last (top_dlg); d != NULL; d = g_list_previous (d))
362 dialog_switch_resize (DIALOG (d->data));
363
364
365 repaint_screen ();
366 }
367
368