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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #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>
51 #include "dialog.h" /* For do_refresh() */
52 #include "profile.h" /* For sync_profiles() */
56 #include "subshell.h" /* For use_subshell and resize_subshell() */
60 /* Needed for the extern declarations of integer parameters */
62 #include "panel.h" /* The Panel widget */
64 #include "cons.saver.h"
66 #include "info.h" /* The Info widget */
67 #include "view.h" /* The view widget */
70 #include "setup.h" /* For save_setup() */
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 */
86 /* Set if the split is the same */
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) */
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 :-) */
118 } panels
[MAX_VIEWS
];
120 /* These variables are used to avoid updating the information unless */
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
;
141 /* Width 12 for a wee Quick (Hex) View */
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] = {
159 static WRadio
*radio_widget
;
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" },
179 static int first_width
, second_width
;
180 static char *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
){
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
;
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*/
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
)){
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
);
228 printw ("%03d", COLS
- _first_panel_size
);
231 static int b2left_cback (int action
, void *data
)
234 /* Turn equal split off */
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
);
244 static int b2right_cback (int action
, void *data
)
247 /* Turn equal split off */
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
);
257 static int bplus_cback (int action
, void *data
)
259 if (_output_lines
< 99)
264 static int bminus_cback (int action
, void *data
)
266 if (_output_lines
> 0)
271 static int layout_callback (struct Dlg_head
*h
, int Id
, int Msg
)
275 /*When repainting the whole dialog (e.g. with C-l) we have to
277 common_dialog_repaint (h
);
279 old_first_panel_size
= -1;
280 old_horizontal_split
= -1;
281 old_output_lines
= -1;
283 attrset (COLOR_NORMAL
);
284 draw_box (h
, 2, 4, 6, first_width
);
285 draw_box (h
, 8, 4, 4, first_width
);
286 draw_box (h
, 2, 5 + first_width
, 10, second_width
);
288 attrset (COLOR_HOT_NORMAL
);
293 dlg_move (h
, 2, 6 + first_width
);
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
);
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
;
321 if (_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
;
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;
341 _first_panel_size
= COLS
/ 2;
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
);
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");
373 first_width
= 19; /* length of line with '<' '>' buttons */
375 title1
= _(" Panel split ");
376 title2
= _(" Highlight... ");
377 title3
= _(" Other options ");
378 output_lines_label
= _("output lines");
382 s_split_direction
[i
] = _(s_split_direction
[i
]);
383 l1
= strlen (s_split_direction
[i
]) + 7;
384 if (l1
> first_width
)
388 for (i
= 0; i
<= 8; i
++)
390 check_options
[i
].text
= _(check_options
[i
].text
);
391 l1
= strlen (check_options
[i
].text
) + 7;
392 if (l1
> first_width
)
396 l1
= strlen (title1
) + 1;
397 if (l1
> first_width
)
400 l1
= strlen (title2
) + 1;
401 if (l1
> first_width
)
405 second_width
= strlen (title3
) + 1;
406 for (i
= 0; i
< 6; i
++)
408 check_options
[i
].text
= _(check_options
[i
].text
);
409 l1
= strlen (check_options
[i
].text
) + 7;
410 if (l1
> second_width
)
415 l1
= strlen (output_lines_label
) + 13;
416 if (l1
> second_width
)
422 * To be completely correct, one need to check if the title
423 * does not exceed dialog length and total length of 3 buttons
424 * allows their placement in one row. But assuming this dialog
425 * is wide enough, I don't include such a tests.
427 * Now the last thing to do - properly space buttons...
429 l1
= 11 + strlen (ok_button
) /* 14 - all brackets and inner space */
430 + strlen (save_button
) /* notice: it is 3 char less because */
431 + strlen (cancel_button
); /* of '&' char in button text */
433 i
= (first_width
+ second_width
- l1
) / 4;
435 b2
= b1
+ strlen(ok_button
) + i
+ 6;
436 b3
= b2
+ strlen(save_button
) + i
+ 4;
441 layout_dlg
= create_dlg (0, 0, 15, first_width
+ second_width
+ 9,
442 dialog_colors
, layout_callback
,
443 "[Layout]", _("Layout"), DLG_CENTER
);
445 add_widget (layout_dlg
,
446 button_new (BY
, b3
, B_CANCEL
, NORMAL_BUTTON
, cancel_button
, 0, 0, "c"));
447 add_widget (layout_dlg
,
448 button_new (BY
, b2
, B_EXIT
, NORMAL_BUTTON
, save_button
, 0, 0, "s"));
449 add_widget (layout_dlg
,
450 button_new (BY
, b1
, B_ENTER
, DEFPUSH_BUTTON
, ok_button
, 0, 0, "o"));
452 add_widget (layout_dlg
,
453 button_new (9, 12 + first_width
, B_MINUS
, NARROW_BUTTON
, "&-",
454 bminus_cback
, 0, NULL
));
455 add_widget (layout_dlg
,
456 button_new (9, 7 + first_width
, B_PLUS
, NARROW_BUTTON
, "&+",
457 bplus_cback
, 0, NULL
));
460 #define XTRACT(i) *check_options[i].variable, check_options[i].text, check_options[i].tkname
462 for (i
= 0; i
< 6; i
++){
463 check_options
[i
].widget
= check_new (8 - i
, 7 + first_width
, XTRACT(i
));
464 add_widget (layout_dlg
, check_options
[i
].widget
);
466 check_options
[8].widget
= check_new (10, 6, XTRACT(8));
467 add_widget (layout_dlg
, check_options
[8].widget
);
468 check_options
[7].widget
= check_new (9, 6, XTRACT(7));
469 add_widget (layout_dlg
, check_options
[7].widget
);
471 _filetype_mode
= filetype_mode
;
472 _permission_mode
= permission_mode
;
473 _equal_split
= equal_split
;
474 _menubar_visible
= menubar_visible
;
475 _command_prompt
= command_prompt
;
476 _keybar_visible
= keybar_visible
;
477 _message_visible
= message_visible
;
478 _xterm_hintbar
= xterm_hintbar
;
479 bright_widget
= button_new(6, 15, B_2RIGHT
, NARROW_BUTTON
, "&>", b2right_cback
, 0, ">");
480 add_widget (layout_dlg
, bright_widget
);
481 bleft_widget
= button_new (6, 9, B_2LEFT
, NARROW_BUTTON
, "&<", b2left_cback
, 0, "<");
482 add_widget (layout_dlg
, bleft_widget
);
483 check_options
[6].widget
= check_new (5, 6, XTRACT(6));
484 old_first_panel_size
= -1;
485 old_horizontal_split
= -1;
486 old_output_lines
= -1;
488 _first_panel_size
= first_panel_size
;
489 _output_lines
= output_lines
;
490 add_widget (layout_dlg
, check_options
[6].widget
);
491 radio_widget
= radio_new (3, 6, 2, s_split_direction
, 1, "r");
492 add_widget (layout_dlg
, radio_widget
);
493 radio_widget
->sel
= horizontal_split
;
496 void layout_change (void)
499 layout_do_change
= 0;
500 /* re-init the menu, because perhaps there was a change in the way
501 how the panel are split (horizontal/vertical). */
504 menubar_arrange(the_menubar
);
507 void layout_cmd (void)
513 run_dlg (layout_dlg
);
514 result
= layout_dlg
->ret_value
;
516 if (result
== B_ENTER
|| result
== B_EXIT
){
517 for (i
= 0; check_options
[i
].text
; i
++)
518 if (check_options
[i
].widget
)
519 *check_options
[i
].variable
= check_options
[i
].widget
->state
& C_BOOL
;
520 horizontal_split
= radio_widget
->sel
;
521 first_panel_size
= _first_panel_size
;
522 output_lines
= _output_lines
;
523 layout_do_change
= 1;
525 if (result
== B_EXIT
){
530 destroy_dlg (layout_dlg
);
531 if (layout_do_change
)
535 static void check_split (void)
537 if (horizontal_split
){
539 first_panel_size
= height
/ 2;
540 else if (first_panel_size
< MINHEIGHT
)
541 first_panel_size
= MINHEIGHT
;
542 else if (first_panel_size
> height
- MINHEIGHT
)
543 first_panel_size
= height
- MINHEIGHT
;
546 first_panel_size
= COLS
/ 2;
547 else if (first_panel_size
< MINWIDTH
)
548 first_panel_size
= MINWIDTH
;
549 else if (first_panel_size
> COLS
- MINWIDTH
)
550 first_panel_size
= COLS
- MINWIDTH
;
557 SLtt_get_terminfo ();
558 #ifndef HAS_ACS_AS_PCCHARS
559 if (force_ugly_line_drawing
)
560 SLtt_Has_Alt_Charset
= 0;
565 keypad (stdscr
, TRUE
);
566 nodelay (stdscr
, FALSE
);
569 static const struct {
573 { 'q', '-' }, /* ACS_HLINE */
574 { 'x', '|' }, /* ACS_VLINE */
575 { 'l', '+' }, /* ACS_ULCORNER */
576 { 'k', '+' }, /* ACS_URCORNER */
577 { 'm', '+' }, /* ACS_LLCORNER */
578 { 'j', '+' }, /* ACS_LRCORNER */
579 { 'a', '#' }, /* ACS_CKBOARD */
580 { 'u', '+' }, /* ACS_RTEE */
581 { 't', '+' }, /* ACS_LTEE */
582 { 'w', '+' }, /* ACS_TTEE */
583 { 'v', '+' }, /* ACS_BTEE */
584 { 'n', '+' }, /* ACS_PLUS */
587 void init_curses (void)
593 * If ncurses exports the ESCDELAY variable it should be set to 0
594 * or you'll have to press Esc three times to dismiss a dialog box.
597 #endif /* HAVE_ESCDELAY */
601 keypad (stdscr
, TRUE
);
602 nodelay (stdscr
, FALSE
);
604 if (force_ugly_line_drawing
) {
605 for (i
= 0; acs_approx
[i
].acscode
!= 0; i
++) {
606 acs_map
[acs_approx
[i
].acscode
] = acs_approx
[i
].character
;
610 #endif /* ! HAVE_SLANG */
614 if (!(quit
& SUBSHELL_EXIT
))
618 keypad (stdscr
, FALSE
);
622 panel_do_cols (int index
)
624 if (get_display_type (index
) == view_listing
)
625 set_panel_formats ((WPanel
*) panels
[index
].widget
);
627 panel_update_cols (panels
[index
].widget
, frame_half
);
629 /* In case of an Hex Quick View must review line length */
630 if (get_display_type (index
) == view_quick
)
631 view_update_bytes_per_line ((WView
*) panels
[index
].widget
);
639 int promptl
; /* the prompt len */
643 if (output_lines
< 0)
645 height
= LINES
- keybar_visible
- command_prompt
- menubar_visible
646 - output_lines
- message_visible
;
647 if (message_visible
&& xterm_hintbar
&& xterm_flag
)
649 minimum
= MINHEIGHT
* (1 + horizontal_split
);
650 if (height
< minimum
) {
651 output_lines
-= minimum
- height
;
655 height
= LINES
- menubar_visible
- command_prompt
-
656 keybar_visible
- message_visible
;
657 if (message_visible
&& xterm_hintbar
&& xterm_flag
)
661 start_y
= menubar_visible
;
663 /* The column computing is defered until panel_do_cols */
664 if (horizontal_split
) {
665 widget_set_size (panels
[0].widget
, start_y
, 0,
666 first_panel_size
, 0);
668 widget_set_size (panels
[1].widget
, start_y
+ first_panel_size
, 0,
669 height
- first_panel_size
, 0);
671 int first_x
= first_panel_size
;
673 widget_set_size (panels
[0].widget
, start_y
, 0, height
, 0);
675 widget_set_size (panels
[1].widget
, start_y
, first_x
, height
, 0);
681 promptl
= strlen (prompt
);
683 widget_set_size (&the_menubar
->widget
, 0, 0, 1, COLS
);
685 if (command_prompt
) {
686 widget_set_size (&cmdline
->widget
, LINES
- 1 - keybar_visible
,
688 COLS
- promptl
- (keybar_visible
? 0 : 1));
689 winput_set_origin (cmdline
, promptl
,
690 COLS
- promptl
- (keybar_visible
? 0 : 1));
691 widget_set_size (&the_prompt
->widget
, LINES
- 1 - keybar_visible
,
694 widget_set_size (&cmdline
->widget
, 0, 0, 0, 0);
695 winput_set_origin (cmdline
, 0, 0);
696 widget_set_size (&the_prompt
->widget
, LINES
, COLS
, 0, 0);
699 widget_set_size (&the_bar
->widget
, LINES
- 1, 0, keybar_visible
, COLS
);
700 the_bar
->visible
= keybar_visible
;
703 if (console_flag
&& output_lines
) {
704 output_start_y
= LINES
- command_prompt
- keybar_visible
-
706 show_console_contents (output_start_y
,
707 LINES
- output_lines
- keybar_visible
- 1,
708 LINES
- keybar_visible
- 1);
710 if (message_visible
&& (!xterm_hintbar
|| !xterm_flag
))
711 widget_set_size (&the_hint
->widget
, height
+ start_y
, 0, 1, COLS
);
713 widget_set_size (&the_hint
->widget
, 0, 0, 0, 0);
718 void flag_winch (int dummy
)
720 #ifndef USE_NCURSES /* don't do malloc in a signal handler */
721 low_level_change_screen_size ();
727 low_level_change_screen_size (void)
729 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
730 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
731 struct winsize winsz
;
733 winsz
.ws_col
= winsz
.ws_row
= 0;
734 /* Ioctl on the STDIN_FILENO */
735 ioctl (0, TIOCGWINSZ
, &winsz
);
736 if (winsz
.ws_col
&& winsz
.ws_row
){
737 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
738 resizeterm(winsz
.ws_row
, winsz
.ws_col
);
739 clearok(stdscr
,TRUE
); /* sigwinch's should use a semaphore! */
742 LINES
= winsz
.ws_row
;
744 #ifdef HAVE_SUBSHELL_SUPPORT
748 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
749 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
753 change_screen_size (void)
755 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
756 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
758 #ifndef NCURSES_VERSION
762 low_level_change_screen_size ();
764 #ifndef NCURSES_VERSION
765 /* XSI Curses spec states that portable applications shall not invoke
766 * initscr() more than once. This kludge could be done within the scope
767 * of the specification by using endwin followed by a refresh (in fact,
768 * more than one curses implementation does this); it is guaranteed to work
775 /* Inform currently running dialog */
776 (*current_dlg
->callback
) (current_dlg
, current_dlg
->current
->dlg_id
,
779 #ifdef RESIZABLE_MENUBAR
780 menubar_arrange (the_menubar
);
783 /* Now, force the redraw */
786 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
787 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
791 static int ok_to_refresh
= 1;
793 void use_dash (int flag
)
801 void set_hintbar(char *str
)
803 if (xterm_flag
&& xterm_hintbar
) {
804 fprintf (stdout
, "\33]0;mc - %s\7", str
);
807 label_set_text (the_hint
, str
);
808 if (ok_to_refresh
> 0)
813 void print_vfs_message (char *msg
, ...)
820 g_vsnprintf (str
, sizeof (str
), msg
, ap
);
823 if (midnight_shutdown
)
826 if (!message_visible
|| !the_hint
|| !the_hint
->widget
.parent
) {
828 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
831 attrset (NORMAL_COLOR
);
832 printw ("%-*s", COLS
-1, str
);
837 if (message_visible
|| (xterm_flag
&& xterm_hintbar
)) {
842 void rotate_dash (void)
844 static char rotating_dash
[] = "|/-\\";
847 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
850 if (pos
>= sizeof (rotating_dash
)-1)
853 addch (rotating_dash
[pos
]);
858 void remove_dash (void)
860 if (!nice_rotating_dash
)
863 /* Currently, it's much nicer with the CPU to do this instead of
866 I should implement a routine called invalidate_region that would
867 send a draw message only to the affected views. But for now
875 char *get_nth_panel_name (int num
)
877 static char buffer
[BUF_SMALL
];
880 return "New Left Panel";
882 return "New Right Panel";
884 g_snprintf (buffer
, sizeof (buffer
), "%ith Panel", num
);
889 /* I wonder if I should start to use the folding mode than Dugan uses */
891 /* This is the centralized managing of the panel display types */
892 /* This routine takes care of destroying and creating new widgets */
893 /* Please note that it could manage MAX_VIEWS, not just left and right */
894 /* Currently nothing in the code takes advantage of this and has hard- */
895 /* coded values for two panels only */
897 /* Set the num-th panel to the view type: type */
898 /* This routine also keeps at least one WPanel object in the screen */
899 /* since a lot of routines depend on the current_panel variable */
900 void set_display_type (int num
, int type
)
902 int x
, y
, cols
, lines
;
903 int the_other
; /* Index to the other panel */
904 char *file_name
= 0; /* For Quick view */
905 Widget
*new_widget
, *old_widget
;
906 WPanel
*the_other_panel
;
908 x
= y
= cols
= lines
= 0;
910 if (num
>= MAX_VIEWS
){
911 fprintf (stderr
, "Could not allocate more that %d views\n", MAX_VIEWS
);
915 /* Check that we will have a WPanel * at least */
917 if (type
!= view_listing
){
918 the_other
= num
== 0 ? 1 : 0;
920 if (panels
[the_other
].type
!= view_listing
)
926 if (panels
[num
].widget
){
927 Widget
*w
= panels
[num
].widget
;
928 WPanel
*panel
= (WPanel
*) panels
[num
].widget
;
934 old_widget
= panels
[num
].widget
;
936 if (panels
[num
].type
== view_listing
){
937 if (panel
->frame_size
== frame_full
&& type
!= view_listing
){
938 cols
= COLS
- first_panel_size
;
940 x
= first_panel_size
;
949 new_widget
= (Widget
*) panel_new (get_nth_panel_name (num
));
953 new_widget
= (Widget
*) info_new ();
958 new_widget
= (Widget
*) tree_new (1, 0, 0, 0, 0);
962 new_widget
= (Widget
*) view_new (0, 0, 0, 0, 1);
963 the_other_panel
= (WPanel
*) panels
[the_other
].widget
;
966 the_other_panel
->dir
.list
[the_other_panel
->selected
].fname
;
970 view_init ((WView
*) new_widget
, 0, file_name
, 0);
973 panels
[num
].type
= type
;
974 panels
[num
].widget
= (Widget
*) new_widget
;
976 /* We set the same size the old widget had */
977 widget_set_size ((Widget
*) new_widget
, y
, x
, lines
, cols
);
979 /* We use replace to keep the circular list of the dialog in the */
980 /* same state. Maybe we could just kill it and then replace it */
981 if (midnight_dlg
&& old_widget
){
982 dlg_replace_widget (midnight_dlg
, old_widget
, panels
[num
].widget
);
984 if (type
== view_listing
){
986 left_panel
= (WPanel
*) new_widget
;
988 right_panel
= (WPanel
*) new_widget
;
991 if (type
== view_tree
)
992 the_tree
= (WTree
*) new_widget
;
994 /* Prevent current_panel's value from becoming invalid.
995 * It's just a quick hack to prevent segfaults. Comment out and
997 * - select left panel
998 * - invoke menue left/tree
999 * - as long as you stay in the left panel almost everything that uses
1000 * cpanel causes segfault, e.g. C-Enter, C-x c, ...
1003 if (type
!= view_listing
)
1004 if (cpanel
== (WPanel
*) old_widget
)
1005 current_panel
= num
== 0 ? right_panel
: left_panel
;
1008 /* This routine is deeply sticked to the two panels idea.
1009 What should it do in more panels. ANSWER - don't use it
1010 in any multiple panels environment. */
1016 WPanel
*panel1
, *panel2
;
1019 #define panelswap(x) panel. x = panel1-> x; panel1-> x = panel2-> x; panel2-> x = panel. x;
1021 #define panelswapstr(e) strcpy (panel. e, panel1-> e); \
1022 strcpy (panel1-> e, panel2-> e); \
1023 strcpy (panel2-> e, panel. e);
1024 panel1
= (WPanel
*) panels
[0].widget
;
1025 panel2
= (WPanel
*) panels
[1].widget
;
1026 if (panels
[0].type
== view_listing
&& panels
[1].type
== view_listing
) {
1027 /* Change everything except format/sort/panel_name etc. */
1034 panelswap (dirs_marked
);
1036 panelswap (top_file
);
1037 panelswap (selected
);
1038 panelswap (is_panelized
);
1039 panelswap (dir_stat
);
1041 panel1
->searching
= 0;
1042 panel2
->searching
= 0;
1043 if (cpanel
== panel1
)
1044 current_panel
= panel2
;
1046 current_panel
= panel1
;
1047 if (midnight_dlg
->current
->widget
== panels
[0].widget
)
1048 dlg_select_widget (midnight_dlg
, (void *) panels
[1].widget
);
1049 else if (midnight_dlg
->current
->widget
== panels
[1].widget
)
1050 dlg_select_widget (midnight_dlg
, (void *) panels
[0].widget
);
1054 tmp_panel
=right_panel
;
1055 right_panel
=left_panel
;
1056 left_panel
=tmp_panel
;
1058 if (panels
[0].type
== view_listing
) {
1059 if (!strcmp (panel1
->panel_name
, get_nth_panel_name (0))) {
1060 g_free (panel1
->panel_name
);
1061 panel1
->panel_name
= g_strdup (get_nth_panel_name (1));
1064 if (panels
[1].type
== view_listing
) {
1065 if (!strcmp (panel2
->panel_name
, get_nth_panel_name (1))) {
1066 g_free (panel2
->panel_name
);
1067 panel2
->panel_name
= g_strdup (get_nth_panel_name (0));
1071 tmp
.x
= panels
[0].widget
->x
;
1072 tmp
.y
= panels
[0].widget
->y
;
1073 tmp
.cols
= panels
[0].widget
->cols
;
1074 tmp
.lines
= panels
[0].widget
->lines
;
1076 panels
[0].widget
->x
= panels
[1].widget
->x
;
1077 panels
[0].widget
->y
= panels
[1].widget
->y
;
1078 panels
[0].widget
->cols
= panels
[1].widget
->cols
;
1079 panels
[0].widget
->lines
= panels
[1].widget
->lines
;
1081 panels
[1].widget
->x
= tmp
.x
;
1082 panels
[1].widget
->y
= tmp
.y
;
1083 panels
[1].widget
->cols
= tmp
.cols
;
1084 panels
[1].widget
->lines
= tmp
.lines
;
1086 tmp_widget
= panels
[0].widget
;
1087 panels
[0].widget
= panels
[1].widget
;
1088 panels
[1].widget
= tmp_widget
;
1089 tmp_type
= panels
[0].type
;
1090 panels
[0].type
= panels
[1].type
;
1091 panels
[1].type
= tmp_type
;
1095 int get_display_type (int index
)
1097 return panels
[index
].type
;
1100 Widget
*get_panel_widget (int index
)
1102 return panels
[index
].widget
;
1105 int get_current_index (void)
1107 if (panels
[0].widget
== ((Widget
*) cpanel
))
1113 int get_other_index (void)
1115 return !get_current_index ();
1118 /* Returns the view type for the current panel/view */
1119 int get_current_type (void)
1121 if (panels
[0].widget
== (Widget
*) cpanel
)
1122 return panels
[0].type
;
1124 return panels
[1].type
;
1127 /* Returns the view type of the unselected panel */
1128 int get_other_type (void)
1130 if (panels
[0].widget
== (Widget
*) cpanel
)
1131 return panels
[1].type
;
1133 return panels
[0].type
;