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