comparison src/event-msw.c @ 424:11054d720c21 r21-2-20

Import from CVS: tag r21-2-20
author cvs
date Mon, 13 Aug 2007 11:26:11 +0200
parents 95016f13131a
children
comparison
equal deleted inserted replaced
423:28d9c139be4c 424:11054d720c21
96 extern Lisp_Object 96 extern Lisp_Object
97 mswindows_handle_gui_wm_command (struct frame* f, HWND ctrl, WORD id); 97 mswindows_handle_gui_wm_command (struct frame* f, HWND ctrl, WORD id);
98 98
99 static Lisp_Object mswindows_find_frame (HWND hwnd); 99 static Lisp_Object mswindows_find_frame (HWND hwnd);
100 static Lisp_Object mswindows_find_console (HWND hwnd); 100 static Lisp_Object mswindows_find_console (HWND hwnd);
101 static Lisp_Object mswindows_key_to_emacs_keysym(int mswindows_key, int mods); 101 static Lisp_Object mswindows_key_to_emacs_keysym (int mswindows_key, int mods,
102 int extendedp);
102 static int mswindows_modifier_state (BYTE* keymap, int has_AltGr); 103 static int mswindows_modifier_state (BYTE* keymap, int has_AltGr);
103 static void mswindows_set_chord_timer (HWND hwnd); 104 static void mswindows_set_chord_timer (HWND hwnd);
104 static int mswindows_button2_near_enough (POINTS p1, POINTS p2); 105 static int mswindows_button2_near_enough (POINTS p1, POINTS p2);
105 static int mswindows_current_layout_has_AltGr (void); 106 static int mswindows_current_layout_has_AltGr (void);
106 107
142 Decremented in mswindows_dequeue_dispatch_event() */ 143 Decremented in mswindows_dequeue_dispatch_event() */
143 int mswindows_quit_chars_count = 0; 144 int mswindows_quit_chars_count = 0;
144 145
145 /* These are Lisp integers; see DEFVARS in this file for description. */ 146 /* These are Lisp integers; see DEFVARS in this file for description. */
146 int mswindows_dynamic_frame_resize; 147 int mswindows_dynamic_frame_resize;
148 int mswindows_meta_activates_menu;
147 int mswindows_num_mouse_buttons; 149 int mswindows_num_mouse_buttons;
148 int mswindows_mouse_button_max_skew_x; 150 int mswindows_mouse_button_max_skew_x;
149 int mswindows_mouse_button_max_skew_y; 151 int mswindows_mouse_button_max_skew_y;
150 int mswindows_mouse_button_tolerance; 152 int mswindows_mouse_button_tolerance;
151 153
1657 * calling TranslateMessage() unless AltGr is *really* down. */ 1659 * calling TranslateMessage() unless AltGr is *really* down. */
1658 { 1660 {
1659 BYTE keymap[256]; 1661 BYTE keymap[256];
1660 int has_AltGr = mswindows_current_layout_has_AltGr (); 1662 int has_AltGr = mswindows_current_layout_has_AltGr ();
1661 int mods; 1663 int mods;
1664 int extendedp = lParam & 0x1000000;
1662 Lisp_Object keysym; 1665 Lisp_Object keysym;
1663 1666
1664 GetKeyboardState (keymap); 1667 GetKeyboardState (keymap);
1665 mods = mswindows_modifier_state (keymap, has_AltGr); 1668 mods = mswindows_modifier_state (keymap, has_AltGr);
1666 1669
1667 /* Handle those keys for which TranslateMessage won't generate a WM_CHAR */ 1670 /* Handle non-printables */
1668 if (!NILP (keysym = mswindows_key_to_emacs_keysym(wParam, mods))) 1671 if (!NILP (keysym = mswindows_key_to_emacs_keysym (wParam, mods,
1672 extendedp)))
1669 mswindows_enqueue_keypress_event (hwnd, keysym, mods); 1673 mswindows_enqueue_keypress_event (hwnd, keysym, mods);
1670 else 1674 else /* Normal keys & modifiers */
1671 { 1675 {
1672 int quit_ch = CONSOLE_QUIT_CHAR (XCONSOLE (mswindows_find_console (hwnd))); 1676 int quit_ch = CONSOLE_QUIT_CHAR (XCONSOLE (mswindows_find_console (hwnd)));
1673 BYTE keymap_orig[256]; 1677 BYTE keymap_orig[256];
1674 POINT pnt = { LOWORD (GetMessagePos()), HIWORD (GetMessagePos()) }; 1678 POINT pnt = { LOWORD (GetMessagePos()), HIWORD (GetMessagePos()) };
1675 MSG msg; 1679 MSG msg;
1683 1687
1684 /* GetKeyboardState() does not work as documented on Win95. We have 1688 /* GetKeyboardState() does not work as documented on Win95. We have
1685 * to loosely track Left and Right modifiers on behalf of the OS, 1689 * to loosely track Left and Right modifiers on behalf of the OS,
1686 * without screwing up Windows NT which tracks them properly. */ 1690 * without screwing up Windows NT which tracks them properly. */
1687 if (wParam == VK_CONTROL) 1691 if (wParam == VK_CONTROL)
1688 keymap [(lParam & 0x1000000) ? VK_RCONTROL : VK_LCONTROL] |= 0x80; 1692 keymap [extendedp ? VK_RCONTROL : VK_LCONTROL] |= 0x80;
1689 else if (wParam == VK_MENU) 1693 else if (wParam == VK_MENU)
1690 keymap [(lParam & 0x1000000) ? VK_RMENU : VK_LMENU] |= 0x80; 1694 keymap [extendedp ? VK_RMENU : VK_LMENU] |= 0x80;
1691 1695
1692 memcpy (keymap_orig, keymap, 256); 1696 memcpy (keymap_orig, keymap, 256);
1693 1697
1694 /* Remove shift modifier from an ascii character */ 1698 /* Remove shift modifier from an ascii character */
1695 mods &= ~MOD_SHIFT; 1699 mods &= ~MOD_SHIFT;
1732 } /* while */ 1736 } /* while */
1733 SetKeyboardState (keymap_orig); 1737 SetKeyboardState (keymap_orig);
1734 } /* else */ 1738 } /* else */
1735 } 1739 }
1736 /* F10 causes menu activation by default. We do not want this */ 1740 /* F10 causes menu activation by default. We do not want this */
1737 if (wParam != VK_F10) 1741 if (wParam != VK_F10 && (mswindows_meta_activates_menu || wParam != VK_MENU))
1738 goto defproc; 1742 goto defproc;
1739 break; 1743 break;
1740 1744
1741 case WM_MBUTTONDOWN: 1745 case WM_MBUTTONDOWN:
1742 case WM_MBUTTONUP: 1746 case WM_MBUTTONUP:
1980 } 1984 }
1981 break; 1985 break;
1982 1986
1983 case WM_PAINT: 1987 case WM_PAINT:
1984 { 1988 {
1985 PAINTSTRUCT paintStruct; 1989 /* According to the docs we need to check GetUpdateRect() before
1986 1990 actually doing a WM_PAINT */
1987 frame = XFRAME (mswindows_find_frame (hwnd)); 1991 if (GetUpdateRect (hwnd, NULL, FALSE))
1988 1992 {
1989 BeginPaint (hwnd, &paintStruct); 1993 PAINTSTRUCT paintStruct;
1990 mswindows_redraw_exposed_area (frame, 1994 int x, y, width, height;
1991 paintStruct.rcPaint.left, paintStruct.rcPaint.top, 1995
1992 paintStruct.rcPaint.right, paintStruct.rcPaint.bottom); 1996 frame = XFRAME (mswindows_find_frame (hwnd));
1993 EndPaint (hwnd, &paintStruct); 1997
1998 BeginPaint (hwnd, &paintStruct);
1999 x = paintStruct.rcPaint.left;
2000 y = paintStruct.rcPaint.top;
2001 width = paintStruct.rcPaint.right - paintStruct.rcPaint.left;
2002 height = paintStruct.rcPaint.bottom - paintStruct.rcPaint.top;
2003 /* Normally we want to ignore expose events when child
2004 windows are unmapped, however once we are in the guts of
2005 WM_PAINT we need to make sure that we don't register
2006 unmaps then because they will not actually occur. */
2007 if (!check_for_ignored_expose (frame, x, y, width, height))
2008 {
2009 hold_ignored_expose_registration = 1;
2010 mswindows_redraw_exposed_area (frame, x, y, width, height);
2011 hold_ignored_expose_registration = 0;
2012 }
2013
2014 EndPaint (hwnd, &paintStruct);
2015 }
2016 else
2017 goto defproc;
1994 } 2018 }
1995 break; 2019 break;
1996 2020
1997 case WM_SIZE: 2021 case WM_SIZE:
1998 /* We only care about this message if our size has really changed */ 2022 /* We only care about this message if our size has really changed */
2138 { 2162 {
2139 /* Error during event pumping - cancel scroll */ 2163 /* Error during event pumping - cancel scroll */
2140 SendMessage (hwndScrollBar, WM_CANCELMODE, 0, 0); 2164 SendMessage (hwndScrollBar, WM_CANCELMODE, 0, 0);
2141 } 2165 }
2142 UNGCPRO; 2166 UNGCPRO;
2167 break;
2168 }
2169
2170 case WM_MOUSEWHEEL:
2171 {
2172 int keys = LOWORD (wParam); /* Modifier key flags */
2173 int delta = (short) HIWORD (wParam); /* Wheel rotation amount */
2174 struct gcpro gcpro1, gcpro2;
2175
2176 if (mswindows_handle_mousewheel_event (mswindows_find_frame (hwnd), keys, delta))
2177 {
2178 GCPRO2 (emacs_event, fobj);
2179 mswindows_pump_outstanding_events (); /* Can GC */
2180 UNGCPRO;
2181 }
2182 else
2183 goto defproc;
2143 break; 2184 break;
2144 } 2185 }
2145 #endif 2186 #endif
2146 2187
2147 #ifdef HAVE_MENUBARS 2188 #ifdef HAVE_MENUBARS
2415 /* 2456 /*
2416 * Translate a mswindows virtual key to a keysym. 2457 * Translate a mswindows virtual key to a keysym.
2417 * Only returns non-Qnil for keys that don't generate WM_CHAR messages 2458 * Only returns non-Qnil for keys that don't generate WM_CHAR messages
2418 * or whose ASCII codes (like space) xemacs doesn't like. 2459 * or whose ASCII codes (like space) xemacs doesn't like.
2419 * Virtual key values are defined in winresrc.h 2460 * Virtual key values are defined in winresrc.h
2420 * XXX I'm not sure that KEYSYM("name") is the best thing to use here.
2421 */ 2461 */
2422 Lisp_Object mswindows_key_to_emacs_keysym(int mswindows_key, int mods) 2462 Lisp_Object mswindows_key_to_emacs_keysym (int mswindows_key, int mods,
2423 { 2463 int extendedp)
2424 switch (mswindows_key) 2464 {
2425 { 2465 if (extendedp) /* Keys not present on a 82 key keyboard */
2426 /* First the predefined ones */ 2466 {
2427 case VK_BACK: return QKbackspace; 2467 switch (mswindows_key)
2428 case VK_TAB: return QKtab; 2468 {
2429 case '\n': return QKlinefeed; /* No VK_LINEFEED in winresrc.h */ 2469 case VK_RETURN: return KEYSYM ("kp-enter");
2430 case VK_RETURN: return QKreturn; 2470 case VK_PRIOR: return KEYSYM ("prior");
2431 case VK_ESCAPE: return QKescape; 2471 case VK_NEXT: return KEYSYM ("next");
2432 case VK_SPACE: return QKspace; 2472 case VK_END: return KEYSYM ("end");
2433 case VK_DELETE: return QKdelete; 2473 case VK_HOME: return KEYSYM ("home");
2434 2474 case VK_LEFT: return KEYSYM ("left");
2435 /* The rest */ 2475 case VK_UP: return KEYSYM ("up");
2436 case VK_CLEAR: return KEYSYM ("clear"); /* Should do ^L ? */ 2476 case VK_RIGHT: return KEYSYM ("right");
2437 case VK_PRIOR: return KEYSYM ("prior"); 2477 case VK_DOWN: return KEYSYM ("down");
2438 case VK_NEXT: return KEYSYM ("next"); 2478 case VK_INSERT: return KEYSYM ("insert");
2439 case VK_END: return KEYSYM ("end"); 2479 case VK_DELETE: return QKdelete;
2440 case VK_HOME: return KEYSYM ("home"); 2480 }
2441 case VK_LEFT: return KEYSYM ("left"); 2481 }
2442 case VK_UP: return KEYSYM ("up"); 2482 else
2443 case VK_RIGHT: return KEYSYM ("right"); 2483 {
2444 case VK_DOWN: return KEYSYM ("down"); 2484 switch (mswindows_key)
2445 case VK_SELECT: return KEYSYM ("select"); 2485 {
2446 case VK_PRINT: return KEYSYM ("print"); 2486 case VK_BACK: return QKbackspace;
2447 case VK_EXECUTE: return KEYSYM ("execute"); 2487 case VK_TAB: return QKtab;
2448 case VK_SNAPSHOT: return KEYSYM ("print"); 2488 case '\n': return QKlinefeed;
2449 case VK_INSERT: return KEYSYM ("insert"); 2489 case VK_CLEAR: return KEYSYM ("clear");
2450 case VK_HELP: return KEYSYM ("help"); 2490 case VK_RETURN: return QKreturn;
2451 #if 0 /* XXX What are these supposed to do? */ 2491 case VK_ESCAPE: return QKescape;
2452 case VK_LWIN return KEYSYM (""); 2492 case VK_SPACE: return QKspace;
2453 case VK_RWIN return KEYSYM (""); 2493 case VK_PRIOR: return KEYSYM ("kp-prior");
2454 #endif 2494 case VK_NEXT: return KEYSYM ("kp-next");
2455 case VK_APPS: return KEYSYM ("menu"); 2495 case VK_END: return KEYSYM ("kp-end");
2456 case VK_F1: return KEYSYM ("f1"); 2496 case VK_HOME: return KEYSYM ("kp-home");
2457 case VK_F2: return KEYSYM ("f2"); 2497 case VK_LEFT: return KEYSYM ("kp-left");
2458 case VK_F3: return KEYSYM ("f3"); 2498 case VK_UP: return KEYSYM ("kp-up");
2459 case VK_F4: return KEYSYM ("f4"); 2499 case VK_RIGHT: return KEYSYM ("kp-right");
2460 case VK_F5: return KEYSYM ("f5"); 2500 case VK_DOWN: return KEYSYM ("kp-down");
2461 case VK_F6: return KEYSYM ("f6"); 2501 case VK_SELECT: return KEYSYM ("select");
2462 case VK_F7: return KEYSYM ("f7"); 2502 case VK_PRINT: return KEYSYM ("print");
2463 case VK_F8: return KEYSYM ("f8"); 2503 case VK_EXECUTE: return KEYSYM ("execute");
2464 case VK_F9: return KEYSYM ("f9"); 2504 case VK_SNAPSHOT: return KEYSYM ("print");
2465 case VK_F10: return KEYSYM ("f10"); 2505 case VK_INSERT: return KEYSYM ("kp-insert");
2466 case VK_F11: return KEYSYM ("f11"); 2506 case VK_DELETE: return KEYSYM ("kp-delete");
2467 case VK_F12: return KEYSYM ("f12"); 2507 case VK_HELP: return KEYSYM ("help");
2468 case VK_F13: return KEYSYM ("f13"); 2508 #if 0 /* FSF Emacs allows these to return configurable syms/mods */
2469 case VK_F14: return KEYSYM ("f14"); 2509 case VK_LWIN return KEYSYM ("");
2470 case VK_F15: return KEYSYM ("f15"); 2510 case VK_RWIN return KEYSYM ("");
2471 case VK_F16: return KEYSYM ("f16"); 2511 #endif
2472 case VK_F17: return KEYSYM ("f17"); 2512 case VK_APPS: return KEYSYM ("menu");
2473 case VK_F18: return KEYSYM ("f18"); 2513 case VK_NUMPAD0: return KEYSYM ("kp-0");
2474 case VK_F19: return KEYSYM ("f19"); 2514 case VK_NUMPAD1: return KEYSYM ("kp-1");
2475 case VK_F20: return KEYSYM ("f20"); 2515 case VK_NUMPAD2: return KEYSYM ("kp-2");
2476 case VK_F21: return KEYSYM ("f21"); 2516 case VK_NUMPAD3: return KEYSYM ("kp-3");
2477 case VK_F22: return KEYSYM ("f22"); 2517 case VK_NUMPAD4: return KEYSYM ("kp-4");
2478 case VK_F23: return KEYSYM ("f23"); 2518 case VK_NUMPAD5: return KEYSYM ("kp-5");
2479 case VK_F24: return KEYSYM ("f24"); 2519 case VK_NUMPAD6: return KEYSYM ("kp-6");
2480 } 2520 case VK_NUMPAD7: return KEYSYM ("kp-7");
2521 case VK_NUMPAD8: return KEYSYM ("kp-8");
2522 case VK_NUMPAD9: return KEYSYM ("kp-9");
2523 case VK_MULTIPLY: return KEYSYM ("kp-multiply");
2524 case VK_ADD: return KEYSYM ("kp-add");
2525 case VK_SEPARATOR: return KEYSYM ("kp-separator");
2526 case VK_SUBTRACT: return KEYSYM ("kp-subtract");
2527 case VK_DECIMAL: return KEYSYM ("kp-decimal");
2528 case VK_DIVIDE: return KEYSYM ("kp-divide");
2529 case VK_F1: return KEYSYM ("f1");
2530 case VK_F2: return KEYSYM ("f2");
2531 case VK_F3: return KEYSYM ("f3");
2532 case VK_F4: return KEYSYM ("f4");
2533 case VK_F5: return KEYSYM ("f5");
2534 case VK_F6: return KEYSYM ("f6");
2535 case VK_F7: return KEYSYM ("f7");
2536 case VK_F8: return KEYSYM ("f8");
2537 case VK_F9: return KEYSYM ("f9");
2538 case VK_F10: return KEYSYM ("f10");
2539 case VK_F11: return KEYSYM ("f11");
2540 case VK_F12: return KEYSYM ("f12");
2541 case VK_F13: return KEYSYM ("f13");
2542 case VK_F14: return KEYSYM ("f14");
2543 case VK_F15: return KEYSYM ("f15");
2544 case VK_F16: return KEYSYM ("f16");
2545 case VK_F17: return KEYSYM ("f17");
2546 case VK_F18: return KEYSYM ("f18");
2547 case VK_F19: return KEYSYM ("f19");
2548 case VK_F20: return KEYSYM ("f20");
2549 case VK_F21: return KEYSYM ("f21");
2550 case VK_F22: return KEYSYM ("f22");
2551 case VK_F23: return KEYSYM ("f23");
2552 case VK_F24: return KEYSYM ("f24");
2553 }
2554 }
2481 return Qnil; 2555 return Qnil;
2482 } 2556 }
2483 2557
2484 /* 2558 /*
2485 * Find the console that matches the supplied mswindows window handle 2559 * Find the console that matches the supplied mswindows window handle
2875 #endif 2949 #endif
2876 2950
2877 /************************************************************************/ 2951 /************************************************************************/
2878 /* initialization */ 2952 /* initialization */
2879 /************************************************************************/ 2953 /************************************************************************/
2880 2954
2881 void 2955 void
2882 vars_of_event_mswindows (void) 2956 reinit_vars_of_event_mswindows (void)
2883 { 2957 {
2884 mswindows_u_dispatch_event_queue = Qnil;
2885 staticpro (&mswindows_u_dispatch_event_queue);
2886 mswindows_u_dispatch_event_queue_tail = Qnil;
2887
2888 mswindows_s_dispatch_event_queue = Qnil;
2889 staticpro (&mswindows_s_dispatch_event_queue);
2890 mswindows_s_dispatch_event_queue_tail = Qnil;
2891
2892 mswindows_error_caught_in_modal_loop = Qnil;
2893 staticpro (&mswindows_error_caught_in_modal_loop);
2894 mswindows_in_modal_loop = 0; 2958 mswindows_in_modal_loop = 0;
2895 mswindows_pending_timers_count = 0; 2959 mswindows_pending_timers_count = 0;
2896 2960
2897 mswindows_event_stream = xnew (struct event_stream); 2961 mswindows_event_stream = xnew (struct event_stream);
2898 2962
2915 mswindows_event_stream->select_process_cb = emacs_mswindows_select_process; 2979 mswindows_event_stream->select_process_cb = emacs_mswindows_select_process;
2916 mswindows_event_stream->unselect_process_cb = emacs_mswindows_unselect_process; 2980 mswindows_event_stream->unselect_process_cb = emacs_mswindows_unselect_process;
2917 mswindows_event_stream->create_stream_pair_cb = emacs_mswindows_create_stream_pair; 2981 mswindows_event_stream->create_stream_pair_cb = emacs_mswindows_create_stream_pair;
2918 mswindows_event_stream->delete_stream_pair_cb = emacs_mswindows_delete_stream_pair; 2982 mswindows_event_stream->delete_stream_pair_cb = emacs_mswindows_delete_stream_pair;
2919 #endif 2983 #endif
2984 }
2985
2986 void
2987 vars_of_event_mswindows (void)
2988 {
2989 reinit_vars_of_event_mswindows ();
2990
2991 mswindows_u_dispatch_event_queue = Qnil;
2992 staticpro (&mswindows_u_dispatch_event_queue);
2993 mswindows_u_dispatch_event_queue_tail = Qnil;
2994 pdump_wire (&mswindows_u_dispatch_event_queue_tail);
2995
2996 mswindows_s_dispatch_event_queue = Qnil;
2997 staticpro (&mswindows_s_dispatch_event_queue);
2998 mswindows_s_dispatch_event_queue_tail = Qnil;
2999 pdump_wire (&mswindows_u_dispatch_event_queue_tail);
3000
3001 mswindows_error_caught_in_modal_loop = Qnil;
3002 staticpro (&mswindows_error_caught_in_modal_loop);
3003
3004 DEFVAR_BOOL ("mswindows-meta-activates-menu", &mswindows_meta_activates_menu /*
3005 *Controls whether pressing and releasing the Meta (Alt) key should
3006 activate the menubar.
3007 Default is t.
3008 */ );
2920 3009
2921 DEFVAR_BOOL ("mswindows-dynamic-frame-resize", &mswindows_dynamic_frame_resize /* 3010 DEFVAR_BOOL ("mswindows-dynamic-frame-resize", &mswindows_dynamic_frame_resize /*
2922 *Controls redrawing frame contents during mouse-drag or keyboard resize 3011 *Controls redrawing frame contents during mouse-drag or keyboard resize
2923 operation. When non-nil, the frame is redrawn while being resized. When 3012 operation. When non-nil, the frame is redrawn while being resized. When
2924 nil, frame is not redrawn, and exposed areas are filled with default 3013 nil, frame is not redrawn, and exposed areas are filled with default
2960 */ ); 3049 */ );
2961 3050
2962 mswindows_mouse_button_max_skew_x = 0; 3051 mswindows_mouse_button_max_skew_x = 0;
2963 mswindows_mouse_button_max_skew_y = 0; 3052 mswindows_mouse_button_max_skew_y = 0;
2964 mswindows_mouse_button_tolerance = 0; 3053 mswindows_mouse_button_tolerance = 0;
3054 mswindows_meta_activates_menu = 1;
2965 } 3055 }
2966 3056
2967 void 3057 void
2968 syms_of_event_mswindows (void) 3058 syms_of_event_mswindows (void)
2969 { 3059 {