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