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