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)
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. */
26 #include "blockinput.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
;
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
);
50 DeleteCriticalSection (&critsect
);
54 CloseHandle (input_available
);
55 input_available
= NULL
;
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
);
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
));
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. */
88 get_frame_dc (FRAME_PTR f
)
94 hdc
= GetDC (f
->output_data
.win32
->window_desc
);
95 select_palette (f
, hdc
);
101 release_frame_dc (FRAME_PTR f
, HDC hdc
)
105 deselect_palette (f
, hdc
);
106 ret
= ReleaseDC (f
->output_data
.win32
->window_desc
, hdc
);
113 typedef struct int_msg
116 struct int_msg
*lpNext
;
119 int_msg
*lpHead
= NULL
;
120 int_msg
*lpTail
= NULL
;
124 get_next_msg (lpmsg
, bWait
)
132 /* The while loop takes care of multiple sets */
134 while (!nQueue
&& bWait
)
137 WaitForSingleObject (input_available
, INFINITE
);
143 bcopy (&(lpHead
->w32msg
), lpmsg
, sizeof (Win32Msg
));
146 int_msg
* lpCur
= lpHead
;
148 lpHead
= lpHead
->lpNext
;
159 ResetEvent (input_available
);
170 int_msg
* lpNew
= (int_msg
*) myalloc (sizeof (int_msg
));
175 bcopy (lpmsg
, &(lpNew
->w32msg
), sizeof (Win32Msg
));
176 lpNew
->lpNext
= NULL
;
182 lpTail
->lpNext
= lpNew
;
190 SetEvent (input_available
);
198 prepend_msg (Win32Msg
*lpmsg
)
200 int_msg
* lpNew
= (int_msg
*) myalloc (sizeof (int_msg
));
205 bcopy (lpmsg
, &(lpNew
->w32msg
), sizeof (Win32Msg
));
210 lpNew
->lpNext
= lpHead
;
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.
231 read_integer (string
, NextString
)
232 register char *string
;
235 register int Result
= 0;
240 else if (*string
== '-')
245 for (; (*string
>= '0') && (*string
<= '9'); string
++)
247 Result
= (Result
* 10) + (*string
- '0');
249 *NextString
= string
;
257 XParseGeometry (string
, x
, y
, width
, height
)
260 unsigned int *width
, *height
; /* RETURN */
263 register char *strind
;
264 unsigned int tempWidth
, tempHeight
;
268 if ((string
== NULL
) || (*string
== '\0')) return (mask
);
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
)
278 strind
= nextCharacter
;
282 if (*strind
== 'x' || *strind
== 'X')
285 tempHeight
= read_integer (strind
, &nextCharacter
);
286 if (strind
== nextCharacter
)
288 strind
= nextCharacter
;
292 if ((*strind
== '+') || (*strind
== '-'))
297 tempX
= -read_integer (strind
, &nextCharacter
);
298 if (strind
== nextCharacter
)
300 strind
= nextCharacter
;
307 tempX
= read_integer (strind
, &nextCharacter
);
308 if (strind
== nextCharacter
)
310 strind
= nextCharacter
;
313 if ((*strind
== '+') || (*strind
== '-'))
318 tempY
= -read_integer (strind
, &nextCharacter
);
319 if (strind
== nextCharacter
)
321 strind
= nextCharacter
;
328 tempY
= read_integer (strind
, &nextCharacter
);
329 if (strind
== nextCharacter
)
331 strind
= nextCharacter
;
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);
346 if (mask
& WidthValue
)
348 if (mask
& HeightValue
)
349 *height
= tempHeight
;
353 /* We can use mouse menus when we wish. */
360 /* x_sync is a no-op on Win32. */