Clean menu -- made to use standart GNOME menu entries
[midnight-commander.git] / src / layout.c
blob1a8c2466c318d8e53386d7604400190c43a49ab3
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., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <config.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <sys/param.h> /* Required by tree.h */
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #if (!defined(__IBMC__) && !defined(__IBMCPP__)) && !defined(HAS_NO_TERMIOS_H)
30 # include <termios.h>
31 #endif
33 * If TIOCGWINSZ supported, make it available here, because window-
34 * resizing code depends on it...
36 #if (!defined(__IBMC__) && !defined(__IBMCPP__)) && !defined(HAS_NO_SYS_IOCTL_H)
37 # include <sys/ioctl.h>
38 #endif
39 #ifdef HAVE_UNISTD_H
40 # include <unistd.h>
41 #endif
42 #include <signal.h>
43 #include "tty.h"
44 #include "global.h"
45 #include "win.h"
46 #include "color.h"
47 #include "key.h"
49 #include "dlg.h"
50 #include "widget.h"
51 #include "command.h"
53 #include "dialog.h" /* For do_refresh() */
54 #include "profile.h" /* For sync_profiles() */
55 #include "mouse.h"
56 #define WANT_WIDGETS
57 #include "main.h"
58 #include "subshell.h" /* For use_subshell and resize_subshell() */
59 #include "tree.h"
60 #include "menu.h"
62 /* Needed for the extern declarations of integer parameters */
63 #include "dir.h"
64 #include "panel.h" /* The Panel widget */
65 #include "file.h"
66 #include "cons.saver.h"
67 #include "layout.h"
68 #include "info.h" /* The Info widget */
69 #include "view.h" /* The view widget */
71 #define WANT_WIDGETS
72 #include "setup.h" /* For save_setup() */
74 #include "x.h"
76 /* "$Id$" */
78 /* Controls the display of the rotating dash on the verbose mode */
79 int nice_rotating_dash = 1;
81 /* If set, then we have to call the layout_change routine from main */
82 int layout_do_change = 0;
84 /* Set if the panels are split horizontally */
85 int horizontal_split = 0;
87 /* Set if the window has changed it's size */
88 int winch_flag = 0;
90 /* Set if the split is the same */
91 int equal_split = 1;
93 /* First panel size if the panel are not split equally */
94 int first_panel_size = 0;
96 /* The number of output lines shown (if available) */
97 int output_lines = 0;
99 /* Set if the command prompt is to be displayed */
100 int command_prompt = 1;
102 /* Set if the nice and usefull keybar is visible */
103 int keybar_visible = 1;
105 /* Set if the nice message (hint) bar is visible */
106 int message_visible = 1;
108 /* Set if you want the message bar shown in xterm title bar to save space */
109 int xterm_hintbar = 0;
111 /* The starting line for the output of the subprogram */
112 int output_start_y = 0;
114 /* The maximum number of views managed by the set_display_type routine */
115 /* Must be at least two (for current and other). Please note that until */
116 /* Janne gets around this, we will only manage two of them :-) */
117 #define MAX_VIEWS 2
119 struct {
120 int type;
121 Widget *widget;
122 } panels [MAX_VIEWS];
124 /* These variables are used to avoid updating the information unless */
125 /* we need it */
126 static int old_first_panel_size;
127 static int old_horizontal_split;
128 static int old_output_lines;
130 /* Internal variables */
131 static int _horizontal_split;
132 static int _equal_split;
133 static int _first_panel_size;
134 static int _menubar_visible;
135 static int _output_lines;
136 static int _command_prompt;
137 static int _keybar_visible;
138 static int _message_visible;
139 static int _xterm_hintbar;
140 static int _permission_mode;
141 static int _filetype_mode;
143 static int height;
145 #define MINWIDTH 10
146 #define MINHEIGHT 5
148 #define BY 12
150 #define B_2LEFT B_USER
151 #define B_2RIGHT B_USER + 1
152 #define B_PLUS B_USER + 2
153 #define B_MINUS B_USER + 3
155 static Dlg_head *layout_dlg;
157 static char *s_split_direction [2] = {
158 N_("&Vertical"),
159 N_("&Horizontal")
161 WRadio *radio_widget;
163 static struct {
164 char *text;
165 int *variable;
166 WCheck *widget;
167 char *tkname;
168 } check_options [] = {
169 { N_("&Xterm hintbar"), &xterm_hintbar, 0, "h" },
170 { N_("h&Intbar visible"), &message_visible, 0, "v" },
171 { N_("&Keybar visible"), &keybar_visible, 0, "k" },
172 { N_("command &Prompt"), &command_prompt, 0, "p" },
173 { N_("show &Mini status"), &show_mini_info, 0, "m" },
174 { N_("menu&Bar visible"), &menubar_visible, 0, "me" },
175 { N_("&Equal split"), &equal_split, 0, "eq" },
176 { N_("pe&Rmissions"), &permission_mode, 0, "pr" },
177 { N_("&File types"), &filetype_mode, 0, "ft" },
178 { 0, 0, 0, 0 }
181 static int first_width, second_width;
182 static char *layout_title, *title1, *title2, *title3, *output_lines_label;
184 static WButton *bleft_widget, *bright_widget;
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 #ifndef HAVE_X
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 #endif
310 break;
312 case DLG_POST_KEY:
313 _filetype_mode = check_options [8].widget->state & C_BOOL;
314 _permission_mode = check_options [7].widget->state & C_BOOL;
315 #ifndef HAVE_X
316 _equal_split = check_options [6].widget->state & C_BOOL;
317 #endif
318 _menubar_visible = check_options [5].widget->state & C_BOOL;
319 _command_prompt = check_options [4].widget->state & C_BOOL;
320 _keybar_visible = check_options [2].widget->state & C_BOOL;
321 _message_visible = check_options [1].widget->state & C_BOOL;
322 _xterm_hintbar = check_options [0].widget->state & C_BOOL;
323 if (console_flag){
324 int minimum;
325 if (_output_lines < 0)
326 _output_lines = 0;
327 height = LINES - _keybar_visible - _command_prompt -
328 _menubar_visible - _output_lines - _message_visible;
329 if (_message_visible && _xterm_hintbar && xterm_flag) height++;
330 minimum = MINHEIGHT * (1 + _horizontal_split);
331 if (height < minimum){
332 _output_lines -= minimum - height;
333 height = minimum;
335 } else {
336 height = LINES - _keybar_visible - _command_prompt -
337 _menubar_visible - _output_lines - _message_visible;
338 if (_message_visible && _xterm_hintbar && xterm_flag) height++;
340 if (_horizontal_split != radio_widget->sel){
341 _horizontal_split = radio_widget->sel;
342 if (_horizontal_split)
343 _first_panel_size = height / 2;
344 else
345 _first_panel_size = COLS / 2;
347 update_split ();
348 if (console_flag){
349 if (old_output_lines != _output_lines){
350 old_output_lines = _output_lines;
351 attrset (COLOR_NORMAL);
352 dlg_move (h, 9, 10 + first_width);
353 printw ("%02d", _output_lines);
356 break;
358 case DLG_END:
359 break;
361 return 0;
364 static void init_layout (void)
366 static int i18n_layt_flag = 0;
367 static int b1, b2, b3;
368 int i = sizeof (s_split_direction) / sizeof(char*) ;
369 char* ok_button = _("&Ok");
370 char* cancel_button = _("&Cancel");
371 char* save_button = _("&Save");
373 if (!i18n_layt_flag)
375 register int l1;
377 first_width = 19; /* length of line with '<' '>' buttons */
379 layout_title = _(" Layout ");
380 title1 = _(" Panel split ");
381 title2 = _(" Highlight... ");
382 title3 = _(" Other options ");
383 output_lines_label = _("output lines");
385 while (i--)
387 s_split_direction [i] = _(s_split_direction [i]);
388 l1 = strlen (s_split_direction [i]) + 7;
389 if (l1 > first_width)
390 first_width = l1;
393 for (i = 0; i <= 8; i++)
395 check_options[i].text = _(check_options[i].text);
396 l1 = strlen (check_options[i].text) + 7;
397 if (l1 > first_width)
398 first_width = l1;
401 l1 = strlen (title1) + 1;
402 if (l1 > first_width)
403 first_width = l1;
405 l1 = strlen (title2) + 1;
406 if (l1 > first_width)
407 first_width = l1;
410 second_width = strlen (title3) + 1;
411 for (i = 0; i < 6; i++)
413 check_options[i].text = _(check_options[i].text);
414 l1 = strlen (check_options[i].text) + 7;
415 if (l1 > second_width)
416 second_width = l1;
418 if (console_flag)
420 l1 = strlen (output_lines_label) + 13;
421 if (l1 > second_width)
422 second_width = l1;
426 * alex@bcs.zp.ua:
427 * To be completely correct, one need to check if layout_title
428 * does not exceed dialog length and total length of 3 buttons
429 * allows their placement in one row. But assuming this dialog
430 * is wide enough, I don't include such a tests.
432 * Now the last thing to do - properly space buttons...
434 l1 = 11 + strlen (ok_button) /* 14 - all brackets and inner space */
435 + strlen (save_button) /* notice: it is 3 char less because */
436 + strlen (cancel_button); /* of '&' char in button text */
438 i = (first_width + second_width - l1) / 4;
439 b1 = 5 + i;
440 b2 = b1 + strlen(ok_button) + i + 6;
441 b3 = b2 + strlen(save_button) + i + 4;
443 i18n_layt_flag = 1;
446 layout_dlg = create_dlg (0, 0, 15, first_width + second_width + 9,
447 dialog_colors, layout_callback,
448 "[Layout]", "layout", DLG_CENTER | DLG_GRID);
450 x_set_dialog_title (layout_dlg, _("Layout"));
452 add_widgetl (layout_dlg,
453 button_new (BY, b3, B_CANCEL, NORMAL_BUTTON, cancel_button, 0, 0, "c"),
454 XV_WLAY_RIGHTOF);
455 add_widgetl (layout_dlg,
456 button_new (BY, b2, B_EXIT, NORMAL_BUTTON, save_button, 0, 0, "s"),
457 XV_WLAY_RIGHTOF);
458 add_widgetl (layout_dlg,
459 button_new (BY, b1, B_ENTER, DEFPUSH_BUTTON, ok_button, 0, 0, "o"),
460 XV_WLAY_CENTERROW);
461 #ifndef HAVE_X
462 if (console_flag){
463 add_widget (layout_dlg,
464 button_new (9, 12 + first_width, B_MINUS, NARROW_BUTTON, "&-",
465 bminus_cback, 0, NULL));
466 add_widget (layout_dlg,
467 button_new (9, 7 + first_width, B_PLUS, NARROW_BUTTON, "&+",
468 bplus_cback, 0, NULL));
470 #endif
472 #define XTRACT(i) *check_options[i].variable, check_options[i].text, check_options[i].tkname
474 for (i = 0; i < 6; i++){
475 check_options [i].widget = check_new (8 - i, 7 + first_width, XTRACT(i));
476 add_widgetl (layout_dlg, check_options [i].widget, XV_WLAY_BELOWCLOSE);
478 check_options [8].widget = check_new (10, 6, XTRACT(8));
479 add_widgetl (layout_dlg, check_options [8].widget, XV_WLAY_BELOWCLOSE);
480 check_options [7].widget = check_new (9, 6, XTRACT(7));
481 add_widgetl (layout_dlg, check_options [7].widget, XV_WLAY_BELOWCLOSE);
483 _filetype_mode = filetype_mode;
484 _permission_mode = permission_mode;
485 _equal_split = equal_split;
486 _menubar_visible = menubar_visible;
487 _command_prompt = command_prompt;
488 _keybar_visible = keybar_visible;
489 _message_visible = message_visible;
490 _xterm_hintbar = xterm_hintbar;
491 #ifndef HAVE_X
492 bright_widget = button_new(6, 15, B_2RIGHT, NARROW_BUTTON, "&>", b2right_cback, 0, ">");
493 add_widgetl (layout_dlg, bright_widget, XV_WLAY_RIGHTOF);
494 bleft_widget = button_new (6, 9, B_2LEFT, NARROW_BUTTON, "&<", b2left_cback, 0, "<");
495 add_widgetl (layout_dlg, bleft_widget, XV_WLAY_RIGHTOF);
496 check_options [6].widget = check_new (5, 6, XTRACT(6));
497 #endif
498 old_first_panel_size = -1;
499 old_horizontal_split = -1;
500 old_output_lines = -1;
502 _first_panel_size = first_panel_size;
503 _output_lines = output_lines;
504 #ifndef HAVE_X
505 add_widget (layout_dlg, check_options [6].widget);
506 radio_widget = radio_new (3, 6, 2, s_split_direction, 1, "r");
507 add_widget (layout_dlg, radio_widget);
508 radio_widget->sel = horizontal_split;
509 #endif
512 void layout_change (void)
514 setup_panels ();
515 layout_do_change = 0;
516 #ifndef HAVE_X
517 /* re-init the menu, because perhaps there was a change in the way
518 how the panel are split (horizontal/vertical). */
519 done_menu();
520 init_menu();
521 menubar_arrange(the_menubar);
522 #endif
525 void layout_cmd (void)
527 int result;
528 int i;
530 init_layout ();
531 run_dlg (layout_dlg);
532 result = layout_dlg->ret_value;
534 if (result == B_ENTER || result == B_EXIT){
535 for (i = 0; check_options [i].text; i++)
536 if (check_options [i].widget)
537 *check_options [i].variable = check_options [i].widget->state & C_BOOL;
538 #ifndef HAVE_X
539 horizontal_split = radio_widget->sel;
540 first_panel_size = _first_panel_size;
541 output_lines = _output_lines;
542 layout_do_change = 1;
543 #endif
545 if (result == B_EXIT){
546 save_layout ();
547 sync_profiles ();
550 destroy_dlg (layout_dlg);
551 if (layout_do_change)
552 layout_change ();
555 static void check_split (void)
557 if (horizontal_split){
558 if (equal_split)
559 first_panel_size = height / 2;
560 else if (first_panel_size < MINHEIGHT)
561 first_panel_size = MINHEIGHT;
562 else if (first_panel_size > height - MINHEIGHT)
563 first_panel_size = height - MINHEIGHT;
564 } else {
565 if (equal_split)
566 first_panel_size = COLS / 2;
567 else if (first_panel_size < MINWIDTH)
568 first_panel_size = MINWIDTH;
569 else if (first_panel_size > COLS - MINWIDTH)
570 first_panel_size = COLS - MINWIDTH;
574 int panel_event (Gpm_Event *event, WPanel *panel);
575 int menu_bar_event (Gpm_Event *event, void *);
576 extern char *prompt;
578 #ifndef HAVE_X
579 #ifdef HAVE_SLANG
580 void init_curses ()
582 extern int force_ugly_line_drawing;
583 extern int SLtt_Has_Alt_Charset;
584 SLtt_get_terminfo ();
585 #ifndef HAS_ACS_AS_PCCHARS
586 if (force_ugly_line_drawing)
587 SLtt_Has_Alt_Charset = 0;
588 #endif
589 SLsmg_init_smg ();
590 do_enter_ca_mode ();
591 init_colors ();
592 keypad (stdscr, TRUE);
593 nodelay (stdscr, FALSE);
595 #else
596 void init_curses (void)
598 initscr();
599 if (!status_using_ncurses)
600 do_enter_ca_mode ();
601 mc_raw_mode ();
602 noecho ();
603 keypad (stdscr, TRUE);
604 nodelay (stdscr, FALSE);
605 init_colors ();
607 #endif /* ! HAVE_SLANG */
608 void done_screen ()
610 if (!(quit & SUBSHELL_EXIT))
611 clr_scr ();
612 reset_shell_mode ();
613 mc_noraw_mode ();
614 if (use_mouse_p)
615 shut_mouse ();
616 keypad (stdscr, FALSE);
618 #else
619 void init_curses ()
622 void done_screen ()
625 #endif /* HAVE_X */
627 static void
628 panel_do_cols (int index)
630 if (get_display_type (index) == view_listing)
631 set_panel_formats ((WPanel *) panels [index].widget);
632 else {
633 panel_update_cols (panels [index].widget, frame_half);
637 #ifdef HAVE_X
638 void
639 setup_panels (void)
641 Widget *w = panels [0].widget;
643 winput_set_origin (&cmdline->input, 0, 60);
645 /* Only needed by the startup code */
646 if (panels [0].type == view_listing){
647 x_panel_set_size (0);
650 if (panels [1].type == view_listing){
651 x_panel_set_size (1);
654 load_hint ();
657 #else
659 void setup_panels (void)
661 int start_y;
662 int promptl; /* the prompt len */
664 if (console_flag){
665 int minimum;
666 if (output_lines < 0)
667 output_lines = 0;
668 height = LINES - keybar_visible - command_prompt - menubar_visible
669 - output_lines - message_visible;
670 if (message_visible && xterm_hintbar && xterm_flag) height++;
671 minimum = MINHEIGHT * (1 + horizontal_split);
672 if (height < minimum){
673 output_lines -= minimum - height;
674 height = minimum;
676 } else {
677 height = LINES - menubar_visible - command_prompt -
678 keybar_visible - message_visible;
679 if (message_visible && xterm_hintbar && xterm_flag) height++;
681 check_split ();
682 start_y = menubar_visible;
684 /* The column computing is defered until panel_do_cols */
685 if (horizontal_split){
686 widget_set_size (panels [0].widget, start_y, 0,
687 first_panel_size, 0);
689 widget_set_size (panels [1].widget, start_y+first_panel_size, 0,
690 height-first_panel_size, 0);
691 } else {
692 int first_x = first_panel_size;
694 widget_set_size (panels [0].widget, start_y, 0,
695 height, 0);
697 widget_set_size (panels [1].widget, start_y, first_x,
698 height, 0);
701 panel_do_cols (0);
702 panel_do_cols (1);
704 promptl = strlen (prompt);
706 widget_set_size (&the_menubar->widget, 0, 0, 1, COLS);
708 if (command_prompt) {
709 widget_set_size (&cmdline->input.widget,
710 LINES-1-keybar_visible, promptl,
711 1, COLS-promptl-(keybar_visible ? 0 : 1));
712 winput_set_origin (&cmdline->input, promptl, COLS-promptl-(keybar_visible ? 0 : 1));
713 widget_set_size (&the_prompt->widget,
714 LINES-1-keybar_visible, 0,
715 1, promptl);
716 } else {
717 widget_set_size (&cmdline->input.widget, 0, 0, 0, 0);
718 winput_set_origin (&cmdline->input, 0, 0);
719 widget_set_size (&the_prompt->widget, LINES, COLS, 0, 0);
722 widget_set_size (&the_bar->widget, LINES-1, 0, 1, COLS);
723 the_bar->visible = keybar_visible;
725 /* Output window */
726 if (console_flag && output_lines){
727 output_start_y = LINES -command_prompt-keybar_visible-
728 output_lines;
729 show_console_contents (output_start_y,
730 LINES-output_lines-keybar_visible-1,
731 LINES-keybar_visible-1);
733 if (message_visible && (!xterm_hintbar || !xterm_flag))
734 widget_set_size (&the_hint->widget, height+start_y, 0, 1,COLS);
735 else
736 widget_set_size (&the_hint->widget, 0, 0, 0, 0);
738 load_hint ();
740 #endif
742 void flag_winch (int dummy)
744 winch_flag = 1;
747 void edit_adjust_size (Dlg_head * h);
749 #ifdef PORT_NEEDS_CHANGE_SCREEN_SIZE
750 static void
751 low_level_change_screen_size (void)
753 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
754 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
755 struct winsize winsz;
757 winsz.ws_col = winsz.ws_row = 0;
758 /* Ioctl on the STDIN_FILENO */
759 ioctl (0, TIOCGWINSZ, &winsz);
760 if (winsz.ws_col && winsz.ws_row){
761 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
762 resizeterm(winsz.ws_row, winsz.ws_col);
763 clearok(stdscr,TRUE); /* FIXME: sigwinch's should use a semaphore! */
764 #else
765 COLS = winsz.ws_col;
766 LINES = winsz.ws_row;
767 #endif
768 #ifdef HAVE_SUBSHELL_SUPPORT
769 resize_subshell ();
770 #endif
772 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
773 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
776 void change_screen_size (void)
778 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
779 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
780 extern Dlg_head *view_dlg;
781 extern Dlg_head *edit_dlg;
783 #ifndef NCURSES_VERSION
784 mc_noraw_mode ();
785 endwin ();
786 #endif
787 low_level_change_screen_size ();
788 check_split ();
789 #ifndef NCURSES_VERSION
790 /* XSI Curses spec states that portable applications shall not invoke
791 * initscr() more than once. This kludge could be done within the scope
792 * of the specification by using endwin followed by a refresh (in fact,
793 * more than one curses implementation does this); it is guaranteed to work
794 * only with slang.
796 init_curses ();
797 #endif
798 setup_panels ();
799 if (current_dlg == view_dlg)
800 view_adjust_size (view_dlg);
801 #ifdef USE_INTERNAL_EDIT
802 if (current_dlg == edit_dlg)
803 edit_adjust_size (edit_dlg);
804 #endif
806 #ifdef RESIZABLE_MENUBAR
807 menubar_arrange(the_menubar);
808 #endif
810 /* Now, force the redraw */
811 do_refresh ();
812 touchwin (stdscr);
813 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
814 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
815 winch_flag = 0;
817 #endif /* HAVE_X */
819 static int ok_to_refresh = 1;
821 void use_dash (int flag)
823 if (flag)
824 ok_to_refresh++;
825 else
826 ok_to_refresh--;
829 void set_hintbar(char *str)
831 #ifndef HAVE_X
832 if (xterm_flag && xterm_hintbar) {
833 fprintf (stdout, "\33]0;mc - %s\7", str);
834 fflush (stdout);
835 } else
836 #endif
838 label_set_text (the_hint, str);
839 if (ok_to_refresh > 0)
840 refresh();
844 void print_vfs_message (char *msg, ...)
846 va_list ap;
847 char str [128];
849 va_start (ap, msg);
851 g_vsnprintf (str, 126, msg, ap);
852 va_end (ap);
854 if (midnight_shutdown || !the_hint || !the_hint->widget.parent)
855 return;
857 if (message_visible || (xterm_flag && xterm_hintbar)) {
858 set_hintbar(str);
862 void rotate_dash (void)
864 #ifndef HAVE_X
865 static char rotating_dash [] = "|/-\\";
866 static int pos = 0;
868 if (!nice_rotating_dash || (ok_to_refresh <= 0))
869 return;
871 if (pos >= sizeof (rotating_dash)-1)
872 pos = 0;
873 move (0, COLS-1);
874 addch (rotating_dash [pos]);
875 mc_refresh ();
876 pos++;
877 #endif
880 void remove_dash (void)
882 #ifndef HAVE_X
883 if (!nice_rotating_dash)
884 return;
886 /* Currently, it's much nicer with the CPU to do this instead of
887 calling do_refresh.
889 I should implement a routine called invalidate_region that would
890 send a draw message only to the affected views. But for now
891 this is fine.
894 move (0, COLS-1);
895 addch (' ');
896 #endif
899 char *get_nth_panel_name (int num)
901 static char buffer [BUF_SMALL];
903 if (!num)
904 return "New Left Panel";
905 else if (num == 1)
906 return "New Right Panel";
907 else {
908 g_snprintf (buffer, sizeof (buffer), "%ith Panel", num);
909 return buffer;
913 /* I wonder if I should start to use the folding mode than Dugan uses */
914 /* */
915 /* This is the centralized managing of the panel display types */
916 /* This routine takes care of destroying and creating new widgets */
917 /* Please note that it could manage MAX_VIEWS, not just left and right */
918 /* Currently nothing in the code takes advantage of this and has hard- */
919 /* coded values for two panels only */
921 /* Set the num-th panel to the view type: type */
922 /* This routine also keeps at least one WPanel object in the screen */
923 /* since a lot of routines depend on the current_panel variable */
924 void set_display_type (int num, int type)
926 int x, y, cols, lines;
927 int the_other; /* Index to the other panel */
928 char *file_name = 0; /* For Quick view */
929 Widget *new_widget, *old_widget;
930 WPanel *the_other_panel;
932 x =y = cols = lines = 0;
933 old_widget = 0;
934 if (num >= MAX_VIEWS){
935 fprintf (stderr, "Could not allocate more that %d views\n", MAX_VIEWS);
936 abort ();
939 /* Check that we will have a WPanel * at least */
940 the_other = 0;
941 if (type != view_listing){
942 the_other = num == 0 ? 1 : 0;
944 if (panels [the_other].type != view_listing)
945 return;
949 /* Get rid of it */
950 if (panels [num].widget){
951 Widget *w = panels [num].widget;
952 WPanel *panel = (WPanel *) panels [num].widget;
954 x = w->x;
955 y = w->y;
956 cols = w->cols;
957 lines = w->lines;
958 old_widget = panels [num].widget;
960 if (panels [num].type == view_listing){
961 if (panel->frame_size == frame_full && type != view_listing){
962 cols = COLS - first_panel_size;
963 if (num == 1)
964 x = first_panel_size;
969 new_widget = 0;
971 switch (type){
972 case view_listing:
973 new_widget = (Widget *) panel_new (get_nth_panel_name (num));
974 break;
976 case view_info:
977 new_widget = (Widget *) info_new ();
979 break;
981 case view_tree:
982 new_widget = (Widget *) tree_new (1, 0, 0, 0, 0);
983 break;
985 case view_quick:
986 new_widget = (Widget *) view_new (0, 0, 0, 0, 1);
987 the_other_panel = (WPanel *) panels [the_other].widget;
988 if (the_other_panel)
989 file_name =
990 the_other_panel->dir.list[the_other_panel->selected].fname;
991 else
992 file_name = "";
994 view_init ((WView *) new_widget, 0, file_name, 0);
995 break;
997 panels [num].type = type;
998 panels [num].widget = (Widget *) new_widget;
1000 /* We set the same size the old widget had */
1001 widget_set_size ((Widget *) new_widget, y, x, lines, cols);
1003 /* We wanna the new widget at the same position */
1004 /* XView sets wcontainer to !0 <- Not XView, but we, when we create it */
1005 /* Ok, the XView support code does it */
1006 if (old_widget && old_widget->wcontainer){
1007 new_widget->wcontainer = old_widget->wcontainer;
1008 new_widget->area = old_widget->area;
1011 /* We use replace to keep the circular list of the dialog in the */
1012 /* same state. Maybe we could just kill it and then replace it */
1013 if (midnight_dlg && old_widget){
1014 dlg_replace_widget (midnight_dlg, old_widget, panels [num].widget);
1016 if (type == view_listing){
1017 if (num == 0)
1018 left_panel = (WPanel *) new_widget;
1019 else
1020 right_panel = (WPanel *) new_widget;
1023 if (type == view_tree)
1024 the_tree = (WTree *) new_widget;
1026 /* Prevent current_panel's value from becoming invalid.
1027 * It's just a quick hack to prevent segfaults. Comment out and
1028 * try following:
1029 * - select left panel
1030 * - invoke menue left/tree
1031 * - as long as you stay in the left panel almost everything that uses
1032 * cpanel causes segfault, e.g. C-Enter, C-x c, ...
1035 if (type != view_listing)
1036 if (cpanel == (WPanel *) old_widget)
1037 current_panel = num == 0 ? right_panel : left_panel;
1040 /* This routine is deeply sticked to the two panels idea.
1041 What should it do in more panels. ANSWER - don't use it
1042 in any multiple panels environment. */
1043 void swap_panels ()
1045 Widget tmp;
1046 Widget *tmp_widget;
1047 WPanel panel;
1048 WPanel *panel1, *panel2;
1049 int tmp_type;
1051 #if 0
1052 #ifdef HAVE_PORTABLE_TOKEN_PASTING
1053 #define panelswap(e) panel.##e = panel1->##e; panel1->##e = panel2->##e; panel2->##e = panel.##e;
1054 #define panelswapstr(e) strcpy (panel.##e, panel1->##e); strcpy (panel1->##e, panel2->##e); strcpy (panel2->##e, panel.##e);
1055 #else
1056 #define panelswap(e) panel./**/e = panel1->/**/e; panel1->/**/e = panel2->/**/e; panel2->/**/e = panel./**/e;
1057 #define panelswapstr(e) strcpy (panel./**/e, panel1->/**/e); strcpy (panel1->/**/e, panel2->/**/e); strcpy (panel2->/**/e, panel./**/e);
1058 #endif
1059 #endif
1061 #define panelswap(x) panel. x = panel1-> x; panel1-> x = panel2-> x; panel2-> x = panel. x;
1063 #define panelswapstr(e) strcpy (panel. e, panel1-> e); \
1064 strcpy (panel1-> e, panel2-> e); \
1065 strcpy (panel2-> e, panel. e);
1066 panel1 = (WPanel *) panels [0].widget;
1067 panel2 = (WPanel *) panels [1].widget;
1068 if (panels [0].type == view_listing && panels [1].type == view_listing) {
1069 /* Change everything except format/sort/panel_name etc. */
1070 panelswap (dir);
1071 panelswap (active);
1072 panelswapstr (cwd);
1073 panelswapstr (lwd);
1074 panelswap (count);
1075 panelswap (marked);
1076 panelswap (dirs_marked);
1077 panelswap (total);
1078 panelswap (top_file);
1079 panelswap (selected);
1080 panelswap (is_panelized);
1081 panelswap (dir_stat);
1083 panel1->searching = 0;
1084 panel2->searching = 0;
1085 if (cpanel == panel1)
1086 current_panel = panel2;
1087 else
1088 current_panel = panel1;
1089 if (midnight_dlg->current->widget == panels [0].widget)
1090 dlg_select_widget (midnight_dlg, (void *) panels [1].widget);
1091 else if (midnight_dlg->current->widget == panels [1].widget)
1092 dlg_select_widget (midnight_dlg, (void *) panels [0].widget);
1093 } else {
1094 WPanel *tmp_panel;
1096 tmp_panel=right_panel;
1097 right_panel=left_panel;
1098 left_panel=tmp_panel;
1100 if (panels [0].type == view_listing) {
1101 if (!strcmp (panel1->panel_name, get_nth_panel_name (0))) {
1102 g_free (panel1->panel_name);
1103 panel1->panel_name = g_strdup (get_nth_panel_name (1));
1106 if (panels [1].type == view_listing) {
1107 if (!strcmp (panel2->panel_name, get_nth_panel_name (1))) {
1108 g_free (panel2->panel_name);
1109 panel2->panel_name = g_strdup (get_nth_panel_name (0));
1113 tmp.x = panels [0].widget->x;
1114 tmp.y = panels [0].widget->y;
1115 tmp.cols = panels [0].widget->cols;
1116 tmp.lines = panels [0].widget->lines;
1118 panels [0].widget->x = panels [1].widget->x;
1119 panels [0].widget->y = panels [1].widget->y;
1120 panels [0].widget->cols = panels [1].widget->cols;
1121 panels [0].widget->lines = panels [1].widget->lines;
1123 panels [1].widget->x = tmp.x;
1124 panels [1].widget->y = tmp.y;
1125 panels [1].widget->cols = tmp.cols;
1126 panels [1].widget->lines = tmp.lines;
1128 tmp_widget = panels [0].widget;
1129 panels [0].widget = panels [1].widget;
1130 panels [1].widget = tmp_widget;
1131 tmp_type = panels [0].type;
1132 panels [0].type = panels [1].type;
1133 panels [1].type = tmp_type;
1137 int get_display_type (int index)
1139 return panels [index].type;
1142 Widget *get_panel_widget (int index)
1144 return panels [index].widget;
1147 int get_current_index (void)
1149 if (panels [0].widget == ((Widget *) cpanel))
1150 return 0;
1151 else
1152 return 1;
1155 int get_other_index (void)
1157 return !get_current_index ();
1160 /* Returns the view type for the current panel/view */
1161 int get_current_type (void)
1163 if (panels [0].widget == (Widget *) cpanel)
1164 return panels [0].type;
1165 else
1166 return panels [1].type;
1169 /* Returns the view type of the unselected panel */
1170 int get_other_type (void)
1172 if (panels [0].widget == (Widget *) cpanel)
1173 return panels [1].type;
1174 else
1175 return panels [0].type;