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