-
Notifications
You must be signed in to change notification settings - Fork 512
/
layout.c
1603 lines (1295 loc) · 46.3 KB
/
layout.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Panel layout module for the Midnight Commander
Copyright (C) 1995-2024
Free Software Foundation, Inc.
Written by:
Janne Kukonlehto, 1995
Miguel de Icaza, 1995
Andrew Borodin <aborodin@vmail.ru>, 2011-2022
Slava Zanko <slavazanko@gmail.com>, 2013
Avi Kelman <patcherton.fixesthings@gmail.com>, 2013
This file is part of the Midnight Commander.
The Midnight Commander is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
The Midnight Commander is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file layout.c
* \brief Source: panel layout module
*/
#include <config.h>
#include <pwd.h> /* for username in xterm title */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "lib/global.h"
#include "lib/tty/tty.h"
#include "lib/skin.h"
#include "lib/tty/key.h"
#include "lib/tty/mouse.h"
#include "lib/mcconfig.h"
#include "lib/vfs/vfs.h" /* vfs_get_cwd () */
#include "lib/strutil.h"
#include "lib/widget.h"
#include "lib/event.h"
#include "lib/util.h" /* mc_time_elapsed() */
#include "src/consaver/cons.saver.h"
#include "src/viewer/mcviewer.h" /* The view widget */
#include "src/setup.h"
#ifdef ENABLE_SUBSHELL
#include "src/subshell/subshell.h"
#endif
#include "command.h"
#include "filemanager.h"
#include "tree.h"
/* Needed for the extern declarations of integer parameters */
#include "dir.h"
#include "layout.h"
#include "info.h" /* The Info widget */
/*** global variables ****************************************************************************/
panels_layout_t panels_layout = {
/* Set if the panels are split horizontally */
.horizontal_split = FALSE,
/* vertical split */
.vertical_equal = TRUE,
.left_panel_size = 0,
/* horizontal split */
.horizontal_equal = TRUE,
.top_panel_size = 0
};
/* Controls the display of the rotating dash on the verbose mode */
gboolean nice_rotating_dash = TRUE;
/* The number of output lines shown (if available) */
int output_lines = 0;
/* Set if the command prompt is to be displayed */
gboolean command_prompt = TRUE;
/* Set if the main menu is visible */
gboolean menubar_visible = TRUE;
/* Set to show current working dir in xterm window title */
gboolean xterm_title = TRUE;
/* Set to show free space on device assigned to current directory */
gboolean free_space = TRUE;
/* The starting line for the output of the subprogram */
int output_start_y = 0;
int ok_to_refresh = 1;
/*** file scope macro definitions ****************************************************************/
/* The maximum number of views managed by the create_panel routine */
/* Must be at least two (for current and other). Please note that until */
/* Janne gets around this, we will only manage two of them :-) */
#define MAX_VIEWS 2
/* Width 12 for a wee Quick (Hex) View */
#define MINWIDTH 12
#define MINHEIGHT 5
#define B_2LEFT B_USER
#define B_2RIGHT (B_USER + 1)
#define B_PLUS (B_USER + 2)
#define B_MINUS (B_USER + 3)
#define LAYOUT_OPTIONS_COUNT G_N_ELEMENTS (check_options)
/*** file scope type declarations ****************************************************************/
typedef struct
{
gboolean menubar_visible;
gboolean command_prompt;
gboolean keybar_visible;
gboolean message_visible;
gboolean xterm_title;
gboolean free_space;
int output_lines;
} layout_t;
/*** forward declarations (file scope functions) *************************************************/
/*** file scope variables ************************************************************************/
static struct
{
panel_view_mode_t type;
Widget *widget;
char *last_saved_dir; /* last view_list working directory */
} panels[MAX_VIEWS] =
{
/* *INDENT-OFF* */
/* init MAX_VIEWS items */
{ view_listing, NULL, NULL},
{ view_listing, NULL, NULL}
/* *INDENT-ON* */
};
static layout_t old_layout;
static panels_layout_t old_panels_layout;
static gboolean equal_split;
static int _output_lines;
static int height;
static WRadio *radio_widget;
static struct
{
const char *text;
gboolean *variable;
WCheck *widget;
} check_options[] =
{
/* *INDENT-OFF* */
{ N_("&Equal split"), &equal_split, NULL },
{ N_("&Menubar visible"), &menubar_visible, NULL },
{ N_("Command &prompt"), &command_prompt, NULL },
{ N_("&Keybar visible"), &mc_global.keybar_visible, NULL },
{ N_("H&intbar visible"), &mc_global.message_visible, NULL },
{ N_("&XTerm window title"), &xterm_title, NULL },
{ N_("&Show free space"), &free_space, NULL }
/* *INDENT-ON* */
};
static const char *output_lines_label = NULL;
static int output_lines_label_len;
static WButton *bleft_widget, *bright_widget;
/* --------------------------------------------------------------------------------------------- */
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/* don't use max() macro to avoid double call of str_term_width1() in widget width calculation */
#undef max
static int
max (int a, int b)
{
return a > b ? a : b;
}
/* --------------------------------------------------------------------------------------------- */
static void
check_split (panels_layout_t * layout)
{
if (layout->horizontal_split)
{
if (layout->horizontal_equal)
layout->top_panel_size = height / 2;
else if (layout->top_panel_size < MINHEIGHT)
layout->top_panel_size = MINHEIGHT;
else if (layout->top_panel_size > height - MINHEIGHT)
layout->top_panel_size = height - MINHEIGHT;
}
else
{
int md_cols = CONST_WIDGET (filemanager)->rect.cols;
if (layout->vertical_equal)
layout->left_panel_size = md_cols / 2;
else if (layout->left_panel_size < MINWIDTH)
layout->left_panel_size = MINWIDTH;
else if (layout->left_panel_size > md_cols - MINWIDTH)
layout->left_panel_size = md_cols - MINWIDTH;
}
}
/* --------------------------------------------------------------------------------------------- */
static void
update_split (const WDialog * h)
{
/* Check split has to be done before testing if it changed, since
it can change due to calling check_split() as well */
check_split (&panels_layout);
if (panels_layout.horizontal_split)
check_options[0].widget->state = panels_layout.horizontal_equal;
else
check_options[0].widget->state = panels_layout.vertical_equal;
widget_draw (WIDGET (check_options[0].widget));
tty_setcolor (check_options[0].widget->state ? DISABLED_COLOR : COLOR_NORMAL);
widget_gotoyx (h, 6, 5);
if (panels_layout.horizontal_split)
tty_printf ("%03d", panels_layout.top_panel_size);
else
tty_printf ("%03d", panels_layout.left_panel_size);
widget_gotoyx (h, 6, 17);
if (panels_layout.horizontal_split)
tty_printf ("%03d", height - panels_layout.top_panel_size);
else
tty_printf ("%03d", CONST_WIDGET (filemanager)->rect.cols - panels_layout.left_panel_size);
widget_gotoyx (h, 6, 12);
tty_print_char ('=');
}
/* --------------------------------------------------------------------------------------------- */
static int
b_left_right_cback (WButton * button, int action)
{
(void) action;
if (button == bright_widget)
{
if (panels_layout.horizontal_split)
panels_layout.top_panel_size++;
else
panels_layout.left_panel_size++;
}
else
{
if (panels_layout.horizontal_split)
panels_layout.top_panel_size--;
else
panels_layout.left_panel_size--;
}
update_split (DIALOG (WIDGET (button)->owner));
layout_change ();
do_refresh ();
return 0;
}
/* --------------------------------------------------------------------------------------------- */
static int
bplus_cback (WButton * button, int action)
{
(void) button;
(void) action;
if (_output_lines < 99)
_output_lines++;
return 0;
}
/* --------------------------------------------------------------------------------------------- */
static int
bminus_cback (WButton * button, int action)
{
(void) button;
(void) action;
if (_output_lines > 0)
_output_lines--;
return 0;
}
/* --------------------------------------------------------------------------------------------- */
static cb_ret_t
layout_bg_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
switch (msg)
{
case MSG_DRAW:
frame_callback (w, NULL, MSG_DRAW, 0, NULL);
old_layout.output_lines = -1;
update_split (DIALOG (w->owner));
if (old_layout.output_lines != _output_lines)
{
old_layout.output_lines = _output_lines;
tty_setcolor (mc_global.tty.console_flag != '\0' ? COLOR_NORMAL : DISABLED_COLOR);
widget_gotoyx (w, 9, 5);
tty_print_string (output_lines_label);
widget_gotoyx (w, 9, 5 + 3 + output_lines_label_len);
tty_printf ("%02d", _output_lines);
}
return MSG_HANDLED;
default:
return frame_callback (w, sender, msg, parm, data);
}
}
/* --------------------------------------------------------------------------------------------- */
static cb_ret_t
layout_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
WDialog *h = DIALOG (w);
switch (msg)
{
case MSG_POST_KEY:
{
const Widget *mw = CONST_WIDGET (filemanager);
gboolean _menubar_visible, _command_prompt, _keybar_visible, _message_visible;
_menubar_visible = check_options[1].widget->state;
_command_prompt = check_options[2].widget->state;
_keybar_visible = check_options[3].widget->state;
_message_visible = check_options[4].widget->state;
if (mc_global.tty.console_flag == '\0')
height =
mw->rect.lines - (_keybar_visible ? 1 : 0) - (_command_prompt ? 1 : 0) -
(_menubar_visible ? 1 : 0) - _output_lines - (_message_visible ? 1 : 0);
else
{
int minimum;
if (_output_lines < 0)
_output_lines = 0;
height =
mw->rect.lines - (_keybar_visible ? 1 : 0) - (_command_prompt ? 1 : 0) -
(_menubar_visible ? 1 : 0) - _output_lines - (_message_visible ? 1 : 0);
minimum = MINHEIGHT * (1 + (panels_layout.horizontal_split ? 1 : 0));
if (height < minimum)
{
_output_lines -= minimum - height;
height = minimum;
}
}
if (old_layout.output_lines != _output_lines)
{
old_layout.output_lines = _output_lines;
tty_setcolor (mc_global.tty.console_flag != '\0' ? COLOR_NORMAL : DISABLED_COLOR);
widget_gotoyx (h, 9, 5 + 3 + output_lines_label_len);
tty_printf ("%02d", _output_lines);
}
}
return MSG_HANDLED;
case MSG_NOTIFY:
if (sender == WIDGET (radio_widget))
{
if ((panels_layout.horizontal_split ? 1 : 0) == radio_widget->sel)
update_split (h);
else
{
int eq;
panels_layout.horizontal_split = radio_widget->sel != 0;
if (panels_layout.horizontal_split)
{
eq = panels_layout.horizontal_equal;
if (eq)
panels_layout.top_panel_size = height / 2;
}
else
{
eq = panels_layout.vertical_equal;
if (eq)
panels_layout.left_panel_size = CONST_WIDGET (filemanager)->rect.cols / 2;
}
widget_disable (WIDGET (bleft_widget), eq);
widget_disable (WIDGET (bright_widget), eq);
update_split (h);
layout_change ();
do_refresh ();
}
return MSG_HANDLED;
}
if (sender == WIDGET (check_options[0].widget))
{
gboolean eq;
if (panels_layout.horizontal_split)
{
panels_layout.horizontal_equal = check_options[0].widget->state;
eq = panels_layout.horizontal_equal;
}
else
{
panels_layout.vertical_equal = check_options[0].widget->state;
eq = panels_layout.vertical_equal;
}
widget_disable (WIDGET (bleft_widget), eq);
widget_disable (WIDGET (bright_widget), eq);
update_split (h);
layout_change ();
do_refresh ();
return MSG_HANDLED;
}
{
gboolean ok = TRUE;
if (sender == WIDGET (check_options[1].widget))
menubar_visible = check_options[1].widget->state;
else if (sender == WIDGET (check_options[2].widget))
command_prompt = check_options[2].widget->state;
else if (sender == WIDGET (check_options[3].widget))
mc_global.keybar_visible = check_options[3].widget->state;
else if (sender == WIDGET (check_options[4].widget))
mc_global.message_visible = check_options[4].widget->state;
else if (sender == WIDGET (check_options[5].widget))
xterm_title = check_options[5].widget->state;
else if (sender == WIDGET (check_options[6].widget))
free_space = check_options[6].widget->state;
else
ok = FALSE;
if (ok)
{
update_split (h);
layout_change ();
do_refresh ();
return MSG_HANDLED;
}
}
return MSG_NOT_HANDLED;
default:
return dlg_default_callback (w, sender, msg, parm, data);
}
}
/* --------------------------------------------------------------------------------------------- */
static WDialog *
layout_dlg_create (void)
{
WDialog *layout_dlg;
WGroup *g;
int l1 = 0, width;
int b1, b2, b;
size_t i;
const char *title1 = N_("Panel split");
const char *title2 = N_("Console output");
const char *title3 = N_("Other options");
const char *s_split_direction[2] = {
N_("&Vertical"),
N_("&Horizontal")
};
const char *ok_button = N_("&OK");
const char *cancel_button = N_("&Cancel");
output_lines_label = _("Output lines:");
#ifdef ENABLE_NLS
{
static gboolean i18n = FALSE;
title1 = _(title1);
title2 = _(title2);
title3 = _(title3);
i = G_N_ELEMENTS (s_split_direction);
while (i-- != 0)
s_split_direction[i] = _(s_split_direction[i]);
if (!i18n)
{
for (i = 0; i < (size_t) LAYOUT_OPTIONS_COUNT; i++)
check_options[i].text = _(check_options[i].text);
i18n = TRUE;
}
ok_button = _(ok_button);
cancel_button = _(cancel_button);
}
#endif
/* radiobuttons */
i = G_N_ELEMENTS (s_split_direction);
while (i-- != 0)
l1 = max (l1, str_term_width1 (s_split_direction[i]) + 7);
/* checkboxes */
for (i = 0; i < (size_t) LAYOUT_OPTIONS_COUNT; i++)
l1 = max (l1, str_term_width1 (check_options[i].text) + 7);
/* groupboxes */
l1 = max (l1, str_term_width1 (title1) + 4);
l1 = max (l1, str_term_width1 (title2) + 4);
l1 = max (l1, str_term_width1 (title3) + 4);
/* label + "+"/"-" buttons */
output_lines_label_len = str_term_width1 (output_lines_label);
l1 = max (l1, output_lines_label_len + 12);
/* buttons */
b1 = str_term_width1 (ok_button) + 5; /* default button */
b2 = str_term_width1 (cancel_button) + 3;
b = b1 + b2 + 1;
/* dialog width */
width = max (l1 * 2 + 7, b);
layout_dlg =
dlg_create (TRUE, 0, 0, 15, width, WPOS_CENTER, FALSE, dialog_colors, layout_callback, NULL,
"[Layout]", _("Layout"));
g = GROUP (layout_dlg);
/* draw background */
layout_dlg->bg->callback = layout_bg_callback;
#define XTRACT(i) (*check_options[i].variable != 0), check_options[i].text
/* "Panel split" groupbox */
group_add_widget (g, groupbox_new (2, 3, 6, l1, title1));
radio_widget = radio_new (3, 5, 2, s_split_direction);
radio_widget->sel = panels_layout.horizontal_split ? 1 : 0;
group_add_widget (g, radio_widget);
check_options[0].widget = check_new (5, 5, XTRACT (0));
group_add_widget (g, check_options[0].widget);
equal_split = panels_layout.horizontal_split ?
panels_layout.horizontal_equal : panels_layout.vertical_equal;
bleft_widget = button_new (6, 8, B_2LEFT, NARROW_BUTTON, "&<", b_left_right_cback);
widget_disable (WIDGET (bleft_widget), equal_split);
group_add_widget (g, bleft_widget);
bright_widget = button_new (6, 14, B_2RIGHT, NARROW_BUTTON, "&>", b_left_right_cback);
widget_disable (WIDGET (bright_widget), equal_split);
group_add_widget (g, bright_widget);
/* "Console output" groupbox */
{
widget_state_t disabled;
Widget *w;
disabled = mc_global.tty.console_flag != '\0' ? 0 : WST_DISABLED;
w = WIDGET (groupbox_new (8, 3, 3, l1, title2));
w->state |= disabled;
group_add_widget (g, w);
w = WIDGET (button_new (9, output_lines_label_len + 5, B_PLUS,
NARROW_BUTTON, "&+", bplus_cback));
w->state |= disabled;
group_add_widget (g, w);
w = WIDGET (button_new (9, output_lines_label_len + 5 + 5, B_MINUS,
NARROW_BUTTON, "&-", bminus_cback));
w->state |= disabled;
group_add_widget (g, w);
}
/* "Other options" groupbox */
group_add_widget (g, groupbox_new (2, 4 + l1, 9, l1, title3));
for (i = 1; i < (size_t) LAYOUT_OPTIONS_COUNT; i++)
{
check_options[i].widget = check_new (i + 2, 6 + l1, XTRACT (i));
group_add_widget (g, check_options[i].widget);
}
#undef XTRACT
group_add_widget (g, hline_new (11, -1, -1));
/* buttons */
group_add_widget (g, button_new (12, (width - b) / 2, B_ENTER, DEFPUSH_BUTTON, ok_button, 0));
group_add_widget (g,
button_new (12, (width - b) / 2 + b1 + 1, B_CANCEL, NORMAL_BUTTON,
cancel_button, 0));
widget_select (WIDGET (radio_widget));
return layout_dlg;
}
/* --------------------------------------------------------------------------------------------- */
static void
panel_do_cols (int idx)
{
if (get_panel_type (idx) == view_listing)
set_panel_formats (PANEL (panels[idx].widget));
else
panel_update_cols (panels[idx].widget, frame_half);
}
/* --------------------------------------------------------------------------------------------- */
/** Save current list_view widget directory into panel */
static Widget *
restore_into_right_dir_panel (int idx, gboolean last_was_panel, const WRect * r)
{
WPanel *new_widget;
const char *p_name;
p_name = get_nth_panel_name (idx);
if (last_was_panel)
{
vfs_path_t *saved_dir_vpath;
saved_dir_vpath = vfs_path_from_str (panels[idx].last_saved_dir);
new_widget = panel_sized_with_dir_new (p_name, r, saved_dir_vpath);
vfs_path_free (saved_dir_vpath, TRUE);
}
else
new_widget = panel_sized_new (p_name, r);
return WIDGET (new_widget);
}
/* --------------------------------------------------------------------------------------------- */
static void
layout_save (void)
{
old_layout.menubar_visible = menubar_visible;
old_layout.command_prompt = command_prompt;
old_layout.keybar_visible = mc_global.keybar_visible;
old_layout.message_visible = mc_global.message_visible;
old_layout.xterm_title = xterm_title;
old_layout.free_space = free_space;
old_layout.output_lines = -1;
_output_lines = output_lines;
old_panels_layout = panels_layout;
}
/* --------------------------------------------------------------------------------------------- */
static void
layout_restore (void)
{
menubar_visible = old_layout.menubar_visible;
command_prompt = old_layout.command_prompt;
mc_global.keybar_visible = old_layout.keybar_visible;
mc_global.message_visible = old_layout.message_visible;
xterm_title = old_layout.xterm_title;
free_space = old_layout.free_space;
output_lines = old_layout.output_lines;
panels_layout = old_panels_layout;
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
void
layout_change (void)
{
setup_panels ();
/* update the main menu, because perhaps there was a change in the way
how the panel are split (horizontal/vertical),
and a change of menu visibility. */
update_menu ();
load_hint (TRUE);
}
/* --------------------------------------------------------------------------------------------- */
void
layout_box (void)
{
WDialog *layout_dlg;
layout_save ();
layout_dlg = layout_dlg_create ();
if (dlg_run (layout_dlg) == B_ENTER)
{
size_t i;
for (i = 0; i < (size_t) LAYOUT_OPTIONS_COUNT; i++)
if (check_options[i].widget != NULL)
*check_options[i].variable = check_options[i].widget->state;
output_lines = _output_lines;
}
else
layout_restore ();
widget_destroy (WIDGET (layout_dlg));
layout_change ();
do_refresh ();
}
/* --------------------------------------------------------------------------------------------- */
void
panel_update_cols (Widget * widget, panel_display_t frame_size)
{
const Widget *mw = CONST_WIDGET (filemanager);
int cols, x;
/* don't touch panel if it is not in dialog yet */
/* if panel is not in dialog it is not in widgets list
and cannot be compared with get_panel_widget() result */
if (widget->owner == NULL)
return;
if (panels_layout.horizontal_split)
{
widget->rect.cols = mw->rect.cols;
return;
}
if (frame_size == frame_full)
{
cols = mw->rect.cols;
x = mw->rect.x;
}
else if (widget == get_panel_widget (0))
{
cols = panels_layout.left_panel_size;
x = mw->rect.x;
}
else
{
cols = mw->rect.cols - panels_layout.left_panel_size;
x = mw->rect.x + panels_layout.left_panel_size;
}
widget->rect.cols = cols;
widget->rect.x = x;
}
/* --------------------------------------------------------------------------------------------- */
void
setup_panels (void)
{
/* File manager screen layout:
*
* +---------------------------------------------------------------+
* | Menu bar |
* +-------------------------------+-------------------------------+
* | | |
* | | |
* | | |
* | | |
* | Left panel | Right panel |
* | | |
* | | |
* | | |
* | | |
* +-------------------------------+-------------------------------+
* | Hint (message) bar |
* +---------------------------------------------------------------+
* | |
* | Console content |
* | |
* +--------+------------------------------------------------------+
* | Prompt | Command line |
* | Key (button) bar |
* +--------+------------------------------------------------------+
*/
Widget *mw = WIDGET (filemanager);
const WRect *r = &CONST_WIDGET (mw)->rect;
int start_y;
gboolean active;
WRect rb;
active = widget_get_state (mw, WST_ACTIVE);
/* lock the group to avoid many redraws */
if (active)
widget_set_state (mw, WST_SUSPENDED, TRUE);
/* initial height of panels */
height =
r->lines - (menubar_visible ? 1 : 0) - (mc_global.message_visible ? 1 : 0) -
(command_prompt ? 1 : 0) - (mc_global.keybar_visible ? 1 : 0);
if (mc_global.tty.console_flag != '\0')
{
int minimum;
if (output_lines < 0)
output_lines = 0;
else
height -= output_lines;
minimum = MINHEIGHT * (1 + (panels_layout.horizontal_split ? 1 : 0));
if (height < minimum)
{
output_lines -= minimum - height;
height = minimum;
}
}
rb = *r;
rb.lines = 1;
widget_set_size_rect (WIDGET (the_menubar), &rb);
widget_set_visibility (WIDGET (the_menubar), menubar_visible);
check_split (&panels_layout);
start_y = r->y + (menubar_visible ? 1 : 0);
/* update columns first... */
panel_do_cols (0);
panel_do_cols (1);
/* ...then rows and origin */
if (panels_layout.horizontal_split)
{
widget_set_size (panels[0].widget, start_y, r->x, panels_layout.top_panel_size,
panels[0].widget->rect.cols);
widget_set_size (panels[1].widget, start_y + panels_layout.top_panel_size, r->x,
height - panels_layout.top_panel_size, panels[1].widget->rect.cols);
}
else
{
widget_set_size (panels[0].widget, start_y, r->x, height, panels[0].widget->rect.cols);
widget_set_size (panels[1].widget, start_y, panels[1].widget->rect.x, height,
panels[1].widget->rect.cols);
}
widget_set_size (WIDGET (the_hint), height + start_y, r->x, 1, r->cols);
widget_set_visibility (WIDGET (the_hint), mc_global.message_visible);
/* Output window */
if (mc_global.tty.console_flag != '\0' && output_lines != 0)
{
unsigned char end_line;
end_line = r->lines - (mc_global.keybar_visible ? 1 : 0) - 1;
output_start_y = end_line - (command_prompt ? 1 : 0) - output_lines + 1;
show_console_contents (output_start_y, end_line - output_lines, end_line);
}
if (command_prompt)
{
#ifdef ENABLE_SUBSHELL
if (!mc_global.tty.use_subshell || !do_load_prompt ())
#endif
setup_cmdline ();
}
else
{
/* make invisible */
widget_hide (WIDGET (cmdline));
widget_hide (WIDGET (the_prompt));
}
rb = *r;
rb.y = r->lines - 1;
rb.lines = 1;
widget_set_size_rect (WIDGET (the_bar), &rb);
widget_set_visibility (WIDGET (the_bar), mc_global.keybar_visible);
update_xterm_title_path ();
update_terminal_cwd ();
/* unlock */
if (active)
{
widget_set_state (mw, WST_ACTIVE, TRUE);
widget_draw (mw);
}
}
/* --------------------------------------------------------------------------------------------- */
void
panels_split_equal (void)
{
if (panels_layout.horizontal_split)
panels_layout.horizontal_equal = TRUE;
else
panels_layout.vertical_equal = TRUE;
layout_change ();
do_refresh ();
}
/* --------------------------------------------------------------------------------------------- */
void
panels_split_more (void)
{
if (panels_layout.horizontal_split)
{
panels_layout.horizontal_equal = FALSE;
panels_layout.top_panel_size++;
}
else
{
panels_layout.vertical_equal = FALSE;
panels_layout.left_panel_size++;
}
layout_change ();
}
/* --------------------------------------------------------------------------------------------- */
void
panels_split_less (void)
{
if (panels_layout.horizontal_split)
{
panels_layout.horizontal_equal = FALSE;
panels_layout.top_panel_size--;
}
else
{
panels_layout.vertical_equal = FALSE;
panels_layout.left_panel_size--;
}
layout_change ();
}
/* --------------------------------------------------------------------------------------------- */
void
setup_cmdline (void)
{
const Widget *mw = CONST_WIDGET (filemanager);
const WRect *r = &mw->rect;
int prompt_width;
int y;
char *tmp_prompt = (char *) mc_prompt;
if (!command_prompt)
return;
#ifdef ENABLE_SUBSHELL
if (mc_global.tty.use_subshell)
{
/* Workaround: avoid crash on FreeBSD (see ticket #4213 for details) */
if (subshell_prompt != NULL)
tmp_prompt = g_string_free (subshell_prompt, FALSE);
else
tmp_prompt = g_strdup (mc_prompt);
(void) strip_ctrl_codes (tmp_prompt);