213
|
1 /* mswindows specific event-handling.
|
|
2 Copyright (C) 1997 Jonathan Harris.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: Not in FSF. */
|
|
22
|
|
23 /* Authorship:
|
|
24
|
|
25 Jonathan Harris, November 1997 for 20.4.
|
|
26 */
|
|
27
|
|
28 #include <config.h>
|
|
29 #include "lisp.h"
|
|
30
|
|
31 #include "console-msw.h"
|
|
32 #include "device.h"
|
|
33 #include "frame.h"
|
|
34 #include "events.h"
|
|
35 #include "event-msw.h"
|
|
36
|
219
|
37 #ifdef DEBUG_XEMACS
|
|
38 # include "opaque.h" /* For the debug functions at the end of this file */
|
|
39 # undef DEBUG_MESSAGES
|
|
40 # undef DEBUG_TIMEOUTS
|
|
41 #endif
|
|
42
|
223
|
43 #ifdef HAVE_MENUBARS
|
|
44 #define ADJR_MENUFLAG TRUE
|
|
45 #else
|
|
46 #define ADJR_MENUFLAG FALSE
|
|
47 #endif
|
213
|
48
|
223
|
49 /* Timer ID used for button2 emulation */
|
|
50 #define BUTTON_2_TIMER_ID 1
|
|
51
|
213
|
52 static Lisp_Object mswindows_find_frame (HWND hwnd);
|
219
|
53 static Lisp_Object mswindows_key_to_emacs_keysym(int mswindows_key, int mods);
|
|
54 static int mswindows_modifier_state (void);
|
|
55 static int mswindows_enqueue_timeout (int milliseconds);
|
|
56 static void mswindows_dequeue_timeout (int interval_id);
|
|
57
|
|
58 /* Virtual keycode of the '@' key */
|
223
|
59 static int virtual_at_key = -1;
|
219
|
60
|
|
61 /* Timeout queue */
|
|
62 struct mswindows_timeout
|
|
63 {
|
|
64 int ticks;
|
|
65 int interval_id;
|
|
66 struct mswindows_timeout *next;
|
|
67 };
|
|
68 typedef struct mswindows_timeout mswindows_timeout;
|
|
69 static mswindows_timeout timeout_pool[MSW_TIMEOUT_MAX];
|
|
70 static mswindows_timeout *timeout_head = NULL;
|
|
71 static int timeout_mswindows_id;
|
213
|
72
|
223
|
73 #if 0
|
213
|
74 /*
|
|
75 * Entry point for the "windows" message-processing thread
|
|
76 */
|
|
77 DWORD mswindows_win_thread()
|
|
78 {
|
219
|
79 /* Hack! Windows doesn't report Ctrl-@ characters so we have to find out
|
|
80 * which virtual key generates '@' at runtime */
|
|
81 virtual_at_key = VkKeyScan ('@');
|
|
82 if (virtual_at_key & 0x200) /* 0x200 means the control key */
|
|
83 /* If you need Ctrl just to generate @, you can't do Ctrl-@ */
|
|
84 virtual_at_key = -1;
|
|
85 else
|
|
86 virtual_at_key &= 0xff; /* The low byte contains the keycode */
|
|
87
|
213
|
88 /* Main windows loop */
|
|
89 while (1)
|
|
90 {
|
|
91 GetMessage (&msg, NULL, 0, 0);
|
|
92
|
|
93 /*
|
|
94 * Process things that don't have an associated window, so wouldn't
|
|
95 * get sent to mswindows_wnd_proc
|
|
96 */
|
|
97
|
|
98 /* Request from main thread */
|
|
99 if (msg.message>=WM_XEMACS_BASE && msg.message<=WM_XEMACS_END)
|
|
100 mswindows_handle_request(&msg);
|
|
101
|
219
|
102 /* Timeout(s) */
|
213
|
103 else if (msg.message == WM_TIMER)
|
|
104 {
|
219
|
105 EnterCriticalSection (&mswindows_dispatch_crit);
|
|
106 if (timeout_head!=NULL)
|
|
107 --(timeout_head->ticks);
|
|
108
|
|
109 while (timeout_head!=NULL && timeout_head->ticks==0)
|
|
110 {
|
|
111 Lisp_Object emacs_event;
|
|
112 struct Lisp_Event *event;
|
|
113 int id = timeout_head->interval_id;
|
213
|
114
|
219
|
115 #ifdef DEBUG_TIMEOUTS
|
|
116 stderr_out("--> %x\n", id);
|
|
117 #endif
|
|
118 mswindows_dequeue_timeout (id);
|
|
119 emacs_event = Fmake_event (Qnil, Qnil);
|
|
120 event = XEVENT(emacs_event);
|
213
|
121
|
219
|
122 event->channel = Qnil;
|
|
123 event->timestamp = msg.time;
|
|
124 event->event_type = timeout_event;
|
|
125 event->event.timeout.interval_id = id;
|
|
126 mswindows_enqueue_dispatch_event (emacs_event);
|
|
127 }
|
213
|
128 LeaveCriticalSection (&mswindows_dispatch_crit);
|
|
129 }
|
|
130 else
|
|
131 /* Pass on to mswindows_wnd_proc */
|
|
132 DispatchMessage (&msg);
|
|
133 }
|
|
134 }
|
223
|
135 #endif /* 0 */
|
|
136
|
|
137 static void
|
|
138 mswindows_enqueue_magic_event (HWND hwnd, UINT message)
|
|
139 {
|
|
140 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
141 struct Lisp_Event* event = XEVENT (emacs_event);
|
|
142
|
|
143 event->channel = mswindows_find_frame (hwnd);
|
|
144 event->timestamp = GetMessageTime();
|
|
145 event->event_type = magic_event;
|
|
146 EVENT_MSWINDOWS_MAGIC_TYPE (event) = message;
|
|
147
|
|
148 mswindows_enqueue_dispatch_event (emacs_event);
|
|
149 }
|
|
150
|
|
151 static void
|
|
152 mswindows_enqueue_mouse_button_event (HWND hwnd, UINT message, POINTS where, DWORD when)
|
|
153 {
|
|
154
|
|
155 /* We always use last message time, because mouse button
|
|
156 events may get delayed, and XEmacs double click
|
|
157 recognition will fail */
|
|
158
|
|
159 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
160 struct Lisp_Event* event = XEVENT(emacs_event);
|
|
161
|
|
162 event->channel = mswindows_find_frame(hwnd);
|
|
163 event->timestamp = when;
|
|
164 event->event.button.button =
|
|
165 (message==WM_LBUTTONDOWN || message==WM_LBUTTONUP) ? 1 :
|
|
166 ((message==WM_RBUTTONDOWN || message==WM_RBUTTONUP) ? 3 : 2);
|
|
167 event->event.button.x = where.x;
|
|
168 event->event.button.y = where.y;
|
|
169 event->event.button.modifiers = mswindows_modifier_state();
|
|
170
|
|
171 if (message==WM_LBUTTONDOWN || message==WM_MBUTTONDOWN ||
|
|
172 message==WM_RBUTTONDOWN)
|
|
173 {
|
|
174 event->event_type = button_press_event;
|
|
175 SetCapture (hwnd);
|
|
176 }
|
|
177 else
|
|
178 {
|
|
179 event->event_type = button_release_event;
|
|
180 ReleaseCapture ();
|
|
181 }
|
|
182
|
|
183 mswindows_enqueue_dispatch_event (emacs_event);
|
|
184 }
|
|
185
|
|
186 static void
|
|
187 mswindows_set_chord_timer (HWND hwnd)
|
|
188 {
|
|
189 int interval;
|
|
190
|
|
191 /* We get half system threshold as it seems to
|
|
192 long before drag-selection is shown */
|
|
193 if (mswindows_button2_chord_time <= 0)
|
|
194 interval = GetDoubleClickTime () / 2;
|
|
195 else
|
|
196 interval = mswindows_button2_chord_time;
|
|
197
|
|
198 SetTimer (hwnd, BUTTON_2_TIMER_ID, interval, 0);
|
|
199 }
|
|
200
|
|
201 static int
|
|
202 mswindows_button2_near_enough (POINTS p1, POINTS p2)
|
|
203 {
|
|
204 int dx, dy;
|
|
205 if (mswindows_button2_max_skew_x <= 0)
|
|
206 dx = GetSystemMetrics (SM_CXDOUBLECLK) / 2;
|
|
207 else
|
|
208 dx = mswindows_button2_max_skew_x;
|
|
209
|
|
210 if (mswindows_button2_max_skew_y <= 0)
|
|
211 dy = GetSystemMetrics (SM_CYDOUBLECLK) / 2;
|
|
212 else
|
|
213 dy = mswindows_button2_max_skew_y;
|
|
214
|
|
215 return abs (p1.x - p2.x) < dx && abs (p1.y- p2.y)< dy;
|
|
216 }
|
213
|
217
|
|
218 /*
|
|
219 * The windows procedure for the window class XEMACS_CLASS
|
|
220 * Stuffs messages in the mswindows event queue
|
|
221 */
|
223
|
222 LRESULT WINAPI
|
|
223 mswindows_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
213
|
224 {
|
|
225 /* Note: Remember to initialise these before use */
|
|
226 Lisp_Object emacs_event;
|
|
227 struct Lisp_Event *event;
|
223
|
228 Lisp_Object fobj;
|
|
229 struct frame *frame;
|
|
230 struct mswindows_frame* msframe;
|
|
231
|
213
|
232 switch (message)
|
|
233 {
|
223
|
234 case WM_ERASEBKGND:
|
|
235 /* Erase background only during non-dynamic sizing */
|
|
236 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
237 if (msframe->sizing && !mswindows_dynamic_frame_resize)
|
|
238 goto defproc;
|
|
239 return 1;
|
|
240
|
|
241 case WM_CLOSE:
|
|
242 fobj = mswindows_find_frame (hwnd);
|
|
243 enqueue_misc_user_event (fobj, Qeval, list3 (Qdelete_frame, fobj, Qt));
|
|
244 mswindows_enqueue_magic_event (hwnd, XM_BUMPQUEUE);
|
|
245 break;
|
|
246
|
213
|
247 case WM_KEYDOWN:
|
|
248 case WM_SYSKEYDOWN:
|
|
249 {
|
223
|
250 MSG msg = { hwnd, message, wParam, lParam, GetMessageTime(), GetMessagePos() };
|
213
|
251 /* Handle those keys that TranslateMessage won't generate a WM_CHAR for */
|
219
|
252 Lisp_Object keysym;
|
|
253 int mods = mswindows_modifier_state();
|
|
254
|
|
255 if (!NILP (keysym = mswindows_key_to_emacs_keysym(wParam, mods)))
|
213
|
256 {
|
|
257 emacs_event = Fmake_event (Qnil, Qnil);
|
|
258 event = XEVENT(emacs_event);
|
|
259
|
|
260 event->channel = mswindows_find_console(hwnd);
|
223
|
261 event->timestamp = GetMessageTime();
|
213
|
262 event->event_type = key_press_event;
|
|
263 event->event.key.keysym = keysym;
|
|
264 event->event.key.modifiers = mods;
|
|
265 mswindows_enqueue_dispatch_event (emacs_event);
|
|
266 return (0);
|
|
267 }
|
223
|
268 TranslateMessage (&msg);
|
213
|
269 }
|
|
270 goto defproc;
|
|
271
|
|
272 case WM_CHAR:
|
|
273 case WM_SYSCHAR:
|
|
274 {
|
|
275 emacs_event = Fmake_event (Qnil, Qnil);
|
|
276 event = XEVENT(emacs_event);
|
|
277
|
|
278 event->channel = mswindows_find_console(hwnd);
|
223
|
279 event->timestamp = GetMessageTime();
|
213
|
280 event->event_type = key_press_event;
|
219
|
281
|
|
282 /* XEmacs doesn't seem to like Shift on non-alpha keys */
|
|
283 event->event.key.modifiers = isalpha(wParam) ?
|
|
284 mswindows_modifier_state() :
|
|
285 mswindows_modifier_state() & ~MOD_SHIFT;
|
|
286
|
223
|
287 /* If a quit char with no modifiers other than control and
|
|
288 shift, then mark it with a fake modifier, which is removed
|
|
289 upon dequeueing the event */
|
|
290 if (wParam == CONSOLE_QUIT_CHAR (XCONSOLE (mswindows_find_console (hwnd)))
|
|
291 && ((event->event.key.modifiers & ~(MOD_CONTROL | MOD_SHIFT)) == 0))
|
|
292 {
|
|
293 event->event.key.modifiers |= FAKE_MOD_QUIT;
|
|
294 ++mswindows_quit_chars_count;
|
|
295 }
|
|
296
|
219
|
297 if (wParam<' ') /* Control char not already handled under WM_KEYDOWN */
|
213
|
298 {
|
219
|
299 /* Don't capitalise alpha control keys */
|
|
300 event->event.key.keysym = isalpha(wParam+'a'-1) ?
|
|
301 make_char(wParam+'a'-1) :
|
|
302 make_char(wParam+'A'-1);
|
213
|
303 }
|
|
304 else
|
|
305 {
|
|
306 /* Assumes that emacs keysym == ASCII code */
|
|
307 event->event.key.keysym = make_char(wParam);
|
|
308 }
|
219
|
309
|
213
|
310 mswindows_enqueue_dispatch_event (emacs_event);
|
|
311 }
|
|
312 break;
|
|
313
|
223
|
314 case WM_MBUTTONDOWN:
|
|
315 case WM_MBUTTONUP:
|
|
316 /* Real middle mouse button has nothing to do with emulated one:
|
|
317 if one wants to exercise fingers playing chords on the mouse,
|
|
318 he is allowed to do that! */
|
|
319 mswindows_enqueue_mouse_button_event (hwnd, message,
|
|
320 MAKEPOINTS (lParam), GetMessageTime());
|
|
321 break;
|
|
322
|
|
323 case WM_LBUTTONUP:
|
|
324 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
325 msframe->last_click_time = GetMessageTime();
|
|
326
|
|
327 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
328 msframe->button2_need_lbutton = 0;
|
|
329 if (msframe->ignore_next_lbutton_up)
|
|
330 {
|
|
331 msframe->ignore_next_lbutton_up = 0;
|
|
332 }
|
|
333 else if (msframe->button2_is_down)
|
|
334 {
|
|
335 msframe->button2_is_down = 0;
|
|
336 msframe->ignore_next_rbutton_up = 1;
|
|
337 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
|
|
338 MAKEPOINTS (lParam), GetMessageTime());
|
|
339 }
|
|
340 else
|
|
341 {
|
|
342 if (msframe->button2_need_rbutton)
|
|
343 {
|
|
344 msframe->button2_need_rbutton = 0;
|
|
345 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
346 MAKEPOINTS (lParam), GetMessageTime());
|
|
347 }
|
|
348 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONUP,
|
|
349 MAKEPOINTS (lParam), GetMessageTime());
|
|
350 }
|
|
351 break;
|
|
352
|
|
353 case WM_RBUTTONUP:
|
|
354 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
355 msframe->last_click_time = GetMessageTime();
|
|
356
|
|
357 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
358 msframe->button2_need_rbutton = 0;
|
|
359 if (msframe->ignore_next_rbutton_up)
|
|
360 {
|
|
361 msframe->ignore_next_rbutton_up = 0;
|
|
362 }
|
|
363 else if (msframe->button2_is_down)
|
|
364 {
|
|
365 msframe->button2_is_down = 0;
|
|
366 msframe->ignore_next_lbutton_up = 1;
|
|
367 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
|
|
368 MAKEPOINTS (lParam), GetMessageTime());
|
|
369 }
|
|
370 else
|
|
371 {
|
|
372 if (msframe->button2_need_lbutton)
|
|
373 {
|
|
374 msframe->button2_need_lbutton = 0;
|
|
375 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
376 MAKEPOINTS (lParam), GetMessageTime());
|
|
377 }
|
|
378 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONUP,
|
|
379 MAKEPOINTS (lParam), GetMessageTime());
|
|
380 }
|
|
381 break;
|
|
382
|
213
|
383 case WM_LBUTTONDOWN:
|
223
|
384 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
385
|
|
386 if (msframe->button2_need_lbutton)
|
|
387 {
|
|
388 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
389 msframe->button2_need_lbutton = 0;
|
|
390 msframe->button2_need_rbutton = 0;
|
|
391 msframe->button2_is_down = 1;
|
|
392 if (mswindows_button2_near_enough (msframe->last_click_point, MAKEPOINTS (lParam)))
|
|
393 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
|
|
394 MAKEPOINTS (lParam), GetMessageTime());
|
|
395 else
|
|
396 {
|
|
397 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
398 msframe->last_click_point, msframe->last_click_time);
|
|
399 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
400 MAKEPOINTS (lParam), GetMessageTime());
|
|
401 }
|
|
402 }
|
|
403 else
|
|
404 {
|
|
405 mswindows_set_chord_timer (hwnd);
|
|
406 msframe->button2_need_rbutton = 1;
|
|
407 msframe->last_click_point = MAKEPOINTS (lParam);
|
|
408 }
|
|
409 msframe->last_click_time = GetMessageTime();
|
|
410 break;
|
|
411
|
213
|
412 case WM_RBUTTONDOWN:
|
223
|
413 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
414
|
|
415 if (msframe->button2_need_rbutton)
|
|
416 {
|
|
417 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
418 msframe->button2_need_lbutton = 0;
|
|
419 msframe->button2_need_rbutton = 0;
|
|
420 msframe->button2_is_down = 1;
|
|
421 if (mswindows_button2_near_enough (msframe->last_click_point, MAKEPOINTS (lParam)))
|
|
422 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
|
|
423 MAKEPOINTS (lParam), GetMessageTime());
|
|
424 else
|
|
425 {
|
|
426 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
427 msframe->last_click_point, msframe->last_click_time);
|
|
428 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
429 MAKEPOINTS (lParam), GetMessageTime());
|
|
430 }
|
|
431 }
|
|
432 else
|
|
433 {
|
|
434 mswindows_set_chord_timer (hwnd);
|
|
435 msframe->button2_need_lbutton = 1;
|
|
436 msframe->last_click_point = MAKEPOINTS (lParam);
|
|
437 }
|
|
438 msframe->last_click_time = GetMessageTime();
|
|
439 break;
|
|
440
|
|
441 case WM_TIMER:
|
|
442 if (wParam == BUTTON_2_TIMER_ID)
|
|
443 {
|
|
444 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
445 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
446
|
|
447 if (msframe->button2_need_lbutton)
|
|
448 {
|
|
449 msframe->button2_need_lbutton = 0;
|
|
450 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
451 msframe->last_click_point, msframe->last_click_time);
|
|
452 }
|
|
453 else if (msframe->button2_need_rbutton)
|
|
454 {
|
|
455 msframe->button2_need_rbutton = 0;
|
|
456 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
457 msframe->last_click_point, msframe->last_click_time);
|
|
458 }
|
|
459 }
|
|
460 else
|
|
461 assert ("Spurious timer fired" == 0);
|
|
462 break;
|
|
463
|
|
464 case WM_MOUSEMOVE:
|
|
465 /* Optimization: don't report mouse movement while size is changind */
|
|
466 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
467 if (!msframe->sizing)
|
213
|
468 {
|
223
|
469 /* When waiting for the second mouse button to finish
|
|
470 button2 emulation, and have moved too far, just pretend
|
|
471 as if timer has expired. This impoves drag-select feedback */
|
|
472 if ((msframe->button2_need_lbutton || msframe->button2_need_rbutton)
|
|
473 && !mswindows_button2_near_enough (msframe->last_click_point,
|
|
474 MAKEPOINTS (lParam)))
|
|
475 {
|
|
476 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
477 SendMessage (hwnd, WM_TIMER, BUTTON_2_TIMER_ID, 0);
|
|
478 }
|
219
|
479
|
213
|
480 emacs_event = Fmake_event (Qnil, Qnil);
|
|
481 event = XEVENT(emacs_event);
|
|
482
|
|
483 event->channel = mswindows_find_frame(hwnd);
|
223
|
484 event->timestamp = GetMessageTime();
|
213
|
485 event->event_type = pointer_motion_event;
|
223
|
486 event->event.motion.x = MAKEPOINTS(lParam).x;
|
|
487 event->event.motion.y = MAKEPOINTS(lParam).y;
|
219
|
488 event->event.motion.modifiers = mswindows_modifier_state();
|
213
|
489
|
|
490 mswindows_enqueue_dispatch_event (emacs_event);
|
|
491 }
|
|
492 break;
|
|
493
|
|
494 case WM_PAINT:
|
|
495 {
|
|
496 PAINTSTRUCT paintStruct;
|
223
|
497
|
|
498 frame = XFRAME (mswindows_find_frame (hwnd));
|
213
|
499
|
|
500 BeginPaint (hwnd, &paintStruct);
|
223
|
501 mswindows_redraw_exposed_area (frame,
|
|
502 paintStruct.rcPaint.left, paintStruct.rcPaint.top,
|
|
503 paintStruct.rcPaint.right, paintStruct.rcPaint.bottom);
|
213
|
504 EndPaint (hwnd, &paintStruct);
|
|
505 }
|
|
506 break;
|
|
507
|
|
508 case WM_SIZE:
|
|
509 /* We only care about this message if our size has really changed */
|
|
510 if (wParam==SIZE_RESTORED || wParam==SIZE_MAXIMIZED || wParam==SIZE_MINIMIZED)
|
|
511 {
|
|
512 RECT rect;
|
223
|
513 int columns, rows;
|
213
|
514
|
223
|
515 fobj = mswindows_find_frame (hwnd);
|
|
516 frame = XFRAME (fobj);
|
|
517 msframe = FRAME_MSWINDOWS_DATA (frame);
|
|
518
|
|
519 /* We cannot handle frame map and unmap hooks right in
|
|
520 this routine, because these may throw. We queue
|
|
521 magic events to run these hooks instead - kkm */
|
|
522
|
213
|
523 if (wParam==SIZE_MINIMIZED)
|
223
|
524 {
|
|
525 /* Iconified */
|
|
526 FRAME_VISIBLE_P (frame) = 0;
|
|
527 mswindows_enqueue_magic_event (hwnd, XM_UNMAPFRAME);
|
|
528 Fframe_iconified_p (fobj);
|
|
529 }
|
213
|
530 else
|
223
|
531 {
|
|
532 int was_visible = FRAME_VISIBLE_P (frame);
|
|
533 if (!msframe->sizing && !was_visible)
|
|
534 mswindows_enqueue_magic_event (hwnd, XM_MAPFRAME);
|
|
535
|
|
536 GetClientRect(hwnd, &rect);
|
|
537 FRAME_VISIBLE_P(frame) = 1;
|
|
538 FRAME_PIXWIDTH(frame) = rect.right;
|
|
539 FRAME_PIXHEIGHT(frame) = rect.bottom;
|
|
540 pixel_to_char_size (frame, rect.right, rect.bottom, &columns, &rows);
|
|
541 change_frame_size (frame, rows, columns, 1);
|
213
|
542
|
223
|
543 if (mswindows_dynamic_frame_resize)
|
|
544 redisplay ();
|
|
545 }
|
213
|
546 }
|
|
547 break;
|
|
548
|
219
|
549 /* Misc magic events which only require that the frame be identified */
|
213
|
550 case WM_SETFOCUS:
|
|
551 case WM_KILLFOCUS:
|
223
|
552 mswindows_enqueue_magic_event (hwnd, message);
|
213
|
553 break;
|
|
554
|
219
|
555 case WM_WINDOWPOSCHANGING:
|
|
556 {
|
|
557 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
|
|
558 WINDOWPLACEMENT wpl = { sizeof(WINDOWPLACEMENT) };
|
|
559 GetWindowPlacement(hwnd, &wpl);
|
|
560
|
|
561 /* Only interested if size is changing and we're not being iconified */
|
|
562 if ((wpl.showCmd != SW_SHOWMINIMIZED) && !(wp->flags & SWP_NOSIZE))
|
|
563 {
|
|
564 RECT ncsize = { 0, 0, 0, 0 };
|
|
565 int pixwidth, pixheight;
|
223
|
566 AdjustWindowRectEx (&ncsize, GetWindowLong (hwnd, GWL_STYLE),
|
|
567 GetMenu(hwnd) != NULL,
|
|
568 GetWindowLong (hwnd, GWL_EXSTYLE));
|
219
|
569
|
|
570 round_size_to_char (XFRAME (mswindows_find_frame (hwnd)),
|
|
571 wp->cx - (ncsize.right - ncsize.left),
|
|
572 wp->cy - (ncsize.bottom - ncsize.top),
|
|
573 &pixwidth, &pixheight);
|
|
574
|
|
575 /* Convert client sizes to window sizes */
|
|
576 pixwidth += (ncsize.right - ncsize.left);
|
|
577 pixheight += (ncsize.bottom - ncsize.top);
|
|
578
|
|
579 if (wpl.showCmd != SW_SHOWMAXIMIZED)
|
|
580 {
|
|
581 /* Adjust so that the bottom or right doesn't move if it's
|
|
582 * the top or left that's being changed */
|
|
583 RECT rect;
|
|
584 GetWindowRect (hwnd, &rect);
|
|
585
|
|
586 if (rect.left != wp->x)
|
|
587 wp->x += wp->cx - pixwidth;
|
|
588 if (rect.top != wp->y)
|
|
589 wp->y += wp->cy - pixheight;
|
|
590 }
|
|
591
|
|
592 wp->cx = pixwidth;
|
|
593 wp->cy = pixheight;
|
|
594 }
|
|
595 }
|
|
596 break;
|
|
597
|
221
|
598 case WM_ENTERSIZEMOVE:
|
223
|
599 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
600 msframe->sizing = 1;
|
|
601 return 0;
|
|
602
|
221
|
603 case WM_EXITSIZEMOVE:
|
223
|
604 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
605 msframe->sizing = 0;
|
|
606 /* Queue noop event */
|
|
607 mswindows_enqueue_magic_event (hwnd, XM_BUMPQUEUE);
|
|
608 return 0;
|
221
|
609
|
213
|
610 defproc:
|
|
611 default:
|
|
612 return DefWindowProc (hwnd, message, wParam, lParam);
|
|
613 }
|
|
614 return (0);
|
|
615 }
|
|
616
|
|
617
|
223
|
618 #if 0
|
213
|
619 /*
|
|
620 * Make a request to the message-processing thread to do things that
|
|
621 * can't be done in the main thread.
|
|
622 */
|
|
623 LPARAM
|
|
624 mswindows_make_request(UINT message, WPARAM wParam, mswindows_request_type *request)
|
|
625 {
|
|
626 case WM_XEMACS_SETTIMER:
|
|
627 {
|
219
|
628 int id;
|
|
629 id = mswindows_enqueue_timeout((int) request->thing1);
|
|
630 assert(PostThreadMessage (mswindows_main_thread_id, WM_XEMACS_ACK, 0, id));
|
213
|
631 }
|
|
632 break;
|
|
633
|
|
634 case WM_XEMACS_KILLTIMER:
|
|
635 {
|
219
|
636 mswindows_dequeue_timeout((int) request->thing1);
|
|
637 assert(PostThreadMessage (mswindows_main_thread_id, WM_XEMACS_ACK, 0, 0));
|
213
|
638 }
|
|
639 break;
|
|
640
|
|
641 default:
|
|
642 assert(0);
|
|
643 }
|
|
644 }
|
223
|
645 #endif
|
213
|
646
|
219
|
647 /* Returns the state of the modifier keys in the format expected by the
|
|
648 * Lisp_Event key_data, button_data and motion_data modifiers member */
|
|
649 int mswindows_modifier_state (void)
|
|
650 {
|
|
651 /* Set high bit of GetKeyState's return value indicates the key is down */
|
|
652 return ((GetKeyState (VK_SHIFT) & 0x8000) ? MOD_SHIFT : 0) |
|
|
653 ((GetKeyState (VK_CONTROL) & 0x8000) ? MOD_CONTROL: 0) |
|
|
654 ((GetKeyState (VK_MENU) & 0x8000) ? MOD_META : 0);
|
|
655 }
|
|
656
|
|
657
|
213
|
658 /*
|
|
659 * Translate a mswindows virtual key to a keysym.
|
|
660 * Only returns non-Qnil for keys that don't generate WM_CHAR messages
|
|
661 * or whose ASCII codes (like space) xemacs doesn't like.
|
|
662 * Virtual key values are defined in winresrc.h
|
|
663 * XXX I'm not sure that KEYSYM("name") is the best thing to use here.
|
|
664 */
|
219
|
665 Lisp_Object mswindows_key_to_emacs_keysym(int mswindows_key, int mods)
|
213
|
666 {
|
|
667 switch (mswindows_key)
|
|
668 {
|
|
669 /* First the predefined ones */
|
|
670 case VK_BACK: return QKbackspace;
|
|
671 case VK_TAB: return QKtab;
|
|
672 case '\n': return QKlinefeed; /* No VK_LINEFEED in winresrc.h */
|
|
673 case VK_RETURN: return QKreturn;
|
|
674 case VK_ESCAPE: return QKescape;
|
|
675 case VK_SPACE: return QKspace;
|
|
676 case VK_DELETE: return QKdelete;
|
|
677
|
|
678 /* The rest */
|
219
|
679 case VK_CLEAR: return KEYSYM ("clear"); /* Should do ^L ? */
|
213
|
680 case VK_PRIOR: return KEYSYM ("prior");
|
|
681 case VK_NEXT: return KEYSYM ("next");
|
|
682 case VK_END: return KEYSYM ("end");
|
|
683 case VK_HOME: return KEYSYM ("home");
|
|
684 case VK_LEFT: return KEYSYM ("left");
|
|
685 case VK_UP: return KEYSYM ("up");
|
|
686 case VK_RIGHT: return KEYSYM ("right");
|
|
687 case VK_DOWN: return KEYSYM ("down");
|
219
|
688 case VK_SELECT: return KEYSYM ("select");
|
|
689 case VK_PRINT: return KEYSYM ("print");
|
|
690 case VK_EXECUTE: return KEYSYM ("execute");
|
|
691 case VK_SNAPSHOT: return KEYSYM ("print");
|
213
|
692 case VK_INSERT: return KEYSYM ("insert");
|
|
693 case VK_HELP: return KEYSYM ("help");
|
219
|
694 #if 0 /* XXX What are these supposed to do? */
|
|
695 case VK_LWIN return KEYSYM ("");
|
|
696 case VK_RWIN return KEYSYM ("");
|
|
697 #endif
|
|
698 case VK_APPS: return KEYSYM ("menu");
|
221
|
699 case VK_F1: return KEYSYM ("f1");
|
|
700 case VK_F2: return KEYSYM ("f2");
|
|
701 case VK_F3: return KEYSYM ("f3");
|
|
702 case VK_F4: return KEYSYM ("f4");
|
|
703 case VK_F5: return KEYSYM ("f5");
|
|
704 case VK_F6: return KEYSYM ("f6");
|
|
705 case VK_F7: return KEYSYM ("f7");
|
|
706 case VK_F8: return KEYSYM ("f8");
|
|
707 case VK_F9: return KEYSYM ("f9");
|
|
708 case VK_F10: return KEYSYM ("f10");
|
|
709 case VK_F11: return KEYSYM ("f11");
|
|
710 case VK_F12: return KEYSYM ("f12");
|
|
711 case VK_F13: return KEYSYM ("f13");
|
|
712 case VK_F14: return KEYSYM ("f14");
|
|
713 case VK_F15: return KEYSYM ("f15");
|
|
714 case VK_F16: return KEYSYM ("f16");
|
|
715 case VK_F17: return KEYSYM ("f17");
|
|
716 case VK_F18: return KEYSYM ("f18");
|
|
717 case VK_F19: return KEYSYM ("f19");
|
|
718 case VK_F20: return KEYSYM ("f20");
|
|
719 case VK_F21: return KEYSYM ("f21");
|
|
720 case VK_F22: return KEYSYM ("f22");
|
|
721 case VK_F23: return KEYSYM ("f23");
|
|
722 case VK_F24: return KEYSYM ("f24");
|
219
|
723 default:
|
|
724 /* Special handling for Ctrl-'@' because '@' lives shifted on varying
|
|
725 * virtual keys and because Windows doesn't report Ctrl-@ as a WM_CHAR */
|
|
726 if (((mods & (MOD_SHIFT|MOD_CONTROL)) == (MOD_SHIFT|MOD_CONTROL)) &&
|
|
727 (mswindows_key == virtual_at_key))
|
|
728 return make_char('@');
|
213
|
729 }
|
|
730 return Qnil;
|
|
731 }
|
|
732
|
223
|
733 #if 0
|
213
|
734 /*
|
219
|
735 * Add a timeout to the queue. Returns the id or 0 on failure
|
|
736 */
|
|
737 static int mswindows_enqueue_timeout (int milliseconds)
|
|
738 {
|
|
739 static int timeout_last_interval_id;
|
|
740 int target_ticks = (milliseconds + MSW_TIMEOUT_GRANULARITY-1) /
|
|
741 MSW_TIMEOUT_GRANULARITY;
|
|
742 mswindows_timeout *target;
|
|
743 int i;
|
|
744
|
|
745 /* Find a free timeout */
|
|
746 for (i=0; i<MSW_TIMEOUT_MAX; i++)
|
|
747 {
|
|
748 target = timeout_pool + i;
|
|
749 if (target->interval_id == 0)
|
|
750 break;
|
|
751 }
|
|
752
|
|
753 /* No free timeout */
|
|
754 if (i==MSW_TIMEOUT_MAX)
|
|
755 return 0;
|
|
756
|
|
757 if (++timeout_last_interval_id == 0)
|
|
758 ++timeout_last_interval_id;
|
|
759
|
|
760 if (timeout_head == NULL || timeout_head->ticks >= target_ticks)
|
|
761 {
|
|
762 /* First or only timeout in the queue (common case) */
|
|
763 target->interval_id = timeout_last_interval_id;
|
|
764 target->ticks = target_ticks;
|
|
765 target->next = timeout_head;
|
|
766 timeout_head = target;
|
|
767
|
|
768 if (target->next == NULL)
|
|
769 {
|
|
770 /* Queue was empty - restart the timer */
|
|
771 timeout_mswindows_id = SetTimer (NULL, 0, MSW_TIMEOUT_GRANULARITY,
|
|
772 NULL);
|
|
773 #ifdef DEBUG_TIMEOUTS
|
|
774 stderr_out("Start\n");
|
|
775 #endif
|
|
776 }
|
|
777 else
|
|
778 target->next->ticks -= target->ticks;
|
|
779 }
|
|
780 else
|
|
781 {
|
|
782 /* Find the timeout before this new one */
|
|
783 mswindows_timeout *prev = timeout_head;
|
|
784 int tick_count = prev->ticks; /* Number of ticks up to prev */
|
|
785
|
|
786 while (prev->next != NULL)
|
|
787 {
|
|
788 if (tick_count + prev->next->ticks >= target_ticks)
|
|
789 break;
|
|
790 prev = prev->next;
|
|
791 tick_count += prev->ticks;
|
|
792 }
|
|
793
|
|
794 /* Insert the new timeout in the queue */
|
|
795 target->interval_id = timeout_last_interval_id;
|
|
796 target->ticks = target_ticks - tick_count;
|
|
797 target->next = prev->next;
|
|
798 prev->next = target;
|
|
799 if (target->next != NULL)
|
|
800 target->next->ticks -= target->ticks;
|
|
801 }
|
|
802 #ifdef DEBUG_TIMEOUTS
|
|
803 stderr_out("Set %x %d %d\n", timeout_last_interval_id, target_ticks, milliseconds);
|
|
804 #endif
|
|
805 return timeout_last_interval_id;
|
|
806 }
|
|
807
|
|
808
|
|
809 /*
|
|
810 * Remove a timeout from the queue
|
|
811 */
|
|
812 static void mswindows_dequeue_timeout (int interval_id)
|
|
813 {
|
|
814 mswindows_timeout *target;
|
|
815 mswindows_timeout *prev;
|
|
816
|
|
817 target = timeout_head;
|
|
818 prev = NULL;
|
|
819 while (target != NULL)
|
|
820 {
|
|
821 if (target->interval_id == interval_id)
|
|
822 {
|
|
823 #ifdef DEBUG_TIMEOUTS
|
|
824 stderr_out("Kil %x %d\n", interval_id, target->ticks);
|
|
825 #endif
|
|
826 target->interval_id = 0; /* Mark free */
|
|
827
|
|
828 if (prev!=NULL)
|
|
829 {
|
|
830 prev->next = target->next;
|
|
831 if (target->next != NULL)
|
|
832 target->next->ticks += target->ticks;
|
|
833 }
|
|
834 else if ((timeout_head = target->next) == NULL)
|
|
835 {
|
|
836 /* Queue is now empty - stop the timer */
|
|
837 KillTimer (NULL, timeout_mswindows_id);
|
|
838 timeout_mswindows_id = 0;
|
|
839 #ifdef DEBUG_TIMEOUTS
|
|
840 stderr_out("Stop\n");
|
|
841 #endif
|
|
842 }
|
|
843 return;
|
|
844 }
|
|
845 else
|
|
846 {
|
|
847 prev = target;
|
|
848 target = target->next;
|
|
849 }
|
|
850 }
|
|
851
|
|
852 /* Ack! the timeout wasn't in the timeout queue which means that it's
|
|
853 * probably gone off and is now sitting in the dispatch queue. XEmacs will
|
|
854 * be very unhappy if it sees the timeout so we have to fish it out of the
|
|
855 * dispatch queue. This only happens if XEmacs can't keep up with events */
|
|
856 #ifdef DEBUG_TIMEOUTS
|
|
857 stderr_out("Kil %x - not found\n", interval_id);
|
|
858 #endif
|
|
859 {
|
|
860 Lisp_Object match_event, emacs_event;
|
|
861 struct Lisp_Event *event;
|
|
862 match_event = Fmake_event (Qnil, Qnil);
|
|
863 event = XEVENT(match_event);
|
|
864
|
|
865 event->channel = Qnil;
|
|
866 event->event_type = timeout_event;
|
|
867 event->event.timeout.interval_id = interval_id;
|
|
868 emacs_event = mswindows_cancel_dispatch_event (match_event);
|
|
869 if (!NILP (emacs_event))
|
|
870 Fdeallocate_event(emacs_event);
|
|
871 Fdeallocate_event(match_event);
|
|
872 }
|
|
873 }
|
223
|
874 #endif
|
219
|
875
|
|
876 /*
|
213
|
877 * Find the console that matches the supplied mswindows window handle
|
|
878 */
|
223
|
879 Lisp_Object
|
213
|
880 mswindows_find_console (HWND hwnd)
|
|
881 {
|
|
882 Lisp_Object concons;
|
|
883
|
|
884 CONSOLE_LOOP (concons)
|
|
885 {
|
|
886 Lisp_Object console = XCAR (concons);
|
|
887 /* We only support one console so this must be it */
|
|
888 return console;
|
|
889 }
|
|
890
|
|
891 return Qnil;
|
|
892 }
|
|
893
|
|
894 /*
|
|
895 * Find the frame that matches the supplied mswindows window handle
|
|
896 */
|
|
897 static Lisp_Object
|
|
898 mswindows_find_frame (HWND hwnd)
|
|
899 {
|
223
|
900 return (Lisp_Object) GetWindowLong (hwnd, XWL_FRAMEOBJ);
|
213
|
901 }
|
|
902
|
219
|
903
|
|
904 #ifdef DEBUG_XEMACS
|
213
|
905 /*
|
|
906 * Random helper functions for debugging.
|
|
907 * Intended for use in the MSVC "Watch" window which doesn't like
|
|
908 * the aborts that the error_check_foo() functions can make.
|
|
909 */
|
|
910 struct lrecord_header *DHEADER(Lisp_Object obj)
|
|
911 {
|
219
|
912 return (LRECORDP (obj)) ? XRECORD_LHEADER (obj) : NULL;
|
|
913 }
|
|
914
|
|
915 int DOPAQUE_DATA (Lisp_Object obj)
|
|
916 {
|
|
917 return (OPAQUEP (obj)) ? OPAQUE_DATA (XOPAQUE (obj)) : NULL;
|
213
|
918 }
|
|
919
|
|
920 struct Lisp_Event *DEVENT(Lisp_Object obj)
|
|
921 {
|
219
|
922 return (EVENTP (obj)) ? XEVENT (obj) : NULL;
|
213
|
923 }
|
|
924
|
|
925 struct Lisp_Cons *DCONS(Lisp_Object obj)
|
|
926 {
|
219
|
927 return (CONSP (obj)) ? XCONS (obj) : NULL;
|
213
|
928 }
|
|
929
|
|
930 Lisp_Object DCAR(Lisp_Object obj)
|
|
931 {
|
219
|
932 return (CONSP (obj)) ? XCAR (obj) : 0;
|
213
|
933 }
|
|
934
|
|
935 Lisp_Object DCDR(Lisp_Object obj)
|
|
936 {
|
219
|
937 return (CONSP (obj)) ? XCDR (obj) : 0;
|
|
938 }
|
|
939
|
|
940 Lisp_Object DCONSCDR(Lisp_Object obj)
|
|
941 {
|
|
942 return ((CONSP (obj)) && (CONSP (XCDR (obj)))) ? XCONS (XCDR (obj)) : 0;
|
|
943 }
|
|
944
|
|
945 Lisp_Object DCARCDR(Lisp_Object obj)
|
|
946 {
|
|
947 return ((CONSP (obj)) && (CONSP (XCDR (obj)))) ? XCAR (XCDR (obj)) : 0;
|
213
|
948 }
|
|
949
|
|
950 char *DSTRING(Lisp_Object obj)
|
|
951 {
|
219
|
952 return (STRINGP (obj)) ? XSTRING_DATA (obj) : NULL;
|
213
|
953 }
|
|
954
|
|
955 struct Lisp_Vector *DVECTOR(Lisp_Object obj)
|
|
956 {
|
219
|
957 return (VECTORP (obj)) ? XVECTOR (obj) : NULL;
|
213
|
958 }
|
|
959
|
|
960 struct Lisp_Symbol *DSYMBOL(Lisp_Object obj)
|
|
961 {
|
219
|
962 return (SYMBOLP (obj)) ? XSYMBOL (obj) : NULL;
|
213
|
963 }
|
|
964
|
|
965 char *DSYMNAME(Lisp_Object obj)
|
|
966 {
|
219
|
967 return (SYMBOLP (obj)) ? XSYMBOL (obj)->name->_data : NULL;
|
213
|
968 }
|
219
|
969
|
|
970 #endif
|