]> code.delx.au - gnu-emacs/blob - src/w32xfns.c
(Qinhibit_read_only): Declared.
[gnu-emacs] / src / w32xfns.c
1 /* Functions taken directly from X sources
2 Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation.
3
4 This file is part of GNU Emacs.
5
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 #include <signal.h>
22 #include <config.h>
23 #include <stdio.h>
24 #include "lisp.h"
25 #include "blockinput.h"
26 #include "w32term.h"
27 #include "windowsx.h"
28
29 #define myalloc(cb) GlobalAllocPtr (GPTR, cb)
30 #define myfree(lp) GlobalFreePtr (lp)
31
32 CRITICAL_SECTION critsect;
33 extern HANDLE keyboard_handle;
34 HANDLE hEvent = NULL;
35
36 void
37 init_crit ()
38 {
39 InitializeCriticalSection (&critsect);
40 keyboard_handle = hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
41 }
42
43 void
44 enter_crit ()
45 {
46 EnterCriticalSection (&critsect);
47 }
48
49 void
50 leave_crit ()
51 {
52 LeaveCriticalSection (&critsect);
53 }
54
55 void
56 delete_crit ()
57 {
58 DeleteCriticalSection (&critsect);
59 if (hEvent)
60 {
61 CloseHandle (hEvent);
62 hEvent = NULL;
63 }
64 }
65
66 typedef struct int_msg
67 {
68 Win32Msg w32msg;
69 struct int_msg *lpNext;
70 } int_msg;
71
72 int_msg *lpHead = NULL;
73 int_msg *lpTail = NULL;
74 int nQueue = 0;
75
76 BOOL
77 get_next_msg (lpmsg, bWait)
78 Win32Msg * lpmsg;
79 BOOL bWait;
80 {
81 BOOL bRet = FALSE;
82
83 enter_crit ();
84
85 /* The while loop takes care of multiple sets */
86
87 while (!nQueue && bWait)
88 {
89 leave_crit ();
90 WaitForSingleObject (hEvent, INFINITE);
91 enter_crit ();
92 }
93
94 if (nQueue)
95 {
96 bcopy (&(lpHead->w32msg), lpmsg, sizeof (Win32Msg));
97
98 {
99 int_msg * lpCur = lpHead;
100
101 lpHead = lpHead->lpNext;
102
103 myfree (lpCur);
104 }
105
106 nQueue--;
107
108 bRet = TRUE;
109 }
110
111 leave_crit ();
112
113 return (bRet);
114 }
115
116 BOOL
117 post_msg (lpmsg)
118 Win32Msg * lpmsg;
119 {
120 int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg));
121
122 if (!lpNew) return (FALSE);
123
124 bcopy (lpmsg, &(lpNew->w32msg), sizeof (Win32Msg));
125 lpNew->lpNext = NULL;
126
127 enter_crit ();
128
129 if (nQueue++)
130 {
131 lpTail->lpNext = lpNew;
132 }
133 else
134 {
135 lpHead = lpNew;
136 SetEvent (hEvent);
137 }
138
139 lpTail = lpNew;
140
141 leave_crit ();
142
143 return (TRUE);
144 }
145
146 BOOL
147 prepend_msg (Win32Msg *lpmsg)
148 {
149 int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg));
150
151 if (!lpNew)
152 return (FALSE);
153
154 bcopy (lpmsg, &(lpNew->w32msg), sizeof (Win32Msg));
155
156 enter_crit ();
157
158 nQueue++;
159 lpNew->lpNext = lpHead;
160 lpHead = lpNew;
161
162 leave_crit ();
163
164 return (TRUE);
165 }
166
167 /*
168 * XParseGeometry parses strings of the form
169 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
170 * width, height, xoffset, and yoffset are unsigned integers.
171 * Example: "=80x24+300-49"
172 * The equal sign is optional.
173 * It returns a bitmask that indicates which of the four values
174 * were actually found in the string. For each value found,
175 * the corresponding argument is updated; for each value
176 * not found, the corresponding argument is left unchanged.
177 */
178
179 static int
180 read_integer (string, NextString)
181 register char *string;
182 char **NextString;
183 {
184 register int Result = 0;
185 int Sign = 1;
186
187 if (*string == '+')
188 string++;
189 else if (*string == '-')
190 {
191 string++;
192 Sign = -1;
193 }
194 for (; (*string >= '0') && (*string <= '9'); string++)
195 {
196 Result = (Result * 10) + (*string - '0');
197 }
198 *NextString = string;
199 if (Sign >= 0)
200 return (Result);
201 else
202 return (-Result);
203 }
204
205 int
206 XParseGeometry (string, x, y, width, height)
207 char *string;
208 int *x, *y;
209 unsigned int *width, *height; /* RETURN */
210 {
211 int mask = NoValue;
212 register char *strind;
213 unsigned int tempWidth, tempHeight;
214 int tempX, tempY;
215 char *nextCharacter;
216
217 if ((string == NULL) || (*string == '\0')) return (mask);
218 if (*string == '=')
219 string++; /* ignore possible '=' at beg of geometry spec */
220
221 strind = (char *)string;
222 if (*strind != '+' && *strind != '-' && *strind != 'x')
223 {
224 tempWidth = read_integer (strind, &nextCharacter);
225 if (strind == nextCharacter)
226 return (0);
227 strind = nextCharacter;
228 mask |= WidthValue;
229 }
230
231 if (*strind == 'x' || *strind == 'X')
232 {
233 strind++;
234 tempHeight = read_integer (strind, &nextCharacter);
235 if (strind == nextCharacter)
236 return (0);
237 strind = nextCharacter;
238 mask |= HeightValue;
239 }
240
241 if ((*strind == '+') || (*strind == '-'))
242 {
243 if (*strind == '-')
244 {
245 strind++;
246 tempX = -read_integer (strind, &nextCharacter);
247 if (strind == nextCharacter)
248 return (0);
249 strind = nextCharacter;
250 mask |= XNegative;
251
252 }
253 else
254 {
255 strind++;
256 tempX = read_integer (strind, &nextCharacter);
257 if (strind == nextCharacter)
258 return (0);
259 strind = nextCharacter;
260 }
261 mask |= XValue;
262 if ((*strind == '+') || (*strind == '-'))
263 {
264 if (*strind == '-')
265 {
266 strind++;
267 tempY = -read_integer (strind, &nextCharacter);
268 if (strind == nextCharacter)
269 return (0);
270 strind = nextCharacter;
271 mask |= YNegative;
272
273 }
274 else
275 {
276 strind++;
277 tempY = read_integer (strind, &nextCharacter);
278 if (strind == nextCharacter)
279 return (0);
280 strind = nextCharacter;
281 }
282 mask |= YValue;
283 }
284 }
285
286 /* If strind isn't at the end of the string the it's an invalid
287 geometry specification. */
288
289 if (*strind != '\0') return (0);
290
291 if (mask & XValue)
292 *x = tempX;
293 if (mask & YValue)
294 *y = tempY;
295 if (mask & WidthValue)
296 *width = tempWidth;
297 if (mask & HeightValue)
298 *height = tempHeight;
299 return (mask);
300 }
301
302 /* We can use mouse menus when we wish. */
303 int
304 have_menus_p (void)
305 {
306 return 1;
307 }
308
309 /* x_sync is a no-op on Win32. */
310 void
311 x_sync (f)
312 void *f;
313 {
314 }
315