Commit | Line | Data |
---|---|---|
e9e23e23 | 1 | /* Graphical user interface functions for the Microsoft W32 API. |
7c051dd8 GM |
2 | |
3 | Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, | |
5df4f04c | 4 | 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
8cabe764 | 5 | Free Software Foundation, Inc. |
ee78dc32 GV |
6 | |
7 | This file is part of GNU Emacs. | |
8 | ||
9ec0b715 | 9 | GNU Emacs is free software: you can redistribute it and/or modify |
ee78dc32 | 10 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
11 | the Free Software Foundation, either version 3 of the License, or |
12 | (at your option) any later version. | |
ee78dc32 GV |
13 | |
14 | GNU Emacs is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
9ec0b715 | 20 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
ee78dc32 GV |
21 | |
22 | /* Added by Kevin Gallo */ | |
23 | ||
ee78dc32 | 24 | #include <config.h> |
1edf84e7 GV |
25 | |
26 | #include <signal.h> | |
ee78dc32 | 27 | #include <stdio.h> |
1edf84e7 GV |
28 | #include <limits.h> |
29 | #include <errno.h> | |
b00afeae | 30 | #include <math.h> |
d7306fe6 | 31 | #include <setjmp.h> |
ee78dc32 GV |
32 | |
33 | #include "lisp.h" | |
34 | #include "w32term.h" | |
35 | #include "frame.h" | |
36 | #include "window.h" | |
37 | #include "buffer.h" | |
6fc2811b | 38 | #include "intervals.h" |
10b4bc33 JR |
39 | #include "dispextern.h" |
40 | #include "keyboard.h" | |
ee78dc32 | 41 | #include "blockinput.h" |
57bda87a | 42 | #include "epaths.h" |
10b4bc33 JR |
43 | #include "character.h" |
44 | #include "charset.h" | |
4587b026 | 45 | #include "coding.h" |
3545439c | 46 | #include "ccl.h" |
10b4bc33 | 47 | #include "fontset.h" |
6fc2811b | 48 | #include "systime.h" |
10b4bc33 JR |
49 | #include "termhooks.h" |
50 | #include "w32heap.h" | |
5cba3209 | 51 | #include "w32.h" |
6fc2811b JR |
52 | |
53 | #include "bitmaps/gray.xbm" | |
ee78dc32 | 54 | |
60860eb3 | 55 | #include <commctrl.h> |
ee78dc32 | 56 | #include <commdlg.h> |
cb9e33d4 | 57 | #include <shellapi.h> |
6fc2811b | 58 | #include <ctype.h> |
6b61353c | 59 | #include <winspool.h> |
d5781bb6 | 60 | #include <objbase.h> |
ee78dc32 | 61 | |
1030b26b | 62 | #include <dlgs.h> |
820eff5a | 63 | #include <imm.h> |
1030b26b JR |
64 | #define FILE_NAME_TEXT_FIELD edt1 |
65 | ||
a1fe5c00 | 66 | #include "font.h" |
1cc06b86 | 67 | #include "w32font.h" |
a1fe5c00 | 68 | |
6cf29fe8 JR |
69 | #ifndef FOF_NO_CONNECTED_ELEMENTS |
70 | #define FOF_NO_CONNECTED_ELEMENTS 0x2000 | |
71 | #endif | |
72 | ||
b56ceb92 JB |
73 | void syms_of_w32fns (void); |
74 | void globals_of_w32fns (void); | |
9785d95b | 75 | |
b56ceb92 JB |
76 | extern void free_frame_menubar (struct frame *); |
77 | extern double atof (const char *); | |
f57e2426 J |
78 | extern int w32_console_toggle_lock_key (int, Lisp_Object); |
79 | extern void w32_menu_display_help (HWND, HMENU, UINT, UINT); | |
80 | extern void w32_free_menu_strings (HWND); | |
81 | extern const char *map_w32_filename (const char *, const char **); | |
9eb16b62 | 82 | |
5ac45f98 | 83 | extern int quit_char; |
ee78dc32 | 84 | |
24021b38 | 85 | extern const char *const lispy_function_keys[]; |
ccc2d29c | 86 | |
d148e14d JR |
87 | /* If non-zero, a w32 timer that, when it expires, displays an |
88 | hourglass cursor on all frames. */ | |
89 | static unsigned hourglass_timer = 0; | |
90 | static HWND hourglass_hwnd = NULL; | |
91 | ||
c9b2104d JR |
92 | #ifndef IDC_HAND |
93 | #define IDC_HAND MAKEINTRESOURCE(32649) | |
94 | #endif | |
95 | ||
1edf84e7 | 96 | /* Nonzero if using Windows. */ |
dfff8a69 | 97 | |
1edf84e7 GV |
98 | static int w32_in_use; |
99 | ||
ee78dc32 | 100 | Lisp_Object Qnone; |
ee78dc32 | 101 | Lisp_Object Qsuppress_icon; |
ee78dc32 | 102 | Lisp_Object Qundefined_color; |
dc220243 | 103 | Lisp_Object Qcancel_timer; |
27129af9 | 104 | Lisp_Object Qfont_param; |
adcc3809 GV |
105 | Lisp_Object Qhyper; |
106 | Lisp_Object Qsuper; | |
107 | Lisp_Object Qmeta; | |
108 | Lisp_Object Qalt; | |
109 | Lisp_Object Qctrl; | |
110 | Lisp_Object Qcontrol; | |
111 | Lisp_Object Qshift; | |
112 | ||
dfff8a69 | 113 | |
5a8a15ec JR |
114 | /* Prefix for system colors. */ |
115 | #define SYSTEM_COLOR_PREFIX "System" | |
116 | #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1) | |
117 | ||
5ac45f98 GV |
118 | /* State variables for emulating a three button mouse. */ |
119 | #define LMOUSE 1 | |
120 | #define MMOUSE 2 | |
121 | #define RMOUSE 4 | |
122 | ||
123 | static int button_state = 0; | |
fbd6baed | 124 | static W32Msg saved_mouse_button_msg; |
48094ace | 125 | static unsigned mouse_button_timer = 0; /* non-zero when timer is active */ |
fbd6baed | 126 | static W32Msg saved_mouse_move_msg; |
48094ace | 127 | static unsigned mouse_move_timer = 0; |
84fb1139 | 128 | |
9eb16b62 JR |
129 | /* Window that is tracking the mouse. */ |
130 | static HWND track_mouse_window; | |
f60ae425 | 131 | |
64f0809d JR |
132 | /* Multi-monitor API definitions that are not pulled from the headers |
133 | since we are compiling for NT 4. */ | |
134 | #ifndef MONITOR_DEFAULT_TO_NEAREST | |
135 | #define MONITOR_DEFAULT_TO_NEAREST 2 | |
136 | #endif | |
137 | /* MinGW headers define MONITORINFO unconditionally, but MSVC ones don't. | |
138 | To avoid a compile error on one or the other, redefine with a new name. */ | |
139 | struct MONITOR_INFO | |
140 | { | |
141 | DWORD cbSize; | |
142 | RECT rcMonitor; | |
143 | RECT rcWork; | |
144 | DWORD dwFlags; | |
145 | }; | |
146 | ||
8e764ce0 | 147 | /* Reportedly, VS 6 does not have this in its headers. */ |
9d4f32e8 | 148 | #if defined (_MSC_VER) && _MSC_VER < 1300 |
8e764ce0 EZ |
149 | DECLARE_HANDLE(HMONITOR); |
150 | #endif | |
151 | ||
ccc0fdaa JR |
152 | typedef BOOL (WINAPI * TrackMouseEvent_Proc) |
153 | (IN OUT LPTRACKMOUSEEVENT lpEventTrack); | |
820eff5a JR |
154 | typedef LONG (WINAPI * ImmGetCompositionString_Proc) |
155 | (IN HIMC context, IN DWORD index, OUT LPVOID buffer, IN DWORD bufLen); | |
156 | typedef HIMC (WINAPI * ImmGetContext_Proc) (IN HWND window); | |
c902b920 JR |
157 | typedef HWND (WINAPI * ImmReleaseContext_Proc) (IN HWND wnd, IN HIMC context); |
158 | typedef HWND (WINAPI * ImmSetCompositionWindow_Proc) (IN HIMC context, | |
159 | IN COMPOSITIONFORM *form); | |
64f0809d JR |
160 | typedef HMONITOR (WINAPI * MonitorFromPoint_Proc) (IN POINT pt, IN DWORD flags); |
161 | typedef BOOL (WINAPI * GetMonitorInfo_Proc) | |
162 | (IN HMONITOR monitor, OUT struct MONITOR_INFO* info); | |
f60ae425 | 163 | |
ccc0fdaa | 164 | TrackMouseEvent_Proc track_mouse_event_fn = NULL; |
820eff5a JR |
165 | ImmGetCompositionString_Proc get_composition_string_fn = NULL; |
166 | ImmGetContext_Proc get_ime_context_fn = NULL; | |
c902b920 JR |
167 | ImmReleaseContext_Proc release_ime_context_fn = NULL; |
168 | ImmSetCompositionWindow_Proc set_ime_composition_window_fn = NULL; | |
64f0809d JR |
169 | MonitorFromPoint_Proc monitor_from_point_fn = NULL; |
170 | GetMonitorInfo_Proc get_monitor_info_fn = NULL; | |
820eff5a | 171 | |
b4005349 | 172 | extern AppendMenuW_Proc unicode_append_menu; |
9eb16b62 | 173 | |
820eff5a JR |
174 | /* Flag to selectively ignore WM_IME_CHAR messages. */ |
175 | static int ignore_ime_char = 0; | |
176 | ||
93fbe8b7 | 177 | /* W95 mousewheel handler */ |
7d0393cf | 178 | unsigned int msh_mousewheel = 0; |
93fbe8b7 | 179 | |
48094ace | 180 | /* Timers */ |
84fb1139 KH |
181 | #define MOUSE_BUTTON_ID 1 |
182 | #define MOUSE_MOVE_ID 2 | |
48094ace | 183 | #define MENU_FREE_ID 3 |
d148e14d | 184 | #define HOURGLASS_ID 4 |
48094ace JR |
185 | /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP |
186 | is received. */ | |
187 | #define MENU_FREE_DELAY 1000 | |
188 | static unsigned menu_free_timer = 0; | |
5ac45f98 | 189 | |
0682186e | 190 | extern Lisp_Object Qtooltip; |
ee78dc32 | 191 | |
937e601e AI |
192 | #ifdef GLYPH_DEBUG |
193 | int image_cache_refcount, dpyinfo_refcount; | |
194 | #endif | |
195 | ||
196 | ||
65906840 | 197 | extern HWND w32_system_caret_hwnd; |
93f2ca61 | 198 | |
65906840 JR |
199 | extern int w32_system_caret_height; |
200 | extern int w32_system_caret_x; | |
201 | extern int w32_system_caret_y; | |
d285988b | 202 | static HWND w32_visible_system_caret_hwnd; |
65906840 | 203 | |
5d22ded9 JR |
204 | /* From w32menu.c */ |
205 | extern HMENU current_popup_menu; | |
58e55497 | 206 | static int menubar_in_use = 0; |
5d22ded9 | 207 | |
cbfedb1c | 208 | /* From w32uniscribe.c */ |
b56ceb92 | 209 | extern void syms_of_w32uniscribe (void); |
cbfedb1c | 210 | extern int uniscribe_available; |
cbfedb1c | 211 | |
d148e14d | 212 | /* Function prototypes for hourglass support. */ |
f57e2426 J |
213 | static void w32_show_hourglass (struct frame *); |
214 | static void w32_hide_hourglass (void); | |
d148e14d JR |
215 | |
216 | ||
ee78dc32 | 217 | \f |
1edf84e7 GV |
218 | /* Error if we are not connected to MS-Windows. */ |
219 | void | |
b56ceb92 | 220 | check_w32 (void) |
1edf84e7 GV |
221 | { |
222 | if (! w32_in_use) | |
223 | error ("MS-Windows not in use or not initialized"); | |
224 | } | |
225 | ||
226 | /* Nonzero if we can use mouse menus. | |
227 | You should not call this unless HAVE_MENUS is defined. */ | |
7d0393cf | 228 | |
1edf84e7 | 229 | int |
b56ceb92 | 230 | have_menus_p (void) |
1edf84e7 GV |
231 | { |
232 | return w32_in_use; | |
233 | } | |
234 | ||
ee78dc32 | 235 | /* Extract a frame as a FRAME_PTR, defaulting to the selected frame |
fbd6baed | 236 | and checking validity for W32. */ |
ee78dc32 GV |
237 | |
238 | FRAME_PTR | |
b56ceb92 | 239 | check_x_frame (Lisp_Object frame) |
ee78dc32 GV |
240 | { |
241 | FRAME_PTR f; | |
242 | ||
243 | if (NILP (frame)) | |
6fc2811b | 244 | frame = selected_frame; |
b7826503 | 245 | CHECK_LIVE_FRAME (frame); |
6fc2811b | 246 | f = XFRAME (frame); |
fbd6baed | 247 | if (! FRAME_W32_P (f)) |
21517c3d | 248 | error ("Non-W32 frame used"); |
ee78dc32 GV |
249 | return f; |
250 | } | |
251 | ||
7d0393cf | 252 | /* Let the user specify a display with a frame. |
fbd6baed | 253 | nil stands for the selected frame--or, if that is not a w32 frame, |
ee78dc32 GV |
254 | the first display on the list. */ |
255 | ||
6d906347 | 256 | struct w32_display_info * |
b56ceb92 | 257 | check_x_display_info (Lisp_Object frame) |
ee78dc32 GV |
258 | { |
259 | if (NILP (frame)) | |
260 | { | |
6fc2811b | 261 | struct frame *sf = XFRAME (selected_frame); |
7d0393cf | 262 | |
6fc2811b JR |
263 | if (FRAME_W32_P (sf) && FRAME_LIVE_P (sf)) |
264 | return FRAME_W32_DISPLAY_INFO (sf); | |
ee78dc32 | 265 | else |
fbd6baed | 266 | return &one_w32_display_info; |
ee78dc32 GV |
267 | } |
268 | else if (STRINGP (frame)) | |
269 | return x_display_info_for_name (frame); | |
270 | else | |
271 | { | |
272 | FRAME_PTR f; | |
273 | ||
b7826503 | 274 | CHECK_LIVE_FRAME (frame); |
ee78dc32 | 275 | f = XFRAME (frame); |
fbd6baed | 276 | if (! FRAME_W32_P (f)) |
21517c3d | 277 | error ("Non-W32 frame used"); |
fbd6baed | 278 | return FRAME_W32_DISPLAY_INFO (f); |
ee78dc32 GV |
279 | } |
280 | } | |
281 | \f | |
fbd6baed | 282 | /* Return the Emacs frame-object corresponding to an w32 window. |
ee78dc32 GV |
283 | It could be the frame's main window or an icon window. */ |
284 | ||
285 | /* This function can be called during GC, so use GC_xxx type test macros. */ | |
286 | ||
287 | struct frame * | |
b56ceb92 | 288 | x_window_to_frame (struct w32_display_info *dpyinfo, HWND wdesc) |
ee78dc32 GV |
289 | { |
290 | Lisp_Object tail, frame; | |
291 | struct frame *f; | |
292 | ||
8e50cc2d | 293 | for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) |
ee78dc32 | 294 | { |
8e713be6 | 295 | frame = XCAR (tail); |
8e50cc2d | 296 | if (!FRAMEP (frame)) |
ee78dc32 GV |
297 | continue; |
298 | f = XFRAME (frame); | |
2d764c78 | 299 | if (!FRAME_W32_P (f) || FRAME_W32_DISPLAY_INFO (f) != dpyinfo) |
ee78dc32 | 300 | continue; |
f79e6790 | 301 | |
fbd6baed | 302 | if (FRAME_W32_WINDOW (f) == wdesc) |
ee78dc32 GV |
303 | return f; |
304 | } | |
305 | return 0; | |
306 | } | |
307 | ||
308 | \f | |
f57e2426 J |
309 | static Lisp_Object unwind_create_frame (Lisp_Object); |
310 | static Lisp_Object unwind_create_tip_frame (Lisp_Object); | |
311 | static void my_create_window (struct frame *); | |
312 | static void my_create_tip_window (struct frame *); | |
6d906347 | 313 | |
767b1ff0 | 314 | /* TODO: Native Input Method support; see x_create_im. */ |
f57e2426 J |
315 | void x_set_foreground_color (struct frame *, Lisp_Object, Lisp_Object); |
316 | void x_set_background_color (struct frame *, Lisp_Object, Lisp_Object); | |
317 | void x_set_mouse_color (struct frame *, Lisp_Object, Lisp_Object); | |
318 | void x_set_cursor_color (struct frame *, Lisp_Object, Lisp_Object); | |
319 | void x_set_border_color (struct frame *, Lisp_Object, Lisp_Object); | |
320 | void x_set_cursor_type (struct frame *, Lisp_Object, Lisp_Object); | |
321 | void x_set_icon_type (struct frame *, Lisp_Object, Lisp_Object); | |
322 | void x_set_icon_name (struct frame *, Lisp_Object, Lisp_Object); | |
323 | void x_explicitly_set_name (struct frame *, Lisp_Object, Lisp_Object); | |
324 | void x_set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object); | |
325 | void x_set_title (struct frame *, Lisp_Object, Lisp_Object); | |
326 | void x_set_tool_bar_lines (struct frame *, Lisp_Object, Lisp_Object); | |
ee78dc32 | 327 | |
ee78dc32 | 328 | |
ee78dc32 | 329 | \f |
ee78dc32 GV |
330 | |
331 | /* Store the screen positions of frame F into XPTR and YPTR. | |
332 | These are the positions of the containing window manager window, | |
333 | not Emacs's own window. */ | |
334 | ||
335 | void | |
b56ceb92 | 336 | x_real_positions (FRAME_PTR f, int *xptr, int *yptr) |
ee78dc32 GV |
337 | { |
338 | POINT pt; | |
f7b9d4d1 | 339 | RECT rect; |
3c190163 | 340 | |
ee04257d JR |
341 | /* Get the bounds of the WM window. */ |
342 | GetWindowRect (FRAME_W32_WINDOW (f), &rect); | |
f7b9d4d1 | 343 | |
ee04257d JR |
344 | pt.x = 0; |
345 | pt.y = 0; | |
ee78dc32 | 346 | |
ee04257d JR |
347 | /* Convert (0, 0) in the client area to screen co-ordinates. */ |
348 | ClientToScreen (FRAME_W32_WINDOW (f), &pt); | |
ee78dc32 | 349 | |
f7b9d4d1 | 350 | /* Remember x_pixels_diff and y_pixels_diff. */ |
be786000 KS |
351 | f->x_pixels_diff = pt.x - rect.left; |
352 | f->y_pixels_diff = pt.y - rect.top; | |
f7b9d4d1 | 353 | |
ee04257d JR |
354 | *xptr = rect.left; |
355 | *yptr = rect.top; | |
ee78dc32 GV |
356 | } |
357 | ||
ee78dc32 GV |
358 | \f |
359 | ||
74e1aeec JR |
360 | DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color, |
361 | Sw32_define_rgb_color, 4, 4, 0, | |
23f250f4 | 362 | doc: /* Convert RGB numbers to a Windows color reference and associate with NAME. |
02b39a28 | 363 | This adds or updates a named color to `w32-color-map', making it |
74e1aeec JR |
364 | available for use. The original entry's RGB ref is returned, or nil |
365 | if the entry is new. */) | |
5842a27b | 366 | (Lisp_Object red, Lisp_Object green, Lisp_Object blue, Lisp_Object name) |
ee78dc32 | 367 | { |
5ac45f98 GV |
368 | Lisp_Object rgb; |
369 | Lisp_Object oldrgb = Qnil; | |
370 | Lisp_Object entry; | |
371 | ||
b7826503 PJ |
372 | CHECK_NUMBER (red); |
373 | CHECK_NUMBER (green); | |
374 | CHECK_NUMBER (blue); | |
375 | CHECK_STRING (name); | |
ee78dc32 | 376 | |
74084731 | 377 | XSETINT (rgb, RGB (XUINT (red), XUINT (green), XUINT (blue))); |
ee78dc32 | 378 | |
5ac45f98 | 379 | BLOCK_INPUT; |
ee78dc32 | 380 | |
fbd6baed GV |
381 | /* replace existing entry in w32-color-map or add new entry. */ |
382 | entry = Fassoc (name, Vw32_color_map); | |
5ac45f98 GV |
383 | if (NILP (entry)) |
384 | { | |
385 | entry = Fcons (name, rgb); | |
fbd6baed | 386 | Vw32_color_map = Fcons (entry, Vw32_color_map); |
5ac45f98 GV |
387 | } |
388 | else | |
389 | { | |
390 | oldrgb = Fcdr (entry); | |
391 | Fsetcdr (entry, rgb); | |
392 | } | |
393 | ||
394 | UNBLOCK_INPUT; | |
395 | ||
396 | return (oldrgb); | |
ee78dc32 GV |
397 | } |
398 | ||
fbd6baed | 399 | /* The default colors for the w32 color map */ |
7d0393cf | 400 | typedef struct colormap_t |
ee78dc32 GV |
401 | { |
402 | char *name; | |
403 | COLORREF colorref; | |
404 | } colormap_t; | |
405 | ||
7d0393cf | 406 | colormap_t w32_color_map[] = |
ee78dc32 | 407 | { |
1da8a614 GV |
408 | {"snow" , PALETTERGB (255,250,250)}, |
409 | {"ghost white" , PALETTERGB (248,248,255)}, | |
410 | {"GhostWhite" , PALETTERGB (248,248,255)}, | |
411 | {"white smoke" , PALETTERGB (245,245,245)}, | |
412 | {"WhiteSmoke" , PALETTERGB (245,245,245)}, | |
413 | {"gainsboro" , PALETTERGB (220,220,220)}, | |
414 | {"floral white" , PALETTERGB (255,250,240)}, | |
415 | {"FloralWhite" , PALETTERGB (255,250,240)}, | |
416 | {"old lace" , PALETTERGB (253,245,230)}, | |
417 | {"OldLace" , PALETTERGB (253,245,230)}, | |
418 | {"linen" , PALETTERGB (250,240,230)}, | |
419 | {"antique white" , PALETTERGB (250,235,215)}, | |
420 | {"AntiqueWhite" , PALETTERGB (250,235,215)}, | |
421 | {"papaya whip" , PALETTERGB (255,239,213)}, | |
422 | {"PapayaWhip" , PALETTERGB (255,239,213)}, | |
423 | {"blanched almond" , PALETTERGB (255,235,205)}, | |
424 | {"BlanchedAlmond" , PALETTERGB (255,235,205)}, | |
425 | {"bisque" , PALETTERGB (255,228,196)}, | |
426 | {"peach puff" , PALETTERGB (255,218,185)}, | |
427 | {"PeachPuff" , PALETTERGB (255,218,185)}, | |
428 | {"navajo white" , PALETTERGB (255,222,173)}, | |
429 | {"NavajoWhite" , PALETTERGB (255,222,173)}, | |
430 | {"moccasin" , PALETTERGB (255,228,181)}, | |
431 | {"cornsilk" , PALETTERGB (255,248,220)}, | |
432 | {"ivory" , PALETTERGB (255,255,240)}, | |
433 | {"lemon chiffon" , PALETTERGB (255,250,205)}, | |
434 | {"LemonChiffon" , PALETTERGB (255,250,205)}, | |
435 | {"seashell" , PALETTERGB (255,245,238)}, | |
436 | {"honeydew" , PALETTERGB (240,255,240)}, | |
437 | {"mint cream" , PALETTERGB (245,255,250)}, | |
438 | {"MintCream" , PALETTERGB (245,255,250)}, | |
439 | {"azure" , PALETTERGB (240,255,255)}, | |
440 | {"alice blue" , PALETTERGB (240,248,255)}, | |
441 | {"AliceBlue" , PALETTERGB (240,248,255)}, | |
442 | {"lavender" , PALETTERGB (230,230,250)}, | |
443 | {"lavender blush" , PALETTERGB (255,240,245)}, | |
444 | {"LavenderBlush" , PALETTERGB (255,240,245)}, | |
445 | {"misty rose" , PALETTERGB (255,228,225)}, | |
446 | {"MistyRose" , PALETTERGB (255,228,225)}, | |
447 | {"white" , PALETTERGB (255,255,255)}, | |
448 | {"black" , PALETTERGB ( 0, 0, 0)}, | |
449 | {"dark slate gray" , PALETTERGB ( 47, 79, 79)}, | |
450 | {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)}, | |
451 | {"dark slate grey" , PALETTERGB ( 47, 79, 79)}, | |
452 | {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)}, | |
453 | {"dim gray" , PALETTERGB (105,105,105)}, | |
454 | {"DimGray" , PALETTERGB (105,105,105)}, | |
455 | {"dim grey" , PALETTERGB (105,105,105)}, | |
456 | {"DimGrey" , PALETTERGB (105,105,105)}, | |
457 | {"slate gray" , PALETTERGB (112,128,144)}, | |
458 | {"SlateGray" , PALETTERGB (112,128,144)}, | |
459 | {"slate grey" , PALETTERGB (112,128,144)}, | |
460 | {"SlateGrey" , PALETTERGB (112,128,144)}, | |
461 | {"light slate gray" , PALETTERGB (119,136,153)}, | |
462 | {"LightSlateGray" , PALETTERGB (119,136,153)}, | |
463 | {"light slate grey" , PALETTERGB (119,136,153)}, | |
464 | {"LightSlateGrey" , PALETTERGB (119,136,153)}, | |
465 | {"gray" , PALETTERGB (190,190,190)}, | |
466 | {"grey" , PALETTERGB (190,190,190)}, | |
467 | {"light grey" , PALETTERGB (211,211,211)}, | |
468 | {"LightGrey" , PALETTERGB (211,211,211)}, | |
469 | {"light gray" , PALETTERGB (211,211,211)}, | |
470 | {"LightGray" , PALETTERGB (211,211,211)}, | |
471 | {"midnight blue" , PALETTERGB ( 25, 25,112)}, | |
472 | {"MidnightBlue" , PALETTERGB ( 25, 25,112)}, | |
473 | {"navy" , PALETTERGB ( 0, 0,128)}, | |
474 | {"navy blue" , PALETTERGB ( 0, 0,128)}, | |
475 | {"NavyBlue" , PALETTERGB ( 0, 0,128)}, | |
476 | {"cornflower blue" , PALETTERGB (100,149,237)}, | |
477 | {"CornflowerBlue" , PALETTERGB (100,149,237)}, | |
478 | {"dark slate blue" , PALETTERGB ( 72, 61,139)}, | |
479 | {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)}, | |
480 | {"slate blue" , PALETTERGB (106, 90,205)}, | |
481 | {"SlateBlue" , PALETTERGB (106, 90,205)}, | |
482 | {"medium slate blue" , PALETTERGB (123,104,238)}, | |
483 | {"MediumSlateBlue" , PALETTERGB (123,104,238)}, | |
484 | {"light slate blue" , PALETTERGB (132,112,255)}, | |
485 | {"LightSlateBlue" , PALETTERGB (132,112,255)}, | |
486 | {"medium blue" , PALETTERGB ( 0, 0,205)}, | |
487 | {"MediumBlue" , PALETTERGB ( 0, 0,205)}, | |
488 | {"royal blue" , PALETTERGB ( 65,105,225)}, | |
489 | {"RoyalBlue" , PALETTERGB ( 65,105,225)}, | |
490 | {"blue" , PALETTERGB ( 0, 0,255)}, | |
491 | {"dodger blue" , PALETTERGB ( 30,144,255)}, | |
492 | {"DodgerBlue" , PALETTERGB ( 30,144,255)}, | |
493 | {"deep sky blue" , PALETTERGB ( 0,191,255)}, | |
494 | {"DeepSkyBlue" , PALETTERGB ( 0,191,255)}, | |
495 | {"sky blue" , PALETTERGB (135,206,235)}, | |
496 | {"SkyBlue" , PALETTERGB (135,206,235)}, | |
497 | {"light sky blue" , PALETTERGB (135,206,250)}, | |
498 | {"LightSkyBlue" , PALETTERGB (135,206,250)}, | |
499 | {"steel blue" , PALETTERGB ( 70,130,180)}, | |
500 | {"SteelBlue" , PALETTERGB ( 70,130,180)}, | |
501 | {"light steel blue" , PALETTERGB (176,196,222)}, | |
502 | {"LightSteelBlue" , PALETTERGB (176,196,222)}, | |
503 | {"light blue" , PALETTERGB (173,216,230)}, | |
504 | {"LightBlue" , PALETTERGB (173,216,230)}, | |
505 | {"powder blue" , PALETTERGB (176,224,230)}, | |
506 | {"PowderBlue" , PALETTERGB (176,224,230)}, | |
507 | {"pale turquoise" , PALETTERGB (175,238,238)}, | |
508 | {"PaleTurquoise" , PALETTERGB (175,238,238)}, | |
509 | {"dark turquoise" , PALETTERGB ( 0,206,209)}, | |
510 | {"DarkTurquoise" , PALETTERGB ( 0,206,209)}, | |
511 | {"medium turquoise" , PALETTERGB ( 72,209,204)}, | |
512 | {"MediumTurquoise" , PALETTERGB ( 72,209,204)}, | |
513 | {"turquoise" , PALETTERGB ( 64,224,208)}, | |
514 | {"cyan" , PALETTERGB ( 0,255,255)}, | |
515 | {"light cyan" , PALETTERGB (224,255,255)}, | |
516 | {"LightCyan" , PALETTERGB (224,255,255)}, | |
517 | {"cadet blue" , PALETTERGB ( 95,158,160)}, | |
518 | {"CadetBlue" , PALETTERGB ( 95,158,160)}, | |
519 | {"medium aquamarine" , PALETTERGB (102,205,170)}, | |
520 | {"MediumAquamarine" , PALETTERGB (102,205,170)}, | |
521 | {"aquamarine" , PALETTERGB (127,255,212)}, | |
522 | {"dark green" , PALETTERGB ( 0,100, 0)}, | |
523 | {"DarkGreen" , PALETTERGB ( 0,100, 0)}, | |
524 | {"dark olive green" , PALETTERGB ( 85,107, 47)}, | |
525 | {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)}, | |
526 | {"dark sea green" , PALETTERGB (143,188,143)}, | |
527 | {"DarkSeaGreen" , PALETTERGB (143,188,143)}, | |
528 | {"sea green" , PALETTERGB ( 46,139, 87)}, | |
529 | {"SeaGreen" , PALETTERGB ( 46,139, 87)}, | |
530 | {"medium sea green" , PALETTERGB ( 60,179,113)}, | |
531 | {"MediumSeaGreen" , PALETTERGB ( 60,179,113)}, | |
532 | {"light sea green" , PALETTERGB ( 32,178,170)}, | |
533 | {"LightSeaGreen" , PALETTERGB ( 32,178,170)}, | |
534 | {"pale green" , PALETTERGB (152,251,152)}, | |
535 | {"PaleGreen" , PALETTERGB (152,251,152)}, | |
536 | {"spring green" , PALETTERGB ( 0,255,127)}, | |
537 | {"SpringGreen" , PALETTERGB ( 0,255,127)}, | |
538 | {"lawn green" , PALETTERGB (124,252, 0)}, | |
539 | {"LawnGreen" , PALETTERGB (124,252, 0)}, | |
540 | {"green" , PALETTERGB ( 0,255, 0)}, | |
541 | {"chartreuse" , PALETTERGB (127,255, 0)}, | |
542 | {"medium spring green" , PALETTERGB ( 0,250,154)}, | |
543 | {"MediumSpringGreen" , PALETTERGB ( 0,250,154)}, | |
544 | {"green yellow" , PALETTERGB (173,255, 47)}, | |
545 | {"GreenYellow" , PALETTERGB (173,255, 47)}, | |
546 | {"lime green" , PALETTERGB ( 50,205, 50)}, | |
547 | {"LimeGreen" , PALETTERGB ( 50,205, 50)}, | |
548 | {"yellow green" , PALETTERGB (154,205, 50)}, | |
549 | {"YellowGreen" , PALETTERGB (154,205, 50)}, | |
550 | {"forest green" , PALETTERGB ( 34,139, 34)}, | |
551 | {"ForestGreen" , PALETTERGB ( 34,139, 34)}, | |
552 | {"olive drab" , PALETTERGB (107,142, 35)}, | |
553 | {"OliveDrab" , PALETTERGB (107,142, 35)}, | |
554 | {"dark khaki" , PALETTERGB (189,183,107)}, | |
555 | {"DarkKhaki" , PALETTERGB (189,183,107)}, | |
556 | {"khaki" , PALETTERGB (240,230,140)}, | |
557 | {"pale goldenrod" , PALETTERGB (238,232,170)}, | |
558 | {"PaleGoldenrod" , PALETTERGB (238,232,170)}, | |
559 | {"light goldenrod yellow" , PALETTERGB (250,250,210)}, | |
560 | {"LightGoldenrodYellow" , PALETTERGB (250,250,210)}, | |
561 | {"light yellow" , PALETTERGB (255,255,224)}, | |
562 | {"LightYellow" , PALETTERGB (255,255,224)}, | |
563 | {"yellow" , PALETTERGB (255,255, 0)}, | |
564 | {"gold" , PALETTERGB (255,215, 0)}, | |
565 | {"light goldenrod" , PALETTERGB (238,221,130)}, | |
566 | {"LightGoldenrod" , PALETTERGB (238,221,130)}, | |
567 | {"goldenrod" , PALETTERGB (218,165, 32)}, | |
568 | {"dark goldenrod" , PALETTERGB (184,134, 11)}, | |
569 | {"DarkGoldenrod" , PALETTERGB (184,134, 11)}, | |
570 | {"rosy brown" , PALETTERGB (188,143,143)}, | |
571 | {"RosyBrown" , PALETTERGB (188,143,143)}, | |
572 | {"indian red" , PALETTERGB (205, 92, 92)}, | |
573 | {"IndianRed" , PALETTERGB (205, 92, 92)}, | |
574 | {"saddle brown" , PALETTERGB (139, 69, 19)}, | |
575 | {"SaddleBrown" , PALETTERGB (139, 69, 19)}, | |
576 | {"sienna" , PALETTERGB (160, 82, 45)}, | |
577 | {"peru" , PALETTERGB (205,133, 63)}, | |
578 | {"burlywood" , PALETTERGB (222,184,135)}, | |
579 | {"beige" , PALETTERGB (245,245,220)}, | |
580 | {"wheat" , PALETTERGB (245,222,179)}, | |
581 | {"sandy brown" , PALETTERGB (244,164, 96)}, | |
582 | {"SandyBrown" , PALETTERGB (244,164, 96)}, | |
583 | {"tan" , PALETTERGB (210,180,140)}, | |
584 | {"chocolate" , PALETTERGB (210,105, 30)}, | |
585 | {"firebrick" , PALETTERGB (178,34, 34)}, | |
586 | {"brown" , PALETTERGB (165,42, 42)}, | |
587 | {"dark salmon" , PALETTERGB (233,150,122)}, | |
588 | {"DarkSalmon" , PALETTERGB (233,150,122)}, | |
589 | {"salmon" , PALETTERGB (250,128,114)}, | |
590 | {"light salmon" , PALETTERGB (255,160,122)}, | |
591 | {"LightSalmon" , PALETTERGB (255,160,122)}, | |
592 | {"orange" , PALETTERGB (255,165, 0)}, | |
593 | {"dark orange" , PALETTERGB (255,140, 0)}, | |
594 | {"DarkOrange" , PALETTERGB (255,140, 0)}, | |
595 | {"coral" , PALETTERGB (255,127, 80)}, | |
596 | {"light coral" , PALETTERGB (240,128,128)}, | |
597 | {"LightCoral" , PALETTERGB (240,128,128)}, | |
598 | {"tomato" , PALETTERGB (255, 99, 71)}, | |
599 | {"orange red" , PALETTERGB (255, 69, 0)}, | |
600 | {"OrangeRed" , PALETTERGB (255, 69, 0)}, | |
601 | {"red" , PALETTERGB (255, 0, 0)}, | |
602 | {"hot pink" , PALETTERGB (255,105,180)}, | |
603 | {"HotPink" , PALETTERGB (255,105,180)}, | |
604 | {"deep pink" , PALETTERGB (255, 20,147)}, | |
605 | {"DeepPink" , PALETTERGB (255, 20,147)}, | |
606 | {"pink" , PALETTERGB (255,192,203)}, | |
607 | {"light pink" , PALETTERGB (255,182,193)}, | |
608 | {"LightPink" , PALETTERGB (255,182,193)}, | |
609 | {"pale violet red" , PALETTERGB (219,112,147)}, | |
610 | {"PaleVioletRed" , PALETTERGB (219,112,147)}, | |
611 | {"maroon" , PALETTERGB (176, 48, 96)}, | |
612 | {"medium violet red" , PALETTERGB (199, 21,133)}, | |
613 | {"MediumVioletRed" , PALETTERGB (199, 21,133)}, | |
614 | {"violet red" , PALETTERGB (208, 32,144)}, | |
615 | {"VioletRed" , PALETTERGB (208, 32,144)}, | |
616 | {"magenta" , PALETTERGB (255, 0,255)}, | |
617 | {"violet" , PALETTERGB (238,130,238)}, | |
618 | {"plum" , PALETTERGB (221,160,221)}, | |
619 | {"orchid" , PALETTERGB (218,112,214)}, | |
620 | {"medium orchid" , PALETTERGB (186, 85,211)}, | |
621 | {"MediumOrchid" , PALETTERGB (186, 85,211)}, | |
622 | {"dark orchid" , PALETTERGB (153, 50,204)}, | |
623 | {"DarkOrchid" , PALETTERGB (153, 50,204)}, | |
624 | {"dark violet" , PALETTERGB (148, 0,211)}, | |
625 | {"DarkViolet" , PALETTERGB (148, 0,211)}, | |
626 | {"blue violet" , PALETTERGB (138, 43,226)}, | |
627 | {"BlueViolet" , PALETTERGB (138, 43,226)}, | |
628 | {"purple" , PALETTERGB (160, 32,240)}, | |
629 | {"medium purple" , PALETTERGB (147,112,219)}, | |
630 | {"MediumPurple" , PALETTERGB (147,112,219)}, | |
631 | {"thistle" , PALETTERGB (216,191,216)}, | |
632 | {"gray0" , PALETTERGB ( 0, 0, 0)}, | |
633 | {"grey0" , PALETTERGB ( 0, 0, 0)}, | |
634 | {"dark grey" , PALETTERGB (169,169,169)}, | |
635 | {"DarkGrey" , PALETTERGB (169,169,169)}, | |
636 | {"dark gray" , PALETTERGB (169,169,169)}, | |
637 | {"DarkGray" , PALETTERGB (169,169,169)}, | |
638 | {"dark blue" , PALETTERGB ( 0, 0,139)}, | |
639 | {"DarkBlue" , PALETTERGB ( 0, 0,139)}, | |
640 | {"dark cyan" , PALETTERGB ( 0,139,139)}, | |
641 | {"DarkCyan" , PALETTERGB ( 0,139,139)}, | |
642 | {"dark magenta" , PALETTERGB (139, 0,139)}, | |
643 | {"DarkMagenta" , PALETTERGB (139, 0,139)}, | |
644 | {"dark red" , PALETTERGB (139, 0, 0)}, | |
645 | {"DarkRed" , PALETTERGB (139, 0, 0)}, | |
646 | {"light green" , PALETTERGB (144,238,144)}, | |
647 | {"LightGreen" , PALETTERGB (144,238,144)}, | |
ee78dc32 GV |
648 | }; |
649 | ||
fbd6baed | 650 | DEFUN ("w32-default-color-map", Fw32_default_color_map, Sw32_default_color_map, |
74e1aeec | 651 | 0, 0, 0, doc: /* Return the default color map. */) |
5842a27b | 652 | (void) |
ee78dc32 GV |
653 | { |
654 | int i; | |
fbd6baed | 655 | colormap_t *pc = w32_color_map; |
ee78dc32 | 656 | Lisp_Object cmap; |
7d0393cf | 657 | |
ee78dc32 | 658 | BLOCK_INPUT; |
7d0393cf | 659 | |
ee78dc32 | 660 | cmap = Qnil; |
7d0393cf JB |
661 | |
662 | for (i = 0; i < sizeof (w32_color_map) / sizeof (w32_color_map[0]); | |
ee78dc32 GV |
663 | pc++, i++) |
664 | cmap = Fcons (Fcons (build_string (pc->name), | |
665 | make_number (pc->colorref)), | |
666 | cmap); | |
7d0393cf | 667 | |
ee78dc32 | 668 | UNBLOCK_INPUT; |
7d0393cf | 669 | |
ee78dc32 GV |
670 | return (cmap); |
671 | } | |
ee78dc32 | 672 | |
2ba49441 | 673 | static Lisp_Object |
b56ceb92 | 674 | w32_color_map_lookup (char *colorname) |
5d7fed93 GV |
675 | { |
676 | Lisp_Object tail, ret = Qnil; | |
677 | ||
678 | BLOCK_INPUT; | |
679 | ||
99784d63 | 680 | for (tail = Vw32_color_map; CONSP (tail); tail = XCDR (tail)) |
5d7fed93 GV |
681 | { |
682 | register Lisp_Object elt, tem; | |
683 | ||
99784d63 | 684 | elt = XCAR (tail); |
5d7fed93 GV |
685 | if (!CONSP (elt)) continue; |
686 | ||
687 | tem = Fcar (elt); | |
688 | ||
d5db4077 | 689 | if (lstrcmpi (SDATA (tem), colorname) == 0) |
5d7fed93 | 690 | { |
2ba49441 | 691 | ret = Fcdr (elt); |
5d7fed93 GV |
692 | break; |
693 | } | |
694 | ||
695 | QUIT; | |
696 | } | |
697 | ||
698 | ||
699 | UNBLOCK_INPUT; | |
700 | ||
701 | return ret; | |
702 | } | |
703 | ||
5a8a15ec JR |
704 | |
705 | static void | |
b56ceb92 | 706 | add_system_logical_colors_to_map (Lisp_Object *system_colors) |
5a8a15ec JR |
707 | { |
708 | HKEY colors_key; | |
709 | ||
710 | /* Other registry operations are done with input blocked. */ | |
711 | BLOCK_INPUT; | |
712 | ||
713 | /* Look for "Control Panel/Colors" under User and Machine registry | |
714 | settings. */ | |
715 | if (RegOpenKeyEx (HKEY_CURRENT_USER, "Control Panel\\Colors", 0, | |
716 | KEY_READ, &colors_key) == ERROR_SUCCESS | |
717 | || RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Control Panel\\Colors", 0, | |
718 | KEY_READ, &colors_key) == ERROR_SUCCESS) | |
719 | { | |
720 | /* List all keys. */ | |
721 | char color_buffer[64]; | |
722 | char full_name_buffer[MAX_PATH + SYSTEM_COLOR_PREFIX_LEN]; | |
723 | int index = 0; | |
724 | DWORD name_size, color_size; | |
725 | char *name_buffer = full_name_buffer + SYSTEM_COLOR_PREFIX_LEN; | |
726 | ||
727 | name_size = sizeof (full_name_buffer) - SYSTEM_COLOR_PREFIX_LEN; | |
728 | color_size = sizeof (color_buffer); | |
729 | ||
730 | strcpy (full_name_buffer, SYSTEM_COLOR_PREFIX); | |
731 | ||
732 | while (RegEnumValueA (colors_key, index, name_buffer, &name_size, | |
733 | NULL, NULL, color_buffer, &color_size) | |
734 | == ERROR_SUCCESS) | |
735 | { | |
736 | int r, g, b; | |
737 | if (sscanf (color_buffer, " %u %u %u", &r, &g, &b) == 3) | |
738 | *system_colors = Fcons (Fcons (build_string (full_name_buffer), | |
739 | make_number (RGB (r, g, b))), | |
740 | *system_colors); | |
741 | ||
742 | name_size = sizeof (full_name_buffer) - SYSTEM_COLOR_PREFIX_LEN; | |
743 | color_size = sizeof (color_buffer); | |
744 | index++; | |
745 | } | |
746 | RegCloseKey (colors_key); | |
747 | } | |
748 | ||
749 | UNBLOCK_INPUT; | |
750 | } | |
751 | ||
752 | ||
2ba49441 | 753 | static Lisp_Object |
b56ceb92 | 754 | x_to_w32_color (char * colorname) |
ee78dc32 | 755 | { |
8edb0a6f JR |
756 | register Lisp_Object ret = Qnil; |
757 | ||
ee78dc32 | 758 | BLOCK_INPUT; |
1edf84e7 GV |
759 | |
760 | if (colorname[0] == '#') | |
761 | { | |
762 | /* Could be an old-style RGB Device specification. */ | |
763 | char *color; | |
764 | int size; | |
765 | color = colorname + 1; | |
7d0393cf | 766 | |
74084731 | 767 | size = strlen (color); |
1edf84e7 GV |
768 | if (size == 3 || size == 6 || size == 9 || size == 12) |
769 | { | |
770 | UINT colorval; | |
771 | int i, pos; | |
772 | pos = 0; | |
773 | size /= 3; | |
774 | colorval = 0; | |
7d0393cf | 775 | |
1edf84e7 GV |
776 | for (i = 0; i < 3; i++) |
777 | { | |
778 | char *end; | |
779 | char t; | |
780 | unsigned long value; | |
781 | ||
782 | /* The check for 'x' in the following conditional takes into | |
783 | account the fact that strtol allows a "0x" in front of | |
784 | our numbers, and we don't. */ | |
74084731 | 785 | if (!isxdigit (color[0]) || color[1] == 'x') |
1edf84e7 GV |
786 | break; |
787 | t = color[size]; | |
788 | color[size] = '\0'; | |
74084731 | 789 | value = strtoul (color, &end, 16); |
1edf84e7 GV |
790 | color[size] = t; |
791 | if (errno == ERANGE || end - color != size) | |
792 | break; | |
793 | switch (size) | |
794 | { | |
795 | case 1: | |
796 | value = value * 0x10; | |
797 | break; | |
798 | case 2: | |
799 | break; | |
800 | case 3: | |
801 | value /= 0x10; | |
802 | break; | |
803 | case 4: | |
804 | value /= 0x100; | |
805 | break; | |
806 | } | |
807 | colorval |= (value << pos); | |
808 | pos += 0x8; | |
809 | if (i == 2) | |
810 | { | |
811 | UNBLOCK_INPUT; | |
2ba49441 JR |
812 | XSETINT (ret, colorval); |
813 | return ret; | |
1edf84e7 GV |
814 | } |
815 | color = end; | |
816 | } | |
817 | } | |
818 | } | |
74084731 | 819 | else if (strnicmp (colorname, "rgb:", 4) == 0) |
1edf84e7 GV |
820 | { |
821 | char *color; | |
822 | UINT colorval; | |
823 | int i, pos; | |
824 | pos = 0; | |
825 | ||
826 | colorval = 0; | |
827 | color = colorname + 4; | |
828 | for (i = 0; i < 3; i++) | |
829 | { | |
830 | char *end; | |
831 | unsigned long value; | |
7d0393cf | 832 | |
1edf84e7 GV |
833 | /* The check for 'x' in the following conditional takes into |
834 | account the fact that strtol allows a "0x" in front of | |
835 | our numbers, and we don't. */ | |
74084731 | 836 | if (!isxdigit (color[0]) || color[1] == 'x') |
1edf84e7 | 837 | break; |
74084731 | 838 | value = strtoul (color, &end, 16); |
1edf84e7 GV |
839 | if (errno == ERANGE) |
840 | break; | |
841 | switch (end - color) | |
842 | { | |
843 | case 1: | |
844 | value = value * 0x10 + value; | |
845 | break; | |
846 | case 2: | |
847 | break; | |
848 | case 3: | |
849 | value /= 0x10; | |
850 | break; | |
851 | case 4: | |
852 | value /= 0x100; | |
853 | break; | |
854 | default: | |
855 | value = ULONG_MAX; | |
856 | } | |
857 | if (value == ULONG_MAX) | |
858 | break; | |
859 | colorval |= (value << pos); | |
860 | pos += 0x8; | |
861 | if (i == 2) | |
862 | { | |
863 | if (*end != '\0') | |
864 | break; | |
865 | UNBLOCK_INPUT; | |
2ba49441 JR |
866 | XSETINT (ret, colorval); |
867 | return ret; | |
1edf84e7 GV |
868 | } |
869 | if (*end != '/') | |
870 | break; | |
871 | color = end + 1; | |
872 | } | |
873 | } | |
74084731 | 874 | else if (strnicmp (colorname, "rgbi:", 5) == 0) |
1edf84e7 GV |
875 | { |
876 | /* This is an RGB Intensity specification. */ | |
877 | char *color; | |
878 | UINT colorval; | |
879 | int i, pos; | |
880 | pos = 0; | |
881 | ||
882 | colorval = 0; | |
883 | color = colorname + 5; | |
884 | for (i = 0; i < 3; i++) | |
885 | { | |
886 | char *end; | |
887 | double value; | |
888 | UINT val; | |
889 | ||
74084731 | 890 | value = strtod (color, &end); |
1edf84e7 GV |
891 | if (errno == ERANGE) |
892 | break; | |
893 | if (value < 0.0 || value > 1.0) | |
894 | break; | |
895 | val = (UINT)(0x100 * value); | |
7d0393cf | 896 | /* We used 0x100 instead of 0xFF to give a continuous |
1edf84e7 GV |
897 | range between 0.0 and 1.0 inclusive. The next statement |
898 | fixes the 1.0 case. */ | |
899 | if (val == 0x100) | |
900 | val = 0xFF; | |
901 | colorval |= (val << pos); | |
902 | pos += 0x8; | |
903 | if (i == 2) | |
904 | { | |
905 | if (*end != '\0') | |
906 | break; | |
907 | UNBLOCK_INPUT; | |
2ba49441 JR |
908 | XSETINT (ret, colorval); |
909 | return ret; | |
1edf84e7 GV |
910 | } |
911 | if (*end != '/') | |
912 | break; | |
913 | color = end + 1; | |
914 | } | |
915 | } | |
916 | /* I am not going to attempt to handle any of the CIE color schemes | |
917 | or TekHVC, since I don't know the algorithms for conversion to | |
918 | RGB. */ | |
f695b4b1 GV |
919 | |
920 | /* If we fail to lookup the color name in w32_color_map, then check the | |
7d0393cf | 921 | colorname to see if it can be crudely approximated: If the X color |
f695b4b1 GV |
922 | ends in a number (e.g., "darkseagreen2"), strip the number and |
923 | return the result of looking up the base color name. */ | |
924 | ret = w32_color_map_lookup (colorname); | |
7d0393cf | 925 | if (NILP (ret)) |
ee78dc32 | 926 | { |
f695b4b1 | 927 | int len = strlen (colorname); |
ee78dc32 | 928 | |
7d0393cf | 929 | if (isdigit (colorname[len - 1])) |
f695b4b1 | 930 | { |
8b77111c | 931 | char *ptr, *approx = alloca (len + 1); |
ee78dc32 | 932 | |
f695b4b1 GV |
933 | strcpy (approx, colorname); |
934 | ptr = &approx[len - 1]; | |
7d0393cf | 935 | while (ptr > approx && isdigit (*ptr)) |
f695b4b1 | 936 | *ptr-- = '\0'; |
ee78dc32 | 937 | |
f695b4b1 | 938 | ret = w32_color_map_lookup (approx); |
ee78dc32 | 939 | } |
ee78dc32 | 940 | } |
7d0393cf | 941 | |
ee78dc32 | 942 | UNBLOCK_INPUT; |
ee78dc32 GV |
943 | return ret; |
944 | } | |
945 | ||
5ac45f98 | 946 | void |
fbd6baed | 947 | w32_regenerate_palette (FRAME_PTR f) |
5ac45f98 | 948 | { |
fbd6baed | 949 | struct w32_palette_entry * list; |
5ac45f98 GV |
950 | LOGPALETTE * log_palette; |
951 | HPALETTE new_palette; | |
952 | int i; | |
953 | ||
954 | /* don't bother trying to create palette if not supported */ | |
fbd6baed | 955 | if (! FRAME_W32_DISPLAY_INFO (f)->has_palette) |
5ac45f98 GV |
956 | return; |
957 | ||
958 | log_palette = (LOGPALETTE *) | |
959 | alloca (sizeof (LOGPALETTE) + | |
fbd6baed | 960 | FRAME_W32_DISPLAY_INFO (f)->num_colors * sizeof (PALETTEENTRY)); |
5ac45f98 | 961 | log_palette->palVersion = 0x300; |
fbd6baed | 962 | log_palette->palNumEntries = FRAME_W32_DISPLAY_INFO (f)->num_colors; |
5ac45f98 | 963 | |
fbd6baed | 964 | list = FRAME_W32_DISPLAY_INFO (f)->color_list; |
5ac45f98 | 965 | for (i = 0; |
fbd6baed | 966 | i < FRAME_W32_DISPLAY_INFO (f)->num_colors; |
5ac45f98 GV |
967 | i++, list = list->next) |
968 | log_palette->palPalEntry[i] = list->entry; | |
969 | ||
970 | new_palette = CreatePalette (log_palette); | |
971 | ||
972 | enter_crit (); | |
973 | ||
fbd6baed GV |
974 | if (FRAME_W32_DISPLAY_INFO (f)->palette) |
975 | DeleteObject (FRAME_W32_DISPLAY_INFO (f)->palette); | |
976 | FRAME_W32_DISPLAY_INFO (f)->palette = new_palette; | |
5ac45f98 GV |
977 | |
978 | /* Realize display palette and garbage all frames. */ | |
979 | release_frame_dc (f, get_frame_dc (f)); | |
980 | ||
981 | leave_crit (); | |
982 | } | |
983 | ||
fbd6baed GV |
984 | #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue) |
985 | #define SET_W32_COLOR(pe, color) \ | |
5ac45f98 GV |
986 | do \ |
987 | { \ | |
988 | pe.peRed = GetRValue (color); \ | |
989 | pe.peGreen = GetGValue (color); \ | |
990 | pe.peBlue = GetBValue (color); \ | |
991 | pe.peFlags = 0; \ | |
992 | } while (0) | |
993 | ||
994 | #if 0 | |
995 | /* Keep these around in case we ever want to track color usage. */ | |
996 | void | |
fbd6baed | 997 | w32_map_color (FRAME_PTR f, COLORREF color) |
5ac45f98 | 998 | { |
fbd6baed | 999 | struct w32_palette_entry * list = FRAME_W32_DISPLAY_INFO (f)->color_list; |
5ac45f98 | 1000 | |
fbd6baed | 1001 | if (NILP (Vw32_enable_palette)) |
5ac45f98 GV |
1002 | return; |
1003 | ||
1004 | /* check if color is already mapped */ | |
1005 | while (list) | |
1006 | { | |
fbd6baed | 1007 | if (W32_COLOR (list->entry) == color) |
5ac45f98 GV |
1008 | { |
1009 | ++list->refcount; | |
1010 | return; | |
1011 | } | |
1012 | list = list->next; | |
1013 | } | |
1014 | ||
1015 | /* not already mapped, so add to list and recreate Windows palette */ | |
fbd6baed GV |
1016 | list = (struct w32_palette_entry *) |
1017 | xmalloc (sizeof (struct w32_palette_entry)); | |
1018 | SET_W32_COLOR (list->entry, color); | |
5ac45f98 | 1019 | list->refcount = 1; |
fbd6baed GV |
1020 | list->next = FRAME_W32_DISPLAY_INFO (f)->color_list; |
1021 | FRAME_W32_DISPLAY_INFO (f)->color_list = list; | |
1022 | FRAME_W32_DISPLAY_INFO (f)->num_colors++; | |
5ac45f98 GV |
1023 | |
1024 | /* set flag that palette must be regenerated */ | |
fbd6baed | 1025 | FRAME_W32_DISPLAY_INFO (f)->regen_palette = TRUE; |
5ac45f98 GV |
1026 | } |
1027 | ||
1028 | void | |
fbd6baed | 1029 | w32_unmap_color (FRAME_PTR f, COLORREF color) |
5ac45f98 | 1030 | { |
fbd6baed GV |
1031 | struct w32_palette_entry * list = FRAME_W32_DISPLAY_INFO (f)->color_list; |
1032 | struct w32_palette_entry **prev = &FRAME_W32_DISPLAY_INFO (f)->color_list; | |
5ac45f98 | 1033 | |
fbd6baed | 1034 | if (NILP (Vw32_enable_palette)) |
5ac45f98 GV |
1035 | return; |
1036 | ||
1037 | /* check if color is already mapped */ | |
1038 | while (list) | |
1039 | { | |
fbd6baed | 1040 | if (W32_COLOR (list->entry) == color) |
5ac45f98 GV |
1041 | { |
1042 | if (--list->refcount == 0) | |
1043 | { | |
1044 | *prev = list->next; | |
1045 | xfree (list); | |
fbd6baed | 1046 | FRAME_W32_DISPLAY_INFO (f)->num_colors--; |
5ac45f98 GV |
1047 | break; |
1048 | } | |
1049 | else | |
1050 | return; | |
1051 | } | |
1052 | prev = &list->next; | |
1053 | list = list->next; | |
1054 | } | |
1055 | ||
1056 | /* set flag that palette must be regenerated */ | |
fbd6baed | 1057 | FRAME_W32_DISPLAY_INFO (f)->regen_palette = TRUE; |
5ac45f98 GV |
1058 | } |
1059 | #endif | |
1060 | ||
6fc2811b JR |
1061 | |
1062 | /* Gamma-correct COLOR on frame F. */ | |
1063 | ||
1064 | void | |
b56ceb92 | 1065 | gamma_correct (struct frame *f, COLORREF *color) |
6fc2811b JR |
1066 | { |
1067 | if (f->gamma) | |
1068 | { | |
1069 | *color = PALETTERGB ( | |
1070 | pow (GetRValue (*color) / 255.0, f->gamma) * 255.0 + 0.5, | |
1071 | pow (GetGValue (*color) / 255.0, f->gamma) * 255.0 + 0.5, | |
1072 | pow (GetBValue (*color) / 255.0, f->gamma) * 255.0 + 0.5); | |
1073 | } | |
1074 | } | |
1075 | ||
1076 | ||
ee78dc32 GV |
1077 | /* Decide if color named COLOR is valid for the display associated with |
1078 | the selected frame; if so, return the rgb values in COLOR_DEF. | |
1079 | If ALLOC is nonzero, allocate a new colormap cell. */ | |
1080 | ||
1081 | int | |
b56ceb92 | 1082 | w32_defined_color (FRAME_PTR f, char *color, XColor *color_def, int alloc) |
ee78dc32 GV |
1083 | { |
1084 | register Lisp_Object tem; | |
6fc2811b | 1085 | COLORREF w32_color_ref; |
3c190163 | 1086 | |
fbd6baed | 1087 | tem = x_to_w32_color (color); |
3c190163 | 1088 | |
7d0393cf | 1089 | if (!NILP (tem)) |
ee78dc32 | 1090 | { |
d88c567c JR |
1091 | if (f) |
1092 | { | |
1093 | /* Apply gamma correction. */ | |
1094 | w32_color_ref = XUINT (tem); | |
1095 | gamma_correct (f, &w32_color_ref); | |
1096 | XSETINT (tem, w32_color_ref); | |
1097 | } | |
9badad41 JR |
1098 | |
1099 | /* Map this color to the palette if it is enabled. */ | |
fbd6baed | 1100 | if (!NILP (Vw32_enable_palette)) |
5ac45f98 | 1101 | { |
fbd6baed | 1102 | struct w32_palette_entry * entry = |
d88c567c | 1103 | one_w32_display_info.color_list; |
fbd6baed | 1104 | struct w32_palette_entry ** prev = |
d88c567c | 1105 | &one_w32_display_info.color_list; |
7d0393cf | 1106 | |
5ac45f98 GV |
1107 | /* check if color is already mapped */ |
1108 | while (entry) | |
1109 | { | |
fbd6baed | 1110 | if (W32_COLOR (entry->entry) == XUINT (tem)) |
5ac45f98 GV |
1111 | break; |
1112 | prev = &entry->next; | |
1113 | entry = entry->next; | |
1114 | } | |
1115 | ||
1116 | if (entry == NULL && alloc) | |
1117 | { | |
1118 | /* not already mapped, so add to list */ | |
fbd6baed GV |
1119 | entry = (struct w32_palette_entry *) |
1120 | xmalloc (sizeof (struct w32_palette_entry)); | |
1121 | SET_W32_COLOR (entry->entry, XUINT (tem)); | |
5ac45f98 GV |
1122 | entry->next = NULL; |
1123 | *prev = entry; | |
d88c567c | 1124 | one_w32_display_info.num_colors++; |
5ac45f98 GV |
1125 | |
1126 | /* set flag that palette must be regenerated */ | |
d88c567c | 1127 | one_w32_display_info.regen_palette = TRUE; |
5ac45f98 GV |
1128 | } |
1129 | } | |
1130 | /* Ensure COLORREF value is snapped to nearest color in (default) | |
1131 | palette by simulating the PALETTERGB macro. This works whether | |
1132 | or not the display device has a palette. */ | |
6fc2811b JR |
1133 | w32_color_ref = XUINT (tem) | 0x2000000; |
1134 | ||
6fc2811b | 1135 | color_def->pixel = w32_color_ref; |
197edd35 JR |
1136 | color_def->red = GetRValue (w32_color_ref) * 256; |
1137 | color_def->green = GetGValue (w32_color_ref) * 256; | |
1138 | color_def->blue = GetBValue (w32_color_ref) * 256; | |
6fc2811b | 1139 | |
ee78dc32 | 1140 | return 1; |
5ac45f98 | 1141 | } |
7d0393cf | 1142 | else |
3c190163 GV |
1143 | { |
1144 | return 0; | |
1145 | } | |
ee78dc32 GV |
1146 | } |
1147 | ||
1148 | /* Given a string ARG naming a color, compute a pixel value from it | |
1149 | suitable for screen F. | |
1150 | If F is not a color screen, return DEF (default) regardless of what | |
1151 | ARG says. */ | |
1152 | ||
1153 | int | |
b56ceb92 | 1154 | x_decode_color (FRAME_PTR f, Lisp_Object arg, int def) |
ee78dc32 | 1155 | { |
6fc2811b | 1156 | XColor cdef; |
ee78dc32 | 1157 | |
b7826503 | 1158 | CHECK_STRING (arg); |
ee78dc32 | 1159 | |
d5db4077 | 1160 | if (strcmp (SDATA (arg), "black") == 0) |
ee78dc32 | 1161 | return BLACK_PIX_DEFAULT (f); |
d5db4077 | 1162 | else if (strcmp (SDATA (arg), "white") == 0) |
ee78dc32 GV |
1163 | return WHITE_PIX_DEFAULT (f); |
1164 | ||
fbd6baed | 1165 | if ((FRAME_W32_DISPLAY_INFO (f)->n_planes * FRAME_W32_DISPLAY_INFO (f)->n_cbits) == 1) |
ee78dc32 GV |
1166 | return def; |
1167 | ||
6fc2811b | 1168 | /* w32_defined_color is responsible for coping with failures |
ee78dc32 | 1169 | by looking for a near-miss. */ |
d5db4077 | 1170 | if (w32_defined_color (f, SDATA (arg), &cdef, 1)) |
6fc2811b | 1171 | return cdef.pixel; |
ee78dc32 GV |
1172 | |
1173 | /* defined_color failed; return an ultimate default. */ | |
1174 | return def; | |
1175 | } | |
1176 | \f | |
6fc2811b JR |
1177 | |
1178 | ||
ee78dc32 GV |
1179 | /* Functions called only from `x_set_frame_param' |
1180 | to set individual parameters. | |
1181 | ||
fbd6baed | 1182 | If FRAME_W32_WINDOW (f) is 0, |
ee78dc32 GV |
1183 | the frame is being created and its window does not exist yet. |
1184 | In that case, just record the parameter's new value | |
1185 | in the standard place; do not attempt to change the window. */ | |
1186 | ||
1187 | void | |
b56ceb92 | 1188 | x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
ee78dc32 | 1189 | { |
3cf3436e JR |
1190 | struct w32_output *x = f->output_data.w32; |
1191 | PIX_TYPE fg, old_fg; | |
1192 | ||
1193 | fg = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); | |
1194 | old_fg = FRAME_FOREGROUND_PIXEL (f); | |
1195 | FRAME_FOREGROUND_PIXEL (f) = fg; | |
5ac45f98 | 1196 | |
fbd6baed | 1197 | if (FRAME_W32_WINDOW (f) != 0) |
ee78dc32 | 1198 | { |
3cf3436e | 1199 | if (x->cursor_pixel == old_fg) |
1f60c16a EZ |
1200 | { |
1201 | x->cursor_pixel = fg; | |
1202 | x->cursor_gc->background = fg; | |
1203 | } | |
3cf3436e | 1204 | |
6fc2811b | 1205 | update_face_from_frame_parameter (f, Qforeground_color, arg); |
ee78dc32 GV |
1206 | if (FRAME_VISIBLE_P (f)) |
1207 | redraw_frame (f); | |
1208 | } | |
1209 | } | |
1210 | ||
1211 | void | |
b56ceb92 | 1212 | x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
ee78dc32 | 1213 | { |
6fc2811b | 1214 | FRAME_BACKGROUND_PIXEL (f) |
ee78dc32 GV |
1215 | = x_decode_color (f, arg, WHITE_PIX_DEFAULT (f)); |
1216 | ||
fbd6baed | 1217 | if (FRAME_W32_WINDOW (f) != 0) |
ee78dc32 | 1218 | { |
6fc2811b JR |
1219 | SetWindowLong (FRAME_W32_WINDOW (f), WND_BACKGROUND_INDEX, |
1220 | FRAME_BACKGROUND_PIXEL (f)); | |
ee78dc32 | 1221 | |
6fc2811b | 1222 | update_face_from_frame_parameter (f, Qbackground_color, arg); |
ee78dc32 GV |
1223 | |
1224 | if (FRAME_VISIBLE_P (f)) | |
1225 | redraw_frame (f); | |
1226 | } | |
1227 | } | |
1228 | ||
1229 | void | |
b56ceb92 | 1230 | x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
ee78dc32 | 1231 | { |
7d63e5e3 | 1232 | Cursor cursor, nontext_cursor, mode_cursor, hand_cursor; |
dfc465d3 | 1233 | int count; |
ee78dc32 GV |
1234 | int mask_color; |
1235 | ||
1236 | if (!EQ (Qnil, arg)) | |
fbd6baed | 1237 | f->output_data.w32->mouse_pixel |
ee78dc32 | 1238 | = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); |
6fc2811b JR |
1239 | mask_color = FRAME_BACKGROUND_PIXEL (f); |
1240 | ||
1241 | /* Don't let pointers be invisible. */ | |
fbd6baed | 1242 | if (mask_color == f->output_data.w32->mouse_pixel |
6fc2811b JR |
1243 | && mask_color == FRAME_BACKGROUND_PIXEL (f)) |
1244 | f->output_data.w32->mouse_pixel = FRAME_FOREGROUND_PIXEL (f); | |
ee78dc32 | 1245 | |
5f004711 | 1246 | #if 0 /* TODO : Mouse cursor customization. */ |
ee78dc32 GV |
1247 | BLOCK_INPUT; |
1248 | ||
1249 | /* It's not okay to crash if the user selects a screwy cursor. */ | |
fadca6c6 | 1250 | count = x_catch_errors (FRAME_W32_DISPLAY (f)); |
ee78dc32 GV |
1251 | |
1252 | if (!EQ (Qnil, Vx_pointer_shape)) | |
1253 | { | |
b7826503 | 1254 | CHECK_NUMBER (Vx_pointer_shape); |
fbd6baed | 1255 | cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XINT (Vx_pointer_shape)); |
ee78dc32 GV |
1256 | } |
1257 | else | |
fbd6baed GV |
1258 | cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XC_xterm); |
1259 | x_check_errors (FRAME_W32_DISPLAY (f), "bad text pointer cursor: %s"); | |
ee78dc32 GV |
1260 | |
1261 | if (!EQ (Qnil, Vx_nontext_pointer_shape)) | |
1262 | { | |
b7826503 | 1263 | CHECK_NUMBER (Vx_nontext_pointer_shape); |
fbd6baed | 1264 | nontext_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), |
ee78dc32 GV |
1265 | XINT (Vx_nontext_pointer_shape)); |
1266 | } | |
1267 | else | |
fbd6baed GV |
1268 | nontext_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XC_left_ptr); |
1269 | x_check_errors (FRAME_W32_DISPLAY (f), "bad nontext pointer cursor: %s"); | |
ee78dc32 | 1270 | |
0af913d7 | 1271 | if (!EQ (Qnil, Vx_hourglass_pointer_shape)) |
6fc2811b | 1272 | { |
b7826503 | 1273 | CHECK_NUMBER (Vx_hourglass_pointer_shape); |
0af913d7 GM |
1274 | hourglass_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), |
1275 | XINT (Vx_hourglass_pointer_shape)); | |
6fc2811b JR |
1276 | } |
1277 | else | |
0af913d7 | 1278 | hourglass_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XC_watch); |
6fc2811b | 1279 | x_check_errors (FRAME_W32_DISPLAY (f), "bad busy pointer cursor: %s"); |
7d0393cf | 1280 | |
6fc2811b | 1281 | x_check_errors (FRAME_W32_DISPLAY (f), "bad nontext pointer cursor: %s"); |
ee78dc32 GV |
1282 | if (!EQ (Qnil, Vx_mode_pointer_shape)) |
1283 | { | |
b7826503 | 1284 | CHECK_NUMBER (Vx_mode_pointer_shape); |
fbd6baed | 1285 | mode_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), |
ee78dc32 GV |
1286 | XINT (Vx_mode_pointer_shape)); |
1287 | } | |
1288 | else | |
fbd6baed GV |
1289 | mode_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XC_xterm); |
1290 | x_check_errors (FRAME_W32_DISPLAY (f), "bad modeline pointer cursor: %s"); | |
ee78dc32 GV |
1291 | |
1292 | if (!EQ (Qnil, Vx_sensitive_text_pointer_shape)) | |
1293 | { | |
b7826503 | 1294 | CHECK_NUMBER (Vx_sensitive_text_pointer_shape); |
7d63e5e3 | 1295 | hand_cursor |
fbd6baed | 1296 | = XCreateFontCursor (FRAME_W32_DISPLAY (f), |
ee78dc32 GV |
1297 | XINT (Vx_sensitive_text_pointer_shape)); |
1298 | } | |
1299 | else | |
7d63e5e3 | 1300 | hand_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XC_crosshair); |
ee78dc32 | 1301 | |
4694d762 JR |
1302 | if (!NILP (Vx_window_horizontal_drag_shape)) |
1303 | { | |
b7826503 | 1304 | CHECK_NUMBER (Vx_window_horizontal_drag_shape); |
4694d762 JR |
1305 | horizontal_drag_cursor |
1306 | = XCreateFontCursor (FRAME_X_DISPLAY (f), | |
1307 | XINT (Vx_window_horizontal_drag_shape)); | |
1308 | } | |
1309 | else | |
1310 | horizontal_drag_cursor | |
1311 | = XCreateFontCursor (FRAME_X_DISPLAY (f), XC_sb_h_double_arrow); | |
1312 | ||
ee78dc32 | 1313 | /* Check and report errors with the above calls. */ |
fbd6baed | 1314 | x_check_errors (FRAME_W32_DISPLAY (f), "can't set cursor shape: %s"); |
fadca6c6 | 1315 | x_uncatch_errors (FRAME_W32_DISPLAY (f), count); |
ee78dc32 GV |
1316 | |
1317 | { | |
1318 | XColor fore_color, back_color; | |
1319 | ||
fbd6baed | 1320 | fore_color.pixel = f->output_data.w32->mouse_pixel; |
ee78dc32 | 1321 | back_color.pixel = mask_color; |
fbd6baed GV |
1322 | XQueryColor (FRAME_W32_DISPLAY (f), |
1323 | DefaultColormap (FRAME_W32_DISPLAY (f), | |
1324 | DefaultScreen (FRAME_W32_DISPLAY (f))), | |
ee78dc32 | 1325 | &fore_color); |
fbd6baed GV |
1326 | XQueryColor (FRAME_W32_DISPLAY (f), |
1327 | DefaultColormap (FRAME_W32_DISPLAY (f), | |
1328 | DefaultScreen (FRAME_W32_DISPLAY (f))), | |
ee78dc32 | 1329 | &back_color); |
fbd6baed | 1330 | XRecolorCursor (FRAME_W32_DISPLAY (f), cursor, |
ee78dc32 | 1331 | &fore_color, &back_color); |
fbd6baed | 1332 | XRecolorCursor (FRAME_W32_DISPLAY (f), nontext_cursor, |
ee78dc32 | 1333 | &fore_color, &back_color); |
fbd6baed | 1334 | XRecolorCursor (FRAME_W32_DISPLAY (f), mode_cursor, |
ee78dc32 | 1335 | &fore_color, &back_color); |
7d63e5e3 | 1336 | XRecolorCursor (FRAME_W32_DISPLAY (f), hand_cursor, |
ee78dc32 | 1337 | &fore_color, &back_color); |
0af913d7 | 1338 | XRecolorCursor (FRAME_W32_DISPLAY (f), hourglass_cursor, |
6fc2811b | 1339 | &fore_color, &back_color); |
ee78dc32 GV |
1340 | } |
1341 | ||
fbd6baed | 1342 | if (FRAME_W32_WINDOW (f) != 0) |
6fc2811b | 1343 | XDefineCursor (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), cursor); |
ee78dc32 | 1344 | |
fbd6baed GV |
1345 | if (cursor != f->output_data.w32->text_cursor && f->output_data.w32->text_cursor != 0) |
1346 | XFreeCursor (FRAME_W32_DISPLAY (f), f->output_data.w32->text_cursor); | |
1347 | f->output_data.w32->text_cursor = cursor; | |
1348 | ||
1349 | if (nontext_cursor != f->output_data.w32->nontext_cursor | |
1350 | && f->output_data.w32->nontext_cursor != 0) | |
1351 | XFreeCursor (FRAME_W32_DISPLAY (f), f->output_data.w32->nontext_cursor); | |
1352 | f->output_data.w32->nontext_cursor = nontext_cursor; | |
1353 | ||
0af913d7 GM |
1354 | if (hourglass_cursor != f->output_data.w32->hourglass_cursor |
1355 | && f->output_data.w32->hourglass_cursor != 0) | |
1356 | XFreeCursor (FRAME_W32_DISPLAY (f), f->output_data.w32->hourglass_cursor); | |
1357 | f->output_data.w32->hourglass_cursor = hourglass_cursor; | |
6fc2811b | 1358 | |
fbd6baed GV |
1359 | if (mode_cursor != f->output_data.w32->modeline_cursor |
1360 | && f->output_data.w32->modeline_cursor != 0) | |
1361 | XFreeCursor (FRAME_W32_DISPLAY (f), f->output_data.w32->modeline_cursor); | |
1362 | f->output_data.w32->modeline_cursor = mode_cursor; | |
7d0393cf | 1363 | |
7d63e5e3 KS |
1364 | if (hand_cursor != f->output_data.w32->hand_cursor |
1365 | && f->output_data.w32->hand_cursor != 0) | |
1366 | XFreeCursor (FRAME_W32_DISPLAY (f), f->output_data.w32->hand_cursor); | |
1367 | f->output_data.w32->hand_cursor = hand_cursor; | |
fbd6baed GV |
1368 | |
1369 | XFlush (FRAME_W32_DISPLAY (f)); | |
ee78dc32 | 1370 | UNBLOCK_INPUT; |
6fc2811b JR |
1371 | |
1372 | update_face_from_frame_parameter (f, Qmouse_color, arg); | |
767b1ff0 | 1373 | #endif /* TODO */ |
ee78dc32 GV |
1374 | } |
1375 | ||
1376 | void | |
b56ceb92 | 1377 | x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
ee78dc32 | 1378 | { |
70a0239a | 1379 | unsigned long fore_pixel, pixel; |
ee78dc32 | 1380 | |
dfff8a69 | 1381 | if (!NILP (Vx_cursor_fore_pixel)) |
ee78dc32 | 1382 | fore_pixel = x_decode_color (f, Vx_cursor_fore_pixel, |
70a0239a | 1383 | WHITE_PIX_DEFAULT (f)); |
ee78dc32 | 1384 | else |
6fc2811b | 1385 | fore_pixel = FRAME_BACKGROUND_PIXEL (f); |
70a0239a | 1386 | |
6759f872 | 1387 | pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); |
7d0393cf | 1388 | |
ee78dc32 | 1389 | /* Make sure that the cursor color differs from the background color. */ |
70a0239a | 1390 | if (pixel == FRAME_BACKGROUND_PIXEL (f)) |
ee78dc32 | 1391 | { |
70a0239a JR |
1392 | pixel = f->output_data.w32->mouse_pixel; |
1393 | if (pixel == fore_pixel) | |
6fc2811b | 1394 | fore_pixel = FRAME_BACKGROUND_PIXEL (f); |
ee78dc32 | 1395 | } |
70a0239a | 1396 | |
ac849ba4 | 1397 | f->output_data.w32->cursor_foreground_pixel = fore_pixel; |
70a0239a | 1398 | f->output_data.w32->cursor_pixel = pixel; |
ee78dc32 | 1399 | |
fbd6baed | 1400 | if (FRAME_W32_WINDOW (f) != 0) |
ee78dc32 | 1401 | { |
0327b4cc JR |
1402 | BLOCK_INPUT; |
1403 | /* Update frame's cursor_gc. */ | |
1404 | f->output_data.w32->cursor_gc->foreground = fore_pixel; | |
1405 | f->output_data.w32->cursor_gc->background = pixel; | |
1406 | ||
1407 | UNBLOCK_INPUT; | |
1408 | ||
ee78dc32 GV |
1409 | if (FRAME_VISIBLE_P (f)) |
1410 | { | |
70a0239a JR |
1411 | x_update_cursor (f, 0); |
1412 | x_update_cursor (f, 1); | |
ee78dc32 GV |
1413 | } |
1414 | } | |
6fc2811b JR |
1415 | |
1416 | update_face_from_frame_parameter (f, Qcursor_color, arg); | |
ee78dc32 GV |
1417 | } |
1418 | ||
33d52f9c GV |
1419 | /* Set the border-color of frame F to pixel value PIX. |
1420 | Note that this does not fully take effect if done before | |
7d0393cf | 1421 | F has a window. */ |
6d906347 | 1422 | |
33d52f9c | 1423 | void |
b56ceb92 | 1424 | x_set_border_pixel (struct frame *f, int pix) |
33d52f9c | 1425 | { |
6d906347 | 1426 | |
33d52f9c GV |
1427 | f->output_data.w32->border_pixel = pix; |
1428 | ||
be786000 | 1429 | if (FRAME_W32_WINDOW (f) != 0 && f->border_width > 0) |
33d52f9c GV |
1430 | { |
1431 | if (FRAME_VISIBLE_P (f)) | |
1432 | redraw_frame (f); | |
1433 | } | |
1434 | } | |
1435 | ||
ee78dc32 GV |
1436 | /* Set the border-color of frame F to value described by ARG. |
1437 | ARG can be a string naming a color. | |
1438 | The border-color is used for the border that is drawn by the server. | |
1439 | Note that this does not fully take effect if done before | |
1440 | F has a window; it must be redone when the window is created. */ | |
1441 | ||
1442 | void | |
b56ceb92 | 1443 | x_set_border_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
ee78dc32 | 1444 | { |
ee78dc32 GV |
1445 | int pix; |
1446 | ||
b7826503 | 1447 | CHECK_STRING (arg); |
ee78dc32 | 1448 | pix = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); |
ee78dc32 | 1449 | x_set_border_pixel (f, pix); |
6fc2811b | 1450 | update_face_from_frame_parameter (f, Qborder_color, arg); |
ee78dc32 GV |
1451 | } |
1452 | ||
dfff8a69 JR |
1453 | |
1454 | void | |
b56ceb92 | 1455 | x_set_cursor_type (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) |
dfff8a69 | 1456 | { |
50e363e6 | 1457 | set_frame_cursor_types (f, arg); |
ee78dc32 | 1458 | |
623cdbf2 | 1459 | /* Make sure the cursor gets redrawn. */ |
c922a224 | 1460 | cursor_type_changed = 1; |
ee78dc32 | 1461 | } |
dfff8a69 | 1462 | \f |
ee78dc32 | 1463 | void |
b56ceb92 | 1464 | x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
ee78dc32 | 1465 | { |
ee78dc32 GV |
1466 | int result; |
1467 | ||
eb7576ce GV |
1468 | if (NILP (arg) && NILP (oldval)) |
1469 | return; | |
1470 | ||
7d0393cf | 1471 | if (STRINGP (arg) && STRINGP (oldval) |
eb7576ce GV |
1472 | && EQ (Fstring_equal (oldval, arg), Qt)) |
1473 | return; | |
1474 | ||
1475 | if (SYMBOLP (arg) && SYMBOLP (oldval) && EQ (arg, oldval)) | |
ee78dc32 GV |
1476 | return; |
1477 | ||
1478 | BLOCK_INPUT; | |
ee78dc32 | 1479 | |
eb7576ce | 1480 | result = x_bitmap_icon (f, arg); |
ee78dc32 GV |
1481 | if (result) |
1482 | { | |
1483 | UNBLOCK_INPUT; | |
1484 | error ("No icon window available"); | |
1485 | } | |
1486 | ||
ee78dc32 | 1487 | UNBLOCK_INPUT; |
ee78dc32 GV |
1488 | } |
1489 | ||
ee78dc32 | 1490 | void |
b56ceb92 | 1491 | x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
ee78dc32 | 1492 | { |
ee78dc32 GV |
1493 | if (STRINGP (arg)) |
1494 | { | |
1495 | if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt)) | |
1496 | return; | |
1497 | } | |
3f65d6f5 | 1498 | else if (!NILP (arg) || NILP (oldval)) |
ee78dc32 GV |
1499 | return; |
1500 | ||
1501 | f->icon_name = arg; | |
1502 | ||
1503 | #if 0 | |
fbd6baed | 1504 | if (f->output_data.w32->icon_bitmap != 0) |
ee78dc32 GV |
1505 | return; |
1506 | ||
1507 | BLOCK_INPUT; | |
1508 | ||
1509 | result = x_text_icon (f, | |
51b59d79 PE |
1510 | SSDATA ((!NILP (f->icon_name) |
1511 | ? f->icon_name | |
1512 | : !NILP (f->title) | |
1513 | ? f->title | |
1514 | : f->name))); | |
ee78dc32 GV |
1515 | |
1516 | if (result) | |
1517 | { | |
1518 | UNBLOCK_INPUT; | |
1519 | error ("No icon window available"); | |
1520 | } | |
1521 | ||
1522 | /* If the window was unmapped (and its icon was mapped), | |
1523 | the new icon is not mapped, so map the window in its stead. */ | |
1524 | if (FRAME_VISIBLE_P (f)) | |
1525 | { | |
1526 | #ifdef USE_X_TOOLKIT | |
fbd6baed | 1527 | XtPopup (f->output_data.w32->widget, XtGrabNone); |
ee78dc32 | 1528 | #endif |
fbd6baed | 1529 | XMapWindow (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f)); |
ee78dc32 GV |
1530 | } |
1531 | ||
fbd6baed | 1532 | XFlush (FRAME_W32_DISPLAY (f)); |
ee78dc32 GV |
1533 | UNBLOCK_INPUT; |
1534 | #endif | |
1535 | } | |
1536 | ||
a1258667 | 1537 | \f |
ee78dc32 | 1538 | void |
b56ceb92 | 1539 | x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) |
ee78dc32 GV |
1540 | { |
1541 | int nlines; | |
1542 | int olines = FRAME_MENU_BAR_LINES (f); | |
1543 | ||
1544 | /* Right now, menu bars don't work properly in minibuf-only frames; | |
1545 | most of the commands try to apply themselves to the minibuffer | |
6fc2811b | 1546 | frame itself, and get an error because you can't switch buffers |
ee78dc32 GV |
1547 | in or split the minibuffer window. */ |
1548 | if (FRAME_MINIBUF_ONLY_P (f)) | |
1549 | return; | |
1550 | ||
1551 | if (INTEGERP (value)) | |
1552 | nlines = XINT (value); | |
1553 | else | |
1554 | nlines = 0; | |
1555 | ||
1556 | FRAME_MENU_BAR_LINES (f) = 0; | |
1557 | if (nlines) | |
1558 | FRAME_EXTERNAL_MENU_BAR (f) = 1; | |
1559 | else | |
1560 | { | |
1561 | if (FRAME_EXTERNAL_MENU_BAR (f) == 1) | |
1562 | free_frame_menubar (f); | |
1563 | FRAME_EXTERNAL_MENU_BAR (f) = 0; | |
1edf84e7 GV |
1564 | |
1565 | /* Adjust the frame size so that the client (text) dimensions | |
1566 | remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being | |
1567 | set correctly. */ | |
be786000 | 1568 | x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f)); |
6fc2811b | 1569 | do_pending_window_change (0); |
ee78dc32 | 1570 | } |
6fc2811b JR |
1571 | adjust_glyphs (f); |
1572 | } | |
1573 | ||
1574 | ||
1575 | /* Set the number of lines used for the tool bar of frame F to VALUE. | |
1576 | VALUE not an integer, or < 0 means set the lines to zero. OLDVAL | |
1577 | is the old number of tool bar lines. This function changes the | |
1578 | height of all windows on frame F to match the new tool bar height. | |
1579 | The frame's height doesn't change. */ | |
1580 | ||
1581 | void | |
b56ceb92 | 1582 | x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) |
6fc2811b | 1583 | { |
36f8209a JR |
1584 | int delta, nlines, root_height; |
1585 | Lisp_Object root_window; | |
6fc2811b | 1586 | |
dc220243 JR |
1587 | /* Treat tool bars like menu bars. */ |
1588 | if (FRAME_MINIBUF_ONLY_P (f)) | |
1589 | return; | |
1590 | ||
6fc2811b JR |
1591 | /* Use VALUE only if an integer >= 0. */ |
1592 | if (INTEGERP (value) && XINT (value) >= 0) | |
1593 | nlines = XFASTINT (value); | |
1594 | else | |
1595 | nlines = 0; | |
1596 | ||
1597 | /* Make sure we redisplay all windows in this frame. */ | |
1598 | ++windows_or_buffers_changed; | |
1599 | ||
1600 | delta = nlines - FRAME_TOOL_BAR_LINES (f); | |
36f8209a JR |
1601 | |
1602 | /* Don't resize the tool-bar to more than we have room for. */ | |
1603 | root_window = FRAME_ROOT_WINDOW (f); | |
be786000 | 1604 | root_height = WINDOW_TOTAL_LINES (XWINDOW (root_window)); |
36f8209a JR |
1605 | if (root_height - delta < 1) |
1606 | { | |
1607 | delta = root_height - 1; | |
1608 | nlines = FRAME_TOOL_BAR_LINES (f) + delta; | |
1609 | } | |
1610 | ||
6fc2811b | 1611 | FRAME_TOOL_BAR_LINES (f) = nlines; |
6d906347 | 1612 | change_window_heights (root_window, delta); |
6fc2811b | 1613 | adjust_glyphs (f); |
36f8209a JR |
1614 | |
1615 | /* We also have to make sure that the internal border at the top of | |
1616 | the frame, below the menu bar or tool bar, is redrawn when the | |
1617 | tool bar disappears. This is so because the internal border is | |
1618 | below the tool bar if one is displayed, but is below the menu bar | |
1619 | if there isn't a tool bar. The tool bar draws into the area | |
1620 | below the menu bar. */ | |
1621 | if (FRAME_W32_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0) | |
1622 | { | |
2dc8b986 | 1623 | clear_frame (f); |
36f8209a | 1624 | clear_current_matrices (f); |
36f8209a JR |
1625 | } |
1626 | ||
1627 | /* If the tool bar gets smaller, the internal border below it | |
1628 | has to be cleared. It was formerly part of the display | |
1629 | of the larger tool bar, and updating windows won't clear it. */ | |
1630 | if (delta < 0) | |
1631 | { | |
1632 | int height = FRAME_INTERNAL_BORDER_WIDTH (f); | |
be786000 KS |
1633 | int width = FRAME_PIXEL_WIDTH (f); |
1634 | int y = nlines * FRAME_LINE_HEIGHT (f); | |
36f8209a JR |
1635 | |
1636 | BLOCK_INPUT; | |
1637 | { | |
1638 | HDC hdc = get_frame_dc (f); | |
1639 | w32_clear_area (f, hdc, 0, y, width, height); | |
1640 | release_frame_dc (f, hdc); | |
1641 | } | |
1642 | UNBLOCK_INPUT; | |
3cf3436e JR |
1643 | |
1644 | if (WINDOWP (f->tool_bar_window)) | |
1645 | clear_glyph_matrix (XWINDOW (f->tool_bar_window)->current_matrix); | |
36f8209a | 1646 | } |
ee78dc32 GV |
1647 | } |
1648 | ||
6fc2811b | 1649 | |
ee78dc32 | 1650 | /* Change the name of frame F to NAME. If NAME is nil, set F's name to |
fbd6baed | 1651 | w32_id_name. |
ee78dc32 GV |
1652 | |
1653 | If EXPLICIT is non-zero, that indicates that lisp code is setting the | |
1654 | name; if NAME is a string, set F's name to NAME and set | |
1655 | F->explicit_name; if NAME is Qnil, then clear F->explicit_name. | |
1656 | ||
1657 | If EXPLICIT is zero, that indicates that Emacs redisplay code is | |
1658 | suggesting a new name, which lisp code should override; if | |
1659 | F->explicit_name is set, ignore the new name; otherwise, set it. */ | |
1660 | ||
1661 | void | |
b56ceb92 | 1662 | x_set_name (struct frame *f, Lisp_Object name, int explicit) |
ee78dc32 | 1663 | { |
7d0393cf | 1664 | /* Make sure that requests from lisp code override requests from |
ee78dc32 GV |
1665 | Emacs redisplay code. */ |
1666 | if (explicit) | |
1667 | { | |
1668 | /* If we're switching from explicit to implicit, we had better | |
1669 | update the mode lines and thereby update the title. */ | |
1670 | if (f->explicit_name && NILP (name)) | |
1671 | update_mode_lines = 1; | |
1672 | ||
1673 | f->explicit_name = ! NILP (name); | |
1674 | } | |
1675 | else if (f->explicit_name) | |
1676 | return; | |
1677 | ||
fbd6baed | 1678 | /* If NAME is nil, set the name to the w32_id_name. */ |
ee78dc32 GV |
1679 | if (NILP (name)) |
1680 | { | |
1681 | /* Check for no change needed in this very common case | |
1682 | before we do any consing. */ | |
fbd6baed | 1683 | if (!strcmp (FRAME_W32_DISPLAY_INFO (f)->w32_id_name, |
d5db4077 | 1684 | SDATA (f->name))) |
ee78dc32 | 1685 | return; |
fbd6baed | 1686 | name = build_string (FRAME_W32_DISPLAY_INFO (f)->w32_id_name); |
ee78dc32 GV |
1687 | } |
1688 | else | |
b7826503 | 1689 | CHECK_STRING (name); |
ee78dc32 GV |
1690 | |
1691 | /* Don't change the name if it's already NAME. */ | |
1692 | if (! NILP (Fstring_equal (name, f->name))) | |
1693 | return; | |
1694 | ||
1edf84e7 GV |
1695 | f->name = name; |
1696 | ||
1697 | /* For setting the frame title, the title parameter should override | |
1698 | the name parameter. */ | |
1699 | if (! NILP (f->title)) | |
1700 | name = f->title; | |
1701 | ||
fbd6baed | 1702 | if (FRAME_W32_WINDOW (f)) |
ee78dc32 | 1703 | { |
6fc2811b | 1704 | if (STRING_MULTIBYTE (name)) |
dfff8a69 | 1705 | name = ENCODE_SYSTEM (name); |
6fc2811b | 1706 | |
ee78dc32 | 1707 | BLOCK_INPUT; |
74084731 | 1708 | SetWindowText (FRAME_W32_WINDOW (f), SDATA (name)); |
ee78dc32 GV |
1709 | UNBLOCK_INPUT; |
1710 | } | |
ee78dc32 GV |
1711 | } |
1712 | ||
1713 | /* This function should be called when the user's lisp code has | |
1714 | specified a name for the frame; the name will override any set by the | |
1715 | redisplay code. */ | |
1716 | void | |
b56ceb92 | 1717 | x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) |
ee78dc32 GV |
1718 | { |
1719 | x_set_name (f, arg, 1); | |
1720 | } | |
1721 | ||
1722 | /* This function should be called by Emacs redisplay code to set the | |
1723 | name; names set this way will never override names set by the user's | |
1724 | lisp code. */ | |
1725 | void | |
b56ceb92 | 1726 | x_implicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) |
ee78dc32 GV |
1727 | { |
1728 | x_set_name (f, arg, 0); | |
1729 | } | |
1edf84e7 GV |
1730 | \f |
1731 | /* Change the title of frame F to NAME. | |
40aa4c27 | 1732 | If NAME is nil, use the frame name as the title. */ |
ee78dc32 | 1733 | |
1edf84e7 | 1734 | void |
b56ceb92 | 1735 | x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name) |
1edf84e7 GV |
1736 | { |
1737 | /* Don't change the title if it's already NAME. */ | |
1738 | if (EQ (name, f->title)) | |
1739 | return; | |
1740 | ||
1741 | update_mode_lines = 1; | |
1742 | ||
1743 | f->title = name; | |
1744 | ||
1745 | if (NILP (name)) | |
1746 | name = f->name; | |
1747 | ||
1748 | if (FRAME_W32_WINDOW (f)) | |
1749 | { | |
6fc2811b | 1750 | if (STRING_MULTIBYTE (name)) |
dfff8a69 | 1751 | name = ENCODE_SYSTEM (name); |
6fc2811b | 1752 | |
1edf84e7 | 1753 | BLOCK_INPUT; |
74084731 | 1754 | SetWindowText (FRAME_W32_WINDOW (f), SDATA (name)); |
1edf84e7 GV |
1755 | UNBLOCK_INPUT; |
1756 | } | |
1757 | } | |
ee78dc32 | 1758 | |
b56ceb92 JB |
1759 | void |
1760 | x_set_scroll_bar_default_width (struct frame *f) | |
ee78dc32 | 1761 | { |
be786000 | 1762 | int wid = FRAME_COLUMN_WIDTH (f); |
6fc2811b | 1763 | |
be786000 KS |
1764 | FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = GetSystemMetrics (SM_CXVSCROLL); |
1765 | FRAME_CONFIG_SCROLL_BAR_COLS (f) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) + | |
1766 | wid - 1) / wid; | |
ee78dc32 | 1767 | } |
6d906347 | 1768 | |
ee78dc32 | 1769 | \f |
3faa984f | 1770 | /* Subroutines for creating a frame. */ |
ee78dc32 | 1771 | |
c9b2104d JR |
1772 | Cursor |
1773 | w32_load_cursor (LPCTSTR name) | |
1774 | { | |
1775 | /* Try first to load cursor from application resource. */ | |
74084731 | 1776 | Cursor cursor = LoadImage ((HINSTANCE) GetModuleHandle (NULL), |
c9b2104d JR |
1777 | name, IMAGE_CURSOR, 0, 0, |
1778 | LR_DEFAULTCOLOR | LR_DEFAULTSIZE | LR_SHARED); | |
1779 | if (!cursor) | |
1780 | { | |
1781 | /* Then try to load a shared predefined cursor. */ | |
1782 | cursor = LoadImage (NULL, name, IMAGE_CURSOR, 0, 0, | |
1783 | LR_DEFAULTCOLOR | LR_DEFAULTSIZE | LR_SHARED); | |
1784 | } | |
1785 | return cursor; | |
1786 | } | |
ee78dc32 | 1787 | |
24f981c9 | 1788 | static LRESULT CALLBACK w32_wnd_proc (HWND, UINT, WPARAM, LPARAM); |
ee78dc32 | 1789 | |
74084731 | 1790 | static BOOL |
b56ceb92 | 1791 | w32_init_class (HINSTANCE hinst) |
ee78dc32 GV |
1792 | { |
1793 | WNDCLASS wc; | |
1794 | ||
5ac45f98 | 1795 | wc.style = CS_HREDRAW | CS_VREDRAW; |
fbd6baed | 1796 | wc.lpfnWndProc = (WNDPROC) w32_wnd_proc; |
ee78dc32 GV |
1797 | wc.cbClsExtra = 0; |
1798 | wc.cbWndExtra = WND_EXTRA_BYTES; | |
1799 | wc.hInstance = hinst; | |
1800 | wc.hIcon = LoadIcon (hinst, EMACS_CLASS); | |
c9b2104d | 1801 | wc.hCursor = w32_load_cursor (IDC_ARROW); |
4587b026 | 1802 | wc.hbrBackground = NULL; /* GetStockObject (WHITE_BRUSH); */ |
ee78dc32 GV |
1803 | wc.lpszMenuName = NULL; |
1804 | wc.lpszClassName = EMACS_CLASS; | |
1805 | ||
1806 | return (RegisterClass (&wc)); | |
1807 | } | |
1808 | ||
74084731 | 1809 | static HWND |
b56ceb92 | 1810 | w32_createscrollbar (struct frame *f, struct scroll_bar * bar) |
ee78dc32 GV |
1811 | { |
1812 | return (CreateWindow ("SCROLLBAR", "", SBS_VERT | WS_CHILD | WS_VISIBLE, | |
1813 | /* Position and size of scroll bar. */ | |
74084731 JB |
1814 | XINT (bar->left) + VERTICAL_SCROLL_BAR_WIDTH_TRIM, |
1815 | XINT (bar->top), | |
1816 | XINT (bar->width) - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2, | |
1817 | XINT (bar->height), | |
fbd6baed | 1818 | FRAME_W32_WINDOW (f), |
ee78dc32 GV |
1819 | NULL, |
1820 | hinst, | |
1821 | NULL)); | |
1822 | } | |
1823 | ||
74084731 | 1824 | static void |
b56ceb92 | 1825 | w32_createwindow (struct frame *f) |
ee78dc32 GV |
1826 | { |
1827 | HWND hwnd; | |
1edf84e7 | 1828 | RECT rect; |
df70725f EZ |
1829 | Lisp_Object top = Qunbound; |
1830 | Lisp_Object left = Qunbound; | |
3faa984f | 1831 | struct w32_display_info *dpyinfo = &one_w32_display_info; |
1edf84e7 GV |
1832 | |
1833 | rect.left = rect.top = 0; | |
be786000 KS |
1834 | rect.right = FRAME_PIXEL_WIDTH (f); |
1835 | rect.bottom = FRAME_PIXEL_HEIGHT (f); | |
7d0393cf | 1836 | |
1edf84e7 GV |
1837 | AdjustWindowRect (&rect, f->output_data.w32->dwStyle, |
1838 | FRAME_EXTERNAL_MENU_BAR (f)); | |
7d0393cf | 1839 | |
ee78dc32 | 1840 | /* Do first time app init */ |
7d0393cf | 1841 | |
ee78dc32 GV |
1842 | if (!hprevinst) |
1843 | { | |
fbd6baed | 1844 | w32_init_class (hinst); |
ee78dc32 | 1845 | } |
7d0393cf | 1846 | |
2770d589 JR |
1847 | if (f->size_hint_flags & USPosition || f->size_hint_flags & PPosition) |
1848 | { | |
1849 | XSETINT (left, f->left_pos); | |
1850 | XSETINT (top, f->top_pos); | |
1851 | } | |
1852 | else if (EQ (left, Qunbound) && EQ (top, Qunbound)) | |
df70725f EZ |
1853 | { |
1854 | /* When called with RES_TYPE_NUMBER, w32_get_arg will return zero | |
1855 | for anything that is not a number and is not Qunbound. */ | |
3faa984f JR |
1856 | left = x_get_arg (dpyinfo, Qnil, Qleft, "left", "Left", RES_TYPE_NUMBER); |
1857 | top = x_get_arg (dpyinfo, Qnil, Qtop, "top", "Top", RES_TYPE_NUMBER); | |
df70725f | 1858 | } |
48b62d10 | 1859 | |
1edf84e7 GV |
1860 | FRAME_W32_WINDOW (f) = hwnd |
1861 | = CreateWindow (EMACS_CLASS, | |
1862 | f->namebuf, | |
9ead1b60 | 1863 | f->output_data.w32->dwStyle | WS_CLIPCHILDREN, |
48b62d10 EZ |
1864 | EQ (left, Qunbound) ? CW_USEDEFAULT : XINT (left), |
1865 | EQ (top, Qunbound) ? CW_USEDEFAULT : XINT (top), | |
1edf84e7 GV |
1866 | rect.right - rect.left, |
1867 | rect.bottom - rect.top, | |
1868 | NULL, | |
1869 | NULL, | |
1870 | hinst, | |
1871 | NULL); | |
1872 | ||
ee78dc32 GV |
1873 | if (hwnd) |
1874 | { | |
be786000 KS |
1875 | SetWindowLong (hwnd, WND_FONTWIDTH_INDEX, FRAME_COLUMN_WIDTH (f)); |
1876 | SetWindowLong (hwnd, WND_LINEHEIGHT_INDEX, FRAME_LINE_HEIGHT (f)); | |
1877 | SetWindowLong (hwnd, WND_BORDER_INDEX, FRAME_INTERNAL_BORDER_WIDTH (f)); | |
1878 | SetWindowLong (hwnd, WND_SCROLLBAR_INDEX, f->scroll_bar_actual_width); | |
6fc2811b | 1879 | SetWindowLong (hwnd, WND_BACKGROUND_INDEX, FRAME_BACKGROUND_PIXEL (f)); |
ee78dc32 | 1880 | |
cb9e33d4 RS |
1881 | /* Enable drag-n-drop. */ |
1882 | DragAcceptFiles (hwnd, TRUE); | |
7d0393cf | 1883 | |
5ac45f98 GV |
1884 | /* Do this to discard the default setting specified by our parent. */ |
1885 | ShowWindow (hwnd, SW_HIDE); | |
1771bb6e EZ |
1886 | |
1887 | /* Update frame positions. */ | |
1888 | GetWindowRect (hwnd, &rect); | |
1889 | f->left_pos = rect.left; | |
1890 | f->top_pos = rect.top; | |
3c190163 | 1891 | } |
3c190163 GV |
1892 | } |
1893 | ||
74084731 | 1894 | static void |
b56ceb92 | 1895 | my_post_msg (W32Msg * wmsg, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
ee78dc32 GV |
1896 | { |
1897 | wmsg->msg.hwnd = hwnd; | |
1898 | wmsg->msg.message = msg; | |
1899 | wmsg->msg.wParam = wParam; | |
1900 | wmsg->msg.lParam = lParam; | |
1901 | wmsg->msg.time = GetMessageTime (); | |
1902 | ||
1903 | post_msg (wmsg); | |
1904 | } | |
1905 | ||
e9e23e23 | 1906 | /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish |
a1a80b40 GV |
1907 | between left and right keys as advertised. We test for this |
1908 | support dynamically, and set a flag when the support is absent. If | |
1909 | absent, we keep track of the left and right control and alt keys | |
1910 | ourselves. This is particularly necessary on keyboards that rely | |
1911 | upon the AltGr key, which is represented as having the left control | |
1912 | and right alt keys pressed. For these keyboards, we need to know | |
1913 | when the left alt key has been pressed in addition to the AltGr key | |
1914 | so that we can properly support M-AltGr-key sequences (such as M-@ | |
1915 | on Swedish keyboards). */ | |
1916 | ||
1917 | #define EMACS_LCONTROL 0 | |
1918 | #define EMACS_RCONTROL 1 | |
1919 | #define EMACS_LMENU 2 | |
1920 | #define EMACS_RMENU 3 | |
1921 | ||
1922 | static int modifiers[4]; | |
1923 | static int modifiers_recorded; | |
1924 | static int modifier_key_support_tested; | |
1925 | ||
1926 | static void | |
1927 | test_modifier_support (unsigned int wparam) | |
1928 | { | |
1929 | unsigned int l, r; | |
1930 | ||
1931 | if (wparam != VK_CONTROL && wparam != VK_MENU) | |
1932 | return; | |
1933 | if (wparam == VK_CONTROL) | |
1934 | { | |
1935 | l = VK_LCONTROL; | |
1936 | r = VK_RCONTROL; | |
1937 | } | |
1938 | else | |
1939 | { | |
1940 | l = VK_LMENU; | |
1941 | r = VK_RMENU; | |
1942 | } | |
1943 | if (!(GetKeyState (l) & 0x8000) && !(GetKeyState (r) & 0x8000)) | |
1944 | modifiers_recorded = 1; | |
1945 | else | |
1946 | modifiers_recorded = 0; | |
1947 | modifier_key_support_tested = 1; | |
1948 | } | |
1949 | ||
1950 | static void | |
1951 | record_keydown (unsigned int wparam, unsigned int lparam) | |
1952 | { | |
1953 | int i; | |
1954 | ||
1955 | if (!modifier_key_support_tested) | |
1956 | test_modifier_support (wparam); | |
1957 | ||
1958 | if ((wparam != VK_CONTROL && wparam != VK_MENU) || !modifiers_recorded) | |
1959 | return; | |
1960 | ||
1961 | if (wparam == VK_CONTROL) | |
1962 | i = (lparam & 0x1000000) ? EMACS_RCONTROL : EMACS_LCONTROL; | |
1963 | else | |
1964 | i = (lparam & 0x1000000) ? EMACS_RMENU : EMACS_LMENU; | |
1965 | ||
1966 | modifiers[i] = 1; | |
1967 | } | |
1968 | ||
1969 | static void | |
1970 | record_keyup (unsigned int wparam, unsigned int lparam) | |
1971 | { | |
1972 | int i; | |
1973 | ||
1974 | if ((wparam != VK_CONTROL && wparam != VK_MENU) || !modifiers_recorded) | |
1975 | return; | |
1976 | ||
1977 | if (wparam == VK_CONTROL) | |
1978 | i = (lparam & 0x1000000) ? EMACS_RCONTROL : EMACS_LCONTROL; | |
1979 | else | |
1980 | i = (lparam & 0x1000000) ? EMACS_RMENU : EMACS_LMENU; | |
1981 | ||
1982 | modifiers[i] = 0; | |
1983 | } | |
1984 | ||
da36a4d6 | 1985 | /* Emacs can lose focus while a modifier key has been pressed. When |
7d0393cf | 1986 | it regains focus, be conservative and clear all modifiers since |
da36a4d6 GV |
1987 | we cannot reconstruct the left and right modifier state. */ |
1988 | static void | |
b56ceb92 | 1989 | reset_modifiers (void) |
da36a4d6 | 1990 | { |
8681157a RS |
1991 | SHORT ctrl, alt; |
1992 | ||
adcc3809 GV |
1993 | if (GetFocus () == NULL) |
1994 | /* Emacs doesn't have keyboard focus. Do nothing. */ | |
da36a4d6 | 1995 | return; |
8681157a RS |
1996 | |
1997 | ctrl = GetAsyncKeyState (VK_CONTROL); | |
1998 | alt = GetAsyncKeyState (VK_MENU); | |
1999 | ||
8681157a RS |
2000 | if (!(ctrl & 0x08000)) |
2001 | /* Clear any recorded control modifier state. */ | |
2002 | modifiers[EMACS_RCONTROL] = modifiers[EMACS_LCONTROL] = 0; | |
2003 | ||
2004 | if (!(alt & 0x08000)) | |
2005 | /* Clear any recorded alt modifier state. */ | |
2006 | modifiers[EMACS_RMENU] = modifiers[EMACS_LMENU] = 0; | |
2007 | ||
adcc3809 GV |
2008 | /* Update the state of all modifier keys, because modifiers used in |
2009 | hot-key combinations can get stuck on if Emacs loses focus as a | |
2010 | result of a hot-key being pressed. */ | |
2011 | { | |
2012 | BYTE keystate[256]; | |
2013 | ||
2014 | #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8) | |
2015 | ||
2016 | GetKeyboardState (keystate); | |
2017 | keystate[VK_SHIFT] = CURRENT_STATE (VK_SHIFT); | |
2018 | keystate[VK_CONTROL] = CURRENT_STATE (VK_CONTROL); | |
2019 | keystate[VK_LCONTROL] = CURRENT_STATE (VK_LCONTROL); | |
2020 | keystate[VK_RCONTROL] = CURRENT_STATE (VK_RCONTROL); | |
2021 | keystate[VK_MENU] = CURRENT_STATE (VK_MENU); | |
2022 | keystate[VK_LMENU] = CURRENT_STATE (VK_LMENU); | |
2023 | keystate[VK_RMENU] = CURRENT_STATE (VK_RMENU); | |
2024 | keystate[VK_LWIN] = CURRENT_STATE (VK_LWIN); | |
2025 | keystate[VK_RWIN] = CURRENT_STATE (VK_RWIN); | |
2026 | keystate[VK_APPS] = CURRENT_STATE (VK_APPS); | |
2027 | SetKeyboardState (keystate); | |
2028 | } | |
da36a4d6 GV |
2029 | } |
2030 | ||
7830e24b RS |
2031 | /* Synchronize modifier state with what is reported with the current |
2032 | keystroke. Even if we cannot distinguish between left and right | |
2033 | modifier keys, we know that, if no modifiers are set, then neither | |
2034 | the left or right modifier should be set. */ | |
2035 | static void | |
b56ceb92 | 2036 | sync_modifiers (void) |
7830e24b RS |
2037 | { |
2038 | if (!modifiers_recorded) | |
2039 | return; | |
2040 | ||
7d0393cf | 2041 | if (!(GetKeyState (VK_CONTROL) & 0x8000)) |
7830e24b RS |
2042 | modifiers[EMACS_RCONTROL] = modifiers[EMACS_LCONTROL] = 0; |
2043 | ||
7d0393cf | 2044 | if (!(GetKeyState (VK_MENU) & 0x8000)) |
7830e24b RS |
2045 | modifiers[EMACS_RMENU] = modifiers[EMACS_LMENU] = 0; |
2046 | } | |
2047 | ||
a1a80b40 GV |
2048 | static int |
2049 | modifier_set (int vkey) | |
2050 | { | |
ccc2d29c | 2051 | if (vkey == VK_CAPITAL || vkey == VK_SCROLL) |
891560d6 | 2052 | return (GetKeyState (vkey) & 0x1); |
a1a80b40 GV |
2053 | if (!modifiers_recorded) |
2054 | return (GetKeyState (vkey) & 0x8000); | |
2055 | ||
2056 | switch (vkey) | |
2057 | { | |
2058 | case VK_LCONTROL: | |
2059 | return modifiers[EMACS_LCONTROL]; | |
2060 | case VK_RCONTROL: | |
2061 | return modifiers[EMACS_RCONTROL]; | |
2062 | case VK_LMENU: | |
2063 | return modifiers[EMACS_LMENU]; | |
2064 | case VK_RMENU: | |
2065 | return modifiers[EMACS_RMENU]; | |
a1a80b40 GV |
2066 | } |
2067 | return (GetKeyState (vkey) & 0x8000); | |
2068 | } | |
2069 | ||
ccc2d29c GV |
2070 | /* Convert between the modifier bits W32 uses and the modifier bits |
2071 | Emacs uses. */ | |
2072 | ||
2073 | unsigned int | |
2074 | w32_key_to_modifier (int key) | |
2075 | { | |
2076 | Lisp_Object key_mapping; | |
2077 | ||
2078 | switch (key) | |
2079 | { | |
2080 | case VK_LWIN: | |
2081 | key_mapping = Vw32_lwindow_modifier; | |
2082 | break; | |
2083 | case VK_RWIN: | |
2084 | key_mapping = Vw32_rwindow_modifier; | |
2085 | break; | |
2086 | case VK_APPS: | |
2087 | key_mapping = Vw32_apps_modifier; | |
2088 | break; | |
2089 | case VK_SCROLL: | |
2090 | key_mapping = Vw32_scroll_lock_modifier; | |
2091 | break; | |
2092 | default: | |
2093 | key_mapping = Qnil; | |
2094 | } | |
2095 | ||
adcc3809 GV |
2096 | /* NB. This code runs in the input thread, asychronously to the lisp |
2097 | thread, so we must be careful to ensure access to lisp data is | |
2098 | thread-safe. The following code is safe because the modifier | |
2099 | variable values are updated atomically from lisp and symbols are | |
2100 | not relocated by GC. Also, we don't have to worry about seeing GC | |
2101 | markbits here. */ | |
2102 | if (EQ (key_mapping, Qhyper)) | |
ccc2d29c | 2103 | return hyper_modifier; |
adcc3809 | 2104 | if (EQ (key_mapping, Qsuper)) |
ccc2d29c | 2105 | return super_modifier; |
adcc3809 | 2106 | if (EQ (key_mapping, Qmeta)) |
ccc2d29c | 2107 | return meta_modifier; |
adcc3809 | 2108 | if (EQ (key_mapping, Qalt)) |
ccc2d29c | 2109 | return alt_modifier; |
adcc3809 | 2110 | if (EQ (key_mapping, Qctrl)) |
ccc2d29c | 2111 | return ctrl_modifier; |
adcc3809 | 2112 | if (EQ (key_mapping, Qcontrol)) /* synonym for ctrl */ |
ccc2d29c | 2113 | return ctrl_modifier; |
adcc3809 | 2114 | if (EQ (key_mapping, Qshift)) |
ccc2d29c GV |
2115 | return shift_modifier; |
2116 | ||
2117 | /* Don't generate any modifier if not explicitly requested. */ | |
2118 | return 0; | |
2119 | } | |
2120 | ||
74084731 | 2121 | static unsigned int |
b56ceb92 | 2122 | w32_get_modifiers (void) |
ccc2d29c GV |
2123 | { |
2124 | return ((modifier_set (VK_SHIFT) ? shift_modifier : 0) | | |
2125 | (modifier_set (VK_CONTROL) ? ctrl_modifier : 0) | | |
2126 | (modifier_set (VK_LWIN) ? w32_key_to_modifier (VK_LWIN) : 0) | | |
2127 | (modifier_set (VK_RWIN) ? w32_key_to_modifier (VK_RWIN) : 0) | | |
2128 | (modifier_set (VK_APPS) ? w32_key_to_modifier (VK_APPS) : 0) | | |
2129 | (modifier_set (VK_SCROLL) ? w32_key_to_modifier (VK_SCROLL) : 0) | | |
2130 | (modifier_set (VK_MENU) ? | |
2131 | ((NILP (Vw32_alt_is_meta)) ? alt_modifier : meta_modifier) : 0)); | |
2132 | } | |
2133 | ||
a1a80b40 GV |
2134 | /* We map the VK_* modifiers into console modifier constants |
2135 | so that we can use the same routines to handle both console | |
2136 | and window input. */ | |
2137 | ||
2138 | static int | |
b56ceb92 | 2139 | construct_console_modifiers (void) |
a1a80b40 GV |
2140 | { |
2141 | int mods; | |
2142 | ||
a1a80b40 GV |
2143 | mods = 0; |
2144 | mods |= (modifier_set (VK_SHIFT)) ? SHIFT_PRESSED : 0; | |
2145 | mods |= (modifier_set (VK_CAPITAL)) ? CAPSLOCK_ON : 0; | |
ccc2d29c GV |
2146 | mods |= (modifier_set (VK_SCROLL)) ? SCROLLLOCK_ON : 0; |
2147 | mods |= (modifier_set (VK_NUMLOCK)) ? NUMLOCK_ON : 0; | |
a1a80b40 GV |
2148 | mods |= (modifier_set (VK_LCONTROL)) ? LEFT_CTRL_PRESSED : 0; |
2149 | mods |= (modifier_set (VK_RCONTROL)) ? RIGHT_CTRL_PRESSED : 0; | |
2150 | mods |= (modifier_set (VK_LMENU)) ? LEFT_ALT_PRESSED : 0; | |
2151 | mods |= (modifier_set (VK_RMENU)) ? RIGHT_ALT_PRESSED : 0; | |
ccc2d29c GV |
2152 | mods |= (modifier_set (VK_LWIN)) ? LEFT_WIN_PRESSED : 0; |
2153 | mods |= (modifier_set (VK_RWIN)) ? RIGHT_WIN_PRESSED : 0; | |
2154 | mods |= (modifier_set (VK_APPS)) ? APPS_PRESSED : 0; | |
a1a80b40 GV |
2155 | |
2156 | return mods; | |
2157 | } | |
2158 | ||
ccc2d29c GV |
2159 | static int |
2160 | w32_get_key_modifiers (unsigned int wparam, unsigned int lparam) | |
da36a4d6 | 2161 | { |
ccc2d29c GV |
2162 | int mods; |
2163 | ||
2164 | /* Convert to emacs modifiers. */ | |
2165 | mods = w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam); | |
2166 | ||
2167 | return mods; | |
2168 | } | |
da36a4d6 | 2169 | |
ccc2d29c GV |
2170 | unsigned int |
2171 | map_keypad_keys (unsigned int virt_key, unsigned int extended) | |
2172 | { | |
2173 | if (virt_key < VK_CLEAR || virt_key > VK_DELETE) | |
2174 | return virt_key; | |
da36a4d6 | 2175 | |
ccc2d29c | 2176 | if (virt_key == VK_RETURN) |
da36a4d6 GV |
2177 | return (extended ? VK_NUMPAD_ENTER : VK_RETURN); |
2178 | ||
ccc2d29c GV |
2179 | if (virt_key >= VK_PRIOR && virt_key <= VK_DOWN) |
2180 | return (!extended ? (VK_NUMPAD_PRIOR + (virt_key - VK_PRIOR)) : virt_key); | |
2181 | ||
2182 | if (virt_key == VK_INSERT || virt_key == VK_DELETE) | |
2183 | return (!extended ? (VK_NUMPAD_INSERT + (virt_key - VK_INSERT)) : virt_key); | |
2184 | ||
2185 | if (virt_key == VK_CLEAR) | |
2186 | return (!extended ? VK_NUMPAD_CLEAR : virt_key); | |
2187 | ||
2188 | return virt_key; | |
2189 | } | |
2190 | ||
2191 | /* List of special key combinations which w32 would normally capture, | |
74084731 | 2192 | but Emacs should grab instead. Not directly visible to lisp, to |
ccc2d29c GV |
2193 | simplify synchronization. Each item is an integer encoding a virtual |
2194 | key code and modifier combination to capture. */ | |
74084731 | 2195 | static Lisp_Object w32_grabbed_keys; |
ccc2d29c | 2196 | |
74084731 | 2197 | #define HOTKEY(vk, mods) make_number (((vk) & 255) | ((mods) << 8)) |
ccc2d29c GV |
2198 | #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff) |
2199 | #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255) | |
2200 | #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8) | |
2201 | ||
2ba49441 JR |
2202 | #define RAW_HOTKEY_ID(k) ((k) & 0xbfff) |
2203 | #define RAW_HOTKEY_VK_CODE(k) ((k) & 255) | |
2204 | #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8) | |
2205 | ||
ccc2d29c GV |
2206 | /* Register hot-keys for reserved key combinations when Emacs has |
2207 | keyboard focus, since this is the only way Emacs can receive key | |
2208 | combinations like Alt-Tab which are used by the system. */ | |
2209 | ||
2210 | static void | |
b56ceb92 | 2211 | register_hot_keys (HWND hwnd) |
ccc2d29c GV |
2212 | { |
2213 | Lisp_Object keylist; | |
2214 | ||
8e50cc2d SM |
2215 | /* Use CONSP, since we are called asynchronously. */ |
2216 | for (keylist = w32_grabbed_keys; CONSP (keylist); keylist = XCDR (keylist)) | |
ccc2d29c GV |
2217 | { |
2218 | Lisp_Object key = XCAR (keylist); | |
2219 | ||
2220 | /* Deleted entries get set to nil. */ | |
2221 | if (!INTEGERP (key)) | |
2222 | continue; | |
2223 | ||
2224 | RegisterHotKey (hwnd, HOTKEY_ID (key), | |
2225 | HOTKEY_MODIFIERS (key), HOTKEY_VK_CODE (key)); | |
2226 | } | |
2227 | } | |
2228 | ||
2229 | static void | |
b56ceb92 | 2230 | unregister_hot_keys (HWND hwnd) |
ccc2d29c GV |
2231 | { |
2232 | Lisp_Object keylist; | |
2233 | ||
8e50cc2d | 2234 | for (keylist = w32_grabbed_keys; CONSP (keylist); keylist = XCDR (keylist)) |
ccc2d29c GV |
2235 | { |
2236 | Lisp_Object key = XCAR (keylist); | |
2237 | ||
2238 | if (!INTEGERP (key)) | |
2239 | continue; | |
2240 | ||
2241 | UnregisterHotKey (hwnd, HOTKEY_ID (key)); | |
2242 | } | |
2243 | } | |
2244 | ||
5ac45f98 GV |
2245 | /* Main message dispatch loop. */ |
2246 | ||
1edf84e7 GV |
2247 | static void |
2248 | w32_msg_pump (deferred_msg * msg_buf) | |
5ac45f98 GV |
2249 | { |
2250 | MSG msg; | |
ccc2d29c GV |
2251 | int result; |
2252 | HWND focus_window; | |
93fbe8b7 GV |
2253 | |
2254 | msh_mousewheel = RegisterWindowMessage (MSH_MOUSEWHEEL); | |
7d0393cf | 2255 | |
5ac45f98 GV |
2256 | while (GetMessage (&msg, NULL, 0, 0)) |
2257 | { | |
2258 | if (msg.hwnd == NULL) | |
2259 | { | |
2260 | switch (msg.message) | |
2261 | { | |
3ef68e6b AI |
2262 | case WM_NULL: |
2263 | /* Produced by complete_deferred_msg; just ignore. */ | |
2264 | break; | |
5ac45f98 | 2265 | case WM_EMACS_CREATEWINDOW: |
d5781bb6 JR |
2266 | /* Initialize COM for this window. Even though we don't use it, |
2267 | some third party shell extensions can cause it to be used in | |
2268 | system dialogs, which causes a crash if it is not initialized. | |
2269 | This is a known bug in Windows, which was fixed long ago, but | |
2270 | the patch for XP is not publically available until XP SP3, | |
2271 | and older versions will never be patched. */ | |
2272 | CoInitialize (NULL); | |
fbd6baed | 2273 | w32_createwindow ((struct frame *) msg.wParam); |
1edf84e7 GV |
2274 | if (!PostThreadMessage (dwMainThreadId, WM_EMACS_DONE, 0, 0)) |
2275 | abort (); | |
5ac45f98 | 2276 | break; |
dfdb4047 GV |
2277 | case WM_EMACS_SETLOCALE: |
2278 | SetThreadLocale (msg.wParam); | |
2279 | /* Reply is not expected. */ | |
2280 | break; | |
ccc2d29c GV |
2281 | case WM_EMACS_SETKEYBOARDLAYOUT: |
2282 | result = (int) ActivateKeyboardLayout ((HKL) msg.wParam, 0); | |
2283 | if (!PostThreadMessage (dwMainThreadId, WM_EMACS_DONE, | |
2284 | result, 0)) | |
2285 | abort (); | |
2286 | break; | |
2287 | case WM_EMACS_REGISTER_HOT_KEY: | |
2288 | focus_window = GetFocus (); | |
2289 | if (focus_window != NULL) | |
2290 | RegisterHotKey (focus_window, | |
2ba49441 JR |
2291 | RAW_HOTKEY_ID (msg.wParam), |
2292 | RAW_HOTKEY_MODIFIERS (msg.wParam), | |
2293 | RAW_HOTKEY_VK_CODE (msg.wParam)); | |
ccc2d29c GV |
2294 | /* Reply is not expected. */ |
2295 | break; | |
2296 | case WM_EMACS_UNREGISTER_HOT_KEY: | |
2297 | focus_window = GetFocus (); | |
2298 | if (focus_window != NULL) | |
2ba49441 | 2299 | UnregisterHotKey (focus_window, RAW_HOTKEY_ID (msg.wParam)); |
adcc3809 GV |
2300 | /* Mark item as erased. NB: this code must be |
2301 | thread-safe. The next line is okay because the cons | |
2302 | cell is never made into garbage and is not relocated by | |
2303 | GC. */ | |
2ba49441 | 2304 | XSETCAR ((Lisp_Object) ((EMACS_INT) msg.lParam), Qnil); |
ccc2d29c GV |
2305 | if (!PostThreadMessage (dwMainThreadId, WM_EMACS_DONE, 0, 0)) |
2306 | abort (); | |
2307 | break; | |
adcc3809 GV |
2308 | case WM_EMACS_TOGGLE_LOCK_KEY: |
2309 | { | |
2310 | int vk_code = (int) msg.wParam; | |
2311 | int cur_state = (GetKeyState (vk_code) & 1); | |
2ba49441 | 2312 | Lisp_Object new_state = (Lisp_Object) ((EMACS_INT) msg.lParam); |
adcc3809 GV |
2313 | |
2314 | /* NB: This code must be thread-safe. It is safe to | |
2315 | call NILP because symbols are not relocated by GC, | |
2316 | and pointer here is not touched by GC (so the markbit | |
2317 | can't be set). Numbers are safe because they are | |
2318 | immediate values. */ | |
2319 | if (NILP (new_state) | |
2320 | || (NUMBERP (new_state) | |
8edb0a6f | 2321 | && ((XUINT (new_state)) & 1) != cur_state)) |
adcc3809 GV |
2322 | { |
2323 | one_w32_display_info.faked_key = vk_code; | |
2324 | ||
2325 | keybd_event ((BYTE) vk_code, | |
2326 | (BYTE) MapVirtualKey (vk_code, 0), | |
2327 | KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); | |
2328 | keybd_event ((BYTE) vk_code, | |
2329 | (BYTE) MapVirtualKey (vk_code, 0), | |
2330 | KEYEVENTF_EXTENDEDKEY | 0, 0); | |
2331 | keybd_event ((BYTE) vk_code, | |
2332 | (BYTE) MapVirtualKey (vk_code, 0), | |
2333 | KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); | |
2334 | cur_state = !cur_state; | |
2335 | } | |
2336 | if (!PostThreadMessage (dwMainThreadId, WM_EMACS_DONE, | |
2337 | cur_state, 0)) | |
2338 | abort (); | |
2339 | } | |
2340 | break; | |
5dff811e JR |
2341 | #ifdef MSG_DEBUG |
2342 | /* Broadcast messages make it here, so you need to be looking | |
2343 | for something in particular for this to be useful. */ | |
1edf84e7 | 2344 | default: |
1edf84e7 | 2345 | DebPrint (("msg %x not expected by w32_msg_pump\n", msg.message)); |
5dff811e | 2346 | #endif |
5ac45f98 GV |
2347 | } |
2348 | } | |
2349 | else | |
2350 | { | |
2351 | DispatchMessage (&msg); | |
2352 | } | |
1edf84e7 GV |
2353 | |
2354 | /* Exit nested loop when our deferred message has completed. */ | |
2355 | if (msg_buf->completed) | |
2356 | break; | |
5ac45f98 | 2357 | } |
1edf84e7 GV |
2358 | } |
2359 | ||
2360 | deferred_msg * deferred_msg_head; | |
2361 | ||
2362 | static deferred_msg * | |
2363 | find_deferred_msg (HWND hwnd, UINT msg) | |
2364 | { | |
2365 | deferred_msg * item; | |
2366 | ||
2367 | /* Don't actually need synchronization for read access, since | |
2368 | modification of single pointer is always atomic. */ | |
2369 | /* enter_crit (); */ | |
2370 | ||
2371 | for (item = deferred_msg_head; item != NULL; item = item->next) | |
2372 | if (item->w32msg.msg.hwnd == hwnd | |
2373 | && item->w32msg.msg.message == msg) | |
2374 | break; | |
2375 | ||
2376 | /* leave_crit (); */ | |
2377 | ||
2378 | return item; | |
2379 | } | |
2380 | ||
2381 | static LRESULT | |
2382 | send_deferred_msg (deferred_msg * msg_buf, | |
2383 | HWND hwnd, | |
2384 | UINT msg, | |
2385 | WPARAM wParam, | |
2386 | LPARAM lParam) | |
2387 | { | |
2388 | /* Only input thread can send deferred messages. */ | |
2389 | if (GetCurrentThreadId () != dwWindowsThreadId) | |
2390 | abort (); | |
2391 | ||
2392 | /* It is an error to send a message that is already deferred. */ | |
2393 | if (find_deferred_msg (hwnd, msg) != NULL) | |
2394 | abort (); | |
2395 | ||
2396 | /* Enforced synchronization is not needed because this is the only | |
2397 | function that alters deferred_msg_head, and the following critical | |
2398 | section is guaranteed to only be serially reentered (since only the | |
2399 | input thread can call us). */ | |
2400 | ||
2401 | /* enter_crit (); */ | |
2402 | ||
2403 | msg_buf->completed = 0; | |
2404 | msg_buf->next = deferred_msg_head; | |
2405 | deferred_msg_head = msg_buf; | |
2406 | my_post_msg (&msg_buf->w32msg, hwnd, msg, wParam, lParam); | |
2407 | ||
2408 | /* leave_crit (); */ | |
2409 | ||
2410 | /* Start a new nested message loop to process other messages until | |
2411 | this one is completed. */ | |
2412 | w32_msg_pump (msg_buf); | |
2413 | ||
2414 | deferred_msg_head = msg_buf->next; | |
2415 | ||
2416 | return msg_buf->result; | |
2417 | } | |
2418 | ||
2419 | void | |
2420 | complete_deferred_msg (HWND hwnd, UINT msg, LRESULT result) | |
2421 | { | |
2422 | deferred_msg * msg_buf = find_deferred_msg (hwnd, msg); | |
2423 | ||
2424 | if (msg_buf == NULL) | |
74084731 | 2425 | /* Message may have been cancelled, so don't abort. */ |
3ef68e6b | 2426 | return; |
1edf84e7 GV |
2427 | |
2428 | msg_buf->result = result; | |
2429 | msg_buf->completed = 1; | |
2430 | ||
2431 | /* Ensure input thread is woken so it notices the completion. */ | |
2432 | PostThreadMessage (dwWindowsThreadId, WM_NULL, 0, 0); | |
2433 | } | |
2434 | ||
74084731 | 2435 | static void |
b56ceb92 | 2436 | cancel_all_deferred_msgs (void) |
3ef68e6b AI |
2437 | { |
2438 | deferred_msg * item; | |
2439 | ||
2440 | /* Don't actually need synchronization for read access, since | |
2441 | modification of single pointer is always atomic. */ | |
2442 | /* enter_crit (); */ | |
2443 | ||
2444 | for (item = deferred_msg_head; item != NULL; item = item->next) | |
2445 | { | |
2446 | item->result = 0; | |
2447 | item->completed = 1; | |
2448 | } | |
2449 | ||
2450 | /* leave_crit (); */ | |
2451 | ||
2452 | /* Ensure input thread is woken so it notices the completion. */ | |
2453 | PostThreadMessage (dwWindowsThreadId, WM_NULL, 0, 0); | |
2454 | } | |
1edf84e7 | 2455 | |
992dfd90 JR |
2456 | DWORD WINAPI |
2457 | w32_msg_worker (void *arg) | |
1edf84e7 GV |
2458 | { |
2459 | MSG msg; | |
2460 | deferred_msg dummy_buf; | |
2461 | ||
2462 | /* Ensure our message queue is created */ | |
7d0393cf | 2463 | |
1edf84e7 | 2464 | PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE); |
7d0393cf | 2465 | |
1edf84e7 GV |
2466 | if (!PostThreadMessage (dwMainThreadId, WM_EMACS_DONE, 0, 0)) |
2467 | abort (); | |
2468 | ||
2469 | memset (&dummy_buf, 0, sizeof (dummy_buf)); | |
2470 | dummy_buf.w32msg.msg.hwnd = NULL; | |
2471 | dummy_buf.w32msg.msg.message = WM_NULL; | |
2472 | ||
23f250f4 | 2473 | /* This is the initial message loop which should only exit when the |
1edf84e7 GV |
2474 | application quits. */ |
2475 | w32_msg_pump (&dummy_buf); | |
2476 | ||
2477 | return 0; | |
5ac45f98 GV |
2478 | } |
2479 | ||
f0c947b5 | 2480 | static void |
b56ceb92 | 2481 | signal_user_input (void) |
f0c947b5 JR |
2482 | { |
2483 | /* Interrupt any lisp that wants to be interrupted by input. */ | |
2484 | if (!NILP (Vthrow_on_input)) | |
2485 | { | |
2486 | Vquit_flag = Vthrow_on_input; | |
2487 | /* If we're inside a function that wants immediate quits, | |
2488 | do it now. */ | |
2489 | if (immediate_quit && NILP (Vinhibit_quit)) | |
2490 | { | |
2491 | immediate_quit = 0; | |
2492 | QUIT; | |
2493 | } | |
2494 | } | |
2495 | } | |
2496 | ||
2497 | ||
3ef68e6b | 2498 | static void |
b56ceb92 JB |
2499 | post_character_message (HWND hwnd, UINT msg, |
2500 | WPARAM wParam, LPARAM lParam, | |
2501 | DWORD modifiers) | |
3ef68e6b AI |
2502 | { |
2503 | W32Msg wmsg; | |
2504 | ||
2505 | wmsg.dwModifiers = modifiers; | |
2506 | ||
2507 | /* Detect quit_char and set quit-flag directly. Note that we | |
2508 | still need to post a message to ensure the main thread will be | |
74084731 | 2509 | woken up if blocked in sys_select, but we do NOT want to post |
3ef68e6b AI |
2510 | the quit_char message itself (because it will usually be as if |
2511 | the user had typed quit_char twice). Instead, we post a dummy | |
2512 | message that has no particular effect. */ | |
2513 | { | |
2514 | int c = wParam; | |
2515 | if (isalpha (c) && wmsg.dwModifiers == ctrl_modifier) | |
2516 | c = make_ctrl_char (c) & 0377; | |
7d081355 AI |
2517 | if (c == quit_char |
2518 | || (wmsg.dwModifiers == 0 && | |
2ba49441 | 2519 | w32_quit_key && wParam == w32_quit_key)) |
3ef68e6b AI |
2520 | { |
2521 | Vquit_flag = Qt; | |
2522 | ||
2523 | /* The choice of message is somewhat arbitrary, as long as | |
2524 | the main thread handler just ignores it. */ | |
2525 | msg = WM_NULL; | |
2526 | ||
2527 | /* Interrupt any blocking system calls. */ | |
2528 | signal_quit (); | |
2529 | ||
2530 | /* As a safety precaution, forcibly complete any deferred | |
2531 | messages. This is a kludge, but I don't see any particularly | |
2532 | clean way to handle the situation where a deferred message is | |
2533 | "dropped" in the lisp thread, and will thus never be | |
2534 | completed, eg. by the user trying to activate the menubar | |
2535 | when the lisp thread is busy, and then typing C-g when the | |
2536 | menubar doesn't open promptly (with the result that the | |
2537 | menubar never responds at all because the deferred | |
2538 | WM_INITMENU message is never completed). Another problem | |
2539 | situation is when the lisp thread calls SendMessage (to send | |
2540 | a window manager command) when a message has been deferred; | |
2541 | the lisp thread gets blocked indefinitely waiting for the | |
2542 | deferred message to be completed, which itself is waiting for | |
2543 | the lisp thread to respond. | |
2544 | ||
2545 | Note that we don't want to block the input thread waiting for | |
2546 | a reponse from the lisp thread (although that would at least | |
2547 | solve the deadlock problem above), because we want to be able | |
2548 | to receive C-g to interrupt the lisp thread. */ | |
2549 | cancel_all_deferred_msgs (); | |
2550 | } | |
f0c947b5 JR |
2551 | else |
2552 | signal_user_input (); | |
3ef68e6b AI |
2553 | } |
2554 | ||
2555 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); | |
2556 | } | |
2557 | ||
ee78dc32 GV |
2558 | /* Main window procedure */ |
2559 | ||
24f981c9 | 2560 | static LRESULT CALLBACK |
b56ceb92 | 2561 | w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
ee78dc32 GV |
2562 | { |
2563 | struct frame *f; | |
fbd6baed GV |
2564 | struct w32_display_info *dpyinfo = &one_w32_display_info; |
2565 | W32Msg wmsg; | |
84fb1139 | 2566 | int windows_translate; |
576ba81c | 2567 | int key; |
84fb1139 | 2568 | |
a6085637 KH |
2569 | /* Note that it is okay to call x_window_to_frame, even though we are |
2570 | not running in the main lisp thread, because frame deletion | |
2571 | requires the lisp thread to synchronize with this thread. Thus, if | |
2572 | a frame struct is returned, it can be used without concern that the | |
2573 | lisp thread might make it disappear while we are using it. | |
2574 | ||
2575 | NB. Walking the frame list in this thread is safe (as long as | |
2576 | writes of Lisp_Object slots are atomic, which they are on Windows). | |
2577 | Although delete-frame can destructively modify the frame list while | |
2578 | we are walking it, a garbage collection cannot occur until after | |
2579 | delete-frame has synchronized with this thread. | |
2580 | ||
2581 | It is also safe to use functions that make GDI calls, such as | |
fbd6baed | 2582 | w32_clear_rect, because these functions must obtain a DC handle |
a6085637 KH |
2583 | from the frame struct using get_frame_dc which is thread-aware. */ |
2584 | ||
7d0393cf | 2585 | switch (msg) |
ee78dc32 GV |
2586 | { |
2587 | case WM_ERASEBKGND: | |
a6085637 KH |
2588 | f = x_window_to_frame (dpyinfo, hwnd); |
2589 | if (f) | |
2590 | { | |
9badad41 | 2591 | HDC hdc = get_frame_dc (f); |
a6085637 | 2592 | GetUpdateRect (hwnd, &wmsg.rect, FALSE); |
9badad41 JR |
2593 | w32_clear_rect (f, hdc, &wmsg.rect); |
2594 | release_frame_dc (f, hdc); | |
ce6059da AI |
2595 | |
2596 | #if defined (W32_DEBUG_DISPLAY) | |
18f0b342 AI |
2597 | DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n", |
2598 | f, | |
2599 | wmsg.rect.left, wmsg.rect.top, | |
2600 | wmsg.rect.right, wmsg.rect.bottom)); | |
ce6059da | 2601 | #endif /* W32_DEBUG_DISPLAY */ |
a6085637 | 2602 | } |
5ac45f98 GV |
2603 | return 1; |
2604 | case WM_PALETTECHANGED: | |
2605 | /* ignore our own changes */ | |
2606 | if ((HWND)wParam != hwnd) | |
2607 | { | |
a6085637 KH |
2608 | f = x_window_to_frame (dpyinfo, hwnd); |
2609 | if (f) | |
2610 | /* get_frame_dc will realize our palette and force all | |
2611 | frames to be redrawn if needed. */ | |
2612 | release_frame_dc (f, get_frame_dc (f)); | |
5ac45f98 GV |
2613 | } |
2614 | return 0; | |
ee78dc32 | 2615 | case WM_PAINT: |
ce6059da | 2616 | { |
55dcfc15 AI |
2617 | PAINTSTRUCT paintStruct; |
2618 | RECT update_rect; | |
72af86bd | 2619 | memset (&update_rect, 0, sizeof (update_rect)); |
55dcfc15 | 2620 | |
18f0b342 AI |
2621 | f = x_window_to_frame (dpyinfo, hwnd); |
2622 | if (f == 0) | |
2623 | { | |
2624 | DebPrint (("WM_PAINT received for unknown window %p\n", hwnd)); | |
2625 | return 0; | |
2626 | } | |
2627 | ||
55dcfc15 AI |
2628 | /* MSDN Docs say not to call BeginPaint if GetUpdateRect |
2629 | fails. Apparently this can happen under some | |
2630 | circumstances. */ | |
aa35b6ad | 2631 | if (GetUpdateRect (hwnd, &update_rect, FALSE) || !w32_strict_painting) |
55dcfc15 AI |
2632 | { |
2633 | enter_crit (); | |
2634 | BeginPaint (hwnd, &paintStruct); | |
2635 | ||
aa35b6ad JR |
2636 | /* The rectangles returned by GetUpdateRect and BeginPaint |
2637 | do not always match. Play it safe by assuming both areas | |
2638 | are invalid. */ | |
2639 | UnionRect (&(wmsg.rect), &update_rect, &(paintStruct.rcPaint)); | |
55dcfc15 AI |
2640 | |
2641 | #if defined (W32_DEBUG_DISPLAY) | |
18f0b342 AI |
2642 | DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n", |
2643 | f, | |
2644 | wmsg.rect.left, wmsg.rect.top, | |
2645 | wmsg.rect.right, wmsg.rect.bottom)); | |
2646 | DebPrint ((" [update region is %d,%d-%d,%d]\n", | |
55dcfc15 AI |
2647 | update_rect.left, update_rect.top, |
2648 | update_rect.right, update_rect.bottom)); | |
2649 | #endif | |
2650 | EndPaint (hwnd, &paintStruct); | |
2651 | leave_crit (); | |
2652 | ||
f7b146dc JR |
2653 | /* Change the message type to prevent Windows from |
2654 | combining WM_PAINT messages in the Lisp thread's queue, | |
2655 | since Windows assumes that each message queue is | |
2656 | dedicated to one frame and does not bother checking | |
2657 | that hwnd matches before combining them. */ | |
2658 | my_post_msg (&wmsg, hwnd, WM_EMACS_PAINT, wParam, lParam); | |
7d0393cf | 2659 | |
55dcfc15 AI |
2660 | return 0; |
2661 | } | |
c0611964 AI |
2662 | |
2663 | /* If GetUpdateRect returns 0 (meaning there is no update | |
2664 | region), assume the whole window needs to be repainted. */ | |
74084731 | 2665 | GetClientRect (hwnd, &wmsg.rect); |
c0611964 AI |
2666 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); |
2667 | return 0; | |
ee78dc32 | 2668 | } |
a1a80b40 | 2669 | |
ccc2d29c GV |
2670 | case WM_INPUTLANGCHANGE: |
2671 | /* Inform lisp thread of keyboard layout changes. */ | |
2672 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); | |
2673 | ||
2674 | /* Clear dead keys in the keyboard state; for simplicity only | |
2675 | preserve modifier key states. */ | |
2676 | { | |
2677 | int i; | |
2678 | BYTE keystate[256]; | |
2679 | ||
2680 | GetKeyboardState (keystate); | |
2681 | for (i = 0; i < 256; i++) | |
2682 | if (1 | |
2683 | && i != VK_SHIFT | |
2684 | && i != VK_LSHIFT | |
2685 | && i != VK_RSHIFT | |
2686 | && i != VK_CAPITAL | |
2687 | && i != VK_NUMLOCK | |
2688 | && i != VK_SCROLL | |
2689 | && i != VK_CONTROL | |
2690 | && i != VK_LCONTROL | |
2691 | && i != VK_RCONTROL | |
2692 | && i != VK_MENU | |
2693 | && i != VK_LMENU | |
2694 | && i != VK_RMENU | |
2695 | && i != VK_LWIN | |
2696 | && i != VK_RWIN) | |
2697 | keystate[i] = 0; | |
2698 | SetKeyboardState (keystate); | |
2699 | } | |
2700 | goto dflt; | |
2701 | ||
2702 | case WM_HOTKEY: | |
2703 | /* Synchronize hot keys with normal input. */ | |
2704 | PostMessage (hwnd, WM_KEYDOWN, HIWORD (lParam), 0); | |
2705 | return (0); | |
2706 | ||
a1a80b40 GV |
2707 | case WM_KEYUP: |
2708 | case WM_SYSKEYUP: | |
2709 | record_keyup (wParam, lParam); | |
2710 | goto dflt; | |
2711 | ||
ee78dc32 GV |
2712 | case WM_KEYDOWN: |
2713 | case WM_SYSKEYDOWN: | |
ccc2d29c GV |
2714 | /* Ignore keystrokes we fake ourself; see below. */ |
2715 | if (dpyinfo->faked_key == wParam) | |
2716 | { | |
2717 | dpyinfo->faked_key = 0; | |
576ba81c AI |
2718 | /* Make sure TranslateMessage sees them though (as long as |
2719 | they don't produce WM_CHAR messages). This ensures that | |
2720 | indicator lights are toggled promptly on Windows 9x, for | |
2721 | example. */ | |
bf254037 | 2722 | if (wParam < 256 && lispy_function_keys[wParam]) |
576ba81c AI |
2723 | { |
2724 | windows_translate = 1; | |
2725 | goto translate; | |
2726 | } | |
2727 | return 0; | |
ccc2d29c GV |
2728 | } |
2729 | ||
7830e24b RS |
2730 | /* Synchronize modifiers with current keystroke. */ |
2731 | sync_modifiers (); | |
a1a80b40 | 2732 | record_keydown (wParam, lParam); |
ccc2d29c | 2733 | wParam = map_keypad_keys (wParam, (lParam & 0x1000000L) != 0); |
84fb1139 KH |
2734 | |
2735 | windows_translate = 0; | |
ccc2d29c GV |
2736 | |
2737 | switch (wParam) | |
2738 | { | |
2739 | case VK_LWIN: | |
2740 | if (NILP (Vw32_pass_lwindow_to_system)) | |
2741 | { | |
2742 | /* Prevent system from acting on keyup (which opens the | |
2743 | Start menu if no other key was pressed) by simulating a | |
2744 | press of Space which we will ignore. */ | |
2745 | if (GetAsyncKeyState (wParam) & 1) | |
2746 | { | |
adcc3809 | 2747 | if (NUMBERP (Vw32_phantom_key_code)) |
576ba81c | 2748 | key = XUINT (Vw32_phantom_key_code) & 255; |
adcc3809 | 2749 | else |
576ba81c AI |
2750 | key = VK_SPACE; |
2751 | dpyinfo->faked_key = key; | |
2752 | keybd_event (key, (BYTE) MapVirtualKey (key, 0), 0, 0); | |
ccc2d29c GV |
2753 | } |
2754 | } | |
2755 | if (!NILP (Vw32_lwindow_modifier)) | |
2756 | return 0; | |
2757 | break; | |
2758 | case VK_RWIN: | |
2759 | if (NILP (Vw32_pass_rwindow_to_system)) | |
2760 | { | |
2761 | if (GetAsyncKeyState (wParam) & 1) | |
2762 | { | |
adcc3809 | 2763 | if (NUMBERP (Vw32_phantom_key_code)) |
576ba81c | 2764 | key = XUINT (Vw32_phantom_key_code) & 255; |
adcc3809 | 2765 | else |
576ba81c AI |
2766 | key = VK_SPACE; |
2767 | dpyinfo->faked_key = key; | |
2768 | keybd_event (key, (BYTE) MapVirtualKey (key, 0), 0, 0); | |
ccc2d29c GV |
2769 | } |
2770 | } | |
2771 | if (!NILP (Vw32_rwindow_modifier)) | |
2772 | return 0; | |
2773 | break; | |
576ba81c | 2774 | case VK_APPS: |
ccc2d29c GV |
2775 | if (!NILP (Vw32_apps_modifier)) |
2776 | return 0; | |
2777 | break; | |
2778 | case VK_MENU: | |
7d0393cf | 2779 | if (NILP (Vw32_pass_alt_to_system)) |
adcc3809 GV |
2780 | /* Prevent DefWindowProc from activating the menu bar if an |
2781 | Alt key is pressed and released by itself. */ | |
ccc2d29c | 2782 | return 0; |
84fb1139 | 2783 | windows_translate = 1; |
ccc2d29c | 2784 | break; |
7d0393cf | 2785 | case VK_CAPITAL: |
ccc2d29c GV |
2786 | /* Decide whether to treat as modifier or function key. */ |
2787 | if (NILP (Vw32_enable_caps_lock)) | |
2788 | goto disable_lock_key; | |
adcc3809 GV |
2789 | windows_translate = 1; |
2790 | break; | |
ccc2d29c GV |
2791 | case VK_NUMLOCK: |
2792 | /* Decide whether to treat as modifier or function key. */ | |
2793 | if (NILP (Vw32_enable_num_lock)) | |
2794 | goto disable_lock_key; | |
adcc3809 GV |
2795 | windows_translate = 1; |
2796 | break; | |
ccc2d29c GV |
2797 | case VK_SCROLL: |
2798 | /* Decide whether to treat as modifier or function key. */ | |
2799 | if (NILP (Vw32_scroll_lock_modifier)) | |
2800 | goto disable_lock_key; | |
adcc3809 GV |
2801 | windows_translate = 1; |
2802 | break; | |
ccc2d29c | 2803 | disable_lock_key: |
adcc3809 GV |
2804 | /* Ensure the appropriate lock key state (and indicator light) |
2805 | remains in the same state. We do this by faking another | |
2806 | press of the relevant key. Apparently, this really is the | |
2807 | only way to toggle the state of the indicator lights. */ | |
2808 | dpyinfo->faked_key = wParam; | |
2809 | keybd_event ((BYTE) wParam, (BYTE) MapVirtualKey (wParam, 0), | |
2810 | KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); | |
2811 | keybd_event ((BYTE) wParam, (BYTE) MapVirtualKey (wParam, 0), | |
2812 | KEYEVENTF_EXTENDEDKEY | 0, 0); | |
2813 | keybd_event ((BYTE) wParam, (BYTE) MapVirtualKey (wParam, 0), | |
2814 | KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); | |
2815 | /* Ensure indicator lights are updated promptly on Windows 9x | |
2816 | (TranslateMessage apparently does this), after forwarding | |
2817 | input event. */ | |
2818 | post_character_message (hwnd, msg, wParam, lParam, | |
2819 | w32_get_key_modifiers (wParam, lParam)); | |
2820 | windows_translate = 1; | |
ccc2d29c | 2821 | break; |
7d0393cf | 2822 | case VK_CONTROL: |
ccc2d29c GV |
2823 | case VK_SHIFT: |
2824 | case VK_PROCESSKEY: /* Generated by IME. */ | |
2825 | windows_translate = 1; | |
2826 | break; | |
adcc3809 GV |
2827 | case VK_CANCEL: |
2828 | /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL, | |
2829 | which is confusing for purposes of key binding; convert | |
2830 | VK_CANCEL events into VK_PAUSE events. */ | |
2831 | wParam = VK_PAUSE; | |
2832 | break; | |
2833 | case VK_PAUSE: | |
2834 | /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing | |
2835 | for purposes of key binding; convert these back into | |
2836 | VK_NUMLOCK events, at least when we want to see NumLock key | |
2837 | presses. (Note that there is never any possibility that | |
2838 | VK_PAUSE with Ctrl really is C-Pause as per above.) */ | |
2839 | if (NILP (Vw32_enable_num_lock) && modifier_set (VK_CONTROL)) | |
2840 | wParam = VK_NUMLOCK; | |
2841 | break; | |
ccc2d29c GV |
2842 | default: |
2843 | /* If not defined as a function key, change it to a WM_CHAR message. */ | |
bf254037 | 2844 | if (wParam > 255 || !lispy_function_keys[wParam]) |
ccc2d29c | 2845 | { |
adcc3809 GV |
2846 | DWORD modifiers = construct_console_modifiers (); |
2847 | ||
ccc2d29c GV |
2848 | if (!NILP (Vw32_recognize_altgr) |
2849 | && modifier_set (VK_LCONTROL) && modifier_set (VK_RMENU)) | |
2850 | { | |
2851 | /* Always let TranslateMessage handle AltGr key chords; | |
2852 | for some reason, ToAscii doesn't always process AltGr | |
2853 | chords correctly. */ | |
2854 | windows_translate = 1; | |
2855 | } | |
adcc3809 | 2856 | else if ((modifiers & (~SHIFT_PRESSED & ~CAPSLOCK_ON)) != 0) |
ccc2d29c | 2857 | { |
adcc3809 GV |
2858 | /* Handle key chords including any modifiers other |
2859 | than shift directly, in order to preserve as much | |
2860 | modifier information as possible. */ | |
ccc2d29c GV |
2861 | if ('A' <= wParam && wParam <= 'Z') |
2862 | { | |
2863 | /* Don't translate modified alphabetic keystrokes, | |
2864 | so the user doesn't need to constantly switch | |
2865 | layout to type control or meta keystrokes when | |
2866 | the normal layout translates alphabetic | |
2867 | characters to non-ascii characters. */ | |
2868 | if (!modifier_set (VK_SHIFT)) | |
2869 | wParam += ('a' - 'A'); | |
2870 | msg = WM_CHAR; | |
2871 | } | |
2872 | else | |
2873 | { | |
2874 | /* Try to handle other keystrokes by determining the | |
2875 | base character (ie. translating the base key plus | |
2876 | shift modifier). */ | |
2877 | int add; | |
2878 | int isdead = 0; | |
2879 | KEY_EVENT_RECORD key; | |
7d0393cf | 2880 | |
ccc2d29c GV |
2881 | key.bKeyDown = TRUE; |
2882 | key.wRepeatCount = 1; | |
2883 | key.wVirtualKeyCode = wParam; | |
2884 | key.wVirtualScanCode = (lParam & 0xFF0000) >> 16; | |
2885 | key.uChar.AsciiChar = 0; | |
adcc3809 | 2886 | key.dwControlKeyState = modifiers; |
ccc2d29c GV |
2887 | |
2888 | add = w32_kbd_patch_key (&key); | |
2889 | /* 0 means an unrecognised keycode, negative means | |
2890 | dead key. Ignore both. */ | |
2891 | while (--add >= 0) | |
2892 | { | |
2893 | /* Forward asciified character sequence. */ | |
2894 | post_character_message | |
a313b291 JR |
2895 | (hwnd, WM_CHAR, |
2896 | (unsigned char) key.uChar.AsciiChar, lParam, | |
ccc2d29c GV |
2897 | w32_get_key_modifiers (wParam, lParam)); |
2898 | w32_kbd_patch_key (&key); | |
2899 | } | |
2900 | return 0; | |
2901 | } | |
2902 | } | |
2903 | else | |
2904 | { | |
2905 | /* Let TranslateMessage handle everything else. */ | |
2906 | windows_translate = 1; | |
2907 | } | |
2908 | } | |
2909 | } | |
a1a80b40 | 2910 | |
adcc3809 | 2911 | translate: |
84fb1139 KH |
2912 | if (windows_translate) |
2913 | { | |
e9e23e23 | 2914 | MSG windows_msg = { hwnd, msg, wParam, lParam, 0, {0,0} }; |
e9e23e23 GV |
2915 | windows_msg.time = GetMessageTime (); |
2916 | TranslateMessage (&windows_msg); | |
84fb1139 KH |
2917 | goto dflt; |
2918 | } | |
2919 | ||
ee78dc32 | 2920 | /* Fall through */ |
7d0393cf | 2921 | |
ee78dc32 GV |
2922 | case WM_SYSCHAR: |
2923 | case WM_CHAR: | |
ccc2d29c GV |
2924 | post_character_message (hwnd, msg, wParam, lParam, |
2925 | w32_get_key_modifiers (wParam, lParam)); | |
ee78dc32 | 2926 | break; |
da36a4d6 | 2927 | |
820eff5a JR |
2928 | case WM_UNICHAR: |
2929 | /* WM_UNICHAR looks promising from the docs, but the exact | |
2930 | circumstances in which TranslateMessage sends it is one of those | |
2931 | Microsoft secret API things that EU and US courts are supposed | |
2932 | to have put a stop to already. Spy++ shows it being sent to Notepad | |
2933 | and other MS apps, but never to Emacs. | |
2934 | ||
2935 | Some third party IMEs send it in accordance with the official | |
2936 | documentation though, so handle it here. | |
2937 | ||
2938 | UNICODE_NOCHAR is used to test for support for this message. | |
2939 | TRUE indicates that the message is supported. */ | |
2940 | if (wParam == UNICODE_NOCHAR) | |
2941 | return TRUE; | |
2942 | ||
2943 | { | |
2944 | W32Msg wmsg; | |
2945 | wmsg.dwModifiers = w32_get_key_modifiers (wParam, lParam); | |
2946 | signal_user_input (); | |
2947 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); | |
2948 | } | |
2949 | break; | |
2950 | ||
2951 | case WM_IME_CHAR: | |
2952 | /* If we can't get the IME result as unicode, use default processing, | |
2953 | which will at least allow characters decodable in the system locale | |
2954 | get through. */ | |
2955 | if (!get_composition_string_fn) | |
2956 | goto dflt; | |
2957 | ||
2958 | else if (!ignore_ime_char) | |
2959 | { | |
2960 | wchar_t * buffer; | |
2961 | int size, i; | |
2962 | W32Msg wmsg; | |
2963 | HIMC context = get_ime_context_fn (hwnd); | |
2964 | wmsg.dwModifiers = w32_get_key_modifiers (wParam, lParam); | |
2965 | /* Get buffer size. */ | |
2966 | size = get_composition_string_fn (context, GCS_RESULTSTR, buffer, 0); | |
ed3751c8 | 2967 | buffer = alloca (size); |
820eff5a JR |
2968 | size = get_composition_string_fn (context, GCS_RESULTSTR, |
2969 | buffer, size); | |
c902b920 JR |
2970 | release_ime_context_fn (hwnd, context); |
2971 | ||
820eff5a JR |
2972 | signal_user_input (); |
2973 | for (i = 0; i < size / sizeof (wchar_t); i++) | |
2974 | { | |
2975 | my_post_msg (&wmsg, hwnd, WM_UNICHAR, (WPARAM) buffer[i], | |
2976 | lParam); | |
2977 | } | |
2c93b248 JR |
2978 | /* Ignore the messages for the rest of the |
2979 | characters in the string that was output above. */ | |
2980 | ignore_ime_char = (size / sizeof (wchar_t)) - 1; | |
820eff5a | 2981 | } |
2c93b248 JR |
2982 | else |
2983 | ignore_ime_char--; | |
2984 | ||
820eff5a JR |
2985 | break; |
2986 | ||
c902b920 JR |
2987 | case WM_IME_STARTCOMPOSITION: |
2988 | if (!set_ime_composition_window_fn) | |
2989 | goto dflt; | |
2990 | else | |
2991 | { | |
2992 | COMPOSITIONFORM form; | |
2993 | HIMC context; | |
2994 | struct window *w; | |
2995 | ||
c902b920 JR |
2996 | f = x_window_to_frame (dpyinfo, hwnd); |
2997 | w = XWINDOW (FRAME_SELECTED_WINDOW (f)); | |
2998 | ||
2999 | form.dwStyle = CFS_RECT; | |
3000 | form.ptCurrentPos.x = w32_system_caret_x; | |
3001 | form.ptCurrentPos.y = w32_system_caret_y; | |
3002 | ||
3003 | form.rcArea.left = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, 0); | |
3004 | form.rcArea.top = (WINDOW_TOP_EDGE_Y (w) | |
3005 | + WINDOW_HEADER_LINE_HEIGHT (w)); | |
3006 | form.rcArea.right = (WINDOW_BOX_RIGHT_EDGE_X (w) | |
3007 | - WINDOW_RIGHT_MARGIN_WIDTH (w) | |
3008 | - WINDOW_RIGHT_FRINGE_WIDTH (w)); | |
3009 | form.rcArea.bottom = (WINDOW_BOTTOM_EDGE_Y (w) | |
3010 | - WINDOW_MODE_LINE_HEIGHT (w)); | |
3011 | ||
3012 | context = get_ime_context_fn (hwnd); | |
20d60baf JR |
3013 | |
3014 | if (!context) | |
3015 | break; | |
3016 | ||
c902b920 JR |
3017 | set_ime_composition_window_fn (context, &form); |
3018 | release_ime_context_fn (hwnd, context); | |
3019 | } | |
3020 | break; | |
3021 | ||
820eff5a JR |
3022 | case WM_IME_ENDCOMPOSITION: |
3023 | ignore_ime_char = 0; | |
3024 | goto dflt; | |
3025 | ||
5ac45f98 GV |
3026 | /* Simulate middle mouse button events when left and right buttons |
3027 | are used together, but only if user has two button mouse. */ | |
ee78dc32 | 3028 | case WM_LBUTTONDOWN: |
5ac45f98 | 3029 | case WM_RBUTTONDOWN: |
2ba49441 | 3030 | if (w32_num_mouse_buttons > 2) |
5ac45f98 GV |
3031 | goto handle_plain_button; |
3032 | ||
3033 | { | |
3034 | int this = (msg == WM_LBUTTONDOWN) ? LMOUSE : RMOUSE; | |
3035 | int other = (msg == WM_LBUTTONDOWN) ? RMOUSE : LMOUSE; | |
3036 | ||
3cb20f4a RS |
3037 | if (button_state & this) |
3038 | return 0; | |
5ac45f98 GV |
3039 | |
3040 | if (button_state == 0) | |
3041 | SetCapture (hwnd); | |
3042 | ||
3043 | button_state |= this; | |
3044 | ||
3045 | if (button_state & other) | |
3046 | { | |
84fb1139 | 3047 | if (mouse_button_timer) |
5ac45f98 | 3048 | { |
84fb1139 KH |
3049 | KillTimer (hwnd, mouse_button_timer); |
3050 | mouse_button_timer = 0; | |
5ac45f98 GV |
3051 | |
3052 | /* Generate middle mouse event instead. */ | |
3053 | msg = WM_MBUTTONDOWN; | |
3054 | button_state |= MMOUSE; | |
3055 | } | |
3056 | else if (button_state & MMOUSE) | |
3057 | { | |
3058 | /* Ignore button event if we've already generated a | |
3059 | middle mouse down event. This happens if the | |
3060 | user releases and press one of the two buttons | |
3061 | after we've faked a middle mouse event. */ | |
3062 | return 0; | |
3063 | } | |
3064 | else | |
3065 | { | |
3066 | /* Flush out saved message. */ | |
84fb1139 | 3067 | post_msg (&saved_mouse_button_msg); |
5ac45f98 | 3068 | } |
fbd6baed | 3069 | wmsg.dwModifiers = w32_get_modifiers (); |
5ac45f98 | 3070 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); |
f5f69b6b | 3071 | signal_user_input (); |
5ac45f98 GV |
3072 | |
3073 | /* Clear message buffer. */ | |
84fb1139 | 3074 | saved_mouse_button_msg.msg.hwnd = 0; |
5ac45f98 GV |
3075 | } |
3076 | else | |
3077 | { | |
3078 | /* Hold onto message for now. */ | |
84fb1139 | 3079 | mouse_button_timer = |
adcc3809 | 3080 | SetTimer (hwnd, MOUSE_BUTTON_ID, |
2ba49441 | 3081 | w32_mouse_button_tolerance, NULL); |
84fb1139 KH |
3082 | saved_mouse_button_msg.msg.hwnd = hwnd; |
3083 | saved_mouse_button_msg.msg.message = msg; | |
3084 | saved_mouse_button_msg.msg.wParam = wParam; | |
3085 | saved_mouse_button_msg.msg.lParam = lParam; | |
3086 | saved_mouse_button_msg.msg.time = GetMessageTime (); | |
fbd6baed | 3087 | saved_mouse_button_msg.dwModifiers = w32_get_modifiers (); |
5ac45f98 GV |
3088 | } |
3089 | } | |
3090 | return 0; | |
3091 | ||
ee78dc32 | 3092 | case WM_LBUTTONUP: |
5ac45f98 | 3093 | case WM_RBUTTONUP: |
2ba49441 | 3094 | if (w32_num_mouse_buttons > 2) |
5ac45f98 GV |
3095 | goto handle_plain_button; |
3096 | ||
3097 | { | |
3098 | int this = (msg == WM_LBUTTONUP) ? LMOUSE : RMOUSE; | |
3099 | int other = (msg == WM_LBUTTONUP) ? RMOUSE : LMOUSE; | |
3100 | ||
3cb20f4a RS |
3101 | if ((button_state & this) == 0) |
3102 | return 0; | |
5ac45f98 GV |
3103 | |
3104 | button_state &= ~this; | |
3105 | ||
3106 | if (button_state & MMOUSE) | |
3107 | { | |
3108 | /* Only generate event when second button is released. */ | |
3109 | if ((button_state & other) == 0) | |
3110 | { | |
3111 | msg = WM_MBUTTONUP; | |
3112 | button_state &= ~MMOUSE; | |
3113 | ||
3114 | if (button_state) abort (); | |
3115 | } | |
3116 | else | |
3117 | return 0; | |
3118 | } | |
3119 | else | |
3120 | { | |
3121 | /* Flush out saved message if necessary. */ | |
84fb1139 | 3122 | if (saved_mouse_button_msg.msg.hwnd) |
5ac45f98 | 3123 | { |
84fb1139 | 3124 | post_msg (&saved_mouse_button_msg); |
5ac45f98 GV |
3125 | } |
3126 | } | |
fbd6baed | 3127 | wmsg.dwModifiers = w32_get_modifiers (); |
5ac45f98 | 3128 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); |
f5f69b6b | 3129 | signal_user_input (); |
5ac45f98 GV |
3130 | |
3131 | /* Always clear message buffer and cancel timer. */ | |
84fb1139 KH |
3132 | saved_mouse_button_msg.msg.hwnd = 0; |
3133 | KillTimer (hwnd, mouse_button_timer); | |
3134 | mouse_button_timer = 0; | |
5ac45f98 GV |
3135 | |
3136 | if (button_state == 0) | |
3137 | ReleaseCapture (); | |
3138 | } | |
3139 | return 0; | |
3140 | ||
74214547 JR |
3141 | case WM_XBUTTONDOWN: |
3142 | case WM_XBUTTONUP: | |
3143 | if (w32_pass_extra_mouse_buttons_to_system) | |
3144 | goto dflt; | |
3145 | /* else fall through and process them. */ | |
ee78dc32 GV |
3146 | case WM_MBUTTONDOWN: |
3147 | case WM_MBUTTONUP: | |
5ac45f98 | 3148 | handle_plain_button: |
ee78dc32 GV |
3149 | { |
3150 | BOOL up; | |
1edf84e7 | 3151 | int button; |
ee78dc32 | 3152 | |
b48f9276 EZ |
3153 | /* Ignore middle and extra buttons as long as the menu is active. */ |
3154 | f = x_window_to_frame (dpyinfo, hwnd); | |
3155 | if (f && f->output_data.w32->menubar_active) | |
3156 | return 0; | |
3157 | ||
74214547 | 3158 | if (parse_button (msg, HIWORD (wParam), &button, &up)) |
ee78dc32 GV |
3159 | { |
3160 | if (up) ReleaseCapture (); | |
3161 | else SetCapture (hwnd); | |
7d0393cf | 3162 | button = (button == 0) ? LMOUSE : |
1edf84e7 GV |
3163 | ((button == 1) ? MMOUSE : RMOUSE); |
3164 | if (up) | |
3165 | button_state &= ~button; | |
3166 | else | |
3167 | button_state |= button; | |
ee78dc32 GV |
3168 | } |
3169 | } | |
7d0393cf | 3170 | |
fbd6baed | 3171 | wmsg.dwModifiers = w32_get_modifiers (); |
ee78dc32 | 3172 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); |
f0c947b5 | 3173 | signal_user_input (); |
74214547 JR |
3174 | |
3175 | /* Need to return true for XBUTTON messages, false for others, | |
3176 | to indicate that we processed the message. */ | |
3177 | return (msg == WM_XBUTTONDOWN || msg == WM_XBUTTONUP); | |
5ac45f98 | 3178 | |
5ac45f98 | 3179 | case WM_MOUSEMOVE: |
f93bd8e4 EZ |
3180 | /* Ignore mouse movements as long as the menu is active. These |
3181 | movements are processed by the window manager anyway, and | |
3182 | it's wrong to handle them as if they happened on the | |
3183 | underlying frame. */ | |
3184 | f = x_window_to_frame (dpyinfo, hwnd); | |
3185 | if (f && f->output_data.w32->menubar_active) | |
3186 | return 0; | |
3187 | ||
9eb16b62 JR |
3188 | /* If the mouse has just moved into the frame, start tracking |
3189 | it, so we will be notified when it leaves the frame. Mouse | |
3190 | tracking only works under W98 and NT4 and later. On earlier | |
3191 | versions, there is no way of telling when the mouse leaves the | |
3192 | frame, so we just have to put up with help-echo and mouse | |
3193 | highlighting remaining while the frame is not active. */ | |
3194 | if (track_mouse_event_fn && !track_mouse_window) | |
3195 | { | |
3196 | TRACKMOUSEEVENT tme; | |
3197 | tme.cbSize = sizeof (tme); | |
3198 | tme.dwFlags = TME_LEAVE; | |
3199 | tme.hwndTrack = hwnd; | |
3200 | ||
3201 | track_mouse_event_fn (&tme); | |
3202 | track_mouse_window = hwnd; | |
3203 | } | |
3204 | case WM_VSCROLL: | |
2ba49441 | 3205 | if (w32_mouse_move_interval <= 0 |
84fb1139 KH |
3206 | || (msg == WM_MOUSEMOVE && button_state == 0)) |
3207 | { | |
fbd6baed | 3208 | wmsg.dwModifiers = w32_get_modifiers (); |
84fb1139 KH |
3209 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); |
3210 | return 0; | |
3211 | } | |
7d0393cf | 3212 | |
84fb1139 KH |
3213 | /* Hang onto mouse move and scroll messages for a bit, to avoid |
3214 | sending such events to Emacs faster than it can process them. | |
3215 | If we get more events before the timer from the first message | |
3216 | expires, we just replace the first message. */ | |
3217 | ||
3218 | if (saved_mouse_move_msg.msg.hwnd == 0) | |
3219 | mouse_move_timer = | |
adcc3809 | 3220 | SetTimer (hwnd, MOUSE_MOVE_ID, |
2ba49441 | 3221 | w32_mouse_move_interval, NULL); |
84fb1139 KH |
3222 | |
3223 | /* Hold onto message for now. */ | |
3224 | saved_mouse_move_msg.msg.hwnd = hwnd; | |
3225 | saved_mouse_move_msg.msg.message = msg; | |
3226 | saved_mouse_move_msg.msg.wParam = wParam; | |
3227 | saved_mouse_move_msg.msg.lParam = lParam; | |
3228 | saved_mouse_move_msg.msg.time = GetMessageTime (); | |
fbd6baed | 3229 | saved_mouse_move_msg.dwModifiers = w32_get_modifiers (); |
7d0393cf | 3230 | |
84fb1139 KH |
3231 | return 0; |
3232 | ||
1edf84e7 | 3233 | case WM_MOUSEWHEEL: |
fd142562 | 3234 | case WM_DROPFILES: |
1edf84e7 GV |
3235 | wmsg.dwModifiers = w32_get_modifiers (); |
3236 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); | |
f0c947b5 | 3237 | signal_user_input (); |
1edf84e7 GV |
3238 | return 0; |
3239 | ||
0b151762 JR |
3240 | case WM_APPCOMMAND: |
3241 | if (w32_pass_multimedia_buttons_to_system) | |
3242 | goto dflt; | |
3243 | /* Otherwise, pass to lisp, the same way we do with mousehwheel. */ | |
fd142562 | 3244 | case WM_MOUSEHWHEEL: |
cb9e33d4 RS |
3245 | wmsg.dwModifiers = w32_get_modifiers (); |
3246 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); | |
f0c947b5 | 3247 | signal_user_input (); |
fd142562 JR |
3248 | /* Non-zero must be returned when WM_MOUSEHWHEEL messages are |
3249 | handled, to prevent the system trying to handle it by faking | |
3250 | scroll bar events. */ | |
3251 | return 1; | |
cb9e33d4 | 3252 | |
84fb1139 KH |
3253 | case WM_TIMER: |
3254 | /* Flush out saved messages if necessary. */ | |
3255 | if (wParam == mouse_button_timer) | |
5ac45f98 | 3256 | { |
84fb1139 KH |
3257 | if (saved_mouse_button_msg.msg.hwnd) |
3258 | { | |
3259 | post_msg (&saved_mouse_button_msg); | |
f0c947b5 | 3260 | signal_user_input (); |
84fb1139 KH |
3261 | saved_mouse_button_msg.msg.hwnd = 0; |
3262 | } | |
3263 | KillTimer (hwnd, mouse_button_timer); | |
3264 | mouse_button_timer = 0; | |
3265 | } | |
3266 | else if (wParam == mouse_move_timer) | |
3267 | { | |
3268 | if (saved_mouse_move_msg.msg.hwnd) | |
3269 | { | |
3270 | post_msg (&saved_mouse_move_msg); | |
3271 | saved_mouse_move_msg.msg.hwnd = 0; | |
3272 | } | |
3273 | KillTimer (hwnd, mouse_move_timer); | |
3274 | mouse_move_timer = 0; | |
5ac45f98 | 3275 | } |
48094ace JR |
3276 | else if (wParam == menu_free_timer) |
3277 | { | |
3278 | KillTimer (hwnd, menu_free_timer); | |
3279 | menu_free_timer = 0; | |
27605fa7 | 3280 | f = x_window_to_frame (dpyinfo, hwnd); |
5d22ded9 | 3281 | /* If a popup menu is active, don't wipe its strings. */ |
58e55497 | 3282 | if (menubar_in_use |
5d22ded9 | 3283 | && current_popup_menu == NULL) |
48094ace JR |
3284 | { |
3285 | /* Free memory used by owner-drawn and help-echo strings. */ | |
3286 | w32_free_menu_strings (hwnd); | |
3287 | f->output_data.w32->menubar_active = 0; | |
58e55497 | 3288 | menubar_in_use = 0; |
48094ace JR |
3289 | } |
3290 | } | |
d148e14d JR |
3291 | else if (wParam == hourglass_timer) |
3292 | { | |
3293 | KillTimer (hwnd, hourglass_timer); | |
3294 | hourglass_timer = 0; | |
1391cd54 | 3295 | w32_show_hourglass (x_window_to_frame (dpyinfo, hwnd)); |
d148e14d | 3296 | } |
5ac45f98 | 3297 | return 0; |
7d0393cf | 3298 | |
84fb1139 KH |
3299 | case WM_NCACTIVATE: |
3300 | /* Windows doesn't send us focus messages when putting up and | |
e9e23e23 | 3301 | taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95. |
84fb1139 KH |
3302 | The only indication we get that something happened is receiving |
3303 | this message afterwards. So this is a good time to reset our | |
3304 | keyboard modifiers' state. */ | |
3305 | reset_modifiers (); | |
3306 | goto dflt; | |
da36a4d6 | 3307 | |
1edf84e7 | 3308 | case WM_INITMENU: |
487163ac AI |
3309 | button_state = 0; |
3310 | ReleaseCapture (); | |
1edf84e7 GV |
3311 | /* We must ensure menu bar is fully constructed and up to date |
3312 | before allowing user interaction with it. To achieve this | |
3313 | we send this message to the lisp thread and wait for a | |
3314 | reply (whose value is not actually needed) to indicate that | |
3315 | the menu bar is now ready for use, so we can now return. | |
3316 | ||
3317 | To remain responsive in the meantime, we enter a nested message | |
3318 | loop that can process all other messages. | |
3319 | ||
3320 | However, we skip all this if the message results from calling | |
3321 | TrackPopupMenu - in fact, we must NOT attempt to send the lisp | |
3322 | thread a message because it is blocked on us at this point. We | |
3323 | set menubar_active before calling TrackPopupMenu to indicate | |
3324 | this (there is no possibility of confusion with real menubar | |
3325 | being active). */ | |
3326 | ||
3327 | f = x_window_to_frame (dpyinfo, hwnd); | |
3328 | if (f | |
3329 | && (f->output_data.w32->menubar_active | |
3330 | /* We can receive this message even in the absence of a | |
3331 | menubar (ie. when the system menu is activated) - in this | |
3332 | case we do NOT want to forward the message, otherwise it | |
3333 | will cause the menubar to suddenly appear when the user | |
3334 | had requested it to be turned off! */ | |
3335 | || f->output_data.w32->menubar_widget == NULL)) | |
3336 | return 0; | |
3337 | ||
3338 | { | |
3339 | deferred_msg msg_buf; | |
3340 | ||
3341 | /* Detect if message has already been deferred; in this case | |
3342 | we cannot return any sensible value to ignore this. */ | |
3343 | if (find_deferred_msg (hwnd, msg) != NULL) | |
3344 | abort (); | |
3345 | ||
58e55497 | 3346 | menubar_in_use = 1; |
90816b86 | 3347 | |
1edf84e7 GV |
3348 | return send_deferred_msg (&msg_buf, hwnd, msg, wParam, lParam); |
3349 | } | |
3350 | ||
3351 | case WM_EXITMENULOOP: | |
3352 | f = x_window_to_frame (dpyinfo, hwnd); | |
3353 | ||
5d22ded9 JR |
3354 | /* If a menu is still active, check again after a short delay, |
3355 | since Windows often (always?) sends the WM_EXITMENULOOP | |
3356 | before the corresponding WM_COMMAND message. | |
3357 | Don't do this if a popup menu is active, since it is only | |
3358 | menubar menus that require cleaning up in this way. | |
3359 | */ | |
58e55497 | 3360 | if (f && menubar_in_use && current_popup_menu == NULL) |
48094ace | 3361 | menu_free_timer = SetTimer (hwnd, MENU_FREE_ID, MENU_FREE_DELAY, NULL); |
d148e14d JR |
3362 | |
3363 | /* If hourglass cursor should be displayed, display it now. */ | |
3364 | if (f && f->output_data.w32->hourglass_p) | |
3365 | SetCursor (f->output_data.w32->hourglass_cursor); | |
3366 | ||
1edf84e7 GV |
3367 | goto dflt; |
3368 | ||
126f2e35 | 3369 | case WM_MENUSELECT: |
4e3a1c61 JR |
3370 | /* Direct handling of help_echo in menus. Should be safe now |
3371 | that we generate the help_echo by placing a help event in the | |
3372 | keyboard buffer. */ | |
ca56d953 | 3373 | { |
ca56d953 JR |
3374 | HMENU menu = (HMENU) lParam; |
3375 | UINT menu_item = (UINT) LOWORD (wParam); | |
3376 | UINT flags = (UINT) HIWORD (wParam); | |
3377 | ||
4e3a1c61 | 3378 | w32_menu_display_help (hwnd, menu, menu_item, flags); |
ca56d953 | 3379 | } |
126f2e35 JR |
3380 | return 0; |
3381 | ||
87996783 GV |
3382 | case WM_MEASUREITEM: |
3383 | f = x_window_to_frame (dpyinfo, hwnd); | |
3384 | if (f) | |
3385 | { | |
3386 | MEASUREITEMSTRUCT * pMis = (MEASUREITEMSTRUCT *) lParam; | |
3387 | ||
3388 | if (pMis->CtlType == ODT_MENU) | |
3389 | { | |
3390 | /* Work out dimensions for popup menu titles. */ | |
3391 | char * title = (char *) pMis->itemData; | |
3392 | HDC hdc = GetDC (hwnd); | |
3393 | HFONT menu_font = GetCurrentObject (hdc, OBJ_FONT); | |
3394 | LOGFONT menu_logfont; | |
3395 | HFONT old_font; | |
3396 | SIZE size; | |
3397 | ||
3398 | GetObject (menu_font, sizeof (menu_logfont), &menu_logfont); | |
3399 | menu_logfont.lfWeight = FW_BOLD; | |
3400 | menu_font = CreateFontIndirect (&menu_logfont); | |
3401 | old_font = SelectObject (hdc, menu_font); | |
3402 | ||
dfff8a69 JR |
3403 | pMis->itemHeight = GetSystemMetrics (SM_CYMENUSIZE); |
3404 | if (title) | |
3405 | { | |
b4005349 JR |
3406 | if (unicode_append_menu) |
3407 | GetTextExtentPoint32W (hdc, (WCHAR *) title, | |
3408 | wcslen ((WCHAR *) title), | |
3409 | &size); | |
3410 | else | |
3411 | GetTextExtentPoint32 (hdc, title, strlen (title), &size); | |
3412 | ||
dfff8a69 JR |
3413 | pMis->itemWidth = size.cx; |
3414 | if (pMis->itemHeight < size.cy) | |
3415 | pMis->itemHeight = size.cy; | |
3416 | } | |
3417 | else | |
3418 | pMis->itemWidth = 0; | |
87996783 GV |
3419 | |
3420 | SelectObject (hdc, old_font); | |
3421 | DeleteObject (menu_font); | |
3422 | ReleaseDC (hwnd, hdc); | |
3423 | return TRUE; | |
3424 | } | |
3425 | } | |
3426 | return 0; | |
3427 | ||
3428 | case WM_DRAWITEM: | |
3429 | f = x_window_to_frame (dpyinfo, hwnd); | |
3430 | if (f) | |
3431 | { | |
3432 | DRAWITEMSTRUCT * pDis = (DRAWITEMSTRUCT *) lParam; | |
3433 | ||
3434 | if (pDis->CtlType == ODT_MENU) | |
3435 | { | |
3436 | /* Draw popup menu title. */ | |
3437 | char * title = (char *) pDis->itemData; | |
212da13b JR |
3438 | if (title) |
3439 | { | |
3440 | HDC hdc = pDis->hDC; | |
3441 | HFONT menu_font = GetCurrentObject (hdc, OBJ_FONT); | |
3442 | LOGFONT menu_logfont; | |
3443 | HFONT old_font; | |
3444 | ||
3445 | GetObject (menu_font, sizeof (menu_logfont), &menu_logfont); | |
3446 | menu_logfont.lfWeight = FW_BOLD; | |
3447 | menu_font = CreateFontIndirect (&menu_logfont); | |
3448 | old_font = SelectObject (hdc, menu_font); | |
3449 | ||
b4005349 JR |
3450 | /* Always draw title as if not selected. */ |
3451 | if (unicode_append_menu) | |
3452 | ExtTextOutW (hdc, | |
3453 | pDis->rcItem.left | |
3454 | + GetSystemMetrics (SM_CXMENUCHECK), | |
3455 | pDis->rcItem.top, | |
3456 | ETO_OPAQUE, &pDis->rcItem, | |
3457 | (WCHAR *) title, | |
3458 | wcslen ((WCHAR *) title), NULL); | |
3459 | else | |
3460 | ExtTextOut (hdc, | |
3461 | pDis->rcItem.left | |
3462 | + GetSystemMetrics (SM_CXMENUCHECK), | |
3463 | pDis->rcItem.top, | |
3464 | ETO_OPAQUE, &pDis->rcItem, | |
3465 | title, strlen (title), NULL); | |
212da13b JR |
3466 | |
3467 | SelectObject (hdc, old_font); | |
3468 | DeleteObject (menu_font); | |
3469 | } | |
87996783 GV |
3470 | return TRUE; |
3471 | } | |
3472 | } | |
3473 | return 0; | |
3474 | ||
1edf84e7 GV |
3475 | #if 0 |
3476 | /* Still not right - can't distinguish between clicks in the | |
3477 | client area of the frame from clicks forwarded from the scroll | |
3478 | bars - may have to hook WM_NCHITTEST to remember the mouse | |
3479 | position and then check if it is in the client area ourselves. */ | |
3480 | case WM_MOUSEACTIVATE: | |
3481 | /* Discard the mouse click that activates a frame, allowing the | |
3482 | user to click anywhere without changing point (or worse!). | |
3483 | Don't eat mouse clicks on scrollbars though!! */ | |
3484 | if (LOWORD (lParam) == HTCLIENT ) | |
3485 | return MA_ACTIVATEANDEAT; | |
3486 | goto dflt; | |
3487 | #endif | |
3488 | ||
9eb16b62 JR |
3489 | case WM_MOUSELEAVE: |
3490 | /* No longer tracking mouse. */ | |
3491 | track_mouse_window = NULL; | |
3492 | ||
1edf84e7 | 3493 | case WM_ACTIVATEAPP: |
ccc2d29c | 3494 | case WM_ACTIVATE: |
1edf84e7 GV |
3495 | case WM_WINDOWPOSCHANGED: |
3496 | case WM_SHOWWINDOW: | |
3497 | /* Inform lisp thread that a frame might have just been obscured | |
3498 | or exposed, so should recheck visibility of all frames. */ | |
3499 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); | |
3500 | goto dflt; | |
3501 | ||
da36a4d6 | 3502 | case WM_SETFOCUS: |
adcc3809 GV |
3503 | dpyinfo->faked_key = 0; |
3504 | reset_modifiers (); | |
ccc2d29c GV |
3505 | register_hot_keys (hwnd); |
3506 | goto command; | |
8681157a | 3507 | case WM_KILLFOCUS: |
ccc2d29c | 3508 | unregister_hot_keys (hwnd); |
487163ac AI |
3509 | button_state = 0; |
3510 | ReleaseCapture (); | |
65906840 JR |
3511 | /* Relinquish the system caret. */ |
3512 | if (w32_system_caret_hwnd) | |
3513 | { | |
93f2ca61 | 3514 | w32_visible_system_caret_hwnd = NULL; |
d285988b JR |
3515 | w32_system_caret_hwnd = NULL; |
3516 | DestroyCaret (); | |
65906840 | 3517 | } |
48094ace JR |
3518 | goto command; |
3519 | case WM_COMMAND: | |
58e55497 | 3520 | menubar_in_use = 0; |
48094ace JR |
3521 | f = x_window_to_frame (dpyinfo, hwnd); |
3522 | if (f && HIWORD (wParam) == 0) | |
3523 | { | |
48094ace JR |
3524 | if (menu_free_timer) |
3525 | { | |
3526 | KillTimer (hwnd, menu_free_timer); | |
7d0393cf | 3527 | menu_free_timer = 0; |
48094ace JR |
3528 | } |
3529 | } | |
ee78dc32 GV |
3530 | case WM_MOVE: |
3531 | case WM_SIZE: | |
ccc2d29c | 3532 | command: |
fbd6baed | 3533 | wmsg.dwModifiers = w32_get_modifiers (); |
ee78dc32 GV |
3534 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); |
3535 | goto dflt; | |
8847d890 | 3536 | |
d5781bb6 JR |
3537 | case WM_DESTROY: |
3538 | CoUninitialize (); | |
3539 | return 0; | |
3540 | ||
8847d890 | 3541 | case WM_CLOSE: |
fbd6baed | 3542 | wmsg.dwModifiers = w32_get_modifiers (); |
8847d890 RS |
3543 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); |
3544 | return 0; | |
3545 | ||
ee78dc32 | 3546 | case WM_WINDOWPOSCHANGING: |
bfd6edcc JR |
3547 | /* Don't restrict the sizing of tip frames. */ |
3548 | if (hwnd == tip_window) | |
3549 | return 0; | |
ee78dc32 GV |
3550 | { |
3551 | WINDOWPLACEMENT wp; | |
3552 | LPWINDOWPOS lppos = (WINDOWPOS *) lParam; | |
1edf84e7 GV |
3553 | |
3554 | wp.length = sizeof (WINDOWPLACEMENT); | |
ee78dc32 | 3555 | GetWindowPlacement (hwnd, &wp); |
7d0393cf | 3556 | |
1edf84e7 | 3557 | if (wp.showCmd != SW_SHOWMINIMIZED && (lppos->flags & SWP_NOSIZE) == 0) |
ee78dc32 GV |
3558 | { |
3559 | RECT rect; | |
3560 | int wdiff; | |
3561 | int hdiff; | |
1edf84e7 GV |
3562 | DWORD font_width; |
3563 | DWORD line_height; | |
3564 | DWORD internal_border; | |
3565 | DWORD scrollbar_extra; | |
ee78dc32 | 3566 | RECT wr; |
7d0393cf | 3567 | |
74084731 | 3568 | wp.length = sizeof (wp); |
ee78dc32 | 3569 | GetWindowRect (hwnd, &wr); |
7d0393cf | 3570 | |
3c190163 | 3571 | enter_crit (); |
7d0393cf | 3572 | |
1edf84e7 GV |
3573 | font_width = GetWindowLong (hwnd, WND_FONTWIDTH_INDEX); |
3574 | line_height = GetWindowLong (hwnd, WND_LINEHEIGHT_INDEX); | |
3575 | internal_border = GetWindowLong (hwnd, WND_BORDER_INDEX); | |
3576 | scrollbar_extra = GetWindowLong (hwnd, WND_SCROLLBAR_INDEX); | |
7d0393cf | 3577 | |
3c190163 | 3578 | leave_crit (); |
7d0393cf | 3579 | |
ee78dc32 | 3580 | memset (&rect, 0, sizeof (rect)); |
7d0393cf | 3581 | AdjustWindowRect (&rect, GetWindowLong (hwnd, GWL_STYLE), |
ee78dc32 GV |
3582 | GetMenu (hwnd) != NULL); |
3583 | ||
1edf84e7 GV |
3584 | /* Force width and height of client area to be exact |
3585 | multiples of the character cell dimensions. */ | |
3586 | wdiff = (lppos->cx - (rect.right - rect.left) | |
3587 | - 2 * internal_border - scrollbar_extra) | |
3588 | % font_width; | |
3589 | hdiff = (lppos->cy - (rect.bottom - rect.top) | |
3590 | - 2 * internal_border) | |
3591 | % line_height; | |
7d0393cf | 3592 | |
ee78dc32 GV |
3593 | if (wdiff || hdiff) |
3594 | { | |
7d0393cf JB |
3595 | /* For right/bottom sizing we can just fix the sizes. |
3596 | However for top/left sizing we will need to fix the X | |
ee78dc32 | 3597 | and Y positions as well. */ |
7d0393cf | 3598 | |
8a4c4c7f JB |
3599 | int cx_mintrack = GetSystemMetrics (SM_CXMINTRACK); |
3600 | int cy_mintrack = GetSystemMetrics (SM_CYMINTRACK); | |
3601 | ||
3602 | lppos->cx = max (lppos->cx - wdiff, cx_mintrack); | |
3603 | lppos->cy = max (lppos->cy - hdiff, cy_mintrack); | |
7d0393cf JB |
3604 | |
3605 | if (wp.showCmd != SW_SHOWMAXIMIZED | |
1edf84e7 | 3606 | && (lppos->flags & SWP_NOMOVE) == 0) |
ee78dc32 GV |
3607 | { |
3608 | if (lppos->x != wr.left || lppos->y != wr.top) | |
3609 | { | |
3610 | lppos->x += wdiff; | |
3611 | lppos->y += hdiff; | |
3612 | } | |
3613 | else | |
3614 | { | |
3615 | lppos->flags |= SWP_NOMOVE; | |
3616 | } | |
3617 | } | |
7d0393cf | 3618 | |
1edf84e7 | 3619 | return 0; |
ee78dc32 GV |
3620 | } |
3621 | } | |
3622 | } | |
7d0393cf | 3623 | |
ee78dc32 | 3624 | goto dflt; |
1edf84e7 | 3625 | |
b1f918f8 | 3626 | case WM_GETMINMAXINFO: |
bf853fee AI |
3627 | /* Hack to allow resizing the Emacs frame above the screen size. |
3628 | Note that Windows 9x limits coordinates to 16-bits. */ | |
3629 | ((LPMINMAXINFO) lParam)->ptMaxTrackSize.x = 32767; | |
3630 | ((LPMINMAXINFO) lParam)->ptMaxTrackSize.y = 32767; | |
b1f918f8 GV |
3631 | return 0; |
3632 | ||
c9b2104d JR |
3633 | case WM_SETCURSOR: |
3634 | if (LOWORD (lParam) == HTCLIENT) | |
d148e14d JR |
3635 | { |
3636 | f = x_window_to_frame (dpyinfo, hwnd); | |
3637 | if (f->output_data.w32->hourglass_p && !menubar_in_use | |
3638 | && !current_popup_menu) | |
3639 | SetCursor (f->output_data.w32->hourglass_cursor); | |
3640 | else | |
3641 | SetCursor (f->output_data.w32->current_cursor); | |
3642 | return 0; | |
3643 | } | |
c9b2104d | 3644 | goto dflt; |
c922a224 | 3645 | |
c9b2104d JR |
3646 | case WM_EMACS_SETCURSOR: |
3647 | { | |
3648 | Cursor cursor = (Cursor) wParam; | |
d148e14d JR |
3649 | f = x_window_to_frame (dpyinfo, hwnd); |
3650 | if (f && cursor) | |
3651 | { | |
3652 | f->output_data.w32->current_cursor = cursor; | |
3653 | if (!f->output_data.w32->hourglass_p) | |
3654 | SetCursor (cursor); | |
3655 | } | |
c9b2104d JR |
3656 | return 0; |
3657 | } | |
c922a224 | 3658 | |
1edf84e7 GV |
3659 | case WM_EMACS_CREATESCROLLBAR: |
3660 | return (LRESULT) w32_createscrollbar ((struct frame *) wParam, | |
3661 | (struct scroll_bar *) lParam); | |
3662 | ||
5ac45f98 | 3663 | case WM_EMACS_SHOWWINDOW: |
1edf84e7 GV |
3664 | return ShowWindow ((HWND) wParam, (WPARAM) lParam); |
3665 | ||
dfdb4047 | 3666 | case WM_EMACS_SETFOREGROUND: |
ce6059da AI |
3667 | { |
3668 | HWND foreground_window; | |
3669 | DWORD foreground_thread, retval; | |
3670 | ||
3671 | /* On NT 5.0, and apparently Windows 98, it is necessary to | |
3672 | attach to the thread that currently has focus in order to | |
3673 | pull the focus away from it. */ | |
3674 | foreground_window = GetForegroundWindow (); | |
3675 | foreground_thread = GetWindowThreadProcessId (foreground_window, NULL); | |
3676 | if (!foreground_window | |
3677 | || foreground_thread == GetCurrentThreadId () | |
3678 | || !AttachThreadInput (GetCurrentThreadId (), | |
3679 | foreground_thread, TRUE)) | |
3680 | foreground_thread = 0; | |
3681 | ||
3682 | retval = SetForegroundWindow ((HWND) wParam); | |
3683 | ||
3684 | /* Detach from the previous foreground thread. */ | |
3685 | if (foreground_thread) | |
3686 | AttachThreadInput (GetCurrentThreadId (), | |
3687 | foreground_thread, FALSE); | |
3688 | ||
3689 | return retval; | |
3690 | } | |
dfdb4047 | 3691 | |
5ac45f98 GV |
3692 | case WM_EMACS_SETWINDOWPOS: |
3693 | { | |
1edf84e7 GV |
3694 | WINDOWPOS * pos = (WINDOWPOS *) wParam; |
3695 | return SetWindowPos (hwnd, pos->hwndInsertAfter, | |
5ac45f98 GV |
3696 | pos->x, pos->y, pos->cx, pos->cy, pos->flags); |
3697 | } | |
1edf84e7 | 3698 | |
ee78dc32 | 3699 | case WM_EMACS_DESTROYWINDOW: |
cb9e33d4 | 3700 | DragAcceptFiles ((HWND) wParam, FALSE); |
1edf84e7 GV |
3701 | return DestroyWindow ((HWND) wParam); |
3702 | ||
93f2ca61 JR |
3703 | case WM_EMACS_HIDE_CARET: |
3704 | return HideCaret (hwnd); | |
3705 | ||
3706 | case WM_EMACS_SHOW_CARET: | |
3707 | return ShowCaret (hwnd); | |
3708 | ||
65906840 JR |
3709 | case WM_EMACS_DESTROY_CARET: |
3710 | w32_system_caret_hwnd = NULL; | |
93f2ca61 | 3711 | w32_visible_system_caret_hwnd = NULL; |
65906840 JR |
3712 | return DestroyCaret (); |
3713 | ||
3714 | case WM_EMACS_TRACK_CARET: | |
3715 | /* If there is currently no system caret, create one. */ | |
3716 | if (w32_system_caret_hwnd == NULL) | |
3717 | { | |
93f2ca61 JR |
3718 | /* Use the default caret width, and avoid changing it |
3719 | unneccesarily, as it confuses screen reader software. */ | |
65906840 | 3720 | w32_system_caret_hwnd = hwnd; |
93f2ca61 | 3721 | CreateCaret (hwnd, NULL, 0, |
65906840 JR |
3722 | w32_system_caret_height); |
3723 | } | |
7d0393cf | 3724 | |
93f2ca61 JR |
3725 | if (!SetCaretPos (w32_system_caret_x, w32_system_caret_y)) |
3726 | return 0; | |
3727 | /* Ensure visible caret gets turned on when requested. */ | |
3728 | else if (w32_use_visible_system_caret | |
3729 | && w32_visible_system_caret_hwnd != hwnd) | |
3730 | { | |
3731 | w32_visible_system_caret_hwnd = hwnd; | |
3732 | return ShowCaret (hwnd); | |
3733 | } | |
3734 | /* Ensure visible caret gets turned off when requested. */ | |
3735 | else if (!w32_use_visible_system_caret | |
3736 | && w32_visible_system_caret_hwnd) | |
3737 | { | |
3738 | w32_visible_system_caret_hwnd = NULL; | |
3739 | return HideCaret (hwnd); | |
3740 | } | |
3741 | else | |
3742 | return 1; | |
65906840 | 3743 | |
1edf84e7 GV |
3744 | case WM_EMACS_TRACKPOPUPMENU: |
3745 | { | |
3746 | UINT flags; | |
3747 | POINT *pos; | |
3748 | int retval; | |
3749 | pos = (POINT *)lParam; | |
3750 | flags = TPM_CENTERALIGN; | |
3751 | if (button_state & LMOUSE) | |
3752 | flags |= TPM_LEFTBUTTON; | |
3753 | else if (button_state & RMOUSE) | |
3754 | flags |= TPM_RIGHTBUTTON; | |
7d0393cf | 3755 | |
87996783 GV |
3756 | /* Remember we did a SetCapture on the initial mouse down event, |
3757 | so for safety, we make sure the capture is cancelled now. */ | |
3758 | ReleaseCapture (); | |
490822ff | 3759 | button_state = 0; |
87996783 | 3760 | |
1edf84e7 GV |
3761 | /* Use menubar_active to indicate that WM_INITMENU is from |
3762 | TrackPopupMenu below, and should be ignored. */ | |
3763 | f = x_window_to_frame (dpyinfo, hwnd); | |
3764 | if (f) | |
3765 | f->output_data.w32->menubar_active = 1; | |
7d0393cf JB |
3766 | |
3767 | if (TrackPopupMenu ((HMENU)wParam, flags, pos->x, pos->y, | |
1edf84e7 GV |
3768 | 0, hwnd, NULL)) |
3769 | { | |
3770 | MSG amsg; | |
3771 | /* Eat any mouse messages during popupmenu */ | |
3772 | while (PeekMessage (&amsg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, | |
3773 | PM_REMOVE)); | |
3774 | /* Get the menu selection, if any */ | |
3775 | if (PeekMessage (&amsg, hwnd, WM_COMMAND, WM_COMMAND, PM_REMOVE)) | |
3776 | { | |
3777 | retval = LOWORD (amsg.wParam); | |
3778 | } | |
3779 | else | |
3780 | { | |
3781 | retval = 0; | |
3782 | } | |
1edf84e7 GV |
3783 | } |
3784 | else | |
3785 | { | |
3786 | retval = -1; | |
3787 | } | |
3788 | ||
3789 | return retval; | |
3790 | } | |
3791 | ||
ee78dc32 | 3792 | default: |
93fbe8b7 GV |
3793 | /* Check for messages registered at runtime. */ |
3794 | if (msg == msh_mousewheel) | |
3795 | { | |
3796 | wmsg.dwModifiers = w32_get_modifiers (); | |
3797 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); | |
f0c947b5 | 3798 | signal_user_input (); |
93fbe8b7 GV |
3799 | return 0; |
3800 | } | |
7d0393cf | 3801 | |
ee78dc32 GV |
3802 | dflt: |
3803 | return DefWindowProc (hwnd, msg, wParam, lParam); | |
3804 | } | |
7d0393cf | 3805 | |
1edf84e7 GV |
3806 | /* The most common default return code for handled messages is 0. */ |
3807 | return 0; | |
ee78dc32 GV |
3808 | } |
3809 | ||
0962822d | 3810 | static void |
b56ceb92 | 3811 | my_create_window (struct frame * f) |
ee78dc32 GV |
3812 | { |
3813 | MSG msg; | |
3814 | ||
1edf84e7 GV |
3815 | if (!PostThreadMessage (dwWindowsThreadId, WM_EMACS_CREATEWINDOW, (WPARAM)f, 0)) |
3816 | abort (); | |
ee78dc32 GV |
3817 | GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE); |
3818 | } | |
3819 | ||
ca56d953 JR |
3820 | |
3821 | /* Create a tooltip window. Unlike my_create_window, we do not do this | |
3822 | indirectly via the Window thread, as we do not need to process Window | |
3823 | messages for the tooltip. Creating tooltips indirectly also creates | |
3824 | deadlocks when tooltips are created for menu items. */ | |
0962822d | 3825 | static void |
b56ceb92 | 3826 | my_create_tip_window (struct frame *f) |
ca56d953 | 3827 | { |
bfd6edcc | 3828 | RECT rect; |
ca56d953 | 3829 | |
bfd6edcc | 3830 | rect.left = rect.top = 0; |
be786000 KS |
3831 | rect.right = FRAME_PIXEL_WIDTH (f); |
3832 | rect.bottom = FRAME_PIXEL_HEIGHT (f); | |
bfd6edcc JR |
3833 | |
3834 | AdjustWindowRect (&rect, f->output_data.w32->dwStyle, | |
3835 | FRAME_EXTERNAL_MENU_BAR (f)); | |
3836 | ||
3837 | tip_window = FRAME_W32_WINDOW (f) | |
ca56d953 JR |
3838 | = CreateWindow (EMACS_CLASS, |
3839 | f->namebuf, | |
3840 | f->output_data.w32->dwStyle, | |
be786000 KS |
3841 | f->left_pos, |
3842 | f->top_pos, | |
bfd6edcc JR |
3843 | rect.right - rect.left, |
3844 | rect.bottom - rect.top, | |
ca56d953 JR |
3845 | FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */ |
3846 | NULL, | |
3847 | hinst, | |
3848 | NULL); | |
3849 | ||
bfd6edcc | 3850 | if (tip_window) |
ca56d953 | 3851 | { |
be786000 KS |
3852 | SetWindowLong (tip_window, WND_FONTWIDTH_INDEX, FRAME_COLUMN_WIDTH (f)); |
3853 | SetWindowLong (tip_window, WND_LINEHEIGHT_INDEX, FRAME_LINE_HEIGHT (f)); | |
3854 | SetWindowLong (tip_window, WND_BORDER_INDEX, FRAME_INTERNAL_BORDER_WIDTH (f)); | |
bfd6edcc JR |
3855 | SetWindowLong (tip_window, WND_BACKGROUND_INDEX, FRAME_BACKGROUND_PIXEL (f)); |
3856 | ||
3857 | /* Tip frames have no scrollbars. */ | |
3858 | SetWindowLong (tip_window, WND_SCROLLBAR_INDEX, 0); | |
ca56d953 JR |
3859 | |
3860 | /* Do this to discard the default setting specified by our parent. */ | |
bfd6edcc | 3861 | ShowWindow (tip_window, SW_HIDE); |
ca56d953 JR |
3862 | } |
3863 | } | |
3864 | ||
3865 | ||
fbd6baed | 3866 | /* Create and set up the w32 window for frame F. */ |
ee78dc32 GV |
3867 | |
3868 | static void | |
b56ceb92 | 3869 | w32_window (struct frame *f, long window_prompting, int minibuffer_only) |
ee78dc32 GV |
3870 | { |
3871 | BLOCK_INPUT; | |
3872 | ||
3873 | /* Use the resource name as the top-level window name | |
3874 | for looking up resources. Make a non-Lisp copy | |
3875 | for the window manager, so GC relocation won't bother it. | |
3876 | ||
3877 | Elsewhere we specify the window name for the window manager. */ | |
7d0393cf | 3878 | |
ee78dc32 | 3879 | { |
51b59d79 | 3880 | char *str = SSDATA (Vx_resource_name); |
ee78dc32 GV |
3881 | f->namebuf = (char *) xmalloc (strlen (str) + 1); |
3882 | strcpy (f->namebuf, str); | |
3883 | } | |
3884 | ||
3885 | my_create_window (f); | |
3886 | ||
3887 | validate_x_resource_name (); | |
3888 | ||
3889 | /* x_set_name normally ignores requests to set the name if the | |
3890 | requested name is the same as the current name. This is the one | |
3891 | place where that assumption isn't correct; f->name is set, but | |
3892 | the server hasn't been told. */ | |
3893 | { | |
3894 | Lisp_Object name; | |
3895 | int explicit = f->explicit_name; | |
3896 | ||
3897 | f->explicit_name = 0; | |
3898 | name = f->name; | |
3899 | f->name = Qnil; | |
3900 | x_set_name (f, name, explicit); | |
3901 | } | |
3902 | ||
3903 | UNBLOCK_INPUT; | |
3904 | ||
3905 | if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f)) | |
3906 | initialize_frame_menubar (f); | |
3907 | ||
fbd6baed | 3908 | if (FRAME_W32_WINDOW (f) == 0) |
ee78dc32 GV |
3909 | error ("Unable to create window"); |
3910 | } | |
3911 | ||
3912 | /* Handle the icon stuff for this window. Perhaps later we might | |
3913 | want an x_set_icon_position which can be called interactively as | |
3914 | well. */ | |
3915 | ||
3916 | static void | |
b56ceb92 | 3917 | x_icon (struct frame *f, Lisp_Object parms) |
ee78dc32 GV |
3918 | { |
3919 | Lisp_Object icon_x, icon_y; | |
3faa984f | 3920 | struct w32_display_info *dpyinfo = &one_w32_display_info; |
ee78dc32 | 3921 | |
e9e23e23 | 3922 | /* Set the position of the icon. Note that Windows 95 groups all |
ee78dc32 | 3923 | icons in the tray. */ |
3faa984f JR |
3924 | icon_x = x_get_arg (dpyinfo, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER); |
3925 | icon_y = x_get_arg (dpyinfo, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER); | |
ee78dc32 GV |
3926 | if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound)) |
3927 | { | |
b7826503 PJ |
3928 | CHECK_NUMBER (icon_x); |
3929 | CHECK_NUMBER (icon_y); | |
ee78dc32 GV |
3930 | } |
3931 | else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound)) | |
3932 | error ("Both left and top icon corners of icon must be specified"); | |
3933 | ||
3934 | BLOCK_INPUT; | |
3935 | ||
3936 | if (! EQ (icon_x, Qunbound)) | |
3937 | x_wm_set_icon_position (f, XINT (icon_x), XINT (icon_y)); | |
3938 | ||
1edf84e7 GV |
3939 | #if 0 /* TODO */ |
3940 | /* Start up iconic or window? */ | |
3941 | x_wm_set_window_state | |
3faa984f | 3942 | (f, (EQ (x_get_arg (dpyinfo, parms, Qvisibility, 0, 0, RES_TYPE_SYMBOL), Qicon) |
1edf84e7 GV |
3943 | ? IconicState |
3944 | : NormalState)); | |
3945 | ||
51b59d79 PE |
3946 | x_text_icon (f, SSDATA ((!NILP (f->icon_name) |
3947 | ? f->icon_name | |
3948 | : f->name))); | |
1edf84e7 GV |
3949 | #endif |
3950 | ||
ee78dc32 GV |
3951 | UNBLOCK_INPUT; |
3952 | } | |
3953 | ||
6fc2811b JR |
3954 | |
3955 | static void | |
b56ceb92 | 3956 | x_make_gc (struct frame *f) |
6fc2811b JR |
3957 | { |
3958 | XGCValues gc_values; | |
3959 | ||
3960 | BLOCK_INPUT; | |
3961 | ||
3962 | /* Create the GC's of this frame. | |
3963 | Note that many default values are used. */ | |
3964 | ||
3965 | /* Normal video */ | |
be786000 | 3966 | gc_values.font = FRAME_FONT (f); |
6fc2811b JR |
3967 | |
3968 | /* Cursor has cursor-color background, background-color foreground. */ | |
3969 | gc_values.foreground = FRAME_BACKGROUND_PIXEL (f); | |
3970 | gc_values.background = f->output_data.w32->cursor_pixel; | |
3971 | f->output_data.w32->cursor_gc | |
3972 | = XCreateGC (NULL, FRAME_W32_WINDOW (f), | |
3973 | (GCFont | GCForeground | GCBackground), | |
3974 | &gc_values); | |
3975 | ||
3976 | /* Reliefs. */ | |
3977 | f->output_data.w32->white_relief.gc = 0; | |
3978 | f->output_data.w32->black_relief.gc = 0; | |
3979 | ||
3980 | UNBLOCK_INPUT; | |
3981 | } | |
3982 | ||
3983 | ||
937e601e AI |
3984 | /* Handler for signals raised during x_create_frame and |
3985 | x_create_top_frame. FRAME is the frame which is partially | |
3986 | constructed. */ | |
3987 | ||
3988 | static Lisp_Object | |
b56ceb92 | 3989 | unwind_create_frame (Lisp_Object frame) |
937e601e AI |
3990 | { |
3991 | struct frame *f = XFRAME (frame); | |
3992 | ||
3993 | /* If frame is ``official'', nothing to do. */ | |
3994 | if (!CONSP (Vframe_list) || !EQ (XCAR (Vframe_list), frame)) | |
3995 | { | |
3996 | #ifdef GLYPH_DEBUG | |
3997 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
3998 | #endif | |
7d0393cf | 3999 | |
937e601e AI |
4000 | x_free_frame_resources (f); |
4001 | ||
a9b555d3 | 4002 | #if GLYPH_DEBUG |
937e601e AI |
4003 | /* Check that reference counts are indeed correct. */ |
4004 | xassert (dpyinfo->reference_count == dpyinfo_refcount); | |
4005 | xassert (dpyinfo->image_cache->refcount == image_cache_refcount); | |
a9b555d3 | 4006 | #endif |
c844a81a | 4007 | return Qt; |
937e601e | 4008 | } |
7d0393cf | 4009 | |
937e601e AI |
4010 | return Qnil; |
4011 | } | |
4012 | ||
a1fe5c00 | 4013 | static void |
b56ceb92 | 4014 | x_default_font_parameter (struct frame *f, Lisp_Object parms) |
a1fe5c00 JR |
4015 | { |
4016 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
770e2e6e SM |
4017 | Lisp_Object font_param = x_get_arg (dpyinfo, parms, Qfont, NULL, NULL, |
4018 | RES_TYPE_STRING); | |
4019 | Lisp_Object font; | |
4020 | if (EQ (font_param, Qunbound)) | |
4021 | font_param = Qnil; | |
4022 | font = !NILP (font_param) ? font_param | |
4023 | : x_get_arg (dpyinfo, parms, Qfont, "font", "Font", RES_TYPE_STRING); | |
a1fe5c00 JR |
4024 | |
4025 | if (!STRINGP (font)) | |
4026 | { | |
4027 | int i; | |
4028 | static char *names[] | |
82523155 | 4029 | = { "Courier New-10", |
a1fe5c00 JR |
4030 | "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1", |
4031 | "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1", | |
4032 | "Fixedsys", | |
4033 | NULL }; | |
4034 | ||
4035 | for (i = 0; names[i]; i++) | |
4036 | { | |
4037 | font = font_open_by_name (f, names[i]); | |
4038 | if (! NILP (font)) | |
4039 | break; | |
4040 | } | |
4041 | if (NILP (font)) | |
4042 | error ("No suitable font was found"); | |
4043 | } | |
770e2e6e | 4044 | else if (!NILP (font_param)) |
27129af9 SM |
4045 | { |
4046 | /* Remember the explicit font parameter, so we can re-apply it after | |
4047 | we've applied the `default' face settings. */ | |
770e2e6e SM |
4048 | x_set_frame_parameters (f, Fcons (Fcons (Qfont_param, font_param), Qnil)); |
4049 | } | |
a1fe5c00 JR |
4050 | x_default_parameter (f, parms, Qfont, font, "font", "Font", RES_TYPE_STRING); |
4051 | } | |
937e601e | 4052 | |
ee78dc32 GV |
4053 | DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame, |
4054 | 1, 1, 0, | |
74e1aeec | 4055 | doc: /* Make a new window, which is called a \"frame\" in Emacs terms. |
36458ebd | 4056 | Return an Emacs frame object. |
52deb19f | 4057 | PARAMETERS is an alist of frame parameters. |
74e1aeec JR |
4058 | If the parameters specify that the frame should not have a minibuffer, |
4059 | and do not specify a specific minibuffer window to use, | |
4060 | then `default-minibuffer-frame' must be a frame whose minibuffer can | |
4061 | be shared by the new frame. | |
4062 | ||
4063 | This function is an internal primitive--use `make-frame' instead. */) | |
5842a27b | 4064 | (Lisp_Object parameters) |
ee78dc32 GV |
4065 | { |
4066 | struct frame *f; | |
4067 | Lisp_Object frame, tem; | |
4068 | Lisp_Object name; | |
4069 | int minibuffer_only = 0; | |
4070 | long window_prompting = 0; | |
4071 | int width, height; | |
331379bf | 4072 | int count = SPECPDL_INDEX (); |
1edf84e7 | 4073 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
ee78dc32 | 4074 | Lisp_Object display; |
6fc2811b | 4075 | struct w32_display_info *dpyinfo = NULL; |
ee78dc32 GV |
4076 | Lisp_Object parent; |
4077 | struct kboard *kb; | |
4078 | ||
1da8a031 MR |
4079 | /* Make copy of frame parameters because the original is in pure |
4080 | storage now. */ | |
4081 | parameters = Fcopy_alist (parameters); | |
4082 | ||
ee78dc32 GV |
4083 | /* Use this general default value to start with |
4084 | until we know if this frame has a specified name. */ | |
4085 | Vx_resource_name = Vinvocation_name; | |
4086 | ||
3faa984f JR |
4087 | display = x_get_arg (dpyinfo, parameters, Qterminal, 0, 0, RES_TYPE_NUMBER); |
4088 | if (EQ (display, Qunbound)) | |
4089 | display = x_get_arg (dpyinfo, parameters, Qdisplay, 0, 0, RES_TYPE_STRING); | |
ee78dc32 GV |
4090 | if (EQ (display, Qunbound)) |
4091 | display = Qnil; | |
4092 | dpyinfo = check_x_display_info (display); | |
80ca7302 | 4093 | kb = dpyinfo->terminal->kboard; |
ee78dc32 | 4094 | |
3faa984f JR |
4095 | if (!dpyinfo->terminal->name) |
4096 | error ("Terminal is not live, can't create new frames on it"); | |
4097 | ||
4098 | name = x_get_arg (dpyinfo, parameters, Qname, "name", "Name", RES_TYPE_STRING); | |
ee78dc32 GV |
4099 | if (!STRINGP (name) |
4100 | && ! EQ (name, Qunbound) | |
4101 | && ! NILP (name)) | |
4102 | error ("Invalid frame name--not a string or nil"); | |
4103 | ||
4104 | if (STRINGP (name)) | |
4105 | Vx_resource_name = name; | |
4106 | ||
4107 | /* See if parent window is specified. */ | |
3faa984f | 4108 | parent = x_get_arg (dpyinfo, parameters, Qparent_id, NULL, NULL, RES_TYPE_NUMBER); |
ee78dc32 GV |
4109 | if (EQ (parent, Qunbound)) |
4110 | parent = Qnil; | |
4111 | if (! NILP (parent)) | |
b7826503 | 4112 | CHECK_NUMBER (parent); |
ee78dc32 | 4113 | |
1edf84e7 GV |
4114 | /* make_frame_without_minibuffer can run Lisp code and garbage collect. */ |
4115 | /* No need to protect DISPLAY because that's not used after passing | |
4116 | it to make_frame_without_minibuffer. */ | |
4117 | frame = Qnil; | |
52deb19f | 4118 | GCPRO4 (parameters, parent, name, frame); |
3faa984f | 4119 | tem = x_get_arg (dpyinfo, parameters, Qminibuffer, "minibuffer", "Minibuffer", |
1660f34a | 4120 | RES_TYPE_SYMBOL); |
ee78dc32 GV |
4121 | if (EQ (tem, Qnone) || NILP (tem)) |
4122 | f = make_frame_without_minibuffer (Qnil, kb, display); | |
4123 | else if (EQ (tem, Qonly)) | |
4124 | { | |
4125 | f = make_minibuffer_frame (); | |
4126 | minibuffer_only = 1; | |
4127 | } | |
4128 | else if (WINDOWP (tem)) | |
4129 | f = make_frame_without_minibuffer (tem, kb, display); | |
4130 | else | |
4131 | f = make_frame (1); | |
4132 | ||
1edf84e7 GV |
4133 | XSETFRAME (frame, f); |
4134 | ||
ee78dc32 GV |
4135 | /* Note that Windows does support scroll bars. */ |
4136 | FRAME_CAN_HAVE_SCROLL_BARS (f) = 1; | |
6d906347 | 4137 | |
5ac45f98 | 4138 | /* By default, make scrollbars the system standard width. */ |
be786000 | 4139 | FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = GetSystemMetrics (SM_CXVSCROLL); |
ee78dc32 | 4140 | |
2dc8b986 JR |
4141 | f->terminal = dpyinfo->terminal; |
4142 | f->terminal->reference_count++; | |
4143 | ||
fbd6baed | 4144 | f->output_method = output_w32; |
6fc2811b JR |
4145 | f->output_data.w32 = |
4146 | (struct w32_output *) xmalloc (sizeof (struct w32_output)); | |
72af86bd | 4147 | memset (f->output_data.w32, 0, sizeof (struct w32_output)); |
4587b026 GV |
4148 | FRAME_FONTSET (f) = -1; |
4149 | ||
1edf84e7 | 4150 | f->icon_name |
3faa984f JR |
4151 | = x_get_arg (dpyinfo, parameters, Qicon_name, "iconName", "Title", |
4152 | RES_TYPE_STRING); | |
1edf84e7 GV |
4153 | if (! STRINGP (f->icon_name)) |
4154 | f->icon_name = Qnil; | |
4155 | ||
fbd6baed | 4156 | /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */ |
3faa984f JR |
4157 | |
4158 | /* With FRAME_X_DISPLAY_INFO set up, this unwind-protect is safe. */ | |
4159 | record_unwind_protect (unwind_create_frame, frame); | |
4160 | #if GLYPH_DEBUG | |
4161 | image_cache_refcount = FRAME_IMAGE_CACHE (f)->refcount; | |
4162 | dpyinfo_refcount = dpyinfo->reference_count; | |
4163 | #endif /* GLYPH_DEBUG */ | |
ee78dc32 GV |
4164 | |
4165 | /* Specify the parent under which to make this window. */ | |
4166 | ||
4167 | if (!NILP (parent)) | |
4168 | { | |
1660f34a | 4169 | f->output_data.w32->parent_desc = (Window) XFASTINT (parent); |
fbd6baed | 4170 | f->output_data.w32->explicit_parent = 1; |
ee78dc32 GV |
4171 | } |
4172 | else | |
4173 | { | |
fbd6baed GV |
4174 | f->output_data.w32->parent_desc = FRAME_W32_DISPLAY_INFO (f)->root_window; |
4175 | f->output_data.w32->explicit_parent = 0; | |
ee78dc32 GV |
4176 | } |
4177 | ||
ee78dc32 GV |
4178 | /* Set the name; the functions to which we pass f expect the name to |
4179 | be set. */ | |
4180 | if (EQ (name, Qunbound) || NILP (name)) | |
4181 | { | |
fbd6baed | 4182 | f->name = build_string (dpyinfo->w32_id_name); |
ee78dc32 GV |
4183 | f->explicit_name = 0; |
4184 | } | |
4185 | else | |
4186 | { | |
4187 | f->name = name; | |
4188 | f->explicit_name = 1; | |
4189 | /* use the frame's title when getting resources for this frame. */ | |
4190 | specbind (Qx_resource_name, name); | |
4191 | } | |
4192 | ||
82523155 JR |
4193 | f->resx = dpyinfo->resx; |
4194 | f->resy = dpyinfo->resy; | |
4195 | ||
1cc06b86 KH |
4196 | if (uniscribe_available) |
4197 | register_font_driver (&uniscribe_font_driver, f); | |
4198 | register_font_driver (&w32font_driver, f); | |
a1fe5c00 | 4199 | |
1cc06b86 KH |
4200 | x_default_parameter (f, parameters, Qfont_backend, Qnil, |
4201 | "fontBackend", "FontBackend", RES_TYPE_STRING); | |
ee78dc32 GV |
4202 | /* Extract the window parameters from the supplied values |
4203 | that are needed to determine window geometry. */ | |
1cc06b86 | 4204 | x_default_font_parameter (f, parameters); |
52deb19f | 4205 | x_default_parameter (f, parameters, Qborder_width, make_number (2), |
1660f34a | 4206 | "borderWidth", "BorderWidth", RES_TYPE_NUMBER); |
3faa984f | 4207 | |
601a9cf1 | 4208 | /* We recognize either internalBorderWidth or internalBorder |
3faa984f | 4209 | (which is what xterm calls it). */ |
52deb19f | 4210 | if (NILP (Fassq (Qinternal_border_width, parameters))) |
ee78dc32 GV |
4211 | { |
4212 | Lisp_Object value; | |
4213 | ||
3faa984f | 4214 | value = x_get_arg (dpyinfo, parameters, Qinternal_border_width, |
52deb19f | 4215 | "internalBorder", "InternalBorder", RES_TYPE_NUMBER); |
ee78dc32 | 4216 | if (! EQ (value, Qunbound)) |
52deb19f JB |
4217 | parameters = Fcons (Fcons (Qinternal_border_width, value), |
4218 | parameters); | |
ee78dc32 | 4219 | } |
1edf84e7 | 4220 | /* Default internalBorderWidth to 0 on Windows to match other programs. */ |
52deb19f | 4221 | x_default_parameter (f, parameters, Qinternal_border_width, make_number (0), |
1660f34a | 4222 | "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER); |
52deb19f | 4223 | x_default_parameter (f, parameters, Qvertical_scroll_bars, Qright, |
1660f34a | 4224 | "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL); |
ee78dc32 GV |
4225 | |
4226 | /* Also do the stuff which must be set before the window exists. */ | |
52deb19f | 4227 | x_default_parameter (f, parameters, Qforeground_color, build_string ("black"), |
6fc2811b | 4228 | "foreground", "Foreground", RES_TYPE_STRING); |
52deb19f | 4229 | x_default_parameter (f, parameters, Qbackground_color, build_string ("white"), |
6fc2811b | 4230 | "background", "Background", RES_TYPE_STRING); |
52deb19f | 4231 | x_default_parameter (f, parameters, Qmouse_color, build_string ("black"), |
6fc2811b | 4232 | "pointerColor", "Foreground", RES_TYPE_STRING); |
52deb19f | 4233 | x_default_parameter (f, parameters, Qborder_color, build_string ("black"), |
6fc2811b | 4234 | "borderColor", "BorderColor", RES_TYPE_STRING); |
52deb19f | 4235 | x_default_parameter (f, parameters, Qscreen_gamma, Qnil, |
6fc2811b | 4236 | "screenGamma", "ScreenGamma", RES_TYPE_FLOAT); |
52deb19f | 4237 | x_default_parameter (f, parameters, Qline_spacing, Qnil, |
dfff8a69 | 4238 | "lineSpacing", "LineSpacing", RES_TYPE_NUMBER); |
52deb19f | 4239 | x_default_parameter (f, parameters, Qleft_fringe, Qnil, |
41c1bdd9 | 4240 | "leftFringe", "LeftFringe", RES_TYPE_NUMBER); |
52deb19f | 4241 | x_default_parameter (f, parameters, Qright_fringe, Qnil, |
41c1bdd9 | 4242 | "rightFringe", "RightFringe", RES_TYPE_NUMBER); |
6fc2811b | 4243 | |
6fc2811b JR |
4244 | /* Init faces before x_default_parameter is called for scroll-bar |
4245 | parameters because that function calls x_set_scroll_bar_width, | |
4246 | which calls change_frame_size, which calls Fset_window_buffer, | |
4247 | which runs hooks, which call Fvertical_motion. At the end, we | |
4248 | end up in init_iterator with a null face cache, which should not | |
4249 | happen. */ | |
4250 | init_frame_faces (f); | |
7d0393cf | 4251 | |
6431f2e6 CY |
4252 | /* The X resources controlling the menu-bar and tool-bar are |
4253 | processed specially at startup, and reflected in the mode | |
4254 | variables; ignore them here. */ | |
4255 | x_default_parameter (f, parameters, Qmenu_bar_lines, | |
4256 | NILP (Vmenu_bar_mode) | |
4257 | ? make_number (0) : make_number (1), | |
4258 | NULL, NULL, RES_TYPE_NUMBER); | |
4259 | x_default_parameter (f, parameters, Qtool_bar_lines, | |
4260 | NILP (Vtool_bar_mode) | |
4261 | ? make_number (0) : make_number (1), | |
4262 | NULL, NULL, RES_TYPE_NUMBER); | |
919f1e88 | 4263 | |
52deb19f | 4264 | x_default_parameter (f, parameters, Qbuffer_predicate, Qnil, |
6fc2811b | 4265 | "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL); |
52deb19f | 4266 | x_default_parameter (f, parameters, Qtitle, Qnil, |
6fc2811b | 4267 | "title", "Title", RES_TYPE_STRING); |
52deb19f | 4268 | x_default_parameter (f, parameters, Qfullscreen, Qnil, |
f7b9d4d1 | 4269 | "fullscreen", "Fullscreen", RES_TYPE_SYMBOL); |
ee78dc32 | 4270 | |
fbd6baed GV |
4271 | f->output_data.w32->dwStyle = WS_OVERLAPPEDWINDOW; |
4272 | f->output_data.w32->parent_desc = FRAME_W32_DISPLAY_INFO (f)->root_window; | |
3cf3436e | 4273 | |
c9b2104d JR |
4274 | f->output_data.w32->text_cursor = w32_load_cursor (IDC_IBEAM); |
4275 | f->output_data.w32->nontext_cursor = w32_load_cursor (IDC_ARROW); | |
4276 | f->output_data.w32->modeline_cursor = w32_load_cursor (IDC_ARROW); | |
7d63e5e3 | 4277 | f->output_data.w32->hand_cursor = w32_load_cursor (IDC_HAND); |
c9b2104d JR |
4278 | f->output_data.w32->hourglass_cursor = w32_load_cursor (IDC_WAIT); |
4279 | f->output_data.w32->horizontal_drag_cursor = w32_load_cursor (IDC_SIZEWE); | |
c9b2104d | 4280 | |
d148e14d JR |
4281 | f->output_data.w32->current_cursor = f->output_data.w32->nontext_cursor; |
4282 | ||
52deb19f | 4283 | window_prompting = x_figure_window_size (f, parameters, 1); |
ee78dc32 | 4284 | |
3faa984f | 4285 | tem = x_get_arg (dpyinfo, parameters, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN); |
6fc2811b JR |
4286 | f->no_split = minibuffer_only || EQ (tem, Qt); |
4287 | ||
fbd6baed | 4288 | w32_window (f, window_prompting, minibuffer_only); |
52deb19f | 4289 | x_icon (f, parameters); |
6fc2811b JR |
4290 | |
4291 | x_make_gc (f); | |
4292 | ||
4293 | /* Now consider the frame official. */ | |
4294 | FRAME_W32_DISPLAY_INFO (f)->reference_count++; | |
4295 | Vframe_list = Fcons (frame, Vframe_list); | |
ee78dc32 GV |
4296 | |
4297 | /* We need to do this after creating the window, so that the | |
4298 | icon-creation functions can say whose icon they're describing. */ | |
52deb19f | 4299 | x_default_parameter (f, parameters, Qicon_type, Qnil, |
6fc2811b | 4300 | "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL); |
ee78dc32 | 4301 | |
52deb19f | 4302 | x_default_parameter (f, parameters, Qauto_raise, Qnil, |
6fc2811b | 4303 | "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN); |
52deb19f | 4304 | x_default_parameter (f, parameters, Qauto_lower, Qnil, |
6fc2811b | 4305 | "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN); |
52deb19f | 4306 | x_default_parameter (f, parameters, Qcursor_type, Qbox, |
6fc2811b | 4307 | "cursorType", "CursorType", RES_TYPE_SYMBOL); |
52deb19f | 4308 | x_default_parameter (f, parameters, Qscroll_bar_width, Qnil, |
6fc2811b | 4309 | "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER); |
8b61a891 JR |
4310 | x_default_parameter (f, parameters, Qalpha, Qnil, |
4311 | "alpha", "Alpha", RES_TYPE_NUMBER); | |
ee78dc32 | 4312 | |
be786000 | 4313 | /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size. |
ee78dc32 | 4314 | Change will not be effected unless different from the current |
be786000 KS |
4315 | FRAME_LINES (f). */ |
4316 | width = FRAME_COLS (f); | |
4317 | height = FRAME_LINES (f); | |
dc220243 | 4318 | |
be786000 KS |
4319 | FRAME_LINES (f) = 0; |
4320 | SET_FRAME_COLS (f, 0); | |
6fc2811b JR |
4321 | change_frame_size (f, height, width, 1, 0, 0); |
4322 | ||
6fc2811b JR |
4323 | /* Tell the server what size and position, etc, we want, and how |
4324 | badly we want them. This should be done after we have the menu | |
4325 | bar so that its size can be taken into account. */ | |
ee78dc32 GV |
4326 | BLOCK_INPUT; |
4327 | x_wm_set_size_hint (f, window_prompting, 0); | |
4328 | UNBLOCK_INPUT; | |
4329 | ||
6fc2811b JR |
4330 | /* Make the window appear on the frame and enable display, unless |
4331 | the caller says not to. However, with explicit parent, Emacs | |
4332 | cannot control visibility, so don't try. */ | |
fbd6baed | 4333 | if (! f->output_data.w32->explicit_parent) |
ee78dc32 GV |
4334 | { |
4335 | Lisp_Object visibility; | |
4336 | ||
3faa984f | 4337 | visibility = x_get_arg (dpyinfo, parameters, Qvisibility, 0, 0, RES_TYPE_SYMBOL); |
ee78dc32 GV |
4338 | if (EQ (visibility, Qunbound)) |
4339 | visibility = Qt; | |
4340 | ||
4341 | if (EQ (visibility, Qicon)) | |
4342 | x_iconify_frame (f); | |
4343 | else if (! NILP (visibility)) | |
4344 | x_make_frame_visible (f); | |
4345 | else | |
4346 | /* Must have been Qnil. */ | |
4347 | ; | |
4348 | } | |
55d5acfa DN |
4349 | |
4350 | /* Initialize `default-minibuffer-frame' in case this is the first | |
4351 | frame on this terminal. */ | |
4352 | if (FRAME_HAS_MINIBUF_P (f) | |
4353 | && (!FRAMEP (kb->Vdefault_minibuffer_frame) | |
4354 | || !FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))) | |
4355 | kb->Vdefault_minibuffer_frame = frame; | |
4356 | ||
4357 | /* All remaining specified parameters, which have not been "used" | |
4358 | by x_get_arg and friends, now go in the misc. alist of the frame. */ | |
99784d63 | 4359 | for (tem = parameters; CONSP (tem); tem = XCDR (tem)) |
55d5acfa DN |
4360 | if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem)))) |
4361 | f->param_alist = Fcons (XCAR (tem), f->param_alist); | |
4362 | ||
6fc2811b | 4363 | UNGCPRO; |
7d0393cf | 4364 | |
9e57df62 GM |
4365 | /* Make sure windows on this frame appear in calls to next-window |
4366 | and similar functions. */ | |
4367 | Vwindow_list = Qnil; | |
7d0393cf | 4368 | |
ee78dc32 GV |
4369 | return unbind_to (count, frame); |
4370 | } | |
4371 | ||
4372 | /* FRAME is used only to get a handle on the X display. We don't pass the | |
4373 | display info directly because we're called from frame.c, which doesn't | |
4374 | know about that structure. */ | |
4375 | Lisp_Object | |
b56ceb92 | 4376 | x_get_focus_frame (struct frame *frame) |
ee78dc32 | 4377 | { |
fbd6baed | 4378 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (frame); |
ee78dc32 | 4379 | Lisp_Object xfocus; |
fbd6baed | 4380 | if (! dpyinfo->w32_focus_frame) |
ee78dc32 GV |
4381 | return Qnil; |
4382 | ||
fbd6baed | 4383 | XSETFRAME (xfocus, dpyinfo->w32_focus_frame); |
ee78dc32 GV |
4384 | return xfocus; |
4385 | } | |
1edf84e7 | 4386 | |
334a1195 | 4387 | DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0, |
74e1aeec | 4388 | doc: /* Give FRAME input focus, raising to foreground if necessary. */) |
5842a27b | 4389 | (Lisp_Object frame) |
1edf84e7 GV |
4390 | { |
4391 | x_focus_on_frame (check_x_frame (frame)); | |
4392 | return Qnil; | |
4393 | } | |
4394 | ||
ee78dc32 | 4395 | \f |
6fc2811b | 4396 | DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0, |
4f4f2973 GM |
4397 | doc: /* Internal function called by `color-defined-p', which see. |
4398 | \(Note that the Nextstep version of this function ignores FRAME.) */) | |
5842a27b | 4399 | (Lisp_Object color, Lisp_Object frame) |
6fc2811b JR |
4400 | { |
4401 | XColor foo; | |
4402 | FRAME_PTR f = check_x_frame (frame); | |
ee78dc32 | 4403 | |
b7826503 | 4404 | CHECK_STRING (color); |
ee78dc32 | 4405 | |
d5db4077 | 4406 | if (w32_defined_color (f, SDATA (color), &foo, 0)) |
6fc2811b JR |
4407 | return Qt; |
4408 | else | |
4409 | return Qnil; | |
4410 | } | |
ee78dc32 | 4411 | |
2d764c78 | 4412 | DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0, |
74e1aeec | 4413 | doc: /* Internal function called by `color-values', which see. */) |
5842a27b | 4414 | (Lisp_Object color, Lisp_Object frame) |
ee78dc32 | 4415 | { |
6fc2811b | 4416 | XColor foo; |
ee78dc32 GV |
4417 | FRAME_PTR f = check_x_frame (frame); |
4418 | ||
b7826503 | 4419 | CHECK_STRING (color); |
ee78dc32 | 4420 | |
d5db4077 | 4421 | if (w32_defined_color (f, SDATA (color), &foo, 0)) |
a508663b KS |
4422 | return list3 (make_number ((GetRValue (foo.pixel) << 8) |
4423 | | GetRValue (foo.pixel)), | |
4424 | make_number ((GetGValue (foo.pixel) << 8) | |
4425 | | GetGValue (foo.pixel)), | |
4426 | make_number ((GetBValue (foo.pixel) << 8) | |
4427 | | GetBValue (foo.pixel))); | |
ee78dc32 GV |
4428 | else |
4429 | return Qnil; | |
4430 | } | |
4431 | ||
2d764c78 | 4432 | DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0, |
74e1aeec | 4433 | doc: /* Internal function called by `display-color-p', which see. */) |
5842a27b | 4434 | (Lisp_Object display) |
ee78dc32 | 4435 | { |
fbd6baed | 4436 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 GV |
4437 | |
4438 | if ((dpyinfo->n_planes * dpyinfo->n_cbits) <= 2) | |
4439 | return Qnil; | |
4440 | ||
4441 | return Qt; | |
4442 | } | |
4443 | ||
74e1aeec JR |
4444 | DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, |
4445 | Sx_display_grayscale_p, 0, 1, 0, | |
52deb19f | 4446 | doc: /* Return t if DISPLAY supports shades of gray. |
74e1aeec JR |
4447 | Note that color displays do support shades of gray. |
4448 | The optional argument DISPLAY specifies which display to ask about. | |
4449 | DISPLAY should be either a frame or a display name (a string). | |
4450 | If omitted or nil, that stands for the selected frame's display. */) | |
5842a27b | 4451 | (Lisp_Object display) |
ee78dc32 | 4452 | { |
fbd6baed | 4453 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 GV |
4454 | |
4455 | if ((dpyinfo->n_planes * dpyinfo->n_cbits) <= 1) | |
4456 | return Qnil; | |
4457 | ||
4458 | return Qt; | |
4459 | } | |
4460 | ||
74e1aeec JR |
4461 | DEFUN ("x-display-pixel-width", Fx_display_pixel_width, |
4462 | Sx_display_pixel_width, 0, 1, 0, | |
36458ebd | 4463 | doc: /* Return the width in pixels of DISPLAY. |
74e1aeec JR |
4464 | The optional argument DISPLAY specifies which display to ask about. |
4465 | DISPLAY should be either a frame or a display name (a string). | |
4466 | If omitted or nil, that stands for the selected frame's display. */) | |
5842a27b | 4467 | (Lisp_Object display) |
ee78dc32 | 4468 | { |
fbd6baed | 4469 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 | 4470 | |
05eb7cdc | 4471 | return make_number (x_display_pixel_width (dpyinfo)); |
ee78dc32 GV |
4472 | } |
4473 | ||
4474 | DEFUN ("x-display-pixel-height", Fx_display_pixel_height, | |
74e1aeec | 4475 | Sx_display_pixel_height, 0, 1, 0, |
36458ebd | 4476 | doc: /* Return the height in pixels of DISPLAY. |
74e1aeec JR |
4477 | The optional argument DISPLAY specifies which display to ask about. |
4478 | DISPLAY should be either a frame or a display name (a string). | |
4479 | If omitted or nil, that stands for the selected frame's display. */) | |
5842a27b | 4480 | (Lisp_Object display) |
ee78dc32 | 4481 | { |
fbd6baed | 4482 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 | 4483 | |
05eb7cdc | 4484 | return make_number (x_display_pixel_height (dpyinfo)); |
ee78dc32 GV |
4485 | } |
4486 | ||
4487 | DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes, | |
74e1aeec | 4488 | 0, 1, 0, |
36458ebd | 4489 | doc: /* Return the number of bitplanes of DISPLAY. |
74e1aeec JR |
4490 | The optional argument DISPLAY specifies which display to ask about. |
4491 | DISPLAY should be either a frame or a display name (a string). | |
4492 | If omitted or nil, that stands for the selected frame's display. */) | |
5842a27b | 4493 | (Lisp_Object display) |
ee78dc32 | 4494 | { |
fbd6baed | 4495 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 GV |
4496 | |
4497 | return make_number (dpyinfo->n_planes * dpyinfo->n_cbits); | |
4498 | } | |
4499 | ||
4500 | DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells, | |
74e1aeec | 4501 | 0, 1, 0, |
36458ebd | 4502 | doc: /* Return the number of color cells of DISPLAY. |
74e1aeec JR |
4503 | The optional argument DISPLAY specifies which display to ask about. |
4504 | DISPLAY should be either a frame or a display name (a string). | |
4505 | If omitted or nil, that stands for the selected frame's display. */) | |
5842a27b | 4506 | (Lisp_Object display) |
ee78dc32 | 4507 | { |
fbd6baed | 4508 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 GV |
4509 | HDC hdc; |
4510 | int cap; | |
4511 | ||
5ac45f98 GV |
4512 | hdc = GetDC (dpyinfo->root_window); |
4513 | if (dpyinfo->has_palette) | |
52deb19f | 4514 | cap = GetDeviceCaps (hdc, SIZEPALETTE); |
5ac45f98 | 4515 | else |
52deb19f | 4516 | cap = GetDeviceCaps (hdc, NUMCOLORS); |
abf8c61b | 4517 | |
007776bc JB |
4518 | /* We force 24+ bit depths to 24-bit, both to prevent an overflow |
4519 | and because probably is more meaningful on Windows anyway */ | |
abf8c61b | 4520 | if (cap < 0) |
74084731 | 4521 | cap = 1 << min (dpyinfo->n_planes * dpyinfo->n_cbits, 24); |
7d0393cf | 4522 | |
ee78dc32 | 4523 | ReleaseDC (dpyinfo->root_window, hdc); |
7d0393cf | 4524 | |
ee78dc32 GV |
4525 | return make_number (cap); |
4526 | } | |
4527 | ||
4528 | DEFUN ("x-server-max-request-size", Fx_server_max_request_size, | |
4529 | Sx_server_max_request_size, | |
74e1aeec | 4530 | 0, 1, 0, |
36458ebd | 4531 | doc: /* Return the maximum request size of the server of DISPLAY. |
74e1aeec JR |
4532 | The optional argument DISPLAY specifies which display to ask about. |
4533 | DISPLAY should be either a frame or a display name (a string). | |
4534 | If omitted or nil, that stands for the selected frame's display. */) | |
5842a27b | 4535 | (Lisp_Object display) |
ee78dc32 | 4536 | { |
fbd6baed | 4537 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 GV |
4538 | |
4539 | return make_number (1); | |
4540 | } | |
4541 | ||
4542 | DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0, | |
36458ebd | 4543 | doc: /* Return the "vendor ID" string of the W32 system (Microsoft). |
74e1aeec JR |
4544 | The optional argument DISPLAY specifies which display to ask about. |
4545 | DISPLAY should be either a frame or a display name (a string). | |
4546 | If omitted or nil, that stands for the selected frame's display. */) | |
5842a27b | 4547 | (Lisp_Object display) |
ee78dc32 | 4548 | { |
dfff8a69 | 4549 | return build_string ("Microsoft Corp."); |
ee78dc32 GV |
4550 | } |
4551 | ||
4552 | DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0, | |
36458ebd | 4553 | doc: /* Return the version numbers of the server of DISPLAY. |
74e1aeec | 4554 | The value is a list of three integers: the major and minor |
02b39a28 JB |
4555 | version numbers of the X Protocol in use, and the distributor-specific |
4556 | release number. See also the function `x-server-vendor'. | |
74e1aeec JR |
4557 | |
4558 | The optional argument DISPLAY specifies which display to ask about. | |
4559 | DISPLAY should be either a frame or a display name (a string). | |
4560 | If omitted or nil, that stands for the selected frame's display. */) | |
5842a27b | 4561 | (Lisp_Object display) |
ee78dc32 | 4562 | { |
fbd6baed | 4563 | return Fcons (make_number (w32_major_version), |
58e0f0e4 AI |
4564 | Fcons (make_number (w32_minor_version), |
4565 | Fcons (make_number (w32_build_number), Qnil))); | |
ee78dc32 GV |
4566 | } |
4567 | ||
4568 | DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0, | |
36458ebd | 4569 | doc: /* Return the number of screens on the server of DISPLAY. |
74e1aeec JR |
4570 | The optional argument DISPLAY specifies which display to ask about. |
4571 | DISPLAY should be either a frame or a display name (a string). | |
4572 | If omitted or nil, that stands for the selected frame's display. */) | |
5842a27b | 4573 | (Lisp_Object display) |
ee78dc32 | 4574 | { |
ee78dc32 GV |
4575 | return make_number (1); |
4576 | } | |
4577 | ||
74e1aeec JR |
4578 | DEFUN ("x-display-mm-height", Fx_display_mm_height, |
4579 | Sx_display_mm_height, 0, 1, 0, | |
36458ebd | 4580 | doc: /* Return the height in millimeters of DISPLAY. |
74e1aeec JR |
4581 | The optional argument DISPLAY specifies which display to ask about. |
4582 | DISPLAY should be either a frame or a display name (a string). | |
4583 | If omitted or nil, that stands for the selected frame's display. */) | |
5842a27b | 4584 | (Lisp_Object display) |
ee78dc32 | 4585 | { |
fbd6baed | 4586 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 GV |
4587 | HDC hdc; |
4588 | int cap; | |
4589 | ||
5ac45f98 | 4590 | hdc = GetDC (dpyinfo->root_window); |
7d0393cf | 4591 | |
ee78dc32 | 4592 | cap = GetDeviceCaps (hdc, VERTSIZE); |
7d0393cf | 4593 | |
ee78dc32 | 4594 | ReleaseDC (dpyinfo->root_window, hdc); |
7d0393cf | 4595 | |
ee78dc32 GV |
4596 | return make_number (cap); |
4597 | } | |
4598 | ||
4599 | DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0, | |
36458ebd | 4600 | doc: /* Return the width in millimeters of DISPLAY. |
74e1aeec JR |
4601 | The optional argument DISPLAY specifies which display to ask about. |
4602 | DISPLAY should be either a frame or a display name (a string). | |
4603 | If omitted or nil, that stands for the selected frame's display. */) | |
5842a27b | 4604 | (Lisp_Object display) |
ee78dc32 | 4605 | { |
fbd6baed | 4606 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 GV |
4607 | |
4608 | HDC hdc; | |
4609 | int cap; | |
4610 | ||
5ac45f98 | 4611 | hdc = GetDC (dpyinfo->root_window); |
7d0393cf | 4612 | |
ee78dc32 | 4613 | cap = GetDeviceCaps (hdc, HORZSIZE); |
7d0393cf | 4614 | |
ee78dc32 | 4615 | ReleaseDC (dpyinfo->root_window, hdc); |
7d0393cf | 4616 | |
ee78dc32 GV |
4617 | return make_number (cap); |
4618 | } | |
4619 | ||
4620 | DEFUN ("x-display-backing-store", Fx_display_backing_store, | |
74e1aeec | 4621 | Sx_display_backing_store, 0, 1, 0, |
36458ebd | 4622 | doc: /* Return an indication of whether DISPLAY does backing store. |
74e1aeec JR |
4623 | The value may be `always', `when-mapped', or `not-useful'. |
4624 | The optional argument DISPLAY specifies which display to ask about. | |
4625 | DISPLAY should be either a frame or a display name (a string). | |
4626 | If omitted or nil, that stands for the selected frame's display. */) | |
5842a27b | 4627 | (Lisp_Object display) |
ee78dc32 GV |
4628 | { |
4629 | return intern ("not-useful"); | |
4630 | } | |
4631 | ||
4632 | DEFUN ("x-display-visual-class", Fx_display_visual_class, | |
74e1aeec | 4633 | Sx_display_visual_class, 0, 1, 0, |
36458ebd | 4634 | doc: /* Return the visual class of DISPLAY. |
74e1aeec JR |
4635 | The value is one of the symbols `static-gray', `gray-scale', |
4636 | `static-color', `pseudo-color', `true-color', or `direct-color'. | |
4637 | ||
4638 | The optional argument DISPLAY specifies which display to ask about. | |
4639 | DISPLAY should be either a frame or a display name (a string). | |
4640 | If omitted or nil, that stands for the selected frame's display. */) | |
5842a27b | 4641 | (Lisp_Object display) |
ee78dc32 | 4642 | { |
fbd6baed | 4643 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
abf8c61b | 4644 | Lisp_Object result = Qnil; |
ee78dc32 | 4645 | |
abf8c61b AI |
4646 | if (dpyinfo->has_palette) |
4647 | result = intern ("pseudo-color"); | |
4648 | else if (dpyinfo->n_planes * dpyinfo->n_cbits == 1) | |
4649 | result = intern ("static-grey"); | |
4650 | else if (dpyinfo->n_planes * dpyinfo->n_cbits == 4) | |
4651 | result = intern ("static-color"); | |
4652 | else if (dpyinfo->n_planes * dpyinfo->n_cbits > 8) | |
4653 | result = intern ("true-color"); | |
ee78dc32 | 4654 | |
abf8c61b | 4655 | return result; |
ee78dc32 GV |
4656 | } |
4657 | ||
4658 | DEFUN ("x-display-save-under", Fx_display_save_under, | |
74e1aeec | 4659 | Sx_display_save_under, 0, 1, 0, |
02b39a28 | 4660 | doc: /* Return t if DISPLAY supports the save-under feature. |
74e1aeec JR |
4661 | The optional argument DISPLAY specifies which display to ask about. |
4662 | DISPLAY should be either a frame or a display name (a string). | |
4663 | If omitted or nil, that stands for the selected frame's display. */) | |
5842a27b | 4664 | (Lisp_Object display) |
ee78dc32 | 4665 | { |
6fc2811b JR |
4666 | return Qnil; |
4667 | } | |
4668 | \f | |
4669 | int | |
b56ceb92 | 4670 | x_pixel_width (register struct frame *f) |
6fc2811b | 4671 | { |
be786000 | 4672 | return FRAME_PIXEL_WIDTH (f); |
6fc2811b JR |
4673 | } |
4674 | ||
4675 | int | |
b56ceb92 | 4676 | x_pixel_height (register struct frame *f) |
6fc2811b | 4677 | { |
be786000 | 4678 | return FRAME_PIXEL_HEIGHT (f); |
6fc2811b JR |
4679 | } |
4680 | ||
4681 | int | |
b56ceb92 | 4682 | x_char_width (register struct frame *f) |
6fc2811b | 4683 | { |
be786000 | 4684 | return FRAME_COLUMN_WIDTH (f); |
6fc2811b JR |
4685 | } |
4686 | ||
4687 | int | |
b56ceb92 | 4688 | x_char_height (register struct frame *f) |
6fc2811b | 4689 | { |
be786000 | 4690 | return FRAME_LINE_HEIGHT (f); |
6fc2811b JR |
4691 | } |
4692 | ||
4693 | int | |
b56ceb92 | 4694 | x_screen_planes (register struct frame *f) |
6fc2811b JR |
4695 | { |
4696 | return FRAME_W32_DISPLAY_INFO (f)->n_planes; | |
4697 | } | |
4698 | \f | |
4699 | /* Return the display structure for the display named NAME. | |
4700 | Open a new connection if necessary. */ | |
4701 | ||
4702 | struct w32_display_info * | |
b56ceb92 | 4703 | x_display_info_for_name (Lisp_Object name) |
6fc2811b JR |
4704 | { |
4705 | Lisp_Object names; | |
4706 | struct w32_display_info *dpyinfo; | |
4707 | ||
b7826503 | 4708 | CHECK_STRING (name); |
6fc2811b JR |
4709 | |
4710 | for (dpyinfo = &one_w32_display_info, names = w32_display_name_list; | |
4711 | dpyinfo; | |
4712 | dpyinfo = dpyinfo->next, names = XCDR (names)) | |
4713 | { | |
4714 | Lisp_Object tem; | |
4715 | tem = Fstring_equal (XCAR (XCAR (names)), name); | |
4716 | if (!NILP (tem)) | |
4717 | return dpyinfo; | |
4718 | } | |
4719 | ||
4720 | /* Use this general default value to start with. */ | |
4721 | Vx_resource_name = Vinvocation_name; | |
4722 | ||
4723 | validate_x_resource_name (); | |
4724 | ||
4725 | dpyinfo = w32_term_init (name, (unsigned char *)0, | |
51b59d79 | 4726 | SSDATA (Vx_resource_name)); |
6fc2811b JR |
4727 | |
4728 | if (dpyinfo == 0) | |
d5db4077 | 4729 | error ("Cannot connect to server %s", SDATA (name)); |
6fc2811b JR |
4730 | |
4731 | w32_in_use = 1; | |
d5272e33 | 4732 | XSETFASTINT (Vwindow_system_version, w32_major_version); |
6fc2811b JR |
4733 | |
4734 | return dpyinfo; | |
4735 | } | |
4736 | ||
4737 | DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection, | |
4f4f2973 | 4738 | 1, 3, 0, doc: /* Open a connection to a display server. |
74e1aeec JR |
4739 | DISPLAY is the name of the display to connect to. |
4740 | Optional second arg XRM-STRING is a string of resources in xrdb format. | |
4741 | If the optional third arg MUST-SUCCEED is non-nil, | |
4f4f2973 GM |
4742 | terminate Emacs if we can't open the connection. |
4743 | \(In the Nextstep version, the last two arguments are currently ignored.) */) | |
5842a27b | 4744 | (Lisp_Object display, Lisp_Object xrm_string, Lisp_Object must_succeed) |
6fc2811b JR |
4745 | { |
4746 | unsigned char *xrm_option; | |
4747 | struct w32_display_info *dpyinfo; | |
4748 | ||
74e1aeec JR |
4749 | /* If initialization has already been done, return now to avoid |
4750 | overwriting critical parts of one_w32_display_info. */ | |
4751 | if (w32_in_use) | |
4752 | return Qnil; | |
4753 | ||
b7826503 | 4754 | CHECK_STRING (display); |
6fc2811b | 4755 | if (! NILP (xrm_string)) |
b7826503 | 4756 | CHECK_STRING (xrm_string); |
6fc2811b | 4757 | |
2dc8b986 | 4758 | #if 0 |
6fc2811b JR |
4759 | if (! EQ (Vwindow_system, intern ("w32"))) |
4760 | error ("Not using Microsoft Windows"); | |
2dc8b986 | 4761 | #endif |
6fc2811b JR |
4762 | |
4763 | /* Allow color mapping to be defined externally; first look in user's | |
4764 | HOME directory, then in Emacs etc dir for a file called rgb.txt. */ | |
4765 | { | |
4766 | Lisp_Object color_file; | |
4767 | struct gcpro gcpro1; | |
4768 | ||
74084731 | 4769 | color_file = build_string ("~/rgb.txt"); |
6fc2811b JR |
4770 | |
4771 | GCPRO1 (color_file); | |
4772 | ||
4773 | if (NILP (Ffile_readable_p (color_file))) | |
4774 | color_file = | |
4775 | Fexpand_file_name (build_string ("rgb.txt"), | |
4776 | Fsymbol_value (intern ("data-directory"))); | |
4777 | ||
7ded3383 | 4778 | Vw32_color_map = Fx_load_color_file (color_file); |
6fc2811b JR |
4779 | |
4780 | UNGCPRO; | |
4781 | } | |
4782 | if (NILP (Vw32_color_map)) | |
4783 | Vw32_color_map = Fw32_default_color_map (); | |
4784 | ||
5a8a15ec JR |
4785 | /* Merge in system logical colors. */ |
4786 | add_system_logical_colors_to_map (&Vw32_color_map); | |
4787 | ||
6fc2811b | 4788 | if (! NILP (xrm_string)) |
51b59d79 | 4789 | xrm_option = SDATA (xrm_string); |
6fc2811b JR |
4790 | else |
4791 | xrm_option = (unsigned char *) 0; | |
4792 | ||
4793 | /* Use this general default value to start with. */ | |
4794 | /* First remove .exe suffix from invocation-name - it looks ugly. */ | |
4795 | { | |
4796 | char basename[ MAX_PATH ], *str; | |
4797 | ||
d5db4077 | 4798 | strcpy (basename, SDATA (Vinvocation_name)); |
6fc2811b JR |
4799 | str = strrchr (basename, '.'); |
4800 | if (str) *str = 0; | |
4801 | Vinvocation_name = build_string (basename); | |
4802 | } | |
4803 | Vx_resource_name = Vinvocation_name; | |
4804 | ||
4805 | validate_x_resource_name (); | |
4806 | ||
4807 | /* This is what opens the connection and sets x_current_display. | |
4808 | This also initializes many symbols, such as those used for input. */ | |
4809 | dpyinfo = w32_term_init (display, xrm_option, | |
51b59d79 | 4810 | SSDATA (Vx_resource_name)); |
6fc2811b JR |
4811 | |
4812 | if (dpyinfo == 0) | |
4813 | { | |
4814 | if (!NILP (must_succeed)) | |
4815 | fatal ("Cannot connect to server %s.\n", | |
d5db4077 | 4816 | SDATA (display)); |
6fc2811b | 4817 | else |
d5db4077 | 4818 | error ("Cannot connect to server %s", SDATA (display)); |
6fc2811b JR |
4819 | } |
4820 | ||
4821 | w32_in_use = 1; | |
4822 | ||
d5272e33 | 4823 | XSETFASTINT (Vwindow_system_version, w32_major_version); |
6fc2811b JR |
4824 | return Qnil; |
4825 | } | |
4826 | ||
4827 | DEFUN ("x-close-connection", Fx_close_connection, | |
4828 | Sx_close_connection, 1, 1, 0, | |
74e1aeec JR |
4829 | doc: /* Close the connection to DISPLAY's server. |
4830 | For DISPLAY, specify either a frame or a display name (a string). | |
4831 | If DISPLAY is nil, that stands for the selected frame's display. */) | |
5842a27b | 4832 | (Lisp_Object display) |
6fc2811b JR |
4833 | { |
4834 | struct w32_display_info *dpyinfo = check_x_display_info (display); | |
4835 | int i; | |
4836 | ||
4837 | if (dpyinfo->reference_count > 0) | |
4838 | error ("Display still has frames on it"); | |
4839 | ||
4840 | BLOCK_INPUT; | |
6fc2811b JR |
4841 | x_destroy_all_bitmaps (dpyinfo); |
4842 | ||
4843 | x_delete_display (dpyinfo); | |
4844 | UNBLOCK_INPUT; | |
4845 | ||
4846 | return Qnil; | |
4847 | } | |
4848 | ||
4849 | DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0, | |
74e1aeec | 4850 | doc: /* Return the list of display names that Emacs has connections to. */) |
5842a27b | 4851 | (void) |
6fc2811b JR |
4852 | { |
4853 | Lisp_Object tail, result; | |
4854 | ||
4855 | result = Qnil; | |
99784d63 | 4856 | for (tail = w32_display_name_list; CONSP (tail); tail = XCDR (tail)) |
6fc2811b JR |
4857 | result = Fcons (XCAR (XCAR (tail)), result); |
4858 | ||
4859 | return result; | |
4860 | } | |
4861 | ||
4862 | DEFUN ("x-synchronize", Fx_synchronize, Sx_synchronize, 1, 2, 0, | |
7c051dd8 GM |
4863 | doc: /* If ON is non-nil, report X errors as soon as the erring request is made. |
4864 | This function only has an effect on X Windows. With MS Windows, it is | |
4865 | defined but does nothing. | |
4866 | ||
4867 | If ON is nil, allow buffering of requests. | |
4868 | Turning on synchronization prohibits the Xlib routines from buffering | |
4869 | requests and seriously degrades performance, but makes debugging much | |
4870 | easier. | |
4871 | The optional second argument TERMINAL specifies which display to act on. | |
4872 | TERMINAL should be a terminal object, a frame or a display name (a string). | |
4873 | If TERMINAL is omitted or nil, that stands for the selected frame's display. */) | |
5842a27b | 4874 | (Lisp_Object on, Lisp_Object display) |
6fc2811b | 4875 | { |
6fc2811b JR |
4876 | return Qnil; |
4877 | } | |
4878 | ||
6b61353c | 4879 | |
6fc2811b | 4880 | \f |
6fc2811b | 4881 | /*********************************************************************** |
6b61353c | 4882 | Window properties |
6fc2811b JR |
4883 | ***********************************************************************/ |
4884 | ||
6b61353c KH |
4885 | DEFUN ("x-change-window-property", Fx_change_window_property, |
4886 | Sx_change_window_property, 2, 6, 0, | |
4887 | doc: /* Change window property PROP to VALUE on the X window of FRAME. | |
7c051dd8 GM |
4888 | PROP must be a string. VALUE may be a string or a list of conses, |
4889 | numbers and/or strings. If an element in the list is a string, it is | |
4890 | converted to an atom and the value of the Atom is used. If an element | |
4891 | is a cons, it is converted to a 32 bit number where the car is the 16 | |
4892 | top bits and the cdr is the lower 16 bits. | |
4893 | ||
6b61353c KH |
4894 | FRAME nil or omitted means use the selected frame. |
4895 | If TYPE is given and non-nil, it is the name of the type of VALUE. | |
4896 | If TYPE is not given or nil, the type is STRING. | |
4897 | FORMAT gives the size in bits of each element if VALUE is a list. | |
4898 | It must be one of 8, 16 or 32. | |
4899 | If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8. | |
4900 | If OUTER_P is non-nil, the property is changed for the outer X window of | |
7c051dd8 | 4901 | FRAME. Default is to change on the edit X window. */) |
5842a27b | 4902 | (Lisp_Object prop, Lisp_Object value, Lisp_Object frame, Lisp_Object type, Lisp_Object format, Lisp_Object outer_p) |
6b61353c KH |
4903 | { |
4904 | #if 0 /* TODO : port window properties to W32 */ | |
4905 | struct frame *f = check_x_frame (frame); | |
4906 | Atom prop_atom; | |
6fc2811b | 4907 | |
6b61353c KH |
4908 | CHECK_STRING (prop); |
4909 | CHECK_STRING (value); | |
6fc2811b | 4910 | |
6b61353c KH |
4911 | BLOCK_INPUT; |
4912 | prop_atom = XInternAtom (FRAME_W32_DISPLAY (f), SDATA (prop), False); | |
4913 | XChangeProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), | |
4914 | prop_atom, XA_STRING, 8, PropModeReplace, | |
4915 | SDATA (value), SCHARS (value)); | |
6fc2811b | 4916 | |
6b61353c KH |
4917 | /* Make sure the property is set when we return. */ |
4918 | XFlush (FRAME_W32_DISPLAY (f)); | |
4919 | UNBLOCK_INPUT; | |
6fc2811b | 4920 | |
6b61353c | 4921 | #endif /* TODO */ |
6fc2811b | 4922 | |
6b61353c KH |
4923 | return value; |
4924 | } | |
dfff8a69 | 4925 | |
6fc2811b | 4926 | |
6b61353c KH |
4927 | DEFUN ("x-delete-window-property", Fx_delete_window_property, |
4928 | Sx_delete_window_property, 1, 2, 0, | |
4929 | doc: /* Remove window property PROP from X window of FRAME. | |
4930 | FRAME nil or omitted means use the selected frame. Value is PROP. */) | |
5842a27b | 4931 | (Lisp_Object prop, Lisp_Object frame) |
6fc2811b | 4932 | { |
6b61353c | 4933 | #if 0 /* TODO : port window properties to W32 */ |
6fc2811b | 4934 | |
6b61353c KH |
4935 | struct frame *f = check_x_frame (frame); |
4936 | Atom prop_atom; | |
6fc2811b | 4937 | |
6b61353c KH |
4938 | CHECK_STRING (prop); |
4939 | BLOCK_INPUT; | |
4940 | prop_atom = XInternAtom (FRAME_W32_DISPLAY (f), SDATA (prop), False); | |
4941 | XDeleteProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), prop_atom); | |
6fc2811b | 4942 | |
6b61353c KH |
4943 | /* Make sure the property is removed when we return. */ |
4944 | XFlush (FRAME_W32_DISPLAY (f)); | |
4945 | UNBLOCK_INPUT; | |
4946 | #endif /* TODO */ | |
6fc2811b | 4947 | |
6b61353c | 4948 | return prop; |
6fc2811b JR |
4949 | } |
4950 | ||
4951 | ||
6b61353c KH |
4952 | DEFUN ("x-window-property", Fx_window_property, Sx_window_property, |
4953 | 1, 2, 0, | |
4954 | doc: /* Value is the value of window property PROP on FRAME. | |
7c051dd8 GM |
4955 | If FRAME is nil or omitted, use the selected frame. |
4956 | ||
4957 | On MS Windows, this function only accepts the PROP and FRAME arguments. | |
4958 | ||
4959 | On X Windows, the following optional arguments are also accepted: | |
4960 | If TYPE is nil or omitted, get the property as a string. | |
4961 | Otherwise TYPE is the name of the atom that denotes the type expected. | |
4962 | If SOURCE is non-nil, get the property on that window instead of from | |
4963 | FRAME. The number 0 denotes the root window. | |
4964 | If DELETE_P is non-nil, delete the property after retreiving it. | |
4965 | If VECTOR_RET_P is non-nil, don't return a string but a vector of values. | |
4966 | ||
4967 | Value is nil if FRAME hasn't a property with name PROP or if PROP has | |
4968 | no value of TYPE (always string in the MS Windows case). */) | |
5842a27b | 4969 | (Lisp_Object prop, Lisp_Object frame) |
6fc2811b | 4970 | { |
6b61353c KH |
4971 | #if 0 /* TODO : port window properties to W32 */ |
4972 | ||
4973 | struct frame *f = check_x_frame (frame); | |
4974 | Atom prop_atom; | |
4975 | int rc; | |
4976 | Lisp_Object prop_value = Qnil; | |
4977 | char *tmp_data = NULL; | |
4978 | Atom actual_type; | |
4979 | int actual_format; | |
4980 | unsigned long actual_size, bytes_remaining; | |
7d0393cf | 4981 | |
6b61353c KH |
4982 | CHECK_STRING (prop); |
4983 | BLOCK_INPUT; | |
4984 | prop_atom = XInternAtom (FRAME_W32_DISPLAY (f), SDATA (prop), False); | |
4985 | rc = XGetWindowProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), | |
4986 | prop_atom, 0, 0, False, XA_STRING, | |
4987 | &actual_type, &actual_format, &actual_size, | |
4988 | &bytes_remaining, (unsigned char **) &tmp_data); | |
4989 | if (rc == Success) | |
6fc2811b | 4990 | { |
6b61353c | 4991 | int size = bytes_remaining; |
3cf3436e | 4992 | |
6b61353c KH |
4993 | XFree (tmp_data); |
4994 | tmp_data = NULL; | |
3cf3436e | 4995 | |
6b61353c KH |
4996 | rc = XGetWindowProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), |
4997 | prop_atom, 0, bytes_remaining, | |
4998 | False, XA_STRING, | |
4999 | &actual_type, &actual_format, | |
5000 | &actual_size, &bytes_remaining, | |
5001 | (unsigned char **) &tmp_data); | |
5002 | if (rc == Success) | |
5003 | prop_value = make_string (tmp_data, size); | |
6fc2811b | 5004 | |
6b61353c KH |
5005 | XFree (tmp_data); |
5006 | } | |
6fc2811b | 5007 | |
6b61353c | 5008 | UNBLOCK_INPUT; |
6fc2811b | 5009 | |
6b61353c | 5010 | return prop_value; |
6fc2811b | 5011 | |
6b61353c KH |
5012 | #endif /* TODO */ |
5013 | return Qnil; | |
6fc2811b JR |
5014 | } |
5015 | ||
5016 | ||
5017 | \f | |
5018 | /*********************************************************************** | |
6b61353c | 5019 | Busy cursor |
6fc2811b JR |
5020 | ***********************************************************************/ |
5021 | ||
1391cd54 JR |
5022 | /* Default number of seconds to wait before displaying an hourglass |
5023 | cursor. Duplicated from xdisp.c, but cannot use the version there | |
5024 | due to lack of atimers on w32. */ | |
5025 | #define DEFAULT_HOURGLASS_DELAY 1 | |
d148e14d | 5026 | /* Return non-zero if houglass timer has been started or hourglass is shown. */ |
1885ab29 AR |
5027 | /* PENDING: if W32 can use atimers (atimer.[hc]) then the common impl in |
5028 | xdisp.c could be used. */ | |
6fc2811b | 5029 | |
d148e14d | 5030 | int |
b56ceb92 | 5031 | hourglass_started (void) |
d148e14d JR |
5032 | { |
5033 | return hourglass_shown_p || hourglass_timer; | |
5034 | } | |
6fc2811b | 5035 | |
6b61353c | 5036 | /* Cancel a currently active hourglass timer, and start a new one. */ |
6fc2811b | 5037 | |
6b61353c | 5038 | void |
b56ceb92 | 5039 | start_hourglass (void) |
6fc2811b | 5040 | { |
d148e14d JR |
5041 | DWORD delay; |
5042 | int secs, msecs = 0; | |
5043 | struct frame * f = SELECTED_FRAME (); | |
6fc2811b | 5044 | |
30076589 JR |
5045 | /* No cursors on non GUI frames. */ |
5046 | if (!FRAME_W32_P (f)) | |
5047 | return; | |
5048 | ||
6b61353c | 5049 | cancel_hourglass (); |
6fc2811b | 5050 | |
6b61353c KH |
5051 | if (INTEGERP (Vhourglass_delay) |
5052 | && XINT (Vhourglass_delay) > 0) | |
5053 | secs = XFASTINT (Vhourglass_delay); | |
5054 | else if (FLOATP (Vhourglass_delay) | |
5055 | && XFLOAT_DATA (Vhourglass_delay) > 0) | |
6fc2811b | 5056 | { |
6b61353c KH |
5057 | Lisp_Object tem; |
5058 | tem = Ftruncate (Vhourglass_delay, Qnil); | |
5059 | secs = XFASTINT (tem); | |
d148e14d | 5060 | msecs = (XFLOAT_DATA (Vhourglass_delay) - secs) * 1000; |
6b61353c KH |
5061 | } |
5062 | else | |
5063 | secs = DEFAULT_HOURGLASS_DELAY; | |
7d0393cf | 5064 | |
d148e14d JR |
5065 | delay = secs * 1000 + msecs; |
5066 | hourglass_hwnd = FRAME_W32_WINDOW (f); | |
5067 | hourglass_timer = SetTimer (hourglass_hwnd, HOURGLASS_ID, delay, NULL); | |
f79e6790 JR |
5068 | } |
5069 | ||
5070 | ||
0af913d7 GM |
5071 | /* Cancel the hourglass cursor timer if active, hide an hourglass |
5072 | cursor if shown. */ | |
f79e6790 JR |
5073 | |
5074 | void | |
b56ceb92 | 5075 | cancel_hourglass (void) |
f79e6790 | 5076 | { |
d148e14d | 5077 | if (hourglass_timer) |
dfff8a69 | 5078 | { |
d148e14d JR |
5079 | KillTimer (hourglass_hwnd, hourglass_timer); |
5080 | hourglass_timer = 0; | |
dfff8a69 | 5081 | } |
7d0393cf | 5082 | |
0af913d7 | 5083 | if (hourglass_shown_p) |
1391cd54 | 5084 | w32_hide_hourglass (); |
f79e6790 JR |
5085 | } |
5086 | ||
5087 | ||
d148e14d | 5088 | /* Timer function of hourglass_timer. |
f79e6790 | 5089 | |
d148e14d JR |
5090 | Display an hourglass cursor. Set the hourglass_p flag in display info |
5091 | to indicate that an hourglass cursor is shown. */ | |
f79e6790 JR |
5092 | |
5093 | static void | |
b56ceb92 | 5094 | w32_show_hourglass (struct frame *f) |
6fc2811b | 5095 | { |
0af913d7 | 5096 | if (!hourglass_shown_p) |
6fc2811b | 5097 | { |
d148e14d JR |
5098 | f->output_data.w32->hourglass_p = 1; |
5099 | if (!menubar_in_use && !current_popup_menu) | |
5100 | SetCursor (f->output_data.w32->hourglass_cursor); | |
0af913d7 | 5101 | hourglass_shown_p = 1; |
f79e6790 | 5102 | } |
6fc2811b JR |
5103 | } |
5104 | ||
5105 | ||
0af913d7 | 5106 | /* Hide the hourglass cursor on all frames, if it is currently shown. */ |
6fc2811b | 5107 | |
f79e6790 | 5108 | static void |
b56ceb92 | 5109 | w32_hide_hourglass (void) |
f79e6790 | 5110 | { |
0af913d7 | 5111 | if (hourglass_shown_p) |
6fc2811b | 5112 | { |
d148e14d JR |
5113 | struct frame *f = x_window_to_frame (&one_w32_display_info, |
5114 | hourglass_hwnd); | |
89e09428 JR |
5115 | if (f) |
5116 | f->output_data.w32->hourglass_p = 0; | |
5117 | else | |
5118 | /* If frame was deleted, restore to selected frame's cursor. */ | |
5119 | f = SELECTED_FRAME (); | |
5120 | ||
5121 | if (FRAME_W32_P (f)) | |
5122 | SetCursor (f->output_data.w32->current_cursor); | |
5123 | else | |
5124 | /* No cursors on non GUI frames - restore to stock arrow cursor. */ | |
5125 | SetCursor (w32_load_cursor (IDC_ARROW)); | |
6fc2811b | 5126 | |
0af913d7 | 5127 | hourglass_shown_p = 0; |
f79e6790 | 5128 | } |
6fc2811b JR |
5129 | } |
5130 | ||
5131 | ||
5132 | \f | |
5133 | /*********************************************************************** | |
5134 | Tool tips | |
5135 | ***********************************************************************/ | |
5136 | ||
f57e2426 J |
5137 | static Lisp_Object x_create_tip_frame (struct w32_display_info *, |
5138 | Lisp_Object, Lisp_Object); | |
5139 | static void compute_tip_xy (struct frame *, Lisp_Object, Lisp_Object, | |
5140 | Lisp_Object, int, int, int *, int *); | |
7d0393cf | 5141 | |
3cf3436e | 5142 | /* The frame of a currently visible tooltip. */ |
6fc2811b | 5143 | |
937e601e | 5144 | Lisp_Object tip_frame; |
6fc2811b JR |
5145 | |
5146 | /* If non-nil, a timer started that hides the last tooltip when it | |
5147 | fires. */ | |
5148 | ||
5149 | Lisp_Object tip_timer; | |
5150 | Window tip_window; | |
5151 | ||
3cf3436e JR |
5152 | /* If non-nil, a vector of 3 elements containing the last args |
5153 | with which x-show-tip was called. See there. */ | |
5154 | ||
5155 | Lisp_Object last_show_tip_args; | |
5156 | ||
3cf3436e | 5157 | |
937e601e | 5158 | static Lisp_Object |
b56ceb92 | 5159 | unwind_create_tip_frame (Lisp_Object frame) |
937e601e | 5160 | { |
c844a81a GM |
5161 | Lisp_Object deleted; |
5162 | ||
5163 | deleted = unwind_create_frame (frame); | |
5164 | if (EQ (deleted, Qt)) | |
5165 | { | |
5166 | tip_window = NULL; | |
5167 | tip_frame = Qnil; | |
5168 | } | |
7d0393cf | 5169 | |
c844a81a | 5170 | return deleted; |
937e601e AI |
5171 | } |
5172 | ||
5173 | ||
6fc2811b | 5174 | /* Create a frame for a tooltip on the display described by DPYINFO. |
3cf3436e JR |
5175 | PARMS is a list of frame parameters. TEXT is the string to |
5176 | display in the tip frame. Value is the frame. | |
937e601e AI |
5177 | |
5178 | Note that functions called here, esp. x_default_parameter can | |
5179 | signal errors, for instance when a specified color name is | |
5180 | undefined. We have to make sure that we're in a consistent state | |
5181 | when this happens. */ | |
6fc2811b JR |
5182 | |
5183 | static Lisp_Object | |
b56ceb92 JB |
5184 | x_create_tip_frame (struct w32_display_info *dpyinfo, |
5185 | Lisp_Object parms, Lisp_Object text) | |
6fc2811b | 5186 | { |
6fc2811b JR |
5187 | struct frame *f; |
5188 | Lisp_Object frame, tem; | |
5189 | Lisp_Object name; | |
5190 | long window_prompting = 0; | |
5191 | int width, height; | |
331379bf | 5192 | int count = SPECPDL_INDEX (); |
6fc2811b JR |
5193 | struct gcpro gcpro1, gcpro2, gcpro3; |
5194 | struct kboard *kb; | |
3cf3436e JR |
5195 | int face_change_count_before = face_change_count; |
5196 | Lisp_Object buffer; | |
5197 | struct buffer *old_buffer; | |
6fc2811b | 5198 | |
ca56d953 | 5199 | check_w32 (); |
6fc2811b JR |
5200 | |
5201 | /* Use this general default value to start with until we know if | |
5202 | this frame has a specified name. */ | |
5203 | Vx_resource_name = Vinvocation_name; | |
5204 | ||
fd142562 | 5205 | kb = dpyinfo->terminal->kboard; |
6fc2811b | 5206 | |
4a217bed EZ |
5207 | /* The calls to x_get_arg remove elements from PARMS, so copy it to |
5208 | avoid destructive changes behind our caller's back. */ | |
5209 | parms = Fcopy_alist (parms); | |
5210 | ||
6fc2811b | 5211 | /* Get the name of the frame to use for resource lookup. */ |
3faa984f | 5212 | name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING); |
6fc2811b JR |
5213 | if (!STRINGP (name) |
5214 | && !EQ (name, Qunbound) | |
5215 | && !NILP (name)) | |
5216 | error ("Invalid frame name--not a string or nil"); | |
5217 | Vx_resource_name = name; | |
5218 | ||
5219 | frame = Qnil; | |
5220 | GCPRO3 (parms, name, frame); | |
9eb16b62 JR |
5221 | /* Make a frame without minibuffer nor mode-line. */ |
5222 | f = make_frame (0); | |
5223 | f->wants_modeline = 0; | |
6fc2811b | 5224 | XSETFRAME (frame, f); |
3cf3436e JR |
5225 | |
5226 | buffer = Fget_buffer_create (build_string (" *tip*")); | |
be786000 | 5227 | Fset_window_buffer (FRAME_ROOT_WINDOW (f), buffer, Qnil); |
3cf3436e JR |
5228 | old_buffer = current_buffer; |
5229 | set_buffer_internal_1 (XBUFFER (buffer)); | |
5230 | current_buffer->truncate_lines = Qnil; | |
5c2a995d KH |
5231 | specbind (Qinhibit_read_only, Qt); |
5232 | specbind (Qinhibit_modification_hooks, Qt); | |
3cf3436e JR |
5233 | Ferase_buffer (); |
5234 | Finsert (1, &text); | |
5235 | set_buffer_internal_1 (old_buffer); | |
7d0393cf | 5236 | |
6fc2811b | 5237 | FRAME_CAN_HAVE_SCROLL_BARS (f) = 0; |
937e601e | 5238 | record_unwind_protect (unwind_create_tip_frame, frame); |
6fc2811b | 5239 | |
3cf3436e JR |
5240 | /* By setting the output method, we're essentially saying that |
5241 | the frame is live, as per FRAME_LIVE_P. If we get a signal | |
5242 | from this point on, x_destroy_window might screw up reference | |
5243 | counts etc. */ | |
ebbb61be JR |
5244 | f->terminal = dpyinfo->terminal; |
5245 | f->terminal->reference_count++; | |
d88c567c | 5246 | f->output_method = output_w32; |
6fc2811b JR |
5247 | f->output_data.w32 = |
5248 | (struct w32_output *) xmalloc (sizeof (struct w32_output)); | |
72af86bd | 5249 | memset (f->output_data.w32, 0, sizeof (struct w32_output)); |
ca56d953 JR |
5250 | |
5251 | FRAME_FONTSET (f) = -1; | |
6fc2811b JR |
5252 | f->icon_name = Qnil; |
5253 | ||
5f004711 | 5254 | #if GLYPH_DEBUG |
354884c4 | 5255 | image_cache_refcount = FRAME_IMAGE_CACHE (f)->refcount; |
937e601e AI |
5256 | dpyinfo_refcount = dpyinfo->reference_count; |
5257 | #endif /* GLYPH_DEBUG */ | |
6fc2811b | 5258 | FRAME_KBOARD (f) = kb; |
6fc2811b JR |
5259 | f->output_data.w32->parent_desc = FRAME_W32_DISPLAY_INFO (f)->root_window; |
5260 | f->output_data.w32->explicit_parent = 0; | |
5261 | ||
5262 | /* Set the name; the functions to which we pass f expect the name to | |
5263 | be set. */ | |
5264 | if (EQ (name, Qunbound) || NILP (name)) | |
5265 | { | |
ca56d953 | 5266 | f->name = build_string (dpyinfo->w32_id_name); |
6fc2811b JR |
5267 | f->explicit_name = 0; |
5268 | } | |
5269 | else | |
5270 | { | |
5271 | f->name = name; | |
5272 | f->explicit_name = 1; | |
5273 | /* use the frame's title when getting resources for this frame. */ | |
5274 | specbind (Qx_resource_name, name); | |
5275 | } | |
5276 | ||
82523155 JR |
5277 | f->resx = dpyinfo->resx; |
5278 | f->resy = dpyinfo->resy; | |
5279 | ||
fdb55376 JR |
5280 | if (uniscribe_available) |
5281 | register_font_driver (&uniscribe_font_driver, f); | |
1cc06b86 | 5282 | register_font_driver (&w32font_driver, f); |
a1fe5c00 | 5283 | |
1cc06b86 KH |
5284 | x_default_parameter (f, parms, Qfont_backend, Qnil, |
5285 | "fontBackend", "FontBackend", RES_TYPE_STRING); | |
a1fe5c00 | 5286 | |
6fc2811b JR |
5287 | /* Extract the window parameters from the supplied values |
5288 | that are needed to determine window geometry. */ | |
1cc06b86 | 5289 | x_default_font_parameter (f, parms); |
6fc2811b JR |
5290 | |
5291 | x_default_parameter (f, parms, Qborder_width, make_number (2), | |
5292 | "borderWidth", "BorderWidth", RES_TYPE_NUMBER); | |
6fc2811b JR |
5293 | /* This defaults to 2 in order to match xterm. We recognize either |
5294 | internalBorderWidth or internalBorder (which is what xterm calls | |
5295 | it). */ | |
5296 | if (NILP (Fassq (Qinternal_border_width, parms))) | |
5297 | { | |
5298 | Lisp_Object value; | |
5299 | ||
3faa984f | 5300 | value = x_get_arg (dpyinfo, parms, Qinternal_border_width, |
6fc2811b JR |
5301 | "internalBorder", "internalBorder", RES_TYPE_NUMBER); |
5302 | if (! EQ (value, Qunbound)) | |
5303 | parms = Fcons (Fcons (Qinternal_border_width, value), | |
5304 | parms); | |
5305 | } | |
bfd6edcc | 5306 | x_default_parameter (f, parms, Qinternal_border_width, make_number (1), |
6fc2811b JR |
5307 | "internalBorderWidth", "internalBorderWidth", |
5308 | RES_TYPE_NUMBER); | |
5309 | ||
5310 | /* Also do the stuff which must be set before the window exists. */ | |
5311 | x_default_parameter (f, parms, Qforeground_color, build_string ("black"), | |
5312 | "foreground", "Foreground", RES_TYPE_STRING); | |
5313 | x_default_parameter (f, parms, Qbackground_color, build_string ("white"), | |
5314 | "background", "Background", RES_TYPE_STRING); | |
5315 | x_default_parameter (f, parms, Qmouse_color, build_string ("black"), | |
5316 | "pointerColor", "Foreground", RES_TYPE_STRING); | |
5317 | x_default_parameter (f, parms, Qcursor_color, build_string ("black"), | |
5318 | "cursorColor", "Foreground", RES_TYPE_STRING); | |
5319 | x_default_parameter (f, parms, Qborder_color, build_string ("black"), | |
5320 | "borderColor", "BorderColor", RES_TYPE_STRING); | |
5321 | ||
5322 | /* Init faces before x_default_parameter is called for scroll-bar | |
5323 | parameters because that function calls x_set_scroll_bar_width, | |
5324 | which calls change_frame_size, which calls Fset_window_buffer, | |
5325 | which runs hooks, which call Fvertical_motion. At the end, we | |
5326 | end up in init_iterator with a null face cache, which should not | |
5327 | happen. */ | |
5328 | init_frame_faces (f); | |
ca56d953 JR |
5329 | |
5330 | f->output_data.w32->dwStyle = WS_BORDER | WS_POPUP | WS_DISABLED; | |
6fc2811b | 5331 | f->output_data.w32->parent_desc = FRAME_W32_DISPLAY_INFO (f)->root_window; |
9eb16b62 | 5332 | |
6d906347 | 5333 | window_prompting = x_figure_window_size (f, parms, 0); |
6fc2811b | 5334 | |
9eb16b62 | 5335 | /* No fringes on tip frame. */ |
be786000 KS |
5336 | f->fringe_cols = 0; |
5337 | f->left_fringe_width = 0; | |
5338 | f->right_fringe_width = 0; | |
9eb16b62 | 5339 | |
ca56d953 JR |
5340 | BLOCK_INPUT; |
5341 | my_create_tip_window (f); | |
5342 | UNBLOCK_INPUT; | |
6fc2811b JR |
5343 | |
5344 | x_make_gc (f); | |
5345 | ||
5346 | x_default_parameter (f, parms, Qauto_raise, Qnil, | |
5347 | "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN); | |
5348 | x_default_parameter (f, parms, Qauto_lower, Qnil, | |
5349 | "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN); | |
5350 | x_default_parameter (f, parms, Qcursor_type, Qbox, | |
5351 | "cursorType", "CursorType", RES_TYPE_SYMBOL); | |
5352 | ||
be786000 | 5353 | /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size. |
6fc2811b | 5354 | Change will not be effected unless different from the current |
be786000 KS |
5355 | FRAME_LINES (f). */ |
5356 | width = FRAME_COLS (f); | |
5357 | height = FRAME_LINES (f); | |
5358 | FRAME_LINES (f) = 0; | |
5359 | SET_FRAME_COLS (f, 0); | |
6fc2811b JR |
5360 | change_frame_size (f, height, width, 1, 0, 0); |
5361 | ||
cd1d850f | 5362 | /* Add `tooltip' frame parameter's default value. */ |
54ee7410 CY |
5363 | if (NILP (Fframe_parameter (frame, Qtooltip))) |
5364 | Fmodify_frame_parameters (frame, Fcons (Fcons (Qtooltip, Qt), Qnil)); | |
7d0393cf | 5365 | |
3cf3436e JR |
5366 | /* Set up faces after all frame parameters are known. This call |
5367 | also merges in face attributes specified for new frames. | |
5368 | ||
5369 | Frame parameters may be changed if .Xdefaults contains | |
5370 | specifications for the default font. For example, if there is an | |
5371 | `Emacs.default.attributeBackground: pink', the `background-color' | |
5372 | attribute of the frame get's set, which let's the internal border | |
5373 | of the tooltip frame appear in pink. Prevent this. */ | |
5374 | { | |
5375 | Lisp_Object bg = Fframe_parameter (frame, Qbackground_color); | |
601a9cf1 JB |
5376 | Lisp_Object fg = Fframe_parameter (frame, Qforeground_color); |
5377 | Lisp_Object colors = Qnil; | |
3cf3436e JR |
5378 | |
5379 | /* Set tip_frame here, so that */ | |
5380 | tip_frame = frame; | |
45cebfd9 | 5381 | call2 (Qface_set_after_frame_default, frame, Qnil); |
7d0393cf | 5382 | |
3cf3436e | 5383 | if (!EQ (bg, Fframe_parameter (frame, Qbackground_color))) |
601a9cf1 JB |
5384 | colors = Fcons (Fcons (Qbackground_color, bg), colors); |
5385 | if (!EQ (fg, Fframe_parameter (frame, Qforeground_color))) | |
5386 | colors = Fcons (Fcons (Qforeground_color, fg), colors); | |
5387 | ||
5388 | if (!NILP (colors)) | |
5389 | Fmodify_frame_parameters (frame, colors); | |
3cf3436e | 5390 | } |
7d0393cf | 5391 | |
6fc2811b JR |
5392 | f->no_split = 1; |
5393 | ||
5394 | UNGCPRO; | |
5395 | ||
5396 | /* It is now ok to make the frame official even if we get an error | |
5397 | below. And the frame needs to be on Vframe_list or making it | |
5398 | visible won't work. */ | |
5399 | Vframe_list = Fcons (frame, Vframe_list); | |
5400 | ||
5401 | /* Now that the frame is official, it counts as a reference to | |
5402 | its display. */ | |
5403 | FRAME_W32_DISPLAY_INFO (f)->reference_count++; | |
ee78dc32 | 5404 | |
3cf3436e JR |
5405 | /* Setting attributes of faces of the tooltip frame from resources |
5406 | and similar will increment face_change_count, which leads to the | |
5407 | clearing of all current matrices. Since this isn't necessary | |
5408 | here, avoid it by resetting face_change_count to the value it | |
5409 | had before we created the tip frame. */ | |
5410 | face_change_count = face_change_count_before; | |
5411 | ||
5412 | /* Discard the unwind_protect. */ | |
6fc2811b | 5413 | return unbind_to (count, frame); |
ee78dc32 GV |
5414 | } |
5415 | ||
3cf3436e JR |
5416 | |
5417 | /* Compute where to display tip frame F. PARMS is the list of frame | |
5418 | parameters for F. DX and DY are specified offsets from the current | |
5419 | location of the mouse. WIDTH and HEIGHT are the width and height | |
5420 | of the tooltip. Return coordinates relative to the root window of | |
5421 | the display in *ROOT_X, and *ROOT_Y. */ | |
5422 | ||
5423 | static void | |
b56ceb92 JB |
5424 | compute_tip_xy (struct frame *f, |
5425 | Lisp_Object parms, Lisp_Object dx, Lisp_Object dy, | |
5426 | int width, int height, int *root_x, int *root_y) | |
3cf3436e | 5427 | { |
3cf3436e | 5428 | Lisp_Object left, top; |
64f0809d | 5429 | int min_x, min_y, max_x, max_y; |
7d0393cf | 5430 | |
3cf3436e JR |
5431 | /* User-specified position? */ |
5432 | left = Fcdr (Fassq (Qleft, parms)); | |
5433 | top = Fcdr (Fassq (Qtop, parms)); | |
7d0393cf | 5434 | |
3cf3436e JR |
5435 | /* Move the tooltip window where the mouse pointer is. Resize and |
5436 | show it. */ | |
ca56d953 | 5437 | if (!INTEGERP (left) || !INTEGERP (top)) |
3cf3436e | 5438 | { |
ca56d953 JR |
5439 | POINT pt; |
5440 | ||
64f0809d JR |
5441 | /* Default min and max values. */ |
5442 | min_x = 0; | |
5443 | min_y = 0; | |
05eb7cdc JB |
5444 | max_x = x_display_pixel_width (FRAME_W32_DISPLAY_INFO (f)); |
5445 | max_y = x_display_pixel_height (FRAME_W32_DISPLAY_INFO (f)); | |
64f0809d | 5446 | |
3cf3436e | 5447 | BLOCK_INPUT; |
ca56d953 JR |
5448 | GetCursorPos (&pt); |
5449 | *root_x = pt.x; | |
5450 | *root_y = pt.y; | |
3cf3436e | 5451 | UNBLOCK_INPUT; |
64f0809d JR |
5452 | |
5453 | /* If multiple monitor support is available, constrain the tip onto | |
5454 | the current monitor. This improves the above by allowing negative | |
5455 | co-ordinates if monitor positions are such that they are valid, and | |
5456 | snaps a tooltip onto a single monitor if we are close to the edge | |
5457 | where it would otherwise flow onto the other monitor (or into | |
5458 | nothingness if there is a gap in the overlap). */ | |
5459 | if (monitor_from_point_fn && get_monitor_info_fn) | |
5460 | { | |
5461 | struct MONITOR_INFO info; | |
5462 | HMONITOR monitor | |
5463 | = monitor_from_point_fn (pt, MONITOR_DEFAULT_TO_NEAREST); | |
5464 | info.cbSize = sizeof (info); | |
5465 | ||
5466 | if (get_monitor_info_fn (monitor, &info)) | |
5467 | { | |
5468 | min_x = info.rcWork.left; | |
5469 | min_y = info.rcWork.top; | |
5470 | max_x = info.rcWork.right; | |
5471 | max_y = info.rcWork.bottom; | |
5472 | } | |
5473 | } | |
3cf3436e JR |
5474 | } |
5475 | ||
5476 | if (INTEGERP (top)) | |
5477 | *root_y = XINT (top); | |
64f0809d JR |
5478 | else if (*root_y + XINT (dy) <= min_y) |
5479 | *root_y = min_y; /* Can happen for negative dy */ | |
5480 | else if (*root_y + XINT (dy) + height <= max_y) | |
7e8410d1 | 5481 | /* It fits below the pointer */ |
3cf3436e | 5482 | *root_y += XINT (dy); |
64f0809d | 5483 | else if (height + XINT (dy) + min_y <= *root_y) |
7e8410d1 JD |
5484 | /* It fits above the pointer. */ |
5485 | *root_y -= height + XINT (dy); | |
5486 | else | |
5487 | /* Put it on the top. */ | |
64f0809d | 5488 | *root_y = min_y; |
3cf3436e JR |
5489 | |
5490 | if (INTEGERP (left)) | |
5491 | *root_x = XINT (left); | |
64f0809d | 5492 | else if (*root_x + XINT (dx) <= min_x) |
bf63eb69 | 5493 | *root_x = 0; /* Can happen for negative dx */ |
64f0809d | 5494 | else if (*root_x + XINT (dx) + width <= max_x) |
72e4adef JR |
5495 | /* It fits to the right of the pointer. */ |
5496 | *root_x += XINT (dx); | |
64f0809d | 5497 | else if (width + XINT (dx) + min_x <= *root_x) |
72e4adef | 5498 | /* It fits to the left of the pointer. */ |
3cf3436e JR |
5499 | *root_x -= width + XINT (dx); |
5500 | else | |
72e4adef | 5501 | /* Put it left justified on the screen -- it ought to fit that way. */ |
64f0809d | 5502 | *root_x = min_x; |
3cf3436e JR |
5503 | } |
5504 | ||
5505 | ||
71eab8d1 | 5506 | DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0, |
74e1aeec JR |
5507 | doc: /* Show STRING in a \"tooltip\" window on frame FRAME. |
5508 | A tooltip window is a small window displaying a string. | |
5509 | ||
87c891c7 EZ |
5510 | This is an internal function; Lisp code should call `tooltip-show'. |
5511 | ||
74e1aeec JR |
5512 | FRAME nil or omitted means use the selected frame. |
5513 | ||
5514 | PARMS is an optional list of frame parameters which can be | |
5515 | used to change the tooltip's appearance. | |
5516 | ||
ca56d953 JR |
5517 | Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil |
5518 | means use the default timeout of 5 seconds. | |
74e1aeec | 5519 | |
52deb19f | 5520 | If the list of frame parameters PARMS contains a `left' parameter, |
74e1aeec JR |
5521 | the tooltip is displayed at that x-position. Otherwise it is |
5522 | displayed at the mouse position, with offset DX added (default is 5 if | |
5523 | DX isn't specified). Likewise for the y-position; if a `top' frame | |
5524 | parameter is specified, it determines the y-position of the tooltip | |
5525 | window, otherwise it is displayed at the mouse position, with offset | |
5526 | DY added (default is -10). | |
5527 | ||
5528 | A tooltip's maximum size is specified by `x-max-tooltip-size'. | |
5529 | Text larger than the specified size is clipped. */) | |
5842a27b | 5530 | (Lisp_Object string, Lisp_Object frame, Lisp_Object parms, Lisp_Object timeout, Lisp_Object dx, Lisp_Object dy) |
ee78dc32 | 5531 | { |
6fc2811b JR |
5532 | struct frame *f; |
5533 | struct window *w; | |
3cf3436e | 5534 | int root_x, root_y; |
6fc2811b JR |
5535 | struct buffer *old_buffer; |
5536 | struct text_pos pos; | |
a971c0a7 | 5537 | int i, width, height, seen_reversed_p; |
6fc2811b JR |
5538 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
5539 | int old_windows_or_buffers_changed = windows_or_buffers_changed; | |
331379bf | 5540 | int count = SPECPDL_INDEX (); |
7d0393cf | 5541 | |
6fc2811b | 5542 | specbind (Qinhibit_redisplay, Qt); |
ee78dc32 | 5543 | |
dfff8a69 | 5544 | GCPRO4 (string, parms, frame, timeout); |
ee78dc32 | 5545 | |
b7826503 | 5546 | CHECK_STRING (string); |
6fc2811b JR |
5547 | f = check_x_frame (frame); |
5548 | if (NILP (timeout)) | |
5549 | timeout = make_number (5); | |
5550 | else | |
b7826503 | 5551 | CHECK_NATNUM (timeout); |
ee78dc32 | 5552 | |
71eab8d1 AI |
5553 | if (NILP (dx)) |
5554 | dx = make_number (5); | |
5555 | else | |
b7826503 | 5556 | CHECK_NUMBER (dx); |
7d0393cf | 5557 | |
71eab8d1 | 5558 | if (NILP (dy)) |
dc220243 | 5559 | dy = make_number (-10); |
71eab8d1 | 5560 | else |
b7826503 | 5561 | CHECK_NUMBER (dy); |
71eab8d1 | 5562 | |
dc220243 JR |
5563 | if (NILP (last_show_tip_args)) |
5564 | last_show_tip_args = Fmake_vector (make_number (3), Qnil); | |
5565 | ||
5566 | if (!NILP (tip_frame)) | |
5567 | { | |
5568 | Lisp_Object last_string = AREF (last_show_tip_args, 0); | |
5569 | Lisp_Object last_frame = AREF (last_show_tip_args, 1); | |
5570 | Lisp_Object last_parms = AREF (last_show_tip_args, 2); | |
5571 | ||
5572 | if (EQ (frame, last_frame) | |
5573 | && !NILP (Fequal (last_string, string)) | |
5574 | && !NILP (Fequal (last_parms, parms))) | |
5575 | { | |
5576 | struct frame *f = XFRAME (tip_frame); | |
7d0393cf | 5577 | |
dc220243 JR |
5578 | /* Only DX and DY have changed. */ |
5579 | if (!NILP (tip_timer)) | |
5580 | { | |
5581 | Lisp_Object timer = tip_timer; | |
5582 | tip_timer = Qnil; | |
5583 | call1 (Qcancel_timer, timer); | |
5584 | } | |
5585 | ||
5586 | BLOCK_INPUT; | |
be786000 KS |
5587 | compute_tip_xy (f, parms, dx, dy, FRAME_PIXEL_WIDTH (f), |
5588 | FRAME_PIXEL_HEIGHT (f), &root_x, &root_y); | |
d65a9cdc JR |
5589 | |
5590 | /* Put tooltip in topmost group and in position. */ | |
ca56d953 JR |
5591 | SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOPMOST, |
5592 | root_x, root_y, 0, 0, | |
5593 | SWP_NOSIZE | SWP_NOACTIVATE); | |
d65a9cdc JR |
5594 | |
5595 | /* Ensure tooltip is on top of other topmost windows (eg menus). */ | |
5596 | SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOP, | |
5597 | 0, 0, 0, 0, | |
5598 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); | |
5599 | ||
dc220243 JR |
5600 | UNBLOCK_INPUT; |
5601 | goto start_timer; | |
5602 | } | |
5603 | } | |
5604 | ||
6fc2811b JR |
5605 | /* Hide a previous tip, if any. */ |
5606 | Fx_hide_tip (); | |
ee78dc32 | 5607 | |
dc220243 JR |
5608 | ASET (last_show_tip_args, 0, string); |
5609 | ASET (last_show_tip_args, 1, frame); | |
5610 | ASET (last_show_tip_args, 2, parms); | |
5611 | ||
6fc2811b JR |
5612 | /* Add default values to frame parameters. */ |
5613 | if (NILP (Fassq (Qname, parms))) | |
5614 | parms = Fcons (Fcons (Qname, build_string ("tooltip")), parms); | |
5615 | if (NILP (Fassq (Qinternal_border_width, parms))) | |
5616 | parms = Fcons (Fcons (Qinternal_border_width, make_number (3)), parms); | |
5617 | if (NILP (Fassq (Qborder_width, parms))) | |
5618 | parms = Fcons (Fcons (Qborder_width, make_number (1)), parms); | |
5619 | if (NILP (Fassq (Qborder_color, parms))) | |
5620 | parms = Fcons (Fcons (Qborder_color, build_string ("lightyellow")), parms); | |
5621 | if (NILP (Fassq (Qbackground_color, parms))) | |
5622 | parms = Fcons (Fcons (Qbackground_color, build_string ("lightyellow")), | |
5623 | parms); | |
5624 | ||
0e3fcdef JR |
5625 | /* Block input until the tip has been fully drawn, to avoid crashes |
5626 | when drawing tips in menus. */ | |
5627 | BLOCK_INPUT; | |
5628 | ||
6fc2811b JR |
5629 | /* Create a frame for the tooltip, and record it in the global |
5630 | variable tip_frame. */ | |
ca56d953 | 5631 | frame = x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f), parms, string); |
937e601e | 5632 | f = XFRAME (frame); |
6fc2811b | 5633 | |
3cf3436e | 5634 | /* Set up the frame's root window. */ |
6fc2811b | 5635 | w = XWINDOW (FRAME_ROOT_WINDOW (f)); |
be786000 | 5636 | w->left_col = w->top_line = make_number (0); |
3cf3436e JR |
5637 | |
5638 | if (CONSP (Vx_max_tooltip_size) | |
5639 | && INTEGERP (XCAR (Vx_max_tooltip_size)) | |
5640 | && XINT (XCAR (Vx_max_tooltip_size)) > 0 | |
5641 | && INTEGERP (XCDR (Vx_max_tooltip_size)) | |
5642 | && XINT (XCDR (Vx_max_tooltip_size)) > 0) | |
5643 | { | |
be786000 KS |
5644 | w->total_cols = XCAR (Vx_max_tooltip_size); |
5645 | w->total_lines = XCDR (Vx_max_tooltip_size); | |
3cf3436e JR |
5646 | } |
5647 | else | |
5648 | { | |
be786000 KS |
5649 | w->total_cols = make_number (80); |
5650 | w->total_lines = make_number (40); | |
3cf3436e | 5651 | } |
7d0393cf | 5652 | |
be786000 | 5653 | FRAME_TOTAL_COLS (f) = XINT (w->total_cols); |
6fc2811b JR |
5654 | adjust_glyphs (f); |
5655 | w->pseudo_window_p = 1; | |
5656 | ||
5657 | /* Display the tooltip text in a temporary buffer. */ | |
6fc2811b | 5658 | old_buffer = current_buffer; |
3cf3436e JR |
5659 | set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f))->buffer)); |
5660 | current_buffer->truncate_lines = Qnil; | |
6fc2811b JR |
5661 | clear_glyph_matrix (w->desired_matrix); |
5662 | clear_glyph_matrix (w->current_matrix); | |
5663 | SET_TEXT_POS (pos, BEGV, BEGV_BYTE); | |
39321b94 | 5664 | try_window (FRAME_ROOT_WINDOW (f), pos, TRY_WINDOW_IGNORE_FONTS_CHANGE); |
6fc2811b JR |
5665 | |
5666 | /* Compute width and height of the tooltip. */ | |
a971c0a7 | 5667 | width = height = seen_reversed_p = 0; |
6fc2811b | 5668 | for (i = 0; i < w->desired_matrix->nrows; ++i) |
ee78dc32 | 5669 | { |
6fc2811b JR |
5670 | struct glyph_row *row = &w->desired_matrix->rows[i]; |
5671 | struct glyph *last; | |
5672 | int row_width; | |
5673 | ||
5674 | /* Stop at the first empty row at the end. */ | |
5675 | if (!row->enabled_p || !row->displays_text_p) | |
5676 | break; | |
5677 | ||
5678 | /* Let the row go over the full width of the frame. */ | |
5679 | row->full_width_p = 1; | |
5680 | ||
a971c0a7 | 5681 | row_width = row->pixel_width; |
6fc2811b JR |
5682 | if (row->used[TEXT_AREA]) |
5683 | { | |
a971c0a7 EZ |
5684 | if (!row->reversed_p) |
5685 | { | |
a971c0a7 EZ |
5686 | /* There's a glyph at the end of rows that is used to |
5687 | place the cursor there. Don't include the width of | |
5688 | this glyph. */ | |
5689 | last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1]; | |
5690 | if (INTEGERP (last->object)) | |
5691 | row_width -= last->pixel_width; | |
a971c0a7 EZ |
5692 | } |
5693 | else | |
5694 | { | |
5695 | /* There could be a stretch glyph at the beginning of R2L | |
5696 | rows that is produced by extend_face_to_end_of_line. | |
5697 | Don't count that glyph. */ | |
5698 | struct glyph *g = row->glyphs[TEXT_AREA]; | |
5699 | ||
5700 | if (g->type == STRETCH_GLYPH && INTEGERP (g->object)) | |
5701 | { | |
5702 | row_width -= g->pixel_width; | |
5703 | seen_reversed_p = 1; | |
5704 | } | |
5705 | } | |
5706 | } | |
7d0393cf | 5707 | |
bfd6edcc | 5708 | height += row->height; |
6fc2811b | 5709 | width = max (width, row_width); |
ee78dc32 GV |
5710 | } |
5711 | ||
a971c0a7 EZ |
5712 | /* If we've seen partial-length R2L rows, we need to re-adjust the |
5713 | tool-tip frame width and redisplay it again, to avoid over-wide | |
5714 | tips due to the stretch glyph that extends R2L lines to full | |
5715 | width of the frame. */ | |
5716 | if (seen_reversed_p) | |
5717 | { | |
5718 | /* w->total_cols and FRAME_TOTAL_COLS want the width in columns, | |
5719 | not in pixels. */ | |
5720 | width /= WINDOW_FRAME_COLUMN_WIDTH (w); | |
5721 | w->total_cols = make_number (width); | |
5722 | FRAME_TOTAL_COLS (f) = width; | |
5723 | adjust_glyphs (f); | |
39321b94 | 5724 | w->pseudo_window_p = 1; |
a971c0a7 EZ |
5725 | clear_glyph_matrix (w->desired_matrix); |
5726 | clear_glyph_matrix (w->current_matrix); | |
39321b94 | 5727 | try_window (FRAME_ROOT_WINDOW (f), pos, TRY_WINDOW_IGNORE_FONTS_CHANGE); |
a971c0a7 EZ |
5728 | width = height = 0; |
5729 | /* Recompute width and height of the tooltip. */ | |
5730 | for (i = 0; i < w->desired_matrix->nrows; ++i) | |
5731 | { | |
5732 | struct glyph_row *row = &w->desired_matrix->rows[i]; | |
5733 | struct glyph *last; | |
5734 | int row_width; | |
5735 | ||
5736 | if (!row->enabled_p || !row->displays_text_p) | |
5737 | break; | |
5738 | row->full_width_p = 1; | |
5739 | row_width = row->pixel_width; | |
a971c0a7 EZ |
5740 | if (row->used[TEXT_AREA] && !row->reversed_p) |
5741 | { | |
5742 | last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1]; | |
5743 | if (INTEGERP (last->object)) | |
5744 | row_width -= last->pixel_width; | |
5745 | } | |
a971c0a7 EZ |
5746 | |
5747 | height += row->height; | |
5748 | width = max (width, row_width); | |
5749 | } | |
5750 | } | |
5751 | ||
39321b94 EZ |
5752 | /* Round up the height to an integral multiple of FRAME_LINE_HEIGHT. */ |
5753 | if (height % FRAME_LINE_HEIGHT (f) != 0) | |
5754 | height += FRAME_LINE_HEIGHT (f) - height % FRAME_LINE_HEIGHT (f); | |
5755 | /* Add the frame's internal border to the width and height the w32 | |
6fc2811b JR |
5756 | window should have. */ |
5757 | height += 2 * FRAME_INTERNAL_BORDER_WIDTH (f); | |
5758 | width += 2 * FRAME_INTERNAL_BORDER_WIDTH (f); | |
ee78dc32 | 5759 | |
6fc2811b JR |
5760 | /* Move the tooltip window where the mouse pointer is. Resize and |
5761 | show it. */ | |
3cf3436e | 5762 | compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y); |
71eab8d1 | 5763 | |
bfd6edcc JR |
5764 | { |
5765 | /* Adjust Window size to take border into account. */ | |
5766 | RECT rect; | |
5767 | rect.left = rect.top = 0; | |
5768 | rect.right = width; | |
5769 | rect.bottom = height; | |
5770 | AdjustWindowRect (&rect, f->output_data.w32->dwStyle, | |
5771 | FRAME_EXTERNAL_MENU_BAR (f)); | |
5772 | ||
1d79e521 | 5773 | /* Position and size tooltip, and put it in the topmost group. |
39321b94 EZ |
5774 | The add-on of FRAME_COLUMN_WIDTH to the 5th argument is a |
5775 | peculiarity of w32 display: without it, some fonts cause the | |
5776 | last character of the tip to be truncated or wrapped around to | |
5777 | the next line. */ | |
bfd6edcc | 5778 | SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOPMOST, |
39321b94 EZ |
5779 | root_x, root_y, |
5780 | rect.right - rect.left + FRAME_COLUMN_WIDTH (f), | |
bfd6edcc JR |
5781 | rect.bottom - rect.top, SWP_NOACTIVATE); |
5782 | ||
d65a9cdc JR |
5783 | /* Ensure tooltip is on top of other topmost windows (eg menus). */ |
5784 | SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOP, | |
5785 | 0, 0, 0, 0, | |
5786 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); | |
5787 | ||
bfd6edcc JR |
5788 | /* Let redisplay know that we have made the frame visible already. */ |
5789 | f->async_visible = 1; | |
5790 | ||
5791 | ShowWindow (FRAME_W32_WINDOW (f), SW_SHOWNOACTIVATE); | |
5792 | } | |
ee78dc32 | 5793 | |
6fc2811b JR |
5794 | /* Draw into the window. */ |
5795 | w->must_be_updated_p = 1; | |
5796 | update_single_window (w, 1); | |
ee78dc32 | 5797 | |
0e3fcdef JR |
5798 | UNBLOCK_INPUT; |
5799 | ||
6fc2811b JR |
5800 | /* Restore original current buffer. */ |
5801 | set_buffer_internal_1 (old_buffer); | |
5802 | windows_or_buffers_changed = old_windows_or_buffers_changed; | |
ee78dc32 | 5803 | |
dc220243 | 5804 | start_timer: |
6fc2811b JR |
5805 | /* Let the tip disappear after timeout seconds. */ |
5806 | tip_timer = call3 (intern ("run-at-time"), timeout, Qnil, | |
5807 | intern ("x-hide-tip")); | |
ee78dc32 | 5808 | |
dfff8a69 | 5809 | UNGCPRO; |
6fc2811b | 5810 | return unbind_to (count, Qnil); |
ee78dc32 GV |
5811 | } |
5812 | ||
ee78dc32 | 5813 | |
6fc2811b | 5814 | DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0, |
74e1aeec JR |
5815 | doc: /* Hide the current tooltip window, if there is any. |
5816 | Value is t if tooltip was open, nil otherwise. */) | |
5842a27b | 5817 | (void) |
6fc2811b | 5818 | { |
937e601e AI |
5819 | int count; |
5820 | Lisp_Object deleted, frame, timer; | |
5821 | struct gcpro gcpro1, gcpro2; | |
5822 | ||
5823 | /* Return quickly if nothing to do. */ | |
5824 | if (NILP (tip_timer) && NILP (tip_frame)) | |
5825 | return Qnil; | |
7d0393cf | 5826 | |
937e601e AI |
5827 | frame = tip_frame; |
5828 | timer = tip_timer; | |
5829 | GCPRO2 (frame, timer); | |
5830 | tip_frame = tip_timer = deleted = Qnil; | |
7d0393cf | 5831 | |
331379bf | 5832 | count = SPECPDL_INDEX (); |
6fc2811b | 5833 | specbind (Qinhibit_redisplay, Qt); |
937e601e | 5834 | specbind (Qinhibit_quit, Qt); |
7d0393cf | 5835 | |
937e601e | 5836 | if (!NILP (timer)) |
dc220243 | 5837 | call1 (Qcancel_timer, timer); |
ee78dc32 | 5838 | |
937e601e | 5839 | if (FRAMEP (frame)) |
6fc2811b | 5840 | { |
56f2de10 | 5841 | delete_frame (frame, Qnil); |
937e601e | 5842 | deleted = Qt; |
6fc2811b | 5843 | } |
1edf84e7 | 5844 | |
937e601e AI |
5845 | UNGCPRO; |
5846 | return unbind_to (count, deleted); | |
6fc2811b | 5847 | } |
5ac45f98 | 5848 | |
5ac45f98 | 5849 | |
6fc2811b JR |
5850 | \f |
5851 | /*********************************************************************** | |
5852 | File selection dialog | |
5853 | ***********************************************************************/ | |
6fc2811b JR |
5854 | extern Lisp_Object Qfile_name_history; |
5855 | ||
fffa137c | 5856 | /* Callback for altering the behavior of the Open File dialog. |
1030b26b JR |
5857 | Makes the Filename text field contain "Current Directory" and be |
5858 | read-only when "Directories" is selected in the filter. This | |
5859 | allows us to work around the fact that the standard Open File | |
5860 | dialog does not support directories. */ | |
24f981c9 | 5861 | static UINT CALLBACK |
b56ceb92 | 5862 | file_dialog_callback (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
1030b26b JR |
5863 | { |
5864 | if (msg == WM_NOTIFY) | |
5865 | { | |
5866 | OFNOTIFY * notify = (OFNOTIFY *)lParam; | |
5867 | /* Detect when the Filter dropdown is changed. */ | |
ef544dc8 JR |
5868 | if (notify->hdr.code == CDN_TYPECHANGE |
5869 | || notify->hdr.code == CDN_INITDONE) | |
1030b26b JR |
5870 | { |
5871 | HWND dialog = GetParent (hwnd); | |
5872 | HWND edit_control = GetDlgItem (dialog, FILE_NAME_TEXT_FIELD); | |
5873 | ||
5874 | /* Directories is in index 2. */ | |
5875 | if (notify->lpOFN->nFilterIndex == 2) | |
5876 | { | |
5877 | CommDlg_OpenSave_SetControlText (dialog, FILE_NAME_TEXT_FIELD, | |
5878 | "Current Directory"); | |
5879 | EnableWindow (edit_control, FALSE); | |
5880 | } | |
5881 | else | |
5882 | { | |
ef544dc8 JR |
5883 | /* Don't override default filename on init done. */ |
5884 | if (notify->hdr.code == CDN_TYPECHANGE) | |
5885 | CommDlg_OpenSave_SetControlText (dialog, | |
5886 | FILE_NAME_TEXT_FIELD, ""); | |
1030b26b JR |
5887 | EnableWindow (edit_control, TRUE); |
5888 | } | |
5889 | } | |
5890 | } | |
5891 | return 0; | |
5892 | } | |
5893 | ||
7f2b4738 JR |
5894 | /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility) |
5895 | we end up with the old file dialogs. Define a big enough struct for the | |
5896 | new dialog to trick GetOpenFileName into giving us the new dialogs on | |
5897 | Windows 2000 and XP. */ | |
5898 | typedef struct | |
5899 | { | |
5900 | OPENFILENAME real_details; | |
5901 | void * pReserved; | |
5902 | DWORD dwReserved; | |
5903 | DWORD FlagsEx; | |
5904 | } NEWOPENFILENAME; | |
5905 | ||
21517c3d | 5906 | |
f9d64bb3 | 5907 | DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0, |
74e1aeec | 5908 | doc: /* Read file name, prompting with PROMPT in directory DIR. |
7c051dd8 GM |
5909 | Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file |
5910 | selection box, if specified. If MUSTMATCH is non-nil, the returned file | |
5911 | or directory must exist. | |
5912 | ||
5913 | This function is only defined on MS Windows, and X Windows with the | |
5914 | Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored. | |
5915 | Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) | |
5842a27b | 5916 | (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p) |
6fc2811b JR |
5917 | { |
5918 | struct frame *f = SELECTED_FRAME (); | |
5919 | Lisp_Object file = Qnil; | |
aed13378 | 5920 | int count = SPECPDL_INDEX (); |
f9d64bb3 | 5921 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; |
6fc2811b JR |
5922 | char filename[MAX_PATH + 1]; |
5923 | char init_dir[MAX_PATH + 1]; | |
ef544dc8 | 5924 | int default_filter_index = 1; /* 1: All Files, 2: Directories only */ |
6fc2811b | 5925 | |
f9d64bb3 | 5926 | GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file); |
b7826503 PJ |
5927 | CHECK_STRING (prompt); |
5928 | CHECK_STRING (dir); | |
6fc2811b JR |
5929 | |
5930 | /* Create the dialog with PROMPT as title, using DIR as initial | |
5931 | directory and using "*" as pattern. */ | |
5932 | dir = Fexpand_file_name (dir, Qnil); | |
dda741ec | 5933 | strncpy (init_dir, SDATA (ENCODE_FILE (dir)), MAX_PATH); |
6fc2811b JR |
5934 | init_dir[MAX_PATH] = '\0'; |
5935 | unixtodos_filename (init_dir); | |
5936 | ||
5937 | if (STRINGP (default_filename)) | |
5938 | { | |
5939 | char *file_name_only; | |
dda741ec | 5940 | char *full_path_name = SDATA (ENCODE_FILE (default_filename)); |
5ac45f98 | 5941 | |
6fc2811b | 5942 | unixtodos_filename (full_path_name); |
5ac45f98 | 5943 | |
6fc2811b JR |
5944 | file_name_only = strrchr (full_path_name, '\\'); |
5945 | if (!file_name_only) | |
5946 | file_name_only = full_path_name; | |
5947 | else | |
ef544dc8 | 5948 | file_name_only++; |
ee78dc32 | 5949 | |
6fc2811b JR |
5950 | strncpy (filename, file_name_only, MAX_PATH); |
5951 | filename[MAX_PATH] = '\0'; | |
5952 | } | |
ee78dc32 | 5953 | else |
6fc2811b | 5954 | filename[0] = '\0'; |
ee78dc32 | 5955 | |
1030b26b | 5956 | { |
7f2b4738 | 5957 | NEWOPENFILENAME new_file_details; |
ba6f3859 | 5958 | BOOL file_opened = FALSE; |
7f2b4738 | 5959 | OPENFILENAME * file_details = &new_file_details.real_details; |
21517c3d | 5960 | |
1030b26b JR |
5961 | /* Prevent redisplay. */ |
5962 | specbind (Qinhibit_redisplay, Qt); | |
5963 | BLOCK_INPUT; | |
ee78dc32 | 5964 | |
72af86bd | 5965 | memset (&new_file_details, 0, sizeof (new_file_details)); |
7f2b4738 JR |
5966 | /* Apparently NT4 crashes if you give it an unexpected size. |
5967 | I'm not sure about Windows 9x, so play it safe. */ | |
5968 | if (w32_major_version > 4 && w32_major_version < 95) | |
843d2458 | 5969 | file_details->lStructSize = sizeof (NEWOPENFILENAME); |
7f2b4738 | 5970 | else |
843d2458 | 5971 | file_details->lStructSize = sizeof (OPENFILENAME); |
7f2b4738 JR |
5972 | |
5973 | file_details->hwndOwner = FRAME_W32_WINDOW (f); | |
1030b26b JR |
5974 | /* Undocumented Bug in Common File Dialog: |
5975 | If a filter is not specified, shell links are not resolved. */ | |
7f2b4738 JR |
5976 | file_details->lpstrFilter = "All Files (*.*)\0*.*\0Directories\0*|*\0\0"; |
5977 | file_details->lpstrFile = filename; | |
5978 | file_details->nMaxFile = sizeof (filename); | |
5979 | file_details->lpstrInitialDir = init_dir; | |
5980 | file_details->lpstrTitle = SDATA (prompt); | |
ef544dc8 | 5981 | |
f9d64bb3 | 5982 | if (! NILP (only_dir_p)) |
ef544dc8 JR |
5983 | default_filter_index = 2; |
5984 | ||
7f2b4738 | 5985 | file_details->nFilterIndex = default_filter_index; |
ef544dc8 | 5986 | |
7f2b4738 | 5987 | file_details->Flags = (OFN_HIDEREADONLY | OFN_NOCHANGEDIR |
1030b26b JR |
5988 | | OFN_EXPLORER | OFN_ENABLEHOOK); |
5989 | if (!NILP (mustmatch)) | |
7f2b4738 JR |
5990 | { |
5991 | /* Require that the path to the parent directory exists. */ | |
5992 | file_details->Flags |= OFN_PATHMUSTEXIST; | |
5993 | /* If we are looking for a file, require that it exists. */ | |
5994 | if (NILP (only_dir_p)) | |
5995 | file_details->Flags |= OFN_FILEMUSTEXIST; | |
5996 | } | |
1030b26b | 5997 | |
7f2b4738 | 5998 | file_details->lpfnHook = (LPOFNHOOKPROC) file_dialog_callback; |
1030b26b | 5999 | |
7f2b4738 | 6000 | file_opened = GetOpenFileName (file_details); |
1030b26b | 6001 | |
ba6f3859 JR |
6002 | UNBLOCK_INPUT; |
6003 | ||
6004 | if (file_opened) | |
1030b26b JR |
6005 | { |
6006 | dostounix_filename (filename); | |
7f2b4738 JR |
6007 | |
6008 | if (file_details->nFilterIndex == 2) | |
1030b26b | 6009 | { |
ef544dc8 | 6010 | /* "Directories" selected - strip dummy file name. */ |
1030b26b JR |
6011 | char * last = strrchr (filename, '/'); |
6012 | *last = '\0'; | |
6013 | } | |
6fc2811b | 6014 | |
74084731 | 6015 | file = DECODE_FILE (build_string (filename)); |
1030b26b JR |
6016 | } |
6017 | /* User cancelled the dialog without making a selection. */ | |
6018 | else if (!CommDlgExtendedError ()) | |
6019 | file = Qnil; | |
6020 | /* An error occurred, fallback on reading from the mini-buffer. */ | |
6021 | else | |
6022 | file = Fcompleting_read (prompt, intern ("read-file-name-internal"), | |
6023 | dir, mustmatch, dir, Qfile_name_history, | |
6024 | default_filename, Qnil); | |
6025 | ||
1030b26b JR |
6026 | file = unbind_to (count, file); |
6027 | } | |
ee78dc32 | 6028 | |
6fc2811b | 6029 | UNGCPRO; |
1edf84e7 | 6030 | |
6fc2811b JR |
6031 | /* Make "Cancel" equivalent to C-g. */ |
6032 | if (NILP (file)) | |
6033 | Fsignal (Qquit, Qnil); | |
ee78dc32 | 6034 | |
dfff8a69 | 6035 | return unbind_to (count, file); |
6fc2811b | 6036 | } |
ee78dc32 | 6037 | |
ee78dc32 | 6038 | |
6cf29fe8 JR |
6039 | /* Moving files to the system recycle bin. |
6040 | Used by `move-file-to-trash' instead of the default moving to ~/.Trash */ | |
6041 | DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash, | |
6042 | Ssystem_move_file_to_trash, 1, 1, 0, | |
6043 | doc: /* Move file or directory named FILENAME to the recycle bin. */) | |
5842a27b | 6044 | (Lisp_Object filename) |
6cf29fe8 JR |
6045 | { |
6046 | Lisp_Object handler; | |
6047 | Lisp_Object encoded_file; | |
6048 | Lisp_Object operation; | |
6049 | ||
6050 | operation = Qdelete_file; | |
6051 | if (!NILP (Ffile_directory_p (filename)) | |
6052 | && NILP (Ffile_symlink_p (filename))) | |
6053 | { | |
e9a0aef8 | 6054 | operation = intern ("delete-directory"); |
6cf29fe8 JR |
6055 | filename = Fdirectory_file_name (filename); |
6056 | } | |
6057 | filename = Fexpand_file_name (filename, Qnil); | |
6058 | ||
6059 | handler = Ffind_file_name_handler (filename, operation); | |
6060 | if (!NILP (handler)) | |
6061 | return call2 (handler, operation, filename); | |
6062 | ||
6063 | encoded_file = ENCODE_FILE (filename); | |
6064 | ||
6065 | { | |
6066 | const char * path; | |
6067 | SHFILEOPSTRUCT file_op; | |
6068 | char tmp_path[MAX_PATH + 1]; | |
6069 | ||
6070 | path = map_w32_filename (SDATA (encoded_file), NULL); | |
6071 | ||
6072 | /* On Windows, write permission is required to delete/move files. */ | |
6073 | _chmod (path, 0666); | |
6074 | ||
72af86bd | 6075 | memset (tmp_path, 0, sizeof (tmp_path)); |
6cf29fe8 JR |
6076 | strcpy (tmp_path, path); |
6077 | ||
72af86bd | 6078 | memset (&file_op, 0, sizeof (file_op)); |
6cf29fe8 JR |
6079 | file_op.hwnd = HWND_DESKTOP; |
6080 | file_op.wFunc = FO_DELETE; | |
6081 | file_op.pFrom = tmp_path; | |
6082 | file_op.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_ALLOWUNDO | |
6083 | | FOF_NOERRORUI | FOF_NO_CONNECTED_ELEMENTS; | |
6084 | file_op.fAnyOperationsAborted = FALSE; | |
6085 | ||
6086 | if (SHFileOperation (&file_op) != 0) | |
6087 | report_file_error ("Removing old name", list1 (filename)); | |
6088 | } | |
6089 | return Qnil; | |
6090 | } | |
6091 | ||
6fc2811b | 6092 | \f |
6fc2811b JR |
6093 | /*********************************************************************** |
6094 | w32 specialized functions | |
6095 | ***********************************************************************/ | |
ee78dc32 | 6096 | |
74e1aeec JR |
6097 | DEFUN ("w32-send-sys-command", Fw32_send_sys_command, |
6098 | Sw32_send_sys_command, 1, 2, 0, | |
6099 | doc: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND. | |
52deb19f | 6100 | Some useful values for COMMAND are #xf030 to maximize frame (#xf020 |
d84b082d JR |
6101 | to minimize), #xf120 to restore frame to original size, and #xf100 |
6102 | to activate the menubar for keyboard access. #xf140 activates the | |
74e1aeec JR |
6103 | screen saver if defined. |
6104 | ||
6105 | If optional parameter FRAME is not specified, use selected frame. */) | |
5842a27b | 6106 | (Lisp_Object command, Lisp_Object frame) |
1edf84e7 | 6107 | { |
1edf84e7 GV |
6108 | FRAME_PTR f = check_x_frame (frame); |
6109 | ||
b7826503 | 6110 | CHECK_NUMBER (command); |
1edf84e7 | 6111 | |
ce6059da | 6112 | PostMessage (FRAME_W32_WINDOW (f), WM_SYSCOMMAND, XINT (command), 0); |
1edf84e7 GV |
6113 | |
6114 | return Qnil; | |
6115 | } | |
6116 | ||
55dcfc15 | 6117 | DEFUN ("w32-shell-execute", Fw32_shell_execute, Sw32_shell_execute, 2, 4, 0, |
74e1aeec JR |
6118 | doc: /* Get Windows to perform OPERATION on DOCUMENT. |
6119 | This is a wrapper around the ShellExecute system function, which | |
6120 | invokes the application registered to handle OPERATION for DOCUMENT. | |
74e1aeec | 6121 | |
1dccd454 EZ |
6122 | OPERATION is either nil or a string that names a supported operation. |
6123 | What operations can be used depends on the particular DOCUMENT and its | |
6124 | handler application, but typically it is one of the following common | |
6125 | operations: | |
6126 | ||
6127 | \"open\" - open DOCUMENT, which could be a file, a directory, or an | |
6128 | executable program. If it is an application, that | |
6129 | application is launched in the current buffer's default | |
6130 | directory. Otherwise, the application associated with | |
6131 | DOCUMENT is launched in the buffer's default directory. | |
6132 | \"print\" - print DOCUMENT, which must be a file | |
6133 | \"explore\" - start the Windows Explorer on DOCUMENT | |
6134 | \"edit\" - launch an editor and open DOCUMENT for editing; which | |
6135 | editor is launched depends on the association for the | |
6136 | specified DOCUMENT | |
6137 | \"find\" - initiate search starting from DOCUMENT which must specify | |
6138 | a directory | |
6139 | nil - invoke the default OPERATION, or \"open\" if default is | |
6140 | not defined or unavailable | |
6141 | ||
6142 | DOCUMENT is typically the name of a document file or a URL, but can | |
6143 | also be a program executable to run, or a directory to open in the | |
6144 | Windows Explorer. | |
6145 | ||
02b39a28 JB |
6146 | If DOCUMENT is a program executable, the optional third arg PARAMETERS |
6147 | can be a string containing command line parameters that will be passed | |
6148 | to the program; otherwise, PARAMETERS should be nil or unspecified. | |
1dccd454 | 6149 | |
02b39a28 | 6150 | Optional fourth argument SHOW-FLAG can be used to control how the |
1dccd454 | 6151 | application will be displayed when it is invoked. If SHOW-FLAG is nil |
02b39a28 | 6152 | or unspecified, the application is displayed normally, otherwise it is |
1dccd454 | 6153 | an integer representing a ShowWindow flag: |
74e1aeec JR |
6154 | |
6155 | 0 - start hidden | |
6156 | 1 - start normally | |
6157 | 3 - start maximized | |
6158 | 6 - start minimized */) | |
5842a27b | 6159 | (Lisp_Object operation, Lisp_Object document, Lisp_Object parameters, Lisp_Object show_flag) |
55dcfc15 AI |
6160 | { |
6161 | Lisp_Object current_dir; | |
5cba3209 | 6162 | char *errstr; |
55dcfc15 | 6163 | |
b7826503 | 6164 | CHECK_STRING (document); |
55dcfc15 | 6165 | |
3bc143eb | 6166 | /* Encode filename, current directory and parameters. */ |
55dcfc15 AI |
6167 | current_dir = ENCODE_FILE (current_buffer->directory); |
6168 | document = ENCODE_FILE (document); | |
3bc143eb JR |
6169 | if (STRINGP (parameters)) |
6170 | parameters = ENCODE_SYSTEM (parameters); | |
6171 | ||
55dcfc15 | 6172 | if ((int) ShellExecute (NULL, |
6fc2811b | 6173 | (STRINGP (operation) ? |
d5db4077 KR |
6174 | SDATA (operation) : NULL), |
6175 | SDATA (document), | |
55dcfc15 | 6176 | (STRINGP (parameters) ? |
d5db4077 KR |
6177 | SDATA (parameters) : NULL), |
6178 | SDATA (current_dir), | |
55dcfc15 AI |
6179 | (INTEGERP (show_flag) ? |
6180 | XINT (show_flag) : SW_SHOWDEFAULT)) | |
6181 | > 32) | |
6182 | return Qt; | |
5cba3209 EZ |
6183 | errstr = w32_strerror (0); |
6184 | /* The error string might be encoded in the locale's encoding. */ | |
6185 | if (!NILP (Vlocale_coding_system)) | |
6186 | { | |
6187 | Lisp_Object decoded = | |
6188 | code_convert_string_norecord (make_unibyte_string (errstr, | |
6189 | strlen (errstr)), | |
6190 | Vlocale_coding_system, 0); | |
51b59d79 | 6191 | errstr = SSDATA (decoded); |
5cba3209 EZ |
6192 | } |
6193 | error ("ShellExecute failed: %s", errstr); | |
55dcfc15 AI |
6194 | } |
6195 | ||
ccc2d29c GV |
6196 | /* Lookup virtual keycode from string representing the name of a |
6197 | non-ascii keystroke into the corresponding virtual key, using | |
6198 | lispy_function_keys. */ | |
6199 | static int | |
6200 | lookup_vk_code (char *key) | |
6201 | { | |
6202 | int i; | |
6203 | ||
6204 | for (i = 0; i < 256; i++) | |
bf254037 | 6205 | if (lispy_function_keys[i] |
ccc2d29c GV |
6206 | && strcmp (lispy_function_keys[i], key) == 0) |
6207 | return i; | |
6208 | ||
6209 | return -1; | |
6210 | } | |
6211 | ||
6212 | /* Convert a one-element vector style key sequence to a hot key | |
6213 | definition. */ | |
2ba49441 | 6214 | static Lisp_Object |
b56ceb92 | 6215 | w32_parse_hot_key (Lisp_Object key) |
ccc2d29c GV |
6216 | { |
6217 | /* Copied from Fdefine_key and store_in_keymap. */ | |
6218 | register Lisp_Object c; | |
6219 | int vk_code; | |
6220 | int lisp_modifiers; | |
6221 | int w32_modifiers; | |
6222 | struct gcpro gcpro1; | |
6223 | ||
b7826503 | 6224 | CHECK_VECTOR (key); |
ccc2d29c GV |
6225 | |
6226 | if (XFASTINT (Flength (key)) != 1) | |
6227 | return Qnil; | |
6228 | ||
6229 | GCPRO1 (key); | |
6230 | ||
6231 | c = Faref (key, make_number (0)); | |
6232 | ||
6233 | if (CONSP (c) && lucid_event_type_list_p (c)) | |
6234 | c = Fevent_convert_list (c); | |
6235 | ||
6236 | UNGCPRO; | |
6237 | ||
6238 | if (! INTEGERP (c) && ! SYMBOLP (c)) | |
6239 | error ("Key definition is invalid"); | |
6240 | ||
6241 | /* Work out the base key and the modifiers. */ | |
6242 | if (SYMBOLP (c)) | |
6243 | { | |
6244 | c = parse_modifiers (c); | |
2ba49441 | 6245 | lisp_modifiers = XINT (Fcar (Fcdr (c))); |
ccc2d29c GV |
6246 | c = Fcar (c); |
6247 | if (!SYMBOLP (c)) | |
6248 | abort (); | |
d5db4077 | 6249 | vk_code = lookup_vk_code (SDATA (SYMBOL_NAME (c))); |
ccc2d29c GV |
6250 | } |
6251 | else if (INTEGERP (c)) | |
6252 | { | |
6253 | lisp_modifiers = XINT (c) & ~CHARACTERBITS; | |
6254 | /* Many ascii characters are their own virtual key code. */ | |
6255 | vk_code = XINT (c) & CHARACTERBITS; | |
6256 | } | |
6257 | ||
6258 | if (vk_code < 0 || vk_code > 255) | |
6259 | return Qnil; | |
6260 | ||
6261 | if ((lisp_modifiers & meta_modifier) != 0 | |
6262 | && !NILP (Vw32_alt_is_meta)) | |
6263 | lisp_modifiers |= alt_modifier; | |
6264 | ||
71eab8d1 AI |
6265 | /* Supply defs missing from mingw32. */ |
6266 | #ifndef MOD_ALT | |
6267 | #define MOD_ALT 0x0001 | |
6268 | #define MOD_CONTROL 0x0002 | |
6269 | #define MOD_SHIFT 0x0004 | |
6270 | #define MOD_WIN 0x0008 | |
6271 | #endif | |
6272 | ||
ccc2d29c GV |
6273 | /* Convert lisp modifiers to Windows hot-key form. */ |
6274 | w32_modifiers = (lisp_modifiers & hyper_modifier) ? MOD_WIN : 0; | |
6275 | w32_modifiers |= (lisp_modifiers & alt_modifier) ? MOD_ALT : 0; | |
6276 | w32_modifiers |= (lisp_modifiers & ctrl_modifier) ? MOD_CONTROL : 0; | |
6277 | w32_modifiers |= (lisp_modifiers & shift_modifier) ? MOD_SHIFT : 0; | |
6278 | ||
6279 | return HOTKEY (vk_code, w32_modifiers); | |
6280 | } | |
6281 | ||
74e1aeec JR |
6282 | DEFUN ("w32-register-hot-key", Fw32_register_hot_key, |
6283 | Sw32_register_hot_key, 1, 1, 0, | |
6284 | doc: /* Register KEY as a hot-key combination. | |
6285 | Certain key combinations like Alt-Tab are reserved for system use on | |
6286 | Windows, and therefore are normally intercepted by the system. However, | |
6287 | most of these key combinations can be received by registering them as | |
6288 | hot-keys, overriding their special meaning. | |
6289 | ||
6290 | KEY must be a one element key definition in vector form that would be | |
6291 | acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta | |
6292 | modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper | |
6293 | is always interpreted as the Windows modifier keys. | |
6294 | ||
6295 | The return value is the hotkey-id if registered, otherwise nil. */) | |
5842a27b | 6296 | (Lisp_Object key) |
ccc2d29c GV |
6297 | { |
6298 | key = w32_parse_hot_key (key); | |
6299 | ||
fb053a1f | 6300 | if (!NILP (key) && NILP (Fmemq (key, w32_grabbed_keys))) |
ccc2d29c GV |
6301 | { |
6302 | /* Reuse an empty slot if possible. */ | |
6303 | Lisp_Object item = Fmemq (Qnil, w32_grabbed_keys); | |
6304 | ||
6305 | /* Safe to add new key to list, even if we have focus. */ | |
6306 | if (NILP (item)) | |
6307 | w32_grabbed_keys = Fcons (key, w32_grabbed_keys); | |
6308 | else | |
f3fbd155 | 6309 | XSETCAR (item, key); |
ccc2d29c GV |
6310 | |
6311 | /* Notify input thread about new hot-key definition, so that it | |
6312 | takes effect without needing to switch focus. */ | |
2ba49441 JR |
6313 | #ifdef USE_LISP_UNION_TYPE |
6314 | PostThreadMessage (dwWindowsThreadId, WM_EMACS_REGISTER_HOT_KEY, | |
6315 | (WPARAM) key.i, 0); | |
6316 | #else | |
ccc2d29c GV |
6317 | PostThreadMessage (dwWindowsThreadId, WM_EMACS_REGISTER_HOT_KEY, |
6318 | (WPARAM) key, 0); | |
2ba49441 | 6319 | #endif |
ccc2d29c GV |
6320 | } |
6321 | ||
6322 | return key; | |
6323 | } | |
6324 | ||
74e1aeec JR |
6325 | DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key, |
6326 | Sw32_unregister_hot_key, 1, 1, 0, | |
52deb19f | 6327 | doc: /* Unregister KEY as a hot-key combination. */) |
5842a27b | 6328 | (Lisp_Object key) |
ccc2d29c GV |
6329 | { |
6330 | Lisp_Object item; | |
6331 | ||
6332 | if (!INTEGERP (key)) | |
6333 | key = w32_parse_hot_key (key); | |
6334 | ||
6335 | item = Fmemq (key, w32_grabbed_keys); | |
6336 | ||
6337 | if (!NILP (item)) | |
6338 | { | |
6339 | /* Notify input thread about hot-key definition being removed, so | |
6340 | that it takes effect without needing focus switch. */ | |
2ba49441 JR |
6341 | #ifdef USE_LISP_UNION_TYPE |
6342 | if (PostThreadMessage (dwWindowsThreadId, WM_EMACS_UNREGISTER_HOT_KEY, | |
6343 | (WPARAM) XINT (XCAR (item)), (LPARAM) item.i)) | |
6344 | #else | |
ccc2d29c GV |
6345 | if (PostThreadMessage (dwWindowsThreadId, WM_EMACS_UNREGISTER_HOT_KEY, |
6346 | (WPARAM) XINT (XCAR (item)), (LPARAM) item)) | |
2ba49441 | 6347 | #endif |
ccc2d29c GV |
6348 | { |
6349 | MSG msg; | |
6350 | GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE); | |
6351 | } | |
6352 | return Qt; | |
6353 | } | |
6354 | return Qnil; | |
6355 | } | |
6356 | ||
74e1aeec JR |
6357 | DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys, |
6358 | Sw32_registered_hot_keys, 0, 0, 0, | |
6359 | doc: /* Return list of registered hot-key IDs. */) | |
5842a27b | 6360 | (void) |
ccc2d29c | 6361 | { |
74084731 | 6362 | return Fdelq (Qnil, Fcopy_sequence (w32_grabbed_keys)); |
ccc2d29c GV |
6363 | } |
6364 | ||
74e1aeec JR |
6365 | DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key, |
6366 | Sw32_reconstruct_hot_key, 1, 1, 0, | |
52deb19f JB |
6367 | doc: /* Convert hot-key ID to a lisp key combination. |
6368 | usage: (w32-reconstruct-hot-key ID) */) | |
5842a27b | 6369 | (Lisp_Object hotkeyid) |
ccc2d29c GV |
6370 | { |
6371 | int vk_code, w32_modifiers; | |
6372 | Lisp_Object key; | |
6373 | ||
b7826503 | 6374 | CHECK_NUMBER (hotkeyid); |
ccc2d29c GV |
6375 | |
6376 | vk_code = HOTKEY_VK_CODE (hotkeyid); | |
6377 | w32_modifiers = HOTKEY_MODIFIERS (hotkeyid); | |
6378 | ||
bf254037 | 6379 | if (vk_code < 256 && lispy_function_keys[vk_code]) |
ccc2d29c GV |
6380 | key = intern (lispy_function_keys[vk_code]); |
6381 | else | |
6382 | key = make_number (vk_code); | |
6383 | ||
6384 | key = Fcons (key, Qnil); | |
6385 | if (w32_modifiers & MOD_SHIFT) | |
3ef68e6b | 6386 | key = Fcons (Qshift, key); |
ccc2d29c | 6387 | if (w32_modifiers & MOD_CONTROL) |
3ef68e6b | 6388 | key = Fcons (Qctrl, key); |
ccc2d29c | 6389 | if (w32_modifiers & MOD_ALT) |
3ef68e6b | 6390 | key = Fcons (NILP (Vw32_alt_is_meta) ? Qalt : Qmeta, key); |
ccc2d29c | 6391 | if (w32_modifiers & MOD_WIN) |
3ef68e6b | 6392 | key = Fcons (Qhyper, key); |
ccc2d29c GV |
6393 | |
6394 | return key; | |
6395 | } | |
adcc3809 | 6396 | |
74e1aeec JR |
6397 | DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key, |
6398 | Sw32_toggle_lock_key, 1, 2, 0, | |
6399 | doc: /* Toggle the state of the lock key KEY. | |
6400 | KEY can be `capslock', `kp-numlock', or `scroll'. | |
6401 | If the optional parameter NEW-STATE is a number, then the state of KEY | |
6402 | is set to off if the low bit of NEW-STATE is zero, otherwise on. */) | |
5842a27b | 6403 | (Lisp_Object key, Lisp_Object new_state) |
adcc3809 GV |
6404 | { |
6405 | int vk_code; | |
adcc3809 GV |
6406 | |
6407 | if (EQ (key, intern ("capslock"))) | |
6408 | vk_code = VK_CAPITAL; | |
6409 | else if (EQ (key, intern ("kp-numlock"))) | |
6410 | vk_code = VK_NUMLOCK; | |
6411 | else if (EQ (key, intern ("scroll"))) | |
6412 | vk_code = VK_SCROLL; | |
6413 | else | |
6414 | return Qnil; | |
6415 | ||
6416 | if (!dwWindowsThreadId) | |
6417 | return make_number (w32_console_toggle_lock_key (vk_code, new_state)); | |
6418 | ||
2ba49441 JR |
6419 | #ifdef USE_LISP_UNION_TYPE |
6420 | if (PostThreadMessage (dwWindowsThreadId, WM_EMACS_TOGGLE_LOCK_KEY, | |
6421 | (WPARAM) vk_code, (LPARAM) new_state.i)) | |
6422 | #else | |
adcc3809 GV |
6423 | if (PostThreadMessage (dwWindowsThreadId, WM_EMACS_TOGGLE_LOCK_KEY, |
6424 | (WPARAM) vk_code, (LPARAM) new_state)) | |
2ba49441 | 6425 | #endif |
adcc3809 GV |
6426 | { |
6427 | MSG msg; | |
6428 | GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE); | |
6429 | return make_number (msg.wParam); | |
6430 | } | |
6431 | return Qnil; | |
6432 | } | |
a01763cb EZ |
6433 | |
6434 | DEFUN ("w32-window-exists-p", Fw32_window_exists_p, Sw32_window_exists_p, | |
6435 | 2, 2, 0, | |
6436 | doc: /* Return non-nil if a window exists with the specified CLASS and NAME. | |
6437 | ||
6438 | This is a direct interface to the Windows API FindWindow function. */) | |
5842a27b | 6439 | (Lisp_Object class, Lisp_Object name) |
a01763cb EZ |
6440 | { |
6441 | HWND hnd; | |
6442 | ||
6443 | if (!NILP (class)) | |
6444 | CHECK_STRING (class); | |
6445 | if (!NILP (name)) | |
6446 | CHECK_STRING (name); | |
6447 | ||
6448 | hnd = FindWindow (STRINGP (class) ? ((LPCTSTR) SDATA (class)) : NULL, | |
6449 | STRINGP (name) ? ((LPCTSTR) SDATA (name)) : NULL); | |
6450 | if (!hnd) | |
6451 | return Qnil; | |
6452 | return Qt; | |
6453 | } | |
6454 | ||
2c2279c6 JR |
6455 | DEFUN ("w32-battery-status", Fw32_battery_status, Sw32_battery_status, 0, 0, 0, |
6456 | doc: /* Get power status information from Windows system. | |
6457 | ||
6458 | The following %-sequences are provided: | |
6459 | %L AC line status (verbose) | |
6460 | %B Battery status (verbose) | |
6461 | %b Battery status, empty means high, `-' means low, | |
6462 | `!' means critical, and `+' means charging | |
6463 | %p Battery load percentage | |
6464 | %s Remaining time (to charge or discharge) in seconds | |
6465 | %m Remaining time (to charge or discharge) in minutes | |
6466 | %h Remaining time (to charge or discharge) in hours | |
6467 | %t Remaining time (to charge or discharge) in the form `h:min' */) | |
5842a27b | 6468 | (void) |
2c2279c6 JR |
6469 | { |
6470 | Lisp_Object status = Qnil; | |
6471 | ||
6472 | SYSTEM_POWER_STATUS system_status; | |
6473 | if (GetSystemPowerStatus (&system_status)) | |
6474 | { | |
6475 | Lisp_Object line_status, battery_status, battery_status_symbol; | |
6476 | Lisp_Object load_percentage, seconds, minutes, hours, remain; | |
6477 | Lisp_Object sequences[8]; | |
6478 | ||
6479 | long seconds_left = (long) system_status.BatteryLifeTime; | |
6480 | ||
6481 | if (system_status.ACLineStatus == 0) | |
6482 | line_status = build_string ("off-line"); | |
6483 | else if (system_status.ACLineStatus == 1) | |
6484 | line_status = build_string ("on-line"); | |
6485 | else | |
6486 | line_status = build_string ("N/A"); | |
6487 | ||
6488 | if (system_status.BatteryFlag & 128) | |
6489 | { | |
6490 | battery_status = build_string ("N/A"); | |
fff4e459 | 6491 | battery_status_symbol = empty_unibyte_string; |
2c2279c6 JR |
6492 | } |
6493 | else if (system_status.BatteryFlag & 8) | |
6494 | { | |
6495 | battery_status = build_string ("charging"); | |
6496 | battery_status_symbol = build_string ("+"); | |
6497 | if (system_status.BatteryFullLifeTime != -1L) | |
6498 | seconds_left = system_status.BatteryFullLifeTime - seconds_left; | |
6499 | } | |
6500 | else if (system_status.BatteryFlag & 4) | |
6501 | { | |
6502 | battery_status = build_string ("critical"); | |
6503 | battery_status_symbol = build_string ("!"); | |
6504 | } | |
6505 | else if (system_status.BatteryFlag & 2) | |
6506 | { | |
6507 | battery_status = build_string ("low"); | |
6508 | battery_status_symbol = build_string ("-"); | |
6509 | } | |
6510 | else if (system_status.BatteryFlag & 1) | |
6511 | { | |
6512 | battery_status = build_string ("high"); | |
fff4e459 | 6513 | battery_status_symbol = empty_unibyte_string; |
2c2279c6 JR |
6514 | } |
6515 | else | |
6516 | { | |
6517 | battery_status = build_string ("medium"); | |
fff4e459 | 6518 | battery_status_symbol = empty_unibyte_string; |
2c2279c6 JR |
6519 | } |
6520 | ||
6521 | if (system_status.BatteryLifePercent > 100) | |
6522 | load_percentage = build_string ("N/A"); | |
6523 | else | |
6524 | { | |
6525 | char buffer[16]; | |
6526 | _snprintf (buffer, 16, "%d", system_status.BatteryLifePercent); | |
6527 | load_percentage = build_string (buffer); | |
6528 | } | |
6529 | ||
6530 | if (seconds_left < 0) | |
6531 | seconds = minutes = hours = remain = build_string ("N/A"); | |
6532 | else | |
6533 | { | |
6534 | long m; | |
6535 | float h; | |
6536 | char buffer[16]; | |
6537 | _snprintf (buffer, 16, "%ld", seconds_left); | |
6538 | seconds = build_string (buffer); | |
6539 | ||
6540 | m = seconds_left / 60; | |
e9184ccb | 6541 | _snprintf (buffer, 16, "%ld", m); |
2c2279c6 JR |
6542 | minutes = build_string (buffer); |
6543 | ||
6544 | h = seconds_left / 3600.0; | |
6545 | _snprintf (buffer, 16, "%3.1f", h); | |
6546 | hours = build_string (buffer); | |
6547 | ||
e9184ccb | 6548 | _snprintf (buffer, 16, "%ld:%02ld", m / 60, m % 60); |
2c2279c6 JR |
6549 | remain = build_string (buffer); |
6550 | } | |
6551 | sequences[0] = Fcons (make_number ('L'), line_status); | |
6552 | sequences[1] = Fcons (make_number ('B'), battery_status); | |
6553 | sequences[2] = Fcons (make_number ('b'), battery_status_symbol); | |
6554 | sequences[3] = Fcons (make_number ('p'), load_percentage); | |
6555 | sequences[4] = Fcons (make_number ('s'), seconds); | |
6556 | sequences[5] = Fcons (make_number ('m'), minutes); | |
6557 | sequences[6] = Fcons (make_number ('h'), hours); | |
6558 | sequences[7] = Fcons (make_number ('t'), remain); | |
6559 | ||
6560 | status = Flist (8, sequences); | |
6561 | } | |
6562 | return status; | |
6563 | } | |
a01763cb | 6564 | |
ee78dc32 | 6565 | \f |
2254bcde | 6566 | DEFUN ("file-system-info", Ffile_system_info, Sfile_system_info, 1, 1, 0, |
74e1aeec JR |
6567 | doc: /* Return storage information about the file system FILENAME is on. |
6568 | Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total | |
6569 | storage of the file system, FREE is the free storage, and AVAIL is the | |
6570 | storage available to a non-superuser. All 3 numbers are in bytes. | |
6571 | If the underlying system call fails, value is nil. */) | |
5842a27b | 6572 | (Lisp_Object filename) |
2254bcde AI |
6573 | { |
6574 | Lisp_Object encoded, value; | |
6575 | ||
b7826503 | 6576 | CHECK_STRING (filename); |
2254bcde AI |
6577 | filename = Fexpand_file_name (filename, Qnil); |
6578 | encoded = ENCODE_FILE (filename); | |
6579 | ||
6580 | value = Qnil; | |
6581 | ||
6582 | /* Determining the required information on Windows turns out, sadly, | |
6583 | to be more involved than one would hope. The original Win32 api | |
6584 | call for this will return bogus information on some systems, but we | |
6585 | must dynamically probe for the replacement api, since that was | |
6586 | added rather late on. */ | |
6587 | { | |
6588 | HMODULE hKernel = GetModuleHandle ("kernel32"); | |
6589 | BOOL (*pfn_GetDiskFreeSpaceEx) | |
6590 | (char *, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER) | |
6591 | = (void *) GetProcAddress (hKernel, "GetDiskFreeSpaceEx"); | |
6592 | ||
6593 | /* On Windows, we may need to specify the root directory of the | |
6594 | volume holding FILENAME. */ | |
6595 | char rootname[MAX_PATH]; | |
d5db4077 | 6596 | char *name = SDATA (encoded); |
2254bcde AI |
6597 | |
6598 | /* find the root name of the volume if given */ | |
6599 | if (isalpha (name[0]) && name[1] == ':') | |
6600 | { | |
6601 | rootname[0] = name[0]; | |
6602 | rootname[1] = name[1]; | |
6603 | rootname[2] = '\\'; | |
6604 | rootname[3] = 0; | |
6605 | } | |
6606 | else if (IS_DIRECTORY_SEP (name[0]) && IS_DIRECTORY_SEP (name[1])) | |
6607 | { | |
6608 | char *str = rootname; | |
6609 | int slashes = 4; | |
6610 | do | |
6611 | { | |
6612 | if (IS_DIRECTORY_SEP (*name) && --slashes == 0) | |
6613 | break; | |
6614 | *str++ = *name++; | |
6615 | } | |
6616 | while ( *name ); | |
6617 | ||
6618 | *str++ = '\\'; | |
6619 | *str = 0; | |
6620 | } | |
6621 | ||
6622 | if (pfn_GetDiskFreeSpaceEx) | |
6623 | { | |
ac849ba4 JR |
6624 | /* Unsigned large integers cannot be cast to double, so |
6625 | use signed ones instead. */ | |
2254bcde AI |
6626 | LARGE_INTEGER availbytes; |
6627 | LARGE_INTEGER freebytes; | |
6628 | LARGE_INTEGER totalbytes; | |
6629 | ||
74084731 JB |
6630 | if (pfn_GetDiskFreeSpaceEx (rootname, |
6631 | (ULARGE_INTEGER *)&availbytes, | |
6632 | (ULARGE_INTEGER *)&totalbytes, | |
6633 | (ULARGE_INTEGER *)&freebytes)) | |
2254bcde AI |
6634 | value = list3 (make_float ((double) totalbytes.QuadPart), |
6635 | make_float ((double) freebytes.QuadPart), | |
6636 | make_float ((double) availbytes.QuadPart)); | |
6637 | } | |
6638 | else | |
6639 | { | |
6640 | DWORD sectors_per_cluster; | |
6641 | DWORD bytes_per_sector; | |
6642 | DWORD free_clusters; | |
6643 | DWORD total_clusters; | |
6644 | ||
74084731 JB |
6645 | if (GetDiskFreeSpace (rootname, |
6646 | §ors_per_cluster, | |
6647 | &bytes_per_sector, | |
6648 | &free_clusters, | |
6649 | &total_clusters)) | |
2254bcde AI |
6650 | value = list3 (make_float ((double) total_clusters |
6651 | * sectors_per_cluster * bytes_per_sector), | |
6652 | make_float ((double) free_clusters | |
6653 | * sectors_per_cluster * bytes_per_sector), | |
6654 | make_float ((double) free_clusters | |
6655 | * sectors_per_cluster * bytes_per_sector)); | |
6656 | } | |
6657 | } | |
6658 | ||
6659 | return value; | |
6660 | } | |
6661 | \f | |
6b61353c KH |
6662 | DEFUN ("default-printer-name", Fdefault_printer_name, Sdefault_printer_name, |
6663 | 0, 0, 0, doc: /* Return the name of Windows default printer device. */) | |
5842a27b | 6664 | (void) |
6b61353c KH |
6665 | { |
6666 | static char pname_buf[256]; | |
6667 | int err; | |
6668 | HANDLE hPrn; | |
6669 | PRINTER_INFO_2 *ppi2 = NULL; | |
6670 | DWORD dwNeeded = 0, dwReturned = 0; | |
6671 | ||
6672 | /* Retrieve the default string from Win.ini (the registry). | |
6673 | * String will be in form "printername,drivername,portname". | |
6674 | * This is the most portable way to get the default printer. */ | |
6675 | if (GetProfileString ("windows", "device", ",,", pname_buf, sizeof (pname_buf)) <= 0) | |
6676 | return Qnil; | |
6677 | /* printername precedes first "," character */ | |
6678 | strtok (pname_buf, ","); | |
6679 | /* We want to know more than the printer name */ | |
6680 | if (!OpenPrinter (pname_buf, &hPrn, NULL)) | |
6681 | return Qnil; | |
6682 | GetPrinter (hPrn, 2, NULL, 0, &dwNeeded); | |
6683 | if (dwNeeded == 0) | |
6684 | { | |
6685 | ClosePrinter (hPrn); | |
6686 | return Qnil; | |
6687 | } | |
6688 | /* Allocate memory for the PRINTER_INFO_2 struct */ | |
6689 | ppi2 = (PRINTER_INFO_2 *) xmalloc (dwNeeded); | |
6690 | if (!ppi2) | |
6691 | { | |
6692 | ClosePrinter (hPrn); | |
6693 | return Qnil; | |
6694 | } | |
74084731 | 6695 | /* Call GetPrinter again with big enouth memory block */ |
6b61353c KH |
6696 | err = GetPrinter (hPrn, 2, (LPBYTE)ppi2, dwNeeded, &dwReturned); |
6697 | ClosePrinter (hPrn); | |
6698 | if (!err) | |
6699 | { | |
74084731 | 6700 | xfree (ppi2); |
6b61353c KH |
6701 | return Qnil; |
6702 | } | |
6703 | ||
6704 | if (ppi2) | |
6705 | { | |
6706 | if (ppi2->Attributes & PRINTER_ATTRIBUTE_SHARED && ppi2->pServerName) | |
6707 | { | |
6708 | /* a remote printer */ | |
6709 | if (*ppi2->pServerName == '\\') | |
74084731 | 6710 | _snprintf (pname_buf, sizeof (pname_buf), "%s\\%s", ppi2->pServerName, |
02b39a28 | 6711 | ppi2->pShareName); |
6b61353c | 6712 | else |
74084731 | 6713 | _snprintf (pname_buf, sizeof (pname_buf), "\\\\%s\\%s", ppi2->pServerName, |
02b39a28 | 6714 | ppi2->pShareName); |
6b61353c KH |
6715 | pname_buf[sizeof (pname_buf) - 1] = '\0'; |
6716 | } | |
6717 | else | |
6718 | { | |
6719 | /* a local printer */ | |
74084731 | 6720 | strncpy (pname_buf, ppi2->pPortName, sizeof (pname_buf)); |
6b61353c KH |
6721 | pname_buf[sizeof (pname_buf) - 1] = '\0'; |
6722 | /* `pPortName' can include several ports, delimited by ','. | |
6723 | * we only use the first one. */ | |
74084731 | 6724 | strtok (pname_buf, ","); |
6b61353c | 6725 | } |
74084731 | 6726 | xfree (ppi2); |
6b61353c KH |
6727 | } |
6728 | ||
6729 | return build_string (pname_buf); | |
6730 | } | |
6731 | \f | |
0e3fcdef JR |
6732 | /*********************************************************************** |
6733 | Initialization | |
6734 | ***********************************************************************/ | |
6735 | ||
52deb19f | 6736 | /* Keep this list in the same order as frame_parms in frame.c. |
6d906347 KS |
6737 | Use 0 for unsupported frame parameters. */ |
6738 | ||
6739 | frame_parm_handler w32_frame_parm_handlers[] = | |
6740 | { | |
6741 | x_set_autoraise, | |
6742 | x_set_autolower, | |
6743 | x_set_background_color, | |
6744 | x_set_border_color, | |
6745 | x_set_border_width, | |
6746 | x_set_cursor_color, | |
6747 | x_set_cursor_type, | |
6748 | x_set_font, | |
6749 | x_set_foreground_color, | |
6750 | x_set_icon_name, | |
6751 | x_set_icon_type, | |
6752 | x_set_internal_border_width, | |
6753 | x_set_menu_bar_lines, | |
6754 | x_set_mouse_color, | |
6755 | x_explicitly_set_name, | |
6756 | x_set_scroll_bar_width, | |
6757 | x_set_title, | |
6758 | x_set_unsplittable, | |
6759 | x_set_vertical_scroll_bars, | |
6760 | x_set_visibility, | |
6761 | x_set_tool_bar_lines, | |
6762 | 0, /* x_set_scroll_bar_foreground, */ | |
6763 | 0, /* x_set_scroll_bar_background, */ | |
6764 | x_set_screen_gamma, | |
6765 | x_set_line_spacing, | |
6766 | x_set_fringe_width, | |
6767 | x_set_fringe_width, | |
6768 | 0, /* x_set_wait_for_wm, */ | |
6769 | x_set_fullscreen, | |
a2979e8e | 6770 | x_set_font_backend, |
cad9ef74 JD |
6771 | x_set_alpha, |
6772 | 0, /* x_set_sticky */ | |
0cc56427 | 6773 | 0, /* x_set_tool_bar_position */ |
6d906347 KS |
6774 | }; |
6775 | ||
0e3fcdef | 6776 | void |
b56ceb92 | 6777 | syms_of_w32fns (void) |
ee78dc32 | 6778 | { |
afc390dc JR |
6779 | globals_of_w32fns (); |
6780 | /* This is zero if not using MS-Windows. */ | |
1edf84e7 | 6781 | w32_in_use = 0; |
9eb16b62 JR |
6782 | track_mouse_window = NULL; |
6783 | ||
d285988b JR |
6784 | w32_visible_system_caret_hwnd = NULL; |
6785 | ||
4f5b288c JR |
6786 | DEFSYM (Qnone, "none"); |
6787 | DEFSYM (Qsuppress_icon, "suppress-icon"); | |
6788 | DEFSYM (Qundefined_color, "undefined-color"); | |
6789 | DEFSYM (Qcancel_timer, "cancel-timer"); | |
6790 | DEFSYM (Qhyper, "hyper"); | |
6791 | DEFSYM (Qsuper, "super"); | |
6792 | DEFSYM (Qmeta, "meta"); | |
6793 | DEFSYM (Qalt, "alt"); | |
6794 | DEFSYM (Qctrl, "ctrl"); | |
6795 | DEFSYM (Qcontrol, "control"); | |
6796 | DEFSYM (Qshift, "shift"); | |
27129af9 | 6797 | DEFSYM (Qfont_param, "font-parameter"); |
f7b9d4d1 | 6798 | /* This is the end of symbol initialization. */ |
adcc3809 | 6799 | |
6fc2811b JR |
6800 | /* Text property `display' should be nonsticky by default. */ |
6801 | Vtext_property_default_nonsticky | |
6802 | = Fcons (Fcons (Qdisplay, Qt), Vtext_property_default_nonsticky); | |
6803 | ||
6804 | ||
ee78dc32 | 6805 | Fput (Qundefined_color, Qerror_conditions, |
d67b4f80 | 6806 | pure_cons (Qundefined_color, pure_cons (Qerror, Qnil))); |
ee78dc32 | 6807 | Fput (Qundefined_color, Qerror_message, |
d67b4f80 | 6808 | make_pure_c_string ("Undefined color")); |
ee78dc32 | 6809 | |
ccc2d29c GV |
6810 | staticpro (&w32_grabbed_keys); |
6811 | w32_grabbed_keys = Qnil; | |
6812 | ||
29208e82 | 6813 | DEFVAR_LISP ("w32-color-map", Vw32_color_map, |
52deb19f | 6814 | doc: /* An array of color name mappings for Windows. */); |
fbd6baed | 6815 | Vw32_color_map = Qnil; |
ee78dc32 | 6816 | |
29208e82 | 6817 | DEFVAR_LISP ("w32-pass-alt-to-system", Vw32_pass_alt_to_system, |
1133f8e7 EZ |
6818 | doc: /* Non-nil if Alt key presses are passed on to Windows. |
6819 | When non-nil, for example, Alt pressed and released and then space will | |
6820 | open the System menu. When nil, Emacs processes the Alt key events, and | |
6821 | then silently swallows them. */); | |
fbd6baed | 6822 | Vw32_pass_alt_to_system = Qnil; |
da36a4d6 | 6823 | |
29208e82 | 6824 | DEFVAR_LISP ("w32-alt-is-meta", Vw32_alt_is_meta, |
1133f8e7 EZ |
6825 | doc: /* Non-nil if the Alt key is to be considered the same as the META key. |
6826 | When nil, Emacs will translate the Alt key to the ALT modifier, not to META. */); | |
fbd6baed | 6827 | Vw32_alt_is_meta = Qt; |
8c205c63 | 6828 | |
29208e82 | 6829 | DEFVAR_INT ("w32-quit-key", w32_quit_key, |
2ba49441 JR |
6830 | doc: /* If non-zero, the virtual key code for an alternative quit key. */); |
6831 | w32_quit_key = 0; | |
7d081355 | 6832 | |
7d0393cf | 6833 | DEFVAR_LISP ("w32-pass-lwindow-to-system", |
29208e82 | 6834 | Vw32_pass_lwindow_to_system, |
1133f8e7 EZ |
6835 | doc: /* If non-nil, the left \"Windows\" key is passed on to Windows. |
6836 | ||
6837 | When non-nil, the Start menu is opened by tapping the key. | |
6838 | If you set this to nil, the left \"Windows\" key is processed by Emacs | |
6839 | according to the value of `w32-lwindow-modifier', which see. | |
6840 | ||
6841 | Note that some combinations of the left \"Windows\" key with other keys are | |
6842 | caught by Windows at low level, and so binding them in Emacs will have no | |
6843 | effect. For example, <lwindow>-r always pops up the Windows Run dialog, | |
6844 | <lwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see | |
6845 | the doc string of `w32-phantom-key-code'. */); | |
ccc2d29c GV |
6846 | Vw32_pass_lwindow_to_system = Qt; |
6847 | ||
7d0393cf | 6848 | DEFVAR_LISP ("w32-pass-rwindow-to-system", |
29208e82 | 6849 | Vw32_pass_rwindow_to_system, |
1133f8e7 EZ |
6850 | doc: /* If non-nil, the right \"Windows\" key is passed on to Windows. |
6851 | ||
6852 | When non-nil, the Start menu is opened by tapping the key. | |
6853 | If you set this to nil, the right \"Windows\" key is processed by Emacs | |
6854 | according to the value of `w32-rwindow-modifier', which see. | |
6855 | ||
6856 | Note that some combinations of the right \"Windows\" key with other keys are | |
6857 | caught by Windows at low level, and so binding them in Emacs will have no | |
6858 | effect. For example, <rwindow>-r always pops up the Windows Run dialog, | |
6859 | <rwindow>-<Pause> pops up the "System Properties" dialog, etc. However, see | |
6860 | the doc string of `w32-phantom-key-code'. */); | |
ccc2d29c GV |
6861 | Vw32_pass_rwindow_to_system = Qt; |
6862 | ||
2ba49441 | 6863 | DEFVAR_LISP ("w32-phantom-key-code", |
29208e82 | 6864 | Vw32_phantom_key_code, |
2ba49441 | 6865 | doc: /* Virtual key code used to generate \"phantom\" key presses. |
74e1aeec JR |
6866 | Value is a number between 0 and 255. |
6867 | ||
6868 | Phantom key presses are generated in order to stop the system from | |
6869 | acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or | |
6870 | `w32-pass-rwindow-to-system' is nil. */); | |
ce6059da AI |
6871 | /* Although 255 is technically not a valid key code, it works and |
6872 | means that this hack won't interfere with any real key code. */ | |
2ba49441 | 6873 | XSETINT (Vw32_phantom_key_code, 255); |
adcc3809 | 6874 | |
7d0393cf | 6875 | DEFVAR_LISP ("w32-enable-num-lock", |
29208e82 | 6876 | Vw32_enable_num_lock, |
1133f8e7 EZ |
6877 | doc: /* If non-nil, the Num Lock key acts normally. |
6878 | Set to nil to handle Num Lock as the `kp-numlock' key. */); | |
ccc2d29c GV |
6879 | Vw32_enable_num_lock = Qt; |
6880 | ||
7d0393cf | 6881 | DEFVAR_LISP ("w32-enable-caps-lock", |
29208e82 | 6882 | Vw32_enable_caps_lock, |
1133f8e7 EZ |
6883 | doc: /* If non-nil, the Caps Lock key acts normally. |
6884 | Set to nil to handle Caps Lock as the `capslock' key. */); | |
ccc2d29c GV |
6885 | Vw32_enable_caps_lock = Qt; |
6886 | ||
6887 | DEFVAR_LISP ("w32-scroll-lock-modifier", | |
29208e82 | 6888 | Vw32_scroll_lock_modifier, |
1133f8e7 | 6889 | doc: /* Modifier to use for the Scroll Lock ON state. |
74e1aeec | 6890 | The value can be hyper, super, meta, alt, control or shift for the |
1133f8e7 EZ |
6891 | respective modifier, or nil to handle Scroll Lock as the `scroll' key. |
6892 | Any other value will cause the Scroll Lock key to be ignored. */); | |
47e0e0e4 | 6893 | Vw32_scroll_lock_modifier = Qnil; |
ccc2d29c GV |
6894 | |
6895 | DEFVAR_LISP ("w32-lwindow-modifier", | |
29208e82 | 6896 | Vw32_lwindow_modifier, |
74e1aeec JR |
6897 | doc: /* Modifier to use for the left \"Windows\" key. |
6898 | The value can be hyper, super, meta, alt, control or shift for the | |
1133f8e7 | 6899 | respective modifier, or nil to appear as the `lwindow' key. |
74e1aeec | 6900 | Any other value will cause the key to be ignored. */); |
ccc2d29c GV |
6901 | Vw32_lwindow_modifier = Qnil; |
6902 | ||
6903 | DEFVAR_LISP ("w32-rwindow-modifier", | |
29208e82 | 6904 | Vw32_rwindow_modifier, |
74e1aeec JR |
6905 | doc: /* Modifier to use for the right \"Windows\" key. |
6906 | The value can be hyper, super, meta, alt, control or shift for the | |
1133f8e7 | 6907 | respective modifier, or nil to appear as the `rwindow' key. |
74e1aeec | 6908 | Any other value will cause the key to be ignored. */); |
ccc2d29c GV |
6909 | Vw32_rwindow_modifier = Qnil; |
6910 | ||
6911 | DEFVAR_LISP ("w32-apps-modifier", | |
29208e82 | 6912 | Vw32_apps_modifier, |
74e1aeec JR |
6913 | doc: /* Modifier to use for the \"Apps\" key. |
6914 | The value can be hyper, super, meta, alt, control or shift for the | |
1133f8e7 | 6915 | respective modifier, or nil to appear as the `apps' key. |
74e1aeec | 6916 | Any other value will cause the key to be ignored. */); |
ccc2d29c | 6917 | Vw32_apps_modifier = Qnil; |
da36a4d6 | 6918 | |
29208e82 | 6919 | DEFVAR_BOOL ("w32-enable-synthesized-fonts", w32_enable_synthesized_fonts, |
74e1aeec | 6920 | doc: /* Non-nil enables selection of artificially italicized and bold fonts. */); |
d84b082d | 6921 | w32_enable_synthesized_fonts = 0; |
5ac45f98 | 6922 | |
29208e82 | 6923 | DEFVAR_LISP ("w32-enable-palette", Vw32_enable_palette, |
74e1aeec | 6924 | doc: /* Non-nil enables Windows palette management to map colors exactly. */); |
fbd6baed | 6925 | Vw32_enable_palette = Qt; |
5ac45f98 | 6926 | |
fbd6baed | 6927 | DEFVAR_INT ("w32-mouse-button-tolerance", |
29208e82 | 6928 | w32_mouse_button_tolerance, |
74e1aeec JR |
6929 | doc: /* Analogue of double click interval for faking middle mouse events. |
6930 | The value is the minimum time in milliseconds that must elapse between | |
1133f8e7 | 6931 | left and right button down events before they are considered distinct events. |
74e1aeec JR |
6932 | If both mouse buttons are depressed within this interval, a middle mouse |
6933 | button down event is generated instead. */); | |
2ba49441 | 6934 | w32_mouse_button_tolerance = GetDoubleClickTime () / 2; |
5ac45f98 | 6935 | |
fbd6baed | 6936 | DEFVAR_INT ("w32-mouse-move-interval", |
29208e82 | 6937 | w32_mouse_move_interval, |
74e1aeec JR |
6938 | doc: /* Minimum interval between mouse move events. |
6939 | The value is the minimum time in milliseconds that must elapse between | |
6940 | successive mouse move (or scroll bar drag) events before they are | |
6941 | reported as lisp events. */); | |
2ba49441 | 6942 | w32_mouse_move_interval = 0; |
84fb1139 | 6943 | |
74214547 | 6944 | DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system", |
29208e82 | 6945 | w32_pass_extra_mouse_buttons_to_system, |
1133f8e7 | 6946 | doc: /* If non-nil, the fourth and fifth mouse buttons are passed to Windows. |
74214547 JR |
6947 | Recent versions of Windows support mice with up to five buttons. |
6948 | Since most applications don't support these extra buttons, most mouse | |
6949 | drivers will allow you to map them to functions at the system level. | |
6950 | If this variable is non-nil, Emacs will pass them on, allowing the | |
6951 | system to handle them. */); | |
6952 | w32_pass_extra_mouse_buttons_to_system = 0; | |
6953 | ||
0b151762 | 6954 | DEFVAR_BOOL ("w32-pass-multimedia-buttons-to-system", |
29208e82 | 6955 | w32_pass_multimedia_buttons_to_system, |
0b151762 JR |
6956 | doc: /* If non-nil, media buttons are passed to Windows. |
6957 | Some modern keyboards contain buttons for controlling media players, web | |
74084731 | 6958 | browsers and other applications. Generally these buttons are handled on a |
0b151762 JR |
6959 | system wide basis, but by setting this to nil they are made available |
6960 | to Emacs for binding. Depending on your keyboard, additional keys that | |
6961 | may be available are: | |
6962 | ||
6963 | browser-back, browser-forward, browser-refresh, browser-stop, | |
6964 | browser-search, browser-favorites, browser-home, | |
6965 | mail, mail-reply, mail-forward, mail-send, | |
6966 | app-1, app-2, | |
6967 | help, find, new, open, close, save, print, undo, redo, copy, cut, paste, | |
6968 | spell-check, correction-list, toggle-dictate-command, | |
6969 | media-next, media-previous, media-stop, media-play-pause, media-select, | |
6970 | media-play, media-pause, media-record, media-fast-forward, media-rewind, | |
6971 | media-channel-up, media-channel-down, | |
6972 | volume-mute, volume-up, volume-down, | |
6973 | mic-volume-mute, mic-volume-down, mic-volume-up, mic-toggle, | |
74084731 | 6974 | bass-down, bass-boost, bass-up, treble-down, treble-up */); |
0b151762 JR |
6975 | w32_pass_multimedia_buttons_to_system = 1; |
6976 | ||
5f004711 | 6977 | #if 0 /* TODO: Mouse cursor customization. */ |
29208e82 | 6978 | DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape, |
74e1aeec JR |
6979 | doc: /* The shape of the pointer when over text. |
6980 | Changing the value does not affect existing frames | |
6981 | unless you set the mouse color. */); | |
ee78dc32 GV |
6982 | Vx_pointer_shape = Qnil; |
6983 | ||
ee78dc32 GV |
6984 | Vx_nontext_pointer_shape = Qnil; |
6985 | ||
6986 | Vx_mode_pointer_shape = Qnil; | |
6987 | ||
29208e82 | 6988 | DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape, |
74e1aeec JR |
6989 | doc: /* The shape of the pointer when Emacs is busy. |
6990 | This variable takes effect when you create a new frame | |
6991 | or when you set the mouse color. */); | |
0af913d7 | 6992 | Vx_hourglass_pointer_shape = Qnil; |
6fc2811b | 6993 | |
6fc2811b | 6994 | DEFVAR_LISP ("x-sensitive-text-pointer-shape", |
29208e82 | 6995 | Vx_sensitive_text_pointer_shape, |
74e1aeec JR |
6996 | doc: /* The shape of the pointer when over mouse-sensitive text. |
6997 | This variable takes effect when you create a new frame | |
6998 | or when you set the mouse color. */); | |
ee78dc32 GV |
6999 | Vx_sensitive_text_pointer_shape = Qnil; |
7000 | ||
4694d762 | 7001 | DEFVAR_LISP ("x-window-horizontal-drag-cursor", |
29208e82 | 7002 | Vx_window_horizontal_drag_shape, |
74e1aeec JR |
7003 | doc: /* Pointer shape to use for indicating a window can be dragged horizontally. |
7004 | This variable takes effect when you create a new frame | |
7005 | or when you set the mouse color. */); | |
4694d762 | 7006 | Vx_window_horizontal_drag_shape = Qnil; |
5f004711 | 7007 | #endif |
4694d762 | 7008 | |
29208e82 | 7009 | DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel, |
74e1aeec | 7010 | doc: /* A string indicating the foreground color of the cursor box. */); |
ee78dc32 GV |
7011 | Vx_cursor_fore_pixel = Qnil; |
7012 | ||
29208e82 | 7013 | DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size, |
b3700ae7 | 7014 | doc: /* Maximum size for tooltips. |
f5f6c0e0 | 7015 | Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */); |
3cf3436e | 7016 | Vx_max_tooltip_size = Fcons (make_number (80), make_number (40)); |
7d0393cf | 7017 | |
29208e82 | 7018 | DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager, |
74e1aeec JR |
7019 | doc: /* Non-nil if no window manager is in use. |
7020 | Emacs doesn't try to figure this out; this is always nil | |
7021 | unless you set it to something else. */); | |
ee78dc32 GV |
7022 | /* We don't have any way to find this out, so set it to nil |
7023 | and maybe the user would like to set it to t. */ | |
7024 | Vx_no_window_manager = Qnil; | |
7025 | ||
4587b026 | 7026 | DEFVAR_LISP ("x-pixel-size-width-font-regexp", |
29208e82 | 7027 | Vx_pixel_size_width_font_regexp, |
74e1aeec JR |
7028 | doc: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. |
7029 | ||
7030 | Since Emacs gets width of a font matching with this regexp from | |
7031 | PIXEL_SIZE field of the name, font finding mechanism gets faster for | |
7032 | such a font. This is especially effective for such large fonts as | |
7033 | Chinese, Japanese, and Korean. */); | |
4587b026 GV |
7034 | Vx_pixel_size_width_font_regexp = Qnil; |
7035 | ||
33d52f9c | 7036 | DEFVAR_LISP ("w32-bdf-filename-alist", |
29208e82 | 7037 | Vw32_bdf_filename_alist, |
74e1aeec | 7038 | doc: /* List of bdf fonts and their corresponding filenames. */); |
33d52f9c GV |
7039 | Vw32_bdf_filename_alist = Qnil; |
7040 | ||
1075afa9 | 7041 | DEFVAR_BOOL ("w32-strict-fontnames", |
29208e82 | 7042 | w32_strict_fontnames, |
74e1aeec JR |
7043 | doc: /* Non-nil means only use fonts that are exact matches for those requested. |
7044 | Default is nil, which allows old fontnames that are not XLFD compliant, | |
7045 | and allows third-party CJK display to work by specifying false charset | |
7046 | fields to trick Emacs into translating to Big5, SJIS etc. | |
7047 | Setting this to t will prevent wrong fonts being selected when | |
7048 | fontsets are automatically created. */); | |
1075afa9 GV |
7049 | w32_strict_fontnames = 0; |
7050 | ||
c0611964 | 7051 | DEFVAR_BOOL ("w32-strict-painting", |
29208e82 | 7052 | w32_strict_painting, |
74e1aeec | 7053 | doc: /* Non-nil means use strict rules for repainting frames. |
a8ab3e96 | 7054 | Set this to nil to get the old behavior for repainting; this should |
74e1aeec | 7055 | only be necessary if the default setting causes problems. */); |
c0611964 AI |
7056 | w32_strict_painting = 1; |
7057 | ||
767b1ff0 | 7058 | #if 0 /* TODO: Port to W32 */ |
6fc2811b JR |
7059 | defsubr (&Sx_change_window_property); |
7060 | defsubr (&Sx_delete_window_property); | |
7061 | defsubr (&Sx_window_property); | |
7062 | #endif | |
2d764c78 | 7063 | defsubr (&Sxw_display_color_p); |
ee78dc32 | 7064 | defsubr (&Sx_display_grayscale_p); |
2d764c78 EZ |
7065 | defsubr (&Sxw_color_defined_p); |
7066 | defsubr (&Sxw_color_values); | |
ee78dc32 GV |
7067 | defsubr (&Sx_server_max_request_size); |
7068 | defsubr (&Sx_server_vendor); | |
7069 | defsubr (&Sx_server_version); | |
7070 | defsubr (&Sx_display_pixel_width); | |
7071 | defsubr (&Sx_display_pixel_height); | |
7072 | defsubr (&Sx_display_mm_width); | |
7073 | defsubr (&Sx_display_mm_height); | |
7074 | defsubr (&Sx_display_screens); | |
7075 | defsubr (&Sx_display_planes); | |
7076 | defsubr (&Sx_display_color_cells); | |
7077 | defsubr (&Sx_display_visual_class); | |
7078 | defsubr (&Sx_display_backing_store); | |
7079 | defsubr (&Sx_display_save_under); | |
ee78dc32 | 7080 | defsubr (&Sx_create_frame); |
ee78dc32 GV |
7081 | defsubr (&Sx_open_connection); |
7082 | defsubr (&Sx_close_connection); | |
7083 | defsubr (&Sx_display_list); | |
7084 | defsubr (&Sx_synchronize); | |
334a1195 | 7085 | defsubr (&Sx_focus_frame); |
ee78dc32 | 7086 | |
fbd6baed | 7087 | /* W32 specific functions */ |
ee78dc32 | 7088 | |
fbd6baed GV |
7089 | defsubr (&Sw32_define_rgb_color); |
7090 | defsubr (&Sw32_default_color_map); | |
1edf84e7 | 7091 | defsubr (&Sw32_send_sys_command); |
55dcfc15 | 7092 | defsubr (&Sw32_shell_execute); |
ccc2d29c GV |
7093 | defsubr (&Sw32_register_hot_key); |
7094 | defsubr (&Sw32_unregister_hot_key); | |
7095 | defsubr (&Sw32_registered_hot_keys); | |
7096 | defsubr (&Sw32_reconstruct_hot_key); | |
adcc3809 | 7097 | defsubr (&Sw32_toggle_lock_key); |
a01763cb | 7098 | defsubr (&Sw32_window_exists_p); |
2c2279c6 | 7099 | defsubr (&Sw32_battery_status); |
4587b026 | 7100 | |
2254bcde | 7101 | defsubr (&Sfile_system_info); |
6b61353c | 7102 | defsubr (&Sdefault_printer_name); |
2254bcde | 7103 | |
4587b026 | 7104 | check_window_system_func = check_w32; |
6fc2811b | 7105 | |
463f5630 | 7106 | |
d148e14d JR |
7107 | hourglass_timer = 0; |
7108 | hourglass_hwnd = NULL; | |
1885ab29 | 7109 | |
6fc2811b JR |
7110 | defsubr (&Sx_show_tip); |
7111 | defsubr (&Sx_hide_tip); | |
6fc2811b | 7112 | tip_timer = Qnil; |
57fa2774 JR |
7113 | staticpro (&tip_timer); |
7114 | tip_frame = Qnil; | |
7115 | staticpro (&tip_frame); | |
6fc2811b | 7116 | |
ca56d953 JR |
7117 | last_show_tip_args = Qnil; |
7118 | staticpro (&last_show_tip_args); | |
7119 | ||
6fc2811b | 7120 | defsubr (&Sx_file_dialog); |
6cf29fe8 | 7121 | defsubr (&Ssystem_move_file_to_trash); |
6fc2811b JR |
7122 | } |
7123 | ||
c922a224 | 7124 | |
9785d95b BK |
7125 | /* |
7126 | globals_of_w32fns is used to initialize those global variables that | |
7127 | must always be initialized on startup even when the global variable | |
7128 | initialized is non zero (see the function main in emacs.c). | |
7129 | globals_of_w32fns is called from syms_of_w32fns when the global | |
7130 | variable initialized is 0 and directly from main when initialized | |
7131 | is non zero. | |
7132 | */ | |
02b39a28 | 7133 | void |
b56ceb92 | 7134 | globals_of_w32fns (void) |
9785d95b BK |
7135 | { |
7136 | HMODULE user32_lib = GetModuleHandle ("user32.dll"); | |
ccc0fdaa JR |
7137 | /* |
7138 | TrackMouseEvent not available in all versions of Windows, so must load | |
7139 | it dynamically. Do it once, here, instead of every time it is used. | |
9785d95b | 7140 | */ |
ccc0fdaa JR |
7141 | track_mouse_event_fn = (TrackMouseEvent_Proc) |
7142 | GetProcAddress (user32_lib, "TrackMouseEvent"); | |
64f0809d JR |
7143 | |
7144 | monitor_from_point_fn = (MonitorFromPoint_Proc) | |
7145 | GetProcAddress (user32_lib, "MonitorFromPoint"); | |
7146 | get_monitor_info_fn = (GetMonitorInfo_Proc) | |
7147 | GetProcAddress (user32_lib, "GetMonitorInfoA"); | |
7148 | ||
820eff5a JR |
7149 | { |
7150 | HMODULE imm32_lib = GetModuleHandle ("imm32.dll"); | |
7151 | get_composition_string_fn = (ImmGetCompositionString_Proc) | |
7152 | GetProcAddress (imm32_lib, "ImmGetCompositionStringW"); | |
7153 | get_ime_context_fn = (ImmGetContext_Proc) | |
7154 | GetProcAddress (imm32_lib, "ImmGetContext"); | |
c902b920 JR |
7155 | release_ime_context_fn = (ImmReleaseContext_Proc) |
7156 | GetProcAddress (imm32_lib, "ImmReleaseContext"); | |
7157 | set_ime_composition_window_fn = (ImmSetCompositionWindow_Proc) | |
7158 | GetProcAddress (imm32_lib, "ImmSetCompositionWindow"); | |
820eff5a | 7159 | } |
4bf91535 | 7160 | DEFVAR_INT ("w32-ansi-code-page", |
29208e82 | 7161 | w32_ansi_code_page, |
4bf91535 | 7162 | doc: /* The ANSI code page used by the system. */); |
2ba49441 | 7163 | w32_ansi_code_page = GetACP (); |
60860eb3 JR |
7164 | |
7165 | /* MessageBox does not work without this when linked to comctl32.dll 6.0. */ | |
7166 | InitCommonControls (); | |
cbfedb1c | 7167 | |
cbfedb1c | 7168 | syms_of_w32uniscribe (); |
9785d95b | 7169 | } |
6fc2811b | 7170 | |
ee78dc32 GV |
7171 | #undef abort |
7172 | ||
7d0393cf | 7173 | void |
b56ceb92 | 7174 | w32_abort (void) |
ee78dc32 | 7175 | { |
5ac45f98 GV |
7176 | int button; |
7177 | button = MessageBox (NULL, | |
7178 | "A fatal error has occurred!\n\n" | |
c52e1638 | 7179 | "Would you like to attach a debugger?\n\n" |
cb91d111 EZ |
7180 | "Select YES to debug, NO to abort Emacs" |
7181 | #if __GNUC__ | |
7182 | "\n\n(type \"gdb -p <emacs-PID>\" and\n" | |
7183 | "\"continue\" inside GDB before clicking YES.)" | |
7184 | #endif | |
7185 | , "Emacs Abort Dialog", | |
5ac45f98 | 7186 | MB_ICONEXCLAMATION | MB_TASKMODAL |
c52e1638 | 7187 | | MB_SETFOREGROUND | MB_YESNO); |
5ac45f98 GV |
7188 | switch (button) |
7189 | { | |
c52e1638 | 7190 | case IDYES: |
5ac45f98 | 7191 | DebugBreak (); |
c52e1638 EZ |
7192 | exit (2); /* tell the compiler we will never return */ |
7193 | case IDNO: | |
5ac45f98 GV |
7194 | default: |
7195 | abort (); | |
7196 | break; | |
7197 | } | |
ee78dc32 | 7198 | } |
d573caac | 7199 | |
83c75055 GV |
7200 | /* For convenience when debugging. */ |
7201 | int | |
b56ceb92 | 7202 | w32_last_error (void) |
83c75055 GV |
7203 | { |
7204 | return GetLastError (); | |
7205 | } |