fix panel_scroll_pages start page
[midnight-commander.git] / src / win.c
blob4c4654aab20e43dea4ce3ebff263920af27ab0c5
1 /* Curses utilities
2 Copyright (C) 1995 Miguel de Icaza, Janne Kukonlehto
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.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 #include <config.h>
19 #include <stdio.h>
20 #include <string.h>
21 #ifdef HAVE_TERMIOS_H
22 # include <termios.h>
23 #endif
25 #include "global.h"
26 #include "tty.h"
27 #include "color.h"
28 #include "mouse.h"
29 #include "dlg.h"
30 #include "widget.h"
31 #include "win.h"
32 #include "key.h" /* XCTRL and ALT macros */
33 #include "layout.h"
35 /* "$Id$" */
37 typedef void (*fnptr)(void);
39 typedef struct Fkey_Table_List {
40 fnptr actions[11];
41 struct Fkey_Table_List *next;
42 int has_labels;
43 } Fkey_Table_List;
45 static Fkey_Table_List *fkey_table_list = NULL;
47 /* Return values: 0 = not a fkey, other = was a fkey */
48 int check_fkeys (int c)
50 int fkey;
52 if (!fkey_table_list)
53 return 0;
55 switch (c){
56 case KEY_F(1):
57 fkey = 1;
58 break;
59 case KEY_F(2):
60 fkey = 2;
61 break;
62 case KEY_F(3):
63 fkey = 3;
64 break;
65 case KEY_F(4):
66 fkey = 4;
67 break;
68 case KEY_F(5):
69 fkey = 5;
70 break;
71 case KEY_F(6):
72 fkey = 6;
73 break;
74 case KEY_F(7):
75 fkey = 7;
76 break;
77 case KEY_F(8):
78 fkey = 8;
79 break;
80 case KEY_F(9):
81 fkey = 9;
82 break;
83 case KEY_F(10):
84 fkey = 10;
85 break;
86 default:
87 return 0;
89 if (fkey_table_list->actions [fkey]){
90 fkey_table_list->actions [fkey] ();
91 return fkey;
93 else
94 return 0;
97 /* Return values: 0 = not a movement key, 1 = was a movement key */
98 int check_movement_keys (int c, int additional, int page_size, void *data,
99 movefn backfn, movefn forfn, movefn topfn,
100 movefn bottomfn)
102 switch (c){
103 case KEY_UP:
104 case XCTRL ('p'):
105 (*backfn)(data, 1);
106 return 1;
108 case KEY_DOWN:
109 case XCTRL ('n'):
110 (*forfn)(data, 1);
111 return 1;
113 case KEY_PPAGE:
114 case ALT('v'):
115 (*backfn)(data, page_size-1);
116 return 1;
118 case KEY_NPAGE:
119 case XCTRL('v'):
120 (*forfn)(data, page_size-1);
121 return 1;
123 case KEY_HOME:
124 case KEY_A1:
125 (*topfn)(data, 0);
126 return 1;
127 case KEY_END:
128 case KEY_C1:
129 (*bottomfn)(data, 0);
130 return 1;
132 if (additional)
133 switch (c){
134 case 'b':
135 case XCTRL('h'):
136 case KEY_BACKSPACE:
137 case 0177:
138 (*backfn)(data, page_size-1);
139 return 1;
140 case ' ':
141 (*forfn)(data, page_size-1);
142 return 1;
143 case 'u':
144 (*backfn)(data, page_size / 2);
145 return 1;
146 case 'd':
147 (*forfn)(data, page_size / 2);
148 return 1;
149 case 'g':
150 (*topfn)(data, 0);
151 return 1;
152 case 'G':
153 (*bottomfn)(data, 0);
154 return 1;
156 return 0;
159 /* Classification routines */
160 int is_abort_char (int c)
162 return (c == XCTRL('c') || c == XCTRL('g') || c == ESC_CHAR ||
163 c == KEY_F(10));
166 void mc_raw_mode (void)
168 raw ();
171 void mc_noraw_mode (void)
173 noraw ();
176 int is_quit_char (int c)
178 return (c == XCTRL('g') || (c == ESC_CHAR) || (c == KEY_F(10)));
181 /* This table is a mapping between names and the constants we use
182 * We use this to allow users to define alternate definitions for
183 * certain keys that may be missing from the terminal database
185 key_code_name_t key_name_conv_tab [] = {
186 /* KEY_F(0) is not here, since we are mapping it to f10, so there is no reason
187 to define f0 as well. Also, it makes Learn keys a bunch of problems :( */
188 { KEY_F(1), "f1", N_("Function key 1") },
189 { KEY_F(2), "f2", N_("Function key 2") },
190 { KEY_F(3), "f3", N_("Function key 3") },
191 { KEY_F(4), "f4", N_("Function key 4") },
192 { KEY_F(5), "f5", N_("Function key 5") },
193 { KEY_F(6), "f6", N_("Function key 6") },
194 { KEY_F(7), "f7", N_("Function key 7") },
195 { KEY_F(8), "f8", N_("Function key 8") },
196 { KEY_F(9), "f9", N_("Function key 9") },
197 { KEY_F(10), "f10", N_("Function key 10") },
198 { KEY_F(11), "f11", N_("Function key 11") },
199 { KEY_F(12), "f12", N_("Function key 12") },
200 { KEY_F(13), "f13", N_("Function key 13") },
201 { KEY_F(14), "f14", N_("Function key 14") },
202 { KEY_F(15), "f15", N_("Function key 15") },
203 { KEY_F(16), "f16", N_("Function key 16") },
204 { KEY_F(17), "f17", N_("Function key 17") },
205 { KEY_F(18), "f18", N_("Function key 18") },
206 { KEY_F(19), "f19", N_("Function key 19") },
207 { KEY_F(20), "f20", N_("Function key 20") },
208 { KEY_BACKSPACE, "bs", N_("Backspace key") },
209 { KEY_END, "end", N_("End key") },
210 { KEY_UP, "up", N_("Up arrow key") },
211 { KEY_DOWN, "down", N_("Down arrow key") },
212 { KEY_LEFT, "left", N_("Left arrow key") },
213 { KEY_RIGHT, "right", N_("Right arrow key") },
214 { KEY_HOME, "home", N_("Home key") },
215 { KEY_NPAGE, "pgdn", N_("Page Down key") },
216 { KEY_PPAGE, "pgup", N_("Page Up key") },
217 { KEY_IC, "insert", N_("Insert key") },
218 { KEY_DC, "delete", N_("Delete key") },
219 { ALT('\t'), "complete", N_("Completion/M-tab") },
220 { KEY_KP_ADD, "kpplus", N_("+ on keypad") },
221 { KEY_KP_SUBTRACT,"kpminus", N_("- on keypad") },
222 { KEY_KP_MULTIPLY,"kpasterix", N_("* on keypad") },
223 /* From here on, these won't be shown in Learn keys (no space) */
224 { KEY_LEFT, "kpleft", N_("Left arrow keypad") },
225 { KEY_RIGHT, "kpright", N_("Right arrow keypad") },
226 { KEY_UP, "kpup", N_("Up arrow keypad") },
227 { KEY_DOWN, "kpdown", N_("Down arrow keypad") },
228 { KEY_HOME, "kphome", N_("Home on keypad") },
229 { KEY_END, "kpend", N_("End on keypad") },
230 { KEY_NPAGE, "kpnpage", N_("Page Down keypad") },
231 { KEY_PPAGE, "kpppage", N_("Page Up keypad") },
232 { KEY_IC, "kpinsert", N_("Insert on keypad") },
233 { KEY_DC, "kpdelete", N_("Delete on keypad") },
234 { (int) '\n', "kpenter", N_("Enter on keypad") },
235 { (int) '/', "kpslash", N_("Slash on keypad") },
236 { (int) '#', "kpnumlock", N_("NumLock on keypad") },
237 { 0, 0, 0 }
240 /* Return the code associated with the symbolic name keyname */
241 int lookup_key (char *keyname)
243 int i;
245 for (i = 0; key_name_conv_tab [i].code; i++){
246 if ( g_strcasecmp (key_name_conv_tab [i].name, keyname))
247 continue;
248 return key_name_conv_tab [i].code;
250 return 0;