1 /* Panel layout module for the Midnight Commander
2 Copyright (C) 1995 the Free Software Foundation
4 Written: 1995 Janne Kukonlehto
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 #include <sys/types.h>
32 * If TIOCGWINSZ supported, make it available here, because window-
33 * resizing code depends on it...
35 #ifdef HAVE_SYS_IOCTL_H
36 # include <sys/ioctl.h>
44 #include "tty.h" /* COLS */
51 #include "profile.h" /* For sync_profiles() */
55 #include "subshell.h" /* For use_subshell and resize_subshell() */
59 /* Needed for the extern declarations of integer parameters */
61 #include "panel.h" /* The Panel widget */
62 #include "cons.saver.h"
64 #include "info.h" /* The Info widget */
65 #include "view.h" /* The view widget */
67 #include "setup.h" /* For save_setup() */
69 /* Controls the display of the rotating dash on the verbose mode */
70 int nice_rotating_dash
= 1;
72 /* If set, then we have to call the layout_change routine from main */
73 static int layout_do_change
= 0;
75 /* Set if the panels are split horizontally */
76 int horizontal_split
= 0;
78 /* Set if the window has changed it's size */
81 /* Set if the split is the same */
84 /* First panel size if the panel are not split equally */
85 int first_panel_size
= 0;
87 /* The number of output lines shown (if available) */
90 /* Set if the command prompt is to be displayed */
91 int command_prompt
= 1;
93 /* Set if the nice and useful keybar is visible */
94 int keybar_visible
= 1;
96 /* Set if the nice message (hint) bar is visible */
97 int message_visible
= 1;
99 /* Set to show current working dir in xterm window title */
102 /* The starting line for the output of the subprogram */
103 int output_start_y
= 0;
105 /* The maximum number of views managed by the set_display_type routine */
106 /* Must be at least two (for current and other). Please note that until */
107 /* Janne gets around this, we will only manage two of them :-) */
113 } panels
[MAX_VIEWS
];
115 /* These variables are used to avoid updating the information unless */
117 static int old_first_panel_size
;
118 static int old_horizontal_split
;
119 static int old_output_lines
;
121 /* Internal variables */
122 static int _horizontal_split
;
123 static int _equal_split
;
124 static int _first_panel_size
;
125 static int _menubar_visible
;
126 static int _output_lines
;
127 static int _command_prompt
;
128 static int _keybar_visible
;
129 static int _message_visible
;
130 static int _xterm_title
;
131 static int _permission_mode
;
132 static int _filetype_mode
;
136 /* Width 12 for a wee Quick (Hex) View */
142 #define B_2LEFT B_USER
143 #define B_2RIGHT (B_USER + 1)
144 #define B_PLUS (B_USER + 2)
145 #define B_MINUS (B_USER + 3)
147 static Dlg_head
*layout_dlg
;
149 static const char *s_split_direction
[2] = {
154 static WRadio
*radio_widget
;
160 } check_options
[] = {
161 { N_("&Xterm window title"), &xterm_title
, 0 },
162 { N_("h&Intbar visible"), &message_visible
, 0 },
163 { N_("&Keybar visible"), &keybar_visible
, 0 },
164 { N_("command &Prompt"), &command_prompt
, 0 },
165 { N_("show &Mini status"), &show_mini_info
, 0 },
166 { N_("menu&Bar visible"), &menubar_visible
, 0 },
167 { N_("&Equal split"), &equal_split
, 0 },
168 { N_("pe&Rmissions"), &permission_mode
, 0 },
169 { N_("&File types"), &filetype_mode
, 0 },
173 static int first_width
, second_width
;
174 static const char *output_lines_label
;
176 static WButton
*bleft_widget
, *bright_widget
;
178 /* Declarations for static functions */
179 static void low_level_change_screen_size (void);
181 static void _check_split (void)
183 if (_horizontal_split
){
185 _first_panel_size
= height
/ 2;
186 else if (_first_panel_size
< MINHEIGHT
)
187 _first_panel_size
= MINHEIGHT
;
188 else if (_first_panel_size
> height
- MINHEIGHT
)
189 _first_panel_size
= height
- MINHEIGHT
;
192 _first_panel_size
= COLS
/ 2;
193 else if (_first_panel_size
< MINWIDTH
)
194 _first_panel_size
= MINWIDTH
;
195 else if (_first_panel_size
> COLS
- MINWIDTH
)
196 _first_panel_size
= COLS
- MINWIDTH
;
200 static void update_split (void)
202 /* Check split has to be done before testing if it changed, since
203 it can change due to calling _check_split() as well*/
206 /* To avoid setting the cursor to the wrong place */
207 if ((old_first_panel_size
== _first_panel_size
) &&
208 (old_horizontal_split
== _horizontal_split
)){
212 old_first_panel_size
= _first_panel_size
;
213 old_horizontal_split
= _horizontal_split
;
215 attrset (COLOR_NORMAL
);
216 dlg_move (layout_dlg
, 6, 6);
217 printw ("%03d", _first_panel_size
);
218 dlg_move (layout_dlg
, 6, 18);
219 if (_horizontal_split
)
220 printw ("%03d", height
- _first_panel_size
);
222 printw ("%03d", COLS
- _first_panel_size
);
225 static int b2left_cback (int action
)
230 /* Turn equal split off */
232 check_options
[6].widget
->state
= check_options
[6].widget
->state
& ~C_BOOL
;
233 dlg_select_widget (check_options
[6].widget
);
234 dlg_select_widget (bleft_widget
);
240 static int b2right_cback (int action
)
245 /* Turn equal split off */
247 check_options
[6].widget
->state
= check_options
[6].widget
->state
& ~C_BOOL
;
248 dlg_select_widget (check_options
[6].widget
);
249 dlg_select_widget (bright_widget
);
255 static int bplus_cback (int action
)
259 if (_output_lines
< 99)
264 static int bminus_cback (int action
)
268 if (_output_lines
> 0)
274 layout_callback (struct Dlg_head
*h
, dlg_msg_t msg
, int parm
)
278 /*When repainting the whole dialog (e.g. with C-l) we have to
280 common_dialog_repaint (h
);
282 old_first_panel_size
= -1;
283 old_horizontal_split
= -1;
284 old_output_lines
= -1;
286 attrset (COLOR_HOT_NORMAL
);
291 if (old_output_lines
!= _output_lines
){
292 old_output_lines
= _output_lines
;
293 attrset (COLOR_NORMAL
);
294 dlg_move (h
, 9, 16 + first_width
);
295 addstr (output_lines_label
);
296 dlg_move (h
, 9, 10 + first_width
);
297 printw ("%02d", _output_lines
);
303 _filetype_mode
= check_options
[8].widget
->state
& C_BOOL
;
304 _permission_mode
= check_options
[7].widget
->state
& C_BOOL
;
305 _equal_split
= check_options
[6].widget
->state
& C_BOOL
;
306 _menubar_visible
= check_options
[5].widget
->state
& C_BOOL
;
307 _command_prompt
= check_options
[4].widget
->state
& C_BOOL
;
308 _keybar_visible
= check_options
[2].widget
->state
& C_BOOL
;
309 _message_visible
= check_options
[1].widget
->state
& C_BOOL
;
310 _xterm_title
= check_options
[0].widget
->state
& C_BOOL
;
313 if (_output_lines
< 0)
315 height
= LINES
- _keybar_visible
- _command_prompt
-
316 _menubar_visible
- _output_lines
- _message_visible
;
317 minimum
= MINHEIGHT
* (1 + _horizontal_split
);
318 if (height
< minimum
){
319 _output_lines
-= minimum
- height
;
323 height
= LINES
- _keybar_visible
- _command_prompt
-
324 _menubar_visible
- _output_lines
- _message_visible
;
326 if (_horizontal_split
!= radio_widget
->sel
){
327 _horizontal_split
= radio_widget
->sel
;
328 if (_horizontal_split
)
329 _first_panel_size
= height
/ 2;
331 _first_panel_size
= COLS
/ 2;
335 if (old_output_lines
!= _output_lines
){
336 old_output_lines
= _output_lines
;
337 attrset (COLOR_NORMAL
);
338 dlg_move (h
, 9, 10 + first_width
);
339 printw ("%02d", _output_lines
);
345 return default_dlg_callback (h
, msg
, parm
);
352 static int i18n_layt_flag
= 0;
353 static int b1
, b2
, b3
;
354 int i
= sizeof (s_split_direction
) / sizeof (char *);
355 const char *ok_button
= _("&OK");
356 const char *cancel_button
= _("&Cancel");
357 const char *save_button
= _("&Save");
358 static const char *title1
, *title2
, *title3
;
360 if (!i18n_layt_flag
) {
363 first_width
= 19; /* length of line with '<' '>' buttons */
365 title1
= _(" Panel split ");
366 title2
= _(" Highlight... ");
367 title3
= _(" Other options ");
368 output_lines_label
= _("output lines");
371 s_split_direction
[i
] = _(s_split_direction
[i
]);
372 l1
= strlen (s_split_direction
[i
]) + 7;
373 if (l1
> first_width
)
377 for (i
= 0; i
<= 8; i
++) {
378 check_options
[i
].text
= _(check_options
[i
].text
);
379 l1
= strlen (check_options
[i
].text
) + 7;
380 if (l1
> first_width
)
384 l1
= strlen (title1
) + 1;
385 if (l1
> first_width
)
388 l1
= strlen (title2
) + 1;
389 if (l1
> first_width
)
393 second_width
= strlen (title3
) + 1;
394 for (i
= 0; i
< 6; i
++) {
395 check_options
[i
].text
= _(check_options
[i
].text
);
396 l1
= strlen (check_options
[i
].text
) + 7;
397 if (l1
> second_width
)
401 l1
= strlen (output_lines_label
) + 13;
402 if (l1
> second_width
)
408 * To be completely correct, one need to check if the title
409 * does not exceed dialog length and total length of 3 buttons
410 * allows their placement in one row. But assuming this dialog
411 * is wide enough, I don't include such a tests.
413 * Now the last thing to do - properly space buttons...
415 l1
= 11 + strlen (ok_button
) /* 14 - all brackets and inner space */
416 +strlen (save_button
) /* notice: it is 3 char less because */
417 +strlen (cancel_button
); /* of '&' char in button text */
419 i
= (first_width
+ second_width
- l1
) / 4;
421 b2
= b1
+ strlen (ok_button
) + i
+ 6;
422 b3
= b2
+ strlen (save_button
) + i
+ 4;
428 create_dlg (0, 0, 15, first_width
+ second_width
+ 9,
429 dialog_colors
, layout_callback
, "[Layout]",
430 _("Layout"), DLG_CENTER
| DLG_REVERSE
);
432 add_widget (layout_dlg
, groupbox_new (4, 2, first_width
, 6, title1
));
433 add_widget (layout_dlg
, groupbox_new (4, 8, first_width
, 4, title2
));
434 add_widget (layout_dlg
,
435 groupbox_new (5 + first_width
, 2, second_width
, 10,
438 add_widget (layout_dlg
,
439 button_new (BY
, b3
, B_CANCEL
, NORMAL_BUTTON
, cancel_button
,
441 add_widget (layout_dlg
,
442 button_new (BY
, b2
, B_EXIT
, NORMAL_BUTTON
, save_button
,
444 add_widget (layout_dlg
,
445 button_new (BY
, b1
, B_ENTER
, DEFPUSH_BUTTON
, ok_button
,
448 add_widget (layout_dlg
,
449 button_new (9, 12 + first_width
, B_MINUS
,
450 NARROW_BUTTON
, "&-", bminus_cback
));
451 add_widget (layout_dlg
,
452 button_new (9, 7 + first_width
, B_PLUS
, NARROW_BUTTON
,
455 #define XTRACT(i) *check_options[i].variable, check_options[i].text
457 for (i
= 0; i
< 6; i
++) {
458 check_options
[i
].widget
=
459 check_new (8 - i
, 7 + first_width
, XTRACT (i
));
460 add_widget (layout_dlg
, check_options
[i
].widget
);
462 check_options
[8].widget
= check_new (10, 6, XTRACT (8));
463 add_widget (layout_dlg
, check_options
[8].widget
);
464 check_options
[7].widget
= check_new (9, 6, XTRACT (7));
465 add_widget (layout_dlg
, check_options
[7].widget
);
467 _filetype_mode
= filetype_mode
;
468 _permission_mode
= permission_mode
;
469 _equal_split
= equal_split
;
470 _menubar_visible
= menubar_visible
;
471 _command_prompt
= command_prompt
;
472 _keybar_visible
= keybar_visible
;
473 _message_visible
= message_visible
;
474 _xterm_title
= xterm_title
;
476 button_new (6, 15, B_2RIGHT
, NARROW_BUTTON
, "&>", b2right_cback
);
477 add_widget (layout_dlg
, bright_widget
);
479 button_new (6, 9, B_2LEFT
, NARROW_BUTTON
, "&<", b2left_cback
);
480 add_widget (layout_dlg
, bleft_widget
);
481 check_options
[6].widget
= check_new (5, 6, XTRACT (6));
482 old_first_panel_size
= -1;
483 old_horizontal_split
= -1;
484 old_output_lines
= -1;
486 _first_panel_size
= first_panel_size
;
487 _output_lines
= output_lines
;
488 add_widget (layout_dlg
, check_options
[6].widget
);
489 radio_widget
= radio_new (3, 6, 2, s_split_direction
, 1);
490 add_widget (layout_dlg
, radio_widget
);
491 radio_widget
->sel
= horizontal_split
;
498 layout_do_change
= 0;
499 /* re-init the menu, because perhaps there was a change in the way
500 how the panel are split (horizontal/vertical). */
503 menubar_arrange (the_menubar
);
506 void layout_cmd (void)
512 run_dlg (layout_dlg
);
513 result
= layout_dlg
->ret_value
;
515 if (result
== B_ENTER
|| result
== B_EXIT
){
516 for (i
= 0; check_options
[i
].text
; i
++)
517 if (check_options
[i
].widget
)
518 *check_options
[i
].variable
= check_options
[i
].widget
->state
& C_BOOL
;
519 horizontal_split
= radio_widget
->sel
;
520 first_panel_size
= _first_panel_size
;
521 output_lines
= _output_lines
;
522 layout_do_change
= 1;
524 if (result
== B_EXIT
){
529 destroy_dlg (layout_dlg
);
530 if (layout_do_change
)
534 static void check_split (void)
536 if (horizontal_split
){
538 first_panel_size
= height
/ 2;
539 else if (first_panel_size
< MINHEIGHT
)
540 first_panel_size
= MINHEIGHT
;
541 else if (first_panel_size
> height
- MINHEIGHT
)
542 first_panel_size
= height
- MINHEIGHT
;
545 first_panel_size
= COLS
/ 2;
546 else if (first_panel_size
< MINWIDTH
)
547 first_panel_size
= MINWIDTH
;
548 else if (first_panel_size
> COLS
- MINWIDTH
)
549 first_panel_size
= COLS
- MINWIDTH
;
557 #ifndef HAS_ACS_AS_PCCHARS
558 if (force_ugly_line_drawing
)
559 SLtt_Has_Alt_Charset
= 0;
564 keypad (stdscr
, TRUE
);
565 nodelay (stdscr
, FALSE
);
568 static const struct {
572 { 'q', '-' }, /* ACS_HLINE */
573 { 'x', '|' }, /* ACS_VLINE */
574 { 'l', '+' }, /* ACS_ULCORNER */
575 { 'k', '+' }, /* ACS_URCORNER */
576 { 'm', '+' }, /* ACS_LLCORNER */
577 { 'j', '+' }, /* ACS_LRCORNER */
578 { 'a', '#' }, /* ACS_CKBOARD */
579 { 'u', '+' }, /* ACS_RTEE */
580 { 't', '+' }, /* ACS_LTEE */
581 { 'w', '+' }, /* ACS_TTEE */
582 { 'v', '+' }, /* ACS_BTEE */
583 { 'n', '+' }, /* ACS_PLUS */
586 void init_curses (void)
592 * If ncurses exports the ESCDELAY variable, it should be set to
593 * a low value, or you'll experience a delay in processing escape
594 * sequences that are recognized by mc (e.g. Esc-Esc). On the other
595 * hand, making ESCDELAY too small can result in some sequences
596 * (e.g. cursor arrows) being reported as separate keys under heavy
597 * processor load, and this can be a problem if mc hasn't learned
598 * them in the "Learn Keys" dialog. The value is in milliseconds.
601 #endif /* HAVE_ESCDELAY */
605 keypad (stdscr
, TRUE
);
606 nodelay (stdscr
, FALSE
);
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 */
620 dlg_erase (midnight_dlg
);
628 if (!(quit
& SUBSHELL_EXIT
))
632 keypad (stdscr
, FALSE
);
637 panel_do_cols (int index
)
639 if (get_display_type (index
) == view_listing
)
640 set_panel_formats ((WPanel
*) panels
[index
].widget
);
642 panel_update_cols (panels
[index
].widget
, frame_half
);
650 int promptl
; /* the prompt len */
654 if (output_lines
< 0)
657 LINES
- keybar_visible
- command_prompt
- menubar_visible
-
658 output_lines
- message_visible
;
659 minimum
= MINHEIGHT
* (1 + horizontal_split
);
660 if (height
< minimum
) {
661 output_lines
-= minimum
- height
;
666 LINES
- menubar_visible
- command_prompt
- keybar_visible
-
670 start_y
= menubar_visible
;
672 /* The column computing is defered until panel_do_cols */
673 if (horizontal_split
) {
674 widget_set_size (panels
[0].widget
, start_y
, 0, first_panel_size
,
677 widget_set_size (panels
[1].widget
, start_y
+ first_panel_size
, 0,
678 height
- first_panel_size
, 0);
680 int first_x
= first_panel_size
;
682 widget_set_size (panels
[0].widget
, start_y
, 0, height
, 0);
684 widget_set_size (panels
[1].widget
, start_y
, first_x
, height
, 0);
690 promptl
= strlen (prompt
);
692 widget_set_size (&the_menubar
->widget
, 0, 0, 1, COLS
);
694 if (command_prompt
) {
695 widget_set_size (&cmdline
->widget
, LINES
- 1 - keybar_visible
,
697 COLS
- promptl
- (keybar_visible
? 0 : 1));
698 winput_set_origin (cmdline
, promptl
,
699 COLS
- promptl
- (keybar_visible
? 0 : 1));
700 widget_set_size (&the_prompt
->widget
, LINES
- 1 - keybar_visible
,
703 widget_set_size (&cmdline
->widget
, 0, 0, 0, 0);
704 winput_set_origin (cmdline
, 0, 0);
705 widget_set_size (&the_prompt
->widget
, LINES
, COLS
, 0, 0);
708 widget_set_size ((Widget
*) the_bar
, LINES
- 1, 0, keybar_visible
, COLS
);
709 buttonbar_set_visible (the_bar
, keybar_visible
);
712 if (console_flag
&& output_lines
) {
714 LINES
- command_prompt
- keybar_visible
- output_lines
;
715 show_console_contents (output_start_y
,
716 LINES
- output_lines
- keybar_visible
- 1,
717 LINES
- keybar_visible
- 1);
719 if (message_visible
) {
720 widget_set_size (&the_hint
->widget
, height
+ start_y
, 0, 1, COLS
);
721 set_hintbar (""); /* clean up the line */
723 widget_set_size (&the_hint
->widget
, 0, 0, 0, 0);
726 update_xterm_title_path ();
729 void flag_winch (int dummy
)
732 #ifndef USE_NCURSES /* don't do malloc in a signal handler */
733 low_level_change_screen_size ();
739 low_level_change_screen_size (void)
741 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
742 #if defined TIOCGWINSZ
743 struct winsize winsz
;
745 winsz
.ws_col
= winsz
.ws_row
= 0;
746 /* Ioctl on the STDIN_FILENO */
747 ioctl (0, TIOCGWINSZ
, &winsz
);
748 if (winsz
.ws_col
&& winsz
.ws_row
){
749 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
750 resizeterm(winsz
.ws_row
, winsz
.ws_col
);
751 clearok(stdscr
,TRUE
); /* sigwinch's should use a semaphore! */
754 LINES
= winsz
.ws_row
;
756 #ifdef HAVE_SUBSHELL_SUPPORT
760 #endif /* TIOCGWINSZ */
761 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
765 change_screen_size (void)
767 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
768 #if defined TIOCGWINSZ
770 #ifndef NCURSES_VERSION
774 low_level_change_screen_size ();
776 #ifndef NCURSES_VERSION
777 /* XSI Curses spec states that portable applications shall not invoke
778 * initscr() more than once. This kludge could be done within the scope
779 * of the specification by using endwin followed by a refresh (in fact,
780 * more than one curses implementation does this); it is guaranteed to work
787 /* Inform currently running dialog */
788 (*current_dlg
->callback
) (current_dlg
, DLG_RESIZE
, 0);
790 #ifdef RESIZABLE_MENUBAR
791 menubar_arrange (the_menubar
);
794 /* Now, force the redraw */
797 #endif /* TIOCGWINSZ */
798 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
802 static int ok_to_refresh
= 1;
804 void use_dash (int flag
)
812 void set_hintbar(const char *str
)
814 label_set_text (the_hint
, str
);
815 if (ok_to_refresh
> 0)
819 void print_vfs_message (const char *msg
, ...)
826 g_vsnprintf (str
, sizeof (str
), msg
, ap
);
829 if (midnight_shutdown
)
832 if (!message_visible
|| !the_hint
|| !the_hint
->widget
.parent
) {
835 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
838 /* Preserve current cursor position */
839 getyx (stdscr
, row
, col
);
842 attrset (NORMAL_COLOR
);
843 printw ("%-*s", COLS
-1, str
);
845 /* Restore cursor position */
851 if (message_visible
) {
856 void rotate_dash (void)
858 static const char rotating_dash
[] = "|/-\\";
859 static size_t pos
= 0;
861 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
864 if (pos
>= sizeof (rotating_dash
)-1)
867 attrset (NORMAL_COLOR
);
868 addch (rotating_dash
[pos
]);
873 const char *get_nth_panel_name (int num
)
875 static char buffer
[BUF_SMALL
];
878 return "New Left Panel";
880 return "New Right Panel";
882 g_snprintf (buffer
, sizeof (buffer
), "%ith Panel", num
);
887 /* I wonder if I should start to use the folding mode than Dugan uses */
889 /* This is the centralized managing of the panel display types */
890 /* This routine takes care of destroying and creating new widgets */
891 /* Please note that it could manage MAX_VIEWS, not just left and right */
892 /* Currently nothing in the code takes advantage of this and has hard- */
893 /* coded values for two panels only */
895 /* Set the num-th panel to the view type: type */
896 /* This routine also keeps at least one WPanel object in the screen */
897 /* since a lot of routines depend on the current_panel variable */
898 void set_display_type (int num
, int type
)
900 int x
, y
, cols
, lines
;
901 int the_other
; /* Index to the other panel */
902 const char *file_name
= NULL
; /* For Quick view */
903 Widget
*new_widget
, *old_widget
;
904 WPanel
*the_other_panel
;
906 x
= y
= cols
= lines
= 0;
908 if (num
>= MAX_VIEWS
){
909 fprintf (stderr
, "Cannot allocate more that %d views\n", MAX_VIEWS
);
913 /* Check that we will have a WPanel * at least */
915 if (type
!= view_listing
){
916 the_other
= num
== 0 ? 1 : 0;
918 if (panels
[the_other
].type
!= view_listing
)
924 if (panels
[num
].widget
){
925 Widget
*w
= panels
[num
].widget
;
926 WPanel
*panel
= (WPanel
*) panels
[num
].widget
;
932 old_widget
= panels
[num
].widget
;
934 if (panels
[num
].type
== view_listing
){
935 if (panel
->frame_size
== frame_full
&& type
!= view_listing
){
936 cols
= COLS
- first_panel_size
;
938 x
= first_panel_size
;
947 new_widget
= (Widget
*) panel_new (get_nth_panel_name (num
));
951 new_widget
= (Widget
*) info_new ();
956 new_widget
= (Widget
*) tree_new (1, 0, 0, 0, 0);
960 new_widget
= (Widget
*) view_new (0, 0, 0, 0, 1);
961 the_other_panel
= (WPanel
*) panels
[the_other
].widget
;
964 the_other_panel
->dir
.list
[the_other_panel
->selected
].fname
;
968 view_load ((WView
*) new_widget
, 0, file_name
, 0);
971 panels
[num
].type
= type
;
972 panels
[num
].widget
= (Widget
*) new_widget
;
974 /* We set the same size the old widget had */
975 widget_set_size ((Widget
*) new_widget
, y
, x
, lines
, cols
);
977 /* We use replace to keep the circular list of the dialog in the */
978 /* same state. Maybe we could just kill it and then replace it */
979 if (midnight_dlg
&& old_widget
){
980 dlg_replace_widget (old_widget
, panels
[num
].widget
);
982 if (type
== view_listing
){
984 left_panel
= (WPanel
*) new_widget
;
986 right_panel
= (WPanel
*) new_widget
;
989 if (type
== view_tree
)
990 the_tree
= (WTree
*) new_widget
;
992 /* Prevent current_panel's value from becoming invalid.
993 * It's just a quick hack to prevent segfaults. Comment out and
995 * - select left panel
996 * - invoke menue left/tree
997 * - as long as you stay in the left panel almost everything that uses
998 * current_panel causes segfault, e.g. C-Enter, C-x c, ...
1001 if (type
!= view_listing
)
1002 if (current_panel
== (WPanel
*) old_widget
)
1003 current_panel
= num
== 0 ? right_panel
: left_panel
;
1006 /* This routine is deeply sticked to the two panels idea.
1007 What should it do in more panels. ANSWER - don't use it
1008 in any multiple panels environment. */
1014 WPanel
*panel1
, *panel2
;
1017 #define panelswap(x) panel. x = panel1-> x; panel1-> x = panel2-> x; panel2-> x = panel. x;
1019 #define panelswapstr(e) strcpy (panel. e, panel1-> e); \
1020 strcpy (panel1-> e, panel2-> e); \
1021 strcpy (panel2-> e, panel. e);
1022 panel1
= (WPanel
*) panels
[0].widget
;
1023 panel2
= (WPanel
*) panels
[1].widget
;
1024 if (panels
[0].type
== view_listing
&& panels
[1].type
== view_listing
) {
1025 /* Change everything except format/sort/panel_name etc. */
1032 panelswap (dirs_marked
);
1034 panelswap (top_file
);
1035 panelswap (selected
);
1036 panelswap (is_panelized
);
1037 panelswap (dir_stat
);
1039 panel1
->searching
= 0;
1040 panel2
->searching
= 0;
1041 if (current_panel
== panel1
)
1042 current_panel
= panel2
;
1044 current_panel
= panel1
;
1046 if (dlg_widget_active (panels
[0].widget
))
1047 dlg_select_widget (panels
[1].widget
);
1048 else if (dlg_widget_active (panels
[1].widget
))
1049 dlg_select_widget (panels
[0].widget
);
1053 tmp_panel
=right_panel
;
1054 right_panel
=left_panel
;
1055 left_panel
=tmp_panel
;
1057 if (panels
[0].type
== view_listing
) {
1058 if (!strcmp (panel1
->panel_name
, get_nth_panel_name (0))) {
1059 g_free (panel1
->panel_name
);
1060 panel1
->panel_name
= g_strdup (get_nth_panel_name (1));
1063 if (panels
[1].type
== view_listing
) {
1064 if (!strcmp (panel2
->panel_name
, get_nth_panel_name (1))) {
1065 g_free (panel2
->panel_name
);
1066 panel2
->panel_name
= g_strdup (get_nth_panel_name (0));
1070 tmp
.x
= panels
[0].widget
->x
;
1071 tmp
.y
= panels
[0].widget
->y
;
1072 tmp
.cols
= panels
[0].widget
->cols
;
1073 tmp
.lines
= panels
[0].widget
->lines
;
1075 panels
[0].widget
->x
= panels
[1].widget
->x
;
1076 panels
[0].widget
->y
= panels
[1].widget
->y
;
1077 panels
[0].widget
->cols
= panels
[1].widget
->cols
;
1078 panels
[0].widget
->lines
= panels
[1].widget
->lines
;
1080 panels
[1].widget
->x
= tmp
.x
;
1081 panels
[1].widget
->y
= tmp
.y
;
1082 panels
[1].widget
->cols
= tmp
.cols
;
1083 panels
[1].widget
->lines
= tmp
.lines
;
1085 tmp_widget
= panels
[0].widget
;
1086 panels
[0].widget
= panels
[1].widget
;
1087 panels
[1].widget
= tmp_widget
;
1088 tmp_type
= panels
[0].type
;
1089 panels
[0].type
= panels
[1].type
;
1090 panels
[1].type
= tmp_type
;
1094 int get_display_type (int index
)
1096 return panels
[index
].type
;
1100 get_panel_widget (int index
)
1102 return panels
[index
].widget
;
1105 int get_current_index (void)
1107 if (panels
[0].widget
== ((Widget
*) current_panel
))
1113 int get_other_index (void)
1115 return !get_current_index ();
1119 get_other_panel (void)
1121 return (struct WPanel
*) get_panel_widget (get_other_index ());
1124 /* Returns the view type for the current panel/view */
1125 int get_current_type (void)
1127 if (panels
[0].widget
== (Widget
*) current_panel
)
1128 return panels
[0].type
;
1130 return panels
[1].type
;
1133 /* Returns the view type of the unselected panel */
1134 int get_other_type (void)
1136 if (panels
[0].widget
== (Widget
*) current_panel
)
1137 return panels
[1].type
;
1139 return panels
[0].type
;