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