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"
|
225
|
36 #include "redisplay.h"
|
213
|
37
|
219
|
38 #ifdef DEBUG_XEMACS
|
|
39 # include "opaque.h" /* For the debug functions at the end of this file */
|
|
40 # undef DEBUG_MESSAGES
|
|
41 # undef DEBUG_TIMEOUTS
|
|
42 #endif
|
|
43
|
223
|
44 #ifdef HAVE_MENUBARS
|
|
45 #define ADJR_MENUFLAG TRUE
|
|
46 #else
|
|
47 #define ADJR_MENUFLAG FALSE
|
|
48 #endif
|
213
|
49
|
223
|
50 /* Timer ID used for button2 emulation */
|
|
51 #define BUTTON_2_TIMER_ID 1
|
|
52
|
213
|
53 static Lisp_Object mswindows_find_frame (HWND hwnd);
|
219
|
54 static Lisp_Object mswindows_key_to_emacs_keysym(int mswindows_key, int mods);
|
225
|
55 static int mswindows_modifier_state (BYTE* keymap, int has_AltGr);
|
219
|
56 static int mswindows_enqueue_timeout (int milliseconds);
|
|
57 static void mswindows_dequeue_timeout (int interval_id);
|
|
58
|
|
59 /* Timeout queue */
|
|
60 struct mswindows_timeout
|
|
61 {
|
|
62 int ticks;
|
|
63 int interval_id;
|
|
64 struct mswindows_timeout *next;
|
|
65 };
|
|
66 typedef struct mswindows_timeout mswindows_timeout;
|
|
67 static mswindows_timeout timeout_pool[MSW_TIMEOUT_MAX];
|
|
68 static mswindows_timeout *timeout_head = NULL;
|
|
69 static int timeout_mswindows_id;
|
213
|
70
|
225
|
71 /*----------------------------------------------------------------------------*/
|
|
72 /* Enqueue helpers */
|
|
73 /*----------------------------------------------------------------------------*/
|
223
|
74
|
|
75 static void
|
|
76 mswindows_enqueue_magic_event (HWND hwnd, UINT message)
|
|
77 {
|
|
78 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
79 struct Lisp_Event* event = XEVENT (emacs_event);
|
|
80
|
|
81 event->channel = mswindows_find_frame (hwnd);
|
|
82 event->timestamp = GetMessageTime();
|
|
83 event->event_type = magic_event;
|
|
84 EVENT_MSWINDOWS_MAGIC_TYPE (event) = message;
|
|
85
|
|
86 mswindows_enqueue_dispatch_event (emacs_event);
|
|
87 }
|
|
88
|
|
89 static void
|
|
90 mswindows_enqueue_mouse_button_event (HWND hwnd, UINT message, POINTS where, DWORD when)
|
|
91 {
|
|
92
|
|
93 /* We always use last message time, because mouse button
|
|
94 events may get delayed, and XEmacs double click
|
|
95 recognition will fail */
|
|
96
|
|
97 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
98 struct Lisp_Event* event = XEVENT(emacs_event);
|
|
99
|
|
100 event->channel = mswindows_find_frame(hwnd);
|
|
101 event->timestamp = when;
|
|
102 event->event.button.button =
|
|
103 (message==WM_LBUTTONDOWN || message==WM_LBUTTONUP) ? 1 :
|
|
104 ((message==WM_RBUTTONDOWN || message==WM_RBUTTONUP) ? 3 : 2);
|
|
105 event->event.button.x = where.x;
|
|
106 event->event.button.y = where.y;
|
225
|
107 event->event.button.modifiers = mswindows_modifier_state (NULL, 0);
|
223
|
108
|
|
109 if (message==WM_LBUTTONDOWN || message==WM_MBUTTONDOWN ||
|
|
110 message==WM_RBUTTONDOWN)
|
|
111 {
|
|
112 event->event_type = button_press_event;
|
|
113 SetCapture (hwnd);
|
|
114 }
|
|
115 else
|
|
116 {
|
|
117 event->event_type = button_release_event;
|
|
118 ReleaseCapture ();
|
|
119 }
|
|
120
|
|
121 mswindows_enqueue_dispatch_event (emacs_event);
|
|
122 }
|
|
123
|
|
124 static void
|
225
|
125 mswindows_enqueue_keypress_event (HWND hwnd, Lisp_Object keysym, int mods)
|
|
126 {
|
|
127 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
128 struct Lisp_Event* event = XEVENT(emacs_event);
|
|
129
|
|
130 event->channel = mswindows_find_console(hwnd);
|
|
131 event->timestamp = GetMessageTime();
|
|
132 event->event_type = key_press_event;
|
|
133 event->event.key.keysym = keysym;
|
|
134 event->event.key.modifiers = mods;
|
|
135 mswindows_enqueue_dispatch_event (emacs_event);
|
|
136 }
|
|
137
|
|
138 static void
|
223
|
139 mswindows_set_chord_timer (HWND hwnd)
|
|
140 {
|
|
141 int interval;
|
|
142
|
|
143 /* We get half system threshold as it seems to
|
|
144 long before drag-selection is shown */
|
|
145 if (mswindows_button2_chord_time <= 0)
|
|
146 interval = GetDoubleClickTime () / 2;
|
|
147 else
|
|
148 interval = mswindows_button2_chord_time;
|
|
149
|
|
150 SetTimer (hwnd, BUTTON_2_TIMER_ID, interval, 0);
|
|
151 }
|
|
152
|
|
153 static int
|
|
154 mswindows_button2_near_enough (POINTS p1, POINTS p2)
|
|
155 {
|
|
156 int dx, dy;
|
|
157 if (mswindows_button2_max_skew_x <= 0)
|
|
158 dx = GetSystemMetrics (SM_CXDOUBLECLK) / 2;
|
|
159 else
|
|
160 dx = mswindows_button2_max_skew_x;
|
|
161
|
|
162 if (mswindows_button2_max_skew_y <= 0)
|
|
163 dy = GetSystemMetrics (SM_CYDOUBLECLK) / 2;
|
|
164 else
|
|
165 dy = mswindows_button2_max_skew_y;
|
|
166
|
|
167 return abs (p1.x - p2.x) < dx && abs (p1.y- p2.y)< dy;
|
|
168 }
|
213
|
169
|
225
|
170 static int
|
|
171 mswindows_current_layout_has_AltGr ()
|
|
172 {
|
|
173 /* This simple caching mechanism saves 10% of CPU
|
|
174 time when a key typed at autorepeat rate of 30 cps! */
|
|
175 static HKL last_hkl = 0;
|
|
176 static int last_hkl_has_AltGr;
|
|
177
|
|
178 HKL current_hkl = GetKeyboardLayout (0);
|
|
179 if (current_hkl != last_hkl)
|
|
180 {
|
|
181 int c;
|
|
182 last_hkl_has_AltGr = 0;
|
|
183 /* In this loop, we query whether a character requires
|
|
184 AltGr to be down to generate it. If at least such one
|
|
185 found, this means that the layout does regard AltGr */
|
|
186 for (c = ' '; c <= 0xFF && !last_hkl_has_AltGr; ++c)
|
|
187 if (HIBYTE (VkKeyScan (c)) == 6)
|
|
188 last_hkl_has_AltGr = 1;
|
|
189 last_hkl = current_hkl;
|
|
190 }
|
|
191 return last_hkl_has_AltGr;
|
|
192 }
|
|
193
|
213
|
194 /*
|
|
195 * The windows procedure for the window class XEMACS_CLASS
|
|
196 * Stuffs messages in the mswindows event queue
|
|
197 */
|
223
|
198 LRESULT WINAPI
|
|
199 mswindows_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
213
|
200 {
|
|
201 /* Note: Remember to initialise these before use */
|
|
202 Lisp_Object emacs_event;
|
|
203 struct Lisp_Event *event;
|
223
|
204 Lisp_Object fobj;
|
|
205 struct frame *frame;
|
|
206 struct mswindows_frame* msframe;
|
|
207
|
213
|
208 switch (message)
|
|
209 {
|
223
|
210 case WM_ERASEBKGND:
|
|
211 /* Erase background only during non-dynamic sizing */
|
|
212 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
213 if (msframe->sizing && !mswindows_dynamic_frame_resize)
|
|
214 goto defproc;
|
|
215 return 1;
|
|
216
|
|
217 case WM_CLOSE:
|
|
218 fobj = mswindows_find_frame (hwnd);
|
|
219 enqueue_misc_user_event (fobj, Qeval, list3 (Qdelete_frame, fobj, Qt));
|
|
220 mswindows_enqueue_magic_event (hwnd, XM_BUMPQUEUE);
|
|
221 break;
|
|
222
|
213
|
223 case WM_KEYDOWN:
|
|
224 case WM_SYSKEYDOWN:
|
|
225 {
|
225
|
226 BYTE keymap[256];
|
|
227 int has_AltGr = mswindows_current_layout_has_AltGr ();
|
|
228 int mods, ch;
|
219
|
229 Lisp_Object keysym;
|
225
|
230
|
|
231 GetKeyboardState (keymap);
|
|
232 mods = mswindows_modifier_state (keymap, has_AltGr);
|
219
|
233
|
225
|
234 /* Handle those keys that TranslateMessage won't generate a WM_CHAR for */
|
219
|
235 if (!NILP (keysym = mswindows_key_to_emacs_keysym(wParam, mods)))
|
225
|
236 mswindows_enqueue_keypress_event (hwnd, keysym, mods);
|
|
237 else
|
213
|
238 {
|
225
|
239 int ch;
|
|
240 int quit_ch = CONSOLE_QUIT_CHAR (XCONSOLE (mswindows_find_console (hwnd)));
|
|
241 BYTE keymap_orig[256];
|
|
242 MSG msg = { hwnd, message, wParam, lParam, GetMessageTime(), GetMessagePos() };
|
|
243 memcpy (keymap_orig, keymap, 256);
|
|
244
|
|
245 /* Clear control and alt modifiers out of the keymap */
|
|
246 keymap [VK_RCONTROL] = 0;
|
|
247 keymap [VK_LMENU] = 0;
|
|
248 if (!has_AltGr || !(keymap [VK_LCONTROL] & 0x80) || !(keymap [VK_RMENU] & 0x80)) {
|
|
249 keymap [VK_LCONTROL] = 0;
|
|
250 keymap [VK_CONTROL] = 0;
|
|
251 keymap [VK_RMENU] = 0;
|
|
252 keymap [VK_MENU] = 0;
|
|
253 }
|
|
254 SetKeyboardState (keymap);
|
|
255
|
|
256 /* Have some WM_[SYS]CHARS in the queue */
|
|
257 TranslateMessage (&msg);
|
213
|
258
|
225
|
259 while (PeekMessage (&msg, hwnd, WM_CHAR, WM_CHAR, PM_REMOVE)
|
|
260 ||PeekMessage (&msg, hwnd, WM_SYSCHAR, WM_SYSCHAR, PM_REMOVE))
|
|
261 {
|
|
262 ch = msg.wParam;
|
|
263 /* CH is a character code for the key:
|
|
264 'C' for Shift+C and Ctrl+Shift+C
|
|
265 'c' for c and Ctrl+c */
|
|
266
|
|
267 /* #### If locale is not C, US or other latin-1,
|
|
268 isalpha() maybe not what do we mean */
|
|
269
|
|
270 /* XEmacs doesn't seem to like Shift on non-alpha keys */
|
|
271 if (!isalpha(ch))
|
|
272 mods &= ~MOD_SHIFT;
|
|
273
|
|
274 /* Un-capitalise alpha control keys */
|
|
275 if ((mods & MOD_CONTROL) && isalpha(ch))
|
|
276 ch |= ('A' ^ 'a');
|
|
277
|
|
278 /* If a quit char with no modifiers other than control and
|
|
279 shift, then mark it with a fake modifier, which is removed
|
|
280 upon dequeueing the event */
|
|
281 /* #### This might also not withstand localization, if
|
|
282 quit character is not a latin-1 symbol */
|
|
283 if (((quit_ch < ' ' && (mods & MOD_CONTROL) && quit_ch + 'a' - 1 == ch)
|
|
284 || (quit_ch >= ' ' && !(mods & MOD_CONTROL) && quit_ch == ch))
|
|
285 && ((mods & ~(MOD_CONTROL | MOD_SHIFT)) == 0))
|
|
286 {
|
|
287 mods |= FAKE_MOD_QUIT;
|
|
288 ++mswindows_quit_chars_count;
|
|
289 }
|
|
290
|
|
291 mswindows_enqueue_keypress_event (hwnd, make_char(ch), mods);
|
|
292 } /* while */
|
|
293 SetKeyboardState (keymap_orig);
|
|
294 } /* else */
|
213
|
295 }
|
|
296 goto defproc;
|
|
297
|
223
|
298 case WM_MBUTTONDOWN:
|
|
299 case WM_MBUTTONUP:
|
|
300 /* Real middle mouse button has nothing to do with emulated one:
|
|
301 if one wants to exercise fingers playing chords on the mouse,
|
|
302 he is allowed to do that! */
|
|
303 mswindows_enqueue_mouse_button_event (hwnd, message,
|
|
304 MAKEPOINTS (lParam), GetMessageTime());
|
|
305 break;
|
|
306
|
|
307 case WM_LBUTTONUP:
|
|
308 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
309 msframe->last_click_time = GetMessageTime();
|
|
310
|
|
311 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
312 msframe->button2_need_lbutton = 0;
|
|
313 if (msframe->ignore_next_lbutton_up)
|
|
314 {
|
|
315 msframe->ignore_next_lbutton_up = 0;
|
|
316 }
|
|
317 else if (msframe->button2_is_down)
|
|
318 {
|
|
319 msframe->button2_is_down = 0;
|
|
320 msframe->ignore_next_rbutton_up = 1;
|
|
321 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
|
|
322 MAKEPOINTS (lParam), GetMessageTime());
|
|
323 }
|
|
324 else
|
|
325 {
|
|
326 if (msframe->button2_need_rbutton)
|
|
327 {
|
|
328 msframe->button2_need_rbutton = 0;
|
|
329 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
330 MAKEPOINTS (lParam), GetMessageTime());
|
|
331 }
|
|
332 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONUP,
|
|
333 MAKEPOINTS (lParam), GetMessageTime());
|
|
334 }
|
|
335 break;
|
|
336
|
|
337 case WM_RBUTTONUP:
|
|
338 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
339 msframe->last_click_time = GetMessageTime();
|
|
340
|
|
341 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
342 msframe->button2_need_rbutton = 0;
|
|
343 if (msframe->ignore_next_rbutton_up)
|
|
344 {
|
|
345 msframe->ignore_next_rbutton_up = 0;
|
|
346 }
|
|
347 else if (msframe->button2_is_down)
|
|
348 {
|
|
349 msframe->button2_is_down = 0;
|
|
350 msframe->ignore_next_lbutton_up = 1;
|
|
351 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
|
|
352 MAKEPOINTS (lParam), GetMessageTime());
|
|
353 }
|
|
354 else
|
|
355 {
|
|
356 if (msframe->button2_need_lbutton)
|
|
357 {
|
|
358 msframe->button2_need_lbutton = 0;
|
|
359 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
360 MAKEPOINTS (lParam), GetMessageTime());
|
|
361 }
|
|
362 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONUP,
|
|
363 MAKEPOINTS (lParam), GetMessageTime());
|
|
364 }
|
|
365 break;
|
|
366
|
213
|
367 case WM_LBUTTONDOWN:
|
223
|
368 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
369
|
|
370 if (msframe->button2_need_lbutton)
|
|
371 {
|
|
372 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
373 msframe->button2_need_lbutton = 0;
|
|
374 msframe->button2_need_rbutton = 0;
|
|
375 if (mswindows_button2_near_enough (msframe->last_click_point, MAKEPOINTS (lParam)))
|
225
|
376 {
|
|
377 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
|
|
378 MAKEPOINTS (lParam), GetMessageTime());
|
|
379 msframe->button2_is_down = 1;
|
|
380 }
|
223
|
381 else
|
|
382 {
|
|
383 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
384 msframe->last_click_point, msframe->last_click_time);
|
|
385 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
386 MAKEPOINTS (lParam), GetMessageTime());
|
|
387 }
|
|
388 }
|
|
389 else
|
|
390 {
|
|
391 mswindows_set_chord_timer (hwnd);
|
|
392 msframe->button2_need_rbutton = 1;
|
|
393 msframe->last_click_point = MAKEPOINTS (lParam);
|
|
394 }
|
|
395 msframe->last_click_time = GetMessageTime();
|
|
396 break;
|
|
397
|
213
|
398 case WM_RBUTTONDOWN:
|
223
|
399 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
400
|
|
401 if (msframe->button2_need_rbutton)
|
|
402 {
|
|
403 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
404 msframe->button2_need_lbutton = 0;
|
|
405 msframe->button2_need_rbutton = 0;
|
|
406 if (mswindows_button2_near_enough (msframe->last_click_point, MAKEPOINTS (lParam)))
|
225
|
407 {
|
|
408 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
|
|
409 MAKEPOINTS (lParam), GetMessageTime());
|
|
410 msframe->button2_is_down = 1;
|
|
411 }
|
223
|
412 else
|
|
413 {
|
|
414 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
415 msframe->last_click_point, msframe->last_click_time);
|
|
416 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
417 MAKEPOINTS (lParam), GetMessageTime());
|
|
418 }
|
|
419 }
|
|
420 else
|
|
421 {
|
|
422 mswindows_set_chord_timer (hwnd);
|
|
423 msframe->button2_need_lbutton = 1;
|
|
424 msframe->last_click_point = MAKEPOINTS (lParam);
|
|
425 }
|
|
426 msframe->last_click_time = GetMessageTime();
|
|
427 break;
|
|
428
|
|
429 case WM_TIMER:
|
|
430 if (wParam == BUTTON_2_TIMER_ID)
|
|
431 {
|
|
432 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
433 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
434
|
|
435 if (msframe->button2_need_lbutton)
|
|
436 {
|
|
437 msframe->button2_need_lbutton = 0;
|
|
438 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
439 msframe->last_click_point, msframe->last_click_time);
|
|
440 }
|
|
441 else if (msframe->button2_need_rbutton)
|
|
442 {
|
|
443 msframe->button2_need_rbutton = 0;
|
|
444 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
445 msframe->last_click_point, msframe->last_click_time);
|
|
446 }
|
|
447 }
|
|
448 else
|
|
449 assert ("Spurious timer fired" == 0);
|
|
450 break;
|
|
451
|
|
452 case WM_MOUSEMOVE:
|
|
453 /* Optimization: don't report mouse movement while size is changind */
|
|
454 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
455 if (!msframe->sizing)
|
213
|
456 {
|
223
|
457 /* When waiting for the second mouse button to finish
|
|
458 button2 emulation, and have moved too far, just pretend
|
|
459 as if timer has expired. This impoves drag-select feedback */
|
|
460 if ((msframe->button2_need_lbutton || msframe->button2_need_rbutton)
|
|
461 && !mswindows_button2_near_enough (msframe->last_click_point,
|
|
462 MAKEPOINTS (lParam)))
|
|
463 {
|
|
464 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
465 SendMessage (hwnd, WM_TIMER, BUTTON_2_TIMER_ID, 0);
|
|
466 }
|
219
|
467
|
213
|
468 emacs_event = Fmake_event (Qnil, Qnil);
|
|
469 event = XEVENT(emacs_event);
|
|
470
|
|
471 event->channel = mswindows_find_frame(hwnd);
|
223
|
472 event->timestamp = GetMessageTime();
|
213
|
473 event->event_type = pointer_motion_event;
|
223
|
474 event->event.motion.x = MAKEPOINTS(lParam).x;
|
|
475 event->event.motion.y = MAKEPOINTS(lParam).y;
|
225
|
476 event->event.motion.modifiers = mswindows_modifier_state (NULL, 0);
|
213
|
477
|
|
478 mswindows_enqueue_dispatch_event (emacs_event);
|
|
479 }
|
|
480 break;
|
|
481
|
|
482 case WM_PAINT:
|
|
483 {
|
|
484 PAINTSTRUCT paintStruct;
|
223
|
485
|
|
486 frame = XFRAME (mswindows_find_frame (hwnd));
|
213
|
487
|
|
488 BeginPaint (hwnd, &paintStruct);
|
223
|
489 mswindows_redraw_exposed_area (frame,
|
|
490 paintStruct.rcPaint.left, paintStruct.rcPaint.top,
|
|
491 paintStruct.rcPaint.right, paintStruct.rcPaint.bottom);
|
213
|
492 EndPaint (hwnd, &paintStruct);
|
|
493 }
|
|
494 break;
|
|
495
|
|
496 case WM_SIZE:
|
|
497 /* We only care about this message if our size has really changed */
|
|
498 if (wParam==SIZE_RESTORED || wParam==SIZE_MAXIMIZED || wParam==SIZE_MINIMIZED)
|
|
499 {
|
|
500 RECT rect;
|
223
|
501 int columns, rows;
|
213
|
502
|
223
|
503 fobj = mswindows_find_frame (hwnd);
|
|
504 frame = XFRAME (fobj);
|
|
505 msframe = FRAME_MSWINDOWS_DATA (frame);
|
|
506
|
|
507 /* We cannot handle frame map and unmap hooks right in
|
|
508 this routine, because these may throw. We queue
|
|
509 magic events to run these hooks instead - kkm */
|
|
510
|
213
|
511 if (wParam==SIZE_MINIMIZED)
|
223
|
512 {
|
|
513 /* Iconified */
|
|
514 FRAME_VISIBLE_P (frame) = 0;
|
|
515 mswindows_enqueue_magic_event (hwnd, XM_UNMAPFRAME);
|
|
516 Fframe_iconified_p (fobj);
|
|
517 }
|
213
|
518 else
|
223
|
519 {
|
|
520 int was_visible = FRAME_VISIBLE_P (frame);
|
|
521 if (!msframe->sizing && !was_visible)
|
|
522 mswindows_enqueue_magic_event (hwnd, XM_MAPFRAME);
|
|
523
|
|
524 GetClientRect(hwnd, &rect);
|
|
525 FRAME_VISIBLE_P(frame) = 1;
|
|
526 FRAME_PIXWIDTH(frame) = rect.right;
|
|
527 FRAME_PIXHEIGHT(frame) = rect.bottom;
|
|
528 pixel_to_char_size (frame, rect.right, rect.bottom, &columns, &rows);
|
|
529 change_frame_size (frame, rows, columns, 1);
|
213
|
530
|
223
|
531 if (mswindows_dynamic_frame_resize)
|
|
532 redisplay ();
|
|
533 }
|
213
|
534 }
|
|
535 break;
|
|
536
|
219
|
537 /* Misc magic events which only require that the frame be identified */
|
213
|
538 case WM_SETFOCUS:
|
|
539 case WM_KILLFOCUS:
|
223
|
540 mswindows_enqueue_magic_event (hwnd, message);
|
213
|
541 break;
|
|
542
|
219
|
543 case WM_WINDOWPOSCHANGING:
|
|
544 {
|
|
545 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
|
|
546 WINDOWPLACEMENT wpl = { sizeof(WINDOWPLACEMENT) };
|
|
547 GetWindowPlacement(hwnd, &wpl);
|
|
548
|
|
549 /* Only interested if size is changing and we're not being iconified */
|
|
550 if ((wpl.showCmd != SW_SHOWMINIMIZED) && !(wp->flags & SWP_NOSIZE))
|
|
551 {
|
|
552 RECT ncsize = { 0, 0, 0, 0 };
|
|
553 int pixwidth, pixheight;
|
223
|
554 AdjustWindowRectEx (&ncsize, GetWindowLong (hwnd, GWL_STYLE),
|
|
555 GetMenu(hwnd) != NULL,
|
|
556 GetWindowLong (hwnd, GWL_EXSTYLE));
|
219
|
557
|
|
558 round_size_to_char (XFRAME (mswindows_find_frame (hwnd)),
|
|
559 wp->cx - (ncsize.right - ncsize.left),
|
|
560 wp->cy - (ncsize.bottom - ncsize.top),
|
|
561 &pixwidth, &pixheight);
|
|
562
|
|
563 /* Convert client sizes to window sizes */
|
|
564 pixwidth += (ncsize.right - ncsize.left);
|
|
565 pixheight += (ncsize.bottom - ncsize.top);
|
|
566
|
|
567 if (wpl.showCmd != SW_SHOWMAXIMIZED)
|
|
568 {
|
|
569 /* Adjust so that the bottom or right doesn't move if it's
|
|
570 * the top or left that's being changed */
|
|
571 RECT rect;
|
|
572 GetWindowRect (hwnd, &rect);
|
|
573
|
|
574 if (rect.left != wp->x)
|
|
575 wp->x += wp->cx - pixwidth;
|
|
576 if (rect.top != wp->y)
|
|
577 wp->y += wp->cy - pixheight;
|
|
578 }
|
|
579
|
|
580 wp->cx = pixwidth;
|
|
581 wp->cy = pixheight;
|
|
582 }
|
|
583 }
|
|
584 break;
|
|
585
|
221
|
586 case WM_ENTERSIZEMOVE:
|
223
|
587 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
588 msframe->sizing = 1;
|
|
589 return 0;
|
|
590
|
221
|
591 case WM_EXITSIZEMOVE:
|
223
|
592 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
593 msframe->sizing = 0;
|
|
594 /* Queue noop event */
|
|
595 mswindows_enqueue_magic_event (hwnd, XM_BUMPQUEUE);
|
|
596 return 0;
|
221
|
597
|
225
|
598 case WM_VSCROLL:
|
|
599 case WM_HSCROLL:
|
|
600 {
|
|
601 /* Direction of scroll is determined by scrollbar instance. */
|
|
602 int code = (int) LOWORD(wParam);
|
|
603 int pos = (short int) HIWORD(wParam);
|
|
604 HWND hwndScrollBar = (HWND) lParam;
|
|
605 mswindows_handle_scrollbar_event (hwndScrollBar, code, pos);
|
227
|
606
|
|
607 if (NILP(mswindows_pump_outstanding_events()))
|
|
608 {
|
|
609 /* Error during event pumping - cancel scroll */
|
|
610 SendMessage (hwndScrollBar, WM_CANCELMODE, 0, 0);
|
|
611 }
|
|
612
|
225
|
613 break;
|
|
614 }
|
|
615
|
213
|
616 defproc:
|
|
617 default:
|
|
618 return DefWindowProc (hwnd, message, wParam, lParam);
|
|
619 }
|
|
620 return (0);
|
|
621 }
|
|
622
|
219
|
623 /* Returns the state of the modifier keys in the format expected by the
|
|
624 * Lisp_Event key_data, button_data and motion_data modifiers member */
|
225
|
625 int mswindows_modifier_state (BYTE* keymap, int has_AltGr)
|
219
|
626 {
|
225
|
627 int mods = 0;
|
|
628
|
|
629 if (keymap == NULL)
|
|
630 {
|
|
631 keymap = (BYTE*) alloca(256);
|
|
632 GetKeyboardState (keymap);
|
|
633 has_AltGr = mswindows_current_layout_has_AltGr ();
|
|
634 }
|
|
635
|
|
636 if (has_AltGr && (keymap [VK_LCONTROL] & 0x80) && (keymap [VK_RMENU] & 0x80))
|
|
637 {
|
|
638 mods |= (keymap [VK_LMENU] & 0x80) ? MOD_META : 0;
|
|
639 mods |= (keymap [VK_RCONTROL] & 0x80) ? MOD_CONTROL : 0;
|
|
640 }
|
|
641 else
|
|
642 {
|
|
643 mods |= (keymap [VK_MENU] & 0x80) ? MOD_META : 0;
|
|
644 mods |= (keymap [VK_CONTROL] & 0x80) ? MOD_CONTROL : 0;
|
|
645 }
|
|
646
|
|
647 mods |= (keymap [VK_SHIFT] & 0x80) ? MOD_SHIFT : 0;
|
|
648
|
|
649 return mods;
|
219
|
650 }
|
|
651
|
213
|
652 /*
|
|
653 * Translate a mswindows virtual key to a keysym.
|
|
654 * Only returns non-Qnil for keys that don't generate WM_CHAR messages
|
|
655 * or whose ASCII codes (like space) xemacs doesn't like.
|
|
656 * Virtual key values are defined in winresrc.h
|
|
657 * XXX I'm not sure that KEYSYM("name") is the best thing to use here.
|
|
658 */
|
219
|
659 Lisp_Object mswindows_key_to_emacs_keysym(int mswindows_key, int mods)
|
213
|
660 {
|
|
661 switch (mswindows_key)
|
|
662 {
|
|
663 /* First the predefined ones */
|
|
664 case VK_BACK: return QKbackspace;
|
|
665 case VK_TAB: return QKtab;
|
|
666 case '\n': return QKlinefeed; /* No VK_LINEFEED in winresrc.h */
|
|
667 case VK_RETURN: return QKreturn;
|
|
668 case VK_ESCAPE: return QKescape;
|
|
669 case VK_SPACE: return QKspace;
|
|
670 case VK_DELETE: return QKdelete;
|
|
671
|
|
672 /* The rest */
|
219
|
673 case VK_CLEAR: return KEYSYM ("clear"); /* Should do ^L ? */
|
213
|
674 case VK_PRIOR: return KEYSYM ("prior");
|
|
675 case VK_NEXT: return KEYSYM ("next");
|
|
676 case VK_END: return KEYSYM ("end");
|
|
677 case VK_HOME: return KEYSYM ("home");
|
|
678 case VK_LEFT: return KEYSYM ("left");
|
|
679 case VK_UP: return KEYSYM ("up");
|
|
680 case VK_RIGHT: return KEYSYM ("right");
|
|
681 case VK_DOWN: return KEYSYM ("down");
|
219
|
682 case VK_SELECT: return KEYSYM ("select");
|
|
683 case VK_PRINT: return KEYSYM ("print");
|
|
684 case VK_EXECUTE: return KEYSYM ("execute");
|
|
685 case VK_SNAPSHOT: return KEYSYM ("print");
|
213
|
686 case VK_INSERT: return KEYSYM ("insert");
|
|
687 case VK_HELP: return KEYSYM ("help");
|
219
|
688 #if 0 /* XXX What are these supposed to do? */
|
|
689 case VK_LWIN return KEYSYM ("");
|
|
690 case VK_RWIN return KEYSYM ("");
|
|
691 #endif
|
|
692 case VK_APPS: return KEYSYM ("menu");
|
221
|
693 case VK_F1: return KEYSYM ("f1");
|
|
694 case VK_F2: return KEYSYM ("f2");
|
|
695 case VK_F3: return KEYSYM ("f3");
|
|
696 case VK_F4: return KEYSYM ("f4");
|
|
697 case VK_F5: return KEYSYM ("f5");
|
|
698 case VK_F6: return KEYSYM ("f6");
|
|
699 case VK_F7: return KEYSYM ("f7");
|
|
700 case VK_F8: return KEYSYM ("f8");
|
|
701 case VK_F9: return KEYSYM ("f9");
|
|
702 case VK_F10: return KEYSYM ("f10");
|
|
703 case VK_F11: return KEYSYM ("f11");
|
|
704 case VK_F12: return KEYSYM ("f12");
|
|
705 case VK_F13: return KEYSYM ("f13");
|
|
706 case VK_F14: return KEYSYM ("f14");
|
|
707 case VK_F15: return KEYSYM ("f15");
|
|
708 case VK_F16: return KEYSYM ("f16");
|
|
709 case VK_F17: return KEYSYM ("f17");
|
|
710 case VK_F18: return KEYSYM ("f18");
|
|
711 case VK_F19: return KEYSYM ("f19");
|
|
712 case VK_F20: return KEYSYM ("f20");
|
|
713 case VK_F21: return KEYSYM ("f21");
|
|
714 case VK_F22: return KEYSYM ("f22");
|
|
715 case VK_F23: return KEYSYM ("f23");
|
|
716 case VK_F24: return KEYSYM ("f24");
|
213
|
717 }
|
|
718 return Qnil;
|
|
719 }
|
|
720
|
219
|
721 /*
|
213
|
722 * Find the console that matches the supplied mswindows window handle
|
|
723 */
|
223
|
724 Lisp_Object
|
213
|
725 mswindows_find_console (HWND hwnd)
|
|
726 {
|
|
727 Lisp_Object concons;
|
|
728
|
|
729 CONSOLE_LOOP (concons)
|
|
730 {
|
|
731 Lisp_Object console = XCAR (concons);
|
|
732 /* We only support one console so this must be it */
|
|
733 return console;
|
|
734 }
|
|
735
|
|
736 return Qnil;
|
|
737 }
|
|
738
|
|
739 /*
|
|
740 * Find the frame that matches the supplied mswindows window handle
|
|
741 */
|
|
742 static Lisp_Object
|
|
743 mswindows_find_frame (HWND hwnd)
|
|
744 {
|
223
|
745 return (Lisp_Object) GetWindowLong (hwnd, XWL_FRAMEOBJ);
|
213
|
746 }
|
|
747
|
219
|
748
|
|
749 #ifdef DEBUG_XEMACS
|
213
|
750 /*
|
|
751 * Random helper functions for debugging.
|
|
752 * Intended for use in the MSVC "Watch" window which doesn't like
|
|
753 * the aborts that the error_check_foo() functions can make.
|
|
754 */
|
|
755 struct lrecord_header *DHEADER(Lisp_Object obj)
|
|
756 {
|
219
|
757 return (LRECORDP (obj)) ? XRECORD_LHEADER (obj) : NULL;
|
|
758 }
|
|
759
|
|
760 int DOPAQUE_DATA (Lisp_Object obj)
|
|
761 {
|
|
762 return (OPAQUEP (obj)) ? OPAQUE_DATA (XOPAQUE (obj)) : NULL;
|
213
|
763 }
|
|
764
|
|
765 struct Lisp_Event *DEVENT(Lisp_Object obj)
|
|
766 {
|
219
|
767 return (EVENTP (obj)) ? XEVENT (obj) : NULL;
|
213
|
768 }
|
|
769
|
|
770 struct Lisp_Cons *DCONS(Lisp_Object obj)
|
|
771 {
|
219
|
772 return (CONSP (obj)) ? XCONS (obj) : NULL;
|
213
|
773 }
|
|
774
|
|
775 Lisp_Object DCAR(Lisp_Object obj)
|
|
776 {
|
219
|
777 return (CONSP (obj)) ? XCAR (obj) : 0;
|
213
|
778 }
|
|
779
|
|
780 Lisp_Object DCDR(Lisp_Object obj)
|
|
781 {
|
219
|
782 return (CONSP (obj)) ? XCDR (obj) : 0;
|
|
783 }
|
|
784
|
|
785 Lisp_Object DCONSCDR(Lisp_Object obj)
|
|
786 {
|
|
787 return ((CONSP (obj)) && (CONSP (XCDR (obj)))) ? XCONS (XCDR (obj)) : 0;
|
|
788 }
|
|
789
|
|
790 Lisp_Object DCARCDR(Lisp_Object obj)
|
|
791 {
|
|
792 return ((CONSP (obj)) && (CONSP (XCDR (obj)))) ? XCAR (XCDR (obj)) : 0;
|
213
|
793 }
|
|
794
|
|
795 char *DSTRING(Lisp_Object obj)
|
|
796 {
|
219
|
797 return (STRINGP (obj)) ? XSTRING_DATA (obj) : NULL;
|
213
|
798 }
|
|
799
|
|
800 struct Lisp_Vector *DVECTOR(Lisp_Object obj)
|
|
801 {
|
219
|
802 return (VECTORP (obj)) ? XVECTOR (obj) : NULL;
|
213
|
803 }
|
|
804
|
|
805 struct Lisp_Symbol *DSYMBOL(Lisp_Object obj)
|
|
806 {
|
219
|
807 return (SYMBOLP (obj)) ? XSYMBOL (obj) : NULL;
|
213
|
808 }
|
|
809
|
|
810 char *DSYMNAME(Lisp_Object obj)
|
|
811 {
|
219
|
812 return (SYMBOLP (obj)) ? XSYMBOL (obj)->name->_data : NULL;
|
213
|
813 }
|
219
|
814
|
|
815 #endif
|