- Use the included S-Lang again, since we include a better version now.
[midnight-commander.git] / src / layout.c
blob3e1555dc41ac7c308f1b4e30b3300112d0d80e16
1 /* Panel layout module for the Midnight Commander
2 Copyright (C) 1995 the Free Software Foundation
4 Written: 1995 Janne Kukonlehto
5 1995 Miguel de Icaza
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <config.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #if HAVE_TERMIOS_H
29 # include <termios.h>
30 #endif
32 * If TIOCGWINSZ supported, make it available here, because window-
33 * resizing code depends on it...
35 #ifdef HAVE_SYS_IOCTL_H
36 # include <sys/ioctl.h>
37 #endif
38 #ifdef HAVE_UNISTD_H
39 # include <unistd.h>
40 #endif
41 #include <signal.h>
43 #include "global.h"
44 #include "tty.h"
45 #include "win.h"
46 #include "color.h"
47 #include "key.h"
48 #include "dlg.h"
49 #include "widget.h"
50 #include "command.h"
51 #include "dialog.h" /* For do_refresh() */
52 #include "profile.h" /* For sync_profiles() */
53 #include "mouse.h"
54 #define WANT_WIDGETS
55 #include "main.h"
56 #include "subshell.h" /* For use_subshell and resize_subshell() */
57 #include "tree.h"
58 #include "menu.h"
60 /* Needed for the extern declarations of integer parameters */
61 #include "dir.h"
62 #include "panel.h" /* The Panel widget */
63 #include "file.h"
64 #include "cons.saver.h"
65 #include "layout.h"
66 #include "info.h" /* The Info widget */
67 #include "view.h" /* The view widget */
69 #define WANT_WIDGETS
70 #include "setup.h" /* For save_setup() */
72 /* Controls the display of the rotating dash on the verbose mode */
73 int nice_rotating_dash = 1;
75 /* If set, then we have to call the layout_change routine from main */
76 int layout_do_change = 0;
78 /* Set if the panels are split horizontally */
79 int horizontal_split = 0;
81 /* Set if the window has changed it's size */
82 int winch_flag = 0;
84 /* Set if the split is the same */
85 int equal_split = 1;
87 /* First panel size if the panel are not split equally */
88 int first_panel_size = 0;
90 /* The number of output lines shown (if available) */
91 int output_lines = 0;
93 /* Set if the command prompt is to be displayed */
94 int command_prompt = 1;
96 /* Set if the nice and usefull keybar is visible */
97 int keybar_visible = 1;
99 /* Set if the nice message (hint) bar is visible */
100 int message_visible = 1;
102 /* Set if you want the message bar shown in xterm title bar to save space */
103 int xterm_hintbar = 0;
105 /* The starting line for the output of the subprogram */
106 int output_start_y = 0;
108 /* The maximum number of views managed by the set_display_type routine */
109 /* Must be at least two (for current and other). Please note that until */
110 /* Janne gets around this, we will only manage two of them :-) */
111 #define MAX_VIEWS 2
113 static struct {
114 int type;
115 Widget *widget;
116 } panels [MAX_VIEWS];
118 /* These variables are used to avoid updating the information unless */
119 /* we need it */
120 static int old_first_panel_size;
121 static int old_horizontal_split;
122 static int old_output_lines;
124 /* Internal variables */
125 static int _horizontal_split;
126 static int _equal_split;
127 static int _first_panel_size;
128 static int _menubar_visible;
129 static int _output_lines;
130 static int _command_prompt;
131 static int _keybar_visible;
132 static int _message_visible;
133 static int _xterm_hintbar;
134 static int _permission_mode;
135 static int _filetype_mode;
137 static int height;
139 /* Width 12 for a wee Quick (Hex) View */
140 #define MINWIDTH 12
141 #define MINHEIGHT 5
143 #define BY 12
145 #define B_2LEFT B_USER
146 #define B_2RIGHT B_USER + 1
147 #define B_PLUS B_USER + 2
148 #define B_MINUS B_USER + 3
150 static Dlg_head *layout_dlg;
152 static char *s_split_direction [2] = {
153 N_("&Vertical"),
154 N_("&Horizontal")
157 static WRadio *radio_widget;
159 static struct {
160 char *text;
161 int *variable;
162 WCheck *widget;
163 char *tkname;
164 } check_options [] = {
165 { N_("&Xterm hintbar"), &xterm_hintbar, 0, "h" },
166 { N_("h&Intbar visible"), &message_visible, 0, "v" },
167 { N_("&Keybar visible"), &keybar_visible, 0, "k" },
168 { N_("command &Prompt"), &command_prompt, 0, "p" },
169 { N_("show &Mini status"), &show_mini_info, 0, "m" },
170 { N_("menu&Bar visible"), &menubar_visible, 0, "me" },
171 { N_("&Equal split"), &equal_split, 0, "eq" },
172 { N_("pe&Rmissions"), &permission_mode, 0, "pr" },
173 { N_("&File types"), &filetype_mode, 0, "ft" },
174 { 0, 0, 0, 0 }
177 static int first_width, second_width;
178 static char *title1, *title2, *title3, *output_lines_label;
180 static WButton *bleft_widget, *bright_widget;
182 /* Declarations for static functions */
183 static void low_level_change_screen_size (void);
185 static void _check_split (void)
187 if (_horizontal_split){
188 if (_equal_split)
189 _first_panel_size = height / 2;
190 else if (_first_panel_size < MINHEIGHT)
191 _first_panel_size = MINHEIGHT;
192 else if (_first_panel_size > height - MINHEIGHT)
193 _first_panel_size = height - MINHEIGHT;
194 } else {
195 if (_equal_split)
196 _first_panel_size = COLS / 2;
197 else if (_first_panel_size < MINWIDTH)
198 _first_panel_size = MINWIDTH;
199 else if (_first_panel_size > COLS - MINWIDTH)
200 _first_panel_size = COLS - MINWIDTH;
204 static void update_split (void)
206 /* Check split has to be done before testing if it changed, since
207 it can change due to calling _check_split() as well*/
208 _check_split ();
210 /* To avoid setting the cursor to the wrong place */
211 if ((old_first_panel_size == _first_panel_size) &&
212 (old_horizontal_split == _horizontal_split)){
213 return;
216 old_first_panel_size = _first_panel_size;
217 old_horizontal_split = _horizontal_split;
219 attrset (COLOR_NORMAL);
220 dlg_move (layout_dlg, 6, 6);
221 printw ("%03d", _first_panel_size);
222 dlg_move (layout_dlg, 6, 18);
223 if (_horizontal_split)
224 printw ("%03d", height - _first_panel_size);
225 else
226 printw ("%03d", COLS - _first_panel_size);
229 static int b2left_cback (int action, void *data)
231 if (_equal_split){
232 /* Turn equal split off */
233 _equal_split = 0;
234 check_options [6].widget->state = check_options [6].widget->state & ~C_BOOL;
235 dlg_select_widget (layout_dlg, check_options [6].widget);
236 dlg_select_widget (layout_dlg, bleft_widget);
238 _first_panel_size++;
239 return 0;
242 static int b2right_cback (int action, void *data)
244 if (_equal_split){
245 /* Turn equal split off */
246 _equal_split = 0;
247 check_options [6].widget->state = check_options [6].widget->state & ~C_BOOL;
248 dlg_select_widget (layout_dlg, check_options [6].widget);
249 dlg_select_widget (layout_dlg, bright_widget);
251 _first_panel_size--;
252 return 0;
255 static int bplus_cback (int action, void *data)
257 if (_output_lines < 99)
258 _output_lines++;
259 return 0;
262 static int bminus_cback (int action, void *data)
264 if (_output_lines > 0)
265 _output_lines--;
266 return 0;
269 static int layout_callback (struct Dlg_head *h, int Id, int Msg)
271 switch (Msg){
272 case DLG_DRAW:
273 /*When repainting the whole dialog (e.g. with C-l) we have to
274 update everything*/
275 common_dialog_repaint (h);
277 old_first_panel_size = -1;
278 old_horizontal_split = -1;
279 old_output_lines = -1;
281 attrset (COLOR_NORMAL);
282 draw_box (h, 2, 4, 6, first_width);
283 draw_box (h, 8, 4, 4, first_width);
284 draw_box (h, 2, 5 + first_width, 10, second_width);
286 attrset (COLOR_HOT_NORMAL);
287 dlg_move (h, 2, 5);
288 addstr (title1);
289 dlg_move (h, 8, 5);
290 addstr (title2);
291 dlg_move (h, 2, 6 + first_width);
292 addstr (title3);
293 update_split ();
294 dlg_move (h, 6, 13);
295 addch ('=');
296 if (console_flag){
297 if (old_output_lines != _output_lines){
298 old_output_lines = _output_lines;
299 attrset (COLOR_NORMAL);
300 dlg_move (h, 9, 16 + first_width);
301 addstr (output_lines_label);
302 dlg_move (h, 9, 10 + first_width);
303 printw ("%02d", _output_lines);
306 break;
308 case DLG_POST_KEY:
309 _filetype_mode = check_options [8].widget->state & C_BOOL;
310 _permission_mode = check_options [7].widget->state & C_BOOL;
311 _equal_split = check_options [6].widget->state & C_BOOL;
312 _menubar_visible = check_options [5].widget->state & C_BOOL;
313 _command_prompt = check_options [4].widget->state & C_BOOL;
314 _keybar_visible = check_options [2].widget->state & C_BOOL;
315 _message_visible = check_options [1].widget->state & C_BOOL;
316 _xterm_hintbar = check_options [0].widget->state & C_BOOL;
317 if (console_flag){
318 int minimum;
319 if (_output_lines < 0)
320 _output_lines = 0;
321 height = LINES - _keybar_visible - _command_prompt -
322 _menubar_visible - _output_lines - _message_visible;
323 if (_message_visible && _xterm_hintbar && xterm_flag) height++;
324 minimum = MINHEIGHT * (1 + _horizontal_split);
325 if (height < minimum){
326 _output_lines -= minimum - height;
327 height = minimum;
329 } else {
330 height = LINES - _keybar_visible - _command_prompt -
331 _menubar_visible - _output_lines - _message_visible;
332 if (_message_visible && _xterm_hintbar && xterm_flag) height++;
334 if (_horizontal_split != radio_widget->sel){
335 _horizontal_split = radio_widget->sel;
336 if (_horizontal_split)
337 _first_panel_size = height / 2;
338 else
339 _first_panel_size = COLS / 2;
341 update_split ();
342 if (console_flag){
343 if (old_output_lines != _output_lines){
344 old_output_lines = _output_lines;
345 attrset (COLOR_NORMAL);
346 dlg_move (h, 9, 10 + first_width);
347 printw ("%02d", _output_lines);
350 break;
352 case DLG_END:
353 break;
355 return 0;
358 static void init_layout (void)
360 static int i18n_layt_flag = 0;
361 static int b1, b2, b3;
362 int i = sizeof (s_split_direction) / sizeof(char*) ;
363 char* ok_button = _("&Ok");
364 char* cancel_button = _("&Cancel");
365 char* save_button = _("&Save");
367 if (!i18n_layt_flag)
369 register int l1;
371 first_width = 19; /* length of line with '<' '>' buttons */
373 title1 = _(" Panel split ");
374 title2 = _(" Highlight... ");
375 title3 = _(" Other options ");
376 output_lines_label = _("output lines");
378 while (i--)
380 s_split_direction [i] = _(s_split_direction [i]);
381 l1 = strlen (s_split_direction [i]) + 7;
382 if (l1 > first_width)
383 first_width = l1;
386 for (i = 0; i <= 8; i++)
388 check_options[i].text = _(check_options[i].text);
389 l1 = strlen (check_options[i].text) + 7;
390 if (l1 > first_width)
391 first_width = l1;
394 l1 = strlen (title1) + 1;
395 if (l1 > first_width)
396 first_width = l1;
398 l1 = strlen (title2) + 1;
399 if (l1 > first_width)
400 first_width = l1;
403 second_width = strlen (title3) + 1;
404 for (i = 0; i < 6; i++)
406 check_options[i].text = _(check_options[i].text);
407 l1 = strlen (check_options[i].text) + 7;
408 if (l1 > second_width)
409 second_width = l1;
411 if (console_flag)
413 l1 = strlen (output_lines_label) + 13;
414 if (l1 > second_width)
415 second_width = l1;
419 * alex@bcs.zp.ua:
420 * To be completely correct, one need to check if the title
421 * does not exceed dialog length and total length of 3 buttons
422 * allows their placement in one row. But assuming this dialog
423 * is wide enough, I don't include such a tests.
425 * Now the last thing to do - properly space buttons...
427 l1 = 11 + strlen (ok_button) /* 14 - all brackets and inner space */
428 + strlen (save_button) /* notice: it is 3 char less because */
429 + strlen (cancel_button); /* of '&' char in button text */
431 i = (first_width + second_width - l1) / 4;
432 b1 = 5 + i;
433 b2 = b1 + strlen(ok_button) + i + 6;
434 b3 = b2 + strlen(save_button) + i + 4;
436 i18n_layt_flag = 1;
439 layout_dlg = create_dlg (0, 0, 15, first_width + second_width + 9,
440 dialog_colors, layout_callback,
441 "[Layout]", _("Layout"), DLG_CENTER);
443 add_widget (layout_dlg,
444 button_new (BY, b3, B_CANCEL, NORMAL_BUTTON, cancel_button, 0, 0, "c"));
445 add_widget (layout_dlg,
446 button_new (BY, b2, B_EXIT, NORMAL_BUTTON, save_button, 0, 0, "s"));
447 add_widget (layout_dlg,
448 button_new (BY, b1, B_ENTER, DEFPUSH_BUTTON, ok_button, 0, 0, "o"));
449 if (console_flag){
450 add_widget (layout_dlg,
451 button_new (9, 12 + first_width, B_MINUS, NARROW_BUTTON, "&-",
452 bminus_cback, 0, NULL));
453 add_widget (layout_dlg,
454 button_new (9, 7 + first_width, B_PLUS, NARROW_BUTTON, "&+",
455 bplus_cback, 0, NULL));
458 #define XTRACT(i) *check_options[i].variable, check_options[i].text, check_options[i].tkname
460 for (i = 0; i < 6; i++){
461 check_options [i].widget = check_new (8 - i, 7 + first_width, XTRACT(i));
462 add_widget (layout_dlg, check_options [i].widget);
464 check_options [8].widget = check_new (10, 6, XTRACT(8));
465 add_widget (layout_dlg, check_options [8].widget);
466 check_options [7].widget = check_new (9, 6, XTRACT(7));
467 add_widget (layout_dlg, check_options [7].widget);
469 _filetype_mode = filetype_mode;
470 _permission_mode = permission_mode;
471 _equal_split = equal_split;
472 _menubar_visible = menubar_visible;
473 _command_prompt = command_prompt;
474 _keybar_visible = keybar_visible;
475 _message_visible = message_visible;
476 _xterm_hintbar = xterm_hintbar;
477 bright_widget = button_new(6, 15, B_2RIGHT, NARROW_BUTTON, "&>", b2right_cback, 0, ">");
478 add_widget (layout_dlg, bright_widget);
479 bleft_widget = button_new (6, 9, B_2LEFT, NARROW_BUTTON, "&<", b2left_cback, 0, "<");
480 add_widget (layout_dlg, bleft_widget);
481 check_options [6].widget = check_new (5, 6, XTRACT(6));
482 old_first_panel_size = -1;
483 old_horizontal_split = -1;
484 old_output_lines = -1;
486 _first_panel_size = first_panel_size;
487 _output_lines = output_lines;
488 add_widget (layout_dlg, check_options [6].widget);
489 radio_widget = radio_new (3, 6, 2, s_split_direction, 1, "r");
490 add_widget (layout_dlg, radio_widget);
491 radio_widget->sel = horizontal_split;
494 void layout_change (void)
496 setup_panels ();
497 layout_do_change = 0;
498 /* re-init the menu, because perhaps there was a change in the way
499 how the panel are split (horizontal/vertical). */
500 done_menu();
501 init_menu();
502 menubar_arrange(the_menubar);
505 void layout_cmd (void)
507 int result;
508 int i;
510 init_layout ();
511 run_dlg (layout_dlg);
512 result = layout_dlg->ret_value;
514 if (result == B_ENTER || result == B_EXIT){
515 for (i = 0; check_options [i].text; i++)
516 if (check_options [i].widget)
517 *check_options [i].variable = check_options [i].widget->state & C_BOOL;
518 horizontal_split = radio_widget->sel;
519 first_panel_size = _first_panel_size;
520 output_lines = _output_lines;
521 layout_do_change = 1;
523 if (result == B_EXIT){
524 save_layout ();
525 sync_profiles ();
528 destroy_dlg (layout_dlg);
529 if (layout_do_change)
530 layout_change ();
533 static void check_split (void)
535 if (horizontal_split){
536 if (equal_split)
537 first_panel_size = height / 2;
538 else if (first_panel_size < MINHEIGHT)
539 first_panel_size = MINHEIGHT;
540 else if (first_panel_size > height - MINHEIGHT)
541 first_panel_size = height - MINHEIGHT;
542 } else {
543 if (equal_split)
544 first_panel_size = COLS / 2;
545 else if (first_panel_size < MINWIDTH)
546 first_panel_size = MINWIDTH;
547 else if (first_panel_size > COLS - MINWIDTH)
548 first_panel_size = COLS - MINWIDTH;
552 #ifdef HAVE_SLANG
553 void init_curses ()
555 SLtt_get_terminfo ();
556 #ifndef HAS_ACS_AS_PCCHARS
557 if (force_ugly_line_drawing)
558 SLtt_Has_Alt_Charset = 0;
559 #endif
560 SLsmg_init_smg ();
561 do_enter_ca_mode ();
562 init_colors ();
563 keypad (stdscr, TRUE);
564 nodelay (stdscr, FALSE);
566 #else
567 static const struct {
568 int acscode;
569 int character;
570 } acs_approx [] = {
571 { 'q', '-' }, /* ACS_HLINE */
572 { 'x', '|' }, /* ACS_VLINE */
573 { 'l', '+' }, /* ACS_ULCORNER */
574 { 'k', '+' }, /* ACS_URCORNER */
575 { 'm', '+' }, /* ACS_LLCORNER */
576 { 'j', '+' }, /* ACS_LRCORNER */
577 { 'a', '#' }, /* ACS_CKBOARD */
578 { 'u', '+' }, /* ACS_RTEE */
579 { 't', '+' }, /* ACS_LTEE */
580 { 'w', '+' }, /* ACS_TTEE */
581 { 'v', '+' }, /* ACS_BTEE */
582 { 'n', '+' }, /* ACS_PLUS */
583 { 0, 0 } };
585 void init_curses (void)
587 int i;
588 initscr();
589 #ifdef HAVE_ESCDELAY
591 * If ncurses exports the ESCDELAY variable it should be set to 0
592 * or you'll have to press Esc three times to dismiss a dialog box.
594 ESCDELAY = 0;
595 #endif /* HAVE_ESCDELAY */
596 do_enter_ca_mode ();
597 mc_raw_mode ();
598 noecho ();
599 keypad (stdscr, TRUE);
600 nodelay (stdscr, FALSE);
601 init_colors ();
602 if (force_ugly_line_drawing) {
603 for (i = 0; acs_approx[i].acscode != 0; i++) {
604 acs_map[acs_approx[i].acscode] = acs_approx[i].character;
608 #endif /* ! HAVE_SLANG */
610 void done_screen ()
612 if (!(quit & SUBSHELL_EXIT))
613 clr_scr ();
614 reset_shell_mode ();
615 mc_noraw_mode ();
616 keypad (stdscr, FALSE);
619 static void
620 panel_do_cols (int index)
622 if (get_display_type (index) == view_listing)
623 set_panel_formats ((WPanel *) panels [index].widget);
624 else {
625 panel_update_cols (panels [index].widget, frame_half);
627 /* In case of an Hex Quick View must review line length */
628 if (get_display_type (index) == view_quick)
629 view_update_bytes_per_line ((WView *) panels [index].widget);
633 void
634 setup_panels (void)
636 int start_y;
637 int promptl; /* the prompt len */
639 if (console_flag) {
640 int minimum;
641 if (output_lines < 0)
642 output_lines = 0;
643 height = LINES - keybar_visible - command_prompt - menubar_visible
644 - output_lines - message_visible;
645 if (message_visible && xterm_hintbar && xterm_flag)
646 height++;
647 minimum = MINHEIGHT * (1 + horizontal_split);
648 if (height < minimum) {
649 output_lines -= minimum - height;
650 height = minimum;
652 } else {
653 height = LINES - menubar_visible - command_prompt -
654 keybar_visible - message_visible;
655 if (message_visible && xterm_hintbar && xterm_flag)
656 height++;
658 check_split ();
659 start_y = menubar_visible;
661 /* The column computing is defered until panel_do_cols */
662 if (horizontal_split) {
663 widget_set_size (panels[0].widget, start_y, 0,
664 first_panel_size, 0);
666 widget_set_size (panels[1].widget, start_y + first_panel_size, 0,
667 height - first_panel_size, 0);
668 } else {
669 int first_x = first_panel_size;
671 widget_set_size (panels[0].widget, start_y, 0, height, 0);
673 widget_set_size (panels[1].widget, start_y, first_x, height, 0);
676 panel_do_cols (0);
677 panel_do_cols (1);
679 promptl = strlen (prompt);
681 widget_set_size (&the_menubar->widget, 0, 0, 1, COLS);
683 if (command_prompt) {
684 widget_set_size (&cmdline->widget, LINES - 1 - keybar_visible,
685 promptl, 1,
686 COLS - promptl - (keybar_visible ? 0 : 1));
687 winput_set_origin (cmdline, promptl,
688 COLS - promptl - (keybar_visible ? 0 : 1));
689 widget_set_size (&the_prompt->widget, LINES - 1 - keybar_visible,
690 0, 1, promptl);
691 } else {
692 widget_set_size (&cmdline->widget, 0, 0, 0, 0);
693 winput_set_origin (cmdline, 0, 0);
694 widget_set_size (&the_prompt->widget, LINES, COLS, 0, 0);
697 widget_set_size (&the_bar->widget, LINES - 1, 0, keybar_visible, COLS);
698 the_bar->visible = keybar_visible;
700 /* Output window */
701 if (console_flag && output_lines) {
702 output_start_y = LINES - command_prompt - keybar_visible -
703 output_lines;
704 show_console_contents (output_start_y,
705 LINES - output_lines - keybar_visible - 1,
706 LINES - keybar_visible - 1);
708 if (message_visible && (!xterm_hintbar || !xterm_flag))
709 widget_set_size (&the_hint->widget, height + start_y, 0, 1, COLS);
710 else
711 widget_set_size (&the_hint->widget, 0, 0, 0, 0);
713 load_hint ();
716 void flag_winch (int dummy)
718 #ifndef USE_NCURSES /* don't do malloc in a signal handler */
719 low_level_change_screen_size ();
720 #endif
721 winch_flag = 1;
724 static void
725 low_level_change_screen_size (void)
727 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
728 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
729 struct winsize winsz;
731 winsz.ws_col = winsz.ws_row = 0;
732 /* Ioctl on the STDIN_FILENO */
733 ioctl (0, TIOCGWINSZ, &winsz);
734 if (winsz.ws_col && winsz.ws_row){
735 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
736 resizeterm(winsz.ws_row, winsz.ws_col);
737 clearok(stdscr,TRUE); /* sigwinch's should use a semaphore! */
738 #else
739 COLS = winsz.ws_col;
740 LINES = winsz.ws_row;
741 #endif
742 #ifdef HAVE_SUBSHELL_SUPPORT
743 resize_subshell ();
744 #endif
746 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
747 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
750 void
751 change_screen_size (void)
753 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
754 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
756 #ifndef NCURSES_VERSION
757 mc_noraw_mode ();
758 endwin ();
759 #endif
760 low_level_change_screen_size ();
761 check_split ();
762 #ifndef NCURSES_VERSION
763 /* XSI Curses spec states that portable applications shall not invoke
764 * initscr() more than once. This kludge could be done within the scope
765 * of the specification by using endwin followed by a refresh (in fact,
766 * more than one curses implementation does this); it is guaranteed to work
767 * only with slang.
769 init_curses ();
770 #endif
771 setup_panels ();
773 /* Inform currently running dialog */
774 (*current_dlg->callback) (current_dlg, current_dlg->current->dlg_id,
775 DLG_RESIZE);
777 #ifdef RESIZABLE_MENUBAR
778 menubar_arrange (the_menubar);
779 #endif
781 /* Now, force the redraw */
782 do_refresh ();
783 touchwin (stdscr);
784 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
785 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
786 winch_flag = 0;
789 static int ok_to_refresh = 1;
791 void use_dash (int flag)
793 if (flag)
794 ok_to_refresh++;
795 else
796 ok_to_refresh--;
799 void set_hintbar(char *str)
801 if (xterm_flag && xterm_hintbar) {
802 fprintf (stdout, "\33]0;mc - %s\7", str);
803 fflush (stdout);
804 } else {
805 label_set_text (the_hint, str);
806 if (ok_to_refresh > 0)
807 refresh();
811 void print_vfs_message (char *msg, ...)
813 va_list ap;
814 char str [128];
816 va_start (ap, msg);
818 g_vsnprintf (str, sizeof (str), msg, ap);
819 va_end (ap);
821 if (midnight_shutdown)
822 return;
824 if (!message_visible || !the_hint || !the_hint->widget.parent) {
826 if (!nice_rotating_dash || (ok_to_refresh <= 0))
827 return;
828 move (0, 0);
829 attrset (NORMAL_COLOR);
830 printw ("%-*s", COLS-1, str);
831 mc_refresh ();
832 return;
835 if (message_visible || (xterm_flag && xterm_hintbar)) {
836 set_hintbar(str);
840 void rotate_dash (void)
842 static char rotating_dash [] = "|/-\\";
843 static int pos = 0;
845 if (!nice_rotating_dash || (ok_to_refresh <= 0))
846 return;
848 if (pos >= sizeof (rotating_dash)-1)
849 pos = 0;
850 move (0, COLS-1);
851 addch (rotating_dash [pos]);
852 mc_refresh ();
853 pos++;
856 void remove_dash (void)
858 if (!nice_rotating_dash)
859 return;
861 /* Currently, it's much nicer with the CPU to do this instead of
862 calling do_refresh.
864 I should implement a routine called invalidate_region that would
865 send a draw message only to the affected views. But for now
866 this is fine.
869 move (0, COLS-1);
870 addch (' ');
873 char *get_nth_panel_name (int num)
875 static char buffer [BUF_SMALL];
877 if (!num)
878 return "New Left Panel";
879 else if (num == 1)
880 return "New Right Panel";
881 else {
882 g_snprintf (buffer, sizeof (buffer), "%ith Panel", num);
883 return buffer;
887 /* I wonder if I should start to use the folding mode than Dugan uses */
888 /* */
889 /* This is the centralized managing of the panel display types */
890 /* This routine takes care of destroying and creating new widgets */
891 /* Please note that it could manage MAX_VIEWS, not just left and right */
892 /* Currently nothing in the code takes advantage of this and has hard- */
893 /* coded values for two panels only */
895 /* Set the num-th panel to the view type: type */
896 /* This routine also keeps at least one WPanel object in the screen */
897 /* since a lot of routines depend on the current_panel variable */
898 void set_display_type (int num, int type)
900 int x, y, cols, lines;
901 int the_other; /* Index to the other panel */
902 char *file_name = 0; /* For Quick view */
903 Widget *new_widget, *old_widget;
904 WPanel *the_other_panel;
906 x = y = cols = lines = 0;
907 old_widget = 0;
908 if (num >= MAX_VIEWS){
909 fprintf (stderr, "Could not allocate more that %d views\n", MAX_VIEWS);
910 abort ();
913 /* Check that we will have a WPanel * at least */
914 the_other = 0;
915 if (type != view_listing){
916 the_other = num == 0 ? 1 : 0;
918 if (panels [the_other].type != view_listing)
919 return;
923 /* Get rid of it */
924 if (panels [num].widget){
925 Widget *w = panels [num].widget;
926 WPanel *panel = (WPanel *) panels [num].widget;
928 x = w->x;
929 y = w->y;
930 cols = w->cols;
931 lines = w->lines;
932 old_widget = panels [num].widget;
934 if (panels [num].type == view_listing){
935 if (panel->frame_size == frame_full && type != view_listing){
936 cols = COLS - first_panel_size;
937 if (num == 1)
938 x = first_panel_size;
943 new_widget = 0;
945 switch (type){
946 case view_listing:
947 new_widget = (Widget *) panel_new (get_nth_panel_name (num));
948 break;
950 case view_info:
951 new_widget = (Widget *) info_new ();
953 break;
955 case view_tree:
956 new_widget = (Widget *) tree_new (1, 0, 0, 0, 0);
957 break;
959 case view_quick:
960 new_widget = (Widget *) view_new (0, 0, 0, 0, 1);
961 the_other_panel = (WPanel *) panels [the_other].widget;
962 if (the_other_panel)
963 file_name =
964 the_other_panel->dir.list[the_other_panel->selected].fname;
965 else
966 file_name = "";
968 view_init ((WView *) new_widget, 0, file_name, 0);
969 break;
971 panels [num].type = type;
972 panels [num].widget = (Widget *) new_widget;
974 /* We set the same size the old widget had */
975 widget_set_size ((Widget *) new_widget, y, x, lines, cols);
977 /* We use replace to keep the circular list of the dialog in the */
978 /* same state. Maybe we could just kill it and then replace it */
979 if (midnight_dlg && old_widget){
980 dlg_replace_widget (midnight_dlg, old_widget, panels [num].widget);
982 if (type == view_listing){
983 if (num == 0)
984 left_panel = (WPanel *) new_widget;
985 else
986 right_panel = (WPanel *) new_widget;
989 if (type == view_tree)
990 the_tree = (WTree *) new_widget;
992 /* Prevent current_panel's value from becoming invalid.
993 * It's just a quick hack to prevent segfaults. Comment out and
994 * try following:
995 * - select left panel
996 * - invoke menue left/tree
997 * - as long as you stay in the left panel almost everything that uses
998 * cpanel causes segfault, e.g. C-Enter, C-x c, ...
1001 if (type != view_listing)
1002 if (cpanel == (WPanel *) old_widget)
1003 current_panel = num == 0 ? right_panel : left_panel;
1006 /* This routine is deeply sticked to the two panels idea.
1007 What should it do in more panels. ANSWER - don't use it
1008 in any multiple panels environment. */
1009 void swap_panels ()
1011 Widget tmp;
1012 Widget *tmp_widget;
1013 WPanel panel;
1014 WPanel *panel1, *panel2;
1015 int tmp_type;
1017 #define panelswap(x) panel. x = panel1-> x; panel1-> x = panel2-> x; panel2-> x = panel. x;
1019 #define panelswapstr(e) strcpy (panel. e, panel1-> e); \
1020 strcpy (panel1-> e, panel2-> e); \
1021 strcpy (panel2-> e, panel. e);
1022 panel1 = (WPanel *) panels [0].widget;
1023 panel2 = (WPanel *) panels [1].widget;
1024 if (panels [0].type == view_listing && panels [1].type == view_listing) {
1025 /* Change everything except format/sort/panel_name etc. */
1026 panelswap (dir);
1027 panelswap (active);
1028 panelswapstr (cwd);
1029 panelswapstr (lwd);
1030 panelswap (count);
1031 panelswap (marked);
1032 panelswap (dirs_marked);
1033 panelswap (total);
1034 panelswap (top_file);
1035 panelswap (selected);
1036 panelswap (is_panelized);
1037 panelswap (dir_stat);
1039 panel1->searching = 0;
1040 panel2->searching = 0;
1041 if (cpanel == panel1)
1042 current_panel = panel2;
1043 else
1044 current_panel = panel1;
1045 if (midnight_dlg->current->widget == panels [0].widget)
1046 dlg_select_widget (midnight_dlg, (void *) panels [1].widget);
1047 else if (midnight_dlg->current->widget == panels [1].widget)
1048 dlg_select_widget (midnight_dlg, (void *) panels [0].widget);
1049 } else {
1050 WPanel *tmp_panel;
1052 tmp_panel=right_panel;
1053 right_panel=left_panel;
1054 left_panel=tmp_panel;
1056 if (panels [0].type == view_listing) {
1057 if (!strcmp (panel1->panel_name, get_nth_panel_name (0))) {
1058 g_free (panel1->panel_name);
1059 panel1->panel_name = g_strdup (get_nth_panel_name (1));
1062 if (panels [1].type == view_listing) {
1063 if (!strcmp (panel2->panel_name, get_nth_panel_name (1))) {
1064 g_free (panel2->panel_name);
1065 panel2->panel_name = g_strdup (get_nth_panel_name (0));
1069 tmp.x = panels [0].widget->x;
1070 tmp.y = panels [0].widget->y;
1071 tmp.cols = panels [0].widget->cols;
1072 tmp.lines = panels [0].widget->lines;
1074 panels [0].widget->x = panels [1].widget->x;
1075 panels [0].widget->y = panels [1].widget->y;
1076 panels [0].widget->cols = panels [1].widget->cols;
1077 panels [0].widget->lines = panels [1].widget->lines;
1079 panels [1].widget->x = tmp.x;
1080 panels [1].widget->y = tmp.y;
1081 panels [1].widget->cols = tmp.cols;
1082 panels [1].widget->lines = tmp.lines;
1084 tmp_widget = panels [0].widget;
1085 panels [0].widget = panels [1].widget;
1086 panels [1].widget = tmp_widget;
1087 tmp_type = panels [0].type;
1088 panels [0].type = panels [1].type;
1089 panels [1].type = tmp_type;
1093 int get_display_type (int index)
1095 return panels [index].type;
1098 Widget *get_panel_widget (int index)
1100 return panels [index].widget;
1103 int get_current_index (void)
1105 if (panels [0].widget == ((Widget *) cpanel))
1106 return 0;
1107 else
1108 return 1;
1111 int get_other_index (void)
1113 return !get_current_index ();
1116 /* Returns the view type for the current panel/view */
1117 int get_current_type (void)
1119 if (panels [0].widget == (Widget *) cpanel)
1120 return panels [0].type;
1121 else
1122 return panels [1].type;
1125 /* Returns the view type of the unselected panel */
1126 int get_other_type (void)
1128 if (panels [0].widget == (Widget *) cpanel)
1129 return panels [1].type;
1130 else
1131 return panels [0].type;