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., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <sys/param.h> /* Required by tree.h */
28 #include <sys/types.h>
30 #if (!defined(__IBMC__) && !defined(__IBMCPP__)) && !defined(OS2_NT)
33 * If TIOCGWINSZ supported, make it available here, because window-
34 * resizing code depends on it...
36 # ifdef __QNX__ /* Maybe not only QNX-specific... */
37 # include <sys/ioctl.h>
46 #include "util.h" /* Needed for the externs */
55 #include "dialog.h" /* For do_refresh() */
56 #include "profile.h" /* For sync_profiles() */
60 #include "subshell.h" /* For use_subshell and resize_subshell() */
64 /* Needed for the extern declarations of integer parameters */
66 #include "panel.h" /* The Panel widget */
68 #include "cons.saver.h"
70 #include "info.h" /* The Info widget */
71 #include "view.h" /* The view widget */
74 #include "setup.h" /* For save_setup() */
80 /* Controls the display of the rotating dash on the verbose mode */
81 int nice_rotating_dash
= 1;
83 /* If set, then we have to call the layout_change routine from main */
84 int layout_do_change
= 0;
86 /* Set if the panels are split horizontally */
87 int horizontal_split
= 0;
89 /* Set if the window has changed it's size */
92 /* Set if the split is the same */
95 /* First panel size if the panel are not split equally */
96 int first_panel_size
= 0;
98 /* The number of output lines shown (if available) */
101 /* Set if the command prompt is to be displayed */
102 int command_prompt
= 1;
104 /* Set if the nice and usefull keybar is visible */
105 int keybar_visible
= 1;
107 /* Set if the nice message (hint) bar is visible */
108 int message_visible
= 1;
110 /* Set if you want the message bar shown in xterm title bar to save space */
111 int xterm_hintbar
= 0;
113 /* The starting line for the output of the subprogram */
114 int output_start_y
= 0;
116 /* The maximum number of views managed by the set_display_type routine */
117 /* Must be at least two (for current and other). Please note that until */
118 /* Janne gets around this, we will only manage two of them :-) */
124 } panels
[MAX_VIEWS
];
126 /* These variables are used to avoid updating the information unless */
128 static int old_first_panel_size
;
129 static int old_horizontal_split
;
130 static int old_output_lines
;
132 /* Internal variables */
133 static int _horizontal_split
;
134 static int _equal_split
;
135 static int _first_panel_size
;
136 static int _menubar_visible
;
137 static int _output_lines
;
138 static int _command_prompt
;
139 static int _keybar_visible
;
140 static int _message_visible
;
141 static int _xterm_hintbar
;
142 static int _permission_mode
;
143 static int _filetype_mode
;
152 #define B_2LEFT B_USER
153 #define B_2RIGHT B_USER + 1
154 #define B_PLUS B_USER + 2
155 #define B_MINUS B_USER + 3
157 static Dlg_head
*layout_dlg
;
159 static char *s_split_direction
[2] = {
163 WRadio
*radio_widget
;
170 } check_options
[] = {
171 { N_("&Xterm hintbar"), &xterm_hintbar
, 0, "h" },
172 { N_("h&Intbar visible"), &message_visible
, 0, "v" },
173 { N_("&Keybar visible"), &keybar_visible
, 0, "k" },
174 { N_("command &Prompt"), &command_prompt
, 0, "p" },
175 { N_("show &Mini status"), &show_mini_info
, 0, "m" },
176 { N_("menu&Bar visible"), &menubar_visible
, 0, "me" },
177 { N_("&Equal split"), &equal_split
, 0, "eq" },
178 { N_("pe&Rmissions"), &permission_mode
, 0, "pr" },
179 { N_("&File types"), &filetype_mode
, 0, "ft" },
183 static int first_width
, second_width
;
184 static char *layout_title
, *title1
, *title2
, *title3
, *output_lines_label
;
186 static WButton
*bleft_widget
, *bright_widget
;
188 static void _check_split (void)
190 if (_horizontal_split
){
192 _first_panel_size
= height
/ 2;
193 else if (_first_panel_size
< MINHEIGHT
)
194 _first_panel_size
= MINHEIGHT
;
195 else if (_first_panel_size
> height
- MINHEIGHT
)
196 _first_panel_size
= height
- MINHEIGHT
;
199 _first_panel_size
= COLS
/ 2;
200 else if (_first_panel_size
< MINWIDTH
)
201 _first_panel_size
= MINWIDTH
;
202 else if (_first_panel_size
> COLS
- MINWIDTH
)
203 _first_panel_size
= COLS
- MINWIDTH
;
207 static void update_split (void)
209 /* Check split has to be done before testing if it changed, since
210 it can change due to calling _check_split() as well*/
213 /* To avoid setting the cursor to the wrong place */
214 if ((old_first_panel_size
== _first_panel_size
) &&
215 (old_horizontal_split
== _horizontal_split
)){
219 old_first_panel_size
= _first_panel_size
;
220 old_horizontal_split
= _horizontal_split
;
222 attrset (COLOR_NORMAL
);
223 dlg_move (layout_dlg
, 6, 6);
224 printw ("%03d", _first_panel_size
);
225 dlg_move (layout_dlg
, 6, 18);
226 if (_horizontal_split
)
227 printw ("%03d", height
- _first_panel_size
);
229 printw ("%03d", COLS
- _first_panel_size
);
232 static int b2left_cback (int action
, void *data
)
235 /* Turn equal split off */
237 check_options
[6].widget
->state
= check_options
[6].widget
->state
& ~C_BOOL
;
238 dlg_select_widget (layout_dlg
, check_options
[6].widget
);
239 dlg_select_widget (layout_dlg
, bleft_widget
);
245 static int b2right_cback (int action
, void *data
)
248 /* Turn equal split off */
250 check_options
[6].widget
->state
= check_options
[6].widget
->state
& ~C_BOOL
;
251 dlg_select_widget (layout_dlg
, check_options
[6].widget
);
252 dlg_select_widget (layout_dlg
, bright_widget
);
258 static int bplus_cback (int action
, void *data
)
260 if (_output_lines
< 99)
265 static int bminus_cback (int action
, void *data
)
267 if (_output_lines
> 0)
272 static int layout_callback (struct Dlg_head
*h
, int Id
, int Msg
)
277 /*When repainting the whole dialog (e.g. with C-l) we have to
279 old_first_panel_size
= -1;
280 old_horizontal_split
= -1;
281 old_output_lines
= -1;
282 attrset (COLOR_NORMAL
);
284 draw_box (h
, 1, 2, h
->lines
- 2, h
->cols
- 4);
285 draw_box (h
, 2, 4, 6, first_width
);
286 draw_box (h
, 8, 4, 4, first_width
);
287 draw_box (h
, 2, 5 + first_width
, 10, second_width
);
289 attrset (COLOR_HOT_NORMAL
);
290 dlg_move (h
, 1, (h
->cols
- strlen(layout_title
))/2);
291 addstr (layout_title
);
296 dlg_move (h
, 2, 6 + first_width
);
302 if (old_output_lines
!= _output_lines
){
303 old_output_lines
= _output_lines
;
304 attrset (COLOR_NORMAL
);
305 dlg_move (h
, 9, 16 + first_width
);
306 addstr (output_lines_label
);
307 dlg_move (h
, 9, 10 + first_width
);
308 printw ("%02d", _output_lines
);
315 _filetype_mode
= check_options
[8].widget
->state
& C_BOOL
;
316 _permission_mode
= check_options
[7].widget
->state
& C_BOOL
;
318 _equal_split
= check_options
[6].widget
->state
& C_BOOL
;
320 _menubar_visible
= check_options
[5].widget
->state
& C_BOOL
;
321 _command_prompt
= check_options
[4].widget
->state
& C_BOOL
;
322 _keybar_visible
= check_options
[2].widget
->state
& C_BOOL
;
323 _message_visible
= check_options
[1].widget
->state
& C_BOOL
;
324 _xterm_hintbar
= check_options
[0].widget
->state
& C_BOOL
;
327 if (_output_lines
< 0)
329 height
= LINES
- _keybar_visible
- _command_prompt
-
330 _menubar_visible
- _output_lines
- _message_visible
;
331 if (_message_visible
&& _xterm_hintbar
&& xterm_flag
) height
++;
332 minimum
= MINHEIGHT
* (1 + _horizontal_split
);
333 if (height
< minimum
){
334 _output_lines
-= minimum
- height
;
338 height
= LINES
- _keybar_visible
- _command_prompt
-
339 _menubar_visible
- _output_lines
- _message_visible
;
340 if (_message_visible
&& _xterm_hintbar
&& xterm_flag
) height
++;
342 if (_horizontal_split
!= radio_widget
->sel
){
343 _horizontal_split
= radio_widget
->sel
;
344 if (_horizontal_split
)
345 _first_panel_size
= height
/ 2;
347 _first_panel_size
= COLS
/ 2;
351 if (old_output_lines
!= _output_lines
){
352 old_output_lines
= _output_lines
;
353 attrset (COLOR_NORMAL
);
354 dlg_move (h
, 9, 10 + first_width
);
355 printw ("%02d", _output_lines
);
366 static void init_layout (void)
368 static int i18n_layt_flag
= 0;
369 static int b1
, b2
, b3
;
370 int i
= sizeof (s_split_direction
) / sizeof(char*) ;
371 char* ok_button
= _("&Ok");
372 char* cancel_button
= _("&Cancel");
373 char* save_button
= _("&Save");
379 first_width
= 19; /* length of line with '<' '>' buttons */
381 layout_title
= _(" Layout ");
382 title1
= _(" Panel split ");
383 title2
= _(" Highlight... ");
384 title3
= _(" Other options ");
385 output_lines_label
= _("output lines");
389 s_split_direction
[i
] = _(s_split_direction
[i
]);
390 l1
= strlen (s_split_direction
[i
]) + 7;
391 if (l1
> first_width
)
395 for (i
= 0; i
<= 8; i
++)
397 check_options
[i
].text
= _(check_options
[i
].text
);
398 l1
= strlen (check_options
[i
].text
) + 7;
399 if (l1
> first_width
)
403 l1
= strlen (title1
) + 1;
404 if (l1
> first_width
)
407 l1
= strlen (title2
) + 1;
408 if (l1
> first_width
)
412 second_width
= strlen (title3
) + 1;
413 for (i
= 0; i
< 6; i
++)
415 check_options
[i
].text
= _(check_options
[i
].text
);
416 l1
= strlen (check_options
[i
].text
) + 7;
417 if (l1
> second_width
)
422 l1
= strlen (output_lines_label
) + 13;
423 if (l1
> second_width
)
429 * To be completely correct, one need to check if layout_title
430 * does not exceed dialog length and total length of 3 buttons
431 * allows their placement in one row. But assuming this dialog
432 * is wide enough, I don't include such a tests.
434 * Now the last thing to do - properly space buttons...
436 l1
= 11 + strlen (ok_button
) /* 14 - all brackets and inner space */
437 + strlen (save_button
) /* notice: it is 3 char less because */
438 + strlen (cancel_button
); /* of '&' char in button text */
440 i
= (first_width
+ second_width
- l1
) / 4;
442 b2
= b1
+ strlen(ok_button
) + i
+ 6;
443 b3
= b2
+ strlen(save_button
) + i
+ 4;
448 layout_dlg
= create_dlg (0, 0, 15, first_width
+ second_width
+ 9,
449 dialog_colors
, layout_callback
,
450 "[Layout]", "layout", DLG_CENTER
| DLG_GRID
);
452 x_set_dialog_title (layout_dlg
, _("Layout"));
454 add_widgetl (layout_dlg
,
455 button_new (BY
, b3
, B_CANCEL
, NORMAL_BUTTON
, cancel_button
, 0, 0, "c"),
457 add_widgetl (layout_dlg
,
458 button_new (BY
, b2
, B_EXIT
, NORMAL_BUTTON
, save_button
, 0, 0, "s"),
460 add_widgetl (layout_dlg
,
461 button_new (BY
, b1
, B_ENTER
, DEFPUSH_BUTTON
, ok_button
, 0, 0, "o"),
465 add_widget (layout_dlg
,
466 button_new (9, 12 + first_width
, B_MINUS
, NARROW_BUTTON
, "&-",
467 bminus_cback
, 0, NULL
));
468 add_widget (layout_dlg
,
469 button_new (9, 7 + first_width
, B_PLUS
, NARROW_BUTTON
, "&+",
470 bplus_cback
, 0, NULL
));
474 #define XTRACT(i) *check_options[i].variable, check_options[i].text, check_options[i].tkname
476 for (i
= 0; i
< 6; i
++){
477 check_options
[i
].widget
= check_new (8 - i
, 7 + first_width
, XTRACT(i
));
478 add_widgetl (layout_dlg
, check_options
[i
].widget
, XV_WLAY_BELOWCLOSE
);
481 add_widgetl (layout_dlg
, label_new (2, 7 + first_width
, _("Other options"), "oo"),
483 add_widgetl (layout_dlg
, label_new (8, 5, _("Highlight..."), "hl"),
485 add_widgetl (layout_dlg
, label_new (2, 5, _("Panel split"), "ps"),
488 check_options
[8].widget
= check_new (10, 6, XTRACT(8));
489 add_widgetl (layout_dlg
, check_options
[8].widget
, XV_WLAY_BELOWCLOSE
);
490 check_options
[7].widget
= check_new (9, 6, XTRACT(7));
491 add_widgetl (layout_dlg
, check_options
[7].widget
, XV_WLAY_BELOWCLOSE
);
493 _filetype_mode
= filetype_mode
;
494 _permission_mode
= permission_mode
;
495 _equal_split
= equal_split
;
496 _menubar_visible
= menubar_visible
;
497 _command_prompt
= command_prompt
;
498 _keybar_visible
= keybar_visible
;
499 _message_visible
= message_visible
;
500 _xterm_hintbar
= xterm_hintbar
;
502 bright_widget
= button_new(6, 15, B_2RIGHT
, NARROW_BUTTON
, "&>", b2right_cback
, 0, ">");
503 add_widgetl (layout_dlg
, bright_widget
, XV_WLAY_RIGHTOF
);
504 bleft_widget
= button_new (6, 9, B_2LEFT
, NARROW_BUTTON
, "&<", b2left_cback
, 0, "<");
505 add_widgetl (layout_dlg
, bleft_widget
, XV_WLAY_RIGHTOF
);
506 check_options
[6].widget
= check_new (5, 6, XTRACT(6));
508 old_first_panel_size
= -1;
509 old_horizontal_split
= -1;
510 old_output_lines
= -1;
512 _first_panel_size
= first_panel_size
;
513 _output_lines
= output_lines
;
515 add_widget (layout_dlg
, check_options
[6].widget
);
516 radio_widget
= radio_new (3, 6, 2, s_split_direction
, 1, "r");
517 add_widget (layout_dlg
, radio_widget
);
518 radio_widget
->sel
= horizontal_split
;
522 void layout_change (void)
525 layout_do_change
= 0;
527 /* re-init the menu, because perhaps there was a change in the way
528 how the panel are split (horizontal/vertical). */
531 menubar_arrange(the_menubar
);
535 void layout_cmd (void)
541 run_dlg (layout_dlg
);
542 result
= layout_dlg
->ret_value
;
544 if (result
== B_ENTER
|| result
== B_EXIT
){
545 for (i
= 0; check_options
[i
].text
; i
++)
546 if (check_options
[i
].widget
)
547 *check_options
[i
].variable
= check_options
[i
].widget
->state
& C_BOOL
;
549 horizontal_split
= radio_widget
->sel
;
550 first_panel_size
= _first_panel_size
;
551 output_lines
= _output_lines
;
552 layout_do_change
= 1;
555 if (result
== B_EXIT
){
560 destroy_dlg (layout_dlg
);
561 if (layout_do_change
)
565 static void check_split (void)
567 if (horizontal_split
){
569 first_panel_size
= height
/ 2;
570 else if (first_panel_size
< MINHEIGHT
)
571 first_panel_size
= MINHEIGHT
;
572 else if (first_panel_size
> height
- MINHEIGHT
)
573 first_panel_size
= height
- MINHEIGHT
;
576 first_panel_size
= COLS
/ 2;
577 else if (first_panel_size
< MINWIDTH
)
578 first_panel_size
= MINWIDTH
;
579 else if (first_panel_size
> COLS
- MINWIDTH
)
580 first_panel_size
= COLS
- MINWIDTH
;
584 int panel_event (Gpm_Event
*event
, WPanel
*panel
);
585 int menu_bar_event (Gpm_Event
*event
, void *);
592 extern int force_ugly_line_drawing
;
593 extern int SLtt_Has_Alt_Charset
;
594 SLtt_get_terminfo ();
596 if (force_ugly_line_drawing
)
597 SLtt_Has_Alt_Charset
= 0;
602 keypad (stdscr
, TRUE
);
603 nodelay (stdscr
, FALSE
);
606 void init_curses (void)
609 if (!status_using_ncurses
)
613 keypad (stdscr
, TRUE
);
614 nodelay (stdscr
, FALSE
);
617 #endif /* ! HAVE_SLANG */
620 if (!(quit
& SUBSHELL_EXIT
))
626 keypad (stdscr
, FALSE
);
637 void 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 Widget
*w
= panels
[0].widget
;
652 winput_set_origin (&cmdline
->input
, 0, 60);
654 /* Only needed by the startup code */
655 if (panels
[0].type
== view_listing
){
656 x_panel_set_size (0);
659 if (panels
[1].type
== view_listing
){
660 x_panel_set_size (1);
672 void setup_panels (void)
675 int promptl
; /* the prompt len */
679 if (output_lines
< 0)
681 height
= LINES
- keybar_visible
- command_prompt
- menubar_visible
682 - output_lines
- message_visible
;
683 if (message_visible
&& xterm_hintbar
&& xterm_flag
) height
++;
684 minimum
= MINHEIGHT
* (1 + horizontal_split
);
685 if (height
< minimum
){
686 output_lines
-= minimum
- height
;
690 height
= LINES
- menubar_visible
- command_prompt
-
691 keybar_visible
- message_visible
;
692 if (message_visible
&& xterm_hintbar
&& xterm_flag
) height
++;
695 start_y
= menubar_visible
;
697 /* The column computing is defered until panel_do_cols */
698 if (horizontal_split
){
699 widget_set_size (panels
[0].widget
, start_y
, 0,
700 first_panel_size
, 0);
702 widget_set_size (panels
[1].widget
, start_y
+first_panel_size
, 0,
703 height
-first_panel_size
, 0);
705 int first_x
= first_panel_size
;
707 widget_set_size (panels
[0].widget
, start_y
, 0,
710 widget_set_size (panels
[1].widget
, start_y
, first_x
,
717 promptl
= strlen (prompt
);
719 widget_set_size (&the_menubar
->widget
, 0, 0, 1, COLS
);
721 if (command_prompt
) {
722 widget_set_size (&cmdline
->input
.widget
,
723 LINES
-1-keybar_visible
, promptl
,
724 1, COLS
-promptl
-(keybar_visible
? 0 : 1));
725 winput_set_origin (&cmdline
->input
, promptl
, COLS
-promptl
-(keybar_visible
? 0 : 1));
726 widget_set_size (&the_prompt
->widget
,
727 LINES
-1-keybar_visible
, 0,
730 widget_set_size (&cmdline
->input
.widget
, 0, 0, 0, 0);
731 winput_set_origin (&cmdline
->input
, 0, 0);
732 widget_set_size (&the_prompt
->widget
, LINES
, COLS
, 0, 0);
735 widget_set_size (&the_bar
->widget
, LINES
-1, 0, 1, COLS
);
736 the_bar
->visible
= keybar_visible
;
739 if (console_flag
&& output_lines
){
740 output_start_y
= LINES
-command_prompt
-keybar_visible
-
742 show_console_contents (output_start_y
,
743 LINES
-output_lines
-keybar_visible
-1,
744 LINES
-keybar_visible
-1);
746 if (message_visible
&& (!xterm_hintbar
|| !xterm_flag
))
747 widget_set_size (&the_hint
->widget
, height
+start_y
, 0, 1,COLS
);
749 widget_set_size (&the_hint
->widget
, 0, 0, 0, 0);
755 void flag_winch (int dummy
)
760 void edit_adjust_size (Dlg_head
* h
);
762 #ifdef PORT_NEEDS_CHANGE_SCREEN_SIZE
763 void low_level_change_screen_size (void)
765 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
766 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
767 struct winsize winsz
;
769 winsz
.ws_col
= winsz
.ws_row
= 0;
770 /* Ioctl on the STDIN_FILENO */
771 ioctl (0, TIOCGWINSZ
, &winsz
);
772 if (winsz
.ws_col
&& winsz
.ws_row
){
773 #if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
774 resizeterm(winsz
.ws_row
, winsz
.ws_col
);
775 clearok(stdscr
,TRUE
); /* FIXME: sigwinch's should use a semaphore! */
778 LINES
= winsz
.ws_row
;
780 #ifdef HAVE_SUBSHELL_SUPPORT
784 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
785 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
788 void change_screen_size (void)
790 #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
791 #if defined TIOCGWINSZ && !defined SCO_FLAVOR
792 extern Dlg_head
*view_dlg
;
793 extern Dlg_head
*edit_dlg
;
795 #ifndef NCURSES_VERSION
799 low_level_change_screen_size ();
801 #ifndef NCURSES_VERSION
802 /* XSI Curses spec states that portable applications shall not invoke
803 * initscr() more than once. This kludge could be done within the scope
804 * of the specification by using endwin followed by a refresh (in fact,
805 * more than one curses implementation does this); it is guaranteed to work
811 if (current_dlg
== view_dlg
)
812 view_adjust_size (view_dlg
);
813 #ifdef USE_INTERNAL_EDIT
814 if (current_dlg
== edit_dlg
)
815 edit_adjust_size (edit_dlg
);
818 #ifdef RESIZABLE_MENUBAR
819 menubar_arrange(the_menubar
);
822 /* Now, force the redraw */
825 #endif /* TIOCGWINSZ && !SCO_FLAVOR */
826 #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
832 static int ok_to_refresh
= 1;
834 void use_dash (int flag
)
842 void set_hintbar(char *str
)
845 if (xterm_flag
&& xterm_hintbar
) {
846 fprintf (stderr
, "\33]0;mc - %s\7", str
);
850 label_set_text (the_hint
, str
);
851 if (ok_to_refresh
> 0)
856 void print_vfs_message(char *msg
, ...)
862 vsprintf(str
, msg
, ap
);
864 if (midnight_shutdown
|| !the_hint
|| !the_hint
->widget
.parent
)
867 if (message_visible
|| (xterm_flag
&& xterm_hintbar
)) {
872 void rotate_dash (void)
875 static char rotating_dash
[] = "|/-\\";
878 if (!nice_rotating_dash
|| (ok_to_refresh
<= 0))
881 if (pos
>= sizeof (rotating_dash
)-1)
884 addch (rotating_dash
[pos
]);
890 void remove_dash (void)
893 if (!nice_rotating_dash
)
896 /* Currently, it's much nicer with the CPU to do this instead of
899 I should implement a routine called invalidate_region that would
900 send a draw message only to the affected views. But for now
909 char *get_nth_panel_name (int num
)
911 static char buffer
[20];
914 return "New Left Panel";
916 return "New Right Panel";
918 sprintf (buffer
, "%ith Panel", num
);
923 /* I wonder if I should start to use the folding mode than Dugan uses */
925 /* This is the centralized managing of the panel display types */
926 /* This routine takes care of destroying and creating new widgets */
927 /* Please note that it could manage MAX_VIEWS, not just left and right */
928 /* Currently nothing in the code takes advantage of this and has hard- */
929 /* coded values for two panels only */
931 /* Set the num-th panel to the view type: type */
932 /* This routine also keeps at least one WPanel object in the screen */
933 /* since a lot of routines depend on the current_panel variable */
934 void set_display_type (int num
, int type
)
936 int x
, y
, cols
, lines
;
937 int the_other
; /* Index to the other panel */
938 char *file_name
= 0; /* For Quick view */
939 Widget
*new_widget
, *old_widget
;
940 WPanel
*the_other_panel
;
942 x
=y
= cols
= lines
= 0;
944 if (num
>= MAX_VIEWS
){
945 fprintf (stderr
, "Could not allocate more that %d views\n", MAX_VIEWS
);
949 /* Check that we will have a WPanel * at least */
951 if (type
!= view_listing
){
952 the_other
= num
== 0 ? 1 : 0;
954 if (panels
[the_other
].type
!= view_listing
)
960 if (panels
[num
].widget
){
961 Widget
*w
= panels
[num
].widget
;
962 WPanel
*panel
= (WPanel
*) panels
[num
].widget
;
968 old_widget
= panels
[num
].widget
;
970 if (panels
[num
].type
== view_listing
){
971 if (panel
->frame_size
== frame_full
&& type
!= view_listing
){
972 cols
= COLS
- first_panel_size
;
974 x
= first_panel_size
;
978 tk_evalf ("container_clean %s", panel
->widget
.wcontainer
);
986 new_widget
= (Widget
*) panel_new (get_nth_panel_name (num
));
990 new_widget
= (Widget
*) info_new ();
995 new_widget
= (Widget
*) tree_new (1, 0, 0, 0, 0);
999 new_widget
= (Widget
*) view_new (0, 0, 0, 0, 1);
1000 the_other_panel
= (WPanel
*) panels
[the_other
].widget
;
1001 if (the_other_panel
)
1003 the_other_panel
->dir
.list
[the_other_panel
->selected
].fname
;
1007 view_init ((WView
*) new_widget
, 0, file_name
, 0);
1010 panels
[num
].type
= type
;
1011 panels
[num
].widget
= (Widget
*) new_widget
;
1013 /* We set the same size the old widget had */
1014 widget_set_size ((Widget
*) new_widget
, y
, x
, lines
, cols
);
1016 /* We wanna the new widget at the same position */
1017 /* XView sets wcontainer to !0 <- Not XView, but we, when we create it */
1018 /* Ok, the XView support code does it */
1019 if (old_widget
&& old_widget
->wcontainer
){
1020 new_widget
->wcontainer
= old_widget
->wcontainer
;
1021 new_widget
->area
= old_widget
->area
;
1024 /* We use replace to keep the circular list of the dialog in the */
1025 /* same state. Maybe we could just kill it and then replace it */
1026 if (midnight_dlg
&& old_widget
){
1027 dlg_replace_widget (midnight_dlg
, old_widget
, panels
[num
].widget
);
1029 if (type
== view_listing
){
1031 left_panel
= (WPanel
*) new_widget
;
1033 right_panel
= (WPanel
*) new_widget
;
1036 if (type
== view_tree
)
1037 the_tree
= (WTree
*) new_widget
;
1039 /* Prevent current_panel's value from becoming invalid.
1040 * It's just a quick hack to prevent segfaults. Comment out and
1042 * - select left panel
1043 * - invoke menue left/tree
1044 * - as long as you stay in the left panel almost everything that uses
1045 * cpanel causes segfault, e.g. C-Enter, C-x c, ...
1048 if (type
!= view_listing
)
1049 if (cpanel
== (WPanel
*) old_widget
)
1050 current_panel
= num
== 0 ? right_panel
: left_panel
;
1054 /* This routine is deeply sticked to the two panels idea.
1055 What should it do in more panels. ANSWER - don't use it
1056 in any multiple panels environment. */
1062 WPanel
*panel1
, *panel2
;
1066 #ifdef HAVE_PORTABLE_TOKEN_PASTING
1067 #define panelswap(e) panel.##e = panel1->##e; panel1->##e = panel2->##e; panel2->##e = panel.##e;
1068 #define panelswapstr(e) strcpy (panel.##e, panel1->##e); strcpy (panel1->##e, panel2->##e); strcpy (panel2->##e, panel.##e);
1070 #define panelswap(e) panel./**/e = panel1->/**/e; panel1->/**/e = panel2->/**/e; panel2->/**/e = panel./**/e;
1071 #define panelswapstr(e) strcpy (panel./**/e, panel1->/**/e); strcpy (panel1->/**/e, panel2->/**/e); strcpy (panel2->/**/e, panel./**/e);
1075 #define panelswap(x) panel. x = panel1-> x; panel1-> x = panel2-> x; panel2-> x = panel. x;
1077 #define panelswapstr(e) strcpy (panel. e, panel1-> e); \
1078 strcpy (panel1-> e, panel2-> e); \
1079 strcpy (panel2-> e, panel. e);
1080 panel1
= (WPanel
*) panels
[0].widget
;
1081 panel2
= (WPanel
*) panels
[1].widget
;
1082 if (panels
[0].type
== view_listing
&& panels
[1].type
== view_listing
) {
1083 /* Change everything except format/sort/panel_name etc. */
1090 panelswap (dirs_marked
);
1092 panelswap (top_file
);
1093 panelswap (selected
);
1094 panelswap (is_panelized
);
1095 panelswap (dir_stat
);
1097 panel1
->searching
= 0;
1098 panel2
->searching
= 0;
1099 if (cpanel
== panel1
)
1100 current_panel
= panel2
;
1102 current_panel
= panel1
;
1103 if (midnight_dlg
->current
->widget
== panels
[0].widget
)
1104 dlg_select_widget (midnight_dlg
, (void *) panels
[1].widget
);
1105 else if (midnight_dlg
->current
->widget
== panels
[1].widget
)
1106 dlg_select_widget (midnight_dlg
, (void *) panels
[0].widget
);
1110 tmp_panel
=right_panel
;
1111 right_panel
=left_panel
;
1112 left_panel
=tmp_panel
;
1114 if (panels
[0].type
== view_listing
) {
1115 if (!strcmp (panel1
->panel_name
, get_nth_panel_name (0))) {
1116 free (panel1
->panel_name
);
1117 panel1
->panel_name
= strdup (get_nth_panel_name (1));
1120 if (panels
[1].type
== view_listing
) {
1121 if (!strcmp (panel2
->panel_name
, get_nth_panel_name (1))) {
1122 free (panel2
->panel_name
);
1123 panel2
->panel_name
= strdup (get_nth_panel_name (0));
1127 tmp
.x
= panels
[0].widget
->x
;
1128 tmp
.y
= panels
[0].widget
->y
;
1129 tmp
.cols
= panels
[0].widget
->cols
;
1130 tmp
.lines
= panels
[0].widget
->lines
;
1132 panels
[0].widget
->x
= panels
[1].widget
->x
;
1133 panels
[0].widget
->y
= panels
[1].widget
->y
;
1134 panels
[0].widget
->cols
= panels
[1].widget
->cols
;
1135 panels
[0].widget
->lines
= panels
[1].widget
->lines
;
1137 panels
[1].widget
->x
= tmp
.x
;
1138 panels
[1].widget
->y
= tmp
.y
;
1139 panels
[1].widget
->cols
= tmp
.cols
;
1140 panels
[1].widget
->lines
= tmp
.lines
;
1142 tmp_widget
= panels
[0].widget
;
1143 panels
[0].widget
= panels
[1].widget
;
1144 panels
[1].widget
= tmp_widget
;
1145 tmp_type
= panels
[0].type
;
1146 panels
[0].type
= panels
[1].type
;
1147 panels
[1].type
= tmp_type
;
1152 int get_display_type (int index
)
1154 return panels
[index
].type
;
1157 Widget
*get_panel_widget (int index
)
1159 return panels
[index
].widget
;
1162 int get_current_index (void)
1164 if (panels
[0].widget
== ((Widget
*) cpanel
))
1170 int get_other_index (void)
1172 return !get_current_index ();
1175 /* Returns the view type for the current panel/view */
1176 int get_current_type (void)
1178 if (panels
[0].widget
== (Widget
*) cpanel
)
1179 return panels
[0].type
;
1181 return panels
[1].type
;
1184 /* Returns the view type of the unselected panel */
1185 int get_other_type (void)
1187 if (panels
[0].widget
== (Widget
*) cpanel
)
1188 return panels
[1].type
;
1190 return panels
[0].type
;