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