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
[ CRIT_TOTAL
];
34 extern HANDLE keyboard_handle
;
35 HANDLE h_input_available
= NULL
;
42 for (i
= 0; i
< CRIT_TOTAL
; i
++)
43 InitializeCriticalSection (&critsect
[i
]);
44 /* For safety, h_input_available should only be reset by get_next_msg
45 when the input queue is empty, so make it a manual reset event. */
46 keyboard_handle
= h_input_available
= CreateEvent (NULL
, TRUE
, FALSE
, NULL
);
54 for (i
= 0; i
< CRIT_TOTAL
; i
++)
55 DeleteCriticalSection (&critsect
[i
]);
56 if (h_input_available
)
58 CloseHandle (h_input_available
);
59 h_input_available
= NULL
;
63 /* Get a DC for frame and select palette for drawing; force an update of
64 all frames if palette's mapping changes. */
66 GetFrameDC (FRAME_PTR f
)
70 enter_crit (CRIT_GDI
);
72 hDC
= GetDC (f
->output_data
.win32
->window_desc
);
74 if (!NILP (Vwin32_enable_palette
))
75 f
->output_data
.win32
->h_old_palette
=
76 SelectPalette (hDC
, one_win32_display_info
.h_palette
, FALSE
);
78 f
->output_data
.win32
->h_old_palette
= NULL
;
80 if (RealizePalette (hDC
))
82 Lisp_Object frame
, framelist
;
83 FOR_EACH_FRAME (framelist
, frame
)
85 SET_FRAME_GARBAGED (XFRAME (frame
));
93 ReleaseFrameDC (FRAME_PTR f
, HDC hDC
)
97 if (f
->output_data
.win32
->h_old_palette
)
98 SelectPalette (hDC
, f
->output_data
.win32
->h_old_palette
, FALSE
);
100 ret
= ReleaseDC (f
->output_data
.win32
->window_desc
, hDC
);
102 leave_crit (CRIT_GDI
);
107 typedef struct int_msg
110 struct int_msg
*lpNext
;
113 int_msg
*lpHead
= NULL
;
114 int_msg
*lpTail
= NULL
;
118 get_next_msg (lpmsg
, bWait
)
124 enter_crit (CRIT_MSG
);
126 /* The while loop takes care of multiple sets */
128 while (!nQueue
&& bWait
)
130 leave_crit (CRIT_MSG
);
131 WaitForSingleObject (h_input_available
, INFINITE
);
132 enter_crit (CRIT_MSG
);
137 bcopy (&(lpHead
->w32msg
), lpmsg
, sizeof (Win32Msg
));
140 int_msg
* lpCur
= lpHead
;
142 lpHead
= lpHead
->lpNext
;
153 ResetEvent (h_input_available
);
155 leave_crit (CRIT_MSG
);
164 int_msg
* lpNew
= (int_msg
*) myalloc (sizeof (int_msg
));
169 bcopy (lpmsg
, &(lpNew
->w32msg
), sizeof (Win32Msg
));
170 lpNew
->lpNext
= NULL
;
172 enter_crit (CRIT_MSG
);
175 lpTail
->lpNext
= lpNew
;
180 SetEvent (h_input_available
);
182 leave_crit (CRIT_MSG
);
188 * XParseGeometry parses strings of the form
189 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
190 * width, height, xoffset, and yoffset are unsigned integers.
191 * Example: "=80x24+300-49"
192 * The equal sign is optional.
193 * It returns a bitmask that indicates which of the four values
194 * were actually found in the string. For each value found,
195 * the corresponding argument is updated; for each value
196 * not found, the corresponding argument is left unchanged.
200 read_integer (string
, NextString
)
201 register char *string
;
204 register int Result
= 0;
209 else if (*string
== '-')
214 for (; (*string
>= '0') && (*string
<= '9'); string
++)
216 Result
= (Result
* 10) + (*string
- '0');
218 *NextString
= string
;
226 XParseGeometry (string
, x
, y
, width
, height
)
229 unsigned int *width
, *height
; /* RETURN */
232 register char *strind
;
233 unsigned int tempWidth
, tempHeight
;
237 if ((string
== NULL
) || (*string
== '\0')) return (mask
);
239 string
++; /* ignore possible '=' at beg of geometry spec */
241 strind
= (char *)string
;
242 if (*strind
!= '+' && *strind
!= '-' && *strind
!= 'x')
244 tempWidth
= read_integer (strind
, &nextCharacter
);
245 if (strind
== nextCharacter
)
247 strind
= nextCharacter
;
251 if (*strind
== 'x' || *strind
== 'X')
254 tempHeight
= read_integer (strind
, &nextCharacter
);
255 if (strind
== nextCharacter
)
257 strind
= nextCharacter
;
261 if ((*strind
== '+') || (*strind
== '-'))
266 tempX
= -read_integer (strind
, &nextCharacter
);
267 if (strind
== nextCharacter
)
269 strind
= nextCharacter
;
276 tempX
= read_integer (strind
, &nextCharacter
);
277 if (strind
== nextCharacter
)
279 strind
= nextCharacter
;
282 if ((*strind
== '+') || (*strind
== '-'))
287 tempY
= -read_integer (strind
, &nextCharacter
);
288 if (strind
== nextCharacter
)
290 strind
= nextCharacter
;
297 tempY
= read_integer (strind
, &nextCharacter
);
298 if (strind
== nextCharacter
)
300 strind
= nextCharacter
;
306 /* If strind isn't at the end of the string the it's an invalid
307 geometry specification. */
309 if (*strind
!= '\0') return (0);
315 if (mask
& WidthValue
)
317 if (mask
& HeightValue
)
318 *height
= tempHeight
;
322 /* We can use mouse menus when we wish. */
329 /* x_sync is a no-op on Win32. */