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