*** empty log message ***
[midnight-commander.git] / src / layout.c
blob370dea74c5cf246fe6110eab8c89e37d787d34ac
1 /* Panel layout module for the Midnight Commander
2 Copyright (C) 1995 the Free Software Foundation
4 Written: 1995 Janne Kukonlehto
5 1995 Miguel de Icaza
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <config.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #if HAVE_TERMIOS_H
29 # include <termios.h>
30 #endif
32 * If TIOCGWINSZ supported, make it available here, because window-
33 * resizing code depends on it...
35 #ifdef HAVE_SYS_IOCTL_H
36 # include <sys/ioctl.h>
37 #endif
38 #ifdef HAVE_UNISTD_H
39 # include <unistd.h>
40 #endif
41 #include <signal.h>
43 #include "global.h"
44 #include "tty.h"
45 #include "win.h"
46 #include "color.h"
47 #include "key.h"
48 #include "dlg.h"
49 #include "widget.h"
50 #include "command.h"
51 #include "dialog.h" /* For do_refresh() */
52 #include "profile.h" /* For sync_profiles() */
53 #include "mouse.h"
54 #define WANT_WIDGETS
55 #include "main.h"
56 #include "subshell.h" /* For use_subshell and resize_subshell() */
57 #include "tree.h"
58 #include "menu.h"
60 /* Needed for the extern declarations of integer parameters */
61 #include "dir.h"
62 #include "panel.h" /* The Panel widget */
63 #include "file.h"
64 #include "cons.saver.h"
65 #include "layout.h"
66 #include "info.h" /* The Info widget */
67 #include "view.h" /* The view widget */
69 #define WANT_WIDGETS
70 #include "setup.h" /* For save_setup() */
72 /* "$Id$" */
74 /* Controls the display of the rotating dash on the verbose mode */
75 int nice_rotating_dash = 1;
77 /* If set, then we have to call the layout_change routine from main */
78 int layout_do_change = 0;
80 /* Set if the panels are split horizontally */
81 int horizontal_split = 0;
83 /* Set if the window has changed it's size */
84 int winch_flag = 0;
86 /* Set if the split is the same */
87 int equal_split = 1;
89 /* First panel size if the panel are not split equally */
90 int first_panel_size = 0;
92 /* The number of output lines shown (if available) */
93 int output_lines = 0;
95 /* Set if the command prompt is to be displayed */
96 int command_prompt = 1;
98 /* Set if the nice and usefull keybar is visible */
99 int keybar_visible = 1;
101 /* Set if the nice message (hint) bar is visible */
102 int message_visible = 1;
104 /* Set if you want the message bar shown in xterm title bar to save space */
105 int xterm_hintbar = 0;
107 /* The starting line for the output of the subprogram */
108 int output_start_y = 0;
110 /* The maximum number of views managed by the set_display_type routine */
111 /* Must be at least two (for current and other). Please note that until */
112 /* Janne gets around this, we will only manage two of them :-) */
113 #define MAX_VIEWS 2
115 static struct {
116 int type;
117 Widget *widget;
118 } panels [MAX_VIEWS];
120 /* These variables are used to avoid updating the information unless */
121 /* we need it */
122 static int old_first_panel_size;
123 static int old_horizontal_split;
124 static int old_output_lines;
126 /* Internal variables */
127 static int _horizontal_split;
128 static int _equal_split;
129 static int _first_panel_size;
130 static int _menubar_visible;
131 static int _output_lines;
132 static int _command_prompt;
133 static int _keybar_visible;
134 static int _message_visible;
135 static int _xterm_hintbar;
136 static int _permission_mode;
137 static int _filetype_mode;
139 static int height;
141 /* Width 12 for a wee Quick (Hex) View */
142 #define MINWIDTH 12
143 #define MINHEIGHT 5
145 #define BY 12
147 #define B_2LEFT B_USER
148 #define B_2RIGHT B_USER + 1
149 #define B_PLUS B_USER + 2
150 #define B_MINUS B_USER + 3
152 static Dlg_head *layout_dlg;
154 static char *s_split_direction [2] = {
155 N_("&Vertical"),
156 N_("&Horizontal")
159 static WRadio *radio_widget;
161 static struct {
162 char *text;
163 int *variable;
164 WCheck *widget;
165 char *tkname;
166 } check_options [] = {
167 { N_("&Xterm hintbar"), &xterm_hintbar, 0, "h" },
168 { N_("h&Intbar visible"), &message_visible, 0, "v" },
169 { N_("&Keybar visible"), &keybar_visible, 0, "k" },
170 { N_("command &Prompt"), &command_prompt, 0, "p" },
171 { N_("show &Mini status"), &show_mini_info, 0, "m" },
172 { N_("menu&Bar visible"), &menubar_visible, 0, "me" },
173 { N_("&Equal split"), &equal_split, 0, "eq" },
174 { N_("pe&Rmissions"), &permission_mode, 0, "pr" },
175 { N_("&File types"), &filetype_mode, 0, "ft" },
176 { 0, 0, 0, 0 }
179 static int first_width, second_width;
180 static char *layout_title, *title1, *title2, *title3, *output_lines_label;
182 static WButton *bleft_widget, *bright_widget;
184 /* Declarations for static functions */
185 static void low_level_change_screen_size (void);
187 static void _check_split (void)
189 if (_horizontal_split){
190 if (_equal_split)
191 _first_panel_size = height / 2;
192 else if (_first_panel_size < MINHEIGHT)
193 _first_panel_size = MINHEIGHT;
194 else if (_first_panel_size > height - MINHEIGHT)
195 _first_panel_size = height - MINHEIGHT;
196 } else {
197 if (_equal_split)
198 _first_panel_size = COLS / 2;
199 else if (_first_panel_size < MINWIDTH)
200 _first_panel_size = MINWIDTH;
201 else if (_first_panel_size > COLS - MINWIDTH)
202 _first_panel_size = COLS - MINWIDTH;
206 static void update_split (void)
208 /* Check split has to be done before testing if it changed, since
209 it can change due to calling _check_split() as well*/
210 _check_split ();
212 /* To avoid setting the cursor to the wrong place */
213 if ((old_first_panel_size == _first_panel_size) &&
214 (old_horizontal_split == _horizontal_split)){
215 return;
218 old_first_panel_size = _first_panel_size;
219 old_horizontal_split = _horizontal_split;
221 attrset (COLOR_NORMAL);
222 dlg_move (layout_dlg, 6, 6);
223 printw ("%03d", _first_panel_size);
224 dlg_move (layout_dlg, 6, 18);
225 if (_horizontal_split)
226 printw ("%03d", height - _first_panel_size);
227 else
228 printw ("%03d", COLS - _first_panel_size);
231 static int b2left_cback (int action, void *data)
233 if (_equal_split){
234 /* Turn equal split off */
235 _equal_split = 0;
236 check_options [6].widget->state = check_options [6].widget->state & ~C_BOOL;
237 dlg_select_widget (layout_dlg, check_options [6].widget);
238 dlg_select_widget (layout_dlg, bleft_widget);
240 _first_panel_size++;
241 return 0;
244 static int b2right_cback (int action, void *data)
246 if (_equal_split){
247 /* Turn equal split off */
248 _equal_split = 0;
249 check_options [6].widget->state = check_options [6].widget->state & ~C_BOOL;
250 dlg_select_widget (layout_dlg, check_options [6].widget);
251 dlg_select_widget (layout_dlg, bright_widget);
253 _first_panel_size--;
254 return 0;
257 static int bplus_cback (int action, void *data)
259 if (_output_lines < 99)
260 _output_lines++;
261 return 0;
264 static int bminus_cback (int action, void *data)
266 if (_output_lines > 0)
267 _output_lines--;
268 return 0;
271 static int layout_callback (struct Dlg_head *h, int Id, int Msg)
273 switch (Msg){
274 case DLG_DRAW:
275 /*When repainting the whole dialog (e.g. with C-l) we have to
276 update everything*/
277 old_first_panel_size = -1;
278 old_horizontal_split = -1;
279 old_output_lines = -1;
280 attrset (COLOR_NORMAL);
281 dlg_erase (h);
282 draw_box (h, 1, 2, h->lines - 2, h->cols - 4);
283 draw_box (h, 2, 4, 6, first_width);
284 draw_box (h, 8, 4, 4, first_width);
285 draw_box (h, 2, 5 + first_width, 10, second_width);
287 attrset (COLOR_HOT_NORMAL);
288 dlg_move (h, 1, (h->cols - strlen(layout_title))/2);
289 addstr (layout_title);
290 dlg_move (h, 2, 5);
291 addstr (title1);
292 dlg_move (h, 8, 5);
293 addstr (title2);
294 dlg_move (h, 2, 6 + first_width);
295 addstr (title3);
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, 9, 16 + first_width);
304 addstr (output_lines_label);
305 dlg_move (h, 9, 10 + first_width);
306 printw ("%02d", _output_lines);
309 break;
311 case DLG_POST_KEY:
312 _filetype_mode = check_options [8].widget->state & C_BOOL;
313 _permission_mode = check_options [7].widget->state & C_BOOL;
314 _equal_split = check_options [6].widget->state & C_BOOL;
315 _menubar_visible = check_options [5].widget->state & C_BOOL;
316 _command_prompt = check_options [4].widget->state & C_BOOL;
317 _keybar_visible = check_options [2].widget->state & C_BOOL;
318 _message_visible = check_options [1].widget->state & C_BOOL;
319 _xterm_hintbar = check_options [0].widget->state & C_BOOL;
320 if (console_flag){
321 int minimum;
322 if (_output_lines < 0)
323 _output_lines = 0;
324 height = LINES - _keybar_visible - _command_prompt -
325 _menubar_visible - _output_lines - _message_visible;
326 if (_message_visible && _xterm_hintbar && xterm_flag) height++;
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;
335 if (_message_visible && _xterm_hintbar && xterm_flag) height++;
337 if (_horizontal_split != radio_widget->sel){
338 _horizontal_split = radio_widget->sel;
339 if (_horizontal_split)
340 _first_panel_size = height / 2;
341 else
342 _first_panel_size = COLS / 2;
344 update_split ();
345 if (console_flag){
346 if (old_output_lines != _output_lines){
347 old_output_lines = _output_lines;
348 attrset (COLOR_NORMAL);
349 dlg_move (h, 9, 10 + first_width);
350 printw ("%02d", _output_lines);
353 break;
355 case DLG_END:
356 break;
358 return 0;
361 static void init_layout (void)
363 static int i18n_layt_flag = 0;
364 static int b1, b2, b3;
365 int i = sizeof (s_split_direction) / sizeof(char*) ;
366 char* ok_button = _("&Ok");
367 char* cancel_button = _("&Cancel");
368 char* save_button = _("&Save");
370 if (!i18n_layt_flag)
372 register int l1;
374 first_width = 19; /* length of line with '<' '>' buttons */
376 layout_title = _(" Layout ");
377 title1 = _(" Panel split ");
378 title2 = _(" Highlight... ");
379 title3 = _(" Other options ");
380 output_lines_label = _("output lines");
382 while (i--)
384 s_split_direction [i] = _(s_split_direction [i]);
385 l1 = strlen (s_split_direction [i]) + 7;
386 if (l1 > first_width)
387 first_width = l1;
390 for (i = 0; i <= 8; i++)
392 check_options[i].text = _(check_options[i].text);
393 l1 = strlen (check_options[i].text) + 7;
394 if (l1 > first_width)
395 first_width = l1;
398 l1 = strlen (title1) + 1;
399 if (l1 > first_width)
400 first_width = l1;
402 l1 = strlen (title2) + 1;
403 if (l1 > first_width)
404 first_width = l1;
407 second_width = strlen (title3) + 1;
408 for (i = 0; i < 6; i++)
410 check_options[i].text = _(check_options[i].text);
411 l1 = strlen (check_options[i].text) + 7;
412 if (l1 > second_width)
413 second_width = l1;
415 if (console_flag)
417 l1 = strlen (output_lines_label) + 13;
418 if (l1 > second_width)
419 second_width = l1;
423 * alex@bcs.zp.ua:
424 * To be completely correct, one need to check if layout_title
425 * does not exceed dialog length and total length of 3 buttons
426 * allows their placement in one row. But assuming this dialog
427 * is wide enough, I don't include such a tests.
429 * Now the last thing to do - properly space buttons...
431 l1 = 11 + strlen (ok_button) /* 14 - all brackets and inner space */
432 + strlen (save_button) /* notice: it is 3 char less because */
433 + strlen (cancel_button); /* of '&' char in button text */
435 i = (first_width + second_width - l1) / 4;
436 b1 = 5 + i;
437 b2 = b1 + strlen(ok_button) + i + 6;
438 b3 = b2 + strlen(save_button) + i + 4;
440 i18n_layt_flag = 1;
443 layout_dlg = create_dlg (0, 0, 15, first_width + second_width + 9,
444 dialog_colors, layout_callback,
445 "[Layout]", "layout", DLG_CENTER);
447 x_set_dialog_title (layout_dlg, _("Layout"));
449 add_widget (layout_dlg,
450 button_new (BY, b3, B_CANCEL, NORMAL_BUTTON, cancel_button, 0, 0, "c"));
451 add_widget (layout_dlg,
452 button_new (BY, b2, B_EXIT, NORMAL_BUTTON, save_button, 0, 0, "s"));
453 add_widget (layout_dlg,
454 button_new (BY, b1, B_ENTER, DEFPUSH_BUTTON, ok_button, 0, 0, "o"));
455 if (console_flag){
456 add_widget (layout_dlg,
457 button_new (9, 12 + first_width, B_MINUS, NARROW_BUTTON, "&-",
458 bminus_cback, 0, NULL));
459 add_widget (layout_dlg,
460 button_new (9, 7 + first_width, B_PLUS, NARROW_BUTTON, "&+",
461 bplus_cback, 0, NULL));
464 #define XTRACT(i) *check_options[i].variable, check_options[i].text, check_options[i].tkname
466 for (i = 0; i < 6; i++){
467 check_options [i].widget = check_new (8 - i, 7 + first_width, XTRACT(i));
468 add_widget (layout_dlg, check_options [i].widget);
470 check_options [8].widget = check_new (10, 6, XTRACT(8));
471 add_widget (layout_dlg, check_options [8].widget);
472 check_options [7].widget = check_new (9, 6, XTRACT(7));
473 add_widget (layout_dlg, check_options [7].widget);
475 _filetype_mode = filetype_mode;
476 _permission_mode = permission_mode;
477 _equal_split = equal_split;
478 _menubar_visible = menubar_visible;
479 _command_prompt = command_prompt;
480 _keybar_visible = keybar_visible;
481 _message_visible = message_visible;
482 _xterm_hintbar = xterm_hintbar;
483 bright_widget = button_new(6, 15, B_2RIGHT, NARROW_BUTTON, "&>", b2right_cback, 0, ">");
484 add_widget (layout_dlg, bright_widget);
485 bleft_widget = button_new (6, 9, B_2LEFT, NARROW_BUTTON, "&<", b2left_cback, 0, "<");
486 add_widget (layout_dlg, bleft_widget);
487 check_options [6].widget = check_new (5, 6, XTRACT(6));
488 old_first_panel_size = -1;
489 old_horizontal_split = -1;
490 old_output_lines = -1;
492 _first_panel_size = first_panel_size;
493 _output_lines = output_lines;
494 add_widget (layout_dlg, check_options [6].widget);
495 radio_widget = radio_new (3, 6, 2, s_split_direction, 1, "r");
496 add_widget (layout_dlg, radio_widget);
497 radio_widget->sel = horizontal_split;
500 void layout_change (void)
502 setup_panels ();
503 layout_do_change = 0;
504 /* re-init the menu, because perhaps there was a change in the way
505 how the panel are split (horizontal/vertical). */
506 done_menu();
507 init_menu();
508 menubar_arrange(the_menubar);
511 void layout_cmd (void)
513 int result;
514 int i;
516 init_layout ();
517 run_dlg (layout_dlg);
518 result = layout_dlg->ret_value;
520 if (result == B_ENTER || result == B_EXIT){
521 for (i = 0; check_options [i].text; i++)
522 if (check_options [i].widget)
523 *check_options [i].variable = check_options [i].widget->state & C_BOOL;
524 horizontal_split = radio_widget->sel;
525 first_panel_size = _first_panel_size;
526 output_lines = _output_lines;
527 layout_do_change = 1;
529 if (result == B_EXIT){
530 save_layout ();
531 sync_profiles ();
534 destroy_dlg (layout_dlg);
535 if (layout_do_change)
536 layout_change ();
539 static void check_split (void)
541 if (horizontal_split){
542 if (equal_split)
543 first_panel_size = height / 2;
544 else if (first_panel_size < MINHEIGHT)
545 first_panel_size = MINHEIGHT;
546 else if (first_panel_size > height - MINHEIGHT)
547 first_panel_size = height - MINHEIGHT;
548 } else {
549 if (equal_split)
550 first_panel_size = COLS / 2;
551 else if (first_panel_size < MINWIDTH)
552 first_panel_size = MINWIDTH;
553 else if (first_panel_size > COLS - MINWIDTH)
554 first_panel_size = COLS - MINWIDTH;
558 #ifdef HAVE_SLANG
559 void init_curses ()
561 SLtt_get_terminfo ();
562 #ifndef HAS_ACS_AS_PCCHARS
563 if (force_ugly_line_drawing)
564 SLtt_Has_Alt_Charset = 0;
565 #endif
566 SLsmg_init_smg ();
567 do_enter_ca_mode ();
568 init_colors ();
569 keypad (stdscr, TRUE);
570 nodelay (stdscr, FALSE);
572 #else
573 static const struct {
574 int acscode;
575 int character;
576 } acs_approx [] = {
577 { 'q', '-' }, /* ACS_HLINE */
578 { 'x', '|' }, /* ACS_VLINE */
579 { 'l', '+' }, /* ACS_ULCORNER */
580 { 'k', '+' }, /* ACS_URCORNER */
581 { 'm', '+' }, /* ACS_LLCORNER */
582 { 'j', '+' }, /* ACS_LRCORNER */
583 { 'a', '#' }, /* ACS_CKBOARD */
584 { 'u', '+' }, /* ACS_RTEE */
585 { 't', '+' }, /* ACS_LTEE */
586 { 'w', '+' }, /* ACS_TTEE */
587 { 'v', '+' }, /* ACS_BTEE */
588 { 'n', '+' }, /* ACS_PLUS */
589 { 0, 0 } };
591 void init_curses (void)
593 int i;
594 initscr();
595 #ifdef HAVE_ESCDELAY
597 * If ncurses exports the ESCDELAY variable it should be set to 0
598 * or you'll have to press Esc three times to dismiss a dialog box.
600 ESCDELAY = 0;
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 done_screen ()
618 if (!(quit & SUBSHELL_EXIT))
619 clr_scr ();
620 reset_shell_mode ();
621 mc_noraw_mode ();
622 disable_mouse ();
623 keypad (stdscr, FALSE);
626 static void
627 panel_do_cols (int index)
629 if (get_display_type (index) == view_listing)
630 set_panel_formats ((WPanel *) panels [index].widget);
631 else {
632 panel_update_cols (panels [index].widget, frame_half);
634 /* In case of an Hex Quick View must review line length */
635 if (get_display_type (index) == view_quick)
636 view_update_bytes_per_line ((WView *) panels [index].widget);
640 void setup_panels (void)
642 int start_y;
643 int promptl; /* the prompt len */
645 if (console_flag){
646 int minimum;
647 if (output_lines < 0)
648 output_lines = 0;
649 height = LINES - keybar_visible - command_prompt - menubar_visible
650 - output_lines - message_visible;
651 if (message_visible && xterm_hintbar && xterm_flag) height++;
652 minimum = MINHEIGHT * (1 + horizontal_split);
653 if (height < minimum){
654 output_lines -= minimum - height;
655 height = minimum;
657 } else {
658 height = LINES - menubar_visible - command_prompt -
659 keybar_visible - message_visible;
660 if (message_visible && xterm_hintbar && xterm_flag) height++;
662 check_split ();
663 start_y = menubar_visible;
665 /* The column computing is defered until panel_do_cols */
666 if (horizontal_split){
667 widget_set_size (panels [0].widget, start_y, 0,
668 first_panel_size, 0);
670 widget_set_size (panels [1].widget, start_y+first_panel_size, 0,
671 height-first_panel_size, 0);
672 } else {
673 int first_x = first_panel_size;
675 widget_set_size (panels [0].widget, start_y, 0,
676 height, 0);
678 widget_set_size (panels [1].widget, start_y, first_x,
679 height, 0);
682 panel_do_cols (0);
683 panel_do_cols (1);
685 promptl = strlen (prompt);
687 widget_set_size (&the_menubar->widget, 0, 0, 1, COLS);
689 if (command_prompt) {
690 widget_set_size (&cmdline->input.widget,
691 LINES-1-keybar_visible, promptl,
692 1, COLS-promptl-(keybar_visible ? 0 : 1));
693 winput_set_origin (&cmdline->input, promptl, COLS-promptl-(keybar_visible ? 0 : 1));
694 widget_set_size (&the_prompt->widget,
695 LINES-1-keybar_visible, 0,
696 1, promptl);
697 } else {
698 widget_set_size (&cmdline->input.widget, 0, 0, 0, 0);
699 winput_set_origin (&cmdline->input, 0, 0);
700 widget_set_size (&the_prompt->widget, LINES, COLS, 0, 0);
703 widget_set_size (&the_bar->widget, LINES-1, 0, keybar_visible, COLS);
704 the_bar->visible = keybar_visible;
706 /* Output window */
707 if (console_flag && output_lines){
708 output_start_y = LINES -command_prompt-keybar_visible-
709 output_lines;
710 show_console_contents (output_start_y,
711 LINES-output_lines-keybar_visible-1,
712 LINES-keybar_visible-1);
714 if (message_visible && (!xterm_hintbar || !xterm_flag))
715 widget_set_size (&the_hint->widget, height+start_y, 0, 1,COLS);
716 else
717 widget_set_size (&the_hint->widget, 0, 0, 0, 0);
719 load_hint ();
722 void flag_winch (int dummy)
724 #ifndef USE_NCURSES /* don't do malloc in a signal handler */
725 low_level_change_screen_size ();
726 #endif
727 winch_flag = 1;
730 void edit_adjust_size (Dlg_head * h);
732 static void
733 low_level_change_screen_size (void)
735 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
736 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
737 struct winsize winsz;
739 winsz.ws_col = winsz.ws_row = 0;
740 /* Ioctl on the STDIN_FILENO */
741 ioctl (0, TIOCGWINSZ, &winsz);
742 if (winsz.ws_col && winsz.ws_row){
743 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
744 resizeterm(winsz.ws_row, winsz.ws_col);
745 clearok(stdscr,TRUE); /* sigwinch's should use a semaphore! */
746 #else
747 COLS = winsz.ws_col;
748 LINES = winsz.ws_row;
749 #endif
750 #ifdef HAVE_SUBSHELL_SUPPORT
751 resize_subshell ();
752 #endif
754 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
755 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
758 void change_screen_size (void)
760 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
761 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
763 #ifndef NCURSES_VERSION
764 mc_noraw_mode ();
765 endwin ();
766 #endif
767 low_level_change_screen_size ();
768 check_split ();
769 #ifndef NCURSES_VERSION
770 /* XSI Curses spec states that portable applications shall not invoke
771 * initscr() more than once. This kludge could be done within the scope
772 * of the specification by using endwin followed by a refresh (in fact,
773 * more than one curses implementation does this); it is guaranteed to work
774 * only with slang.
776 init_curses ();
777 #endif
778 setup_panels ();
779 if (current_dlg == view_dlg)
780 view_adjust_size (view_dlg);
781 #ifdef USE_INTERNAL_EDIT
782 if (current_dlg == edit_dlg)
783 edit_adjust_size (edit_dlg);
784 #endif
786 #ifdef RESIZABLE_MENUBAR
787 menubar_arrange(the_menubar);
788 #endif
790 /* Now, force the redraw */
791 do_refresh ();
792 touchwin (stdscr);
793 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
794 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
795 winch_flag = 0;
798 static int ok_to_refresh = 1;
800 void use_dash (int flag)
802 if (flag)
803 ok_to_refresh++;
804 else
805 ok_to_refresh--;
808 void set_hintbar(char *str)
810 if (xterm_flag && xterm_hintbar) {
811 fprintf (stdout, "\33]0;mc - %s\7", str);
812 fflush (stdout);
813 } else {
814 label_set_text (the_hint, str);
815 if (ok_to_refresh > 0)
816 refresh();
820 void print_vfs_message (char *msg, ...)
822 va_list ap;
823 char str [128];
825 va_start (ap, msg);
827 g_vsnprintf (str, sizeof (str), msg, ap);
828 va_end (ap);
830 if (midnight_shutdown)
831 return;
833 if (!message_visible || !the_hint || !the_hint->widget.parent) {
835 if (!nice_rotating_dash || (ok_to_refresh <= 0))
836 return;
837 move (0, 0);
838 attrset (NORMAL_COLOR);
839 printw ("%-*s", COLS-1, str);
840 mc_refresh ();
841 return;
844 if (message_visible || (xterm_flag && xterm_hintbar)) {
845 set_hintbar(str);
849 void rotate_dash (void)
851 static char rotating_dash [] = "|/-\\";
852 static int pos = 0;
854 if (!nice_rotating_dash || (ok_to_refresh <= 0))
855 return;
857 if (pos >= sizeof (rotating_dash)-1)
858 pos = 0;
859 move (0, COLS-1);
860 addch (rotating_dash [pos]);
861 mc_refresh ();
862 pos++;
865 void remove_dash (void)
867 if (!nice_rotating_dash)
868 return;
870 /* Currently, it's much nicer with the CPU to do this instead of
871 calling do_refresh.
873 I should implement a routine called invalidate_region that would
874 send a draw message only to the affected views. But for now
875 this is fine.
878 move (0, COLS-1);
879 addch (' ');
882 char *get_nth_panel_name (int num)
884 static char buffer [BUF_SMALL];
886 if (!num)
887 return "New Left Panel";
888 else if (num == 1)
889 return "New Right Panel";
890 else {
891 g_snprintf (buffer, sizeof (buffer), "%ith Panel", num);
892 return buffer;
896 /* I wonder if I should start to use the folding mode than Dugan uses */
897 /* */
898 /* This is the centralized managing of the panel display types */
899 /* This routine takes care of destroying and creating new widgets */
900 /* Please note that it could manage MAX_VIEWS, not just left and right */
901 /* Currently nothing in the code takes advantage of this and has hard- */
902 /* coded values for two panels only */
904 /* Set the num-th panel to the view type: type */
905 /* This routine also keeps at least one WPanel object in the screen */
906 /* since a lot of routines depend on the current_panel variable */
907 void set_display_type (int num, int type)
909 int x, y, cols, lines;
910 int the_other; /* Index to the other panel */
911 char *file_name = 0; /* For Quick view */
912 Widget *new_widget, *old_widget;
913 WPanel *the_other_panel;
915 x = y = cols = lines = 0;
916 old_widget = 0;
917 if (num >= MAX_VIEWS){
918 fprintf (stderr, "Could not allocate more that %d views\n", MAX_VIEWS);
919 abort ();
922 /* Check that we will have a WPanel * at least */
923 the_other = 0;
924 if (type != view_listing){
925 the_other = num == 0 ? 1 : 0;
927 if (panels [the_other].type != view_listing)
928 return;
932 /* Get rid of it */
933 if (panels [num].widget){
934 Widget *w = panels [num].widget;
935 WPanel *panel = (WPanel *) panels [num].widget;
937 x = w->x;
938 y = w->y;
939 cols = w->cols;
940 lines = w->lines;
941 old_widget = panels [num].widget;
943 if (panels [num].type == view_listing){
944 if (panel->frame_size == frame_full && type != view_listing){
945 cols = COLS - first_panel_size;
946 if (num == 1)
947 x = first_panel_size;
952 new_widget = 0;
954 switch (type){
955 case view_listing:
956 new_widget = (Widget *) panel_new (get_nth_panel_name (num));
957 break;
959 case view_info:
960 new_widget = (Widget *) info_new ();
962 break;
964 case view_tree:
965 new_widget = (Widget *) tree_new (1, 0, 0, 0, 0);
966 break;
968 case view_quick:
969 new_widget = (Widget *) view_new (0, 0, 0, 0, 1);
970 the_other_panel = (WPanel *) panels [the_other].widget;
971 if (the_other_panel)
972 file_name =
973 the_other_panel->dir.list[the_other_panel->selected].fname;
974 else
975 file_name = "";
977 view_init ((WView *) new_widget, 0, file_name, 0);
978 break;
980 panels [num].type = type;
981 panels [num].widget = (Widget *) new_widget;
983 /* We set the same size the old widget had */
984 widget_set_size ((Widget *) new_widget, y, x, lines, cols);
986 /* We use replace to keep the circular list of the dialog in the */
987 /* same state. Maybe we could just kill it and then replace it */
988 if (midnight_dlg && old_widget){
989 dlg_replace_widget (midnight_dlg, old_widget, panels [num].widget);
991 if (type == view_listing){
992 if (num == 0)
993 left_panel = (WPanel *) new_widget;
994 else
995 right_panel = (WPanel *) new_widget;
998 if (type == view_tree)
999 the_tree = (WTree *) new_widget;
1001 /* Prevent current_panel's value from becoming invalid.
1002 * It's just a quick hack to prevent segfaults. Comment out and
1003 * try following:
1004 * - select left panel
1005 * - invoke menue left/tree
1006 * - as long as you stay in the left panel almost everything that uses
1007 * cpanel causes segfault, e.g. C-Enter, C-x c, ...
1010 if (type != view_listing)
1011 if (cpanel == (WPanel *) old_widget)
1012 current_panel = num == 0 ? right_panel : left_panel;
1015 /* This routine is deeply sticked to the two panels idea.
1016 What should it do in more panels. ANSWER - don't use it
1017 in any multiple panels environment. */
1018 void swap_panels ()
1020 Widget tmp;
1021 Widget *tmp_widget;
1022 WPanel panel;
1023 WPanel *panel1, *panel2;
1024 int tmp_type;
1026 #define panelswap(x) panel. x = panel1-> x; panel1-> x = panel2-> x; panel2-> x = panel. x;
1028 #define panelswapstr(e) strcpy (panel. e, panel1-> e); \
1029 strcpy (panel1-> e, panel2-> e); \
1030 strcpy (panel2-> e, panel. e);
1031 panel1 = (WPanel *) panels [0].widget;
1032 panel2 = (WPanel *) panels [1].widget;
1033 if (panels [0].type == view_listing && panels [1].type == view_listing) {
1034 /* Change everything except format/sort/panel_name etc. */
1035 panelswap (dir);
1036 panelswap (active);
1037 panelswapstr (cwd);
1038 panelswapstr (lwd);
1039 panelswap (count);
1040 panelswap (marked);
1041 panelswap (dirs_marked);
1042 panelswap (total);
1043 panelswap (top_file);
1044 panelswap (selected);
1045 panelswap (is_panelized);
1046 panelswap (dir_stat);
1048 panel1->searching = 0;
1049 panel2->searching = 0;
1050 if (cpanel == panel1)
1051 current_panel = panel2;
1052 else
1053 current_panel = panel1;
1054 if (midnight_dlg->current->widget == panels [0].widget)
1055 dlg_select_widget (midnight_dlg, (void *) panels [1].widget);
1056 else if (midnight_dlg->current->widget == panels [1].widget)
1057 dlg_select_widget (midnight_dlg, (void *) panels [0].widget);
1058 } else {
1059 WPanel *tmp_panel;
1061 tmp_panel=right_panel;
1062 right_panel=left_panel;
1063 left_panel=tmp_panel;
1065 if (panels [0].type == view_listing) {
1066 if (!strcmp (panel1->panel_name, get_nth_panel_name (0))) {
1067 g_free (panel1->panel_name);
1068 panel1->panel_name = g_strdup (get_nth_panel_name (1));
1071 if (panels [1].type == view_listing) {
1072 if (!strcmp (panel2->panel_name, get_nth_panel_name (1))) {
1073 g_free (panel2->panel_name);
1074 panel2->panel_name = g_strdup (get_nth_panel_name (0));
1078 tmp.x = panels [0].widget->x;
1079 tmp.y = panels [0].widget->y;
1080 tmp.cols = panels [0].widget->cols;
1081 tmp.lines = panels [0].widget->lines;
1083 panels [0].widget->x = panels [1].widget->x;
1084 panels [0].widget->y = panels [1].widget->y;
1085 panels [0].widget->cols = panels [1].widget->cols;
1086 panels [0].widget->lines = panels [1].widget->lines;
1088 panels [1].widget->x = tmp.x;
1089 panels [1].widget->y = tmp.y;
1090 panels [1].widget->cols = tmp.cols;
1091 panels [1].widget->lines = tmp.lines;
1093 tmp_widget = panels [0].widget;
1094 panels [0].widget = panels [1].widget;
1095 panels [1].widget = tmp_widget;
1096 tmp_type = panels [0].type;
1097 panels [0].type = panels [1].type;
1098 panels [1].type = tmp_type;
1102 int get_display_type (int index)
1104 return panels [index].type;
1107 Widget *get_panel_widget (int index)
1109 return panels [index].widget;
1112 int get_current_index (void)
1114 if (panels [0].widget == ((Widget *) cpanel))
1115 return 0;
1116 else
1117 return 1;
1120 int get_other_index (void)
1122 return !get_current_index ();
1125 /* Returns the view type for the current panel/view */
1126 int get_current_type (void)
1128 if (panels [0].widget == (Widget *) cpanel)
1129 return panels [0].type;
1130 else
1131 return panels [1].type;
1134 /* Returns the view type of the unselected panel */
1135 int get_other_type (void)
1137 if (panels [0].widget == (Widget *) cpanel)
1138 return panels [1].type;
1139 else
1140 return panels [0].type;