*** empty log message ***
[midnight-commander.git] / src / layout.c
blob806530e21043e2a3e772d5d0bdcc7436ae81c816
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 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")
158 WRadio *radio_widget;
160 static struct {
161 char *text;
162 int *variable;
163 WCheck *widget;
164 char *tkname;
165 } check_options [] = {
166 { N_("&Xterm hintbar"), &xterm_hintbar, 0, "h" },
167 { N_("h&Intbar visible"), &message_visible, 0, "v" },
168 { N_("&Keybar visible"), &keybar_visible, 0, "k" },
169 { N_("command &Prompt"), &command_prompt, 0, "p" },
170 { N_("show &Mini status"), &show_mini_info, 0, "m" },
171 { N_("menu&Bar visible"), &menubar_visible, 0, "me" },
172 { N_("&Equal split"), &equal_split, 0, "eq" },
173 { N_("pe&Rmissions"), &permission_mode, 0, "pr" },
174 { N_("&File types"), &filetype_mode, 0, "ft" },
175 { 0, 0, 0, 0 }
178 static int first_width, second_width;
179 static char *layout_title, *title1, *title2, *title3, *output_lines_label;
181 static WButton *bleft_widget, *bright_widget;
183 /* Declarations for static functions */
184 static void low_level_change_screen_size (void);
186 static void _check_split (void)
188 if (_horizontal_split){
189 if (_equal_split)
190 _first_panel_size = height / 2;
191 else if (_first_panel_size < MINHEIGHT)
192 _first_panel_size = MINHEIGHT;
193 else if (_first_panel_size > height - MINHEIGHT)
194 _first_panel_size = height - MINHEIGHT;
195 } else {
196 if (_equal_split)
197 _first_panel_size = COLS / 2;
198 else if (_first_panel_size < MINWIDTH)
199 _first_panel_size = MINWIDTH;
200 else if (_first_panel_size > COLS - MINWIDTH)
201 _first_panel_size = COLS - MINWIDTH;
205 static void update_split (void)
207 /* Check split has to be done before testing if it changed, since
208 it can change due to calling _check_split() as well*/
209 _check_split ();
211 /* To avoid setting the cursor to the wrong place */
212 if ((old_first_panel_size == _first_panel_size) &&
213 (old_horizontal_split == _horizontal_split)){
214 return;
217 old_first_panel_size = _first_panel_size;
218 old_horizontal_split = _horizontal_split;
220 attrset (COLOR_NORMAL);
221 dlg_move (layout_dlg, 6, 6);
222 printw ("%03d", _first_panel_size);
223 dlg_move (layout_dlg, 6, 18);
224 if (_horizontal_split)
225 printw ("%03d", height - _first_panel_size);
226 else
227 printw ("%03d", COLS - _first_panel_size);
230 static int b2left_cback (int action, void *data)
232 if (_equal_split){
233 /* Turn equal split off */
234 _equal_split = 0;
235 check_options [6].widget->state = check_options [6].widget->state & ~C_BOOL;
236 dlg_select_widget (layout_dlg, check_options [6].widget);
237 dlg_select_widget (layout_dlg, bleft_widget);
239 _first_panel_size++;
240 return 0;
243 static int b2right_cback (int action, void *data)
245 if (_equal_split){
246 /* Turn equal split off */
247 _equal_split = 0;
248 check_options [6].widget->state = check_options [6].widget->state & ~C_BOOL;
249 dlg_select_widget (layout_dlg, check_options [6].widget);
250 dlg_select_widget (layout_dlg, bright_widget);
252 _first_panel_size--;
253 return 0;
256 static int bplus_cback (int action, void *data)
258 if (_output_lines < 99)
259 _output_lines++;
260 return 0;
263 static int bminus_cback (int action, void *data)
265 if (_output_lines > 0)
266 _output_lines--;
267 return 0;
270 static int layout_callback (struct Dlg_head *h, int Id, int Msg)
272 switch (Msg){
273 case DLG_DRAW:
274 /*When repainting the whole dialog (e.g. with C-l) we have to
275 update everything*/
276 old_first_panel_size = -1;
277 old_horizontal_split = -1;
278 old_output_lines = -1;
279 attrset (COLOR_NORMAL);
280 dlg_erase (h);
281 draw_box (h, 1, 2, h->lines - 2, h->cols - 4);
282 draw_box (h, 2, 4, 6, first_width);
283 draw_box (h, 8, 4, 4, first_width);
284 draw_box (h, 2, 5 + first_width, 10, second_width);
286 attrset (COLOR_HOT_NORMAL);
287 dlg_move (h, 1, (h->cols - strlen(layout_title))/2);
288 addstr (layout_title);
289 dlg_move (h, 2, 5);
290 addstr (title1);
291 dlg_move (h, 8, 5);
292 addstr (title2);
293 dlg_move (h, 2, 6 + first_width);
294 addstr (title3);
295 update_split ();
296 dlg_move (h, 6, 13);
297 addch ('=');
298 if (console_flag){
299 if (old_output_lines != _output_lines){
300 old_output_lines = _output_lines;
301 attrset (COLOR_NORMAL);
302 dlg_move (h, 9, 16 + first_width);
303 addstr (output_lines_label);
304 dlg_move (h, 9, 10 + first_width);
305 printw ("%02d", _output_lines);
308 break;
310 case DLG_POST_KEY:
311 _filetype_mode = check_options [8].widget->state & C_BOOL;
312 _permission_mode = check_options [7].widget->state & C_BOOL;
313 _equal_split = check_options [6].widget->state & C_BOOL;
314 _menubar_visible = check_options [5].widget->state & C_BOOL;
315 _command_prompt = check_options [4].widget->state & C_BOOL;
316 _keybar_visible = check_options [2].widget->state & C_BOOL;
317 _message_visible = check_options [1].widget->state & C_BOOL;
318 _xterm_hintbar = check_options [0].widget->state & C_BOOL;
319 if (console_flag){
320 int minimum;
321 if (_output_lines < 0)
322 _output_lines = 0;
323 height = LINES - _keybar_visible - _command_prompt -
324 _menubar_visible - _output_lines - _message_visible;
325 if (_message_visible && _xterm_hintbar && xterm_flag) height++;
326 minimum = MINHEIGHT * (1 + _horizontal_split);
327 if (height < minimum){
328 _output_lines -= minimum - height;
329 height = minimum;
331 } else {
332 height = LINES - _keybar_visible - _command_prompt -
333 _menubar_visible - _output_lines - _message_visible;
334 if (_message_visible && _xterm_hintbar && xterm_flag) height++;
336 if (_horizontal_split != radio_widget->sel){
337 _horizontal_split = radio_widget->sel;
338 if (_horizontal_split)
339 _first_panel_size = height / 2;
340 else
341 _first_panel_size = COLS / 2;
343 update_split ();
344 if (console_flag){
345 if (old_output_lines != _output_lines){
346 old_output_lines = _output_lines;
347 attrset (COLOR_NORMAL);
348 dlg_move (h, 9, 10 + first_width);
349 printw ("%02d", _output_lines);
352 break;
354 case DLG_END:
355 break;
357 return 0;
360 static void init_layout (void)
362 static int i18n_layt_flag = 0;
363 static int b1, b2, b3;
364 int i = sizeof (s_split_direction) / sizeof(char*) ;
365 char* ok_button = _("&Ok");
366 char* cancel_button = _("&Cancel");
367 char* save_button = _("&Save");
369 if (!i18n_layt_flag)
371 register int l1;
373 first_width = 19; /* length of line with '<' '>' buttons */
375 layout_title = _(" Layout ");
376 title1 = _(" Panel split ");
377 title2 = _(" Highlight... ");
378 title3 = _(" Other options ");
379 output_lines_label = _("output lines");
381 while (i--)
383 s_split_direction [i] = _(s_split_direction [i]);
384 l1 = strlen (s_split_direction [i]) + 7;
385 if (l1 > first_width)
386 first_width = l1;
389 for (i = 0; i <= 8; i++)
391 check_options[i].text = _(check_options[i].text);
392 l1 = strlen (check_options[i].text) + 7;
393 if (l1 > first_width)
394 first_width = l1;
397 l1 = strlen (title1) + 1;
398 if (l1 > first_width)
399 first_width = l1;
401 l1 = strlen (title2) + 1;
402 if (l1 > first_width)
403 first_width = l1;
406 second_width = strlen (title3) + 1;
407 for (i = 0; i < 6; i++)
409 check_options[i].text = _(check_options[i].text);
410 l1 = strlen (check_options[i].text) + 7;
411 if (l1 > second_width)
412 second_width = l1;
414 if (console_flag)
416 l1 = strlen (output_lines_label) + 13;
417 if (l1 > second_width)
418 second_width = l1;
422 * alex@bcs.zp.ua:
423 * To be completely correct, one need to check if layout_title
424 * does not exceed dialog length and total length of 3 buttons
425 * allows their placement in one row. But assuming this dialog
426 * is wide enough, I don't include such a tests.
428 * Now the last thing to do - properly space buttons...
430 l1 = 11 + strlen (ok_button) /* 14 - all brackets and inner space */
431 + strlen (save_button) /* notice: it is 3 char less because */
432 + strlen (cancel_button); /* of '&' char in button text */
434 i = (first_width + second_width - l1) / 4;
435 b1 = 5 + i;
436 b2 = b1 + strlen(ok_button) + i + 6;
437 b3 = b2 + strlen(save_button) + i + 4;
439 i18n_layt_flag = 1;
442 layout_dlg = create_dlg (0, 0, 15, first_width + second_width + 9,
443 dialog_colors, layout_callback,
444 "[Layout]", "layout", DLG_CENTER | DLG_GRID);
446 x_set_dialog_title (layout_dlg, _("Layout"));
448 add_widget (layout_dlg,
449 button_new (BY, b3, B_CANCEL, NORMAL_BUTTON, cancel_button, 0, 0, "c"));
450 add_widget (layout_dlg,
451 button_new (BY, b2, B_EXIT, NORMAL_BUTTON, save_button, 0, 0, "s"));
452 add_widget (layout_dlg,
453 button_new (BY, b1, B_ENTER, DEFPUSH_BUTTON, ok_button, 0, 0, "o"));
454 if (console_flag){
455 add_widget (layout_dlg,
456 button_new (9, 12 + first_width, B_MINUS, NARROW_BUTTON, "&-",
457 bminus_cback, 0, NULL));
458 add_widget (layout_dlg,
459 button_new (9, 7 + first_width, B_PLUS, NARROW_BUTTON, "&+",
460 bplus_cback, 0, NULL));
463 #define XTRACT(i) *check_options[i].variable, check_options[i].text, check_options[i].tkname
465 for (i = 0; i < 6; i++){
466 check_options [i].widget = check_new (8 - i, 7 + first_width, XTRACT(i));
467 add_widget (layout_dlg, check_options [i].widget);
469 check_options [8].widget = check_new (10, 6, XTRACT(8));
470 add_widget (layout_dlg, check_options [8].widget);
471 check_options [7].widget = check_new (9, 6, XTRACT(7));
472 add_widget (layout_dlg, check_options [7].widget);
474 _filetype_mode = filetype_mode;
475 _permission_mode = permission_mode;
476 _equal_split = equal_split;
477 _menubar_visible = menubar_visible;
478 _command_prompt = command_prompt;
479 _keybar_visible = keybar_visible;
480 _message_visible = message_visible;
481 _xterm_hintbar = xterm_hintbar;
482 bright_widget = button_new(6, 15, B_2RIGHT, NARROW_BUTTON, "&>", b2right_cback, 0, ">");
483 add_widget (layout_dlg, bright_widget);
484 bleft_widget = button_new (6, 9, B_2LEFT, NARROW_BUTTON, "&<", b2left_cback, 0, "<");
485 add_widget (layout_dlg, bleft_widget);
486 check_options [6].widget = check_new (5, 6, XTRACT(6));
487 old_first_panel_size = -1;
488 old_horizontal_split = -1;
489 old_output_lines = -1;
491 _first_panel_size = first_panel_size;
492 _output_lines = output_lines;
493 add_widget (layout_dlg, check_options [6].widget);
494 radio_widget = radio_new (3, 6, 2, s_split_direction, 1, "r");
495 add_widget (layout_dlg, radio_widget);
496 radio_widget->sel = horizontal_split;
499 void layout_change (void)
501 setup_panels ();
502 layout_do_change = 0;
503 /* re-init the menu, because perhaps there was a change in the way
504 how the panel are split (horizontal/vertical). */
505 done_menu();
506 init_menu();
507 menubar_arrange(the_menubar);
510 void layout_cmd (void)
512 int result;
513 int i;
515 init_layout ();
516 run_dlg (layout_dlg);
517 result = layout_dlg->ret_value;
519 if (result == B_ENTER || result == B_EXIT){
520 for (i = 0; check_options [i].text; i++)
521 if (check_options [i].widget)
522 *check_options [i].variable = check_options [i].widget->state & C_BOOL;
523 horizontal_split = radio_widget->sel;
524 first_panel_size = _first_panel_size;
525 output_lines = _output_lines;
526 layout_do_change = 1;
528 if (result == B_EXIT){
529 save_layout ();
530 sync_profiles ();
533 destroy_dlg (layout_dlg);
534 if (layout_do_change)
535 layout_change ();
538 static void check_split (void)
540 if (horizontal_split){
541 if (equal_split)
542 first_panel_size = height / 2;
543 else if (first_panel_size < MINHEIGHT)
544 first_panel_size = MINHEIGHT;
545 else if (first_panel_size > height - MINHEIGHT)
546 first_panel_size = height - MINHEIGHT;
547 } else {
548 if (equal_split)
549 first_panel_size = COLS / 2;
550 else if (first_panel_size < MINWIDTH)
551 first_panel_size = MINWIDTH;
552 else if (first_panel_size > COLS - MINWIDTH)
553 first_panel_size = COLS - MINWIDTH;
557 #ifdef HAVE_SLANG
558 void init_curses ()
560 SLtt_get_terminfo ();
561 #ifndef HAS_ACS_AS_PCCHARS
562 if (force_ugly_line_drawing)
563 SLtt_Has_Alt_Charset = 0;
564 #endif
565 SLsmg_init_smg ();
566 do_enter_ca_mode ();
567 init_colors ();
568 keypad (stdscr, TRUE);
569 nodelay (stdscr, FALSE);
571 #else
572 void init_curses (void)
574 initscr();
575 #ifdef HAVE_ESCDELAY
577 * If ncurses exports the ESCDELAY variable it should be set to 0
578 * or you'll have to press Esc three times to dismiss a dialog box.
580 ESCDELAY = 0;
581 #endif /* HAVE_ESCDELAY */
582 do_enter_ca_mode ();
583 mc_raw_mode ();
584 noecho ();
585 keypad (stdscr, TRUE);
586 nodelay (stdscr, FALSE);
587 init_colors ();
589 #endif /* ! HAVE_SLANG */
591 void done_screen ()
593 if (!(quit & SUBSHELL_EXIT))
594 clr_scr ();
595 reset_shell_mode ();
596 mc_noraw_mode ();
597 disable_mouse ();
598 keypad (stdscr, FALSE);
601 static void
602 panel_do_cols (int index)
604 if (get_display_type (index) == view_listing)
605 set_panel_formats ((WPanel *) panels [index].widget);
606 else {
607 panel_update_cols (panels [index].widget, frame_half);
609 /* In case of an Hex Quick View must review line length */
610 if (get_display_type (index) == view_quick)
611 view_update_bytes_per_line ((WView *) panels [index].widget);
615 void setup_panels (void)
617 int start_y;
618 int promptl; /* the prompt len */
620 if (console_flag){
621 int minimum;
622 if (output_lines < 0)
623 output_lines = 0;
624 height = LINES - keybar_visible - command_prompt - menubar_visible
625 - output_lines - message_visible;
626 if (message_visible && xterm_hintbar && xterm_flag) height++;
627 minimum = MINHEIGHT * (1 + horizontal_split);
628 if (height < minimum){
629 output_lines -= minimum - height;
630 height = minimum;
632 } else {
633 height = LINES - menubar_visible - command_prompt -
634 keybar_visible - message_visible;
635 if (message_visible && xterm_hintbar && xterm_flag) height++;
637 check_split ();
638 start_y = menubar_visible;
640 /* The column computing is defered until panel_do_cols */
641 if (horizontal_split){
642 widget_set_size (panels [0].widget, start_y, 0,
643 first_panel_size, 0);
645 widget_set_size (panels [1].widget, start_y+first_panel_size, 0,
646 height-first_panel_size, 0);
647 } else {
648 int first_x = first_panel_size;
650 widget_set_size (panels [0].widget, start_y, 0,
651 height, 0);
653 widget_set_size (panels [1].widget, start_y, first_x,
654 height, 0);
657 panel_do_cols (0);
658 panel_do_cols (1);
660 promptl = strlen (prompt);
662 widget_set_size (&the_menubar->widget, 0, 0, 1, COLS);
664 if (command_prompt) {
665 widget_set_size (&cmdline->input.widget,
666 LINES-1-keybar_visible, promptl,
667 1, COLS-promptl-(keybar_visible ? 0 : 1));
668 winput_set_origin (&cmdline->input, promptl, COLS-promptl-(keybar_visible ? 0 : 1));
669 widget_set_size (&the_prompt->widget,
670 LINES-1-keybar_visible, 0,
671 1, promptl);
672 } else {
673 widget_set_size (&cmdline->input.widget, 0, 0, 0, 0);
674 winput_set_origin (&cmdline->input, 0, 0);
675 widget_set_size (&the_prompt->widget, LINES, COLS, 0, 0);
678 widget_set_size (&the_bar->widget, LINES-1, 0, 1, COLS);
679 the_bar->visible = keybar_visible;
681 /* Output window */
682 if (console_flag && output_lines){
683 output_start_y = LINES -command_prompt-keybar_visible-
684 output_lines;
685 show_console_contents (output_start_y,
686 LINES-output_lines-keybar_visible-1,
687 LINES-keybar_visible-1);
689 if (message_visible && (!xterm_hintbar || !xterm_flag))
690 widget_set_size (&the_hint->widget, height+start_y, 0, 1,COLS);
691 else
692 widget_set_size (&the_hint->widget, 0, 0, 0, 0);
694 load_hint ();
697 void flag_winch (int dummy)
699 low_level_change_screen_size ();
700 winch_flag = 1;
703 void edit_adjust_size (Dlg_head * h);
705 static void
706 low_level_change_screen_size (void)
708 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
709 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
710 struct winsize winsz;
712 winsz.ws_col = winsz.ws_row = 0;
713 /* Ioctl on the STDIN_FILENO */
714 ioctl (0, TIOCGWINSZ, &winsz);
715 if (winsz.ws_col && winsz.ws_row){
716 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
717 resizeterm(winsz.ws_row, winsz.ws_col);
718 clearok(stdscr,TRUE); /* FIXME: sigwinch's should use a semaphore! */
719 #else
720 COLS = winsz.ws_col;
721 LINES = winsz.ws_row;
722 #endif
723 #ifdef HAVE_SUBSHELL_SUPPORT
724 resize_subshell ();
725 #endif
727 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
728 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
731 void change_screen_size (void)
733 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
734 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
736 #ifndef NCURSES_VERSION
737 mc_noraw_mode ();
738 endwin ();
739 #endif
740 low_level_change_screen_size ();
741 check_split ();
742 #ifndef NCURSES_VERSION
743 /* XSI Curses spec states that portable applications shall not invoke
744 * initscr() more than once. This kludge could be done within the scope
745 * of the specification by using endwin followed by a refresh (in fact,
746 * more than one curses implementation does this); it is guaranteed to work
747 * only with slang.
749 init_curses ();
750 #endif
751 setup_panels ();
752 if (current_dlg == view_dlg)
753 view_adjust_size (view_dlg);
754 #ifdef USE_INTERNAL_EDIT
755 if (current_dlg == edit_dlg)
756 edit_adjust_size (edit_dlg);
757 #endif
759 #ifdef RESIZABLE_MENUBAR
760 menubar_arrange(the_menubar);
761 #endif
763 /* Now, force the redraw */
764 do_refresh ();
765 touchwin (stdscr);
766 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
767 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
768 winch_flag = 0;
771 static int ok_to_refresh = 1;
773 void use_dash (int flag)
775 if (flag)
776 ok_to_refresh++;
777 else
778 ok_to_refresh--;
781 void set_hintbar(char *str)
783 if (xterm_flag && xterm_hintbar) {
784 fprintf (stdout, "\33]0;mc - %s\7", str);
785 fflush (stdout);
786 } else {
787 label_set_text (the_hint, str);
788 if (ok_to_refresh > 0)
789 refresh();
793 void print_vfs_message (char *msg, ...)
795 va_list ap;
796 char str [128];
798 va_start (ap, msg);
800 g_vsnprintf (str, sizeof (str), msg, ap);
801 va_end (ap);
803 if (midnight_shutdown)
804 return;
806 if (!message_visible || !the_hint || !the_hint->widget.parent) {
808 if (!nice_rotating_dash || (ok_to_refresh <= 0))
809 return;
810 move (0, 0);
811 printw ("%-*s", COLS-1, str);
812 mc_refresh ();
813 return;
816 if (message_visible || (xterm_flag && xterm_hintbar)) {
817 set_hintbar(str);
821 void rotate_dash (void)
823 static char rotating_dash [] = "|/-\\";
824 static int pos = 0;
826 if (!nice_rotating_dash || (ok_to_refresh <= 0))
827 return;
829 if (pos >= sizeof (rotating_dash)-1)
830 pos = 0;
831 move (0, COLS-1);
832 addch (rotating_dash [pos]);
833 mc_refresh ();
834 pos++;
837 void remove_dash (void)
839 if (!nice_rotating_dash)
840 return;
842 /* Currently, it's much nicer with the CPU to do this instead of
843 calling do_refresh.
845 I should implement a routine called invalidate_region that would
846 send a draw message only to the affected views. But for now
847 this is fine.
850 move (0, COLS-1);
851 addch (' ');
854 char *get_nth_panel_name (int num)
856 static char buffer [BUF_SMALL];
858 if (!num)
859 return "New Left Panel";
860 else if (num == 1)
861 return "New Right Panel";
862 else {
863 g_snprintf (buffer, sizeof (buffer), "%ith Panel", num);
864 return buffer;
868 /* I wonder if I should start to use the folding mode than Dugan uses */
869 /* */
870 /* This is the centralized managing of the panel display types */
871 /* This routine takes care of destroying and creating new widgets */
872 /* Please note that it could manage MAX_VIEWS, not just left and right */
873 /* Currently nothing in the code takes advantage of this and has hard- */
874 /* coded values for two panels only */
876 /* Set the num-th panel to the view type: type */
877 /* This routine also keeps at least one WPanel object in the screen */
878 /* since a lot of routines depend on the current_panel variable */
879 void set_display_type (int num, int type)
881 int x, y, cols, lines;
882 int the_other; /* Index to the other panel */
883 char *file_name = 0; /* For Quick view */
884 Widget *new_widget, *old_widget;
885 WPanel *the_other_panel;
887 x = y = cols = lines = 0;
888 old_widget = 0;
889 if (num >= MAX_VIEWS){
890 fprintf (stderr, "Could not allocate more that %d views\n", MAX_VIEWS);
891 abort ();
894 /* Check that we will have a WPanel * at least */
895 the_other = 0;
896 if (type != view_listing){
897 the_other = num == 0 ? 1 : 0;
899 if (panels [the_other].type != view_listing)
900 return;
904 /* Get rid of it */
905 if (panels [num].widget){
906 Widget *w = panels [num].widget;
907 WPanel *panel = (WPanel *) panels [num].widget;
909 x = w->x;
910 y = w->y;
911 cols = w->cols;
912 lines = w->lines;
913 old_widget = panels [num].widget;
915 if (panels [num].type == view_listing){
916 if (panel->frame_size == frame_full && type != view_listing){
917 cols = COLS - first_panel_size;
918 if (num == 1)
919 x = first_panel_size;
924 new_widget = 0;
926 switch (type){
927 case view_listing:
928 new_widget = (Widget *) panel_new (get_nth_panel_name (num));
929 break;
931 case view_info:
932 new_widget = (Widget *) info_new ();
934 break;
936 case view_tree:
937 new_widget = (Widget *) tree_new (1, 0, 0, 0, 0);
938 break;
940 case view_quick:
941 new_widget = (Widget *) view_new (0, 0, 0, 0, 1);
942 the_other_panel = (WPanel *) panels [the_other].widget;
943 if (the_other_panel)
944 file_name =
945 the_other_panel->dir.list[the_other_panel->selected].fname;
946 else
947 file_name = "";
949 view_init ((WView *) new_widget, 0, file_name, 0);
950 break;
952 panels [num].type = type;
953 panels [num].widget = (Widget *) new_widget;
955 /* We set the same size the old widget had */
956 widget_set_size ((Widget *) new_widget, y, x, lines, cols);
958 /* We wanna the new widget at the same position */
959 /* XView sets wcontainer to !0 <- Not XView, but we, when we create it */
960 /* Ok, the XView support code does it */
961 if (old_widget && old_widget->wcontainer){
962 new_widget->wcontainer = old_widget->wcontainer;
963 new_widget->area = old_widget->area;
966 /* We use replace to keep the circular list of the dialog in the */
967 /* same state. Maybe we could just kill it and then replace it */
968 if (midnight_dlg && old_widget){
969 dlg_replace_widget (midnight_dlg, old_widget, panels [num].widget);
971 if (type == view_listing){
972 if (num == 0)
973 left_panel = (WPanel *) new_widget;
974 else
975 right_panel = (WPanel *) new_widget;
978 if (type == view_tree)
979 the_tree = (WTree *) new_widget;
981 /* Prevent current_panel's value from becoming invalid.
982 * It's just a quick hack to prevent segfaults. Comment out and
983 * try following:
984 * - select left panel
985 * - invoke menue left/tree
986 * - as long as you stay in the left panel almost everything that uses
987 * cpanel causes segfault, e.g. C-Enter, C-x c, ...
990 if (type != view_listing)
991 if (cpanel == (WPanel *) old_widget)
992 current_panel = num == 0 ? right_panel : left_panel;
995 /* This routine is deeply sticked to the two panels idea.
996 What should it do in more panels. ANSWER - don't use it
997 in any multiple panels environment. */
998 void swap_panels ()
1000 Widget tmp;
1001 Widget *tmp_widget;
1002 WPanel panel;
1003 WPanel *panel1, *panel2;
1004 int tmp_type;
1006 #define panelswap(x) panel. x = panel1-> x; panel1-> x = panel2-> x; panel2-> x = panel. x;
1008 #define panelswapstr(e) strcpy (panel. e, panel1-> e); \
1009 strcpy (panel1-> e, panel2-> e); \
1010 strcpy (panel2-> e, panel. e);
1011 panel1 = (WPanel *) panels [0].widget;
1012 panel2 = (WPanel *) panels [1].widget;
1013 if (panels [0].type == view_listing && panels [1].type == view_listing) {
1014 /* Change everything except format/sort/panel_name etc. */
1015 panelswap (dir);
1016 panelswap (active);
1017 panelswapstr (cwd);
1018 panelswapstr (lwd);
1019 panelswap (count);
1020 panelswap (marked);
1021 panelswap (dirs_marked);
1022 panelswap (total);
1023 panelswap (top_file);
1024 panelswap (selected);
1025 panelswap (is_panelized);
1026 panelswap (dir_stat);
1028 panel1->searching = 0;
1029 panel2->searching = 0;
1030 if (cpanel == panel1)
1031 current_panel = panel2;
1032 else
1033 current_panel = panel1;
1034 if (midnight_dlg->current->widget == panels [0].widget)
1035 dlg_select_widget (midnight_dlg, (void *) panels [1].widget);
1036 else if (midnight_dlg->current->widget == panels [1].widget)
1037 dlg_select_widget (midnight_dlg, (void *) panels [0].widget);
1038 } else {
1039 WPanel *tmp_panel;
1041 tmp_panel=right_panel;
1042 right_panel=left_panel;
1043 left_panel=tmp_panel;
1045 if (panels [0].type == view_listing) {
1046 if (!strcmp (panel1->panel_name, get_nth_panel_name (0))) {
1047 g_free (panel1->panel_name);
1048 panel1->panel_name = g_strdup (get_nth_panel_name (1));
1051 if (panels [1].type == view_listing) {
1052 if (!strcmp (panel2->panel_name, get_nth_panel_name (1))) {
1053 g_free (panel2->panel_name);
1054 panel2->panel_name = g_strdup (get_nth_panel_name (0));
1058 tmp.x = panels [0].widget->x;
1059 tmp.y = panels [0].widget->y;
1060 tmp.cols = panels [0].widget->cols;
1061 tmp.lines = panels [0].widget->lines;
1063 panels [0].widget->x = panels [1].widget->x;
1064 panels [0].widget->y = panels [1].widget->y;
1065 panels [0].widget->cols = panels [1].widget->cols;
1066 panels [0].widget->lines = panels [1].widget->lines;
1068 panels [1].widget->x = tmp.x;
1069 panels [1].widget->y = tmp.y;
1070 panels [1].widget->cols = tmp.cols;
1071 panels [1].widget->lines = tmp.lines;
1073 tmp_widget = panels [0].widget;
1074 panels [0].widget = panels [1].widget;
1075 panels [1].widget = tmp_widget;
1076 tmp_type = panels [0].type;
1077 panels [0].type = panels [1].type;
1078 panels [1].type = tmp_type;
1082 int get_display_type (int index)
1084 return panels [index].type;
1087 Widget *get_panel_widget (int index)
1089 return panels [index].widget;
1092 int get_current_index (void)
1094 if (panels [0].widget == ((Widget *) cpanel))
1095 return 0;
1096 else
1097 return 1;
1100 int get_other_index (void)
1102 return !get_current_index ();
1105 /* Returns the view type for the current panel/view */
1106 int get_current_type (void)
1108 if (panels [0].widget == (Widget *) cpanel)
1109 return panels [0].type;
1110 else
1111 return panels [1].type;
1114 /* Returns the view type of the unselected panel */
1115 int get_other_type (void)
1117 if (panels [0].widget == (Widget *) cpanel)
1118 return panels [1].type;
1119 else
1120 return panels [0].type;