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