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