Don't overide default value of diary-file.
[emacs.git] / src / w32xfns.c
blobc2b1d705c9aac7410182be792a5890e5c21c73af
1 /* Functions taken directly from X sources for use with the Microsoft W32 API.
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;
36 HANDLE interrupt_handle = NULL;
38 void
39 init_crit ()
41 InitializeCriticalSection (&critsect);
43 /* For safety, input_available should only be reset by get_next_msg
44 when the input queue is empty, so make it a manual reset event. */
45 keyboard_handle = input_available = CreateEvent (NULL, TRUE, FALSE, NULL);
47 /* interrupt_handle is signalled when quit (C-g) is detected, so that
48 blocking system calls can be interrupted. We make it a manual
49 reset event, so that if we should ever have multiple threads
50 performing system calls, they will all be interrupted (I'm guessing
51 that would the right response). Note that we use PulseEvent to
52 signal this event, so that it never remains signalled. */
53 interrupt_handle = CreateEvent (NULL, TRUE, FALSE, NULL);
56 void
57 delete_crit ()
59 DeleteCriticalSection (&critsect);
61 if (input_available)
63 CloseHandle (input_available);
64 input_available = NULL;
66 if (interrupt_handle)
68 CloseHandle (interrupt_handle);
69 interrupt_handle = NULL;
73 void
74 signal_quit ()
76 /* Make sure this event never remains signalled; if the main thread
77 isn't in a blocking call, then this should do nothing. */
78 PulseEvent (interrupt_handle);
81 void
82 select_palette (FRAME_PTR f, HDC hdc)
84 if (!NILP (Vw32_enable_palette))
85 f->output_data.w32->old_palette =
86 SelectPalette (hdc, one_w32_display_info.palette, FALSE);
87 else
88 f->output_data.w32->old_palette = NULL;
90 if (RealizePalette (hdc))
92 Lisp_Object frame, framelist;
93 FOR_EACH_FRAME (framelist, frame)
95 SET_FRAME_GARBAGED (XFRAME (frame));
100 void
101 deselect_palette (FRAME_PTR f, HDC hdc)
103 if (f->output_data.w32->old_palette)
104 SelectPalette (hdc, f->output_data.w32->old_palette, FALSE);
107 /* Get a DC for frame and select palette for drawing; force an update of
108 all frames if palette's mapping changes. */
110 get_frame_dc (FRAME_PTR f)
112 HDC hdc;
114 enter_crit ();
116 hdc = GetDC (f->output_data.w32->window_desc);
117 select_palette (f, hdc);
119 return hdc;
123 release_frame_dc (FRAME_PTR f, HDC hdc)
125 int ret;
127 deselect_palette (f, hdc);
128 ret = ReleaseDC (f->output_data.w32->window_desc, hdc);
130 leave_crit ();
132 return ret;
135 typedef struct int_msg
137 W32Msg w32msg;
138 struct int_msg *lpNext;
139 } int_msg;
141 int_msg *lpHead = NULL;
142 int_msg *lpTail = NULL;
143 int nQueue = 0;
145 BOOL
146 get_next_msg (lpmsg, bWait)
147 W32Msg * lpmsg;
148 BOOL bWait;
150 BOOL bRet = FALSE;
152 enter_crit ();
154 /* The while loop takes care of multiple sets */
156 while (!nQueue && bWait)
158 leave_crit ();
159 WaitForSingleObject (input_available, INFINITE);
160 enter_crit ();
163 if (nQueue)
165 bcopy (&(lpHead->w32msg), lpmsg, sizeof (W32Msg));
168 int_msg * lpCur = lpHead;
170 lpHead = lpHead->lpNext;
172 myfree (lpCur);
175 nQueue--;
177 bRet = TRUE;
180 if (nQueue == 0)
181 ResetEvent (input_available);
183 leave_crit ();
185 return (bRet);
188 BOOL
189 post_msg (lpmsg)
190 W32Msg * lpmsg;
192 int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg));
194 if (!lpNew)
195 return (FALSE);
197 bcopy (lpmsg, &(lpNew->w32msg), sizeof (W32Msg));
198 lpNew->lpNext = NULL;
200 enter_crit ();
202 if (nQueue++)
204 lpTail->lpNext = lpNew;
206 else
208 lpHead = lpNew;
211 lpTail = lpNew;
212 SetEvent (input_available);
214 leave_crit ();
216 return (TRUE);
219 BOOL
220 prepend_msg (W32Msg *lpmsg)
222 int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg));
224 if (!lpNew)
225 return (FALSE);
227 bcopy (lpmsg, &(lpNew->w32msg), sizeof (W32Msg));
229 enter_crit ();
231 nQueue++;
232 lpNew->lpNext = lpHead;
233 lpHead = lpNew;
235 leave_crit ();
237 return (TRUE);
241 * XParseGeometry parses strings of the form
242 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
243 * width, height, xoffset, and yoffset are unsigned integers.
244 * Example: "=80x24+300-49"
245 * The equal sign is optional.
246 * It returns a bitmask that indicates which of the four values
247 * were actually found in the string. For each value found,
248 * the corresponding argument is updated; for each value
249 * not found, the corresponding argument is left unchanged.
252 static int
253 read_integer (string, NextString)
254 register char *string;
255 char **NextString;
257 register int Result = 0;
258 int Sign = 1;
260 if (*string == '+')
261 string++;
262 else if (*string == '-')
264 string++;
265 Sign = -1;
267 for (; (*string >= '0') && (*string <= '9'); string++)
269 Result = (Result * 10) + (*string - '0');
271 *NextString = string;
272 if (Sign >= 0)
273 return (Result);
274 else
275 return (-Result);
278 int
279 XParseGeometry (string, x, y, width, height)
280 char *string;
281 int *x, *y;
282 unsigned int *width, *height; /* RETURN */
284 int mask = NoValue;
285 register char *strind;
286 unsigned int tempWidth, tempHeight;
287 int tempX, tempY;
288 char *nextCharacter;
290 if ((string == NULL) || (*string == '\0')) return (mask);
291 if (*string == '=')
292 string++; /* ignore possible '=' at beg of geometry spec */
294 strind = (char *)string;
295 if (*strind != '+' && *strind != '-' && *strind != 'x')
297 tempWidth = read_integer (strind, &nextCharacter);
298 if (strind == nextCharacter)
299 return (0);
300 strind = nextCharacter;
301 mask |= WidthValue;
304 if (*strind == 'x' || *strind == 'X')
306 strind++;
307 tempHeight = read_integer (strind, &nextCharacter);
308 if (strind == nextCharacter)
309 return (0);
310 strind = nextCharacter;
311 mask |= HeightValue;
314 if ((*strind == '+') || (*strind == '-'))
316 if (*strind == '-')
318 strind++;
319 tempX = -read_integer (strind, &nextCharacter);
320 if (strind == nextCharacter)
321 return (0);
322 strind = nextCharacter;
323 mask |= XNegative;
326 else
328 strind++;
329 tempX = read_integer (strind, &nextCharacter);
330 if (strind == nextCharacter)
331 return (0);
332 strind = nextCharacter;
334 mask |= XValue;
335 if ((*strind == '+') || (*strind == '-'))
337 if (*strind == '-')
339 strind++;
340 tempY = -read_integer (strind, &nextCharacter);
341 if (strind == nextCharacter)
342 return (0);
343 strind = nextCharacter;
344 mask |= YNegative;
347 else
349 strind++;
350 tempY = read_integer (strind, &nextCharacter);
351 if (strind == nextCharacter)
352 return (0);
353 strind = nextCharacter;
355 mask |= YValue;
359 /* If strind isn't at the end of the string the it's an invalid
360 geometry specification. */
362 if (*strind != '\0') return (0);
364 if (mask & XValue)
365 *x = tempX;
366 if (mask & YValue)
367 *y = tempY;
368 if (mask & WidthValue)
369 *width = tempWidth;
370 if (mask & HeightValue)
371 *height = tempHeight;
372 return (mask);
375 /* x_sync is a no-op on W32. */
376 void
377 x_sync (f)
378 void *f;