Just a little correction at the it.po file.
[midnight-commander.git] / src / layout.c
blob6e098f98b9e3fc5df5148225efd7a1957c9f98b7
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" /* COLS */
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 "cons.saver.h"
64 #include "layout.h"
65 #include "info.h" /* The Info widget */
66 #include "view.h" /* The view widget */
68 #define WANT_WIDGETS
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 /* If set, then we have to call the layout_change routine from main */
75 int layout_do_change = 0;
77 /* Set if the panels are split horizontally */
78 int horizontal_split = 0;
80 /* Set if the window has changed it's size */
81 int winch_flag = 0;
83 /* Set if the split is the same */
84 int equal_split = 1;
86 /* First panel size if the panel are not split equally */
87 int first_panel_size = 0;
89 /* The number of output lines shown (if available) */
90 int output_lines = 0;
92 /* Set if the command prompt is to be displayed */
93 int command_prompt = 1;
95 /* Set if the nice and usefull keybar is visible */
96 int keybar_visible = 1;
98 /* Set if the nice message (hint) bar is visible */
99 int message_visible = 1;
101 /* Set to show current working dir in xterm window title */
102 int xterm_title = 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 _permission_mode;
134 static int _filetype_mode;
136 static int height;
138 /* Width 12 for a wee Quick (Hex) View */
139 #define MINWIDTH 12
140 #define MINHEIGHT 5
142 #define BY 12
144 #define B_2LEFT B_USER
145 #define B_2RIGHT B_USER + 1
146 #define B_PLUS B_USER + 2
147 #define B_MINUS B_USER + 3
149 static Dlg_head *layout_dlg;
151 static char *s_split_direction [2] = {
152 N_("&Vertical"),
153 N_("&Horizontal")
156 static WRadio *radio_widget;
158 static struct {
159 char *text;
160 int *variable;
161 WCheck *widget;
162 char *tkname;
163 } check_options [] = {
164 { N_("&Xterm window title"), &xterm_title, 0, "t" },
165 { N_("h&Intbar visible"), &message_visible, 0, "v" },
166 { N_("&Keybar visible"), &keybar_visible, 0, "k" },
167 { N_("command &Prompt"), &command_prompt, 0, "p" },
168 { N_("show &Mini status"), &show_mini_info, 0, "m" },
169 { N_("menu&Bar visible"), &menubar_visible, 0, "me" },
170 { N_("&Equal split"), &equal_split, 0, "eq" },
171 { N_("pe&Rmissions"), &permission_mode, 0, "pr" },
172 { N_("&File types"), &filetype_mode, 0, "ft" },
173 { 0, 0, 0, 0 }
176 static int first_width, second_width;
177 static char *title1, *title2, *title3, *output_lines_label;
179 static WButton *bleft_widget, *bright_widget;
181 /* Declarations for static functions */
182 static void low_level_change_screen_size (void);
184 static void _check_split (void)
186 if (_horizontal_split){
187 if (_equal_split)
188 _first_panel_size = height / 2;
189 else if (_first_panel_size < MINHEIGHT)
190 _first_panel_size = MINHEIGHT;
191 else if (_first_panel_size > height - MINHEIGHT)
192 _first_panel_size = height - MINHEIGHT;
193 } else {
194 if (_equal_split)
195 _first_panel_size = COLS / 2;
196 else if (_first_panel_size < MINWIDTH)
197 _first_panel_size = MINWIDTH;
198 else if (_first_panel_size > COLS - MINWIDTH)
199 _first_panel_size = COLS - MINWIDTH;
203 static void update_split (void)
205 /* Check split has to be done before testing if it changed, since
206 it can change due to calling _check_split() as well*/
207 _check_split ();
209 /* To avoid setting the cursor to the wrong place */
210 if ((old_first_panel_size == _first_panel_size) &&
211 (old_horizontal_split == _horizontal_split)){
212 return;
215 old_first_panel_size = _first_panel_size;
216 old_horizontal_split = _horizontal_split;
218 attrset (COLOR_NORMAL);
219 dlg_move (layout_dlg, 6, 6);
220 printw ("%03d", _first_panel_size);
221 dlg_move (layout_dlg, 6, 18);
222 if (_horizontal_split)
223 printw ("%03d", height - _first_panel_size);
224 else
225 printw ("%03d", COLS - _first_panel_size);
228 static int b2left_cback (int action, void *data)
230 if (_equal_split){
231 /* Turn equal split off */
232 _equal_split = 0;
233 check_options [6].widget->state = check_options [6].widget->state & ~C_BOOL;
234 dlg_select_widget (layout_dlg, check_options [6].widget);
235 dlg_select_widget (layout_dlg, bleft_widget);
237 _first_panel_size++;
238 return 0;
241 static int b2right_cback (int action, void *data)
243 if (_equal_split){
244 /* Turn equal split off */
245 _equal_split = 0;
246 check_options [6].widget->state = check_options [6].widget->state & ~C_BOOL;
247 dlg_select_widget (layout_dlg, check_options [6].widget);
248 dlg_select_widget (layout_dlg, bright_widget);
250 _first_panel_size--;
251 return 0;
254 static int bplus_cback (int action, void *data)
256 if (_output_lines < 99)
257 _output_lines++;
258 return 0;
261 static int bminus_cback (int action, void *data)
263 if (_output_lines > 0)
264 _output_lines--;
265 return 0;
268 static int layout_callback (struct Dlg_head *h, int Id, int Msg)
270 switch (Msg){
271 case DLG_DRAW:
272 /*When repainting the whole dialog (e.g. with C-l) we have to
273 update everything*/
274 common_dialog_repaint (h);
276 old_first_panel_size = -1;
277 old_horizontal_split = -1;
278 old_output_lines = -1;
280 attrset (COLOR_NORMAL);
281 draw_box (h, 2, 4, 6, first_width);
282 draw_box (h, 8, 4, 4, first_width);
283 draw_box (h, 2, 5 + first_width, 10, second_width);
285 attrset (COLOR_HOT_NORMAL);
286 dlg_move (h, 2, 5);
287 addstr (title1);
288 dlg_move (h, 8, 5);
289 addstr (title2);
290 dlg_move (h, 2, 6 + first_width);
291 addstr (title3);
292 update_split ();
293 dlg_move (h, 6, 13);
294 addch ('=');
295 if (console_flag){
296 if (old_output_lines != _output_lines){
297 old_output_lines = _output_lines;
298 attrset (COLOR_NORMAL);
299 dlg_move (h, 9, 16 + first_width);
300 addstr (output_lines_label);
301 dlg_move (h, 9, 10 + first_width);
302 printw ("%02d", _output_lines);
305 break;
307 case DLG_POST_KEY:
308 _filetype_mode = check_options [8].widget->state & C_BOOL;
309 _permission_mode = check_options [7].widget->state & C_BOOL;
310 _equal_split = check_options [6].widget->state & C_BOOL;
311 _menubar_visible = check_options [5].widget->state & C_BOOL;
312 _command_prompt = check_options [4].widget->state & C_BOOL;
313 _keybar_visible = check_options [2].widget->state & C_BOOL;
314 _message_visible = check_options [1].widget->state & C_BOOL;
315 _xterm_title = check_options [0].widget->state & C_BOOL;
316 if (console_flag){
317 int minimum;
318 if (_output_lines < 0)
319 _output_lines = 0;
320 height = LINES - _keybar_visible - _command_prompt -
321 _menubar_visible - _output_lines - _message_visible;
322 minimum = MINHEIGHT * (1 + _horizontal_split);
323 if (height < minimum){
324 _output_lines -= minimum - height;
325 height = minimum;
327 } else {
328 height = LINES - _keybar_visible - _command_prompt -
329 _menubar_visible - _output_lines - _message_visible;
331 if (_horizontal_split != radio_widget->sel){
332 _horizontal_split = radio_widget->sel;
333 if (_horizontal_split)
334 _first_panel_size = height / 2;
335 else
336 _first_panel_size = COLS / 2;
338 update_split ();
339 if (console_flag){
340 if (old_output_lines != _output_lines){
341 old_output_lines = _output_lines;
342 attrset (COLOR_NORMAL);
343 dlg_move (h, 9, 10 + first_width);
344 printw ("%02d", _output_lines);
347 break;
349 case DLG_END:
350 break;
352 return 0;
355 static void init_layout (void)
357 static int i18n_layt_flag = 0;
358 static int b1, b2, b3;
359 int i = sizeof (s_split_direction) / sizeof(char*) ;
360 char* ok_button = _("&OK");
361 char* cancel_button = _("&Cancel");
362 char* save_button = _("&Save");
364 if (!i18n_layt_flag)
366 register int l1;
368 first_width = 19; /* length of line with '<' '>' buttons */
370 title1 = _(" Panel split ");
371 title2 = _(" Highlight... ");
372 title3 = _(" Other options ");
373 output_lines_label = _("output lines");
375 while (i--)
377 s_split_direction [i] = _(s_split_direction [i]);
378 l1 = strlen (s_split_direction [i]) + 7;
379 if (l1 > first_width)
380 first_width = l1;
383 for (i = 0; i <= 8; i++)
385 check_options[i].text = _(check_options[i].text);
386 l1 = strlen (check_options[i].text) + 7;
387 if (l1 > first_width)
388 first_width = l1;
391 l1 = strlen (title1) + 1;
392 if (l1 > first_width)
393 first_width = l1;
395 l1 = strlen (title2) + 1;
396 if (l1 > first_width)
397 first_width = l1;
400 second_width = strlen (title3) + 1;
401 for (i = 0; i < 6; i++)
403 check_options[i].text = _(check_options[i].text);
404 l1 = strlen (check_options[i].text) + 7;
405 if (l1 > second_width)
406 second_width = l1;
408 if (console_flag)
410 l1 = strlen (output_lines_label) + 13;
411 if (l1 > second_width)
412 second_width = l1;
416 * alex@bcs.zp.ua:
417 * To be completely correct, one need to check if the title
418 * does not exceed dialog length and total length of 3 buttons
419 * allows their placement in one row. But assuming this dialog
420 * is wide enough, I don't include such a tests.
422 * Now the last thing to do - properly space buttons...
424 l1 = 11 + strlen (ok_button) /* 14 - all brackets and inner space */
425 + strlen (save_button) /* notice: it is 3 char less because */
426 + strlen (cancel_button); /* of '&' char in button text */
428 i = (first_width + second_width - l1) / 4;
429 b1 = 5 + i;
430 b2 = b1 + strlen(ok_button) + i + 6;
431 b3 = b2 + strlen(save_button) + i + 4;
433 i18n_layt_flag = 1;
436 layout_dlg = create_dlg (0, 0, 15, first_width + second_width + 9,
437 dialog_colors, layout_callback,
438 "[Layout]", _("Layout"), DLG_CENTER);
440 add_widget (layout_dlg,
441 button_new (BY, b3, B_CANCEL, NORMAL_BUTTON, cancel_button, 0, 0, "c"));
442 add_widget (layout_dlg,
443 button_new (BY, b2, B_EXIT, NORMAL_BUTTON, save_button, 0, 0, "s"));
444 add_widget (layout_dlg,
445 button_new (BY, b1, B_ENTER, DEFPUSH_BUTTON, ok_button, 0, 0, "o"));
446 if (console_flag){
447 add_widget (layout_dlg,
448 button_new (9, 12 + first_width, B_MINUS, NARROW_BUTTON, "&-",
449 bminus_cback, 0, NULL));
450 add_widget (layout_dlg,
451 button_new (9, 7 + first_width, B_PLUS, NARROW_BUTTON, "&+",
452 bplus_cback, 0, NULL));
455 #define XTRACT(i) *check_options[i].variable, check_options[i].text, check_options[i].tkname
457 for (i = 0; i < 6; i++){
458 check_options [i].widget = check_new (8 - i, 7 + first_width, XTRACT(i));
459 add_widget (layout_dlg, check_options [i].widget);
461 check_options [8].widget = check_new (10, 6, XTRACT(8));
462 add_widget (layout_dlg, check_options [8].widget);
463 check_options [7].widget = check_new (9, 6, XTRACT(7));
464 add_widget (layout_dlg, check_options [7].widget);
466 _filetype_mode = filetype_mode;
467 _permission_mode = permission_mode;
468 _equal_split = equal_split;
469 _menubar_visible = menubar_visible;
470 _command_prompt = command_prompt;
471 _keybar_visible = keybar_visible;
472 _message_visible = message_visible;
473 _xterm_title = xterm_title;
474 bright_widget = button_new(6, 15, B_2RIGHT, NARROW_BUTTON, "&>", b2right_cback, 0, ">");
475 add_widget (layout_dlg, bright_widget);
476 bleft_widget = button_new (6, 9, B_2LEFT, NARROW_BUTTON, "&<", b2left_cback, 0, "<");
477 add_widget (layout_dlg, bleft_widget);
478 check_options [6].widget = check_new (5, 6, XTRACT(6));
479 old_first_panel_size = -1;
480 old_horizontal_split = -1;
481 old_output_lines = -1;
483 _first_panel_size = first_panel_size;
484 _output_lines = output_lines;
485 add_widget (layout_dlg, check_options [6].widget);
486 radio_widget = radio_new (3, 6, 2, s_split_direction, 1, "r");
487 add_widget (layout_dlg, radio_widget);
488 radio_widget->sel = horizontal_split;
491 void layout_change (void)
493 setup_panels ();
494 layout_do_change = 0;
495 /* re-init the menu, because perhaps there was a change in the way
496 how the panel are split (horizontal/vertical). */
497 done_menu();
498 init_menu();
499 menubar_arrange(the_menubar);
502 void layout_cmd (void)
504 int result;
505 int i;
507 init_layout ();
508 run_dlg (layout_dlg);
509 result = layout_dlg->ret_value;
511 if (result == B_ENTER || result == B_EXIT){
512 for (i = 0; check_options [i].text; i++)
513 if (check_options [i].widget)
514 *check_options [i].variable = check_options [i].widget->state & C_BOOL;
515 horizontal_split = radio_widget->sel;
516 first_panel_size = _first_panel_size;
517 output_lines = _output_lines;
518 layout_do_change = 1;
520 if (result == B_EXIT){
521 save_layout ();
522 sync_profiles ();
525 destroy_dlg (layout_dlg);
526 if (layout_do_change)
527 layout_change ();
530 static void check_split (void)
532 if (horizontal_split){
533 if (equal_split)
534 first_panel_size = height / 2;
535 else if (first_panel_size < MINHEIGHT)
536 first_panel_size = MINHEIGHT;
537 else if (first_panel_size > height - MINHEIGHT)
538 first_panel_size = height - MINHEIGHT;
539 } else {
540 if (equal_split)
541 first_panel_size = COLS / 2;
542 else if (first_panel_size < MINWIDTH)
543 first_panel_size = MINWIDTH;
544 else if (first_panel_size > COLS - MINWIDTH)
545 first_panel_size = COLS - MINWIDTH;
549 #ifdef HAVE_SLANG
550 void
551 init_curses ()
553 #ifndef HAS_ACS_AS_PCCHARS
554 if (force_ugly_line_drawing)
555 SLtt_Has_Alt_Charset = 0;
556 #endif
557 SLsmg_init_smg ();
558 do_enter_ca_mode ();
559 init_colors ();
560 keypad (stdscr, TRUE);
561 nodelay (stdscr, FALSE);
563 #else
564 static const struct {
565 int acscode;
566 int character;
567 } acs_approx [] = {
568 { 'q', '-' }, /* ACS_HLINE */
569 { 'x', '|' }, /* ACS_VLINE */
570 { 'l', '+' }, /* ACS_ULCORNER */
571 { 'k', '+' }, /* ACS_URCORNER */
572 { 'm', '+' }, /* ACS_LLCORNER */
573 { 'j', '+' }, /* ACS_LRCORNER */
574 { 'a', '#' }, /* ACS_CKBOARD */
575 { 'u', '+' }, /* ACS_RTEE */
576 { 't', '+' }, /* ACS_LTEE */
577 { 'w', '+' }, /* ACS_TTEE */
578 { 'v', '+' }, /* ACS_BTEE */
579 { 'n', '+' }, /* ACS_PLUS */
580 { 0, 0 } };
582 void init_curses (void)
584 int i;
585 initscr();
586 #ifdef HAVE_ESCDELAY
588 * If ncurses exports the ESCDELAY variable, it should be set to
589 * a low value, or you'll experience a delay in processing escape
590 * sequences that are recognized by mc (e.g. Esc-Esc). On the other
591 * hand, making ESCDELAY too small can result in some sequences
592 * (e.g. cursor arrows) being reported as separate keys under heavy
593 * processor load, and this can be a problem if mc hasn't learned
594 * them in the "Learn Keys" dialog. The value is in milliseconds.
596 ESCDELAY = 200;
597 #endif /* HAVE_ESCDELAY */
598 do_enter_ca_mode ();
599 mc_raw_mode ();
600 noecho ();
601 keypad (stdscr, TRUE);
602 nodelay (stdscr, FALSE);
603 init_colors ();
604 if (force_ugly_line_drawing) {
605 for (i = 0; acs_approx[i].acscode != 0; i++) {
606 acs_map[acs_approx[i].acscode] = acs_approx[i].character;
610 #endif /* ! HAVE_SLANG */
612 void
613 done_screen ()
615 if (!(quit & SUBSHELL_EXIT))
616 clr_scr ();
617 reset_shell_mode ();
618 mc_noraw_mode ();
619 keypad (stdscr, FALSE);
622 static void
623 panel_do_cols (int index)
625 if (get_display_type (index) == view_listing)
626 set_panel_formats ((WPanel *) panels [index].widget);
627 else {
628 panel_update_cols (panels [index].widget, frame_half);
630 /* In case of an Hex Quick View must review line length */
631 if (get_display_type (index) == view_quick)
632 view_update_bytes_per_line ((WView *) panels [index].widget);
636 void
637 setup_panels (void)
639 int start_y;
640 int promptl; /* the prompt len */
642 if (console_flag) {
643 int minimum;
644 if (output_lines < 0)
645 output_lines = 0;
646 height =
647 LINES - keybar_visible - command_prompt - menubar_visible -
648 output_lines - message_visible;
649 minimum = MINHEIGHT * (1 + horizontal_split);
650 if (height < minimum) {
651 output_lines -= minimum - height;
652 height = minimum;
654 } else {
655 height =
656 LINES - menubar_visible - command_prompt - keybar_visible -
657 message_visible;
659 check_split ();
660 start_y = menubar_visible;
662 /* The column computing is defered until panel_do_cols */
663 if (horizontal_split) {
664 widget_set_size (panels[0].widget, start_y, 0, first_panel_size,
667 widget_set_size (panels[1].widget, start_y + first_panel_size, 0,
668 height - first_panel_size, 0);
669 } else {
670 int first_x = first_panel_size;
672 widget_set_size (panels[0].widget, start_y, 0, height, 0);
674 widget_set_size (panels[1].widget, start_y, first_x, height, 0);
677 panel_do_cols (0);
678 panel_do_cols (1);
680 promptl = strlen (prompt);
682 widget_set_size (&the_menubar->widget, 0, 0, 1, COLS);
684 if (command_prompt) {
685 widget_set_size (&cmdline->widget, LINES - 1 - keybar_visible,
686 promptl, 1,
687 COLS - promptl - (keybar_visible ? 0 : 1));
688 winput_set_origin (cmdline, promptl,
689 COLS - promptl - (keybar_visible ? 0 : 1));
690 widget_set_size (&the_prompt->widget, LINES - 1 - keybar_visible,
691 0, 1, promptl);
692 } else {
693 widget_set_size (&cmdline->widget, 0, 0, 0, 0);
694 winput_set_origin (cmdline, 0, 0);
695 widget_set_size (&the_prompt->widget, LINES, COLS, 0, 0);
698 widget_set_size (&the_bar->widget, LINES - 1, 0, keybar_visible, COLS);
699 the_bar->visible = keybar_visible;
701 /* Output window */
702 if (console_flag && output_lines) {
703 output_start_y =
704 LINES - command_prompt - keybar_visible - output_lines;
705 show_console_contents (output_start_y,
706 LINES - output_lines - keybar_visible - 1,
707 LINES - keybar_visible - 1);
709 if (message_visible) {
710 widget_set_size (&the_hint->widget, height + start_y, 0, 1, COLS);
711 set_hintbar (""); /* clean up the line */
712 } else
713 widget_set_size (&the_hint->widget, 0, 0, 0, 0);
715 load_hint (1);
716 update_xterm_title_path ();
719 void flag_winch (int dummy)
721 #ifndef USE_NCURSES /* don't do malloc in a signal handler */
722 low_level_change_screen_size ();
723 #endif
724 winch_flag = 1;
727 static void
728 low_level_change_screen_size (void)
730 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
731 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
732 struct winsize winsz;
734 winsz.ws_col = winsz.ws_row = 0;
735 /* Ioctl on the STDIN_FILENO */
736 ioctl (0, TIOCGWINSZ, &winsz);
737 if (winsz.ws_col && winsz.ws_row){
738 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
739 resizeterm(winsz.ws_row, winsz.ws_col);
740 clearok(stdscr,TRUE); /* sigwinch's should use a semaphore! */
741 #else
742 COLS = winsz.ws_col;
743 LINES = winsz.ws_row;
744 #endif
745 #ifdef HAVE_SUBSHELL_SUPPORT
746 resize_subshell ();
747 #endif
749 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
750 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
753 void
754 change_screen_size (void)
756 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
757 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
759 #ifndef NCURSES_VERSION
760 mc_noraw_mode ();
761 endwin ();
762 #endif
763 low_level_change_screen_size ();
764 check_split ();
765 #ifndef NCURSES_VERSION
766 /* XSI Curses spec states that portable applications shall not invoke
767 * initscr() more than once. This kludge could be done within the scope
768 * of the specification by using endwin followed by a refresh (in fact,
769 * more than one curses implementation does this); it is guaranteed to work
770 * only with slang.
772 init_curses ();
773 #endif
774 setup_panels ();
776 /* Inform currently running dialog */
777 (*current_dlg->callback) (current_dlg, current_dlg->current->dlg_id,
778 DLG_RESIZE);
780 #ifdef RESIZABLE_MENUBAR
781 menubar_arrange (the_menubar);
782 #endif
784 /* Now, force the redraw */
785 do_refresh ();
786 touchwin (stdscr);
787 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
788 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
789 winch_flag = 0;
792 static int ok_to_refresh = 1;
794 void use_dash (int flag)
796 if (flag)
797 ok_to_refresh++;
798 else
799 ok_to_refresh--;
802 void set_hintbar(char *str)
804 label_set_text (the_hint, str);
805 if (ok_to_refresh > 0)
806 refresh();
809 void print_vfs_message (char *msg, ...)
811 va_list ap;
812 char str [128];
814 va_start (ap, msg);
816 g_vsnprintf (str, sizeof (str), msg, ap);
817 va_end (ap);
819 if (midnight_shutdown)
820 return;
822 if (!message_visible || !the_hint || !the_hint->widget.parent) {
823 int col, row;
825 if (!nice_rotating_dash || (ok_to_refresh <= 0))
826 return;
828 /* Preserve current cursor position */
829 getyx (stdscr, row, col);
831 move (0, 0);
832 attrset (NORMAL_COLOR);
833 printw ("%-*s", COLS-1, str);
835 /* Restore cursor position */
836 move(row, col);
837 mc_refresh ();
838 return;
841 if (message_visible) {
842 set_hintbar(str);
846 void rotate_dash (void)
848 static char rotating_dash [] = "|/-\\";
849 static int pos = 0;
851 if (!nice_rotating_dash || (ok_to_refresh <= 0))
852 return;
854 if (pos >= sizeof (rotating_dash)-1)
855 pos = 0;
856 move (0, COLS-1);
857 addch (rotating_dash [pos]);
858 mc_refresh ();
859 pos++;
862 void remove_dash (void)
864 if (!nice_rotating_dash)
865 return;
867 /* Currently, it's much nicer with the CPU to do this instead of
868 calling do_refresh.
870 I should implement a routine called invalidate_region that would
871 send a draw message only to the affected views. But for now
872 this is fine.
875 move (0, COLS-1);
876 addch (' ');
879 char *get_nth_panel_name (int num)
881 static char buffer [BUF_SMALL];
883 if (!num)
884 return "New Left Panel";
885 else if (num == 1)
886 return "New Right Panel";
887 else {
888 g_snprintf (buffer, sizeof (buffer), "%ith Panel", num);
889 return buffer;
893 /* I wonder if I should start to use the folding mode than Dugan uses */
894 /* */
895 /* This is the centralized managing of the panel display types */
896 /* This routine takes care of destroying and creating new widgets */
897 /* Please note that it could manage MAX_VIEWS, not just left and right */
898 /* Currently nothing in the code takes advantage of this and has hard- */
899 /* coded values for two panels only */
901 /* Set the num-th panel to the view type: type */
902 /* This routine also keeps at least one WPanel object in the screen */
903 /* since a lot of routines depend on the current_panel variable */
904 void set_display_type (int num, int type)
906 int x, y, cols, lines;
907 int the_other; /* Index to the other panel */
908 char *file_name = 0; /* For Quick view */
909 Widget *new_widget, *old_widget;
910 WPanel *the_other_panel;
912 x = y = cols = lines = 0;
913 old_widget = 0;
914 if (num >= MAX_VIEWS){
915 fprintf (stderr, "Cannot allocate more that %d views\n", MAX_VIEWS);
916 abort ();
919 /* Check that we will have a WPanel * at least */
920 the_other = 0;
921 if (type != view_listing){
922 the_other = num == 0 ? 1 : 0;
924 if (panels [the_other].type != view_listing)
925 return;
929 /* Get rid of it */
930 if (panels [num].widget){
931 Widget *w = panels [num].widget;
932 WPanel *panel = (WPanel *) panels [num].widget;
934 x = w->x;
935 y = w->y;
936 cols = w->cols;
937 lines = w->lines;
938 old_widget = panels [num].widget;
940 if (panels [num].type == view_listing){
941 if (panel->frame_size == frame_full && type != view_listing){
942 cols = COLS - first_panel_size;
943 if (num == 1)
944 x = first_panel_size;
949 new_widget = 0;
951 switch (type){
952 case view_listing:
953 new_widget = (Widget *) panel_new (get_nth_panel_name (num));
954 break;
956 case view_info:
957 new_widget = (Widget *) info_new ();
959 break;
961 case view_tree:
962 new_widget = (Widget *) tree_new (1, 0, 0, 0, 0);
963 break;
965 case view_quick:
966 new_widget = (Widget *) view_new (0, 0, 0, 0, 1);
967 the_other_panel = (WPanel *) panels [the_other].widget;
968 if (the_other_panel)
969 file_name =
970 the_other_panel->dir.list[the_other_panel->selected].fname;
971 else
972 file_name = "";
974 view_init ((WView *) new_widget, 0, file_name, 0);
975 break;
977 panels [num].type = type;
978 panels [num].widget = (Widget *) new_widget;
980 /* We set the same size the old widget had */
981 widget_set_size ((Widget *) new_widget, y, x, lines, cols);
983 /* We use replace to keep the circular list of the dialog in the */
984 /* same state. Maybe we could just kill it and then replace it */
985 if (midnight_dlg && old_widget){
986 dlg_replace_widget (midnight_dlg, old_widget, panels [num].widget);
988 if (type == view_listing){
989 if (num == 0)
990 left_panel = (WPanel *) new_widget;
991 else
992 right_panel = (WPanel *) new_widget;
995 if (type == view_tree)
996 the_tree = (WTree *) new_widget;
998 /* Prevent current_panel's value from becoming invalid.
999 * It's just a quick hack to prevent segfaults. Comment out and
1000 * try following:
1001 * - select left panel
1002 * - invoke menue left/tree
1003 * - as long as you stay in the left panel almost everything that uses
1004 * cpanel causes segfault, e.g. C-Enter, C-x c, ...
1007 if (type != view_listing)
1008 if (cpanel == (WPanel *) old_widget)
1009 current_panel = num == 0 ? right_panel : left_panel;
1012 /* This routine is deeply sticked to the two panels idea.
1013 What should it do in more panels. ANSWER - don't use it
1014 in any multiple panels environment. */
1015 void swap_panels ()
1017 Widget tmp;
1018 Widget *tmp_widget;
1019 WPanel panel;
1020 WPanel *panel1, *panel2;
1021 int tmp_type;
1023 #define panelswap(x) panel. x = panel1-> x; panel1-> x = panel2-> x; panel2-> x = panel. x;
1025 #define panelswapstr(e) strcpy (panel. e, panel1-> e); \
1026 strcpy (panel1-> e, panel2-> e); \
1027 strcpy (panel2-> e, panel. e);
1028 panel1 = (WPanel *) panels [0].widget;
1029 panel2 = (WPanel *) panels [1].widget;
1030 if (panels [0].type == view_listing && panels [1].type == view_listing) {
1031 /* Change everything except format/sort/panel_name etc. */
1032 panelswap (dir);
1033 panelswap (active);
1034 panelswapstr (cwd);
1035 panelswapstr (lwd);
1036 panelswap (count);
1037 panelswap (marked);
1038 panelswap (dirs_marked);
1039 panelswap (total);
1040 panelswap (top_file);
1041 panelswap (selected);
1042 panelswap (is_panelized);
1043 panelswap (dir_stat);
1045 panel1->searching = 0;
1046 panel2->searching = 0;
1047 if (cpanel == panel1)
1048 current_panel = panel2;
1049 else
1050 current_panel = panel1;
1051 if (midnight_dlg->current->widget == panels [0].widget)
1052 dlg_select_widget (midnight_dlg, (void *) panels [1].widget);
1053 else if (midnight_dlg->current->widget == panels [1].widget)
1054 dlg_select_widget (midnight_dlg, (void *) panels [0].widget);
1055 } else {
1056 WPanel *tmp_panel;
1058 tmp_panel=right_panel;
1059 right_panel=left_panel;
1060 left_panel=tmp_panel;
1062 if (panels [0].type == view_listing) {
1063 if (!strcmp (panel1->panel_name, get_nth_panel_name (0))) {
1064 g_free (panel1->panel_name);
1065 panel1->panel_name = g_strdup (get_nth_panel_name (1));
1068 if (panels [1].type == view_listing) {
1069 if (!strcmp (panel2->panel_name, get_nth_panel_name (1))) {
1070 g_free (panel2->panel_name);
1071 panel2->panel_name = g_strdup (get_nth_panel_name (0));
1075 tmp.x = panels [0].widget->x;
1076 tmp.y = panels [0].widget->y;
1077 tmp.cols = panels [0].widget->cols;
1078 tmp.lines = panels [0].widget->lines;
1080 panels [0].widget->x = panels [1].widget->x;
1081 panels [0].widget->y = panels [1].widget->y;
1082 panels [0].widget->cols = panels [1].widget->cols;
1083 panels [0].widget->lines = panels [1].widget->lines;
1085 panels [1].widget->x = tmp.x;
1086 panels [1].widget->y = tmp.y;
1087 panels [1].widget->cols = tmp.cols;
1088 panels [1].widget->lines = tmp.lines;
1090 tmp_widget = panels [0].widget;
1091 panels [0].widget = panels [1].widget;
1092 panels [1].widget = tmp_widget;
1093 tmp_type = panels [0].type;
1094 panels [0].type = panels [1].type;
1095 panels [1].type = tmp_type;
1099 int get_display_type (int index)
1101 return panels [index].type;
1104 Widget *get_panel_widget (int index)
1106 return panels [index].widget;
1109 int get_current_index (void)
1111 if (panels [0].widget == ((Widget *) cpanel))
1112 return 0;
1113 else
1114 return 1;
1117 int get_other_index (void)
1119 return !get_current_index ();
1122 /* Returns the view type for the current panel/view */
1123 int get_current_type (void)
1125 if (panels [0].widget == (Widget *) cpanel)
1126 return panels [0].type;
1127 else
1128 return panels [1].type;
1131 /* Returns the view type of the unselected panel */
1132 int get_other_type (void)
1134 if (panels [0].widget == (Widget *) cpanel)
1135 return panels [1].type;
1136 else
1137 return panels [0].type;