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