(REL_ALLOC): #undef deleted.
[emacs.git] / src / w32xfns.c
blob3898ff00d8f7f75027ee85b52168ea7a6d9a1a5f
1 /* Functions taken directly from X sources
2 Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation.
4 This file is part of GNU Emacs.
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.
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.
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. */
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"
29 #define myalloc(cb) GlobalAllocPtr (GPTR, cb)
30 #define myfree(lp) GlobalFreePtr (lp)
32 CRITICAL_SECTION critsect;
33 extern HANDLE keyboard_handle;
34 HANDLE hEvent = NULL;
36 void
37 init_crit ()
39 InitializeCriticalSection (&critsect);
40 keyboard_handle = hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
43 void
44 enter_crit ()
46 EnterCriticalSection (&critsect);
49 void
50 leave_crit ()
52 LeaveCriticalSection (&critsect);
55 void
56 delete_crit ()
58 DeleteCriticalSection (&critsect);
59 if (hEvent)
61 CloseHandle (hEvent);
62 hEvent = NULL;
66 typedef struct int_msg
68 Win32Msg w32msg;
69 struct int_msg *lpNext;
70 } int_msg;
72 int_msg *lpHead = NULL;
73 int_msg *lpTail = NULL;
74 int nQueue = 0;
76 BOOL
77 get_next_msg (lpmsg, bWait)
78 Win32Msg * lpmsg;
79 BOOL bWait;
81 BOOL bRet = FALSE;
83 enter_crit ();
85 /* The while loop takes care of multiple sets */
87 while (!nQueue && bWait)
89 leave_crit ();
90 WaitForSingleObject (hEvent, INFINITE);
91 enter_crit ();
94 if (nQueue)
96 bcopy (&(lpHead->w32msg), lpmsg, sizeof (Win32Msg));
99 int_msg * lpCur = lpHead;
101 lpHead = lpHead->lpNext;
103 myfree (lpCur);
106 nQueue--;
108 bRet = TRUE;
111 leave_crit ();
113 return (bRet);
116 BOOL
117 post_msg (lpmsg)
118 Win32Msg * lpmsg;
120 int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg));
122 if (!lpNew) return (FALSE);
124 bcopy (lpmsg, &(lpNew->w32msg), sizeof (Win32Msg));
125 lpNew->lpNext = NULL;
127 enter_crit ();
129 if (nQueue++)
131 lpTail->lpNext = lpNew;
133 else
135 lpHead = lpNew;
136 SetEvent (hEvent);
139 lpTail = lpNew;
141 leave_crit ();
143 return (TRUE);
146 BOOL
147 prepend_msg (Win32Msg *lpmsg)
149 int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg));
151 if (!lpNew)
152 return (FALSE);
154 bcopy (lpmsg, &(lpNew->w32msg), sizeof (Win32Msg));
156 enter_crit ();
158 nQueue++;
159 lpNew->lpNext = lpHead;
160 lpHead = lpNew;
162 leave_crit ();
164 return (TRUE);
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.
179 static int
180 read_integer (string, NextString)
181 register char *string;
182 char **NextString;
184 register int Result = 0;
185 int Sign = 1;
187 if (*string == '+')
188 string++;
189 else if (*string == '-')
191 string++;
192 Sign = -1;
194 for (; (*string >= '0') && (*string <= '9'); string++)
196 Result = (Result * 10) + (*string - '0');
198 *NextString = string;
199 if (Sign >= 0)
200 return (Result);
201 else
202 return (-Result);
205 int
206 XParseGeometry (string, x, y, width, height)
207 char *string;
208 int *x, *y;
209 unsigned int *width, *height; /* RETURN */
211 int mask = NoValue;
212 register char *strind;
213 unsigned int tempWidth, tempHeight;
214 int tempX, tempY;
215 char *nextCharacter;
217 if ((string == NULL) || (*string == '\0')) return (mask);
218 if (*string == '=')
219 string++; /* ignore possible '=' at beg of geometry spec */
221 strind = (char *)string;
222 if (*strind != '+' && *strind != '-' && *strind != 'x')
224 tempWidth = read_integer (strind, &nextCharacter);
225 if (strind == nextCharacter)
226 return (0);
227 strind = nextCharacter;
228 mask |= WidthValue;
231 if (*strind == 'x' || *strind == 'X')
233 strind++;
234 tempHeight = read_integer (strind, &nextCharacter);
235 if (strind == nextCharacter)
236 return (0);
237 strind = nextCharacter;
238 mask |= HeightValue;
241 if ((*strind == '+') || (*strind == '-'))
243 if (*strind == '-')
245 strind++;
246 tempX = -read_integer (strind, &nextCharacter);
247 if (strind == nextCharacter)
248 return (0);
249 strind = nextCharacter;
250 mask |= XNegative;
253 else
255 strind++;
256 tempX = read_integer (strind, &nextCharacter);
257 if (strind == nextCharacter)
258 return (0);
259 strind = nextCharacter;
261 mask |= XValue;
262 if ((*strind == '+') || (*strind == '-'))
264 if (*strind == '-')
266 strind++;
267 tempY = -read_integer (strind, &nextCharacter);
268 if (strind == nextCharacter)
269 return (0);
270 strind = nextCharacter;
271 mask |= YNegative;
274 else
276 strind++;
277 tempY = read_integer (strind, &nextCharacter);
278 if (strind == nextCharacter)
279 return (0);
280 strind = nextCharacter;
282 mask |= YValue;
286 /* If strind isn't at the end of the string the it's an invalid
287 geometry specification. */
289 if (*strind != '\0') return (0);
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);
302 /* We can use mouse menus when we wish. */
304 have_menus_p (void)
306 return 1;
309 /* x_sync is a no-op on Win32. */
310 void
311 x_sync (f)
312 void *f;