annotate src/msw-proc.c @ 221:6c0ae1f9357f r20-4b9

Import from CVS: tag r20-4b9
author cvs
date Mon, 13 Aug 2007 10:10:02 +0200
parents 262b8bb4a523
children 2c611d1463a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
1 /* mswindows specific event-handling.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
2 Copyright (C) 1997 Jonathan Harris.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
3
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
4 This file is part of XEmacs.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
5
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
9 later version.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
10
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
14 for more details.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
15
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
20
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
21 /* Synched up with: Not in FSF. */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
22
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
23 /* Authorship:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
24
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
25 Jonathan Harris, November 1997 for 20.4.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
26 */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
27
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
28 /*
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
29 * Comment:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
30 *
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
31 * X on UNIX may be bad, but the win32 API really really really sucks.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
32 *
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
33 * Windows user-input type events are stored in a per-thread message queue
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
34 * and retrieved using GetMessage(). It is not possible to wait on this
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
35 * queue and on other events (eg process input) simultaneously. Also, the
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
36 * main event-handling code in windows (the "windows procedure") is called
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
37 * asynchronously when windows has certain other types of events ("nonqueued
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
38 * messages") to deliver. The documentation doesn't appear to specify the
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
39 * context in which the windows procedure is called, but I assume that the
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
40 * thread that created the window is temporarily highjacked for this purpose
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
41 * when it calls GetMessage (a bit like X callbacks?).
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
42 *
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
43 * We spawn off a single thread to deal with both queued and non-queued
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
44 * events. The thread turns both kinds of events into emacs_events and stuffs
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
45 * them in a queue which XEmacs reads at its leisure. This file contains the
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
46 * code for that thread.
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
47 *
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
48 * Unfortunately, under win32 a seemingly-random selection of resources are
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
49 * owned by the thread that created/asked for them and not by the process. In
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
50 * particular, only the thread that created a window can retrieve messages
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
51 * destined for that window ("GetMessage does not retrieve messages for
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
52 * windows that belong to other threads..."). This means that our message-
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
53 * processing thread also has to do all window creation, deletion and various
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
54 * other random stuff. We handle this bogosity by getting the main XEmacs
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
55 * thread to send special user-defined messages to the message-processing
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
56 * thread to instruct it to create windows etc.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
57 *
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
58 * More bogosity: Windows95 doesn't offer any one-shot timers, only a
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
59 * periodic timer. Worse, if you don't want a periodic timer to be associated
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
60 * with a particular mswindows window (we don't) your periodic timers don't
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
61 * have unique ids associated with them. We get round this lameness by
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
62 * setting off a single periodic timer and we use this to schedule timeouts
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
63 * manually. Implementing basic stuff like one-shot timers at the application
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
64 * level is not particularly efficient, but Windows95 leaves us no choice.
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
65 */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
66
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
67
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
68 #include <config.h>
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
69 #include "lisp.h"
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
70
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
71 #include "console-msw.h"
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
72 #include "device.h"
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
73 #include "frame.h"
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
74 #include "events.h"
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
75 #include "event-msw.h"
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
76
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
77 #ifdef DEBUG_XEMACS
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
78 # include "opaque.h" /* For the debug functions at the end of this file */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
79 # undef DEBUG_MESSAGES
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
80 # undef DEBUG_TIMEOUTS
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
81 #endif
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
82
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
83 #define MSWINDOWS_FRAME_STYLE WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_TILEDWINDOW
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
84 #define MSWINDOWS_POPUP_STYLE WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_CAPTION|WS_POPUP
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
85
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
86 static LRESULT WINAPI mswindows_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
87 static Lisp_Object mswindows_find_console (HWND hwnd);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
88 static Lisp_Object mswindows_find_frame (HWND hwnd);
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
89 static Lisp_Object mswindows_key_to_emacs_keysym(int mswindows_key, int mods);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
90 static int mswindows_modifier_state (void);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
91 static int mswindows_enqueue_timeout (int milliseconds);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
92 static void mswindows_dequeue_timeout (int interval_id);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
93
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
94 /* Virtual keycode of the '@' key */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
95 static int virtual_at_key;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
96
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
97 /* Timeout queue */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
98 struct mswindows_timeout
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
99 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
100 int ticks;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
101 int interval_id;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
102 struct mswindows_timeout *next;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
103 };
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
104 typedef struct mswindows_timeout mswindows_timeout;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
105 static mswindows_timeout timeout_pool[MSW_TIMEOUT_MAX];
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
106 static mswindows_timeout *timeout_head = NULL;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
107 static int timeout_mswindows_id;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
108
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
109 /*
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
110 * Entry point for the "windows" message-processing thread
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
111 */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
112 DWORD mswindows_win_thread()
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
113 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
114 WNDCLASS wc;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
115 MSG msg;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
116 mswindows_waitable_info_type info;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
117
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
118 /* Register the main window class */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
119 wc.style = CS_OWNDC; /* One DC per window */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
120 wc.lpfnWndProc = (WNDPROC) mswindows_wnd_proc;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
121 wc.cbClsExtra = 0;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
122 wc.cbWndExtra = 0; /* ? */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
123 wc.hInstance = NULL; /* ? */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
124 wc.hIcon = LoadIcon (NULL, XEMACS_CLASS);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
125 wc.hCursor = LoadCursor (NULL, IDC_ARROW);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
126 wc.hbrBackground = NULL; /* GetStockObject (WHITE_BRUSH); */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
127 wc.lpszMenuName = NULL; /* XXX FIXME? Add a menu? */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
128 wc.lpszClassName = XEMACS_CLASS;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
129 RegisterClass(&wc); /* XXX FIXME: Should use RegisterClassEx */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
130
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
131 info.type = mswindows_waitable_type_dispatch;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
132 mswindows_add_waitable(&info);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
133
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
134 /* Ensure our message queue is created XXX FIXME: Is this necessary? */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
135 PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
136
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
137 /* Notify the main thread that we're ready */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
138 assert(PostThreadMessage (mswindows_main_thread_id, WM_XEMACS_ACK, 0, 0));
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
139
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
140 /* Hack! Windows doesn't report Ctrl-@ characters so we have to find out
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
141 * which virtual key generates '@' at runtime */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
142 virtual_at_key = VkKeyScan ('@');
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
143 if (virtual_at_key & 0x200) /* 0x200 means the control key */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
144 /* If you need Ctrl just to generate @, you can't do Ctrl-@ */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
145 virtual_at_key = -1;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
146 else
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
147 virtual_at_key &= 0xff; /* The low byte contains the keycode */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
148
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
149 /* Main windows loop */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
150 while (1)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
151 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
152 GetMessage (&msg, NULL, 0, 0);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
153
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
154 /*
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
155 * Process things that don't have an associated window, so wouldn't
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
156 * get sent to mswindows_wnd_proc
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
157 */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
158
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
159 /* Request from main thread */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
160 if (msg.message>=WM_XEMACS_BASE && msg.message<=WM_XEMACS_END)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
161 mswindows_handle_request(&msg);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
162
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
163 /* Timeout(s) */
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
164 else if (msg.message == WM_TIMER)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
165 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
166 EnterCriticalSection (&mswindows_dispatch_crit);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
167 if (timeout_head!=NULL)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
168 --(timeout_head->ticks);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
169
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
170 while (timeout_head!=NULL && timeout_head->ticks==0)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
171 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
172 Lisp_Object emacs_event;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
173 struct Lisp_Event *event;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
174 int id = timeout_head->interval_id;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
175
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
176 #ifdef DEBUG_TIMEOUTS
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
177 stderr_out("--> %x\n", id);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
178 #endif
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
179 mswindows_dequeue_timeout (id);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
180 emacs_event = Fmake_event (Qnil, Qnil);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
181 event = XEVENT(emacs_event);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
182
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
183 event->channel = Qnil;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
184 event->timestamp = msg.time;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
185 event->event_type = timeout_event;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
186 event->event.timeout.interval_id = id;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
187 mswindows_enqueue_dispatch_event (emacs_event);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
188 }
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
189 LeaveCriticalSection (&mswindows_dispatch_crit);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
190 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
191 else
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
192 /* Pass on to mswindows_wnd_proc */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
193 DispatchMessage (&msg);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
194 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
195 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
196
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
197 /*
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
198 * The windows procedure for the window class XEMACS_CLASS
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
199 * Stuffs messages in the mswindows event queue
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
200 */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
201 static LRESULT WINAPI mswindows_wnd_proc(HWND hwnd, UINT message, WPARAM wParam,
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
202 LPARAM lParam)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
203 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
204 /* Note: Remember to initialise these before use */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
205 Lisp_Object emacs_event;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
206 struct Lisp_Event *event;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
207
221
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
208 static sizing = 0;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
209 MSG msg = { hwnd, message, wParam, lParam, 0, {0,0} };
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
210 msg.time = GetMessageTime();
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
211
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
212 #ifdef DEBUG_MESSAGES
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
213 stderr_out("Message %04x, wParam=%04x, lParam=%08lx\n", message, wParam, lParam);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
214 #endif
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
215 switch (message)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
216 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
217 case WM_KEYDOWN:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
218 case WM_SYSKEYDOWN:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
219 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
220 /* Handle those keys that TranslateMessage won't generate a WM_CHAR for */
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
221 Lisp_Object keysym;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
222 int mods = mswindows_modifier_state();
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
223
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
224 if (!NILP (keysym = mswindows_key_to_emacs_keysym(wParam, mods)))
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
225 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
226 EnterCriticalSection (&mswindows_dispatch_crit);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
227 emacs_event = Fmake_event (Qnil, Qnil);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
228 event = XEVENT(emacs_event);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
229
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
230 event->channel = mswindows_find_console(hwnd);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
231 event->timestamp = msg.time;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
232 event->event_type = key_press_event;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
233 event->event.key.keysym = keysym;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
234 event->event.key.modifiers = mods;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
235 mswindows_enqueue_dispatch_event (emacs_event);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
236 LeaveCriticalSection (&mswindows_dispatch_crit);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
237 return (0);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
238 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
239 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
240 TranslateMessage (&msg); /* Maybe generates WM_[SYS]CHAR in message queue */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
241 goto defproc;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
242
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
243 case WM_CHAR:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
244 case WM_SYSCHAR:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
245 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
246 EnterCriticalSection (&mswindows_dispatch_crit);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
247 emacs_event = Fmake_event (Qnil, Qnil);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
248 event = XEVENT(emacs_event);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
249
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
250 event->channel = mswindows_find_console(hwnd);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
251 event->timestamp = msg.time;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
252 event->event_type = key_press_event;
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
253
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
254 /* XEmacs doesn't seem to like Shift on non-alpha keys */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
255 event->event.key.modifiers = isalpha(wParam) ?
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
256 mswindows_modifier_state() :
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
257 mswindows_modifier_state() & ~MOD_SHIFT;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
258
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
259 if (wParam<' ') /* Control char not already handled under WM_KEYDOWN */
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
260 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
261 /* Don't capitalise alpha control keys */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
262 event->event.key.keysym = isalpha(wParam+'a'-1) ?
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
263 make_char(wParam+'a'-1) :
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
264 make_char(wParam+'A'-1);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
265 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
266 else
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
267 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
268 /* Assumes that emacs keysym == ASCII code */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
269 event->event.key.keysym = make_char(wParam);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
270 }
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
271
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
272 mswindows_enqueue_dispatch_event (emacs_event);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
273 LeaveCriticalSection (&mswindows_dispatch_crit);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
274 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
275 break;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
276
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
277 case WM_LBUTTONDOWN:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
278 case WM_MBUTTONDOWN:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
279 case WM_RBUTTONDOWN:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
280 case WM_LBUTTONUP:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
281 case WM_MBUTTONUP:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
282 case WM_RBUTTONUP:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
283 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
284 /* XXX FIXME: Do middle button emulation */
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
285 short x, y;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
286
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
287 EnterCriticalSection (&mswindows_dispatch_crit);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
288 emacs_event = Fmake_event (Qnil, Qnil);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
289 event = XEVENT(emacs_event);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
290
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
291 event->channel = mswindows_find_frame(hwnd);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
292 event->timestamp = msg.time;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
293 event->event.button.button =
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
294 (message==WM_LBUTTONDOWN || message==WM_LBUTTONUP) ? 1 :
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
295 ((message==WM_RBUTTONDOWN || message==WM_RBUTTONUP) ? 3 : 2);
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
296 x = LOWORD (lParam);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
297 y = HIWORD (lParam);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
298 event->event.button.x = x;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
299 event->event.button.y = y;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
300 event->event.button.modifiers = mswindows_modifier_state();
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
301
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
302 if (message==WM_LBUTTONDOWN || message==WM_MBUTTONDOWN ||
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
303 message==WM_RBUTTONDOWN)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
304 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
305 event->event_type = button_press_event;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
306 SetCapture (hwnd);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
307 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
308 else
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
309 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
310 event->event_type = button_release_event;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
311 ReleaseCapture ();
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
312 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
313
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
314 mswindows_enqueue_dispatch_event (emacs_event);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
315 LeaveCriticalSection (&mswindows_dispatch_crit);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
316 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
317 break;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
318
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
319 case WM_MOUSEMOVE:
221
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
320 /* Optimization: don't report mouse movement while size is changind */
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
321 if (!sizing)
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
322 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
323 short x, y;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
324
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
325 EnterCriticalSection (&mswindows_dispatch_crit);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
326 emacs_event = Fmake_event (Qnil, Qnil);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
327 event = XEVENT(emacs_event);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
328
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
329 event->channel = mswindows_find_frame(hwnd);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
330 event->timestamp = msg.time;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
331 event->event_type = pointer_motion_event;
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
332 x = LOWORD (lParam);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
333 y = HIWORD (lParam);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
334 event->event.motion.x = x;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
335 event->event.motion.y = y;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
336 event->event.motion.modifiers = mswindows_modifier_state();
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
337
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
338 mswindows_enqueue_dispatch_event (emacs_event);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
339 LeaveCriticalSection (&mswindows_dispatch_crit);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
340 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
341 break;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
342
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
343 case WM_PAINT:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
344 if (GetUpdateRect(hwnd, NULL, FALSE))
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
345 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
346 PAINTSTRUCT paintStruct;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
347
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
348 EnterCriticalSection (&mswindows_dispatch_crit);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
349 emacs_event = Fmake_event (Qnil, Qnil);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
350 event = XEVENT(emacs_event);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
351
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
352 event->channel = mswindows_find_frame(hwnd);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
353 event->timestamp = msg.time;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
354 event->event_type = magic_event;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
355 BeginPaint (hwnd, &paintStruct);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
356 EVENT_MSWINDOWS_MAGIC_TYPE(event) = message;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
357 EVENT_MSWINDOWS_MAGIC_DATA(event) = paintStruct.rcPaint;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
358 EndPaint (hwnd, &paintStruct);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
359
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
360 mswindows_enqueue_dispatch_event (emacs_event);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
361 LeaveCriticalSection (&mswindows_dispatch_crit);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
362 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
363 break;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
364
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
365 case WM_SIZE:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
366 /* We only care about this message if our size has really changed */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
367 if (wParam==SIZE_RESTORED || wParam==SIZE_MAXIMIZED || wParam==SIZE_MINIMIZED)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
368 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
369 RECT rect;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
370 EnterCriticalSection (&mswindows_dispatch_crit);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
371 emacs_event = Fmake_event (Qnil, Qnil);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
372 event = XEVENT(emacs_event);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
373
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
374 event->channel = mswindows_find_frame(hwnd);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
375 event->timestamp = msg.time;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
376 event->event_type = magic_event;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
377 if (wParam==SIZE_MINIMIZED)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
378 rect.left = rect.top = rect.right = rect.bottom = -1;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
379 else
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
380 GetClientRect(hwnd, &rect);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
381 EVENT_MSWINDOWS_MAGIC_TYPE(event) = message;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
382 EVENT_MSWINDOWS_MAGIC_DATA(event) = rect;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
383
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
384 mswindows_enqueue_dispatch_event (emacs_event);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
385 LeaveCriticalSection (&mswindows_dispatch_crit);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
386 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
387 break;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
388
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
389 /* Misc magic events which only require that the frame be identified */
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
390 case WM_SETFOCUS:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
391 case WM_KILLFOCUS:
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
392 case WM_CLOSE:
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
393 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
394 EnterCriticalSection (&mswindows_dispatch_crit);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
395 emacs_event = Fmake_event (Qnil, Qnil);
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
396 event = XEVENT (emacs_event);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
397
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
398 event->channel = mswindows_find_frame (hwnd);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
399 event->timestamp = msg.time;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
400 event->event_type = magic_event;
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
401 EVENT_MSWINDOWS_MAGIC_TYPE (event) = message;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
402
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
403 mswindows_enqueue_dispatch_event (emacs_event);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
404 LeaveCriticalSection (&mswindows_dispatch_crit);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
405 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
406 break;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
407
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
408 case WM_WINDOWPOSCHANGING:
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
409 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
410 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
411 WINDOWPLACEMENT wpl = { sizeof(WINDOWPLACEMENT) };
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
412 GetWindowPlacement(hwnd, &wpl);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
413
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
414 /* Only interested if size is changing and we're not being iconified */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
415 if ((wpl.showCmd != SW_SHOWMINIMIZED) && !(wp->flags & SWP_NOSIZE))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
416 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
417 RECT ncsize = { 0, 0, 0, 0 };
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
418 int pixwidth, pixheight;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
419 AdjustWindowRect (&ncsize, GetWindowLong (hwnd, GWL_STYLE), FALSE);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
420
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
421 round_size_to_char (XFRAME (mswindows_find_frame (hwnd)),
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
422 wp->cx - (ncsize.right - ncsize.left),
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
423 wp->cy - (ncsize.bottom - ncsize.top),
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
424 &pixwidth, &pixheight);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
425
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
426 /* Convert client sizes to window sizes */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
427 pixwidth += (ncsize.right - ncsize.left);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
428 pixheight += (ncsize.bottom - ncsize.top);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
429
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
430 if (wpl.showCmd != SW_SHOWMAXIMIZED)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
431 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
432 /* Adjust so that the bottom or right doesn't move if it's
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
433 * the top or left that's being changed */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
434 RECT rect;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
435 GetWindowRect (hwnd, &rect);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
436
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
437 if (rect.left != wp->x)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
438 wp->x += wp->cx - pixwidth;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
439 if (rect.top != wp->y)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
440 wp->y += wp->cy - pixheight;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
441 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
442
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
443 wp->cx = pixwidth;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
444 wp->cy = pixheight;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
445 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
446 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
447 break;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
448
221
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
449 case WM_ENTERSIZEMOVE:
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
450 case WM_EXITSIZEMOVE:
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
451 sizing = (message == WM_ENTERSIZEMOVE);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
452 goto defproc;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
453
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
454 defproc:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
455 default:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
456 return DefWindowProc (hwnd, message, wParam, lParam);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
457 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
458 return (0);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
459 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
460
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
461
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
462 /*
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
463 * Make a request to the message-processing thread to do things that
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
464 * can't be done in the main thread.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
465 */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
466 LPARAM
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
467 mswindows_make_request(UINT message, WPARAM wParam, mswindows_request_type *request)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
468 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
469 MSG msg;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
470 assert(PostThreadMessage (mswindows_win_thread_id, message, wParam,
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
471 (LPARAM) request));
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
472 GetMessage (&msg, NULL, WM_XEMACS_ACK, WM_XEMACS_ACK);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
473 return (msg.lParam);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
474 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
475
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
476
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
477 /*
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
478 * Handle a request from the main thread to do things that have to be
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
479 * done in the message-processing thread.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
480 */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
481 static void
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
482 mswindows_handle_request (MSG *msg)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
483 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
484 mswindows_request_type *request = (mswindows_request_type *) msg->lParam;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
485
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
486 switch (msg->message)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
487 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
488 case WM_XEMACS_CREATEWINDOW:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
489 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
490 struct frame *f = request->thing1;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
491 Lisp_Object *props = request->thing2;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
492 Lisp_Object name, height, width, popup, top, left;
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents: 213
diff changeset
493 int pixel_width, pixel_height;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
494 RECT rect;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
495 DWORD style;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
496 HWND hwnd;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
497
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
498 name = Fplist_get (*props, Qname, Qnil);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
499 height = Fplist_get (*props, Qheight, Qnil);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
500 width = Fplist_get (*props, Qwidth, Qnil);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
501 popup = Fplist_get (*props, Qpopup, Qnil);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
502 top = Fplist_get (*props, Qtop, Qnil);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
503 left = Fplist_get (*props, Qleft, Qnil);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
504
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
505 style = (NILP(popup)) ? MSWINDOWS_FRAME_STYLE : MSWINDOWS_POPUP_STYLE;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
506
221
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
507 FRAME_WIDTH (f) = INTP(width) ? XINT(width) : 80;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
508 FRAME_HEIGHT (f) = INTP(height) ? XINT(height) : 30;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
509 char_to_pixel_size (f, FRAME_WIDTH(f), FRAME_HEIGHT (f),
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
510 &FRAME_PIXWIDTH (f), &FRAME_PIXHEIGHT (f));
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
511
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
512 rect.left = rect.top = 0;
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
513 rect.right = FRAME_PIXWIDTH (f);
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
514 rect.bottom = FRAME_PIXHEIGHT (f);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
515 #ifdef HAVE_MENUBARS
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
516 AdjustWindowRect(&rect, style, TRUE);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
517 #else
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
518 AdjustWindowRect(&rect, style, FALSE);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
519 #endif
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
520
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
521 hwnd = CreateWindow (XEMACS_CLASS,
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
522 STRINGP(f->name) ? XSTRING_DATA(f->name) :
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
523 (STRINGP(name) ? XSTRING_DATA(name) : XEMACS_CLASS),
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
524 style,
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
525 INTP(left) ? XINT(left) : CW_USEDEFAULT,
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
526 INTP(top) ? XINT(top) : CW_USEDEFAULT,
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
527 rect.right-rect.left, rect.bottom-rect.top,
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
528 NULL, NULL, NULL, NULL);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
529 assert(PostThreadMessage (mswindows_main_thread_id, WM_XEMACS_ACK, 0, (LPARAM) hwnd));
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
530 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
531 return;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
532
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
533 case WM_XEMACS_DESTROYWINDOW:
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
534 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
535 struct frame *f = request->thing1;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
536 ReleaseDC(FRAME_MSWINDOWS_HANDLE(f), FRAME_MSWINDOWS_DC(f));
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
537 DestroyWindow(FRAME_MSWINDOWS_HANDLE(f));
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
538 assert (PostThreadMessage (mswindows_main_thread_id, WM_XEMACS_ACK, 0, 0));
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
539 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
540 break;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
541
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
542 case WM_XEMACS_SETTIMER:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
543 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
544 int id;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
545 EnterCriticalSection (&mswindows_dispatch_crit);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
546 id = mswindows_enqueue_timeout((int) request->thing1);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
547 LeaveCriticalSection (&mswindows_dispatch_crit);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
548 assert(PostThreadMessage (mswindows_main_thread_id, WM_XEMACS_ACK, 0, id));
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
549 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
550 break;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
551
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
552 case WM_XEMACS_KILLTIMER:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
553 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
554 EnterCriticalSection (&mswindows_dispatch_crit);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
555 mswindows_dequeue_timeout((int) request->thing1);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
556 LeaveCriticalSection (&mswindows_dispatch_crit);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
557 assert(PostThreadMessage (mswindows_main_thread_id, WM_XEMACS_ACK, 0, 0));
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
558 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
559 break;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
560
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
561 default:
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
562 assert(0);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
563 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
564 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
565
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
566
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
567 /* Returns the state of the modifier keys in the format expected by the
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
568 * Lisp_Event key_data, button_data and motion_data modifiers member */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
569 int mswindows_modifier_state (void)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
570 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
571 /* Set high bit of GetKeyState's return value indicates the key is down */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
572 return ((GetKeyState (VK_SHIFT) & 0x8000) ? MOD_SHIFT : 0) |
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
573 ((GetKeyState (VK_CONTROL) & 0x8000) ? MOD_CONTROL: 0) |
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
574 ((GetKeyState (VK_MENU) & 0x8000) ? MOD_META : 0);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
575 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
576
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
577
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
578 /*
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
579 * Translate a mswindows virtual key to a keysym.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
580 * Only returns non-Qnil for keys that don't generate WM_CHAR messages
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
581 * or whose ASCII codes (like space) xemacs doesn't like.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
582 * Virtual key values are defined in winresrc.h
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
583 * XXX I'm not sure that KEYSYM("name") is the best thing to use here.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
584 */
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
585 Lisp_Object mswindows_key_to_emacs_keysym(int mswindows_key, int mods)
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
586 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
587 switch (mswindows_key)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
588 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
589 /* First the predefined ones */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
590 case VK_BACK: return QKbackspace;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
591 case VK_TAB: return QKtab;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
592 case '\n': return QKlinefeed; /* No VK_LINEFEED in winresrc.h */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
593 case VK_RETURN: return QKreturn;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
594 case VK_ESCAPE: return QKescape;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
595 case VK_SPACE: return QKspace;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
596 case VK_DELETE: return QKdelete;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
597
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
598 /* The rest */
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
599 case VK_CLEAR: return KEYSYM ("clear"); /* Should do ^L ? */
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
600 case VK_PRIOR: return KEYSYM ("prior");
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
601 case VK_NEXT: return KEYSYM ("next");
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
602 case VK_END: return KEYSYM ("end");
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
603 case VK_HOME: return KEYSYM ("home");
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
604 case VK_LEFT: return KEYSYM ("left");
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
605 case VK_UP: return KEYSYM ("up");
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
606 case VK_RIGHT: return KEYSYM ("right");
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
607 case VK_DOWN: return KEYSYM ("down");
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
608 case VK_SELECT: return KEYSYM ("select");
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
609 case VK_PRINT: return KEYSYM ("print");
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
610 case VK_EXECUTE: return KEYSYM ("execute");
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
611 case VK_SNAPSHOT: return KEYSYM ("print");
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
612 case VK_INSERT: return KEYSYM ("insert");
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
613 case VK_HELP: return KEYSYM ("help");
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
614 #if 0 /* XXX What are these supposed to do? */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
615 case VK_LWIN return KEYSYM ("");
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
616 case VK_RWIN return KEYSYM ("");
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
617 #endif
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
618 case VK_APPS: return KEYSYM ("menu");
221
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
619 case VK_F1: return KEYSYM ("f1");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
620 case VK_F2: return KEYSYM ("f2");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
621 case VK_F3: return KEYSYM ("f3");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
622 case VK_F4: return KEYSYM ("f4");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
623 case VK_F5: return KEYSYM ("f5");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
624 case VK_F6: return KEYSYM ("f6");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
625 case VK_F7: return KEYSYM ("f7");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
626 case VK_F8: return KEYSYM ("f8");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
627 case VK_F9: return KEYSYM ("f9");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
628 case VK_F10: return KEYSYM ("f10");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
629 case VK_F11: return KEYSYM ("f11");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
630 case VK_F12: return KEYSYM ("f12");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
631 case VK_F13: return KEYSYM ("f13");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
632 case VK_F14: return KEYSYM ("f14");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
633 case VK_F15: return KEYSYM ("f15");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
634 case VK_F16: return KEYSYM ("f16");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
635 case VK_F17: return KEYSYM ("f17");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
636 case VK_F18: return KEYSYM ("f18");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
637 case VK_F19: return KEYSYM ("f19");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
638 case VK_F20: return KEYSYM ("f20");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
639 case VK_F21: return KEYSYM ("f21");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
640 case VK_F22: return KEYSYM ("f22");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
641 case VK_F23: return KEYSYM ("f23");
6c0ae1f9357f Import from CVS: tag r20-4b9
cvs
parents: 219
diff changeset
642 case VK_F24: return KEYSYM ("f24");
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
643 default:
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
644 /* Special handling for Ctrl-'@' because '@' lives shifted on varying
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
645 * virtual keys and because Windows doesn't report Ctrl-@ as a WM_CHAR */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
646 if (((mods & (MOD_SHIFT|MOD_CONTROL)) == (MOD_SHIFT|MOD_CONTROL)) &&
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
647 (mswindows_key == virtual_at_key))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
648 return make_char('@');
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
649 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
650 return Qnil;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
651 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
652
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
653
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
654 /*
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
655 * Add a timeout to the queue. Returns the id or 0 on failure
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
656 */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
657 static int mswindows_enqueue_timeout (int milliseconds)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
658 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
659 static int timeout_last_interval_id;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
660 int target_ticks = (milliseconds + MSW_TIMEOUT_GRANULARITY-1) /
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
661 MSW_TIMEOUT_GRANULARITY;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
662 mswindows_timeout *target;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
663 int i;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
664
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
665 /* Find a free timeout */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
666 for (i=0; i<MSW_TIMEOUT_MAX; i++)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
667 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
668 target = timeout_pool + i;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
669 if (target->interval_id == 0)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
670 break;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
671 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
672
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
673 /* No free timeout */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
674 if (i==MSW_TIMEOUT_MAX)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
675 return 0;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
676
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
677 if (++timeout_last_interval_id == 0)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
678 ++timeout_last_interval_id;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
679
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
680 if (timeout_head == NULL || timeout_head->ticks >= target_ticks)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
681 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
682 /* First or only timeout in the queue (common case) */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
683 target->interval_id = timeout_last_interval_id;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
684 target->ticks = target_ticks;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
685 target->next = timeout_head;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
686 timeout_head = target;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
687
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
688 if (target->next == NULL)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
689 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
690 /* Queue was empty - restart the timer */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
691 timeout_mswindows_id = SetTimer (NULL, 0, MSW_TIMEOUT_GRANULARITY,
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
692 NULL);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
693 #ifdef DEBUG_TIMEOUTS
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
694 stderr_out("Start\n");
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
695 #endif
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
696 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
697 else
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
698 target->next->ticks -= target->ticks;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
699 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
700 else
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
701 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
702 /* Find the timeout before this new one */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
703 mswindows_timeout *prev = timeout_head;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
704 int tick_count = prev->ticks; /* Number of ticks up to prev */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
705
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
706 while (prev->next != NULL)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
707 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
708 if (tick_count + prev->next->ticks >= target_ticks)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
709 break;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
710 prev = prev->next;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
711 tick_count += prev->ticks;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
712 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
713
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
714 /* Insert the new timeout in the queue */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
715 target->interval_id = timeout_last_interval_id;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
716 target->ticks = target_ticks - tick_count;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
717 target->next = prev->next;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
718 prev->next = target;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
719 if (target->next != NULL)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
720 target->next->ticks -= target->ticks;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
721 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
722 #ifdef DEBUG_TIMEOUTS
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
723 stderr_out("Set %x %d %d\n", timeout_last_interval_id, target_ticks, milliseconds);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
724 #endif
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
725 return timeout_last_interval_id;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
726 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
727
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
728
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
729 /*
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
730 * Remove a timeout from the queue
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
731 */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
732 static void mswindows_dequeue_timeout (int interval_id)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
733 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
734 mswindows_timeout *target;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
735 mswindows_timeout *prev;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
736
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
737 target = timeout_head;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
738 prev = NULL;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
739 while (target != NULL)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
740 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
741 if (target->interval_id == interval_id)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
742 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
743 #ifdef DEBUG_TIMEOUTS
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
744 stderr_out("Kil %x %d\n", interval_id, target->ticks);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
745 #endif
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
746 target->interval_id = 0; /* Mark free */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
747
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
748 if (prev!=NULL)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
749 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
750 prev->next = target->next;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
751 if (target->next != NULL)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
752 target->next->ticks += target->ticks;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
753 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
754 else if ((timeout_head = target->next) == NULL)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
755 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
756 /* Queue is now empty - stop the timer */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
757 KillTimer (NULL, timeout_mswindows_id);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
758 timeout_mswindows_id = 0;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
759 #ifdef DEBUG_TIMEOUTS
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
760 stderr_out("Stop\n");
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
761 #endif
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
762 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
763 return;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
764 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
765 else
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
766 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
767 prev = target;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
768 target = target->next;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
769 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
770 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
771
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
772 /* Ack! the timeout wasn't in the timeout queue which means that it's
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
773 * probably gone off and is now sitting in the dispatch queue. XEmacs will
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
774 * be very unhappy if it sees the timeout so we have to fish it out of the
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
775 * dispatch queue. This only happens if XEmacs can't keep up with events */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
776 #ifdef DEBUG_TIMEOUTS
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
777 stderr_out("Kil %x - not found\n", interval_id);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
778 #endif
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
779 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
780 Lisp_Object match_event, emacs_event;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
781 struct Lisp_Event *event;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
782 match_event = Fmake_event (Qnil, Qnil);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
783 event = XEVENT(match_event);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
784
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
785 event->channel = Qnil;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
786 event->event_type = timeout_event;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
787 event->event.timeout.interval_id = interval_id;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
788 emacs_event = mswindows_cancel_dispatch_event (match_event);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
789 if (!NILP (emacs_event))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
790 Fdeallocate_event(emacs_event);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
791 Fdeallocate_event(match_event);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
792 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
793 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
794
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
795
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
796 /*
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
797 * Find the console that matches the supplied mswindows window handle
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
798 */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
799 static Lisp_Object
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
800 mswindows_find_console (HWND hwnd)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
801 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
802 Lisp_Object concons;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
803
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
804 CONSOLE_LOOP (concons)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
805 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
806 Lisp_Object console = XCAR (concons);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
807 /* We only support one console so this must be it */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
808 return console;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
809 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
810
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
811 return Qnil;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
812 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
813
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
814 /*
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
815 * Find the frame that matches the supplied mswindows window handle
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
816 */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
817 static Lisp_Object
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
818 mswindows_find_frame (HWND hwnd)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
819 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
820 Lisp_Object frmcons, devcons, concons;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
821
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
822 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
823 {
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
824 struct frame *f;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
825 Lisp_Object frame = XCAR (frmcons);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
826 f = XFRAME (frame);
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
827 if (FRAME_TYPE_P(f, mswindows)) /* Might be a stream-type frame */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
828 if (FRAME_MSWINDOWS_HANDLE(f)==hwnd)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
829 return frame;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
830 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
831 assert(0); /* XXX Can't happen! we only get messages for our windows */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
832 return Qnil;
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
833 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
834
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
835
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
836 #ifdef DEBUG_XEMACS
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
837 /*
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
838 * Random helper functions for debugging.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
839 * Intended for use in the MSVC "Watch" window which doesn't like
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
840 * the aborts that the error_check_foo() functions can make.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
841 */
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
842 struct lrecord_header *DHEADER(Lisp_Object obj)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
843 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
844 return (LRECORDP (obj)) ? XRECORD_LHEADER (obj) : NULL;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
845 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
846
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
847 int DOPAQUE_DATA (Lisp_Object obj)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
848 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
849 return (OPAQUEP (obj)) ? OPAQUE_DATA (XOPAQUE (obj)) : NULL;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
850 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
851
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
852 struct Lisp_Event *DEVENT(Lisp_Object obj)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
853 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
854 return (EVENTP (obj)) ? XEVENT (obj) : NULL;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
855 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
856
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
857 struct Lisp_Cons *DCONS(Lisp_Object obj)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
858 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
859 return (CONSP (obj)) ? XCONS (obj) : NULL;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
860 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
861
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
862 Lisp_Object DCAR(Lisp_Object obj)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
863 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
864 return (CONSP (obj)) ? XCAR (obj) : 0;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
865 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
866
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
867 Lisp_Object DCDR(Lisp_Object obj)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
868 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
869 return (CONSP (obj)) ? XCDR (obj) : 0;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
870 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
871
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
872 Lisp_Object DCONSCDR(Lisp_Object obj)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
873 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
874 return ((CONSP (obj)) && (CONSP (XCDR (obj)))) ? XCONS (XCDR (obj)) : 0;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
875 }
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
876
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
877 Lisp_Object DCARCDR(Lisp_Object obj)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
878 {
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
879 return ((CONSP (obj)) && (CONSP (XCDR (obj)))) ? XCAR (XCDR (obj)) : 0;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
880 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
881
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
882 char *DSTRING(Lisp_Object obj)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
883 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
884 return (STRINGP (obj)) ? XSTRING_DATA (obj) : NULL;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
885 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
886
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
887 struct Lisp_Vector *DVECTOR(Lisp_Object obj)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
888 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
889 return (VECTORP (obj)) ? XVECTOR (obj) : NULL;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
890 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
891
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
892 struct Lisp_Symbol *DSYMBOL(Lisp_Object obj)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
893 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
894 return (SYMBOLP (obj)) ? XSYMBOL (obj) : NULL;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
895 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
896
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
897 char *DSYMNAME(Lisp_Object obj)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
898 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
899 return (SYMBOLP (obj)) ? XSYMBOL (obj)->name->_data : NULL;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents:
diff changeset
900 }
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
901
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
902 #endif