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);
|
245
|
65 #if 0 /* NOTUSED */
|
219
|
66 static int mswindows_enqueue_timeout (int milliseconds);
|
|
67 static void mswindows_dequeue_timeout (int interval_id);
|
|
68
|
|
69 /* Timeout queue */
|
|
70 struct mswindows_timeout
|
|
71 {
|
|
72 int ticks;
|
|
73 int interval_id;
|
|
74 struct mswindows_timeout *next;
|
|
75 };
|
|
76 typedef struct mswindows_timeout mswindows_timeout;
|
|
77 static mswindows_timeout timeout_pool[MSW_TIMEOUT_MAX];
|
|
78 static mswindows_timeout *timeout_head = NULL;
|
245
|
79
|
219
|
80 static int timeout_mswindows_id;
|
245
|
81 #endif
|
213
|
82
|
225
|
83 /*----------------------------------------------------------------------------*/
|
|
84 /* Enqueue helpers */
|
|
85 /*----------------------------------------------------------------------------*/
|
223
|
86
|
233
|
87 void
|
223
|
88 mswindows_enqueue_magic_event (HWND hwnd, UINT message)
|
|
89 {
|
|
90 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
91 struct Lisp_Event* event = XEVENT (emacs_event);
|
|
92
|
|
93 event->channel = mswindows_find_frame (hwnd);
|
|
94 event->timestamp = GetMessageTime();
|
|
95 event->event_type = magic_event;
|
|
96 EVENT_MSWINDOWS_MAGIC_TYPE (event) = message;
|
|
97
|
|
98 mswindows_enqueue_dispatch_event (emacs_event);
|
|
99 }
|
|
100
|
|
101 static void
|
|
102 mswindows_enqueue_mouse_button_event (HWND hwnd, UINT message, POINTS where, DWORD when)
|
|
103 {
|
|
104
|
|
105 /* We always use last message time, because mouse button
|
|
106 events may get delayed, and XEmacs double click
|
|
107 recognition will fail */
|
|
108
|
|
109 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
110 struct Lisp_Event* event = XEVENT(emacs_event);
|
|
111
|
|
112 event->channel = mswindows_find_frame(hwnd);
|
|
113 event->timestamp = when;
|
|
114 event->event.button.button =
|
|
115 (message==WM_LBUTTONDOWN || message==WM_LBUTTONUP) ? 1 :
|
|
116 ((message==WM_RBUTTONDOWN || message==WM_RBUTTONUP) ? 3 : 2);
|
|
117 event->event.button.x = where.x;
|
|
118 event->event.button.y = where.y;
|
225
|
119 event->event.button.modifiers = mswindows_modifier_state (NULL, 0);
|
223
|
120
|
|
121 if (message==WM_LBUTTONDOWN || message==WM_MBUTTONDOWN ||
|
|
122 message==WM_RBUTTONDOWN)
|
|
123 {
|
|
124 event->event_type = button_press_event;
|
|
125 SetCapture (hwnd);
|
|
126 }
|
|
127 else
|
|
128 {
|
|
129 event->event_type = button_release_event;
|
|
130 ReleaseCapture ();
|
|
131 }
|
|
132
|
|
133 mswindows_enqueue_dispatch_event (emacs_event);
|
|
134 }
|
|
135
|
|
136 static void
|
225
|
137 mswindows_enqueue_keypress_event (HWND hwnd, Lisp_Object keysym, int mods)
|
|
138 {
|
|
139 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
140 struct Lisp_Event* event = XEVENT(emacs_event);
|
|
141
|
|
142 event->channel = mswindows_find_console(hwnd);
|
|
143 event->timestamp = GetMessageTime();
|
|
144 event->event_type = key_press_event;
|
|
145 event->event.key.keysym = keysym;
|
|
146 event->event.key.modifiers = mods;
|
|
147 mswindows_enqueue_dispatch_event (emacs_event);
|
|
148 }
|
|
149
|
|
150 static void
|
223
|
151 mswindows_set_chord_timer (HWND hwnd)
|
|
152 {
|
|
153 int interval;
|
|
154
|
|
155 /* We get half system threshold as it seems to
|
|
156 long before drag-selection is shown */
|
|
157 if (mswindows_button2_chord_time <= 0)
|
|
158 interval = GetDoubleClickTime () / 2;
|
|
159 else
|
|
160 interval = mswindows_button2_chord_time;
|
|
161
|
|
162 SetTimer (hwnd, BUTTON_2_TIMER_ID, interval, 0);
|
|
163 }
|
|
164
|
|
165 static int
|
|
166 mswindows_button2_near_enough (POINTS p1, POINTS p2)
|
|
167 {
|
|
168 int dx, dy;
|
|
169 if (mswindows_button2_max_skew_x <= 0)
|
|
170 dx = GetSystemMetrics (SM_CXDOUBLECLK) / 2;
|
|
171 else
|
|
172 dx = mswindows_button2_max_skew_x;
|
|
173
|
|
174 if (mswindows_button2_max_skew_y <= 0)
|
|
175 dy = GetSystemMetrics (SM_CYDOUBLECLK) / 2;
|
|
176 else
|
|
177 dy = mswindows_button2_max_skew_y;
|
|
178
|
|
179 return abs (p1.x - p2.x) < dx && abs (p1.y- p2.y)< dy;
|
|
180 }
|
213
|
181
|
225
|
182 static int
|
|
183 mswindows_current_layout_has_AltGr ()
|
|
184 {
|
|
185 /* This simple caching mechanism saves 10% of CPU
|
|
186 time when a key typed at autorepeat rate of 30 cps! */
|
|
187 static HKL last_hkl = 0;
|
|
188 static int last_hkl_has_AltGr;
|
|
189
|
|
190 HKL current_hkl = GetKeyboardLayout (0);
|
|
191 if (current_hkl != last_hkl)
|
|
192 {
|
231
|
193 TCHAR c;
|
225
|
194 last_hkl_has_AltGr = 0;
|
|
195 /* In this loop, we query whether a character requires
|
|
196 AltGr to be down to generate it. If at least such one
|
|
197 found, this means that the layout does regard AltGr */
|
231
|
198 for (c = ' '; c <= 0xFFU && c != 0 && !last_hkl_has_AltGr; ++c)
|
225
|
199 if (HIBYTE (VkKeyScan (c)) == 6)
|
|
200 last_hkl_has_AltGr = 1;
|
|
201 last_hkl = current_hkl;
|
|
202 }
|
|
203 return last_hkl_has_AltGr;
|
|
204 }
|
|
205
|
213
|
206 /*
|
|
207 * The windows procedure for the window class XEMACS_CLASS
|
|
208 * Stuffs messages in the mswindows event queue
|
|
209 */
|
223
|
210 LRESULT WINAPI
|
|
211 mswindows_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
213
|
212 {
|
|
213 /* Note: Remember to initialise these before use */
|
|
214 Lisp_Object emacs_event;
|
|
215 struct Lisp_Event *event;
|
223
|
216 Lisp_Object fobj;
|
|
217 struct frame *frame;
|
|
218 struct mswindows_frame* msframe;
|
231
|
219
|
213
|
220 switch (message)
|
|
221 {
|
223
|
222 case WM_ERASEBKGND:
|
|
223 /* Erase background only during non-dynamic sizing */
|
|
224 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
225 if (msframe->sizing && !mswindows_dynamic_frame_resize)
|
|
226 goto defproc;
|
|
227 return 1;
|
|
228
|
|
229 case WM_CLOSE:
|
|
230 fobj = mswindows_find_frame (hwnd);
|
|
231 enqueue_misc_user_event (fobj, Qeval, list3 (Qdelete_frame, fobj, Qt));
|
|
232 mswindows_enqueue_magic_event (hwnd, XM_BUMPQUEUE);
|
|
233 break;
|
|
234
|
213
|
235 case WM_KEYDOWN:
|
|
236 case WM_SYSKEYDOWN:
|
|
237 {
|
225
|
238 BYTE keymap[256];
|
|
239 int has_AltGr = mswindows_current_layout_has_AltGr ();
|
231
|
240 int mods;
|
219
|
241 Lisp_Object keysym;
|
225
|
242
|
|
243 GetKeyboardState (keymap);
|
|
244 mods = mswindows_modifier_state (keymap, has_AltGr);
|
219
|
245
|
225
|
246 /* Handle those keys that TranslateMessage won't generate a WM_CHAR for */
|
219
|
247 if (!NILP (keysym = mswindows_key_to_emacs_keysym(wParam, mods)))
|
225
|
248 mswindows_enqueue_keypress_event (hwnd, keysym, mods);
|
|
249 else
|
213
|
250 {
|
225
|
251 int quit_ch = CONSOLE_QUIT_CHAR (XCONSOLE (mswindows_find_console (hwnd)));
|
|
252 BYTE keymap_orig[256];
|
245
|
253 MSG msg = { hwnd, message, wParam, lParam, GetMessageTime(), (GetMessagePos()) };
|
225
|
254 memcpy (keymap_orig, keymap, 256);
|
|
255
|
|
256 /* Clear control and alt modifiers out of the keymap */
|
|
257 keymap [VK_RCONTROL] = 0;
|
|
258 keymap [VK_LMENU] = 0;
|
231
|
259 if (!has_AltGr || !(keymap [VK_LCONTROL] & 0x80) || !(keymap [VK_RMENU] & 0x80))
|
|
260 {
|
|
261 keymap [VK_LCONTROL] = 0;
|
|
262 keymap [VK_CONTROL] = 0;
|
|
263 keymap [VK_RMENU] = 0;
|
|
264 keymap [VK_MENU] = 0;
|
|
265 }
|
225
|
266 SetKeyboardState (keymap);
|
|
267
|
|
268 /* Have some WM_[SYS]CHARS in the queue */
|
|
269 TranslateMessage (&msg);
|
213
|
270
|
225
|
271 while (PeekMessage (&msg, hwnd, WM_CHAR, WM_CHAR, PM_REMOVE)
|
|
272 ||PeekMessage (&msg, hwnd, WM_SYSCHAR, WM_SYSCHAR, PM_REMOVE))
|
|
273 {
|
231
|
274 int ch = msg.wParam;
|
225
|
275 /* CH is a character code for the key:
|
|
276 'C' for Shift+C and Ctrl+Shift+C
|
|
277 'c' for c and Ctrl+c */
|
|
278
|
|
279 /* #### If locale is not C, US or other latin-1,
|
|
280 isalpha() maybe not what do we mean */
|
|
281
|
|
282 /* XEmacs doesn't seem to like Shift on non-alpha keys */
|
|
283 if (!isalpha(ch))
|
|
284 mods &= ~MOD_SHIFT;
|
|
285
|
|
286 /* Un-capitalise alpha control keys */
|
|
287 if ((mods & MOD_CONTROL) && isalpha(ch))
|
|
288 ch |= ('A' ^ 'a');
|
|
289
|
|
290 /* If a quit char with no modifiers other than control and
|
|
291 shift, then mark it with a fake modifier, which is removed
|
|
292 upon dequeueing the event */
|
|
293 /* #### This might also not withstand localization, if
|
|
294 quit character is not a latin-1 symbol */
|
|
295 if (((quit_ch < ' ' && (mods & MOD_CONTROL) && quit_ch + 'a' - 1 == ch)
|
|
296 || (quit_ch >= ' ' && !(mods & MOD_CONTROL) && quit_ch == ch))
|
|
297 && ((mods & ~(MOD_CONTROL | MOD_SHIFT)) == 0))
|
|
298 {
|
|
299 mods |= FAKE_MOD_QUIT;
|
|
300 ++mswindows_quit_chars_count;
|
|
301 }
|
|
302
|
|
303 mswindows_enqueue_keypress_event (hwnd, make_char(ch), mods);
|
|
304 } /* while */
|
|
305 SetKeyboardState (keymap_orig);
|
|
306 } /* else */
|
213
|
307 }
|
|
308 goto defproc;
|
|
309
|
223
|
310 case WM_MBUTTONDOWN:
|
|
311 case WM_MBUTTONUP:
|
|
312 /* Real middle mouse button has nothing to do with emulated one:
|
|
313 if one wants to exercise fingers playing chords on the mouse,
|
|
314 he is allowed to do that! */
|
|
315 mswindows_enqueue_mouse_button_event (hwnd, message,
|
|
316 MAKEPOINTS (lParam), GetMessageTime());
|
|
317 break;
|
|
318
|
|
319 case WM_LBUTTONUP:
|
|
320 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
321 msframe->last_click_time = GetMessageTime();
|
|
322
|
|
323 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
324 msframe->button2_need_lbutton = 0;
|
|
325 if (msframe->ignore_next_lbutton_up)
|
|
326 {
|
|
327 msframe->ignore_next_lbutton_up = 0;
|
|
328 }
|
|
329 else if (msframe->button2_is_down)
|
|
330 {
|
|
331 msframe->button2_is_down = 0;
|
|
332 msframe->ignore_next_rbutton_up = 1;
|
|
333 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
|
|
334 MAKEPOINTS (lParam), GetMessageTime());
|
|
335 }
|
|
336 else
|
|
337 {
|
|
338 if (msframe->button2_need_rbutton)
|
|
339 {
|
|
340 msframe->button2_need_rbutton = 0;
|
|
341 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
342 MAKEPOINTS (lParam), GetMessageTime());
|
|
343 }
|
|
344 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONUP,
|
|
345 MAKEPOINTS (lParam), GetMessageTime());
|
|
346 }
|
|
347 break;
|
|
348
|
|
349 case WM_RBUTTONUP:
|
|
350 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
351 msframe->last_click_time = GetMessageTime();
|
|
352
|
|
353 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
354 msframe->button2_need_rbutton = 0;
|
|
355 if (msframe->ignore_next_rbutton_up)
|
|
356 {
|
|
357 msframe->ignore_next_rbutton_up = 0;
|
|
358 }
|
|
359 else if (msframe->button2_is_down)
|
|
360 {
|
|
361 msframe->button2_is_down = 0;
|
|
362 msframe->ignore_next_lbutton_up = 1;
|
|
363 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONUP,
|
|
364 MAKEPOINTS (lParam), GetMessageTime());
|
|
365 }
|
|
366 else
|
|
367 {
|
|
368 if (msframe->button2_need_lbutton)
|
|
369 {
|
|
370 msframe->button2_need_lbutton = 0;
|
|
371 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
372 MAKEPOINTS (lParam), GetMessageTime());
|
|
373 }
|
|
374 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONUP,
|
|
375 MAKEPOINTS (lParam), GetMessageTime());
|
|
376 }
|
|
377 break;
|
|
378
|
213
|
379 case WM_LBUTTONDOWN:
|
223
|
380 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
381
|
|
382 if (msframe->button2_need_lbutton)
|
|
383 {
|
|
384 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
385 msframe->button2_need_lbutton = 0;
|
|
386 msframe->button2_need_rbutton = 0;
|
|
387 if (mswindows_button2_near_enough (msframe->last_click_point, MAKEPOINTS (lParam)))
|
225
|
388 {
|
|
389 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
|
|
390 MAKEPOINTS (lParam), GetMessageTime());
|
|
391 msframe->button2_is_down = 1;
|
|
392 }
|
223
|
393 else
|
|
394 {
|
|
395 mswindows_enqueue_mouse_button_event (hwnd, WM_RBUTTONDOWN,
|
|
396 msframe->last_click_point, msframe->last_click_time);
|
|
397 mswindows_enqueue_mouse_button_event (hwnd, WM_LBUTTONDOWN,
|
|
398 MAKEPOINTS (lParam), GetMessageTime());
|
|
399 }
|
|
400 }
|
|
401 else
|
|
402 {
|
|
403 mswindows_set_chord_timer (hwnd);
|
|
404 msframe->button2_need_rbutton = 1;
|
|
405 msframe->last_click_point = MAKEPOINTS (lParam);
|
|
406 }
|
|
407 msframe->last_click_time = GetMessageTime();
|
|
408 break;
|
|
409
|
213
|
410 case WM_RBUTTONDOWN:
|
223
|
411 msframe = FRAME_MSWINDOWS_DATA (XFRAME (mswindows_find_frame (hwnd)));
|
|
412
|
|
413 if (msframe->button2_need_rbutton)
|
|
414 {
|
|
415 KillTimer (hwnd, BUTTON_2_TIMER_ID);
|
|
416 msframe->button2_need_lbutton = 0;
|
|
417 msframe->button2_need_rbutton = 0;
|
|
418 if (mswindows_button2_near_enough (msframe->last_click_point, MAKEPOINTS (lParam)))
|
225
|
419 {
|
|
420 mswindows_enqueue_mouse_button_event (hwnd, WM_MBUTTONDOWN,
|
|
421 MAKEPOINTS (lParam), GetMessageTime());
|
|
422 msframe->button2_is_down = 1;
|
|
423 }
|
223
|
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;
|
225
|
488 event->event.motion.modifiers = mswindows_modifier_state (NULL, 0);
|
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
|
239
|
543 if (msframe->sizing && mswindows_dynamic_frame_resize)
|
223
|
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
|
231
|
610 #ifdef HAVE_SCROLLBARS
|
225
|
611 case WM_VSCROLL:
|
|
612 case WM_HSCROLL:
|
|
613 {
|
|
614 /* Direction of scroll is determined by scrollbar instance. */
|
|
615 int code = (int) LOWORD(wParam);
|
|
616 int pos = (short int) HIWORD(wParam);
|
|
617 HWND hwndScrollBar = (HWND) lParam;
|
|
618 mswindows_handle_scrollbar_event (hwndScrollBar, code, pos);
|
227
|
619
|
231
|
620 if (UNBOUNDP(mswindows_pump_outstanding_events()))
|
227
|
621 {
|
|
622 /* Error during event pumping - cancel scroll */
|
|
623 SendMessage (hwndScrollBar, WM_CANCELMODE, 0, 0);
|
|
624 }
|
|
625
|
225
|
626 break;
|
|
627 }
|
231
|
628 #endif
|
|
629
|
|
630 #ifdef HAVE_MENUBARS
|
|
631 case WM_INITMENU:
|
|
632 if (UNBOUNDP (mswindows_handle_wm_initmenu (
|
233
|
633 (HMENU) wParam,
|
231
|
634 XFRAME (mswindows_find_frame (hwnd)))))
|
|
635 SendMessage (hwnd, WM_CANCELMODE, 0, 0);
|
|
636 break;
|
|
637
|
|
638 case WM_INITMENUPOPUP:
|
|
639 if (!HIWORD(lParam))
|
|
640 {
|
|
641 if (UNBOUNDP (mswindows_handle_wm_initmenupopup (
|
|
642 (HMENU) wParam,
|
|
643 XFRAME (mswindows_find_frame (hwnd)))))
|
|
644 SendMessage (hwnd, WM_CANCELMODE, 0, 0);
|
|
645 }
|
|
646 break;
|
|
647
|
|
648 case WM_EXITMENULOOP:
|
|
649 if (UNBOUNDP (mswindows_handle_wm_exitmenuloop (
|
|
650 XFRAME (mswindows_find_frame (hwnd)))))
|
|
651 SendMessage (hwnd, WM_CANCELMODE, 0, 0);
|
|
652 break;
|
|
653
|
|
654 #endif /* HAVE_MENUBARS */
|
|
655
|
|
656 case WM_COMMAND:
|
|
657 {
|
|
658 WORD id = LOWORD (wParam);
|
|
659 frame = XFRAME (mswindows_find_frame (hwnd));
|
|
660
|
|
661 #ifdef HAVE_MENUBARS
|
|
662 if (!NILP (mswindows_handle_wm_command (frame, id)))
|
|
663 break;
|
|
664 #endif
|
|
665
|
|
666 #ifdef HAVE_TOOLBARS
|
|
667 O Toolbar Implementor, this place may have something for you!;
|
|
668 #endif
|
|
669
|
|
670 /* Bite me - a spurious command. No abort(), for safety */
|
|
671 /* #### Perhaps, this message should be changed */
|
|
672 error ("Cannot decode command. Tell kkm he's a parallelogramm, if you know"
|
|
673 " what does that mean!");
|
|
674 }
|
|
675 break;
|
225
|
676
|
213
|
677 defproc:
|
|
678 default:
|
|
679 return DefWindowProc (hwnd, message, wParam, lParam);
|
|
680 }
|
|
681 return (0);
|
|
682 }
|
|
683
|
219
|
684 /* Returns the state of the modifier keys in the format expected by the
|
|
685 * Lisp_Event key_data, button_data and motion_data modifiers member */
|
225
|
686 int mswindows_modifier_state (BYTE* keymap, int has_AltGr)
|
219
|
687 {
|
225
|
688 int mods = 0;
|
|
689
|
|
690 if (keymap == NULL)
|
|
691 {
|
|
692 keymap = (BYTE*) alloca(256);
|
|
693 GetKeyboardState (keymap);
|
|
694 has_AltGr = mswindows_current_layout_has_AltGr ();
|
|
695 }
|
|
696
|
|
697 if (has_AltGr && (keymap [VK_LCONTROL] & 0x80) && (keymap [VK_RMENU] & 0x80))
|
|
698 {
|
|
699 mods |= (keymap [VK_LMENU] & 0x80) ? MOD_META : 0;
|
|
700 mods |= (keymap [VK_RCONTROL] & 0x80) ? MOD_CONTROL : 0;
|
|
701 }
|
|
702 else
|
|
703 {
|
|
704 mods |= (keymap [VK_MENU] & 0x80) ? MOD_META : 0;
|
|
705 mods |= (keymap [VK_CONTROL] & 0x80) ? MOD_CONTROL : 0;
|
|
706 }
|
|
707
|
|
708 mods |= (keymap [VK_SHIFT] & 0x80) ? MOD_SHIFT : 0;
|
|
709
|
|
710 return mods;
|
219
|
711 }
|
|
712
|
213
|
713 /*
|
|
714 * Translate a mswindows virtual key to a keysym.
|
|
715 * Only returns non-Qnil for keys that don't generate WM_CHAR messages
|
|
716 * or whose ASCII codes (like space) xemacs doesn't like.
|
|
717 * Virtual key values are defined in winresrc.h
|
|
718 * XXX I'm not sure that KEYSYM("name") is the best thing to use here.
|
|
719 */
|
219
|
720 Lisp_Object mswindows_key_to_emacs_keysym(int mswindows_key, int mods)
|
213
|
721 {
|
|
722 switch (mswindows_key)
|
|
723 {
|
|
724 /* First the predefined ones */
|
|
725 case VK_BACK: return QKbackspace;
|
|
726 case VK_TAB: return QKtab;
|
|
727 case '\n': return QKlinefeed; /* No VK_LINEFEED in winresrc.h */
|
|
728 case VK_RETURN: return QKreturn;
|
|
729 case VK_ESCAPE: return QKescape;
|
|
730 case VK_SPACE: return QKspace;
|
|
731 case VK_DELETE: return QKdelete;
|
|
732
|
|
733 /* The rest */
|
219
|
734 case VK_CLEAR: return KEYSYM ("clear"); /* Should do ^L ? */
|
213
|
735 case VK_PRIOR: return KEYSYM ("prior");
|
|
736 case VK_NEXT: return KEYSYM ("next");
|
|
737 case VK_END: return KEYSYM ("end");
|
|
738 case VK_HOME: return KEYSYM ("home");
|
|
739 case VK_LEFT: return KEYSYM ("left");
|
|
740 case VK_UP: return KEYSYM ("up");
|
|
741 case VK_RIGHT: return KEYSYM ("right");
|
|
742 case VK_DOWN: return KEYSYM ("down");
|
219
|
743 case VK_SELECT: return KEYSYM ("select");
|
|
744 case VK_PRINT: return KEYSYM ("print");
|
|
745 case VK_EXECUTE: return KEYSYM ("execute");
|
|
746 case VK_SNAPSHOT: return KEYSYM ("print");
|
213
|
747 case VK_INSERT: return KEYSYM ("insert");
|
|
748 case VK_HELP: return KEYSYM ("help");
|
219
|
749 #if 0 /* XXX What are these supposed to do? */
|
|
750 case VK_LWIN return KEYSYM ("");
|
|
751 case VK_RWIN return KEYSYM ("");
|
|
752 #endif
|
|
753 case VK_APPS: return KEYSYM ("menu");
|
221
|
754 case VK_F1: return KEYSYM ("f1");
|
|
755 case VK_F2: return KEYSYM ("f2");
|
|
756 case VK_F3: return KEYSYM ("f3");
|
|
757 case VK_F4: return KEYSYM ("f4");
|
|
758 case VK_F5: return KEYSYM ("f5");
|
|
759 case VK_F6: return KEYSYM ("f6");
|
|
760 case VK_F7: return KEYSYM ("f7");
|
|
761 case VK_F8: return KEYSYM ("f8");
|
|
762 case VK_F9: return KEYSYM ("f9");
|
|
763 case VK_F10: return KEYSYM ("f10");
|
|
764 case VK_F11: return KEYSYM ("f11");
|
|
765 case VK_F12: return KEYSYM ("f12");
|
|
766 case VK_F13: return KEYSYM ("f13");
|
|
767 case VK_F14: return KEYSYM ("f14");
|
|
768 case VK_F15: return KEYSYM ("f15");
|
|
769 case VK_F16: return KEYSYM ("f16");
|
|
770 case VK_F17: return KEYSYM ("f17");
|
|
771 case VK_F18: return KEYSYM ("f18");
|
|
772 case VK_F19: return KEYSYM ("f19");
|
|
773 case VK_F20: return KEYSYM ("f20");
|
|
774 case VK_F21: return KEYSYM ("f21");
|
|
775 case VK_F22: return KEYSYM ("f22");
|
|
776 case VK_F23: return KEYSYM ("f23");
|
|
777 case VK_F24: return KEYSYM ("f24");
|
213
|
778 }
|
|
779 return Qnil;
|
|
780 }
|
|
781
|
219
|
782 /*
|
213
|
783 * Find the console that matches the supplied mswindows window handle
|
|
784 */
|
223
|
785 Lisp_Object
|
213
|
786 mswindows_find_console (HWND hwnd)
|
|
787 {
|
|
788 Lisp_Object concons;
|
|
789
|
|
790 CONSOLE_LOOP (concons)
|
|
791 {
|
|
792 Lisp_Object console = XCAR (concons);
|
|
793 /* We only support one console so this must be it */
|
|
794 return console;
|
|
795 }
|
|
796
|
|
797 return Qnil;
|
|
798 }
|
|
799
|
|
800 /*
|
|
801 * Find the frame that matches the supplied mswindows window handle
|
|
802 */
|
|
803 static Lisp_Object
|
|
804 mswindows_find_frame (HWND hwnd)
|
|
805 {
|
223
|
806 return (Lisp_Object) GetWindowLong (hwnd, XWL_FRAMEOBJ);
|
213
|
807 }
|
|
808
|
219
|
809
|
|
810 #ifdef DEBUG_XEMACS
|
213
|
811 /*
|
|
812 * Random helper functions for debugging.
|
|
813 * Intended for use in the MSVC "Watch" window which doesn't like
|
|
814 * the aborts that the error_check_foo() functions can make.
|
|
815 */
|
|
816 struct lrecord_header *DHEADER(Lisp_Object obj)
|
|
817 {
|
219
|
818 return (LRECORDP (obj)) ? XRECORD_LHEADER (obj) : NULL;
|
|
819 }
|
|
820
|
231
|
821 int *DOPAQUE_DATA (Lisp_Object obj)
|
219
|
822 {
|
|
823 return (OPAQUEP (obj)) ? OPAQUE_DATA (XOPAQUE (obj)) : NULL;
|
213
|
824 }
|
|
825
|
|
826 struct Lisp_Event *DEVENT(Lisp_Object obj)
|
|
827 {
|
219
|
828 return (EVENTP (obj)) ? XEVENT (obj) : NULL;
|
213
|
829 }
|
|
830
|
|
831 struct Lisp_Cons *DCONS(Lisp_Object obj)
|
|
832 {
|
219
|
833 return (CONSP (obj)) ? XCONS (obj) : NULL;
|
213
|
834 }
|
|
835
|
|
836 Lisp_Object DCAR(Lisp_Object obj)
|
|
837 {
|
219
|
838 return (CONSP (obj)) ? XCAR (obj) : 0;
|
213
|
839 }
|
|
840
|
|
841 Lisp_Object DCDR(Lisp_Object obj)
|
|
842 {
|
219
|
843 return (CONSP (obj)) ? XCDR (obj) : 0;
|
|
844 }
|
|
845
|
231
|
846 struct Lisp_Cons *DCONSCDR(Lisp_Object obj)
|
219
|
847 {
|
|
848 return ((CONSP (obj)) && (CONSP (XCDR (obj)))) ? XCONS (XCDR (obj)) : 0;
|
|
849 }
|
|
850
|
|
851 Lisp_Object DCARCDR(Lisp_Object obj)
|
|
852 {
|
|
853 return ((CONSP (obj)) && (CONSP (XCDR (obj)))) ? XCAR (XCDR (obj)) : 0;
|
213
|
854 }
|
|
855
|
|
856 char *DSTRING(Lisp_Object obj)
|
|
857 {
|
219
|
858 return (STRINGP (obj)) ? XSTRING_DATA (obj) : NULL;
|
213
|
859 }
|
|
860
|
|
861 struct Lisp_Vector *DVECTOR(Lisp_Object obj)
|
|
862 {
|
219
|
863 return (VECTORP (obj)) ? XVECTOR (obj) : NULL;
|
213
|
864 }
|
|
865
|
|
866 struct Lisp_Symbol *DSYMBOL(Lisp_Object obj)
|
|
867 {
|
219
|
868 return (SYMBOLP (obj)) ? XSYMBOL (obj) : NULL;
|
213
|
869 }
|
|
870
|
|
871 char *DSYMNAME(Lisp_Object obj)
|
|
872 {
|
219
|
873 return (SYMBOLP (obj)) ? XSYMBOL (obj)->name->_data : NULL;
|
213
|
874 }
|
219
|
875
|
|
876 #endif
|