Editor: sync with new global config location (user menu and syntax files).
[midnight-commander.git] / src / win.c
blobbf53c8b6af2f201d1481591e6e97c692f6df1006
1 /* Curses utilities
2 Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2007 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 /** \file win.c
20 * \brief Source: curses utilities
23 #include <config.h>
25 #include <stdio.h>
26 #include <string.h>
28 #ifdef HAVE_TERMIOS_H
29 #include <termios.h>
30 #endif
32 #include "global.h"
33 #include "tty.h"
34 #include "color.h"
35 #include "mouse.h"
36 #include "dialog.h"
37 #include "widget.h"
38 #include "win.h"
39 #include "key.h" /* XCTRL and ALT macros */
40 #include "layout.h"
41 #include "strutil.h"
44 * Common handler for standard movement keys in a text area. Provided
45 * functions are called with the "data" argument. backfn and forfn also
46 * get an argument indicating how many lines to scroll. Return 1 if
47 * the key was handled, 0 otherwise.
49 int
50 check_movement_keys (int key, int page_size, void *data, movefn backfn,
51 movefn forfn, movefn topfn, movefn bottomfn)
53 switch (key) {
54 case KEY_UP:
55 case XCTRL ('p'):
56 (*backfn) (data, 1);
57 break;
59 case KEY_DOWN:
60 case XCTRL ('n'):
61 (*forfn) (data, 1);
62 break;
64 case KEY_PPAGE:
65 case ALT ('v'):
66 (*backfn) (data, page_size - 1);
67 break;
69 case KEY_NPAGE:
70 case XCTRL ('v'):
71 (*forfn) (data, page_size - 1);
72 break;
74 case KEY_HOME:
75 case KEY_M_CTRL | KEY_HOME:
76 case KEY_M_CTRL | KEY_PPAGE:
77 case KEY_A1:
78 case ALT ('<'):
79 (*topfn) (data, 0);
80 break;
82 case KEY_END:
83 case KEY_M_CTRL | KEY_END:
84 case KEY_M_CTRL | KEY_NPAGE:
85 case KEY_C1:
86 case ALT ('>'):
87 (*bottomfn) (data, 0);
88 break;
90 case 'b':
91 case KEY_BACKSPACE:
92 (*backfn) (data, page_size - 1);
93 break;
95 case ' ':
96 (*forfn) (data, page_size - 1);
97 break;
99 case 'u':
100 (*backfn) (data, page_size / 2);
101 break;
103 case 'd':
104 (*forfn) (data, page_size / 2);
105 break;
107 case 'g':
108 (*topfn) (data, 0);
109 break;
111 case 'G':
112 (*bottomfn) (data, 0);
113 break;
115 default:
116 return MSG_NOT_HANDLED;
118 return MSG_HANDLED;
121 /* Classification routines */
122 int is_abort_char (int c)
124 return (c == XCTRL('c') || c == XCTRL('g') || c == ESC_CHAR ||
125 c == KEY_F(10));
128 void mc_raw_mode (void)
130 raw ();
133 void mc_noraw_mode (void)
135 noraw ();
138 /* This flag is set by xterm detection routine in function main() */
139 /* It is used by function view_other_cmd() */
140 int xterm_flag = 0;
142 /* The following routines only work on xterm terminals */
144 void do_enter_ca_mode (void)
146 if (!xterm_flag)
147 return;
148 fprintf (stdout, /* ESC_STR ")0" */ ESC_STR "7" ESC_STR "[?47h");
149 fflush (stdout);
152 void do_exit_ca_mode (void)
154 if (!xterm_flag)
155 return;
156 fprintf (stdout, ESC_STR "[?47l" ESC_STR "8" ESC_STR "[m");
157 fflush (stdout);
160 /* This table is a mapping between names and the constants we use
161 * We use this to allow users to define alternate definitions for
162 * certain keys that may be missing from the terminal database
164 key_code_name_t key_name_conv_tab [] = {
165 /* KEY_F(0) is not here, since we are mapping it to f10, so there is no reason
166 to define f0 as well. Also, it makes Learn keys a bunch of problems :( */
167 { KEY_F(1), "f1", N_("Function key 1") },
168 { KEY_F(2), "f2", N_("Function key 2") },
169 { KEY_F(3), "f3", N_("Function key 3") },
170 { KEY_F(4), "f4", N_("Function key 4") },
171 { KEY_F(5), "f5", N_("Function key 5") },
172 { KEY_F(6), "f6", N_("Function key 6") },
173 { KEY_F(7), "f7", N_("Function key 7") },
174 { KEY_F(8), "f8", N_("Function key 8") },
175 { KEY_F(9), "f9", N_("Function key 9") },
176 { KEY_F(10), "f10", N_("Function key 10") },
177 { KEY_F(11), "f11", N_("Function key 11") },
178 { KEY_F(12), "f12", N_("Function key 12") },
179 { KEY_F(13), "f13", N_("Function key 13") },
180 { KEY_F(14), "f14", N_("Function key 14") },
181 { KEY_F(15), "f15", N_("Function key 15") },
182 { KEY_F(16), "f16", N_("Function key 16") },
183 { KEY_F(17), "f17", N_("Function key 17") },
184 { KEY_F(18), "f18", N_("Function key 18") },
185 { KEY_F(19), "f19", N_("Function key 19") },
186 { KEY_F(20), "f20", N_("Function key 20") },
187 { KEY_BACKSPACE, "bs", N_("Backspace key") },
188 { KEY_END, "end", N_("End key") },
189 { KEY_UP, "up", N_("Up arrow key") },
190 { KEY_DOWN, "down", N_("Down arrow key") },
191 { KEY_LEFT, "left", N_("Left arrow key") },
192 { KEY_RIGHT, "right", N_("Right arrow key") },
193 { KEY_HOME, "home", N_("Home key") },
194 { KEY_NPAGE, "pgdn", N_("Page Down key") },
195 { KEY_PPAGE, "pgup", N_("Page Up key") },
196 { KEY_IC, "insert", N_("Insert key") },
197 { KEY_DC, "delete", N_("Delete key") },
198 { ALT('\t'), "complete", N_("Completion/M-tab") },
199 { KEY_KP_ADD, "kpplus", N_("+ on keypad") },
200 { KEY_KP_SUBTRACT,"kpminus", N_("- on keypad") },
201 { KEY_KP_MULTIPLY,"kpasterix", N_("* on keypad") },
202 /* From here on, these won't be shown in Learn keys (no space) */
203 { KEY_LEFT, "kpleft", N_("Left arrow keypad") },
204 { KEY_RIGHT, "kpright", N_("Right arrow keypad") },
205 { KEY_UP, "kpup", N_("Up arrow keypad") },
206 { KEY_DOWN, "kpdown", N_("Down arrow keypad") },
207 { KEY_HOME, "kphome", N_("Home on keypad") },
208 { KEY_END, "kpend", N_("End on keypad") },
209 { KEY_NPAGE, "kpnpage", N_("Page Down keypad") },
210 { KEY_PPAGE, "kpppage", N_("Page Up keypad") },
211 { KEY_IC, "kpinsert", N_("Insert on keypad") },
212 { KEY_DC, "kpdelete", N_("Delete on keypad") },
213 { (int) '\n', "kpenter", N_("Enter on keypad") },
214 { (int) '/', "kpslash", N_("Slash on keypad") },
215 { (int) '#', "kpnumlock", N_("NumLock on keypad") },
216 { 0, 0, 0 }
219 /* Return the code associated with the symbolic name keyname */
220 int lookup_key (char *keyname)
222 int i;
224 for (i = 0; key_name_conv_tab [i].code; i++){
225 if (str_casecmp (key_name_conv_tab [i].name, keyname))
226 continue;
227 return key_name_conv_tab [i].code;
229 return 0;