(have_menus_p): Renamed from using_x_p.
[bpt/emacs.git] / 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #include <signal.h>
21 #include <config.h>
22 #include <stdio.h>
23 #include "lisp.h"
24 #include "blockinput.h"
25 #include "w32term.h"
26 #include "windowsx.h"
27
28 #define myalloc(cb) GlobalAllocPtr (GPTR, cb)
29 #define myfree(lp) GlobalFreePtr (lp)
30
31 CRITICAL_SECTION critsect;
32 extern HANDLE keyboard_handle;
33 HANDLE hEvent = NULL;
34
35 void
36 init_crit ()
37 {
38 InitializeCriticalSection (&critsect);
39 keyboard_handle = hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
40 }
41
42 void
43 enter_crit ()
44 {
45 EnterCriticalSection (&critsect);
46 }
47
48 void
49 leave_crit ()
50 {
51 LeaveCriticalSection (&critsect);
52 }
53
54 void
55 delete_crit ()
56 {
57 DeleteCriticalSection (&critsect);
58 if (hEvent)
59 {
60 CloseHandle (hEvent);
61 hEvent = NULL;
62 }
63 }
64
65 typedef struct int_msg
66 {
67 Win32Msg w32msg;
68 struct int_msg *lpNext;
69 } int_msg;
70
71 int_msg *lpHead = NULL;
72 int_msg *lpTail = NULL;
73 int nQueue = 0;
74
75 BOOL
76 get_next_msg (lpmsg, bWait)
77 Win32Msg * lpmsg;
78 BOOL bWait;
79 {
80 BOOL bRet = FALSE;
81
82 enter_crit ();
83
84 /* The while loop takes care of multiple sets */
85
86 while (!nQueue && bWait)
87 {
88 leave_crit ();
89 WaitForSingleObject (hEvent, INFINITE);
90 enter_crit ();
91 }
92
93 if (nQueue)
94 {
95 bcopy (&(lpHead->w32msg), lpmsg, sizeof (Win32Msg));
96
97 {
98 int_msg * lpCur = lpHead;
99
100 lpHead = lpHead->lpNext;
101
102 myfree (lpCur);
103 }
104
105 nQueue--;
106
107 bRet = TRUE;
108 }
109
110 leave_crit ();
111
112 return (bRet);
113 }
114
115 BOOL
116 post_msg (lpmsg)
117 Win32Msg * lpmsg;
118 {
119 int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg));
120
121 if (!lpNew) return (FALSE);
122
123 bcopy (lpmsg, &(lpNew->w32msg), sizeof (Win32Msg));
124 lpNew->lpNext = NULL;
125
126 enter_crit ();
127
128 if (nQueue++)
129 {
130 lpTail->lpNext = lpNew;
131 }
132 else
133 {
134 lpHead = lpNew;
135 SetEvent (hEvent);
136 }
137
138 lpTail = lpNew;
139
140 leave_crit ();
141
142 return (TRUE);
143 }
144
145 /*
146 * XParseGeometry parses strings of the form
147 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
148 * width, height, xoffset, and yoffset are unsigned integers.
149 * Example: "=80x24+300-49"
150 * The equal sign is optional.
151 * It returns a bitmask that indicates which of the four values
152 * were actually found in the string. For each value found,
153 * the corresponding argument is updated; for each value
154 * not found, the corresponding argument is left unchanged.
155 */
156
157 static int
158 read_integer (string, NextString)
159 register char *string;
160 char **NextString;
161 {
162 register int Result = 0;
163 int Sign = 1;
164
165 if (*string == '+')
166 string++;
167 else if (*string == '-')
168 {
169 string++;
170 Sign = -1;
171 }
172 for (; (*string >= '0') && (*string <= '9'); string++)
173 {
174 Result = (Result * 10) + (*string - '0');
175 }
176 *NextString = string;
177 if (Sign >= 0)
178 return (Result);
179 else
180 return (-Result);
181 }
182
183 int
184 XParseGeometry (string, x, y, width, height)
185 char *string;
186 int *x, *y;
187 unsigned int *width, *height; /* RETURN */
188 {
189 int mask = NoValue;
190 register char *strind;
191 unsigned int tempWidth, tempHeight;
192 int tempX, tempY;
193 char *nextCharacter;
194
195 if ((string == NULL) || (*string == '\0')) return (mask);
196 if (*string == '=')
197 string++; /* ignore possible '=' at beg of geometry spec */
198
199 strind = (char *)string;
200 if (*strind != '+' && *strind != '-' && *strind != 'x')
201 {
202 tempWidth = read_integer (strind, &nextCharacter);
203 if (strind == nextCharacter)
204 return (0);
205 strind = nextCharacter;
206 mask |= WidthValue;
207 }
208
209 if (*strind == 'x' || *strind == 'X')
210 {
211 strind++;
212 tempHeight = read_integer (strind, &nextCharacter);
213 if (strind == nextCharacter)
214 return (0);
215 strind = nextCharacter;
216 mask |= HeightValue;
217 }
218
219 if ((*strind == '+') || (*strind == '-'))
220 {
221 if (*strind == '-')
222 {
223 strind++;
224 tempX = -read_integer (strind, &nextCharacter);
225 if (strind == nextCharacter)
226 return (0);
227 strind = nextCharacter;
228 mask |= XNegative;
229
230 }
231 else
232 {
233 strind++;
234 tempX = read_integer (strind, &nextCharacter);
235 if (strind == nextCharacter)
236 return (0);
237 strind = nextCharacter;
238 }
239 mask |= XValue;
240 if ((*strind == '+') || (*strind == '-'))
241 {
242 if (*strind == '-')
243 {
244 strind++;
245 tempY = -read_integer (strind, &nextCharacter);
246 if (strind == nextCharacter)
247 return (0);
248 strind = nextCharacter;
249 mask |= YNegative;
250
251 }
252 else
253 {
254 strind++;
255 tempY = read_integer (strind, &nextCharacter);
256 if (strind == nextCharacter)
257 return (0);
258 strind = nextCharacter;
259 }
260 mask |= YValue;
261 }
262 }
263
264 /* If strind isn't at the end of the string the it's an invalid
265 geometry specification. */
266
267 if (*strind != '\0') return (0);
268
269 if (mask & XValue)
270 *x = tempX;
271 if (mask & YValue)
272 *y = tempY;
273 if (mask & WidthValue)
274 *width = tempWidth;
275 if (mask & HeightValue)
276 *height = tempHeight;
277 return (mask);
278 }
279
280 /* We can use mouse menus when we wish. */
281 int
282 have_menus_p (void)
283 {
284 return 1;
285 }
286
287 /* x_sync is a no-op on Win32. */
288 void
289 x_sync (f)
290 void *f;
291 {
292 }
293