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 */
|
269
|
1002 FRAME_VISIBLE_P (frame) = 0;
|
249
|
1003 mswindows_enqueue_magic_event (hwnd, XM_UNMAPFRAME);
|
|
1004 }
|
|
1005 else
|
|
1006 {
|
|
1007 GetClientRect(hwnd, &rect);
|
|
1008 FRAME_PIXWIDTH(frame) = rect.right;
|
|
1009 FRAME_PIXHEIGHT(frame) = rect.bottom;
|
269
|
1010
|
|
1011 pixel_to_real_char_size (frame, rect.right, rect.bottom,
|
|
1012 &MSWINDOWS_FRAME_CHARWIDTH (frame),
|
|
1013 &MSWINDOWS_FRAME_CHARHEIGHT (frame));
|
|
1014
|
249
|
1015 pixel_to_char_size (frame, rect.right, rect.bottom, &columns, &rows);
|
|
1016 change_frame_size (frame, rows, columns, 1);
|
|
1017
|
269
|
1018 /* If we are inside frame creation, we have to apply geometric
|
|
1019 properties now. */
|
|
1020 if (mswindows_frame_target_rect.left >= 0
|
|
1021 || mswindows_frame_target_rect.top >= 0
|
|
1022 || mswindows_frame_target_rect.width >= 0
|
|
1023 || mswindows_frame_target_rect.height >= 0)
|
|
1024 {
|
|
1025 /* Yes, we have to size again */
|
|
1026 XEMACS_RECT_WH geom;
|
|
1027
|
|
1028 geom.left = mswindows_frame_target_rect.left;
|
|
1029 geom.top = mswindows_frame_target_rect.top;
|
|
1030 char_to_real_pixel_size (frame,
|
|
1031 mswindows_frame_target_rect.width,
|
|
1032 mswindows_frame_target_rect.height,
|
|
1033 &geom.width, &geom.height);
|
|
1034 if (mswindows_frame_target_rect.width < 0)
|
|
1035 geom.width = -1;
|
|
1036 if (mswindows_frame_target_rect.height < 0)
|
|
1037 geom.height = -1;
|
|
1038
|
|
1039 /* Reset to we do not get here again */
|
|
1040 mswindows_frame_target_rect.left = -1;
|
|
1041 mswindows_frame_target_rect.top = -1;
|
|
1042 mswindows_frame_target_rect.width = -1;
|
|
1043 mswindows_frame_target_rect.height = -1;
|
|
1044
|
|
1045 /* Size the rectangle to the actual size */
|
|
1046 GetWindowRect (hwnd, &rect);
|
|
1047 SetWindowPos
|
|
1048 (hwnd, NULL,
|
|
1049 geom.left >= 0 ? geom.left : rect.left,
|
|
1050 geom.top >= 0 ? geom.top : rect.top,
|
|
1051 geom.width >= 0 ? geom.width : rect.right - rect.left,
|
|
1052 geom.height >= 0 ? geom.height : rect.bottom - rect.top,
|
|
1053 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSENDCHANGING
|
|
1054 | ((geom.left >= 0 || geom.top >= 0) ? 0 : SWP_NOMOVE)
|
|
1055 | ((geom.width >= 0 || geom.height >= 0) ? 0 : SWP_NOSIZE));
|
|
1056 }
|
|
1057 else
|
|
1058 {
|
|
1059 if (!msframe->sizing && !FRAME_VISIBLE_P (frame))
|
|
1060 mswindows_enqueue_magic_event (hwnd, XM_MAPFRAME);
|
|
1061 FRAME_VISIBLE_P (frame) = 1;
|
|
1062
|
|
1063 if (!msframe->sizing || mswindows_dynamic_frame_resize)
|
|
1064 redisplay ();
|
|
1065 }
|
249
|
1066 }
|
|
1067 }
|
|
1068 break;
|
|
1069
|
|
1070 /* Misc magic events which only require that the frame be identified */
|
|
1071 case WM_SETFOCUS:
|
|
1072 case WM_KILLFOCUS:
|
|
1073 mswindows_enqueue_magic_event (hwnd, message);
|
|
1074 break;
|
|
1075
|
|
1076 case WM_WINDOWPOSCHANGING:
|
|
1077 {
|
|
1078 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
|
|
1079 WINDOWPLACEMENT wpl = { sizeof(WINDOWPLACEMENT) };
|
|
1080 GetWindowPlacement(hwnd, &wpl);
|
|
1081
|
|
1082 /* Only interested if size is changing and we're not being iconified */
|
269
|
1083 if (wpl.showCmd != SW_SHOWMINIMIZED
|
|
1084 && wpl.showCmd != SW_SHOWMAXIMIZED
|
|
1085 && !(wp->flags & SWP_NOSIZE))
|
249
|
1086 {
|
|
1087 RECT ncsize = { 0, 0, 0, 0 };
|
|
1088 int pixwidth, pixheight;
|
|
1089 AdjustWindowRectEx (&ncsize, GetWindowLong (hwnd, GWL_STYLE),
|
|
1090 GetMenu(hwnd) != NULL,
|
|
1091 GetWindowLong (hwnd, GWL_EXSTYLE));
|
|
1092
|
269
|
1093 round_size_to_real_char (XFRAME (mswindows_find_frame (hwnd)),
|
|
1094 wp->cx - (ncsize.right - ncsize.left),
|
|
1095 wp->cy - (ncsize.bottom - ncsize.top),
|
|
1096 &pixwidth, &pixheight);
|
249
|
1097
|
|
1098 /* Convert client sizes to window sizes */
|
|
1099 pixwidth += (ncsize.right - ncsize.left);
|
|
1100 pixheight += (ncsize.bottom - ncsize.top);
|
|
1101
|
|
1102 if (wpl.showCmd != SW_SHOWMAXIMIZED)
|
|
1103 {
|
|
1104 /* Adjust so that the bottom or right doesn't move if it's
|
|
1105 * the top or left that's being changed */
|
|
1106 RECT rect;
|
|
1107 GetWindowRect (hwnd, &rect);
|
|
1108
|
|
1109 if (rect.left != wp->x)
|
|
1110 wp->x += wp->cx - pixwidth;
|
|
1111 if (rect.top != wp->y)
|
|
1112 wp->y += wp->cy - pixheight;
|
|
1113 }
|
|
1114
|
|
1115 wp->cx = pixwidth;
|
|
1116 wp->cy = pixheight;
|
|
1117 }
|
269
|
1118 /* DefWindowProc sends useful WM_GETMINMAXINFO message, and adjusts
|
|
1119 window position if the user tries to track window too small */
|
249
|
1120 }
|
269
|
1121 goto defproc;
|
249
|
1122
|
|
1123 case WM_ENTERSIZEMOVE:
|
|
1124 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
1125 msframe->sizing = 1;
|
|
1126 return 0;
|
|
1127
|
|
1128 case WM_EXITSIZEMOVE:
|
|
1129 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
1130 msframe->sizing = 0;
|
|
1131 /* Queue noop event */
|
|
1132 mswindows_enqueue_magic_event (hwnd, XM_BUMPQUEUE);
|
|
1133 return 0;
|
|
1134
|
|
1135 #ifdef HAVE_SCROLLBARS
|
|
1136 case WM_VSCROLL:
|
|
1137 case WM_HSCROLL:
|
|
1138 {
|
|
1139 /* Direction of scroll is determined by scrollbar instance. */
|
|
1140 int code = (int) LOWORD(wParam);
|
|
1141 int pos = (short int) HIWORD(wParam);
|
|
1142 HWND hwndScrollBar = (HWND) lParam;
|
|
1143 struct gcpro gcpro1, gcpro2;
|
|
1144
|
|
1145 mswindows_handle_scrollbar_event (hwndScrollBar, code, pos);
|
|
1146 GCPRO2 (emacs_event, fobj);
|
|
1147 if (UNBOUNDP(mswindows_pump_outstanding_events())) /* Can GC */
|
|
1148 {
|
|
1149 /* Error during event pumping - cancel scroll */
|
|
1150 SendMessage (hwndScrollBar, WM_CANCELMODE, 0, 0);
|
|
1151 }
|
|
1152 UNGCPRO;
|
|
1153 break;
|
|
1154 }
|
|
1155 #endif
|
|
1156
|
|
1157 #ifdef HAVE_MENUBARS
|
|
1158 case WM_INITMENU:
|
|
1159 if (UNBOUNDP (mswindows_handle_wm_initmenu (
|
|
1160 (HMENU) wParam,
|
|
1161 XFRAME (mswindows_find_frame (hwnd)))))
|
|
1162 SendMessage (hwnd, WM_CANCELMODE, 0, 0);
|
|
1163 break;
|
|
1164
|
|
1165 case WM_INITMENUPOPUP:
|
|
1166 if (!HIWORD(lParam))
|
|
1167 {
|
|
1168 if (UNBOUNDP (mswindows_handle_wm_initmenupopup (
|
|
1169 (HMENU) wParam,
|
|
1170 XFRAME (mswindows_find_frame (hwnd)))))
|
|
1171 SendMessage (hwnd, WM_CANCELMODE, 0, 0);
|
|
1172 }
|
|
1173 break;
|
|
1174
|
|
1175 case WM_EXITMENULOOP:
|
|
1176 if (UNBOUNDP (mswindows_handle_wm_exitmenuloop (
|
|
1177 XFRAME (mswindows_find_frame (hwnd)))))
|
|
1178 SendMessage (hwnd, WM_CANCELMODE, 0, 0);
|
|
1179 break;
|
|
1180
|
|
1181 #endif /* HAVE_MENUBARS */
|
|
1182
|
|
1183 case WM_COMMAND:
|
|
1184 {
|
|
1185 WORD id = LOWORD (wParam);
|
|
1186 frame = XFRAME (mswindows_find_frame (hwnd));
|
|
1187
|
|
1188 #ifdef HAVE_MENUBARS
|
|
1189 if (!NILP (mswindows_handle_wm_command (frame, id)))
|
|
1190 break;
|
|
1191 #endif
|
|
1192
|
|
1193 #ifdef HAVE_TOOLBARS
|
263
|
1194 /* O Toolbar Implementor, this place may have something for you!;*/
|
249
|
1195 #endif
|
|
1196
|
269
|
1197 /* Bite me - a spurious command. This cannot happen. */
|
|
1198 error ("XEMACS BUG: Cannot decode command message");
|
249
|
1199 }
|
|
1200 break;
|
|
1201
|
|
1202 case WM_DROPFILES: /* implementation ripped-off from event-Xt.c */
|
|
1203 {
|
|
1204 UINT filecount, i, len;
|
|
1205 POINT point;
|
|
1206 char filename[MAX_PATH];
|
259
|
1207 #ifdef __CYGWIN32__
|
|
1208 char* fname;
|
|
1209 #endif
|
249
|
1210 Lisp_Object l_type, l_dndlist = Qnil, l_item;
|
|
1211
|
|
1212 emacs_event = Fmake_event (Qnil, Qnil);
|
|
1213 event = XEVENT(emacs_event);
|
|
1214
|
|
1215 if (!DragQueryPoint ((HANDLE) wParam, &point))
|
|
1216 point.x = point.y = -1; /* outside client area */
|
|
1217
|
|
1218 filecount = DragQueryFile ((HANDLE) wParam, -1, NULL, 0);
|
|
1219 if (filecount == 1)
|
|
1220 {
|
|
1221 l_type = make_int (DndFile);
|
|
1222 len = DragQueryFile ((HANDLE) wParam, 0, filename, MAX_PATH);
|
259
|
1223 #ifdef __CYGWIN32__
|
|
1224 CYGWIN_CONV_PATH(filename, fname);
|
|
1225 len=strlen(fname);
|
|
1226 l_dndlist = make_ext_string (fname, len, FORMAT_FILENAME);
|
|
1227 #else
|
249
|
1228 l_dndlist = make_ext_string (filename, len, FORMAT_FILENAME);
|
259
|
1229 #endif
|
249
|
1230 }
|
|
1231 else
|
|
1232 {
|
|
1233 l_type = make_int (DndFiles);
|
|
1234 for (i=0; i<filecount; i++)
|
|
1235 {
|
|
1236 len = DragQueryFile ((HANDLE) wParam, i, filename, MAX_PATH);
|
259
|
1237 #ifdef __CYGWIN32__
|
|
1238 CYGWIN_CONV_PATH(filename, fname);
|
|
1239 len=strlen(fname);
|
|
1240 l_item = make_ext_string (fname, len, FORMAT_FILENAME);
|
|
1241 #else
|
249
|
1242 l_item = make_ext_string (filename, len, FORMAT_FILENAME);
|
259
|
1243 #endif
|
249
|
1244 l_dndlist = Fcons (l_item, l_dndlist); /* reverse order */
|
|
1245 }
|
|
1246 }
|
|
1247 DragFinish ((HANDLE) wParam);
|
|
1248
|
|
1249 event->channel = mswindows_find_frame(hwnd);
|
|
1250 event->timestamp = GetMessageTime();
|
|
1251 event->event_type = dnd_drop_event;
|
|
1252 event->event.dnd_drop.button = 1; /* #### Should try harder */
|
|
1253 event->event.dnd_drop.modifiers = mswindows_modifier_state (NULL, 0);
|
|
1254 event->event.dnd_drop.x = point.x;
|
|
1255 event->event.dnd_drop.y = point.y;
|
|
1256 event->event.dnd_drop.data = Fcons (l_type, Fcons (l_dndlist, Qnil));
|
|
1257
|
|
1258 mswindows_enqueue_dispatch_event (emacs_event);
|
|
1259 }
|
|
1260 break;
|
|
1261
|
|
1262 defproc:
|
|
1263 default:
|
|
1264 return DefWindowProc (hwnd, message, wParam, lParam);
|
|
1265 }
|
|
1266 return (0);
|
|
1267 }
|
|
1268
|
|
1269
|
|
1270 /************************************************************************/
|
|
1271 /* keyboard, mouse & other helpers for the windows procedure */
|
|
1272 /************************************************************************/
|
|
1273 static void
|
|
1274 mswindows_set_chord_timer (HWND hwnd)
|
|
1275 {
|
|
1276 int interval;
|
|
1277
|
269
|
1278 /* We get one third half system double click threshold */
|
249
|
1279 if (mswindows_button2_chord_time <= 0)
|
269
|
1280 interval = GetDoubleClickTime () / 3;
|
249
|
1281 else
|
|
1282 interval = mswindows_button2_chord_time;
|
|
1283
|
|
1284 SetTimer (hwnd, BUTTON_2_TIMER_ID, interval, 0);
|
|
1285 }
|
|
1286
|
|
1287 static int
|
|
1288 mswindows_button2_near_enough (POINTS p1, POINTS p2)
|
|
1289 {
|
|
1290 int dx, dy;
|
|
1291 if (mswindows_button2_max_skew_x <= 0)
|
|
1292 dx = GetSystemMetrics (SM_CXDOUBLECLK) / 2;
|
|
1293 else
|
|
1294 dx = mswindows_button2_max_skew_x;
|
|
1295
|
|
1296 if (mswindows_button2_max_skew_y <= 0)
|
|
1297 dy = GetSystemMetrics (SM_CYDOUBLECLK) / 2;
|
|
1298 else
|
|
1299 dy = mswindows_button2_max_skew_y;
|
|
1300
|
|
1301 return abs (p1.x - p2.x) < dx && abs (p1.y- p2.y)< dy;
|
|
1302 }
|
|
1303
|
|
1304 static int
|
|
1305 mswindows_current_layout_has_AltGr (void)
|
|
1306 {
|
|
1307 /* This simple caching mechanism saves 10% of CPU
|
|
1308 time when a key typed at autorepeat rate of 30 cps! */
|
|
1309 static HKL last_hkl = 0;
|
|
1310 static int last_hkl_has_AltGr;
|
|
1311
|
|
1312 HKL current_hkl = GetKeyboardLayout (0);
|
|
1313 if (current_hkl != last_hkl)
|
|
1314 {
|
|
1315 TCHAR c;
|
|
1316 last_hkl_has_AltGr = 0;
|
|
1317 /* In this loop, we query whether a character requires
|
|
1318 AltGr to be down to generate it. If at least such one
|
|
1319 found, this means that the layout does regard AltGr */
|
|
1320 for (c = ' '; c <= 0xFFU && c != 0 && !last_hkl_has_AltGr; ++c)
|
|
1321 if (HIBYTE (VkKeyScan (c)) == 6)
|
|
1322 last_hkl_has_AltGr = 1;
|
|
1323 last_hkl = current_hkl;
|
|
1324 }
|
|
1325 return last_hkl_has_AltGr;
|
|
1326 }
|
|
1327
|
|
1328
|
|
1329 /* Returns the state of the modifier keys in the format expected by the
|
|
1330 * Lisp_Event key_data, button_data and motion_data modifiers member */
|
|
1331 int mswindows_modifier_state (BYTE* keymap, int has_AltGr)
|
|
1332 {
|
|
1333 int mods = 0;
|
|
1334
|
|
1335 if (keymap == NULL)
|
|
1336 {
|
|
1337 keymap = (BYTE*) alloca(256);
|
|
1338 GetKeyboardState (keymap);
|
|
1339 has_AltGr = mswindows_current_layout_has_AltGr ();
|
|
1340 }
|
|
1341
|
|
1342 if (has_AltGr && (keymap [VK_LCONTROL] & 0x80) && (keymap [VK_RMENU] & 0x80))
|
|
1343 {
|
|
1344 mods |= (keymap [VK_LMENU] & 0x80) ? MOD_META : 0;
|
|
1345 mods |= (keymap [VK_RCONTROL] & 0x80) ? MOD_CONTROL : 0;
|
|
1346 }
|
|
1347 else
|
|
1348 {
|
|
1349 mods |= (keymap [VK_MENU] & 0x80) ? MOD_META : 0;
|
|
1350 mods |= (keymap [VK_CONTROL] & 0x80) ? MOD_CONTROL : 0;
|
|
1351 }
|
|
1352
|
|
1353 mods |= (keymap [VK_SHIFT] & 0x80) ? MOD_SHIFT : 0;
|
|
1354
|
|
1355 return mods;
|
|
1356 }
|
|
1357
|
|
1358 /*
|
|
1359 * Translate a mswindows virtual key to a keysym.
|
|
1360 * Only returns non-Qnil for keys that don't generate WM_CHAR messages
|
|
1361 * or whose ASCII codes (like space) xemacs doesn't like.
|
|
1362 * Virtual key values are defined in winresrc.h
|
|
1363 * XXX I'm not sure that KEYSYM("name") is the best thing to use here.
|
|
1364 */
|
|
1365 Lisp_Object mswindows_key_to_emacs_keysym(int mswindows_key, int mods)
|
|
1366 {
|
|
1367 switch (mswindows_key)
|
|
1368 {
|
|
1369 /* First the predefined ones */
|
|
1370 case VK_BACK: return QKbackspace;
|
|
1371 case VK_TAB: return QKtab;
|
|
1372 case '\n': return QKlinefeed; /* No VK_LINEFEED in winresrc.h */
|
|
1373 case VK_RETURN: return QKreturn;
|
|
1374 case VK_ESCAPE: return QKescape;
|
|
1375 case VK_SPACE: return QKspace;
|
|
1376 case VK_DELETE: return QKdelete;
|
|
1377
|
|
1378 /* The rest */
|
|
1379 case VK_CLEAR: return KEYSYM ("clear"); /* Should do ^L ? */
|
|
1380 case VK_PRIOR: return KEYSYM ("prior");
|
|
1381 case VK_NEXT: return KEYSYM ("next");
|
|
1382 case VK_END: return KEYSYM ("end");
|
|
1383 case VK_HOME: return KEYSYM ("home");
|
|
1384 case VK_LEFT: return KEYSYM ("left");
|
|
1385 case VK_UP: return KEYSYM ("up");
|
|
1386 case VK_RIGHT: return KEYSYM ("right");
|
|
1387 case VK_DOWN: return KEYSYM ("down");
|
|
1388 case VK_SELECT: return KEYSYM ("select");
|
|
1389 case VK_PRINT: return KEYSYM ("print");
|
|
1390 case VK_EXECUTE: return KEYSYM ("execute");
|
|
1391 case VK_SNAPSHOT: return KEYSYM ("print");
|
|
1392 case VK_INSERT: return KEYSYM ("insert");
|
|
1393 case VK_HELP: return KEYSYM ("help");
|
|
1394 #if 0 /* XXX What are these supposed to do? */
|
|
1395 case VK_LWIN return KEYSYM ("");
|
|
1396 case VK_RWIN return KEYSYM ("");
|
|
1397 #endif
|
|
1398 case VK_APPS: return KEYSYM ("menu");
|
|
1399 case VK_F1: return KEYSYM ("f1");
|
|
1400 case VK_F2: return KEYSYM ("f2");
|
|
1401 case VK_F3: return KEYSYM ("f3");
|
|
1402 case VK_F4: return KEYSYM ("f4");
|
|
1403 case VK_F5: return KEYSYM ("f5");
|
|
1404 case VK_F6: return KEYSYM ("f6");
|
|
1405 case VK_F7: return KEYSYM ("f7");
|
|
1406 case VK_F8: return KEYSYM ("f8");
|
|
1407 case VK_F9: return KEYSYM ("f9");
|
|
1408 case VK_F10: return KEYSYM ("f10");
|
|
1409 case VK_F11: return KEYSYM ("f11");
|
|
1410 case VK_F12: return KEYSYM ("f12");
|
|
1411 case VK_F13: return KEYSYM ("f13");
|
|
1412 case VK_F14: return KEYSYM ("f14");
|
|
1413 case VK_F15: return KEYSYM ("f15");
|
|
1414 case VK_F16: return KEYSYM ("f16");
|
|
1415 case VK_F17: return KEYSYM ("f17");
|
|
1416 case VK_F18: return KEYSYM ("f18");
|
|
1417 case VK_F19: return KEYSYM ("f19");
|
|
1418 case VK_F20: return KEYSYM ("f20");
|
|
1419 case VK_F21: return KEYSYM ("f21");
|
|
1420 case VK_F22: return KEYSYM ("f22");
|
|
1421 case VK_F23: return KEYSYM ("f23");
|
|
1422 case VK_F24: return KEYSYM ("f24");
|
|
1423 }
|
|
1424 return Qnil;
|
|
1425 }
|
|
1426
|
|
1427 /*
|
|
1428 * Find the console that matches the supplied mswindows window handle
|
|
1429 */
|
|
1430 Lisp_Object
|
|
1431 mswindows_find_console (HWND hwnd)
|
|
1432 {
|
|
1433 Lisp_Object concons;
|
|
1434
|
|
1435 CONSOLE_LOOP (concons)
|
|
1436 {
|
|
1437 Lisp_Object console = XCAR (concons);
|
|
1438 /* We only support one console so this must be it */
|
|
1439 return console;
|
|
1440 }
|
|
1441
|
|
1442 return Qnil;
|
|
1443 }
|
|
1444
|
|
1445 /*
|
|
1446 * Find the frame that matches the supplied mswindows window handle
|
|
1447 */
|
|
1448 static Lisp_Object
|
|
1449 mswindows_find_frame (HWND hwnd)
|
|
1450 {
|
269
|
1451 LONG l = GetWindowLong (hwnd, XWL_FRAMEOBJ);
|
|
1452 Lisp_Object f;
|
|
1453 if (l == 0)
|
|
1454 {
|
|
1455 /* We are in progress of frame creation. Return the frame
|
|
1456 being created, as it still not remembered in the window
|
|
1457 extra storage. */
|
|
1458 assert (!NILP (mswindows_frame_being_created));
|
|
1459 return mswindows_frame_being_created;
|
|
1460 }
|
|
1461 VOID_TO_LISP (f, l);
|
|
1462 return f;
|
249
|
1463 }
|
|
1464
|
213
|
1465
|
|
1466 /************************************************************************/
|
|
1467 /* methods */
|
|
1468 /************************************************************************/
|
|
1469
|
|
1470 static int
|
|
1471 emacs_mswindows_add_timeout (EMACS_TIME thyme)
|
|
1472 {
|
223
|
1473 int milliseconds;
|
213
|
1474 EMACS_TIME current_time;
|
|
1475 EMACS_GET_TIME (current_time);
|
|
1476 EMACS_SUB_TIME (thyme, thyme, current_time);
|
223
|
1477 milliseconds = EMACS_SECS (thyme) * 1000 +
|
|
1478 (EMACS_USECS (thyme) + 500) / 1000;
|
213
|
1479 if (milliseconds < 1)
|
|
1480 milliseconds = 1;
|
227
|
1481 ++mswindows_pending_timers_count;
|
249
|
1482 return SetTimer (NULL, 0, milliseconds,
|
|
1483 (TIMERPROC) mswindows_wm_timer_callback);
|
213
|
1484 }
|
|
1485
|
|
1486 static void
|
|
1487 emacs_mswindows_remove_timeout (int id)
|
|
1488 {
|
223
|
1489 struct Lisp_Event match_against;
|
|
1490 Lisp_Object emacs_event;
|
|
1491
|
233
|
1492 if (KillTimer (NULL, id))
|
|
1493 --mswindows_pending_timers_count;
|
223
|
1494
|
|
1495 /* If there is a dispatch event generated by this
|
|
1496 timeout in the queue, we have to remove it too. */
|
|
1497 match_against.event_type = timeout_event;
|
|
1498 match_against.event.timeout.interval_id = id;
|
|
1499 emacs_event = mswindows_cancel_dispatch_event (&match_against);
|
|
1500 if (!NILP (emacs_event))
|
|
1501 Fdeallocate_event(emacs_event);
|
213
|
1502 }
|
|
1503
|
219
|
1504 /* If `user_p' is false, then return whether there are any win32, timeout,
|
|
1505 * or subprocess events pending (that is, whether
|
|
1506 * emacs_mswindows_next_event() would return immediately without blocking).
|
|
1507 *
|
|
1508 * if `user_p' is true, then return whether there are any *user generated*
|
|
1509 * events available (that is, whether there are keyboard or mouse-click
|
|
1510 * events ready to be read). This also implies that
|
|
1511 * emacs_mswindows_next_event() would not block.
|
|
1512 */
|
213
|
1513 static int
|
|
1514 emacs_mswindows_event_pending_p (int user_p)
|
|
1515 {
|
223
|
1516 mswindows_need_event (user_p, 0);
|
219
|
1517
|
223
|
1518 return (!NILP (mswindows_u_dispatch_event_queue)
|
|
1519 || (!user_p && !NILP (mswindows_s_dispatch_event_queue)));
|
213
|
1520 }
|
|
1521
|
|
1522 /*
|
|
1523 * Return the next event
|
|
1524 */
|
|
1525 static void
|
|
1526 emacs_mswindows_next_event (struct Lisp_Event *emacs_event)
|
|
1527 {
|
223
|
1528 Lisp_Object event, event2;
|
|
1529
|
|
1530 /* Give strong preference to user events */
|
|
1531 mswindows_need_event (1, 1);
|
213
|
1532
|
223
|
1533 /* XXX Copied from event-Xt.c */
|
|
1534 event = mswindows_dequeue_dispatch_event (!NILP(mswindows_u_dispatch_event_queue));
|
|
1535 XSETEVENT (event2, emacs_event);
|
|
1536 Fcopy_event (event, event2);
|
|
1537 Fdeallocate_event (event);
|
213
|
1538 }
|
|
1539
|
|
1540 /*
|
|
1541 * Handle a magic event off the dispatch queue.
|
|
1542 */
|
|
1543 static void
|
|
1544 emacs_mswindows_handle_magic_event (struct Lisp_Event *emacs_event)
|
|
1545 {
|
|
1546 switch (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event))
|
|
1547 {
|
|
1548 case WM_SETFOCUS:
|
|
1549 case WM_KILLFOCUS:
|
|
1550 {
|
223
|
1551 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
|
|
1552 struct frame *f = XFRAME (frame);
|
213
|
1553 int in_p = (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event) == WM_SETFOCUS);
|
|
1554 Lisp_Object conser;
|
223
|
1555
|
213
|
1556 /* struct gcpro gcpro1; */
|
|
1557
|
|
1558 /* Clear sticky modifiers here (if we had any) */
|
|
1559
|
|
1560 conser = Fcons (frame, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil));
|
|
1561 /* GCPRO1 (conser); XXX Not necessary? */
|
|
1562 emacs_handle_focus_change_preliminary (conser);
|
|
1563 /* Under X the stuff up to here is done in the X event handler.
|
|
1564 I Don't know why */
|
|
1565 emacs_handle_focus_change_final (conser);
|
|
1566 /* UNGCPRO; */
|
223
|
1567
|
213
|
1568 }
|
|
1569 break;
|
|
1570
|
223
|
1571 case XM_BUMPQUEUE:
|
|
1572 /* This is a nice event, when we're in need to queue *something* */
|
|
1573 break;
|
|
1574
|
|
1575 case XM_MAPFRAME:
|
|
1576 case XM_UNMAPFRAME:
|
|
1577 {
|
|
1578 Lisp_Object frame = EVENT_CHANNEL (emacs_event);
|
|
1579 va_run_hook_with_args (EVENT_MSWINDOWS_MAGIC_TYPE(emacs_event)
|
|
1580 == XM_MAPFRAME ?
|
|
1581 Qmap_frame_hook : Qunmap_frame_hook,
|
|
1582 1, frame);
|
|
1583 }
|
|
1584 break;
|
|
1585
|
249
|
1586 /* #### What about Enter & Leave */
|
213
|
1587 #if 0
|
|
1588 va_run_hook_with_args (in_p ? Qmouse_enter_frame_hook :
|
|
1589 Qmouse_leave_frame_hook, 1, frame);
|
|
1590 #endif
|
|
1591
|
|
1592 default:
|
|
1593 assert(0);
|
|
1594 }
|
|
1595 }
|
|
1596
|
|
1597 static void
|
|
1598 emacs_mswindows_select_process (struct Lisp_Process *process)
|
|
1599 {
|
|
1600 }
|
|
1601
|
|
1602 static void
|
|
1603 emacs_mswindows_unselect_process (struct Lisp_Process *process)
|
|
1604 {
|
|
1605 }
|
|
1606
|
|
1607 static void
|
|
1608 emacs_mswindows_select_console (struct console *con)
|
|
1609 {
|
|
1610 }
|
|
1611
|
|
1612 static void
|
|
1613 emacs_mswindows_unselect_console (struct console *con)
|
|
1614 {
|
|
1615 }
|
|
1616
|
|
1617 static void
|
|
1618 emacs_mswindows_quit_p (void)
|
|
1619 {
|
223
|
1620 mswindows_need_event (1, 0);
|
|
1621
|
|
1622 if (mswindows_quit_chars_count > 0)
|
|
1623 {
|
|
1624 /* Yes there's a hidden one... Throw it away */
|
|
1625 struct Lisp_Event match_against;
|
|
1626 Lisp_Object emacs_event;
|
|
1627
|
|
1628 match_against.event_type = key_press_event;
|
|
1629 match_against.event.key.modifiers = FAKE_MOD_QUIT;
|
|
1630
|
|
1631 emacs_event = mswindows_cancel_dispatch_event (&match_against);
|
|
1632 assert (!NILP (emacs_event));
|
|
1633
|
|
1634 Vquit_flag = (XEVENT(emacs_event)->event.key.modifiers & MOD_SHIFT
|
|
1635 ? Qcritical : Qt);
|
|
1636
|
|
1637 Fdeallocate_event(emacs_event);
|
|
1638 --mswindows_quit_chars_count;
|
|
1639 }
|
213
|
1640 }
|
|
1641
|
263
|
1642 #ifndef HAVE_X_WINDOWS
|
213
|
1643 /* This is called from GC when a process object is about to be freed.
|
|
1644 If we've still got pointers to it in this file, we're gonna lose hard.
|
|
1645 */
|
|
1646 void
|
|
1647 debug_process_finalization (struct Lisp_Process *p)
|
|
1648 {
|
|
1649 #if 0 /* #### */
|
263
|
1650 Lisp_Object instr, outstr;
|
|
1651
|
|
1652 get_process_streams (p, &instr, &outstr);
|
213
|
1653 /* if it still has fds, then it hasn't been killed yet. */
|
263
|
1654 assert (NILP(instr));
|
|
1655 assert (NILP(outstr));
|
|
1656
|
|
1657 /* #### More checks here */
|
213
|
1658 #endif
|
|
1659 }
|
263
|
1660 #endif
|
213
|
1661
|
|
1662 /************************************************************************/
|
|
1663 /* initialization */
|
|
1664 /************************************************************************/
|
|
1665
|
|
1666 void
|
|
1667 vars_of_event_mswindows (void)
|
|
1668 {
|
223
|
1669 mswindows_u_dispatch_event_queue = Qnil;
|
|
1670 staticpro (&mswindows_u_dispatch_event_queue);
|
|
1671 mswindows_u_dispatch_event_queue_tail = Qnil;
|
|
1672
|
|
1673 mswindows_s_dispatch_event_queue = Qnil;
|
|
1674 staticpro (&mswindows_s_dispatch_event_queue);
|
|
1675 mswindows_s_dispatch_event_queue_tail = Qnil;
|
213
|
1676
|
231
|
1677 mswindows_error_caught_in_modal_loop = Qnil;
|
|
1678 staticpro (&mswindows_error_caught_in_modal_loop);
|
|
1679 mswindows_in_modal_loop = 0;
|
227
|
1680 mswindows_pending_timers_count = 0;
|
|
1681
|
213
|
1682 mswindows_event_stream = xnew (struct event_stream);
|
|
1683
|
|
1684 mswindows_event_stream->event_pending_p = emacs_mswindows_event_pending_p;
|
223
|
1685 mswindows_event_stream->next_event_cb = emacs_mswindows_next_event;
|
213
|
1686 mswindows_event_stream->handle_magic_event_cb = emacs_mswindows_handle_magic_event;
|
|
1687 mswindows_event_stream->add_timeout_cb = emacs_mswindows_add_timeout;
|
|
1688 mswindows_event_stream->remove_timeout_cb = emacs_mswindows_remove_timeout;
|
|
1689 mswindows_event_stream->select_console_cb = emacs_mswindows_select_console;
|
223
|
1690 mswindows_event_stream->unselect_console_cb = emacs_mswindows_unselect_console;
|
213
|
1691 mswindows_event_stream->select_process_cb = emacs_mswindows_select_process;
|
223
|
1692 mswindows_event_stream->unselect_process_cb = emacs_mswindows_unselect_process;
|
213
|
1693 mswindows_event_stream->quit_p_cb = emacs_mswindows_quit_p;
|
223
|
1694
|
225
|
1695 DEFVAR_BOOL ("mswindows-dynamic-frame-resize", &mswindows_dynamic_frame_resize /*
|
223
|
1696 *Controls redrawing frame contents during mouse-drag or keyboard resize
|
|
1697 operation. When non-nil, the frame is redrawn while being resized. When
|
|
1698 nil, frame is not redrawn, and exposed areas are filled with default
|
|
1699 MDI application background color. Note that this option only has effect
|
|
1700 if "Show window contents while dragging" is on in system Display/Plus!
|
|
1701 settings.
|
|
1702 Default is t on fast machines, nil on slow.
|
|
1703 */ );
|
|
1704
|
|
1705 /* The description copied verbatim from nt-emacs. (C) Geoff Voelker */
|
225
|
1706 DEFVAR_INT ("mswindows-mouse-button-tolerance", &mswindows_button2_chord_time /*
|
223
|
1707 *Analogue of double click interval for faking middle mouse events.
|
|
1708 The value is the minimum time in milliseconds that must elapse between
|
|
1709 left/right button down events before they are considered distinct events.
|
|
1710 If both mouse buttons are depressed within this interval, a middle mouse
|
|
1711 button down event is generated instead.
|
|
1712 If negative or zero, currently set system default is used instead.
|
|
1713 */ );
|
|
1714
|
|
1715 /* The description copied verbatim from nt-emacs. (C) Geoff Voelker */
|
225
|
1716 DEFVAR_INT ("mswindows-num-mouse-buttons", &mswindows_num_mouse_buttons /*
|
223
|
1717 Number of physical mouse buttons.
|
|
1718 */ );
|
|
1719
|
225
|
1720 DEFVAR_INT ("mswindows-mouse-button-max-skew-x", &mswindows_button2_max_skew_x /*
|
223
|
1721 *Maximum horizontal distance in pixels between points in which left and
|
|
1722 right button clicks occured for them to be translated into single
|
|
1723 middle button event. Clicks must occur in time not longer than defined
|
225
|
1724 by the variable mswindows-mouse-button-tolerance.
|
223
|
1725 If negative or zero, currently set system default is used instead.
|
|
1726 */ );
|
|
1727
|
225
|
1728 DEFVAR_INT ("mswindows-mouse-button-max-skew-y", &mswindows_button2_max_skew_y /*
|
223
|
1729 *Maximum vertical distance in pixels between points in which left and
|
|
1730 right button clicks occured for them to be translated into single
|
|
1731 middle button event. Clicks must occur in time not longer than defined
|
225
|
1732 by the variable mswindows-mouse-button-tolerance.
|
223
|
1733 If negative or zero, currently set system default is used instead.
|
|
1734 */ );
|
|
1735
|
|
1736 mswindows_button2_max_skew_x = 0;
|
|
1737 mswindows_button2_max_skew_y = 0;
|
|
1738 mswindows_button2_chord_time = 0;
|
213
|
1739 }
|
|
1740
|
|
1741 void
|
|
1742 syms_of_event_mswindows (void)
|
|
1743 {
|
|
1744 }
|
|
1745
|
|
1746 void
|
|
1747 init_event_mswindows_late (void)
|
|
1748 {
|
|
1749 event_stream = mswindows_event_stream;
|
223
|
1750
|
|
1751 mswindows_dynamic_frame_resize = !GetSystemMetrics (SM_SLOWMACHINE);
|
|
1752 mswindows_num_mouse_buttons = GetSystemMetrics (SM_CMOUSEBUTTONS);
|
213
|
1753 }
|