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