mandriva: Srpm support for extfs
[midnight-commander.git] / src / layout.c
blob99c4862625895dee69390583bc916b43a98114a7
1 /* Panel layout module for the Midnight Commander
2 Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007 Free Software Foundation, Inc.
5 Written: 1995 Janne Kukonlehto
6 1995 Miguel de Icaza
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <config.h>
25 #include <signal.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <string.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
34 * If TIOCGWINSZ supported, make it available here, because window-
35 * resizing code depends on it...
37 #ifdef HAVE_SYS_IOCTL_H
38 # include <sys/ioctl.h>
39 #endif
40 #ifdef HAVE_TERMIOS_H
41 #include <termios.h>
42 #endif
43 #include <unistd.h>
45 #include "global.h"
46 #include "tty.h" /* COLS */
47 #include "win.h"
48 #include "color.h"
49 #include "key.h"
50 #include "dialog.h"
51 #include "widget.h"
52 #include "command.h"
53 #include "profile.h" /* For sync_profiles() */
54 #include "mouse.h"
55 #include "main-widgets.h"
56 #include "main.h"
57 #include "subshell.h" /* For use_subshell and resize_subshell() */
58 #include "tree.h"
59 #include "menu.h"
61 /* Needed for the extern declarations of integer parameters */
62 #include "dir.h"
63 #include "panel.h" /* The Panel widget */
64 #include "cons.saver.h"
65 #include "layout.h"
66 #include "info.h" /* The Info widget */
67 #include "view.h" /* The view widget */
69 #include "setup.h" /* For save_setup() */
71 /* Controls the display of the rotating dash on the verbose mode */
72 int nice_rotating_dash = 1;
74 /* Set if the panels are split horizontally */
75 int horizontal_split = 0;
77 /* Set if the window has changed it's size */
78 int winch_flag = 0;
80 /* Set if the split is the same */
81 int equal_split = 1;
83 /* First panel size if the panel are not split equally */
84 int first_panel_size = 0;
86 /* The number of output lines shown (if available) */
87 int output_lines = 0;
89 /* Set if the command prompt is to be displayed */
90 int command_prompt = 1;
92 /* Set if the nice and useful keybar is visible */
93 int keybar_visible = 1;
95 /* Set if the nice message (hint) bar is visible */
96 int message_visible = 1;
98 /* Set to show current working dir in xterm window title */
99 int xterm_title = 1;
101 /* Set to show free space on device assigned to current directory */
102 int free_space = 1;
104 /* The starting line for the output of the subprogram */
105 int output_start_y = 0;
107 /* The maximum number of views managed by the set_display_type routine */
108 /* Must be at least two (for current and other). Please note that until */
109 /* Janne gets around this, we will only manage two of them :-) */
110 #define MAX_VIEWS 2
112 static struct {
113 int type;
114 Widget *widget;
115 } panels [MAX_VIEWS];
117 /* These variables are used to avoid updating the information unless */
118 /* we need it */
119 static int old_first_panel_size;
120 static int old_horizontal_split;
121 static int old_output_lines;
123 /* Internal variables */
124 static int _horizontal_split;
125 static int _equal_split;
126 static int _first_panel_size;
127 static int _menubar_visible;
128 static int _output_lines;
129 static int _command_prompt;
130 static int _keybar_visible;
131 static int _message_visible;
132 static int _xterm_title;
133 static int _free_space;
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 const char *s_split_direction [2] = {
153 N_("&Vertical"),
154 N_("&Horizontal")
157 static WRadio *radio_widget;
159 static struct {
160 const char *text;
161 int *variable;
162 WCheck *widget;
163 } check_options [] = {
164 { N_("show free sp&Ace"), &free_space, 0 },
165 { N_("&Xterm window title"), &xterm_title, 0 },
166 { N_("h&Intbar visible"), &message_visible, 0 },
167 { N_("&Keybar visible"), &keybar_visible, 0 },
168 { N_("command &Prompt"), &command_prompt, 0 },
169 { N_("show &Mini status"), &show_mini_info, 0 },
170 { N_("menu&Bar visible"), &menubar_visible, 0 },
171 { N_("&Equal split"), &equal_split, 0 },
172 { N_("pe&Rmissions"), &permission_mode, 0 },
173 { N_("&File types"), &filetype_mode, 0 },
174 { 0, 0, 0 }
177 #define LAYOUT_OPTIONS_COUNT 10
178 #define HIGHLIGHT_OPTIONS_COUNT 2
179 #define SPLIT_OPTIONS_COUNT 1
180 #define OTHER_OPTIONS_COUNT 7
182 static int first_width, second_width;
183 static const char *output_lines_label;
185 static WButton *bleft_widget, *bright_widget;
187 /* Declarations for static functions */
188 static void low_level_change_screen_size (void);
190 static void _check_split (void)
192 if (_horizontal_split){
193 if (_equal_split)
194 _first_panel_size = height / 2;
195 else if (_first_panel_size < MINHEIGHT)
196 _first_panel_size = MINHEIGHT;
197 else if (_first_panel_size > height - MINHEIGHT)
198 _first_panel_size = height - MINHEIGHT;
199 } else {
200 if (_equal_split)
201 _first_panel_size = COLS / 2;
202 else if (_first_panel_size < MINWIDTH)
203 _first_panel_size = MINWIDTH;
204 else if (_first_panel_size > COLS - MINWIDTH)
205 _first_panel_size = COLS - MINWIDTH;
209 static void update_split (void)
211 /* Check split has to be done before testing if it changed, since
212 it can change due to calling _check_split() as well*/
213 _check_split ();
215 /* To avoid setting the cursor to the wrong place */
216 if ((old_first_panel_size == _first_panel_size) &&
217 (old_horizontal_split == _horizontal_split)){
218 return;
221 old_first_panel_size = _first_panel_size;
222 old_horizontal_split = _horizontal_split;
224 attrset (COLOR_NORMAL);
225 dlg_move (layout_dlg, 6, 6);
226 tty_printf ("%03d", _first_panel_size);
227 dlg_move (layout_dlg, 6, 18);
228 if (_horizontal_split)
229 tty_printf ("%03d", height - _first_panel_size);
230 else
231 tty_printf ("%03d", COLS - _first_panel_size);
234 static int b2left_cback (int action)
236 (void) action;
238 if (_equal_split){
239 /* Turn equal split off */
240 _equal_split = 0;
241 check_options [7].widget->state = check_options [7].widget->state & ~C_BOOL;
242 dlg_select_widget (check_options [7].widget);
243 dlg_select_widget (bleft_widget);
245 _first_panel_size++;
246 return 0;
249 static int b2right_cback (int action)
251 (void) action;
253 if (_equal_split){
254 /* Turn equal split off */
255 _equal_split = 0;
256 check_options [7].widget->state = check_options [7].widget->state & ~C_BOOL;
257 dlg_select_widget (check_options [7].widget);
258 dlg_select_widget (bright_widget);
260 _first_panel_size--;
261 return 0;
264 static int bplus_cback (int action)
266 (void) action;
268 if (_output_lines < 99)
269 _output_lines++;
270 return 0;
273 static int bminus_cback (int action)
275 (void) action;
277 if (_output_lines > 0)
278 _output_lines--;
279 return 0;
282 static cb_ret_t
283 layout_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
285 switch (msg) {
286 case DLG_DRAW:
287 /*When repainting the whole dialog (e.g. with C-l) we have to
288 update everything*/
289 common_dialog_repaint (h);
291 old_first_panel_size = -1;
292 old_horizontal_split = -1;
293 old_output_lines = -1;
295 attrset (COLOR_HOT_NORMAL);
296 update_split ();
297 dlg_move (h, 6, 13);
298 addch ('=');
299 if (console_flag){
300 if (old_output_lines != _output_lines){
301 old_output_lines = _output_lines;
302 attrset (COLOR_NORMAL);
303 dlg_move (h, LAYOUT_OPTIONS_COUNT, 16 + first_width);
304 addstr (output_lines_label);
305 dlg_move (h, LAYOUT_OPTIONS_COUNT, 10 + first_width);
306 tty_printf ("%02d", _output_lines);
309 return MSG_HANDLED;
311 case DLG_POST_KEY:
312 _filetype_mode = check_options [9].widget->state & C_BOOL;
313 _permission_mode = check_options [8].widget->state & C_BOOL;
314 _equal_split = check_options [7].widget->state & C_BOOL;
315 _menubar_visible = check_options [6].widget->state & C_BOOL;
316 _command_prompt = check_options [5].widget->state & C_BOOL;
317 _keybar_visible = check_options [3].widget->state & C_BOOL;
318 _message_visible = check_options [2].widget->state & C_BOOL;
319 _xterm_title = check_options [1].widget->state & C_BOOL;
320 _free_space = check_options [0].widget->state & C_BOOL;
321 if (console_flag){
322 int minimum;
323 if (_output_lines < 0)
324 _output_lines = 0;
325 height = LINES - _keybar_visible - _command_prompt -
326 _menubar_visible - _output_lines - _message_visible;
327 minimum = MINHEIGHT * (1 + _horizontal_split);
328 if (height < minimum){
329 _output_lines -= minimum - height;
330 height = minimum;
332 } else {
333 height = LINES - _keybar_visible - _command_prompt -
334 _menubar_visible - _output_lines - _message_visible;
336 if (_horizontal_split != radio_widget->sel){
337 _horizontal_split = radio_widget->sel;
338 if (_horizontal_split)
339 _first_panel_size = height / 2;
340 else
341 _first_panel_size = COLS / 2;
343 update_split ();
344 if (console_flag){
345 if (old_output_lines != _output_lines){
346 old_output_lines = _output_lines;
347 attrset (COLOR_NORMAL);
348 dlg_move (h, LAYOUT_OPTIONS_COUNT, 10 + first_width);
349 tty_printf ("%02d", _output_lines);
352 return MSG_HANDLED;
354 default:
355 return default_dlg_callback (h, msg, parm);
359 static void
360 init_layout (void)
362 static int i18n_layt_flag = 0;
363 static int b1, b2, b3;
364 int i = sizeof (s_split_direction) / sizeof (char *);
365 const char *ok_button = _("&OK");
366 const char *cancel_button = _("&Cancel");
367 const char *save_button = _("&Save");
368 static const char *title1, *title2, *title3;
370 if (!i18n_layt_flag) {
371 size_t l1;
373 first_width = 19; /* length of line with '<' '>' buttons */
375 title1 = _(" Panel split ");
376 title2 = _(" Highlight... ");
377 title3 = _(" Other options ");
378 output_lines_label = _("output lines");
380 while (i--) {
381 s_split_direction[i] = _(s_split_direction[i]);
382 l1 = strlen (s_split_direction[i]) + 7;
383 if (l1 > first_width)
384 first_width = l1;
387 for (i = 0; i < LAYOUT_OPTIONS_COUNT; 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 < OTHER_OPTIONS_COUNT; i++) {
405 check_options[i].text = _(check_options[i].text);
406 l1 = strlen (check_options[i].text) + 7;
407 if (l1 > second_width)
408 second_width = l1;
410 if (console_flag) {
411 l1 = strlen (output_lines_label) + 13;
412 if (l1 > second_width)
413 second_width = l1;
417 * alex@bcs.zp.ua:
418 * To be completely correct, one need to check if the title
419 * does not exceed dialog length and total length of 3 buttons
420 * allows their placement in one row. But assuming this dialog
421 * is wide enough, I don't include such a tests.
423 * Now the last thing to do - properly space buttons...
425 l1 = 11 + strlen (ok_button) /* 14 - all brackets and inner space */
426 +strlen (save_button) /* notice: it is 3 char less because */
427 +strlen (cancel_button); /* of '&' char in button text */
429 i = (first_width + second_width - l1) / 4;
430 b1 = 5 + i;
431 b2 = b1 + strlen (ok_button) + i + 6;
432 b3 = b2 + strlen (save_button) + i + 4;
434 i18n_layt_flag = 1;
437 layout_dlg =
438 create_dlg (0, 0, 15, first_width + second_width + 9,
439 dialog_colors, layout_callback, "[Layout]",
440 _("Layout"), DLG_CENTER | DLG_REVERSE);
442 add_widget (layout_dlg, groupbox_new (4, 2, first_width, 6, title1));
443 add_widget (layout_dlg, groupbox_new (4, 8, first_width, 4, title2));
444 add_widget (layout_dlg,
445 groupbox_new (5 + first_width, 2, second_width, 10,
446 title3));
448 add_widget (layout_dlg,
449 button_new (BY, b3, B_CANCEL, NORMAL_BUTTON, cancel_button,
450 0));
451 add_widget (layout_dlg,
452 button_new (BY, b2, B_EXIT, NORMAL_BUTTON, save_button,
453 0));
454 add_widget (layout_dlg,
455 button_new (BY, b1, B_ENTER, DEFPUSH_BUTTON, ok_button,
456 0));
457 if (console_flag) {
458 add_widget (layout_dlg,
459 button_new (LAYOUT_OPTIONS_COUNT, 12 + first_width, B_MINUS,
460 NARROW_BUTTON, "&-", bminus_cback));
461 add_widget (layout_dlg,
462 button_new (LAYOUT_OPTIONS_COUNT, 7 + first_width, B_PLUS, NARROW_BUTTON,
463 "&+", bplus_cback));
465 #define XTRACT(i) *check_options[i].variable, check_options[i].text
467 for (i = 0; i < OTHER_OPTIONS_COUNT; i++) {
468 check_options[i].widget =
469 check_new (LAYOUT_OPTIONS_COUNT - i - 1, 7 + first_width, XTRACT (i));
470 add_widget (layout_dlg, check_options[i].widget);
472 check_options[9].widget = check_new (10, 6, XTRACT (9));
473 add_widget (layout_dlg, check_options[9].widget);
474 check_options[8].widget = check_new (9, 6, XTRACT (8));
475 add_widget (layout_dlg, check_options[8].widget);
477 _filetype_mode = filetype_mode;
478 _permission_mode = permission_mode;
479 _equal_split = equal_split;
480 _menubar_visible = menubar_visible;
481 _command_prompt = command_prompt;
482 _keybar_visible = keybar_visible;
483 _message_visible = message_visible;
484 _xterm_title = xterm_title;
485 _free_space = free_space;
486 bright_widget =
487 button_new (6, 15, B_2RIGHT, NARROW_BUTTON, "&>", b2right_cback);
488 add_widget (layout_dlg, bright_widget);
489 bleft_widget =
490 button_new (6, 9, B_2LEFT, NARROW_BUTTON, "&<", b2left_cback);
491 add_widget (layout_dlg, bleft_widget);
492 check_options[7].widget = check_new (5, 6, XTRACT (7));
493 old_first_panel_size = -1;
494 old_horizontal_split = -1;
495 old_output_lines = -1;
497 _first_panel_size = first_panel_size;
498 _output_lines = output_lines;
499 add_widget (layout_dlg, check_options[7].widget);
500 radio_widget = radio_new (3, 6, 2, s_split_direction);
501 add_widget (layout_dlg, radio_widget);
502 radio_widget->sel = horizontal_split;
505 static void
506 layout_change (void)
508 setup_panels ();
509 /* re-init the menu, because perhaps there was a change in the way
510 how the panel are split (horizontal/vertical). */
511 done_menu ();
512 init_menu ();
513 menubar_arrange (the_menubar);
516 void layout_cmd (void)
518 int result;
519 int i;
520 int layout_do_change = 0;
522 init_layout ();
523 run_dlg (layout_dlg);
524 result = layout_dlg->ret_value;
526 if (result == B_ENTER || result == B_EXIT){
527 for (i = 0; check_options [i].text; i++)
528 if (check_options [i].widget)
529 *check_options [i].variable = check_options [i].widget->state & C_BOOL;
530 horizontal_split = radio_widget->sel;
531 first_panel_size = _first_panel_size;
532 output_lines = _output_lines;
533 layout_do_change = 1;
535 if (result == B_EXIT){
536 save_layout ();
537 sync_profiles ();
540 destroy_dlg (layout_dlg);
541 if (layout_do_change)
542 layout_change ();
545 static void check_split (void)
547 if (horizontal_split){
548 if (equal_split)
549 first_panel_size = height / 2;
550 else if (first_panel_size < MINHEIGHT)
551 first_panel_size = MINHEIGHT;
552 else if (first_panel_size > height - MINHEIGHT)
553 first_panel_size = height - MINHEIGHT;
554 } else {
555 if (equal_split)
556 first_panel_size = COLS / 2;
557 else if (first_panel_size < MINWIDTH)
558 first_panel_size = MINWIDTH;
559 else if (first_panel_size > COLS - MINWIDTH)
560 first_panel_size = COLS - MINWIDTH;
564 #ifdef HAVE_SLANG
565 void
566 init_curses ()
568 SLsmg_init_smg ();
569 do_enter_ca_mode ();
570 init_colors ();
571 keypad (stdscr, TRUE);
572 nodelay (stdscr, FALSE);
574 #else
575 static const struct {
576 int acscode;
577 int character;
578 } acs_approx [] = {
579 { 'q', '-' }, /* ACS_HLINE */
580 { 'x', '|' }, /* ACS_VLINE */
581 { 'l', '+' }, /* ACS_ULCORNER */
582 { 'k', '+' }, /* ACS_URCORNER */
583 { 'm', '+' }, /* ACS_LLCORNER */
584 { 'j', '+' }, /* ACS_LRCORNER */
585 { 'a', '#' }, /* ACS_CKBOARD */
586 { 'u', '+' }, /* ACS_RTEE */
587 { 't', '+' }, /* ACS_LTEE */
588 { 'w', '+' }, /* ACS_TTEE */
589 { 'v', '+' }, /* ACS_BTEE */
590 { 'n', '+' }, /* ACS_PLUS */
591 { 0, 0 } };
593 void init_curses (void)
595 int i;
596 initscr();
597 #ifdef HAVE_ESCDELAY
599 * If ncurses exports the ESCDELAY variable, it should be set to
600 * a low value, or you'll experience a delay in processing escape
601 * sequences that are recognized by mc (e.g. Esc-Esc). On the other
602 * hand, making ESCDELAY too small can result in some sequences
603 * (e.g. cursor arrows) being reported as separate keys under heavy
604 * processor load, and this can be a problem if mc hasn't learned
605 * them in the "Learn Keys" dialog. The value is in milliseconds.
607 ESCDELAY = 200;
608 #endif /* HAVE_ESCDELAY */
609 do_enter_ca_mode ();
610 mc_raw_mode ();
611 noecho ();
612 keypad (stdscr, TRUE);
613 nodelay (stdscr, FALSE);
614 init_colors ();
615 if (force_ugly_line_drawing) {
616 for (i = 0; acs_approx[i].acscode != 0; i++) {
617 acs_map[acs_approx[i].acscode] = acs_approx[i].character;
621 #endif /* ! HAVE_SLANG */
623 void
624 clr_scr (void)
626 standend ();
627 dlg_erase (midnight_dlg);
628 mc_refresh ();
629 doupdate ();
632 void
633 done_screen ()
635 if (!(quit & SUBSHELL_EXIT))
636 clr_scr ();
637 reset_shell_mode ();
638 mc_noraw_mode ();
639 keypad (stdscr, FALSE);
640 done_colors ();
643 static void
644 panel_do_cols (int index)
646 if (get_display_type (index) == view_listing)
647 set_panel_formats ((WPanel *) panels [index].widget);
648 else {
649 panel_update_cols (panels [index].widget, frame_half);
653 void
654 setup_panels (void)
656 int start_y;
657 int promptl; /* the prompt len */
659 if (console_flag) {
660 int minimum;
661 if (output_lines < 0)
662 output_lines = 0;
663 height =
664 LINES - keybar_visible - command_prompt - menubar_visible -
665 output_lines - message_visible;
666 minimum = MINHEIGHT * (1 + horizontal_split);
667 if (height < minimum) {
668 output_lines -= minimum - height;
669 height = minimum;
671 } else {
672 height =
673 LINES - menubar_visible - command_prompt - keybar_visible -
674 message_visible;
676 check_split ();
677 start_y = menubar_visible;
679 /* The column computing is defered until panel_do_cols */
680 if (horizontal_split) {
681 widget_set_size (panels[0].widget, start_y, 0, first_panel_size,
684 widget_set_size (panels[1].widget, start_y + first_panel_size, 0,
685 height - first_panel_size, 0);
686 } else {
687 int first_x = first_panel_size;
689 widget_set_size (panels[0].widget, start_y, 0, height, 0);
691 widget_set_size (panels[1].widget, start_y, first_x, height, 0);
694 panel_do_cols (0);
695 panel_do_cols (1);
697 promptl = strlen (prompt);
699 widget_set_size (&the_menubar->widget, 0, 0, 1, COLS);
701 if (command_prompt) {
702 widget_set_size (&cmdline->widget, LINES - 1 - keybar_visible,
703 promptl, 1,
704 COLS - promptl - (keybar_visible ? 0 : 1));
705 winput_set_origin (cmdline, promptl,
706 COLS - promptl - (keybar_visible ? 0 : 1));
707 widget_set_size (&the_prompt->widget, LINES - 1 - keybar_visible,
708 0, 1, promptl);
709 } else {
710 widget_set_size (&cmdline->widget, 0, 0, 0, 0);
711 winput_set_origin (cmdline, 0, 0);
712 widget_set_size (&the_prompt->widget, LINES, COLS, 0, 0);
715 widget_set_size ((Widget *) the_bar, LINES - 1, 0, keybar_visible, COLS);
716 buttonbar_set_visible (the_bar, keybar_visible);
718 /* Output window */
719 if (console_flag && output_lines) {
720 output_start_y =
721 LINES - command_prompt - keybar_visible - output_lines;
722 show_console_contents (output_start_y,
723 LINES - output_lines - keybar_visible - 1,
724 LINES - keybar_visible - 1);
726 if (message_visible) {
727 widget_set_size (&the_hint->widget, height + start_y, 0, 1, COLS);
728 set_hintbar (""); /* clean up the line */
729 } else
730 widget_set_size (&the_hint->widget, 0, 0, 0, 0);
732 load_hint (1);
733 update_xterm_title_path ();
736 void flag_winch (int dummy)
738 (void) dummy;
739 #ifndef USE_NCURSES /* don't do malloc in a signal handler */
740 low_level_change_screen_size ();
741 #endif
742 winch_flag = 1;
745 static void
746 low_level_change_screen_size (void)
748 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
749 #if defined TIOCGWINSZ
750 struct winsize winsz;
752 winsz.ws_col = winsz.ws_row = 0;
753 /* Ioctl on the STDIN_FILENO */
754 ioctl (0, TIOCGWINSZ, &winsz);
755 if (winsz.ws_col && winsz.ws_row){
756 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
757 resizeterm(winsz.ws_row, winsz.ws_col);
758 clearok(stdscr,TRUE); /* sigwinch's should use a semaphore! */
759 #else
760 COLS = winsz.ws_col;
761 LINES = winsz.ws_row;
762 #endif
763 #ifdef HAVE_SUBSHELL_SUPPORT
764 resize_subshell ();
765 #endif
767 #endif /* TIOCGWINSZ */
768 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
771 void
772 change_screen_size (void)
774 winch_flag = 0;
775 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
776 #if defined TIOCGWINSZ
778 #ifndef NCURSES_VERSION
779 mc_noraw_mode ();
780 endwin ();
781 #endif
782 low_level_change_screen_size ();
783 check_split ();
784 #ifndef NCURSES_VERSION
785 /* XSI Curses spec states that portable applications shall not invoke
786 * initscr() more than once. This kludge could be done within the scope
787 * of the specification by using endwin followed by a refresh (in fact,
788 * more than one curses implementation does this); it is guaranteed to work
789 * only with slang.
791 init_curses ();
792 #endif
793 setup_panels ();
795 /* Inform currently running dialog */
796 (*current_dlg->callback) (current_dlg, DLG_RESIZE, 0);
798 #ifdef RESIZABLE_MENUBAR
799 menubar_arrange (the_menubar);
800 #endif
802 /* Now, force the redraw */
803 do_refresh ();
804 touchwin (stdscr);
805 #endif /* TIOCGWINSZ */
806 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
809 static int ok_to_refresh = 1;
811 void use_dash (int flag)
813 if (flag)
814 ok_to_refresh++;
815 else
816 ok_to_refresh--;
819 void set_hintbar(const char *str)
821 label_set_text (the_hint, str);
822 if (ok_to_refresh > 0)
823 refresh();
826 void print_vfs_message (const char *msg, ...)
828 va_list ap;
829 char str [128];
831 va_start (ap, msg);
833 g_vsnprintf (str, sizeof (str), msg, ap);
834 va_end (ap);
836 if (midnight_shutdown)
837 return;
839 if (!message_visible || !the_hint || !the_hint->widget.parent) {
840 int col, row;
842 if (!nice_rotating_dash || (ok_to_refresh <= 0))
843 return;
845 /* Preserve current cursor position */
846 getyx (stdscr, row, col);
848 move (0, 0);
849 attrset (NORMAL_COLOR);
850 tty_printf ("%-*s", COLS-1, str);
852 /* Restore cursor position */
853 move(row, col);
854 mc_refresh ();
855 return;
858 if (message_visible) {
859 set_hintbar(str);
863 void rotate_dash (void)
865 static const char rotating_dash [] = "|/-\\";
866 static size_t pos = 0;
868 if (!nice_rotating_dash || (ok_to_refresh <= 0))
869 return;
871 if (pos >= sizeof (rotating_dash)-1)
872 pos = 0;
873 move (0, COLS-1);
874 attrset (NORMAL_COLOR);
875 addch (rotating_dash [pos]);
876 mc_refresh ();
877 pos++;
880 const char *get_nth_panel_name (int num)
882 static char buffer [BUF_SMALL];
884 if (!num)
885 return "New Left Panel";
886 else if (num == 1)
887 return "New Right Panel";
888 else {
889 g_snprintf (buffer, sizeof (buffer), "%ith Panel", num);
890 return buffer;
894 /* I wonder if I should start to use the folding mode than Dugan uses */
895 /* */
896 /* This is the centralized managing of the panel display types */
897 /* This routine takes care of destroying and creating new widgets */
898 /* Please note that it could manage MAX_VIEWS, not just left and right */
899 /* Currently nothing in the code takes advantage of this and has hard- */
900 /* coded values for two panels only */
902 /* Set the num-th panel to the view type: type */
903 /* This routine also keeps at least one WPanel object in the screen */
904 /* since a lot of routines depend on the current_panel variable */
905 void set_display_type (int num, int type)
907 int x, y, cols, lines;
908 int the_other; /* Index to the other panel */
909 const char *file_name = NULL; /* For Quick view */
910 Widget *new_widget, *old_widget;
911 WPanel *the_other_panel;
913 x = y = cols = lines = 0;
914 old_widget = 0;
915 if (num >= MAX_VIEWS){
916 fprintf (stderr, "Cannot allocate more that %d views\n", MAX_VIEWS);
917 abort ();
920 /* Check that we will have a WPanel * at least */
921 the_other = 0;
922 if (type != view_listing){
923 the_other = num == 0 ? 1 : 0;
925 if (panels [the_other].type != view_listing)
926 return;
930 /* Get rid of it */
931 if (panels [num].widget){
932 Widget *w = panels [num].widget;
933 WPanel *panel = (WPanel *) panels [num].widget;
935 x = w->x;
936 y = w->y;
937 cols = w->cols;
938 lines = w->lines;
939 old_widget = panels [num].widget;
941 if (panels [num].type == view_listing){
942 if (panel->frame_size == frame_full && type != view_listing){
943 cols = COLS - first_panel_size;
944 if (num == 1)
945 x = first_panel_size;
950 new_widget = 0;
952 switch (type){
953 case view_listing:
954 new_widget = (Widget *) panel_new (get_nth_panel_name (num));
955 break;
957 case view_info:
958 new_widget = (Widget *) info_new ();
960 break;
962 case view_tree:
963 new_widget = (Widget *) tree_new (1, 0, 0, 0, 0);
964 break;
966 case view_quick:
967 new_widget = (Widget *) view_new (0, 0, 0, 0, 1);
968 the_other_panel = (WPanel *) panels [the_other].widget;
969 if (the_other_panel)
970 file_name =
971 the_other_panel->dir.list[the_other_panel->selected].fname;
972 else
973 file_name = "";
975 view_load ((WView *) new_widget, 0, file_name, 0);
976 break;
978 panels [num].type = type;
979 panels [num].widget = (Widget *) new_widget;
981 /* We set the same size the old widget had */
982 widget_set_size ((Widget *) new_widget, y, x, lines, cols);
984 /* We use replace to keep the circular list of the dialog in the */
985 /* same state. Maybe we could just kill it and then replace it */
986 if (midnight_dlg && old_widget){
987 dlg_replace_widget (old_widget, panels [num].widget);
989 if (type == view_listing){
990 if (num == 0)
991 left_panel = (WPanel *) new_widget;
992 else
993 right_panel = (WPanel *) new_widget;
996 if (type == view_tree)
997 the_tree = (WTree *) new_widget;
999 /* Prevent current_panel's value from becoming invalid.
1000 * It's just a quick hack to prevent segfaults. Comment out and
1001 * try following:
1002 * - select left panel
1003 * - invoke menue left/tree
1004 * - as long as you stay in the left panel almost everything that uses
1005 * current_panel causes segfault, e.g. C-Enter, C-x c, ...
1008 if (type != view_listing)
1009 if (current_panel == (WPanel *) old_widget)
1010 current_panel = num == 0 ? right_panel : left_panel;
1013 /* This routine is deeply sticked to the two panels idea.
1014 What should it do in more panels. ANSWER - don't use it
1015 in any multiple panels environment. */
1016 void swap_panels ()
1018 Widget tmp;
1019 Widget *tmp_widget;
1020 WPanel panel;
1021 WPanel *panel1, *panel2;
1022 int tmp_type;
1024 #define panelswap(x) panel. x = panel1-> x; panel1-> x = panel2-> x; panel2-> x = panel. x;
1026 #define panelswapstr(e) strcpy (panel. e, panel1-> e); \
1027 strcpy (panel1-> e, panel2-> e); \
1028 strcpy (panel2-> e, panel. e);
1029 panel1 = (WPanel *) panels [0].widget;
1030 panel2 = (WPanel *) panels [1].widget;
1031 if (panels [0].type == view_listing && panels [1].type == view_listing) {
1032 /* Change everything except format/sort/panel_name etc. */
1033 panelswap (dir);
1034 panelswap (active);
1035 panelswapstr (cwd);
1036 panelswapstr (lwd);
1037 panelswap (count);
1038 panelswap (marked);
1039 panelswap (dirs_marked);
1040 panelswap (total);
1041 panelswap (top_file);
1042 panelswap (selected);
1043 panelswap (is_panelized);
1044 panelswap (dir_stat);
1046 panel1->searching = 0;
1047 panel2->searching = 0;
1048 if (current_panel == panel1)
1049 current_panel = panel2;
1050 else
1051 current_panel = panel1;
1053 if (dlg_widget_active (panels[0].widget))
1054 dlg_select_widget (panels [1].widget);
1055 else if (dlg_widget_active (panels[1].widget))
1056 dlg_select_widget (panels [0].widget);
1057 } else {
1058 WPanel *tmp_panel;
1060 tmp_panel=right_panel;
1061 right_panel=left_panel;
1062 left_panel=tmp_panel;
1064 if (panels [0].type == view_listing) {
1065 if (!strcmp (panel1->panel_name, get_nth_panel_name (0))) {
1066 g_free (panel1->panel_name);
1067 panel1->panel_name = g_strdup (get_nth_panel_name (1));
1070 if (panels [1].type == view_listing) {
1071 if (!strcmp (panel2->panel_name, get_nth_panel_name (1))) {
1072 g_free (panel2->panel_name);
1073 panel2->panel_name = g_strdup (get_nth_panel_name (0));
1077 tmp.x = panels [0].widget->x;
1078 tmp.y = panels [0].widget->y;
1079 tmp.cols = panels [0].widget->cols;
1080 tmp.lines = panels [0].widget->lines;
1082 panels [0].widget->x = panels [1].widget->x;
1083 panels [0].widget->y = panels [1].widget->y;
1084 panels [0].widget->cols = panels [1].widget->cols;
1085 panels [0].widget->lines = panels [1].widget->lines;
1087 panels [1].widget->x = tmp.x;
1088 panels [1].widget->y = tmp.y;
1089 panels [1].widget->cols = tmp.cols;
1090 panels [1].widget->lines = tmp.lines;
1092 tmp_widget = panels [0].widget;
1093 panels [0].widget = panels [1].widget;
1094 panels [1].widget = tmp_widget;
1095 tmp_type = panels [0].type;
1096 panels [0].type = panels [1].type;
1097 panels [1].type = tmp_type;
1101 int get_display_type (int index)
1103 return panels [index].type;
1106 struct Widget *
1107 get_panel_widget (int index)
1109 return panels[index].widget;
1112 int get_current_index (void)
1114 if (panels [0].widget == ((Widget *) current_panel))
1115 return 0;
1116 else
1117 return 1;
1120 int get_other_index (void)
1122 return !get_current_index ();
1125 struct WPanel *
1126 get_other_panel (void)
1128 return (struct WPanel *) get_panel_widget (get_other_index ());
1131 /* Returns the view type for the current panel/view */
1132 int get_current_type (void)
1134 if (panels [0].widget == (Widget *) current_panel)
1135 return panels [0].type;
1136 else
1137 return panels [1].type;
1140 /* Returns the view type of the unselected panel */
1141 int get_other_type (void)
1143 if (panels [0].widget == (Widget *) current_panel)
1144 return panels [1].type;
1145 else
1146 return panels [0].type;