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