(server-visit-files): New argument NOWAIT.
[emacs.git] / src / w32xfns.c
blob24bbf6c7df43e9f408ec88a34d9a2a69263576a2
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 "frame.h"
26 #include "blockinput.h"
27 #include "w32term.h"
28 #include "windowsx.h"
30 #define myalloc(cb) GlobalAllocPtr (GPTR, cb)
31 #define myfree(lp) GlobalFreePtr (lp)
33 CRITICAL_SECTION critsect;
34 extern HANDLE keyboard_handle;
35 HANDLE input_available = NULL;
37 void
38 init_crit ()
40 InitializeCriticalSection (&critsect);
42 /* For safety, input_available should only be reset by get_next_msg
43 when the input queue is empty, so make it a manual reset event. */
44 keyboard_handle = input_available = CreateEvent (NULL, TRUE, FALSE, NULL);
47 void
48 delete_crit ()
50 DeleteCriticalSection (&critsect);
52 if (input_available)
54 CloseHandle (input_available);
55 input_available = NULL;
59 void
60 select_palette (FRAME_PTR f, HDC hdc)
62 if (!NILP (Vwin32_enable_palette))
63 f->output_data.win32->old_palette =
64 SelectPalette (hdc, one_win32_display_info.palette, FALSE);
65 else
66 f->output_data.win32->old_palette = NULL;
68 if (RealizePalette (hdc))
70 Lisp_Object frame, framelist;
71 FOR_EACH_FRAME (framelist, frame)
73 SET_FRAME_GARBAGED (XFRAME (frame));
78 void
79 deselect_palette (FRAME_PTR f, HDC hdc)
81 if (f->output_data.win32->old_palette)
82 SelectPalette (hdc, f->output_data.win32->old_palette, FALSE);
85 /* Get a DC for frame and select palette for drawing; force an update of
86 all frames if palette's mapping changes. */
87 HDC
88 get_frame_dc (FRAME_PTR f)
90 HDC hdc;
92 enter_crit ();
94 hdc = GetDC (f->output_data.win32->window_desc);
95 select_palette (f, hdc);
97 return hdc;
101 release_frame_dc (FRAME_PTR f, HDC hdc)
103 int ret;
105 deselect_palette (f, hdc);
106 ret = ReleaseDC (f->output_data.win32->window_desc, hdc);
108 leave_crit ();
110 return ret;
113 typedef struct int_msg
115 Win32Msg w32msg;
116 struct int_msg *lpNext;
117 } int_msg;
119 int_msg *lpHead = NULL;
120 int_msg *lpTail = NULL;
121 int nQueue = 0;
123 BOOL
124 get_next_msg (lpmsg, bWait)
125 Win32Msg * lpmsg;
126 BOOL bWait;
128 BOOL bRet = FALSE;
130 enter_crit ();
132 /* The while loop takes care of multiple sets */
134 while (!nQueue && bWait)
136 leave_crit ();
137 WaitForSingleObject (input_available, INFINITE);
138 enter_crit ();
141 if (nQueue)
143 bcopy (&(lpHead->w32msg), lpmsg, sizeof (Win32Msg));
146 int_msg * lpCur = lpHead;
148 lpHead = lpHead->lpNext;
150 myfree (lpCur);
153 nQueue--;
155 bRet = TRUE;
158 if (nQueue == 0)
159 ResetEvent (input_available);
161 leave_crit ();
163 return (bRet);
166 BOOL
167 post_msg (lpmsg)
168 Win32Msg * lpmsg;
170 int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg));
172 if (!lpNew)
173 return (FALSE);
175 bcopy (lpmsg, &(lpNew->w32msg), sizeof (Win32Msg));
176 lpNew->lpNext = NULL;
178 enter_crit ();
180 if (nQueue++)
182 lpTail->lpNext = lpNew;
184 else
186 lpHead = lpNew;
189 lpTail = lpNew;
190 SetEvent (input_available);
192 leave_crit ();
194 return (TRUE);
197 BOOL
198 prepend_msg (Win32Msg *lpmsg)
200 int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg));
202 if (!lpNew)
203 return (FALSE);
205 bcopy (lpmsg, &(lpNew->w32msg), sizeof (Win32Msg));
207 enter_crit ();
209 nQueue++;
210 lpNew->lpNext = lpHead;
211 lpHead = lpNew;
213 leave_crit ();
215 return (TRUE);
219 * XParseGeometry parses strings of the form
220 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
221 * width, height, xoffset, and yoffset are unsigned integers.
222 * Example: "=80x24+300-49"
223 * The equal sign is optional.
224 * It returns a bitmask that indicates which of the four values
225 * were actually found in the string. For each value found,
226 * the corresponding argument is updated; for each value
227 * not found, the corresponding argument is left unchanged.
230 static int
231 read_integer (string, NextString)
232 register char *string;
233 char **NextString;
235 register int Result = 0;
236 int Sign = 1;
238 if (*string == '+')
239 string++;
240 else if (*string == '-')
242 string++;
243 Sign = -1;
245 for (; (*string >= '0') && (*string <= '9'); string++)
247 Result = (Result * 10) + (*string - '0');
249 *NextString = string;
250 if (Sign >= 0)
251 return (Result);
252 else
253 return (-Result);
256 int
257 XParseGeometry (string, x, y, width, height)
258 char *string;
259 int *x, *y;
260 unsigned int *width, *height; /* RETURN */
262 int mask = NoValue;
263 register char *strind;
264 unsigned int tempWidth, tempHeight;
265 int tempX, tempY;
266 char *nextCharacter;
268 if ((string == NULL) || (*string == '\0')) return (mask);
269 if (*string == '=')
270 string++; /* ignore possible '=' at beg of geometry spec */
272 strind = (char *)string;
273 if (*strind != '+' && *strind != '-' && *strind != 'x')
275 tempWidth = read_integer (strind, &nextCharacter);
276 if (strind == nextCharacter)
277 return (0);
278 strind = nextCharacter;
279 mask |= WidthValue;
282 if (*strind == 'x' || *strind == 'X')
284 strind++;
285 tempHeight = read_integer (strind, &nextCharacter);
286 if (strind == nextCharacter)
287 return (0);
288 strind = nextCharacter;
289 mask |= HeightValue;
292 if ((*strind == '+') || (*strind == '-'))
294 if (*strind == '-')
296 strind++;
297 tempX = -read_integer (strind, &nextCharacter);
298 if (strind == nextCharacter)
299 return (0);
300 strind = nextCharacter;
301 mask |= XNegative;
304 else
306 strind++;
307 tempX = read_integer (strind, &nextCharacter);
308 if (strind == nextCharacter)
309 return (0);
310 strind = nextCharacter;
312 mask |= XValue;
313 if ((*strind == '+') || (*strind == '-'))
315 if (*strind == '-')
317 strind++;
318 tempY = -read_integer (strind, &nextCharacter);
319 if (strind == nextCharacter)
320 return (0);
321 strind = nextCharacter;
322 mask |= YNegative;
325 else
327 strind++;
328 tempY = read_integer (strind, &nextCharacter);
329 if (strind == nextCharacter)
330 return (0);
331 strind = nextCharacter;
333 mask |= YValue;
337 /* If strind isn't at the end of the string the it's an invalid
338 geometry specification. */
340 if (*strind != '\0') return (0);
342 if (mask & XValue)
343 *x = tempX;
344 if (mask & YValue)
345 *y = tempY;
346 if (mask & WidthValue)
347 *width = tempWidth;
348 if (mask & HeightValue)
349 *height = tempHeight;
350 return (mask);
353 /* We can use mouse menus when we wish. */
355 have_menus_p (void)
357 return 1;
360 /* x_sync is a no-op on Win32. */
361 void
362 x_sync (f)
363 void *f;