comparison src/event-msw.c @ 278:90d73dddcdc4 r21-0b37

Import from CVS: tag r21-0b37
author cvs
date Mon, 13 Aug 2007 10:31:29 +0200
parents 6330739388db
children 7df0dd720c89
comparison
equal deleted inserted replaced
277:cfdf3ff11843 278:90d73dddcdc4
50 #include "process.h" 50 #include "process.h"
51 #include "redisplay.h" 51 #include "redisplay.h"
52 #include "sysproc.h" 52 #include "sysproc.h"
53 #include "syswait.h" 53 #include "syswait.h"
54 #include "systime.h" 54 #include "systime.h"
55 #include "sysdep.h"
55 56
56 #include "events-mod.h" 57 #include "events-mod.h"
58 #ifdef HAVE_MSG_SELECT
59 #include "sysfile.h"
60 #endif
57 #include <io.h> 61 #include <io.h>
58 #include <errno.h> 62 #include <errno.h>
59
60 #ifdef BROKEN_CYGWIN
61 int WINAPI DdeCmpStringHandles (HSZ, HSZ);
62 HDDEDATA WINAPI DdeCreateDataHandle (DWORD, LPBYTE, DWORD, DWORD, HSZ,
63 UINT, UINT);
64 #endif
65 63
66 #ifdef HAVE_MENUBARS 64 #ifdef HAVE_MENUBARS
67 #define ADJR_MENUFLAG TRUE 65 #define ADJR_MENUFLAG TRUE
68 #else 66 #else
69 #define ADJR_MENUFLAG FALSE 67 #define ADJR_MENUFLAG FALSE
79 /* Drag and drop event data types (subset of types in offix-types.h) */ 77 /* Drag and drop event data types (subset of types in offix-types.h) */
80 #define DndFile 2 78 #define DndFile 2
81 #define DndFiles 3 79 #define DndFiles 3
82 #define DndText 4 80 #define DndText 4
83 81
82 extern Lisp_Object
83 mswindows_get_toolbar_button_text (struct frame* f, int command_id);
84 extern Lisp_Object
85 mswindows_handle_toolbar_wm_command (struct frame* f, HWND ctrl, WORD id);
84 86
85 static Lisp_Object mswindows_find_frame (HWND hwnd); 87 static Lisp_Object mswindows_find_frame (HWND hwnd);
86 static Lisp_Object mswindows_find_console (HWND hwnd); 88 static Lisp_Object mswindows_find_console (HWND hwnd);
87 static Lisp_Object mswindows_key_to_emacs_keysym(int mswindows_key, int mods); 89 static Lisp_Object mswindows_key_to_emacs_keysym(int mswindows_key, int mods);
88 static int mswindows_modifier_state (BYTE* keymap, int has_AltGr); 90 static int mswindows_modifier_state (BYTE* keymap, int has_AltGr);
89 static void mswindows_set_chord_timer (HWND hwnd); 91 static void mswindows_set_chord_timer (HWND hwnd);
90 static int mswindows_button2_near_enough (POINTS p1, POINTS p2); 92 static int mswindows_button2_near_enough (POINTS p1, POINTS p2);
91 static int mswindows_current_layout_has_AltGr (void); 93 static int mswindows_current_layout_has_AltGr (void);
92 94
93 static struct event_stream *mswindows_event_stream; 95 static struct event_stream *mswindows_event_stream;
96
97 #ifdef HAVE_MSG_SELECT
98 extern SELECT_TYPE input_wait_mask, non_fake_input_wait_mask;
99 extern SELECT_TYPE process_only_mask, tty_only_mask;
100 extern int signal_event_pipe_initialized;
101 int windows_fd;
102 #endif
94 103
95 /* 104 /*
96 * Two separate queues, for efficiency, one (_u_) for user events, and 105 * Two separate queues, for efficiency, one (_u_) for user events, and
97 * another (_s_) for non-user ones. We always return events out of the 106 * another (_s_) for non-user ones. We always return events out of the
98 * first one until it is empty and only then proceed with the second 107 * first one until it is empty and only then proceed with the second
169 BYTE onebyte; /* One byte buffer read by thread */ 178 BYTE onebyte; /* One byte buffer read by thread */
170 }; 179 };
171 180
172 #define MAX_SLURP_STREAMS 32 181 #define MAX_SLURP_STREAMS 32
173 struct ntpipe_slurp_stream_shared_data 182 struct ntpipe_slurp_stream_shared_data
174 shared_data_block[MAX_SLURP_STREAMS]={0}; 183 shared_data_block[MAX_SLURP_STREAMS]={{0}};
175 184
176 struct ntpipe_slurp_stream 185 struct ntpipe_slurp_stream
177 { 186 {
178 LPARAM user_data; /* Any user data stored in the stream object */ 187 LPARAM user_data; /* Any user data stored in the stream object */
179 struct ntpipe_slurp_stream_shared_data* thread_data; 188 struct ntpipe_slurp_stream_shared_data* thread_data;
399 /* Now we can unblock thread, so it attempts to read more */ 408 /* Now we can unblock thread, so it attempts to read more */
400 SetEvent (s->hev_thread); 409 SetEvent (s->hev_thread);
401 return bytes_read + 1; 410 return bytes_read + 1;
402 } 411 }
403 } 412 }
413 return 0;
404 } 414 }
405 415
406 static int 416 static int
407 ntpipe_slurp_closer (Lstream *stream) 417 ntpipe_slurp_closer (Lstream *stream)
408 { 418 {
1055 quit char when called from quit_p */ 1065 quit char when called from quit_p */
1056 mswindows_drain_windows_queue (); 1066 mswindows_drain_windows_queue ();
1057 1067
1058 while (NILP (mswindows_u_dispatch_event_queue) 1068 while (NILP (mswindows_u_dispatch_event_queue)
1059 && NILP (mswindows_s_dispatch_event_queue)) 1069 && NILP (mswindows_s_dispatch_event_queue))
1060 { 1070 {
1061 /* Now try getting a message or process event */ 1071 #ifdef HAVE_MSG_SELECT
1072 int i;
1073 SELECT_TYPE temp_mask = input_wait_mask;
1074 EMACS_TIME sometime;
1075 EMACS_SELECT_TIME select_time_to_block, *pointer_to_this;
1076
1077 if (badly_p)
1078 pointer_to_this = 0;
1079 else
1080 {
1081 EMACS_SET_SECS_USECS (sometime, 0, 0);
1082 EMACS_TIME_TO_SELECT_TIME (sometime, select_time_to_block);
1083 pointer_to_this = &select_time_to_block;
1084 }
1085 active = select (MAXDESC, &temp_mask, 0, 0, pointer_to_this);
1086
1087 if (active == 0)
1088 {
1089 return; /* timeout */
1090 }
1091 else if (active > 0)
1092 {
1093 if (FD_ISSET (windows_fd, &temp_mask))
1094 {
1095 mswindows_drain_windows_queue ();
1096 }
1097
1098 /* Look for a process event */
1099 for (i = 0; i < MAXDESC-1; i++)
1100 {
1101 if (FD_ISSET (i, &temp_mask))
1102 {
1103 if (FD_ISSET (i, &process_only_mask))
1104 {
1105 struct Lisp_Process *p =
1106 get_process_from_usid (FD_TO_USID(i));
1107
1108 mswindows_enqueue_process_event (p);
1109 }
1110 else if (FD_ISSET (i, &tty_only_mask))
1111 {
1112 /* do we care about tty events? Do we
1113 ever get tty events? */
1114 }
1115 else
1116 {
1117 /* We might get here when a fake event came
1118 through a signal. Return a dummy event, so
1119 that a cycle of the command loop will
1120 occur. */
1121 drain_signal_event_pipe ();
1122 mswindows_bump_queue();
1123 }
1124 }
1125 }
1126 }
1127 else if (active==-1)
1128 {
1129 if (errno != EINTR)
1130 {
1131 /* something bad happended */
1132 assert(0);
1133 }
1134 }
1135 else
1136 {
1137 assert(0);
1138 }
1139 #else
1140 /* Now try getting a message or process event */
1062 active = MsgWaitForMultipleObjects (mswindows_waitable_count, 1141 active = MsgWaitForMultipleObjects (mswindows_waitable_count,
1063 mswindows_waitable_handles, 1142 mswindows_waitable_handles,
1064 FALSE, badly_p ? INFINITE : 0, 1143 FALSE, badly_p ? INFINITE : 0,
1065 QS_ALLINPUT); 1144 QS_ALLINPUT);
1066 1145
1102 /* Have to return something: there may be no accompanying 1181 /* Have to return something: there may be no accompanying
1103 process event */ 1182 process event */
1104 mswindows_bump_queue (); 1183 mswindows_bump_queue ();
1105 } 1184 }
1106 } 1185 }
1186 #endif
1107 } /* while */ 1187 } /* while */
1108 } 1188 }
1109 1189
1110 /************************************************************************/ 1190 /************************************************************************/
1111 /* Event generators */ 1191 /* Event generators */
1514 1594
1515 mswindows_enqueue_dispatch_event (emacs_event); 1595 mswindows_enqueue_dispatch_event (emacs_event);
1516 } 1596 }
1517 break; 1597 break;
1518 1598
1599 #ifdef HAVE_TOOLBARS
1600 case WM_NOTIFY:
1601 {
1602 LPTOOLTIPTEXT tttext = (LPTOOLTIPTEXT)lParam;
1603 Lisp_Object btext;
1604 if (tttext->hdr.code == TTN_NEEDTEXT)
1605 {
1606 /* find out which toolbar */
1607 frame = XFRAME (mswindows_find_frame (hwnd));
1608 btext = mswindows_get_toolbar_button_text ( frame,
1609 tttext->hdr.idFrom );
1610
1611 tttext->lpszText = NULL;
1612 tttext->hinst = NULL;
1613
1614 if (!NILP(btext))
1615 {
1616 strncpy (tttext->szText, XSTRING_DATA (btext), 80);
1617 tttext->lpszText=tttext->szText;
1618 }
1619 #if 0
1620 tttext->uFlags |= TTF_DI_SETITEM;
1621 #endif
1622 }
1623 }
1624 break;
1625 #endif
1626
1519 case WM_PAINT: 1627 case WM_PAINT:
1520 { 1628 {
1521 PAINTSTRUCT paintStruct; 1629 PAINTSTRUCT paintStruct;
1522 1630
1523 frame = XFRAME (mswindows_find_frame (hwnd)); 1631 frame = XFRAME (mswindows_find_frame (hwnd));
1724 #endif /* HAVE_MENUBARS */ 1832 #endif /* HAVE_MENUBARS */
1725 1833
1726 case WM_COMMAND: 1834 case WM_COMMAND:
1727 { 1835 {
1728 WORD id = LOWORD (wParam); 1836 WORD id = LOWORD (wParam);
1837 HWND cid = (HWND)lParam;
1729 frame = XFRAME (mswindows_find_frame (hwnd)); 1838 frame = XFRAME (mswindows_find_frame (hwnd));
1730 1839
1731 #ifdef HAVE_TOOLBARS 1840 #ifdef HAVE_TOOLBARS
1732 if (!NILP (mswindows_handle_toolbar_wm_command (frame, id))) 1841 if (!NILP (mswindows_handle_toolbar_wm_command (frame, cid, id)))
1733 break; 1842 break;
1734 #endif 1843 #endif
1735 1844
1736 #ifdef HAVE_MENUBARS 1845 #ifdef HAVE_MENUBARS
1737 if (!NILP (mswindows_handle_wm_command (frame, id))) 1846 if (!NILP (mswindows_handle_wm_command (frame, id)))
2329 mswindows_event_stream->event_pending_p = emacs_mswindows_event_pending_p; 2438 mswindows_event_stream->event_pending_p = emacs_mswindows_event_pending_p;
2330 mswindows_event_stream->next_event_cb = emacs_mswindows_next_event; 2439 mswindows_event_stream->next_event_cb = emacs_mswindows_next_event;
2331 mswindows_event_stream->handle_magic_event_cb = emacs_mswindows_handle_magic_event; 2440 mswindows_event_stream->handle_magic_event_cb = emacs_mswindows_handle_magic_event;
2332 mswindows_event_stream->add_timeout_cb = emacs_mswindows_add_timeout; 2441 mswindows_event_stream->add_timeout_cb = emacs_mswindows_add_timeout;
2333 mswindows_event_stream->remove_timeout_cb = emacs_mswindows_remove_timeout; 2442 mswindows_event_stream->remove_timeout_cb = emacs_mswindows_remove_timeout;
2443 mswindows_event_stream->quit_p_cb = emacs_mswindows_quit_p;
2334 mswindows_event_stream->select_console_cb = emacs_mswindows_select_console; 2444 mswindows_event_stream->select_console_cb = emacs_mswindows_select_console;
2335 mswindows_event_stream->unselect_console_cb = emacs_mswindows_unselect_console; 2445 mswindows_event_stream->unselect_console_cb = emacs_mswindows_unselect_console;
2446 #ifdef HAVE_MSG_SELECT
2447 mswindows_event_stream->select_process_cb =
2448 (void (*)(struct Lisp_Process*))event_stream_unixoid_select_process;
2449 mswindows_event_stream->unselect_process_cb =
2450 (void (*)(struct Lisp_Process*))event_stream_unixoid_unselect_process;
2451 mswindows_event_stream->create_stream_pair_cb = event_stream_unixoid_create_stream_pair;
2452 mswindows_event_stream->delete_stream_pair_cb = event_stream_unixoid_delete_stream_pair;
2453 #else
2336 mswindows_event_stream->select_process_cb = emacs_mswindows_select_process; 2454 mswindows_event_stream->select_process_cb = emacs_mswindows_select_process;
2337 mswindows_event_stream->unselect_process_cb = emacs_mswindows_unselect_process; 2455 mswindows_event_stream->unselect_process_cb = emacs_mswindows_unselect_process;
2338 mswindows_event_stream->quit_p_cb = emacs_mswindows_quit_p;
2339 mswindows_event_stream->create_stream_pair_cb = emacs_mswindows_create_stream_pair; 2456 mswindows_event_stream->create_stream_pair_cb = emacs_mswindows_create_stream_pair;
2340 mswindows_event_stream->delete_stream_pair_cb = emacs_mswindows_delete_stream_pair; 2457 mswindows_event_stream->delete_stream_pair_cb = emacs_mswindows_delete_stream_pair;
2458 #endif
2341 2459
2342 DEFVAR_BOOL ("mswindows-dynamic-frame-resize", &mswindows_dynamic_frame_resize /* 2460 DEFVAR_BOOL ("mswindows-dynamic-frame-resize", &mswindows_dynamic_frame_resize /*
2343 *Controls redrawing frame contents during mouse-drag or keyboard resize 2461 *Controls redrawing frame contents during mouse-drag or keyboard resize
2344 operation. When non-nil, the frame is redrawn while being resized. When 2462 operation. When non-nil, the frame is redrawn while being resized. When
2345 nil, frame is not redrawn, and exposed areas are filled with default 2463 nil, frame is not redrawn, and exposed areas are filled with default
2398 } 2516 }
2399 2517
2400 void 2518 void
2401 init_event_mswindows_late (void) 2519 init_event_mswindows_late (void)
2402 { 2520 {
2521 #ifdef HAVE_MSG_SELECT
2522 windows_fd = open("/dev/windows", O_RDONLY | O_NONBLOCK, 0);
2523 assert (windows_fd>=0);
2524 FD_SET (windows_fd, &input_wait_mask);
2525 /* for some reason I get blocks on the signal event pipe, which is
2526 bad...
2527 signal_event_pipe_initialized = 0; */
2528 #endif
2529
2403 event_stream = mswindows_event_stream; 2530 event_stream = mswindows_event_stream;
2404 2531
2405 mswindows_dynamic_frame_resize = !GetSystemMetrics (SM_SLOWMACHINE); 2532 mswindows_dynamic_frame_resize = !GetSystemMetrics (SM_SLOWMACHINE);
2406 mswindows_num_mouse_buttons = GetSystemMetrics (SM_CMOUSEBUTTONS); 2533 mswindows_num_mouse_buttons = GetSystemMetrics (SM_CMOUSEBUTTONS);
2407 } 2534 }