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/param.h> /* Required by tree.h */
27 #include <sys/types.h>
29 #if (!defined(__IBMC__) && !defined(__IBMCPP__)) && !defined(HAS_NO_TERMIOS_H)
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>
53 #include "dialog.h" /* For do_refresh() */
54 #include "profile.h" /* For sync_profiles() */
58 #include "subshell.h" /* For use_subshell and resize_subshell() */
62 /* Needed for the extern declarations of integer parameters */
64 #include "panel.h" /* The Panel widget */
66 #include "cons.saver.h"
68 #include "info.h" /* The Info widget */
69 #include "view.h" /* The view widget */
72 #include "setup.h" /* For save_setup() */
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 */
90 /* Set if the split is the same */
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) */
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 :-) */
122 } panels
[MAX_VIEWS
];
124 /* These variables are used to avoid updating the information unless */
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
;
145 /* Width 12 for a wee Quick (Hex) View */
151 #define B_2LEFT B_USER
152 #define B_2RIGHT B_USER + 1
153 #define B_PLUS B_USER + 2
154 #define B_MINUS B_USER + 3
156 static Dlg_head
*layout_dlg
;
158 static char *s_split_direction
[2] = {
162 WRadio
*radio_widget
;
169 } check_options
[] = {
170 { N_("&Xterm hintbar"), &xterm_hintbar
, 0, "h" },
171 { N_("h&Intbar visible"), &message_visible
, 0, "v" },
172 { N_("&Keybar visible"), &keybar_visible
, 0, "k" },
173 { N_("command &Prompt"), &command_prompt
, 0, "p" },
174 { N_("show &Mini status"), &show_mini_info
, 0, "m" },
175 { N_("menu&Bar visible"), &menubar_visible
, 0, "me" },
176 { N_("&Equal split"), &equal_split
, 0, "eq" },
177 { N_("pe&Rmissions"), &permission_mode
, 0, "pr" },
178 { N_("&File types"), &filetype_mode
, 0, "ft" },
182 static int first_width
, second_width
;
183 static char *layout_title
, *title1
, *title2
, *title3
, *output_lines_label
;
185 static WButton
*bleft_widget
, *bright_widget
;
187 /* Declarations for static functions */
188 static void low_level_change_screen_size (void);
190 static void _check_split (void)
192 if (_horizontal_split
){
194 _first_panel_size
= height
/ 2;
195 else if (_first_panel_size
< MINHEIGHT
)
196 _first_panel_size
= MINHEIGHT
;
197 else if (_first_panel_size
> height
- MINHEIGHT
)
198 _first_panel_size
= height
- MINHEIGHT
;
201 _first_panel_size
= COLS
/ 2;
202 else if (_first_panel_size
< MINWIDTH
)
203 _first_panel_size
= MINWIDTH
;
204 else if (_first_panel_size
> COLS
- MINWIDTH
)
205 _first_panel_size
= COLS
- MINWIDTH
;
209 static void update_split (void)
211 /* Check split has to be done before testing if it changed, since
212 it can change due to calling _check_split() as well*/
215 /* To avoid setting the cursor to the wrong place */
216 if ((old_first_panel_size
== _first_panel_size
) &&
217 (old_horizontal_split
== _horizontal_split
)){
221 old_first_panel_size
= _first_panel_size
;
222 old_horizontal_split
= _horizontal_split
;
224 attrset (COLOR_NORMAL
);
225 dlg_move (layout_dlg
, 6, 6);
226 printw ("%03d", _first_panel_size
);
227 dlg_move (layout_dlg
, 6, 18);
228 if (_horizontal_split
)
229 printw ("%03d", height
- _first_panel_size
);
231 printw ("%03d", COLS
- _first_panel_size
);
234 static int b2left_cback (int action
, void *data
)
237 /* Turn equal split off */
239 check_options
[6].widget
->state
= check_options
[6].widget
->state
& ~C_BOOL
;
240 dlg_select_widget (layout_dlg
, check_options
[6].widget
);
241 dlg_select_widget (layout_dlg
, bleft_widget
);
247 static int b2right_cback (int action
, void *data
)
250 /* Turn equal split off */
252 check_options
[6].widget
->state
= check_options
[6].widget
->state
& ~C_BOOL
;
253 dlg_select_widget (layout_dlg
, check_options
[6].widget
);
254 dlg_select_widget (layout_dlg
, bright_widget
);
260 static int bplus_cback (int action
, void *data
)
262 if (_output_lines
< 99)
267 static int bminus_cback (int action
, void *data
)
269 if (_output_lines
> 0)
274 static int layout_callback (struct Dlg_head
*h
, int Id
, int Msg
)
278 /*When repainting the whole dialog (e.g. with C-l) we have to
280 old_first_panel_size
= -1;
281 old_horizontal_split
= -1;
282 old_output_lines
= -1;
283 attrset (COLOR_NORMAL
);
285 draw_box (h
, 1, 2, h
->lines
- 2, h
->cols
- 4);
286 draw_box (h
, 2, 4, 6, first_width
);
287 draw_box (h
, 8, 4, 4, first_width
);
288 draw_box (h
, 2, 5 + first_width
, 10, second_width
);
290 attrset (COLOR_HOT_NORMAL
);
291 dlg_move (h
, 1, (h
->cols
- strlen(layout_title
))/2);
292 addstr (layout_title
);
297 dlg_move (h
, 2, 6 + first_width
);
303 if (old_output_lines
!= _output_lines
){
304 old_output_lines
= _output_lines
;
305 attrset (COLOR_NORMAL
);
306 dlg_move (h
, 9, 16 + first_width
);
307 addstr (output_lines_label
);
308 dlg_move (h
, 9, 10 + first_width
);
309 printw ("%02d", _output_lines
);
315 _filetype_mode
= check_options
[8].widget
->state
& C_BOOL
;
316 _permission_mode
= check_options
[7].widget
->state
& C_BOOL
;
317 _equal_split
= check_options
[6].widget
->state
& C_BOOL
;
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
;
325 if (_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
;
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;
345 _first_panel_size
= COLS
/ 2;
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
);
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");
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");
387 s_split_direction
[i
] = _(s_split_direction
[i
]);
388 l1
= strlen (s_split_direction
[i
]) + 7;
389 if (l1
> first_width
)
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
)
401 l1
= strlen (title1
) + 1;
402 if (l1
> first_width
)
405 l1
= strlen (title2
) + 1;
406 if (l1
> first_width
)
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
)
420 l1
= strlen (output_lines_label
) + 13;
421 if (l1
> second_width
)
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;
440 b2
= b1
+ strlen(ok_button
) + i
+ 6;
441 b3
= b2
+ strlen(save_button
) + i
+ 4;
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_widget (layout_dlg
,
453 button_new (BY
, b3
, B_CANCEL
, NORMAL_BUTTON
, cancel_button
, 0, 0, "c"));
454 add_widget (layout_dlg
,
455 button_new (BY
, b2
, B_EXIT
, NORMAL_BUTTON
, save_button
, 0, 0, "s"));
456 add_widget (layout_dlg
,
457 button_new (BY
, b1
, B_ENTER
, DEFPUSH_BUTTON
, ok_button
, 0, 0, "o"));
459 add_widget (layout_dlg
,
460 button_new (9, 12 + first_width
, B_MINUS
, NARROW_BUTTON
, "&-",
461 bminus_cback
, 0, NULL
));
462 add_widget (layout_dlg
,
463 button_new (9, 7 + first_width
, B_PLUS
, NARROW_BUTTON
, "&+",
464 bplus_cback
, 0, NULL
));
467 #define XTRACT(i) *check_options[i].variable, check_options[i].text, check_options[i].tkname
469 for (i
= 0; i
< 6; i
++){
470 check_options
[i
].widget
= check_new (8 - i
, 7 + first_width
, XTRACT(i
));
471 add_widget (layout_dlg
, check_options
[i
].widget
);
473 check_options
[8].widget
= check_new (10, 6, XTRACT(8));
474 add_widget (layout_dlg
, check_options
[8].widget
);
475 check_options
[7].widget
= check_new (9, 6, XTRACT(7));
476 add_widget (layout_dlg
, check_options
[7].widget
);
478 _filetype_mode
= filetype_mode
;
479 _permission_mode
= permission_mode
;
480 _equal_split
= equal_split
;
481 _menubar_visible
= menubar_visible
;
482 _command_prompt
= command_prompt
;
483 _keybar_visible
= keybar_visible
;
484 _message_visible
= message_visible
;
485 _xterm_hintbar
= xterm_hintbar
;
486 bright_widget
= button_new(6, 15, B_2RIGHT
, NARROW_BUTTON
, "&>", b2right_cback
, 0, ">");
487 add_widget (layout_dlg
, bright_widget
);
488 bleft_widget
= button_new (6, 9, B_2LEFT
, NARROW_BUTTON
, "&<", b2left_cback
, 0, "<");
489 add_widget (layout_dlg
, bleft_widget
);
490 check_options
[6].widget
= check_new (5, 6, XTRACT(6));
491 old_first_panel_size
= -1;
492 old_horizontal_split
= -1;
493 old_output_lines
= -1;
495 _first_panel_size
= first_panel_size
;
496 _output_lines
= output_lines
;
497 add_widget (layout_dlg
, check_options
[6].widget
);
498 radio_widget
= radio_new (3, 6, 2, s_split_direction
, 1, "r");
499 add_widget (layout_dlg
, radio_widget
);
500 radio_widget
->sel
= horizontal_split
;
503 void layout_change (void)
506 layout_do_change
= 0;
507 /* re-init the menu, because perhaps there was a change in the way
508 how the panel are split (horizontal/vertical). */
511 menubar_arrange(the_menubar
);
514 void layout_cmd (void)
520 run_dlg (layout_dlg
);
521 result
= layout_dlg
->ret_value
;
523 if (result
== B_ENTER
|| result
== B_EXIT
){
524 for (i
= 0; check_options
[i
].text
; i
++)
525 if (check_options
[i
].widget
)
526 *check_options
[i
].variable
= check_options
[i
].widget
->state
& C_BOOL
;
527 horizontal_split
= radio_widget
->sel
;
528 first_panel_size
= _first_panel_size
;
529 output_lines
= _output_lines
;
530 layout_do_change
= 1;
532 if (result
== B_EXIT
){
537 destroy_dlg (layout_dlg
);
538 if (layout_do_change
)
542 static void check_split (void)
544 if (horizontal_split
){
546 first_panel_size
= height
/ 2;
547 else if (first_panel_size
< MINHEIGHT
)
548 first_panel_size
= MINHEIGHT
;
549 else if (first_panel_size
> height
- MINHEIGHT
)
550 first_panel_size
= height
- MINHEIGHT
;
553 first_panel_size
= COLS
/ 2;
554 else if (first_panel_size
< MINWIDTH
)
555 first_panel_size
= MINWIDTH
;
556 else if (first_panel_size
> COLS
- MINWIDTH
)
557 first_panel_size
= COLS
- MINWIDTH
;
561 int panel_event (Gpm_Event
*event
, WPanel
*panel
);
562 int menu_bar_event (Gpm_Event
*event
, void *);
568 extern int force_ugly_line_drawing
;
569 extern int SLtt_Has_Alt_Charset
;
570 SLtt_get_terminfo ();
571 #ifndef HAS_ACS_AS_PCCHARS
572 if (force_ugly_line_drawing
)
573 SLtt_Has_Alt_Charset
= 0;
578 keypad (stdscr
, TRUE
);
579 nodelay (stdscr
, FALSE
);
582 void init_curses (void)
587 * If ncurses exports the ESCDELAY variable it should be set to 0
588 * or you'll have to press Esc three times to dismiss a dialog box.
592 if (!status_using_ncurses
)
596 keypad (stdscr
, TRUE
);
597 nodelay (stdscr
, FALSE
);
600 #endif /* ! HAVE_SLANG */
604 if (!(quit
& SUBSHELL_EXIT
))
610 keypad (stdscr
, FALSE
);
614 panel_do_cols (int index
)
616 if (get_display_type (index
) == view_listing
)
617 set_panel_formats ((WPanel
*) panels
[index
].widget
);
619 panel_update_cols (panels
[index
].widget
, frame_half
);
621 /* In case of an Hex Quick View must review line length */
622 if (get_display_type (index
) == view_quick
)
623 view_update_bytes_per_line ((WView
*) panels
[index
].widget
);
627 void setup_panels (void)
630 int promptl
; /* the prompt len */
634 if (output_lines
< 0)
636 height
= LINES
- keybar_visible
- command_prompt
- menubar_visible
637 - output_lines
- message_visible
;
638 if (message_visible
&& xterm_hintbar
&& xterm_flag
) height
++;
639 minimum
= MINHEIGHT
* (1 + horizontal_split
);
640 if (height
< minimum
){
641 output_lines
-= minimum
- height
;
645 height
= LINES
- menubar_visible
- command_prompt
-
646 keybar_visible
- message_visible
;
647 if (message_visible
&& xterm_hintbar
&& xterm_flag
) height
++;
650 start_y
= menubar_visible
;
652 /* The column computing is defered until panel_do_cols */
653 if (horizontal_split
){
654 widget_set_size (panels
[0].widget
, start_y
, 0,
655 first_panel_size
, 0);
657 widget_set_size (panels
[1].widget
, start_y
+first_panel_size
, 0,
658 height
-first_panel_size
, 0);
660 int first_x
= first_panel_size
;
662 widget_set_size (panels
[0].widget
, start_y
, 0,
665 widget_set_size (panels
[1].widget
, start_y
, first_x
,
672 promptl
= strlen (prompt
);
674 widget_set_size (&the_menubar
->widget
, 0, 0, 1, COLS
);
676 if (command_prompt
) {
677 widget_set_size (&cmdline
->input
.widget
,
678 LINES
-1-keybar_visible
, promptl
,
679 1, COLS
-promptl
-(keybar_visible
? 0 : 1));
680 winput_set_origin (&cmdline
->input
, promptl
, COLS
-promptl
-(keybar_visible
? 0 : 1));
681 widget_set_size (&the_prompt
->widget
,
682 LINES
-1-keybar_visible
, 0,
685 widget_set_size (&cmdline
->input
.widget
, 0, 0, 0, 0);
686 winput_set_origin (&cmdline
->input
, 0, 0);
687 widget_set_size (&the_prompt
->widget
, LINES
, COLS
, 0, 0);
690 widget_set_size (&the_bar
->widget
, LINES
-1, 0, 1, COLS
);
691 the_bar
->visible
= keybar_visible
;
694 if (console_flag
&& output_lines
){
695 output_start_y
= LINES
-command_prompt
-keybar_visible
-
697 show_console_contents (output_start_y
,
698 LINES
-output_lines
-keybar_visible
-1,
699 LINES
-keybar_visible
-1);
701 if (message_visible
&& (!xterm_hintbar
|| !xterm_flag
))
702 widget_set_size (&the_hint
->widget
, height
+start_y
, 0, 1,COLS
);
704 widget_set_size (&the_hint
->widget
, 0, 0, 0, 0);
709 void flag_winch (int dummy
)
711 low_level_change_screen_size ();
715 void edit_adjust_size (Dlg_head
* h
);
718 low_level_change_screen_size (void)
720 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
721 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
722 struct winsize winsz
;
724 winsz
.ws_col
= winsz
.ws_row
= 0;
725 /* Ioctl on the STDIN_FILENO */
726 ioctl (0, TIOCGWINSZ
, &winsz
);
727 if (winsz
.ws_col
&& winsz
.ws_row
){
728 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
729 resizeterm(winsz
.ws_row
, winsz
.ws_col
);
730 clearok(stdscr
,TRUE
); /* FIXME: sigwinch's should use a semaphore! */
733 LINES
= winsz
.ws_row
;
735 #ifdef HAVE_SUBSHELL_SUPPORT
739 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
740 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
743 void change_screen_size (void)
745 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
746 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
747 extern Dlg_head
*view_dlg
;
748 extern Dlg_head
*edit_dlg
;
750 #ifndef NCURSES_VERSION
754 low_level_change_screen_size ();
756 #ifndef NCURSES_VERSION
757 /* XSI Curses spec states that portable applications shall not invoke
758 * initscr() more than once. This kludge could be done within the scope
759 * of the specification by using endwin followed by a refresh (in fact,
760 * more than one curses implementation does this); it is guaranteed to work
766 if (current_dlg
== view_dlg
)
767 view_adjust_size (view_dlg
);
768 #ifdef USE_INTERNAL_EDIT
769 if (current_dlg
== edit_dlg
)
770 edit_adjust_size (edit_dlg
);
773 #ifdef RESIZABLE_MENUBAR
774 menubar_arrange(the_menubar
);
777 /* Now, force the redraw */
780 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
781 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
785 static int ok_to_refresh
= 1;
787 void use_dash (int flag
)
795 void set_hintbar(char *str
)
797 if (xterm_flag
&& xterm_hintbar
) {
798 fprintf (stdout
, "\33]0;mc - %s\7", str
);
801 label_set_text (the_hint
, str
);
802 if (ok_to_refresh
> 0)
807 void print_vfs_message (char *msg
, ...)
814 g_vsnprintf (str
, sizeof (str
), msg
, ap
);
817 if (midnight_shutdown
)
820 if (!message_visible
|| !the_hint
|| !the_hint
->widget
.parent
) {
822 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
825 printw ("%-*s", COLS
-1, str
);
830 if (message_visible
|| (xterm_flag
&& xterm_hintbar
)) {
835 void rotate_dash (void)
837 static char rotating_dash
[] = "|/-\\";
840 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
843 if (pos
>= sizeof (rotating_dash
)-1)
846 addch (rotating_dash
[pos
]);
851 void remove_dash (void)
853 if (!nice_rotating_dash
)
856 /* Currently, it's much nicer with the CPU to do this instead of
859 I should implement a routine called invalidate_region that would
860 send a draw message only to the affected views. But for now
868 char *get_nth_panel_name (int num
)
870 static char buffer
[BUF_SMALL
];
873 return "New Left Panel";
875 return "New Right Panel";
877 g_snprintf (buffer
, sizeof (buffer
), "%ith Panel", num
);
882 /* I wonder if I should start to use the folding mode than Dugan uses */
884 /* This is the centralized managing of the panel display types */
885 /* This routine takes care of destroying and creating new widgets */
886 /* Please note that it could manage MAX_VIEWS, not just left and right */
887 /* Currently nothing in the code takes advantage of this and has hard- */
888 /* coded values for two panels only */
890 /* Set the num-th panel to the view type: type */
891 /* This routine also keeps at least one WPanel object in the screen */
892 /* since a lot of routines depend on the current_panel variable */
893 void set_display_type (int num
, int type
)
895 int x
, y
, cols
, lines
;
896 int the_other
; /* Index to the other panel */
897 char *file_name
= 0; /* For Quick view */
898 Widget
*new_widget
, *old_widget
;
899 WPanel
*the_other_panel
;
901 x
= y
= cols
= lines
= 0;
903 if (num
>= MAX_VIEWS
){
904 fprintf (stderr
, "Could not allocate more that %d views\n", MAX_VIEWS
);
908 /* Check that we will have a WPanel * at least */
910 if (type
!= view_listing
){
911 the_other
= num
== 0 ? 1 : 0;
913 if (panels
[the_other
].type
!= view_listing
)
919 if (panels
[num
].widget
){
920 Widget
*w
= panels
[num
].widget
;
921 WPanel
*panel
= (WPanel
*) panels
[num
].widget
;
927 old_widget
= panels
[num
].widget
;
929 if (panels
[num
].type
== view_listing
){
930 if (panel
->frame_size
== frame_full
&& type
!= view_listing
){
931 cols
= COLS
- first_panel_size
;
933 x
= first_panel_size
;
942 new_widget
= (Widget
*) panel_new (get_nth_panel_name (num
));
946 new_widget
= (Widget
*) info_new ();
951 new_widget
= (Widget
*) tree_new (1, 0, 0, 0, 0);
955 new_widget
= (Widget
*) view_new (0, 0, 0, 0, 1);
956 the_other_panel
= (WPanel
*) panels
[the_other
].widget
;
959 the_other_panel
->dir
.list
[the_other_panel
->selected
].fname
;
963 view_init ((WView
*) new_widget
, 0, file_name
, 0);
966 panels
[num
].type
= type
;
967 panels
[num
].widget
= (Widget
*) new_widget
;
969 /* We set the same size the old widget had */
970 widget_set_size ((Widget
*) new_widget
, y
, x
, lines
, cols
);
972 /* We wanna the new widget at the same position */
973 /* XView sets wcontainer to !0 <- Not XView, but we, when we create it */
974 /* Ok, the XView support code does it */
975 if (old_widget
&& old_widget
->wcontainer
){
976 new_widget
->wcontainer
= old_widget
->wcontainer
;
977 new_widget
->area
= old_widget
->area
;
980 /* We use replace to keep the circular list of the dialog in the */
981 /* same state. Maybe we could just kill it and then replace it */
982 if (midnight_dlg
&& old_widget
){
983 dlg_replace_widget (midnight_dlg
, old_widget
, panels
[num
].widget
);
985 if (type
== view_listing
){
987 left_panel
= (WPanel
*) new_widget
;
989 right_panel
= (WPanel
*) new_widget
;
992 if (type
== view_tree
)
993 the_tree
= (WTree
*) new_widget
;
995 /* Prevent current_panel's value from becoming invalid.
996 * It's just a quick hack to prevent segfaults. Comment out and
998 * - select left panel
999 * - invoke menue left/tree
1000 * - as long as you stay in the left panel almost everything that uses
1001 * cpanel causes segfault, e.g. C-Enter, C-x c, ...
1004 if (type
!= view_listing
)
1005 if (cpanel
== (WPanel
*) old_widget
)
1006 current_panel
= num
== 0 ? right_panel
: left_panel
;
1009 /* This routine is deeply sticked to the two panels idea.
1010 What should it do in more panels. ANSWER - don't use it
1011 in any multiple panels environment. */
1017 WPanel
*panel1
, *panel2
;
1020 #define panelswap(x) panel. x = panel1-> x; panel1-> x = panel2-> x; panel2-> x = panel. x;
1022 #define panelswapstr(e) strcpy (panel. e, panel1-> e); \
1023 strcpy (panel1-> e, panel2-> e); \
1024 strcpy (panel2-> e, panel. e);
1025 panel1
= (WPanel
*) panels
[0].widget
;
1026 panel2
= (WPanel
*) panels
[1].widget
;
1027 if (panels
[0].type
== view_listing
&& panels
[1].type
== view_listing
) {
1028 /* Change everything except format/sort/panel_name etc. */
1035 panelswap (dirs_marked
);
1037 panelswap (top_file
);
1038 panelswap (selected
);
1039 panelswap (is_panelized
);
1040 panelswap (dir_stat
);
1042 panel1
->searching
= 0;
1043 panel2
->searching
= 0;
1044 if (cpanel
== panel1
)
1045 current_panel
= panel2
;
1047 current_panel
= panel1
;
1048 if (midnight_dlg
->current
->widget
== panels
[0].widget
)
1049 dlg_select_widget (midnight_dlg
, (void *) panels
[1].widget
);
1050 else if (midnight_dlg
->current
->widget
== panels
[1].widget
)
1051 dlg_select_widget (midnight_dlg
, (void *) panels
[0].widget
);
1055 tmp_panel
=right_panel
;
1056 right_panel
=left_panel
;
1057 left_panel
=tmp_panel
;
1059 if (panels
[0].type
== view_listing
) {
1060 if (!strcmp (panel1
->panel_name
, get_nth_panel_name (0))) {
1061 g_free (panel1
->panel_name
);
1062 panel1
->panel_name
= g_strdup (get_nth_panel_name (1));
1065 if (panels
[1].type
== view_listing
) {
1066 if (!strcmp (panel2
->panel_name
, get_nth_panel_name (1))) {
1067 g_free (panel2
->panel_name
);
1068 panel2
->panel_name
= g_strdup (get_nth_panel_name (0));
1072 tmp
.x
= panels
[0].widget
->x
;
1073 tmp
.y
= panels
[0].widget
->y
;
1074 tmp
.cols
= panels
[0].widget
->cols
;
1075 tmp
.lines
= panels
[0].widget
->lines
;
1077 panels
[0].widget
->x
= panels
[1].widget
->x
;
1078 panels
[0].widget
->y
= panels
[1].widget
->y
;
1079 panels
[0].widget
->cols
= panels
[1].widget
->cols
;
1080 panels
[0].widget
->lines
= panels
[1].widget
->lines
;
1082 panels
[1].widget
->x
= tmp
.x
;
1083 panels
[1].widget
->y
= tmp
.y
;
1084 panels
[1].widget
->cols
= tmp
.cols
;
1085 panels
[1].widget
->lines
= tmp
.lines
;
1087 tmp_widget
= panels
[0].widget
;
1088 panels
[0].widget
= panels
[1].widget
;
1089 panels
[1].widget
= tmp_widget
;
1090 tmp_type
= panels
[0].type
;
1091 panels
[0].type
= panels
[1].type
;
1092 panels
[1].type
= tmp_type
;
1096 int get_display_type (int index
)
1098 return panels
[index
].type
;
1101 Widget
*get_panel_widget (int index
)
1103 return panels
[index
].widget
;
1106 int get_current_index (void)
1108 if (panels
[0].widget
== ((Widget
*) cpanel
))
1114 int get_other_index (void)
1116 return !get_current_index ();
1119 /* Returns the view type for the current panel/view */
1120 int get_current_type (void)
1122 if (panels
[0].widget
== (Widget
*) cpanel
)
1123 return panels
[0].type
;
1125 return panels
[1].type
;
1128 /* Returns the view type of the unselected panel */
1129 int get_other_type (void)
1131 if (panels
[0].widget
== (Widget
*) cpanel
)
1132 return panels
[1].type
;
1134 return panels
[0].type
;