*** empty log message ***
[midnight-commander.git] / src / win.c
blobd49427ab0be8e468eba1fdc8d014160141441c52
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 #ifndef HAVE_X
38 typedef void (*fnptr)(void);
40 typedef struct Fkey_Table_List {
41 fnptr actions[11];
42 struct Fkey_Table_List *next;
43 int has_labels;
44 } Fkey_Table_List;
46 static Fkey_Table_List *fkey_table_list = NULL;
48 /* Return values: 0 = not a fkey, other = was a fkey */
49 int check_fkeys (int c)
51 int fkey;
53 if (!fkey_table_list)
54 return 0;
56 switch (c){
57 case KEY_F(1):
58 fkey = 1;
59 break;
60 case KEY_F(2):
61 fkey = 2;
62 break;
63 case KEY_F(3):
64 fkey = 3;
65 break;
66 case KEY_F(4):
67 fkey = 4;
68 break;
69 case KEY_F(5):
70 fkey = 5;
71 break;
72 case KEY_F(6):
73 fkey = 6;
74 break;
75 case KEY_F(7):
76 fkey = 7;
77 break;
78 case KEY_F(8):
79 fkey = 8;
80 break;
81 case KEY_F(9):
82 fkey = 9;
83 break;
84 case KEY_F(10):
85 fkey = 10;
86 break;
87 default:
88 return 0;
90 if (fkey_table_list->actions [fkey]){
91 fkey_table_list->actions [fkey] ();
92 return fkey;
94 else
95 return 0;
97 #endif /* !HAVE_X */
99 /* Return values: 0 = not a movement key, 1 = was a movement key */
100 int check_movement_keys (int c, int additional, int page_size, void *data,
101 movefn backfn, movefn forfn, movefn topfn,
102 movefn bottomfn)
104 switch (c){
105 case KEY_UP:
106 case XCTRL ('p'):
107 (*backfn)(data, 1);
108 return 1;
110 case KEY_DOWN:
111 case XCTRL ('n'):
112 (*forfn)(data, 1);
113 return 1;
115 case KEY_PPAGE:
116 case ALT('v'):
117 (*backfn)(data, page_size-1);
118 return 1;
120 case KEY_NPAGE:
121 case XCTRL('v'):
122 (*forfn)(data, page_size-1);
123 return 1;
125 case KEY_HOME:
126 case KEY_A1:
127 (*topfn)(data, 0);
128 return 1;
129 case KEY_END:
130 case KEY_C1:
131 (*bottomfn)(data, 0);
132 return 1;
134 if (additional)
135 switch (c){
136 case 'b':
137 case XCTRL('h'):
138 case KEY_BACKSPACE:
139 case 0177:
140 (*backfn)(data, page_size-1);
141 return 1;
142 case ' ':
143 (*forfn)(data, page_size-1);
144 return 1;
145 case 'u':
146 (*backfn)(data, page_size / 2);
147 return 1;
148 case 'd':
149 (*forfn)(data, page_size / 2);
150 return 1;
151 case 'g':
152 (*topfn)(data, 0);
153 return 1;
154 case 'G':
155 (*bottomfn)(data, 0);
156 return 1;
158 return 0;
161 /* Classification routines */
162 int is_abort_char (int c)
164 return (c == XCTRL('c') || c == XCTRL('g') || c == ESC_CHAR ||
165 c == KEY_F(10));
168 #ifndef HAVE_X
169 void mc_raw_mode (void)
171 raw ();
174 void mc_noraw_mode (void)
176 noraw ();
179 int is_quit_char (int c)
181 return (c == XCTRL('g') || (c == ESC_CHAR) || (c == KEY_F(10)));
184 /* This table is a mapping between names and the constants we use
185 * We use this to allow users to define alternate definitions for
186 * certain keys that may be missing from the terminal database
188 key_code_name_t key_name_conv_tab [] = {
189 /* KEY_F(0) is not here, since we are mapping it to f10, so there is no reason
190 to define f0 as well. Also, it makes Learn keys a bunch of problems :( */
191 { KEY_F(1), "f1", N_("Function key 1") },
192 { KEY_F(2), "f2", N_("Function key 2") },
193 { KEY_F(3), "f3", N_("Function key 3") },
194 { KEY_F(4), "f4", N_("Function key 4") },
195 { KEY_F(5), "f5", N_("Function key 5") },
196 { KEY_F(6), "f6", N_("Function key 6") },
197 { KEY_F(7), "f7", N_("Function key 7") },
198 { KEY_F(8), "f8", N_("Function key 8") },
199 { KEY_F(9), "f9", N_("Function key 9") },
200 { KEY_F(10), "f10", N_("Function key 10") },
201 { KEY_F(11), "f11", N_("Function key 11") },
202 { KEY_F(12), "f12", N_("Function key 12") },
203 { KEY_F(13), "f13", N_("Function key 13") },
204 { KEY_F(14), "f14", N_("Function key 14") },
205 { KEY_F(15), "f15", N_("Function key 15") },
206 { KEY_F(16), "f16", N_("Function key 16") },
207 { KEY_F(17), "f17", N_("Function key 17") },
208 { KEY_F(18), "f18", N_("Function key 18") },
209 { KEY_F(19), "f19", N_("Function key 19") },
210 { KEY_F(20), "f20", N_("Function key 20") },
211 { KEY_BACKSPACE, "bs", N_("Backspace key") },
212 { KEY_END, "end", N_("End key") },
213 { KEY_UP, "up", N_("Up arrow key") },
214 { KEY_DOWN, "down", N_("Down arrow key") },
215 { KEY_LEFT, "left", N_("Left arrow key") },
216 { KEY_RIGHT, "right", N_("Right arrow key") },
217 { KEY_HOME, "home", N_("Home key") },
218 { KEY_NPAGE, "pgdn", N_("Page Down key") },
219 { KEY_PPAGE, "pgup", N_("Page Up key") },
220 { KEY_IC, "insert", N_("Insert key") },
221 { KEY_DC, "delete", N_("Delete key") },
222 { ALT('\t'), "complete", N_("Completion/M-tab") },
223 { KEY_KP_ADD, "kpplus", N_("+ on keypad") },
224 { KEY_KP_SUBTRACT,"kpminus", N_("- on keypad") },
225 { KEY_KP_MULTIPLY,"kpasterix", N_("* on keypad") },
226 /* From here on, these won't be shown in Learn keys (no space) */
227 { KEY_LEFT, "kpleft", N_("Left arrow keypad") },
228 { KEY_RIGHT, "kpright", N_("Right arrow keypad") },
229 { KEY_UP, "kpup", N_("Up arrow keypad") },
230 { KEY_DOWN, "kpdown", N_("Down arrow keypad") },
231 { KEY_HOME, "kphome", N_("Home on keypad") },
232 { KEY_END, "kpend", N_("End on keypad") },
233 { KEY_NPAGE, "kpnpage", N_("Page Down keypad") },
234 { KEY_PPAGE, "kpppage", N_("Page Up keypad") },
235 { KEY_IC, "kpinsert", N_("Insert on keypad") },
236 { KEY_DC, "kpdelete", N_("Delete on keypad") },
237 { (int) '\n', "kpenter", N_("Enter on keypad") },
238 { (int) '/', "kpslash", N_("Slash on keypad") },
239 { (int) '#', "kpnumlock", N_("NumLock on keypad") },
240 { 0, 0 }
243 /* Return the code associated with the symbolic name keyname */
244 int lookup_key (char *keyname)
246 int i;
248 for (i = 0; key_name_conv_tab [i].code; i++){
249 if ( g_strcasecmp (key_name_conv_tab [i].name, keyname))
250 continue;
251 return key_name_conv_tab [i].code;
253 return 0;
256 #endif /* !HAVE_X */