442
|
1 /* The mswindows event_stream interface.
|
428
|
2 Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
558
|
4 Copyright (C) 1996, 2000, 2001 Ben Wing.
|
428
|
5 Copyright (C) 1997 Jonathan Harris.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Not in FSF. */
|
|
25
|
|
26 /* Authorship:
|
|
27
|
|
28 Ultimately based on FSF.
|
|
29 Rewritten by Ben Wing.
|
|
30 Rewritten for mswindows by Jonathan Harris, November 1997 for 21.0.
|
|
31 Subprocess and modal loop support by Kirill M. Katsnelson.
|
|
32 */
|
|
33
|
|
34 #include <config.h>
|
|
35 #include "lisp.h"
|
|
36
|
|
37 #include "console-msw.h"
|
|
38
|
|
39 #ifdef HAVE_SCROLLBARS
|
|
40 # include "scrollbar-msw.h"
|
|
41 #endif
|
|
42
|
|
43 #ifdef HAVE_MENUBARS
|
442
|
44 # include "menubar.h"
|
428
|
45 # include "menubar-msw.h"
|
|
46 #endif
|
|
47
|
|
48 #ifdef HAVE_DRAGNDROP
|
|
49 # include "dragdrop.h"
|
|
50 #endif
|
|
51
|
558
|
52 #include "buffer.h"
|
428
|
53 #include "device.h"
|
|
54 #include "events.h"
|
558
|
55 #include "faces.h"
|
428
|
56 #include "frame.h"
|
|
57 #include "lstream.h"
|
558
|
58 #include "objects-msw.h"
|
428
|
59 #include "process.h"
|
|
60 #include "redisplay.h"
|
430
|
61 #include "select.h"
|
558
|
62 #include "sysdep.h"
|
442
|
63 #include "window.h"
|
558
|
64
|
|
65 #include "sysfile.h"
|
428
|
66 #include "sysproc.h"
|
558
|
67 #include "systime.h"
|
428
|
68 #include "syswait.h"
|
|
69
|
|
70 #ifdef HAVE_MSG_SELECT
|
|
71 #include "console-tty.h"
|
442
|
72 #elif defined(CYGWIN)
|
428
|
73 typedef unsigned int SOCKET;
|
|
74 #endif
|
|
75
|
442
|
76 #if !(defined(CYGWIN) || defined(MINGW))
|
|
77 # include <shlobj.h> /* For IShellLink */
|
428
|
78 #endif
|
|
79
|
|
80 #ifdef HAVE_MENUBARS
|
|
81 #define ADJR_MENUFLAG TRUE
|
|
82 #else
|
|
83 #define ADJR_MENUFLAG FALSE
|
|
84 #endif
|
|
85
|
|
86 /* Fake key modifier which is attached to a quit char event.
|
|
87 Removed upon dequeueing an event */
|
502
|
88 #define FAKE_MOD_QUIT (1 << 20)
|
|
89 #define FAKE_MOD_QUIT_CRITICAL (1 << 21)
|
428
|
90
|
|
91 /* Timer ID used for button2 emulation */
|
|
92 #define BUTTON_2_TIMER_ID 1
|
|
93
|
|
94 static Lisp_Object mswindows_find_console (HWND hwnd);
|
|
95 static Lisp_Object mswindows_key_to_emacs_keysym (int mswindows_key, int mods,
|
|
96 int extendedp);
|
442
|
97 static int mswindows_modifier_state (BYTE* keymap, DWORD fwKeys,
|
|
98 int has_AltGr);
|
428
|
99 static void mswindows_set_chord_timer (HWND hwnd);
|
|
100 static int mswindows_button2_near_enough (POINTS p1, POINTS p2);
|
|
101 static int mswindows_current_layout_has_AltGr (void);
|
442
|
102 static int mswindows_handle_sticky_modifiers (WPARAM wParam, LPARAM lParam,
|
|
103 int downp, int keyp);
|
428
|
104
|
|
105 static struct event_stream *mswindows_event_stream;
|
|
106
|
|
107 #ifdef HAVE_MSG_SELECT
|
|
108 extern SELECT_TYPE input_wait_mask, non_fake_input_wait_mask;
|
|
109 extern SELECT_TYPE process_only_mask, tty_only_mask;
|
|
110 SELECT_TYPE zero_mask;
|
|
111 extern int signal_event_pipe_initialized;
|
|
112 int windows_fd;
|
|
113 #endif
|
|
114
|
|
115 /*
|
|
116 * Two separate queues, for efficiency, one (_u_) for user events, and
|
|
117 * another (_s_) for non-user ones. We always return events out of the
|
|
118 * first one until it is empty and only then proceed with the second
|
|
119 * one.
|
|
120 */
|
|
121 static Lisp_Object mswindows_u_dispatch_event_queue, mswindows_u_dispatch_event_queue_tail;
|
|
122 static Lisp_Object mswindows_s_dispatch_event_queue, mswindows_s_dispatch_event_queue_tail;
|
|
123
|
|
124 /* The number of things we can wait on */
|
|
125 #define MAX_WAITABLE (MAXIMUM_WAIT_OBJECTS - 1)
|
|
126
|
|
127 #ifndef HAVE_MSG_SELECT
|
|
128 /* List of mswindows waitable handles. */
|
|
129 static HANDLE mswindows_waitable_handles[MAX_WAITABLE];
|
|
130
|
|
131 /* Number of wait handles */
|
|
132 static int mswindows_waitable_count=0;
|
|
133 #endif /* HAVE_MSG_SELECT */
|
442
|
134
|
428
|
135 /* Brush for painting widgets */
|
|
136 static HBRUSH widget_brush = 0;
|
|
137 static LONG last_widget_brushed = 0;
|
|
138
|
|
139 /* Count of quit chars currently in the queue */
|
|
140 /* Incremented in WM_[SYS]KEYDOWN handler in the mswindows_wnd_proc()
|
|
141 Decremented in mswindows_dequeue_dispatch_event() */
|
|
142 int mswindows_quit_chars_count = 0;
|
|
143
|
|
144 /* These are Lisp integers; see DEFVARS in this file for description. */
|
|
145 int mswindows_dynamic_frame_resize;
|
442
|
146 int mswindows_alt_by_itself_activates_menu;
|
458
|
147 Fixnum mswindows_num_mouse_buttons;
|
|
148 Fixnum mswindows_mouse_button_max_skew_x;
|
|
149 Fixnum mswindows_mouse_button_max_skew_y;
|
|
150 Fixnum mswindows_mouse_button_tolerance;
|
428
|
151
|
442
|
152 #ifdef DEBUG_XEMACS
|
458
|
153 Fixnum debug_mswindows_events;
|
593
|
154
|
|
155 static void debug_output_mswin_message (HWND hwnd, UINT message_,
|
|
156 WPARAM wParam, LPARAM lParam);
|
442
|
157 #endif
|
|
158
|
428
|
159 /* This is the event signaled by the event pump.
|
|
160 See mswindows_pump_outstanding_events for comments */
|
|
161 static Lisp_Object mswindows_error_caught_in_modal_loop;
|
|
162 static int mswindows_in_modal_loop;
|
|
163
|
|
164 /* Count of wound timers */
|
|
165 static int mswindows_pending_timers_count;
|
442
|
166
|
|
167 static DWORD mswindows_last_mouse_button_state;
|
428
|
168
|
|
169 /************************************************************************/
|
|
170 /* Pipe instream - reads process output */
|
|
171 /************************************************************************/
|
|
172
|
|
173 #define PIPE_READ_DELAY 20
|
|
174
|
|
175 #define HANDLE_TO_USID(h) ((USID)(h))
|
|
176
|
|
177 #define NTPIPE_SLURP_STREAM_DATA(stream) \
|
|
178 LSTREAM_TYPE_DATA (stream, ntpipe_slurp)
|
|
179
|
|
180 /* This structure is allocated by the main thread, and is deallocated
|
|
181 in the thread upon exit. There are situations when a thread
|
|
182 remains blocked for a long time, much longer than the lstream
|
|
183 exists. For example, "start notepad" command is issued from the
|
|
184 shell, then the shell is closed by C-c C-d. Although the shell
|
|
185 process exits, its output pipe will not get closed until the
|
|
186 notepad process exits also, because it inherits the pipe form the
|
|
187 shell. In this case, we abandon the thread, and let it live until
|
|
188 all such processes exit. While struct ntpipe_slurp_stream is
|
|
189 deallocated in this case, ntpipe_slurp_stream_shared_data are not. */
|
|
190
|
|
191 struct ntpipe_slurp_stream_shared_data
|
|
192 {
|
|
193 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */
|
442
|
194 /* This is a manual-reset object. */
|
428
|
195 HANDLE hev_caller; /* Caller blocks on this, and we signal it */
|
442
|
196 /* This is a manual-reset object. */
|
428
|
197 HANDLE hev_unsleep; /* Pipe read delay is canceled if this is set */
|
442
|
198 /* This is a manual-reset object. */
|
428
|
199 HANDLE hpipe; /* Pipe read end handle. */
|
|
200 LONG die_p; /* Thread must exit ASAP if non-zero */
|
|
201 BOOL eof_p : 1; /* Set when thread saw EOF */
|
|
202 BOOL error_p : 1; /* Read error other than EOF/broken pipe */
|
|
203 BOOL inuse_p : 1; /* this structure is in use */
|
|
204 LONG lock_count; /* Client count of this struct, 0=safe to free */
|
|
205 BYTE onebyte; /* One byte buffer read by thread */
|
|
206 };
|
|
207
|
|
208 #define MAX_SLURP_STREAMS 32
|
|
209 struct ntpipe_slurp_stream_shared_data
|
|
210 shared_data_block[MAX_SLURP_STREAMS]={{0}};
|
|
211
|
|
212 struct ntpipe_slurp_stream
|
|
213 {
|
|
214 LPARAM user_data; /* Any user data stored in the stream object */
|
|
215 struct ntpipe_slurp_stream_shared_data* thread_data;
|
|
216 };
|
|
217
|
|
218 DEFINE_LSTREAM_IMPLEMENTATION ("ntpipe-input", lstream_ntpipe_slurp,
|
|
219 sizeof (struct ntpipe_slurp_stream));
|
|
220
|
|
221 /* This function is thread-safe, and is called from either thread
|
|
222 context. It serializes freeing shared data structure */
|
|
223 static void
|
|
224 slurper_free_shared_data_maybe (struct ntpipe_slurp_stream_shared_data* s)
|
|
225 {
|
|
226 if (InterlockedDecrement (&s->lock_count) == 0)
|
|
227 {
|
|
228 /* Destroy events */
|
|
229 CloseHandle (s->hev_thread);
|
|
230 CloseHandle (s->hev_caller);
|
|
231 CloseHandle (s->hev_unsleep);
|
|
232 s->inuse_p = 0;
|
|
233 }
|
|
234 }
|
|
235
|
|
236 static struct ntpipe_slurp_stream_shared_data*
|
442
|
237 slurper_allocate_shared_data (void)
|
428
|
238 {
|
|
239 int i=0;
|
|
240 for (i=0; i<MAX_SLURP_STREAMS; i++)
|
|
241 {
|
|
242 if (!shared_data_block[i].inuse_p)
|
|
243 {
|
|
244 shared_data_block[i].inuse_p=1;
|
|
245 return &shared_data_block[i];
|
|
246 }
|
|
247 }
|
|
248 return (struct ntpipe_slurp_stream_shared_data*)0;
|
|
249 }
|
|
250
|
|
251 static DWORD WINAPI
|
|
252 slurp_thread (LPVOID vparam)
|
|
253 {
|
|
254 struct ntpipe_slurp_stream_shared_data *s =
|
|
255 (struct ntpipe_slurp_stream_shared_data*)vparam;
|
|
256
|
|
257 for (;;)
|
|
258 {
|
|
259 /* Read one byte from the pipe */
|
|
260 DWORD actually_read;
|
|
261 if (!ReadFile (s->hpipe, &s->onebyte, 1, &actually_read, NULL))
|
|
262 {
|
|
263 DWORD err = GetLastError ();
|
|
264 if (err == ERROR_BROKEN_PIPE || err == ERROR_NO_DATA)
|
|
265 s->eof_p = TRUE;
|
|
266 else
|
|
267 s->error_p = TRUE;
|
|
268 }
|
|
269 else if (actually_read == 0)
|
|
270 s->eof_p = TRUE;
|
|
271
|
|
272 /* We must terminate on an error or eof */
|
|
273 if (s->eof_p || s->error_p)
|
|
274 InterlockedIncrement (&s->die_p);
|
|
275
|
|
276 /* Before we notify caller, we unsignal our event. */
|
|
277 ResetEvent (s->hev_thread);
|
|
278
|
|
279 /* Now we got something to notify caller, either a byte or an
|
|
280 error/eof indication. Before we do, allow internal pipe
|
|
281 buffer to accumulate little bit more data.
|
|
282 Reader function pulses this event before waiting for
|
|
283 a character, to avoid pipe delay, and to get the byte
|
|
284 immediately. */
|
|
285 if (!s->die_p)
|
|
286 WaitForSingleObject (s->hev_unsleep, PIPE_READ_DELAY);
|
|
287
|
|
288 /* Either make event loop generate a process event, or
|
|
289 inblock reader */
|
|
290 SetEvent (s->hev_caller);
|
|
291
|
|
292 /* Cleanup and exit if we're shot off */
|
|
293 if (s->die_p)
|
|
294 break;
|
|
295
|
|
296 /* Block until the client finishes with retrieving the rest of
|
|
297 pipe data */
|
|
298 WaitForSingleObject (s->hev_thread, INFINITE);
|
|
299 }
|
|
300
|
|
301 slurper_free_shared_data_maybe (s);
|
|
302
|
|
303 return 0;
|
|
304 }
|
|
305
|
|
306 static Lisp_Object
|
|
307 make_ntpipe_input_stream (HANDLE hpipe, LPARAM param)
|
|
308 {
|
|
309 Lisp_Object obj;
|
|
310 Lstream *lstr = Lstream_new (lstream_ntpipe_slurp, "r");
|
|
311 struct ntpipe_slurp_stream* s = NTPIPE_SLURP_STREAM_DATA (lstr);
|
|
312 DWORD thread_id_unused;
|
|
313 HANDLE hthread;
|
|
314
|
|
315 /* We deal only with pipes, for we're using PeekNamedPipe api */
|
|
316 assert (GetFileType (hpipe) == FILE_TYPE_PIPE);
|
|
317
|
|
318 s->thread_data = slurper_allocate_shared_data();
|
|
319
|
|
320 /* Create reader thread. This could fail, so do not create events
|
|
321 until thread is created */
|
|
322 hthread = CreateThread (NULL, 0, slurp_thread, (LPVOID)s->thread_data,
|
|
323 CREATE_SUSPENDED, &thread_id_unused);
|
|
324 if (hthread == NULL)
|
|
325 {
|
|
326 Lstream_delete (lstr);
|
|
327 s->thread_data->inuse_p=0;
|
|
328 return Qnil;
|
|
329 }
|
|
330
|
|
331 /* Shared data are initially owned by both main and slurper
|
|
332 threads. */
|
|
333 s->thread_data->lock_count = 2;
|
|
334 s->thread_data->die_p = 0;
|
|
335 s->thread_data->eof_p = FALSE;
|
|
336 s->thread_data->error_p = FALSE;
|
|
337 s->thread_data->hpipe = hpipe;
|
|
338 s->user_data = param;
|
|
339
|
|
340 /* hev_thread is a manual-reset event, initially signaled */
|
|
341 s->thread_data->hev_thread = CreateEvent (NULL, TRUE, TRUE, NULL);
|
|
342 /* hev_caller is a manual-reset event, initially nonsignaled */
|
|
343 s->thread_data->hev_caller = CreateEvent (NULL, TRUE, FALSE, NULL);
|
|
344 /* hev_unsleep is a manual-reset event, initially nonsignaled */
|
|
345 s->thread_data->hev_unsleep = CreateEvent (NULL, TRUE, FALSE, NULL);
|
|
346
|
|
347 /* Now let it go */
|
|
348 ResumeThread (hthread);
|
|
349 CloseHandle (hthread);
|
|
350
|
|
351 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
|
|
352 XSETLSTREAM (obj, lstr);
|
|
353 return obj;
|
|
354 }
|
|
355
|
|
356 static LPARAM
|
|
357 get_ntpipe_input_stream_param (Lstream *stream)
|
|
358 {
|
|
359 struct ntpipe_slurp_stream* s = NTPIPE_SLURP_STREAM_DATA(stream);
|
|
360 return s->user_data;
|
|
361 }
|
|
362
|
|
363 static HANDLE
|
|
364 get_ntpipe_input_stream_waitable (Lstream *stream)
|
|
365 {
|
|
366 struct ntpipe_slurp_stream* s = NTPIPE_SLURP_STREAM_DATA(stream);
|
|
367 return s->thread_data->hev_caller;
|
|
368 }
|
|
369
|
647
|
370 static Lstream_Data_Count
|
462
|
371 ntpipe_slurp_reader (Lstream *stream, unsigned char *data,
|
647
|
372 Lstream_Data_Count size)
|
428
|
373 {
|
|
374 /* This function must be called from the main thread only */
|
|
375 struct ntpipe_slurp_stream_shared_data* s =
|
|
376 NTPIPE_SLURP_STREAM_DATA(stream)->thread_data;
|
|
377
|
|
378 if (!s->die_p)
|
|
379 {
|
|
380 DWORD wait_result;
|
|
381 /* Disallow pipe read delay for the thread: we need a character
|
|
382 ASAP */
|
|
383 SetEvent (s->hev_unsleep);
|
|
384
|
|
385 /* Check if we have a character ready. Give it a short delay,
|
|
386 for the thread to awake from pipe delay, just ion case*/
|
|
387 wait_result = WaitForSingleObject (s->hev_caller, 2);
|
|
388
|
|
389 /* Revert to the normal sleep behavior. */
|
|
390 ResetEvent (s->hev_unsleep);
|
|
391
|
|
392 /* If there's no byte buffered yet, give up */
|
|
393 if (wait_result == WAIT_TIMEOUT)
|
|
394 {
|
|
395 errno = EAGAIN;
|
|
396 return -1;
|
|
397 }
|
|
398 }
|
|
399
|
|
400 /* Reset caller unlock event now, as we've handled the pending
|
|
401 process output event */
|
|
402 ResetEvent (s->hev_caller);
|
|
403
|
|
404 /* It is now safe to do anything with contents of S, except for
|
|
405 changing s->die_p, which still should be interlocked */
|
|
406
|
|
407 if (s->eof_p)
|
|
408 return 0;
|
|
409 if (s->error_p || s->die_p)
|
|
410 return -1;
|
|
411
|
|
412 /* Ok, there were no error neither eof - we've got a byte from the
|
|
413 pipe */
|
|
414 *(data++) = s->onebyte;
|
|
415 --size;
|
|
416
|
|
417 {
|
|
418 DWORD bytes_read = 0;
|
|
419 if (size > 0)
|
|
420 {
|
|
421 DWORD bytes_available;
|
|
422
|
|
423 /* If the api call fails, return at least one byte already
|
|
424 read. ReadFile in thread will return error */
|
|
425 if (PeekNamedPipe (s->hpipe, NULL, 0, NULL, &bytes_available, NULL))
|
|
426 {
|
|
427
|
|
428 /* Fetch available bytes. The same consideration applies,
|
|
429 so do not check for errors. ReadFile in the thread will
|
|
430 fail if the next call fails. */
|
|
431 if (bytes_available)
|
647
|
432 ReadFile (s->hpipe, data, min (bytes_available, (DWORD) size),
|
428
|
433 &bytes_read, NULL);
|
|
434 }
|
|
435
|
|
436 /* Now we can unblock thread, so it attempts to read more */
|
|
437 SetEvent (s->hev_thread);
|
|
438 return bytes_read + 1;
|
|
439 }
|
|
440 }
|
|
441 return 0;
|
|
442 }
|
|
443
|
|
444 static int
|
|
445 ntpipe_slurp_closer (Lstream *stream)
|
|
446 {
|
|
447 /* This function must be called from the main thread only */
|
|
448 struct ntpipe_slurp_stream_shared_data* s =
|
|
449 NTPIPE_SLURP_STREAM_DATA(stream)->thread_data;
|
|
450
|
|
451 /* Force thread to stop */
|
|
452 InterlockedIncrement (&s->die_p);
|
|
453
|
|
454 /* Set events which could possibly block slurper. Let it finish soon
|
|
455 or later. */
|
|
456 SetEvent (s->hev_unsleep);
|
|
457 SetEvent (s->hev_thread);
|
|
458
|
|
459 /* Unlock and maybe free shared data */
|
|
460 slurper_free_shared_data_maybe (s);
|
|
461
|
|
462 return 0;
|
|
463 }
|
|
464
|
|
465 static void
|
|
466 init_slurp_stream (void)
|
|
467 {
|
|
468 LSTREAM_HAS_METHOD (ntpipe_slurp, reader);
|
|
469 LSTREAM_HAS_METHOD (ntpipe_slurp, closer);
|
|
470 }
|
|
471
|
|
472 /************************************************************************/
|
|
473 /* Pipe outstream - writes process input */
|
|
474 /************************************************************************/
|
|
475
|
|
476 #define NTPIPE_SHOVE_STREAM_DATA(stream) \
|
|
477 LSTREAM_TYPE_DATA (stream, ntpipe_shove)
|
|
478
|
442
|
479 #define MAX_SHOVE_BUFFER_SIZE 512
|
428
|
480
|
|
481 struct ntpipe_shove_stream
|
|
482 {
|
|
483 LPARAM user_data; /* Any user data stored in the stream object */
|
|
484 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */
|
442
|
485 /* This is an auto-reset object. */
|
428
|
486 HANDLE hpipe; /* Pipe write end handle. */
|
|
487 HANDLE hthread; /* Reader thread handle. */
|
|
488 char buffer[MAX_SHOVE_BUFFER_SIZE]; /* Buffer being written */
|
|
489 DWORD size; /* Number of bytes to write */
|
|
490 LONG die_p; /* Thread must exit ASAP if non-zero */
|
|
491 LONG idle_p; /* Non-zero if thread is waiting for job */
|
|
492 BOOL error_p : 1; /* Read error other than EOF/broken pipe */
|
|
493 BOOL blocking_p : 1;/* Last write attempt would cause blocking */
|
|
494 };
|
|
495
|
|
496 DEFINE_LSTREAM_IMPLEMENTATION ("ntpipe-output", lstream_ntpipe_shove,
|
|
497 sizeof (struct ntpipe_shove_stream));
|
|
498
|
|
499 #ifndef HAVE_MSG_SELECT
|
|
500 static DWORD WINAPI
|
|
501 shove_thread (LPVOID vparam)
|
|
502 {
|
|
503 struct ntpipe_shove_stream *s = (struct ntpipe_shove_stream*) vparam;
|
|
504
|
|
505 for (;;)
|
|
506 {
|
|
507 DWORD bytes_written;
|
|
508
|
|
509 /* Block on event and wait for a job */
|
|
510 InterlockedIncrement (&s->idle_p);
|
|
511 WaitForSingleObject (s->hev_thread, INFINITE);
|
|
512
|
442
|
513 /* Write passed buffer if any */
|
|
514 if (s->size > 0)
|
428
|
515 {
|
442
|
516 if (!WriteFile (s->hpipe, s->buffer, s->size, &bytes_written, NULL)
|
|
517 || bytes_written != s->size)
|
|
518 {
|
|
519 s->error_p = TRUE;
|
|
520 InterlockedIncrement (&s->die_p);
|
|
521 }
|
|
522 /* Set size to zero so we won't write it again if the closer sets
|
|
523 die_p and kicks us */
|
|
524 s->size = 0;
|
428
|
525 }
|
|
526
|
|
527 if (s->die_p)
|
|
528 break;
|
|
529 }
|
|
530
|
|
531 return 0;
|
|
532 }
|
|
533
|
|
534 static Lisp_Object
|
|
535 make_ntpipe_output_stream (HANDLE hpipe, LPARAM param)
|
|
536 {
|
|
537 Lisp_Object obj;
|
|
538 Lstream *lstr = Lstream_new (lstream_ntpipe_shove, "w");
|
|
539 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA (lstr);
|
|
540 DWORD thread_id_unused;
|
|
541
|
|
542 s->die_p = 0;
|
|
543 s->error_p = FALSE;
|
|
544 s->hpipe = hpipe;
|
|
545 s->user_data = param;
|
|
546
|
|
547 /* Create reader thread. This could fail, so do not
|
|
548 create the event until thread is created */
|
|
549 s->hthread = CreateThread (NULL, 0, shove_thread, (LPVOID)s,
|
|
550 CREATE_SUSPENDED, &thread_id_unused);
|
|
551 if (s->hthread == NULL)
|
|
552 {
|
|
553 Lstream_delete (lstr);
|
|
554 return Qnil;
|
|
555 }
|
|
556
|
442
|
557 /* Set the priority of the thread higher so we don't end up waiting
|
|
558 on it to send things. */
|
|
559 if (!SetThreadPriority (s->hthread, THREAD_PRIORITY_HIGHEST))
|
|
560 {
|
|
561 CloseHandle (s->hthread);
|
|
562 Lstream_delete (lstr);
|
|
563 return Qnil;
|
|
564 }
|
|
565
|
428
|
566 /* hev_thread is an auto-reset event, initially nonsignaled */
|
|
567 s->hev_thread = CreateEvent (NULL, FALSE, FALSE, NULL);
|
|
568
|
|
569 /* Now let it go */
|
|
570 ResumeThread (s->hthread);
|
|
571
|
|
572 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
|
|
573 XSETLSTREAM (obj, lstr);
|
|
574 return obj;
|
|
575 }
|
|
576
|
|
577 static LPARAM
|
|
578 get_ntpipe_output_stream_param (Lstream *stream)
|
|
579 {
|
|
580 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream);
|
|
581 return s->user_data;
|
|
582 }
|
|
583 #endif
|
|
584
|
647
|
585 static Lstream_Data_Count
|
462
|
586 ntpipe_shove_writer (Lstream *stream, const unsigned char *data,
|
647
|
587 Lstream_Data_Count size)
|
428
|
588 {
|
|
589 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream);
|
|
590
|
|
591 if (s->error_p)
|
|
592 return -1;
|
|
593
|
|
594 s->blocking_p = !s->idle_p;
|
|
595 if (s->blocking_p)
|
|
596 return 0;
|
|
597
|
|
598 if (size>MAX_SHOVE_BUFFER_SIZE)
|
|
599 return 0;
|
|
600
|
|
601 memcpy (s->buffer, data, size);
|
|
602 s->size = size;
|
|
603
|
|
604 /* Start output */
|
|
605 InterlockedDecrement (&s->idle_p);
|
|
606 SetEvent (s->hev_thread);
|
442
|
607 /* Give it a chance to run -- this dramatically improves performance
|
|
608 of things like crypt. */
|
|
609 if (xSwitchToThread) /* not in Win9x or NT 3.51 */
|
|
610 (void) xSwitchToThread ();
|
428
|
611 return size;
|
|
612 }
|
|
613
|
|
614 static int
|
|
615 ntpipe_shove_was_blocked_p (Lstream *stream)
|
|
616 {
|
|
617 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream);
|
|
618 return s->blocking_p;
|
|
619 }
|
|
620
|
|
621 static int
|
|
622 ntpipe_shove_closer (Lstream *stream)
|
|
623 {
|
|
624 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream);
|
|
625
|
|
626 /* Force thread stop */
|
|
627 InterlockedIncrement (&s->die_p);
|
|
628
|
442
|
629 /* Thread will end upon unblocking. If it's already unblocked this will
|
|
630 do nothing, but the thread won't look at die_p until it's written any
|
|
631 pending output. */
|
428
|
632 SetEvent (s->hev_thread);
|
|
633
|
|
634 /* Wait while thread terminates */
|
|
635 WaitForSingleObject (s->hthread, INFINITE);
|
442
|
636
|
|
637 /* Close pipe handle, possibly breaking it */
|
|
638 CloseHandle (s->hpipe);
|
|
639
|
|
640 /* Close the thread handle */
|
428
|
641 CloseHandle (s->hthread);
|
|
642
|
|
643 /* Destroy the event */
|
|
644 CloseHandle (s->hev_thread);
|
|
645
|
|
646 return 0;
|
|
647 }
|
|
648
|
|
649 static void
|
|
650 init_shove_stream (void)
|
|
651 {
|
|
652 LSTREAM_HAS_METHOD (ntpipe_shove, writer);
|
|
653 LSTREAM_HAS_METHOD (ntpipe_shove, was_blocked_p);
|
|
654 LSTREAM_HAS_METHOD (ntpipe_shove, closer);
|
|
655 }
|
|
656
|
|
657 /************************************************************************/
|
|
658 /* Winsock I/O stream */
|
|
659 /************************************************************************/
|
|
660 #if defined (HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
|
|
661
|
|
662 #define WINSOCK_READ_BUFFER_SIZE 1024
|
|
663
|
|
664 struct winsock_stream
|
|
665 {
|
|
666 LPARAM user_data; /* Any user data stored in the stream object */
|
|
667 SOCKET s; /* Socket handle (which is a Win32 handle) */
|
|
668 OVERLAPPED ov; /* Overlapped I/O structure */
|
647
|
669 void *buffer; /* Buffer. */
|
|
670 DWORD bufsize; /* Number of bytes last read */
|
|
671 DWORD bufpos; /* Position in buffer for next fetch */
|
428
|
672 unsigned int error_p :1; /* I/O Error seen */
|
|
673 unsigned int eof_p :1; /* EOF Error seen */
|
|
674 unsigned int pending_p :1; /* There is a pending I/O operation */
|
|
675 unsigned int blocking_p :1; /* Last write attempt would block */
|
|
676 };
|
|
677
|
|
678 #define WINSOCK_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, winsock)
|
|
679
|
|
680 DEFINE_LSTREAM_IMPLEMENTATION ("winsock", lstream_winsock,
|
|
681 sizeof (struct winsock_stream));
|
|
682
|
|
683 static void
|
|
684 winsock_initiate_read (struct winsock_stream *str)
|
|
685 {
|
|
686 ResetEvent (str->ov.hEvent);
|
|
687 str->bufpos = 0;
|
|
688
|
|
689 if (!ReadFile ((HANDLE)str->s, str->buffer, WINSOCK_READ_BUFFER_SIZE,
|
|
690 &str->bufsize, &str->ov))
|
|
691 {
|
|
692 if (GetLastError () == ERROR_IO_PENDING)
|
|
693 str->pending_p = 1;
|
|
694 else if (GetLastError () == ERROR_HANDLE_EOF)
|
|
695 str->eof_p = 1;
|
|
696 else
|
|
697 str->error_p = 1;
|
|
698 }
|
|
699 else if (str->bufsize == 0)
|
|
700 str->eof_p = 1;
|
|
701 }
|
|
702
|
647
|
703 static Lstream_Data_Count
|
|
704 winsock_reader (Lstream *stream, unsigned char *data, Lstream_Data_Count size)
|
428
|
705 {
|
|
706 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
|
|
707
|
|
708 /* If the current operation is not yet complete, there's nothing to
|
|
709 give back */
|
|
710 if (str->pending_p)
|
|
711 {
|
|
712 if (WaitForSingleObject (str->ov.hEvent, 0) == WAIT_TIMEOUT)
|
|
713 {
|
|
714 errno = EAGAIN;
|
|
715 return -1;
|
|
716 }
|
|
717 else
|
|
718 {
|
|
719 if (!GetOverlappedResult ((HANDLE)str->s, &str->ov, &str->bufsize, TRUE))
|
|
720 {
|
|
721 if (GetLastError() == ERROR_HANDLE_EOF)
|
|
722 str->bufsize = 0;
|
|
723 else
|
|
724 str->error_p = 1;
|
|
725 }
|
|
726 if (str->bufsize == 0)
|
|
727 str->eof_p = 1;
|
|
728 str->pending_p = 0;
|
|
729 }
|
|
730 }
|
|
731
|
|
732 if (str->eof_p)
|
|
733 return 0;
|
|
734 if (str->error_p)
|
|
735 return -1;
|
|
736
|
|
737 /* Return as much of buffer as we have */
|
647
|
738 size = min (size, (Lstream_Data_Count) (str->bufsize - str->bufpos));
|
428
|
739 memcpy (data, (void*)((BYTE*)str->buffer + str->bufpos), size);
|
|
740 str->bufpos += size;
|
|
741
|
|
742 /* Read more if buffer is exhausted */
|
|
743 if (str->bufsize == str->bufpos)
|
|
744 winsock_initiate_read (str);
|
|
745
|
|
746 return size;
|
|
747 }
|
|
748
|
647
|
749 static Lstream_Data_Count
|
462
|
750 winsock_writer (Lstream *stream, const unsigned char *data,
|
647
|
751 Lstream_Data_Count size)
|
428
|
752 {
|
|
753 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
|
|
754
|
|
755 if (str->pending_p)
|
|
756 {
|
|
757 if (WaitForSingleObject (str->ov.hEvent, 0) == WAIT_TIMEOUT)
|
|
758 {
|
|
759 str->blocking_p = 1;
|
|
760 return -1;
|
|
761 }
|
|
762 else
|
|
763 {
|
|
764 DWORD dw_unused;
|
|
765 if (!GetOverlappedResult ((HANDLE)str->s, &str->ov, &dw_unused, TRUE))
|
|
766 str->error_p = 1;
|
|
767 str->pending_p = 0;
|
|
768 }
|
|
769 }
|
|
770
|
|
771 str->blocking_p = 0;
|
|
772
|
|
773 if (str->error_p)
|
|
774 return -1;
|
|
775
|
|
776 if (size == 0)
|
|
777 return 0;
|
|
778
|
558
|
779 ResetEvent (str->ov.hEvent);
|
|
780
|
|
781 /* According to WriteFile docs, we must hold onto the data we pass to it
|
|
782 and not make any changes until it finishes -- which may not be until
|
|
783 the next time we get here, since we use asynchronous I/O. We have
|
|
784 in fact seen data loss as a result of not doing this. */
|
|
785 str->buffer = xrealloc (str->buffer, size);
|
|
786 memcpy (str->buffer, data, size);
|
|
787
|
560
|
788 /* According to MSDN WriteFile docs, the fourth parameter cannot be NULL
|
|
789 on Win95 even when doing an overlapped operation, as we are, where
|
|
790 the return value through that parameter is not meaningful. */
|
|
791 if (WriteFile ((HANDLE)str->s, str->buffer, size, &str->bufsize,
|
558
|
792 &str->ov)
|
|
793 || GetLastError() == ERROR_IO_PENDING)
|
|
794 str->pending_p = 1;
|
|
795 else
|
|
796 str->error_p = 1;
|
428
|
797
|
|
798 return str->error_p ? -1 : size;
|
|
799 }
|
|
800
|
|
801 static int
|
|
802 winsock_closer (Lstream *lstr)
|
|
803 {
|
|
804 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
|
|
805
|
|
806 if (lstr->flags & LSTREAM_FL_READ)
|
|
807 shutdown (str->s, 0);
|
|
808 else
|
|
809 shutdown (str->s, 1);
|
|
810
|
|
811 CloseHandle ((HANDLE)str->s);
|
|
812 if (str->pending_p)
|
|
813 WaitForSingleObject (str->ov.hEvent, INFINITE);
|
|
814
|
558
|
815 if (str->buffer)
|
560
|
816 {
|
|
817 xfree (str->buffer);
|
|
818 str->buffer = 0;
|
|
819 }
|
428
|
820
|
|
821 CloseHandle (str->ov.hEvent);
|
|
822 return 0;
|
|
823 }
|
|
824
|
|
825 static int
|
|
826 winsock_was_blocked_p (Lstream *stream)
|
|
827 {
|
|
828 struct winsock_stream *str = WINSOCK_STREAM_DATA (stream);
|
|
829 return str->blocking_p;
|
|
830 }
|
|
831
|
|
832 static Lisp_Object
|
442
|
833 make_winsock_stream_1 (SOCKET s, LPARAM param, const char *mode)
|
428
|
834 {
|
|
835 Lisp_Object obj;
|
|
836 Lstream *lstr = Lstream_new (lstream_winsock, mode);
|
|
837 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
|
|
838
|
558
|
839 xzero (*str);
|
428
|
840 str->s = s;
|
|
841 str->user_data = param;
|
|
842
|
|
843 str->ov.hEvent = CreateEvent (NULL, TRUE, FALSE, NULL);
|
|
844
|
|
845 if (lstr->flags & LSTREAM_FL_READ)
|
|
846 {
|
|
847 str->buffer = xmalloc (WINSOCK_READ_BUFFER_SIZE);
|
|
848 winsock_initiate_read (str);
|
|
849 }
|
|
850
|
|
851 lstr->flags |= LSTREAM_FL_CLOSE_AT_DISKSAVE;
|
|
852 XSETLSTREAM (obj, lstr);
|
|
853 return obj;
|
|
854 }
|
|
855
|
|
856 static Lisp_Object
|
|
857 make_winsock_input_stream (SOCKET s, LPARAM param)
|
|
858 {
|
|
859 return make_winsock_stream_1 (s, param, "r");
|
|
860 }
|
|
861
|
|
862 static Lisp_Object
|
|
863 make_winsock_output_stream (SOCKET s, LPARAM param)
|
|
864 {
|
|
865 return make_winsock_stream_1 (s, param, "w");
|
|
866 }
|
|
867
|
|
868 static HANDLE
|
|
869 get_winsock_stream_waitable (Lstream *lstr)
|
|
870 {
|
|
871 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
|
|
872 return str->ov.hEvent;
|
|
873 }
|
|
874
|
|
875 static LPARAM
|
|
876 get_winsock_stream_param (Lstream *lstr)
|
|
877 {
|
|
878 struct winsock_stream *str = WINSOCK_STREAM_DATA (lstr);
|
|
879 return str->user_data;
|
|
880 }
|
|
881
|
|
882 static void
|
|
883 init_winsock_stream (void)
|
|
884 {
|
|
885 LSTREAM_HAS_METHOD (winsock, reader);
|
|
886 LSTREAM_HAS_METHOD (winsock, writer);
|
|
887 LSTREAM_HAS_METHOD (winsock, closer);
|
|
888 LSTREAM_HAS_METHOD (winsock, was_blocked_p);
|
|
889 }
|
|
890 #endif /* defined (HAVE_SOCKETS) */
|
|
891
|
|
892 /************************************************************************/
|
|
893 /* Dispatch queue management */
|
|
894 /************************************************************************/
|
|
895
|
|
896 static int
|
440
|
897 mswindows_user_event_p (Lisp_Event* sevt)
|
428
|
898 {
|
|
899 return (sevt->event_type == key_press_event
|
|
900 || sevt->event_type == button_press_event
|
|
901 || sevt->event_type == button_release_event
|
|
902 || sevt->event_type == misc_user_event);
|
|
903 }
|
|
904
|
|
905 /*
|
|
906 * Add an emacs event to the proper dispatch queue
|
|
907 */
|
442
|
908 void
|
428
|
909 mswindows_enqueue_dispatch_event (Lisp_Object event)
|
|
910 {
|
|
911 int user_p = mswindows_user_event_p (XEVENT(event));
|
|
912 enqueue_event (event,
|
|
913 user_p ? &mswindows_u_dispatch_event_queue :
|
442
|
914 &mswindows_s_dispatch_event_queue,
|
428
|
915 user_p ? &mswindows_u_dispatch_event_queue_tail :
|
442
|
916 &mswindows_s_dispatch_event_queue_tail);
|
428
|
917
|
|
918 /* Avoid blocking on WaitMessage */
|
|
919 PostMessage (NULL, XM_BUMPQUEUE, 0, 0);
|
|
920 }
|
|
921
|
|
922 /*
|
|
923 * Add a misc-user event to the dispatch queue.
|
|
924 *
|
|
925 * Stuff it into our own dispatch queue, so we have something
|
|
926 * to return from next_event callback.
|
|
927 */
|
|
928 void
|
|
929 mswindows_enqueue_misc_user_event (Lisp_Object channel, Lisp_Object function,
|
|
930 Lisp_Object object)
|
|
931 {
|
|
932 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
440
|
933 Lisp_Event* e = XEVENT (event);
|
428
|
934
|
|
935 e->event_type = misc_user_event;
|
|
936 e->channel = channel;
|
440
|
937 e->timestamp = GetTickCount ();
|
428
|
938 e->event.misc.function = function;
|
|
939 e->event.misc.object = object;
|
|
940
|
|
941 mswindows_enqueue_dispatch_event (event);
|
|
942 }
|
|
943
|
|
944 void
|
440
|
945 mswindows_enqueue_magic_event (HWND hwnd, UINT msg)
|
428
|
946 {
|
|
947 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
440
|
948 Lisp_Event* event = XEVENT (emacs_event);
|
428
|
949
|
|
950 event->channel = hwnd ? mswindows_find_frame (hwnd) : Qnil;
|
|
951 event->timestamp = GetMessageTime();
|
|
952 event->event_type = magic_event;
|
440
|
953 EVENT_MSWINDOWS_MAGIC_TYPE (event) = msg;
|
428
|
954
|
|
955 mswindows_enqueue_dispatch_event (emacs_event);
|
|
956 }
|
|
957
|
|
958 static void
|
440
|
959 mswindows_enqueue_process_event (Lisp_Process* p)
|
428
|
960 {
|
|
961 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
440
|
962 Lisp_Event* event = XEVENT (emacs_event);
|
428
|
963 Lisp_Object process;
|
|
964 XSETPROCESS (process, p);
|
|
965
|
|
966 event->event_type = process_event;
|
|
967 event->timestamp = GetTickCount ();
|
|
968 event->event.process.process = process;
|
|
969
|
|
970 mswindows_enqueue_dispatch_event (emacs_event);
|
|
971 }
|
|
972
|
|
973 static void
|
442
|
974 mswindows_enqueue_mouse_button_event (HWND hwnd, UINT msg, POINTS where,
|
|
975 int mods, DWORD when)
|
428
|
976 {
|
442
|
977 int downp = (msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN ||
|
|
978 msg == WM_RBUTTONDOWN);
|
428
|
979
|
|
980 /* We always use last message time, because mouse button
|
|
981 events may get delayed, and XEmacs double click
|
|
982 recognition will fail */
|
|
983
|
|
984 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
442
|
985 Lisp_Event* event = XEVENT (emacs_event);
|
|
986
|
|
987 mswindows_handle_sticky_modifiers (0, 0, downp, 0);
|
|
988 event->channel = mswindows_find_frame (hwnd);
|
428
|
989 event->timestamp = when;
|
|
990 event->event.button.button =
|
440
|
991 (msg==WM_LBUTTONDOWN || msg==WM_LBUTTONUP) ? 1 :
|
|
992 ((msg==WM_RBUTTONDOWN || msg==WM_RBUTTONUP) ? 3 : 2);
|
428
|
993 event->event.button.x = where.x;
|
|
994 event->event.button.y = where.y;
|
442
|
995 event->event.button.modifiers = mswindows_modifier_state (NULL, mods, 0);
|
|
996
|
|
997 if (downp)
|
428
|
998 {
|
|
999 event->event_type = button_press_event;
|
|
1000 SetCapture (hwnd);
|
|
1001 /* we need this to make sure the main window regains the focus
|
|
1002 from control subwindows */
|
|
1003 if (GetFocus() != hwnd)
|
|
1004 {
|
|
1005 SetFocus (hwnd);
|
|
1006 mswindows_enqueue_magic_event (hwnd, WM_SETFOCUS);
|
|
1007 }
|
|
1008 }
|
|
1009 else
|
|
1010 {
|
|
1011 event->event_type = button_release_event;
|
|
1012 ReleaseCapture ();
|
|
1013 }
|
|
1014
|
|
1015 mswindows_enqueue_dispatch_event (emacs_event);
|
|
1016 }
|
|
1017
|
|
1018 static void
|
|
1019 mswindows_enqueue_keypress_event (HWND hwnd, Lisp_Object keysym, int mods)
|
|
1020 {
|
|
1021 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
440
|
1022 Lisp_Event* event = XEVENT(emacs_event);
|
428
|
1023
|
|
1024 event->channel = mswindows_find_console(hwnd);
|
|
1025 event->timestamp = GetMessageTime();
|
|
1026 event->event_type = key_press_event;
|
|
1027 event->event.key.keysym = keysym;
|
|
1028 event->event.key.modifiers = mods;
|
|
1029 mswindows_enqueue_dispatch_event (emacs_event);
|
|
1030 }
|
|
1031
|
|
1032 /*
|
|
1033 * Remove and return the first emacs event on the dispatch queue.
|
|
1034 * Give a preference to user events over non-user ones.
|
|
1035 */
|
|
1036 static Lisp_Object
|
442
|
1037 mswindows_dequeue_dispatch_event (void)
|
428
|
1038 {
|
|
1039 Lisp_Object event;
|
440
|
1040 Lisp_Event* sevt;
|
428
|
1041
|
|
1042 assert (!NILP(mswindows_u_dispatch_event_queue) ||
|
|
1043 !NILP(mswindows_s_dispatch_event_queue));
|
|
1044
|
|
1045 event = dequeue_event (
|
442
|
1046 NILP(mswindows_u_dispatch_event_queue) ?
|
428
|
1047 &mswindows_s_dispatch_event_queue :
|
|
1048 &mswindows_u_dispatch_event_queue,
|
442
|
1049 NILP(mswindows_u_dispatch_event_queue) ?
|
428
|
1050 &mswindows_s_dispatch_event_queue_tail :
|
|
1051 &mswindows_u_dispatch_event_queue_tail);
|
|
1052
|
593
|
1053 sevt = XEVENT (event);
|
428
|
1054 if (sevt->event_type == key_press_event
|
|
1055 && (sevt->event.key.modifiers & FAKE_MOD_QUIT))
|
593
|
1056 sevt->event.key.modifiers &=
|
|
1057 ~(FAKE_MOD_QUIT | FAKE_MOD_QUIT_CRITICAL);
|
428
|
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)
|
563
|
1371 invalid_operation ("Deadlock due to an attempt to call next-event in a wrong context", Qunbound);
|
428
|
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 while (NILP (mswindows_u_dispatch_event_queue)
|
|
1390 && NILP (mswindows_s_dispatch_event_queue))
|
|
1391 {
|
|
1392 #ifdef HAVE_MSG_SELECT
|
|
1393 int i;
|
647
|
1394 int active;
|
428
|
1395 SELECT_TYPE temp_mask = input_wait_mask;
|
|
1396 EMACS_TIME sometime;
|
|
1397 EMACS_SELECT_TIME select_time_to_block, *pointer_to_this;
|
|
1398
|
|
1399 if (badly_p)
|
|
1400 pointer_to_this = 0;
|
|
1401 else
|
|
1402 {
|
|
1403 EMACS_SET_SECS_USECS (sometime, 0, 0);
|
|
1404 EMACS_TIME_TO_SELECT_TIME (sometime, select_time_to_block);
|
|
1405 pointer_to_this = &select_time_to_block;
|
534
|
1406 if (mswindows_in_modal_loop)
|
|
1407 /* In modal loop with badly_p false, don't care about
|
|
1408 Windows events. */
|
|
1409 FD_CLR (windows_fd, &temp_mask);
|
428
|
1410 }
|
|
1411
|
|
1412 active = select (MAXDESC, &temp_mask, 0, 0, pointer_to_this);
|
|
1413
|
|
1414 if (active == 0)
|
|
1415 {
|
|
1416 assert (!badly_p);
|
|
1417 return; /* timeout */
|
|
1418 }
|
|
1419 else if (active > 0)
|
|
1420 {
|
|
1421 if (FD_ISSET (windows_fd, &temp_mask))
|
|
1422 {
|
534
|
1423 if (mswindows_in_modal_loop)
|
|
1424 mswindows_need_event_in_modal_loop (badly_p);
|
|
1425 else
|
|
1426 mswindows_drain_windows_queue ();
|
428
|
1427 }
|
442
|
1428 else
|
428
|
1429 {
|
442
|
1430 #ifdef HAVE_TTY
|
|
1431 /* Look for a TTY event */
|
|
1432 for (i = 0; i < MAXDESC-1; i++)
|
428
|
1433 {
|
442
|
1434 /* To avoid race conditions (among other things, an infinite
|
|
1435 loop when called from Fdiscard_input()), we must return
|
|
1436 user events ahead of process events. */
|
|
1437 if (FD_ISSET (i, &temp_mask) && FD_ISSET (i, &tty_only_mask))
|
428
|
1438 {
|
442
|
1439 struct console *c = tty_find_console_from_fd (i);
|
|
1440 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
1441 Lisp_Event* event = XEVENT (emacs_event);
|
|
1442
|
|
1443 assert (c);
|
|
1444 if (read_event_from_tty_or_stream_desc (event, c, i))
|
|
1445 {
|
|
1446 mswindows_enqueue_dispatch_event (emacs_event);
|
|
1447 return;
|
|
1448 }
|
428
|
1449 }
|
|
1450 }
|
|
1451 #endif
|
442
|
1452 /* Look for a process event */
|
|
1453 for (i = 0; i < MAXDESC-1; i++)
|
428
|
1454 {
|
442
|
1455 if (FD_ISSET (i, &temp_mask))
|
428
|
1456 {
|
442
|
1457 if (FD_ISSET (i, &process_only_mask))
|
|
1458 {
|
|
1459 Lisp_Process *p =
|
|
1460 get_process_from_usid (FD_TO_USID(i));
|
|
1461
|
|
1462 mswindows_enqueue_process_event (p);
|
|
1463 }
|
|
1464 else
|
|
1465 {
|
|
1466 /* We might get here when a fake event came
|
|
1467 through a signal. Return a dummy event, so
|
|
1468 that a cycle of the command loop will
|
|
1469 occur. */
|
|
1470 drain_signal_event_pipe ();
|
|
1471 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
|
|
1472 }
|
428
|
1473 }
|
|
1474 }
|
|
1475 }
|
|
1476 }
|
|
1477 else if (active==-1)
|
|
1478 {
|
|
1479 if (errno != EINTR)
|
|
1480 {
|
|
1481 /* something bad happened */
|
|
1482 assert(0);
|
|
1483 }
|
|
1484 }
|
|
1485 else
|
|
1486 {
|
|
1487 assert(0);
|
|
1488 }
|
647
|
1489 #else /* not HAVE_MSG_SELECT */
|
428
|
1490 /* Now try getting a message or process event */
|
647
|
1491 DWORD active;
|
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 }
|
647
|
1573 #endif /* not HAVE_MSG_SELECT */
|
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;
|
647
|
2062 struct mswindows_frame *msframe;
|
428
|
2063
|
611
|
2064 /* If you hit this, rewrite the offending API call to occur after GC,
|
|
2065 using register_post_gc_action(). */
|
|
2066 assert (!gc_in_progress);
|
593
|
2067
|
|
2068 #ifdef DEBUG_XEMACS
|
|
2069 if (debug_mswindows_events)
|
|
2070 debug_output_mswin_message (hwnd, message_, wParam, lParam);
|
|
2071 #endif /* DEBUG_XEMACS */
|
442
|
2072
|
|
2073 assert (!GetWindowLong (hwnd, GWL_USERDATA));
|
|
2074 switch (message_)
|
428
|
2075 {
|
442
|
2076 case WM_DESTROYCLIPBOARD:
|
|
2077 /* We own the clipboard and someone else wants it. Delete our
|
|
2078 cached copy of the clipboard contents so we'll ask for it from
|
|
2079 Windows again when someone does a paste, and destroy any memory
|
|
2080 objects we hold on the clipboard that are not in the list of types
|
|
2081 that Windows will delete itself. */
|
|
2082 mswindows_destroy_selection (QCLIPBOARD);
|
|
2083 handle_selection_clear (QCLIPBOARD);
|
|
2084 break;
|
|
2085
|
|
2086 case WM_ERASEBKGND:
|
|
2087 /* Erase background only during non-dynamic sizing */
|
|
2088 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
2089 if (msframe->sizing && !mswindows_dynamic_frame_resize)
|
|
2090 goto defproc;
|
|
2091 return 1;
|
|
2092
|
|
2093 case WM_CLOSE:
|
|
2094 fobj = mswindows_find_frame (hwnd);
|
|
2095 mswindows_enqueue_misc_user_event (fobj, Qeval, list3 (Qdelete_frame, fobj, Qt));
|
440
|
2096 break;
|
428
|
2097
|
442
|
2098 case WM_KEYUP:
|
|
2099 case WM_SYSKEYUP:
|
|
2100
|
|
2101 /* See Win95 comment under WM_KEYDOWN */
|
|
2102 {
|
|
2103 BYTE keymap[256];
|
|
2104 int should_set_keymap = 0;
|
|
2105
|
|
2106 #ifdef DEBUG_XEMACS
|
593
|
2107 if (debug_mswindows_events > 2)
|
|
2108 output_alt_keyboard_state ();
|
442
|
2109 #endif /* DEBUG_XEMACS */
|
|
2110
|
|
2111 mswindows_handle_sticky_modifiers (wParam, lParam, 0, 1);
|
|
2112 if (wParam == VK_CONTROL)
|
|
2113 {
|
|
2114 GetKeyboardState (keymap);
|
|
2115 keymap [(lParam & 0x1000000) ? VK_RCONTROL : VK_LCONTROL] &= ~0x80;
|
|
2116 should_set_keymap = 1;
|
|
2117 }
|
|
2118 else if (wParam == VK_MENU)
|
|
2119 {
|
|
2120 GetKeyboardState (keymap);
|
|
2121 keymap [(lParam & 0x1000000) ? VK_RMENU : VK_LMENU] &= ~0x80;
|
|
2122 should_set_keymap = 1;
|
|
2123 }
|
|
2124
|
|
2125 if (should_set_keymap)
|
|
2126 // && (message_ != WM_SYSKEYUP
|
|
2127 // || NILP (Vmenu_accelerator_enabled)))
|
428
|
2128 SetKeyboardState (keymap);
|
|
2129
|
|
2130 }
|
442
|
2131
|
|
2132 if (key_needs_default_processing_p (wParam))
|
|
2133 goto defproc;
|
|
2134 else
|
|
2135 break;
|
|
2136
|
|
2137 case WM_KEYDOWN:
|
|
2138 case WM_SYSKEYDOWN:
|
|
2139
|
|
2140 /* In some locales the right-hand Alt key is labelled AltGr. This key
|
|
2141 * should produce alternative characters when combined with another key.
|
|
2142 * eg on a German keyboard pressing AltGr+q should produce '@'.
|
|
2143 * AltGr generates exactly the same keystrokes as LCtrl+RAlt. But if
|
|
2144 * TranslateMessage() is called with *any* combination of Ctrl+Alt down,
|
|
2145 * it translates as if AltGr were down.
|
|
2146 * We get round this by removing all modifiers from the keymap before
|
|
2147 * calling TranslateMessage() unless AltGr is *really* down. */
|
428
|
2148 {
|
442
|
2149 BYTE keymap_trans[256];
|
|
2150 BYTE keymap_orig[256];
|
|
2151 BYTE keymap_sticky[256];
|
|
2152 int has_AltGr = mswindows_current_layout_has_AltGr ();
|
502
|
2153 int mods = 0, mods_with_shift = 0;
|
442
|
2154 int extendedp = lParam & 0x1000000;
|
|
2155 Lisp_Object keysym;
|
|
2156 int sticky_changed;
|
|
2157
|
|
2158 #ifdef DEBUG_XEMACS
|
593
|
2159 if (debug_mswindows_events > 2)
|
|
2160 output_alt_keyboard_state ();
|
442
|
2161 #endif /* DEBUG_XEMACS */
|
|
2162
|
|
2163 GetKeyboardState (keymap_orig);
|
|
2164 frame = XFRAME (mswindows_find_frame (hwnd));
|
|
2165 if ((sticky_changed =
|
|
2166 mswindows_handle_sticky_modifiers (wParam, lParam, 1, 1)))
|
428
|
2167 {
|
442
|
2168 GetKeyboardState (keymap_sticky);
|
|
2169 if (keymap_sticky[VK_MENU] & 0x80)
|
|
2170 {
|
|
2171 message_ = WM_SYSKEYDOWN;
|
|
2172 /* We have to set the "context bit" so that the
|
|
2173 TranslateMessage() call below that generates the
|
|
2174 SYSCHAR message does its thing; see the documentation
|
|
2175 on WM_SYSKEYDOWN */
|
|
2176 lParam |= 1 << 29;
|
|
2177 }
|
428
|
2178 }
|
|
2179 else
|
442
|
2180 memcpy (keymap_sticky, keymap_orig, 256);
|
|
2181
|
|
2182 mods = mswindows_modifier_state (keymap_sticky, (DWORD) -1, has_AltGr);
|
502
|
2183 mods_with_shift = mods;
|
442
|
2184
|
|
2185 /* Handle non-printables */
|
|
2186 if (!NILP (keysym = mswindows_key_to_emacs_keysym (wParam, mods,
|
|
2187 extendedp)))
|
428
|
2188 {
|
442
|
2189 mswindows_enqueue_keypress_event (hwnd, keysym, mods);
|
|
2190 if (sticky_changed)
|
|
2191 SetKeyboardState (keymap_orig);
|
428
|
2192 }
|
442
|
2193 else /* Normal keys & modifiers */
|
428
|
2194 {
|
442
|
2195 Emchar quit_ch =
|
|
2196 CONSOLE_QUIT_CHAR (XCONSOLE (mswindows_find_console (hwnd)));
|
|
2197 POINT pnt = { LOWORD (GetMessagePos()), HIWORD (GetMessagePos()) };
|
|
2198 MSG msg, tranmsg;
|
|
2199 int potential_accelerator = 0;
|
|
2200 int got_accelerator = 0;
|
|
2201
|
|
2202 msg.hwnd = hwnd;
|
|
2203 msg.message = message_;
|
|
2204 msg.wParam = wParam;
|
|
2205 msg.lParam = lParam;
|
|
2206 msg.time = GetMessageTime();
|
|
2207 msg.pt = pnt;
|
|
2208
|
|
2209 /* GetKeyboardState() does not work as documented on Win95. We have
|
|
2210 * to loosely track Left and Right modifiers on behalf of the OS,
|
|
2211 * without screwing up Windows NT which tracks them properly. */
|
|
2212 if (wParam == VK_CONTROL)
|
|
2213 {
|
|
2214 keymap_orig[extendedp ? VK_RCONTROL : VK_LCONTROL] |= 0x80;
|
|
2215 keymap_sticky[extendedp ? VK_RCONTROL : VK_LCONTROL] |= 0x80;
|
|
2216 }
|
|
2217 else if (wParam == VK_MENU)
|
|
2218 {
|
|
2219 keymap_orig[extendedp ? VK_RMENU : VK_LMENU] |= 0x80;
|
|
2220 keymap_sticky[extendedp ? VK_RMENU : VK_LMENU] |= 0x80;
|
|
2221 }
|
|
2222
|
|
2223 if (!NILP (Vmenu_accelerator_enabled) &&
|
|
2224 !(mods & XEMACS_MOD_SHIFT) && message_ == WM_SYSKEYDOWN)
|
|
2225 potential_accelerator = 1;
|
|
2226
|
|
2227 /* Remove shift modifier from an ascii character */
|
|
2228 mods &= ~XEMACS_MOD_SHIFT;
|
|
2229
|
|
2230 memcpy (keymap_trans, keymap_sticky, 256);
|
|
2231
|
|
2232 /* Clear control and alt modifiers unless AltGr is pressed */
|
|
2233 keymap_trans[VK_RCONTROL] = 0;
|
|
2234 keymap_trans[VK_LMENU] = 0;
|
|
2235 if (!has_AltGr || !(keymap_trans[VK_LCONTROL] & 0x80)
|
|
2236 || !(keymap_trans[VK_RMENU] & 0x80))
|
|
2237 {
|
|
2238 keymap_trans[VK_LCONTROL] = 0;
|
|
2239 keymap_trans[VK_CONTROL] = 0;
|
|
2240 keymap_trans[VK_RMENU] = 0;
|
|
2241 keymap_trans[VK_MENU] = 0;
|
|
2242 }
|
|
2243 SetKeyboardState (keymap_trans);
|
|
2244
|
|
2245 /* Maybe generate some WM_[SYS]CHARs in the queue */
|
|
2246 TranslateMessage (&msg);
|
|
2247
|
|
2248 while (PeekMessage (&tranmsg, hwnd, WM_CHAR, WM_CHAR, PM_REMOVE)
|
|
2249 || PeekMessage (&tranmsg, hwnd, WM_SYSCHAR, WM_SYSCHAR,
|
|
2250 PM_REMOVE))
|
|
2251 {
|
502
|
2252 int mods_with_quit = mods;
|
647
|
2253 Emchar ch = (Emchar) tranmsg.wParam;
|
442
|
2254
|
593
|
2255 #ifdef DEBUG_XEMACS
|
|
2256 if (debug_mswindows_events)
|
|
2257 {
|
|
2258 stderr_out ("-> ");
|
|
2259 debug_output_mswin_message (tranmsg.hwnd, tranmsg.message,
|
|
2260 tranmsg.wParam,
|
|
2261 tranmsg.lParam);
|
|
2262 }
|
|
2263 #endif /* DEBUG_XEMACS */
|
|
2264
|
442
|
2265 /* If a quit char with no modifiers other than control and
|
|
2266 shift, then mark it with a fake modifier, which is removed
|
|
2267 upon dequeueing the event */
|
502
|
2268 /* !!#### Fix this in my mule ws -- replace current_buffer
|
|
2269 with 0 */
|
442
|
2270 if (((quit_ch < ' ' && (mods & XEMACS_MOD_CONTROL)
|
502
|
2271 && DOWNCASE (current_buffer, quit_ch + 'a' - 1) ==
|
|
2272 DOWNCASE (current_buffer, ch))
|
442
|
2273 || (quit_ch >= ' ' && !(mods & XEMACS_MOD_CONTROL)
|
502
|
2274 && DOWNCASE (current_buffer, quit_ch) ==
|
|
2275 DOWNCASE (current_buffer, ch)))
|
|
2276 && ((mods_with_shift &
|
|
2277 ~(XEMACS_MOD_CONTROL | XEMACS_MOD_SHIFT))
|
442
|
2278 == 0))
|
|
2279 {
|
502
|
2280 mods_with_quit |= FAKE_MOD_QUIT;
|
|
2281 if (mods_with_shift & XEMACS_MOD_SHIFT)
|
|
2282 mods_with_quit |= FAKE_MOD_QUIT_CRITICAL;
|
593
|
2283 mswindows_quit_chars_count++;
|
442
|
2284 }
|
|
2285 else if (potential_accelerator && !got_accelerator &&
|
|
2286 mswindows_char_is_accelerator (frame, ch))
|
|
2287 {
|
|
2288 got_accelerator = 1;
|
|
2289 break;
|
|
2290 }
|
502
|
2291 mswindows_enqueue_keypress_event (hwnd, make_char (ch),
|
|
2292 mods_with_quit);
|
442
|
2293 } /* while */
|
|
2294
|
|
2295 /* This generates WM_SYSCHAR messages, which are interpreted
|
|
2296 by DefWindowProc as the menu selections. */
|
|
2297 if (got_accelerator)
|
|
2298 {
|
|
2299 SetKeyboardState (keymap_sticky);
|
|
2300 TranslateMessage (&msg);
|
|
2301 SetKeyboardState (keymap_orig);
|
|
2302 goto defproc;
|
|
2303 }
|
|
2304
|
|
2305 SetKeyboardState (keymap_orig);
|
|
2306 } /* else */
|
428
|
2307 }
|
442
|
2308
|
|
2309 if (key_needs_default_processing_p (wParam))
|
|
2310 goto defproc;
|
|
2311 else
|
|
2312 break;
|
|
2313
|
|
2314 case WM_MBUTTONDOWN:
|
|
2315 case WM_MBUTTONUP:
|
|
2316 /* Real middle mouse button has nothing to do with emulated one:
|
|
2317 if one wants to exercise fingers playing chords on the mouse,
|
|
2318 he is allowed to do that! */
|
|
2319 mswindows_enqueue_mouse_button_event (hwnd, message_,
|
|
2320 MAKEPOINTS (lParam),
|
|
2321 wParam &~ MK_MBUTTON,
|
|
2322 GetMessageTime());
|
|
2323 break;
|
|
2324
|
|
2325 case WM_LBUTTONUP:
|
|
2326 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
2327 msframe->last_click_time = GetMessageTime();
|
|
2328
|
|
2329 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
2330 msframe->button2_need_lbutton = 0;
|
|
2331 if (msframe->ignore_next_lbutton_up)
|
|
2332 {
|
|
2333 msframe->ignore_next_lbutton_up = 0;
|
|
2334 }
|
|
2335 else if (msframe->button2_is_down)
|
|
2336 {
|
|
2337 msframe->button2_is_down = 0;
|
|
2338 msframe->ignore_next_rbutton_up = 1;
|
|
2339 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
|
|
2340 MAKEPOINTS (lParam),
|
|
2341 wParam
|
|
2342 &~ (MK_LBUTTON | MK_MBUTTON
|
|
2343 | MK_RBUTTON),
|
|
2344 GetMessageTime());
|
|
2345 }
|
|
2346 else
|
|
2347 {
|
|
2348 if (msframe->button2_need_rbutton)
|
|
2349 {
|
|
2350 msframe->button2_need_rbutton = 0;
|
|
2351 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
2352 MAKEPOINTS (lParam),
|
|
2353 wParam &~ MK_LBUTTON,
|
|
2354 GetMessageTime());
|
|
2355 }
|
|
2356 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONUP,
|
|
2357 MAKEPOINTS (lParam),
|
|
2358 wParam &~ MK_LBUTTON,
|
|
2359 GetMessageTime());
|
|
2360 }
|
|
2361 break;
|
|
2362
|
|
2363 case WM_RBUTTONUP:
|
|
2364 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
2365 msframe->last_click_time = GetMessageTime();
|
|
2366
|
|
2367 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
2368 msframe->button2_need_rbutton = 0;
|
|
2369 if (msframe->ignore_next_rbutton_up)
|
|
2370 {
|
|
2371 msframe->ignore_next_rbutton_up = 0;
|
|
2372 }
|
|
2373 else if (msframe->button2_is_down)
|
|
2374 {
|
|
2375 msframe->button2_is_down = 0;
|
|
2376 msframe->ignore_next_lbutton_up = 1;
|
|
2377 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
|
|
2378 MAKEPOINTS (lParam),
|
|
2379 wParam
|
|
2380 &~ (MK_LBUTTON | MK_MBUTTON
|
|
2381 | MK_RBUTTON),
|
|
2382 GetMessageTime());
|
|
2383 }
|
|
2384 else
|
|
2385 {
|
|
2386 if (msframe->button2_need_lbutton)
|
|
2387 {
|
|
2388 msframe->button2_need_lbutton = 0;
|
|
2389 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
2390 MAKEPOINTS (lParam),
|
|
2391 wParam &~ MK_RBUTTON,
|
|
2392 GetMessageTime());
|
|
2393 }
|
|
2394 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONUP,
|
|
2395 MAKEPOINTS (lParam),
|
|
2396 wParam &~ MK_RBUTTON,
|
|
2397 GetMessageTime());
|
|
2398 }
|
|
2399 break;
|
|
2400
|
|
2401 case WM_LBUTTONDOWN:
|
|
2402 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
2403
|
|
2404 if (msframe->button2_need_lbutton)
|
428
|
2405 {
|
|
2406 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
442
|
2407 msframe->button2_need_lbutton = 0;
|
|
2408 msframe->button2_need_rbutton = 0;
|
|
2409 if (mswindows_button2_near_enough (msframe->last_click_point,
|
|
2410 MAKEPOINTS (lParam)))
|
428
|
2411 {
|
442
|
2412 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
|
|
2413 MAKEPOINTS (lParam),
|
|
2414 wParam
|
|
2415 &~ (MK_LBUTTON | MK_MBUTTON
|
|
2416 | MK_RBUTTON),
|
|
2417 GetMessageTime());
|
|
2418 msframe->button2_is_down = 1;
|
428
|
2419 }
|
442
|
2420 else
|
428
|
2421 {
|
442
|
2422 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
2423 msframe->last_click_point,
|
|
2424 msframe->last_click_mods
|
|
2425 &~ MK_RBUTTON,
|
|
2426 msframe->last_click_time);
|
|
2427 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
2428 MAKEPOINTS (lParam),
|
|
2429 wParam &~ MK_LBUTTON,
|
|
2430 GetMessageTime());
|
428
|
2431 }
|
|
2432 }
|
|
2433 else
|
442
|
2434 {
|
|
2435 mswindows_set_chord_timer (hwnd);
|
|
2436 msframe->button2_need_rbutton = 1;
|
|
2437 msframe->last_click_point = MAKEPOINTS (lParam);
|
|
2438 msframe->last_click_mods = wParam;
|
|
2439 }
|
|
2440 msframe->last_click_time = GetMessageTime();
|
|
2441 break;
|
|
2442
|
|
2443 case WM_RBUTTONDOWN:
|
|
2444 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
2445
|
|
2446 if (msframe->button2_need_rbutton)
|
428
|
2447 {
|
442
|
2448 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
2449 msframe->button2_need_lbutton = 0;
|
|
2450 msframe->button2_need_rbutton = 0;
|
|
2451 if (mswindows_button2_near_enough (msframe->last_click_point,
|
|
2452 MAKEPOINTS (lParam)))
|
|
2453 {
|
|
2454 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
|
|
2455 MAKEPOINTS (lParam),
|
|
2456 wParam
|
|
2457 &~ (MK_LBUTTON | MK_MBUTTON
|
|
2458 | MK_RBUTTON),
|
|
2459 GetMessageTime());
|
|
2460 msframe->button2_is_down = 1;
|
|
2461 }
|
|
2462 else
|
|
2463 {
|
|
2464 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
2465 msframe->last_click_point,
|
|
2466 msframe->last_click_mods
|
|
2467 &~ MK_LBUTTON,
|
|
2468 msframe->last_click_time);
|
|
2469 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
2470 MAKEPOINTS (lParam),
|
|
2471 wParam &~ MK_RBUTTON,
|
|
2472 GetMessageTime());
|
|
2473 }
|
428
|
2474 }
|
|
2475 else
|
|
2476 {
|
442
|
2477 mswindows_set_chord_timer (hwnd);
|
|
2478 msframe->button2_need_lbutton = 1;
|
|
2479 msframe->last_click_point = MAKEPOINTS (lParam);
|
|
2480 msframe->last_click_mods = wParam;
|
|
2481 }
|
|
2482 msframe->last_click_time = GetMessageTime();
|
|
2483 break;
|
|
2484
|
|
2485 case WM_TIMER:
|
|
2486 if (wParam == BUTTON_2_TIMER_ID)
|
|
2487 {
|
|
2488 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
2489 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
2490
|
|
2491 if (msframe->button2_need_lbutton)
|
|
2492 {
|
|
2493 msframe->button2_need_lbutton = 0;
|
|
2494 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
2495 msframe->last_click_point,
|
|
2496 msframe->last_click_mods
|
|
2497 &~ MK_RBUTTON,
|
|
2498 msframe->last_click_time);
|
|
2499 }
|
|
2500 else if (msframe->button2_need_rbutton)
|
|
2501 {
|
|
2502 msframe->button2_need_rbutton = 0;
|
|
2503 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
2504 msframe->last_click_point,
|
|
2505 msframe->last_click_mods
|
|
2506 &~ MK_LBUTTON,
|
|
2507 msframe->last_click_time);
|
|
2508 }
|
|
2509 }
|
|
2510 else
|
|
2511 assert ("Spurious timer fired" == 0);
|
|
2512 break;
|
|
2513
|
|
2514 case WM_MOUSEMOVE:
|
|
2515 /* Optimization: don't report mouse movement while size is changing */
|
|
2516 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
2517 if (!msframe->sizing)
|
|
2518 {
|
|
2519 /* When waiting for the second mouse button to finish
|
|
2520 button2 emulation, and have moved too far, just pretend
|
|
2521 as if timer has expired. This improves drag-select feedback */
|
|
2522 if ((msframe->button2_need_lbutton || msframe->button2_need_rbutton)
|
|
2523 && !mswindows_button2_near_enough (msframe->last_click_point,
|
|
2524 MAKEPOINTS (lParam)))
|
428
|
2525 {
|
442
|
2526 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
2527 SendMessage (hwnd, WM_TIMER, BUTTON_2_TIMER_ID, 0);
|
|
2528 }
|
|
2529
|
|
2530 emacs_event = Fmake_event (Qnil, Qnil);
|
|
2531 event = XEVENT(emacs_event);
|
|
2532
|
|
2533 event->channel = mswindows_find_frame(hwnd);
|
|
2534 event->timestamp = GetMessageTime();
|
|
2535 event->event_type = pointer_motion_event;
|
|
2536 event->event.motion.x = MAKEPOINTS(lParam).x;
|
|
2537 event->event.motion.y = MAKEPOINTS(lParam).y;
|
|
2538 event->event.motion.modifiers =
|
|
2539 mswindows_modifier_state (NULL, wParam, 0);
|
|
2540
|
|
2541 mswindows_enqueue_dispatch_event (emacs_event);
|
|
2542 }
|
|
2543 break;
|
|
2544
|
|
2545 case WM_CANCELMODE:
|
|
2546 ReleaseCapture ();
|
|
2547 /* Queue a `cancel-mode-internal' misc user event, so mouse
|
|
2548 selection would be canceled if any */
|
|
2549 mswindows_enqueue_misc_user_event (mswindows_find_frame (hwnd),
|
|
2550 Qcancel_mode_internal, Qnil);
|
|
2551 break;
|
|
2552
|
|
2553 case WM_NOTIFY:
|
|
2554 {
|
647
|
2555 LPNMHDR nmhdr = (LPNMHDR) lParam;
|
|
2556
|
|
2557 if ((int) nmhdr->code == TTN_NEEDTEXT)
|
442
|
2558 {
|
|
2559 #ifdef HAVE_TOOLBARS
|
647
|
2560 LPTOOLTIPTEXT tttext = (LPTOOLTIPTEXT) lParam;
|
442
|
2561 Lisp_Object btext;
|
|
2562
|
|
2563 /* find out which toolbar */
|
|
2564 frame = XFRAME (mswindows_find_frame (hwnd));
|
647
|
2565 btext = mswindows_get_toolbar_button_text (frame, nmhdr->idFrom);
|
442
|
2566
|
|
2567 tttext->lpszText = NULL;
|
|
2568 tttext->hinst = NULL;
|
|
2569
|
|
2570 if (!NILP(btext))
|
|
2571 {
|
|
2572 /* I think this is safe since the text will only go away
|
|
2573 when the toolbar does...*/
|
|
2574 LISP_STRING_TO_EXTERNAL (btext, tttext->lpszText, Qnative);
|
|
2575 }
|
|
2576 #endif
|
|
2577 }
|
|
2578 /* handle tree view callbacks */
|
647
|
2579 else if ((int) nmhdr->code == TVN_SELCHANGED)
|
442
|
2580 {
|
647
|
2581 NM_TREEVIEW *ptree = (NM_TREEVIEW *) lParam;
|
442
|
2582 frame = XFRAME (mswindows_find_frame (hwnd));
|
|
2583 mswindows_handle_gui_wm_command (frame, 0, ptree->itemNew.lParam);
|
|
2584 }
|
|
2585 /* handle tab control callbacks */
|
647
|
2586 else if ((int) nmhdr->code == TCN_SELCHANGE)
|
442
|
2587 {
|
|
2588 TC_ITEM item;
|
|
2589 int idx = SendMessage (nmhdr->hwndFrom, TCM_GETCURSEL, 0, 0);
|
|
2590 frame = XFRAME (mswindows_find_frame (hwnd));
|
|
2591
|
|
2592 item.mask = TCIF_PARAM;
|
|
2593 SendMessage (nmhdr->hwndFrom, TCM_GETITEM, (WPARAM)idx,
|
|
2594 (LPARAM)&item);
|
|
2595
|
|
2596 mswindows_handle_gui_wm_command (frame, 0, item.lParam);
|
|
2597 }
|
|
2598 }
|
|
2599 break;
|
|
2600
|
|
2601 case WM_PAINT:
|
|
2602 /* hdc will be NULL unless this is a subwindow - in which case we
|
|
2603 shouldn't have received a paint message for it here. */
|
|
2604 assert (wParam == 0);
|
|
2605
|
|
2606 /* Can't queue a magic event because windows goes modal and sends paint
|
|
2607 messages directly to the windows procedure when doing solid drags
|
|
2608 and the message queue doesn't get processed. */
|
|
2609 mswindows_handle_paint (XFRAME (mswindows_find_frame (hwnd)));
|
|
2610 break;
|
|
2611
|
593
|
2612 case WM_WINDOWPOSCHANGED:
|
|
2613 /* This is sent before WM_SIZE; in fact, the processing of this
|
|
2614 by DefWindowProc() sends WM_SIZE. But WM_SIZE is not sent when
|
|
2615 a window is hidden (make-frame-invisible), so we need to process
|
|
2616 this and update the state flags. */
|
|
2617 {
|
|
2618 fobj = mswindows_find_frame (hwnd);
|
|
2619 frame = XFRAME (fobj);
|
|
2620 if (IsIconic (hwnd))
|
|
2621 {
|
|
2622 FRAME_VISIBLE_P (frame) = 0;
|
|
2623 FRAME_ICONIFIED_P (frame) = 1;
|
|
2624 }
|
|
2625 else if (IsWindowVisible (hwnd))
|
|
2626 {
|
|
2627 FRAME_VISIBLE_P (frame) = 1;
|
|
2628 FRAME_ICONIFIED_P (frame) = 0;
|
|
2629 }
|
|
2630 else
|
|
2631 {
|
|
2632 FRAME_VISIBLE_P (frame) = 0;
|
|
2633 FRAME_ICONIFIED_P (frame) = 0;
|
|
2634 }
|
|
2635
|
|
2636 return DefWindowProc (hwnd, message_, wParam, lParam);
|
|
2637 }
|
|
2638
|
442
|
2639 case WM_SIZE:
|
|
2640 /* We only care about this message if our size has really changed */
|
|
2641 if (wParam==SIZE_RESTORED || wParam==SIZE_MAXIMIZED || wParam==SIZE_MINIMIZED)
|
|
2642 {
|
|
2643 RECT rect;
|
|
2644 int columns, rows;
|
|
2645
|
|
2646 fobj = mswindows_find_frame (hwnd);
|
|
2647 frame = XFRAME (fobj);
|
|
2648 msframe = FRAME_MSWINDOWS_DATA (frame);
|
|
2649
|
|
2650 /* We cannot handle frame map and unmap hooks right in
|
|
2651 this routine, because these may throw. We queue
|
|
2652 magic events to run these hooks instead - kkm */
|
|
2653
|
|
2654 if (wParam==SIZE_MINIMIZED)
|
|
2655 {
|
|
2656 /* Iconified */
|
|
2657 mswindows_enqueue_magic_event (hwnd, XM_UNMAPFRAME);
|
428
|
2658 }
|
|
2659 else
|
|
2660 {
|
442
|
2661 GetClientRect(hwnd, &rect);
|
|
2662 FRAME_PIXWIDTH(frame) = rect.right;
|
|
2663 FRAME_PIXHEIGHT(frame) = rect.bottom;
|
|
2664
|
|
2665 pixel_to_real_char_size (frame, rect.right, rect.bottom,
|
|
2666 &FRAME_MSWINDOWS_CHARWIDTH (frame),
|
|
2667 &FRAME_MSWINDOWS_CHARHEIGHT (frame));
|
|
2668
|
|
2669 pixel_to_char_size (frame, rect.right, rect.bottom, &columns, &rows);
|
|
2670 change_frame_size (frame, rows, columns, 1);
|
|
2671
|
|
2672 /* If we are inside frame creation, we have to apply geometric
|
|
2673 properties now. */
|
|
2674 if (FRAME_MSWINDOWS_TARGET_RECT (frame))
|
|
2675 {
|
|
2676 /* Yes, we have to size again */
|
|
2677 mswindows_size_frame_internal ( frame,
|
|
2678 FRAME_MSWINDOWS_TARGET_RECT
|
|
2679 (frame));
|
|
2680 /* Reset so we do not get here again. The SetWindowPos call in
|
|
2681 * mswindows_size_frame_internal can cause recursion here. */
|
|
2682 if (FRAME_MSWINDOWS_TARGET_RECT (frame))
|
|
2683 {
|
|
2684 xfree (FRAME_MSWINDOWS_TARGET_RECT (frame));
|
|
2685 FRAME_MSWINDOWS_TARGET_RECT (frame) = 0;
|
|
2686 }
|
|
2687 }
|
|
2688 else
|
|
2689 {
|
|
2690 if (!msframe->sizing && !FRAME_VISIBLE_P (frame))
|
|
2691 mswindows_enqueue_magic_event (hwnd, XM_MAPFRAME);
|
|
2692
|
|
2693 if (!msframe->sizing || mswindows_dynamic_frame_resize)
|
|
2694 redisplay ();
|
|
2695 }
|
428
|
2696 }
|
|
2697 }
|
442
|
2698 break;
|
|
2699
|
|
2700 case WM_DISPLAYCHANGE:
|
|
2701 {
|
|
2702 struct device *d;
|
|
2703 DWORD message_tick = GetMessageTime ();
|
|
2704
|
|
2705 fobj = mswindows_find_frame (hwnd);
|
|
2706 frame = XFRAME (fobj);
|
|
2707 d = XDEVICE (FRAME_DEVICE (frame));
|
|
2708
|
|
2709 /* Do this only once per message. XEmacs can receive this message
|
|
2710 through as many frames as it currently has open. Message time
|
|
2711 will be the same for all these messages. Despite extreme
|
|
2712 efficiency, the code below has about one in 4 billion
|
|
2713 probability that the HDC is not recreated, provided that
|
|
2714 XEmacs is running sufficiently longer than 52 days. */
|
|
2715 if (DEVICE_MSWINDOWS_UPDATE_TICK(d) != message_tick)
|
|
2716 {
|
|
2717 DEVICE_MSWINDOWS_UPDATE_TICK(d) = message_tick;
|
|
2718 DeleteDC (DEVICE_MSWINDOWS_HCDC(d));
|
|
2719 DEVICE_MSWINDOWS_HCDC(d) = CreateCompatibleDC (NULL);
|
|
2720 }
|
|
2721 }
|
|
2722 break;
|
|
2723
|
|
2724 /* Misc magic events which only require that the frame be identified */
|
|
2725 case WM_SETFOCUS:
|
|
2726 case WM_KILLFOCUS:
|
|
2727 mswindows_enqueue_magic_event (hwnd, message_);
|
|
2728 break;
|
|
2729
|
|
2730 case WM_WINDOWPOSCHANGING:
|
428
|
2731 {
|
442
|
2732 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
|
|
2733 WINDOWPLACEMENT wpl = { sizeof(WINDOWPLACEMENT) };
|
|
2734 GetWindowPlacement(hwnd, &wpl);
|
|
2735
|
|
2736 /* Only interested if size is changing and we're not being iconified */
|
|
2737 if (wpl.showCmd != SW_SHOWMINIMIZED
|
|
2738 && wpl.showCmd != SW_SHOWMAXIMIZED
|
|
2739 && !(wp->flags & SWP_NOSIZE))
|
428
|
2740 {
|
442
|
2741 RECT ncsize = { 0, 0, 0, 0 };
|
|
2742 int pixwidth, pixheight;
|
|
2743 AdjustWindowRectEx (&ncsize, GetWindowLong (hwnd, GWL_STYLE),
|
|
2744 GetMenu(hwnd) != NULL,
|
|
2745 GetWindowLong (hwnd, GWL_EXSTYLE));
|
|
2746
|
|
2747 round_size_to_real_char (XFRAME (mswindows_find_frame (hwnd)),
|
|
2748 wp->cx - (ncsize.right - ncsize.left),
|
|
2749 wp->cy - (ncsize.bottom - ncsize.top),
|
|
2750 &pixwidth, &pixheight);
|
|
2751
|
|
2752 /* Convert client sizes to window sizes */
|
|
2753 pixwidth += (ncsize.right - ncsize.left);
|
|
2754 pixheight += (ncsize.bottom - ncsize.top);
|
|
2755
|
|
2756 if (wpl.showCmd != SW_SHOWMAXIMIZED)
|
|
2757 {
|
|
2758 /* Adjust so that the bottom or right doesn't move if it's
|
|
2759 * the top or left that's being changed */
|
|
2760 RECT rect;
|
|
2761 GetWindowRect (hwnd, &rect);
|
|
2762
|
|
2763 if (rect.left != wp->x)
|
|
2764 wp->x += wp->cx - pixwidth;
|
|
2765 if (rect.top != wp->y)
|
|
2766 wp->y += wp->cy - pixheight;
|
|
2767 }
|
|
2768
|
|
2769 wp->cx = pixwidth;
|
|
2770 wp->cy = pixheight;
|
428
|
2771 }
|
442
|
2772 /* DefWindowProc sends useful WM_GETMINMAXINFO message, and adjusts
|
|
2773 window position if the user tries to track window too small */
|
428
|
2774 }
|
442
|
2775 goto defproc;
|
|
2776
|
|
2777 case WM_ENTERSIZEMOVE:
|
|
2778 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
2779 msframe->sizing = 1;
|
|
2780 return 0;
|
|
2781
|
|
2782 case WM_EXITSIZEMOVE:
|
|
2783 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
2784 msframe->sizing = 0;
|
|
2785 /* Queue noop event */
|
|
2786 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
|
|
2787 return 0;
|
428
|
2788
|
|
2789 #ifdef HAVE_SCROLLBARS
|
442
|
2790 case WM_VSCROLL:
|
|
2791 case WM_HSCROLL:
|
|
2792 {
|
|
2793 /* Direction of scroll is determined by scrollbar instance. */
|
|
2794 int code = (int) LOWORD(wParam);
|
|
2795 int pos = (short int) HIWORD(wParam);
|
|
2796 HWND hwndScrollBar = (HWND) lParam;
|
|
2797 struct gcpro gcpro1, gcpro2;
|
|
2798
|
|
2799 mswindows_handle_scrollbar_event (hwndScrollBar, code, pos);
|
|
2800 GCPRO2 (emacs_event, fobj);
|
|
2801 if (UNBOUNDP(mswindows_pump_outstanding_events())) /* Can GC */
|
|
2802 {
|
|
2803 /* Error during event pumping - cancel scroll */
|
|
2804 SendMessage (hwndScrollBar, WM_CANCELMODE, 0, 0);
|
|
2805 }
|
|
2806 UNGCPRO;
|
|
2807 break;
|
|
2808 }
|
|
2809
|
|
2810 case WM_MOUSEWHEEL:
|
|
2811 {
|
|
2812 int keys = LOWORD (wParam); /* Modifier key flags */
|
|
2813 int delta = (short) HIWORD (wParam); /* Wheel rotation amount */
|
|
2814 struct gcpro gcpro1, gcpro2;
|
|
2815
|
464
|
2816 if (mswindows_handle_mousewheel_event (mswindows_find_frame (hwnd),
|
|
2817 keys, delta,
|
|
2818 MAKEPOINTS (lParam)))
|
442
|
2819 {
|
|
2820 GCPRO2 (emacs_event, fobj);
|
|
2821 mswindows_pump_outstanding_events (); /* Can GC */
|
|
2822 UNGCPRO;
|
|
2823 }
|
|
2824 else
|
|
2825 goto defproc;
|
|
2826 break;
|
|
2827 }
|
428
|
2828 #endif
|
|
2829
|
|
2830 #ifdef HAVE_MENUBARS
|
442
|
2831 case WM_INITMENU:
|
|
2832 if (UNBOUNDP (mswindows_handle_wm_initmenu (
|
|
2833 (HMENU) wParam,
|
|
2834 XFRAME (mswindows_find_frame (hwnd)))))
|
|
2835 SendMessage (hwnd, WM_CANCELMODE, 0, 0);
|
|
2836 break;
|
|
2837
|
|
2838 case WM_INITMENUPOPUP:
|
|
2839 if (!HIWORD(lParam))
|
|
2840 {
|
|
2841 if (UNBOUNDP (mswindows_handle_wm_initmenupopup (
|
|
2842 (HMENU) wParam,
|
|
2843 XFRAME (mswindows_find_frame (hwnd)))))
|
|
2844 SendMessage (hwnd, WM_CANCELMODE, 0, 0);
|
|
2845 }
|
|
2846 break;
|
428
|
2847
|
|
2848 #endif /* HAVE_MENUBARS */
|
|
2849
|
442
|
2850 case WM_COMMAND:
|
|
2851 {
|
|
2852 WORD id = LOWORD (wParam);
|
|
2853 WORD nid = HIWORD (wParam);
|
|
2854 HWND cid = (HWND)lParam;
|
|
2855 frame = XFRAME (mswindows_find_frame (hwnd));
|
428
|
2856
|
|
2857 #ifdef HAVE_TOOLBARS
|
442
|
2858 if (!NILP (mswindows_handle_toolbar_wm_command (frame, cid, id)))
|
|
2859 break;
|
428
|
2860 #endif
|
442
|
2861 /* widgets in a buffer only eval a callback for suitable events.*/
|
|
2862 switch (nid)
|
|
2863 {
|
|
2864 case BN_CLICKED:
|
|
2865 case EN_CHANGE:
|
|
2866 case CBN_EDITCHANGE:
|
|
2867 case CBN_SELCHANGE:
|
|
2868 if (!NILP (mswindows_handle_gui_wm_command (frame, cid, id)))
|
|
2869 return 0;
|
|
2870 }
|
|
2871 /* menubars always must come last since the hashtables do not
|
|
2872 always exist*/
|
428
|
2873 #ifdef HAVE_MENUBARS
|
442
|
2874 if (!NILP (mswindows_handle_wm_command (frame, id)))
|
|
2875 break;
|
428
|
2876 #endif
|
|
2877
|
442
|
2878 return DefWindowProc (hwnd, message_, wParam, lParam);
|
|
2879 /* Bite me - a spurious command. This used to not be able to
|
|
2880 happen but with the introduction of widgets its now
|
|
2881 possible. */
|
|
2882 }
|
|
2883 break;
|
|
2884
|
|
2885 case WM_CTLCOLORBTN:
|
|
2886 case WM_CTLCOLORLISTBOX:
|
|
2887 case WM_CTLCOLOREDIT:
|
|
2888 case WM_CTLCOLORSTATIC:
|
|
2889 case WM_CTLCOLORSCROLLBAR:
|
|
2890 {
|
|
2891 /* if we get an opportunity to paint a widget then do so if
|
|
2892 there is an appropriate face */
|
|
2893 HWND crtlwnd = (HWND)lParam;
|
|
2894 LONG ii = GetWindowLong (crtlwnd, GWL_USERDATA);
|
|
2895 if (ii)
|
|
2896 {
|
|
2897 Lisp_Object image_instance;
|
|
2898 VOID_TO_LISP (image_instance, ii);
|
|
2899 if (IMAGE_INSTANCEP (image_instance)
|
|
2900 &&
|
|
2901 IMAGE_INSTANCE_TYPE_P (image_instance, IMAGE_WIDGET))
|
|
2902 {
|
|
2903 /* set colors for the buttons */
|
|
2904 HDC hdc = (HDC)wParam;
|
|
2905 if (last_widget_brushed != ii)
|
|
2906 {
|
|
2907 if (widget_brush)
|
|
2908 DeleteObject (widget_brush);
|
|
2909 widget_brush = CreateSolidBrush
|
|
2910 (COLOR_INSTANCE_MSWINDOWS_COLOR
|
|
2911 (XCOLOR_INSTANCE
|
|
2912 (FACE_BACKGROUND
|
|
2913 (XIMAGE_INSTANCE_WIDGET_FACE (image_instance),
|
|
2914 XIMAGE_INSTANCE_FRAME (image_instance)))));
|
|
2915 }
|
|
2916 last_widget_brushed = ii;
|
|
2917 SetTextColor
|
|
2918 (hdc,
|
|
2919 COLOR_INSTANCE_MSWINDOWS_COLOR
|
|
2920 (XCOLOR_INSTANCE
|
|
2921 (FACE_FOREGROUND
|
|
2922 (XIMAGE_INSTANCE_WIDGET_FACE (image_instance),
|
|
2923 XIMAGE_INSTANCE_FRAME (image_instance)))));
|
|
2924 SetBkMode (hdc, OPAQUE);
|
|
2925 SetBkColor
|
|
2926 (hdc,
|
|
2927 COLOR_INSTANCE_MSWINDOWS_COLOR
|
|
2928 (XCOLOR_INSTANCE
|
|
2929 (FACE_BACKGROUND
|
|
2930 (XIMAGE_INSTANCE_WIDGET_FACE (image_instance),
|
|
2931 XIMAGE_INSTANCE_FRAME (image_instance)))));
|
|
2932 return (LRESULT)widget_brush;
|
|
2933 }
|
|
2934 }
|
|
2935 }
|
|
2936 goto defproc;
|
428
|
2937
|
|
2938 #ifdef HAVE_DRAGNDROP
|
442
|
2939 case WM_DROPFILES: /* implementation ripped-off from event-Xt.c */
|
|
2940 {
|
|
2941 UINT filecount, i, len;
|
|
2942 POINT point;
|
|
2943 char* filename;
|
|
2944 char* fname;
|
|
2945
|
|
2946 Lisp_Object l_dndlist = Qnil, l_item = Qnil;
|
|
2947 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
2948
|
|
2949 emacs_event = Fmake_event (Qnil, Qnil);
|
|
2950 event = XEVENT(emacs_event);
|
|
2951
|
|
2952 GCPRO3 (emacs_event, l_dndlist, l_item);
|
|
2953
|
|
2954 if (!DragQueryPoint ((HDROP) wParam, &point))
|
|
2955 point.x = point.y = -1; /* outside client area */
|
|
2956
|
|
2957 event->event_type = misc_user_event;
|
|
2958 event->channel = mswindows_find_frame(hwnd);
|
|
2959 event->timestamp = GetMessageTime();
|
|
2960 event->event.misc.button = 1; /* #### Should try harder */
|
|
2961 event->event.misc.modifiers = mswindows_modifier_state (NULL,
|
|
2962 (DWORD) -1, 0);
|
|
2963 event->event.misc.x = point.x;
|
|
2964 event->event.misc.y = point.y;
|
|
2965 event->event.misc.function = Qdragdrop_drop_dispatch;
|
|
2966
|
|
2967 filecount = DragQueryFile ((HDROP) wParam, 0xffffffff, NULL, 0);
|
|
2968 for (i=0; i<filecount; i++)
|
|
2969 {
|
|
2970 len = DragQueryFile ((HDROP) wParam, i, NULL, 0);
|
|
2971 /* The URLs that we make here aren't correct according to section
|
|
2972 * 3.10 of rfc1738 because they're missing the //<host>/ part and
|
|
2973 * because they may contain reserved characters. But that's OK -
|
|
2974 * they just need to be good enough to keep dragdrop.el happy. */
|
|
2975 fname = (char *)xmalloc (len+1);
|
|
2976 DragQueryFile ((HANDLE) wParam, i, fname, len+1);
|
|
2977
|
|
2978 /* May be a shell link aka "shortcut" - replace fname if so */
|
|
2979 #if !(defined(CYGWIN) || defined(MINGW))
|
|
2980 /* cygwin doesn't define this COM stuff */
|
|
2981 if (!stricmp (fname + strlen (fname) - 4, ".LNK"))
|
|
2982 {
|
|
2983 IShellLink* psl;
|
|
2984
|
|
2985 if (CoCreateInstance (&CLSID_ShellLink, NULL,
|
|
2986 CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl) == S_OK)
|
|
2987 {
|
|
2988 IPersistFile* ppf;
|
|
2989
|
|
2990 if (psl->lpVtbl->QueryInterface (psl, &IID_IPersistFile,
|
|
2991 &ppf) == S_OK)
|
|
2992 {
|
588
|
2993 OLECHAR wsz[PATH_MAX];
|
442
|
2994 WIN32_FIND_DATA wfd;
|
558
|
2995 LPSTR resolved = (char *) xmalloc (PATH_MAX+1);
|
|
2996
|
|
2997 MultiByteToWideChar (CP_ACP,0, fname, -1, wsz, PATH_MAX);
|
442
|
2998
|
|
2999 if ((ppf->lpVtbl->Load (ppf, wsz, STGM_READ) == S_OK) &&
|
558
|
3000 (psl->lpVtbl->GetPath (psl, resolved, PATH_MAX,
|
442
|
3001 &wfd, 0)==S_OK))
|
|
3002 {
|
|
3003 xfree (fname);
|
|
3004 fname = resolved;
|
|
3005 len = strlen (fname);
|
|
3006 }
|
|
3007
|
|
3008 ppf->lpVtbl->Release (ppf);
|
|
3009 }
|
|
3010
|
|
3011 psl->lpVtbl->Release (psl);
|
|
3012 }
|
|
3013 }
|
428
|
3014 #endif
|
442
|
3015
|
|
3016 #ifdef CYGWIN
|
531
|
3017 filename = xmalloc (cygwin_win32_to_posix_path_list_buf_size (fname) + 5);
|
442
|
3018 strcpy (filename, "file:");
|
531
|
3019 cygwin_win32_to_posix_path_list (fname, filename+5);
|
428
|
3020 #else
|
442
|
3021 filename = (char *)xmalloc (len+6);
|
|
3022 strcat (strcpy (filename, "file:"), fname);
|
|
3023 dostounix_filename (filename+5);
|
428
|
3024 #endif
|
442
|
3025 xfree (fname);
|
|
3026 l_item = make_string (filename, strlen (filename));
|
|
3027 l_dndlist = Fcons (l_item, l_dndlist);
|
|
3028 xfree (filename);
|
|
3029 }
|
|
3030 DragFinish ((HDROP) wParam);
|
|
3031
|
|
3032 event->event.misc.object = Fcons (Qdragdrop_URL, l_dndlist);
|
|
3033 mswindows_enqueue_dispatch_event (emacs_event);
|
|
3034 UNGCPRO;
|
|
3035 }
|
|
3036 break;
|
|
3037 #endif
|
|
3038
|
|
3039 defproc:
|
|
3040 default:
|
|
3041 return DefWindowProc (hwnd, message_, wParam, lParam);
|
428
|
3042 }
|
|
3043 return (0);
|
|
3044 }
|
|
3045
|
|
3046
|
|
3047 /************************************************************************/
|
|
3048 /* keyboard, mouse & other helpers for the windows procedure */
|
|
3049 /************************************************************************/
|
|
3050 static void
|
|
3051 mswindows_set_chord_timer (HWND hwnd)
|
|
3052 {
|
|
3053 int interval;
|
|
3054
|
|
3055 /* We get one third half system double click threshold */
|
|
3056 if (mswindows_mouse_button_tolerance <= 0)
|
|
3057 interval = GetDoubleClickTime () / 3;
|
|
3058 else
|
|
3059 interval = mswindows_mouse_button_tolerance;
|
|
3060
|
|
3061 SetTimer (hwnd, BUTTON_2_TIMER_ID, interval, 0);
|
|
3062 }
|
|
3063
|
|
3064 static int
|
|
3065 mswindows_button2_near_enough (POINTS p1, POINTS p2)
|
|
3066 {
|
|
3067 int dx, dy;
|
|
3068 if (mswindows_mouse_button_max_skew_x <= 0)
|
|
3069 dx = GetSystemMetrics (SM_CXDOUBLECLK) / 2;
|
|
3070 else
|
|
3071 dx = mswindows_mouse_button_max_skew_x;
|
|
3072
|
|
3073 if (mswindows_mouse_button_max_skew_y <= 0)
|
|
3074 dy = GetSystemMetrics (SM_CYDOUBLECLK) / 2;
|
|
3075 else
|
|
3076 dy = mswindows_mouse_button_max_skew_y;
|
|
3077
|
|
3078 return abs (p1.x - p2.x) < dx && abs (p1.y- p2.y)< dy;
|
|
3079 }
|
|
3080
|
|
3081 static int
|
|
3082 mswindows_current_layout_has_AltGr (void)
|
|
3083 {
|
|
3084 /* This simple caching mechanism saves 10% of CPU
|
|
3085 time when a key typed at autorepeat rate of 30 cps! */
|
|
3086 static HKL last_hkl = 0;
|
|
3087 static int last_hkl_has_AltGr;
|
442
|
3088 HKL current_hkl = (HKL) -1;
|
|
3089
|
|
3090 if (xGetKeyboardLayout) /* not in NT 3.5 */
|
|
3091 current_hkl = xGetKeyboardLayout (0);
|
428
|
3092 if (current_hkl != last_hkl)
|
|
3093 {
|
647
|
3094 int c;
|
428
|
3095 last_hkl_has_AltGr = 0;
|
|
3096 /* In this loop, we query whether a character requires
|
|
3097 AltGr to be down to generate it. If at least such one
|
|
3098 found, this means that the layout does regard AltGr */
|
647
|
3099 for (c = ' '; c <= 255 && !last_hkl_has_AltGr; ++c)
|
|
3100 /* #### This is not really such a good check. What about under
|
|
3101 CJK locales? It may not matter there, though. We always
|
|
3102 call VkKeyScanA so that we check the locale-specific characters
|
|
3103 in non-Latin-1 locales, instead of just the Latin-1 characters. */
|
|
3104 if (HIBYTE (VkKeyScanA ((char) c)) == 6)
|
428
|
3105 last_hkl_has_AltGr = 1;
|
|
3106 last_hkl = current_hkl;
|
|
3107 }
|
|
3108 return last_hkl_has_AltGr;
|
|
3109 }
|
|
3110
|
|
3111
|
|
3112 /* Returns the state of the modifier keys in the format expected by the
|
|
3113 * Lisp_Event key_data, button_data and motion_data modifiers member */
|
442
|
3114 static int
|
|
3115 mswindows_modifier_state (BYTE* keymap, DWORD fwKeys, int has_AltGr)
|
428
|
3116 {
|
|
3117 int mods = 0;
|
442
|
3118 int keys_is_real = 0;
|
|
3119 BYTE keymap2[256];
|
|
3120
|
|
3121 if (fwKeys == (DWORD) -1)
|
|
3122 fwKeys = mswindows_last_mouse_button_state;
|
|
3123 else
|
|
3124 {
|
|
3125 keys_is_real = 1;
|
|
3126 mswindows_last_mouse_button_state = fwKeys;
|
|
3127 }
|
428
|
3128
|
|
3129 if (keymap == NULL)
|
|
3130 {
|
442
|
3131 keymap = keymap2;
|
428
|
3132 GetKeyboardState (keymap);
|
|
3133 has_AltGr = mswindows_current_layout_has_AltGr ();
|
|
3134 }
|
|
3135
|
442
|
3136 /* #### should look at fwKeys for MK_CONTROL. I don't understand how
|
|
3137 AltGr works. */
|
428
|
3138 if (has_AltGr && (keymap [VK_LCONTROL] & 0x80) && (keymap [VK_RMENU] & 0x80))
|
|
3139 {
|
442
|
3140 mods |= (keymap [VK_LMENU] & 0x80) ? XEMACS_MOD_META : 0;
|
|
3141 mods |= (keymap [VK_RCONTROL] & 0x80) ? XEMACS_MOD_CONTROL : 0;
|
428
|
3142 }
|
|
3143 else
|
|
3144 {
|
442
|
3145 mods |= (keymap [VK_MENU] & 0x80) ? XEMACS_MOD_META : 0;
|
|
3146 mods |= (keymap [VK_CONTROL] & 0x80) ? XEMACS_MOD_CONTROL : 0;
|
428
|
3147 }
|
|
3148
|
442
|
3149 mods |= (keys_is_real ? fwKeys & MK_SHIFT : (keymap [VK_SHIFT] & 0x80))
|
|
3150 ? XEMACS_MOD_SHIFT : 0;
|
|
3151 mods |= fwKeys & MK_LBUTTON ? XEMACS_MOD_BUTTON1 : 0;
|
|
3152 mods |= fwKeys & MK_MBUTTON ? XEMACS_MOD_BUTTON2 : 0;
|
|
3153 mods |= fwKeys & MK_RBUTTON ? XEMACS_MOD_BUTTON3 : 0;
|
428
|
3154
|
|
3155 return mods;
|
|
3156 }
|
|
3157
|
|
3158 /*
|
|
3159 * Translate a mswindows virtual key to a keysym.
|
|
3160 * Only returns non-Qnil for keys that don't generate WM_CHAR messages
|
|
3161 * or whose ASCII codes (like space) xemacs doesn't like.
|
|
3162 */
|
|
3163 Lisp_Object mswindows_key_to_emacs_keysym (int mswindows_key, int mods,
|
|
3164 int extendedp)
|
|
3165 {
|
|
3166 if (extendedp) /* Keys not present on a 82 key keyboard */
|
|
3167 {
|
|
3168 switch (mswindows_key)
|
|
3169 {
|
442
|
3170 case VK_CANCEL: return KEYSYM ("pause");
|
428
|
3171 case VK_RETURN: return KEYSYM ("kp-enter");
|
|
3172 case VK_PRIOR: return KEYSYM ("prior");
|
|
3173 case VK_NEXT: return KEYSYM ("next");
|
|
3174 case VK_END: return KEYSYM ("end");
|
|
3175 case VK_HOME: return KEYSYM ("home");
|
|
3176 case VK_LEFT: return KEYSYM ("left");
|
|
3177 case VK_UP: return KEYSYM ("up");
|
|
3178 case VK_RIGHT: return KEYSYM ("right");
|
|
3179 case VK_DOWN: return KEYSYM ("down");
|
|
3180 case VK_INSERT: return KEYSYM ("insert");
|
|
3181 case VK_DELETE: return QKdelete;
|
442
|
3182 #if 0 /* FSF Emacs allows these to return configurable syms/mods */
|
|
3183 case VK_LWIN return KEYSYM ("");
|
|
3184 case VK_RWIN return KEYSYM ("");
|
|
3185 #endif
|
|
3186 case VK_APPS: return KEYSYM ("menu");
|
428
|
3187 }
|
|
3188 }
|
|
3189 else
|
|
3190 {
|
|
3191 switch (mswindows_key)
|
|
3192 {
|
|
3193 case VK_BACK: return QKbackspace;
|
|
3194 case VK_TAB: return QKtab;
|
|
3195 case '\n': return QKlinefeed;
|
|
3196 case VK_CLEAR: return KEYSYM ("clear");
|
|
3197 case VK_RETURN: return QKreturn;
|
442
|
3198 case VK_PAUSE: return KEYSYM ("pause");
|
428
|
3199 case VK_ESCAPE: return QKescape;
|
|
3200 case VK_SPACE: return QKspace;
|
|
3201 case VK_PRIOR: return KEYSYM ("kp-prior");
|
|
3202 case VK_NEXT: return KEYSYM ("kp-next");
|
|
3203 case VK_END: return KEYSYM ("kp-end");
|
|
3204 case VK_HOME: return KEYSYM ("kp-home");
|
|
3205 case VK_LEFT: return KEYSYM ("kp-left");
|
|
3206 case VK_UP: return KEYSYM ("kp-up");
|
|
3207 case VK_RIGHT: return KEYSYM ("kp-right");
|
|
3208 case VK_DOWN: return KEYSYM ("kp-down");
|
|
3209 case VK_SELECT: return KEYSYM ("select");
|
|
3210 case VK_PRINT: return KEYSYM ("print");
|
|
3211 case VK_EXECUTE: return KEYSYM ("execute");
|
|
3212 case VK_SNAPSHOT: return KEYSYM ("print");
|
|
3213 case VK_INSERT: return KEYSYM ("kp-insert");
|
|
3214 case VK_DELETE: return KEYSYM ("kp-delete");
|
|
3215 case VK_HELP: return KEYSYM ("help");
|
|
3216 case VK_NUMPAD0: return KEYSYM ("kp-0");
|
|
3217 case VK_NUMPAD1: return KEYSYM ("kp-1");
|
|
3218 case VK_NUMPAD2: return KEYSYM ("kp-2");
|
|
3219 case VK_NUMPAD3: return KEYSYM ("kp-3");
|
|
3220 case VK_NUMPAD4: return KEYSYM ("kp-4");
|
|
3221 case VK_NUMPAD5: return KEYSYM ("kp-5");
|
|
3222 case VK_NUMPAD6: return KEYSYM ("kp-6");
|
|
3223 case VK_NUMPAD7: return KEYSYM ("kp-7");
|
|
3224 case VK_NUMPAD8: return KEYSYM ("kp-8");
|
|
3225 case VK_NUMPAD9: return KEYSYM ("kp-9");
|
|
3226 case VK_MULTIPLY: return KEYSYM ("kp-multiply");
|
|
3227 case VK_ADD: return KEYSYM ("kp-add");
|
|
3228 case VK_SEPARATOR: return KEYSYM ("kp-separator");
|
|
3229 case VK_SUBTRACT: return KEYSYM ("kp-subtract");
|
|
3230 case VK_DECIMAL: return KEYSYM ("kp-decimal");
|
|
3231 case VK_DIVIDE: return KEYSYM ("kp-divide");
|
|
3232 case VK_F1: return KEYSYM ("f1");
|
|
3233 case VK_F2: return KEYSYM ("f2");
|
|
3234 case VK_F3: return KEYSYM ("f3");
|
|
3235 case VK_F4: return KEYSYM ("f4");
|
|
3236 case VK_F5: return KEYSYM ("f5");
|
|
3237 case VK_F6: return KEYSYM ("f6");
|
|
3238 case VK_F7: return KEYSYM ("f7");
|
|
3239 case VK_F8: return KEYSYM ("f8");
|
|
3240 case VK_F9: return KEYSYM ("f9");
|
|
3241 case VK_F10: return KEYSYM ("f10");
|
|
3242 case VK_F11: return KEYSYM ("f11");
|
|
3243 case VK_F12: return KEYSYM ("f12");
|
|
3244 case VK_F13: return KEYSYM ("f13");
|
|
3245 case VK_F14: return KEYSYM ("f14");
|
|
3246 case VK_F15: return KEYSYM ("f15");
|
|
3247 case VK_F16: return KEYSYM ("f16");
|
|
3248 case VK_F17: return KEYSYM ("f17");
|
|
3249 case VK_F18: return KEYSYM ("f18");
|
|
3250 case VK_F19: return KEYSYM ("f19");
|
|
3251 case VK_F20: return KEYSYM ("f20");
|
|
3252 case VK_F21: return KEYSYM ("f21");
|
|
3253 case VK_F22: return KEYSYM ("f22");
|
|
3254 case VK_F23: return KEYSYM ("f23");
|
|
3255 case VK_F24: return KEYSYM ("f24");
|
|
3256 }
|
|
3257 }
|
|
3258 return Qnil;
|
|
3259 }
|
|
3260
|
|
3261 /*
|
|
3262 * Find the console that matches the supplied mswindows window handle
|
|
3263 */
|
|
3264 Lisp_Object
|
|
3265 mswindows_find_console (HWND hwnd)
|
|
3266 {
|
|
3267 /* We only support one console */
|
|
3268 return XCAR (Vconsole_list);
|
|
3269 }
|
|
3270
|
|
3271 /*
|
|
3272 * Find the frame that matches the supplied mswindows window handle
|
|
3273 */
|
546
|
3274 Lisp_Object
|
428
|
3275 mswindows_find_frame (HWND hwnd)
|
|
3276 {
|
|
3277 LONG l = GetWindowLong (hwnd, XWL_FRAMEOBJ);
|
|
3278 Lisp_Object f;
|
|
3279 if (l == 0)
|
|
3280 {
|
|
3281 /* We are in progress of frame creation. Return the frame
|
|
3282 being created, as it still not remembered in the window
|
|
3283 extra storage. */
|
|
3284 assert (!NILP (Vmswindows_frame_being_created));
|
|
3285 return Vmswindows_frame_being_created;
|
|
3286 }
|
|
3287 VOID_TO_LISP (f, l);
|
|
3288 return f;
|
|
3289 }
|
|
3290
|
|
3291
|
|
3292 /************************************************************************/
|
|
3293 /* methods */
|
|
3294 /************************************************************************/
|
|
3295
|
|
3296 static int
|
|
3297 emacs_mswindows_add_timeout (EMACS_TIME thyme)
|
|
3298 {
|
|
3299 int milliseconds;
|
|
3300 EMACS_TIME current_time;
|
|
3301 EMACS_GET_TIME (current_time);
|
|
3302 EMACS_SUB_TIME (thyme, thyme, current_time);
|
|
3303 milliseconds = EMACS_SECS (thyme) * 1000 +
|
|
3304 (EMACS_USECS (thyme) + 500) / 1000;
|
|
3305 if (milliseconds < 1)
|
|
3306 milliseconds = 1;
|
|
3307 ++mswindows_pending_timers_count;
|
|
3308 return SetTimer (NULL, 0, milliseconds,
|
|
3309 (TIMERPROC) mswindows_wm_timer_callback);
|
|
3310 }
|
|
3311
|
|
3312 static void
|
|
3313 emacs_mswindows_remove_timeout (int id)
|
|
3314 {
|
440
|
3315 Lisp_Event match_against;
|
428
|
3316 Lisp_Object emacs_event;
|
|
3317
|
|
3318 if (KillTimer (NULL, id))
|
|
3319 --mswindows_pending_timers_count;
|
|
3320
|
|
3321 /* If there is a dispatch event generated by this
|
|
3322 timeout in the queue, we have to remove it too. */
|
|
3323 match_against.event_type = timeout_event;
|
|
3324 match_against.event.timeout.interval_id = id;
|
|
3325 emacs_event = mswindows_cancel_dispatch_event (&match_against);
|
|
3326 if (!NILP (emacs_event))
|
|
3327 Fdeallocate_event(emacs_event);
|
|
3328 }
|
|
3329
|
|
3330 /* If `user_p' is false, then return whether there are any win32, timeout,
|
|
3331 * or subprocess events pending (that is, whether
|
|
3332 * emacs_mswindows_next_event() would return immediately without blocking).
|
|
3333 *
|
|
3334 * if `user_p' is true, then return whether there are any *user generated*
|
|
3335 * events available (that is, whether there are keyboard or mouse-click
|
|
3336 * events ready to be read). This also implies that
|
|
3337 * emacs_mswindows_next_event() would not block.
|
|
3338 */
|
|
3339 static int
|
|
3340 emacs_mswindows_event_pending_p (int user_p)
|
|
3341 {
|
|
3342 mswindows_need_event (0);
|
|
3343 return (!NILP (mswindows_u_dispatch_event_queue)
|
|
3344 || (!user_p && !NILP (mswindows_s_dispatch_event_queue)));
|
|
3345 }
|
|
3346
|
|
3347 /*
|
|
3348 * Return the next event
|
|
3349 */
|
|
3350 static void
|
440
|
3351 emacs_mswindows_next_event (Lisp_Event *emacs_event)
|
428
|
3352 {
|
|
3353 Lisp_Object event, event2;
|
|
3354
|
|
3355 mswindows_need_event (1);
|
|
3356
|
|
3357 event = mswindows_dequeue_dispatch_event ();
|
|
3358 XSETEVENT (event2, emacs_event);
|
|
3359 Fcopy_event (event, event2);
|
|
3360 Fdeallocate_event (event);
|
|
3361 }
|
|
3362
|
|
3363 /*
|
|
3364 * Handle a magic event off the dispatch queue.
|
|
3365 */
|
|
3366 static void
|
440
|
3367 emacs_mswindows_handle_magic_event (Lisp_Event *emacs_event)
|
428
|
3368 {
|
|
3369 switch (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event))
|
|
3370 {
|
|
3371 case XM_BUMPQUEUE:
|
|
3372 break;
|
|
3373
|
442
|
3374 case WM_PAINT:
|
|
3375 {
|
|
3376 struct frame *f = XFRAME (EVENT_CHANNEL (emacs_event));
|
|
3377 mswindows_handle_paint (f);
|
|
3378 (FRAME_MSWINDOWS_DATA (f))->paint_pending = 0;
|
|
3379 }
|
|
3380 break;
|
|
3381
|
428
|
3382 case WM_SETFOCUS:
|
|
3383 case WM_KILLFOCUS:
|
|
3384 {
|
|
3385 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
|
|
3386 struct frame *f = XFRAME (frame);
|
|
3387 int in_p = (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event) == WM_SETFOCUS);
|
|
3388 Lisp_Object conser;
|
442
|
3389 struct gcpro gcpro1;
|
|
3390
|
|
3391 /* On focus change, clear all memory of sticky modifiers
|
|
3392 to avoid non-intuitive behavior. */
|
|
3393 clear_sticky_modifiers ();
|
428
|
3394
|
|
3395 conser = Fcons (frame, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil));
|
442
|
3396 GCPRO1 (conser);
|
428
|
3397 emacs_handle_focus_change_preliminary (conser);
|
|
3398 /* Under X the stuff up to here is done in the X event handler.
|
|
3399 I Don't know why */
|
|
3400 emacs_handle_focus_change_final (conser);
|
442
|
3401 UNGCPRO;
|
428
|
3402
|
|
3403 }
|
|
3404 break;
|
|
3405
|
|
3406 case XM_MAPFRAME:
|
|
3407 case XM_UNMAPFRAME:
|
|
3408 {
|
|
3409 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
|
|
3410 va_run_hook_with_args (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event)
|
|
3411 == XM_MAPFRAME ?
|
|
3412 Qmap_frame_hook : Qunmap_frame_hook,
|
|
3413 1, frame);
|
|
3414 }
|
|
3415 break;
|
|
3416
|
|
3417 /* #### What about Enter & Leave */
|
|
3418 #if 0
|
|
3419 va_run_hook_with_args (in_p ? Qmouse_enter_frame_hook :
|
|
3420 Qmouse_leave_frame_hook, 1, frame);
|
|
3421 #endif
|
|
3422
|
|
3423 default:
|
|
3424 assert(0);
|
|
3425 }
|
|
3426 }
|
|
3427
|
|
3428 #ifndef HAVE_MSG_SELECT
|
|
3429 static HANDLE
|
440
|
3430 get_process_input_waitable (Lisp_Process *process)
|
428
|
3431 {
|
|
3432 Lisp_Object instr, outstr, p;
|
|
3433 XSETPROCESS (p, process);
|
|
3434 get_process_streams (process, &instr, &outstr);
|
|
3435 assert (!NILP (instr));
|
|
3436 #if defined (HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
|
|
3437 return (network_connection_p (p)
|
|
3438 ? get_winsock_stream_waitable (XLSTREAM (instr))
|
|
3439 : get_ntpipe_input_stream_waitable (XLSTREAM (instr)));
|
|
3440 #else
|
442
|
3441 return get_ntpipe_input_stream_waitable (XLSTREAM (instr));
|
428
|
3442 #endif
|
|
3443 }
|
|
3444
|
|
3445 static void
|
440
|
3446 emacs_mswindows_select_process (Lisp_Process *process)
|
428
|
3447 {
|
|
3448 HANDLE hev = get_process_input_waitable (process);
|
|
3449
|
|
3450 if (!add_waitable_handle (hev))
|
563
|
3451 invalid_operation ("Too many active processes", Qunbound);
|
428
|
3452
|
|
3453 #ifdef HAVE_WIN32_PROCESSES
|
|
3454 {
|
|
3455 Lisp_Object p;
|
|
3456 XSETPROCESS (p, process);
|
|
3457 if (!network_connection_p (p))
|
|
3458 {
|
|
3459 HANDLE hprocess = get_nt_process_handle (process);
|
|
3460 if (!add_waitable_handle (hprocess))
|
|
3461 {
|
|
3462 remove_waitable_handle (hev);
|
563
|
3463 invalid_operation ("Too many active processes", Qunbound);
|
428
|
3464 }
|
|
3465 }
|
|
3466 }
|
|
3467 #endif
|
|
3468 }
|
|
3469
|
|
3470 static void
|
440
|
3471 emacs_mswindows_unselect_process (Lisp_Process *process)
|
428
|
3472 {
|
|
3473 /* Process handle is removed in the event loop as soon
|
|
3474 as it is signaled, so don't bother here about it */
|
|
3475 HANDLE hev = get_process_input_waitable (process);
|
|
3476 remove_waitable_handle (hev);
|
|
3477 }
|
|
3478 #endif /* HAVE_MSG_SELECT */
|
|
3479
|
|
3480 static void
|
|
3481 emacs_mswindows_select_console (struct console *con)
|
|
3482 {
|
|
3483 #ifdef HAVE_MSG_SELECT
|
|
3484 if (CONSOLE_MSWINDOWS_P (con))
|
|
3485 return; /* mswindows consoles are automatically selected */
|
|
3486
|
|
3487 event_stream_unixoid_select_console (con);
|
|
3488 #endif
|
|
3489 }
|
|
3490
|
|
3491 static void
|
|
3492 emacs_mswindows_unselect_console (struct console *con)
|
|
3493 {
|
|
3494 #ifdef HAVE_MSG_SELECT
|
|
3495 if (CONSOLE_MSWINDOWS_P (con))
|
|
3496 return; /* mswindows consoles are automatically selected */
|
|
3497
|
|
3498 event_stream_unixoid_unselect_console (con);
|
|
3499 #endif
|
|
3500 }
|
|
3501
|
|
3502 static void
|
|
3503 emacs_mswindows_quit_p (void)
|
|
3504 {
|
|
3505 /* Quit cannot happen in modal loop: all program
|
|
3506 input is dedicated to Windows. */
|
|
3507 if (mswindows_in_modal_loop)
|
|
3508 return;
|
|
3509
|
593
|
3510 mswindows_quit_chars_count = 0;
|
502
|
3511 /* Drain windows queue. This sets up number of quit characters in
|
|
3512 the queue. */
|
442
|
3513 mswindows_drain_windows_queue ();
|
428
|
3514
|
|
3515 if (mswindows_quit_chars_count > 0)
|
|
3516 {
|
|
3517 /* Yes there's a hidden one... Throw it away */
|
440
|
3518 Lisp_Event match_against;
|
428
|
3519 Lisp_Object emacs_event;
|
440
|
3520 int critical_p = 0;
|
428
|
3521
|
|
3522 match_against.event_type = key_press_event;
|
|
3523 match_against.event.key.modifiers = FAKE_MOD_QUIT;
|
|
3524
|
593
|
3525 while (mswindows_quit_chars_count > 0)
|
440
|
3526 {
|
|
3527 emacs_event = mswindows_cancel_dispatch_event (&match_against);
|
|
3528 assert (!NILP (emacs_event));
|
442
|
3529
|
502
|
3530 if (XEVENT (emacs_event)->event.key.modifiers &
|
|
3531 FAKE_MOD_QUIT_CRITICAL)
|
440
|
3532 critical_p = 1;
|
|
3533
|
502
|
3534 Fdeallocate_event (emacs_event);
|
593
|
3535 mswindows_quit_chars_count--;
|
440
|
3536 }
|
|
3537
|
|
3538 Vquit_flag = critical_p ? Qcritical : Qt;
|
428
|
3539 }
|
|
3540 }
|
|
3541
|
|
3542 USID
|
|
3543 emacs_mswindows_create_stream_pair (void* inhandle, void* outhandle,
|
|
3544 Lisp_Object* instream,
|
|
3545 Lisp_Object* outstream,
|
|
3546 int flags)
|
|
3547 {
|
|
3548 /* Handles for streams */
|
|
3549 HANDLE hin, hout;
|
|
3550 /* fds. These just stored along with the streams, and are closed in
|
|
3551 delete stream pair method, because we need to handle fake unices
|
|
3552 here. */
|
|
3553 int fdi, fdo;
|
|
3554
|
|
3555 /* Decode inhandle and outhandle. Their meaning depends on
|
|
3556 the process implementation being used. */
|
|
3557 #if defined (HAVE_WIN32_PROCESSES)
|
|
3558 /* We're passed in Windows handles. That's what we like most... */
|
|
3559 hin = (HANDLE) inhandle;
|
|
3560 hout = (HANDLE) outhandle;
|
|
3561 fdi = fdo = -1;
|
|
3562 #elif defined (HAVE_UNIX_PROCESSES)
|
|
3563 /* We are passed UNIX fds. This must be Cygwin.
|
|
3564 Fetch os handles */
|
|
3565 hin = inhandle >= 0 ? (HANDLE)get_osfhandle ((int)inhandle) : INVALID_HANDLE_VALUE;
|
|
3566 hout = outhandle >= 0 ? (HANDLE)get_osfhandle ((int)outhandle) : INVALID_HANDLE_VALUE;
|
|
3567 fdi=(int)inhandle;
|
|
3568 fdo=(int)outhandle;
|
|
3569 #else
|
|
3570 #error "So, WHICH kind of processes do you want?"
|
|
3571 #endif
|
|
3572
|
|
3573 *instream = (hin == INVALID_HANDLE_VALUE
|
|
3574 ? Qnil
|
|
3575 #if defined (HAVE_SOCKETS) && !defined (HAVE_MSG_SELECT)
|
|
3576 : flags & STREAM_NETWORK_CONNECTION
|
|
3577 ? make_winsock_input_stream ((SOCKET)hin, fdi)
|
|
3578 #endif
|
|
3579 : make_ntpipe_input_stream (hin, fdi));
|
|
3580
|
|
3581 #ifdef HAVE_WIN32_PROCESSES
|
|
3582 *outstream = (hout == INVALID_HANDLE_VALUE
|
|
3583 ? Qnil
|
|
3584 #if defined (HAVE_SOCKETS) && !defined (HAVE_MSG_SELECT)
|
|
3585 : flags & STREAM_NETWORK_CONNECTION
|
|
3586 ? make_winsock_output_stream ((SOCKET)hout, fdo)
|
|
3587 #endif
|
|
3588 : make_ntpipe_output_stream (hout, fdo));
|
|
3589 #elif defined (HAVE_UNIX_PROCESSES)
|
|
3590 *outstream = (fdo >= 0
|
|
3591 ? make_filedesc_output_stream (fdo, 0, -1, LSTR_BLOCKED_OK)
|
|
3592 : Qnil);
|
|
3593
|
535
|
3594 #if defined(HAVE_UNIX_PROCESSES)
|
428
|
3595 /* FLAGS is process->pty_flag for UNIX_PROCESSES */
|
|
3596 if ((flags & STREAM_PTY_FLUSHING) && fdo >= 0)
|
|
3597 {
|
|
3598 Bufbyte eof_char = get_eof_char (fdo);
|
|
3599 int pty_max_bytes = get_pty_max_bytes (fdo);
|
|
3600 filedesc_stream_set_pty_flushing (XLSTREAM(*outstream), pty_max_bytes, eof_char);
|
|
3601 }
|
|
3602 #endif
|
|
3603 #endif
|
|
3604
|
|
3605 return (NILP (*instream)
|
|
3606 ? USID_ERROR
|
|
3607 #if defined(HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
|
|
3608 : flags & STREAM_NETWORK_CONNECTION
|
|
3609 ? HANDLE_TO_USID (get_winsock_stream_waitable (XLSTREAM (*instream)))
|
|
3610 #endif
|
|
3611 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM (*instream))));
|
|
3612 }
|
|
3613
|
|
3614 USID
|
|
3615 emacs_mswindows_delete_stream_pair (Lisp_Object instream,
|
442
|
3616 Lisp_Object outstream)
|
428
|
3617 {
|
|
3618 /* Oh nothing special here for Win32 at all */
|
|
3619 #if defined (HAVE_UNIX_PROCESSES)
|
|
3620 int in = (NILP(instream)
|
|
3621 ? -1
|
|
3622 #if defined(HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
|
|
3623 : LSTREAM_TYPE_P (XLSTREAM (instream), winsock)
|
|
3624 ? get_winsock_stream_param (XLSTREAM (instream))
|
|
3625 #endif
|
|
3626 : get_ntpipe_input_stream_param (XLSTREAM (instream)));
|
|
3627 int out = (NILP(outstream) ? -1
|
|
3628 : filedesc_stream_fd (XLSTREAM (outstream)));
|
|
3629
|
|
3630 if (in >= 0)
|
|
3631 close (in);
|
|
3632 if (out != in && out >= 0)
|
|
3633 close (out);
|
|
3634 #endif
|
|
3635
|
|
3636 return (NILP (instream)
|
|
3637 ? USID_DONTHASH
|
|
3638 #if defined(HAVE_SOCKETS) && !defined(HAVE_MSG_SELECT)
|
|
3639 : LSTREAM_TYPE_P (XLSTREAM (instream), winsock)
|
|
3640 ? HANDLE_TO_USID (get_winsock_stream_waitable (XLSTREAM (instream)))
|
|
3641 #endif
|
|
3642 : HANDLE_TO_USID (get_ntpipe_input_stream_waitable (XLSTREAM (instream))));
|
|
3643 }
|
|
3644
|
442
|
3645 static int
|
|
3646 emacs_mswindows_current_event_timestamp (struct console *c)
|
|
3647 {
|
|
3648 return GetTickCount ();
|
|
3649 }
|
|
3650
|
428
|
3651 #ifndef HAVE_X_WINDOWS
|
|
3652 /* This is called from GC when a process object is about to be freed.
|
|
3653 If we've still got pointers to it in this file, we're gonna lose hard.
|
|
3654 */
|
|
3655 void
|
440
|
3656 debug_process_finalization (Lisp_Process *p)
|
428
|
3657 {
|
|
3658 #if 0 /* #### */
|
|
3659 Lisp_Object instr, outstr;
|
|
3660
|
|
3661 get_process_streams (p, &instr, &outstr);
|
|
3662 /* if it still has fds, then it hasn't been killed yet. */
|
|
3663 assert (NILP(instr));
|
|
3664 assert (NILP(outstr));
|
|
3665
|
|
3666 /* #### More checks here */
|
|
3667 #endif
|
|
3668 }
|
|
3669 #endif
|
|
3670
|
593
|
3671 #ifdef DEBUG_XEMACS
|
|
3672
|
|
3673 struct mswin_message_debug
|
|
3674 {
|
|
3675 int mess;
|
|
3676 char *string;
|
|
3677 };
|
|
3678
|
|
3679 #define FROB(val) { val, #val, },
|
|
3680
|
|
3681 struct mswin_message_debug debug_mswin_messages[] =
|
|
3682 {
|
|
3683 FROB (WM_NULL)
|
|
3684 FROB (WM_CREATE)
|
|
3685 FROB (WM_DESTROY)
|
|
3686 FROB (WM_MOVE)
|
|
3687 FROB (WM_SIZE)
|
|
3688
|
|
3689 FROB (WM_ACTIVATE)
|
|
3690
|
|
3691 FROB (WM_SETFOCUS)
|
|
3692 FROB (WM_KILLFOCUS)
|
|
3693 FROB (WM_ENABLE)
|
|
3694 FROB (WM_SETREDRAW)
|
|
3695 FROB (WM_SETTEXT)
|
|
3696 FROB (WM_GETTEXT)
|
|
3697 FROB (WM_GETTEXTLENGTH)
|
|
3698 FROB (WM_PAINT)
|
|
3699 FROB (WM_CLOSE)
|
|
3700 FROB (WM_QUERYENDSESSION)
|
|
3701 FROB (WM_QUIT)
|
|
3702 FROB (WM_QUERYOPEN)
|
|
3703 FROB (WM_ERASEBKGND)
|
|
3704 FROB (WM_SYSCOLORCHANGE)
|
|
3705 FROB (WM_ENDSESSION)
|
|
3706 FROB (WM_SHOWWINDOW)
|
|
3707 FROB (WM_WININICHANGE)
|
|
3708 #if(WINVER >= 0x0400)
|
|
3709 FROB (WM_SETTINGCHANGE)
|
|
3710 #endif /* WINVER >= 0x0400 */
|
|
3711
|
|
3712 FROB (WM_DEVMODECHANGE)
|
|
3713 FROB (WM_ACTIVATEAPP)
|
|
3714 FROB (WM_FONTCHANGE)
|
|
3715 FROB (WM_TIMECHANGE)
|
|
3716 FROB (WM_CANCELMODE)
|
|
3717 FROB (WM_SETCURSOR)
|
|
3718 FROB (WM_MOUSEACTIVATE)
|
|
3719 FROB (WM_CHILDACTIVATE)
|
|
3720 FROB (WM_QUEUESYNC)
|
|
3721
|
|
3722 FROB (WM_GETMINMAXINFO)
|
|
3723
|
|
3724 FROB (WM_PAINTICON)
|
|
3725 FROB (WM_ICONERASEBKGND)
|
|
3726 FROB (WM_NEXTDLGCTL)
|
|
3727 FROB (WM_SPOOLERSTATUS)
|
|
3728 FROB (WM_DRAWITEM)
|
|
3729 FROB (WM_MEASUREITEM)
|
|
3730 FROB (WM_DELETEITEM)
|
|
3731 FROB (WM_VKEYTOITEM)
|
|
3732 FROB (WM_CHARTOITEM)
|
|
3733 FROB (WM_SETFONT)
|
|
3734 FROB (WM_GETFONT)
|
|
3735 FROB (WM_SETHOTKEY)
|
|
3736 FROB (WM_GETHOTKEY)
|
|
3737 FROB (WM_QUERYDRAGICON)
|
|
3738 FROB (WM_COMPAREITEM)
|
|
3739 #if(WINVER >= 0x0500)
|
|
3740 FROB (WM_GETOBJECT)
|
|
3741 #endif /* WINVER >= 0x0500 */
|
|
3742 FROB (WM_COMPACTING)
|
|
3743 FROB (WM_COMMNOTIFY)
|
|
3744 FROB (WM_WINDOWPOSCHANGING)
|
|
3745 FROB (WM_WINDOWPOSCHANGED)
|
|
3746
|
|
3747 FROB (WM_POWER)
|
|
3748
|
|
3749 FROB (WM_COPYDATA)
|
|
3750 FROB (WM_CANCELJOURNAL)
|
|
3751
|
|
3752 #if(WINVER >= 0x0400)
|
|
3753 FROB (WM_NOTIFY)
|
|
3754 FROB (WM_INPUTLANGCHANGEREQUEST)
|
|
3755 FROB (WM_INPUTLANGCHANGE)
|
|
3756 FROB (WM_TCARD)
|
|
3757 FROB (WM_HELP)
|
|
3758 FROB (WM_USERCHANGED)
|
|
3759 FROB (WM_NOTIFYFORMAT)
|
|
3760
|
|
3761 FROB (WM_CONTEXTMENU)
|
|
3762 FROB (WM_STYLECHANGING)
|
|
3763 FROB (WM_STYLECHANGED)
|
|
3764 FROB (WM_DISPLAYCHANGE)
|
|
3765 FROB (WM_GETICON)
|
|
3766 FROB (WM_SETICON)
|
|
3767 #endif /* WINVER >= 0x0400 */
|
|
3768
|
|
3769 FROB (WM_NCCREATE)
|
|
3770 FROB (WM_NCDESTROY)
|
|
3771 FROB (WM_NCCALCSIZE)
|
|
3772 FROB (WM_NCHITTEST)
|
|
3773 FROB (WM_NCPAINT)
|
|
3774 FROB (WM_NCACTIVATE)
|
|
3775 FROB (WM_GETDLGCODE)
|
604
|
3776 #ifdef WM_SYNCPAINT /* not in VC 5 */
|
593
|
3777 FROB (WM_SYNCPAINT)
|
604
|
3778 #endif /* WM_SYNCPAINT */
|
593
|
3779 FROB (WM_NCMOUSEMOVE)
|
|
3780 FROB (WM_NCLBUTTONDOWN)
|
|
3781 FROB (WM_NCLBUTTONUP)
|
|
3782 FROB (WM_NCLBUTTONDBLCLK)
|
|
3783 FROB (WM_NCRBUTTONDOWN)
|
|
3784 FROB (WM_NCRBUTTONUP)
|
|
3785 FROB (WM_NCRBUTTONDBLCLK)
|
|
3786 FROB (WM_NCMBUTTONDOWN)
|
|
3787 FROB (WM_NCMBUTTONUP)
|
|
3788 FROB (WM_NCMBUTTONDBLCLK)
|
|
3789
|
|
3790 /* FROB (WM_KEYFIRST) */
|
|
3791 FROB (WM_KEYDOWN)
|
|
3792 FROB (WM_KEYUP)
|
|
3793 FROB (WM_CHAR)
|
|
3794 FROB (WM_DEADCHAR)
|
|
3795 FROB (WM_SYSKEYDOWN)
|
|
3796 FROB (WM_SYSKEYUP)
|
|
3797 FROB (WM_SYSCHAR)
|
|
3798 FROB (WM_SYSDEADCHAR)
|
|
3799 FROB (WM_KEYLAST)
|
|
3800
|
604
|
3801 #if(WINVER >= 0x0400) && defined (WM_IME_STARTCOMPOSITION)
|
|
3802 /* not in Cygwin? */
|
593
|
3803 FROB (WM_IME_STARTCOMPOSITION)
|
|
3804 FROB (WM_IME_ENDCOMPOSITION)
|
|
3805 FROB (WM_IME_COMPOSITION)
|
|
3806 FROB (WM_IME_KEYLAST)
|
604
|
3807 #endif /* WINVER >= 0x0400 && defined (WM_IME_STARTCOMPOSITION) */
|
593
|
3808
|
|
3809 FROB (WM_INITDIALOG)
|
|
3810 FROB (WM_COMMAND)
|
|
3811 FROB (WM_SYSCOMMAND)
|
|
3812 FROB (WM_TIMER)
|
|
3813 FROB (WM_HSCROLL)
|
|
3814 FROB (WM_VSCROLL)
|
|
3815 FROB (WM_INITMENU)
|
|
3816 FROB (WM_INITMENUPOPUP)
|
|
3817 FROB (WM_MENUSELECT)
|
|
3818 FROB (WM_MENUCHAR)
|
|
3819 FROB (WM_ENTERIDLE)
|
|
3820 #if(WINVER >= 0x0500)
|
|
3821 FROB (WM_MENURBUTTONUP)
|
|
3822 FROB (WM_MENUDRAG)
|
|
3823 FROB (WM_MENUGETOBJECT)
|
|
3824 FROB (WM_UNINITMENUPOPUP)
|
|
3825 FROB (WM_MENUCOMMAND)
|
|
3826 #endif /* WINVER >= 0x0500 */
|
|
3827
|
|
3828
|
|
3829 FROB (WM_CTLCOLORMSGBOX)
|
|
3830 FROB (WM_CTLCOLOREDIT)
|
|
3831 FROB (WM_CTLCOLORLISTBOX)
|
|
3832 FROB (WM_CTLCOLORBTN)
|
|
3833 FROB (WM_CTLCOLORDLG)
|
|
3834 FROB (WM_CTLCOLORSCROLLBAR)
|
|
3835 FROB (WM_CTLCOLORSTATIC)
|
|
3836
|
|
3837
|
|
3838 /* FROB (WM_MOUSEFIRST) */
|
|
3839 FROB (WM_MOUSEMOVE)
|
|
3840 FROB (WM_LBUTTONDOWN)
|
|
3841 FROB (WM_LBUTTONUP)
|
|
3842 FROB (WM_LBUTTONDBLCLK)
|
|
3843 FROB (WM_RBUTTONDOWN)
|
|
3844 FROB (WM_RBUTTONUP)
|
|
3845 FROB (WM_RBUTTONDBLCLK)
|
|
3846 FROB (WM_MBUTTONDOWN)
|
|
3847 FROB (WM_MBUTTONUP)
|
|
3848 FROB (WM_MBUTTONDBLCLK)
|
|
3849
|
|
3850 #if (_WIN32_WINNT >= 0x0400) || (_WIN32_WINDOWS > 0x0400)
|
|
3851 FROB (WM_MOUSEWHEEL)
|
|
3852 FROB (WM_MOUSELAST)
|
|
3853 #else
|
|
3854 FROB (WM_MOUSELAST)
|
|
3855 #endif /* if (_WIN32_WINNT < 0x0400) */
|
|
3856
|
|
3857 FROB (WM_PARENTNOTIFY)
|
|
3858 FROB (WM_ENTERMENULOOP)
|
|
3859 FROB (WM_EXITMENULOOP)
|
|
3860
|
|
3861 #if(WINVER >= 0x0400)
|
|
3862 FROB (WM_NEXTMENU)
|
|
3863
|
|
3864 FROB (WM_SIZING)
|
|
3865 FROB (WM_CAPTURECHANGED)
|
|
3866 FROB (WM_MOVING)
|
|
3867 FROB (WM_POWERBROADCAST)
|
|
3868
|
|
3869 FROB (WM_DEVICECHANGE)
|
|
3870
|
|
3871 #endif /* WINVER >= 0x0400 */
|
|
3872
|
|
3873 FROB (WM_MDICREATE)
|
|
3874 FROB (WM_MDIDESTROY)
|
|
3875 FROB (WM_MDIACTIVATE)
|
|
3876 FROB (WM_MDIRESTORE)
|
|
3877 FROB (WM_MDINEXT)
|
|
3878 FROB (WM_MDIMAXIMIZE)
|
|
3879 FROB (WM_MDITILE)
|
|
3880 FROB (WM_MDICASCADE)
|
|
3881 FROB (WM_MDIICONARRANGE)
|
|
3882 FROB (WM_MDIGETACTIVE)
|
|
3883
|
|
3884
|
|
3885 FROB (WM_MDISETMENU)
|
|
3886 FROB (WM_ENTERSIZEMOVE)
|
|
3887 FROB (WM_EXITSIZEMOVE)
|
|
3888 FROB (WM_DROPFILES)
|
|
3889 FROB (WM_MDIREFRESHMENU)
|
|
3890
|
604
|
3891 #ifdef WM_IME_SETCONTEXT /* not in Cygwin? */
|
593
|
3892
|
|
3893 #if(WINVER >= 0x0400)
|
|
3894 FROB (WM_IME_SETCONTEXT)
|
|
3895 FROB (WM_IME_NOTIFY)
|
|
3896 FROB (WM_IME_CONTROL)
|
|
3897 FROB (WM_IME_COMPOSITIONFULL)
|
|
3898 FROB (WM_IME_SELECT)
|
|
3899 FROB (WM_IME_CHAR)
|
|
3900 #endif /* WINVER >= 0x0400 */
|
|
3901 #if(WINVER >= 0x0500)
|
|
3902 FROB (WM_IME_REQUEST)
|
|
3903 #endif /* WINVER >= 0x0500 */
|
|
3904 #if(WINVER >= 0x0400)
|
|
3905 FROB (WM_IME_KEYDOWN)
|
|
3906 FROB (WM_IME_KEYUP)
|
|
3907 #endif /* WINVER >= 0x0400 */
|
|
3908
|
604
|
3909 #endif /* WM_IME_SETCONTEXT */
|
593
|
3910
|
|
3911 #if(_WIN32_WINNT >= 0x0400)
|
|
3912 FROB (WM_MOUSEHOVER)
|
|
3913 FROB (WM_MOUSELEAVE)
|
|
3914 #endif /* _WIN32_WINNT >= 0x0400 */
|
|
3915
|
|
3916 FROB (WM_CUT)
|
|
3917 FROB (WM_COPY)
|
|
3918 FROB (WM_PASTE)
|
|
3919 FROB (WM_CLEAR)
|
|
3920 FROB (WM_UNDO)
|
|
3921 FROB (WM_RENDERFORMAT)
|
|
3922 FROB (WM_RENDERALLFORMATS)
|
|
3923 FROB (WM_DESTROYCLIPBOARD)
|
|
3924 FROB (WM_DRAWCLIPBOARD)
|
|
3925 FROB (WM_PAINTCLIPBOARD)
|
|
3926 FROB (WM_VSCROLLCLIPBOARD)
|
|
3927 FROB (WM_SIZECLIPBOARD)
|
|
3928 FROB (WM_ASKCBFORMATNAME)
|
|
3929 FROB (WM_CHANGECBCHAIN)
|
|
3930 FROB (WM_HSCROLLCLIPBOARD)
|
|
3931 FROB (WM_QUERYNEWPALETTE)
|
|
3932 FROB (WM_PALETTEISCHANGING)
|
|
3933 FROB (WM_PALETTECHANGED)
|
|
3934 FROB (WM_HOTKEY)
|
|
3935
|
|
3936 #if(WINVER >= 0x0400)
|
|
3937 FROB (WM_PRINT)
|
|
3938 FROB (WM_PRINTCLIENT)
|
|
3939
|
|
3940 FROB (WM_HANDHELDFIRST)
|
|
3941 FROB (WM_HANDHELDLAST)
|
|
3942
|
|
3943 FROB (WM_AFXFIRST)
|
|
3944 FROB (WM_AFXLAST)
|
|
3945 #endif /* WINVER >= 0x0400 */
|
|
3946
|
|
3947 FROB (WM_PENWINFIRST)
|
|
3948 FROB (WM_PENWINLAST)
|
|
3949 };
|
|
3950
|
|
3951 #undef FROB
|
|
3952
|
|
3953 static void
|
|
3954 debug_output_mswin_message (HWND hwnd, UINT message_, WPARAM wParam,
|
|
3955 LPARAM lParam)
|
|
3956 {
|
|
3957 Lisp_Object frame = mswindows_find_frame (hwnd);
|
|
3958 int i;
|
|
3959 char *str = 0;
|
|
3960 /* struct mswin_message_debug *i_hate_cranking_out_code_like_this; */
|
|
3961
|
|
3962 for (i = 0; i < countof (debug_mswin_messages); i++)
|
|
3963 {
|
647
|
3964 if (debug_mswin_messages[i].mess == (int) message_)
|
593
|
3965 {
|
|
3966 str = debug_mswin_messages[i].string;
|
|
3967 break;
|
|
3968 }
|
|
3969 }
|
|
3970
|
|
3971 if (str)
|
|
3972 stderr_out ("%s", str);
|
|
3973 else
|
|
3974 stderr_out ("%x", message_);
|
|
3975
|
|
3976 if (debug_mswindows_events > 1)
|
|
3977 {
|
|
3978 stderr_out (" wparam=%d lparam=%d hwnd=%x frame: ",
|
|
3979 wParam, (int) lParam, (unsigned int) hwnd);
|
|
3980 debug_print (frame);
|
|
3981 }
|
|
3982 else
|
|
3983 stderr_out ("\n");
|
|
3984 }
|
|
3985
|
|
3986 #endif /* DEBUG_XEMACS */
|
|
3987
|
428
|
3988 /************************************************************************/
|
|
3989 /* initialization */
|
|
3990 /************************************************************************/
|
|
3991
|
|
3992 void
|
|
3993 reinit_vars_of_event_mswindows (void)
|
|
3994 {
|
|
3995 mswindows_in_modal_loop = 0;
|
|
3996 mswindows_pending_timers_count = 0;
|
|
3997
|
|
3998 mswindows_event_stream = xnew (struct event_stream);
|
|
3999
|
|
4000 mswindows_event_stream->event_pending_p = emacs_mswindows_event_pending_p;
|
442
|
4001 mswindows_event_stream->force_event_pending = 0;
|
428
|
4002 mswindows_event_stream->next_event_cb = emacs_mswindows_next_event;
|
|
4003 mswindows_event_stream->handle_magic_event_cb = emacs_mswindows_handle_magic_event;
|
|
4004 mswindows_event_stream->add_timeout_cb = emacs_mswindows_add_timeout;
|
|
4005 mswindows_event_stream->remove_timeout_cb = emacs_mswindows_remove_timeout;
|
|
4006 mswindows_event_stream->quit_p_cb = emacs_mswindows_quit_p;
|
|
4007 mswindows_event_stream->select_console_cb = emacs_mswindows_select_console;
|
|
4008 mswindows_event_stream->unselect_console_cb = emacs_mswindows_unselect_console;
|
|
4009 #ifdef HAVE_MSG_SELECT
|
|
4010 mswindows_event_stream->select_process_cb =
|
440
|
4011 (void (*)(Lisp_Process*))event_stream_unixoid_select_process;
|
428
|
4012 mswindows_event_stream->unselect_process_cb =
|
440
|
4013 (void (*)(Lisp_Process*))event_stream_unixoid_unselect_process;
|
428
|
4014 mswindows_event_stream->create_stream_pair_cb = event_stream_unixoid_create_stream_pair;
|
|
4015 mswindows_event_stream->delete_stream_pair_cb = event_stream_unixoid_delete_stream_pair;
|
|
4016 #else
|
|
4017 mswindows_event_stream->select_process_cb = emacs_mswindows_select_process;
|
|
4018 mswindows_event_stream->unselect_process_cb = emacs_mswindows_unselect_process;
|
|
4019 mswindows_event_stream->create_stream_pair_cb = emacs_mswindows_create_stream_pair;
|
|
4020 mswindows_event_stream->delete_stream_pair_cb = emacs_mswindows_delete_stream_pair;
|
|
4021 #endif
|
442
|
4022 mswindows_event_stream->current_event_timestamp_cb =
|
|
4023 emacs_mswindows_current_event_timestamp;
|
428
|
4024 }
|
|
4025
|
|
4026 void
|
|
4027 vars_of_event_mswindows (void)
|
|
4028 {
|
|
4029 reinit_vars_of_event_mswindows ();
|
|
4030
|
|
4031 mswindows_u_dispatch_event_queue = Qnil;
|
|
4032 staticpro (&mswindows_u_dispatch_event_queue);
|
|
4033 mswindows_u_dispatch_event_queue_tail = Qnil;
|
452
|
4034 dump_add_root_object (&mswindows_u_dispatch_event_queue_tail);
|
428
|
4035
|
|
4036 mswindows_s_dispatch_event_queue = Qnil;
|
|
4037 staticpro (&mswindows_s_dispatch_event_queue);
|
|
4038 mswindows_s_dispatch_event_queue_tail = Qnil;
|
452
|
4039 dump_add_root_object (&mswindows_s_dispatch_event_queue_tail);
|
428
|
4040
|
|
4041 mswindows_error_caught_in_modal_loop = Qnil;
|
|
4042 staticpro (&mswindows_error_caught_in_modal_loop);
|
|
4043
|
442
|
4044
|
|
4045 #ifdef DEBUG_XEMACS
|
|
4046 DEFVAR_INT ("debug-mswindows-events", &debug_mswindows_events /*
|
593
|
4047 If non-zero, display debug information about Windows messages that XEmacs sees.
|
442
|
4048 Information is displayed in a console window. Currently defined values are:
|
|
4049
|
593
|
4050 1 == non-verbose output (just the message name)
|
|
4051 2 == verbose output (all parameters)
|
|
4052 3 == even more verbose output (extra debugging info)
|
442
|
4053 */ );
|
|
4054 debug_mswindows_events = 0;
|
|
4055 #endif
|
|
4056
|
|
4057 DEFVAR_BOOL ("mswindows-alt-by-itself-activates-menu",
|
|
4058 &mswindows_alt_by_itself_activates_menu /*
|
|
4059 *Controls whether pressing and releasing the Alt key activates the menubar.
|
|
4060 This applies only if no intervening key was pressed. See also
|
|
4061 `menu-accelerator-enabled', which is probably the behavior you actually want.
|
428
|
4062 Default is t.
|
|
4063 */ );
|
|
4064
|
442
|
4065 DEFVAR_BOOL ("mswindows-dynamic-frame-resize",
|
|
4066 &mswindows_dynamic_frame_resize /*
|
428
|
4067 *Controls redrawing frame contents during mouse-drag or keyboard resize
|
|
4068 operation. When non-nil, the frame is redrawn while being resized. When
|
|
4069 nil, frame is not redrawn, and exposed areas are filled with default
|
|
4070 MDI application background color. Note that this option only has effect
|
|
4071 if "Show window contents while dragging" is on in system Display/Plus!
|
|
4072 settings.
|
|
4073 Default is t on fast machines, nil on slow.
|
|
4074 */ );
|
|
4075
|
442
|
4076 DEFVAR_INT ("mswindows-mouse-button-tolerance",
|
|
4077 &mswindows_mouse_button_tolerance /*
|
428
|
4078 *Analogue of double click interval for faking middle mouse events.
|
|
4079 The value is the minimum time in milliseconds that must elapse between
|
|
4080 left/right button down events before they are considered distinct events.
|
|
4081 If both mouse buttons are depressed within this interval, a middle mouse
|
|
4082 button down event is generated instead.
|
|
4083 If negative or zero, currently set system default is used instead.
|
|
4084 */ );
|
|
4085
|
|
4086 DEFVAR_INT ("mswindows-num-mouse-buttons", &mswindows_num_mouse_buttons /*
|
|
4087 Number of physical mouse buttons.
|
|
4088 */ );
|
|
4089
|
442
|
4090 DEFVAR_INT ("mswindows-mouse-button-max-skew-x",
|
|
4091 &mswindows_mouse_button_max_skew_x /*
|
428
|
4092 *Maximum horizontal distance in pixels between points in which left and
|
|
4093 right button clicks occurred for them to be translated into single
|
|
4094 middle button event. Clicks must occur in time not longer than defined
|
|
4095 by the variable `mswindows-mouse-button-tolerance'.
|
|
4096 If negative or zero, currently set system default is used instead.
|
|
4097 */ );
|
|
4098
|
442
|
4099 DEFVAR_INT ("mswindows-mouse-button-max-skew-y",
|
|
4100 &mswindows_mouse_button_max_skew_y /*
|
428
|
4101 *Maximum vertical distance in pixels between points in which left and
|
|
4102 right button clicks occurred for them to be translated into single
|
|
4103 middle button event. Clicks must occur in time not longer than defined
|
|
4104 by the variable `mswindows-mouse-button-tolerance'.
|
|
4105 If negative or zero, currently set system default is used instead.
|
|
4106 */ );
|
|
4107
|
|
4108 mswindows_mouse_button_max_skew_x = 0;
|
|
4109 mswindows_mouse_button_max_skew_y = 0;
|
|
4110 mswindows_mouse_button_tolerance = 0;
|
442
|
4111 mswindows_alt_by_itself_activates_menu = 1;
|
428
|
4112 }
|
|
4113
|
|
4114 void
|
|
4115 syms_of_event_mswindows (void)
|
|
4116 {
|
|
4117 }
|
|
4118
|
|
4119 void
|
|
4120 lstream_type_create_mswindows_selectable (void)
|
|
4121 {
|
|
4122 init_slurp_stream ();
|
|
4123 init_shove_stream ();
|
502
|
4124 #if defined (HAVE_SOCKETS) && !defined (HAVE_MSG_SELECT)
|
428
|
4125 init_winsock_stream ();
|
|
4126 #endif
|
|
4127 }
|
|
4128
|
|
4129 void
|
|
4130 init_event_mswindows_late (void)
|
|
4131 {
|
|
4132 #ifdef HAVE_MSG_SELECT
|
|
4133 windows_fd = open("/dev/windows", O_RDONLY | O_NONBLOCK, 0);
|
|
4134 assert (windows_fd>=0);
|
|
4135 FD_SET (windows_fd, &input_wait_mask);
|
|
4136 FD_ZERO(&zero_mask);
|
|
4137 #endif
|
|
4138
|
|
4139 event_stream = mswindows_event_stream;
|
|
4140
|
|
4141 mswindows_dynamic_frame_resize = !GetSystemMetrics (SM_SLOWMACHINE);
|
|
4142 mswindows_num_mouse_buttons = GetSystemMetrics (SM_CMOUSEBUTTONS);
|
|
4143 }
|