213
|
1 /* The mswindows event_stream interface.
|
|
2 Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
4 Copyright (C) 1996 Ben Wing.
|
|
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 20.4.
|
|
31 */
|
|
32
|
|
33 #include <config.h>
|
|
34 #include "lisp.h"
|
|
35
|
249
|
36 #include "console-msw.h"
|
|
37
|
|
38 #ifdef HAVE_SCROLLBARS
|
|
39 # include "scrollbar-msw.h"
|
|
40 #endif
|
|
41
|
|
42 #ifdef HAVE_MENUBARS
|
|
43 # include "menubar-msw.h"
|
|
44 #endif
|
|
45
|
213
|
46 #include "device.h"
|
227
|
47 #include "emacsfns.h"
|
213
|
48 #include "events.h"
|
|
49 #include "frame.h"
|
|
50 #include "process.h"
|
227
|
51 #include "redisplay.h"
|
213
|
52 #include "sysproc.h"
|
|
53 #include "syswait.h"
|
|
54 #include "systime.h"
|
|
55
|
249
|
56 #include "events-mod.h"
|
|
57
|
|
58 #ifdef HAVE_MENUBARS
|
|
59 #define ADJR_MENUFLAG TRUE
|
|
60 #else
|
|
61 #define ADJR_MENUFLAG FALSE
|
|
62 #endif
|
|
63
|
|
64 /* Fake key modifier which is attached to a quit char event.
|
|
65 Removed upon dequeueing an event */
|
|
66 #define FAKE_MOD_QUIT 0x80
|
|
67
|
|
68 /* Timer ID used for button2 emulation */
|
|
69 #define BUTTON_2_TIMER_ID 1
|
|
70
|
|
71 /* Drag and drop event data types (subset of types in offix-types.h) */
|
|
72 #define DndFile 2
|
|
73 #define DndFiles 3
|
|
74 #define DndText 4
|
|
75
|
|
76
|
|
77 static Lisp_Object mswindows_find_frame (HWND hwnd);
|
|
78 static Lisp_Object mswindows_find_console (HWND hwnd);
|
|
79 static Lisp_Object mswindows_key_to_emacs_keysym(int mswindows_key, int mods);
|
|
80 static int mswindows_modifier_state (BYTE* keymap, int has_AltGr);
|
|
81 static void mswindows_set_chord_timer (HWND hwnd);
|
|
82 static int mswindows_button2_near_enough (POINTS p1, POINTS p2);
|
|
83 static int mswindows_current_layout_has_AltGr (void);
|
|
84
|
213
|
85
|
|
86 static struct event_stream *mswindows_event_stream;
|
223
|
87
|
|
88 /*
|
|
89 * Two separate queues, for efficiency, one (_u_) for user events, and
|
|
90 * another (_s_) for non-user ones. We always return events out of the
|
|
91 * first one until it is empty and only then proceed with the second
|
|
92 * one.
|
|
93 */
|
|
94 static Lisp_Object mswindows_u_dispatch_event_queue, mswindows_u_dispatch_event_queue_tail;
|
|
95 static Lisp_Object mswindows_s_dispatch_event_queue, mswindows_s_dispatch_event_queue_tail;
|
213
|
96
|
249
|
97 /* The number of things we can wait on */
|
|
98 #define MAX_WAITABLE (MAXIMUM_WAIT_OBJECTS - 1)
|
|
99
|
|
100 /* List of mswindows waitable handles. */
|
213
|
101 static HANDLE mswindows_waitable[MAX_WAITABLE];
|
|
102
|
223
|
103 /* Count of quit chars currently in the queue */
|
249
|
104 /* Incremented in WM_[SYS]KEYDOWN handler in the mswindows_wnd_proc()
|
223
|
105 Decremented in mswindows_dequeue_dispatch_event() */
|
|
106 int mswindows_quit_chars_count = 0;
|
|
107
|
|
108 /* These are Lisp integers; see DEFVARS in this file for description. */
|
|
109 int mswindows_dynamic_frame_resize;
|
|
110 int mswindows_num_mouse_buttons;
|
|
111 int mswindows_button2_max_skew_x;
|
|
112 int mswindows_button2_max_skew_y;
|
|
113 int mswindows_button2_chord_time;
|
|
114
|
219
|
115 /* Number of wait handles */
|
245
|
116 static int mswindows_waitable_count=0;
|
219
|
117
|
227
|
118 /* This is the event signaled by the event pump.
|
|
119 See mswindows_pump_outstanding_events for comments */
|
231
|
120 static Lisp_Object mswindows_error_caught_in_modal_loop;
|
|
121 static int mswindows_in_modal_loop;
|
227
|
122
|
|
123 /* Count of wound timers */
|
|
124 static int mswindows_pending_timers_count;
|
|
125
|
223
|
126 static int
|
|
127 mswindows_user_event_p (struct Lisp_Event* sevt)
|
|
128 {
|
|
129 return (sevt->event_type == key_press_event
|
|
130 || sevt->event_type == button_press_event
|
249
|
131 || sevt->event_type == button_release_event
|
|
132 || sevt->event_type == dnd_drop_event);
|
223
|
133 }
|
|
134
|
249
|
135 /************************************************************************/
|
|
136 /* Dispatch queue management */
|
|
137 /************************************************************************/
|
|
138
|
|
139 /*
|
223
|
140 * Add an emacs event to the proper dispatch queue
|
219
|
141 */
|
213
|
142 void
|
|
143 mswindows_enqueue_dispatch_event (Lisp_Object event)
|
|
144 {
|
223
|
145 int user_p = mswindows_user_event_p (XEVENT(event));
|
|
146 enqueue_event (event,
|
|
147 user_p ? &mswindows_u_dispatch_event_queue :
|
|
148 &mswindows_s_dispatch_event_queue,
|
|
149 user_p ? &mswindows_u_dispatch_event_queue_tail :
|
|
150 &mswindows_s_dispatch_event_queue_tail);
|
|
151
|
|
152 /* This one does not go to window procedure, hence does not
|
|
153 generate XM_BUMPQUEUE magic event! */
|
|
154 PostMessage (NULL, XM_BUMPQUEUE, 0, 0);
|
213
|
155 }
|
|
156
|
249
|
157 void
|
|
158 mswindows_enqueue_magic_event (HWND hwnd, UINT message)
|
|
159 {
|
|
160 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
161 struct Lisp_Event* event = XEVENT (emacs_event);
|
|
162
|
|
163 event->channel = mswindows_find_frame (hwnd);
|
|
164 event->timestamp = GetMessageTime();
|
|
165 event->event_type = magic_event;
|
|
166 EVENT_MSWINDOWS_MAGIC_TYPE (event) = message;
|
|
167
|
|
168 mswindows_enqueue_dispatch_event (emacs_event);
|
|
169 }
|
|
170
|
|
171 static void
|
|
172 mswindows_enqueue_mouse_button_event (HWND hwnd, UINT message, POINTS where, DWORD when)
|
|
173 {
|
|
174
|
|
175 /* We always use last message time, because mouse button
|
|
176 events may get delayed, and XEmacs double click
|
|
177 recognition will fail */
|
|
178
|
|
179 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
180 struct Lisp_Event* event = XEVENT(emacs_event);
|
|
181
|
|
182 event->channel = mswindows_find_frame(hwnd);
|
|
183 event->timestamp = when;
|
|
184 event->event.button.button =
|
|
185 (message==WM_LBUTTONDOWN || message==WM_LBUTTONUP) ? 1 :
|
|
186 ((message==WM_RBUTTONDOWN || message==WM_RBUTTONUP) ? 3 : 2);
|
|
187 event->event.button.x = where.x;
|
|
188 event->event.button.y = where.y;
|
|
189 event->event.button.modifiers = mswindows_modifier_state (NULL, 0);
|
|
190
|
|
191 if (message==WM_LBUTTONDOWN || message==WM_MBUTTONDOWN ||
|
|
192 message==WM_RBUTTONDOWN)
|
|
193 {
|
|
194 event->event_type = button_press_event;
|
|
195 SetCapture (hwnd);
|
|
196 }
|
|
197 else
|
|
198 {
|
|
199 event->event_type = button_release_event;
|
|
200 ReleaseCapture ();
|
|
201 }
|
|
202
|
|
203 mswindows_enqueue_dispatch_event (emacs_event);
|
|
204 }
|
|
205
|
|
206 static void
|
|
207 mswindows_enqueue_keypress_event (HWND hwnd, Lisp_Object keysym, int mods)
|
|
208 {
|
|
209 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
210 struct Lisp_Event* event = XEVENT(emacs_event);
|
|
211
|
|
212 event->channel = mswindows_find_console(hwnd);
|
|
213 event->timestamp = GetMessageTime();
|
|
214 event->event_type = key_press_event;
|
|
215 event->event.key.keysym = keysym;
|
|
216 event->event.key.modifiers = mods;
|
|
217 mswindows_enqueue_dispatch_event (emacs_event);
|
|
218 }
|
|
219
|
219
|
220 /*
|
223
|
221 * Remove and return the first emacs event on the dispatch queue.
|
|
222 * Give a preference to user events over non-user ones.
|
219
|
223 */
|
213
|
224 static Lisp_Object
|
223
|
225 mswindows_dequeue_dispatch_event ()
|
213
|
226 {
|
|
227 Lisp_Object event;
|
223
|
228 struct Lisp_Event* sevt;
|
|
229
|
|
230 assert (!NILP(mswindows_u_dispatch_event_queue) ||
|
|
231 !NILP(mswindows_s_dispatch_event_queue));
|
|
232
|
|
233 event = dequeue_event (
|
|
234 NILP(mswindows_u_dispatch_event_queue) ?
|
|
235 &mswindows_s_dispatch_event_queue :
|
|
236 &mswindows_u_dispatch_event_queue,
|
|
237 NILP(mswindows_u_dispatch_event_queue) ?
|
|
238 &mswindows_s_dispatch_event_queue_tail :
|
|
239 &mswindows_u_dispatch_event_queue_tail);
|
|
240
|
|
241 sevt = XEVENT(event);
|
|
242 if (sevt->event_type == key_press_event
|
|
243 && (sevt->event.key.modifiers & FAKE_MOD_QUIT))
|
|
244 {
|
|
245 sevt->event.key.modifiers &= ~FAKE_MOD_QUIT;
|
|
246 --mswindows_quit_chars_count;
|
|
247 }
|
|
248
|
213
|
249 return event;
|
|
250 }
|
|
251
|
|
252 /*
|
219
|
253 * Remove and return the first emacs event on the dispatch queue that matches
|
223
|
254 * the supplied event
|
|
255 * Timeout event matches if interval_id equals to that of the given event.
|
|
256 * Keypress event matches if logical AND between modifiers bitmask of the
|
|
257 * event in the queue and that of the given event is non-zero
|
|
258 * For all other event types, this function asserts.
|
219
|
259 */
|
223
|
260
|
219
|
261 Lisp_Object
|
223
|
262 mswindows_cancel_dispatch_event (struct Lisp_Event* match)
|
219
|
263 {
|
|
264 Lisp_Object event;
|
|
265 Lisp_Object previous_event=Qnil;
|
223
|
266 int user_p = mswindows_user_event_p (match);
|
|
267 Lisp_Object* head = user_p ? &mswindows_u_dispatch_event_queue :
|
|
268 &mswindows_s_dispatch_event_queue;
|
|
269 Lisp_Object* tail = user_p ? &mswindows_u_dispatch_event_queue_tail :
|
|
270 &mswindows_s_dispatch_event_queue_tail;
|
219
|
271
|
223
|
272 assert (match->event_type == timeout_event
|
|
273 || match->event_type == key_press_event);
|
219
|
274
|
223
|
275 EVENT_CHAIN_LOOP (event, *head)
|
|
276 {
|
|
277 int found = 1;
|
|
278 if (XEVENT_TYPE (event) != match->event_type)
|
|
279 found = 0;
|
|
280 if (found && match->event_type == timeout_event
|
|
281 && (XEVENT(event)->event.timeout.interval_id !=
|
|
282 match->event.timeout.interval_id))
|
|
283 found = 0;
|
|
284 if (found && match->event_type == key_press_event
|
|
285 && ((XEVENT(event)->event.key.modifiers &
|
|
286 match->event.key.modifiers) == 0))
|
|
287 found = 0;
|
|
288
|
|
289 if (found)
|
|
290 {
|
|
291 if (NILP (previous_event))
|
|
292 dequeue_event (head, tail);
|
|
293 else
|
|
294 {
|
|
295 XSET_EVENT_NEXT (previous_event, XEVENT_NEXT (event));
|
|
296 if (EQ (*tail, event))
|
|
297 *tail = previous_event;
|
|
298 }
|
|
299
|
|
300 return event;
|
|
301 }
|
219
|
302 previous_event = event;
|
223
|
303 }
|
239
|
304 return Qnil;
|
219
|
305 }
|
|
306
|
249
|
307
|
|
308 /************************************************************************/
|
|
309 /* Event pump */
|
|
310 /************************************************************************/
|
|
311
|
231
|
312 static Lisp_Object
|
|
313 mswindows_modal_loop_error_handler (Lisp_Object cons_sig_data,
|
|
314 Lisp_Object u_n_u_s_e_d)
|
|
315 {
|
|
316 mswindows_error_caught_in_modal_loop = cons_sig_data;
|
|
317 return Qunbound;
|
|
318 }
|
|
319
|
|
320 Lisp_Object
|
|
321 mswindows_protect_modal_loop (Lisp_Object (*bfun) (Lisp_Object barg),
|
|
322 Lisp_Object barg)
|
|
323 {
|
|
324 Lisp_Object tmp;
|
|
325
|
|
326 ++mswindows_in_modal_loop;
|
|
327 tmp = condition_case_1 (Qt,
|
|
328 bfun, barg,
|
|
329 mswindows_modal_loop_error_handler, Qnil);
|
|
330 --mswindows_in_modal_loop;
|
|
331
|
|
332 return tmp;
|
|
333 }
|
|
334
|
|
335 void
|
|
336 mswindows_unmodalize_signal_maybe (void)
|
|
337 {
|
|
338 if (!NILP (mswindows_error_caught_in_modal_loop))
|
|
339 {
|
|
340 /* Got an error while messages were pumped while
|
|
341 in window procedure - have to resignal */
|
|
342 Lisp_Object sym = XCAR (mswindows_error_caught_in_modal_loop);
|
|
343 Lisp_Object data = XCDR (mswindows_error_caught_in_modal_loop);
|
|
344 mswindows_error_caught_in_modal_loop = Qnil;
|
|
345 Fsignal (sym, data);
|
|
346 }
|
|
347 }
|
|
348
|
219
|
349 /*
|
227
|
350 * This is an unsafe part of event pump, guarded by
|
|
351 * condition_case. See mswindows_pump_outstanding_events
|
|
352 */
|
|
353 static Lisp_Object
|
|
354 mswindows_unsafe_pump_events (Lisp_Object u_n_u_s_e_d)
|
|
355 {
|
|
356 /* This function can call lisp */
|
|
357 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
|
358 struct gcpro gcpro1;
|
|
359 int do_redisplay = 0;
|
|
360 GCPRO1 (event);
|
|
361
|
|
362 while (detect_input_pending ())
|
|
363 {
|
|
364 Fnext_event (event, Qnil);
|
|
365 Fdispatch_event (event);
|
|
366 do_redisplay = 1;
|
|
367 }
|
|
368
|
|
369 if (do_redisplay)
|
|
370 redisplay ();
|
|
371
|
|
372 Fdeallocate_event (event);
|
|
373 UNGCPRO;
|
|
374
|
|
375 /* Qt becomes return value of mswindows_pump_outstanding_events
|
|
376 once we get here */
|
|
377 return Qt;
|
|
378 }
|
|
379
|
|
380 /*
|
|
381 * This function pumps emacs events, while available, by using
|
|
382 * next_message/dispatch_message loop. Errors are trapped around
|
|
383 * the loop so the function always returns.
|
|
384 *
|
|
385 * Windows message queue is not looked into during the call,
|
|
386 * neither are waitable handles checked. The function pumps
|
|
387 * thus only dispatch events already queued, as well as those
|
|
388 * resulted in dispatching thereof. This is done by setting
|
231
|
389 * module local variable mswidows_in_modal_loop to nonzero.
|
227
|
390 *
|
231
|
391 * Return value is Qt if no errors was trapped, or Qunbound if
|
227
|
392 * there was an error.
|
|
393 *
|
|
394 * In case of error, a cons representing the error, in the
|
|
395 * form (SIGNAL . DATA), is stored in the module local variable
|
231
|
396 * mswindows_error_caught_in_modal_loop. This error is signaled
|
227
|
397 * again when DispatchMessage returns. Thus, Windows internal
|
|
398 * modal loops are protected against throws, which are proven
|
|
399 * to corrupt internal Windows structures.
|
|
400 *
|
231
|
401 * In case of success, mswindows_error_caught_in_modal_loop is
|
227
|
402 * assigned Qnil.
|
|
403 *
|
231
|
404 * If the value of mswindows_error_caught_in_modal_loop is not
|
227
|
405 * nil already upon entry, the function just returns non-nil.
|
|
406 * This situation means that a new event has been queued while
|
|
407 * cancleng mode. The event will be dequeued on the next regular
|
|
408 * call of next-event; the pump is off since error is caught.
|
|
409 * The caller must *unconditionally* cancel modal loop if the
|
|
410 * value returned by this function is nil. Otherwise, everything
|
|
411 * will become frozen until the modal loop exits under normal
|
|
412 * condition (scrollbar drag is released, menu closed etc.)
|
|
413 */
|
|
414 Lisp_Object
|
|
415 mswindows_pump_outstanding_events (void)
|
|
416 {
|
|
417 /* This function can call lisp */
|
|
418
|
|
419 Lisp_Object result = Qt;
|
249
|
420 struct gcpro gcpro1;
|
|
421 GCPRO1 (result);
|
|
422
|
231
|
423 if (NILP(mswindows_error_caught_in_modal_loop))
|
|
424 result = mswindows_protect_modal_loop (mswindows_unsafe_pump_events, Qnil);
|
249
|
425 UNGCPRO;
|
227
|
426 return result;
|
|
427 }
|
|
428
|
213
|
429
|
223
|
430
|
|
431 static void
|
|
432 mswindows_drain_windows_queue ()
|
|
433 {
|
|
434 MSG msg;
|
|
435 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
|
227
|
436 {
|
|
437 DispatchMessage (&msg);
|
231
|
438 mswindows_unmodalize_signal_maybe ();
|
227
|
439 }
|
|
440 }
|
|
441
|
|
442 /*
|
|
443 * This is a special flavour of the mswindows_need_event function,
|
|
444 * used while in event pump. Actually, there is only kind of events
|
|
445 * allowed while in event pump: a timer. An attempt to fetch any
|
|
446 * other event leads to a dealock, as there's no source of user input
|
|
447 * ('cause event pump mirrors windows modal loop, which is a sole
|
|
448 * owner of thread message queue).
|
|
449 *
|
|
450 * To detect this, we use a counter of active timers, and allow
|
|
451 * fetching WM_TIMER messages. Instead of trying to fetch a WM_TIMER
|
|
452 * which will never come when there are no pending timers, which leads
|
|
453 * to deadlock, we simply signal an error.
|
|
454 *
|
|
455 * The implementation does not honor user_p by design.
|
|
456 */
|
|
457 static void
|
231
|
458 mswindows_need_event_in_modal_loop (int user_p, int badly_p)
|
227
|
459 {
|
|
460 MSG msg;
|
|
461
|
|
462 /* Check if already have one */
|
|
463 if (!NILP (mswindows_u_dispatch_event_queue)
|
|
464 || !NILP (mswindows_s_dispatch_event_queue))
|
|
465 return;
|
|
466
|
|
467 /* No event is ok */
|
|
468 if (!badly_p)
|
|
469 return;
|
|
470
|
|
471 /* We do not check the _u_ queue, because timers go to _s_ */
|
|
472 while (NILP (mswindows_s_dispatch_event_queue))
|
|
473 {
|
|
474 /* We'll deadlock if go waiting */
|
|
475 if (mswindows_pending_timers_count == 0)
|
|
476 error ("Deadlock due to an attempt to call next-event in a wrong context");
|
|
477
|
|
478 /* Fetch and dispatch any pending timers */
|
|
479 GetMessage (&msg, NULL, WM_TIMER, WM_TIMER);
|
|
480 DispatchMessage (&msg);
|
|
481 }
|
223
|
482 }
|
|
483
|
|
484 /*
|
|
485 * This drains the event queue and fills up two internal queues until
|
|
486 * an event of a type specified by USER_P is retrieved.
|
|
487 *
|
|
488 * If user_p, then the function drains until the first user event, or
|
|
489 * the first non-user event if there no user events. Otherwise, If
|
|
490 * not user_p, it does not give preference to user events.
|
|
491 *
|
|
492 * If badly_p, then the function does not return until an event is
|
|
493 * available.
|
|
494 *
|
|
495 * The code does not rely on MsgWaitForMultipleObjects preference for
|
|
496 * messages over waitable handles.
|
|
497 *
|
|
498 * Used by emacs_mswindows_event_pending_p and emacs_mswindows_next_event
|
|
499 */
|
|
500 static void
|
|
501 mswindows_need_event (int user_p, int badly_p)
|
|
502 {
|
|
503 int active;
|
|
504
|
231
|
505 if (mswindows_in_modal_loop)
|
227
|
506 {
|
231
|
507 mswindows_need_event_in_modal_loop (user_p, badly_p);
|
227
|
508 return;
|
|
509 }
|
|
510
|
223
|
511 /* Have to drain Windows message queue first, otherwise, we may miss
|
|
512 quit char when called from quit_p */
|
|
513 mswindows_drain_windows_queue ();
|
|
514
|
|
515 while (NILP (mswindows_u_dispatch_event_queue) &&
|
|
516 (user_p || NILP (mswindows_s_dispatch_event_queue)))
|
|
517 {
|
|
518 /* If we already have an event, we've got someting to return - no wait! */
|
|
519 if (!NILP (mswindows_u_dispatch_event_queue)
|
|
520 || !NILP (mswindows_s_dispatch_event_queue))
|
|
521 badly_p = 0;
|
|
522
|
|
523 /* Now try getting a message */
|
|
524 active = MsgWaitForMultipleObjects (mswindows_waitable_count,
|
|
525 mswindows_waitable,
|
|
526 FALSE, badly_p ? INFINITE : 0,
|
|
527 QS_ALLINPUT);
|
|
528
|
|
529 /* This will assert if handle being waited for becomes abandoned.
|
|
530 Not the case currently tho */
|
|
531 assert ((!badly_p && active == WAIT_TIMEOUT) ||
|
|
532 (active >= WAIT_OBJECT_0 &&
|
|
533 active <= WAIT_OBJECT_0 + mswindows_waitable_count));
|
|
534
|
|
535 if (active == WAIT_TIMEOUT)
|
|
536 {
|
|
537 /* No luck trying - just return what we've already got */
|
|
538 return;
|
|
539 }
|
|
540 else if (active == WAIT_OBJECT_0 + mswindows_waitable_count)
|
|
541 {
|
|
542 /* Got your message, thanks */
|
|
543 mswindows_drain_windows_queue ();
|
|
544 }
|
|
545 else
|
|
546 {
|
|
547 /* XXX FIXME: We should do some kind of round-robin scheme to ensure fairness */
|
|
548 int waitable = active - WAIT_OBJECT_0;
|
249
|
549 assert(0); /* #### */
|
223
|
550 }
|
|
551 } /* while */
|
|
552
|
|
553 return;
|
|
554 }
|
|
555
|
249
|
556 /************************************************************************/
|
|
557 /* Event generators */
|
|
558 /************************************************************************/
|
|
559
|
|
560 /*
|
|
561 * Callback procedure for synchronous timer messages
|
|
562 */
|
|
563 static void CALLBACK
|
|
564 mswindows_wm_timer_callback (HWND hwnd, UINT umsg, UINT id_timer, DWORD dwtime)
|
|
565 {
|
|
566 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
567 struct Lisp_Event *event = XEVENT (emacs_event);
|
|
568
|
|
569 if (KillTimer (NULL, id_timer))
|
|
570 --mswindows_pending_timers_count;
|
|
571
|
|
572 event->channel = Qnil;
|
|
573 event->timestamp = dwtime;
|
|
574 event->event_type = timeout_event;
|
|
575 event->event.timeout.interval_id = id_timer;
|
|
576
|
|
577 mswindows_enqueue_dispatch_event (emacs_event);
|
|
578 }
|
|
579
|
|
580 /*
|
|
581 * Callback procedure for dde messages
|
|
582 */
|
|
583 HDDEDATA CALLBACK
|
|
584 mswindows_dde_callback (UINT uType, UINT uFmt, HCONV hconv,
|
|
585 HSZ hszTopic, HSZ hszItem, HDDEDATA hdata,
|
|
586 DWORD dwData1, DWORD dwData2)
|
|
587 {
|
|
588 switch (uType)
|
|
589 {
|
|
590 case XTYP_CONNECT:
|
|
591 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system))
|
|
592 return (HDDEDATA)TRUE;
|
|
593 return (HDDEDATA)FALSE;
|
|
594
|
|
595 case XTYP_WILDCONNECT:
|
|
596 {
|
|
597 /* We only support one {service,topic} pair */
|
|
598 HSZPAIR pairs[2] = {
|
|
599 { mswindows_dde_service, mswindows_dde_topic_system }, { 0, 0 } };
|
|
600
|
|
601 if (!(hszItem || DdeCmpStringHandles (hszItem, mswindows_dde_service)) &&
|
|
602 !(hszTopic || DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system)));
|
|
603 return (DdeCreateDataHandle (mswindows_dde_mlid, (LPBYTE)pairs,
|
|
604 sizeof (pairs), 0L, 0, uFmt, 0));
|
|
605 }
|
|
606 return (HDDEDATA)NULL;
|
|
607
|
|
608 case XTYP_EXECUTE:
|
|
609 if (!DdeCmpStringHandles (hszTopic, mswindows_dde_topic_system))
|
|
610 {
|
|
611 DWORD len = DdeGetData (hdata, NULL, 0, 0);
|
|
612 char *cmd = alloca (len+1);
|
|
613 char *end;
|
|
614 Lisp_Object l_dndlist;
|
|
615 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
616 struct Lisp_Event *event = XEVENT (emacs_event);
|
|
617
|
|
618 DdeGetData (hdata, cmd, len, 0);
|
|
619 cmd[len] = '\0';
|
|
620 DdeFreeDataHandle (hdata);
|
|
621
|
|
622 /* Check syntax & that it's an [Open("foo")] command */
|
|
623 /* #### Ought to be generalised and accept some other commands */
|
|
624 if (*cmd == '[')
|
|
625 cmd++;
|
|
626 if (strnicmp (cmd, MSWINDOWS_DDE_ITEM_OPEN,
|
|
627 strlen (MSWINDOWS_DDE_ITEM_OPEN)))
|
|
628 return DDE_FNOTPROCESSED;
|
|
629 cmd += strlen (MSWINDOWS_DDE_ITEM_OPEN);
|
|
630 while (*cmd==' ')
|
|
631 cmd++;
|
|
632 if (*cmd!='(' || *(cmd+1)!='\"')
|
|
633 return DDE_FNOTPROCESSED;
|
|
634 end = (cmd+=2);
|
|
635 while (*end && *end!='\"')
|
|
636 end++;
|
|
637 if (!*end)
|
|
638 return DDE_FNOTPROCESSED;
|
|
639 *end = '\0';
|
|
640 if (*(++end)!=')')
|
|
641 return DDE_FNOTPROCESSED;
|
|
642 if (*(++end)==']')
|
|
643 end++;
|
|
644 if (*end)
|
|
645 return DDE_FNOTPROCESSED;
|
|
646
|
|
647 l_dndlist = make_ext_string (cmd, strlen(cmd), FORMAT_FILENAME);
|
|
648
|
|
649 event->channel = Qnil;
|
|
650 event->timestamp = GetTickCount();
|
|
651 event->event_type = dnd_drop_event;
|
|
652 event->event.dnd_drop.button = 0;
|
|
653 event->event.dnd_drop.modifiers = 0;
|
|
654 event->event.dnd_drop.x = -1;
|
|
655 event->event.dnd_drop.y = -1;
|
|
656 event->event.dnd_drop.data = Fcons (make_int (DndFile),
|
|
657 Fcons (l_dndlist, Qnil));
|
|
658 mswindows_enqueue_dispatch_event (emacs_event);
|
|
659
|
|
660 return (HDDEDATA) DDE_FACK;
|
|
661 }
|
|
662 DdeFreeDataHandle (hdata);
|
|
663 return (HDDEDATA) DDE_FNOTPROCESSED;
|
|
664
|
|
665 default:
|
|
666 return (HDDEDATA) NULL;
|
|
667 }
|
|
668
|
|
669 }
|
|
670
|
|
671 /*
|
|
672 * The windows procedure for the window class XEMACS_CLASS
|
|
673 */
|
|
674 LRESULT WINAPI
|
|
675 mswindows_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
676 {
|
|
677 /* Note: Remember to initialise emacs_event and event before use.
|
|
678 This code calls code that can GC. You must GCPRO before calling such code. */
|
|
679 Lisp_Object emacs_event = Qnil;
|
|
680 Lisp_Object fobj = Qnil;
|
|
681
|
|
682 struct Lisp_Event *event;
|
|
683 struct frame *frame;
|
|
684 struct mswindows_frame* msframe;
|
|
685
|
|
686 switch (message)
|
|
687 {
|
|
688 case WM_ERASEBKGND:
|
|
689 /* Erase background only during non-dynamic sizing */
|
|
690 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
691 if (msframe->sizing && !mswindows_dynamic_frame_resize)
|
|
692 goto defproc;
|
|
693 return 1;
|
|
694
|
|
695 case WM_CLOSE:
|
|
696 fobj = mswindows_find_frame (hwnd);
|
|
697 enqueue_misc_user_event (fobj, Qeval, list3 (Qdelete_frame, fobj, Qt));
|
|
698 mswindows_enqueue_magic_event (hwnd, XM_BUMPQUEUE);
|
|
699 break;
|
|
700
|
|
701 case WM_KEYDOWN:
|
|
702 case WM_SYSKEYDOWN:
|
|
703 {
|
|
704 BYTE keymap[256];
|
|
705 int has_AltGr = mswindows_current_layout_has_AltGr ();
|
|
706 int mods;
|
|
707 Lisp_Object keysym;
|
|
708
|
|
709 GetKeyboardState (keymap);
|
|
710 mods = mswindows_modifier_state (keymap, has_AltGr);
|
|
711
|
|
712 /* Handle those keys that TranslateMessage won't generate a WM_CHAR for */
|
|
713 if (!NILP (keysym = mswindows_key_to_emacs_keysym(wParam, mods)))
|
|
714 mswindows_enqueue_keypress_event (hwnd, keysym, mods);
|
|
715 else
|
|
716 {
|
|
717 int quit_ch = CONSOLE_QUIT_CHAR (XCONSOLE (mswindows_find_console (hwnd)));
|
|
718 BYTE keymap_orig[256];
|
|
719 MSG msg = { hwnd, message, wParam, lParam, GetMessageTime(), (GetMessagePos()) };
|
|
720 memcpy (keymap_orig, keymap, 256);
|
|
721
|
|
722 /* Clear control and alt modifiers out of the keymap */
|
|
723 keymap [VK_RCONTROL] = 0;
|
|
724 keymap [VK_LMENU] = 0;
|
|
725 if (!has_AltGr || !(keymap [VK_LCONTROL] & 0x80) || !(keymap [VK_RMENU] & 0x80))
|
|
726 {
|
|
727 keymap [VK_LCONTROL] = 0;
|
|
728 keymap [VK_CONTROL] = 0;
|
|
729 keymap [VK_RMENU] = 0;
|
|
730 keymap [VK_MENU] = 0;
|
|
731 }
|
|
732 SetKeyboardState (keymap);
|
|
733
|
|
734 /* Have some WM_[SYS]CHARS in the queue */
|
|
735 TranslateMessage (&msg);
|
|
736
|
|
737 while (PeekMessage (&msg, hwnd, WM_CHAR, WM_CHAR, PM_REMOVE)
|
|
738 ||PeekMessage (&msg, hwnd, WM_SYSCHAR, WM_SYSCHAR, PM_REMOVE))
|
|
739 {
|
|
740 int ch = msg.wParam;
|
|
741 /* CH is a character code for the key:
|
|
742 'C' for Shift+C and Ctrl+Shift+C
|
|
743 'c' for c and Ctrl+c */
|
|
744
|
|
745 /* #### If locale is not C, US or other latin-1,
|
|
746 isalpha() maybe not what do we mean */
|
|
747
|
|
748 /* XEmacs doesn't seem to like Shift on non-alpha keys */
|
|
749 if (!isalpha(ch))
|
|
750 mods &= ~MOD_SHIFT;
|
|
751
|
|
752 /* Un-capitalise alpha control keys */
|
|
753 if ((mods & MOD_CONTROL) && isalpha(ch))
|
|
754 ch |= ('A' ^ 'a');
|
|
755
|
|
756 /* If a quit char with no modifiers other than control and
|
|
757 shift, then mark it with a fake modifier, which is removed
|
|
758 upon dequeueing the event */
|
|
759 /* #### This might also not withstand localization, if
|
|
760 quit character is not a latin-1 symbol */
|
|
761 if (((quit_ch < ' ' && (mods & MOD_CONTROL) && quit_ch + 'a' - 1 == ch)
|
|
762 || (quit_ch >= ' ' && !(mods & MOD_CONTROL) && quit_ch == ch))
|
|
763 && ((mods & ~(MOD_CONTROL | MOD_SHIFT)) == 0))
|
|
764 {
|
|
765 mods |= FAKE_MOD_QUIT;
|
|
766 ++mswindows_quit_chars_count;
|
|
767 }
|
|
768
|
|
769 mswindows_enqueue_keypress_event (hwnd, make_char(ch), mods);
|
|
770 } /* while */
|
|
771 SetKeyboardState (keymap_orig);
|
|
772 } /* else */
|
|
773 }
|
|
774 goto defproc;
|
|
775
|
|
776 case WM_MBUTTONDOWN:
|
|
777 case WM_MBUTTONUP:
|
|
778 /* Real middle mouse button has nothing to do with emulated one:
|
|
779 if one wants to exercise fingers playing chords on the mouse,
|
|
780 he is allowed to do that! */
|
|
781 mswindows_enqueue_mouse_button_event (hwnd, message,
|
|
782 MAKEPOINTS (lParam), GetMessageTime());
|
|
783 break;
|
|
784
|
|
785 case WM_LBUTTONUP:
|
|
786 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
787 msframe->last_click_time = GetMessageTime();
|
|
788
|
|
789 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
790 msframe->button2_need_lbutton = 0;
|
|
791 if (msframe->ignore_next_lbutton_up)
|
|
792 {
|
|
793 msframe->ignore_next_lbutton_up = 0;
|
|
794 }
|
|
795 else if (msframe->button2_is_down)
|
|
796 {
|
|
797 msframe->button2_is_down = 0;
|
|
798 msframe->ignore_next_rbutton_up = 1;
|
|
799 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
|
|
800 MAKEPOINTS (lParam), GetMessageTime());
|
|
801 }
|
|
802 else
|
|
803 {
|
|
804 if (msframe->button2_need_rbutton)
|
|
805 {
|
|
806 msframe->button2_need_rbutton = 0;
|
|
807 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
808 MAKEPOINTS (lParam), GetMessageTime());
|
|
809 }
|
|
810 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONUP,
|
|
811 MAKEPOINTS (lParam), GetMessageTime());
|
|
812 }
|
|
813 break;
|
|
814
|
|
815 case WM_RBUTTONUP:
|
|
816 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
817 msframe->last_click_time = GetMessageTime();
|
|
818
|
|
819 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
820 msframe->button2_need_rbutton = 0;
|
|
821 if (msframe->ignore_next_rbutton_up)
|
|
822 {
|
|
823 msframe->ignore_next_rbutton_up = 0;
|
|
824 }
|
|
825 else if (msframe->button2_is_down)
|
|
826 {
|
|
827 msframe->button2_is_down = 0;
|
|
828 msframe->ignore_next_lbutton_up = 1;
|
|
829 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
|
|
830 MAKEPOINTS (lParam), GetMessageTime());
|
|
831 }
|
|
832 else
|
|
833 {
|
|
834 if (msframe->button2_need_lbutton)
|
|
835 {
|
|
836 msframe->button2_need_lbutton = 0;
|
|
837 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
838 MAKEPOINTS (lParam), GetMessageTime());
|
|
839 }
|
|
840 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONUP,
|
|
841 MAKEPOINTS (lParam), GetMessageTime());
|
|
842 }
|
|
843 break;
|
|
844
|
|
845 case WM_LBUTTONDOWN:
|
|
846 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
847
|
|
848 if (msframe->button2_need_lbutton)
|
|
849 {
|
|
850 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
851 msframe->button2_need_lbutton = 0;
|
|
852 msframe->button2_need_rbutton = 0;
|
|
853 if (mswindows_button2_near_enough (msframe->last_click_point, MAKEPOINTS (lParam)))
|
|
854 {
|
|
855 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
|
|
856 MAKEPOINTS (lParam), GetMessageTime());
|
|
857 msframe->button2_is_down = 1;
|
|
858 }
|
|
859 else
|
|
860 {
|
|
861 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
862 msframe->last_click_point, msframe->last_click_time);
|
|
863 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
864 MAKEPOINTS (lParam), GetMessageTime());
|
|
865 }
|
|
866 }
|
|
867 else
|
|
868 {
|
|
869 mswindows_set_chord_timer (hwnd);
|
|
870 msframe->button2_need_rbutton = 1;
|
|
871 msframe->last_click_point = MAKEPOINTS (lParam);
|
|
872 }
|
|
873 msframe->last_click_time = GetMessageTime();
|
|
874 break;
|
|
875
|
|
876 case WM_RBUTTONDOWN:
|
|
877 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
878
|
|
879 if (msframe->button2_need_rbutton)
|
|
880 {
|
|
881 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
882 msframe->button2_need_lbutton = 0;
|
|
883 msframe->button2_need_rbutton = 0;
|
|
884 if (mswindows_button2_near_enough (msframe->last_click_point, MAKEPOINTS (lParam)))
|
|
885 {
|
|
886 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
|
|
887 MAKEPOINTS (lParam), GetMessageTime());
|
|
888 msframe->button2_is_down = 1;
|
|
889 }
|
|
890 else
|
|
891 {
|
|
892 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
893 msframe->last_click_point, msframe->last_click_time);
|
|
894 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
895 MAKEPOINTS (lParam), GetMessageTime());
|
|
896 }
|
|
897 }
|
|
898 else
|
|
899 {
|
|
900 mswindows_set_chord_timer (hwnd);
|
|
901 msframe->button2_need_lbutton = 1;
|
|
902 msframe->last_click_point = MAKEPOINTS (lParam);
|
|
903 }
|
|
904 msframe->last_click_time = GetMessageTime();
|
|
905 break;
|
|
906
|
|
907 case WM_TIMER:
|
|
908 if (wParam == BUTTON_2_TIMER_ID)
|
|
909 {
|
|
910 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
911 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
912
|
|
913 if (msframe->button2_need_lbutton)
|
|
914 {
|
|
915 msframe->button2_need_lbutton = 0;
|
|
916 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
917 msframe->last_click_point, msframe->last_click_time);
|
|
918 }
|
|
919 else if (msframe->button2_need_rbutton)
|
|
920 {
|
|
921 msframe->button2_need_rbutton = 0;
|
|
922 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
923 msframe->last_click_point, msframe->last_click_time);
|
|
924 }
|
|
925 }
|
|
926 else
|
|
927 assert ("Spurious timer fired" == 0);
|
|
928 break;
|
|
929
|
|
930 case WM_MOUSEMOVE:
|
|
931 /* Optimization: don't report mouse movement while size is changind */
|
|
932 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
933 if (!msframe->sizing)
|
|
934 {
|
|
935 /* When waiting for the second mouse button to finish
|
|
936 button2 emulation, and have moved too far, just pretend
|
|
937 as if timer has expired. This impoves drag-select feedback */
|
|
938 if ((msframe->button2_need_lbutton || msframe->button2_need_rbutton)
|
|
939 && !mswindows_button2_near_enough (msframe->last_click_point,
|
|
940 MAKEPOINTS (lParam)))
|
|
941 {
|
|
942 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
943 SendMessage (hwnd, WM_TIMER, BUTTON_2_TIMER_ID, 0);
|
|
944 }
|
|
945
|
|
946 emacs_event = Fmake_event (Qnil, Qnil);
|
|
947 event = XEVENT(emacs_event);
|
|
948
|
|
949 event->channel = mswindows_find_frame(hwnd);
|
|
950 event->timestamp = GetMessageTime();
|
|
951 event->event_type = pointer_motion_event;
|
|
952 event->event.motion.x = MAKEPOINTS(lParam).x;
|
|
953 event->event.motion.y = MAKEPOINTS(lParam).y;
|
|
954 event->event.motion.modifiers = mswindows_modifier_state (NULL, 0);
|
|
955
|
|
956 mswindows_enqueue_dispatch_event (emacs_event);
|
|
957 }
|
|
958 break;
|
|
959
|
|
960 case WM_PAINT:
|
|
961 {
|
|
962 PAINTSTRUCT paintStruct;
|
|
963
|
|
964 frame = XFRAME (mswindows_find_frame (hwnd));
|
|
965
|
|
966 BeginPaint (hwnd, &paintStruct);
|
|
967 mswindows_redraw_exposed_area (frame,
|
|
968 paintStruct.rcPaint.left, paintStruct.rcPaint.top,
|
|
969 paintStruct.rcPaint.right, paintStruct.rcPaint.bottom);
|
|
970 EndPaint (hwnd, &paintStruct);
|
|
971 }
|
|
972 break;
|
|
973
|
|
974 case WM_SIZE:
|
|
975 /* We only care about this message if our size has really changed */
|
|
976 if (wParam==SIZE_RESTORED || wParam==SIZE_MAXIMIZED || wParam==SIZE_MINIMIZED)
|
|
977 {
|
|
978 RECT rect;
|
|
979 int columns, rows;
|
|
980
|
|
981 fobj = mswindows_find_frame (hwnd);
|
|
982 frame = XFRAME (fobj);
|
|
983 msframe = FRAME_MSWINDOWS_DATA (frame);
|
|
984
|
|
985 /* We cannot handle frame map and unmap hooks right in
|
|
986 this routine, because these may throw. We queue
|
|
987 magic events to run these hooks instead - kkm */
|
|
988
|
|
989 if (wParam==SIZE_MINIMIZED)
|
|
990 {
|
|
991 /* Iconified */
|
|
992 FRAME_VISIBLE_P (frame) = 0;
|
|
993 mswindows_enqueue_magic_event (hwnd, XM_UNMAPFRAME);
|
|
994 Fframe_iconified_p (fobj);
|
|
995 }
|
|
996 else
|
|
997 {
|
|
998 int was_visible = FRAME_VISIBLE_P (frame);
|
|
999 if (!msframe->sizing && !was_visible)
|
|
1000 mswindows_enqueue_magic_event (hwnd, XM_MAPFRAME);
|
|
1001
|
|
1002 GetClientRect(hwnd, &rect);
|
|
1003 FRAME_VISIBLE_P(frame) = 1;
|
|
1004 FRAME_PIXWIDTH(frame) = rect.right;
|
|
1005 FRAME_PIXHEIGHT(frame) = rect.bottom;
|
|
1006 pixel_to_char_size (frame, rect.right, rect.bottom, &columns, &rows);
|
|
1007 change_frame_size (frame, rows, columns, 1);
|
|
1008
|
|
1009 if (msframe->sizing && mswindows_dynamic_frame_resize)
|
|
1010 redisplay ();
|
|
1011 }
|
|
1012 }
|
|
1013 break;
|
|
1014
|
|
1015 /* Misc magic events which only require that the frame be identified */
|
|
1016 case WM_SETFOCUS:
|
|
1017 case WM_KILLFOCUS:
|
|
1018 mswindows_enqueue_magic_event (hwnd, message);
|
|
1019 break;
|
|
1020
|
|
1021 case WM_WINDOWPOSCHANGING:
|
|
1022 {
|
|
1023 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
|
|
1024 WINDOWPLACEMENT wpl = { sizeof(WINDOWPLACEMENT) };
|
|
1025 GetWindowPlacement(hwnd, &wpl);
|
|
1026
|
|
1027 /* Only interested if size is changing and we're not being iconified */
|
|
1028 if ((wpl.showCmd != SW_SHOWMINIMIZED) && !(wp->flags & SWP_NOSIZE))
|
|
1029 {
|
|
1030 RECT ncsize = { 0, 0, 0, 0 };
|
|
1031 int pixwidth, pixheight;
|
|
1032 AdjustWindowRectEx (&ncsize, GetWindowLong (hwnd, GWL_STYLE),
|
|
1033 GetMenu(hwnd) != NULL,
|
|
1034 GetWindowLong (hwnd, GWL_EXSTYLE));
|
|
1035
|
|
1036 round_size_to_char (XFRAME (mswindows_find_frame (hwnd)),
|
|
1037 wp->cx - (ncsize.right - ncsize.left),
|
|
1038 wp->cy - (ncsize.bottom - ncsize.top),
|
|
1039 &pixwidth, &pixheight);
|
|
1040
|
|
1041 /* Convert client sizes to window sizes */
|
|
1042 pixwidth += (ncsize.right - ncsize.left);
|
|
1043 pixheight += (ncsize.bottom - ncsize.top);
|
|
1044
|
|
1045 if (wpl.showCmd != SW_SHOWMAXIMIZED)
|
|
1046 {
|
|
1047 /* Adjust so that the bottom or right doesn't move if it's
|
|
1048 * the top or left that's being changed */
|
|
1049 RECT rect;
|
|
1050 GetWindowRect (hwnd, &rect);
|
|
1051
|
|
1052 if (rect.left != wp->x)
|
|
1053 wp->x += wp->cx - pixwidth;
|
|
1054 if (rect.top != wp->y)
|
|
1055 wp->y += wp->cy - pixheight;
|
|
1056 }
|
|
1057
|
|
1058 wp->cx = pixwidth;
|
|
1059 wp->cy = pixheight;
|
|
1060 }
|
|
1061 }
|
|
1062 break;
|
|
1063
|
|
1064 case WM_ENTERSIZEMOVE:
|
|
1065 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
1066 msframe->sizing = 1;
|
|
1067 return 0;
|
|
1068
|
|
1069 case WM_EXITSIZEMOVE:
|
|
1070 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
1071 msframe->sizing = 0;
|
|
1072 /* Queue noop event */
|
|
1073 mswindows_enqueue_magic_event (hwnd, XM_BUMPQUEUE);
|
|
1074 return 0;
|
|
1075
|
|
1076 #ifdef HAVE_SCROLLBARS
|
|
1077 case WM_VSCROLL:
|
|
1078 case WM_HSCROLL:
|
|
1079 {
|
|
1080 /* Direction of scroll is determined by scrollbar instance. */
|
|
1081 int code = (int) LOWORD(wParam);
|
|
1082 int pos = (short int) HIWORD(wParam);
|
|
1083 HWND hwndScrollBar = (HWND) lParam;
|
|
1084 struct gcpro gcpro1, gcpro2;
|
|
1085
|
|
1086 mswindows_handle_scrollbar_event (hwndScrollBar, code, pos);
|
|
1087 GCPRO2 (emacs_event, fobj);
|
|
1088 if (UNBOUNDP(mswindows_pump_outstanding_events())) /* Can GC */
|
|
1089 {
|
|
1090 /* Error during event pumping - cancel scroll */
|
|
1091 SendMessage (hwndScrollBar, WM_CANCELMODE, 0, 0);
|
|
1092 }
|
|
1093 UNGCPRO;
|
|
1094 break;
|
|
1095 }
|
|
1096 #endif
|
|
1097
|
|
1098 #ifdef HAVE_MENUBARS
|
|
1099 case WM_INITMENU:
|
|
1100 if (UNBOUNDP (mswindows_handle_wm_initmenu (
|
|
1101 (HMENU) wParam,
|
|
1102 XFRAME (mswindows_find_frame (hwnd)))))
|
|
1103 SendMessage (hwnd, WM_CANCELMODE, 0, 0);
|
|
1104 break;
|
|
1105
|
|
1106 case WM_INITMENUPOPUP:
|
|
1107 if (!HIWORD(lParam))
|
|
1108 {
|
|
1109 if (UNBOUNDP (mswindows_handle_wm_initmenupopup (
|
|
1110 (HMENU) wParam,
|
|
1111 XFRAME (mswindows_find_frame (hwnd)))))
|
|
1112 SendMessage (hwnd, WM_CANCELMODE, 0, 0);
|
|
1113 }
|
|
1114 break;
|
|
1115
|
|
1116 case WM_EXITMENULOOP:
|
|
1117 if (UNBOUNDP (mswindows_handle_wm_exitmenuloop (
|
|
1118 XFRAME (mswindows_find_frame (hwnd)))))
|
|
1119 SendMessage (hwnd, WM_CANCELMODE, 0, 0);
|
|
1120 break;
|
|
1121
|
|
1122 #endif /* HAVE_MENUBARS */
|
|
1123
|
|
1124 case WM_COMMAND:
|
|
1125 {
|
|
1126 WORD id = LOWORD (wParam);
|
|
1127 frame = XFRAME (mswindows_find_frame (hwnd));
|
|
1128
|
|
1129 #ifdef HAVE_MENUBARS
|
|
1130 if (!NILP (mswindows_handle_wm_command (frame, id)))
|
|
1131 break;
|
|
1132 #endif
|
|
1133
|
|
1134 #ifdef HAVE_TOOLBARS
|
|
1135 O Toolbar Implementor, this place may have something for you!;
|
|
1136 #endif
|
|
1137
|
|
1138 /* Bite me - a spurious command. No abort(), for safety */
|
|
1139 /* #### Perhaps, this message should be changed */
|
|
1140 error ("Cannot decode command. Tell kkm he's a parallelogramm, if you know"
|
|
1141 " what does that mean!");
|
|
1142 }
|
|
1143 break;
|
|
1144
|
|
1145 case WM_DROPFILES: /* implementation ripped-off from event-Xt.c */
|
|
1146 {
|
|
1147 UINT filecount, i, len;
|
|
1148 POINT point;
|
|
1149 char filename[MAX_PATH];
|
|
1150 Lisp_Object l_type, l_dndlist = Qnil, l_item;
|
|
1151
|
|
1152 emacs_event = Fmake_event (Qnil, Qnil);
|
|
1153 event = XEVENT(emacs_event);
|
|
1154
|
|
1155 if (!DragQueryPoint ((HANDLE) wParam, &point))
|
|
1156 point.x = point.y = -1; /* outside client area */
|
|
1157
|
|
1158 filecount = DragQueryFile ((HANDLE) wParam, -1, NULL, 0);
|
|
1159 if (filecount == 1)
|
|
1160 {
|
|
1161 l_type = make_int (DndFile);
|
|
1162 len = DragQueryFile ((HANDLE) wParam, 0, filename, MAX_PATH);
|
|
1163 l_dndlist = make_ext_string (filename, len, FORMAT_FILENAME);
|
|
1164 }
|
|
1165 else
|
|
1166 {
|
|
1167 l_type = make_int (DndFiles);
|
|
1168 for (i=0; i<filecount; i++)
|
|
1169 {
|
|
1170 len = DragQueryFile ((HANDLE) wParam, i, filename, MAX_PATH);
|
|
1171 l_item = make_ext_string (filename, len, FORMAT_FILENAME);
|
|
1172 l_dndlist = Fcons (l_item, l_dndlist); /* reverse order */
|
|
1173 }
|
|
1174 }
|
|
1175 DragFinish ((HANDLE) wParam);
|
|
1176
|
|
1177 event->channel = mswindows_find_frame(hwnd);
|
|
1178 event->timestamp = GetMessageTime();
|
|
1179 event->event_type = dnd_drop_event;
|
|
1180 event->event.dnd_drop.button = 1; /* #### Should try harder */
|
|
1181 event->event.dnd_drop.modifiers = mswindows_modifier_state (NULL, 0);
|
|
1182 event->event.dnd_drop.x = point.x;
|
|
1183 event->event.dnd_drop.y = point.y;
|
|
1184 event->event.dnd_drop.data = Fcons (l_type, Fcons (l_dndlist, Qnil));
|
|
1185
|
|
1186 mswindows_enqueue_dispatch_event (emacs_event);
|
|
1187 }
|
|
1188 break;
|
|
1189
|
|
1190 defproc:
|
|
1191 default:
|
|
1192 return DefWindowProc (hwnd, message, wParam, lParam);
|
|
1193 }
|
|
1194 return (0);
|
|
1195 }
|
|
1196
|
|
1197
|
|
1198 /************************************************************************/
|
|
1199 /* keyboard, mouse & other helpers for the windows procedure */
|
|
1200 /************************************************************************/
|
|
1201 static void
|
|
1202 mswindows_set_chord_timer (HWND hwnd)
|
|
1203 {
|
|
1204 int interval;
|
|
1205
|
|
1206 /* We get half system threshold as it seems to
|
|
1207 long before drag-selection is shown */
|
|
1208 if (mswindows_button2_chord_time <= 0)
|
|
1209 interval = GetDoubleClickTime () / 2;
|
|
1210 else
|
|
1211 interval = mswindows_button2_chord_time;
|
|
1212
|
|
1213 SetTimer (hwnd, BUTTON_2_TIMER_ID, interval, 0);
|
|
1214 }
|
|
1215
|
|
1216 static int
|
|
1217 mswindows_button2_near_enough (POINTS p1, POINTS p2)
|
|
1218 {
|
|
1219 int dx, dy;
|
|
1220 if (mswindows_button2_max_skew_x <= 0)
|
|
1221 dx = GetSystemMetrics (SM_CXDOUBLECLK) / 2;
|
|
1222 else
|
|
1223 dx = mswindows_button2_max_skew_x;
|
|
1224
|
|
1225 if (mswindows_button2_max_skew_y <= 0)
|
|
1226 dy = GetSystemMetrics (SM_CYDOUBLECLK) / 2;
|
|
1227 else
|
|
1228 dy = mswindows_button2_max_skew_y;
|
|
1229
|
|
1230 return abs (p1.x - p2.x) < dx && abs (p1.y- p2.y)< dy;
|
|
1231 }
|
|
1232
|
|
1233 static int
|
|
1234 mswindows_current_layout_has_AltGr (void)
|
|
1235 {
|
|
1236 /* This simple caching mechanism saves 10% of CPU
|
|
1237 time when a key typed at autorepeat rate of 30 cps! */
|
|
1238 static HKL last_hkl = 0;
|
|
1239 static int last_hkl_has_AltGr;
|
|
1240
|
|
1241 HKL current_hkl = GetKeyboardLayout (0);
|
|
1242 if (current_hkl != last_hkl)
|
|
1243 {
|
|
1244 TCHAR c;
|
|
1245 last_hkl_has_AltGr = 0;
|
|
1246 /* In this loop, we query whether a character requires
|
|
1247 AltGr to be down to generate it. If at least such one
|
|
1248 found, this means that the layout does regard AltGr */
|
|
1249 for (c = ' '; c <= 0xFFU && c != 0 && !last_hkl_has_AltGr; ++c)
|
|
1250 if (HIBYTE (VkKeyScan (c)) == 6)
|
|
1251 last_hkl_has_AltGr = 1;
|
|
1252 last_hkl = current_hkl;
|
|
1253 }
|
|
1254 return last_hkl_has_AltGr;
|
|
1255 }
|
|
1256
|
|
1257
|
|
1258 /* Returns the state of the modifier keys in the format expected by the
|
|
1259 * Lisp_Event key_data, button_data and motion_data modifiers member */
|
|
1260 int mswindows_modifier_state (BYTE* keymap, int has_AltGr)
|
|
1261 {
|
|
1262 int mods = 0;
|
|
1263
|
|
1264 if (keymap == NULL)
|
|
1265 {
|
|
1266 keymap = (BYTE*) alloca(256);
|
|
1267 GetKeyboardState (keymap);
|
|
1268 has_AltGr = mswindows_current_layout_has_AltGr ();
|
|
1269 }
|
|
1270
|
|
1271 if (has_AltGr && (keymap [VK_LCONTROL] & 0x80) && (keymap [VK_RMENU] & 0x80))
|
|
1272 {
|
|
1273 mods |= (keymap [VK_LMENU] & 0x80) ? MOD_META : 0;
|
|
1274 mods |= (keymap [VK_RCONTROL] & 0x80) ? MOD_CONTROL : 0;
|
|
1275 }
|
|
1276 else
|
|
1277 {
|
|
1278 mods |= (keymap [VK_MENU] & 0x80) ? MOD_META : 0;
|
|
1279 mods |= (keymap [VK_CONTROL] & 0x80) ? MOD_CONTROL : 0;
|
|
1280 }
|
|
1281
|
|
1282 mods |= (keymap [VK_SHIFT] & 0x80) ? MOD_SHIFT : 0;
|
|
1283
|
|
1284 return mods;
|
|
1285 }
|
|
1286
|
|
1287 /*
|
|
1288 * Translate a mswindows virtual key to a keysym.
|
|
1289 * Only returns non-Qnil for keys that don't generate WM_CHAR messages
|
|
1290 * or whose ASCII codes (like space) xemacs doesn't like.
|
|
1291 * Virtual key values are defined in winresrc.h
|
|
1292 * XXX I'm not sure that KEYSYM("name") is the best thing to use here.
|
|
1293 */
|
|
1294 Lisp_Object mswindows_key_to_emacs_keysym(int mswindows_key, int mods)
|
|
1295 {
|
|
1296 switch (mswindows_key)
|
|
1297 {
|
|
1298 /* First the predefined ones */
|
|
1299 case VK_BACK: return QKbackspace;
|
|
1300 case VK_TAB: return QKtab;
|
|
1301 case '\n': return QKlinefeed; /* No VK_LINEFEED in winresrc.h */
|
|
1302 case VK_RETURN: return QKreturn;
|
|
1303 case VK_ESCAPE: return QKescape;
|
|
1304 case VK_SPACE: return QKspace;
|
|
1305 case VK_DELETE: return QKdelete;
|
|
1306
|
|
1307 /* The rest */
|
|
1308 case VK_CLEAR: return KEYSYM ("clear"); /* Should do ^L ? */
|
|
1309 case VK_PRIOR: return KEYSYM ("prior");
|
|
1310 case VK_NEXT: return KEYSYM ("next");
|
|
1311 case VK_END: return KEYSYM ("end");
|
|
1312 case VK_HOME: return KEYSYM ("home");
|
|
1313 case VK_LEFT: return KEYSYM ("left");
|
|
1314 case VK_UP: return KEYSYM ("up");
|
|
1315 case VK_RIGHT: return KEYSYM ("right");
|
|
1316 case VK_DOWN: return KEYSYM ("down");
|
|
1317 case VK_SELECT: return KEYSYM ("select");
|
|
1318 case VK_PRINT: return KEYSYM ("print");
|
|
1319 case VK_EXECUTE: return KEYSYM ("execute");
|
|
1320 case VK_SNAPSHOT: return KEYSYM ("print");
|
|
1321 case VK_INSERT: return KEYSYM ("insert");
|
|
1322 case VK_HELP: return KEYSYM ("help");
|
|
1323 #if 0 /* XXX What are these supposed to do? */
|
|
1324 case VK_LWIN return KEYSYM ("");
|
|
1325 case VK_RWIN return KEYSYM ("");
|
|
1326 #endif
|
|
1327 case VK_APPS: return KEYSYM ("menu");
|
|
1328 case VK_F1: return KEYSYM ("f1");
|
|
1329 case VK_F2: return KEYSYM ("f2");
|
|
1330 case VK_F3: return KEYSYM ("f3");
|
|
1331 case VK_F4: return KEYSYM ("f4");
|
|
1332 case VK_F5: return KEYSYM ("f5");
|
|
1333 case VK_F6: return KEYSYM ("f6");
|
|
1334 case VK_F7: return KEYSYM ("f7");
|
|
1335 case VK_F8: return KEYSYM ("f8");
|
|
1336 case VK_F9: return KEYSYM ("f9");
|
|
1337 case VK_F10: return KEYSYM ("f10");
|
|
1338 case VK_F11: return KEYSYM ("f11");
|
|
1339 case VK_F12: return KEYSYM ("f12");
|
|
1340 case VK_F13: return KEYSYM ("f13");
|
|
1341 case VK_F14: return KEYSYM ("f14");
|
|
1342 case VK_F15: return KEYSYM ("f15");
|
|
1343 case VK_F16: return KEYSYM ("f16");
|
|
1344 case VK_F17: return KEYSYM ("f17");
|
|
1345 case VK_F18: return KEYSYM ("f18");
|
|
1346 case VK_F19: return KEYSYM ("f19");
|
|
1347 case VK_F20: return KEYSYM ("f20");
|
|
1348 case VK_F21: return KEYSYM ("f21");
|
|
1349 case VK_F22: return KEYSYM ("f22");
|
|
1350 case VK_F23: return KEYSYM ("f23");
|
|
1351 case VK_F24: return KEYSYM ("f24");
|
|
1352 }
|
|
1353 return Qnil;
|
|
1354 }
|
|
1355
|
|
1356 /*
|
|
1357 * Find the console that matches the supplied mswindows window handle
|
|
1358 */
|
|
1359 Lisp_Object
|
|
1360 mswindows_find_console (HWND hwnd)
|
|
1361 {
|
|
1362 Lisp_Object concons;
|
|
1363
|
|
1364 CONSOLE_LOOP (concons)
|
|
1365 {
|
|
1366 Lisp_Object console = XCAR (concons);
|
|
1367 /* We only support one console so this must be it */
|
|
1368 return console;
|
|
1369 }
|
|
1370
|
|
1371 return Qnil;
|
|
1372 }
|
|
1373
|
|
1374 /*
|
|
1375 * Find the frame that matches the supplied mswindows window handle
|
|
1376 */
|
|
1377 static Lisp_Object
|
|
1378 mswindows_find_frame (HWND hwnd)
|
|
1379 {
|
|
1380 return (Lisp_Object) GetWindowLong (hwnd, XWL_FRAMEOBJ);
|
|
1381 }
|
|
1382
|
|
1383
|
213
|
1384
|
|
1385 /************************************************************************/
|
|
1386 /* methods */
|
|
1387 /************************************************************************/
|
|
1388
|
|
1389 static int
|
|
1390 emacs_mswindows_add_timeout (EMACS_TIME thyme)
|
|
1391 {
|
223
|
1392 int milliseconds;
|
213
|
1393 EMACS_TIME current_time;
|
|
1394 EMACS_GET_TIME (current_time);
|
|
1395 EMACS_SUB_TIME (thyme, thyme, current_time);
|
223
|
1396 milliseconds = EMACS_SECS (thyme) * 1000 +
|
|
1397 (EMACS_USECS (thyme) + 500) / 1000;
|
213
|
1398 if (milliseconds < 1)
|
|
1399 milliseconds = 1;
|
227
|
1400 ++mswindows_pending_timers_count;
|
249
|
1401 return SetTimer (NULL, 0, milliseconds,
|
|
1402 (TIMERPROC) mswindows_wm_timer_callback);
|
213
|
1403 }
|
|
1404
|
|
1405 static void
|
|
1406 emacs_mswindows_remove_timeout (int id)
|
|
1407 {
|
223
|
1408 struct Lisp_Event match_against;
|
|
1409 Lisp_Object emacs_event;
|
|
1410
|
233
|
1411 if (KillTimer (NULL, id))
|
|
1412 --mswindows_pending_timers_count;
|
223
|
1413
|
|
1414 /* If there is a dispatch event generated by this
|
|
1415 timeout in the queue, we have to remove it too. */
|
|
1416 match_against.event_type = timeout_event;
|
|
1417 match_against.event.timeout.interval_id = id;
|
|
1418 emacs_event = mswindows_cancel_dispatch_event (&match_against);
|
|
1419 if (!NILP (emacs_event))
|
|
1420 Fdeallocate_event(emacs_event);
|
213
|
1421 }
|
|
1422
|
219
|
1423 /* If `user_p' is false, then return whether there are any win32, timeout,
|
|
1424 * or subprocess events pending (that is, whether
|
|
1425 * emacs_mswindows_next_event() would return immediately without blocking).
|
|
1426 *
|
|
1427 * if `user_p' is true, then return whether there are any *user generated*
|
|
1428 * events available (that is, whether there are keyboard or mouse-click
|
|
1429 * events ready to be read). This also implies that
|
|
1430 * emacs_mswindows_next_event() would not block.
|
|
1431 */
|
213
|
1432 static int
|
|
1433 emacs_mswindows_event_pending_p (int user_p)
|
|
1434 {
|
223
|
1435 mswindows_need_event (user_p, 0);
|
219
|
1436
|
223
|
1437 return (!NILP (mswindows_u_dispatch_event_queue)
|
|
1438 || (!user_p && !NILP (mswindows_s_dispatch_event_queue)));
|
213
|
1439 }
|
|
1440
|
|
1441 /*
|
|
1442 * Return the next event
|
|
1443 */
|
|
1444 static void
|
|
1445 emacs_mswindows_next_event (struct Lisp_Event *emacs_event)
|
|
1446 {
|
223
|
1447 Lisp_Object event, event2;
|
|
1448
|
|
1449 /* Give strong preference to user events */
|
|
1450 mswindows_need_event (1, 1);
|
213
|
1451
|
223
|
1452 /* XXX Copied from event-Xt.c */
|
|
1453 event = mswindows_dequeue_dispatch_event (!NILP(mswindows_u_dispatch_event_queue));
|
|
1454 XSETEVENT (event2, emacs_event);
|
|
1455 Fcopy_event (event, event2);
|
|
1456 Fdeallocate_event (event);
|
213
|
1457 }
|
|
1458
|
|
1459 /*
|
|
1460 * Handle a magic event off the dispatch queue.
|
|
1461 */
|
|
1462 static void
|
|
1463 emacs_mswindows_handle_magic_event (struct Lisp_Event *emacs_event)
|
|
1464 {
|
|
1465 switch (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event))
|
|
1466 {
|
|
1467 case WM_SETFOCUS:
|
|
1468 case WM_KILLFOCUS:
|
|
1469 {
|
223
|
1470 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
|
|
1471 struct frame *f = XFRAME (frame);
|
213
|
1472 int in_p = (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event) == WM_SETFOCUS);
|
|
1473 Lisp_Object conser;
|
223
|
1474
|
213
|
1475 /* struct gcpro gcpro1; */
|
|
1476
|
|
1477 /* Clear sticky modifiers here (if we had any) */
|
|
1478
|
|
1479 conser = Fcons (frame, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil));
|
|
1480 /* GCPRO1 (conser); XXX Not necessary? */
|
|
1481 emacs_handle_focus_change_preliminary (conser);
|
|
1482 /* Under X the stuff up to here is done in the X event handler.
|
|
1483 I Don't know why */
|
|
1484 emacs_handle_focus_change_final (conser);
|
|
1485 /* UNGCPRO; */
|
223
|
1486
|
213
|
1487 }
|
|
1488 break;
|
|
1489
|
223
|
1490 case XM_BUMPQUEUE:
|
|
1491 /* This is a nice event, when we're in need to queue *something* */
|
|
1492 break;
|
|
1493
|
|
1494 case XM_MAPFRAME:
|
|
1495 case XM_UNMAPFRAME:
|
|
1496 {
|
|
1497 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
|
|
1498 va_run_hook_with_args (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event)
|
|
1499 == XM_MAPFRAME ?
|
|
1500 Qmap_frame_hook : Qunmap_frame_hook,
|
|
1501 1, frame);
|
|
1502 }
|
|
1503 break;
|
|
1504
|
249
|
1505 /* #### What about Enter & Leave */
|
213
|
1506 #if 0
|
|
1507 va_run_hook_with_args (in_p ? Qmouse_enter_frame_hook :
|
|
1508 Qmouse_leave_frame_hook, 1, frame);
|
|
1509 #endif
|
|
1510
|
|
1511 default:
|
|
1512 assert(0);
|
|
1513 }
|
|
1514 }
|
|
1515
|
|
1516 static void
|
|
1517 emacs_mswindows_select_process (struct Lisp_Process *process)
|
|
1518 {
|
|
1519 }
|
|
1520
|
|
1521 static void
|
|
1522 emacs_mswindows_unselect_process (struct Lisp_Process *process)
|
|
1523 {
|
|
1524 }
|
|
1525
|
|
1526 static void
|
|
1527 emacs_mswindows_select_console (struct console *con)
|
|
1528 {
|
|
1529 }
|
|
1530
|
|
1531 static void
|
|
1532 emacs_mswindows_unselect_console (struct console *con)
|
|
1533 {
|
|
1534 }
|
|
1535
|
|
1536 static void
|
|
1537 emacs_mswindows_quit_p (void)
|
|
1538 {
|
223
|
1539 mswindows_need_event (1, 0);
|
|
1540
|
|
1541 if (mswindows_quit_chars_count > 0)
|
|
1542 {
|
|
1543 /* Yes there's a hidden one... Throw it away */
|
|
1544 struct Lisp_Event match_against;
|
|
1545 Lisp_Object emacs_event;
|
|
1546
|
|
1547 match_against.event_type = key_press_event;
|
|
1548 match_against.event.key.modifiers = FAKE_MOD_QUIT;
|
|
1549
|
|
1550 emacs_event = mswindows_cancel_dispatch_event (&match_against);
|
|
1551 assert (!NILP (emacs_event));
|
|
1552
|
|
1553 Vquit_flag = (XEVENT(emacs_event)->event.key.modifiers & MOD_SHIFT
|
|
1554 ? Qcritical : Qt);
|
|
1555
|
|
1556 Fdeallocate_event(emacs_event);
|
|
1557 --mswindows_quit_chars_count;
|
|
1558 }
|
213
|
1559 }
|
|
1560
|
|
1561 /* This is called from GC when a process object is about to be freed.
|
|
1562 If we've still got pointers to it in this file, we're gonna lose hard.
|
|
1563 */
|
|
1564 void
|
|
1565 debug_process_finalization (struct Lisp_Process *p)
|
|
1566 {
|
|
1567 #if 0 /* #### */
|
|
1568 int i;
|
|
1569 int infd, outfd;
|
|
1570 get_process_file_descriptors (p, &infd, &outfd);
|
|
1571 /* if it still has fds, then it hasn't been killed yet. */
|
|
1572 assert (infd < 0);
|
|
1573 assert (outfd < 0);
|
|
1574 /* Better not still be in the "with input" table; we know it's got no fds. */
|
|
1575 for (i = 0; i < MAXDESC; i++)
|
|
1576 {
|
|
1577 Lisp_Object process = filedesc_fds_with_input [i];
|
|
1578 assert (!PROCESSP (process) || XPROCESS (process) != p);
|
|
1579 }
|
|
1580 #endif
|
|
1581 }
|
|
1582
|
|
1583 /************************************************************************/
|
|
1584 /* initialization */
|
|
1585 /************************************************************************/
|
|
1586
|
|
1587 void
|
|
1588 vars_of_event_mswindows (void)
|
|
1589 {
|
223
|
1590 mswindows_u_dispatch_event_queue = Qnil;
|
|
1591 staticpro (&mswindows_u_dispatch_event_queue);
|
|
1592 mswindows_u_dispatch_event_queue_tail = Qnil;
|
|
1593
|
|
1594 mswindows_s_dispatch_event_queue = Qnil;
|
|
1595 staticpro (&mswindows_s_dispatch_event_queue);
|
|
1596 mswindows_s_dispatch_event_queue_tail = Qnil;
|
213
|
1597
|
231
|
1598 mswindows_error_caught_in_modal_loop = Qnil;
|
|
1599 staticpro (&mswindows_error_caught_in_modal_loop);
|
|
1600 mswindows_in_modal_loop = 0;
|
227
|
1601 mswindows_pending_timers_count = 0;
|
|
1602
|
213
|
1603 mswindows_event_stream = xnew (struct event_stream);
|
|
1604
|
|
1605 mswindows_event_stream->event_pending_p = emacs_mswindows_event_pending_p;
|
223
|
1606 mswindows_event_stream->next_event_cb = emacs_mswindows_next_event;
|
213
|
1607 mswindows_event_stream->handle_magic_event_cb = emacs_mswindows_handle_magic_event;
|
|
1608 mswindows_event_stream->add_timeout_cb = emacs_mswindows_add_timeout;
|
|
1609 mswindows_event_stream->remove_timeout_cb = emacs_mswindows_remove_timeout;
|
|
1610 mswindows_event_stream->select_console_cb = emacs_mswindows_select_console;
|
223
|
1611 mswindows_event_stream->unselect_console_cb = emacs_mswindows_unselect_console;
|
213
|
1612 mswindows_event_stream->select_process_cb = emacs_mswindows_select_process;
|
223
|
1613 mswindows_event_stream->unselect_process_cb = emacs_mswindows_unselect_process;
|
213
|
1614 mswindows_event_stream->quit_p_cb = emacs_mswindows_quit_p;
|
223
|
1615
|
225
|
1616 DEFVAR_BOOL ("mswindows-dynamic-frame-resize", &mswindows_dynamic_frame_resize /*
|
223
|
1617 *Controls redrawing frame contents during mouse-drag or keyboard resize
|
|
1618 operation. When non-nil, the frame is redrawn while being resized. When
|
|
1619 nil, frame is not redrawn, and exposed areas are filled with default
|
|
1620 MDI application background color. Note that this option only has effect
|
|
1621 if "Show window contents while dragging" is on in system Display/Plus!
|
|
1622 settings.
|
|
1623 Default is t on fast machines, nil on slow.
|
|
1624 */ );
|
|
1625
|
|
1626 /* The description copied verbatim from nt-emacs. (C) Geoff Voelker */
|
225
|
1627 DEFVAR_INT ("mswindows-mouse-button-tolerance", &mswindows_button2_chord_time /*
|
223
|
1628 *Analogue of double click interval for faking middle mouse events.
|
|
1629 The value is the minimum time in milliseconds that must elapse between
|
|
1630 left/right button down events before they are considered distinct events.
|
|
1631 If both mouse buttons are depressed within this interval, a middle mouse
|
|
1632 button down event is generated instead.
|
|
1633 If negative or zero, currently set system default is used instead.
|
|
1634 */ );
|
|
1635
|
|
1636 /* The description copied verbatim from nt-emacs. (C) Geoff Voelker */
|
225
|
1637 DEFVAR_INT ("mswindows-num-mouse-buttons", &mswindows_num_mouse_buttons /*
|
223
|
1638 Number of physical mouse buttons.
|
|
1639 */ );
|
|
1640
|
225
|
1641 DEFVAR_INT ("mswindows-mouse-button-max-skew-x", &mswindows_button2_max_skew_x /*
|
223
|
1642 *Maximum horizontal distance in pixels between points in which left and
|
|
1643 right button clicks occured for them to be translated into single
|
|
1644 middle button event. Clicks must occur in time not longer than defined
|
225
|
1645 by the variable mswindows-mouse-button-tolerance.
|
223
|
1646 If negative or zero, currently set system default is used instead.
|
|
1647 */ );
|
|
1648
|
225
|
1649 DEFVAR_INT ("mswindows-mouse-button-max-skew-y", &mswindows_button2_max_skew_y /*
|
223
|
1650 *Maximum vertical distance in pixels between points in which left and
|
|
1651 right button clicks occured for them to be translated into single
|
|
1652 middle button event. Clicks must occur in time not longer than defined
|
225
|
1653 by the variable mswindows-mouse-button-tolerance.
|
223
|
1654 If negative or zero, currently set system default is used instead.
|
|
1655 */ );
|
|
1656
|
|
1657 mswindows_button2_max_skew_x = 0;
|
|
1658 mswindows_button2_max_skew_y = 0;
|
|
1659 mswindows_button2_chord_time = 0;
|
213
|
1660 }
|
|
1661
|
|
1662 void
|
|
1663 syms_of_event_mswindows (void)
|
|
1664 {
|
|
1665 }
|
|
1666
|
|
1667 void
|
|
1668 init_event_mswindows_late (void)
|
|
1669 {
|
|
1670 event_stream = mswindows_event_stream;
|
223
|
1671
|
|
1672 mswindows_dynamic_frame_resize = !GetSystemMetrics (SM_SLOWMACHINE);
|
|
1673 mswindows_num_mouse_buttons = GetSystemMetrics (SM_CMOUSEBUTTONS);
|
213
|
1674 }
|