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