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