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