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