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