- Rearrange reactos.dff according to rosapps rearrange.
[reactos.git] / rosapps / mc / src / layout.c
1 /* Panel layout module for the Midnight Commander
2 Copyright (C) 1995 the Free Software Foundation
3
4 Written: 1995 Janne Kukonlehto
5 1995 Miguel de Icaza
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include <config.h>
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <sys/param.h> /* Required by tree.h */
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #if (!defined(__IBMC__) && !defined(__IBMCPP__)) && !defined(OS2_NT)
31 # include <termios.h>
32 /*
33 * If TIOCGWINSZ supported, make it available here, because window-
34 * resizing code depends on it...
35 */
36 # ifdef __QNX__ /* Maybe not only QNX-specific... */
37 # include <sys/ioctl.h>
38 # endif
39 #endif
40 #ifdef HAVE_UNISTD_H
41 # include <unistd.h>
42 #endif
43 #include <signal.h>
44 #include "tty.h"
45 #include "mad.h"
46 #include "util.h" /* Needed for the externs */
47 #include "win.h"
48 #include "color.h"
49 #include "key.h"
50
51 #include "dlg.h"
52 #include "widget.h"
53 #include "command.h"
54
55 #include "dialog.h" /* For do_refresh() */
56 #include "profile.h" /* For sync_profiles() */
57 #include "mouse.h"
58 #define WANT_WIDGETS
59 #include "main.h"
60 #include "subshell.h" /* For use_subshell and resize_subshell() */
61 #include "tree.h"
62 #include "menu.h"
63
64 /* Needed for the extern declarations of integer parameters */
65 #include "dir.h"
66 #include "panel.h" /* The Panel widget */
67 #include "file.h"
68 #include "cons.saver.h"
69 #include "layout.h"
70 #include "info.h" /* The Info widget */
71 #include "view.h" /* The view widget */
72
73 #define WANT_DEFAULTS
74 #include "setup.h" /* For save_setup() */
75
76 #include "x.h"
77
78 /* "$Id$" */
79
80 /* Controls the display of the rotating dash on the verbose mode */
81 int nice_rotating_dash = 1;
82
83 /* If set, then we have to call the layout_change routine from main */
84 int layout_do_change = 0;
85
86 /* Set if the panels are split horizontally */
87 int horizontal_split = 0;
88
89 /* Set if the window has changed it's size */
90 int winch_flag = 0;
91
92 /* Set if the split is the same */
93 int equal_split = 1;
94
95 /* First panel size if the panel are not split equally */
96 int first_panel_size = 0;
97
98 /* The number of output lines shown (if available) */
99 int output_lines = 0;
100
101 /* Set if the command prompt is to be displayed */
102 int command_prompt = 1;
103
104 /* Set if the nice and usefull keybar is visible */
105 int keybar_visible = 1;
106
107 /* Set if the nice message (hint) bar is visible */
108 int message_visible = 1;
109
110 /* Set if you want the message bar shown in xterm title bar to save space */
111 int xterm_hintbar = 0;
112
113 /* The starting line for the output of the subprogram */
114 int output_start_y = 0;
115
116 /* The maximum number of views managed by the set_display_type routine */
117 /* Must be at least two (for current and other). Please note that until */
118 /* Janne gets around this, we will only manage two of them :-) */
119 #define MAX_VIEWS 2
120
121 struct {
122 int type;
123 Widget *widget;
124 } panels [MAX_VIEWS];
125
126 /* These variables are used to avoid updating the information unless */
127 /* we need it */
128 static int old_first_panel_size;
129 static int old_horizontal_split;
130 static int old_output_lines;
131
132 /* Internal variables */
133 static int _horizontal_split;
134 static int _equal_split;
135 static int _first_panel_size;
136 static int _menubar_visible;
137 static int _output_lines;
138 static int _command_prompt;
139 static int _keybar_visible;
140 static int _message_visible;
141 static int _xterm_hintbar;
142 static int _permission_mode;
143 static int _filetype_mode;
144
145 static int height;
146
147 #define MINWIDTH 10
148 #define MINHEIGHT 5
149
150 #define BY 12
151
152 #define B_2LEFT B_USER
153 #define B_2RIGHT B_USER + 1
154 #define B_PLUS B_USER + 2
155 #define B_MINUS B_USER + 3
156
157 static Dlg_head *layout_dlg;
158
159 static char *s_split_direction [2] = {
160 N_("&Vertical"),
161 N_("&Horizontal")
162 };
163 WRadio *radio_widget;
164
165 static struct {
166 char *text;
167 int *variable;
168 WCheck *widget;
169 char *tkname;
170 } check_options [] = {
171 { N_("&Xterm hintbar"), &xterm_hintbar, 0, "h" },
172 { N_("h&Intbar visible"), &message_visible, 0, "v" },
173 { N_("&Keybar visible"), &keybar_visible, 0, "k" },
174 { N_("command &Prompt"), &command_prompt, 0, "p" },
175 { N_("show &Mini status"), &show_mini_info, 0, "m" },
176 { N_("menu&Bar visible"), &menubar_visible, 0, "me" },
177 { N_("&Equal split"), &equal_split, 0, "eq" },
178 { N_("pe&Rmissions"), &permission_mode, 0, "pr" },
179 { N_("&File types"), &filetype_mode, 0, "ft" },
180 { 0, 0, 0, 0 }
181 };
182
183 static int first_width, second_width;
184 static char *layout_title, *title1, *title2, *title3, *output_lines_label;
185
186 static WButton *bleft_widget, *bright_widget;
187
188 static void _check_split (void)
189 {
190 if (_horizontal_split){
191 if (_equal_split)
192 _first_panel_size = height / 2;
193 else if (_first_panel_size < MINHEIGHT)
194 _first_panel_size = MINHEIGHT;
195 else if (_first_panel_size > height - MINHEIGHT)
196 _first_panel_size = height - MINHEIGHT;
197 } else {
198 if (_equal_split)
199 _first_panel_size = COLS / 2;
200 else if (_first_panel_size < MINWIDTH)
201 _first_panel_size = MINWIDTH;
202 else if (_first_panel_size > COLS - MINWIDTH)
203 _first_panel_size = COLS - MINWIDTH;
204 }
205 }
206
207 static void update_split (void)
208 {
209 /* Check split has to be done before testing if it changed, since
210 it can change due to calling _check_split() as well*/
211 _check_split ();
212
213 /* To avoid setting the cursor to the wrong place */
214 if ((old_first_panel_size == _first_panel_size) &&
215 (old_horizontal_split == _horizontal_split)){
216 return;
217 }
218
219 old_first_panel_size = _first_panel_size;
220 old_horizontal_split = _horizontal_split;
221
222 attrset (COLOR_NORMAL);
223 dlg_move (layout_dlg, 6, 6);
224 printw ("%03d", _first_panel_size);
225 dlg_move (layout_dlg, 6, 18);
226 if (_horizontal_split)
227 printw ("%03d", height - _first_panel_size);
228 else
229 printw ("%03d", COLS - _first_panel_size);
230 }
231
232 static int b2left_cback (int action, void *data)
233 {
234 if (_equal_split){
235 /* Turn equal split off */
236 _equal_split = 0;
237 check_options [6].widget->state = check_options [6].widget->state & ~C_BOOL;
238 dlg_select_widget (layout_dlg, check_options [6].widget);
239 dlg_select_widget (layout_dlg, bleft_widget);
240 }
241 _first_panel_size++;
242 return 0;
243 }
244
245 static int b2right_cback (int action, void *data)
246 {
247 if (_equal_split){
248 /* Turn equal split off */
249 _equal_split = 0;
250 check_options [6].widget->state = check_options [6].widget->state & ~C_BOOL;
251 dlg_select_widget (layout_dlg, check_options [6].widget);
252 dlg_select_widget (layout_dlg, bright_widget);
253 }
254 _first_panel_size--;
255 return 0;
256 }
257
258 static int bplus_cback (int action, void *data)
259 {
260 if (_output_lines < 99)
261 _output_lines++;
262 return 0;
263 }
264
265 static int bminus_cback (int action, void *data)
266 {
267 if (_output_lines > 0)
268 _output_lines--;
269 return 0;
270 }
271
272 static int layout_callback (struct Dlg_head *h, int Id, int Msg)
273 {
274 switch (Msg){
275 case DLG_DRAW:
276 #ifndef HAVE_X
277 /*When repainting the whole dialog (e.g. with C-l) we have to
278 update everything*/
279 old_first_panel_size = -1;
280 old_horizontal_split = -1;
281 old_output_lines = -1;
282 attrset (COLOR_NORMAL);
283 dlg_erase (h);
284 draw_box (h, 1, 2, h->lines - 2, h->cols - 4);
285 draw_box (h, 2, 4, 6, first_width);
286 draw_box (h, 8, 4, 4, first_width);
287 draw_box (h, 2, 5 + first_width, 10, second_width);
288
289 attrset (COLOR_HOT_NORMAL);
290 dlg_move (h, 1, (h->cols - strlen(layout_title))/2);
291 addstr (layout_title);
292 dlg_move (h, 2, 5);
293 addstr (title1);
294 dlg_move (h, 8, 5);
295 addstr (title2);
296 dlg_move (h, 2, 6 + first_width);
297 addstr (title3);
298 update_split ();
299 dlg_move (h, 6, 13);
300 addch ('=');
301 if (console_flag){
302 if (old_output_lines != _output_lines){
303 old_output_lines = _output_lines;
304 attrset (COLOR_NORMAL);
305 dlg_move (h, 9, 16 + first_width);
306 addstr (output_lines_label);
307 dlg_move (h, 9, 10 + first_width);
308 printw ("%02d", _output_lines);
309 }
310 }
311 #endif
312 break;
313
314 case DLG_POST_KEY:
315 _filetype_mode = check_options [8].widget->state & C_BOOL;
316 _permission_mode = check_options [7].widget->state & C_BOOL;
317 #ifndef HAVE_X
318 _equal_split = check_options [6].widget->state & C_BOOL;
319 #endif
320 _menubar_visible = check_options [5].widget->state & C_BOOL;
321 _command_prompt = check_options [4].widget->state & C_BOOL;
322 _keybar_visible = check_options [2].widget->state & C_BOOL;
323 _message_visible = check_options [1].widget->state & C_BOOL;
324 _xterm_hintbar = check_options [0].widget->state & C_BOOL;
325 if (console_flag){
326 int minimum;
327 if (_output_lines < 0)
328 _output_lines = 0;
329 height = LINES - _keybar_visible - _command_prompt -
330 _menubar_visible - _output_lines - _message_visible;
331 if (_message_visible && _xterm_hintbar && xterm_flag) height++;
332 minimum = MINHEIGHT * (1 + _horizontal_split);
333 if (height < minimum){
334 _output_lines -= minimum - height;
335 height = minimum;
336 }
337 } else {
338 height = LINES - _keybar_visible - _command_prompt -
339 _menubar_visible - _output_lines - _message_visible;
340 if (_message_visible && _xterm_hintbar && xterm_flag) height++;
341 }
342 if (_horizontal_split != radio_widget->sel){
343 _horizontal_split = radio_widget->sel;
344 if (_horizontal_split)
345 _first_panel_size = height / 2;
346 else
347 _first_panel_size = COLS / 2;
348 }
349 update_split ();
350 if (console_flag){
351 if (old_output_lines != _output_lines){
352 old_output_lines = _output_lines;
353 attrset (COLOR_NORMAL);
354 dlg_move (h, 9, 10 + first_width);
355 printw ("%02d", _output_lines);
356 }
357 }
358 break;
359
360 case DLG_END:
361 break;
362 }
363 return 0;
364 }
365
366 static void init_layout (void)
367 {
368 static int i18n_layt_flag = 0;
369 static int b1, b2, b3;
370 int i = sizeof (s_split_direction) / sizeof(char*) ;
371 char* ok_button = _("&Ok");
372 char* cancel_button = _("&Cancel");
373 char* save_button = _("&Save");
374
375 if (!i18n_layt_flag)
376 {
377 register int l1;
378
379 first_width = 19; /* length of line with '<' '>' buttons */
380
381 layout_title = _(" Layout ");
382 title1 = _(" Panel split ");
383 title2 = _(" Highlight... ");
384 title3 = _(" Other options ");
385 output_lines_label = _("output lines");
386
387 while (i--)
388 {
389 s_split_direction [i] = _(s_split_direction [i]);
390 l1 = strlen (s_split_direction [i]) + 7;
391 if (l1 > first_width)
392 first_width = l1;
393 }
394
395 for (i = 0; i <= 8; i++)
396 {
397 check_options[i].text = _(check_options[i].text);
398 l1 = strlen (check_options[i].text) + 7;
399 if (l1 > first_width)
400 first_width = l1;
401 }
402
403 l1 = strlen (title1) + 1;
404 if (l1 > first_width)
405 first_width = l1;
406
407 l1 = strlen (title2) + 1;
408 if (l1 > first_width)
409 first_width = l1;
410
411
412 second_width = strlen (title3) + 1;
413 for (i = 0; i < 6; i++)
414 {
415 check_options[i].text = _(check_options[i].text);
416 l1 = strlen (check_options[i].text) + 7;
417 if (l1 > second_width)
418 second_width = l1;
419 }
420 if (console_flag)
421 {
422 l1 = strlen (output_lines_label) + 13;
423 if (l1 > second_width)
424 second_width = l1;
425 }
426
427 /*
428 * alex@bcs.zp.ua:
429 * To be completely correct, one need to check if layout_title
430 * does not exceed dialog length and total length of 3 buttons
431 * allows their placement in one row. But assuming this dialog
432 * is wide enough, I don't include such a tests.
433 *
434 * Now the last thing to do - properly space buttons...
435 */
436 l1 = 11 + strlen (ok_button) /* 14 - all brackets and inner space */
437 + strlen (save_button) /* notice: it is 3 char less because */
438 + strlen (cancel_button); /* of '&' char in button text */
439
440 i = (first_width + second_width - l1) / 4;
441 b1 = 5 + i;
442 b2 = b1 + strlen(ok_button) + i + 6;
443 b3 = b2 + strlen(save_button) + i + 4;
444
445 i18n_layt_flag = 1;
446 }
447
448 layout_dlg = create_dlg (0, 0, 15, first_width + second_width + 9,
449 dialog_colors, layout_callback,
450 "[Layout]", "layout", DLG_CENTER | DLG_GRID);
451
452 x_set_dialog_title (layout_dlg, _("Layout"));
453
454 add_widgetl (layout_dlg,
455 button_new (BY, b3, B_CANCEL, NORMAL_BUTTON, cancel_button, 0, 0, "c"),
456 XV_WLAY_RIGHTOF);
457 add_widgetl (layout_dlg,
458 button_new (BY, b2, B_EXIT, NORMAL_BUTTON, save_button, 0, 0, "s"),
459 XV_WLAY_RIGHTOF);
460 add_widgetl (layout_dlg,
461 button_new (BY, b1, B_ENTER, DEFPUSH_BUTTON, ok_button, 0, 0, "o"),
462 XV_WLAY_CENTERROW);
463 #ifndef HAVE_X
464 if (console_flag){
465 add_widget (layout_dlg,
466 button_new (9, 12 + first_width, B_MINUS, NARROW_BUTTON, "&-",
467 bminus_cback, 0, NULL));
468 add_widget (layout_dlg,
469 button_new (9, 7 + first_width, B_PLUS, NARROW_BUTTON, "&+",
470 bplus_cback, 0, NULL));
471 }
472 #endif
473
474 #define XTRACT(i) *check_options[i].variable, check_options[i].text, check_options[i].tkname
475
476 for (i = 0; i < 6; i++){
477 check_options [i].widget = check_new (8 - i, 7 + first_width, XTRACT(i));
478 add_widgetl (layout_dlg, check_options [i].widget, XV_WLAY_BELOWCLOSE);
479 }
480 #ifdef HAVE_XVIEW
481 add_widgetl (layout_dlg, label_new (2, 7 + first_width, _("Other options"), "oo"),
482 XV_WLAY_NEXTCOLUMN);
483 add_widgetl (layout_dlg, label_new (8, 5, _("Highlight..."), "hl"),
484 XV_WLAY_NEXTCOLUMN);
485 add_widgetl (layout_dlg, label_new (2, 5, _("Panel split"), "ps"),
486 XV_WLAY_NEXTCOLUMN);
487 #endif
488 check_options [8].widget = check_new (10, 6, XTRACT(8));
489 add_widgetl (layout_dlg, check_options [8].widget, XV_WLAY_BELOWCLOSE);
490 check_options [7].widget = check_new (9, 6, XTRACT(7));
491 add_widgetl (layout_dlg, check_options [7].widget, XV_WLAY_BELOWCLOSE);
492
493 _filetype_mode = filetype_mode;
494 _permission_mode = permission_mode;
495 _equal_split = equal_split;
496 _menubar_visible = menubar_visible;
497 _command_prompt = command_prompt;
498 _keybar_visible = keybar_visible;
499 _message_visible = message_visible;
500 _xterm_hintbar = xterm_hintbar;
501 #ifndef HAVE_X
502 bright_widget = button_new(6, 15, B_2RIGHT, NARROW_BUTTON, "&>", b2right_cback, 0, ">");
503 add_widgetl (layout_dlg, bright_widget, XV_WLAY_RIGHTOF);
504 bleft_widget = button_new (6, 9, B_2LEFT, NARROW_BUTTON, "&<", b2left_cback, 0, "<");
505 add_widgetl (layout_dlg, bleft_widget, XV_WLAY_RIGHTOF);
506 check_options [6].widget = check_new (5, 6, XTRACT(6));
507 #endif
508 old_first_panel_size = -1;
509 old_horizontal_split = -1;
510 old_output_lines = -1;
511
512 _first_panel_size = first_panel_size;
513 _output_lines = output_lines;
514 #ifndef HAVE_X
515 add_widget (layout_dlg, check_options [6].widget);
516 radio_widget = radio_new (3, 6, 2, s_split_direction, 1, "r");
517 add_widget (layout_dlg, radio_widget);
518 radio_widget->sel = horizontal_split;
519 #endif
520 }
521
522 void layout_change (void)
523 {
524 setup_panels ();
525 layout_do_change = 0;
526 #ifndef HAVE_X
527 /* re-init the menu, because perhaps there was a change in the way
528 how the panel are split (horizontal/vertical). */
529 done_menu();
530 init_menu();
531 menubar_arrange(the_menubar);
532 #endif
533 }
534
535 void layout_cmd (void)
536 {
537 int result;
538 int i;
539
540 init_layout ();
541 run_dlg (layout_dlg);
542 result = layout_dlg->ret_value;
543
544 if (result == B_ENTER || result == B_EXIT){
545 for (i = 0; check_options [i].text; i++)
546 if (check_options [i].widget)
547 *check_options [i].variable = check_options [i].widget->state & C_BOOL;
548 #ifndef HAVE_X
549 horizontal_split = radio_widget->sel;
550 first_panel_size = _first_panel_size;
551 output_lines = _output_lines;
552 layout_do_change = 1;
553 #endif
554 }
555 if (result == B_EXIT){
556 save_layout ();
557 sync_profiles ();
558 }
559
560 destroy_dlg (layout_dlg);
561 if (layout_do_change)
562 layout_change ();
563 }
564
565 static void check_split (void)
566 {
567 if (horizontal_split){
568 if (equal_split)
569 first_panel_size = height / 2;
570 else if (first_panel_size < MINHEIGHT)
571 first_panel_size = MINHEIGHT;
572 else if (first_panel_size > height - MINHEIGHT)
573 first_panel_size = height - MINHEIGHT;
574 } else {
575 if (equal_split)
576 first_panel_size = COLS / 2;
577 else if (first_panel_size < MINWIDTH)
578 first_panel_size = MINWIDTH;
579 else if (first_panel_size > COLS - MINWIDTH)
580 first_panel_size = COLS - MINWIDTH;
581 }
582 }
583
584 int panel_event (Gpm_Event *event, WPanel *panel);
585 int menu_bar_event (Gpm_Event *event, void *);
586 extern char *prompt;
587
588 #ifndef HAVE_X
589 #ifdef HAVE_SLANG
590 void init_curses ()
591 {
592 extern int force_ugly_line_drawing;
593 extern int SLtt_Has_Alt_Charset;
594 SLtt_get_terminfo ();
595 #ifndef OS2_NT
596 if (force_ugly_line_drawing)
597 SLtt_Has_Alt_Charset = 0;
598 #endif
599 SLsmg_init_smg ();
600 do_enter_ca_mode ();
601 init_colors ();
602 keypad (stdscr, TRUE);
603 nodelay (stdscr, FALSE);
604 }
605 #else
606 void init_curses (void)
607 {
608 initscr();
609 if (!status_using_ncurses)
610 do_enter_ca_mode ();
611 mc_raw_mode ();
612 noecho ();
613 keypad (stdscr, TRUE);
614 nodelay (stdscr, FALSE);
615 init_colors ();
616 }
617 #endif /* ! HAVE_SLANG */
618 void done_screen ()
619 {
620 if (!(quit & SUBSHELL_EXIT))
621 clr_scr ();
622 reset_shell_mode ();
623 mc_noraw_mode ();
624 if (use_mouse_p)
625 shut_mouse ();
626 keypad (stdscr, FALSE);
627 }
628 #else
629 void init_curses ()
630 {
631 }
632 void done_screen ()
633 {
634 }
635 #endif /* HAVE_X */
636
637 void panel_do_cols (int index)
638 {
639 if (get_display_type (index) == view_listing)
640 set_panel_formats ((WPanel *) panels [index].widget);
641 else {
642 panel_update_cols (panels [index].widget, frame_half);
643 }
644 }
645
646 #ifdef HAVE_X
647 void
648 setup_panels (void)
649 {
650 Widget *w = panels [0].widget;
651
652 winput_set_origin (&cmdline->input, 0, 60);
653
654 /* Only needed by the startup code */
655 if (panels [0].type == view_listing){
656 x_panel_set_size (0);
657 }
658
659 if (panels [1].type == view_listing){
660 x_panel_set_size (1);
661 }
662
663 load_hint ();
664 #ifdef HAVE_XVIEW
665 panel_do_cols (0);
666 panel_do_cols (1);
667 #endif
668 }
669
670 #else
671
672 void setup_panels (void)
673 {
674 int start_y;
675 int promptl; /* the prompt len */
676
677 if (console_flag){
678 int minimum;
679 if (output_lines < 0)
680 output_lines = 0;
681 height = LINES - keybar_visible - command_prompt - menubar_visible
682 - output_lines - message_visible;
683 if (message_visible && xterm_hintbar && xterm_flag) height++;
684 minimum = MINHEIGHT * (1 + horizontal_split);
685 if (height < minimum){
686 output_lines -= minimum - height;
687 height = minimum;
688 }
689 } else {
690 height = LINES - menubar_visible - command_prompt -
691 keybar_visible - message_visible;
692 if (message_visible && xterm_hintbar && xterm_flag) height++;
693 }
694 check_split ();
695 start_y = menubar_visible;
696
697 /* The column computing is defered until panel_do_cols */
698 if (horizontal_split){
699 widget_set_size (panels [0].widget, start_y, 0,
700 first_panel_size, 0);
701
702 widget_set_size (panels [1].widget, start_y+first_panel_size, 0,
703 height-first_panel_size, 0);
704 } else {
705 int first_x = first_panel_size;
706
707 widget_set_size (panels [0].widget, start_y, 0,
708 height, 0);
709
710 widget_set_size (panels [1].widget, start_y, first_x,
711 height, 0);
712
713 }
714 panel_do_cols (0);
715 panel_do_cols (1);
716
717 promptl = strlen (prompt);
718
719 widget_set_size (&the_menubar->widget, 0, 0, 1, COLS);
720
721 if (command_prompt) {
722 widget_set_size (&cmdline->input.widget,
723 LINES-1-keybar_visible, promptl,
724 1, COLS-promptl-(keybar_visible ? 0 : 1));
725 winput_set_origin (&cmdline->input, promptl, COLS-promptl-(keybar_visible ? 0 : 1));
726 widget_set_size (&the_prompt->widget,
727 LINES-1-keybar_visible, 0,
728 1, promptl);
729 } else {
730 widget_set_size (&cmdline->input.widget, 0, 0, 0, 0);
731 winput_set_origin (&cmdline->input, 0, 0);
732 widget_set_size (&the_prompt->widget, LINES, COLS, 0, 0);
733 }
734
735 widget_set_size (&the_bar->widget, LINES-1, 0, 1, COLS);
736 the_bar->visible = keybar_visible;
737
738 /* Output window */
739 if (console_flag && output_lines){
740 output_start_y = LINES -command_prompt-keybar_visible-
741 output_lines;
742 show_console_contents (output_start_y,
743 LINES-output_lines-keybar_visible-1,
744 LINES-keybar_visible-1);
745 }
746 if (message_visible && (!xterm_hintbar || !xterm_flag))
747 widget_set_size (&the_hint->widget, height+start_y, 0, 1,COLS);
748 else
749 widget_set_size (&the_hint->widget, 0, 0, 0, 0);
750
751 load_hint ();
752 }
753 #endif
754
755 void flag_winch (int dummy)
756 {
757 winch_flag = 1;
758 }
759
760 void edit_adjust_size (Dlg_head * h);
761
762 #ifdef PORT_NEEDS_CHANGE_SCREEN_SIZE
763 void low_level_change_screen_size (void)
764 {
765 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
766 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
767 struct winsize winsz;
768
769 winsz.ws_col = winsz.ws_row = 0;
770 /* Ioctl on the STDIN_FILENO */
771 ioctl (0, TIOCGWINSZ, &winsz);
772 if (winsz.ws_col && winsz.ws_row){
773 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
774 resizeterm(winsz.ws_row, winsz.ws_col);
775 clearok(stdscr,TRUE); /* FIXME: sigwinch's should use a semaphore! */
776 #else
777 COLS = winsz.ws_col;
778 LINES = winsz.ws_row;
779 #endif
780 #ifdef HAVE_SUBSHELL_SUPPORT
781 resize_subshell ();
782 #endif
783 }
784 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
785 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
786 }
787
788 void change_screen_size (void)
789 {
790 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
791 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
792 extern Dlg_head *view_dlg;
793 extern Dlg_head *edit_dlg;
794
795 #ifndef NCURSES_VERSION
796 mc_noraw_mode ();
797 endwin ();
798 #endif
799 low_level_change_screen_size ();
800 check_split ();
801 #ifndef NCURSES_VERSION
802 /* XSI Curses spec states that portable applications shall not invoke
803 * initscr() more than once. This kludge could be done within the scope
804 * of the specification by using endwin followed by a refresh (in fact,
805 * more than one curses implementation does this); it is guaranteed to work
806 * only with slang.
807 */
808 init_curses ();
809 #endif
810 setup_panels ();
811 if (current_dlg == view_dlg)
812 view_adjust_size (view_dlg);
813 #ifdef USE_INTERNAL_EDIT
814 if (current_dlg == edit_dlg)
815 edit_adjust_size (edit_dlg);
816 #endif
817
818 #ifdef RESIZABLE_MENUBAR
819 menubar_arrange(the_menubar);
820 #endif
821
822 /* Now, force the redraw */
823 do_refresh ();
824 touchwin (stdscr);
825 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
826 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
827 winch_flag = 0;
828 }
829 #endif /* HAVE_X */
830
831 extern int verbose;
832 static int ok_to_refresh = 1;
833
834 void use_dash (int flag)
835 {
836 if (flag)
837 ok_to_refresh++;
838 else
839 ok_to_refresh--;
840 }
841
842 void set_hintbar(char *str)
843 {
844 #ifndef HAVE_X
845 if (xterm_flag && xterm_hintbar) {
846 fprintf (stderr, "\33]0;mc - %s\7", str);
847 } else
848 #endif
849 {
850 label_set_text (the_hint, str);
851 if (ok_to_refresh > 0)
852 refresh();
853 }
854 }
855
856 void print_vfs_message(char *msg, ...)
857 {
858 va_list ap;
859 char str[128];
860
861 va_start(ap, msg);
862 vsprintf(str, msg, ap);
863 va_end(ap);
864 if (midnight_shutdown || !the_hint || !the_hint->widget.parent)
865 return;
866
867 if (message_visible || (xterm_flag && xterm_hintbar)) {
868 set_hintbar(str);
869 }
870 }
871
872 void rotate_dash (void)
873 {
874 #ifndef HAVE_X
875 static char rotating_dash [] = "|/-\\";
876 static int pos = 0;
877
878 if (!nice_rotating_dash || (ok_to_refresh <= 0))
879 return;
880
881 if (pos >= sizeof (rotating_dash)-1)
882 pos = 0;
883 move (0, COLS-1);
884 addch (rotating_dash [pos]);
885 mc_refresh ();
886 pos++;
887 #endif
888 }
889
890 void remove_dash (void)
891 {
892 #ifndef HAVE_X
893 if (!nice_rotating_dash)
894 return;
895
896 /* Currently, it's much nicer with the CPU to do this instead of
897 calling do_refresh.
898
899 I should implement a routine called invalidate_region that would
900 send a draw message only to the affected views. But for now
901 this is fine.
902 */
903
904 move (0, COLS-1);
905 addch (' ');
906 #endif
907 }
908
909 char *get_nth_panel_name (int num)
910 {
911 static char buffer [20];
912
913 if (!num)
914 return "New Left Panel";
915 else if (num == 1)
916 return "New Right Panel";
917 else {
918 sprintf (buffer, "%ith Panel", num);
919 return buffer;
920 }
921 }
922
923 /* I wonder if I should start to use the folding mode than Dugan uses */
924 /* */
925 /* This is the centralized managing of the panel display types */
926 /* This routine takes care of destroying and creating new widgets */
927 /* Please note that it could manage MAX_VIEWS, not just left and right */
928 /* Currently nothing in the code takes advantage of this and has hard- */
929 /* coded values for two panels only */
930
931 /* Set the num-th panel to the view type: type */
932 /* This routine also keeps at least one WPanel object in the screen */
933 /* since a lot of routines depend on the current_panel variable */
934 void set_display_type (int num, int type)
935 {
936 int x, y, cols, lines;
937 int the_other; /* Index to the other panel */
938 char *file_name = 0; /* For Quick view */
939 Widget *new_widget, *old_widget;
940 WPanel *the_other_panel;
941
942 x =y = cols = lines = 0;
943 old_widget = 0;
944 if (num >= MAX_VIEWS){
945 fprintf (stderr, "Could not allocate more that %d views\n", MAX_VIEWS);
946 abort ();
947 }
948
949 /* Check that we will have a WPanel * at least */
950 the_other = 0;
951 if (type != view_listing){
952 the_other = num == 0 ? 1 : 0;
953
954 if (panels [the_other].type != view_listing)
955 return;
956
957 }
958
959 /* Get rid of it */
960 if (panels [num].widget){
961 Widget *w = panels [num].widget;
962 WPanel *panel = (WPanel *) panels [num].widget;
963
964 x = w->x;
965 y = w->y;
966 cols = w->cols;
967 lines = w->lines;
968 old_widget = panels [num].widget;
969
970 if (panels [num].type == view_listing){
971 if (panel->frame_size == frame_full && type != view_listing){
972 cols = COLS - first_panel_size;
973 if (num == 1)
974 x = first_panel_size;
975 }
976 }
977 #ifdef HAVE_TK
978 tk_evalf ("container_clean %s", panel->widget.wcontainer);
979 #endif
980 }
981
982 new_widget = 0;
983
984 switch (type){
985 case view_listing:
986 new_widget = (Widget *) panel_new (get_nth_panel_name (num));
987 break;
988
989 case view_info:
990 new_widget = (Widget *) info_new ();
991
992 break;
993
994 case view_tree:
995 new_widget = (Widget *) tree_new (1, 0, 0, 0, 0);
996 break;
997
998 case view_quick:
999 new_widget = (Widget *) view_new (0, 0, 0, 0, 1);
1000 the_other_panel = (WPanel *) panels [the_other].widget;
1001 if (the_other_panel)
1002 file_name =
1003 the_other_panel->dir.list[the_other_panel->selected].fname;
1004 else
1005 file_name = "";
1006
1007 view_init ((WView *) new_widget, 0, file_name, 0);
1008 break;
1009 }
1010 panels [num].type = type;
1011 panels [num].widget = (Widget *) new_widget;
1012
1013 /* We set the same size the old widget had */
1014 widget_set_size ((Widget *) new_widget, y, x, lines, cols);
1015
1016 /* We wanna the new widget at the same position */
1017 /* XView sets wcontainer to !0 <- Not XView, but we, when we create it */
1018 /* Ok, the XView support code does it */
1019 if (old_widget && old_widget->wcontainer){
1020 new_widget->wcontainer = old_widget->wcontainer;
1021 new_widget->area = old_widget->area;
1022 }
1023
1024 /* We use replace to keep the circular list of the dialog in the */
1025 /* same state. Maybe we could just kill it and then replace it */
1026 if (midnight_dlg && old_widget){
1027 dlg_replace_widget (midnight_dlg, old_widget, panels [num].widget);
1028 }
1029 if (type == view_listing){
1030 if (num == 0)
1031 left_panel = (WPanel *) new_widget;
1032 else
1033 right_panel = (WPanel *) new_widget;
1034 }
1035
1036 if (type == view_tree)
1037 the_tree = (WTree *) new_widget;
1038
1039 /* Prevent current_panel's value from becoming invalid.
1040 * It's just a quick hack to prevent segfaults. Comment out and
1041 * try following:
1042 * - select left panel
1043 * - invoke menue left/tree
1044 * - as long as you stay in the left panel almost everything that uses
1045 * cpanel causes segfault, e.g. C-Enter, C-x c, ...
1046 */
1047
1048 if (type != view_listing)
1049 if (cpanel == (WPanel *) old_widget)
1050 current_panel = num == 0 ? right_panel : left_panel;
1051 }
1052
1053 #ifndef HAVE_XVIEW
1054 /* This routine is deeply sticked to the two panels idea.
1055 What should it do in more panels. ANSWER - don't use it
1056 in any multiple panels environment. */
1057 void swap_panels ()
1058 {
1059 Widget tmp;
1060 Widget *tmp_widget;
1061 WPanel panel;
1062 WPanel *panel1, *panel2;
1063 int tmp_type;
1064
1065 #if 0
1066 #ifdef HAVE_PORTABLE_TOKEN_PASTING
1067 #define panelswap(e) panel.##e = panel1->##e; panel1->##e = panel2->##e; panel2->##e = panel.##e;
1068 #define panelswapstr(e) strcpy (panel.##e, panel1->##e); strcpy (panel1->##e, panel2->##e); strcpy (panel2->##e, panel.##e);
1069 #else
1070 #define panelswap(e) panel./**/e = panel1->/**/e; panel1->/**/e = panel2->/**/e; panel2->/**/e = panel./**/e;
1071 #define panelswapstr(e) strcpy (panel./**/e, panel1->/**/e); strcpy (panel1->/**/e, panel2->/**/e); strcpy (panel2->/**/e, panel./**/e);
1072 #endif
1073 #endif
1074
1075 #define panelswap(x) panel. x = panel1-> x; panel1-> x = panel2-> x; panel2-> x = panel. x;
1076
1077 #define panelswapstr(e) strcpy (panel. e, panel1-> e); \
1078 strcpy (panel1-> e, panel2-> e); \
1079 strcpy (panel2-> e, panel. e);
1080 panel1 = (WPanel *) panels [0].widget;
1081 panel2 = (WPanel *) panels [1].widget;
1082 if (panels [0].type == view_listing && panels [1].type == view_listing) {
1083 /* Change everything except format/sort/panel_name etc. */
1084 panelswap (dir);
1085 panelswap (active);
1086 panelswapstr (cwd);
1087 panelswapstr (lwd);
1088 panelswap (count);
1089 panelswap (marked);
1090 panelswap (dirs_marked);
1091 panelswap (total);
1092 panelswap (top_file);
1093 panelswap (selected);
1094 panelswap (is_panelized);
1095 panelswap (dir_stat);
1096
1097 panel1->searching = 0;
1098 panel2->searching = 0;
1099 if (cpanel == panel1)
1100 current_panel = panel2;
1101 else
1102 current_panel = panel1;
1103 if (midnight_dlg->current->widget == panels [0].widget)
1104 dlg_select_widget (midnight_dlg, (void *) panels [1].widget);
1105 else if (midnight_dlg->current->widget == panels [1].widget)
1106 dlg_select_widget (midnight_dlg, (void *) panels [0].widget);
1107 } else {
1108 WPanel *tmp_panel;
1109
1110 tmp_panel=right_panel;
1111 right_panel=left_panel;
1112 left_panel=tmp_panel;
1113
1114 if (panels [0].type == view_listing) {
1115 if (!strcmp (panel1->panel_name, get_nth_panel_name (0))) {
1116 free (panel1->panel_name);
1117 panel1->panel_name = strdup (get_nth_panel_name (1));
1118 }
1119 }
1120 if (panels [1].type == view_listing) {
1121 if (!strcmp (panel2->panel_name, get_nth_panel_name (1))) {
1122 free (panel2->panel_name);
1123 panel2->panel_name = strdup (get_nth_panel_name (0));
1124 }
1125 }
1126
1127 tmp.x = panels [0].widget->x;
1128 tmp.y = panels [0].widget->y;
1129 tmp.cols = panels [0].widget->cols;
1130 tmp.lines = panels [0].widget->lines;
1131
1132 panels [0].widget->x = panels [1].widget->x;
1133 panels [0].widget->y = panels [1].widget->y;
1134 panels [0].widget->cols = panels [1].widget->cols;
1135 panels [0].widget->lines = panels [1].widget->lines;
1136
1137 panels [1].widget->x = tmp.x;
1138 panels [1].widget->y = tmp.y;
1139 panels [1].widget->cols = tmp.cols;
1140 panels [1].widget->lines = tmp.lines;
1141
1142 tmp_widget = panels [0].widget;
1143 panels [0].widget = panels [1].widget;
1144 panels [1].widget = tmp_widget;
1145 tmp_type = panels [0].type;
1146 panels [0].type = panels [1].type;
1147 panels [1].type = tmp_type;
1148 }
1149 }
1150 #endif
1151
1152 int get_display_type (int index)
1153 {
1154 return panels [index].type;
1155 }
1156
1157 Widget *get_panel_widget (int index)
1158 {
1159 return panels [index].widget;
1160 }
1161
1162 int get_current_index (void)
1163 {
1164 if (panels [0].widget == ((Widget *) cpanel))
1165 return 0;
1166 else
1167 return 1;
1168 }
1169
1170 int get_other_index (void)
1171 {
1172 return !get_current_index ();
1173 }
1174
1175 /* Returns the view type for the current panel/view */
1176 int get_current_type (void)
1177 {
1178 if (panels [0].widget == (Widget *) cpanel)
1179 return panels [0].type;
1180 else
1181 return panels [1].type;
1182 }
1183
1184 /* Returns the view type of the unselected panel */
1185 int get_other_type (void)
1186 {
1187 if (panels [0].widget == (Widget *) cpanel)
1188 return panels [1].type;
1189 else
1190 return panels [0].type;
1191 }
1192