comparison src/event-msw.c @ 288:e11d67e05968 r21-0b42

Import from CVS: tag r21-0b42
author cvs
date Mon, 13 Aug 2007 10:35:54 +0200
parents 57709be46d1b
children c9fe270a4101
comparison
equal deleted inserted replaced
287:13a0bd77a29d 288:e11d67e05968
837 static int 837 static int
838 mswindows_user_event_p (struct Lisp_Event* sevt) 838 mswindows_user_event_p (struct Lisp_Event* sevt)
839 { 839 {
840 return (sevt->event_type == key_press_event 840 return (sevt->event_type == key_press_event
841 || sevt->event_type == button_press_event 841 || sevt->event_type == button_press_event
842 || sevt->event_type == button_release_event); 842 || sevt->event_type == button_release_event
843 || sevt->event_type == misc_user_event);
843 } 844 }
844 845
845 /* 846 /*
846 * Add an emacs event to the proper dispatch queue 847 * Add an emacs event to the proper dispatch queue
847 */ 848 */
857 858
858 /* Avoid blocking on WaitMessage */ 859 /* Avoid blocking on WaitMessage */
859 PostMessage (NULL, XM_BUMPQUEUE, 0, 0); 860 PostMessage (NULL, XM_BUMPQUEUE, 0, 0);
860 } 861 }
861 862
863 /*
864 * Add a misc-user event to the dispatch queue.
865 *
866 * Stuff it into our own dispatch queue, so we have something
867 * to return from next_event callback.
868 */
862 void 869 void
863 mswindows_bump_queue (void) 870 mswindows_enqueue_misc_user_event (Lisp_Object channel, Lisp_Object function,
864 { 871 Lisp_Object object)
865 /* Bump queue, by putting in an empty event */ 872 {
873 Lisp_Object event = Fmake_event (Qnil, Qnil);
874 struct Lisp_Event* e = XEVENT (event);
875
876 e->event_type = misc_user_event;
877 e->channel = channel;
878 e->event.misc.function = function;
879 e->event.misc.object = object;
880
881 mswindows_enqueue_dispatch_event (event);
882 }
883
884 static void
885 mswindows_enqueue_magic_event (HWND hwnd, UINT message)
886 {
866 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil); 887 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
867 struct Lisp_Event* event = XEVENT (emacs_event); 888 struct Lisp_Event* event = XEVENT (emacs_event);
868 889
869 event->event_type = empty_event; 890 event->channel = hwnd ? mswindows_find_frame (hwnd) : Qnil;
870
871 mswindows_enqueue_dispatch_event (emacs_event);
872 }
873
874 static void
875 mswindows_enqueue_magic_event (HWND hwnd, UINT message)
876 {
877 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
878 struct Lisp_Event* event = XEVENT (emacs_event);
879
880 event->channel = mswindows_find_frame (hwnd);
881 event->timestamp = GetMessageTime(); 891 event->timestamp = GetMessageTime();
882 event->event_type = magic_event; 892 event->event_type = magic_event;
883 EVENT_MSWINDOWS_MAGIC_TYPE (event) = message; 893 EVENT_MSWINDOWS_MAGIC_TYPE (event) = message;
884 894
885 mswindows_enqueue_dispatch_event (emacs_event); 895 mswindows_enqueue_dispatch_event (emacs_event);
1319 /* We might get here when a fake event came 1329 /* We might get here when a fake event came
1320 through a signal. Return a dummy event, so 1330 through a signal. Return a dummy event, so
1321 that a cycle of the command loop will 1331 that a cycle of the command loop will
1322 occur. */ 1332 occur. */
1323 drain_signal_event_pipe (); 1333 drain_signal_event_pipe ();
1324 mswindows_bump_queue(); 1334 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
1325 } 1335 }
1326 } 1336 }
1327 } 1337 }
1328 } 1338 }
1329 else if (active==-1) 1339 else if (active==-1)
1380 mswindows_waitable_handles [ix] = 1390 mswindows_waitable_handles [ix] =
1381 mswindows_waitable_handles [--mswindows_waitable_count]; 1391 mswindows_waitable_handles [--mswindows_waitable_count];
1382 kick_status_notify (); 1392 kick_status_notify ();
1383 /* Have to return something: there may be no accompanying 1393 /* Have to return something: there may be no accompanying
1384 process event */ 1394 process event */
1385 mswindows_bump_queue (); 1395 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
1386 } 1396 }
1387 } 1397 }
1388 #endif 1398 #endif
1389 } /* while */ 1399 } /* while */
1390 } 1400 }
1557 goto defproc; 1567 goto defproc;
1558 return 1; 1568 return 1;
1559 1569
1560 case WM_CLOSE: 1570 case WM_CLOSE:
1561 fobj = mswindows_find_frame (hwnd); 1571 fobj = mswindows_find_frame (hwnd);
1562 enqueue_misc_user_event (fobj, Qeval, list3 (Qdelete_frame, fobj, Qt)); 1572 mswindows_enqueue_misc_user_event (fobj, Qeval, list3 (Qdelete_frame, fobj, Qt));
1563 mswindows_bump_queue ();
1564 break; 1573 break;
1565 1574
1566 case WM_KEYDOWN: 1575 case WM_KEYDOWN:
1567 case WM_SYSKEYDOWN: 1576 case WM_SYSKEYDOWN:
1568 { 1577 {
1581 { 1590 {
1582 int quit_ch = CONSOLE_QUIT_CHAR (XCONSOLE (mswindows_find_console (hwnd))); 1591 int quit_ch = CONSOLE_QUIT_CHAR (XCONSOLE (mswindows_find_console (hwnd)));
1583 BYTE keymap_orig[256]; 1592 BYTE keymap_orig[256];
1584 MSG msg = { hwnd, message, wParam, lParam, GetMessageTime(), (GetMessagePos()) }; 1593 MSG msg = { hwnd, message, wParam, lParam, GetMessageTime(), (GetMessagePos()) };
1585 memcpy (keymap_orig, keymap, 256); 1594 memcpy (keymap_orig, keymap, 256);
1595
1596 /* Remove shift modifier from an ascii character */
1597 mods &= ~MOD_SHIFT;
1586 1598
1587 /* Clear control and alt modifiers out of the keymap */ 1599 /* Clear control and alt modifiers out of the keymap */
1588 keymap [VK_RCONTROL] = 0; 1600 keymap [VK_RCONTROL] = 0;
1589 keymap [VK_LMENU] = 0; 1601 keymap [VK_LMENU] = 0;
1590 if (!has_AltGr || !(keymap [VK_LCONTROL] & 0x80) || !(keymap [VK_RMENU] & 0x80)) 1602 if (!has_AltGr || !(keymap [VK_LCONTROL] & 0x80) || !(keymap [VK_RMENU] & 0x80))
1600 TranslateMessage (&msg); 1612 TranslateMessage (&msg);
1601 1613
1602 while (PeekMessage (&msg, hwnd, WM_CHAR, WM_CHAR, PM_REMOVE) 1614 while (PeekMessage (&msg, hwnd, WM_CHAR, WM_CHAR, PM_REMOVE)
1603 || PeekMessage (&msg, hwnd, WM_SYSCHAR, WM_SYSCHAR, PM_REMOVE)) 1615 || PeekMessage (&msg, hwnd, WM_SYSCHAR, WM_SYSCHAR, PM_REMOVE))
1604 { 1616 {
1617 int mods1 = mods;
1605 WPARAM ch = msg.wParam; 1618 WPARAM ch = msg.wParam;
1606 /* CH is a character code for the key:
1607 'C' for Shift+C and Ctrl+Shift+C
1608 'c' for c and Ctrl+c */
1609
1610 /* XEmacs doesn't seem to like Shift on non-alpha keys */
1611 if (!IsCharAlpha ((TCHAR)ch))
1612 mods &= ~MOD_SHIFT;
1613 1619
1614 /* If a quit char with no modifiers other than control and 1620 /* If a quit char with no modifiers other than control and
1615 shift, then mark it with a fake modifier, which is removed 1621 shift, then mark it with a fake modifier, which is removed
1616 upon dequeueing the event */ 1622 upon dequeueing the event */
1617 /* #### This might also not withstand localization, if 1623 /* #### This might also not withstand localization, if
1618 quit character is not a latin-1 symbol */ 1624 quit character is not a latin-1 symbol */
1619 if (((quit_ch < ' ' && (mods & MOD_CONTROL) && quit_ch + 'a' - 1 == ch) 1625 if (((quit_ch < ' ' && (mods & MOD_CONTROL) && quit_ch + 'a' - 1 == ch)
1620 || (quit_ch >= ' ' && !(mods & MOD_CONTROL) && quit_ch == ch)) 1626 || (quit_ch >= ' ' && !(mods & MOD_CONTROL) && quit_ch == ch))
1621 && ((mods & ~(MOD_CONTROL | MOD_SHIFT)) == 0)) 1627 && ((mods & ~(MOD_CONTROL | MOD_SHIFT)) == 0))
1622 { 1628 {
1623 mods |= FAKE_MOD_QUIT; 1629 mods1 |= FAKE_MOD_QUIT;
1624 ++mswindows_quit_chars_count; 1630 ++mswindows_quit_chars_count;
1625 } 1631 }
1626 1632
1627 mswindows_enqueue_keypress_event (hwnd, make_char(ch), mods); 1633 mswindows_enqueue_keypress_event (hwnd, make_char(ch), mods1);
1628 } /* while */ 1634 } /* while */
1629 SetKeyboardState (keymap_orig); 1635 SetKeyboardState (keymap_orig);
1630 } /* else */ 1636 } /* else */
1631 } 1637 }
1632 goto defproc; 1638 /* F10 causes menu activation by default. We do not want this */
1639 if (wParam != VK_F10)
1640 goto defproc;
1641 break;
1633 1642
1634 case WM_MBUTTONDOWN: 1643 case WM_MBUTTONDOWN:
1635 case WM_MBUTTONUP: 1644 case WM_MBUTTONUP:
1636 /* Real middle mouse button has nothing to do with emulated one: 1645 /* Real middle mouse button has nothing to do with emulated one:
1637 if one wants to exercise fingers playing chords on the mouse, 1646 if one wants to exercise fingers playing chords on the mouse,
1830 tttext->lpszText = NULL; 1839 tttext->lpszText = NULL;
1831 tttext->hinst = NULL; 1840 tttext->hinst = NULL;
1832 1841
1833 if (!NILP(btext)) 1842 if (!NILP(btext))
1834 { 1843 {
1835 strncpy (tttext->szText, XSTRING_DATA (btext), XSTRING_LENGTH(btext)+1); 1844 /* I think this is safe since the text will only go away
1836 tttext->lpszText=tttext->szText; 1845 when the toolbar does...*/
1846 tttext->lpszText=XSTRING_DATA (btext);
1837 } 1847 }
1838 #if 0 1848 #if 0
1839 tttext->uFlags |= TTF_DI_SETITEM; 1849 tttext->uFlags |= TTF_DI_SETITEM;
1840 #endif 1850 #endif
1841 } 1851 }
2003 2013
2004 case WM_EXITSIZEMOVE: 2014 case WM_EXITSIZEMOVE:
2005 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd))); 2015 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
2006 msframe->sizing = 0; 2016 msframe->sizing = 0;
2007 /* Queue noop event */ 2017 /* Queue noop event */
2008 mswindows_bump_queue (); 2018 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
2009 return 0; 2019 return 0;
2010 2020
2011 #ifdef HAVE_SCROLLBARS 2021 #ifdef HAVE_SCROLLBARS
2012 case WM_VSCROLL: 2022 case WM_VSCROLL:
2013 case WM_HSCROLL: 2023 case WM_HSCROLL:
2405 */ 2415 */
2406 static void 2416 static void
2407 emacs_mswindows_handle_magic_event (struct Lisp_Event *emacs_event) 2417 emacs_mswindows_handle_magic_event (struct Lisp_Event *emacs_event)
2408 { 2418 {
2409 switch (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event)) 2419 switch (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event))
2410 { 2420 {
2411 case WM_SETFOCUS: 2421 case XM_BUMPQUEUE:
2412 case WM_KILLFOCUS: 2422 break;
2413 { 2423
2414 Lisp_Object frame = EVENT_CHANNEL (emacs_event); 2424 case WM_SETFOCUS:
2415 struct frame *f = XFRAME (frame); 2425 case WM_KILLFOCUS:
2416 int in_p = (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event) == WM_SETFOCUS); 2426 {
2417 Lisp_Object conser; 2427 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
2418 2428 struct frame *f = XFRAME (frame);
2419 /* struct gcpro gcpro1; */ 2429 int in_p = (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event) == WM_SETFOCUS);
2420 2430 Lisp_Object conser;
2421 /* Clear sticky modifiers here (if we had any) */ 2431
2422 2432 /* struct gcpro gcpro1; */
2423 conser = Fcons (frame, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil)); 2433
2424 /* GCPRO1 (conser); XXX Not necessary? */ 2434 /* Clear sticky modifiers here (if we had any) */
2425 emacs_handle_focus_change_preliminary (conser); 2435
2426 /* Under X the stuff up to here is done in the X event handler. 2436 conser = Fcons (frame, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil));
2427 I Don't know why */ 2437 /* GCPRO1 (conser); XXX Not necessary? */
2428 emacs_handle_focus_change_final (conser); 2438 emacs_handle_focus_change_preliminary (conser);
2429 /* UNGCPRO; */ 2439 /* Under X the stuff up to here is done in the X event handler.
2430 2440 I Don't know why */
2431 } 2441 emacs_handle_focus_change_final (conser);
2432 break; 2442 /* UNGCPRO; */
2433 2443
2434 case XM_MAPFRAME: 2444 }
2435 case XM_UNMAPFRAME: 2445 break;
2436 { 2446
2437 Lisp_Object frame = EVENT_CHANNEL (emacs_event); 2447 case XM_MAPFRAME:
2438 va_run_hook_with_args (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event) 2448 case XM_UNMAPFRAME:
2439 == XM_MAPFRAME ? 2449 {
2440 Qmap_frame_hook : Qunmap_frame_hook, 2450 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
2441 1, frame); 2451 va_run_hook_with_args (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event)
2442 } 2452 == XM_MAPFRAME ?
2443 break; 2453 Qmap_frame_hook : Qunmap_frame_hook,
2454 1, frame);
2455 }
2456 break;
2444 2457
2445 /* #### What about Enter & Leave */ 2458 /* #### What about Enter & Leave */
2446 #if 0 2459 #if 0
2447 va_run_hook_with_args (in_p ? Qmouse_enter_frame_hook : 2460 va_run_hook_with_args (in_p ? Qmouse_enter_frame_hook :
2448 Qmouse_leave_frame_hook, 1, frame); 2461 Qmouse_leave_frame_hook, 1, frame);
2449 #endif 2462 #endif
2450 2463
2451 default: 2464 default:
2452 assert(0); 2465 assert(0);
2453 } 2466 }
2454 } 2467 }
2455 2468
2456 static HANDLE 2469 static HANDLE
2457 get_process_input_waitable (struct Lisp_Process *process) 2470 get_process_input_waitable (struct Lisp_Process *process)
2458 { 2471 {