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