Updated italian translation
[midnight-commander.git] / src / layout.c
blob5832a04cff15eeb58d21827d4e5b57dcb80d7882
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include <config.h>
24 #include <signal.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <string.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
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_TERMIOS_H
39 #include <termios.h>
40 #endif
41 #include <unistd.h>
43 #include "global.h"
44 #include "tty.h" /* COLS */
45 #include "win.h"
46 #include "color.h"
47 #include "key.h"
48 #include "dialog.h"
49 #include "widget.h"
50 #include "command.h"
51 #include "profile.h" /* For sync_profiles() */
52 #include "mouse.h"
53 #define WANT_WIDGETS
54 #include "main.h"
55 #include "subshell.h" /* For use_subshell and resize_subshell() */
56 #include "tree.h"
57 #include "menu.h"
59 /* Needed for the extern declarations of integer parameters */
60 #include "dir.h"
61 #include "panel.h" /* The Panel widget */
62 #include "cons.saver.h"
63 #include "layout.h"
64 #include "info.h" /* The Info widget */
65 #include "view.h" /* The view widget */
67 #include "setup.h" /* For save_setup() */
69 /* Controls the display of the rotating dash on the verbose mode */
70 int nice_rotating_dash = 1;
72 /* If set, then we have to call the layout_change routine from main */
73 static int layout_do_change = 0;
75 /* Set if the panels are split horizontally */
76 int horizontal_split = 0;
78 /* Set if the window has changed it's size */
79 int winch_flag = 0;
81 /* Set if the split is the same */
82 int equal_split = 1;
84 /* First panel size if the panel are not split equally */
85 int first_panel_size = 0;
87 /* The number of output lines shown (if available) */
88 int output_lines = 0;
90 /* Set if the command prompt is to be displayed */
91 int command_prompt = 1;
93 /* Set if the nice and useful keybar is visible */
94 int keybar_visible = 1;
96 /* Set if the nice message (hint) bar is visible */
97 int message_visible = 1;
99 /* Set to show current working dir in xterm window title */
100 int xterm_title = 1;
102 /* The starting line for the output of the subprogram */
103 int output_start_y = 0;
105 /* The maximum number of views managed by the set_display_type routine */
106 /* Must be at least two (for current and other). Please note that until */
107 /* Janne gets around this, we will only manage two of them :-) */
108 #define MAX_VIEWS 2
110 static struct {
111 int type;
112 Widget *widget;
113 } panels [MAX_VIEWS];
115 /* These variables are used to avoid updating the information unless */
116 /* we need it */
117 static int old_first_panel_size;
118 static int old_horizontal_split;
119 static int old_output_lines;
121 /* Internal variables */
122 static int _horizontal_split;
123 static int _equal_split;
124 static int _first_panel_size;
125 static int _menubar_visible;
126 static int _output_lines;
127 static int _command_prompt;
128 static int _keybar_visible;
129 static int _message_visible;
130 static int _xterm_title;
131 static int _permission_mode;
132 static int _filetype_mode;
134 static int height;
136 /* Width 12 for a wee Quick (Hex) View */
137 #define MINWIDTH 12
138 #define MINHEIGHT 5
140 #define BY 12
142 #define B_2LEFT B_USER
143 #define B_2RIGHT (B_USER + 1)
144 #define B_PLUS (B_USER + 2)
145 #define B_MINUS (B_USER + 3)
147 static Dlg_head *layout_dlg;
149 static const char *s_split_direction [2] = {
150 N_("&Vertical"),
151 N_("&Horizontal")
154 static WRadio *radio_widget;
156 static struct {
157 const char *text;
158 int *variable;
159 WCheck *widget;
160 } check_options [] = {
161 { N_("&Xterm window title"), &xterm_title, 0 },
162 { N_("h&Intbar visible"), &message_visible, 0 },
163 { N_("&Keybar visible"), &keybar_visible, 0 },
164 { N_("command &Prompt"), &command_prompt, 0 },
165 { N_("show &Mini status"), &show_mini_info, 0 },
166 { N_("menu&Bar visible"), &menubar_visible, 0 },
167 { N_("&Equal split"), &equal_split, 0 },
168 { N_("pe&Rmissions"), &permission_mode, 0 },
169 { N_("&File types"), &filetype_mode, 0 },
170 { 0, 0, 0 }
173 static int first_width, second_width;
174 static const char *output_lines_label;
176 static WButton *bleft_widget, *bright_widget;
178 /* Declarations for static functions */
179 static void low_level_change_screen_size (void);
181 static void _check_split (void)
183 if (_horizontal_split){
184 if (_equal_split)
185 _first_panel_size = height / 2;
186 else if (_first_panel_size < MINHEIGHT)
187 _first_panel_size = MINHEIGHT;
188 else if (_first_panel_size > height - MINHEIGHT)
189 _first_panel_size = height - MINHEIGHT;
190 } else {
191 if (_equal_split)
192 _first_panel_size = COLS / 2;
193 else if (_first_panel_size < MINWIDTH)
194 _first_panel_size = MINWIDTH;
195 else if (_first_panel_size > COLS - MINWIDTH)
196 _first_panel_size = COLS - MINWIDTH;
200 static void update_split (void)
202 /* Check split has to be done before testing if it changed, since
203 it can change due to calling _check_split() as well*/
204 _check_split ();
206 /* To avoid setting the cursor to the wrong place */
207 if ((old_first_panel_size == _first_panel_size) &&
208 (old_horizontal_split == _horizontal_split)){
209 return;
212 old_first_panel_size = _first_panel_size;
213 old_horizontal_split = _horizontal_split;
215 attrset (COLOR_NORMAL);
216 dlg_move (layout_dlg, 6, 6);
217 printw ("%03d", _first_panel_size);
218 dlg_move (layout_dlg, 6, 18);
219 if (_horizontal_split)
220 printw ("%03d", height - _first_panel_size);
221 else
222 printw ("%03d", COLS - _first_panel_size);
225 static int b2left_cback (int action)
227 (void) action;
229 if (_equal_split){
230 /* Turn equal split off */
231 _equal_split = 0;
232 check_options [6].widget->state = check_options [6].widget->state & ~C_BOOL;
233 dlg_select_widget (check_options [6].widget);
234 dlg_select_widget (bleft_widget);
236 _first_panel_size++;
237 return 0;
240 static int b2right_cback (int action)
242 (void) action;
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 (check_options [6].widget);
249 dlg_select_widget (bright_widget);
251 _first_panel_size--;
252 return 0;
255 static int bplus_cback (int action)
257 (void) action;
259 if (_output_lines < 99)
260 _output_lines++;
261 return 0;
264 static int bminus_cback (int action)
266 (void) action;
268 if (_output_lines > 0)
269 _output_lines--;
270 return 0;
273 static cb_ret_t
274 layout_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
276 switch (msg) {
277 case DLG_DRAW:
278 /*When repainting the whole dialog (e.g. with C-l) we have to
279 update everything*/
280 common_dialog_repaint (h);
282 old_first_panel_size = -1;
283 old_horizontal_split = -1;
284 old_output_lines = -1;
286 attrset (COLOR_HOT_NORMAL);
287 update_split ();
288 dlg_move (h, 6, 13);
289 addch ('=');
290 if (console_flag){
291 if (old_output_lines != _output_lines){
292 old_output_lines = _output_lines;
293 attrset (COLOR_NORMAL);
294 dlg_move (h, 9, 16 + first_width);
295 addstr (output_lines_label);
296 dlg_move (h, 9, 10 + first_width);
297 printw ("%02d", _output_lines);
300 return MSG_HANDLED;
302 case DLG_POST_KEY:
303 _filetype_mode = check_options [8].widget->state & C_BOOL;
304 _permission_mode = check_options [7].widget->state & C_BOOL;
305 _equal_split = check_options [6].widget->state & C_BOOL;
306 _menubar_visible = check_options [5].widget->state & C_BOOL;
307 _command_prompt = check_options [4].widget->state & C_BOOL;
308 _keybar_visible = check_options [2].widget->state & C_BOOL;
309 _message_visible = check_options [1].widget->state & C_BOOL;
310 _xterm_title = check_options [0].widget->state & C_BOOL;
311 if (console_flag){
312 int minimum;
313 if (_output_lines < 0)
314 _output_lines = 0;
315 height = LINES - _keybar_visible - _command_prompt -
316 _menubar_visible - _output_lines - _message_visible;
317 minimum = MINHEIGHT * (1 + _horizontal_split);
318 if (height < minimum){
319 _output_lines -= minimum - height;
320 height = minimum;
322 } else {
323 height = LINES - _keybar_visible - _command_prompt -
324 _menubar_visible - _output_lines - _message_visible;
326 if (_horizontal_split != radio_widget->sel){
327 _horizontal_split = radio_widget->sel;
328 if (_horizontal_split)
329 _first_panel_size = height / 2;
330 else
331 _first_panel_size = COLS / 2;
333 update_split ();
334 if (console_flag){
335 if (old_output_lines != _output_lines){
336 old_output_lines = _output_lines;
337 attrset (COLOR_NORMAL);
338 dlg_move (h, 9, 10 + first_width);
339 printw ("%02d", _output_lines);
342 return MSG_HANDLED;
344 default:
345 return default_dlg_callback (h, msg, parm);
349 static void
350 init_layout (void)
352 static int i18n_layt_flag = 0;
353 static int b1, b2, b3;
354 int i = sizeof (s_split_direction) / sizeof (char *);
355 const char *ok_button = _("&OK");
356 const char *cancel_button = _("&Cancel");
357 const char *save_button = _("&Save");
358 static const char *title1, *title2, *title3;
360 if (!i18n_layt_flag) {
361 register int l1;
363 first_width = 19; /* length of line with '<' '>' buttons */
365 title1 = _(" Panel split ");
366 title2 = _(" Highlight... ");
367 title3 = _(" Other options ");
368 output_lines_label = _("output lines");
370 while (i--) {
371 s_split_direction[i] = _(s_split_direction[i]);
372 l1 = strlen (s_split_direction[i]) + 7;
373 if (l1 > first_width)
374 first_width = l1;
377 for (i = 0; i <= 8; i++) {
378 check_options[i].text = _(check_options[i].text);
379 l1 = strlen (check_options[i].text) + 7;
380 if (l1 > first_width)
381 first_width = l1;
384 l1 = strlen (title1) + 1;
385 if (l1 > first_width)
386 first_width = l1;
388 l1 = strlen (title2) + 1;
389 if (l1 > first_width)
390 first_width = l1;
393 second_width = strlen (title3) + 1;
394 for (i = 0; i < 6; i++) {
395 check_options[i].text = _(check_options[i].text);
396 l1 = strlen (check_options[i].text) + 7;
397 if (l1 > second_width)
398 second_width = l1;
400 if (console_flag) {
401 l1 = strlen (output_lines_label) + 13;
402 if (l1 > second_width)
403 second_width = l1;
407 * alex@bcs.zp.ua:
408 * To be completely correct, one need to check if the title
409 * does not exceed dialog length and total length of 3 buttons
410 * allows their placement in one row. But assuming this dialog
411 * is wide enough, I don't include such a tests.
413 * Now the last thing to do - properly space buttons...
415 l1 = 11 + strlen (ok_button) /* 14 - all brackets and inner space */
416 +strlen (save_button) /* notice: it is 3 char less because */
417 +strlen (cancel_button); /* of '&' char in button text */
419 i = (first_width + second_width - l1) / 4;
420 b1 = 5 + i;
421 b2 = b1 + strlen (ok_button) + i + 6;
422 b3 = b2 + strlen (save_button) + i + 4;
424 i18n_layt_flag = 1;
427 layout_dlg =
428 create_dlg (0, 0, 15, first_width + second_width + 9,
429 dialog_colors, layout_callback, "[Layout]",
430 _("Layout"), DLG_CENTER | DLG_REVERSE);
432 add_widget (layout_dlg, groupbox_new (4, 2, first_width, 6, title1));
433 add_widget (layout_dlg, groupbox_new (4, 8, first_width, 4, title2));
434 add_widget (layout_dlg,
435 groupbox_new (5 + first_width, 2, second_width, 10,
436 title3));
438 add_widget (layout_dlg,
439 button_new (BY, b3, B_CANCEL, NORMAL_BUTTON, cancel_button,
440 0));
441 add_widget (layout_dlg,
442 button_new (BY, b2, B_EXIT, NORMAL_BUTTON, save_button,
443 0));
444 add_widget (layout_dlg,
445 button_new (BY, b1, B_ENTER, DEFPUSH_BUTTON, ok_button,
446 0));
447 if (console_flag) {
448 add_widget (layout_dlg,
449 button_new (9, 12 + first_width, B_MINUS,
450 NARROW_BUTTON, "&-", bminus_cback));
451 add_widget (layout_dlg,
452 button_new (9, 7 + first_width, B_PLUS, NARROW_BUTTON,
453 "&+", bplus_cback));
455 #define XTRACT(i) *check_options[i].variable, check_options[i].text
457 for (i = 0; i < 6; i++) {
458 check_options[i].widget =
459 check_new (8 - i, 7 + first_width, XTRACT (i));
460 add_widget (layout_dlg, check_options[i].widget);
462 check_options[8].widget = check_new (10, 6, XTRACT (8));
463 add_widget (layout_dlg, check_options[8].widget);
464 check_options[7].widget = check_new (9, 6, XTRACT (7));
465 add_widget (layout_dlg, check_options[7].widget);
467 _filetype_mode = filetype_mode;
468 _permission_mode = permission_mode;
469 _equal_split = equal_split;
470 _menubar_visible = menubar_visible;
471 _command_prompt = command_prompt;
472 _keybar_visible = keybar_visible;
473 _message_visible = message_visible;
474 _xterm_title = xterm_title;
475 bright_widget =
476 button_new (6, 15, B_2RIGHT, NARROW_BUTTON, "&>", b2right_cback);
477 add_widget (layout_dlg, bright_widget);
478 bleft_widget =
479 button_new (6, 9, B_2LEFT, NARROW_BUTTON, "&<", b2left_cback);
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);
490 add_widget (layout_dlg, radio_widget);
491 radio_widget->sel = horizontal_split;
494 static void
495 layout_change (void)
497 setup_panels ();
498 layout_do_change = 0;
499 /* re-init the menu, because perhaps there was a change in the way
500 how the panel are split (horizontal/vertical). */
501 done_menu ();
502 init_menu ();
503 menubar_arrange (the_menubar);
506 void layout_cmd (void)
508 int result;
509 int i;
511 init_layout ();
512 run_dlg (layout_dlg);
513 result = layout_dlg->ret_value;
515 if (result == B_ENTER || result == B_EXIT){
516 for (i = 0; check_options [i].text; i++)
517 if (check_options [i].widget)
518 *check_options [i].variable = check_options [i].widget->state & C_BOOL;
519 horizontal_split = radio_widget->sel;
520 first_panel_size = _first_panel_size;
521 output_lines = _output_lines;
522 layout_do_change = 1;
524 if (result == B_EXIT){
525 save_layout ();
526 sync_profiles ();
529 destroy_dlg (layout_dlg);
530 if (layout_do_change)
531 layout_change ();
534 static void check_split (void)
536 if (horizontal_split){
537 if (equal_split)
538 first_panel_size = height / 2;
539 else if (first_panel_size < MINHEIGHT)
540 first_panel_size = MINHEIGHT;
541 else if (first_panel_size > height - MINHEIGHT)
542 first_panel_size = height - MINHEIGHT;
543 } else {
544 if (equal_split)
545 first_panel_size = COLS / 2;
546 else if (first_panel_size < MINWIDTH)
547 first_panel_size = MINWIDTH;
548 else if (first_panel_size > COLS - MINWIDTH)
549 first_panel_size = COLS - MINWIDTH;
553 #ifdef HAVE_SLANG
554 void
555 init_curses ()
557 #ifndef HAS_ACS_AS_PCCHARS
558 if (force_ugly_line_drawing)
559 SLtt_Has_Alt_Charset = 0;
560 #endif
561 SLsmg_init_smg ();
562 do_enter_ca_mode ();
563 init_colors ();
564 keypad (stdscr, TRUE);
565 nodelay (stdscr, FALSE);
567 #else
568 static const struct {
569 int acscode;
570 int character;
571 } acs_approx [] = {
572 { 'q', '-' }, /* ACS_HLINE */
573 { 'x', '|' }, /* ACS_VLINE */
574 { 'l', '+' }, /* ACS_ULCORNER */
575 { 'k', '+' }, /* ACS_URCORNER */
576 { 'm', '+' }, /* ACS_LLCORNER */
577 { 'j', '+' }, /* ACS_LRCORNER */
578 { 'a', '#' }, /* ACS_CKBOARD */
579 { 'u', '+' }, /* ACS_RTEE */
580 { 't', '+' }, /* ACS_LTEE */
581 { 'w', '+' }, /* ACS_TTEE */
582 { 'v', '+' }, /* ACS_BTEE */
583 { 'n', '+' }, /* ACS_PLUS */
584 { 0, 0 } };
586 void init_curses (void)
588 int i;
589 initscr();
590 #ifdef HAVE_ESCDELAY
592 * If ncurses exports the ESCDELAY variable, it should be set to
593 * a low value, or you'll experience a delay in processing escape
594 * sequences that are recognized by mc (e.g. Esc-Esc). On the other
595 * hand, making ESCDELAY too small can result in some sequences
596 * (e.g. cursor arrows) being reported as separate keys under heavy
597 * processor load, and this can be a problem if mc hasn't learned
598 * them in the "Learn Keys" dialog. The value is in milliseconds.
600 ESCDELAY = 200;
601 #endif /* HAVE_ESCDELAY */
602 do_enter_ca_mode ();
603 mc_raw_mode ();
604 noecho ();
605 keypad (stdscr, TRUE);
606 nodelay (stdscr, FALSE);
607 init_colors ();
608 if (force_ugly_line_drawing) {
609 for (i = 0; acs_approx[i].acscode != 0; i++) {
610 acs_map[acs_approx[i].acscode] = acs_approx[i].character;
614 #endif /* ! HAVE_SLANG */
616 void
617 clr_scr (void)
619 standend ();
620 dlg_erase (midnight_dlg);
621 mc_refresh ();
622 doupdate ();
625 void
626 done_screen ()
628 if (!(quit & SUBSHELL_EXIT))
629 clr_scr ();
630 reset_shell_mode ();
631 mc_noraw_mode ();
632 keypad (stdscr, FALSE);
633 done_colors ();
636 static void
637 panel_do_cols (int index)
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);
646 void
647 setup_panels (void)
649 int start_y;
650 int promptl; /* the prompt len */
652 if (console_flag) {
653 int minimum;
654 if (output_lines < 0)
655 output_lines = 0;
656 height =
657 LINES - keybar_visible - command_prompt - menubar_visible -
658 output_lines - message_visible;
659 minimum = MINHEIGHT * (1 + horizontal_split);
660 if (height < minimum) {
661 output_lines -= minimum - height;
662 height = minimum;
664 } else {
665 height =
666 LINES - menubar_visible - command_prompt - keybar_visible -
667 message_visible;
669 check_split ();
670 start_y = menubar_visible;
672 /* The column computing is defered until panel_do_cols */
673 if (horizontal_split) {
674 widget_set_size (panels[0].widget, start_y, 0, first_panel_size,
677 widget_set_size (panels[1].widget, start_y + first_panel_size, 0,
678 height - first_panel_size, 0);
679 } else {
680 int first_x = first_panel_size;
682 widget_set_size (panels[0].widget, start_y, 0, height, 0);
684 widget_set_size (panels[1].widget, start_y, first_x, height, 0);
687 panel_do_cols (0);
688 panel_do_cols (1);
690 promptl = strlen (prompt);
692 widget_set_size (&the_menubar->widget, 0, 0, 1, COLS);
694 if (command_prompt) {
695 widget_set_size (&cmdline->widget, LINES - 1 - keybar_visible,
696 promptl, 1,
697 COLS - promptl - (keybar_visible ? 0 : 1));
698 winput_set_origin (cmdline, promptl,
699 COLS - promptl - (keybar_visible ? 0 : 1));
700 widget_set_size (&the_prompt->widget, LINES - 1 - keybar_visible,
701 0, 1, promptl);
702 } else {
703 widget_set_size (&cmdline->widget, 0, 0, 0, 0);
704 winput_set_origin (cmdline, 0, 0);
705 widget_set_size (&the_prompt->widget, LINES, COLS, 0, 0);
708 widget_set_size ((Widget *) the_bar, LINES - 1, 0, keybar_visible, COLS);
709 buttonbar_set_visible (the_bar, keybar_visible);
711 /* Output window */
712 if (console_flag && output_lines) {
713 output_start_y =
714 LINES - command_prompt - keybar_visible - output_lines;
715 show_console_contents (output_start_y,
716 LINES - output_lines - keybar_visible - 1,
717 LINES - keybar_visible - 1);
719 if (message_visible) {
720 widget_set_size (&the_hint->widget, height + start_y, 0, 1, COLS);
721 set_hintbar (""); /* clean up the line */
722 } else
723 widget_set_size (&the_hint->widget, 0, 0, 0, 0);
725 load_hint (1);
726 update_xterm_title_path ();
729 void flag_winch (int dummy)
731 (void) dummy;
732 #ifndef USE_NCURSES /* don't do malloc in a signal handler */
733 low_level_change_screen_size ();
734 #endif
735 winch_flag = 1;
738 static void
739 low_level_change_screen_size (void)
741 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
742 #if defined TIOCGWINSZ
743 struct winsize winsz;
745 winsz.ws_col = winsz.ws_row = 0;
746 /* Ioctl on the STDIN_FILENO */
747 ioctl (0, TIOCGWINSZ, &winsz);
748 if (winsz.ws_col && winsz.ws_row){
749 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
750 resizeterm(winsz.ws_row, winsz.ws_col);
751 clearok(stdscr,TRUE); /* sigwinch's should use a semaphore! */
752 #else
753 COLS = winsz.ws_col;
754 LINES = winsz.ws_row;
755 #endif
756 #ifdef HAVE_SUBSHELL_SUPPORT
757 resize_subshell ();
758 #endif
760 #endif /* TIOCGWINSZ */
761 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
764 void
765 change_screen_size (void)
767 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
768 #if defined TIOCGWINSZ
770 #ifndef NCURSES_VERSION
771 mc_noraw_mode ();
772 endwin ();
773 #endif
774 low_level_change_screen_size ();
775 check_split ();
776 #ifndef NCURSES_VERSION
777 /* XSI Curses spec states that portable applications shall not invoke
778 * initscr() more than once. This kludge could be done within the scope
779 * of the specification by using endwin followed by a refresh (in fact,
780 * more than one curses implementation does this); it is guaranteed to work
781 * only with slang.
783 init_curses ();
784 #endif
785 setup_panels ();
787 /* Inform currently running dialog */
788 (*current_dlg->callback) (current_dlg, DLG_RESIZE, 0);
790 #ifdef RESIZABLE_MENUBAR
791 menubar_arrange (the_menubar);
792 #endif
794 /* Now, force the redraw */
795 do_refresh ();
796 touchwin (stdscr);
797 #endif /* TIOCGWINSZ */
798 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
799 winch_flag = 0;
802 static int ok_to_refresh = 1;
804 void use_dash (int flag)
806 if (flag)
807 ok_to_refresh++;
808 else
809 ok_to_refresh--;
812 void set_hintbar(const char *str)
814 label_set_text (the_hint, str);
815 if (ok_to_refresh > 0)
816 refresh();
819 void print_vfs_message (const char *msg, ...)
821 va_list ap;
822 char str [128];
824 va_start (ap, msg);
826 g_vsnprintf (str, sizeof (str), msg, ap);
827 va_end (ap);
829 if (midnight_shutdown)
830 return;
832 if (!message_visible || !the_hint || !the_hint->widget.parent) {
833 int col, row;
835 if (!nice_rotating_dash || (ok_to_refresh <= 0))
836 return;
838 /* Preserve current cursor position */
839 getyx (stdscr, row, col);
841 move (0, 0);
842 attrset (NORMAL_COLOR);
843 printw ("%-*s", COLS-1, str);
845 /* Restore cursor position */
846 move(row, col);
847 mc_refresh ();
848 return;
851 if (message_visible) {
852 set_hintbar(str);
856 void rotate_dash (void)
858 static const char rotating_dash [] = "|/-\\";
859 static size_t pos = 0;
861 if (!nice_rotating_dash || (ok_to_refresh <= 0))
862 return;
864 if (pos >= sizeof (rotating_dash)-1)
865 pos = 0;
866 move (0, COLS-1);
867 attrset (NORMAL_COLOR);
868 addch (rotating_dash [pos]);
869 mc_refresh ();
870 pos++;
873 const 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 const char *file_name = NULL; /* 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, "Cannot 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_load ((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 (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 * current_panel causes segfault, e.g. C-Enter, C-x c, ...
1001 if (type != view_listing)
1002 if (current_panel == (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 (current_panel == panel1)
1042 current_panel = panel2;
1043 else
1044 current_panel = panel1;
1046 if (dlg_widget_active (panels[0].widget))
1047 dlg_select_widget (panels [1].widget);
1048 else if (dlg_widget_active (panels[1].widget))
1049 dlg_select_widget (panels [0].widget);
1050 } else {
1051 WPanel *tmp_panel;
1053 tmp_panel=right_panel;
1054 right_panel=left_panel;
1055 left_panel=tmp_panel;
1057 if (panels [0].type == view_listing) {
1058 if (!strcmp (panel1->panel_name, get_nth_panel_name (0))) {
1059 g_free (panel1->panel_name);
1060 panel1->panel_name = g_strdup (get_nth_panel_name (1));
1063 if (panels [1].type == view_listing) {
1064 if (!strcmp (panel2->panel_name, get_nth_panel_name (1))) {
1065 g_free (panel2->panel_name);
1066 panel2->panel_name = g_strdup (get_nth_panel_name (0));
1070 tmp.x = panels [0].widget->x;
1071 tmp.y = panels [0].widget->y;
1072 tmp.cols = panels [0].widget->cols;
1073 tmp.lines = panels [0].widget->lines;
1075 panels [0].widget->x = panels [1].widget->x;
1076 panels [0].widget->y = panels [1].widget->y;
1077 panels [0].widget->cols = panels [1].widget->cols;
1078 panels [0].widget->lines = panels [1].widget->lines;
1080 panels [1].widget->x = tmp.x;
1081 panels [1].widget->y = tmp.y;
1082 panels [1].widget->cols = tmp.cols;
1083 panels [1].widget->lines = tmp.lines;
1085 tmp_widget = panels [0].widget;
1086 panels [0].widget = panels [1].widget;
1087 panels [1].widget = tmp_widget;
1088 tmp_type = panels [0].type;
1089 panels [0].type = panels [1].type;
1090 panels [1].type = tmp_type;
1094 int get_display_type (int index)
1096 return panels [index].type;
1099 struct Widget *
1100 get_panel_widget (int index)
1102 return panels[index].widget;
1105 int get_current_index (void)
1107 if (panels [0].widget == ((Widget *) current_panel))
1108 return 0;
1109 else
1110 return 1;
1113 int get_other_index (void)
1115 return !get_current_index ();
1118 struct WPanel *
1119 get_other_panel (void)
1121 return (struct WPanel *) get_panel_widget (get_other_index ());
1124 /* Returns the view type for the current panel/view */
1125 int get_current_type (void)
1127 if (panels [0].widget == (Widget *) current_panel)
1128 return panels [0].type;
1129 else
1130 return panels [1].type;
1133 /* Returns the view type of the unselected panel */
1134 int get_other_type (void)
1136 if (panels [0].widget == (Widget *) current_panel)
1137 return panels [1].type;
1138 else
1139 return panels [0].type;