442
|
1 /* The mswindows event_stream interface.
|
428
|
2 Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
1268
|
4 Copyright (C) 1996, 2000, 2001, 2002, 2003 Ben Wing.
|
428
|
5 Copyright (C) 1997 Jonathan Harris.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Not in FSF. */
|
|
25
|
771
|
26 /* This file essentially Mule-ized (except perhaps some Unicode splitting).
|
|
27 5-2000. */
|
|
28
|
428
|
29 /* Authorship:
|
|
30
|
|
31 Ultimately based on FSF.
|
|
32 Rewritten by Ben Wing.
|
|
33 Rewritten for mswindows by Jonathan Harris, November 1997 for 21.0.
|
|
34 Subprocess and modal loop support by Kirill M. Katsnelson.
|
|
35 */
|
|
36
|
771
|
37 #define NEED_MSWINDOWS_SHLOBJ /* for IShellLink */
|
|
38
|
428
|
39 #include <config.h>
|
|
40 #include "lisp.h"
|
|
41
|
853
|
42 #if defined (CYGWIN) && !defined (HAVE_MSG_SELECT)
|
|
43 #error We do not support non-select() versions (i.e. very old) of Cygwin.
|
|
44 #endif
|
|
45
|
|
46 /* Acceptable are:
|
|
47
|
|
48 WIN32_NATIVE and HAVE_WIN32_PROCESSES and nothing else
|
|
49
|
|
50 CYGWIN and HAVE_MSG_SELECT and HAVE_UNIX_PROCESSES and nothing else
|
|
51 */
|
|
52 #ifdef WIN32_NATIVE
|
856
|
53 # if !(defined (HAVE_WIN32_PROCESSES) && !defined (HAVE_UNIX_PROCESSES) && !defined (HAVE_MSG_SELECT) && !defined (CYGWIN))
|
853
|
54 # error Something is wrong with your process definitions for Windows native.
|
|
55 # endif
|
|
56 #elif defined (CYGWIN)
|
|
57 # if !(defined (HAVE_UNIX_PROCESSES) && defined (HAVE_MSG_SELECT) && !defined (HAVE_WIN32_PROCESSES) && !defined (WIN32_NATIVE))
|
|
58 # error Something is wrong with your process definitions for Cygwin.
|
|
59 # endif
|
|
60 #else
|
|
61 # error Something is wrong -- you are neither Windows native (possibly MinGW) nor Cygwin.
|
|
62 #endif
|
|
63
|
800
|
64 #include "buffer.h"
|
872
|
65 #include "device-impl.h"
|
800
|
66 #include "events.h"
|
|
67 #include "faces.h"
|
872
|
68 #include "frame-impl.h"
|
800
|
69 #include "glyphs.h"
|
|
70 #include "lstream.h"
|
|
71 #include "process.h"
|
|
72 #include "redisplay.h"
|
|
73 #include "sysdep.h"
|
|
74 #include "window.h"
|
|
75
|
1204
|
76 #include "console-stream-impl.h"
|
872
|
77 #include "console-msw-impl.h"
|
|
78 #include "objects-msw-impl.h"
|
428
|
79
|
|
80 #ifdef HAVE_SCROLLBARS
|
|
81 # include "scrollbar-msw.h"
|
|
82 #endif
|
|
83
|
|
84 #ifdef HAVE_MENUBARS
|
442
|
85 # include "menubar.h"
|
428
|
86 # include "menubar-msw.h"
|
|
87 #endif
|
|
88
|
|
89 #ifdef HAVE_DRAGNDROP
|
|
90 # include "dragdrop.h"
|
|
91 #endif
|
|
92
|
558
|
93 #include "sysfile.h"
|
428
|
94 #include "sysproc.h"
|
558
|
95 #include "systime.h"
|
428
|
96 #include "syswait.h"
|
|
97
|
|
98 #ifdef HAVE_MENUBARS
|
|
99 #define ADJR_MENUFLAG TRUE
|
|
100 #else
|
|
101 #define ADJR_MENUFLAG FALSE
|
|
102 #endif
|
|
103
|
|
104 /* Timer ID used for button2 emulation */
|
|
105 #define BUTTON_2_TIMER_ID 1
|
|
106
|
|
107 static Lisp_Object mswindows_find_console (HWND hwnd);
|
|
108 static Lisp_Object mswindows_key_to_emacs_keysym (int mswindows_key, int mods,
|
|
109 int extendedp);
|
771
|
110 static int mswindows_modifier_state (BYTE *keymap, DWORD fwKeys,
|
442
|
111 int has_AltGr);
|
428
|
112 static void mswindows_set_chord_timer (HWND hwnd);
|
|
113 static int mswindows_button2_near_enough (POINTS p1, POINTS p2);
|
|
114 static int mswindows_current_layout_has_AltGr (void);
|
442
|
115 static int mswindows_handle_sticky_modifiers (WPARAM wParam, LPARAM lParam,
|
|
116 int downp, int keyp);
|
428
|
117
|
|
118 static struct event_stream *mswindows_event_stream;
|
|
119
|
853
|
120 #ifdef CYGWIN
|
|
121
|
428
|
122 extern SELECT_TYPE input_wait_mask, non_fake_input_wait_mask;
|
|
123 extern SELECT_TYPE process_only_mask, tty_only_mask;
|
|
124 SELECT_TYPE zero_mask;
|
|
125 extern int signal_event_pipe_initialized;
|
|
126 int windows_fd;
|
853
|
127
|
|
128 #else
|
|
129
|
856
|
130 /* The number of things we can wait on */
|
|
131 #define MAX_WAITABLE (MAXIMUM_WAIT_OBJECTS - 1)
|
|
132
|
853
|
133 /* List of mswindows waitable handles. */
|
|
134 static HANDLE mswindows_waitable_handles[MAX_WAITABLE];
|
|
135
|
|
136 /* Number of wait handles */
|
|
137 static int mswindows_waitable_count = 0;
|
|
138
|
428
|
139 #endif
|
|
140
|
|
141 /*
|
1204
|
142 * We use an additional queue, as well as the normal dispatch queue, for
|
|
143 * efficiency, the normal one for user events, and another (_s_) for non-user
|
|
144 * ones. We always return events out of the first one until it is empty and
|
|
145 * only then proceed with the second one.
|
428
|
146 */
|
1204
|
147 static Lisp_Object mswindows_s_dispatch_event_queue;
|
|
148 static Lisp_Object mswindows_s_dispatch_event_queue_tail;
|
428
|
149
|
|
150 /* Brush for painting widgets */
|
|
151 static HBRUSH widget_brush = 0;
|
|
152 static LONG last_widget_brushed = 0;
|
|
153
|
|
154 /* These are Lisp integers; see DEFVARS in this file for description. */
|
|
155 int mswindows_dynamic_frame_resize;
|
442
|
156 int mswindows_alt_by_itself_activates_menu;
|
458
|
157 Fixnum mswindows_num_mouse_buttons;
|
|
158 Fixnum mswindows_mouse_button_max_skew_x;
|
|
159 Fixnum mswindows_mouse_button_max_skew_y;
|
|
160 Fixnum mswindows_mouse_button_tolerance;
|
428
|
161
|
442
|
162 #ifdef DEBUG_XEMACS
|
458
|
163 Fixnum debug_mswindows_events;
|
593
|
164
|
|
165 static void debug_output_mswin_message (HWND hwnd, UINT message_,
|
|
166 WPARAM wParam, LPARAM lParam);
|
442
|
167 #endif
|
|
168
|
428
|
169 /* This is the event signaled by the event pump.
|
|
170 See mswindows_pump_outstanding_events for comments */
|
853
|
171 static int mswindows_error_caught_in_modal_loop;
|
428
|
172
|
|
173 /* Count of wound timers */
|
|
174 static int mswindows_pending_timers_count;
|
442
|
175
|
|
176 static DWORD mswindows_last_mouse_button_state;
|
853
|
177
|
428
|
178
|
853
|
179 #ifndef CYGWIN /* Skips past slurp, shove, or winsock streams */
|
|
180
|
428
|
181 /************************************************************************/
|
|
182 /* Pipe instream - reads process output */
|
|
183 /************************************************************************/
|
|
184
|
|
185 #define PIPE_READ_DELAY 20
|
|
186
|
|
187 #define HANDLE_TO_USID(h) ((USID)(h))
|
|
188
|
|
189 #define NTPIPE_SLURP_STREAM_DATA(stream) \
|
|
190 LSTREAM_TYPE_DATA (stream, ntpipe_slurp)
|
|
191
|
|
192 /* This structure is allocated by the main thread, and is deallocated
|
|
193 in the thread upon exit. There are situations when a thread
|
|
194 remains blocked for a long time, much longer than the lstream
|
|
195 exists. For example, "start notepad" command is issued from the
|
|
196 shell, then the shell is closed by C-c C-d. Although the shell
|
|
197 process exits, its output pipe will not get closed until the
|
656
|
198 notepad process exits also, because it inherits the pipe from the
|
428
|
199 shell. In this case, we abandon the thread, and let it live until
|
|
200 all such processes exit. While struct ntpipe_slurp_stream is
|
|
201 deallocated in this case, ntpipe_slurp_stream_shared_data are not. */
|
|
202
|
|
203 struct ntpipe_slurp_stream_shared_data
|
|
204 {
|
|
205 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */
|
853
|
206 /* This is a manual-reset object. */
|
428
|
207 HANDLE hev_caller; /* Caller blocks on this, and we signal it */
|
853
|
208 /* This is a manual-reset object. */
|
428
|
209 HANDLE hev_unsleep; /* Pipe read delay is canceled if this is set */
|
853
|
210 /* This is a manual-reset object. */
|
428
|
211 HANDLE hpipe; /* Pipe read end handle. */
|
|
212 LONG die_p; /* Thread must exit ASAP if non-zero */
|
|
213 BOOL eof_p : 1; /* Set when thread saw EOF */
|
|
214 BOOL error_p : 1; /* Read error other than EOF/broken pipe */
|
|
215 BOOL inuse_p : 1; /* this structure is in use */
|
|
216 LONG lock_count; /* Client count of this struct, 0=safe to free */
|
|
217 BYTE onebyte; /* One byte buffer read by thread */
|
|
218 };
|
|
219
|
|
220 #define MAX_SLURP_STREAMS 32
|
|
221 struct ntpipe_slurp_stream_shared_data
|
|
222 shared_data_block[MAX_SLURP_STREAMS]={{0}};
|
|
223
|
|
224 struct ntpipe_slurp_stream
|
|
225 {
|
|
226 LPARAM user_data; /* Any user data stored in the stream object */
|
771
|
227 struct ntpipe_slurp_stream_shared_data *thread_data;
|
428
|
228 };
|
|
229
|
771
|
230 DEFINE_LSTREAM_IMPLEMENTATION ("ntpipe-input", ntpipe_slurp);
|
428
|
231
|
|
232 /* This function is thread-safe, and is called from either thread
|
|
233 context. It serializes freeing shared data structure */
|
|
234 static void
|
771
|
235 slurper_free_shared_data_maybe (struct ntpipe_slurp_stream_shared_data *s)
|
428
|
236 {
|
|
237 if (InterlockedDecrement (&s->lock_count) == 0)
|
|
238 {
|
|
239 /* Destroy events */
|
|
240 CloseHandle (s->hev_thread);
|
|
241 CloseHandle (s->hev_caller);
|
|
242 CloseHandle (s->hev_unsleep);
|
673
|
243 CloseHandle (s->hpipe);
|
428
|
244 s->inuse_p = 0;
|
|
245 }
|
|
246 }
|
|
247
|
771
|
248 static struct ntpipe_slurp_stream_shared_data *
|
442
|
249 slurper_allocate_shared_data (void)
|
428
|
250 {
|
|
251 int i=0;
|
771
|
252 for (i = 0; i < MAX_SLURP_STREAMS; i++)
|
428
|
253 {
|
|
254 if (!shared_data_block[i].inuse_p)
|
|
255 {
|
771
|
256 shared_data_block[i].inuse_p = 1;
|
428
|
257 return &shared_data_block[i];
|
|
258 }
|
|
259 }
|
771
|
260 return (struct ntpipe_slurp_stream_shared_data *)0;
|
428
|
261 }
|
|
262
|
|
263 static DWORD WINAPI
|
|
264 slurp_thread (LPVOID vparam)
|
|
265 {
|
|
266 struct ntpipe_slurp_stream_shared_data *s =
|
771
|
267 (struct ntpipe_slurp_stream_shared_data *)vparam;
|
428
|
268
|
|
269 for (;;)
|
|
270 {
|
|
271 /* Read one byte from the pipe */
|
|
272 DWORD actually_read;
|
|
273 if (!ReadFile (s->hpipe, &s->onebyte, 1, &actually_read, NULL))
|
|
274 {
|
|
275 DWORD err = GetLastError ();
|
|
276 if (err == ERROR_BROKEN_PIPE || err == ERROR_NO_DATA)
|
|
277 s->eof_p = TRUE;
|
|
278 else
|
|
279 s->error_p = TRUE;
|
|
280 }
|
|
281 else if (actually_read == 0)
|
|
282 s->eof_p = TRUE;
|
|
283
|
|
284 /* We must terminate on an error or eof */
|
|
285 if (s->eof_p || s->error_p)
|
|
286 InterlockedIncrement (&s->die_p);
|
|
287
|
|
288 /* Before we notify caller, we unsignal our event. */
|
|
289 ResetEvent (s->hev_thread);
|
|
290
|
|
291 /* Now we got something to notify caller, either a byte or an
|
|
292 error/eof indication. Before we do, allow internal pipe
|
|
293 buffer to accumulate little bit more data.
|
|
294 Reader function pulses this event before waiting for
|
|
295 a character, to avoid pipe delay, and to get the byte
|
|
296 immediately. */
|
|
297 if (!s->die_p)
|
|
298 WaitForSingleObject (s->hev_unsleep, PIPE_READ_DELAY);
|
|
299
|
|
300 /* Either make event loop generate a process event, or
|
|
301 inblock reader */
|
|
302 SetEvent (s->hev_caller);
|
|
303
|
|
304 /* Cleanup and exit if we're shot off */
|
|
305 if (s->die_p)
|
|
306 break;
|
|
307
|
|
308 /* Block until the client finishes with retrieving the rest of
|
|
309 pipe data */
|
|
310 WaitForSingleObject (s->hev_thread, INFINITE);
|
|
311 }
|
|
312
|
|
313 slurper_free_shared_data_maybe (s);
|
|
314
|
|
315 return 0;
|
|
316 }
|
|
317
|
|
318 static Lisp_Object
|
|
319 make_ntpipe_input_stream (HANDLE hpipe, LPARAM param)
|
|
320 {
|
|
321 Lstream *lstr = Lstream_new (lstream_ntpipe_slurp, "r");
|
771
|
322 struct ntpipe_slurp_stream *s = NTPIPE_SLURP_STREAM_DATA (lstr);
|
428
|
323 DWORD thread_id_unused;
|
|
324 HANDLE hthread;
|
|
325
|
|
326 /* We deal only with pipes, for we're using PeekNamedPipe api */
|
|
327 assert (GetFileType (hpipe) == FILE_TYPE_PIPE);
|
|
328
|
|
329 s->thread_data = slurper_allocate_shared_data();
|
|
330
|
|
331 /* Create reader thread. This could fail, so do not create events
|
|
332 until thread is created */
|
|
333 hthread = CreateThread (NULL, 0, slurp_thread, (LPVOID)s->thread_data,
|
|
334 CREATE_SUSPENDED, &thread_id_unused);
|
|
335 if (hthread == NULL)
|
|
336 {
|
|
337 Lstream_delete (lstr);
|
|
338 s->thread_data->inuse_p=0;
|
|
339 return Qnil;
|
|
340 }
|
|
341
|
|
342 /* Shared data are initially owned by both main and slurper
|
|
343 threads. */
|
|
344 s->thread_data->lock_count = 2;
|
|
345 s->thread_data->die_p = 0;
|
|
346 s->thread_data->eof_p = FALSE;
|
|
347 s->thread_data->error_p = FALSE;
|
|
348 s->thread_data->hpipe = hpipe;
|
|
349 s->user_data = param;
|
|
350
|
|
351 /* hev_thread is a manual-reset event, initially signaled */
|
771
|
352 s->thread_data->hev_thread = qxeCreateEvent (NULL, TRUE, TRUE, NULL);
|
428
|
353 /* hev_caller is a manual-reset event, initially nonsignaled */
|
771
|
354 s->thread_data->hev_caller = qxeCreateEvent (NULL, TRUE, FALSE, NULL);
|
428
|
355 /* hev_unsleep is a manual-reset event, initially nonsignaled */
|
771
|
356 s->thread_data->hev_unsleep = qxeCreateEvent (NULL, TRUE, FALSE, NULL);
|
428
|
357
|
|
358 /* Now let it go */
|
|
359 ResumeThread (hthread);
|
|
360 CloseHandle (hthread);
|
|
361
|
|
362 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
|
793
|
363 return wrap_lstream (lstr);
|
428
|
364 }
|
|
365
|
|
366 static LPARAM
|
|
367 get_ntpipe_input_stream_param (Lstream *stream)
|
|
368 {
|
771
|
369 struct ntpipe_slurp_stream *s = NTPIPE_SLURP_STREAM_DATA(stream);
|
428
|
370 return s->user_data;
|
|
371 }
|
|
372
|
|
373 static HANDLE
|
|
374 get_ntpipe_input_stream_waitable (Lstream *stream)
|
|
375 {
|
771
|
376 struct ntpipe_slurp_stream *s = NTPIPE_SLURP_STREAM_DATA(stream);
|
428
|
377 return s->thread_data->hev_caller;
|
|
378 }
|
|
379
|
665
|
380 static Bytecount
|
462
|
381 ntpipe_slurp_reader (Lstream *stream, unsigned char *data,
|
665
|
382 Bytecount size)
|
428
|
383 {
|
|
384 /* This function must be called from the main thread only */
|
771
|
385 struct ntpipe_slurp_stream_shared_data *s =
|
428
|
386 NTPIPE_SLURP_STREAM_DATA(stream)->thread_data;
|
|
387
|
|
388 if (!s->die_p)
|
|
389 {
|
|
390 DWORD wait_result;
|
|
391 /* Disallow pipe read delay for the thread: we need a character
|
|
392 ASAP */
|
|
393 SetEvent (s->hev_unsleep);
|
|
394
|
|
395 /* Check if we have a character ready. Give it a short delay,
|
771
|
396 for the thread to awake from pipe delay, just ion case */
|
428
|
397 wait_result = WaitForSingleObject (s->hev_caller, 2);
|
|
398
|
|
399 /* Revert to the normal sleep behavior. */
|
|
400 ResetEvent (s->hev_unsleep);
|
|
401
|
|
402 /* If there's no byte buffered yet, give up */
|
|
403 if (wait_result == WAIT_TIMEOUT)
|
|
404 {
|
|
405 errno = EAGAIN;
|
|
406 return -1;
|
|
407 }
|
|
408 }
|
|
409
|
|
410 /* Reset caller unlock event now, as we've handled the pending
|
|
411 process output event */
|
|
412 ResetEvent (s->hev_caller);
|
|
413
|
|
414 /* It is now safe to do anything with contents of S, except for
|
|
415 changing s->die_p, which still should be interlocked */
|
|
416
|
|
417 if (s->eof_p)
|
|
418 return 0;
|
|
419 if (s->error_p || s->die_p)
|
|
420 return -1;
|
|
421
|
|
422 /* Ok, there were no error neither eof - we've got a byte from the
|
|
423 pipe */
|
|
424 *(data++) = s->onebyte;
|
|
425 --size;
|
|
426
|
|
427 {
|
|
428 DWORD bytes_read = 0;
|
|
429 if (size > 0)
|
|
430 {
|
|
431 DWORD bytes_available;
|
|
432
|
|
433 /* If the api call fails, return at least one byte already
|
|
434 read. ReadFile in thread will return error */
|
|
435 if (PeekNamedPipe (s->hpipe, NULL, 0, NULL, &bytes_available, NULL))
|
|
436 {
|
|
437
|
|
438 /* Fetch available bytes. The same consideration applies,
|
|
439 so do not check for errors. ReadFile in the thread will
|
|
440 fail if the next call fails. */
|
|
441 if (bytes_available)
|
647
|
442 ReadFile (s->hpipe, data, min (bytes_available, (DWORD) size),
|
428
|
443 &bytes_read, NULL);
|
|
444 }
|
|
445
|
|
446 /* Now we can unblock thread, so it attempts to read more */
|
|
447 SetEvent (s->hev_thread);
|
|
448 return bytes_read + 1;
|
|
449 }
|
|
450 }
|
|
451 return 0;
|
|
452 }
|
|
453
|
|
454 static int
|
|
455 ntpipe_slurp_closer (Lstream *stream)
|
|
456 {
|
|
457 /* This function must be called from the main thread only */
|
771
|
458 struct ntpipe_slurp_stream_shared_data *s =
|
428
|
459 NTPIPE_SLURP_STREAM_DATA(stream)->thread_data;
|
|
460
|
|
461 /* Force thread to stop */
|
|
462 InterlockedIncrement (&s->die_p);
|
|
463
|
|
464 /* Set events which could possibly block slurper. Let it finish soon
|
|
465 or later. */
|
|
466 SetEvent (s->hev_unsleep);
|
|
467 SetEvent (s->hev_thread);
|
|
468
|
|
469 /* Unlock and maybe free shared data */
|
|
470 slurper_free_shared_data_maybe (s);
|
|
471
|
|
472 return 0;
|
|
473 }
|
|
474
|
|
475 static void
|
|
476 init_slurp_stream (void)
|
|
477 {
|
|
478 LSTREAM_HAS_METHOD (ntpipe_slurp, reader);
|
|
479 LSTREAM_HAS_METHOD (ntpipe_slurp, closer);
|
|
480 }
|
853
|
481
|
428
|
482
|
|
483 /************************************************************************/
|
|
484 /* Pipe outstream - writes process input */
|
|
485 /************************************************************************/
|
|
486
|
|
487 #define NTPIPE_SHOVE_STREAM_DATA(stream) \
|
|
488 LSTREAM_TYPE_DATA (stream, ntpipe_shove)
|
|
489
|
442
|
490 #define MAX_SHOVE_BUFFER_SIZE 512
|
428
|
491
|
|
492 struct ntpipe_shove_stream
|
|
493 {
|
|
494 LPARAM user_data; /* Any user data stored in the stream object */
|
|
495 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */
|
853
|
496 /* This is an auto-reset object. */
|
428
|
497 HANDLE hpipe; /* Pipe write end handle. */
|
|
498 HANDLE hthread; /* Reader thread handle. */
|
|
499 char buffer[MAX_SHOVE_BUFFER_SIZE]; /* Buffer being written */
|
|
500 DWORD size; /* Number of bytes to write */
|
|
501 LONG die_p; /* Thread must exit ASAP if non-zero */
|
|
502 LONG idle_p; /* Non-zero if thread is waiting for job */
|
|
503 BOOL error_p : 1; /* Read error other than EOF/broken pipe */
|
|
504 BOOL blocking_p : 1;/* Last write attempt would cause blocking */
|
|
505 };
|
|
506
|
771
|
507 DEFINE_LSTREAM_IMPLEMENTATION ("ntpipe-output", ntpipe_shove);
|
428
|
508
|
|
509 static DWORD WINAPI
|
|
510 shove_thread (LPVOID vparam)
|
|
511 {
|
771
|
512 struct ntpipe_shove_stream *s = (struct ntpipe_shove_stream *) vparam;
|
428
|
513
|
|
514 for (;;)
|
|
515 {
|
|
516 DWORD bytes_written;
|
|
517
|
|
518 /* Block on event and wait for a job */
|
|
519 InterlockedIncrement (&s->idle_p);
|
|
520 WaitForSingleObject (s->hev_thread, INFINITE);
|
|
521
|
771
|
522 if (s->die_p)
|
|
523 break;
|
|
524
|
442
|
525 /* Write passed buffer if any */
|
|
526 if (s->size > 0)
|
428
|
527 {
|
442
|
528 if (!WriteFile (s->hpipe, s->buffer, s->size, &bytes_written, NULL)
|
|
529 || bytes_written != s->size)
|
|
530 {
|
|
531 s->error_p = TRUE;
|
|
532 InterlockedIncrement (&s->die_p);
|
|
533 }
|
|
534 /* Set size to zero so we won't write it again if the closer sets
|
|
535 die_p and kicks us */
|
|
536 s->size = 0;
|
428
|
537 }
|
|
538
|
|
539 if (s->die_p)
|
|
540 break;
|
|
541 }
|
|
542
|
|
543 return 0;
|
|
544 }
|
|
545
|
|
546 static Lisp_Object
|
|
547 make_ntpipe_output_stream (HANDLE hpipe, LPARAM param)
|
|
548 {
|
|
549 Lstream *lstr = Lstream_new (lstream_ntpipe_shove, "w");
|
771
|
550 struct ntpipe_shove_stream *s = NTPIPE_SHOVE_STREAM_DATA (lstr);
|
428
|
551 DWORD thread_id_unused;
|
|
552
|
|
553 s->die_p = 0;
|
|
554 s->error_p = FALSE;
|
|
555 s->hpipe = hpipe;
|
|
556 s->user_data = param;
|
|
557
|
|
558 /* Create reader thread. This could fail, so do not
|
|
559 create the event until thread is created */
|
|
560 s->hthread = CreateThread (NULL, 0, shove_thread, (LPVOID)s,
|
|
561 CREATE_SUSPENDED, &thread_id_unused);
|
|
562 if (s->hthread == NULL)
|
|
563 {
|
|
564 Lstream_delete (lstr);
|
|
565 return Qnil;
|
|
566 }
|
|
567
|
442
|
568 /* Set the priority of the thread higher so we don't end up waiting
|
|
569 on it to send things. */
|
|
570 if (!SetThreadPriority (s->hthread, THREAD_PRIORITY_HIGHEST))
|
|
571 {
|
|
572 CloseHandle (s->hthread);
|
|
573 Lstream_delete (lstr);
|
|
574 return Qnil;
|
|
575 }
|
|
576
|
428
|
577 /* hev_thread is an auto-reset event, initially nonsignaled */
|
771
|
578 s->hev_thread = qxeCreateEvent (NULL, FALSE, FALSE, NULL);
|
428
|
579
|
|
580 /* Now let it go */
|
|
581 ResumeThread (s->hthread);
|
|
582
|
|
583 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
|
793
|
584 return wrap_lstream (lstr);
|
428
|
585 }
|
|
586
|
|
587 static LPARAM
|
|
588 get_ntpipe_output_stream_param (Lstream *stream)
|
|
589 {
|
771
|
590 struct ntpipe_shove_stream *s = NTPIPE_SHOVE_STREAM_DATA(stream);
|
428
|
591 return s->user_data;
|
|
592 }
|
|
593
|
665
|
594 static Bytecount
|
462
|
595 ntpipe_shove_writer (Lstream *stream, const unsigned char *data,
|
665
|
596 Bytecount size)
|
428
|
597 {
|
771
|
598 struct ntpipe_shove_stream *s = NTPIPE_SHOVE_STREAM_DATA(stream);
|
428
|
599
|
|
600 if (s->error_p)
|
|
601 return -1;
|
|
602
|
|
603 s->blocking_p = !s->idle_p;
|
|
604 if (s->blocking_p)
|
|
605 return 0;
|
|
606
|
|
607 if (size>MAX_SHOVE_BUFFER_SIZE)
|
|
608 return 0;
|
|
609
|
|
610 memcpy (s->buffer, data, size);
|
|
611 s->size = size;
|
|
612
|
|
613 /* Start output */
|
|
614 InterlockedDecrement (&s->idle_p);
|
|
615 SetEvent (s->hev_thread);
|
442
|
616 /* Give it a chance to run -- this dramatically improves performance
|
|
617 of things like crypt. */
|
771
|
618 if (xSwitchToThread) /* not in Win9x */
|
442
|
619 (void) xSwitchToThread ();
|
428
|
620 return size;
|
|
621 }
|
|
622
|
|
623 static int
|
|
624 ntpipe_shove_was_blocked_p (Lstream *stream)
|
|
625 {
|
771
|
626 struct ntpipe_shove_stream *s = NTPIPE_SHOVE_STREAM_DATA(stream);
|
428
|
627 return s->blocking_p;
|
|
628 }
|
|
629
|
|
630 static int
|
|
631 ntpipe_shove_closer (Lstream *stream)
|
|
632 {
|
771
|
633 struct ntpipe_shove_stream *s = NTPIPE_SHOVE_STREAM_DATA(stream);
|
428
|
634
|
|
635 /* Force thread stop */
|
|
636 InterlockedIncrement (&s->die_p);
|
|
637
|
771
|
638 /* Close pipe handle, possibly breaking it */
|
|
639 CloseHandle (s->hpipe);
|
|
640
|
442
|
641 /* Thread will end upon unblocking. If it's already unblocked this will
|
|
642 do nothing, but the thread won't look at die_p until it's written any
|
|
643 pending output. */
|
428
|
644 SetEvent (s->hev_thread);
|
|
645
|
|
646 /* Wait while thread terminates */
|
|
647 WaitForSingleObject (s->hthread, INFINITE);
|
442
|
648
|
|
649 /* Close the thread handle */
|
428
|
650 CloseHandle (s->hthread);
|
|
651
|
|
652 /* Destroy the event */
|
|
653 CloseHandle (s->hev_thread);
|
|
654
|
|
655 return 0;
|
|
656 }
|
|
657
|
|
658 static void
|
|
659 init_shove_stream (void)
|
|
660 {
|
|
661 LSTREAM_HAS_METHOD (ntpipe_shove, writer);
|
|
662 LSTREAM_HAS_METHOD (ntpipe_shove, was_blocked_p);
|
|
663 LSTREAM_HAS_METHOD (ntpipe_shove, closer);
|
|
664 }
|
|
665
|
|
666 /************************************************************************/
|
|
667 /* Winsock I/O stream */
|
|
668 /************************************************************************/
|
|
669
|
|
670 #define WINSOCK_READ_BUFFER_SIZE 1024
|
|
671
|
|
672 struct winsock_stream
|
|
673 {
|
|
674 LPARAM user_data; /* Any user data stored in the stream object */
|
|
675 SOCKET s; /* Socket handle (which is a Win32 handle) */
|
|
676 OVERLAPPED ov; /* Overlapped I/O structure */
|
647
|
677 void *buffer; /* Buffer. */
|
|
678 DWORD bufsize; /* Number of bytes last read */
|
1204
|
679 DWORD charbpos; /* Position in buffer for next fetch */
|
428
|
680 unsigned int error_p :1; /* I/O Error seen */
|
|
681 unsigned int eof_p :1; /* EOF Error seen */
|
|
682 unsigned int pending_p :1; /* There is a pending I/O operation */
|
|
683 unsigned int blocking_p :1; /* Last write attempt would block */
|
|
684 };
|
|
685
|
|
686 #define WINSOCK_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, winsock)
|
|
687
|
771
|
688 DEFINE_LSTREAM_IMPLEMENTATION ("winsock", winsock);
|
428
|
689
|
|
690 static void
|
|
691 winsock_initiate_read (struct winsock_stream *str)
|
|
692 {
|
|
693 ResetEvent (str->ov.hEvent);
|
665
|
694 str->charbpos = 0;
|
428
|
695
|
|
696 if (!ReadFile ((HANDLE)str->s, str->buffer, WINSOCK_READ_BUFFER_SIZE,
|
|
697 &str->bufsize, &str->ov))
|
|
698 {
|
|
699 if (GetLastError () == ERROR_IO_PENDING)
|
|
700 str->pending_p = 1;
|
|
701 else if (GetLastError () == ERROR_HANDLE_EOF)
|
|
702 str->eof_p = 1;
|
|
703 else
|
|
704 str->error_p = 1;
|
|
705 }
|
|
706 else if (str->bufsize == 0)
|
|
707 str->eof_p = 1;
|
|
708 }
|
|
709
|
665
|
710 static Bytecount
|
|
711 winsock_reader (Lstream *stream, unsigned char *data, Bytecount size)
|
428
|
712 {
|
|
713 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
|
|
714
|
|
715 /* If the current operation is not yet complete, there's nothing to
|
|
716 give back */
|
|
717 if (str->pending_p)
|
|
718 {
|
|
719 if (WaitForSingleObject (str->ov.hEvent, 0) == WAIT_TIMEOUT)
|
|
720 {
|
|
721 errno = EAGAIN;
|
|
722 return -1;
|
|
723 }
|
|
724 else
|
|
725 {
|
1204
|
726 if (!GetOverlappedResult ((HANDLE)str->s, &str->ov, &str->bufsize,
|
|
727 TRUE))
|
428
|
728 {
|
|
729 if (GetLastError() == ERROR_HANDLE_EOF)
|
|
730 str->bufsize = 0;
|
|
731 else
|
|
732 str->error_p = 1;
|
|
733 }
|
|
734 if (str->bufsize == 0)
|
|
735 str->eof_p = 1;
|
|
736 str->pending_p = 0;
|
|
737 }
|
|
738 }
|
|
739
|
|
740 if (str->eof_p)
|
|
741 return 0;
|
|
742 if (str->error_p)
|
|
743 return -1;
|
|
744
|
|
745 /* Return as much of buffer as we have */
|
665
|
746 size = min (size, (Bytecount) (str->bufsize - str->charbpos));
|
771
|
747 memcpy (data, (void *) ((BYTE *) str->buffer + str->charbpos), size);
|
665
|
748 str->charbpos += size;
|
428
|
749
|
|
750 /* Read more if buffer is exhausted */
|
665
|
751 if (str->bufsize == str->charbpos)
|
428
|
752 winsock_initiate_read (str);
|
|
753
|
|
754 return size;
|
|
755 }
|
|
756
|
665
|
757 static Bytecount
|
462
|
758 winsock_writer (Lstream *stream, const unsigned char *data,
|
665
|
759 Bytecount size)
|
428
|
760 {
|
|
761 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
|
|
762
|
|
763 if (str->pending_p)
|
|
764 {
|
|
765 if (WaitForSingleObject (str->ov.hEvent, 0) == WAIT_TIMEOUT)
|
|
766 {
|
|
767 str->blocking_p = 1;
|
|
768 return -1;
|
|
769 }
|
|
770 else
|
|
771 {
|
|
772 DWORD dw_unused;
|
1204
|
773 if (!GetOverlappedResult ((HANDLE)str->s, &str->ov, &dw_unused,
|
|
774 TRUE))
|
428
|
775 str->error_p = 1;
|
|
776 str->pending_p = 0;
|
|
777 }
|
|
778 }
|
|
779
|
|
780 str->blocking_p = 0;
|
|
781
|
|
782 if (str->error_p)
|
|
783 return -1;
|
|
784
|
|
785 if (size == 0)
|
|
786 return 0;
|
|
787
|
558
|
788 ResetEvent (str->ov.hEvent);
|
|
789
|
|
790 /* According to WriteFile docs, we must hold onto the data we pass to it
|
|
791 and not make any changes until it finishes -- which may not be until
|
|
792 the next time we get here, since we use asynchronous I/O. We have
|
|
793 in fact seen data loss as a result of not doing this. */
|
|
794 str->buffer = xrealloc (str->buffer, size);
|
|
795 memcpy (str->buffer, data, size);
|
|
796
|
560
|
797 /* According to MSDN WriteFile docs, the fourth parameter cannot be NULL
|
|
798 on Win95 even when doing an overlapped operation, as we are, where
|
|
799 the return value through that parameter is not meaningful. */
|
|
800 if (WriteFile ((HANDLE)str->s, str->buffer, size, &str->bufsize,
|
558
|
801 &str->ov)
|
|
802 || GetLastError() == ERROR_IO_PENDING)
|
|
803 str->pending_p = 1;
|
|
804 else
|
|
805 str->error_p = 1;
|
428
|
806
|
|
807 return str->error_p ? -1 : size;
|
|
808 }
|
|
809
|
|
810 static int
|
|
811 winsock_closer (Lstream *lstr)
|
|
812 {
|
|
813 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
|
|
814
|
|
815 if (lstr->flags & LSTREAM_FL_READ)
|
|
816 shutdown (str->s, 0);
|
|
817 else
|
|
818 shutdown (str->s, 1);
|
|
819
|
986
|
820 closesocket (str->s);
|
428
|
821 if (str->pending_p)
|
|
822 WaitForSingleObject (str->ov.hEvent, INFINITE);
|
|
823
|
558
|
824 if (str->buffer)
|
560
|
825 {
|
|
826 xfree (str->buffer);
|
|
827 str->buffer = 0;
|
|
828 }
|
428
|
829
|
|
830 CloseHandle (str->ov.hEvent);
|
|
831 return 0;
|
|
832 }
|
|
833
|
|
834 static int
|
|
835 winsock_was_blocked_p (Lstream *stream)
|
|
836 {
|
|
837 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
|
|
838 return str->blocking_p;
|
|
839 }
|
|
840
|
|
841 static Lisp_Object
|
442
|
842 make_winsock_stream_1 (SOCKET s, LPARAM param, const char *mode)
|
428
|
843 {
|
|
844 Lstream *lstr = Lstream_new (lstream_winsock, mode);
|
|
845 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
|
|
846
|
558
|
847 xzero (*str);
|
428
|
848 str->s = s;
|
|
849 str->user_data = param;
|
|
850
|
771
|
851 str->ov.hEvent = qxeCreateEvent (NULL, TRUE, FALSE, NULL);
|
428
|
852
|
|
853 if (lstr->flags & LSTREAM_FL_READ)
|
|
854 {
|
|
855 str->buffer = xmalloc (WINSOCK_READ_BUFFER_SIZE);
|
|
856 winsock_initiate_read (str);
|
|
857 }
|
|
858
|
|
859 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
|
793
|
860 return wrap_lstream (lstr);
|
428
|
861 }
|
|
862
|
|
863 static Lisp_Object
|
|
864 make_winsock_input_stream (SOCKET s, LPARAM param)
|
|
865 {
|
|
866 return make_winsock_stream_1 (s, param, "r");
|
|
867 }
|
|
868
|
|
869 static Lisp_Object
|
|
870 make_winsock_output_stream (SOCKET s, LPARAM param)
|
|
871 {
|
|
872 return make_winsock_stream_1 (s, param, "w");
|
|
873 }
|
|
874
|
|
875 static HANDLE
|
|
876 get_winsock_stream_waitable (Lstream *lstr)
|
|
877 {
|
|
878 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
|
|
879 return str->ov.hEvent;
|
|
880 }
|
|
881
|
|
882 static LPARAM
|
|
883 get_winsock_stream_param (Lstream *lstr)
|
|
884 {
|
|
885 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
|
|
886 return str->user_data;
|
|
887 }
|
|
888
|
|
889 static void
|
|
890 init_winsock_stream (void)
|
|
891 {
|
|
892 LSTREAM_HAS_METHOD (winsock, reader);
|
|
893 LSTREAM_HAS_METHOD (winsock, writer);
|
|
894 LSTREAM_HAS_METHOD (winsock, closer);
|
|
895 LSTREAM_HAS_METHOD (winsock, was_blocked_p);
|
|
896 }
|
853
|
897 #endif /* ! CYGWIN */
|
428
|
898
|
|
899 /************************************************************************/
|
|
900 /* Dispatch queue management */
|
|
901 /************************************************************************/
|
|
902
|
|
903 static int
|
771
|
904 mswindows_user_event_p (Lisp_Event *sevt)
|
428
|
905 {
|
|
906 return (sevt->event_type == key_press_event
|
|
907 || sevt->event_type == button_press_event
|
|
908 || sevt->event_type == button_release_event
|
|
909 || sevt->event_type == misc_user_event);
|
|
910 }
|
|
911
|
|
912 /*
|
|
913 * Add an emacs event to the proper dispatch queue
|
|
914 */
|
442
|
915 void
|
428
|
916 mswindows_enqueue_dispatch_event (Lisp_Object event)
|
|
917 {
|
1204
|
918 int user_p = mswindows_user_event_p (XEVENT (event));
|
|
919 if (user_p)
|
|
920 enqueue_dispatch_event (event);
|
|
921 else
|
|
922 enqueue_event (event, &mswindows_s_dispatch_event_queue,
|
|
923 &mswindows_s_dispatch_event_queue_tail);
|
428
|
924
|
|
925 /* Avoid blocking on WaitMessage */
|
771
|
926 qxePostMessage (NULL, XM_BUMPQUEUE, 0, 0);
|
428
|
927 }
|
|
928
|
|
929 /*
|
|
930 * Add a misc-user event to the dispatch queue.
|
|
931 */
|
|
932 void
|
|
933 mswindows_enqueue_misc_user_event (Lisp_Object channel, Lisp_Object function,
|
|
934 Lisp_Object object)
|
|
935 {
|
|
936 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
964
|
937
|
|
938 XSET_EVENT_TYPE (event, misc_user_event);
|
|
939 XSET_EVENT_CHANNEL (event, channel);
|
|
940 XSET_EVENT_TIMESTAMP (event, GetTickCount());
|
1204
|
941 XSET_EVENT_MISC_USER_FUNCTION (event, function);
|
|
942 XSET_EVENT_MISC_USER_OBJECT (event, object);
|
428
|
943
|
|
944 mswindows_enqueue_dispatch_event (event);
|
|
945 }
|
|
946
|
|
947 void
|
440
|
948 mswindows_enqueue_magic_event (HWND hwnd, UINT msg)
|
428
|
949 {
|
|
950 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
964
|
951
|
1204
|
952 XSET_EVENT_CHANNEL (emacs_event, hwnd ? mswindows_find_frame (hwnd) : Qnil);
|
964
|
953 XSET_EVENT_TIMESTAMP (emacs_event, GetMessageTime ());
|
|
954 XSET_EVENT_TYPE (emacs_event, magic_event);
|
1204
|
955 XSET_EVENT_MAGIC_MSWINDOWS_EVENT (emacs_event, msg);
|
428
|
956
|
|
957 mswindows_enqueue_dispatch_event (emacs_event);
|
|
958 }
|
|
959
|
|
960 static void
|
771
|
961 mswindows_enqueue_process_event (Lisp_Process *p)
|
428
|
962 {
|
|
963 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
793
|
964 Lisp_Object process = wrap_process (p);
|
|
965
|
964
|
966 XSET_EVENT_TYPE (emacs_event, process_event);
|
1204
|
967 XSET_EVENT_TIMESTAMP (emacs_event, GetTickCount ());
|
|
968 XSET_EVENT_PROCESS_PROCESS (emacs_event, process);
|
428
|
969
|
|
970 mswindows_enqueue_dispatch_event (emacs_event);
|
|
971 }
|
|
972
|
|
973 static void
|
442
|
974 mswindows_enqueue_mouse_button_event (HWND hwnd, UINT msg, POINTS where,
|
|
975 int mods, DWORD when)
|
428
|
976 {
|
442
|
977 int downp = (msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN ||
|
|
978 msg == WM_RBUTTONDOWN);
|
428
|
979
|
|
980 /* We always use last message time, because mouse button
|
|
981 events may get delayed, and XEmacs double click
|
|
982 recognition will fail */
|
|
983
|
|
984 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
442
|
985
|
|
986 mswindows_handle_sticky_modifiers (0, 0, downp, 0);
|
964
|
987
|
|
988 if (downp)
|
|
989 {
|
|
990 XSET_EVENT_TYPE (emacs_event, button_press_event);
|
|
991 }
|
|
992 else
|
|
993 {
|
|
994 XSET_EVENT_TYPE (emacs_event, button_release_event);
|
|
995 }
|
|
996
|
|
997 XSET_EVENT_CHANNEL (emacs_event, mswindows_find_frame (hwnd));
|
|
998 XSET_EVENT_TIMESTAMP (emacs_event, when);
|
1204
|
999 XSET_EVENT_BUTTON_BUTTON (emacs_event,
|
964
|
1000 (msg==WM_LBUTTONDOWN || msg==WM_LBUTTONUP) ? 1 :
|
|
1001 ((msg==WM_RBUTTONDOWN || msg==WM_RBUTTONUP) ? 3 : 2));
|
1204
|
1002 XSET_EVENT_BUTTON_X (emacs_event, where.x);
|
|
1003 XSET_EVENT_BUTTON_Y (emacs_event, where.y);
|
|
1004 XSET_EVENT_BUTTON_MODIFIERS (emacs_event,
|
|
1005 mswindows_modifier_state (NULL, mods, 0));
|
442
|
1006
|
|
1007 if (downp)
|
428
|
1008 {
|
|
1009 SetCapture (hwnd);
|
|
1010 /* we need this to make sure the main window regains the focus
|
|
1011 from control subwindows */
|
|
1012 if (GetFocus() != hwnd)
|
|
1013 {
|
|
1014 SetFocus (hwnd);
|
|
1015 mswindows_enqueue_magic_event (hwnd, WM_SETFOCUS);
|
|
1016 }
|
|
1017 }
|
|
1018 else
|
|
1019 {
|
|
1020 ReleaseCapture ();
|
|
1021 }
|
|
1022
|
|
1023 mswindows_enqueue_dispatch_event (emacs_event);
|
|
1024 }
|
|
1025
|
771
|
1026 static Lisp_Object
|
428
|
1027 mswindows_enqueue_keypress_event (HWND hwnd, Lisp_Object keysym, int mods)
|
|
1028 {
|
|
1029 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
964
|
1030
|
|
1031 XSET_EVENT_CHANNEL (emacs_event, mswindows_find_console(hwnd));
|
|
1032 XSET_EVENT_TIMESTAMP (emacs_event, GetMessageTime());
|
|
1033 XSET_EVENT_TYPE (emacs_event, key_press_event);
|
1204
|
1034 XSET_EVENT_KEY_KEYSYM (emacs_event, keysym);
|
|
1035 XSET_EVENT_KEY_MODIFIERS (emacs_event, mods);
|
428
|
1036 mswindows_enqueue_dispatch_event (emacs_event);
|
771
|
1037 return emacs_event;
|
428
|
1038 }
|
|
1039
|
|
1040 /*
|
|
1041 * Remove and return the first emacs event on the dispatch queue.
|
|
1042 * Give a preference to user events over non-user ones.
|
|
1043 */
|
|
1044 static Lisp_Object
|
442
|
1045 mswindows_dequeue_dispatch_event (void)
|
428
|
1046 {
|
1204
|
1047 assert (!NILP (dispatch_event_queue) ||
|
|
1048 !NILP (mswindows_s_dispatch_event_queue));
|
|
1049
|
|
1050 if (!NILP (dispatch_event_queue))
|
|
1051 return dequeue_dispatch_event ();
|
|
1052 else
|
|
1053 return dequeue_event (&mswindows_s_dispatch_event_queue,
|
|
1054 &mswindows_s_dispatch_event_queue_tail);
|
428
|
1055 }
|
|
1056
|
853
|
1057 #ifndef CYGWIN
|
428
|
1058 /************************************************************************/
|
|
1059 /* Waitable handles manipulation */
|
|
1060 /************************************************************************/
|
|
1061 static int
|
|
1062 find_waitable_handle (HANDLE h)
|
|
1063 {
|
|
1064 int i;
|
|
1065 for (i = 0; i < mswindows_waitable_count; ++i)
|
|
1066 if (mswindows_waitable_handles[i] == h)
|
|
1067 return i;
|
|
1068
|
|
1069 return -1;
|
|
1070 }
|
|
1071
|
|
1072 static BOOL
|
|
1073 add_waitable_handle (HANDLE h)
|
|
1074 {
|
|
1075 assert (find_waitable_handle (h) < 0);
|
|
1076 if (mswindows_waitable_count == MAX_WAITABLE)
|
|
1077 return FALSE;
|
|
1078
|
|
1079 mswindows_waitable_handles [mswindows_waitable_count++] = h;
|
|
1080 return TRUE;
|
|
1081 }
|
|
1082
|
|
1083 static void
|
|
1084 remove_waitable_handle (HANDLE h)
|
|
1085 {
|
|
1086 int ix = find_waitable_handle (h);
|
|
1087 if (ix < 0)
|
|
1088 return;
|
|
1089
|
|
1090 mswindows_waitable_handles [ix] =
|
|
1091 mswindows_waitable_handles [--mswindows_waitable_count];
|
|
1092 }
|
853
|
1093
|
|
1094 #endif /* CYGWIN */
|
428
|
1095
|
791
|
1096 /*
|
|
1097 * Given a lisp process pointer remove the corresponding process handle
|
|
1098 * from mswindows_waitable_handles if it is in it. Normally the handle is
|
|
1099 * removed when the process terminates, but if the lisp process structure
|
|
1100 * is deleted before the process terminates we must delete the process
|
|
1101 * handle since it will be invalid and will cause the wait to fail
|
|
1102 */
|
|
1103 void
|
|
1104 mswindows_unwait_process (Lisp_Process *p)
|
|
1105 {
|
853
|
1106 #ifndef CYGWIN
|
791
|
1107 remove_waitable_handle (get_nt_process_handle (p));
|
853
|
1108 #endif /* CYGWIN */
|
791
|
1109 }
|
|
1110
|
428
|
1111
|
|
1112 /************************************************************************/
|
|
1113 /* Event pump */
|
|
1114 /************************************************************************/
|
|
1115
|
771
|
1116 int
|
|
1117 mswindows_window_is_xemacs (HWND hwnd)
|
|
1118 {
|
|
1119 /* GetClassName will truncate a longer class name. By adding one
|
|
1120 extra character, we are forcing textual comparison to fail
|
|
1121 if the name is longer than XEMACS_CLASS */
|
|
1122 Extbyte class_name_buf[sizeof (XEMACS_CLASS) + 2];
|
|
1123
|
|
1124 /* Use GetClassNameA because XEMACS_CLASS is not in Unicode format. */
|
|
1125 if (!GetClassNameA (hwnd, class_name_buf, sizeof (class_name_buf) - 1))
|
|
1126 return 0;
|
|
1127
|
|
1128 return !ascii_strcasecmp (class_name_buf, XEMACS_CLASS);
|
|
1129 }
|
|
1130
|
428
|
1131 void
|
|
1132 mswindows_unmodalize_signal_maybe (void)
|
|
1133 {
|
853
|
1134 mswindows_error_caught_in_modal_loop = 0;
|
428
|
1135 }
|
|
1136
|
|
1137 /*
|
|
1138 * This is an unsafe part of event pump, guarded by
|
|
1139 * condition_case. See mswindows_pump_outstanding_events
|
|
1140 */
|
|
1141 static Lisp_Object
|
1268
|
1142 mswindows_unsafe_pump_events (void *arg)
|
428
|
1143 {
|
|
1144 /* This function can call lisp */
|
|
1145 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
|
1146 struct gcpro gcpro1;
|
|
1147 int do_redisplay = 0;
|
|
1148 GCPRO1 (event);
|
|
1149
|
1268
|
1150 while (detect_input_pending (1))
|
428
|
1151 {
|
|
1152 Fnext_event (event, Qnil);
|
|
1153 Fdispatch_event (event);
|
|
1154 do_redisplay = 1;
|
|
1155 }
|
|
1156
|
|
1157 if (do_redisplay)
|
|
1158 redisplay ();
|
|
1159
|
|
1160 Fdeallocate_event (event);
|
|
1161 UNGCPRO;
|
|
1162
|
|
1163 /* Qt becomes return value of mswindows_pump_outstanding_events
|
|
1164 once we get here */
|
|
1165 return Qt;
|
|
1166 }
|
|
1167
|
|
1168 /*
|
|
1169 * This function pumps emacs events, while available, by using
|
|
1170 * next_message/dispatch_message loop. Errors are trapped around
|
|
1171 * the loop so the function always returns.
|
|
1172 *
|
|
1173 * Windows message queue is not looked into during the call,
|
|
1174 * neither are waitable handles checked. The function pumps
|
|
1175 * thus only dispatch events already queued, as well as those
|
|
1176 * resulted in dispatching thereof. This is done by setting
|
1268
|
1177 * in_modal_loop to nonzero.
|
428
|
1178 *
|
|
1179 * Return value is Qt if no errors was trapped, or Qunbound if
|
|
1180 * there was an error.
|
|
1181 *
|
853
|
1182 * In case of error, a warning is issued and the module local variable
|
|
1183 * mswindows_error_caught_in_modal_loop is set to non-zero. Thus,
|
|
1184 * Windows internal modal loops are protected against throws, which
|
|
1185 * are proven to corrupt internal Windows structures.
|
428
|
1186 *
|
|
1187 * In case of success, mswindows_error_caught_in_modal_loop is
|
853
|
1188 * assigned 0.
|
428
|
1189 *
|
|
1190 * If the value of mswindows_error_caught_in_modal_loop is not
|
853
|
1191 * zero already upon entry, the function just returns non-nil.
|
428
|
1192 * This situation means that a new event has been queued while
|
|
1193 * in cancel mode. The event will be dequeued on the next regular
|
|
1194 * call of next-event; the pump is off since error is caught.
|
|
1195 * The caller must *unconditionally* cancel modal loop if the
|
|
1196 * value returned by this function is nil. Otherwise, everything
|
|
1197 * will become frozen until the modal loop exits under normal
|
853
|
1198 * condition (scrollbar drag is released, menu closed etc.) */
|
428
|
1199 Lisp_Object
|
|
1200 mswindows_pump_outstanding_events (void)
|
|
1201 {
|
|
1202 /* This function can call lisp */
|
|
1203
|
|
1204 Lisp_Object result = Qt;
|
|
1205 struct gcpro gcpro1;
|
|
1206 GCPRO1 (result);
|
|
1207
|
853
|
1208 if (!mswindows_error_caught_in_modal_loop)
|
1268
|
1209 result = event_stream_protect_modal_loop
|
|
1210 ("Error during event handling", mswindows_unsafe_pump_events, 0, 0);
|
428
|
1211 UNGCPRO;
|
1268
|
1212 if (UNBOUNDP (result))
|
|
1213 mswindows_error_caught_in_modal_loop = 1;
|
428
|
1214 return result;
|
|
1215 }
|
|
1216
|
440
|
1217 /*
|
428
|
1218 * This is a special flavor of the mswindows_need_event function,
|
|
1219 * used while in event pump. Actually, there is only kind of events
|
|
1220 * allowed while in event pump: a timer. An attempt to fetch any
|
|
1221 * other event leads to a deadlock, as there's no source of user input
|
|
1222 * ('cause event pump mirrors windows modal loop, which is a sole
|
|
1223 * owner of thread message queue).
|
|
1224 *
|
|
1225 * To detect this, we use a counter of active timers, and allow
|
|
1226 * fetching WM_TIMER messages. Instead of trying to fetch a WM_TIMER
|
|
1227 * which will never come when there are no pending timers, which leads
|
|
1228 * to deadlock, we simply signal an error.
|
487
|
1229 *
|
|
1230 * It might be possible to combine this with mswindows_drain_windows_queue
|
|
1231 * which fetches events when not in a modal loop. It's not clear
|
|
1232 * whether the result would be more complex than is justified.
|
428
|
1233 */
|
|
1234 static void
|
|
1235 mswindows_need_event_in_modal_loop (int badly_p)
|
|
1236 {
|
|
1237 MSG msg;
|
|
1238
|
|
1239 /* Check if already have one */
|
1204
|
1240 if (!NILP (dispatch_event_queue)
|
428
|
1241 || !NILP (mswindows_s_dispatch_event_queue))
|
|
1242 return;
|
|
1243
|
|
1244 /* No event is ok */
|
|
1245 if (!badly_p)
|
|
1246 return;
|
|
1247
|
1204
|
1248 /* We do not check the user queue, because timers go to _s_ */
|
428
|
1249 while (NILP (mswindows_s_dispatch_event_queue))
|
|
1250 {
|
|
1251 /* We'll deadlock if go waiting */
|
|
1252 if (mswindows_pending_timers_count == 0)
|
1204
|
1253 invalid_operation
|
|
1254 ("Deadlock due to an attempt to call next-event in a wrong context",
|
|
1255 Qunbound);
|
428
|
1256
|
|
1257 /* Fetch and dispatch any pending timers */
|
771
|
1258 if (qxeGetMessage (&msg, NULL, WM_TIMER, WM_TIMER) > 0)
|
|
1259 qxeDispatchMessage (&msg);
|
428
|
1260 }
|
|
1261 }
|
|
1262
|
1268
|
1263 /* BADLY_P non-zero means we were called from mswindows_need_event(1). It
|
|
1264 only matters when we are in a modal loop, and causes us to fetch timer
|
|
1265 events (the only kinds we can fetch in such a case).
|
|
1266 */
|
|
1267 static void
|
|
1268 mswindows_drain_windows_queue (int badly_p)
|
|
1269 {
|
|
1270 MSG msg;
|
|
1271
|
|
1272 if (in_modal_loop)
|
|
1273 mswindows_need_event_in_modal_loop (badly_p);
|
|
1274 else
|
|
1275 while (qxePeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
|
|
1276 {
|
|
1277 #ifdef HAVE_DIALOGS
|
|
1278 /* Don't translate messages destined for a dialog box, this
|
|
1279 makes keyboard traversal work. I think?? */
|
|
1280 if (mswindows_is_dialog_msg (&msg))
|
|
1281 {
|
|
1282 mswindows_unmodalize_signal_maybe ();
|
|
1283 continue;
|
|
1284 }
|
|
1285 #endif /* HAVE_DIALOGS */
|
|
1286
|
|
1287 /* We have to translate messages that are not sent to an XEmacs
|
|
1288 frame. This is so that key presses work ok in things like
|
|
1289 edit fields. However, we *musn't* translate message for XEmacs
|
|
1290 frames as this is handled in the wnd proc.
|
|
1291 We also have to avoid generating paint magic events for windows
|
|
1292 that aren't XEmacs frames */
|
|
1293
|
|
1294 if (!mswindows_window_is_xemacs (msg.hwnd))
|
|
1295 TranslateMessage (&msg);
|
|
1296 else if (msg.message == WM_PAINT)
|
|
1297 {
|
|
1298 struct mswindows_frame *msframe;
|
|
1299
|
|
1300 /* hdc will be NULL unless this is a subwindow - in which case we
|
|
1301 shouldn't have received a paint message for it here. */
|
|
1302 assert (msg.wParam == 0);
|
|
1303
|
|
1304 /* Queue a magic event for handling when safe */
|
|
1305 msframe =
|
|
1306 FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (msg.hwnd)));
|
|
1307 if (!msframe->paint_pending)
|
|
1308 {
|
|
1309 msframe->paint_pending = 1;
|
|
1310 mswindows_enqueue_magic_event (msg.hwnd, WM_PAINT);
|
|
1311 }
|
|
1312 /* Don't dispatch. WM_PAINT is always the last message in the
|
|
1313 queue so it's OK to just return. */
|
|
1314 return;
|
|
1315 }
|
|
1316 qxeDispatchMessage (&msg);
|
|
1317 mswindows_unmodalize_signal_maybe ();
|
|
1318 }
|
|
1319 }
|
|
1320
|
|
1321 static void
|
|
1322 emacs_mswindows_drain_queue (void)
|
|
1323 {
|
|
1324 mswindows_drain_windows_queue (0);
|
|
1325 #ifdef HAVE_TTY
|
|
1326 drain_tty_devices ();
|
|
1327 #endif
|
|
1328 }
|
|
1329
|
428
|
1330 /*
|
|
1331 * This drains the event queue and fills up two internal queues until
|
|
1332 * an event of a type specified by USER_P is retrieved.
|
|
1333 *
|
|
1334 *
|
|
1335 * Used by emacs_mswindows_event_pending_p and emacs_mswindows_next_event
|
|
1336 */
|
|
1337 static void
|
|
1338 mswindows_need_event (int badly_p)
|
|
1339 {
|
1204
|
1340 while (NILP (dispatch_event_queue)
|
428
|
1341 && NILP (mswindows_s_dispatch_event_queue))
|
|
1342 {
|
853
|
1343 #ifdef CYGWIN
|
428
|
1344 int i;
|
647
|
1345 int active;
|
428
|
1346 SELECT_TYPE temp_mask = input_wait_mask;
|
|
1347 EMACS_TIME sometime;
|
|
1348 EMACS_SELECT_TIME select_time_to_block, *pointer_to_this;
|
|
1349
|
|
1350 if (badly_p)
|
|
1351 pointer_to_this = 0;
|
|
1352 else
|
|
1353 {
|
|
1354 EMACS_SET_SECS_USECS (sometime, 0, 0);
|
|
1355 EMACS_TIME_TO_SELECT_TIME (sometime, select_time_to_block);
|
|
1356 pointer_to_this = &select_time_to_block;
|
1268
|
1357 if (in_modal_loop)
|
534
|
1358 /* In modal loop with badly_p false, don't care about
|
|
1359 Windows events. */
|
|
1360 FD_CLR (windows_fd, &temp_mask);
|
428
|
1361 }
|
|
1362
|
|
1363 active = select (MAXDESC, &temp_mask, 0, 0, pointer_to_this);
|
|
1364
|
|
1365 if (active == 0)
|
|
1366 {
|
|
1367 assert (!badly_p);
|
|
1368 return; /* timeout */
|
|
1369 }
|
|
1370 else if (active > 0)
|
|
1371 {
|
|
1372 if (FD_ISSET (windows_fd, &temp_mask))
|
1268
|
1373 mswindows_drain_windows_queue (badly_p);
|
442
|
1374 else
|
428
|
1375 {
|
442
|
1376 #ifdef HAVE_TTY
|
|
1377 /* Look for a TTY event */
|
1204
|
1378 for (i = 0; i < MAXDESC; i++)
|
428
|
1379 {
|
442
|
1380 /* To avoid race conditions (among other things, an infinite
|
|
1381 loop when called from Fdiscard_input()), we must return
|
|
1382 user events ahead of process events. */
|
|
1383 if (FD_ISSET (i, &temp_mask) && FD_ISSET (i, &tty_only_mask))
|
428
|
1384 {
|
1204
|
1385 struct console *c =
|
|
1386 find_tty_or_stream_console_from_fd (i);
|
442
|
1387 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
771
|
1388 Lisp_Event *event = XEVENT (emacs_event);
|
|
1389
|
442
|
1390 assert (c);
|
771
|
1391 if (read_event_from_tty_or_stream_desc (event, c))
|
442
|
1392 {
|
|
1393 mswindows_enqueue_dispatch_event (emacs_event);
|
|
1394 return;
|
|
1395 }
|
428
|
1396 }
|
|
1397 }
|
|
1398 #endif
|
442
|
1399 /* Look for a process event */
|
1204
|
1400 for (i = 0; i < MAXDESC; i++)
|
428
|
1401 {
|
442
|
1402 if (FD_ISSET (i, &temp_mask))
|
428
|
1403 {
|
442
|
1404 if (FD_ISSET (i, &process_only_mask))
|
|
1405 {
|
|
1406 Lisp_Process *p =
|
1204
|
1407 get_process_from_usid (FD_TO_USID (i));
|
442
|
1408
|
|
1409 mswindows_enqueue_process_event (p);
|
|
1410 }
|
|
1411 else
|
|
1412 {
|
|
1413 /* We might get here when a fake event came
|
|
1414 through a signal. Return a dummy event, so
|
|
1415 that a cycle of the command loop will
|
|
1416 occur. */
|
|
1417 drain_signal_event_pipe ();
|
|
1418 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
|
|
1419 }
|
428
|
1420 }
|
|
1421 }
|
|
1422 }
|
|
1423 }
|
771
|
1424 else if (active == -1)
|
428
|
1425 {
|
|
1426 if (errno != EINTR)
|
|
1427 {
|
|
1428 /* something bad happened */
|
1204
|
1429 assert (0);
|
428
|
1430 }
|
|
1431 }
|
|
1432 else
|
|
1433 {
|
1204
|
1434 assert (0);
|
428
|
1435 }
|
853
|
1436 #else /* not CYGWIN */
|
428
|
1437 /* Now try getting a message or process event */
|
647
|
1438 DWORD active;
|
487
|
1439 DWORD what_events;
|
1268
|
1440 if (in_modal_loop)
|
534
|
1441 /* In a modal loop, only look for timer events, and only if
|
|
1442 we really need one. */
|
|
1443 {
|
|
1444 if (badly_p)
|
|
1445 what_events = QS_TIMER;
|
|
1446 else
|
|
1447 what_events = 0;
|
|
1448 }
|
487
|
1449 else
|
534
|
1450 /* Look for any event */
|
|
1451 what_events = QS_ALLINPUT;
|
487
|
1452
|
771
|
1453 /*
|
|
1454 #### YUCK YUCK YUCK!!!!
|
|
1455
|
|
1456 When running under a debugger, every time I hit F12 (which for me
|
|
1457 is mapped to right-brace) I hit a breakpoint inside of Windows!
|
|
1458
|
|
1459 NTDLL! DbgBreakPoint@0 address 0x77f9eea9
|
|
1460 KERNEL32! BaseAttachComplete@4 + 41 bytes
|
|
1461 KERNEL32! BaseAttachCompleteThunk@0 + 19 bytes
|
|
1462 USER32! MsgWaitForMultipleObjectsEx@20 + 224 bytes
|
|
1463 USER32! MsgWaitForMultipleObjects@20 + 30 bytes
|
|
1464
|
|
1465 Microsoft says:
|
|
1466
|
|
1467 (Knowledge Base Q130667, PRB: F12 Causes Hard-Coded Breakpoint
|
|
1468 Exception When Debugging)
|
|
1469
|
|
1470 CAUSE
|
|
1471
|
|
1472 When the F12 key is pressed and the application in focus is being
|
|
1473 debugged, Windows NT calls a function similar to DebugBreak(),
|
|
1474 which executes a hard coded breakpoint instruction. The integrated
|
|
1475 debugger then traps the exception generated by this instruction.
|
|
1476
|
|
1477 This behavior is intentional and occurs with other debuggers such
|
|
1478 as WinDbg from the Windows 32-bit SDK.
|
|
1479
|
|
1480 RESOLUTION
|
|
1481
|
|
1482 While there is no way to disable this functionality, it doesn't
|
|
1483 affect the application that's being debugged other than to pause
|
|
1484 debugging and change focus. You can continue debugging by pressing
|
|
1485 the F5 key.
|
|
1486
|
|
1487 This can be annoying if you have an application that heavily uses
|
|
1488 the F12 key, so you may want to temporarily assign another key to
|
|
1489 handle the F12 key functionality in your program when debugging.
|
|
1490
|
|
1491 STATUS
|
|
1492
|
|
1493 This behavior is by design.
|
|
1494
|
|
1495
|
|
1496 However, elsewhere I found this:
|
|
1497
|
|
1498 UserDebuggerHotKey
|
|
1499 HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug
|
|
1500
|
|
1501 Data type Range Default value
|
|
1502 REG_DWORD 0x0 - 0xFF 0x0
|
|
1503
|
|
1504 Description
|
|
1505
|
|
1506 Specifies the key that, when pressed, establishes a breakpoint in
|
|
1507 code being debugged.
|
|
1508
|
|
1509 The debugger interrupts code processing at the breakpoint so the
|
|
1510 programmer can examine a suspected problem.
|
|
1511
|
|
1512 The key specified in this value only sets a breakpoint. It does
|
|
1513 not invoke the debugger (the debugger must be running before the
|
|
1514 key is pressed) and it does not switch the debugger to single-step
|
|
1515 mode.
|
|
1516
|
|
1517 The value of this entry is a keyboard scan code. The default
|
|
1518 value, 0x0, represents the F12 key on a 101-key keyboard or the -
|
|
1519 (hyphen, VK_SUBTRACT) key on an 82-key keyboard.
|
|
1520 */
|
|
1521
|
853
|
1522 __try
|
|
1523 {
|
923
|
1524 /* This fixes a long outstanding bug, where XEmacs would occasionally
|
|
1525 * not redraw its window (or process other events) until "something
|
|
1526 * happened" - usually the mouse moving over a frame.
|
|
1527 *
|
|
1528 * The problem is that MsgWaitForMultipleObjects only checks to see
|
|
1529 * if NEW messages have been placed into the thread queue. So we
|
|
1530 * specifically check to see if the queue is empty (using PeekMessage
|
|
1531 * with the PM_NOREMOVE flag) before we wait.
|
|
1532 */
|
|
1533 MSG msg;
|
|
1534 if (what_events == QS_ALLINPUT && badly_p &&
|
|
1535 qxePeekMessage (&msg, 0, 0, 0, PM_NOREMOVE))
|
|
1536 active = WAIT_OBJECT_0 + mswindows_waitable_count;
|
|
1537 else
|
|
1538 active = MsgWaitForMultipleObjects (mswindows_waitable_count,
|
|
1539 mswindows_waitable_handles,
|
|
1540 FALSE, badly_p ? INFINITE : 0,
|
|
1541 what_events);
|
853
|
1542 }
|
|
1543 __except (GetExceptionCode () == EXCEPTION_BREAKPOINT ?
|
|
1544 EXCEPTION_CONTINUE_EXECUTION :
|
|
1545 EXCEPTION_CONTINUE_SEARCH)
|
|
1546 {
|
|
1547 }
|
442
|
1548
|
|
1549 /* This will assert if handle being waited for becomes abandoned.
|
|
1550 Not the case currently tho */
|
|
1551 assert ((!badly_p && active == WAIT_TIMEOUT) ||
|
|
1552 (active >= WAIT_OBJECT_0 &&
|
|
1553 active <= WAIT_OBJECT_0 + mswindows_waitable_count));
|
|
1554
|
|
1555 if (active == WAIT_TIMEOUT)
|
|
1556 {
|
|
1557 /* No luck trying - just return what we've already got */
|
|
1558 return;
|
|
1559 }
|
|
1560 else if (active == WAIT_OBJECT_0 + mswindows_waitable_count)
|
1268
|
1561 mswindows_drain_windows_queue (badly_p);
|
442
|
1562 else
|
|
1563 {
|
|
1564 int ix = active - WAIT_OBJECT_0;
|
1204
|
1565
|
|
1566 /* look for a stream console event; see
|
|
1567 emacs_mswindows_select_console below. */
|
|
1568 LIST_LOOP_3 (porca_troia, Vconsole_list, vcontail)
|
442
|
1569 {
|
1204
|
1570 struct console *con = XCONSOLE (porca_troia);
|
|
1571
|
|
1572 if (CONSOLE_STREAM_P (con))
|
|
1573 {
|
|
1574 Lisp_Object instr = CONSOLE_STREAM_DATA (con)->instream;
|
|
1575 if (!NILP (instr) && !UNBOUNDP (instr) &&
|
|
1576 get_ntpipe_input_stream_waitable (XLSTREAM (instr)) ==
|
|
1577 mswindows_waitable_handles [ix])
|
|
1578 {
|
|
1579 Ichar ch = Lstream_get_ichar (XLSTREAM (instr));
|
|
1580 if (ch < 0)
|
|
1581 {
|
|
1582 /* deleting the console might not be safe right now
|
|
1583 ... */
|
|
1584 enqueue_magic_eval_event (io_error_delete_console,
|
|
1585 porca_troia);
|
|
1586 /* but we definitely need to unselect it to avoid
|
|
1587 infinite loops reading EOF's */
|
|
1588 Fconsole_disable_input (porca_troia);
|
|
1589 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
|
|
1590 }
|
|
1591 else
|
|
1592 {
|
|
1593 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
|
1594 /* Here we really do want to set the
|
|
1595 use_console_meta_flag because the char is from the
|
|
1596 TTY. */
|
|
1597 character_to_event (ch, XEVENT (event), con, 1, 1);
|
|
1598 XSET_EVENT_CHANNEL (event, porca_troia);
|
|
1599 enqueue_dispatch_event (event);
|
|
1600 }
|
|
1601 break;
|
|
1602 }
|
|
1603 }
|
|
1604 }
|
|
1605
|
|
1606 if (NILP (vcontail))
|
|
1607 { /* no stream console event, look for process event */
|
|
1608 /* First, try to find which process' output has signaled */
|
|
1609 Lisp_Process *p =
|
|
1610 get_process_from_usid (HANDLE_TO_USID
|
|
1611 (mswindows_waitable_handles[ix]));
|
|
1612 if (p != NULL)
|
|
1613 /* Found a signaled process input handle */
|
|
1614 mswindows_enqueue_process_event (p);
|
853
|
1615 else
|
442
|
1616 {
|
1204
|
1617 /* None. This means that the process handle itself has
|
|
1618 signaled. Remove the handle from the wait vector, and
|
|
1619 make status_notify note the exited process. First
|
|
1620 find the process object if possible. */
|
|
1621 LIST_LOOP_3 (vaffanculo, Vprocess_list, vproctail)
|
|
1622 if (get_nt_process_handle (XPROCESS (vaffanculo)) ==
|
|
1623 mswindows_waitable_handles [ix])
|
|
1624 break;
|
|
1625 mswindows_waitable_handles [ix] =
|
|
1626 mswindows_waitable_handles [--mswindows_waitable_count];
|
|
1627 kick_status_notify ();
|
|
1628 /* We need to return a process event here so that (1)
|
|
1629 accept-process-output will return when called on this
|
|
1630 process, and (2) status notifications will happen in
|
|
1631 accept-process-output, sleep-for, and sit-for. */
|
|
1632 if (!NILP (vproctail))
|
|
1633 mswindows_enqueue_process_event (XPROCESS (vaffanculo));
|
|
1634 else
|
|
1635 {
|
|
1636 /* abort (); */
|
|
1637 /* #### FUCKME! When can this happen? I hit this
|
|
1638 abort() when I tried enabling it. */
|
|
1639 /* Have to return something: there may be no
|
|
1640 accompanying process event */
|
|
1641 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
|
|
1642 }
|
442
|
1643 }
|
|
1644 }
|
|
1645 }
|
853
|
1646 #endif /* not CYGWIN */
|
442
|
1647 } /* while */
|
428
|
1648 }
|
|
1649
|
|
1650 /************************************************************************/
|
|
1651 /* Event generators */
|
|
1652 /************************************************************************/
|
|
1653
|
|
1654 /*
|
|
1655 * Callback procedure for synchronous timer messages
|
|
1656 */
|
|
1657 static void CALLBACK
|
|
1658 mswindows_wm_timer_callback (HWND hwnd, UINT umsg, UINT id_timer, DWORD dwtime)
|
|
1659 {
|
|
1660 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
1661
|
|
1662 if (KillTimer (NULL, id_timer))
|
|
1663 --mswindows_pending_timers_count;
|
|
1664
|
964
|
1665 XSET_EVENT_CHANNEL (emacs_event, Qnil);
|
|
1666 XSET_EVENT_TIMESTAMP (emacs_event, dwtime);
|
|
1667 XSET_EVENT_TYPE (emacs_event, timeout_event);
|
1204
|
1668 XSET_EVENT_TIMEOUT_INTERVAL_ID (emacs_event, id_timer);
|
|
1669 XSET_EVENT_TIMEOUT_FUNCTION (emacs_event, Qnil);
|
|
1670 XSET_EVENT_TIMEOUT_OBJECT (emacs_event, Qnil);
|
428
|
1671
|
|
1672 mswindows_enqueue_dispatch_event (emacs_event);
|
|
1673 }
|
|
1674
|
|
1675 /*
|
|
1676 * Callback procedure for dde messages
|
|
1677 *
|
|
1678 * We execute a dde Open("file") by simulating a file drop, so dde support
|
|
1679 * depends on dnd support.
|
|
1680 */
|
|
1681 #ifdef HAVE_DRAGNDROP
|
657
|
1682 extern int mswindows_dde_enable;
|
|
1683
|
903
|
1684 EXFUN(Fread_from_string, 3);
|
|
1685
|
|
1686 /* The following variables are used to maintain consistency of result and
|
|
1687 * error reporting to the client.
|
|
1688 * The basic protocol is to Execute a lisp form, and then Request one or
|
|
1689 * more of the following items: Status (1 = OK, 0 = Error), Result, or Error.
|
|
1690 * When the lisp form is queued, the dde_eval_pending flag is set to 1,
|
|
1691 * to indicate that the items are not yet available. The dde_eval_pending
|
|
1692 * flag is set to 0 when the evaluation is complete. Requests for the result
|
|
1693 * items will block while the dde_eval_pending flag is 1, to avoid clients
|
|
1694 * getting inconsistent results.
|
|
1695 */
|
|
1696 static int dde_eval_pending;
|
|
1697 static Lisp_Object dde_eval_result;
|
|
1698 static Lisp_Object dde_eval_error;
|
|
1699
|
|
1700 static Lisp_Object
|
|
1701 dde_error (Lisp_Object err, Lisp_Object obj)
|
|
1702 {
|
|
1703 dde_eval_error = err;
|
|
1704 return Qnil;
|
|
1705 }
|
|
1706
|
|
1707 /* Read lisp forms from a string. Evaluate the forms as if they were
|
|
1708 * wrapped in a progn form. Return the result of the form.
|
|
1709 */
|
|
1710 static Lisp_Object
|
|
1711 dde_eval_string (Lisp_Object str)
|
|
1712 {
|
|
1713 struct gcpro gcpro1, gcpro2;
|
|
1714 Lisp_Object args[3];
|
|
1715 Lisp_Object obj;
|
|
1716
|
|
1717 /* Heavy handed GCPROing, on the principle of it's better to be safe than
|
|
1718 * sorry...
|
|
1719 */
|
|
1720 args[0] = Qnil;
|
|
1721 args[1] = Qnil;
|
|
1722 args[2] = Qnil;
|
|
1723 GCPRO2 (args[0], str);
|
|
1724 gcpro1.nvars = 3;
|
|
1725
|
|
1726 /* Wrap the user supplied string in string "(progn ...)".
|
|
1727 * We can now just read-from-string a single form. If we
|
|
1728 * get an error, or finish before the end of the string,
|
|
1729 * we know the original string had syntax errors.
|
|
1730 */
|
|
1731 args[0] = build_string ("(progn ");
|
|
1732 args[1] = str;
|
|
1733 args[2] = build_string (")");
|
|
1734 str = Fconcat (3, args);
|
|
1735
|
|
1736 obj = Fread_from_string (str, Qnil, Qnil);
|
|
1737 UNGCPRO;
|
|
1738
|
|
1739 /* The following doesn't check that the length fits in an EMACS_INT.
|
|
1740 * This won't be a problem in reality...?
|
|
1741 *
|
|
1742 * If the read didn't get to the end of the string, we have a syntax
|
|
1743 * error in the string supplied by the user.
|
|
1744 */
|
|
1745 if (XINT (XCDR (obj)) != XSTRING_LENGTH (str))
|
|
1746 return Qnil;
|
|
1747
|
|
1748 GCPRO1 (obj);
|
|
1749 obj = Feval (XCAR (obj));
|
|
1750
|
1204
|
1751 RETURN_UNGCPRO (obj);
|
903
|
1752 }
|
|
1753
|
|
1754 /* Evaluate the supplied string as a sequence of Lisp forms, wrapped in
|
|
1755 * a progn. Catch any evaluation errors. Set the evaluation status and
|
|
1756 * result variables.
|
|
1757 */
|
|
1758 static void
|
|
1759 dde_eval (Lisp_Object str)
|
|
1760 {
|
|
1761 dde_eval_error = Qnil;
|
|
1762 dde_eval_result = condition_case_1 (Qt, dde_eval_string, str,
|
|
1763 dde_error, Qnil);
|
|
1764 dde_eval_pending = 0;
|
|
1765
|
|
1766 /* Re-enable callbacks in case the client is waiting on a request */
|
|
1767 DdeEnableCallback (mswindows_dde_mlid, NULL, EC_ENABLEALL);
|
|
1768
|
|
1769 /* Post advise notifications on the result item */
|
|
1770 DdePostAdvise (mswindows_dde_mlid, mswindows_dde_topic_eval,
|
|
1771 mswindows_dde_item_result);
|
|
1772 }
|
|
1773
|
|
1774 /* A list of DDE advise tokens. Each token is an uninterned symbol,
|
|
1775 * whose value is the DDE string handle for its name (stored as a float,
|
|
1776 * as a Lisp int cannot hold a full C int).
|
|
1777 * The token's 'dde-data property is used to store data for a dde-advise.
|
|
1778 */
|
|
1779 Lisp_Object Vdde_advise_items;
|
|
1780
|
|
1781 /* The symbol 'HSZ */
|
|
1782 Lisp_Object QHSZ;
|
|
1783
|
|
1784 DEFUN("dde-alloc-advise-item", Fdde_alloc_advise_item, 0, 1, 0, /*
|
|
1785 Allocate an advise item, and return its token.
|
|
1786 */
|
|
1787 (name))
|
|
1788 {
|
|
1789 Lisp_Object token;
|
|
1790 Extbyte *str;
|
|
1791 HSZ hsz;
|
|
1792 struct gcpro gcpro1, gcpro2;
|
|
1793
|
|
1794 if (!NILP (name))
|
|
1795 CHECK_STRING (name);
|
|
1796 else
|
|
1797 {
|
|
1798 static int num = 0;
|
|
1799 char buf[20];
|
|
1800 sprintf (buf, "Tok%d", num);
|
|
1801 ++num;
|
|
1802 name = build_string (buf);
|
|
1803 }
|
|
1804
|
|
1805 token = Qnil;
|
|
1806 GCPRO2 (name, token);
|
|
1807 token = Fmake_symbol (name);
|
|
1808 TO_EXTERNAL_FORMAT (LISP_STRING, name, C_STRING_ALLOCA, str,
|
|
1809 Qmswindows_tstr);
|
|
1810 hsz = qxeDdeCreateStringHandle (mswindows_dde_mlid, str,
|
|
1811 XEUNICODE_P ? CP_WINUNICODE : CP_WINANSI);
|
|
1812
|
|
1813 Fput(token, QHSZ, make_float ((int)hsz));
|
|
1814 Vdde_advise_items = Fcons (token, Vdde_advise_items);
|
|
1815
|
1204
|
1816 RETURN_UNGCPRO (token);
|
903
|
1817 }
|
|
1818
|
|
1819 DEFUN("dde-free-advise-item", Fdde_free_advise_item, 1, 1, 0, /*
|
|
1820 Free the resources associated with advise item ITEM.
|
|
1821
|
|
1822 Frees all resources allocated to allow clients to set up advise loops
|
|
1823 on ITEM. It is assumed that no active advise loops remain. However, no
|
|
1824 problems should arise if they do - it's just that we won't ever send any
|
|
1825 notifications again.
|
|
1826
|
|
1827 If the user does not free an advise item, resources will be leaked.
|
|
1828 */
|
|
1829 (item))
|
|
1830 {
|
|
1831 HSZ hsz;
|
|
1832 Lisp_Object val;
|
|
1833
|
|
1834 CHECK_SYMBOL (item);
|
|
1835 val = Fget (item, QHSZ, Qnil);
|
|
1836 if (!FLOATP (val))
|
|
1837 return Qnil;
|
|
1838 hsz = (HSZ)(int)XFLOAT_DATA (val);
|
|
1839 DdeFreeStringHandle (mswindows_dde_mlid, hsz);
|
|
1840 Vdde_advise_items = delq_no_quit (item, Vdde_advise_items);
|
|
1841 return Qnil;
|
|
1842 }
|
|
1843
|
|
1844 DEFUN("dde-advise", Fdde_advise, 2, 2, 0, /*
|
|
1845 Post a DDE advise for ITEM with associated data DATA.
|
|
1846
|
|
1847 Records the value DATA for sending back to clients waiting for
|
|
1848 notifications on DDE item ITEM in the system topic, and posts
|
|
1849 the advise transaction.
|
|
1850
|
|
1851 ITEM must be an advise token allocated using dde-alloc-advise-item.
|
|
1852 */
|
|
1853 (item, data))
|
|
1854 {
|
|
1855 HSZ hsz;
|
|
1856 Lisp_Object val;
|
|
1857
|
|
1858 CHECK_SYMBOL (item);
|
|
1859 val = Fget (item, QHSZ, Qnil);
|
|
1860 if (!FLOATP (val))
|
|
1861 return Qnil;
|
|
1862 hsz = (HSZ)(int)XFLOAT_DATA (val);
|
|
1863
|
|
1864 Fset (item, data);
|
|
1865 DdePostAdvise (mswindows_dde_mlid, mswindows_dde_topic_eval, hsz);
|
|
1866 return Qnil;
|
|
1867 }
|
|
1868
|
428
|
1869 HDDEDATA CALLBACK
|
|
1870 mswindows_dde_callback (UINT uType, UINT uFmt, HCONV hconv,
|
|
1871 HSZ hszTopic, HSZ hszItem, HDDEDATA hdata,
|
|
1872 DWORD dwData1, DWORD dwData2)
|
|
1873 {
|
|
1874 switch (uType)
|
|
1875 {
|
|
1876 case XTYP_CONNECT:
|
903
|
1877 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system)
|
|
1878 || !DdeCmpStringHandles (hszTopic, mswindows_dde_topic_eval))
|
853
|
1879 return (HDDEDATA) TRUE;
|
|
1880 return (HDDEDATA) FALSE;
|
428
|
1881
|
|
1882 case XTYP_WILDCONNECT:
|
|
1883 {
|
903
|
1884 /* We support two {service,topic} pairs */
|
|
1885 HSZPAIR pairs[3] =
|
771
|
1886 {
|
903
|
1887 { mswindows_dde_service, mswindows_dde_topic_system },
|
|
1888 { mswindows_dde_service, mswindows_dde_topic_eval },
|
|
1889 { 0, 0 }
|
|
1890 };
|
|
1891
|
|
1892 if ((!hszItem
|
|
1893 || !DdeCmpStringHandles (hszItem, mswindows_dde_service)) &&
|
|
1894 (!hszTopic
|
|
1895 || !DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system)
|
|
1896 || !DdeCmpStringHandles (hszTopic, mswindows_dde_topic_eval)))
|
853
|
1897 return (DdeCreateDataHandle (mswindows_dde_mlid, (LPBYTE) pairs,
|
428
|
1898 sizeof (pairs), 0L, 0, uFmt, 0));
|
|
1899 }
|
853
|
1900 return (HDDEDATA) NULL;
|
428
|
1901
|
903
|
1902 case XTYP_ADVSTART:
|
|
1903 if (!mswindows_dde_enable)
|
|
1904 return (HDDEDATA) FALSE;
|
|
1905
|
|
1906 /* We only support advise loops on the eval topic for text data */
|
|
1907 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_eval)
|
|
1908 && (uFmt == CF_TEXT || uFmt == CF_UNICODETEXT))
|
|
1909 {
|
|
1910 /* Only allocated items or Result, are allowed */
|
|
1911 if (!DdeCmpStringHandles (hszItem, mswindows_dde_item_result))
|
|
1912 return (HDDEDATA) TRUE;
|
|
1913
|
|
1914 {
|
|
1915 EXTERNAL_LIST_LOOP_2 (elt, Vdde_advise_items)
|
|
1916 {
|
|
1917 Lisp_Object val;
|
|
1918 HSZ hsz;
|
|
1919 if (!SYMBOLP (elt))
|
|
1920 continue;
|
|
1921 val = Fget (elt, QHSZ, Qnil);
|
|
1922 if (!FLOATP (val))
|
|
1923 continue;
|
|
1924 hsz = (HSZ) (int) XFLOAT_DATA (val);
|
|
1925 if (!DdeCmpStringHandles (hszItem, hsz))
|
|
1926 return (HDDEDATA) TRUE;
|
|
1927 }
|
|
1928 }
|
|
1929 }
|
|
1930 return (HDDEDATA) FALSE;
|
|
1931
|
|
1932 /* Both advise requests and normal requests work the same */
|
|
1933 case XTYP_ADVREQ:
|
|
1934 case XTYP_REQUEST:
|
|
1935 if (!mswindows_dde_enable)
|
|
1936 return (HDDEDATA) NULL;
|
|
1937
|
|
1938 if (DdeCmpStringHandles (hszTopic, mswindows_dde_topic_eval) != 0)
|
|
1939 return (HDDEDATA) NULL;
|
|
1940
|
|
1941 /* If this is a normal request and we're in the middle of
|
|
1942 * an Execute, block until the Execute completes.
|
|
1943 */
|
|
1944 if (dde_eval_pending && uType == XTYP_REQUEST)
|
|
1945 return (HDDEDATA) CBR_BLOCK;
|
|
1946
|
|
1947 /* We can only support requests for ANSI or Unicode text */
|
|
1948 if (uFmt != CF_TEXT && uFmt != CF_UNICODETEXT)
|
|
1949 return (HDDEDATA) NULL;
|
|
1950
|
|
1951 {
|
|
1952 Lisp_Object args[2];
|
|
1953 struct gcpro gcpro1;
|
|
1954 Lisp_Object res;
|
|
1955 Extbyte *result;
|
|
1956 DWORD bytes;
|
|
1957
|
|
1958 args[0] = Qnil;
|
|
1959 args[1] = Qnil;
|
|
1960 GCPRO1 (args[0]);
|
|
1961 gcpro1.nvars = 2;
|
|
1962
|
|
1963
|
|
1964 if (!DdeCmpStringHandles (hszItem, mswindows_dde_item_result))
|
|
1965 {
|
|
1966 if (NILP (dde_eval_error))
|
|
1967 {
|
|
1968 args[0] = build_string ("OK: %s");
|
|
1969 args[1] = dde_eval_result;
|
|
1970 }
|
|
1971 else
|
|
1972 {
|
|
1973 args[0] = build_string ("ERR: %s");
|
|
1974 args[1] = dde_eval_error;
|
|
1975 }
|
|
1976 }
|
|
1977 else
|
|
1978 {
|
|
1979 EXTERNAL_LIST_LOOP_2 (elt, Vdde_advise_items)
|
|
1980 {
|
|
1981 Lisp_Object val;
|
|
1982 HSZ hsz;
|
|
1983 if (!SYMBOLP (elt))
|
|
1984 continue;
|
|
1985 val = Fget (elt, QHSZ, Qnil);
|
|
1986 if (!FLOATP (val))
|
|
1987 continue;
|
|
1988 hsz = (HSZ) (int) XFLOAT_DATA (val);
|
|
1989 if (!DdeCmpStringHandles (hszItem, hsz))
|
|
1990 args[1] = Fsymbol_value (elt);
|
|
1991 }
|
|
1992 args[0] = build_string ("%s");
|
|
1993 }
|
|
1994
|
|
1995 res = Fformat (2, args);
|
|
1996 UNGCPRO;
|
|
1997
|
|
1998 bytes = (uFmt == CF_TEXT ? 1 : 2) * (XSTRING_LENGTH (res) + 1);
|
|
1999 TO_EXTERNAL_FORMAT (LISP_STRING, res,
|
|
2000 C_STRING_ALLOCA, result,
|
|
2001 uFmt == CF_TEXT ? Qmswindows_multibyte
|
|
2002 : Qmswindows_unicode);
|
|
2003
|
|
2004 /* If we cannot create the data handle, this passes the null
|
|
2005 * return back to the client, which signals an error as we wish.
|
|
2006 */
|
|
2007 return DdeCreateDataHandle (mswindows_dde_mlid, (LPBYTE)result,
|
|
2008 bytes, 0L, hszItem, uFmt, 0);
|
|
2009 }
|
|
2010
|
428
|
2011 case XTYP_EXECUTE:
|
657
|
2012 if (!mswindows_dde_enable)
|
|
2013 return (HDDEDATA) DDE_FBUSY;
|
|
2014
|
903
|
2015 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_eval))
|
|
2016 {
|
|
2017 DWORD len;
|
|
2018 LPBYTE extcmd;
|
|
2019 Lisp_Object tmp;
|
|
2020
|
|
2021 /* Grab a pointer to the raw data supplied */
|
|
2022 extcmd = DdeAccessData (hdata, &len);
|
|
2023
|
|
2024 TO_INTERNAL_FORMAT (DATA, (extcmd, len),
|
|
2025 LISP_STRING, tmp,
|
|
2026 Qmswindows_tstr);
|
|
2027
|
|
2028 /* Release and free the data handle */
|
|
2029 DdeUnaccessData (hdata);
|
|
2030 DdeFreeDataHandle (hdata);
|
|
2031
|
|
2032 /* Set a flag to say that the evaluation isn't yet complete,
|
|
2033 * enqueue the evaluation, send a dummy event to trigger the
|
|
2034 * event loop (I've no idea why this is needed, but it works...)
|
|
2035 * and return success to the client.
|
|
2036 */
|
|
2037 dde_eval_pending = 1;
|
|
2038 enqueue_magic_eval_event (dde_eval, tmp);
|
|
2039 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
|
|
2040 return (HDDEDATA) DDE_FACK;
|
|
2041 }
|
|
2042 else if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system))
|
428
|
2043 {
|
|
2044 DWORD len = DdeGetData (hdata, NULL, 0, 0);
|
853
|
2045 LPBYTE extcmd = (LPBYTE) ALLOCA (len + 1);
|
867
|
2046 Ibyte *cmd;
|
|
2047 Ibyte *end;
|
428
|
2048 struct gcpro gcpro1, gcpro2;
|
657
|
2049 Lisp_Object l_dndlist = Qnil;
|
428
|
2050 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
2051 Lisp_Object frmcons, devcons, concons;
|
440
|
2052 Lisp_Event *event = XEVENT (emacs_event);
|
428
|
2053
|
771
|
2054 DdeGetData (hdata, extcmd, len, 0);
|
428
|
2055 DdeFreeDataHandle (hdata);
|
|
2056
|
771
|
2057 TO_INTERNAL_FORMAT (DATA, (extcmd, len),
|
|
2058 C_STRING_ALLOCA, cmd,
|
|
2059 Qmswindows_tstr);
|
|
2060
|
428
|
2061 /* Check syntax & that it's an [Open("foo")] command, which we
|
|
2062 * treat like a file drop */
|
|
2063 if (*cmd == '[')
|
|
2064 cmd++;
|
771
|
2065 if (qxestrncasecmp_c (cmd, MSWINDOWS_DDE_ITEM_OPEN,
|
|
2066 strlen (MSWINDOWS_DDE_ITEM_OPEN)))
|
428
|
2067 return DDE_FNOTPROCESSED;
|
|
2068 cmd += strlen (MSWINDOWS_DDE_ITEM_OPEN);
|
771
|
2069 while (*cmd == ' ')
|
428
|
2070 cmd++;
|
771
|
2071 if (*cmd != '(' || *(cmd + 1) != '\"')
|
428
|
2072 return DDE_FNOTPROCESSED;
|
771
|
2073 end = (cmd += 2);
|
|
2074 while (*end && *end != '\"')
|
428
|
2075 end++;
|
|
2076 if (!*end)
|
|
2077 return DDE_FNOTPROCESSED;
|
|
2078 *end = '\0';
|
771
|
2079 if (*++end != ')')
|
428
|
2080 return DDE_FNOTPROCESSED;
|
771
|
2081 if (*++end == ']')
|
428
|
2082 end++;
|
|
2083 if (*end)
|
|
2084 return DDE_FNOTPROCESSED;
|
|
2085
|
771
|
2086 {
|
|
2087 /* The drag-n-drop code in dragdrop.el expects pseudo-URL's,
|
|
2088 consisting of just file: followed by the filename. This
|
|
2089 should maybe work, but both Netscape and IE complain
|
|
2090 whenever they're not given the full file spec, like
|
|
2091
|
|
2092 file:///C|/foo/bar/ or equivalently
|
|
2093 file:///C:/foo/bar/ (less portably)
|
|
2094
|
|
2095 they don't allow relative paths at all! this is way bogus. */
|
|
2096 cmd = urlify_filename (cmd);
|
|
2097 l_dndlist = build_intstring (cmd);
|
|
2098 xfree (cmd);
|
|
2099 }
|
428
|
2100 GCPRO2 (emacs_event, l_dndlist);
|
|
2101
|
|
2102 /* Find a mswindows frame */
|
|
2103 event->channel = Qnil;
|
|
2104 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
|
|
2105 {
|
|
2106 Lisp_Object frame = XCAR (frmcons);
|
|
2107 if (FRAME_TYPE_P (XFRAME (frame), mswindows))
|
|
2108 event->channel = frame;
|
|
2109 };
|
|
2110 assert (!NILP (event->channel));
|
|
2111
|
964
|
2112 SET_EVENT_TIMESTAMP (event, GetTickCount());
|
|
2113 SET_EVENT_TYPE (event, misc_user_event);
|
1204
|
2114 SET_EVENT_MISC_USER_BUTTON (event, 1);
|
|
2115 SET_EVENT_MISC_USER_MODIFIERS (event, 0);
|
|
2116 SET_EVENT_MISC_USER_X (event, -1);
|
|
2117 SET_EVENT_MISC_USER_Y (event, -1);
|
|
2118 SET_EVENT_MISC_USER_FUNCTION (event,
|
964
|
2119 Qdragdrop_drop_dispatch);
|
1204
|
2120 SET_EVENT_MISC_USER_OBJECT (event,
|
964
|
2121 Fcons (Qdragdrop_URL,
|
|
2122 Fcons (l_dndlist, Qnil)));
|
428
|
2123 mswindows_enqueue_dispatch_event (emacs_event);
|
|
2124 UNGCPRO;
|
|
2125 return (HDDEDATA) DDE_FACK;
|
|
2126 }
|
|
2127 DdeFreeDataHandle (hdata);
|
|
2128 return (HDDEDATA) DDE_FNOTPROCESSED;
|
|
2129
|
|
2130 default:
|
|
2131 return (HDDEDATA) NULL;
|
|
2132 }
|
|
2133 }
|
|
2134 #endif
|
|
2135
|
|
2136 /*
|
442
|
2137 * Helper to do repainting - repaints can happen both from the windows
|
|
2138 * procedure and from magic events
|
|
2139 */
|
|
2140 static void
|
|
2141 mswindows_handle_paint (struct frame *frame)
|
|
2142 {
|
|
2143 HWND hwnd = FRAME_MSWINDOWS_HANDLE (frame);
|
|
2144
|
|
2145 /* According to the docs we need to check GetUpdateRect() before
|
|
2146 actually doing a WM_PAINT */
|
|
2147 if (GetUpdateRect (hwnd, NULL, FALSE))
|
|
2148 {
|
|
2149 PAINTSTRUCT paintStruct;
|
|
2150 int x, y, width, height;
|
|
2151
|
|
2152 BeginPaint (hwnd, &paintStruct);
|
|
2153 x = paintStruct.rcPaint.left;
|
|
2154 y = paintStruct.rcPaint.top;
|
|
2155 width = paintStruct.rcPaint.right - paintStruct.rcPaint.left;
|
|
2156 height = paintStruct.rcPaint.bottom - paintStruct.rcPaint.top;
|
|
2157 /* Normally we want to ignore expose events when child
|
|
2158 windows are unmapped, however once we are in the guts of
|
|
2159 WM_PAINT we need to make sure that we don't register
|
|
2160 unmaps then because they will not actually occur. */
|
|
2161 /* #### commenting out the next line seems to fix some problems
|
|
2162 but not all. only andy currently understands this stuff and
|
|
2163 he needs to review it more carefully. --ben */
|
|
2164 if (!check_for_ignored_expose (frame, x, y, width, height))
|
|
2165 {
|
|
2166 hold_ignored_expose_registration = 1;
|
|
2167 mswindows_redraw_exposed_area (frame, x, y, width, height);
|
|
2168 hold_ignored_expose_registration = 0;
|
|
2169 }
|
|
2170 EndPaint (hwnd, &paintStruct);
|
|
2171 }
|
|
2172 }
|
|
2173
|
|
2174 /*
|
|
2175 * Returns 1 if a key is a real modifier or special key, which
|
440
|
2176 * is better handled by DefWindowProc
|
|
2177 */
|
|
2178 static int
|
|
2179 key_needs_default_processing_p (UINT vkey)
|
|
2180 {
|
442
|
2181 if (mswindows_alt_by_itself_activates_menu && vkey == VK_MENU
|
|
2182 /* if we let ALT activate the menu like this, then sticky ALT-modified
|
|
2183 keystrokes become impossible. */
|
|
2184 && !modifier_keys_are_sticky)
|
440
|
2185 return 1;
|
|
2186
|
|
2187 return 0;
|
|
2188 }
|
|
2189
|
442
|
2190 /* key-handling code is always ugly. It just ends up working out
|
|
2191 that way.
|
|
2192
|
|
2193 #### Most of the sticky-modifier code below is copied from similar
|
|
2194 code in event-Xt.c. They should somehow or other be merged.
|
|
2195
|
|
2196 Here are some pointers:
|
|
2197
|
|
2198 -- DOWN_MASK indicates which modifiers should be treated as "down"
|
|
2199 when the corresponding upstroke happens. It gets reset for
|
|
2200 a particular modifier when that modifier goes up, and reset
|
|
2201 for all modifiers when a non-modifier key is pressed. Example:
|
|
2202
|
|
2203 I press Control-A-Shift and then release Control-A-Shift.
|
|
2204 I want the Shift key to be sticky but not the Control key.
|
|
2205
|
|
2206 -- If a modifier key is sticky, I can unstick it by pressing
|
|
2207 the modifier key again. */
|
|
2208
|
|
2209 static WPARAM last_downkey;
|
|
2210 static int need_to_add_mask, down_mask;
|
|
2211
|
|
2212 #define XEMSW_LCONTROL (1<<0)
|
|
2213 #define XEMSW_RCONTROL (1<<1)
|
|
2214 #define XEMSW_LSHIFT (1<<2)
|
|
2215 #define XEMSW_RSHIFT (1<<3)
|
|
2216 #define XEMSW_LMENU (1<<4)
|
|
2217 #define XEMSW_RMENU (1<<5)
|
|
2218
|
|
2219 static int
|
|
2220 mswindows_handle_sticky_modifiers (WPARAM wParam, LPARAM lParam,
|
|
2221 int downp, int keyp)
|
|
2222 {
|
|
2223 int mods = 0;
|
|
2224
|
|
2225 if (!modifier_keys_are_sticky) /* Optimize for non-sticky modifiers */
|
|
2226 return 0;
|
|
2227
|
|
2228 if (! (keyp &&
|
|
2229 (wParam == VK_CONTROL || wParam == VK_LCONTROL ||
|
|
2230 wParam == VK_RCONTROL ||
|
|
2231 wParam == VK_MENU || wParam == VK_LMENU ||
|
|
2232 wParam == VK_RMENU ||
|
|
2233 wParam == VK_SHIFT || wParam == VK_LSHIFT ||
|
|
2234 wParam == VK_RSHIFT)))
|
|
2235 { /* Not a modifier key */
|
|
2236 if (downp && keyp && !last_downkey)
|
|
2237 last_downkey = wParam;
|
|
2238 /* If I hold press-and-release the Control key and then press
|
|
2239 and hold down the right arrow, I want it to auto-repeat
|
|
2240 Control-Right. On the other hand, if I do the same but
|
|
2241 manually press the Right arrow a bunch of times, I want
|
|
2242 to see one Control-Right and then a bunch of Rights.
|
|
2243 This means that we need to distinguish between an
|
|
2244 auto-repeated key and a key pressed and released a bunch
|
|
2245 of times. */
|
|
2246 else if ((downp && !keyp) ||
|
|
2247 (downp && keyp && last_downkey &&
|
|
2248 (wParam != last_downkey ||
|
|
2249 /* the "previous key state" bit indicates autorepeat */
|
|
2250 ! (lParam & (1 << 30)))))
|
|
2251 {
|
|
2252 need_to_add_mask = 0;
|
|
2253 last_downkey = 0;
|
|
2254 }
|
|
2255 if (downp)
|
|
2256 down_mask = 0;
|
|
2257
|
|
2258 mods = need_to_add_mask;
|
|
2259 }
|
|
2260 else /* Modifier key pressed */
|
|
2261 {
|
|
2262 /* If a non-modifier key was pressed in the middle of a bunch
|
|
2263 of modifiers, then it unsticks all the modifiers that were
|
|
2264 previously pressed. We cannot unstick the modifiers until
|
|
2265 now because we want to check for auto-repeat of the
|
|
2266 non-modifier key. */
|
|
2267
|
|
2268 if (last_downkey)
|
|
2269 {
|
|
2270 last_downkey = 0;
|
|
2271 need_to_add_mask = 0;
|
|
2272 }
|
|
2273
|
|
2274 #define FROB(mask) \
|
|
2275 do { \
|
|
2276 if (downp && keyp) \
|
|
2277 { \
|
|
2278 /* If modifier key is already sticky, \
|
|
2279 then unstick it. Note that we do \
|
|
2280 not test down_mask to deal with the \
|
|
2281 unlikely but possible case that the \
|
|
2282 modifier key auto-repeats. */ \
|
|
2283 if (need_to_add_mask & mask) \
|
|
2284 { \
|
|
2285 need_to_add_mask &= ~mask; \
|
|
2286 down_mask &= ~mask; \
|
|
2287 } \
|
|
2288 else \
|
|
2289 down_mask |= mask; \
|
|
2290 } \
|
|
2291 else \
|
|
2292 { \
|
|
2293 if (down_mask & mask) \
|
|
2294 { \
|
|
2295 down_mask &= ~mask; \
|
|
2296 need_to_add_mask |= mask; \
|
|
2297 } \
|
|
2298 } \
|
|
2299 } while (0)
|
|
2300
|
|
2301 if ((wParam == VK_CONTROL && (lParam & 0x1000000))
|
|
2302 || wParam == VK_RCONTROL)
|
|
2303 FROB (XEMSW_RCONTROL);
|
|
2304 if ((wParam == VK_CONTROL && !(lParam & 0x1000000))
|
|
2305 || wParam == VK_LCONTROL)
|
|
2306 FROB (XEMSW_LCONTROL);
|
|
2307
|
|
2308 if ((wParam == VK_SHIFT && (lParam & 0x1000000))
|
|
2309 || wParam == VK_RSHIFT)
|
|
2310 FROB (XEMSW_RSHIFT);
|
|
2311 if ((wParam == VK_SHIFT && !(lParam & 0x1000000))
|
|
2312 || wParam == VK_LSHIFT)
|
|
2313 FROB (XEMSW_LSHIFT);
|
|
2314
|
|
2315 if ((wParam == VK_MENU && (lParam & 0x1000000))
|
|
2316 || wParam == VK_RMENU)
|
|
2317 FROB (XEMSW_RMENU);
|
|
2318 if ((wParam == VK_MENU && !(lParam & 0x1000000))
|
|
2319 || wParam == VK_LMENU)
|
|
2320 FROB (XEMSW_LMENU);
|
|
2321 }
|
|
2322 #undef FROB
|
|
2323
|
|
2324 if (mods && downp)
|
|
2325 {
|
|
2326 BYTE keymap[256];
|
|
2327
|
|
2328 GetKeyboardState (keymap);
|
|
2329
|
|
2330 if (mods & XEMSW_LCONTROL)
|
|
2331 {
|
|
2332 keymap [VK_CONTROL] |= 0x80;
|
|
2333 keymap [VK_LCONTROL] |= 0x80;
|
|
2334 }
|
|
2335 if (mods & XEMSW_RCONTROL)
|
|
2336 {
|
|
2337 keymap [VK_CONTROL] |= 0x80;
|
|
2338 keymap [VK_RCONTROL] |= 0x80;
|
|
2339 }
|
|
2340
|
|
2341 if (mods & XEMSW_LSHIFT)
|
|
2342 {
|
|
2343 keymap [VK_SHIFT] |= 0x80;
|
|
2344 keymap [VK_LSHIFT] |= 0x80;
|
|
2345 }
|
|
2346 if (mods & XEMSW_RSHIFT)
|
|
2347 {
|
|
2348 keymap [VK_SHIFT] |= 0x80;
|
|
2349 keymap [VK_RSHIFT] |= 0x80;
|
|
2350 }
|
|
2351
|
|
2352 if (mods & XEMSW_LMENU)
|
|
2353 {
|
|
2354 keymap [VK_MENU] |= 0x80;
|
|
2355 keymap [VK_LMENU] |= 0x80;
|
|
2356 }
|
|
2357 if (mods & XEMSW_RMENU)
|
|
2358 {
|
|
2359 keymap [VK_MENU] |= 0x80;
|
|
2360 keymap [VK_RMENU] |= 0x80;
|
|
2361 }
|
|
2362
|
|
2363 SetKeyboardState (keymap);
|
|
2364 return 1;
|
|
2365 }
|
|
2366
|
|
2367 return 0;
|
|
2368 }
|
|
2369
|
|
2370 static void
|
|
2371 clear_sticky_modifiers (void)
|
|
2372 {
|
|
2373 need_to_add_mask = 0;
|
|
2374 last_downkey = 0;
|
|
2375 down_mask = 0;
|
|
2376 }
|
|
2377
|
|
2378 #ifdef DEBUG_XEMACS
|
|
2379
|
|
2380 #if 0
|
|
2381
|
|
2382 static void
|
|
2383 output_modifier_keyboard_state (void)
|
|
2384 {
|
|
2385 BYTE keymap[256];
|
|
2386
|
|
2387 GetKeyboardState (keymap);
|
|
2388
|
|
2389 stderr_out ("GetKeyboardState VK_MENU %d %d VK_LMENU %d %d VK_RMENU %d %d\n",
|
|
2390 keymap[VK_MENU] & 0x80 ? 1 : 0,
|
|
2391 keymap[VK_MENU] & 0x1 ? 1 : 0,
|
|
2392 keymap[VK_LMENU] & 0x80 ? 1 : 0,
|
|
2393 keymap[VK_LMENU] & 0x1 ? 1 : 0,
|
|
2394 keymap[VK_RMENU] & 0x80 ? 1 : 0,
|
|
2395 keymap[VK_RMENU] & 0x1 ? 1 : 0);
|
|
2396 stderr_out ("GetKeyboardState VK_CONTROL %d %d VK_LCONTROL %d %d VK_RCONTROL %d %d\n",
|
|
2397 keymap[VK_CONTROL] & 0x80 ? 1 : 0,
|
|
2398 keymap[VK_CONTROL] & 0x1 ? 1 : 0,
|
|
2399 keymap[VK_LCONTROL] & 0x80 ? 1 : 0,
|
|
2400 keymap[VK_LCONTROL] & 0x1 ? 1 : 0,
|
|
2401 keymap[VK_RCONTROL] & 0x80 ? 1 : 0,
|
|
2402 keymap[VK_RCONTROL] & 0x1 ? 1 : 0);
|
|
2403 stderr_out ("GetKeyboardState VK_SHIFT %d %d VK_LSHIFT %d %d VK_RSHIFT %d %d\n",
|
|
2404 keymap[VK_SHIFT] & 0x80 ? 1 : 0,
|
|
2405 keymap[VK_SHIFT] & 0x1 ? 1 : 0,
|
|
2406 keymap[VK_LSHIFT] & 0x80 ? 1 : 0,
|
|
2407 keymap[VK_LSHIFT] & 0x1 ? 1 : 0,
|
|
2408 keymap[VK_RSHIFT] & 0x80 ? 1 : 0,
|
|
2409 keymap[VK_RSHIFT] & 0x1 ? 1 : 0);
|
|
2410 }
|
|
2411
|
|
2412 #endif
|
|
2413
|
|
2414 /* try to debug the stuck-alt-key problem.
|
|
2415
|
|
2416 #### this happens only inconsistently, and may only happen when using
|
|
2417 StickyKeys in the Win2000 accessibility section of the control panel,
|
|
2418 which is extremely broken for other reasons. */
|
|
2419
|
|
2420 static void
|
|
2421 output_alt_keyboard_state (void)
|
|
2422 {
|
|
2423 BYTE keymap[256];
|
|
2424 SHORT keystate[3];
|
1242
|
2425 /* SHORT asyncstate[3]; */
|
442
|
2426
|
|
2427 GetKeyboardState (keymap);
|
|
2428 keystate[0] = GetKeyState (VK_MENU);
|
|
2429 keystate[1] = GetKeyState (VK_LMENU);
|
|
2430 keystate[2] = GetKeyState (VK_RMENU);
|
|
2431 /* Doing this interferes with key processing. */
|
|
2432 /* asyncstate[0] = GetAsyncKeyState (VK_MENU); */
|
|
2433 /* asyncstate[1] = GetAsyncKeyState (VK_LMENU); */
|
|
2434 /* asyncstate[2] = GetAsyncKeyState (VK_RMENU); */
|
|
2435
|
|
2436 stderr_out ("GetKeyboardState VK_MENU %d %d VK_LMENU %d %d VK_RMENU %d %d\n",
|
|
2437 keymap[VK_MENU] & 0x80 ? 1 : 0,
|
|
2438 keymap[VK_MENU] & 0x1 ? 1 : 0,
|
|
2439 keymap[VK_LMENU] & 0x80 ? 1 : 0,
|
|
2440 keymap[VK_LMENU] & 0x1 ? 1 : 0,
|
|
2441 keymap[VK_RMENU] & 0x80 ? 1 : 0,
|
|
2442 keymap[VK_RMENU] & 0x1 ? 1 : 0);
|
|
2443 stderr_out ("GetKeyState VK_MENU %d %d VK_LMENU %d %d VK_RMENU %d %d\n",
|
|
2444 keystate[0] & 0x8000 ? 1 : 0,
|
|
2445 keystate[0] & 0x1 ? 1 : 0,
|
|
2446 keystate[1] & 0x8000 ? 1 : 0,
|
|
2447 keystate[1] & 0x1 ? 1 : 0,
|
|
2448 keystate[2] & 0x8000 ? 1 : 0,
|
|
2449 keystate[2] & 0x1 ? 1 : 0);
|
|
2450 /* stderr_out ("GetAsyncKeyState VK_MENU %d %d VK_LMENU %d %d VK_RMENU %d %d\n", */
|
|
2451 /* asyncstate[0] & 0x8000 ? 1 : 0, */
|
|
2452 /* asyncstate[0] & 0x1 ? 1 : 0, */
|
|
2453 /* asyncstate[1] & 0x8000 ? 1 : 0, */
|
|
2454 /* asyncstate[1] & 0x1 ? 1 : 0, */
|
|
2455 /* asyncstate[2] & 0x8000 ? 1 : 0, */
|
|
2456 /* asyncstate[2] & 0x1 ? 1 : 0); */
|
|
2457 }
|
|
2458
|
|
2459 #endif /* DEBUG_XEMACS */
|
|
2460
|
|
2461
|
440
|
2462 /*
|
428
|
2463 * The windows procedure for the window class XEMACS_CLASS
|
|
2464 */
|
|
2465 LRESULT WINAPI
|
442
|
2466 mswindows_wnd_proc (HWND hwnd, UINT message_, WPARAM wParam, LPARAM lParam)
|
428
|
2467 {
|
1204
|
2468 /* Note: Remember to initialize emacs_event and event before use. This
|
|
2469 code calls code that can GC. You must GCPRO before calling such
|
|
2470 code. */
|
428
|
2471 Lisp_Object emacs_event = Qnil;
|
|
2472 Lisp_Object fobj = Qnil;
|
|
2473
|
440
|
2474 Lisp_Event *event;
|
428
|
2475 struct frame *frame;
|
647
|
2476 struct mswindows_frame *msframe;
|
428
|
2477
|
611
|
2478 /* If you hit this, rewrite the offending API call to occur after GC,
|
|
2479 using register_post_gc_action(). */
|
|
2480 assert (!gc_in_progress);
|
593
|
2481
|
|
2482 #ifdef DEBUG_XEMACS
|
|
2483 if (debug_mswindows_events)
|
|
2484 debug_output_mswin_message (hwnd, message_, wParam, lParam);
|
|
2485 #endif /* DEBUG_XEMACS */
|
442
|
2486
|
771
|
2487 assert (!qxeGetWindowLong (hwnd, GWL_USERDATA));
|
442
|
2488 switch (message_)
|
428
|
2489 {
|
442
|
2490 case WM_DESTROYCLIPBOARD:
|
771
|
2491 mswindows_handle_destroyclipboard ();
|
442
|
2492 break;
|
|
2493
|
|
2494 case WM_ERASEBKGND:
|
|
2495 /* Erase background only during non-dynamic sizing */
|
771
|
2496 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
442
|
2497 if (msframe->sizing && !mswindows_dynamic_frame_resize)
|
|
2498 goto defproc;
|
|
2499 return 1;
|
|
2500
|
|
2501 case WM_CLOSE:
|
|
2502 fobj = mswindows_find_frame (hwnd);
|
853
|
2503 mswindows_enqueue_misc_user_event (fobj, Qeval, list3 (Qdelete_frame, fobj,
|
|
2504 Qt));
|
440
|
2505 break;
|
428
|
2506
|
442
|
2507 case WM_KEYUP:
|
|
2508 case WM_SYSKEYUP:
|
|
2509
|
|
2510 /* See Win95 comment under WM_KEYDOWN */
|
|
2511 {
|
|
2512 BYTE keymap[256];
|
|
2513 int should_set_keymap = 0;
|
|
2514
|
|
2515 #ifdef DEBUG_XEMACS
|
593
|
2516 if (debug_mswindows_events > 2)
|
|
2517 output_alt_keyboard_state ();
|
442
|
2518 #endif /* DEBUG_XEMACS */
|
|
2519
|
|
2520 mswindows_handle_sticky_modifiers (wParam, lParam, 0, 1);
|
|
2521 if (wParam == VK_CONTROL)
|
|
2522 {
|
|
2523 GetKeyboardState (keymap);
|
|
2524 keymap [(lParam & 0x1000000) ? VK_RCONTROL : VK_LCONTROL] &= ~0x80;
|
|
2525 should_set_keymap = 1;
|
|
2526 }
|
|
2527 else if (wParam == VK_MENU)
|
|
2528 {
|
|
2529 GetKeyboardState (keymap);
|
|
2530 keymap [(lParam & 0x1000000) ? VK_RMENU : VK_LMENU] &= ~0x80;
|
|
2531 should_set_keymap = 1;
|
|
2532 }
|
|
2533
|
|
2534 if (should_set_keymap)
|
1242
|
2535 /* && (message_ != WM_SYSKEYUP */
|
|
2536 /* || NILP (Vmenu_accelerator_enabled))) */
|
428
|
2537 SetKeyboardState (keymap);
|
|
2538
|
|
2539 }
|
442
|
2540
|
|
2541 if (key_needs_default_processing_p (wParam))
|
|
2542 goto defproc;
|
|
2543 else
|
|
2544 break;
|
|
2545
|
|
2546 case WM_KEYDOWN:
|
|
2547 case WM_SYSKEYDOWN:
|
|
2548
|
|
2549 /* In some locales the right-hand Alt key is labelled AltGr. This key
|
|
2550 * should produce alternative characters when combined with another key.
|
|
2551 * eg on a German keyboard pressing AltGr+q should produce '@'.
|
|
2552 * AltGr generates exactly the same keystrokes as LCtrl+RAlt. But if
|
|
2553 * TranslateMessage() is called with *any* combination of Ctrl+Alt down,
|
|
2554 * it translates as if AltGr were down.
|
|
2555 * We get round this by removing all modifiers from the keymap before
|
|
2556 * calling TranslateMessage() unless AltGr is *really* down. */
|
428
|
2557 {
|
442
|
2558 BYTE keymap_trans[256];
|
|
2559 BYTE keymap_orig[256];
|
|
2560 BYTE keymap_sticky[256];
|
771
|
2561 /* WARNING: XEmacs code paths are far more subtle than you
|
|
2562 think. In particular, QUIT checking will query and remove
|
|
2563 events, including keyboard events, from the queue. (QUIT is
|
|
2564 definitely invoked from TO_INTERNAL_FORMAT().) If we do
|
|
2565 this recursively anywhere in the following code, it will
|
|
2566 mess certain things up -- in particular, the OS-provided
|
|
2567 sticky modifier code available as part of the accessibility
|
|
2568 package.
|
|
2569
|
|
2570 (Academic question: If QUIT checking is supposed to be
|
|
2571 triggered only every 1/4 second, why is it getting
|
|
2572 consistently triggered here? I saw the problem
|
|
2573 consistently. Answer: It appears that, currently,
|
|
2574 sometimes the code to pump messages is wrapped with
|
|
2575 begin_dont_check_for_quit() and sometimes it isn't. (####
|
|
2576 FIX THIS SHIT!) cmdloop.c, for example, has it, but not
|
|
2577 everywhere. The current games with avoiding QUIT mean that
|
|
2578 the 1/4-second timer consistently fires while
|
|
2579 dont_check_for_quit is set [which causes the quit check to
|
|
2580 get deferred but the flag is still on], and so the next
|
|
2581 time it's unset and we call QUIT is *right here*.
|
|
2582
|
|
2583 In my stderr-proc ws I majorly cleaned up the whole shit by
|
|
2584 just wrapping all the entry points in dont_check_for_quit.
|
|
2585 This fixed the remaining bugs with C-g getting interpreted
|
|
2586 wrong.)
|
|
2587
|
|
2588 #### We should probably wrap this whole function in
|
|
2589 begin_dont_check_for_quit(); but then we should set this
|
|
2590 back to 0 when handling a menu callback, which gets invoked
|
|
2591 from within this function, specifically from
|
|
2592 DefWindowProc(). (We already do the latter in my new
|
|
2593 stderr-proc ws, because in that ws next_event_internal()
|
|
2594 calls begin_dont_check_for_quit(). */
|
|
2595
|
|
2596 int count = begin_dont_check_for_quit ();
|
442
|
2597 int has_AltGr = mswindows_current_layout_has_AltGr ();
|
502
|
2598 int mods = 0, mods_with_shift = 0;
|
442
|
2599 int extendedp = lParam & 0x1000000;
|
|
2600 Lisp_Object keysym;
|
|
2601 int sticky_changed;
|
|
2602
|
|
2603 #ifdef DEBUG_XEMACS
|
593
|
2604 if (debug_mswindows_events > 2)
|
|
2605 output_alt_keyboard_state ();
|
442
|
2606 #endif /* DEBUG_XEMACS */
|
|
2607
|
|
2608 GetKeyboardState (keymap_orig);
|
|
2609 frame = XFRAME (mswindows_find_frame (hwnd));
|
|
2610 if ((sticky_changed =
|
|
2611 mswindows_handle_sticky_modifiers (wParam, lParam, 1, 1)))
|
428
|
2612 {
|
442
|
2613 GetKeyboardState (keymap_sticky);
|
|
2614 if (keymap_sticky[VK_MENU] & 0x80)
|
|
2615 {
|
|
2616 message_ = WM_SYSKEYDOWN;
|
|
2617 /* We have to set the "context bit" so that the
|
|
2618 TranslateMessage() call below that generates the
|
|
2619 SYSCHAR message does its thing; see the documentation
|
|
2620 on WM_SYSKEYDOWN */
|
|
2621 lParam |= 1 << 29;
|
|
2622 }
|
428
|
2623 }
|
|
2624 else
|
442
|
2625 memcpy (keymap_sticky, keymap_orig, 256);
|
|
2626
|
|
2627 mods = mswindows_modifier_state (keymap_sticky, (DWORD) -1, has_AltGr);
|
502
|
2628 mods_with_shift = mods;
|
442
|
2629
|
|
2630 /* Handle non-printables */
|
|
2631 if (!NILP (keysym = mswindows_key_to_emacs_keysym (wParam, mods,
|
|
2632 extendedp)))
|
428
|
2633 {
|
442
|
2634 mswindows_enqueue_keypress_event (hwnd, keysym, mods);
|
|
2635 if (sticky_changed)
|
|
2636 SetKeyboardState (keymap_orig);
|
428
|
2637 }
|
442
|
2638 else /* Normal keys & modifiers */
|
428
|
2639 {
|
442
|
2640 POINT pnt = { LOWORD (GetMessagePos()), HIWORD (GetMessagePos()) };
|
|
2641 MSG msg, tranmsg;
|
1204
|
2642 #ifdef HAVE_MENUBARS
|
442
|
2643 int potential_accelerator = 0;
|
1204
|
2644 #endif
|
442
|
2645 int got_accelerator = 0;
|
771
|
2646 /* No need to gcpro because the event is already on a
|
|
2647 queue when we retrieve it. */
|
|
2648 Lisp_Object lastev = Qnil;
|
442
|
2649
|
|
2650 msg.hwnd = hwnd;
|
|
2651 msg.message = message_;
|
|
2652 msg.wParam = wParam;
|
|
2653 msg.lParam = lParam;
|
|
2654 msg.time = GetMessageTime();
|
|
2655 msg.pt = pnt;
|
|
2656
|
|
2657 /* GetKeyboardState() does not work as documented on Win95. We have
|
|
2658 * to loosely track Left and Right modifiers on behalf of the OS,
|
|
2659 * without screwing up Windows NT which tracks them properly. */
|
|
2660 if (wParam == VK_CONTROL)
|
|
2661 {
|
|
2662 keymap_orig[extendedp ? VK_RCONTROL : VK_LCONTROL] |= 0x80;
|
|
2663 keymap_sticky[extendedp ? VK_RCONTROL : VK_LCONTROL] |= 0x80;
|
|
2664 }
|
|
2665 else if (wParam == VK_MENU)
|
|
2666 {
|
|
2667 keymap_orig[extendedp ? VK_RMENU : VK_LMENU] |= 0x80;
|
|
2668 keymap_sticky[extendedp ? VK_RMENU : VK_LMENU] |= 0x80;
|
|
2669 }
|
|
2670
|
827
|
2671 #ifdef HAVE_MENUBARS
|
442
|
2672 if (!NILP (Vmenu_accelerator_enabled) &&
|
|
2673 !(mods & XEMACS_MOD_SHIFT) && message_ == WM_SYSKEYDOWN)
|
|
2674 potential_accelerator = 1;
|
827
|
2675 #endif
|
442
|
2676
|
|
2677 /* Remove shift modifier from an ascii character */
|
|
2678 mods &= ~XEMACS_MOD_SHIFT;
|
|
2679
|
|
2680 memcpy (keymap_trans, keymap_sticky, 256);
|
|
2681
|
|
2682 /* Clear control and alt modifiers unless AltGr is pressed */
|
|
2683 keymap_trans[VK_RCONTROL] = 0;
|
|
2684 keymap_trans[VK_LMENU] = 0;
|
|
2685 if (!has_AltGr || !(keymap_trans[VK_LCONTROL] & 0x80)
|
|
2686 || !(keymap_trans[VK_RMENU] & 0x80))
|
|
2687 {
|
|
2688 keymap_trans[VK_LCONTROL] = 0;
|
|
2689 keymap_trans[VK_CONTROL] = 0;
|
|
2690 keymap_trans[VK_RMENU] = 0;
|
|
2691 keymap_trans[VK_MENU] = 0;
|
|
2692 }
|
|
2693 SetKeyboardState (keymap_trans);
|
|
2694
|
|
2695 /* Maybe generate some WM_[SYS]CHARs in the queue */
|
|
2696 TranslateMessage (&msg);
|
|
2697
|
771
|
2698 while (qxePeekMessage (&tranmsg, hwnd, WM_CHAR, WM_CHAR, PM_REMOVE)
|
|
2699 || qxePeekMessage (&tranmsg, hwnd, WM_SYSCHAR, WM_SYSCHAR,
|
|
2700 PM_REMOVE))
|
442
|
2701 {
|
502
|
2702 int mods_with_quit = mods;
|
771
|
2703 int length;
|
|
2704 Extbyte extchar[4];
|
867
|
2705 Ibyte *intchar;
|
|
2706 Ichar ch;
|
771
|
2707
|
|
2708 if (XEUNICODE_P)
|
|
2709 {
|
|
2710 length = unicode_char_to_text (tranmsg.wParam, extchar);
|
|
2711 TO_INTERNAL_FORMAT (DATA, (extchar, length),
|
|
2712 C_STRING_ALLOCA, (intchar),
|
|
2713 Qmswindows_unicode);
|
867
|
2714 ch = itext_ichar (intchar);
|
771
|
2715 }
|
|
2716 else
|
|
2717 {
|
|
2718 length = ansi_char_to_text (tranmsg.wParam, extchar);
|
|
2719 intchar = (convert_multibyte_to_internal_malloc
|
|
2720 (extchar, length,
|
|
2721 mswindows_locale_to_code_page
|
|
2722 /* See intl-win32.c for an explanation of
|
|
2723 the following */
|
|
2724 ((LCID) GetKeyboardLayout (0) & 0xFFFF),
|
|
2725 NULL));
|
867
|
2726 ch = itext_ichar (intchar);
|
771
|
2727 xfree (intchar);
|
|
2728 }
|
442
|
2729
|
593
|
2730 #ifdef DEBUG_XEMACS
|
|
2731 if (debug_mswindows_events)
|
|
2732 {
|
|
2733 stderr_out ("-> ");
|
|
2734 debug_output_mswin_message (tranmsg.hwnd, tranmsg.message,
|
|
2735 tranmsg.wParam,
|
|
2736 tranmsg.lParam);
|
|
2737 }
|
|
2738 #endif /* DEBUG_XEMACS */
|
|
2739
|
827
|
2740 #ifdef HAVE_MENUBARS
|
1204
|
2741 if (potential_accelerator && !got_accelerator &&
|
|
2742 mswindows_char_is_accelerator (frame, ch))
|
442
|
2743 {
|
|
2744 got_accelerator = 1;
|
|
2745 break;
|
|
2746 }
|
827
|
2747 #endif /* HAVE_MENUBARS */
|
|
2748
|
771
|
2749 lastev = mswindows_enqueue_keypress_event (hwnd,
|
|
2750 make_char (ch),
|
|
2751 mods_with_quit);
|
442
|
2752 } /* while */
|
|
2753
|
771
|
2754 #ifdef MULE
|
|
2755 /* Also figure out what the character would be in other
|
|
2756 possible keyboard layouts, in this order:
|
|
2757
|
|
2758 -- current language environment
|
|
2759 -- user default language environment
|
|
2760 -- system default language environment
|
|
2761 -- same three, but checking the underlying virtual key,
|
|
2762 and only paying attention if it's alphabetic
|
|
2763 -- US ASCII
|
|
2764
|
|
2765 See events.h, struct key_data, for why we do this.
|
|
2766 */
|
|
2767
|
|
2768 if (!NILP (lastev))
|
|
2769 {
|
|
2770 int i;
|
|
2771 int scan = (lParam >> 16) && 0xFF;
|
|
2772
|
|
2773 for (i = 0; i < KEYCHAR_LAST; i++)
|
|
2774 {
|
|
2775 int vk_only = 0;
|
|
2776 LCID lcid;
|
|
2777 int virtual_key;
|
|
2778
|
|
2779 switch (i)
|
|
2780 {
|
|
2781 case KEYCHAR_UNDERLYING_VIRTUAL_KEY_CURRENT_LANGENV:
|
|
2782 vk_only = 1;
|
|
2783 case KEYCHAR_CURRENT_LANGENV:
|
|
2784 lcid = mswindows_current_locale ();
|
|
2785 break;
|
|
2786
|
|
2787 case KEYCHAR_UNDERLYING_VIRTUAL_KEY_DEFAULT_USER:
|
|
2788 vk_only = 1;
|
|
2789 case KEYCHAR_DEFAULT_USER:
|
|
2790 lcid = GetUserDefaultLCID ();
|
|
2791 break;
|
|
2792
|
|
2793 case KEYCHAR_UNDERLYING_VIRTUAL_KEY_DEFAULT_SYSTEM:
|
|
2794 vk_only = 1;
|
|
2795 case KEYCHAR_DEFAULT_SYSTEM:
|
|
2796 lcid = GetSystemDefaultLCID ();
|
|
2797 break;
|
|
2798
|
|
2799 case KEYCHAR_QWERTY:
|
|
2800 lcid = MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US);
|
|
2801 break;
|
|
2802
|
|
2803 default: abort (); lcid = 0;
|
|
2804 }
|
|
2805
|
|
2806 /* VERY CONFUSING! See intl-win32.c. */
|
|
2807 lcid = lcid & 0xFFFF;
|
|
2808
|
800
|
2809 virtual_key = qxeMapVirtualKeyEx (scan, 1, (HKL) lcid);
|
771
|
2810 if (!vk_only)
|
|
2811 {
|
|
2812 if (XEUNICODE_P)
|
|
2813 {
|
|
2814 Extbyte received_keys[32];
|
|
2815 int tounret =
|
|
2816 ToUnicodeEx
|
|
2817 (virtual_key, scan, keymap_trans,
|
|
2818 (LPWSTR) received_keys,
|
|
2819 sizeof (received_keys) / XETCHAR_SIZE,
|
|
2820 0, /* #### what about this flag? "if
|
|
2821 bit 0 is set, a menu is
|
|
2822 active???" */
|
|
2823 (HKL) lcid);
|
|
2824 if (tounret > 0)
|
|
2825 {
|
867
|
2826 Ibyte *intchar;
|
771
|
2827
|
|
2828 TO_INTERNAL_FORMAT
|
|
2829 (DATA,
|
|
2830 (received_keys + (tounret - 1) * 2, 2),
|
|
2831 C_STRING_ALLOCA, intchar,
|
|
2832 Qmswindows_unicode);
|
1204
|
2833 XSET_EVENT_KEY_ALT_KEYCHARS
|
|
2834 (lastev, i, itext_ichar (intchar));
|
771
|
2835 }
|
|
2836 }
|
|
2837 else
|
|
2838 {
|
|
2839 WORD received_keys[32];
|
|
2840 int tounret =
|
|
2841 ToAsciiEx (virtual_key, scan, keymap_trans,
|
|
2842 received_keys,
|
|
2843 0, /* #### what about this
|
|
2844 flag? "if bit 0 is set, a
|
|
2845 menu is active???" */
|
|
2846 (HKL) lcid);
|
|
2847 if (tounret > 0)
|
|
2848 {
|
|
2849 /* #### I cannot find proper
|
|
2850 documentation on what format the
|
|
2851 return value is in. I'm assuming
|
|
2852 it's like WM_IME_CHAR: DBCS chars
|
|
2853 have the lead byte in bits 8-15 of
|
|
2854 the short. */
|
867
|
2855 Ibyte *intchar;
|
771
|
2856 Extbyte mbstuff[2];
|
|
2857 Bytecount mblength = 0;
|
|
2858 WORD thechar = received_keys[tounret - 1];
|
|
2859
|
|
2860 mbstuff[mblength++] =
|
|
2861 (Extbyte) (thechar & 0xFF);
|
|
2862 if (thechar > 0xFF)
|
|
2863 mbstuff[mblength++] =
|
|
2864 (Extbyte) ((thechar >> 8) & 0xFF);
|
|
2865
|
|
2866 intchar = convert_multibyte_to_internal_malloc
|
|
2867 (mbstuff, mblength,
|
|
2868 mswindows_locale_to_code_page (lcid),
|
|
2869 NULL);
|
|
2870
|
1204
|
2871 XSET_EVENT_KEY_ALT_KEYCHARS
|
|
2872 (lastev, i, itext_ichar (intchar));
|
771
|
2873 xfree (intchar);
|
|
2874 }
|
|
2875 }
|
|
2876 }
|
|
2877 else
|
|
2878 {
|
867
|
2879 Ichar altch;
|
771
|
2880
|
|
2881 if (virtual_key >= 'A' && virtual_key <= 'Z')
|
|
2882 altch =
|
|
2883 virtual_key + (mods_with_shift & XEMACS_MOD_SHIFT ?
|
|
2884 'a' - 'A' : 0);
|
|
2885 else
|
|
2886 altch = 0;
|
|
2887
|
1204
|
2888 XSET_EVENT_KEY_ALT_KEYCHARS (lastev, i, altch);
|
771
|
2889 }
|
|
2890 }
|
|
2891 }
|
|
2892 #endif /* MULE */
|
|
2893
|
442
|
2894 /* This generates WM_SYSCHAR messages, which are interpreted
|
|
2895 by DefWindowProc as the menu selections. */
|
|
2896 if (got_accelerator)
|
|
2897 {
|
|
2898 SetKeyboardState (keymap_sticky);
|
|
2899 TranslateMessage (&msg);
|
|
2900 SetKeyboardState (keymap_orig);
|
771
|
2901 unbind_to (count);
|
442
|
2902 goto defproc;
|
|
2903 }
|
|
2904
|
|
2905 SetKeyboardState (keymap_orig);
|
|
2906 } /* else */
|
771
|
2907
|
|
2908 if (key_needs_default_processing_p (wParam))
|
|
2909 {
|
|
2910 unbind_to (count);
|
|
2911 goto defproc;
|
|
2912 }
|
|
2913 else
|
|
2914 {
|
|
2915 unbind_to (count);
|
|
2916 break;
|
|
2917 }
|
428
|
2918 }
|
442
|
2919
|
|
2920 case WM_MBUTTONDOWN:
|
|
2921 case WM_MBUTTONUP:
|
|
2922 /* Real middle mouse button has nothing to do with emulated one:
|
|
2923 if one wants to exercise fingers playing chords on the mouse,
|
|
2924 he is allowed to do that! */
|
|
2925 mswindows_enqueue_mouse_button_event (hwnd, message_,
|
|
2926 MAKEPOINTS (lParam),
|
|
2927 wParam &~ MK_MBUTTON,
|
|
2928 GetMessageTime());
|
|
2929 break;
|
|
2930
|
|
2931 case WM_LBUTTONUP:
|
771
|
2932 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
2933 msframe->last_click_time = GetMessageTime();
|
442
|
2934
|
|
2935 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
2936 msframe->button2_need_lbutton = 0;
|
|
2937 if (msframe->ignore_next_lbutton_up)
|
|
2938 {
|
|
2939 msframe->ignore_next_lbutton_up = 0;
|
|
2940 }
|
|
2941 else if (msframe->button2_is_down)
|
|
2942 {
|
|
2943 msframe->button2_is_down = 0;
|
|
2944 msframe->ignore_next_rbutton_up = 1;
|
|
2945 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
|
|
2946 MAKEPOINTS (lParam),
|
|
2947 wParam
|
|
2948 &~ (MK_LBUTTON | MK_MBUTTON
|
|
2949 | MK_RBUTTON),
|
|
2950 GetMessageTime());
|
|
2951 }
|
|
2952 else
|
|
2953 {
|
|
2954 if (msframe->button2_need_rbutton)
|
|
2955 {
|
|
2956 msframe->button2_need_rbutton = 0;
|
|
2957 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
2958 MAKEPOINTS (lParam),
|
|
2959 wParam &~ MK_LBUTTON,
|
|
2960 GetMessageTime());
|
|
2961 }
|
|
2962 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONUP,
|
|
2963 MAKEPOINTS (lParam),
|
|
2964 wParam &~ MK_LBUTTON,
|
|
2965 GetMessageTime());
|
|
2966 }
|
|
2967 break;
|
|
2968
|
|
2969 case WM_RBUTTONUP:
|
771
|
2970 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
2971 msframe->last_click_time = GetMessageTime();
|
442
|
2972
|
|
2973 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
2974 msframe->button2_need_rbutton = 0;
|
|
2975 if (msframe->ignore_next_rbutton_up)
|
|
2976 {
|
|
2977 msframe->ignore_next_rbutton_up = 0;
|
|
2978 }
|
|
2979 else if (msframe->button2_is_down)
|
|
2980 {
|
|
2981 msframe->button2_is_down = 0;
|
|
2982 msframe->ignore_next_lbutton_up = 1;
|
|
2983 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
|
|
2984 MAKEPOINTS (lParam),
|
|
2985 wParam
|
|
2986 &~ (MK_LBUTTON | MK_MBUTTON
|
|
2987 | MK_RBUTTON),
|
|
2988 GetMessageTime());
|
|
2989 }
|
|
2990 else
|
|
2991 {
|
|
2992 if (msframe->button2_need_lbutton)
|
|
2993 {
|
|
2994 msframe->button2_need_lbutton = 0;
|
|
2995 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
2996 MAKEPOINTS (lParam),
|
|
2997 wParam &~ MK_RBUTTON,
|
|
2998 GetMessageTime());
|
|
2999 }
|
|
3000 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONUP,
|
|
3001 MAKEPOINTS (lParam),
|
|
3002 wParam &~ MK_RBUTTON,
|
|
3003 GetMessageTime());
|
|
3004 }
|
|
3005 break;
|
|
3006
|
|
3007 case WM_LBUTTONDOWN:
|
771
|
3008 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
442
|
3009
|
|
3010 if (msframe->button2_need_lbutton)
|
428
|
3011 {
|
|
3012 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
442
|
3013 msframe->button2_need_lbutton = 0;
|
|
3014 msframe->button2_need_rbutton = 0;
|
|
3015 if (mswindows_button2_near_enough (msframe->last_click_point,
|
|
3016 MAKEPOINTS (lParam)))
|
428
|
3017 {
|
442
|
3018 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
|
|
3019 MAKEPOINTS (lParam),
|
|
3020 wParam
|
|
3021 &~ (MK_LBUTTON | MK_MBUTTON
|
|
3022 | MK_RBUTTON),
|
|
3023 GetMessageTime());
|
|
3024 msframe->button2_is_down = 1;
|
428
|
3025 }
|
442
|
3026 else
|
428
|
3027 {
|
442
|
3028 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
3029 msframe->last_click_point,
|
|
3030 msframe->last_click_mods
|
|
3031 &~ MK_RBUTTON,
|
|
3032 msframe->last_click_time);
|
|
3033 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
3034 MAKEPOINTS (lParam),
|
|
3035 wParam &~ MK_LBUTTON,
|
|
3036 GetMessageTime());
|
428
|
3037 }
|
|
3038 }
|
|
3039 else
|
442
|
3040 {
|
|
3041 mswindows_set_chord_timer (hwnd);
|
|
3042 msframe->button2_need_rbutton = 1;
|
|
3043 msframe->last_click_point = MAKEPOINTS (lParam);
|
|
3044 msframe->last_click_mods = wParam;
|
|
3045 }
|
771
|
3046 msframe->last_click_time = GetMessageTime();
|
442
|
3047 break;
|
|
3048
|
|
3049 case WM_RBUTTONDOWN:
|
771
|
3050 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
442
|
3051
|
|
3052 if (msframe->button2_need_rbutton)
|
428
|
3053 {
|
442
|
3054 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
3055 msframe->button2_need_lbutton = 0;
|
|
3056 msframe->button2_need_rbutton = 0;
|
|
3057 if (mswindows_button2_near_enough (msframe->last_click_point,
|
|
3058 MAKEPOINTS (lParam)))
|
|
3059 {
|
|
3060 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
|
|
3061 MAKEPOINTS (lParam),
|
|
3062 wParam
|
|
3063 &~ (MK_LBUTTON | MK_MBUTTON
|
|
3064 | MK_RBUTTON),
|
|
3065 GetMessageTime());
|
|
3066 msframe->button2_is_down = 1;
|
|
3067 }
|
|
3068 else
|
|
3069 {
|
|
3070 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
3071 msframe->last_click_point,
|
|
3072 msframe->last_click_mods
|
|
3073 &~ MK_LBUTTON,
|
|
3074 msframe->last_click_time);
|
|
3075 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
3076 MAKEPOINTS (lParam),
|
|
3077 wParam &~ MK_RBUTTON,
|
|
3078 GetMessageTime());
|
|
3079 }
|
428
|
3080 }
|
|
3081 else
|
|
3082 {
|
442
|
3083 mswindows_set_chord_timer (hwnd);
|
|
3084 msframe->button2_need_lbutton = 1;
|
|
3085 msframe->last_click_point = MAKEPOINTS (lParam);
|
|
3086 msframe->last_click_mods = wParam;
|
|
3087 }
|
771
|
3088 msframe->last_click_time = GetMessageTime();
|
442
|
3089 break;
|
|
3090
|
|
3091 case WM_TIMER:
|
|
3092 if (wParam == BUTTON_2_TIMER_ID)
|
|
3093 {
|
771
|
3094 msframe =
|
|
3095 FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
442
|
3096 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
3097
|
|
3098 if (msframe->button2_need_lbutton)
|
|
3099 {
|
|
3100 msframe->button2_need_lbutton = 0;
|
|
3101 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
3102 msframe->last_click_point,
|
|
3103 msframe->last_click_mods
|
|
3104 &~ MK_RBUTTON,
|
|
3105 msframe->last_click_time);
|
|
3106 }
|
|
3107 else if (msframe->button2_need_rbutton)
|
|
3108 {
|
|
3109 msframe->button2_need_rbutton = 0;
|
|
3110 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
3111 msframe->last_click_point,
|
|
3112 msframe->last_click_mods
|
|
3113 &~ MK_LBUTTON,
|
|
3114 msframe->last_click_time);
|
|
3115 }
|
|
3116 }
|
|
3117 else
|
|
3118 assert ("Spurious timer fired" == 0);
|
|
3119 break;
|
|
3120
|
|
3121 case WM_MOUSEMOVE:
|
|
3122 /* Optimization: don't report mouse movement while size is changing */
|
771
|
3123 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
442
|
3124 if (!msframe->sizing)
|
|
3125 {
|
|
3126 /* When waiting for the second mouse button to finish
|
|
3127 button2 emulation, and have moved too far, just pretend
|
|
3128 as if timer has expired. This improves drag-select feedback */
|
|
3129 if ((msframe->button2_need_lbutton || msframe->button2_need_rbutton)
|
|
3130 && !mswindows_button2_near_enough (msframe->last_click_point,
|
|
3131 MAKEPOINTS (lParam)))
|
428
|
3132 {
|
442
|
3133 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
771
|
3134 qxeSendMessage (hwnd, WM_TIMER, BUTTON_2_TIMER_ID, 0);
|
442
|
3135 }
|
|
3136
|
|
3137 emacs_event = Fmake_event (Qnil, Qnil);
|
|
3138 event = XEVENT(emacs_event);
|
|
3139
|
964
|
3140 XSET_EVENT_CHANNEL (emacs_event, mswindows_find_frame(hwnd));
|
|
3141 XSET_EVENT_TIMESTAMP (emacs_event, GetMessageTime());
|
|
3142 XSET_EVENT_TYPE (emacs_event, pointer_motion_event);
|
1204
|
3143 XSET_EVENT_MOTION_X (emacs_event,MAKEPOINTS (lParam).x);
|
|
3144 XSET_EVENT_MOTION_Y (emacs_event,MAKEPOINTS (lParam).y);
|
|
3145 XSET_EVENT_MOTION_MODIFIERS (emacs_event,
|
964
|
3146 mswindows_modifier_state (NULL, wParam, 0));
|
442
|
3147
|
|
3148 mswindows_enqueue_dispatch_event (emacs_event);
|
|
3149 }
|
|
3150 break;
|
|
3151
|
|
3152 case WM_CANCELMODE:
|
|
3153 ReleaseCapture ();
|
|
3154 /* Queue a `cancel-mode-internal' misc user event, so mouse
|
|
3155 selection would be canceled if any */
|
|
3156 mswindows_enqueue_misc_user_event (mswindows_find_frame (hwnd),
|
|
3157 Qcancel_mode_internal, Qnil);
|
|
3158 break;
|
|
3159
|
|
3160 case WM_NOTIFY:
|
|
3161 {
|
647
|
3162 LPNMHDR nmhdr = (LPNMHDR) lParam;
|
|
3163
|
1111
|
3164 if (nmhdr->code == TTN_NEEDTEXT)
|
442
|
3165 {
|
|
3166 #ifdef HAVE_TOOLBARS
|
771
|
3167 LPTOOLTIPTEXTW tttextw = (LPTOOLTIPTEXTW) lParam;
|
442
|
3168 Lisp_Object btext;
|
771
|
3169 Extbyte *btextext = 0;
|
442
|
3170
|
|
3171 /* find out which toolbar */
|
|
3172 frame = XFRAME (mswindows_find_frame (hwnd));
|
647
|
3173 btext = mswindows_get_toolbar_button_text (frame, nmhdr->idFrom);
|
442
|
3174
|
771
|
3175 tttextw->hinst = NULL;
|
|
3176
|
|
3177 if (!NILP (btext))
|
|
3178 LISP_STRING_TO_TSTR (btext, btextext);
|
|
3179
|
|
3180 if (btextext)
|
442
|
3181 {
|
771
|
3182 /* WARNING: We can't just write a '\0' into the 79th
|
|
3183 "character" because tttextw->szText is in WCHAR's but we
|
|
3184 may be copying an ANSI string into it. Easiest to just
|
|
3185 zero the whole thing. */
|
|
3186 xzero (*tttextw->szText);
|
|
3187 xetcsncpy ((Extbyte *) tttextw->szText, btextext, 79);
|
442
|
3188 }
|
771
|
3189 else
|
|
3190 tttextw->lpszText = NULL;
|
442
|
3191 #endif
|
|
3192 }
|
|
3193 /* handle tree view callbacks */
|
1111
|
3194 else if (nmhdr->code == TVN_SELCHANGED)
|
442
|
3195 {
|
647
|
3196 NM_TREEVIEW *ptree = (NM_TREEVIEW *) lParam;
|
442
|
3197 frame = XFRAME (mswindows_find_frame (hwnd));
|
|
3198 mswindows_handle_gui_wm_command (frame, 0, ptree->itemNew.lParam);
|
|
3199 }
|
|
3200 /* handle tab control callbacks */
|
1111
|
3201 else if (nmhdr->code == TCN_SELCHANGE)
|
442
|
3202 {
|
|
3203 TC_ITEM item;
|
771
|
3204 int idx = qxeSendMessage (nmhdr->hwndFrom, TCM_GETCURSEL, 0, 0);
|
442
|
3205 frame = XFRAME (mswindows_find_frame (hwnd));
|
|
3206
|
|
3207 item.mask = TCIF_PARAM;
|
771
|
3208 qxeSendMessage (nmhdr->hwndFrom, TCM_GETITEM, (WPARAM) idx,
|
|
3209 (LPARAM) &item);
|
442
|
3210
|
|
3211 mswindows_handle_gui_wm_command (frame, 0, item.lParam);
|
|
3212 }
|
|
3213 }
|
|
3214 break;
|
|
3215
|
|
3216 case WM_PAINT:
|
|
3217 /* hdc will be NULL unless this is a subwindow - in which case we
|
|
3218 shouldn't have received a paint message for it here. */
|
|
3219 assert (wParam == 0);
|
|
3220
|
|
3221 /* Can't queue a magic event because windows goes modal and sends paint
|
|
3222 messages directly to the windows procedure when doing solid drags
|
|
3223 and the message queue doesn't get processed. */
|
|
3224 mswindows_handle_paint (XFRAME (mswindows_find_frame (hwnd)));
|
|
3225 break;
|
|
3226
|
903
|
3227 case WM_ACTIVATE:
|
|
3228 {
|
|
3229 /*
|
|
3230 * If we receive a WM_ACTIVATE message that indicates that our frame
|
|
3231 * is being activated, make sure that the frame is marked visible
|
|
3232 * if the window itself is visible. This seems to fix the problem
|
|
3233 * where XEmacs appears to lock-up after switching desktops with
|
|
3234 * some virtual window managers.
|
|
3235 */
|
|
3236 int state = (int)(short) LOWORD(wParam);
|
|
3237 #ifdef DEBUG_XEMACS
|
|
3238 if (debug_mswindows_events)
|
|
3239 stderr_out("state = %d\n", state);
|
|
3240 #endif /* DEBUG_XEMACS */
|
|
3241 if (state == WA_ACTIVE || state == WA_CLICKACTIVE)
|
|
3242 {
|
|
3243 #ifdef DEBUG_XEMACS
|
|
3244 if (debug_mswindows_events)
|
|
3245 stderr_out(" activating\n");
|
|
3246 #endif /* DEBUG_XEMACS */
|
|
3247
|
|
3248 fobj = mswindows_find_frame (hwnd);
|
|
3249 frame = XFRAME (fobj);
|
|
3250 if (IsWindowVisible (hwnd))
|
|
3251 {
|
|
3252 #ifdef DEBUG_XEMACS
|
|
3253 if (debug_mswindows_events)
|
|
3254 stderr_out(" window is visible\n");
|
|
3255 #endif /* DEBUG_XEMACS */
|
|
3256 if (!FRAME_VISIBLE_P (frame))
|
|
3257 {
|
|
3258 #ifdef DEBUG_XEMACS
|
|
3259 if (debug_mswindows_events)
|
|
3260 stderr_out(" frame is not visible\n");
|
|
3261 #endif /* DEBUG_XEMACS */
|
|
3262 /*
|
|
3263 * It seems that we have to enqueue the XM_MAPFRAME event
|
|
3264 * prior to setting the frame visible so that
|
|
3265 * suspend-or-iconify-emacs works properly.
|
|
3266 */
|
|
3267 mswindows_enqueue_magic_event (hwnd, XM_MAPFRAME);
|
|
3268 FRAME_VISIBLE_P (frame) = 1;
|
|
3269 FRAME_ICONIFIED_P (frame) = 0;
|
|
3270 }
|
|
3271 #ifdef DEBUG_XEMACS
|
|
3272 else
|
|
3273 {
|
|
3274 if (debug_mswindows_events)
|
|
3275 stderr_out(" frame is visible\n");
|
|
3276 }
|
|
3277 #endif /* DEBUG_XEMACS */
|
|
3278 }
|
|
3279 #ifdef DEBUG_XEMACS
|
|
3280 else
|
|
3281 {
|
|
3282 if (debug_mswindows_events)
|
|
3283 stderr_out(" window is not visible\n");
|
|
3284 }
|
|
3285 #endif /* DEBUG_XEMACS */
|
|
3286 }
|
|
3287 return qxeDefWindowProc (hwnd, message_, wParam, lParam);
|
|
3288 }
|
|
3289 break;
|
|
3290
|
593
|
3291 case WM_WINDOWPOSCHANGED:
|
|
3292 /* This is sent before WM_SIZE; in fact, the processing of this
|
|
3293 by DefWindowProc() sends WM_SIZE. But WM_SIZE is not sent when
|
|
3294 a window is hidden (make-frame-invisible), so we need to process
|
|
3295 this and update the state flags. */
|
|
3296 {
|
|
3297 fobj = mswindows_find_frame (hwnd);
|
|
3298 frame = XFRAME (fobj);
|
|
3299 if (IsIconic (hwnd))
|
|
3300 {
|
|
3301 FRAME_VISIBLE_P (frame) = 0;
|
|
3302 FRAME_ICONIFIED_P (frame) = 1;
|
|
3303 }
|
|
3304 else if (IsWindowVisible (hwnd))
|
|
3305 {
|
707
|
3306 /* APA: It's too early here to set the frame visible.
|
|
3307 * Let's do this later, in WM_SIZE processing, after the
|
|
3308 * magic XM_MAPFRAME event has been sent (just like 21.1
|
|
3309 * did). */
|
|
3310 /* FRAME_VISIBLE_P (frame) = 1; */
|
593
|
3311 FRAME_ICONIFIED_P (frame) = 0;
|
|
3312 }
|
|
3313 else
|
|
3314 {
|
|
3315 FRAME_VISIBLE_P (frame) = 0;
|
|
3316 FRAME_ICONIFIED_P (frame) = 0;
|
|
3317 }
|
|
3318
|
771
|
3319 goto defproc;
|
593
|
3320 }
|
|
3321
|
731
|
3322 case WM_SHOWWINDOW:
|
|
3323 /*
|
|
3324 The WM_SHOWWINDOW message is sent to a window when the window
|
|
3325 is about to be hidden or shown.
|
|
3326 APA: This message is also sent when switching to a virtual
|
|
3327 desktop under the virtuawin virtual window manager.
|
|
3328
|
|
3329 */
|
|
3330 {
|
|
3331 fobj = mswindows_find_frame (hwnd);
|
|
3332 frame = XFRAME (fobj);
|
|
3333 if (wParam == TRUE)
|
|
3334 {
|
|
3335 mswindows_enqueue_magic_event (hwnd, XM_MAPFRAME);
|
|
3336 FRAME_VISIBLE_P (frame) = 1;
|
|
3337 }
|
|
3338 else
|
|
3339 {
|
|
3340 mswindows_enqueue_magic_event (hwnd, XM_UNMAPFRAME);
|
|
3341 FRAME_VISIBLE_P (frame) = 0;
|
|
3342 }
|
|
3343 }
|
|
3344 break;
|
|
3345
|
442
|
3346 case WM_SIZE:
|
|
3347 /* We only care about this message if our size has really changed */
|
771
|
3348 if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED ||
|
|
3349 wParam == SIZE_MINIMIZED)
|
442
|
3350 {
|
|
3351 RECT rect;
|
|
3352 int columns, rows;
|
|
3353
|
|
3354 fobj = mswindows_find_frame (hwnd);
|
|
3355 frame = XFRAME (fobj);
|
771
|
3356 msframe = FRAME_MSWINDOWS_DATA (frame);
|
442
|
3357
|
|
3358 /* We cannot handle frame map and unmap hooks right in
|
|
3359 this routine, because these may throw. We queue
|
|
3360 magic events to run these hooks instead - kkm */
|
|
3361
|
771
|
3362 if (wParam == SIZE_MINIMIZED)
|
442
|
3363 {
|
|
3364 /* Iconified */
|
|
3365 mswindows_enqueue_magic_event (hwnd, XM_UNMAPFRAME);
|
428
|
3366 }
|
|
3367 else
|
|
3368 {
|
1279
|
3369 GetClientRect (hwnd, &rect);
|
|
3370 FRAME_PIXWIDTH (frame) = rect.right;
|
|
3371 FRAME_PIXHEIGHT (frame) = rect.bottom;
|
442
|
3372
|
|
3373 pixel_to_real_char_size (frame, rect.right, rect.bottom,
|
|
3374 &FRAME_MSWINDOWS_CHARWIDTH (frame),
|
|
3375 &FRAME_MSWINDOWS_CHARHEIGHT (frame));
|
|
3376
|
771
|
3377 pixel_to_char_size (frame, rect.right, rect.bottom, &columns,
|
|
3378 &rows);
|
442
|
3379 change_frame_size (frame, rows, columns, 1);
|
|
3380
|
|
3381 /* If we are inside frame creation, we have to apply geometric
|
|
3382 properties now. */
|
|
3383 if (FRAME_MSWINDOWS_TARGET_RECT (frame))
|
|
3384 {
|
|
3385 /* Yes, we have to size again */
|
771
|
3386 mswindows_size_frame_internal (frame,
|
|
3387 FRAME_MSWINDOWS_TARGET_RECT
|
|
3388 (frame));
|
|
3389 /* Reset so we do not get here again. The SetWindowPos
|
|
3390 * call in mswindows_size_frame_internal can cause
|
|
3391 * recursion here. */
|
442
|
3392 if (FRAME_MSWINDOWS_TARGET_RECT (frame))
|
|
3393 {
|
|
3394 xfree (FRAME_MSWINDOWS_TARGET_RECT (frame));
|
|
3395 FRAME_MSWINDOWS_TARGET_RECT (frame) = 0;
|
|
3396 }
|
|
3397 }
|
|
3398 else
|
|
3399 {
|
903
|
3400 if (!msframe->sizing && !FRAME_VISIBLE_P (frame))
|
|
3401 {
|
|
3402 mswindows_enqueue_magic_event (hwnd, XM_MAPFRAME);
|
|
3403 /* APA: Now that the magic XM_MAPFRAME event has
|
|
3404 * been sent we can mark the frame as visible (just
|
|
3405 * like 21.1 did). */
|
|
3406 FRAME_VISIBLE_P (frame) = 1;
|
|
3407 }
|
442
|
3408
|
1279
|
3409 if (frame->init_finished &&
|
|
3410 (!msframe->sizing || mswindows_dynamic_frame_resize))
|
442
|
3411 redisplay ();
|
|
3412 }
|
428
|
3413 }
|
|
3414 }
|
442
|
3415 break;
|
|
3416
|
|
3417 case WM_DISPLAYCHANGE:
|
|
3418 {
|
|
3419 struct device *d;
|
|
3420 DWORD message_tick = GetMessageTime ();
|
|
3421
|
|
3422 fobj = mswindows_find_frame (hwnd);
|
|
3423 frame = XFRAME (fobj);
|
|
3424 d = XDEVICE (FRAME_DEVICE (frame));
|
|
3425
|
|
3426 /* Do this only once per message. XEmacs can receive this message
|
|
3427 through as many frames as it currently has open. Message time
|
|
3428 will be the same for all these messages. Despite extreme
|
|
3429 efficiency, the code below has about one in 4 billion
|
|
3430 probability that the HDC is not recreated, provided that
|
|
3431 XEmacs is running sufficiently longer than 52 days. */
|
1279
|
3432 if (DEVICE_MSWINDOWS_UPDATE_TICK (d) != message_tick)
|
442
|
3433 {
|
1279
|
3434 DEVICE_MSWINDOWS_UPDATE_TICK (d) = message_tick;
|
|
3435 DeleteDC (DEVICE_MSWINDOWS_HCDC (d));
|
|
3436 DEVICE_MSWINDOWS_HCDC (d) = CreateCompatibleDC (NULL);
|
442
|
3437 }
|
|
3438 }
|
|
3439 break;
|
|
3440
|
|
3441 /* Misc magic events which only require that the frame be identified */
|
|
3442 case WM_SETFOCUS:
|
|
3443 case WM_KILLFOCUS:
|
|
3444 mswindows_enqueue_magic_event (hwnd, message_);
|
|
3445 break;
|
|
3446
|
|
3447 case WM_WINDOWPOSCHANGING:
|
428
|
3448 {
|
442
|
3449 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
|
|
3450 WINDOWPLACEMENT wpl = { sizeof(WINDOWPLACEMENT) };
|
|
3451 GetWindowPlacement(hwnd, &wpl);
|
|
3452
|
|
3453 /* Only interested if size is changing and we're not being iconified */
|
|
3454 if (wpl.showCmd != SW_SHOWMINIMIZED
|
|
3455 && wpl.showCmd != SW_SHOWMAXIMIZED
|
|
3456 && !(wp->flags & SWP_NOSIZE))
|
428
|
3457 {
|
442
|
3458 RECT ncsize = { 0, 0, 0, 0 };
|
|
3459 int pixwidth, pixheight;
|
771
|
3460 AdjustWindowRectEx (&ncsize, qxeGetWindowLong (hwnd, GWL_STYLE),
|
442
|
3461 GetMenu(hwnd) != NULL,
|
771
|
3462 qxeGetWindowLong (hwnd, GWL_EXSTYLE));
|
442
|
3463
|
|
3464 round_size_to_real_char (XFRAME (mswindows_find_frame (hwnd)),
|
|
3465 wp->cx - (ncsize.right - ncsize.left),
|
|
3466 wp->cy - (ncsize.bottom - ncsize.top),
|
|
3467 &pixwidth, &pixheight);
|
|
3468
|
|
3469 /* Convert client sizes to window sizes */
|
|
3470 pixwidth += (ncsize.right - ncsize.left);
|
|
3471 pixheight += (ncsize.bottom - ncsize.top);
|
|
3472
|
|
3473 if (wpl.showCmd != SW_SHOWMAXIMIZED)
|
|
3474 {
|
|
3475 /* Adjust so that the bottom or right doesn't move if it's
|
|
3476 * the top or left that's being changed */
|
|
3477 RECT rect;
|
|
3478 GetWindowRect (hwnd, &rect);
|
|
3479
|
|
3480 if (rect.left != wp->x)
|
|
3481 wp->x += wp->cx - pixwidth;
|
|
3482 if (rect.top != wp->y)
|
|
3483 wp->y += wp->cy - pixheight;
|
|
3484 }
|
|
3485
|
|
3486 wp->cx = pixwidth;
|
|
3487 wp->cy = pixheight;
|
428
|
3488 }
|
442
|
3489 /* DefWindowProc sends useful WM_GETMINMAXINFO message, and adjusts
|
|
3490 window position if the user tries to track window too small */
|
428
|
3491 }
|
442
|
3492 goto defproc;
|
|
3493
|
|
3494 case WM_ENTERSIZEMOVE:
|
771
|
3495 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
442
|
3496 msframe->sizing = 1;
|
|
3497 return 0;
|
|
3498
|
|
3499 case WM_EXITSIZEMOVE:
|
771
|
3500 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
442
|
3501 msframe->sizing = 0;
|
|
3502 /* Queue noop event */
|
|
3503 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
|
|
3504 return 0;
|
428
|
3505
|
|
3506 #ifdef HAVE_SCROLLBARS
|
442
|
3507 case WM_VSCROLL:
|
|
3508 case WM_HSCROLL:
|
|
3509 {
|
|
3510 /* Direction of scroll is determined by scrollbar instance. */
|
1279
|
3511 int code = (int) LOWORD (wParam);
|
|
3512 int pos = (short int) HIWORD (wParam);
|
442
|
3513 HWND hwndScrollBar = (HWND) lParam;
|
|
3514 struct gcpro gcpro1, gcpro2;
|
|
3515
|
|
3516 mswindows_handle_scrollbar_event (hwndScrollBar, code, pos);
|
|
3517 GCPRO2 (emacs_event, fobj);
|
853
|
3518 if (UNBOUNDP (mswindows_pump_outstanding_events ())) /* Can GC */
|
442
|
3519 {
|
|
3520 /* Error during event pumping - cancel scroll */
|
771
|
3521 qxeSendMessage (hwndScrollBar, WM_CANCELMODE, 0, 0);
|
442
|
3522 }
|
|
3523 UNGCPRO;
|
|
3524 break;
|
|
3525 }
|
|
3526
|
|
3527 case WM_MOUSEWHEEL:
|
|
3528 {
|
|
3529 int keys = LOWORD (wParam); /* Modifier key flags */
|
|
3530 int delta = (short) HIWORD (wParam); /* Wheel rotation amount */
|
|
3531
|
464
|
3532 if (mswindows_handle_mousewheel_event (mswindows_find_frame (hwnd),
|
|
3533 keys, delta,
|
|
3534 MAKEPOINTS (lParam)))
|
707
|
3535 /* We are not in a modal loop so no pumping is necessary. */
|
|
3536 break;
|
442
|
3537 else
|
|
3538 goto defproc;
|
|
3539 }
|
428
|
3540 #endif
|
|
3541
|
|
3542 #ifdef HAVE_MENUBARS
|
442
|
3543 case WM_INITMENU:
|
771
|
3544 if (UNBOUNDP (mswindows_handle_wm_initmenu
|
|
3545 ((HMENU) wParam,
|
|
3546 XFRAME (mswindows_find_frame (hwnd)))))
|
|
3547 qxeSendMessage (hwnd, WM_CANCELMODE, 0, 0);
|
442
|
3548 break;
|
|
3549
|
|
3550 case WM_INITMENUPOPUP:
|
|
3551 if (!HIWORD(lParam))
|
|
3552 {
|
771
|
3553 if (UNBOUNDP (mswindows_handle_wm_initmenupopup
|
|
3554 ((HMENU) wParam,
|
|
3555 XFRAME (mswindows_find_frame (hwnd)))))
|
|
3556 qxeSendMessage (hwnd, WM_CANCELMODE, 0, 0);
|
442
|
3557 }
|
|
3558 break;
|
428
|
3559
|
|
3560 #endif /* HAVE_MENUBARS */
|
|
3561
|
442
|
3562 case WM_COMMAND:
|
|
3563 {
|
|
3564 WORD id = LOWORD (wParam);
|
|
3565 WORD nid = HIWORD (wParam);
|
|
3566 HWND cid = (HWND)lParam;
|
|
3567 frame = XFRAME (mswindows_find_frame (hwnd));
|
428
|
3568
|
|
3569 #ifdef HAVE_TOOLBARS
|
442
|
3570 if (!NILP (mswindows_handle_toolbar_wm_command (frame, cid, id)))
|
|
3571 break;
|
428
|
3572 #endif
|
771
|
3573 /* widgets in a buffer only eval a callback for suitable events. */
|
442
|
3574 switch (nid)
|
|
3575 {
|
|
3576 case BN_CLICKED:
|
|
3577 case EN_CHANGE:
|
|
3578 case CBN_EDITCHANGE:
|
|
3579 case CBN_SELCHANGE:
|
|
3580 if (!NILP (mswindows_handle_gui_wm_command (frame, cid, id)))
|
|
3581 return 0;
|
|
3582 }
|
|
3583 /* menubars always must come last since the hashtables do not
|
771
|
3584 always exist */
|
428
|
3585 #ifdef HAVE_MENUBARS
|
442
|
3586 if (!NILP (mswindows_handle_wm_command (frame, id)))
|
|
3587 break;
|
428
|
3588 #endif
|
|
3589
|
771
|
3590 goto defproc;
|
|
3591 /* Bite me - a spurious command. This used to not be able to
|
|
3592 happen but with the introduction of widgets it's now
|
|
3593 possible. #### Andy, fix the god-damn widget code! It has
|
|
3594 more bugs than a termite's nest! */
|
442
|
3595 }
|
|
3596 break;
|
|
3597
|
|
3598 case WM_CTLCOLORBTN:
|
|
3599 case WM_CTLCOLORLISTBOX:
|
|
3600 case WM_CTLCOLOREDIT:
|
|
3601 case WM_CTLCOLORSTATIC:
|
|
3602 case WM_CTLCOLORSCROLLBAR:
|
|
3603 {
|
|
3604 /* if we get an opportunity to paint a widget then do so if
|
|
3605 there is an appropriate face */
|
771
|
3606 HWND crtlwnd = (HWND) lParam;
|
|
3607 LONG ii = qxeGetWindowLong (crtlwnd, GWL_USERDATA);
|
442
|
3608 if (ii)
|
|
3609 {
|
|
3610 Lisp_Object image_instance;
|
826
|
3611 image_instance = VOID_TO_LISP ((void *) ii);
|
442
|
3612 if (IMAGE_INSTANCEP (image_instance)
|
|
3613 &&
|
|
3614 IMAGE_INSTANCE_TYPE_P (image_instance, IMAGE_WIDGET))
|
|
3615 {
|
|
3616 /* set colors for the buttons */
|
771
|
3617 HDC hdc = (HDC) wParam;
|
442
|
3618 if (last_widget_brushed != ii)
|
|
3619 {
|
|
3620 if (widget_brush)
|
|
3621 DeleteObject (widget_brush);
|
|
3622 widget_brush = CreateSolidBrush
|
|
3623 (COLOR_INSTANCE_MSWINDOWS_COLOR
|
|
3624 (XCOLOR_INSTANCE
|
|
3625 (FACE_BACKGROUND
|
|
3626 (XIMAGE_INSTANCE_WIDGET_FACE (image_instance),
|
|
3627 XIMAGE_INSTANCE_FRAME (image_instance)))));
|
|
3628 }
|
|
3629 last_widget_brushed = ii;
|
|
3630 SetTextColor
|
|
3631 (hdc,
|
|
3632 COLOR_INSTANCE_MSWINDOWS_COLOR
|
|
3633 (XCOLOR_INSTANCE
|
|
3634 (FACE_FOREGROUND
|
|
3635 (XIMAGE_INSTANCE_WIDGET_FACE (image_instance),
|
|
3636 XIMAGE_INSTANCE_FRAME (image_instance)))));
|
|
3637 SetBkMode (hdc, OPAQUE);
|
|
3638 SetBkColor
|
|
3639 (hdc,
|
|
3640 COLOR_INSTANCE_MSWINDOWS_COLOR
|
|
3641 (XCOLOR_INSTANCE
|
|
3642 (FACE_BACKGROUND
|
|
3643 (XIMAGE_INSTANCE_WIDGET_FACE (image_instance),
|
|
3644 XIMAGE_INSTANCE_FRAME (image_instance)))));
|
|
3645 return (LRESULT)widget_brush;
|
|
3646 }
|
|
3647 }
|
|
3648 }
|
|
3649 goto defproc;
|
428
|
3650
|
|
3651 #ifdef HAVE_DRAGNDROP
|
853
|
3652 case WM_DROPFILES: /* implementation ripped-off from event-Xt.c */
|
442
|
3653 {
|
771
|
3654 UINT filecount, i;
|
442
|
3655 POINT point;
|
|
3656
|
|
3657 Lisp_Object l_dndlist = Qnil, l_item = Qnil;
|
|
3658 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
3659
|
|
3660 emacs_event = Fmake_event (Qnil, Qnil);
|
771
|
3661 event = XEVENT (emacs_event);
|
442
|
3662
|
|
3663 GCPRO3 (emacs_event, l_dndlist, l_item);
|
|
3664
|
|
3665 if (!DragQueryPoint ((HDROP) wParam, &point))
|
853
|
3666 point.x = point.y = -1; /* outside client area */
|
442
|
3667
|
964
|
3668 XSET_EVENT_TYPE (emacs_event, misc_user_event);
|
|
3669 XSET_EVENT_CHANNEL (emacs_event, mswindows_find_frame(hwnd));
|
|
3670 XSET_EVENT_TIMESTAMP (emacs_event, GetMessageTime());
|
1204
|
3671 XSET_EVENT_MISC_USER_BUTTON (emacs_event, 1);
|
|
3672 XSET_EVENT_MISC_USER_MODIFIERS (emacs_event,
|
964
|
3673 mswindows_modifier_state (NULL, (DWORD) -1, 0));
|
1204
|
3674 XSET_EVENT_MISC_USER_X (emacs_event, point.x);
|
|
3675 XSET_EVENT_MISC_USER_Y (emacs_event, point.y);
|
|
3676 XSET_EVENT_MISC_USER_FUNCTION (emacs_event,
|
964
|
3677 Qdragdrop_drop_dispatch);
|
442
|
3678
|
771
|
3679 filecount = qxeDragQueryFile ((HDROP) wParam, 0xffffffff, NULL, 0);
|
|
3680 for (i = 0; i < filecount; i++)
|
442
|
3681 {
|
867
|
3682 Ibyte *fname;
|
771
|
3683 Extbyte *fname_ext;
|
|
3684 Bytecount fnamelen;
|
|
3685 Charcount len = qxeDragQueryFile ((HDROP) wParam, i, NULL, 0);
|
442
|
3686 /* The URLs that we make here aren't correct according to section
|
|
3687 * 3.10 of rfc1738 because they're missing the //<host>/ part and
|
|
3688 * because they may contain reserved characters. But that's OK -
|
|
3689 * they just need to be good enough to keep dragdrop.el happy. */
|
851
|
3690 fname_ext = (Extbyte *) ALLOCA ((len + 1) * XETCHAR_SIZE);
|
771
|
3691 qxeDragQueryFile ((HDROP) wParam, i, fname_ext, len + 1);
|
|
3692
|
|
3693 TO_INTERNAL_FORMAT (DATA, (fname_ext, len * XETCHAR_SIZE),
|
|
3694 ALLOCA, (fname, fnamelen),
|
|
3695 Qmswindows_tstr);
|
442
|
3696
|
|
3697 /* May be a shell link aka "shortcut" - replace fname if so */
|
771
|
3698 #if !defined (NO_CYGWIN_COM_SUPPORT)
|
|
3699 if (!qxestrcasecmp_c (fname + fnamelen - 4, ".LNK"))
|
442
|
3700 {
|
771
|
3701 /* ####
|
|
3702
|
|
3703 Note the following in the docs:
|
|
3704
|
|
3705 Note: The IShellLink interface has an ANSI version
|
|
3706 (IShellLinkA) and a Unicode version (IShellLinkW). The
|
|
3707 version that will be used depends on whether you compile
|
|
3708 for ANSI or Unicode. However, Microsoft® Windows 95 and
|
|
3709 Microsoft® Windows 98 only support IShellLinkA.
|
|
3710
|
|
3711 We haven't yet implemented COM support in the
|
|
3712 Unicode-splitting library. I don't quite understand how
|
|
3713 COM works yet, but it looks like what's happening is
|
|
3714 that the ShellLink class implements both the IShellLinkA
|
|
3715 and IShellLinkW interfaces. To make this work at
|
|
3716 run-time, we have to do something like this:
|
|
3717
|
|
3718 -- define a new interface qxeIShellLink that uses
|
|
3719 Extbyte * instead of LPSTR or LPWSTR. (not totally
|
|
3720 necessary since Extbyte * == LPSTR).
|
|
3721
|
|
3722 -- define a new class qxeShellLink that implements
|
|
3723 qxeIShellLink. the methods on this class need to create
|
|
3724 a shadow ShellLink object to do all the real work, and
|
|
3725 call the corresponding function from either the
|
|
3726 IShellLinkA or IShellLinkW interfaces on this object,
|
|
3727 depending on whether XEUNICODE_P is defined.
|
|
3728
|
|
3729 -- with appropriate preprocessor magic, of course, we
|
|
3730 could make things appear transparent; but we've decided
|
|
3731 not to do preprocessor magic for the moment.
|
|
3732 */
|
|
3733
|
|
3734 /* #### Not Unicode-split for the moment; we have to do it
|
|
3735 ourselves. */
|
|
3736 if (XEUNICODE_P)
|
442
|
3737 {
|
771
|
3738 IShellLinkW *psl;
|
|
3739
|
|
3740 if (CoCreateInstance (
|
|
3741 XECOMID (CLSID_ShellLink),
|
|
3742 NULL,
|
|
3743 CLSCTX_INPROC_SERVER,
|
|
3744 XECOMID (IID_IShellLinkW),
|
|
3745 (void **) &psl) == S_OK)
|
442
|
3746 {
|
771
|
3747 IPersistFile *ppf;
|
|
3748
|
|
3749 if (XECOMCALL2 (psl, QueryInterface,
|
|
3750 XECOMID (IID_IPersistFile),
|
|
3751 (void **) &ppf) ==
|
|
3752 S_OK)
|
442
|
3753 {
|
771
|
3754 Extbyte *fname_unicode;
|
|
3755 WIN32_FIND_DATAW wfd;
|
|
3756 LPWSTR resolved =
|
|
3757 alloca_array (WCHAR, PATH_MAX + 1);
|
|
3758
|
|
3759 TO_EXTERNAL_FORMAT (DATA, (fname, fnamelen),
|
|
3760 C_STRING_ALLOCA,
|
|
3761 fname_unicode,
|
|
3762 Qmswindows_unicode);
|
|
3763
|
|
3764 if (XECOMCALL2 (ppf, Load,
|
|
3765 (LPWSTR) fname_unicode,
|
|
3766 STGM_READ) == S_OK &&
|
|
3767 /* #### YUCK! Docs read
|
|
3768
|
|
3769 cchMaxPath
|
|
3770
|
|
3771 Maximum number of bytes to copy to the buffer pointed to by the
|
|
3772 pszFile parameter.
|
|
3773
|
|
3774 But "cch" means "count of characters", not bytes. I'll assume the doc
|
|
3775 writers messed up and the programmer was correct. Also, this approach
|
|
3776 is safe even if it's actually the other way around. */
|
|
3777 #ifdef CYGWIN_HEADERS /* Another Cygwin prototype error */
|
|
3778 XECOMCALL4 (psl, GetPath, (LPSTR) resolved,
|
|
3779 PATH_MAX, &wfd, 0)
|
|
3780 #else
|
|
3781 XECOMCALL4 (psl, GetPath, resolved,
|
|
3782 PATH_MAX, &wfd, 0)
|
|
3783 #endif
|
|
3784 == S_OK)
|
|
3785 TO_INTERNAL_FORMAT (C_STRING, resolved,
|
|
3786 ALLOCA, (fname, fnamelen),
|
|
3787 Qmswindows_tstr);
|
|
3788
|
|
3789 XECOMCALL0 (ppf, Release);
|
442
|
3790 }
|
|
3791
|
771
|
3792 XECOMCALL0 (psl, Release);
|
442
|
3793 }
|
771
|
3794 }
|
|
3795 else
|
|
3796 {
|
|
3797 IShellLinkA *psl;
|
|
3798
|
|
3799 if (CoCreateInstance (
|
|
3800 XECOMID (CLSID_ShellLink),
|
|
3801 NULL,
|
|
3802 CLSCTX_INPROC_SERVER,
|
|
3803 XECOMID (IID_IShellLinkA),
|
|
3804 (void **) &psl) == S_OK)
|
|
3805 {
|
|
3806 IPersistFile *ppf;
|
|
3807
|
|
3808 if (XECOMCALL2 (psl, QueryInterface,
|
|
3809 XECOMID (IID_IPersistFile),
|
|
3810 (void **) &ppf) ==
|
|
3811 S_OK)
|
|
3812 {
|
|
3813 Extbyte *fname_unicode;
|
|
3814 WIN32_FIND_DATAA wfd;
|
|
3815 LPSTR resolved =
|
|
3816 alloca_array (CHAR, PATH_MAX + 1);
|
|
3817
|
|
3818 /* Always Unicode. Not obvious from the
|
|
3819 IPersistFile documentation, but look under
|
|
3820 "Shell Link" for example code. */
|
|
3821 TO_EXTERNAL_FORMAT (DATA, (fname, fnamelen),
|
|
3822 C_STRING_ALLOCA,
|
|
3823 fname_unicode,
|
|
3824 Qmswindows_unicode);
|
|
3825
|
|
3826 if (XECOMCALL2 (ppf, Load,
|
|
3827 (LPWSTR) fname_unicode,
|
|
3828 STGM_READ) == S_OK
|
|
3829 && XECOMCALL4 (psl, GetPath, resolved,
|
|
3830 PATH_MAX, &wfd, 0) == S_OK)
|
|
3831 TO_INTERNAL_FORMAT (C_STRING, resolved,
|
|
3832 ALLOCA, (fname, fnamelen),
|
|
3833 Qmswindows_tstr);
|
|
3834
|
|
3835 XECOMCALL0 (ppf, Release);
|
|
3836 }
|
|
3837
|
|
3838 XECOMCALL0 (psl, Release);
|
|
3839 }
|
442
|
3840 }
|
|
3841 }
|
771
|
3842 #endif /* !defined (NO_CYGWIN_COM_SUPPORT) */
|
|
3843 {
|
|
3844 fname = urlify_filename (fname);
|
|
3845 l_item = build_intstring (fname);
|
|
3846 xfree (fname);
|
|
3847 l_dndlist = Fcons (l_item, l_dndlist);
|
|
3848 }
|
442
|
3849 }
|
771
|
3850
|
442
|
3851 DragFinish ((HDROP) wParam);
|
|
3852
|
1204
|
3853 SET_EVENT_MISC_USER_OBJECT (event,
|
964
|
3854 Fcons (Qdragdrop_URL, l_dndlist));
|
442
|
3855 mswindows_enqueue_dispatch_event (emacs_event);
|
|
3856 UNGCPRO;
|
|
3857 }
|
|
3858 break;
|
771
|
3859 #endif /* HAVE_DRAGNDROP */
|
|
3860
|
|
3861 #ifdef MULE
|
|
3862 case WM_IME_CHAR:
|
|
3863
|
|
3864 case WM_IME_STARTCOMPOSITION:
|
|
3865 mswindows_start_ime_composition (XFRAME (mswindows_find_frame (hwnd)));
|
|
3866 goto defproc;
|
|
3867
|
|
3868 case WM_IME_COMPOSITION:
|
|
3869 if (lParam & GCS_RESULTSTR)
|
|
3870 {
|
|
3871 HIMC imc = ImmGetContext (hwnd);
|
|
3872 Extbyte *result;
|
|
3873 Bytecount len;
|
867
|
3874 Ibyte *resultint, *endptr;
|
771
|
3875 Bytecount lenint;
|
|
3876 int speccount;
|
|
3877
|
|
3878 if (!imc)
|
|
3879 break;
|
|
3880
|
|
3881 /* See WM_KEYDOWN above. */
|
|
3882 speccount = begin_dont_check_for_quit ();
|
|
3883
|
|
3884 /* Sizes always in bytes, even for unicode.
|
|
3885 ImmGetCompositionStringW is supported even on Windows 9x, and
|
|
3886 allows us to handle multiple languages. */
|
|
3887 len = ImmGetCompositionStringW (imc, GCS_RESULTSTR, NULL, 0);
|
|
3888 result = alloca_array (Extbyte, len);
|
|
3889 ImmGetCompositionStringW (imc, GCS_RESULTSTR, (WCHAR *) result, len);
|
|
3890 ImmReleaseContext (hwnd, imc);
|
|
3891
|
|
3892 TO_INTERNAL_FORMAT (DATA, (result, len),
|
|
3893 ALLOCA, (resultint, lenint),
|
|
3894 Qmswindows_tstr);
|
|
3895
|
|
3896 endptr = resultint + lenint;
|
|
3897
|
|
3898 while (resultint < endptr)
|
|
3899 {
|
867
|
3900 Ichar ch = itext_ichar (resultint);
|
771
|
3901 if (ch == ' ')
|
|
3902 mswindows_enqueue_keypress_event (hwnd, QKspace, 0);
|
|
3903 else
|
|
3904 mswindows_enqueue_keypress_event (hwnd, make_char (ch), 0);
|
867
|
3905 INC_IBYTEPTR (resultint);
|
771
|
3906 }
|
|
3907
|
|
3908 unbind_to (speccount);
|
|
3909 }
|
|
3910 goto defproc;
|
|
3911 #endif /* MULE */
|
442
|
3912
|
|
3913 defproc:
|
|
3914 default:
|
771
|
3915 return qxeDefWindowProc (hwnd, message_, wParam, lParam);
|
428
|
3916 }
|
|
3917 return (0);
|
|
3918 }
|
|
3919
|
|
3920
|
|
3921 /************************************************************************/
|
|
3922 /* keyboard, mouse & other helpers for the windows procedure */
|
|
3923 /************************************************************************/
|
|
3924 static void
|
|
3925 mswindows_set_chord_timer (HWND hwnd)
|
|
3926 {
|
|
3927 int interval;
|
|
3928
|
|
3929 /* We get one third half system double click threshold */
|
|
3930 if (mswindows_mouse_button_tolerance <= 0)
|
|
3931 interval = GetDoubleClickTime () / 3;
|
|
3932 else
|
|
3933 interval = mswindows_mouse_button_tolerance;
|
|
3934
|
|
3935 SetTimer (hwnd, BUTTON_2_TIMER_ID, interval, 0);
|
|
3936 }
|
|
3937
|
|
3938 static int
|
|
3939 mswindows_button2_near_enough (POINTS p1, POINTS p2)
|
|
3940 {
|
|
3941 int dx, dy;
|
|
3942 if (mswindows_mouse_button_max_skew_x <= 0)
|
|
3943 dx = GetSystemMetrics (SM_CXDOUBLECLK) / 2;
|
|
3944 else
|
|
3945 dx = mswindows_mouse_button_max_skew_x;
|
|
3946
|
|
3947 if (mswindows_mouse_button_max_skew_y <= 0)
|
|
3948 dy = GetSystemMetrics (SM_CYDOUBLECLK) / 2;
|
|
3949 else
|
|
3950 dy = mswindows_mouse_button_max_skew_y;
|
|
3951
|
|
3952 return abs (p1.x - p2.x) < dx && abs (p1.y- p2.y)< dy;
|
|
3953 }
|
|
3954
|
|
3955 static int
|
|
3956 mswindows_current_layout_has_AltGr (void)
|
|
3957 {
|
|
3958 /* This simple caching mechanism saves 10% of CPU
|
|
3959 time when a key typed at autorepeat rate of 30 cps! */
|
|
3960 static HKL last_hkl = 0;
|
|
3961 static int last_hkl_has_AltGr;
|
771
|
3962 HKL current_hkl = GetKeyboardLayout (0);
|
|
3963
|
428
|
3964 if (current_hkl != last_hkl)
|
|
3965 {
|
647
|
3966 int c;
|
428
|
3967 last_hkl_has_AltGr = 0;
|
|
3968 /* In this loop, we query whether a character requires
|
|
3969 AltGr to be down to generate it. If at least such one
|
|
3970 found, this means that the layout does regard AltGr */
|
647
|
3971 for (c = ' '; c <= 255 && !last_hkl_has_AltGr; ++c)
|
|
3972 /* #### This is not really such a good check. What about under
|
|
3973 CJK locales? It may not matter there, though. We always
|
|
3974 call VkKeyScanA so that we check the locale-specific characters
|
|
3975 in non-Latin-1 locales, instead of just the Latin-1 characters. */
|
|
3976 if (HIBYTE (VkKeyScanA ((char) c)) == 6)
|
428
|
3977 last_hkl_has_AltGr = 1;
|
|
3978 last_hkl = current_hkl;
|
|
3979 }
|
|
3980 return last_hkl_has_AltGr;
|
|
3981 }
|
|
3982
|
|
3983
|
|
3984 /* Returns the state of the modifier keys in the format expected by the
|
|
3985 * Lisp_Event key_data, button_data and motion_data modifiers member */
|
442
|
3986 static int
|
771
|
3987 mswindows_modifier_state (BYTE *keymap, DWORD fwKeys, int has_AltGr)
|
428
|
3988 {
|
|
3989 int mods = 0;
|
442
|
3990 int keys_is_real = 0;
|
|
3991 BYTE keymap2[256];
|
|
3992
|
|
3993 if (fwKeys == (DWORD) -1)
|
|
3994 fwKeys = mswindows_last_mouse_button_state;
|
|
3995 else
|
|
3996 {
|
|
3997 keys_is_real = 1;
|
|
3998 mswindows_last_mouse_button_state = fwKeys;
|
|
3999 }
|
428
|
4000
|
|
4001 if (keymap == NULL)
|
|
4002 {
|
442
|
4003 keymap = keymap2;
|
428
|
4004 GetKeyboardState (keymap);
|
|
4005 has_AltGr = mswindows_current_layout_has_AltGr ();
|
|
4006 }
|
|
4007
|
442
|
4008 /* #### should look at fwKeys for MK_CONTROL. I don't understand how
|
|
4009 AltGr works. */
|
428
|
4010 if (has_AltGr && (keymap [VK_LCONTROL] & 0x80) && (keymap [VK_RMENU] & 0x80))
|
|
4011 {
|
442
|
4012 mods |= (keymap [VK_LMENU] & 0x80) ? XEMACS_MOD_META : 0;
|
|
4013 mods |= (keymap [VK_RCONTROL] & 0x80) ? XEMACS_MOD_CONTROL : 0;
|
428
|
4014 }
|
|
4015 else
|
|
4016 {
|
442
|
4017 mods |= (keymap [VK_MENU] & 0x80) ? XEMACS_MOD_META : 0;
|
|
4018 mods |= (keymap [VK_CONTROL] & 0x80) ? XEMACS_MOD_CONTROL : 0;
|
428
|
4019 }
|
|
4020
|
1111
|
4021 mods |= (keys_is_real ? (int) (fwKeys & MK_SHIFT) :
|
|
4022 (keymap [VK_SHIFT] & 0x80)) ? XEMACS_MOD_SHIFT : 0;
|
442
|
4023 mods |= fwKeys & MK_LBUTTON ? XEMACS_MOD_BUTTON1 : 0;
|
|
4024 mods |= fwKeys & MK_MBUTTON ? XEMACS_MOD_BUTTON2 : 0;
|
|
4025 mods |= fwKeys & MK_RBUTTON ? XEMACS_MOD_BUTTON3 : 0;
|
428
|
4026
|
|
4027 return mods;
|
|
4028 }
|
|
4029
|
|
4030 /*
|
|
4031 * Translate a mswindows virtual key to a keysym.
|
|
4032 * Only returns non-Qnil for keys that don't generate WM_CHAR messages
|
|
4033 * or whose ASCII codes (like space) xemacs doesn't like.
|
|
4034 */
|
|
4035 Lisp_Object mswindows_key_to_emacs_keysym (int mswindows_key, int mods,
|
|
4036 int extendedp)
|
|
4037 {
|
|
4038 if (extendedp) /* Keys not present on a 82 key keyboard */
|
|
4039 {
|
|
4040 switch (mswindows_key)
|
|
4041 {
|
442
|
4042 case VK_CANCEL: return KEYSYM ("pause");
|
428
|
4043 case VK_RETURN: return KEYSYM ("kp-enter");
|
|
4044 case VK_PRIOR: return KEYSYM ("prior");
|
|
4045 case VK_NEXT: return KEYSYM ("next");
|
|
4046 case VK_END: return KEYSYM ("end");
|
|
4047 case VK_HOME: return KEYSYM ("home");
|
|
4048 case VK_LEFT: return KEYSYM ("left");
|
|
4049 case VK_UP: return KEYSYM ("up");
|
|
4050 case VK_RIGHT: return KEYSYM ("right");
|
|
4051 case VK_DOWN: return KEYSYM ("down");
|
|
4052 case VK_INSERT: return KEYSYM ("insert");
|
|
4053 case VK_DELETE: return QKdelete;
|
442
|
4054 #if 0 /* FSF Emacs allows these to return configurable syms/mods */
|
|
4055 case VK_LWIN return KEYSYM ("");
|
|
4056 case VK_RWIN return KEYSYM ("");
|
|
4057 #endif
|
|
4058 case VK_APPS: return KEYSYM ("menu");
|
428
|
4059 }
|
|
4060 }
|
|
4061 else
|
|
4062 {
|
|
4063 switch (mswindows_key)
|
|
4064 {
|
771
|
4065
|
|
4066 #if 0
|
|
4067 VK_LBUTTON:
|
|
4068 VK_RBUTTON:
|
|
4069 VK_CANCEL:
|
|
4070 VK_MBUTTON:
|
|
4071 VK_XBUTTON1:
|
|
4072 VK_XBUTTON2:
|
|
4073 #endif /* 0 */
|
|
4074
|
428
|
4075 case VK_BACK: return QKbackspace;
|
|
4076 case VK_TAB: return QKtab;
|
771
|
4077 /* #### Officially 0A (and 0B too) are "reserved". */
|
428
|
4078 case '\n': return QKlinefeed;
|
|
4079 case VK_CLEAR: return KEYSYM ("clear");
|
|
4080 case VK_RETURN: return QKreturn;
|
771
|
4081
|
|
4082 #if 0
|
|
4083 VK_SHIFT: "shift"
|
|
4084 VK_CONTROL: "control"
|
|
4085 VK_MENU: "alt"
|
|
4086 #endif /* 0 */
|
|
4087
|
442
|
4088 case VK_PAUSE: return KEYSYM ("pause");
|
771
|
4089
|
|
4090 #if 0
|
|
4091 VK_CAPITAL: "caps-lock"
|
|
4092 VK_KANA: IME Kana mode
|
|
4093 VK_HANGUEL: IME Hanguel mode (maintained for compatibility; use VK_HANGUL)
|
|
4094 VK_HANGUL: IME Hangul mode
|
|
4095 VK_JUNJA: IME Junja mode
|
|
4096 VK_FINAL: IME final mode
|
|
4097 VK_HANJA: IME Hanja mode
|
|
4098 VK_KANJI: IME Kanji mode
|
|
4099 #endif /* 0 */
|
|
4100
|
428
|
4101 case VK_ESCAPE: return QKescape;
|
771
|
4102
|
|
4103 #if 0
|
|
4104 VK_CONVERT: IME convert
|
|
4105 VK_NONCONVERT: IME nonconvert
|
|
4106 VK_ACCEPT: IME accept
|
|
4107 VK_MODECHANGE: IME mode change request
|
|
4108 #endif /* 0 */
|
|
4109
|
428
|
4110 case VK_SPACE: return QKspace;
|
|
4111 case VK_PRIOR: return KEYSYM ("kp-prior");
|
|
4112 case VK_NEXT: return KEYSYM ("kp-next");
|
|
4113 case VK_END: return KEYSYM ("kp-end");
|
|
4114 case VK_HOME: return KEYSYM ("kp-home");
|
|
4115 case VK_LEFT: return KEYSYM ("kp-left");
|
|
4116 case VK_UP: return KEYSYM ("kp-up");
|
|
4117 case VK_RIGHT: return KEYSYM ("kp-right");
|
|
4118 case VK_DOWN: return KEYSYM ("kp-down");
|
|
4119 case VK_SELECT: return KEYSYM ("select");
|
|
4120 case VK_PRINT: return KEYSYM ("print");
|
|
4121 case VK_EXECUTE: return KEYSYM ("execute");
|
|
4122 case VK_SNAPSHOT: return KEYSYM ("print");
|
|
4123 case VK_INSERT: return KEYSYM ("kp-insert");
|
|
4124 case VK_DELETE: return KEYSYM ("kp-delete");
|
|
4125 case VK_HELP: return KEYSYM ("help");
|
771
|
4126 #if 0
|
|
4127 '0' through '9': numeric keys
|
|
4128 'A' through 'Z': alphabetic keys
|
|
4129 VK_LWIN: "lwin"
|
|
4130 VK_RWIN: "rwin"
|
|
4131 VK_APPS: "apps"
|
|
4132 VK_SLEEP: "sleep"
|
|
4133 #endif /* 0 */
|
428
|
4134 case VK_NUMPAD0: return KEYSYM ("kp-0");
|
|
4135 case VK_NUMPAD1: return KEYSYM ("kp-1");
|
|
4136 case VK_NUMPAD2: return KEYSYM ("kp-2");
|
|
4137 case VK_NUMPAD3: return KEYSYM ("kp-3");
|
|
4138 case VK_NUMPAD4: return KEYSYM ("kp-4");
|
|
4139 case VK_NUMPAD5: return KEYSYM ("kp-5");
|
|
4140 case VK_NUMPAD6: return KEYSYM ("kp-6");
|
|
4141 case VK_NUMPAD7: return KEYSYM ("kp-7");
|
|
4142 case VK_NUMPAD8: return KEYSYM ("kp-8");
|
|
4143 case VK_NUMPAD9: return KEYSYM ("kp-9");
|
|
4144 case VK_MULTIPLY: return KEYSYM ("kp-multiply");
|
|
4145 case VK_ADD: return KEYSYM ("kp-add");
|
|
4146 case VK_SEPARATOR: return KEYSYM ("kp-separator");
|
|
4147 case VK_SUBTRACT: return KEYSYM ("kp-subtract");
|
|
4148 case VK_DECIMAL: return KEYSYM ("kp-decimal");
|
|
4149 case VK_DIVIDE: return KEYSYM ("kp-divide");
|
|
4150 case VK_F1: return KEYSYM ("f1");
|
|
4151 case VK_F2: return KEYSYM ("f2");
|
|
4152 case VK_F3: return KEYSYM ("f3");
|
|
4153 case VK_F4: return KEYSYM ("f4");
|
|
4154 case VK_F5: return KEYSYM ("f5");
|
|
4155 case VK_F6: return KEYSYM ("f6");
|
|
4156 case VK_F7: return KEYSYM ("f7");
|
|
4157 case VK_F8: return KEYSYM ("f8");
|
|
4158 case VK_F9: return KEYSYM ("f9");
|
|
4159 case VK_F10: return KEYSYM ("f10");
|
|
4160 case VK_F11: return KEYSYM ("f11");
|
|
4161 case VK_F12: return KEYSYM ("f12");
|
|
4162 case VK_F13: return KEYSYM ("f13");
|
|
4163 case VK_F14: return KEYSYM ("f14");
|
|
4164 case VK_F15: return KEYSYM ("f15");
|
|
4165 case VK_F16: return KEYSYM ("f16");
|
|
4166 case VK_F17: return KEYSYM ("f17");
|
|
4167 case VK_F18: return KEYSYM ("f18");
|
|
4168 case VK_F19: return KEYSYM ("f19");
|
|
4169 case VK_F20: return KEYSYM ("f20");
|
|
4170 case VK_F21: return KEYSYM ("f21");
|
|
4171 case VK_F22: return KEYSYM ("f22");
|
|
4172 case VK_F23: return KEYSYM ("f23");
|
|
4173 case VK_F24: return KEYSYM ("f24");
|
771
|
4174
|
|
4175 #if 0
|
|
4176 VK_NUMLOCK: 90 NUM LOCK key
|
|
4177 VK_SCROLL: 91 SCROLL LOCK key
|
|
4178 92~96 OEM specific;
|
|
4179 VK_LSHIFT:
|
|
4180 VK_RSHIFT:
|
|
4181 VK_LCONTROL:
|
|
4182 VK_RCONTROL:
|
|
4183 VK_LMENU:
|
|
4184 VK_RMENU:
|
|
4185
|
|
4186 #ifdef VK_BROWSER_BACK /* Windows 2000 only */
|
|
4187 VK_BROWSER_BACK: Browser Back key
|
|
4188 VK_BROWSER_FORWARD: Browser Forward key
|
|
4189 VK_BROWSER_REFRESH: Browser Refresh key
|
|
4190 VK_BROWSER_STOP: Browser Stop key
|
|
4191 VK_BROWSER_SEARCH: Browser Search key
|
|
4192 VK_BROWSER_FAVORITES: Browser Favorites key
|
|
4193 VK_BROWSER_HOME: Browser Start and Home key
|
|
4194 VK_VOLUME_MUTE: Volume Mute key
|
|
4195 VK_VOLUME_DOWN: Volume Down key
|
|
4196 VK_VOLUME_UP: Volume Up key
|
|
4197 VK_MEDIA_NEXT_TRACK: Next Track key
|
|
4198 VK_MEDIA_PREV_TRACK: Previous Track key
|
|
4199 VK_MEDIA_STOP: Stop Media key
|
|
4200 VK_MEDIA_PLAY_PAUSE: Play/Pause Media key
|
|
4201 VK_LAUNCH_MAIL: Start Mail key
|
|
4202 VK_LAUNCH_MEDIA_SELECT: Select Media key
|
|
4203 VK_LAUNCH_APP1: Start Application 1 key
|
|
4204 VK_LAUNCH_APP2: Start Application 2 key
|
|
4205 B8-B9 Reserved;
|
|
4206 VK_OEM_1: For the US standard keyboard, the ';:' key
|
|
4207 VK_OEM_PLUS: For any country/region, the '+' key
|
|
4208 VK_OEM_COMMA: For any country/region, the ',' key
|
|
4209 VK_OEM_MINUS: For any country/region, the '-' key
|
|
4210 VK_OEM_PERIOD: For any country/region, the '.' key
|
|
4211 VK_OEM_2: For the US standard keyboard, the '/?' key
|
|
4212 VK_OEM_3: For the US standard keyboard, the '`~' key
|
|
4213 C1~D7 Reserved;
|
|
4214 D8~DA Unassigned;
|
|
4215 VK_OEM_4: For the US standard keyboard, the '[{' key
|
|
4216 VK_OEM_5: For the US standard keyboard, the '\|' key
|
|
4217 VK_OEM_6: For the US standard keyboard, the ']}' key
|
|
4218 VK_OEM_7: For the US standard keyboard, the 'single-quote/double-quote' key
|
|
4219 VK_OEM_8:
|
|
4220 E0 Reserved;
|
|
4221 E1 OEM specific;
|
|
4222 VK_OEM_102: Either the angle bracket key or the backslash key on the RT 102-key keyboard
|
|
4223 E3~E4 OEM specific;
|
|
4224 #endif /* VK_BROWSER_BACK */
|
|
4225 VK_PROCESSKEY: E5 Windows 95/98, Windows NT 4.0, Windows 2000: IME PROCESS key
|
|
4226 E6 OEM specific;
|
|
4227 VK_PACKET: Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP
|
|
4228 E8 Unassigned;
|
|
4229 E9~F5 OEM specific;
|
|
4230 VK_ATTN: Attn key
|
|
4231 VK_CRSEL: CrSel key
|
|
4232 VK_EXSEL: ExSel key
|
|
4233 VK_EREOF: Erase EOF key
|
|
4234 VK_PLAY: Play key
|
|
4235 VK_ZOOM: Zoom key
|
|
4236 VK_NONAME: Reserved for future use
|
|
4237 VK_PA1: PA1 key
|
|
4238 VK_OEM_CLEAR: Clear key
|
|
4239 #endif /* 0 */
|
|
4240
|
428
|
4241 }
|
|
4242 }
|
|
4243 return Qnil;
|
|
4244 }
|
|
4245
|
|
4246 /*
|
|
4247 * Find the console that matches the supplied mswindows window handle
|
|
4248 */
|
|
4249 Lisp_Object
|
|
4250 mswindows_find_console (HWND hwnd)
|
|
4251 {
|
|
4252 /* We only support one console */
|
|
4253 return XCAR (Vconsole_list);
|
|
4254 }
|
|
4255
|
|
4256 /*
|
|
4257 * Find the frame that matches the supplied mswindows window handle
|
|
4258 */
|
546
|
4259 Lisp_Object
|
428
|
4260 mswindows_find_frame (HWND hwnd)
|
|
4261 {
|
771
|
4262 LONG l = qxeGetWindowLong (hwnd, XWL_FRAMEOBJ);
|
428
|
4263 Lisp_Object f;
|
|
4264 if (l == 0)
|
|
4265 {
|
|
4266 /* We are in progress of frame creation. Return the frame
|
|
4267 being created, as it still not remembered in the window
|
|
4268 extra storage. */
|
|
4269 assert (!NILP (Vmswindows_frame_being_created));
|
|
4270 return Vmswindows_frame_being_created;
|
|
4271 }
|
826
|
4272 f = VOID_TO_LISP ((void *) l);
|
428
|
4273 return f;
|
|
4274 }
|
|
4275
|
|
4276
|
|
4277 /************************************************************************/
|
|
4278 /* methods */
|
|
4279 /************************************************************************/
|
|
4280
|
|
4281 static int
|
|
4282 emacs_mswindows_add_timeout (EMACS_TIME thyme)
|
|
4283 {
|
|
4284 int milliseconds;
|
|
4285 EMACS_TIME current_time;
|
|
4286 EMACS_GET_TIME (current_time);
|
|
4287 EMACS_SUB_TIME (thyme, thyme, current_time);
|
|
4288 milliseconds = EMACS_SECS (thyme) * 1000 +
|
|
4289 (EMACS_USECS (thyme) + 500) / 1000;
|
|
4290 if (milliseconds < 1)
|
|
4291 milliseconds = 1;
|
|
4292 ++mswindows_pending_timers_count;
|
|
4293 return SetTimer (NULL, 0, milliseconds,
|
|
4294 (TIMERPROC) mswindows_wm_timer_callback);
|
|
4295 }
|
|
4296
|
1204
|
4297 static int
|
|
4298 remove_timeout_mapper (Lisp_Object ev, void *data)
|
|
4299 {
|
|
4300 if (XEVENT_TYPE (ev) == timeout_event)
|
|
4301 {
|
|
4302 if ((int) data == XEVENT_TIMEOUT_INTERVAL_ID (ev))
|
|
4303 return 1;
|
|
4304 }
|
|
4305
|
|
4306 return 0;
|
|
4307 }
|
|
4308
|
428
|
4309 static void
|
|
4310 emacs_mswindows_remove_timeout (int id)
|
|
4311 {
|
|
4312 if (KillTimer (NULL, id))
|
|
4313 --mswindows_pending_timers_count;
|
|
4314
|
|
4315 /* If there is a dispatch event generated by this
|
|
4316 timeout in the queue, we have to remove it too. */
|
1204
|
4317 map_event_chain_remove (remove_timeout_mapper,
|
|
4318 &mswindows_s_dispatch_event_queue,
|
|
4319 &mswindows_s_dispatch_event_queue_tail,
|
|
4320 (void *) id, MECR_DEALLOCATE_EVENT);
|
428
|
4321 }
|
|
4322
|
|
4323 /* If `user_p' is false, then return whether there are any win32, timeout,
|
|
4324 * or subprocess events pending (that is, whether
|
|
4325 * emacs_mswindows_next_event() would return immediately without blocking).
|
|
4326 *
|
|
4327 * if `user_p' is true, then return whether there are any *user generated*
|
|
4328 * events available (that is, whether there are keyboard or mouse-click
|
|
4329 * events ready to be read). This also implies that
|
|
4330 * emacs_mswindows_next_event() would not block.
|
|
4331 */
|
|
4332 static int
|
1268
|
4333 emacs_mswindows_event_pending_p (int how_many)
|
428
|
4334 {
|
1268
|
4335 if (!how_many)
|
|
4336 {
|
|
4337 mswindows_need_event (0);
|
|
4338 return (!NILP (dispatch_event_queue)
|
|
4339 || !NILP (mswindows_s_dispatch_event_queue));
|
|
4340 }
|
|
4341 else
|
|
4342 {
|
|
4343 Lisp_Object event;
|
|
4344 int count = 0;
|
|
4345
|
|
4346 EVENT_CHAIN_LOOP (event, dispatch_event_queue)
|
|
4347 count++;
|
|
4348
|
|
4349 if (count >= how_many)
|
|
4350 return 1;
|
|
4351
|
|
4352 emacs_mswindows_drain_queue ();
|
|
4353
|
|
4354 EVENT_CHAIN_LOOP (event, dispatch_event_queue)
|
|
4355 count++;
|
|
4356
|
|
4357 return count >= how_many;
|
|
4358 }
|
428
|
4359 }
|
|
4360
|
|
4361 /*
|
|
4362 * Return the next event
|
|
4363 */
|
|
4364 static void
|
440
|
4365 emacs_mswindows_next_event (Lisp_Event *emacs_event)
|
428
|
4366 {
|
|
4367 Lisp_Object event, event2;
|
|
4368
|
|
4369 mswindows_need_event (1);
|
|
4370
|
|
4371 event = mswindows_dequeue_dispatch_event ();
|
793
|
4372 event2 = wrap_event (emacs_event);
|
428
|
4373 Fcopy_event (event, event2);
|
|
4374 Fdeallocate_event (event);
|
|
4375 }
|
|
4376
|
788
|
4377 static void
|
|
4378 emacs_mswindows_format_magic_event (Lisp_Event *emacs_event,
|
|
4379 Lisp_Object pstream)
|
|
4380 {
|
826
|
4381 #define FROB(msg) case msg: write_c_string (pstream, "type=" #msg); break
|
788
|
4382
|
1204
|
4383 switch (EVENT_MAGIC_MSWINDOWS_EVENT (emacs_event))
|
788
|
4384 {
|
|
4385 FROB (XM_BUMPQUEUE);
|
|
4386 FROB (WM_PAINT);
|
|
4387 FROB (WM_SETFOCUS);
|
|
4388 FROB (WM_KILLFOCUS);
|
|
4389 FROB (XM_MAPFRAME);
|
|
4390 FROB (XM_UNMAPFRAME);
|
|
4391
|
|
4392 default: abort ();
|
|
4393 }
|
|
4394 #undef FROB
|
|
4395
|
|
4396 if (!NILP (EVENT_CHANNEL (emacs_event)))
|
|
4397 {
|
826
|
4398 write_c_string (pstream, " ");
|
788
|
4399 print_internal (EVENT_CHANNEL (emacs_event), pstream, 1);
|
|
4400 }
|
|
4401 }
|
|
4402
|
|
4403 static int
|
|
4404 emacs_mswindows_compare_magic_event (Lisp_Event *e1, Lisp_Event *e2)
|
|
4405 {
|
1204
|
4406 return (EVENT_MAGIC_MSWINDOWS_EVENT (e1) ==
|
|
4407 EVENT_MAGIC_MSWINDOWS_EVENT (e2));
|
788
|
4408 }
|
|
4409
|
|
4410 static Hashcode
|
|
4411 emacs_mswindows_hash_magic_event (Lisp_Event *e)
|
|
4412 {
|
1204
|
4413 return (EVENT_MAGIC_MSWINDOWS_EVENT (e));
|
788
|
4414 }
|
|
4415
|
428
|
4416 /*
|
|
4417 * Handle a magic event off the dispatch queue.
|
|
4418 */
|
|
4419 static void
|
440
|
4420 emacs_mswindows_handle_magic_event (Lisp_Event *emacs_event)
|
428
|
4421 {
|
1204
|
4422 switch (EVENT_MAGIC_MSWINDOWS_EVENT (emacs_event))
|
428
|
4423 {
|
|
4424 case XM_BUMPQUEUE:
|
|
4425 break;
|
|
4426
|
442
|
4427 case WM_PAINT:
|
|
4428 {
|
|
4429 struct frame *f = XFRAME (EVENT_CHANNEL (emacs_event));
|
|
4430 mswindows_handle_paint (f);
|
|
4431 (FRAME_MSWINDOWS_DATA (f))->paint_pending = 0;
|
|
4432 }
|
|
4433 break;
|
|
4434
|
428
|
4435 case WM_SETFOCUS:
|
|
4436 case WM_KILLFOCUS:
|
|
4437 {
|
|
4438 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
|
|
4439 struct frame *f = XFRAME (frame);
|
1204
|
4440 int in_p = (EVENT_MAGIC_MSWINDOWS_EVENT (emacs_event)
|
964
|
4441 == WM_SETFOCUS);
|
428
|
4442 Lisp_Object conser;
|
442
|
4443 struct gcpro gcpro1;
|
|
4444
|
|
4445 /* On focus change, clear all memory of sticky modifiers
|
|
4446 to avoid non-intuitive behavior. */
|
|
4447 clear_sticky_modifiers ();
|
428
|
4448
|
|
4449 conser = Fcons (frame, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil));
|
442
|
4450 GCPRO1 (conser);
|
428
|
4451 emacs_handle_focus_change_preliminary (conser);
|
|
4452 /* Under X the stuff up to here is done in the X event handler.
|
|
4453 I Don't know why */
|
|
4454 emacs_handle_focus_change_final (conser);
|
442
|
4455 UNGCPRO;
|
428
|
4456
|
|
4457 }
|
|
4458 break;
|
|
4459
|
|
4460 case XM_MAPFRAME:
|
|
4461 case XM_UNMAPFRAME:
|
|
4462 {
|
|
4463 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
|
1204
|
4464 va_run_hook_with_args (EVENT_MAGIC_MSWINDOWS_EVENT (emacs_event)
|
428
|
4465 == XM_MAPFRAME ?
|
|
4466 Qmap_frame_hook : Qunmap_frame_hook,
|
|
4467 1, frame);
|
|
4468 }
|
|
4469 break;
|
|
4470
|
|
4471 /* #### What about Enter & Leave */
|
|
4472 #if 0
|
|
4473 va_run_hook_with_args (in_p ? Qmouse_enter_frame_hook :
|
|
4474 Qmouse_leave_frame_hook, 1, frame);
|
|
4475 #endif
|
|
4476
|
|
4477 default:
|
|
4478 assert(0);
|
|
4479 }
|
|
4480 }
|
|
4481
|
853
|
4482 #ifndef CYGWIN
|
|
4483
|
428
|
4484 static HANDLE
|
440
|
4485 get_process_input_waitable (Lisp_Process *process)
|
428
|
4486 {
|
853
|
4487 Lisp_Object instr, outstr, errstr, p;
|
793
|
4488 p = wrap_process (process);
|
853
|
4489 get_process_streams (process, &instr, &outstr, &errstr);
|
428
|
4490 assert (!NILP (instr));
|
|
4491 return (network_connection_p (p)
|
|
4492 ? get_winsock_stream_waitable (XLSTREAM (instr))
|
|
4493 : get_ntpipe_input_stream_waitable (XLSTREAM (instr)));
|
|
4494 }
|
|
4495
|
853
|
4496 static HANDLE
|
|
4497 get_process_stderr_waitable (Lisp_Process *process)
|
|
4498 {
|
|
4499 Lisp_Object instr, outstr, errstr;
|
|
4500 get_process_streams (process, &instr, &outstr, &errstr);
|
|
4501 if (NILP (errstr))
|
|
4502 return INVALID_HANDLE_VALUE;
|
|
4503 return get_ntpipe_input_stream_waitable (XLSTREAM (errstr));
|
|
4504 }
|
|
4505
|
|
4506 #endif /* not CYGWIN */
|
|
4507
|
428
|
4508 static void
|
853
|
4509 emacs_mswindows_select_process (Lisp_Process *process, int doin, int doerr)
|
428
|
4510 {
|
853
|
4511 #ifdef CYGWIN
|
|
4512 int infd, errfd;
|
|
4513
|
|
4514 event_stream_unixoid_select_process (process, doin, doerr, &infd, &errfd);
|
|
4515 #else
|
|
4516 HANDLE hev = INVALID_HANDLE_VALUE;
|
|
4517 HANDLE herr = INVALID_HANDLE_VALUE;
|
|
4518
|
|
4519 if (doin)
|
|
4520 {
|
|
4521 hev = get_process_input_waitable (process);
|
|
4522 if (!add_waitable_handle (hev))
|
|
4523 {
|
|
4524 hev = INVALID_HANDLE_VALUE;
|
|
4525 goto err;
|
|
4526 }
|
|
4527 }
|
|
4528
|
|
4529 if (doerr)
|
|
4530 {
|
|
4531 herr = get_process_stderr_waitable (process);
|
|
4532 if (herr != INVALID_HANDLE_VALUE && !add_waitable_handle (herr))
|
|
4533 {
|
|
4534 herr = INVALID_HANDLE_VALUE;
|
|
4535 goto err;
|
|
4536 }
|
|
4537 }
|
|
4538
|
428
|
4539 {
|
853
|
4540 /* Also select on the process handle itself, so we can receive
|
|
4541 exit notifications. Only do this once, not each time this
|
|
4542 function is called (which can happen many times, e.g. if
|
|
4543 (set-process-filter proc t) is called and then a process filter
|
|
4544 is set again). It will be unselected in mswindows_need_event(). */
|
793
|
4545 Lisp_Object p = wrap_process (process);
|
|
4546
|
428
|
4547 if (!network_connection_p (p))
|
|
4548 {
|
853
|
4549 HANDLE hprocess = get_nt_process_handle_only_first_time (process);
|
|
4550 if (hprocess != INVALID_HANDLE_VALUE
|
|
4551 && !add_waitable_handle (hprocess))
|
|
4552 goto err;
|
428
|
4553 }
|
|
4554 }
|
853
|
4555
|
|
4556 return;
|
|
4557
|
|
4558 err:
|
|
4559 if (hev != INVALID_HANDLE_VALUE)
|
|
4560 remove_waitable_handle (hev);
|
|
4561 if (herr != INVALID_HANDLE_VALUE)
|
|
4562 remove_waitable_handle (herr);
|
|
4563 invalid_operation ("Too many active processes", wrap_process (process));
|
|
4564 #endif /* CYGWIN */
|
428
|
4565 }
|
|
4566
|
|
4567 static void
|
853
|
4568 emacs_mswindows_unselect_process (Lisp_Process *process, int doin, int doerr)
|
428
|
4569 {
|
853
|
4570 #ifdef CYGWIN
|
|
4571 int infd, errfd;
|
|
4572
|
|
4573 event_stream_unixoid_unselect_process (process, doin, doerr, &infd, &errfd);
|
|
4574 #else
|
|
4575 if (doin)
|
|
4576 {
|
|
4577 /* Process handle is removed in the event loop as soon
|
|
4578 as it is signaled, so don't bother here about it */
|
|
4579 HANDLE hev = get_process_input_waitable (process);
|
|
4580 remove_waitable_handle (hev);
|
|
4581 }
|
|
4582 if (doerr)
|
|
4583 {
|
|
4584 /* Process handle is removed in the event loop as soon
|
|
4585 as it is signaled, so don't bother here about it */
|
|
4586 HANDLE herr = get_process_stderr_waitable (process);
|
|
4587 if (herr != INVALID_HANDLE_VALUE)
|
|
4588 remove_waitable_handle (herr);
|
|
4589 }
|
|
4590 #endif /* CYGWIN */
|
428
|
4591 }
|
|
4592
|
|
4593 static void
|
|
4594 emacs_mswindows_select_console (struct console *con)
|
|
4595 {
|
853
|
4596 #ifdef CYGWIN
|
428
|
4597 if (CONSOLE_MSWINDOWS_P (con))
|
|
4598 return; /* mswindows consoles are automatically selected */
|
|
4599
|
|
4600 event_stream_unixoid_select_console (con);
|
1204
|
4601 #else
|
|
4602 #if 0
|
|
4603 /* This is an attempt to get `xemacs -batch -l dunnet' to work.
|
|
4604 Doesn't currently work and fucks other things up. */
|
|
4605 if (CONSOLE_STREAM_P (con) &&
|
|
4606 !UNBOUNDP (CONSOLE_STREAM_DATA (con)->instream))
|
|
4607 {
|
|
4608 HANDLE h =
|
|
4609 (HANDLE) _get_osfhandle (fileno (CONSOLE_STREAM_DATA (con)->in));
|
|
4610 if (PeekNamedPipe (h, 0, 0, 0, 0, 0))
|
|
4611 {
|
|
4612 Lisp_Object lstr = make_ntpipe_input_stream (h, 0);
|
|
4613 HANDLE hwait = get_ntpipe_input_stream_waitable (XLSTREAM (lstr));
|
|
4614
|
|
4615 if (!add_waitable_handle (hwait))
|
|
4616 invalid_operation ("Too many active processes",
|
|
4617 wrap_console (con));
|
|
4618 CONSOLE_STREAM_DATA (con)->instream = lstr;
|
|
4619 }
|
|
4620 else
|
|
4621 /* Unable to select on this stream */
|
|
4622 CONSOLE_STREAM_DATA (con)->instream = Qunbound;
|
|
4623 }
|
|
4624 #endif /* 0 */
|
428
|
4625 #endif
|
|
4626 }
|
|
4627
|
|
4628 static void
|
|
4629 emacs_mswindows_unselect_console (struct console *con)
|
|
4630 {
|
853
|
4631 #ifdef CYGWIN
|
428
|
4632 if (CONSOLE_MSWINDOWS_P (con))
|
|
4633 return; /* mswindows consoles are automatically selected */
|
|
4634
|
|
4635 event_stream_unixoid_unselect_console (con);
|
1204
|
4636 #else
|
|
4637 #if 0 /* see above */
|
|
4638 if (CONSOLE_STREAM_P (con) &&
|
|
4639 !UNBOUNDP (CONSOLE_STREAM_DATA (con)->instream))
|
428
|
4640 {
|
1204
|
4641 Lisp_Object instr = CONSOLE_STREAM_DATA (con)->instream;
|
|
4642 HANDLE hwait;
|
|
4643
|
|
4644 assert (!NILP (instr));
|
|
4645 hwait = get_ntpipe_input_stream_waitable (XLSTREAM (instr));
|
|
4646
|
|
4647 remove_waitable_handle (hwait);
|
428
|
4648 }
|
1204
|
4649 #endif /* 0 */
|
|
4650 #endif
|
428
|
4651 }
|
|
4652
|
853
|
4653 static void
|
|
4654 emacs_mswindows_create_io_streams (void *inhandle, void *outhandle,
|
|
4655 void *errhandle, Lisp_Object *instream,
|
|
4656 Lisp_Object *outstream,
|
|
4657 Lisp_Object *errstream,
|
|
4658 USID *in_usid,
|
|
4659 USID *err_usid,
|
|
4660 int flags)
|
428
|
4661 {
|
853
|
4662 #ifdef CYGWIN
|
|
4663 event_stream_unixoid_create_io_streams (inhandle, outhandle,
|
|
4664 errhandle, instream,
|
|
4665 outstream, errstream,
|
|
4666 in_usid, err_usid, flags);
|
|
4667 #else
|
428
|
4668 /* Handles for streams */
|
853
|
4669 HANDLE hin, hout, herr;
|
428
|
4670 /* fds. These just stored along with the streams, and are closed in
|
|
4671 delete stream pair method, because we need to handle fake unices
|
|
4672 here. */
|
853
|
4673 int fdi, fdo, fde;
|
|
4674
|
|
4675 /* Decode inhandle, outhandle, errhandle. Their meaning depends on
|
428
|
4676 the process implementation being used. */
|
|
4677 hin = (HANDLE) inhandle;
|
|
4678 hout = (HANDLE) outhandle;
|
853
|
4679 if (errhandle == (void *) -1)
|
|
4680 herr = INVALID_HANDLE_VALUE;
|
|
4681 else
|
|
4682 herr = (HANDLE) errhandle;
|
|
4683 fdi = fdo = fde = -1;
|
428
|
4684
|
|
4685 *instream = (hin == INVALID_HANDLE_VALUE
|
|
4686 ? Qnil
|
|
4687 : flags & STREAM_NETWORK_CONNECTION
|
853
|
4688 ? make_winsock_input_stream ((SOCKET) hin, fdi)
|
428
|
4689 : make_ntpipe_input_stream (hin, fdi));
|
|
4690
|
853
|
4691 *errstream = (herr == INVALID_HANDLE_VALUE
|
|
4692 ? Qnil
|
|
4693 : make_ntpipe_input_stream (herr, fde));
|
|
4694
|
428
|
4695 *outstream = (hout == INVALID_HANDLE_VALUE
|
|
4696 ? Qnil
|
|
4697 : flags & STREAM_NETWORK_CONNECTION
|
|
4698 ? make_winsock_output_stream ((SOCKET)hout, fdo)
|
|
4699 : make_ntpipe_output_stream (hout, fdo));
|
853
|
4700
|
|
4701 *in_usid =
|
|
4702 (NILP (*instream)
|
|
4703 ? USID_ERROR
|
|
4704 : flags & STREAM_NETWORK_CONNECTION
|
|
4705 ? HANDLE_TO_USID (get_winsock_stream_waitable (XLSTREAM (*instream)))
|
|
4706 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM
|
|
4707 (*instream))));
|
|
4708
|
|
4709 *err_usid =
|
|
4710 (NILP (*errstream)
|
|
4711 ? USID_DONTHASH
|
|
4712 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM
|
|
4713 (*errstream))));
|
|
4714 #endif /* CYGWIN */
|
428
|
4715 }
|
|
4716
|
853
|
4717 static void
|
|
4718 emacs_mswindows_delete_io_streams (Lisp_Object instream,
|
|
4719 Lisp_Object outstream,
|
|
4720 Lisp_Object errstream,
|
|
4721 USID *in_usid,
|
|
4722 USID *err_usid)
|
428
|
4723 {
|
853
|
4724 #ifdef CYGWIN
|
|
4725 event_stream_unixoid_delete_io_streams (instream, outstream, errstream,
|
|
4726 in_usid, err_usid);
|
|
4727 #else
|
|
4728 *in_usid =
|
|
4729 (NILP (instream)
|
|
4730 ? USID_DONTHASH
|
|
4731 : LSTREAM_TYPE_P (XLSTREAM (instream), winsock)
|
|
4732 ? HANDLE_TO_USID (get_winsock_stream_waitable (XLSTREAM (instream)))
|
|
4733 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM
|
|
4734 (instream))));
|
|
4735
|
|
4736 *err_usid =
|
|
4737 (NILP (errstream)
|
|
4738 ? USID_DONTHASH
|
|
4739 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM
|
|
4740 (errstream))));
|
|
4741 #endif /* CYGWIN */
|
428
|
4742 }
|
|
4743
|
442
|
4744 static int
|
|
4745 emacs_mswindows_current_event_timestamp (struct console *c)
|
|
4746 {
|
|
4747 return GetTickCount ();
|
|
4748 }
|
|
4749
|
428
|
4750 #ifndef HAVE_X_WINDOWS
|
|
4751 /* This is called from GC when a process object is about to be freed.
|
|
4752 If we've still got pointers to it in this file, we're gonna lose hard.
|
853
|
4753 */
|
|
4754 void debug_process_finalization (Lisp_Process *p);
|
428
|
4755 void
|
440
|
4756 debug_process_finalization (Lisp_Process *p)
|
428
|
4757 {
|
|
4758 #if 0 /* #### */
|
853
|
4759 Lisp_Object instr, outstr, errstr;
|
|
4760
|
|
4761 get_process_streams (p, &instr, &outstr, &errstr);
|
428
|
4762 /* if it still has fds, then it hasn't been killed yet. */
|
771
|
4763 assert (NILP (instr));
|
|
4764 assert (NILP (outstr));
|
853
|
4765 assert (NILP (errstr));
|
428
|
4766
|
|
4767 /* #### More checks here */
|
|
4768 #endif
|
|
4769 }
|
|
4770 #endif
|
|
4771
|
593
|
4772 #ifdef DEBUG_XEMACS
|
|
4773
|
|
4774 struct mswin_message_debug
|
|
4775 {
|
|
4776 int mess;
|
|
4777 char *string;
|
|
4778 };
|
|
4779
|
|
4780 #define FROB(val) { val, #val, },
|
|
4781
|
|
4782 struct mswin_message_debug debug_mswin_messages[] =
|
|
4783 {
|
|
4784 FROB (WM_NULL)
|
|
4785 FROB (WM_CREATE)
|
|
4786 FROB (WM_DESTROY)
|
|
4787 FROB (WM_MOVE)
|
|
4788 FROB (WM_SIZE)
|
|
4789
|
|
4790 FROB (WM_ACTIVATE)
|
|
4791
|
|
4792 FROB (WM_SETFOCUS)
|
|
4793 FROB (WM_KILLFOCUS)
|
|
4794 FROB (WM_ENABLE)
|
|
4795 FROB (WM_SETREDRAW)
|
|
4796 FROB (WM_SETTEXT)
|
|
4797 FROB (WM_GETTEXT)
|
|
4798 FROB (WM_GETTEXTLENGTH)
|
|
4799 FROB (WM_PAINT)
|
|
4800 FROB (WM_CLOSE)
|
|
4801 FROB (WM_QUERYENDSESSION)
|
|
4802 FROB (WM_QUIT)
|
|
4803 FROB (WM_QUERYOPEN)
|
|
4804 FROB (WM_ERASEBKGND)
|
|
4805 FROB (WM_SYSCOLORCHANGE)
|
|
4806 FROB (WM_ENDSESSION)
|
|
4807 FROB (WM_SHOWWINDOW)
|
|
4808 FROB (WM_WININICHANGE)
|
|
4809 #if(WINVER >= 0x0400)
|
|
4810 FROB (WM_SETTINGCHANGE)
|
|
4811 #endif /* WINVER >= 0x0400 */
|
|
4812
|
|
4813 FROB (WM_DEVMODECHANGE)
|
|
4814 FROB (WM_ACTIVATEAPP)
|
|
4815 FROB (WM_FONTCHANGE)
|
|
4816 FROB (WM_TIMECHANGE)
|
|
4817 FROB (WM_CANCELMODE)
|
|
4818 FROB (WM_SETCURSOR)
|
|
4819 FROB (WM_MOUSEACTIVATE)
|
|
4820 FROB (WM_CHILDACTIVATE)
|
|
4821 FROB (WM_QUEUESYNC)
|
|
4822
|
|
4823 FROB (WM_GETMINMAXINFO)
|
|
4824
|
|
4825 FROB (WM_PAINTICON)
|
|
4826 FROB (WM_ICONERASEBKGND)
|
|
4827 FROB (WM_NEXTDLGCTL)
|
|
4828 FROB (WM_SPOOLERSTATUS)
|
|
4829 FROB (WM_DRAWITEM)
|
|
4830 FROB (WM_MEASUREITEM)
|
|
4831 FROB (WM_DELETEITEM)
|
|
4832 FROB (WM_VKEYTOITEM)
|
|
4833 FROB (WM_CHARTOITEM)
|
|
4834 FROB (WM_SETFONT)
|
|
4835 FROB (WM_GETFONT)
|
|
4836 FROB (WM_SETHOTKEY)
|
|
4837 FROB (WM_GETHOTKEY)
|
|
4838 FROB (WM_QUERYDRAGICON)
|
|
4839 FROB (WM_COMPAREITEM)
|
|
4840 #if(WINVER >= 0x0500)
|
|
4841 FROB (WM_GETOBJECT)
|
|
4842 #endif /* WINVER >= 0x0500 */
|
|
4843 FROB (WM_COMPACTING)
|
|
4844 FROB (WM_COMMNOTIFY)
|
|
4845 FROB (WM_WINDOWPOSCHANGING)
|
|
4846 FROB (WM_WINDOWPOSCHANGED)
|
|
4847
|
|
4848 FROB (WM_POWER)
|
|
4849
|
|
4850 FROB (WM_COPYDATA)
|
|
4851 FROB (WM_CANCELJOURNAL)
|
|
4852
|
|
4853 #if(WINVER >= 0x0400)
|
|
4854 FROB (WM_NOTIFY)
|
|
4855 FROB (WM_INPUTLANGCHANGEREQUEST)
|
|
4856 FROB (WM_INPUTLANGCHANGE)
|
|
4857 FROB (WM_TCARD)
|
|
4858 FROB (WM_HELP)
|
|
4859 FROB (WM_USERCHANGED)
|
|
4860 FROB (WM_NOTIFYFORMAT)
|
|
4861
|
|
4862 FROB (WM_CONTEXTMENU)
|
|
4863 FROB (WM_STYLECHANGING)
|
|
4864 FROB (WM_STYLECHANGED)
|
|
4865 FROB (WM_DISPLAYCHANGE)
|
|
4866 FROB (WM_GETICON)
|
|
4867 FROB (WM_SETICON)
|
|
4868 #endif /* WINVER >= 0x0400 */
|
|
4869
|
|
4870 FROB (WM_NCCREATE)
|
|
4871 FROB (WM_NCDESTROY)
|
|
4872 FROB (WM_NCCALCSIZE)
|
|
4873 FROB (WM_NCHITTEST)
|
|
4874 FROB (WM_NCPAINT)
|
|
4875 FROB (WM_NCACTIVATE)
|
|
4876 FROB (WM_GETDLGCODE)
|
604
|
4877 #ifdef WM_SYNCPAINT /* not in VC 5 */
|
593
|
4878 FROB (WM_SYNCPAINT)
|
604
|
4879 #endif /* WM_SYNCPAINT */
|
593
|
4880 FROB (WM_NCMOUSEMOVE)
|
|
4881 FROB (WM_NCLBUTTONDOWN)
|
|
4882 FROB (WM_NCLBUTTONUP)
|
|
4883 FROB (WM_NCLBUTTONDBLCLK)
|
|
4884 FROB (WM_NCRBUTTONDOWN)
|
|
4885 FROB (WM_NCRBUTTONUP)
|
|
4886 FROB (WM_NCRBUTTONDBLCLK)
|
|
4887 FROB (WM_NCMBUTTONDOWN)
|
|
4888 FROB (WM_NCMBUTTONUP)
|
|
4889 FROB (WM_NCMBUTTONDBLCLK)
|
|
4890
|
|
4891 /* FROB (WM_KEYFIRST) */
|
|
4892 FROB (WM_KEYDOWN)
|
|
4893 FROB (WM_KEYUP)
|
|
4894 FROB (WM_CHAR)
|
|
4895 FROB (WM_DEADCHAR)
|
|
4896 FROB (WM_SYSKEYDOWN)
|
|
4897 FROB (WM_SYSKEYUP)
|
|
4898 FROB (WM_SYSCHAR)
|
|
4899 FROB (WM_SYSDEADCHAR)
|
|
4900 FROB (WM_KEYLAST)
|
|
4901
|
604
|
4902 #if(WINVER >= 0x0400) && defined (WM_IME_STARTCOMPOSITION)
|
|
4903 /* not in Cygwin? */
|
593
|
4904 FROB (WM_IME_STARTCOMPOSITION)
|
|
4905 FROB (WM_IME_ENDCOMPOSITION)
|
|
4906 FROB (WM_IME_COMPOSITION)
|
|
4907 FROB (WM_IME_KEYLAST)
|
604
|
4908 #endif /* WINVER >= 0x0400 && defined (WM_IME_STARTCOMPOSITION) */
|
593
|
4909
|
|
4910 FROB (WM_INITDIALOG)
|
|
4911 FROB (WM_COMMAND)
|
|
4912 FROB (WM_SYSCOMMAND)
|
|
4913 FROB (WM_TIMER)
|
|
4914 FROB (WM_HSCROLL)
|
|
4915 FROB (WM_VSCROLL)
|
|
4916 FROB (WM_INITMENU)
|
|
4917 FROB (WM_INITMENUPOPUP)
|
|
4918 FROB (WM_MENUSELECT)
|
|
4919 FROB (WM_MENUCHAR)
|
|
4920 FROB (WM_ENTERIDLE)
|
|
4921 #if(WINVER >= 0x0500)
|
|
4922 FROB (WM_MENURBUTTONUP)
|
|
4923 FROB (WM_MENUDRAG)
|
|
4924 FROB (WM_MENUGETOBJECT)
|
|
4925 FROB (WM_UNINITMENUPOPUP)
|
|
4926 FROB (WM_MENUCOMMAND)
|
|
4927 #endif /* WINVER >= 0x0500 */
|
|
4928
|
|
4929
|
|
4930 FROB (WM_CTLCOLORMSGBOX)
|
|
4931 FROB (WM_CTLCOLOREDIT)
|
|
4932 FROB (WM_CTLCOLORLISTBOX)
|
|
4933 FROB (WM_CTLCOLORBTN)
|
|
4934 FROB (WM_CTLCOLORDLG)
|
|
4935 FROB (WM_CTLCOLORSCROLLBAR)
|
|
4936 FROB (WM_CTLCOLORSTATIC)
|
|
4937
|
|
4938
|
|
4939 /* FROB (WM_MOUSEFIRST) */
|
|
4940 FROB (WM_MOUSEMOVE)
|
|
4941 FROB (WM_LBUTTONDOWN)
|
|
4942 FROB (WM_LBUTTONUP)
|
|
4943 FROB (WM_LBUTTONDBLCLK)
|
|
4944 FROB (WM_RBUTTONDOWN)
|
|
4945 FROB (WM_RBUTTONUP)
|
|
4946 FROB (WM_RBUTTONDBLCLK)
|
|
4947 FROB (WM_MBUTTONDOWN)
|
|
4948 FROB (WM_MBUTTONUP)
|
|
4949 FROB (WM_MBUTTONDBLCLK)
|
|
4950
|
|
4951 #if (_WIN32_WINNT >= 0x0400) || (_WIN32_WINDOWS > 0x0400)
|
|
4952 FROB (WM_MOUSEWHEEL)
|
|
4953 FROB (WM_MOUSELAST)
|
|
4954 #else
|
|
4955 FROB (WM_MOUSELAST)
|
|
4956 #endif /* if (_WIN32_WINNT < 0x0400) */
|
|
4957
|
|
4958 FROB (WM_PARENTNOTIFY)
|
|
4959 FROB (WM_ENTERMENULOOP)
|
|
4960 FROB (WM_EXITMENULOOP)
|
|
4961
|
|
4962 #if(WINVER >= 0x0400)
|
|
4963 FROB (WM_NEXTMENU)
|
|
4964
|
|
4965 FROB (WM_SIZING)
|
|
4966 FROB (WM_CAPTURECHANGED)
|
|
4967 FROB (WM_MOVING)
|
|
4968 FROB (WM_POWERBROADCAST)
|
|
4969
|
|
4970 FROB (WM_DEVICECHANGE)
|
|
4971
|
|
4972 #endif /* WINVER >= 0x0400 */
|
|
4973
|
|
4974 FROB (WM_MDICREATE)
|
|
4975 FROB (WM_MDIDESTROY)
|
|
4976 FROB (WM_MDIACTIVATE)
|
|
4977 FROB (WM_MDIRESTORE)
|
|
4978 FROB (WM_MDINEXT)
|
|
4979 FROB (WM_MDIMAXIMIZE)
|
|
4980 FROB (WM_MDITILE)
|
|
4981 FROB (WM_MDICASCADE)
|
|
4982 FROB (WM_MDIICONARRANGE)
|
|
4983 FROB (WM_MDIGETACTIVE)
|
|
4984
|
|
4985
|
|
4986 FROB (WM_MDISETMENU)
|
|
4987 FROB (WM_ENTERSIZEMOVE)
|
|
4988 FROB (WM_EXITSIZEMOVE)
|
|
4989 FROB (WM_DROPFILES)
|
|
4990 FROB (WM_MDIREFRESHMENU)
|
|
4991
|
604
|
4992 #ifdef WM_IME_SETCONTEXT /* not in Cygwin? */
|
593
|
4993
|
|
4994 #if(WINVER >= 0x0400)
|
|
4995 FROB (WM_IME_SETCONTEXT)
|
|
4996 FROB (WM_IME_NOTIFY)
|
|
4997 FROB (WM_IME_CONTROL)
|
|
4998 FROB (WM_IME_COMPOSITIONFULL)
|
|
4999 FROB (WM_IME_SELECT)
|
|
5000 FROB (WM_IME_CHAR)
|
|
5001 #endif /* WINVER >= 0x0400 */
|
|
5002 #if(WINVER >= 0x0500)
|
|
5003 FROB (WM_IME_REQUEST)
|
|
5004 #endif /* WINVER >= 0x0500 */
|
|
5005 #if(WINVER >= 0x0400)
|
|
5006 FROB (WM_IME_KEYDOWN)
|
|
5007 FROB (WM_IME_KEYUP)
|
|
5008 #endif /* WINVER >= 0x0400 */
|
|
5009
|
604
|
5010 #endif /* WM_IME_SETCONTEXT */
|
593
|
5011
|
|
5012 #if(_WIN32_WINNT >= 0x0400)
|
|
5013 FROB (WM_MOUSEHOVER)
|
|
5014 FROB (WM_MOUSELEAVE)
|
|
5015 #endif /* _WIN32_WINNT >= 0x0400 */
|
|
5016
|
|
5017 FROB (WM_CUT)
|
|
5018 FROB (WM_COPY)
|
|
5019 FROB (WM_PASTE)
|
|
5020 FROB (WM_CLEAR)
|
|
5021 FROB (WM_UNDO)
|
|
5022 FROB (WM_RENDERFORMAT)
|
|
5023 FROB (WM_RENDERALLFORMATS)
|
|
5024 FROB (WM_DESTROYCLIPBOARD)
|
|
5025 FROB (WM_DRAWCLIPBOARD)
|
|
5026 FROB (WM_PAINTCLIPBOARD)
|
|
5027 FROB (WM_VSCROLLCLIPBOARD)
|
|
5028 FROB (WM_SIZECLIPBOARD)
|
|
5029 FROB (WM_ASKCBFORMATNAME)
|
|
5030 FROB (WM_CHANGECBCHAIN)
|
|
5031 FROB (WM_HSCROLLCLIPBOARD)
|
|
5032 FROB (WM_QUERYNEWPALETTE)
|
|
5033 FROB (WM_PALETTEISCHANGING)
|
|
5034 FROB (WM_PALETTECHANGED)
|
|
5035 FROB (WM_HOTKEY)
|
|
5036
|
|
5037 #if(WINVER >= 0x0400)
|
|
5038 FROB (WM_PRINT)
|
|
5039 FROB (WM_PRINTCLIENT)
|
|
5040
|
|
5041 FROB (WM_HANDHELDFIRST)
|
|
5042 FROB (WM_HANDHELDLAST)
|
|
5043
|
|
5044 FROB (WM_AFXFIRST)
|
|
5045 FROB (WM_AFXLAST)
|
|
5046 #endif /* WINVER >= 0x0400 */
|
|
5047
|
|
5048 FROB (WM_PENWINFIRST)
|
|
5049 FROB (WM_PENWINLAST)
|
|
5050 };
|
|
5051
|
|
5052 #undef FROB
|
|
5053
|
|
5054 static void
|
|
5055 debug_output_mswin_message (HWND hwnd, UINT message_, WPARAM wParam,
|
|
5056 LPARAM lParam)
|
|
5057 {
|
|
5058 Lisp_Object frame = mswindows_find_frame (hwnd);
|
|
5059 int i;
|
|
5060 char *str = 0;
|
|
5061 /* struct mswin_message_debug *i_hate_cranking_out_code_like_this; */
|
|
5062
|
|
5063 for (i = 0; i < countof (debug_mswin_messages); i++)
|
|
5064 {
|
647
|
5065 if (debug_mswin_messages[i].mess == (int) message_)
|
593
|
5066 {
|
|
5067 str = debug_mswin_messages[i].string;
|
|
5068 break;
|
|
5069 }
|
|
5070 }
|
|
5071
|
|
5072 if (str)
|
|
5073 stderr_out ("%s", str);
|
|
5074 else
|
|
5075 stderr_out ("%x", message_);
|
|
5076
|
|
5077 if (debug_mswindows_events > 1)
|
|
5078 {
|
|
5079 stderr_out (" wparam=%d lparam=%d hwnd=%x frame: ",
|
|
5080 wParam, (int) lParam, (unsigned int) hwnd);
|
|
5081 debug_print (frame);
|
903
|
5082 if (message_ == WM_WINDOWPOSCHANGED ||
|
|
5083 message_ == WM_WINDOWPOSCHANGING)
|
|
5084 {
|
|
5085 WINDOWPOS *wp = (WINDOWPOS *) lParam;
|
|
5086 stderr_out(" WINDOWPOS: x=%d, y=%d, h=%d, w=%d\n",
|
|
5087 wp->x, wp->y, wp->cx, wp->cy);
|
|
5088 }
|
|
5089 else if (message_ == WM_MOVE)
|
|
5090 {
|
|
5091 int x = (int)(short) LOWORD(lParam); /* horizontal position */
|
|
5092 int y = (int)(short) HIWORD(lParam); /* vertical position */
|
|
5093 stderr_out(" MOVE: x=%d, y=%d\n", x, y);
|
|
5094 }
|
|
5095 else if (message_ == WM_SIZE)
|
|
5096 {
|
|
5097 int w = (int)(short) LOWORD(lParam); /* width */
|
|
5098 int h = (int)(short) HIWORD(lParam); /* height */
|
|
5099 stderr_out(" SIZE: w=%d, h=%d\n", w, h);
|
|
5100 }
|
593
|
5101 }
|
|
5102 else
|
|
5103 stderr_out ("\n");
|
|
5104 }
|
|
5105
|
|
5106 #endif /* DEBUG_XEMACS */
|
|
5107
|
428
|
5108 /************************************************************************/
|
|
5109 /* initialization */
|
|
5110 /************************************************************************/
|
|
5111
|
|
5112 void
|
|
5113 reinit_vars_of_event_mswindows (void)
|
|
5114 {
|
|
5115 mswindows_pending_timers_count = 0;
|
|
5116
|
1204
|
5117 mswindows_event_stream = xnew_and_zero (struct event_stream);
|
428
|
5118
|
|
5119 mswindows_event_stream->event_pending_p = emacs_mswindows_event_pending_p;
|
|
5120 mswindows_event_stream->next_event_cb = emacs_mswindows_next_event;
|
|
5121 mswindows_event_stream->handle_magic_event_cb = emacs_mswindows_handle_magic_event;
|
788
|
5122 mswindows_event_stream->format_magic_event_cb = emacs_mswindows_format_magic_event;
|
|
5123 mswindows_event_stream->compare_magic_event_cb= emacs_mswindows_compare_magic_event;
|
|
5124 mswindows_event_stream->hash_magic_event_cb = emacs_mswindows_hash_magic_event;
|
428
|
5125 mswindows_event_stream->add_timeout_cb = emacs_mswindows_add_timeout;
|
|
5126 mswindows_event_stream->remove_timeout_cb = emacs_mswindows_remove_timeout;
|
1204
|
5127 mswindows_event_stream->drain_queue_cb = emacs_mswindows_drain_queue;
|
428
|
5128 mswindows_event_stream->select_console_cb = emacs_mswindows_select_console;
|
|
5129 mswindows_event_stream->unselect_console_cb = emacs_mswindows_unselect_console;
|
|
5130 mswindows_event_stream->select_process_cb = emacs_mswindows_select_process;
|
|
5131 mswindows_event_stream->unselect_process_cb = emacs_mswindows_unselect_process;
|
853
|
5132 mswindows_event_stream->create_io_streams_cb = emacs_mswindows_create_io_streams;
|
|
5133 mswindows_event_stream->delete_io_streams_cb = emacs_mswindows_delete_io_streams;
|
442
|
5134 mswindows_event_stream->current_event_timestamp_cb =
|
|
5135 emacs_mswindows_current_event_timestamp;
|
903
|
5136
|
|
5137 dde_eval_pending = 0;
|
428
|
5138 }
|
|
5139
|
|
5140 void
|
|
5141 vars_of_event_mswindows (void)
|
|
5142 {
|
|
5143 reinit_vars_of_event_mswindows ();
|
|
5144
|
|
5145 mswindows_s_dispatch_event_queue = Qnil;
|
|
5146 staticpro (&mswindows_s_dispatch_event_queue);
|
|
5147 mswindows_s_dispatch_event_queue_tail = Qnil;
|
1204
|
5148 dump_add_root_lisp_object (&mswindows_s_dispatch_event_queue_tail);
|
428
|
5149
|
853
|
5150 mswindows_error_caught_in_modal_loop = 0;
|
442
|
5151
|
903
|
5152 #ifdef HAVE_DRAGNDROP
|
|
5153 Fprovide (Qdde);
|
|
5154
|
|
5155 DEFVAR_LISP ("dde-advise-items", &Vdde_advise_items /*
|
|
5156 A list of allocated DDE advise items.
|
|
5157 Each item is an uninterned symbol, created using dde-alloc-advise-item.
|
|
5158
|
|
5159 The symbol's value is the data which is returned to the DDE client when
|
|
5160 a request for the item is made (or a dde-advise call is made).
|
|
5161
|
|
5162 The symbol also has a 'HSZ property, which holds the DDE string handle
|
|
5163 for the item, as a float. This is for internal use only, and should not
|
|
5164 be modified.
|
|
5165 */ );
|
|
5166 Vdde_advise_items = Qnil;
|
|
5167
|
|
5168 dde_eval_result = Qnil;
|
|
5169 staticpro (&dde_eval_result);
|
|
5170 dde_eval_error = Qnil;
|
|
5171 staticpro (&dde_eval_error);
|
|
5172 #endif
|
|
5173
|
442
|
5174 #ifdef DEBUG_XEMACS
|
|
5175 DEFVAR_INT ("debug-mswindows-events", &debug_mswindows_events /*
|
593
|
5176 If non-zero, display debug information about Windows messages that XEmacs sees.
|
442
|
5177 Information is displayed in a console window. Currently defined values are:
|
|
5178
|
593
|
5179 1 == non-verbose output (just the message name)
|
|
5180 2 == verbose output (all parameters)
|
|
5181 3 == even more verbose output (extra debugging info)
|
442
|
5182 */ );
|
|
5183 debug_mswindows_events = 0;
|
|
5184 #endif
|
|
5185
|
|
5186 DEFVAR_BOOL ("mswindows-alt-by-itself-activates-menu",
|
|
5187 &mswindows_alt_by_itself_activates_menu /*
|
|
5188 *Controls whether pressing and releasing the Alt key activates the menubar.
|
|
5189 This applies only if no intervening key was pressed. See also
|
|
5190 `menu-accelerator-enabled', which is probably the behavior you actually want.
|
428
|
5191 Default is t.
|
|
5192 */ );
|
|
5193
|
442
|
5194 DEFVAR_BOOL ("mswindows-dynamic-frame-resize",
|
|
5195 &mswindows_dynamic_frame_resize /*
|
428
|
5196 *Controls redrawing frame contents during mouse-drag or keyboard resize
|
|
5197 operation. When non-nil, the frame is redrawn while being resized. When
|
|
5198 nil, frame is not redrawn, and exposed areas are filled with default
|
|
5199 MDI application background color. Note that this option only has effect
|
|
5200 if "Show window contents while dragging" is on in system Display/Plus!
|
|
5201 settings.
|
|
5202 Default is t on fast machines, nil on slow.
|
|
5203 */ );
|
|
5204
|
442
|
5205 DEFVAR_INT ("mswindows-mouse-button-tolerance",
|
|
5206 &mswindows_mouse_button_tolerance /*
|
428
|
5207 *Analogue of double click interval for faking middle mouse events.
|
|
5208 The value is the minimum time in milliseconds that must elapse between
|
|
5209 left/right button down events before they are considered distinct events.
|
|
5210 If both mouse buttons are depressed within this interval, a middle mouse
|
|
5211 button down event is generated instead.
|
|
5212 If negative or zero, currently set system default is used instead.
|
|
5213 */ );
|
|
5214
|
|
5215 DEFVAR_INT ("mswindows-num-mouse-buttons", &mswindows_num_mouse_buttons /*
|
|
5216 Number of physical mouse buttons.
|
|
5217 */ );
|
|
5218
|
442
|
5219 DEFVAR_INT ("mswindows-mouse-button-max-skew-x",
|
|
5220 &mswindows_mouse_button_max_skew_x /*
|
428
|
5221 *Maximum horizontal distance in pixels between points in which left and
|
|
5222 right button clicks occurred for them to be translated into single
|
|
5223 middle button event. Clicks must occur in time not longer than defined
|
|
5224 by the variable `mswindows-mouse-button-tolerance'.
|
|
5225 If negative or zero, currently set system default is used instead.
|
|
5226 */ );
|
|
5227
|
442
|
5228 DEFVAR_INT ("mswindows-mouse-button-max-skew-y",
|
|
5229 &mswindows_mouse_button_max_skew_y /*
|
428
|
5230 *Maximum vertical distance in pixels between points in which left and
|
|
5231 right button clicks occurred for them to be translated into single
|
|
5232 middle button event. Clicks must occur in time not longer than defined
|
|
5233 by the variable `mswindows-mouse-button-tolerance'.
|
|
5234 If negative or zero, currently set system default is used instead.
|
|
5235 */ );
|
|
5236
|
|
5237 mswindows_mouse_button_max_skew_x = 0;
|
|
5238 mswindows_mouse_button_max_skew_y = 0;
|
|
5239 mswindows_mouse_button_tolerance = 0;
|
442
|
5240 mswindows_alt_by_itself_activates_menu = 1;
|
428
|
5241 }
|
|
5242
|
|
5243 void
|
|
5244 syms_of_event_mswindows (void)
|
|
5245 {
|
903
|
5246 #ifdef HAVE_DRAGNDROP
|
|
5247 DEFSYMBOL(QHSZ);
|
|
5248 DEFSUBR(Fdde_alloc_advise_item);
|
|
5249 DEFSUBR(Fdde_free_advise_item);
|
|
5250 DEFSUBR(Fdde_advise);
|
|
5251 #endif
|
428
|
5252 }
|
|
5253
|
|
5254 void
|
|
5255 lstream_type_create_mswindows_selectable (void)
|
|
5256 {
|
853
|
5257 #ifndef CYGWIN
|
428
|
5258 init_slurp_stream ();
|
|
5259 init_shove_stream ();
|
|
5260 init_winsock_stream ();
|
|
5261 #endif
|
|
5262 }
|
|
5263
|
|
5264 void
|
|
5265 init_event_mswindows_late (void)
|
|
5266 {
|
853
|
5267 #ifdef CYGWIN
|
771
|
5268 windows_fd = retry_open ("/dev/windows", O_RDONLY | O_NONBLOCK, 0);
|
814
|
5269 assert (windows_fd >= 0);
|
428
|
5270 FD_SET (windows_fd, &input_wait_mask);
|
814
|
5271 FD_ZERO (&zero_mask);
|
428
|
5272 #endif
|
|
5273
|
|
5274 event_stream = mswindows_event_stream;
|
|
5275
|
|
5276 mswindows_dynamic_frame_resize = !GetSystemMetrics (SM_SLOWMACHINE);
|
|
5277 mswindows_num_mouse_buttons = GetSystemMetrics (SM_CMOUSEBUTTONS);
|
|
5278 }
|