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