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