(gnus-cache-enter-remove-article, gnus-cache-possibly-remove-articles):
[emacs.git] / src / w32xfns.c
blobed9c9dc036c693eec1c9d60277c4cc7f600d6359
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
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"
28 #define myalloc(cb) GlobalAllocPtr (GPTR, cb)
29 #define myfree(lp) GlobalFreePtr (lp)
31 CRITICAL_SECTION critsect;
32 extern HANDLE keyboard_handle;
33 HANDLE hEvent = NULL;
35 void
36 init_crit ()
38 InitializeCriticalSection (&critsect);
39 keyboard_handle = hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
42 void
43 enter_crit ()
45 EnterCriticalSection (&critsect);
48 void
49 leave_crit ()
51 LeaveCriticalSection (&critsect);
54 void
55 delete_crit ()
57 DeleteCriticalSection (&critsect);
58 if (hEvent)
60 CloseHandle (hEvent);
61 hEvent = NULL;
65 typedef struct int_msg
67 Win32Msg w32msg;
68 struct int_msg *lpNext;
69 } int_msg;
71 int_msg *lpHead = NULL;
72 int_msg *lpTail = NULL;
73 int nQueue = 0;
75 BOOL
76 get_next_msg (lpmsg, bWait)
77 Win32Msg * lpmsg;
78 BOOL bWait;
80 BOOL bRet = FALSE;
82 enter_crit ();
84 /* The while loop takes care of multiple sets */
86 while (!nQueue && bWait)
88 leave_crit ();
89 WaitForSingleObject (hEvent, INFINITE);
90 enter_crit ();
93 if (nQueue)
95 bcopy (&(lpHead->w32msg), lpmsg, sizeof (Win32Msg));
98 int_msg * lpCur = lpHead;
100 lpHead = lpHead->lpNext;
102 myfree (lpCur);
105 nQueue--;
107 bRet = TRUE;
110 leave_crit ();
112 return (bRet);
115 BOOL
116 post_msg (lpmsg)
117 Win32Msg * lpmsg;
119 int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg));
121 if (!lpNew) return (FALSE);
123 bcopy (lpmsg, &(lpNew->w32msg), sizeof (Win32Msg));
124 lpNew->lpNext = NULL;
126 enter_crit ();
128 if (nQueue++)
130 lpTail->lpNext = lpNew;
132 else
134 lpHead = lpNew;
135 SetEvent (hEvent);
138 lpTail = lpNew;
140 leave_crit ();
142 return (TRUE);
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.
157 static int
158 read_integer (string, NextString)
159 register char *string;
160 char **NextString;
162 register int Result = 0;
163 int Sign = 1;
165 if (*string == '+')
166 string++;
167 else if (*string == '-')
169 string++;
170 Sign = -1;
172 for (; (*string >= '0') && (*string <= '9'); string++)
174 Result = (Result * 10) + (*string - '0');
176 *NextString = string;
177 if (Sign >= 0)
178 return (Result);
179 else
180 return (-Result);
183 int
184 XParseGeometry (string, x, y, width, height)
185 char *string;
186 int *x, *y;
187 unsigned int *width, *height; /* RETURN */
189 int mask = NoValue;
190 register char *strind;
191 unsigned int tempWidth, tempHeight;
192 int tempX, tempY;
193 char *nextCharacter;
195 if ((string == NULL) || (*string == '\0')) return (mask);
196 if (*string == '=')
197 string++; /* ignore possible '=' at beg of geometry spec */
199 strind = (char *)string;
200 if (*strind != '+' && *strind != '-' && *strind != 'x')
202 tempWidth = read_integer (strind, &nextCharacter);
203 if (strind == nextCharacter)
204 return (0);
205 strind = nextCharacter;
206 mask |= WidthValue;
209 if (*strind == 'x' || *strind == 'X')
211 strind++;
212 tempHeight = read_integer (strind, &nextCharacter);
213 if (strind == nextCharacter)
214 return (0);
215 strind = nextCharacter;
216 mask |= HeightValue;
219 if ((*strind == '+') || (*strind == '-'))
221 if (*strind == '-')
223 strind++;
224 tempX = -read_integer (strind, &nextCharacter);
225 if (strind == nextCharacter)
226 return (0);
227 strind = nextCharacter;
228 mask |= XNegative;
231 else
233 strind++;
234 tempX = read_integer (strind, &nextCharacter);
235 if (strind == nextCharacter)
236 return (0);
237 strind = nextCharacter;
239 mask |= XValue;
240 if ((*strind == '+') || (*strind == '-'))
242 if (*strind == '-')
244 strind++;
245 tempY = -read_integer (strind, &nextCharacter);
246 if (strind == nextCharacter)
247 return (0);
248 strind = nextCharacter;
249 mask |= YNegative;
252 else
254 strind++;
255 tempY = read_integer (strind, &nextCharacter);
256 if (strind == nextCharacter)
257 return (0);
258 strind = nextCharacter;
260 mask |= YValue;
264 /* If strind isn't at the end of the string the it's an invalid
265 geometry specification. */
267 if (*strind != '\0') return (0);
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);
280 /* We can use mouse menus when we wish. */
282 have_menus_p (void)
284 return 1;
287 /* x_sync is a no-op on Win32. */
288 void
289 x_sync (f)
290 void *f;