comparison src/w32inevt.c @ 11386:62e2ab942896

(do_mouse_event): Use XSETFASTINT. (SET_FRAME): Undefined. (select): Renamed to sys_select to correspond to routine in sysdep.c (sys_select): Support struct timeval. (key_event): Support German keyboard. Replace SET_FRAME with XSETFRAME. (nt_kbd_mods_to_emacs): Renamed to win32_kbd_mods_to_emacs. (win32_kbd_mods_to_emacs): Support AltGr on German keyboards. (win32_number_shift_map): Defined. (WIN32_KEY_SHIFTED): Defined. (win32_patch_key): Defined. (map_virt_key): Support VK_OEM_102 for German keyboards. (win32_mouse_position): Add arg insist. (do_mouse_event): Replace SET_FRAME with XSETFRAME. Use win32_kbd_mods_to_emacs.
author Karl Heuer <kwzh@gnu.org>
date Wed, 12 Apr 1995 02:23:35 +0000
parents e0c580dd4251
children 85bdcc694c7a
comparison
equal deleted inserted replaced
11385:5eb009221225 11386:62e2ab942896
1 /* Input event support for Windows NT port of GNU Emacs. 1 /* Input event support for Windows NT port of GNU Emacs.
2 Copyright (C) 1992, 1993 Free Software Foundation, Inc. 2 Copyright (C) 1992, 1993, 1995 Free Software Foundation, Inc.
3 3
4 This file is part of GNU Emacs. 4 This file is part of GNU Emacs.
5 5
6 GNU Emacs is free software; you can redistribute it and/or modify it 6 GNU Emacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the 7 under the terms of the GNU General Public License as published by the
90 get_frame (void) 90 get_frame (void)
91 { 91 {
92 return selected_frame; 92 return selected_frame;
93 } 93 }
94 94
95 #ifdef MULTI_FRAME 95 /* Translate console modifiers to emacs modifiers.
96 #define SET_FRAME(o, f) XSETFRAME (o, f) 96 German keyboard support (Kai Morgan Zeise 2/18/95). */
97 #else
98 #define SET_FRAME(o, f) ((o) = Qnil)
99 #endif
100
101 /* Translate console modifiers to emacs modifiers. */
102 static int 97 static int
103 nt_kbd_mods_to_emacs (DWORD mods) 98 win32_kbd_mods_to_emacs (DWORD mods)
104 { 99 {
105 return ((mods & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) ? 100 int retval = 0;
106 meta_modifier : 0) | 101
107 ((mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) ? 102 /* If AltGr has been pressed, remove it. */
108 ctrl_modifier : 0) | 103 if ((mods & (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED))
109 ((mods & (SHIFT_PRESSED | CAPSLOCK_ON)) ? 104 == (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED))
110 shift_modifier : 0); 105 mods &= ~ (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED);
106
107 if (mods & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED))
108 retval = meta_modifier;
109
110 if (mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
111 {
112 retval |= ctrl_modifier;
113 if ((mods & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
114 == (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
115 retval |= meta_modifier;
116 }
117
118 if (((mods & (SHIFT_PRESSED | CAPSLOCK_ON)) == SHIFT_PRESSED)
119 || ((mods & (SHIFT_PRESSED | CAPSLOCK_ON)) == CAPSLOCK_ON))
120 retval |= shift_modifier;
121
122 return retval;
123 }
124
125 /* Patch up NT keyboard events when info is missing that should be there,
126 assuming that map_virt_key says that the key is a valid ASCII char. */
127 static char win32_number_shift_map[] = {
128 ')', '!', '@', '#', '$', '%', '^', '&', '*', '('
129 };
130
131 #define WIN32_KEY_SHIFTED(mods, no, yes) \
132 ((mods & (SHIFT_PRESSED | CAPSLOCK_ON)) ? yes : no)
133
134 static void
135 win32_kbd_patch_key (KEY_EVENT_RECORD *event)
136 {
137 unsigned int key_code = event->wVirtualKeyCode;
138 unsigned int mods = event->dwControlKeyState;
139 int mapped_punct = 0;
140
141 /* map_virt_key says its a valid key, but the uChar.AsciiChar field
142 is empty. patch up the uChar.AsciiChar field using wVirtualKeyCode. */
143 if (event->uChar.AsciiChar == 0
144 && ((key_code >= '0' && key_code <= '9')
145 || (key_code >= 'A' && key_code <= 'Z')
146 || (key_code >= 0xBA && key_code <= 0xC0)
147 || (key_code >= 0xDB && key_code <= 0xDE)
148 )) {
149 if (key_code >= '0' && key_code <= '9') {
150 event->uChar.AsciiChar =
151 WIN32_KEY_SHIFTED (mods, key_code,
152 win32_number_shift_map[key_code - '0']);
153 return;
154 }
155 switch (key_code) {
156 case 0xBA: mapped_punct = WIN32_KEY_SHIFTED (mods, ';', ':'); break;
157 case 0xBB: mapped_punct = WIN32_KEY_SHIFTED (mods, '=', '+'); break;
158 case 0xBC: mapped_punct = WIN32_KEY_SHIFTED (mods, ',', '<'); break;
159 case 0xBD: mapped_punct = WIN32_KEY_SHIFTED (mods, '-', '_'); break;
160 case 0xBE: mapped_punct = WIN32_KEY_SHIFTED (mods, '.', '>'); break;
161 case 0xBF: mapped_punct = WIN32_KEY_SHIFTED (mods, '/', '?'); break;
162 case 0xC0: mapped_punct = WIN32_KEY_SHIFTED (mods, '`', '~'); break;
163 case 0xDB: mapped_punct = WIN32_KEY_SHIFTED (mods, '[', '{'); break;
164 case 0xDC: mapped_punct = WIN32_KEY_SHIFTED (mods, '\\', '|'); break;
165 case 0xDD: mapped_punct = WIN32_KEY_SHIFTED (mods, ']', '}'); break;
166 case 0xDE: mapped_punct = WIN32_KEY_SHIFTED (mods, '\'', '"'); break;
167 default:
168 mapped_punct = 0;
169 break;
170 }
171 if (mapped_punct) {
172 event->uChar.AsciiChar = mapped_punct;
173 return;
174 }
175 /* otherwise, it's a letter. */
176 event->uChar.AsciiChar = WIN32_KEY_SHIFTED (mods, key_code - 'A' + 'a',
177 key_code);
178 }
111 } 179 }
112 180
113 /* Map virtual key codes into: 181 /* Map virtual key codes into:
114 -1 - Ignore this key 182 -1 - Ignore this key
115 -2 - ASCII char 183 -2 - ASCII char
221 -2, /* [ */ 289 -2, /* [ */
222 -2, /* - */ 290 -2, /* - */
223 -2, /* ] */ 291 -2, /* ] */
224 -2, /* ' */ 292 -2, /* ' */
225 -1, /* 0xdf */ 293 -1, /* 0xdf */
226 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xef */ 294 -1, -1, -2, /* VK_OEM_102 */
295 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xef */
227 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xff */ 296 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 0xff */
228 }; 297 };
229 298
230 static int 299 static int
231 key_event (KEY_EVENT_RECORD *event, struct input_event *emacs_ev) 300 key_event (KEY_EVENT_RECORD *event, struct input_event *emacs_ev)
232 { 301 {
233 int map; 302 int map;
303 static BOOL map_virt_key_init_done;
234 304
235 /* Skip key-up events. */ 305 /* Skip key-up events. */
236 if (event->bKeyDown == FALSE) 306 if (event->bKeyDown == FALSE)
237 return 0; 307 return 0;
238 308
239 if (event->wVirtualKeyCode > 0xff) 309 if (event->wVirtualKeyCode > 0xff)
240 { 310 {
241 printf ("Unknown key code %d\n", event->wVirtualKeyCode); 311 printf ("Unknown key code %d\n", event->wVirtualKeyCode);
242 return 0; 312 return 0;
313 }
314
315 /* Patch needed for German keyboard. Ulrich Leodolter (1/11/95). */
316 if (! map_virt_key_init_done)
317 {
318 short vk;
319
320 if ((vk = VkKeyScan (0x3c)) >= 0 && vk < 256) map_virt_key[vk] = -2; /* less */
321 if ((vk = VkKeyScan (0x3e)) >= 0 && vk < 256) map_virt_key[vk] = -2; /* greater */
322
323 map_virt_key_init_done = TRUE;
243 } 324 }
244 325
245 /* BUGBUG - Ignores the repeat count 326 /* BUGBUG - Ignores the repeat count
246 It's questionable whether we want to obey the repeat count anyway 327 It's questionable whether we want to obey the repeat count anyway
247 since keys usually aren't repeated unless key events back up in 328 since keys usually aren't repeated unless key events back up in
256 } 337 }
257 else if (map == -2) 338 else if (map == -2)
258 { 339 {
259 /* ASCII */ 340 /* ASCII */
260 emacs_ev->kind = ascii_keystroke; 341 emacs_ev->kind = ascii_keystroke;
342 win32_kbd_patch_key (event);
261 XSETINT (emacs_ev->code, event->uChar.AsciiChar); 343 XSETINT (emacs_ev->code, event->uChar.AsciiChar);
262 } 344 }
263 else 345 else
264 { 346 {
265 /* non-ASCII */ 347 /* non-ASCII */
269 * the full X keysym values (2nd byte is 0xff). add it on. 351 * the full X keysym values (2nd byte is 0xff). add it on.
270 */ 352 */
271 map |= 0xff00; 353 map |= 0xff00;
272 XSETINT (emacs_ev->code, map); 354 XSETINT (emacs_ev->code, map);
273 } 355 }
274 SET_FRAME (emacs_ev->frame_or_window, get_frame ()); 356 XSETFRAME (emacs_ev->frame_or_window, get_frame ());
275 emacs_ev->modifiers = nt_kbd_mods_to_emacs (event->dwControlKeyState); 357 emacs_ev->modifiers = win32_kbd_mods_to_emacs (event->dwControlKeyState);
276 emacs_ev->timestamp = GetTickCount (); 358 emacs_ev->timestamp = GetTickCount ();
277 return 1; 359 return 1;
278 } 360 }
279 361
280 /* Mouse position hook. */ 362 /* Mouse position hook. */
281 void 363 void
282 win32_mouse_position (FRAME_PTR *f, int insist, 364 win32_mouse_position (FRAME_PTR *f,
365 int insist,
283 Lisp_Object *bar_window, 366 Lisp_Object *bar_window,
284 enum scroll_bar_part *part, 367 enum scroll_bar_part *part,
285 Lisp_Object *x, 368 Lisp_Object *x,
286 Lisp_Object *y, 369 Lisp_Object *y,
287 unsigned long *time) 370 unsigned long *time)
288 { 371 {
289 BLOCK_INPUT; 372 BLOCK_INPUT;
290 373
374 insist = insist;
375
291 *f = get_frame (); 376 *f = get_frame ();
292 *bar_window = Qnil; 377 *bar_window = Qnil;
293 *part = 0; 378 *part = 0;
294 mouse_moved = 0; 379 mouse_moved = 0;
295 380
369 if (i == NUM_MOUSE_BUTTONS) 454 if (i == NUM_MOUSE_BUTTONS)
370 return 0; 455 return 0;
371 456
372 button_state = event->dwButtonState; 457 button_state = event->dwButtonState;
373 emacs_ev->timestamp = GetTickCount (); 458 emacs_ev->timestamp = GetTickCount ();
374 emacs_ev->modifiers = nt_kbd_mods_to_emacs (event->dwControlKeyState) | 459 emacs_ev->modifiers = win32_kbd_mods_to_emacs (event->dwControlKeyState) |
375 ((event->dwButtonState & mask) ? down_modifier : up_modifier); 460 ((event->dwButtonState & mask) ? down_modifier : up_modifier);
376 461
377 XSETFASTINT (emacs_ev->x, event->dwMousePosition.X); 462 XSETFASTINT (emacs_ev->x, event->dwMousePosition.X);
378 XSETFASTINT (emacs_ev->y, event->dwMousePosition.Y); 463 XSETFASTINT (emacs_ev->y, event->dwMousePosition.Y);
379 SET_FRAME (emacs_ev->frame_or_window, get_frame ()); 464 XSETFRAME (emacs_ev->frame_or_window, get_frame ());
380 465
381 return 1; 466 return 1;
382 } 467 }
383 468
384 static void 469 static void