fix include file case
[reactos.git] / rosapps / mc / src / screen.c
1 /* Panel managing.
2 Copyright (C) 1994, 1995 Miguel de Icaza.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 Written by: 1995 Miguel de Icaza
15 1997 Timur Bakeyev
16
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. */
20
21 #include <config.h>
22 #include "tty.h"
23 #include "fs.h"
24 #include <sys/param.h>
25 #include <string.h>
26 #include <stdlib.h> /* For malloc() and free() */
27 #include <stdio.h>
28 #include <errno.h>
29 #ifdef HAVE_UNISTD_H
30 # include <unistd.h> /* For chdir(), readlink() and getwd()/getcwd() */
31 #endif
32 #include "mem.h"
33 #include "mad.h"
34 #include "global.h"
35 #include "dir.h"
36 #include "util.h"
37 #include "panel.h"
38 #include "color.h"
39 #include "tree.h"
40 #include "win.h"
41 #include "main.h"
42 #include "ext.h" /* regexp_command */
43 #include "mouse.h" /* For Gpm_Event */
44 #include "cons.saver.h" /* For console_flag */
45 #include "layout.h" /* Most layout variables are here */
46 #include "dialog.h" /* for message (...) */
47 #include "cmd.h"
48 #include "key.h" /* XCTRL and ALT macros */
49 #include "setup.h" /* For loading/saving panel options */
50 #include "user.h"
51 #include "profile.h"
52 #include "widget.h"
53 #include "../vfs/vfs.h"
54 #include "../vfs/extfs.h"
55
56 #if defined(OS2_NT)
57 # include "drive.h"
58 #endif
59
60 #include "x.h"
61
62 /* "$Id$" */
63 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
64
65 /* If true, show the mini-info on the panel */
66 int show_mini_info = 1;
67
68 /* If true, then use stat() on the cwd to determine directory changes */
69 int fast_reload = 0;
70
71 /* If true, use some usability hacks by Torben */
72 int torben_fj_mode = 0;
73
74 /* If true, up/down keys scroll the pane listing by pages */
75 int panel_scroll_pages = 1;
76
77 /* If 1, we use permission hilighting */
78 int permission_mode = 0;
79
80 /* If 1 - then add per file type hilighting */
81 int filetype_mode = 1;
82
83
84 /* This gives abilitiy to determine colored user priveleges */
85 extern user_in_groups *current_user_gid;
86 extern uid_t current_user_uid;
87
88 /* If we have an info panel, this points to it */
89 WPanel *the_info_panel = 0;
90
91 /* The hook list for the select file function */
92 Hook *select_file_hook = 0;
93
94 static int panel_callback (Dlg_head *h, WPanel *p, int Msg, int Par);
95 int panel_event (Gpm_Event *event, WPanel *panel);
96
97 #ifndef PORT_HAS_PANEL_ADJUST_TOP_FILE
98 # define x_adjust_top_file(p)
99 #endif
100
101 #ifndef PORT_HAS_PANEL_RESET_SORT_LABELS
102 # define x_reset_sort_labels(x)
103 #endif
104
105 /* This macro extracts the number of available lines in a panel */
106 #ifndef PORT_HAS_LLINES
107 #define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
108 #else
109 #define llines(p) (p->widget.lines)
110 #endif
111
112 #ifdef PORT_NOT_FOCUS_SELECT_ITEM
113 # define focus_select_item(x)
114 #else
115 # define focus_select_item(x) select_item(x)
116 #endif
117
118 #ifdef PORT_NOT_UNFOCUS_UNSELECT_ITEM
119 # define unfocus_unselect_item(x)
120 #else
121 # define unfocus_unselect_item(x) unselect_item(x)
122 #endif
123
124 #ifdef HAVE_X
125 # define set_colors(x)
126 #else
127 # define x_create_panel(x,y,z) 1;
128 # define x_panel_load_index(p,x)
129 # define x_panel_select_item(a,b,c)
130 # define x_panel_destroy(p)
131
132 void
133 set_colors (WPanel *panel)
134 {
135 standend ();
136 if (hascolors)
137 attrset (NORMAL_COLOR);
138 }
139 #endif
140
141 #ifndef ICONS_PER_ROW
142 # define ICONS_PER_ROW(x) 1
143 #endif
144
145 /* Delete format string, it is a linked list */
146 void
147 delete_format (format_e *format)
148 {
149 format_e *next;
150
151 while (format){
152 next = format->next;
153 free (format);
154 format = next;
155 }
156 }
157
158 /* This code relies on the default justification!!! */
159 void
160 add_permission_string (char *dest, int width, file_entry *fe, int attr, int color, int is_octal)
161 {
162 int i, r, l;
163
164 l = get_user_rights (&fe->buf);
165
166 if (is_octal){
167 /* Place of the access bit in octal mode */
168 l = width + l - 3;
169 r = l + 1;
170 } else {
171 /* The same to the triplet in string mode */
172 l = l * 3 + 1;
173 r = l + 3;
174 }
175
176 for(i = 0; i < width; i++){
177 if (i >= l && i < r){
178 if (attr == SELECTED || attr == MARKED_SELECTED)
179 attrset (MARKED_SELECTED_COLOR);
180 else
181 attrset (MARKED_COLOR);
182 } else
183 attrset (color);
184
185 addch (dest[i]);
186 }
187 }
188
189 int
190 file_entry_color (file_entry *fe)
191 {
192 if (filetype_mode){
193 if (S_ISDIR (fe->buf.st_mode))
194 return (DIRECTORY_COLOR);
195 else if (S_ISLNK (fe->buf.st_mode)) {
196 if (fe->f.link_to_dir)
197 return (DIRECTORY_COLOR);
198 else if (fe->f.stalled_link)
199 return (STALLED_COLOR);
200 else
201 return (LINK_COLOR);
202 } else if (S_ISSOCK (fe->buf.st_mode))
203 return (SPECIAL_COLOR);
204 else if (S_ISCHR (fe->buf.st_mode))
205 return (DEVICE_COLOR);
206 else if (S_ISBLK (fe->buf.st_mode))
207 return (DEVICE_COLOR);
208 else if (S_ISFIFO (fe->buf.st_mode))
209 return (SPECIAL_COLOR);
210 else if (is_exe (fe->buf.st_mode))
211 return (EXECUTABLE_COLOR);
212 else if (fe->fname && (strcmp (fe->fname, "core") == 0))
213 return (CORE_COLOR);
214 }
215 return (NORMAL_COLOR);
216 }
217
218 /* This functions return a string representation of a file entry */
219 char *
220 string_file_type (file_entry *fe, int len)
221 {
222 static char buffer [2];
223
224 if (S_ISDIR (fe->buf.st_mode))
225 buffer [0] = PATH_SEP;
226 else if (S_ISLNK (fe->buf.st_mode)) {
227 if (fe->f.link_to_dir)
228 buffer [0] = '~';
229 else if (fe->f.stalled_link)
230 buffer [0] = '!';
231 else
232 buffer [0] = '@';
233 } else if (S_ISSOCK (fe->buf.st_mode))
234 buffer [0] = '=';
235 else if (S_ISCHR (fe->buf.st_mode))
236 buffer [0] = '-';
237 else if (S_ISBLK (fe->buf.st_mode))
238 buffer [0] = '+';
239 else if (S_ISFIFO (fe->buf.st_mode))
240 buffer [0] = '|';
241 else if (is_exe (fe->buf.st_mode))
242 buffer [0] = '*';
243 else
244 buffer [0] = ' ';
245 buffer [1] = 0;
246 return buffer;
247 }
248
249 char *
250 string_file_size_brief (file_entry *fe, int len)
251 {
252 static char buffer [8];
253
254 if (S_ISDIR (fe->buf.st_mode)){
255 strcpy (buffer, (strcmp (fe->fname, "..") ? "SUB-DIR" : "UP--DIR"));
256 return buffer;
257 }
258
259 return string_file_size (fe, len);
260 }
261
262 char *
263 string_file_permission (file_entry *fe, int len)
264 {
265 return string_perm (fe->buf.st_mode);
266 }
267
268 char *
269 string_file_nlinks (file_entry *fe, int len)
270 {
271 static char buffer [20];
272
273 sprintf (buffer, "%16d", fe->buf.st_nlink);
274 return buffer;
275 }
276
277 char *
278 string_file_owner (file_entry *fe, int len)
279 {
280 return get_owner (fe->buf.st_uid);
281 }
282
283 char *
284 string_file_group (file_entry *fe, int len)
285 {
286 return get_group (fe->buf.st_gid);
287 }
288
289 char *
290 string_file_size (file_entry *fe, int len)
291 {
292 static char buffer [16];
293 int i;
294
295 #ifdef HAVE_ST_RDEV
296 if (S_ISBLK (fe->buf.st_mode) || S_ISCHR (fe->buf.st_mode))
297 sprintf (buffer, "%3d,%3d", (int) (fe->buf.st_rdev >> 8),
298 (int) (fe->buf.st_rdev & 0xff));
299 else
300 #endif
301 {
302 sprintf (buffer, "%lu", (unsigned long) fe->buf.st_size);
303 if (len && (i = strlen (buffer)) > len) {
304 if (i - 2 > len) {
305 if (i - 5 > len)
306 sprintf (buffer, "%luG", (unsigned long) ((fe->buf.st_size) >> 30));
307 else
308 sprintf (buffer, "%luM", (unsigned long) ((fe->buf.st_size) >> 20));
309 } else
310 sprintf (buffer, "%luK", (unsigned long) ((fe->buf.st_size) >> 10));
311 }
312 }
313 return buffer;
314 }
315
316 char *
317 string_file_mtime (file_entry *fe, int len)
318 {
319 return file_date (fe->buf.st_mtime);
320 }
321
322 char *
323 string_file_atime (file_entry *fe, int len)
324 {
325 return file_date (fe->buf.st_atime);
326 }
327
328 char *
329 string_file_ctime (file_entry *fe, int len)
330 {
331 return file_date (fe->buf.st_ctime);
332 }
333
334 #ifdef HAVE_GNOME
335 /* In GNOME, the CList truncates the names */
336 char *
337 string_file_name (file_entry *fe, int len)
338 {
339 return fe->fname;
340 }
341 #else
342 char *
343 string_file_name (file_entry *fe, int len)
344 {
345 if (len)
346 return name_trunc (fe->fname, len);
347 else
348 return fe->fname;
349 }
350 #endif
351
352 char *
353 string_space (file_entry *fe, int len)
354 {
355 return " ";
356 }
357
358 char *
359 string_dot (file_entry *fe, int len)
360 {
361 return ".";
362 }
363
364 char *
365 string_marked (file_entry *fe, int len)
366 {
367 return fe->f.marked ? "*" : " ";
368 }
369
370 char *
371 string_file_perm_octal (file_entry *fe, int len)
372 {
373 static char buffer [9];
374
375 sprintf (buffer, "0%06o", fe->buf.st_mode);
376 return buffer;
377 }
378
379 char *
380 string_inode (file_entry *fe, int len)
381 {
382 static char buffer [9];
383
384 sprintf (buffer, "%ld", (long) fe->buf.st_ino);
385 return buffer;
386 }
387
388 char *
389 string_file_ngid (file_entry *fe, int len)
390 {
391 static char buffer [9];
392
393 sprintf (buffer, "%d", fe->buf.st_gid);
394 return buffer;
395 }
396
397 char *
398 string_file_nuid (file_entry *fe, int len)
399 {
400 static char buffer [9];
401
402 sprintf (buffer, "%d", fe->buf.st_uid);
403 return buffer;
404 }
405
406 #ifdef HAVE_GNOME
407 # define GT 2
408 #else
409 # define GT 1
410 #endif
411
412 static struct {
413 char *id;
414 int min_size;
415 int expands;
416 int default_just;
417 char *title;
418 int use_in_gui;
419 char *(*string_fn)(file_entry *, int);
420 sortfn *sort_routine;
421 } formats [] = {
422 { "name", 12, 1, J_LEFT, N_("Name"), 1, string_file_name, (sortfn *) sort_name },
423 { "size", 7, 0, J_RIGHT, N_("Size"), 1, string_file_size, (sortfn *) sort_size },
424 { "type", GT, 0, J_LEFT, "", 1, string_file_type, (sortfn *) sort_type },
425 { "mtime", 12, 0, J_RIGHT, N_("MTime"), 1, string_file_mtime, (sortfn *) sort_time },
426 { "bsize", 7, 0, J_RIGHT, N_("Size"), 1, string_file_size_brief, (sortfn *) sort_size },
427 { "perm", 10, 0, J_LEFT, N_("Permission"), 1, string_file_permission, NULL },
428 { "mode", 6, 0, J_RIGHT, N_("Perm"), 1, string_file_perm_octal, NULL },
429 { "|", 1, 0, J_RIGHT, N_("|"), 0, 0, NULL },
430 { "nlink", 2, 0, J_RIGHT, N_("Nl"), 1, string_file_nlinks, (sortfn *) sort_links },
431 { "ngid", 5, 0, J_RIGHT, N_("GID"), 1, string_file_ngid, (sortfn *) sort_ngid },
432 { "nuid", 5, 0, J_RIGHT, N_("UID"), 1, string_file_nuid, (sortfn *) sort_nuid },
433 { "owner", 8, 0, J_LEFT, N_("Owner"), 1, string_file_owner, (sortfn *) sort_owner },
434 { "group", 8, 0, J_LEFT, N_("Group"), 1, string_file_group, (sortfn *) sort_group },
435 { "atime", 12, 0, J_RIGHT, N_("ATime"), 1, string_file_atime, (sortfn *) sort_atime },
436 { "ctime", 12, 0, J_RIGHT, N_("CTime"), 1, string_file_ctime, (sortfn *) sort_ctime },
437 { "space", 1, 0, J_RIGHT, " ", 0, string_space, NULL },
438 { "dot", 1, 0, J_RIGHT, " ", 0, string_dot, NULL },
439 { "mark", 1, 0, J_RIGHT, " ", 1, string_marked, NULL },
440 { "inode", 5, 0, J_RIGHT, N_("Inode"), 1, string_inode, (sortfn *) sort_inode },
441 };
442
443 static char *
444 to_buffer (char *dest, int just_mode, int len, char *txt)
445 {
446 int txtlen = strlen (txt);
447 int still;
448
449 if (txtlen > len){
450 if (just_mode != J_LEFT)
451 txt += txtlen - len;
452 txtlen = len;
453 }
454 still = len - txtlen;
455 if (just_mode == J_LEFT){
456 strcpy (dest, txt);
457 dest += txtlen;
458 while (still--)
459 *dest++ = ' ';
460 *dest = 0;
461 } else {
462 while (still--)
463 *dest++ = ' ';
464 strcpy (dest, txt);
465 dest += txtlen;
466 }
467 return dest;
468 }
469
470 int
471 file_compute_color (int attr, file_entry *fe)
472 {
473 int color;
474
475 switch (attr){
476 case SELECTED:
477 color = SELECTED_COLOR;
478 break;
479 case MARKED:
480 color = MARKED_COLOR;
481 break;
482 case MARKED_SELECTED:
483 color = MARKED_SELECTED_COLOR;
484 break;
485 case STATUS:
486 color = NORMAL_COLOR;
487 break;
488 case NORMAL:
489 default:
490 color = file_entry_color(fe);
491 }
492 return color;
493 }
494
495 /* Formats the file number file_index of panel in the buffer dest */
496 void
497 format_file (char *dest, WPanel *panel, int file_index, int width, int attr, int isstatus)
498 {
499 int color, length, empty_line;
500 char *txt;
501 char *old_pos;
502 char *cdest = dest;
503 format_e *format, *home;
504 file_entry *fe;
505
506 length = 0;
507 empty_line = (file_index >= panel->count);
508 home = (isstatus) ? panel->status_format : panel->format;
509 fe = &panel->dir.list [file_index];
510
511 if (!empty_line)
512 color = file_compute_color (attr, fe);
513 else
514 color = NORMAL_COLOR;
515 for (format = home; format; format = format->next){
516 if (format->string_fn){
517 int len;
518
519 if (empty_line)
520 txt = " ";
521 else
522 txt = (*format->string_fn)(fe, format->field_len);
523
524 old_pos = cdest;
525
526 len = format->field_len;
527 if (len + length > width)
528 len = width - length;
529 cdest = to_buffer (cdest, format->just_mode, len, txt);
530 length += len;
531
532 #ifdef HAVE_X
533 if (length == width)
534 break;
535 #else
536 /* What shall we do? Will we color each line according to
537 * the file type? Any suggestions to mc@timur.kazan.su
538 */
539
540 attrset (color);
541
542 if (permission_mode && !strcmp(format->id, "perm"))
543 add_permission_string (old_pos, format->field_len, fe, attr, color, 0);
544 else if (permission_mode && !strcmp(format->id, "mode"))
545 add_permission_string (old_pos, format->field_len, fe, attr, color, 1);
546 else
547 addstr (old_pos);
548 #endif
549 } else {
550 #ifndef HAVE_X
551 /* I'm preffer the view without this 3 lines, try to kill it :-) */
552 if (attr == SELECTED || attr == MARKED_SELECTED)
553 attrset (SELECTED_COLOR);
554 else
555 attrset (NORMAL_COLOR);
556 one_vline ();
557 #else
558 *cdest++ = ' ';
559 #endif
560 length++;
561 }
562 }
563
564 if (length < width){
565 int still = width - length;
566 while (still--)
567 #ifdef HAVE_X
568 *cdest++ = ' ';
569 *cdest = 0;
570 #else
571 addch (' ');
572 #endif
573 }
574 }
575
576 #ifndef HAVE_X
577 void
578 repaint_file (WPanel *panel, int file_index, int mv, int attr, int isstatus)
579 {
580 int second_column = 0;
581 int width, offset;
582 char buffer [255];
583
584 offset = 0;
585 if (!isstatus && panel->split){
586
587 second_column = (file_index - panel->top_file) / llines (panel);
588 width = (panel->widget.cols - 2)/2 - 1;
589
590 if (second_column){
591 offset = 1 + width;
592 width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1;
593 }
594 } else
595 width = (panel->widget.cols - 2);
596
597 if (mv){
598 if (!isstatus && panel->split){
599 widget_move (&panel->widget,
600 (file_index - panel->top_file) %
601 llines (panel) + 2,
602 (offset + 1));
603 } else
604 widget_move (&panel->widget, file_index - panel->top_file + 2, 1);
605 }
606
607 format_file (buffer, panel, file_index, width, attr, isstatus);
608
609 if (!isstatus && panel->split){
610 if (second_column)
611 addch (' ');
612 else {
613 attrset (NORMAL_COLOR);
614 one_vline ();
615 }
616 }
617 }
618 #endif
619
620 #ifndef PORT_HAS_DISPLAY_MINI_INFO
621 void
622 display_mini_info (WPanel *panel)
623 {
624 if (!show_mini_info)
625 return;
626
627 widget_move (&panel->widget, llines (panel)+3, 1);
628
629 if (panel->searching){
630 attrset (INPUT_COLOR);
631 printw ("/%-*s", panel->widget.cols-3, panel->search_buffer);
632 attrset (NORMAL_COLOR);
633 return;
634 }
635
636 /* Status displays total marked size */
637 if (panel->marked){
638 char buffer [100];
639 char *p;
640
641 attrset (MARKED_COLOR);
642 printw ("%*s", panel->widget.cols-2, " ");
643 widget_move (&panel->widget, llines (panel)+3, 1);
644 sprintf (buffer, _(" %s bytes in %d file%s"),
645 size_trunc_sep (panel->total), panel->marked,
646 panel->marked == 1 ? "" : "s");
647 p = buffer;
648 if (strlen (buffer) > panel->widget.cols-4){
649 buffer [panel->widget.cols-4] = 0;
650 p += 2;
651 }
652 printw ("%-*s", panel->widget.cols-2, p);
653 return;
654 }
655
656 /* Status resolves links and show them */
657 set_colors (panel);
658 #ifndef OS2_NT
659 if (S_ISLNK (panel->dir.list [panel->selected].buf.st_mode)){
660 char *link, link_target [MC_MAXPATHLEN];
661 int len;
662
663 link = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname);
664 len = mc_readlink (link, link_target, MC_MAXPATHLEN);
665 free (link);
666 if (len > 0){
667 link_target[len] = 0;
668 printw ("-> %-*s", panel->widget.cols - 5,
669 name_trunc (link_target, panel->widget.cols - 5));
670 } else
671 addstr (_("<readlink failed>"));
672 return;
673 }
674 #endif
675 /* Default behaviour */
676 repaint_file (panel, panel->selected, 0, STATUS, 1);
677 return;
678 }
679 #endif
680
681 #ifndef HAVE_X
682 void
683 paint_dir (WPanel *panel)
684 {
685 int i;
686 int color; /* Color value of the line */
687 int items; /* Number of items */
688
689 items = llines (panel) * (panel->split ? 2 : 1);
690
691 for (i = 0; i < items; i++){
692 if (i+panel->top_file >= panel->count)
693 color = 0;
694 else {
695 color = 2 * (panel->dir.list [i+panel->top_file].f.marked);
696 color += (panel->selected==i+panel->top_file && panel->active);
697 }
698 repaint_file (panel, i+panel->top_file, 1, color, 0);
699 }
700 standend ();
701 panel->dirty = 0;
702 }
703 #endif
704
705 #ifdef HAVE_X
706 #define mini_info_separator(x)
707 #else
708 static void
709 mini_info_separator (WPanel *panel)
710 {
711 if (!show_mini_info)
712 return;
713
714 standend ();
715 widget_move (&panel->widget, llines (panel)+2, 1);
716 #ifdef HAVE_SLANG
717 attrset (NORMAL_COLOR);
718 hline (ACS_HLINE, panel->widget.cols-2);
719 #else
720 hline ((slow_terminal ? '-' : ACS_HLINE) | NORMAL_COLOR,
721 panel->widget.cols-2);
722 #endif
723 }
724
725 void
726 show_dir (WPanel *panel)
727 {
728 char tmp [200];
729
730 set_colors (panel);
731 draw_double_box (panel->widget.parent,
732 panel->widget.y, panel->widget.x,
733 panel->widget.lines, panel->widget.cols);
734
735 #ifdef HAVE_SLANG
736 if (show_mini_info) {
737 #ifdef linux_unicode
738 if (SLtt_Unicode) {
739 SLsmg_draw_unicode (panel->widget.y + llines (panel) + 2,
740 panel->widget.x, SLUNI_DSLTEE_CHAR);
741 SLsmg_draw_unicode (panel->widget.y + llines (panel) + 2,
742 panel->widget.x + panel->widget.cols - 1, SLUNI_DSRTEE_CHAR);
743 } else
744 #endif /* linux_unicode */
745 {
746 SLsmg_draw_object (panel->widget.y + llines (panel) + 2,
747 panel->widget.x, SLSMG_LTEE_CHAR);
748 SLsmg_draw_object (panel->widget.y + llines (panel) + 2,
749 panel->widget.x + panel->widget.cols - 1, SLSMG_RTEE_CHAR);
750 }
751 }
752 #endif /* have_slang */
753
754 if (panel->active)
755 attrset (REVERSE_COLOR);
756
757 widget_move (&panel->widget, 0, 3);
758
759 trim (strip_home_and_password (panel->cwd), tmp, panel->widget.cols-7);
760 addstr (tmp);
761 widget_move (&panel->widget, 0, 1);
762 addstr ("<");
763 widget_move (&panel->widget, 0, panel->widget.cols-2);
764 addstr (">");
765 widget_move (&panel->widget, 0, panel->widget.cols-3);
766 addstr ("v");
767
768 if (panel->active)
769 standend ();
770 }
771 #endif
772
773 #ifndef HAVE_TK
774 /* To be used only by long_frame and full_frame to adjust top_file */
775 static void
776 adjust_top_file (WPanel *panel)
777 {
778 int old_top = panel->top_file;
779
780 if (panel->selected - old_top > llines (panel))
781 panel->top_file = panel->selected;
782 if (old_top - panel->count > llines (panel))
783 panel->top_file = panel->count - llines (panel);
784
785 #ifdef HAVE_TK
786 if (old_top != panel->top_file)
787 x_adjust_top_file (panel);
788 #endif
789 }
790 #else
791 #define adjust_top_file(p)
792 #endif
793
794 extern void paint_info_panel (WPanel *panel);
795
796 /* Repaints the information that changes after a command */
797 void
798 panel_update_contents (WPanel *panel)
799 {
800 show_dir (panel);
801 #ifdef HAVE_X
802 x_fill_panel (panel);
803 #else
804 paint_dir (panel);
805 #endif
806 display_mini_info (panel);
807 }
808
809 void
810 paint_panel (WPanel *panel)
811 {
812 paint_frame (panel);
813 panel_update_contents (panel);
814 mini_info_separator (panel);
815 }
816
817 void
818 Xtry_to_select (WPanel *panel, char *name)
819 {
820 int i;
821 char *subdir;
822
823 if (!name){
824 panel->selected = 0;
825 panel->top_file = 0;
826 x_adjust_top_file (panel);
827 return;
828 }
829
830 /* We only want the last component of the directory */
831 for (subdir = name + strlen (name) - 1; subdir >= name; subdir--){
832 if (*subdir == PATH_SEP){
833 subdir++;
834 break;
835 }
836 }
837 if (subdir < name)
838 subdir = name;
839
840 /* Search that subdirectory, if found select it */
841 for (i = 0; i < panel->count; i++){
842 if (strcmp (subdir, panel->dir.list [i].fname))
843 continue;
844
845 if (i != panel->selected){
846 panel->selected = i;
847 panel->top_file = panel->selected - (panel->widget.lines-2)/2;
848 if (panel->top_file < 0)
849 panel->top_file = 0;
850 x_adjust_top_file (panel);
851 }
852 return;
853 }
854
855 /* Try to select a file near the file that is missing */
856 if (panel->selected >= panel->count){
857 panel->selected = panel->count-1;
858 panel->top_file = panel->selected - (panel->widget.lines)/2;
859 if (panel->top_file < 0)
860 panel->top_file = 0;
861 x_adjust_top_file (panel);
862 } else
863 return;
864 }
865
866 #ifndef PORT_HAS_PANEL_UPDATE_COLS
867 void
868 panel_update_cols (Widget *widget, int frame_size)
869 {
870 int cols, origin;
871
872 if (horizontal_split){
873 widget->cols = COLS;
874 return;
875 }
876
877 if (frame_size == frame_full){
878 cols = COLS;
879 origin = 0;
880 } else {
881 if (widget == get_panel_widget (0)){
882 cols = first_panel_size;
883 origin = 0;
884 } else {
885 cols = COLS-first_panel_size;
886 origin = first_panel_size;
887 }
888 }
889
890 widget->cols = cols;
891 widget->x = origin;
892 }
893 #endif
894
895 static char *
896 panel_save_name (WPanel *panel)
897 {
898 extern int saving_setup;
899
900 /* If the program is shuting down */
901 if ((midnight_shutdown && auto_save_setup) || saving_setup)
902 return copy_strings (panel->panel_name, 0);
903 else
904 return copy_strings ("Temporal:", panel->panel_name, 0);
905 }
906
907 static void
908 panel_destroy (WPanel *p)
909 {
910 int i;
911
912 char *name = panel_save_name (p);
913
914 panel_save_setup (p, name);
915 x_panel_destroy (p);
916 clean_dir (&p->dir, p->count);
917
918 /* save and clean history */
919 if (p->dir_history){
920 Hist *current, *old;
921 history_put (p->hist_name, p->dir_history);
922 current = p->dir_history;
923 while (current->next)
924 current = current->next;
925 while (current){
926 old = current;
927 current = current->prev;
928 free (old->text);
929 free (old);
930 }
931 }
932 free (p->hist_name);
933
934 delete_format (p->format);
935 delete_format (p->status_format);
936
937 free (p->user_format);
938 for (i = 0; i < LIST_TYPES; i++)
939 free (p->user_status_format [i]);
940 free (p->dir.list);
941 free (p->panel_name);
942 free (name);
943 }
944
945 static void
946 panel_format_modified (WPanel *panel)
947 {
948 panel->format_modified = 1;
949 x_reset_sort_labels (panel);
950 }
951
952 int
953 is_a_panel (Widget *w)
954 {
955 return (w->callback == (void *) panel_callback);
956 }
957
958 void directory_history_add (WPanel * panel, char *s);
959
960 /* Panel creation */
961 /* The parameter specifies the name of the panel for setup retieving */
962 WPanel *
963 panel_new (char *panel_name)
964 {
965 WPanel *panel;
966 char *section;
967 int i, err;
968
969 panel = xmalloc (sizeof (WPanel), "panel_new");
970 memset (panel, 0, sizeof (WPanel));
971
972 /* No know sizes of the panel at startup */
973 init_widget (&panel->widget, 0, 0, 0, 0, (callback_fn)
974 panel_callback, (destroy_fn) panel_destroy,
975 (mouse_h) panel_event, NULL);
976
977 /* We do not want the cursor */
978 widget_want_cursor (panel->widget, 0);
979
980 mc_get_current_wd (panel->cwd, sizeof (panel->cwd)-2);
981 strcpy (panel->lwd, ".");
982
983 panel->hist_name = copy_strings ("Dir Hist ", panel_name, 0);
984 panel->dir_history = history_get (panel->hist_name);
985 directory_history_add (panel, panel->cwd);
986
987 panel->dir.list = (file_entry *) malloc (MIN_FILES * sizeof (file_entry));
988 panel->dir.size = MIN_FILES;
989 panel->active = 0;
990 panel->filter = 0;
991 panel->split = 0;
992 panel->top_file = 0;
993 panel->selected = 0;
994 panel->marked = 0;
995 panel->total = 0;
996 panel->reverse = 0;
997 panel->dirty = 1;
998 panel->searching = 0;
999 panel->dirs_marked = 0;
1000 panel->is_panelized = 0;
1001 panel->has_dir_sizes = 0;
1002 panel->format = 0;
1003 panel->status_format = 0;
1004 panel->format_modified = 1;
1005
1006 panel->panel_name = strdup (panel_name);
1007 panel->user_format = strdup (DEFAULT_USER_FORMAT);
1008
1009 for(i = 0; i < LIST_TYPES; i++)
1010 panel->user_status_format [i] = strdup (DEFAULT_USER_FORMAT);
1011
1012 panel->search_buffer [0] = 0;
1013 panel->frame_size = frame_half;
1014 section = copy_strings ("Temporal:", panel->panel_name, 0);
1015 if (!profile_has_section (section, profile_name)){
1016 free (section);
1017 section = strdup (panel->panel_name);
1018 }
1019 panel_load_setup (panel, section);
1020 free (section);
1021
1022 /* Load format strings */
1023 err = set_panel_formats (panel);
1024 if (err){
1025 if (err & 0x01){
1026 free (panel->user_format);
1027 panel->user_format = strdup (DEFAULT_USER_FORMAT);
1028 }
1029 if (err & 0x02){
1030 free (panel->user_status_format [panel->list_type]);
1031 panel->user_status_format [panel->list_type] = strdup (DEFAULT_USER_FORMAT);
1032 }
1033 set_panel_formats (panel);
1034 }
1035
1036 /* Load the default format */
1037 panel->count = do_load_dir (&panel->dir, panel->sort_type,
1038 panel->reverse, panel->case_sensitive, panel->filter);
1039 return panel;
1040 }
1041
1042 void
1043 panel_reload (WPanel *panel)
1044 {
1045 int i;
1046 struct stat current_stat;
1047
1048 if (fast_reload
1049 && !stat (panel->cwd, &current_stat)
1050 && current_stat.st_ctime == panel->dir_stat.st_ctime
1051 && current_stat.st_mtime == panel->dir_stat.st_mtime)
1052 return;
1053
1054 while (mc_chdir (panel->cwd) == -1){
1055 char *last_slash;
1056
1057 if (panel->cwd [0] == PATH_SEP && panel->cwd [1] == 0){
1058 clean_dir (&panel->dir, panel->count);
1059 panel->count = set_zero_dir (&panel->dir);
1060 return;
1061 }
1062 last_slash = strrchr (panel->cwd, PATH_SEP);
1063 if (!last_slash || last_slash == panel->cwd)
1064 strcpy (panel->cwd, PATH_SEP_STR);
1065 else
1066 *last_slash = 0;
1067 bzero (&(panel->dir_stat), sizeof (panel->dir_stat));
1068 show_dir (panel);
1069 }
1070
1071 panel->count = do_reload_dir (&panel->dir, panel->sort_type, panel->count,
1072 panel->reverse, panel->case_sensitive, panel->filter);
1073 panel->marked = 0;
1074 panel->dirs_marked = 0;
1075 panel->total = 0;
1076 panel->has_dir_sizes = 0;
1077
1078 for (i = 0; i < panel->count; i++)
1079 if (panel->dir.list [i].f.marked){
1080 /* do_file_mark will return immediately if newmark == oldmark.
1081 So we have to first unmark it to get panel's summary information
1082 updated. (Norbert) */
1083 panel->dir.list [i].f.marked = 0;
1084 do_file_mark (panel, i, 1);
1085 }
1086 }
1087
1088 #ifndef PORT_HAS_PAINT_FRAME
1089 void
1090 paint_frame (WPanel *panel)
1091 {
1092 int header_len;
1093 int spaces, extra;
1094 int side, width;
1095
1096 char *txt, buffer[30]; /*Hope that this is enough ;-) */
1097 if (!panel->split)
1098 adjust_top_file (panel);
1099
1100 widget_erase (&panel->widget);
1101 show_dir (panel);
1102
1103 widget_move (&panel->widget, 1, 1);
1104
1105 for (side = 0; side <= panel->split; side++){
1106 format_e *format;
1107
1108 if (side){
1109 attrset (NORMAL_COLOR);
1110 one_vline ();
1111 width = panel->widget.cols - panel->widget.cols/2 - 1;
1112 } else if (panel->split)
1113 width = panel->widget.cols/2 - 3;
1114 else
1115 width = panel->widget.cols - 2;
1116
1117 for (format = panel->format; format; format = format->next){
1118 if (format->string_fn){
1119 txt = format->title;
1120
1121 header_len = strlen (txt);
1122 if (header_len > format->field_len){
1123 strcpy (buffer, txt);
1124 txt = buffer;
1125 txt [format->field_len] = 0;
1126 header_len = strlen (txt);
1127 }
1128
1129 attrset (MARKED_COLOR);
1130 spaces = (format->field_len - header_len) / 2;
1131 extra = (format->field_len - header_len) % 2;
1132 printw ("%*s%-s%*s", spaces, "",
1133 txt, spaces+extra, "");
1134 width -= 2 * spaces + extra + header_len;
1135 } else {
1136 attrset (NORMAL_COLOR);
1137 one_vline ();
1138 width --;
1139 continue;
1140 }
1141 }
1142
1143 if (width > 0)
1144 printw ("%*s", width, "");
1145 }
1146 }
1147 #endif
1148
1149 static char *
1150 parse_panel_size (WPanel *panel, char *format, int isstatus)
1151 {
1152 int frame = frame_half;
1153 format = skip_separators (format);
1154
1155 if (!strncmp (format, "full", 4)){
1156 frame = frame_full;
1157 format += 4;
1158 } else if (!strncmp (format, "half", 4)){
1159 frame = frame_half;
1160 format += 4;
1161 }
1162
1163 if (!isstatus){
1164 panel->frame_size = frame;
1165 panel->split = 0;
1166 }
1167
1168 /* Now, the optional column specifier */
1169 format = skip_separators (format);
1170
1171 if (*format == '1' || *format == '2'){
1172 if (!isstatus)
1173 panel->split = *format == '2';
1174 format++;
1175 }
1176
1177 if (!isstatus)
1178 panel_update_cols (&(panel->widget), panel->frame_size);
1179
1180 return skip_separators (format);
1181 }
1182
1183 /* Format is:
1184
1185 all := panel_format? format
1186 panel_format := [full|half] [1|2]
1187 format := one_format_e
1188 | format , one_format_e
1189
1190 one_format_e := just format.id [opt_size]
1191 just := [<|>]
1192 opt_size := : size [opt_expand]
1193 size := [0-9]+
1194 opt_expand := +
1195
1196 */
1197
1198 format_e *
1199 parse_display_format (WPanel *panel, char *format, char **error, int isstatus, int *res_total_cols)
1200 {
1201 format_e *darr, *old, *home = 0; /* The formats we return */
1202 int total_cols = 0; /* Used columns by the format */
1203 int set_justify; /* flag: set justification mode? */
1204 int justify = 0; /* Which mode. */
1205 int items = 0; /* Number of items in the format */
1206 int i;
1207
1208 *error = 0;
1209
1210 /*
1211 * This makes sure that the panel and mini status full/half mode
1212 * setting is equal
1213 */
1214 format = parse_panel_size (panel, format, isstatus);
1215
1216 while (*format){ /* format can be an empty string */
1217 int found = 0;
1218
1219 darr = xmalloc (sizeof (format_e), "parse_display_format");
1220
1221 /* I'm so ugly, don't look at me :-) */
1222 if (!home)
1223 home = old = darr;
1224
1225 old->next = darr;
1226 darr->next = 0;
1227 old = darr;
1228
1229 format = skip_separators (format);
1230
1231 if (*format == '<' || *format == '>'){
1232 set_justify = 1;
1233 justify = *format == '<' ? J_LEFT : J_RIGHT;
1234 format = skip_separators (format+1);
1235 } else
1236 set_justify = 0;
1237
1238 for (i = 0; i < ELEMENTS(formats); i++){
1239 int klen = strlen (formats [i].id);
1240
1241 if (strncmp (format, formats [i].id, klen) != 0)
1242 continue;
1243
1244 format += klen;
1245
1246 if (formats [i].use_in_gui)
1247 items++;
1248
1249 darr->use_in_gui = formats [i].use_in_gui;
1250 darr->requested_field_len = formats [i].min_size;
1251 darr->string_fn = formats [i].string_fn;
1252 if (formats [i].title [0])
1253 darr->title = _(formats [i].title);
1254 else
1255 darr->title = "";
1256 darr->id = formats [i].id;
1257 darr->expand = formats [i].expands;
1258
1259 if (set_justify)
1260 darr->just_mode = justify;
1261 else
1262 darr->just_mode = formats [i].default_just;
1263
1264 found = 1;
1265
1266 format = skip_separators (format);
1267
1268 /* If we have a size specifier */
1269 if (*format == ':'){
1270 int req_length;
1271
1272 /* If the size was specified, we don't want
1273 * auto-expansion by default
1274 */
1275 darr->expand = 0;
1276 format++;
1277 req_length = atoi (format);
1278 darr->requested_field_len = req_length;
1279
1280 format = skip_numbers (format);
1281
1282 /* Now, if they insist on expansion */
1283 if (*format == '+'){
1284 darr->expand = 1;
1285 format++;
1286 }
1287
1288 }
1289
1290 break;
1291 }
1292 if (!found){
1293 char old_char;
1294
1295 int pos = min (8, strlen (format));
1296 delete_format (home);
1297 old_char = format [pos];
1298 format [pos] = 0;
1299 *error = copy_strings(_("Unknow tag on display format: "), format, 0);
1300 format [pos] = old_char;
1301 return 0;
1302 }
1303 total_cols += darr->requested_field_len;
1304 }
1305
1306 *res_total_cols = total_cols;
1307 if (home)
1308 home->items = items;
1309 return home;
1310 }
1311
1312 format_e *
1313 use_display_format (WPanel *panel, char *format, char **error, int isstatus)
1314 {
1315 #define MAX_EXPAND 4
1316 int expand_top = 0; /* Max used element in expand */
1317 int usable_columns; /* Usable columns in the panel */
1318 int total_cols;
1319 char *expand_list [MAX_EXPAND]; /* Expand at most 4 fields. */
1320 int i;
1321 format_e *darr, *home;
1322
1323 if (!format)
1324 format = DEFAULT_USER_FORMAT;
1325
1326 home = parse_display_format (panel, format, error, isstatus, &total_cols);
1327
1328 if (*error)
1329 return 0;
1330
1331 /* Status needn't to be split */
1332 usable_columns = ((panel->widget.cols-2)/((isstatus)
1333 ? 1
1334 : (panel->split+1))) - (!isstatus && panel->split);
1335
1336 /* Clean expand list */
1337 for (i = 0; i < MAX_EXPAND; i++)
1338 expand_list [i] = '\0';
1339
1340
1341 /* Look for the expandable fields and set field_len based on the requested field len */
1342 for (darr = home; darr && expand_top < MAX_EXPAND; darr = darr->next){
1343 darr->field_len = darr->requested_field_len;
1344 if (darr->expand)
1345 expand_list [expand_top++] = darr->id;
1346 }
1347
1348 /* If we used more columns than the available columns, adjust that */
1349 if (total_cols > usable_columns){
1350 int pdif, dif = total_cols - usable_columns;
1351
1352 while (dif){
1353 pdif = dif;
1354 for (darr = home; darr; darr = darr->next){
1355 if (dif && darr->field_len - 1){
1356 darr->field_len--;
1357 dif--;
1358 }
1359 }
1360
1361 /* avoid endless loop if num fields > 40 */
1362 if (pdif == dif)
1363 break;
1364 }
1365 total_cols = usable_columns; /* give up, the rest should be truncated */
1366 }
1367
1368 /* Expand the available space */
1369 if ((usable_columns > total_cols) && expand_top){
1370 int spaces = (usable_columns - total_cols) / expand_top;
1371 int extra = (usable_columns - total_cols) % expand_top;
1372
1373 for (i = 0, darr = home; darr && (i < expand_top); darr = darr->next)
1374 if (darr->expand){
1375 darr->field_len += (spaces + ((i == 0) ? extra : 0));
1376 i++;
1377 }
1378 }
1379 return home;
1380 }
1381
1382 /* Switches the panel to the mode specified in the format */
1383 /* Seting up both format and status string. Return: 0 - on success; */
1384 /* 1 - format error; 2 - status error; 3 - errors in both formats. */
1385 int
1386 set_panel_formats (WPanel *p)
1387 {
1388 format_e *form;
1389 char *err;
1390 int retcode = 0;
1391
1392 form = use_display_format (p, panel_format (p), &err, 0);
1393
1394 if (err){
1395 free (err);
1396 retcode = 1;
1397 }
1398 else {
1399 if (p->format)
1400 delete_format (p->format);
1401
1402 p->format = form;
1403 }
1404
1405 if (show_mini_info){
1406
1407 form = use_display_format (p, mini_status_format (p), &err, 1);
1408
1409 if (err){
1410 free (err);
1411 retcode += 2;
1412 }
1413 else {
1414 if (p->status_format)
1415 delete_format (p->status_format);
1416
1417 p->status_format = form;
1418 }
1419 }
1420
1421 panel_format_modified (p);
1422 panel_update_cols (&(p->widget), p->frame_size);
1423
1424 return retcode;
1425 }
1426
1427 /* Given the panel->view_type returns the format string to be parsed */
1428 char *
1429 panel_format (WPanel *panel)
1430 {
1431 switch (panel->list_type){
1432
1433 case list_long:
1434 return "full perm,space,nlink,space,owner,space,group,space,size,space,mtime,space,name";
1435
1436 case list_brief:
1437 return "half 2,type,name";
1438
1439 case list_user:
1440 return panel->user_format;
1441
1442 default:
1443 case list_full:
1444 return "half type,name,|,size,|,mtime";
1445 }
1446 }
1447
1448 char *
1449 mini_status_format (WPanel *panel)
1450 {
1451 if (panel->user_mini_status)
1452 return panel->user_status_format [panel->list_type];
1453
1454 switch (panel->list_type){
1455
1456 case list_long:
1457 return "full perm,space,nlink,space,owner,space,group,space,size,space,mtime,space,name";
1458
1459 case list_brief:
1460 return "half type,name,space,bsize,space,perm,space";
1461
1462 case list_full:
1463 return "half type,name";
1464
1465 default:
1466 case list_user:
1467 return panel->user_format;
1468 }
1469 }
1470
1471 /* */
1472 /* Panel operation commands */
1473 /* */
1474
1475 /* Returns the number of items in the given panel */
1476 int
1477 ITEMS (WPanel *p)
1478 {
1479 #ifdef HAVE_TK
1480 return p->widget.lines;
1481 #else
1482 if (p->split)
1483 return llines (p) * 2;
1484 else
1485 return llines (p);
1486 #endif
1487 }
1488
1489 /* This function sets redisplays the selection */
1490 void
1491 select_item (WPanel *panel)
1492 {
1493 int repaint = 0;
1494 int items = ITEMS (panel);
1495
1496 /* Although currently all over the code we set the selection and
1497 top file to decent values before calling select_item, I could
1498 forget it someday, so it's better to do the actual fitting here */
1499
1500 #ifdef HAVE_X
1501 int old_top;
1502 old_top = panel->top_file;
1503 #endif
1504
1505 if (panel->top_file < 0){
1506 repaint = 1;
1507 panel->top_file = 0;
1508 }
1509
1510 if (panel->selected < 0)
1511 panel->selected = 0;
1512
1513 if (panel->selected > panel->count-1)
1514 panel->selected = panel->count - 1;
1515
1516 if (panel->top_file > panel->count-1){
1517 repaint = 1;
1518 panel->top_file = panel->count-1;
1519 }
1520
1521 if ((panel->count - panel->top_file) < items){
1522 repaint = 1;
1523 panel->top_file = panel->count - items;
1524 if (panel->top_file < 0)
1525 panel->top_file = 0;
1526 }
1527
1528 if (panel->selected < panel->top_file){
1529 repaint = 1;
1530 panel->top_file = panel->selected;
1531 }
1532
1533 if ((panel->selected - panel->top_file) >= items){
1534 repaint = 1;
1535 panel->top_file = panel->selected - items + 1;
1536 }
1537
1538 #ifndef HAVE_X
1539 if (repaint)
1540 paint_panel (panel);
1541 else
1542 repaint_file (panel, panel->selected, 1, 2*selection (panel)->f.marked+1, 0);
1543 #else
1544 if (old_top != panel->top_file)
1545 x_adjust_top_file (panel);
1546 x_select_item (panel);
1547 #endif
1548
1549 display_mini_info (panel);
1550
1551 execute_hooks (select_file_hook);
1552 }
1553
1554 /* Clears all files in the panel, used only when one file was marked */
1555 void
1556 unmark_files (WPanel *panel)
1557 {
1558 int i;
1559
1560 if (!panel->marked)
1561 return;
1562 for (i = 0; i < panel->count; i++)
1563 file_mark (panel, i, 0);
1564
1565 panel->dirs_marked = 0;
1566 panel->marked = 0;
1567 panel->total = 0;
1568 }
1569
1570 #ifdef HAVE_X
1571 void
1572 unselect_item (WPanel *panel)
1573 {
1574 x_unselect_item (panel);
1575 }
1576 #else
1577 void
1578 unselect_item (WPanel *panel)
1579 {
1580 repaint_file (panel, panel->selected, 1, 2*selection (panel)->f.marked, 0);
1581 }
1582 #endif
1583
1584 static void
1585 do_move_down (WPanel *panel)
1586 {
1587 if (panel->selected+1 == panel->count)
1588 return;
1589
1590 unselect_item (panel);
1591 panel->selected++;
1592
1593 #ifndef HAVE_X
1594 if (panel->selected - panel->top_file == ITEMS (panel) &&
1595 panel_scroll_pages){
1596 /* Scroll window half screen */
1597 panel->top_file += ITEMS (panel)/2;
1598 if (panel->top_file > panel->count - ITEMS (panel))
1599 panel->top_file = panel->count - ITEMS (panel);
1600 paint_dir (panel);
1601 select_item (panel);
1602 }
1603 #endif
1604 select_item (panel);
1605 }
1606
1607 static void
1608 do_move_up (WPanel *panel)
1609 {
1610 if (panel->selected == 0)
1611 return;
1612
1613 unselect_item (panel);
1614 panel->selected--;
1615 #ifndef HAVE_X
1616 if (panel->selected < panel->top_file && panel_scroll_pages){
1617 /* Scroll window half screen */
1618 panel->top_file -= ITEMS (panel)/2;
1619 if (panel->top_file < 0) panel->top_file = 0;
1620 paint_dir (panel);
1621 }
1622 #endif
1623 select_item (panel);
1624 }
1625
1626 static int
1627 move_rel (WPanel *panel, int rel)
1628 {
1629 unselect_item (panel);
1630
1631 if (rel < 0){
1632 if (panel->selected + rel < 0)
1633 panel->selected = 0;
1634 else
1635 panel->selected = panel->selected + rel;
1636 } else {
1637 if (panel->selected + rel >= panel->count)
1638 panel->selected = panel->count - 1;
1639 else
1640 panel->selected = panel->selected + rel;
1641 }
1642 select_item (panel);
1643 }
1644
1645 /* */
1646 /* Panel key binded commands */
1647 /* */
1648 static void
1649 move_up (WPanel *panel)
1650 {
1651 if (panel->list_type == list_icons){
1652 move_rel (panel, -ICONS_PER_ROW (panel));
1653 } else
1654 do_move_up (panel);
1655 }
1656
1657 static void
1658 move_down (WPanel *panel)
1659 {
1660 if (panel->list_type == list_icons){
1661 move_rel (panel, ICONS_PER_ROW (panel));
1662 } else
1663 do_move_down (panel);
1664 }
1665
1666 /* Changes the selection by lines (may be negative) */
1667 static void
1668 move_selection (WPanel *panel, int lines)
1669 {
1670 int new_pos;
1671 int adjust = 0;
1672
1673 new_pos = panel->selected + lines;
1674 if (new_pos >= panel->count)
1675 new_pos = panel->count-1;
1676
1677 if (new_pos < 0)
1678 new_pos = 0;
1679
1680 unselect_item (panel);
1681 panel->selected = new_pos;
1682
1683 #ifndef HAVE_X
1684 if (panel->selected - panel->top_file >= ITEMS (panel)){
1685 panel->top_file += lines;
1686 adjust = 1;
1687 }
1688
1689 if (panel->selected - panel->top_file < 0){
1690 panel->top_file += lines;
1691 adjust = 1;
1692 }
1693
1694 if (adjust){
1695 if (panel->top_file > panel->selected)
1696 panel->top_file = panel->selected;
1697 if (panel->top_file < 0)
1698 panel->top_file = 0;
1699 paint_dir (panel);
1700 }
1701 #endif
1702 select_item (panel);
1703 }
1704
1705 static int
1706 move_left (WPanel *panel, int c_code)
1707 {
1708 if (panel->list_type == list_icons){
1709 do_move_up (panel);
1710 return 1;
1711 } else {
1712 if (panel->split){
1713 move_selection (panel, -llines (panel));
1714 return 1;
1715 } else
1716 return maybe_cd (c_code, 0);
1717 }
1718 }
1719
1720 static int
1721 move_right (WPanel *panel, int c_code)
1722 {
1723 if (panel->list_type == list_icons){
1724 do_move_down (panel);
1725 return 1;
1726 } else {
1727 if (panel->split){
1728 move_selection (panel, llines (panel));
1729 return 1;
1730 } else
1731 return maybe_cd (c_code, 1);
1732 }
1733 }
1734
1735 static void
1736 prev_page (WPanel *panel)
1737 {
1738 int items;
1739
1740 if (!panel->selected && !panel->top_file)
1741 return;
1742 unselect_item (panel);
1743 items = ITEMS (panel);
1744 if (panel->top_file < items)
1745 items = panel->top_file;
1746 if (!items)
1747 panel->selected = 0;
1748 else
1749 panel->selected -= items;
1750 panel->top_file -= items;
1751
1752 /* This keeps the selection in a reasonable place */
1753 if (panel->selected < 0)
1754 panel->selected = 0;
1755 if (panel->top_file < 0)
1756 panel->top_file = 0;
1757 x_adjust_top_file (panel);
1758 select_item (panel);
1759 #ifndef HAVE_X
1760 paint_dir (panel);
1761 #endif
1762 }
1763
1764 static void
1765 prev_page_key (WPanel *panel)
1766 {
1767 if (console_flag && ctrl_pressed ()){
1768 do_cd ("..", cd_exact);
1769 } else
1770 prev_page (panel);
1771 }
1772
1773 static void
1774 next_page (WPanel *panel)
1775 {
1776 int items;
1777
1778 if (panel->selected == panel->count - 1)
1779 return;
1780 unselect_item (panel);
1781 items = ITEMS (panel);
1782 if (panel->top_file > panel->count - 2 * items)
1783 items = panel->count - items - panel->top_file;
1784 if (panel->top_file + items < 0)
1785 items = - panel->top_file;
1786 if (!items)
1787 panel->selected = panel->count - 1;
1788 else
1789 panel->selected += items;
1790 panel->top_file += items;
1791
1792 /* This keeps the selection in it's relative position */
1793 if (panel->selected >= panel->count)
1794 panel->selected = panel->count - 1;
1795 if (panel->top_file >= panel->count)
1796 panel->top_file = panel->count - 1;
1797 x_adjust_top_file (panel);
1798 select_item (panel);
1799 #ifndef HAVE_X
1800 paint_dir (panel);
1801 #endif
1802 }
1803
1804 static void next_page_key (WPanel *panel)
1805 {
1806 if (console_flag&&ctrl_pressed()&&
1807 (S_ISDIR(selection (panel)->buf.st_mode) ||
1808 link_isdir (selection (panel))))
1809 do_cd (selection (panel)->fname, cd_exact);
1810 else
1811 next_page (panel);
1812 }
1813
1814 static void
1815 goto_top_file (WPanel *panel)
1816 {
1817 unselect_item (panel);
1818 panel->selected = panel->top_file;
1819 select_item (panel);
1820 }
1821
1822 static void
1823 goto_middle_file (WPanel *panel)
1824 {
1825 unselect_item (panel);
1826 panel->selected = panel->top_file + (ITEMS (panel)/2);
1827 if (panel->selected >= panel->count)
1828 panel->selected = panel->count - 1;
1829 select_item (panel);
1830 }
1831
1832 static void
1833 goto_bottom_file (WPanel *panel)
1834 {
1835 unselect_item (panel);
1836 panel->selected = panel->top_file + ITEMS (panel)-1;
1837 if (panel->selected >= panel->count)
1838 panel->selected = panel->count - 1;
1839 select_item (panel);
1840 }
1841
1842 static void
1843 move_home (WPanel *panel)
1844 {
1845 if (panel->selected == 0)
1846 return;
1847 unselect_item (panel);
1848
1849 if (torben_fj_mode){
1850 int middle_pos = panel->top_file + (ITEMS (panel)/2);
1851
1852 if (panel->selected > middle_pos){
1853 goto_middle_file (panel);
1854 return;
1855 }
1856 if (panel->selected != panel->top_file){
1857 goto_top_file (panel);
1858 return;
1859 }
1860 }
1861
1862 panel->top_file = 0;
1863 panel->selected = 0;
1864
1865 #ifndef HAVE_X
1866 paint_dir (panel);
1867 #endif
1868 select_item (panel);
1869 }
1870
1871 static void
1872 move_end (WPanel *panel)
1873 {
1874 if (panel->selected == panel->count-1)
1875 return;
1876 unselect_item (panel);
1877 if (torben_fj_mode){
1878 int middle_pos = panel->top_file + (ITEMS (panel)/2);
1879
1880 if (panel->selected < middle_pos){
1881 goto_middle_file (panel);
1882 return;
1883 }
1884 if (panel->selected != (panel->top_file + ITEMS(panel)-1)){
1885 goto_bottom_file (panel);
1886 return;
1887 }
1888 }
1889
1890 panel->selected = panel->count-1;
1891 #ifndef HAVE_X
1892 paint_dir (panel);
1893 #endif
1894 select_item (panel);
1895 }
1896
1897 /* This routine marks a file or a directory */
1898 void
1899 do_file_mark (WPanel *panel, int idx, int mark)
1900 {
1901 if (panel->dir.list [idx].f.marked == mark)
1902 return;
1903 /*
1904 * Only '..' can't be marked, '.' isn't visible.
1905 */
1906 if (strcmp (panel->dir.list [idx].fname, "..")){
1907 file_mark (panel, idx, mark);
1908 if (panel->dir.list [idx].f.marked){
1909 panel->marked++;
1910 if (S_ISDIR (panel->dir.list [idx].buf.st_mode)) {
1911 if (panel->has_dir_sizes)
1912 panel->total += panel->dir.list [idx].buf.st_size;
1913 panel->dirs_marked++;
1914 } else
1915 panel->total += panel->dir.list [idx].buf.st_size;
1916 #ifndef HAVE_XVIEW
1917 set_colors (panel);
1918 #endif
1919 } else {
1920 if (S_ISDIR(panel->dir.list [idx].buf.st_mode)) {
1921 if (panel->has_dir_sizes)
1922 panel->total -= panel->dir.list [idx].buf.st_size;
1923 panel->dirs_marked--;
1924 } else
1925 panel->total -= panel->dir.list [idx].buf.st_size;
1926 panel->marked--;
1927 }
1928 }
1929 }
1930
1931 void
1932 do_file_mark_range (WPanel *panel, int r1, int r2)
1933 {
1934 const int start = min (r1, r2);
1935 const int end = max (r1, r2);
1936 int i, mark;
1937
1938 mark = !panel->dir.list [start].f.marked;
1939
1940 for (i = start; i < end; i++)
1941 do_file_mark (panel, i, mark);
1942 }
1943
1944 static void
1945 do_mark_file (WPanel *panel, int do_move)
1946 {
1947 int idx = panel->selected;
1948 do_file_mark (panel, idx, selection (panel)->f.marked ? 0 : 1);
1949 #ifndef HAVE_XVIEW
1950 repaint_file (panel, idx, 1, 2*panel->dir.list [idx].f.marked+1, 0);
1951 #endif
1952
1953 if (mark_moves_down && do_move)
1954 move_down (panel);
1955 display_mini_info (panel);
1956 }
1957
1958 static void
1959 mark_file (WPanel *panel)
1960 {
1961 do_mark_file (panel, 1);
1962 }
1963
1964 /* Incremental search of a file name in the panel */
1965 static void
1966 do_search (WPanel *panel, int c_code)
1967 {
1968 int l, i;
1969 int wrapped = 0;
1970 int found;
1971
1972 l = strlen (panel->search_buffer);
1973 if (l && (c_code == 8 || c_code == 0177 || c_code == KEY_BACKSPACE))
1974 panel->search_buffer [--l] = 0;
1975 else {
1976 if (c_code && l < sizeof (panel->search_buffer)){
1977 panel->search_buffer [l] = c_code;
1978 panel->search_buffer [l+1] = 0;
1979 l++;
1980 }
1981 }
1982
1983 found = 0;
1984 for (i = panel->selected; !wrapped || i != panel->selected; i++){
1985 if (i >= panel->count){
1986 i = 0;
1987 if (wrapped)
1988 break;
1989 wrapped = 1;
1990 }
1991 if (STRNCOMP (panel->dir.list [i].fname, panel->search_buffer, l) == 0){
1992 unselect_item (panel);
1993 panel->selected = i;
1994 select_item (panel);
1995 found = 1;
1996 break;
1997 }
1998 }
1999 if (!found)
2000 panel->search_buffer [--l] = 0;
2001 #ifndef HAVE_X
2002 paint_panel (panel);
2003 #endif
2004 }
2005
2006 static void
2007 start_search (WPanel *panel)
2008 {
2009 if (panel->searching){
2010 if (panel->selected+1 == panel->count)
2011 panel->selected = 0;
2012 else
2013 move_down (panel);
2014 do_search (panel, 0);
2015 } else {
2016 panel->searching = 1;
2017 panel->search_buffer [0] = 0;
2018 display_mini_info (panel);
2019 mc_refresh ();
2020 }
2021 }
2022
2023 void
2024 do_enter (WPanel *panel)
2025 {
2026 if (S_ISDIR (selection (panel)->buf.st_mode)
2027 || link_isdir (selection (panel))){
2028 do_cd (selection (panel)->fname, cd_exact);
2029 return;
2030 } else {
2031 if (is_exe (selection (panel)->buf.st_mode) &&
2032 if_link_is_exe (selection (panel))) {
2033 #ifdef USE_VFS
2034 if (vfs_current_is_local ())
2035 #endif
2036 {
2037 char *tmp = name_quote (selection (panel)->fname, 0);
2038 char *cmd = copy_strings (".", PATH_SEP_STR, tmp, 0);
2039 if (!confirm_execute || (query_dialog (_(" The Midnight Commander "),
2040 _(" Do you really want to execute? "),
2041 0, 2, _("&Yes"), _("&No")) == 0))
2042 execute (cmd);
2043 free (tmp);
2044 free (cmd);
2045 }
2046 #ifdef USE_VFS
2047 else if (vfs_current_is_extfs ()) {
2048 char *tmp = vfs_get_current_dir();
2049 char *tmp2;
2050
2051 tmp2 = concat_dir_and_file (tmp, selection (panel)->fname);
2052 extfs_run(tmp2);
2053 free (tmp2);
2054 }
2055 #endif /* USE_VFS */
2056 return;
2057 } else {
2058 regex_command (selection (panel)->fname, "Open", NULL, 0);
2059 }
2060 }
2061 }
2062
2063 static void
2064 chdir_other_panel (WPanel *panel)
2065 {
2066 char *new_dir;
2067
2068 if (get_other_type () != view_listing)
2069 return;
2070
2071 if (!S_ISDIR (panel->dir.list [panel->selected].buf.st_mode))
2072 new_dir = concat_dir_and_file (panel->cwd, "..");
2073 else
2074 new_dir = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname);
2075
2076 change_panel ();
2077 do_cd (new_dir, cd_exact);
2078 change_panel ();
2079
2080 move_down (panel);
2081
2082 free (new_dir);
2083 }
2084
2085 static void
2086 chdir_to_readlink (WPanel *panel)
2087 {
2088 char *new_dir;
2089
2090 if (get_other_type () != view_listing)
2091 return;
2092
2093 if (S_ISLNK (panel->dir.list [panel->selected].buf.st_mode)) {
2094 char buffer [MC_MAXPATHLEN], *p;
2095 int i;
2096 struct stat mybuf;
2097
2098 i = readlink (selection (panel)->fname, buffer, MC_MAXPATHLEN);
2099 if (i < 0)
2100 return;
2101 if (mc_stat (selection (panel)->fname, &mybuf) < 0)
2102 return;
2103 buffer [i] = 0;
2104 if (!S_ISDIR (mybuf.st_mode)) {
2105 p = strrchr (buffer, PATH_SEP);
2106 if (p && !p[1]) {
2107 *p = 0;
2108 p = strrchr (buffer, PATH_SEP);
2109 }
2110 if (!p)
2111 return;
2112 p[1] = 0;
2113 }
2114 if (*buffer == PATH_SEP)
2115 new_dir = strdup (buffer);
2116 else
2117 new_dir = concat_dir_and_file (panel->cwd, buffer);
2118
2119 change_panel ();
2120 do_cd (new_dir, cd_exact);
2121 change_panel ();
2122
2123 move_down (panel);
2124
2125 free (new_dir);
2126 }
2127 }
2128
2129 static key_map panel_keymap [] = {
2130 { KEY_DOWN, move_down },
2131 { KEY_UP, move_up },
2132
2133 /* The action button :-) */
2134 { '\n', do_enter },
2135 { KEY_ENTER, do_enter },
2136
2137 { KEY_IC, mark_file },
2138 { KEY_HOME, move_home },
2139 { KEY_C1, move_end },
2140 { KEY_END, move_end },
2141 { KEY_A1, move_home },
2142 { KEY_NPAGE, next_page_key },
2143 { KEY_PPAGE, prev_page_key },
2144
2145 /* To quickly move in the panel */
2146 { ALT('g'), goto_top_file },
2147 { ALT('r'), goto_middle_file }, /* M-r like emacs */
2148 { ALT('j'), goto_bottom_file },
2149
2150 #ifdef OS2_NT
2151 { ALT(KEY_F(11)), drive_cmd_a },
2152 { ALT(KEY_F(12)), drive_cmd_b },
2153 { ALT('d'), drive_chg },
2154 #endif
2155
2156 /* Emacs-like bindings */
2157 { XCTRL('v'), next_page }, /* C-v like emacs */
2158 { ALT('v'), prev_page }, /* M-v like emacs */
2159 { XCTRL('p'), move_up }, /* C-p like emacs */
2160 { XCTRL('n'), move_down }, /* C-n like emacs */
2161 { XCTRL('s'), start_search }, /* C-s like emacs */
2162 { ALT('s'), start_search }, /* M-s not like emacs */
2163 { XCTRL('t'), mark_file },
2164 { ALT('o'), chdir_other_panel },
2165 { ALT('l'), chdir_to_readlink },
2166 { KEY_F(13), view_simple_cmd },
2167 { KEY_F(14), edit_cmd_new },
2168 { ALT('y'), directory_history_prev },
2169 { ALT('u'), directory_history_next },
2170 { ALT('H'), directory_history_list },
2171 { ALT('+'), select_cmd_panel },
2172 { KEY_KP_ADD, select_cmd_panel },
2173 { ALT('\\'), unselect_cmd_panel },
2174 { ALT('-'), unselect_cmd_panel },
2175 { KEY_KP_SUBTRACT, unselect_cmd_panel },
2176 { ALT('*'), reverse_selection_cmd_panel },
2177 { KEY_KP_MULTIPLY, reverse_selection_cmd_panel },
2178
2179
2180 #ifdef HAVE_GNOME
2181 { '+', select_cmd_panel },
2182 { '\\', unselect_cmd_panel },
2183 { '-', unselect_cmd_panel },
2184 { '*', reverse_selection_cmd_panel },
2185 { XCTRL('r'), reread_cmd },
2186 { KEY_F(3), view_panel_cmd },
2187 { KEY_F(5), copy_cmd },
2188 { KEY_F(6), ren_cmd },
2189 { KEY_F(7), mkdir_panel_cmd },
2190 { KEY_F(8), delete_cmd },
2191 #endif
2192
2193 { 0, 0 }
2194 };
2195
2196 static inline int
2197 panel_key (WPanel *panel, int key)
2198 {
2199 int i;
2200
2201 for (i = 0; panel_keymap [i].key_code; i++){
2202 if (key == panel_keymap [i].key_code){
2203 if (panel_keymap [i].fn != start_search)
2204 panel->searching = 0;
2205 (*panel_keymap [i].fn)(panel);
2206 return 1;
2207 }
2208 }
2209 if (torben_fj_mode && key == ALT('h')) {
2210 goto_middle_file (panel);
2211 return 1;
2212 }
2213
2214 /* We do not want to take a key press if nothing can be done with it */
2215 /* The command line widget may do something more usefull */
2216 if (key == KEY_LEFT)
2217 return move_left (panel, key);
2218
2219 if (key == KEY_RIGHT)
2220 return move_right (panel, key);
2221
2222 if (is_abort_char (key)) {
2223 panel->searching = 0;
2224 display_mini_info (panel);
2225 return 1;
2226 }
2227
2228 /* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
2229 if ((key >= ' '&& key <= 255) || key == 8 || key == KEY_BACKSPACE) {
2230 if (panel->searching){
2231 do_search (panel, key);
2232 return 1;
2233 }
2234
2235 if (!command_prompt) {
2236 start_search (panel);
2237 do_search (panel, key);
2238 return 1;
2239 }
2240 }
2241
2242 return 0;
2243 }
2244
2245 static int
2246 panel_callback (Dlg_head *h, WPanel *panel, int msg, int par)
2247 {
2248 switch (msg){
2249 case WIDGET_INIT:
2250 #ifdef HAVE_X
2251 define_label (h, (Widget *)panel, 1, _("Help"), help_cmd);
2252 define_label (h, (Widget *)panel, 2, _("Menu"), user_menu_cmd);
2253 define_label (h, (Widget *)panel, 3, _("View"), view_panel_cmd);
2254 define_label (h, (Widget *)panel, 4, _("Edit"), edit_panel_cmd);
2255 define_label (h, (Widget *)panel, 5, _("Copy"), copy_cmd);
2256 define_label (h, (Widget *)panel, 6, _("RenMov"), ren_cmd);
2257 define_label (h, (Widget *)panel, 7, _("Mkdir"), mkdir_panel_cmd);
2258 define_label (h, (Widget *)panel, 8, _("Delete"), delete_cmd);
2259 x_create_panel (h, h->wdata, panel);
2260 #endif
2261 return 1;
2262
2263 case WIDGET_DRAW:
2264 #ifndef HAVE_XVIEW
2265 paint_panel (panel);
2266 #else
2267 show_dir (panel);
2268 #endif
2269 break;
2270
2271 case WIDGET_FOCUS:
2272 #ifndef HAVE_GNOME
2273 current_panel = panel;
2274 #endif
2275 panel->active = 1;
2276 if (mc_chdir (panel->cwd) != 0){
2277 message (1, " Error ", " Can't chdir to %s \n %s ",
2278 panel->cwd, unix_error_string (errno));
2279 } else
2280 subshell_chdir (panel->cwd);
2281
2282 show_dir (panel);
2283 focus_select_item (panel);
2284 #ifndef HAVE_X
2285 define_label (h, (Widget *)panel, 1, _("Help"), help_cmd);
2286 define_label (h, (Widget *)panel, 2, _("Menu"), user_menu_cmd);
2287 define_label (h, (Widget *)panel, 3, _("View"), view_panel_cmd);
2288 define_label (h, (Widget *)panel, 4, _("Edit"), edit_panel_cmd);
2289 define_label (h, (Widget *)panel, 5, _("Copy"), copy_cmd);
2290 define_label (h, (Widget *)panel, 6, _("RenMov"), ren_cmd);
2291 define_label (h, (Widget *)panel, 7, _("Mkdir"), mkdir_panel_cmd);
2292 define_label (h, (Widget *)panel, 8, _("Delete"), delete_cmd);
2293 redraw_labels (h, (Widget *)panel);
2294 #endif
2295 /* Chain behaviour */
2296 default_proc (h, WIDGET_FOCUS, par);
2297 return 1;
2298
2299 case WIDGET_UNFOCUS:
2300 /* Janne: look at this for the multiple panel options */
2301 if (panel->searching){
2302 panel->searching = 0;
2303 display_mini_info (panel);
2304 }
2305 #ifdef HAVE_X
2306 show_dir (panel);
2307 unfocus_unselect_item (panel);
2308 panel->active = 0;
2309 #else
2310 panel->active = 0;
2311 show_dir (panel);
2312 unselect_item (panel);
2313 #endif
2314 return 1;
2315
2316 case WIDGET_KEY:
2317 return panel_key (panel, par);
2318 break;
2319 }
2320 return default_proc (h, msg, par);
2321 }
2322
2323 /* */
2324 /* Panel mouse events support routines */
2325 /* */
2326 static int mouse_marking = 0;
2327
2328 static void
2329 mouse_toggle_mark (WPanel *panel)
2330 {
2331 do_mark_file (panel, 0);
2332 mouse_marking = selection (panel)->f.marked;
2333 }
2334
2335 static void
2336 mouse_set_mark (WPanel *panel)
2337 {
2338 if (mouse_marking && !(selection (panel)->f.marked))
2339 do_mark_file (panel, 0);
2340 else if (!mouse_marking && (selection (panel)->f.marked))
2341 do_mark_file (panel, 0);
2342 }
2343
2344 static inline int
2345 mark_if_marking (WPanel *panel, Gpm_Event *event)
2346 {
2347 if (event->buttons & GPM_B_RIGHT){
2348 if (event->type & GPM_DOWN)
2349 mouse_toggle_mark (panel);
2350 else
2351 mouse_set_mark (panel);
2352 return 1;
2353 }
2354 return 0;
2355 }
2356
2357 void
2358 file_mark (WPanel *panel, int index, int val)
2359 {
2360 panel->dir.list [index].f.marked = val;
2361 x_panel_select_item (panel, index, val);
2362 }
2363
2364 #ifdef PORT_WANTS_GET_SORT_FN
2365 sortfn *
2366 get_sort_fn (char *name)
2367 {
2368 int i;
2369
2370 /* First, try the long name options, from dir.c */
2371 for (i = 0; i < SORT_TYPES_TOTAL; i++)
2372 if (strcmp (name, sort_orders [i].sort_name) == 0)
2373 return (sortfn *)sort_orders [i].sort_fn;
2374
2375 /* Then try the short name options, from our local table */
2376 for (i = 0; i < ELEMENTS (formats); i++){
2377 if (strcmp (name, formats [i].id) == 0 && formats [i].sort_routine)
2378 return formats [i].sort_routine;
2379 }
2380 return NULL;
2381 }
2382
2383 /* not static because it's called from Tk's version */
2384 int
2385 panel_event (Gpm_Event *event, WPanel *panel)
2386 {
2387 const int lines = panel->count;
2388
2389 int my_index;
2390 extern void change_panel (void);
2391
2392 event->y -= 2;
2393 if ((event->type & (GPM_DOWN|GPM_DRAG))){
2394
2395 if (panel != (WPanel *) current_dlg->current->widget)
2396 change_panel ();
2397
2398 if (event->y <= 0){
2399 mark_if_marking (panel, event);
2400 return MOU_REPEAT;
2401 }
2402
2403 if (!((panel->top_file + event->y <= panel->count) &&
2404 event->y <= lines)){
2405 mark_if_marking (panel, event);
2406 return MOU_REPEAT;
2407 }
2408 my_index = panel->top_file + event->y - 1;
2409 if (panel->split){
2410 if (event->x > ((panel->widget.cols-2)/2))
2411 my_index += llines (panel);
2412 }
2413
2414 if (my_index >= panel->count)
2415 my_index = panel->count - 1;
2416
2417 if (my_index != panel->selected){
2418 unselect_item (panel);
2419 panel->selected = my_index;
2420 select_item (panel);
2421 }
2422
2423 /* This one is new */
2424 mark_if_marking (panel, event);
2425
2426 } else if ((event->type & (GPM_UP|GPM_DOUBLE)) == (GPM_UP|GPM_DOUBLE)){
2427 if (event->y > 0 && event->y <= lines)
2428 do_enter (panel);
2429 }
2430 return MOU_NORMAL;
2431 }
2432
2433 #else
2434
2435 int
2436 panel_event (Gpm_Event *event, WPanel *panel)
2437 {
2438 const int lines = llines (panel);
2439
2440 int my_index;
2441 extern void change_panel (void);
2442
2443 if (event->type & GPM_DOWN && event->x == 1 + 1 && event->y == 0 + 1) {
2444 directory_history_prev (panel);
2445 return MOU_NORMAL;
2446 }
2447
2448 if (event->type & GPM_DOWN && event->x == panel->widget.cols - 2 + 1 && event->y == 0 + 1) {
2449 directory_history_next (panel);
2450 return MOU_NORMAL;
2451 }
2452
2453 if (event->type & GPM_DOWN && event->x == panel->widget.cols - 3 + 1 && event->y == 0 + 1) {
2454 directory_history_list (panel);
2455 return MOU_NORMAL;
2456 }
2457
2458 event->y -= 2;
2459 if ((event->type & (GPM_DOWN|GPM_DRAG))){
2460
2461 if (panel != (WPanel *) current_dlg->current->widget)
2462 change_panel ();
2463
2464 if (event->y <= 0){
2465 mark_if_marking (panel, event);
2466 if (mouse_move_pages)
2467 prev_page (panel);
2468 else
2469 move_up (panel);
2470 return MOU_REPEAT;
2471 }
2472
2473 if (!((panel->top_file + event->y <= panel->count) &&
2474 event->y <= lines)){
2475 mark_if_marking (panel, event);
2476 if (mouse_move_pages)
2477 next_page (panel);
2478 else
2479 move_down (panel);
2480 return MOU_REPEAT;
2481 }
2482 my_index = panel->top_file + event->y - 1;
2483 if (panel->split){
2484 if (event->x > ((panel->widget.cols-2)/2))
2485 my_index += llines (panel);
2486 }
2487
2488 if (my_index >= panel->count)
2489 my_index = panel->count - 1;
2490
2491 if (my_index != panel->selected){
2492 unselect_item (panel);
2493 panel->selected = my_index;
2494 select_item (panel);
2495 }
2496
2497 /* This one is new */
2498 mark_if_marking (panel, event);
2499
2500 } else if ((event->type & (GPM_UP|GPM_DOUBLE)) == (GPM_UP|GPM_DOUBLE)){
2501 if (event->y > 0 && event->y <= lines)
2502 do_enter (panel);
2503 }
2504 return MOU_NORMAL;
2505 }
2506 #endif
2507
2508 void
2509 panel_update_marks (WPanel *panel)
2510 {
2511 #ifdef PORT_HAS_UPDATE_MARKS
2512 x_panel_update_marks (panel);
2513 #endif
2514 }