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