Commit | Line | Data |
---|---|---|
e9e23e23 | 1 | /* Graphical user interface functions for the Microsoft W32 API. |
0b5538bd TTN |
2 | Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, |
3 | 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. | |
ee78dc32 GV |
4 | |
5 | This file is part of GNU Emacs. | |
6 | ||
7 | GNU Emacs is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU Emacs is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU Emacs; see the file COPYING. If not, write to | |
4fc5845f LK |
19 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 | Boston, MA 02110-1301, USA. */ | |
ee78dc32 GV |
21 | |
22 | /* Added by Kevin Gallo */ | |
23 | ||
ee78dc32 | 24 | #include <config.h> |
1edf84e7 GV |
25 | |
26 | #include <signal.h> | |
ee78dc32 | 27 | #include <stdio.h> |
1edf84e7 GV |
28 | #include <limits.h> |
29 | #include <errno.h> | |
ee78dc32 GV |
30 | |
31 | #include "lisp.h" | |
4587b026 | 32 | #include "charset.h" |
71eab8d1 | 33 | #include "dispextern.h" |
ee78dc32 | 34 | #include "w32term.h" |
c7501041 | 35 | #include "keyboard.h" |
ee78dc32 GV |
36 | #include "frame.h" |
37 | #include "window.h" | |
38 | #include "buffer.h" | |
126f2e35 | 39 | #include "fontset.h" |
6fc2811b | 40 | #include "intervals.h" |
ee78dc32 | 41 | #include "blockinput.h" |
57bda87a | 42 | #include "epaths.h" |
489f9371 | 43 | #include "w32heap.h" |
ee78dc32 | 44 | #include "termhooks.h" |
4587b026 | 45 | #include "coding.h" |
3545439c | 46 | #include "ccl.h" |
6fc2811b JR |
47 | #include "systime.h" |
48 | ||
49 | #include "bitmaps/gray.xbm" | |
ee78dc32 GV |
50 | |
51 | #include <commdlg.h> | |
cb9e33d4 | 52 | #include <shellapi.h> |
6fc2811b | 53 | #include <ctype.h> |
39a0e135 | 54 | #include <winspool.h> |
ee78dc32 | 55 | |
1030b26b JR |
56 | #include <dlgs.h> |
57 | #define FILE_NAME_TEXT_FIELD edt1 | |
58 | ||
9785d95b BK |
59 | void syms_of_w32fns (); |
60 | void globals_of_w32fns (); | |
61 | ||
ee78dc32 | 62 | extern void free_frame_menubar (); |
6fc2811b | 63 | extern double atof (); |
9eb16b62 JR |
64 | extern int w32_console_toggle_lock_key P_ ((int, Lisp_Object)); |
65 | extern void w32_menu_display_help P_ ((HWND, HMENU, UINT, UINT)); | |
66 | extern void w32_free_menu_strings P_ ((HWND)); | |
ad5674f5 | 67 | extern XCharStruct *w32_per_char_metric P_ ((XFontStruct *, wchar_t *, int)); |
9eb16b62 | 68 | |
5ac45f98 | 69 | extern int quit_char; |
ee78dc32 | 70 | |
ccc2d29c GV |
71 | extern char *lispy_function_keys[]; |
72 | ||
6fc2811b JR |
73 | /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses |
74 | it, and including `bitmaps/gray' more than once is a problem when | |
75 | config.h defines `static' as an empty replacement string. */ | |
76 | ||
77 | int gray_bitmap_width = gray_width; | |
78 | int gray_bitmap_height = gray_height; | |
79 | unsigned char *gray_bitmap_bits = gray_bits; | |
80 | ||
ee78dc32 | 81 | /* The colormap for converting color names to RGB values */ |
fbd6baed | 82 | Lisp_Object Vw32_color_map; |
ee78dc32 | 83 | |
da36a4d6 | 84 | /* Non nil if alt key presses are passed on to Windows. */ |
fbd6baed | 85 | Lisp_Object Vw32_pass_alt_to_system; |
da36a4d6 | 86 | |
8c205c63 RS |
87 | /* Non nil if alt key is translated to meta_modifier, nil if it is translated |
88 | to alt_modifier. */ | |
fbd6baed | 89 | Lisp_Object Vw32_alt_is_meta; |
8c205c63 | 90 | |
7d081355 | 91 | /* If non-zero, the windows virtual key code for an alternative quit key. */ |
2ba49441 | 92 | int w32_quit_key; |
7d081355 | 93 | |
ccc2d29c GV |
94 | /* Non nil if left window key events are passed on to Windows (this only |
95 | affects whether "tapping" the key opens the Start menu). */ | |
96 | Lisp_Object Vw32_pass_lwindow_to_system; | |
97 | ||
98 | /* Non nil if right window key events are passed on to Windows (this | |
99 | only affects whether "tapping" the key opens the Start menu). */ | |
100 | Lisp_Object Vw32_pass_rwindow_to_system; | |
101 | ||
adcc3809 GV |
102 | /* Virtual key code used to generate "phantom" key presses in order |
103 | to stop system from acting on Windows key events. */ | |
104 | Lisp_Object Vw32_phantom_key_code; | |
105 | ||
ccc2d29c GV |
106 | /* Modifier associated with the left "Windows" key, or nil to act as a |
107 | normal key. */ | |
108 | Lisp_Object Vw32_lwindow_modifier; | |
109 | ||
110 | /* Modifier associated with the right "Windows" key, or nil to act as a | |
111 | normal key. */ | |
112 | Lisp_Object Vw32_rwindow_modifier; | |
113 | ||
114 | /* Modifier associated with the "Apps" key, or nil to act as a normal | |
115 | key. */ | |
116 | Lisp_Object Vw32_apps_modifier; | |
117 | ||
118 | /* Value is nil if Num Lock acts as a function key. */ | |
119 | Lisp_Object Vw32_enable_num_lock; | |
120 | ||
121 | /* Value is nil if Caps Lock acts as a function key. */ | |
122 | Lisp_Object Vw32_enable_caps_lock; | |
123 | ||
124 | /* Modifier associated with Scroll Lock, or nil to act as a normal key. */ | |
125 | Lisp_Object Vw32_scroll_lock_modifier; | |
da36a4d6 | 126 | |
7ce9aaca | 127 | /* Switch to control whether we inhibit requests for synthesized bold |
6fc2811b | 128 | and italic versions of fonts. */ |
d84b082d | 129 | int w32_enable_synthesized_fonts; |
5ac45f98 GV |
130 | |
131 | /* Enable palette management. */ | |
fbd6baed | 132 | Lisp_Object Vw32_enable_palette; |
5ac45f98 GV |
133 | |
134 | /* Control how close left/right button down events must be to | |
135 | be converted to a middle button down event. */ | |
2ba49441 | 136 | int w32_mouse_button_tolerance; |
5ac45f98 | 137 | |
84fb1139 KH |
138 | /* Minimum interval between mouse movement (and scroll bar drag) |
139 | events that are passed on to the event loop. */ | |
2ba49441 | 140 | int w32_mouse_move_interval; |
84fb1139 | 141 | |
74214547 JR |
142 | /* Flag to indicate if XBUTTON events should be passed on to Windows. */ |
143 | int w32_pass_extra_mouse_buttons_to_system; | |
144 | ||
ee78dc32 GV |
145 | /* Non nil if no window manager is in use. */ |
146 | Lisp_Object Vx_no_window_manager; | |
147 | ||
0af913d7 | 148 | /* Non-zero means we're allowed to display a hourglass pointer. */ |
dfff8a69 | 149 | |
0af913d7 | 150 | int display_hourglass_p; |
6fc2811b | 151 | |
ee78dc32 GV |
152 | /* The background and shape of the mouse pointer, and shape when not |
153 | over text or in the modeline. */ | |
dfff8a69 | 154 | |
ee78dc32 | 155 | Lisp_Object Vx_pointer_shape, Vx_nontext_pointer_shape, Vx_mode_pointer_shape; |
829b13e2 | 156 | Lisp_Object Vx_hourglass_pointer_shape, Vx_window_horizontal_drag_shape; |
6fc2811b | 157 | |
ee78dc32 | 158 | /* The shape when over mouse-sensitive text. */ |
dfff8a69 | 159 | |
ee78dc32 GV |
160 | Lisp_Object Vx_sensitive_text_pointer_shape; |
161 | ||
c9b2104d JR |
162 | #ifndef IDC_HAND |
163 | #define IDC_HAND MAKEINTRESOURCE(32649) | |
164 | #endif | |
165 | ||
ee78dc32 | 166 | /* Color of chars displayed in cursor box. */ |
dfff8a69 | 167 | |
ee78dc32 GV |
168 | Lisp_Object Vx_cursor_fore_pixel; |
169 | ||
1edf84e7 | 170 | /* Nonzero if using Windows. */ |
dfff8a69 | 171 | |
1edf84e7 GV |
172 | static int w32_in_use; |
173 | ||
4587b026 | 174 | /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */ |
dfff8a69 | 175 | |
4587b026 GV |
176 | Lisp_Object Vx_pixel_size_width_font_regexp; |
177 | ||
33d52f9c GV |
178 | /* Alist of bdf fonts and the files that define them. */ |
179 | Lisp_Object Vw32_bdf_filename_alist; | |
180 | ||
f46e6225 | 181 | /* A flag to control whether fonts are matched strictly or not. */ |
1075afa9 GV |
182 | int w32_strict_fontnames; |
183 | ||
c0611964 AI |
184 | /* A flag to control whether we should only repaint if GetUpdateRect |
185 | indicates there is an update region. */ | |
186 | int w32_strict_painting; | |
187 | ||
dfff8a69 JR |
188 | /* Associative list linking character set strings to Windows codepages. */ |
189 | Lisp_Object Vw32_charset_info_alist; | |
190 | ||
191 | /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */ | |
192 | #ifndef VIETNAMESE_CHARSET | |
193 | #define VIETNAMESE_CHARSET 163 | |
194 | #endif | |
195 | ||
ee78dc32 | 196 | Lisp_Object Qnone; |
ee78dc32 | 197 | Lisp_Object Qsuppress_icon; |
ee78dc32 | 198 | Lisp_Object Qundefined_color; |
dc220243 | 199 | Lisp_Object Qcancel_timer; |
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 JR |
208 | Lisp_Object Qw32_charset_ansi; |
209 | Lisp_Object Qw32_charset_default; | |
210 | Lisp_Object Qw32_charset_symbol; | |
211 | Lisp_Object Qw32_charset_shiftjis; | |
767b1ff0 | 212 | Lisp_Object Qw32_charset_hangeul; |
dfff8a69 JR |
213 | Lisp_Object Qw32_charset_gb2312; |
214 | Lisp_Object Qw32_charset_chinesebig5; | |
215 | Lisp_Object Qw32_charset_oem; | |
216 | ||
71eab8d1 AI |
217 | #ifndef JOHAB_CHARSET |
218 | #define JOHAB_CHARSET 130 | |
219 | #endif | |
dfff8a69 JR |
220 | #ifdef JOHAB_CHARSET |
221 | Lisp_Object Qw32_charset_easteurope; | |
222 | Lisp_Object Qw32_charset_turkish; | |
223 | Lisp_Object Qw32_charset_baltic; | |
224 | Lisp_Object Qw32_charset_russian; | |
225 | Lisp_Object Qw32_charset_arabic; | |
226 | Lisp_Object Qw32_charset_greek; | |
227 | Lisp_Object Qw32_charset_hebrew; | |
767b1ff0 | 228 | Lisp_Object Qw32_charset_vietnamese; |
dfff8a69 JR |
229 | Lisp_Object Qw32_charset_thai; |
230 | Lisp_Object Qw32_charset_johab; | |
231 | Lisp_Object Qw32_charset_mac; | |
232 | #endif | |
233 | ||
234 | #ifdef UNICODE_CHARSET | |
235 | Lisp_Object Qw32_charset_unicode; | |
236 | #endif | |
237 | ||
4bf91535 | 238 | /* The ANSI codepage. */ |
2ba49441 | 239 | int w32_ansi_code_page; |
4bf91535 | 240 | |
5a8a15ec JR |
241 | /* Prefix for system colors. */ |
242 | #define SYSTEM_COLOR_PREFIX "System" | |
243 | #define SYSTEM_COLOR_PREFIX_LEN (sizeof (SYSTEM_COLOR_PREFIX) - 1) | |
244 | ||
5ac45f98 GV |
245 | /* State variables for emulating a three button mouse. */ |
246 | #define LMOUSE 1 | |
247 | #define MMOUSE 2 | |
248 | #define RMOUSE 4 | |
249 | ||
250 | static int button_state = 0; | |
fbd6baed | 251 | static W32Msg saved_mouse_button_msg; |
48094ace | 252 | static unsigned mouse_button_timer = 0; /* non-zero when timer is active */ |
fbd6baed | 253 | static W32Msg saved_mouse_move_msg; |
48094ace | 254 | static unsigned mouse_move_timer = 0; |
84fb1139 | 255 | |
9eb16b62 JR |
256 | /* Window that is tracking the mouse. */ |
257 | static HWND track_mouse_window; | |
f60ae425 | 258 | |
ccc0fdaa JR |
259 | typedef BOOL (WINAPI * TrackMouseEvent_Proc) |
260 | (IN OUT LPTRACKMOUSEEVENT lpEventTrack); | |
f60ae425 | 261 | |
ccc0fdaa JR |
262 | TrackMouseEvent_Proc track_mouse_event_fn = NULL; |
263 | ClipboardSequence_Proc clipboard_sequence_fn = NULL; | |
b4005349 | 264 | extern AppendMenuW_Proc unicode_append_menu; |
9eb16b62 | 265 | |
93fbe8b7 | 266 | /* W95 mousewheel handler */ |
7d0393cf | 267 | unsigned int msh_mousewheel = 0; |
93fbe8b7 | 268 | |
48094ace | 269 | /* Timers */ |
84fb1139 KH |
270 | #define MOUSE_BUTTON_ID 1 |
271 | #define MOUSE_MOVE_ID 2 | |
48094ace JR |
272 | #define MENU_FREE_ID 3 |
273 | /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP | |
274 | is received. */ | |
275 | #define MENU_FREE_DELAY 1000 | |
276 | static unsigned menu_free_timer = 0; | |
5ac45f98 | 277 | |
ee78dc32 | 278 | /* The below are defined in frame.c. */ |
dfff8a69 | 279 | |
ee78dc32 GV |
280 | extern Lisp_Object Vwindow_system_version; |
281 | ||
937e601e AI |
282 | #ifdef GLYPH_DEBUG |
283 | int image_cache_refcount, dpyinfo_refcount; | |
284 | #endif | |
285 | ||
286 | ||
fbd6baed | 287 | /* From w32term.c. */ |
2ba49441 | 288 | extern int w32_num_mouse_buttons; |
ccc2d29c | 289 | extern Lisp_Object Vw32_recognize_altgr; |
5ac45f98 | 290 | |
65906840 | 291 | extern HWND w32_system_caret_hwnd; |
93f2ca61 | 292 | |
65906840 JR |
293 | extern int w32_system_caret_height; |
294 | extern int w32_system_caret_x; | |
295 | extern int w32_system_caret_y; | |
93f2ca61 JR |
296 | extern int w32_use_visible_system_caret; |
297 | ||
d285988b | 298 | static HWND w32_visible_system_caret_hwnd; |
65906840 | 299 | |
ee78dc32 | 300 | \f |
1edf84e7 GV |
301 | /* Error if we are not connected to MS-Windows. */ |
302 | void | |
303 | check_w32 () | |
304 | { | |
305 | if (! w32_in_use) | |
306 | error ("MS-Windows not in use or not initialized"); | |
307 | } | |
308 | ||
309 | /* Nonzero if we can use mouse menus. | |
310 | You should not call this unless HAVE_MENUS is defined. */ | |
7d0393cf | 311 | |
1edf84e7 GV |
312 | int |
313 | have_menus_p () | |
314 | { | |
315 | return w32_in_use; | |
316 | } | |
317 | ||
ee78dc32 | 318 | /* Extract a frame as a FRAME_PTR, defaulting to the selected frame |
fbd6baed | 319 | and checking validity for W32. */ |
ee78dc32 GV |
320 | |
321 | FRAME_PTR | |
322 | check_x_frame (frame) | |
323 | Lisp_Object frame; | |
324 | { | |
325 | FRAME_PTR f; | |
326 | ||
327 | if (NILP (frame)) | |
6fc2811b | 328 | frame = selected_frame; |
b7826503 | 329 | CHECK_LIVE_FRAME (frame); |
6fc2811b | 330 | f = XFRAME (frame); |
fbd6baed | 331 | if (! FRAME_W32_P (f)) |
21517c3d | 332 | error ("Non-W32 frame used"); |
ee78dc32 GV |
333 | return f; |
334 | } | |
335 | ||
7d0393cf | 336 | /* Let the user specify a display with a frame. |
fbd6baed | 337 | nil stands for the selected frame--or, if that is not a w32 frame, |
ee78dc32 GV |
338 | the first display on the list. */ |
339 | ||
6d906347 | 340 | struct w32_display_info * |
ee78dc32 GV |
341 | check_x_display_info (frame) |
342 | Lisp_Object frame; | |
343 | { | |
344 | if (NILP (frame)) | |
345 | { | |
6fc2811b | 346 | struct frame *sf = XFRAME (selected_frame); |
7d0393cf | 347 | |
6fc2811b JR |
348 | if (FRAME_W32_P (sf) && FRAME_LIVE_P (sf)) |
349 | return FRAME_W32_DISPLAY_INFO (sf); | |
ee78dc32 | 350 | else |
fbd6baed | 351 | return &one_w32_display_info; |
ee78dc32 GV |
352 | } |
353 | else if (STRINGP (frame)) | |
354 | return x_display_info_for_name (frame); | |
355 | else | |
356 | { | |
357 | FRAME_PTR f; | |
358 | ||
b7826503 | 359 | CHECK_LIVE_FRAME (frame); |
ee78dc32 | 360 | f = XFRAME (frame); |
fbd6baed | 361 | if (! FRAME_W32_P (f)) |
21517c3d | 362 | error ("Non-W32 frame used"); |
fbd6baed | 363 | return FRAME_W32_DISPLAY_INFO (f); |
ee78dc32 GV |
364 | } |
365 | } | |
366 | \f | |
fbd6baed | 367 | /* Return the Emacs frame-object corresponding to an w32 window. |
ee78dc32 GV |
368 | It could be the frame's main window or an icon window. */ |
369 | ||
370 | /* This function can be called during GC, so use GC_xxx type test macros. */ | |
371 | ||
372 | struct frame * | |
373 | x_window_to_frame (dpyinfo, wdesc) | |
fbd6baed | 374 | struct w32_display_info *dpyinfo; |
ee78dc32 GV |
375 | HWND wdesc; |
376 | { | |
377 | Lisp_Object tail, frame; | |
378 | struct frame *f; | |
379 | ||
8e713be6 | 380 | for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail)) |
ee78dc32 | 381 | { |
8e713be6 | 382 | frame = XCAR (tail); |
ee78dc32 GV |
383 | if (!GC_FRAMEP (frame)) |
384 | continue; | |
385 | f = XFRAME (frame); | |
2d764c78 | 386 | if (!FRAME_W32_P (f) || FRAME_W32_DISPLAY_INFO (f) != dpyinfo) |
ee78dc32 | 387 | continue; |
0af913d7 | 388 | if (f->output_data.w32->hourglass_window == wdesc) |
f79e6790 JR |
389 | return f; |
390 | ||
fbd6baed | 391 | if (FRAME_W32_WINDOW (f) == wdesc) |
ee78dc32 GV |
392 | return f; |
393 | } | |
394 | return 0; | |
395 | } | |
396 | ||
397 | \f | |
937e601e AI |
398 | static Lisp_Object unwind_create_frame P_ ((Lisp_Object)); |
399 | static Lisp_Object unwind_create_tip_frame P_ ((Lisp_Object)); | |
0962822d JB |
400 | static void my_create_window P_ ((struct frame *)); |
401 | static void my_create_tip_window P_ ((struct frame *)); | |
6d906347 | 402 | |
767b1ff0 | 403 | /* TODO: Native Input Method support; see x_create_im. */ |
6fc2811b JR |
404 | void x_set_foreground_color P_ ((struct frame *, Lisp_Object, Lisp_Object)); |
405 | void x_set_background_color P_ ((struct frame *, Lisp_Object, Lisp_Object)); | |
406 | void x_set_mouse_color P_ ((struct frame *, Lisp_Object, Lisp_Object)); | |
407 | void x_set_cursor_color P_ ((struct frame *, Lisp_Object, Lisp_Object)); | |
408 | void x_set_border_color P_ ((struct frame *, Lisp_Object, Lisp_Object)); | |
409 | void x_set_cursor_type P_ ((struct frame *, Lisp_Object, Lisp_Object)); | |
410 | void x_set_icon_type P_ ((struct frame *, Lisp_Object, Lisp_Object)); | |
411 | void x_set_icon_name P_ ((struct frame *, Lisp_Object, Lisp_Object)); | |
6fc2811b | 412 | void x_explicitly_set_name P_ ((struct frame *, Lisp_Object, Lisp_Object)); |
6fc2811b | 413 | void x_set_menu_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object)); |
6fc2811b | 414 | void x_set_title P_ ((struct frame *, Lisp_Object, Lisp_Object)); |
6fc2811b | 415 | void x_set_tool_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object)); |
3cf3436e JR |
416 | static void x_edge_detection P_ ((struct frame *, struct image *, Lisp_Object, |
417 | Lisp_Object)); | |
ee78dc32 | 418 | |
ee78dc32 | 419 | |
ee78dc32 | 420 | \f |
ee78dc32 GV |
421 | |
422 | /* Store the screen positions of frame F into XPTR and YPTR. | |
423 | These are the positions of the containing window manager window, | |
424 | not Emacs's own window. */ | |
425 | ||
426 | void | |
427 | x_real_positions (f, xptr, yptr) | |
428 | FRAME_PTR f; | |
429 | int *xptr, *yptr; | |
430 | { | |
431 | POINT pt; | |
f7b9d4d1 | 432 | RECT rect; |
3c190163 | 433 | |
f7b9d4d1 JR |
434 | GetClientRect(FRAME_W32_WINDOW(f), &rect); |
435 | AdjustWindowRect(&rect, f->output_data.w32->dwStyle, FRAME_EXTERNAL_MENU_BAR(f)); | |
436 | ||
437 | pt.x = rect.left; | |
438 | pt.y = rect.top; | |
ee78dc32 | 439 | |
fbd6baed | 440 | ClientToScreen (FRAME_W32_WINDOW(f), &pt); |
ee78dc32 | 441 | |
f7b9d4d1 | 442 | /* Remember x_pixels_diff and y_pixels_diff. */ |
be786000 KS |
443 | f->x_pixels_diff = pt.x - rect.left; |
444 | f->y_pixels_diff = pt.y - rect.top; | |
f7b9d4d1 | 445 | |
ee78dc32 GV |
446 | *xptr = pt.x; |
447 | *yptr = pt.y; | |
448 | } | |
449 | ||
ee78dc32 GV |
450 | \f |
451 | ||
74e1aeec JR |
452 | DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color, |
453 | Sw32_define_rgb_color, 4, 4, 0, | |
454 | doc: /* Convert RGB numbers to a windows color reference and associate with NAME. | |
455 | This adds or updates a named color to w32-color-map, making it | |
456 | available for use. The original entry's RGB ref is returned, or nil | |
457 | if the entry is new. */) | |
5ac45f98 GV |
458 | (red, green, blue, name) |
459 | Lisp_Object red, green, blue, name; | |
ee78dc32 | 460 | { |
5ac45f98 GV |
461 | Lisp_Object rgb; |
462 | Lisp_Object oldrgb = Qnil; | |
463 | Lisp_Object entry; | |
464 | ||
b7826503 PJ |
465 | CHECK_NUMBER (red); |
466 | CHECK_NUMBER (green); | |
467 | CHECK_NUMBER (blue); | |
468 | CHECK_STRING (name); | |
ee78dc32 | 469 | |
89458937 | 470 | XSETINT (rgb, RGB(XUINT (red), XUINT (green), XUINT (blue))); |
ee78dc32 | 471 | |
5ac45f98 | 472 | BLOCK_INPUT; |
ee78dc32 | 473 | |
fbd6baed GV |
474 | /* replace existing entry in w32-color-map or add new entry. */ |
475 | entry = Fassoc (name, Vw32_color_map); | |
5ac45f98 GV |
476 | if (NILP (entry)) |
477 | { | |
478 | entry = Fcons (name, rgb); | |
fbd6baed | 479 | Vw32_color_map = Fcons (entry, Vw32_color_map); |
5ac45f98 GV |
480 | } |
481 | else | |
482 | { | |
483 | oldrgb = Fcdr (entry); | |
484 | Fsetcdr (entry, rgb); | |
485 | } | |
486 | ||
487 | UNBLOCK_INPUT; | |
488 | ||
489 | return (oldrgb); | |
ee78dc32 GV |
490 | } |
491 | ||
74e1aeec JR |
492 | DEFUN ("w32-load-color-file", Fw32_load_color_file, |
493 | Sw32_load_color_file, 1, 1, 0, | |
494 | doc: /* Create an alist of color entries from an external file. | |
495 | Assign this value to w32-color-map to replace the existing color map. | |
496 | ||
497 | The file should define one named RGB color per line like so: | |
498 | R G B name | |
499 | where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */) | |
5ac45f98 GV |
500 | (filename) |
501 | Lisp_Object filename; | |
502 | { | |
503 | FILE *fp; | |
504 | Lisp_Object cmap = Qnil; | |
505 | Lisp_Object abspath; | |
506 | ||
b7826503 | 507 | CHECK_STRING (filename); |
5ac45f98 GV |
508 | abspath = Fexpand_file_name (filename, Qnil); |
509 | ||
d5db4077 | 510 | fp = fopen (SDATA (filename), "rt"); |
5ac45f98 GV |
511 | if (fp) |
512 | { | |
513 | char buf[512]; | |
514 | int red, green, blue; | |
515 | int num; | |
516 | ||
517 | BLOCK_INPUT; | |
518 | ||
519 | while (fgets (buf, sizeof (buf), fp) != NULL) { | |
520 | if (sscanf (buf, "%u %u %u %n", &red, &green, &blue, &num) == 3) | |
521 | { | |
522 | char *name = buf + num; | |
523 | num = strlen (name) - 1; | |
524 | if (name[num] == '\n') | |
525 | name[num] = 0; | |
526 | cmap = Fcons (Fcons (build_string (name), | |
527 | make_number (RGB (red, green, blue))), | |
528 | cmap); | |
529 | } | |
530 | } | |
531 | fclose (fp); | |
532 | ||
533 | UNBLOCK_INPUT; | |
534 | } | |
535 | ||
536 | return cmap; | |
537 | } | |
ee78dc32 | 538 | |
fbd6baed | 539 | /* The default colors for the w32 color map */ |
7d0393cf | 540 | typedef struct colormap_t |
ee78dc32 GV |
541 | { |
542 | char *name; | |
543 | COLORREF colorref; | |
544 | } colormap_t; | |
545 | ||
7d0393cf | 546 | colormap_t w32_color_map[] = |
ee78dc32 | 547 | { |
1da8a614 GV |
548 | {"snow" , PALETTERGB (255,250,250)}, |
549 | {"ghost white" , PALETTERGB (248,248,255)}, | |
550 | {"GhostWhite" , PALETTERGB (248,248,255)}, | |
551 | {"white smoke" , PALETTERGB (245,245,245)}, | |
552 | {"WhiteSmoke" , PALETTERGB (245,245,245)}, | |
553 | {"gainsboro" , PALETTERGB (220,220,220)}, | |
554 | {"floral white" , PALETTERGB (255,250,240)}, | |
555 | {"FloralWhite" , PALETTERGB (255,250,240)}, | |
556 | {"old lace" , PALETTERGB (253,245,230)}, | |
557 | {"OldLace" , PALETTERGB (253,245,230)}, | |
558 | {"linen" , PALETTERGB (250,240,230)}, | |
559 | {"antique white" , PALETTERGB (250,235,215)}, | |
560 | {"AntiqueWhite" , PALETTERGB (250,235,215)}, | |
561 | {"papaya whip" , PALETTERGB (255,239,213)}, | |
562 | {"PapayaWhip" , PALETTERGB (255,239,213)}, | |
563 | {"blanched almond" , PALETTERGB (255,235,205)}, | |
564 | {"BlanchedAlmond" , PALETTERGB (255,235,205)}, | |
565 | {"bisque" , PALETTERGB (255,228,196)}, | |
566 | {"peach puff" , PALETTERGB (255,218,185)}, | |
567 | {"PeachPuff" , PALETTERGB (255,218,185)}, | |
568 | {"navajo white" , PALETTERGB (255,222,173)}, | |
569 | {"NavajoWhite" , PALETTERGB (255,222,173)}, | |
570 | {"moccasin" , PALETTERGB (255,228,181)}, | |
571 | {"cornsilk" , PALETTERGB (255,248,220)}, | |
572 | {"ivory" , PALETTERGB (255,255,240)}, | |
573 | {"lemon chiffon" , PALETTERGB (255,250,205)}, | |
574 | {"LemonChiffon" , PALETTERGB (255,250,205)}, | |
575 | {"seashell" , PALETTERGB (255,245,238)}, | |
576 | {"honeydew" , PALETTERGB (240,255,240)}, | |
577 | {"mint cream" , PALETTERGB (245,255,250)}, | |
578 | {"MintCream" , PALETTERGB (245,255,250)}, | |
579 | {"azure" , PALETTERGB (240,255,255)}, | |
580 | {"alice blue" , PALETTERGB (240,248,255)}, | |
581 | {"AliceBlue" , PALETTERGB (240,248,255)}, | |
582 | {"lavender" , PALETTERGB (230,230,250)}, | |
583 | {"lavender blush" , PALETTERGB (255,240,245)}, | |
584 | {"LavenderBlush" , PALETTERGB (255,240,245)}, | |
585 | {"misty rose" , PALETTERGB (255,228,225)}, | |
586 | {"MistyRose" , PALETTERGB (255,228,225)}, | |
587 | {"white" , PALETTERGB (255,255,255)}, | |
588 | {"black" , PALETTERGB ( 0, 0, 0)}, | |
589 | {"dark slate gray" , PALETTERGB ( 47, 79, 79)}, | |
590 | {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)}, | |
591 | {"dark slate grey" , PALETTERGB ( 47, 79, 79)}, | |
592 | {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)}, | |
593 | {"dim gray" , PALETTERGB (105,105,105)}, | |
594 | {"DimGray" , PALETTERGB (105,105,105)}, | |
595 | {"dim grey" , PALETTERGB (105,105,105)}, | |
596 | {"DimGrey" , PALETTERGB (105,105,105)}, | |
597 | {"slate gray" , PALETTERGB (112,128,144)}, | |
598 | {"SlateGray" , PALETTERGB (112,128,144)}, | |
599 | {"slate grey" , PALETTERGB (112,128,144)}, | |
600 | {"SlateGrey" , PALETTERGB (112,128,144)}, | |
601 | {"light slate gray" , PALETTERGB (119,136,153)}, | |
602 | {"LightSlateGray" , PALETTERGB (119,136,153)}, | |
603 | {"light slate grey" , PALETTERGB (119,136,153)}, | |
604 | {"LightSlateGrey" , PALETTERGB (119,136,153)}, | |
605 | {"gray" , PALETTERGB (190,190,190)}, | |
606 | {"grey" , PALETTERGB (190,190,190)}, | |
607 | {"light grey" , PALETTERGB (211,211,211)}, | |
608 | {"LightGrey" , PALETTERGB (211,211,211)}, | |
609 | {"light gray" , PALETTERGB (211,211,211)}, | |
610 | {"LightGray" , PALETTERGB (211,211,211)}, | |
611 | {"midnight blue" , PALETTERGB ( 25, 25,112)}, | |
612 | {"MidnightBlue" , PALETTERGB ( 25, 25,112)}, | |
613 | {"navy" , PALETTERGB ( 0, 0,128)}, | |
614 | {"navy blue" , PALETTERGB ( 0, 0,128)}, | |
615 | {"NavyBlue" , PALETTERGB ( 0, 0,128)}, | |
616 | {"cornflower blue" , PALETTERGB (100,149,237)}, | |
617 | {"CornflowerBlue" , PALETTERGB (100,149,237)}, | |
618 | {"dark slate blue" , PALETTERGB ( 72, 61,139)}, | |
619 | {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)}, | |
620 | {"slate blue" , PALETTERGB (106, 90,205)}, | |
621 | {"SlateBlue" , PALETTERGB (106, 90,205)}, | |
622 | {"medium slate blue" , PALETTERGB (123,104,238)}, | |
623 | {"MediumSlateBlue" , PALETTERGB (123,104,238)}, | |
624 | {"light slate blue" , PALETTERGB (132,112,255)}, | |
625 | {"LightSlateBlue" , PALETTERGB (132,112,255)}, | |
626 | {"medium blue" , PALETTERGB ( 0, 0,205)}, | |
627 | {"MediumBlue" , PALETTERGB ( 0, 0,205)}, | |
628 | {"royal blue" , PALETTERGB ( 65,105,225)}, | |
629 | {"RoyalBlue" , PALETTERGB ( 65,105,225)}, | |
630 | {"blue" , PALETTERGB ( 0, 0,255)}, | |
631 | {"dodger blue" , PALETTERGB ( 30,144,255)}, | |
632 | {"DodgerBlue" , PALETTERGB ( 30,144,255)}, | |
633 | {"deep sky blue" , PALETTERGB ( 0,191,255)}, | |
634 | {"DeepSkyBlue" , PALETTERGB ( 0,191,255)}, | |
635 | {"sky blue" , PALETTERGB (135,206,235)}, | |
636 | {"SkyBlue" , PALETTERGB (135,206,235)}, | |
637 | {"light sky blue" , PALETTERGB (135,206,250)}, | |
638 | {"LightSkyBlue" , PALETTERGB (135,206,250)}, | |
639 | {"steel blue" , PALETTERGB ( 70,130,180)}, | |
640 | {"SteelBlue" , PALETTERGB ( 70,130,180)}, | |
641 | {"light steel blue" , PALETTERGB (176,196,222)}, | |
642 | {"LightSteelBlue" , PALETTERGB (176,196,222)}, | |
643 | {"light blue" , PALETTERGB (173,216,230)}, | |
644 | {"LightBlue" , PALETTERGB (173,216,230)}, | |
645 | {"powder blue" , PALETTERGB (176,224,230)}, | |
646 | {"PowderBlue" , PALETTERGB (176,224,230)}, | |
647 | {"pale turquoise" , PALETTERGB (175,238,238)}, | |
648 | {"PaleTurquoise" , PALETTERGB (175,238,238)}, | |
649 | {"dark turquoise" , PALETTERGB ( 0,206,209)}, | |
650 | {"DarkTurquoise" , PALETTERGB ( 0,206,209)}, | |
651 | {"medium turquoise" , PALETTERGB ( 72,209,204)}, | |
652 | {"MediumTurquoise" , PALETTERGB ( 72,209,204)}, | |
653 | {"turquoise" , PALETTERGB ( 64,224,208)}, | |
654 | {"cyan" , PALETTERGB ( 0,255,255)}, | |
655 | {"light cyan" , PALETTERGB (224,255,255)}, | |
656 | {"LightCyan" , PALETTERGB (224,255,255)}, | |
657 | {"cadet blue" , PALETTERGB ( 95,158,160)}, | |
658 | {"CadetBlue" , PALETTERGB ( 95,158,160)}, | |
659 | {"medium aquamarine" , PALETTERGB (102,205,170)}, | |
660 | {"MediumAquamarine" , PALETTERGB (102,205,170)}, | |
661 | {"aquamarine" , PALETTERGB (127,255,212)}, | |
662 | {"dark green" , PALETTERGB ( 0,100, 0)}, | |
663 | {"DarkGreen" , PALETTERGB ( 0,100, 0)}, | |
664 | {"dark olive green" , PALETTERGB ( 85,107, 47)}, | |
665 | {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)}, | |
666 | {"dark sea green" , PALETTERGB (143,188,143)}, | |
667 | {"DarkSeaGreen" , PALETTERGB (143,188,143)}, | |
668 | {"sea green" , PALETTERGB ( 46,139, 87)}, | |
669 | {"SeaGreen" , PALETTERGB ( 46,139, 87)}, | |
670 | {"medium sea green" , PALETTERGB ( 60,179,113)}, | |
671 | {"MediumSeaGreen" , PALETTERGB ( 60,179,113)}, | |
672 | {"light sea green" , PALETTERGB ( 32,178,170)}, | |
673 | {"LightSeaGreen" , PALETTERGB ( 32,178,170)}, | |
674 | {"pale green" , PALETTERGB (152,251,152)}, | |
675 | {"PaleGreen" , PALETTERGB (152,251,152)}, | |
676 | {"spring green" , PALETTERGB ( 0,255,127)}, | |
677 | {"SpringGreen" , PALETTERGB ( 0,255,127)}, | |
678 | {"lawn green" , PALETTERGB (124,252, 0)}, | |
679 | {"LawnGreen" , PALETTERGB (124,252, 0)}, | |
680 | {"green" , PALETTERGB ( 0,255, 0)}, | |
681 | {"chartreuse" , PALETTERGB (127,255, 0)}, | |
682 | {"medium spring green" , PALETTERGB ( 0,250,154)}, | |
683 | {"MediumSpringGreen" , PALETTERGB ( 0,250,154)}, | |
684 | {"green yellow" , PALETTERGB (173,255, 47)}, | |
685 | {"GreenYellow" , PALETTERGB (173,255, 47)}, | |
686 | {"lime green" , PALETTERGB ( 50,205, 50)}, | |
687 | {"LimeGreen" , PALETTERGB ( 50,205, 50)}, | |
688 | {"yellow green" , PALETTERGB (154,205, 50)}, | |
689 | {"YellowGreen" , PALETTERGB (154,205, 50)}, | |
690 | {"forest green" , PALETTERGB ( 34,139, 34)}, | |
691 | {"ForestGreen" , PALETTERGB ( 34,139, 34)}, | |
692 | {"olive drab" , PALETTERGB (107,142, 35)}, | |
693 | {"OliveDrab" , PALETTERGB (107,142, 35)}, | |
694 | {"dark khaki" , PALETTERGB (189,183,107)}, | |
695 | {"DarkKhaki" , PALETTERGB (189,183,107)}, | |
696 | {"khaki" , PALETTERGB (240,230,140)}, | |
697 | {"pale goldenrod" , PALETTERGB (238,232,170)}, | |
698 | {"PaleGoldenrod" , PALETTERGB (238,232,170)}, | |
699 | {"light goldenrod yellow" , PALETTERGB (250,250,210)}, | |
700 | {"LightGoldenrodYellow" , PALETTERGB (250,250,210)}, | |
701 | {"light yellow" , PALETTERGB (255,255,224)}, | |
702 | {"LightYellow" , PALETTERGB (255,255,224)}, | |
703 | {"yellow" , PALETTERGB (255,255, 0)}, | |
704 | {"gold" , PALETTERGB (255,215, 0)}, | |
705 | {"light goldenrod" , PALETTERGB (238,221,130)}, | |
706 | {"LightGoldenrod" , PALETTERGB (238,221,130)}, | |
707 | {"goldenrod" , PALETTERGB (218,165, 32)}, | |
708 | {"dark goldenrod" , PALETTERGB (184,134, 11)}, | |
709 | {"DarkGoldenrod" , PALETTERGB (184,134, 11)}, | |
710 | {"rosy brown" , PALETTERGB (188,143,143)}, | |
711 | {"RosyBrown" , PALETTERGB (188,143,143)}, | |
712 | {"indian red" , PALETTERGB (205, 92, 92)}, | |
713 | {"IndianRed" , PALETTERGB (205, 92, 92)}, | |
714 | {"saddle brown" , PALETTERGB (139, 69, 19)}, | |
715 | {"SaddleBrown" , PALETTERGB (139, 69, 19)}, | |
716 | {"sienna" , PALETTERGB (160, 82, 45)}, | |
717 | {"peru" , PALETTERGB (205,133, 63)}, | |
718 | {"burlywood" , PALETTERGB (222,184,135)}, | |
719 | {"beige" , PALETTERGB (245,245,220)}, | |
720 | {"wheat" , PALETTERGB (245,222,179)}, | |
721 | {"sandy brown" , PALETTERGB (244,164, 96)}, | |
722 | {"SandyBrown" , PALETTERGB (244,164, 96)}, | |
723 | {"tan" , PALETTERGB (210,180,140)}, | |
724 | {"chocolate" , PALETTERGB (210,105, 30)}, | |
725 | {"firebrick" , PALETTERGB (178,34, 34)}, | |
726 | {"brown" , PALETTERGB (165,42, 42)}, | |
727 | {"dark salmon" , PALETTERGB (233,150,122)}, | |
728 | {"DarkSalmon" , PALETTERGB (233,150,122)}, | |
729 | {"salmon" , PALETTERGB (250,128,114)}, | |
730 | {"light salmon" , PALETTERGB (255,160,122)}, | |
731 | {"LightSalmon" , PALETTERGB (255,160,122)}, | |
732 | {"orange" , PALETTERGB (255,165, 0)}, | |
733 | {"dark orange" , PALETTERGB (255,140, 0)}, | |
734 | {"DarkOrange" , PALETTERGB (255,140, 0)}, | |
735 | {"coral" , PALETTERGB (255,127, 80)}, | |
736 | {"light coral" , PALETTERGB (240,128,128)}, | |
737 | {"LightCoral" , PALETTERGB (240,128,128)}, | |
738 | {"tomato" , PALETTERGB (255, 99, 71)}, | |
739 | {"orange red" , PALETTERGB (255, 69, 0)}, | |
740 | {"OrangeRed" , PALETTERGB (255, 69, 0)}, | |
741 | {"red" , PALETTERGB (255, 0, 0)}, | |
742 | {"hot pink" , PALETTERGB (255,105,180)}, | |
743 | {"HotPink" , PALETTERGB (255,105,180)}, | |
744 | {"deep pink" , PALETTERGB (255, 20,147)}, | |
745 | {"DeepPink" , PALETTERGB (255, 20,147)}, | |
746 | {"pink" , PALETTERGB (255,192,203)}, | |
747 | {"light pink" , PALETTERGB (255,182,193)}, | |
748 | {"LightPink" , PALETTERGB (255,182,193)}, | |
749 | {"pale violet red" , PALETTERGB (219,112,147)}, | |
750 | {"PaleVioletRed" , PALETTERGB (219,112,147)}, | |
751 | {"maroon" , PALETTERGB (176, 48, 96)}, | |
752 | {"medium violet red" , PALETTERGB (199, 21,133)}, | |
753 | {"MediumVioletRed" , PALETTERGB (199, 21,133)}, | |
754 | {"violet red" , PALETTERGB (208, 32,144)}, | |
755 | {"VioletRed" , PALETTERGB (208, 32,144)}, | |
756 | {"magenta" , PALETTERGB (255, 0,255)}, | |
757 | {"violet" , PALETTERGB (238,130,238)}, | |
758 | {"plum" , PALETTERGB (221,160,221)}, | |
759 | {"orchid" , PALETTERGB (218,112,214)}, | |
760 | {"medium orchid" , PALETTERGB (186, 85,211)}, | |
761 | {"MediumOrchid" , PALETTERGB (186, 85,211)}, | |
762 | {"dark orchid" , PALETTERGB (153, 50,204)}, | |
763 | {"DarkOrchid" , PALETTERGB (153, 50,204)}, | |
764 | {"dark violet" , PALETTERGB (148, 0,211)}, | |
765 | {"DarkViolet" , PALETTERGB (148, 0,211)}, | |
766 | {"blue violet" , PALETTERGB (138, 43,226)}, | |
767 | {"BlueViolet" , PALETTERGB (138, 43,226)}, | |
768 | {"purple" , PALETTERGB (160, 32,240)}, | |
769 | {"medium purple" , PALETTERGB (147,112,219)}, | |
770 | {"MediumPurple" , PALETTERGB (147,112,219)}, | |
771 | {"thistle" , PALETTERGB (216,191,216)}, | |
772 | {"gray0" , PALETTERGB ( 0, 0, 0)}, | |
773 | {"grey0" , PALETTERGB ( 0, 0, 0)}, | |
774 | {"dark grey" , PALETTERGB (169,169,169)}, | |
775 | {"DarkGrey" , PALETTERGB (169,169,169)}, | |
776 | {"dark gray" , PALETTERGB (169,169,169)}, | |
777 | {"DarkGray" , PALETTERGB (169,169,169)}, | |
778 | {"dark blue" , PALETTERGB ( 0, 0,139)}, | |
779 | {"DarkBlue" , PALETTERGB ( 0, 0,139)}, | |
780 | {"dark cyan" , PALETTERGB ( 0,139,139)}, | |
781 | {"DarkCyan" , PALETTERGB ( 0,139,139)}, | |
782 | {"dark magenta" , PALETTERGB (139, 0,139)}, | |
783 | {"DarkMagenta" , PALETTERGB (139, 0,139)}, | |
784 | {"dark red" , PALETTERGB (139, 0, 0)}, | |
785 | {"DarkRed" , PALETTERGB (139, 0, 0)}, | |
786 | {"light green" , PALETTERGB (144,238,144)}, | |
787 | {"LightGreen" , PALETTERGB (144,238,144)}, | |
ee78dc32 GV |
788 | }; |
789 | ||
fbd6baed | 790 | DEFUN ("w32-default-color-map", Fw32_default_color_map, Sw32_default_color_map, |
74e1aeec | 791 | 0, 0, 0, doc: /* Return the default color map. */) |
ee78dc32 GV |
792 | () |
793 | { | |
794 | int i; | |
fbd6baed | 795 | colormap_t *pc = w32_color_map; |
ee78dc32 | 796 | Lisp_Object cmap; |
7d0393cf | 797 | |
ee78dc32 | 798 | BLOCK_INPUT; |
7d0393cf | 799 | |
ee78dc32 | 800 | cmap = Qnil; |
7d0393cf JB |
801 | |
802 | for (i = 0; i < sizeof (w32_color_map) / sizeof (w32_color_map[0]); | |
ee78dc32 GV |
803 | pc++, i++) |
804 | cmap = Fcons (Fcons (build_string (pc->name), | |
805 | make_number (pc->colorref)), | |
806 | cmap); | |
7d0393cf | 807 | |
ee78dc32 | 808 | UNBLOCK_INPUT; |
7d0393cf | 809 | |
ee78dc32 GV |
810 | return (cmap); |
811 | } | |
ee78dc32 | 812 | |
7d0393cf | 813 | Lisp_Object |
fbd6baed | 814 | w32_to_x_color (rgb) |
ee78dc32 GV |
815 | Lisp_Object rgb; |
816 | { | |
817 | Lisp_Object color; | |
7d0393cf | 818 | |
b7826503 | 819 | CHECK_NUMBER (rgb); |
7d0393cf | 820 | |
ee78dc32 | 821 | BLOCK_INPUT; |
7d0393cf | 822 | |
fbd6baed | 823 | color = Frassq (rgb, Vw32_color_map); |
7d0393cf | 824 | |
ee78dc32 | 825 | UNBLOCK_INPUT; |
7d0393cf | 826 | |
ee78dc32 GV |
827 | if (!NILP (color)) |
828 | return (Fcar (color)); | |
829 | else | |
830 | return Qnil; | |
831 | } | |
832 | ||
2ba49441 | 833 | static Lisp_Object |
5d7fed93 GV |
834 | w32_color_map_lookup (colorname) |
835 | char *colorname; | |
836 | { | |
837 | Lisp_Object tail, ret = Qnil; | |
838 | ||
839 | BLOCK_INPUT; | |
840 | ||
841 | for (tail = Vw32_color_map; !NILP (tail); tail = Fcdr (tail)) | |
842 | { | |
843 | register Lisp_Object elt, tem; | |
844 | ||
845 | elt = Fcar (tail); | |
846 | if (!CONSP (elt)) continue; | |
847 | ||
848 | tem = Fcar (elt); | |
849 | ||
d5db4077 | 850 | if (lstrcmpi (SDATA (tem), colorname) == 0) |
5d7fed93 | 851 | { |
2ba49441 | 852 | ret = Fcdr (elt); |
5d7fed93 GV |
853 | break; |
854 | } | |
855 | ||
856 | QUIT; | |
857 | } | |
858 | ||
859 | ||
860 | UNBLOCK_INPUT; | |
861 | ||
862 | return ret; | |
863 | } | |
864 | ||
5a8a15ec JR |
865 | |
866 | static void | |
867 | add_system_logical_colors_to_map (system_colors) | |
868 | Lisp_Object *system_colors; | |
869 | { | |
870 | HKEY colors_key; | |
871 | ||
872 | /* Other registry operations are done with input blocked. */ | |
873 | BLOCK_INPUT; | |
874 | ||
875 | /* Look for "Control Panel/Colors" under User and Machine registry | |
876 | settings. */ | |
877 | if (RegOpenKeyEx (HKEY_CURRENT_USER, "Control Panel\\Colors", 0, | |
878 | KEY_READ, &colors_key) == ERROR_SUCCESS | |
879 | || RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Control Panel\\Colors", 0, | |
880 | KEY_READ, &colors_key) == ERROR_SUCCESS) | |
881 | { | |
882 | /* List all keys. */ | |
883 | char color_buffer[64]; | |
884 | char full_name_buffer[MAX_PATH + SYSTEM_COLOR_PREFIX_LEN]; | |
885 | int index = 0; | |
886 | DWORD name_size, color_size; | |
887 | char *name_buffer = full_name_buffer + SYSTEM_COLOR_PREFIX_LEN; | |
888 | ||
889 | name_size = sizeof (full_name_buffer) - SYSTEM_COLOR_PREFIX_LEN; | |
890 | color_size = sizeof (color_buffer); | |
891 | ||
892 | strcpy (full_name_buffer, SYSTEM_COLOR_PREFIX); | |
893 | ||
894 | while (RegEnumValueA (colors_key, index, name_buffer, &name_size, | |
895 | NULL, NULL, color_buffer, &color_size) | |
896 | == ERROR_SUCCESS) | |
897 | { | |
898 | int r, g, b; | |
899 | if (sscanf (color_buffer, " %u %u %u", &r, &g, &b) == 3) | |
900 | *system_colors = Fcons (Fcons (build_string (full_name_buffer), | |
901 | make_number (RGB (r, g, b))), | |
902 | *system_colors); | |
903 | ||
904 | name_size = sizeof (full_name_buffer) - SYSTEM_COLOR_PREFIX_LEN; | |
905 | color_size = sizeof (color_buffer); | |
906 | index++; | |
907 | } | |
908 | RegCloseKey (colors_key); | |
909 | } | |
910 | ||
911 | UNBLOCK_INPUT; | |
912 | } | |
913 | ||
914 | ||
2ba49441 | 915 | static Lisp_Object |
fbd6baed | 916 | x_to_w32_color (colorname) |
ee78dc32 GV |
917 | char * colorname; |
918 | { | |
8edb0a6f JR |
919 | register Lisp_Object ret = Qnil; |
920 | ||
ee78dc32 | 921 | BLOCK_INPUT; |
1edf84e7 GV |
922 | |
923 | if (colorname[0] == '#') | |
924 | { | |
925 | /* Could be an old-style RGB Device specification. */ | |
926 | char *color; | |
927 | int size; | |
928 | color = colorname + 1; | |
7d0393cf | 929 | |
1edf84e7 GV |
930 | size = strlen(color); |
931 | if (size == 3 || size == 6 || size == 9 || size == 12) | |
932 | { | |
933 | UINT colorval; | |
934 | int i, pos; | |
935 | pos = 0; | |
936 | size /= 3; | |
937 | colorval = 0; | |
7d0393cf | 938 | |
1edf84e7 GV |
939 | for (i = 0; i < 3; i++) |
940 | { | |
941 | char *end; | |
942 | char t; | |
943 | unsigned long value; | |
944 | ||
945 | /* The check for 'x' in the following conditional takes into | |
946 | account the fact that strtol allows a "0x" in front of | |
947 | our numbers, and we don't. */ | |
948 | if (!isxdigit(color[0]) || color[1] == 'x') | |
949 | break; | |
950 | t = color[size]; | |
951 | color[size] = '\0'; | |
952 | value = strtoul(color, &end, 16); | |
953 | color[size] = t; | |
954 | if (errno == ERANGE || end - color != size) | |
955 | break; | |
956 | switch (size) | |
957 | { | |
958 | case 1: | |
959 | value = value * 0x10; | |
960 | break; | |
961 | case 2: | |
962 | break; | |
963 | case 3: | |
964 | value /= 0x10; | |
965 | break; | |
966 | case 4: | |
967 | value /= 0x100; | |
968 | break; | |
969 | } | |
970 | colorval |= (value << pos); | |
971 | pos += 0x8; | |
972 | if (i == 2) | |
973 | { | |
974 | UNBLOCK_INPUT; | |
2ba49441 JR |
975 | XSETINT (ret, colorval); |
976 | return ret; | |
1edf84e7 GV |
977 | } |
978 | color = end; | |
979 | } | |
980 | } | |
981 | } | |
982 | else if (strnicmp(colorname, "rgb:", 4) == 0) | |
983 | { | |
984 | char *color; | |
985 | UINT colorval; | |
986 | int i, pos; | |
987 | pos = 0; | |
988 | ||
989 | colorval = 0; | |
990 | color = colorname + 4; | |
991 | for (i = 0; i < 3; i++) | |
992 | { | |
993 | char *end; | |
994 | unsigned long value; | |
7d0393cf | 995 | |
1edf84e7 GV |
996 | /* The check for 'x' in the following conditional takes into |
997 | account the fact that strtol allows a "0x" in front of | |
998 | our numbers, and we don't. */ | |
999 | if (!isxdigit(color[0]) || color[1] == 'x') | |
1000 | break; | |
1001 | value = strtoul(color, &end, 16); | |
1002 | if (errno == ERANGE) | |
1003 | break; | |
1004 | switch (end - color) | |
1005 | { | |
1006 | case 1: | |
1007 | value = value * 0x10 + value; | |
1008 | break; | |
1009 | case 2: | |
1010 | break; | |
1011 | case 3: | |
1012 | value /= 0x10; | |
1013 | break; | |
1014 | case 4: | |
1015 | value /= 0x100; | |
1016 | break; | |
1017 | default: | |
1018 | value = ULONG_MAX; | |
1019 | } | |
1020 | if (value == ULONG_MAX) | |
1021 | break; | |
1022 | colorval |= (value << pos); | |
1023 | pos += 0x8; | |
1024 | if (i == 2) | |
1025 | { | |
1026 | if (*end != '\0') | |
1027 | break; | |
1028 | UNBLOCK_INPUT; | |
2ba49441 JR |
1029 | XSETINT (ret, colorval); |
1030 | return ret; | |
1edf84e7 GV |
1031 | } |
1032 | if (*end != '/') | |
1033 | break; | |
1034 | color = end + 1; | |
1035 | } | |
1036 | } | |
1037 | else if (strnicmp(colorname, "rgbi:", 5) == 0) | |
1038 | { | |
1039 | /* This is an RGB Intensity specification. */ | |
1040 | char *color; | |
1041 | UINT colorval; | |
1042 | int i, pos; | |
1043 | pos = 0; | |
1044 | ||
1045 | colorval = 0; | |
1046 | color = colorname + 5; | |
1047 | for (i = 0; i < 3; i++) | |
1048 | { | |
1049 | char *end; | |
1050 | double value; | |
1051 | UINT val; | |
1052 | ||
1053 | value = strtod(color, &end); | |
1054 | if (errno == ERANGE) | |
1055 | break; | |
1056 | if (value < 0.0 || value > 1.0) | |
1057 | break; | |
1058 | val = (UINT)(0x100 * value); | |
7d0393cf | 1059 | /* We used 0x100 instead of 0xFF to give a continuous |
1edf84e7 GV |
1060 | range between 0.0 and 1.0 inclusive. The next statement |
1061 | fixes the 1.0 case. */ | |
1062 | if (val == 0x100) | |
1063 | val = 0xFF; | |
1064 | colorval |= (val << pos); | |
1065 | pos += 0x8; | |
1066 | if (i == 2) | |
1067 | { | |
1068 | if (*end != '\0') | |
1069 | break; | |
1070 | UNBLOCK_INPUT; | |
2ba49441 JR |
1071 | XSETINT (ret, colorval); |
1072 | return ret; | |
1edf84e7 GV |
1073 | } |
1074 | if (*end != '/') | |
1075 | break; | |
1076 | color = end + 1; | |
1077 | } | |
1078 | } | |
1079 | /* I am not going to attempt to handle any of the CIE color schemes | |
1080 | or TekHVC, since I don't know the algorithms for conversion to | |
1081 | RGB. */ | |
f695b4b1 GV |
1082 | |
1083 | /* If we fail to lookup the color name in w32_color_map, then check the | |
7d0393cf | 1084 | colorname to see if it can be crudely approximated: If the X color |
f695b4b1 GV |
1085 | ends in a number (e.g., "darkseagreen2"), strip the number and |
1086 | return the result of looking up the base color name. */ | |
1087 | ret = w32_color_map_lookup (colorname); | |
7d0393cf | 1088 | if (NILP (ret)) |
ee78dc32 | 1089 | { |
f695b4b1 | 1090 | int len = strlen (colorname); |
ee78dc32 | 1091 | |
7d0393cf | 1092 | if (isdigit (colorname[len - 1])) |
f695b4b1 | 1093 | { |
8b77111c | 1094 | char *ptr, *approx = alloca (len + 1); |
ee78dc32 | 1095 | |
f695b4b1 GV |
1096 | strcpy (approx, colorname); |
1097 | ptr = &approx[len - 1]; | |
7d0393cf | 1098 | while (ptr > approx && isdigit (*ptr)) |
f695b4b1 | 1099 | *ptr-- = '\0'; |
ee78dc32 | 1100 | |
f695b4b1 | 1101 | ret = w32_color_map_lookup (approx); |
ee78dc32 | 1102 | } |
ee78dc32 | 1103 | } |
7d0393cf | 1104 | |
ee78dc32 | 1105 | UNBLOCK_INPUT; |
ee78dc32 GV |
1106 | return ret; |
1107 | } | |
1108 | ||
5ac45f98 | 1109 | void |
fbd6baed | 1110 | w32_regenerate_palette (FRAME_PTR f) |
5ac45f98 | 1111 | { |
fbd6baed | 1112 | struct w32_palette_entry * list; |
5ac45f98 GV |
1113 | LOGPALETTE * log_palette; |
1114 | HPALETTE new_palette; | |
1115 | int i; | |
1116 | ||
1117 | /* don't bother trying to create palette if not supported */ | |
fbd6baed | 1118 | if (! FRAME_W32_DISPLAY_INFO (f)->has_palette) |
5ac45f98 GV |
1119 | return; |
1120 | ||
1121 | log_palette = (LOGPALETTE *) | |
1122 | alloca (sizeof (LOGPALETTE) + | |
fbd6baed | 1123 | FRAME_W32_DISPLAY_INFO (f)->num_colors * sizeof (PALETTEENTRY)); |
5ac45f98 | 1124 | log_palette->palVersion = 0x300; |
fbd6baed | 1125 | log_palette->palNumEntries = FRAME_W32_DISPLAY_INFO (f)->num_colors; |
5ac45f98 | 1126 | |
fbd6baed | 1127 | list = FRAME_W32_DISPLAY_INFO (f)->color_list; |
5ac45f98 | 1128 | for (i = 0; |
fbd6baed | 1129 | i < FRAME_W32_DISPLAY_INFO (f)->num_colors; |
5ac45f98 GV |
1130 | i++, list = list->next) |
1131 | log_palette->palPalEntry[i] = list->entry; | |
1132 | ||
1133 | new_palette = CreatePalette (log_palette); | |
1134 | ||
1135 | enter_crit (); | |
1136 | ||
fbd6baed GV |
1137 | if (FRAME_W32_DISPLAY_INFO (f)->palette) |
1138 | DeleteObject (FRAME_W32_DISPLAY_INFO (f)->palette); | |
1139 | FRAME_W32_DISPLAY_INFO (f)->palette = new_palette; | |
5ac45f98 GV |
1140 | |
1141 | /* Realize display palette and garbage all frames. */ | |
1142 | release_frame_dc (f, get_frame_dc (f)); | |
1143 | ||
1144 | leave_crit (); | |
1145 | } | |
1146 | ||
fbd6baed GV |
1147 | #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue) |
1148 | #define SET_W32_COLOR(pe, color) \ | |
5ac45f98 GV |
1149 | do \ |
1150 | { \ | |
1151 | pe.peRed = GetRValue (color); \ | |
1152 | pe.peGreen = GetGValue (color); \ | |
1153 | pe.peBlue = GetBValue (color); \ | |
1154 | pe.peFlags = 0; \ | |
1155 | } while (0) | |
1156 | ||
1157 | #if 0 | |
1158 | /* Keep these around in case we ever want to track color usage. */ | |
1159 | void | |
fbd6baed | 1160 | w32_map_color (FRAME_PTR f, COLORREF color) |
5ac45f98 | 1161 | { |
fbd6baed | 1162 | struct w32_palette_entry * list = FRAME_W32_DISPLAY_INFO (f)->color_list; |
5ac45f98 | 1163 | |
fbd6baed | 1164 | if (NILP (Vw32_enable_palette)) |
5ac45f98 GV |
1165 | return; |
1166 | ||
1167 | /* check if color is already mapped */ | |
1168 | while (list) | |
1169 | { | |
fbd6baed | 1170 | if (W32_COLOR (list->entry) == color) |
5ac45f98 GV |
1171 | { |
1172 | ++list->refcount; | |
1173 | return; | |
1174 | } | |
1175 | list = list->next; | |
1176 | } | |
1177 | ||
1178 | /* not already mapped, so add to list and recreate Windows palette */ | |
fbd6baed GV |
1179 | list = (struct w32_palette_entry *) |
1180 | xmalloc (sizeof (struct w32_palette_entry)); | |
1181 | SET_W32_COLOR (list->entry, color); | |
5ac45f98 | 1182 | list->refcount = 1; |
fbd6baed GV |
1183 | list->next = FRAME_W32_DISPLAY_INFO (f)->color_list; |
1184 | FRAME_W32_DISPLAY_INFO (f)->color_list = list; | |
1185 | FRAME_W32_DISPLAY_INFO (f)->num_colors++; | |
5ac45f98 GV |
1186 | |
1187 | /* set flag that palette must be regenerated */ | |
fbd6baed | 1188 | FRAME_W32_DISPLAY_INFO (f)->regen_palette = TRUE; |
5ac45f98 GV |
1189 | } |
1190 | ||
1191 | void | |
fbd6baed | 1192 | w32_unmap_color (FRAME_PTR f, COLORREF color) |
5ac45f98 | 1193 | { |
fbd6baed GV |
1194 | struct w32_palette_entry * list = FRAME_W32_DISPLAY_INFO (f)->color_list; |
1195 | struct w32_palette_entry **prev = &FRAME_W32_DISPLAY_INFO (f)->color_list; | |
5ac45f98 | 1196 | |
fbd6baed | 1197 | if (NILP (Vw32_enable_palette)) |
5ac45f98 GV |
1198 | return; |
1199 | ||
1200 | /* check if color is already mapped */ | |
1201 | while (list) | |
1202 | { | |
fbd6baed | 1203 | if (W32_COLOR (list->entry) == color) |
5ac45f98 GV |
1204 | { |
1205 | if (--list->refcount == 0) | |
1206 | { | |
1207 | *prev = list->next; | |
1208 | xfree (list); | |
fbd6baed | 1209 | FRAME_W32_DISPLAY_INFO (f)->num_colors--; |
5ac45f98 GV |
1210 | break; |
1211 | } | |
1212 | else | |
1213 | return; | |
1214 | } | |
1215 | prev = &list->next; | |
1216 | list = list->next; | |
1217 | } | |
1218 | ||
1219 | /* set flag that palette must be regenerated */ | |
fbd6baed | 1220 | FRAME_W32_DISPLAY_INFO (f)->regen_palette = TRUE; |
5ac45f98 GV |
1221 | } |
1222 | #endif | |
1223 | ||
6fc2811b JR |
1224 | |
1225 | /* Gamma-correct COLOR on frame F. */ | |
1226 | ||
1227 | void | |
1228 | gamma_correct (f, color) | |
1229 | struct frame *f; | |
1230 | COLORREF *color; | |
1231 | { | |
1232 | if (f->gamma) | |
1233 | { | |
1234 | *color = PALETTERGB ( | |
1235 | pow (GetRValue (*color) / 255.0, f->gamma) * 255.0 + 0.5, | |
1236 | pow (GetGValue (*color) / 255.0, f->gamma) * 255.0 + 0.5, | |
1237 | pow (GetBValue (*color) / 255.0, f->gamma) * 255.0 + 0.5); | |
1238 | } | |
1239 | } | |
1240 | ||
1241 | ||
ee78dc32 GV |
1242 | /* Decide if color named COLOR is valid for the display associated with |
1243 | the selected frame; if so, return the rgb values in COLOR_DEF. | |
1244 | If ALLOC is nonzero, allocate a new colormap cell. */ | |
1245 | ||
1246 | int | |
6fc2811b | 1247 | w32_defined_color (f, color, color_def, alloc) |
ee78dc32 GV |
1248 | FRAME_PTR f; |
1249 | char *color; | |
6fc2811b | 1250 | XColor *color_def; |
ee78dc32 GV |
1251 | int alloc; |
1252 | { | |
1253 | register Lisp_Object tem; | |
6fc2811b | 1254 | COLORREF w32_color_ref; |
3c190163 | 1255 | |
fbd6baed | 1256 | tem = x_to_w32_color (color); |
3c190163 | 1257 | |
7d0393cf | 1258 | if (!NILP (tem)) |
ee78dc32 | 1259 | { |
d88c567c JR |
1260 | if (f) |
1261 | { | |
1262 | /* Apply gamma correction. */ | |
1263 | w32_color_ref = XUINT (tem); | |
1264 | gamma_correct (f, &w32_color_ref); | |
1265 | XSETINT (tem, w32_color_ref); | |
1266 | } | |
9badad41 JR |
1267 | |
1268 | /* Map this color to the palette if it is enabled. */ | |
fbd6baed | 1269 | if (!NILP (Vw32_enable_palette)) |
5ac45f98 | 1270 | { |
fbd6baed | 1271 | struct w32_palette_entry * entry = |
d88c567c | 1272 | one_w32_display_info.color_list; |
fbd6baed | 1273 | struct w32_palette_entry ** prev = |
d88c567c | 1274 | &one_w32_display_info.color_list; |
7d0393cf | 1275 | |
5ac45f98 GV |
1276 | /* check if color is already mapped */ |
1277 | while (entry) | |
1278 | { | |
fbd6baed | 1279 | if (W32_COLOR (entry->entry) == XUINT (tem)) |
5ac45f98 GV |
1280 | break; |
1281 | prev = &entry->next; | |
1282 | entry = entry->next; | |
1283 | } | |
1284 | ||
1285 | if (entry == NULL && alloc) | |
1286 | { | |
1287 | /* not already mapped, so add to list */ | |
fbd6baed GV |
1288 | entry = (struct w32_palette_entry *) |
1289 | xmalloc (sizeof (struct w32_palette_entry)); | |
1290 | SET_W32_COLOR (entry->entry, XUINT (tem)); | |
5ac45f98 GV |
1291 | entry->next = NULL; |
1292 | *prev = entry; | |
d88c567c | 1293 | one_w32_display_info.num_colors++; |
5ac45f98 GV |
1294 | |
1295 | /* set flag that palette must be regenerated */ | |
d88c567c | 1296 | one_w32_display_info.regen_palette = TRUE; |
5ac45f98 GV |
1297 | } |
1298 | } | |
1299 | /* Ensure COLORREF value is snapped to nearest color in (default) | |
1300 | palette by simulating the PALETTERGB macro. This works whether | |
1301 | or not the display device has a palette. */ | |
6fc2811b JR |
1302 | w32_color_ref = XUINT (tem) | 0x2000000; |
1303 | ||
6fc2811b | 1304 | color_def->pixel = w32_color_ref; |
197edd35 JR |
1305 | color_def->red = GetRValue (w32_color_ref) * 256; |
1306 | color_def->green = GetGValue (w32_color_ref) * 256; | |
1307 | color_def->blue = GetBValue (w32_color_ref) * 256; | |
6fc2811b | 1308 | |
ee78dc32 | 1309 | return 1; |
5ac45f98 | 1310 | } |
7d0393cf | 1311 | else |
3c190163 GV |
1312 | { |
1313 | return 0; | |
1314 | } | |
ee78dc32 GV |
1315 | } |
1316 | ||
1317 | /* Given a string ARG naming a color, compute a pixel value from it | |
1318 | suitable for screen F. | |
1319 | If F is not a color screen, return DEF (default) regardless of what | |
1320 | ARG says. */ | |
1321 | ||
1322 | int | |
1323 | x_decode_color (f, arg, def) | |
1324 | FRAME_PTR f; | |
1325 | Lisp_Object arg; | |
1326 | int def; | |
1327 | { | |
6fc2811b | 1328 | XColor cdef; |
ee78dc32 | 1329 | |
b7826503 | 1330 | CHECK_STRING (arg); |
ee78dc32 | 1331 | |
d5db4077 | 1332 | if (strcmp (SDATA (arg), "black") == 0) |
ee78dc32 | 1333 | return BLACK_PIX_DEFAULT (f); |
d5db4077 | 1334 | else if (strcmp (SDATA (arg), "white") == 0) |
ee78dc32 GV |
1335 | return WHITE_PIX_DEFAULT (f); |
1336 | ||
fbd6baed | 1337 | if ((FRAME_W32_DISPLAY_INFO (f)->n_planes * FRAME_W32_DISPLAY_INFO (f)->n_cbits) == 1) |
ee78dc32 GV |
1338 | return def; |
1339 | ||
6fc2811b | 1340 | /* w32_defined_color is responsible for coping with failures |
ee78dc32 | 1341 | by looking for a near-miss. */ |
d5db4077 | 1342 | if (w32_defined_color (f, SDATA (arg), &cdef, 1)) |
6fc2811b | 1343 | return cdef.pixel; |
ee78dc32 GV |
1344 | |
1345 | /* defined_color failed; return an ultimate default. */ | |
1346 | return def; | |
1347 | } | |
1348 | \f | |
6fc2811b JR |
1349 | |
1350 | ||
ee78dc32 GV |
1351 | /* Functions called only from `x_set_frame_param' |
1352 | to set individual parameters. | |
1353 | ||
fbd6baed | 1354 | If FRAME_W32_WINDOW (f) is 0, |
ee78dc32 GV |
1355 | the frame is being created and its window does not exist yet. |
1356 | In that case, just record the parameter's new value | |
1357 | in the standard place; do not attempt to change the window. */ | |
1358 | ||
1359 | void | |
1360 | x_set_foreground_color (f, arg, oldval) | |
1361 | struct frame *f; | |
1362 | Lisp_Object arg, oldval; | |
1363 | { | |
3cf3436e JR |
1364 | struct w32_output *x = f->output_data.w32; |
1365 | PIX_TYPE fg, old_fg; | |
1366 | ||
1367 | fg = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); | |
1368 | old_fg = FRAME_FOREGROUND_PIXEL (f); | |
1369 | FRAME_FOREGROUND_PIXEL (f) = fg; | |
5ac45f98 | 1370 | |
fbd6baed | 1371 | if (FRAME_W32_WINDOW (f) != 0) |
ee78dc32 | 1372 | { |
3cf3436e JR |
1373 | if (x->cursor_pixel == old_fg) |
1374 | x->cursor_pixel = fg; | |
1375 | ||
6fc2811b | 1376 | update_face_from_frame_parameter (f, Qforeground_color, arg); |
ee78dc32 GV |
1377 | if (FRAME_VISIBLE_P (f)) |
1378 | redraw_frame (f); | |
1379 | } | |
1380 | } | |
1381 | ||
1382 | void | |
1383 | x_set_background_color (f, arg, oldval) | |
1384 | struct frame *f; | |
1385 | Lisp_Object arg, oldval; | |
1386 | { | |
6fc2811b | 1387 | FRAME_BACKGROUND_PIXEL (f) |
ee78dc32 GV |
1388 | = x_decode_color (f, arg, WHITE_PIX_DEFAULT (f)); |
1389 | ||
fbd6baed | 1390 | if (FRAME_W32_WINDOW (f) != 0) |
ee78dc32 | 1391 | { |
6fc2811b JR |
1392 | SetWindowLong (FRAME_W32_WINDOW (f), WND_BACKGROUND_INDEX, |
1393 | FRAME_BACKGROUND_PIXEL (f)); | |
ee78dc32 | 1394 | |
6fc2811b | 1395 | update_face_from_frame_parameter (f, Qbackground_color, arg); |
ee78dc32 GV |
1396 | |
1397 | if (FRAME_VISIBLE_P (f)) | |
1398 | redraw_frame (f); | |
1399 | } | |
1400 | } | |
1401 | ||
1402 | void | |
1403 | x_set_mouse_color (f, arg, oldval) | |
1404 | struct frame *f; | |
1405 | Lisp_Object arg, oldval; | |
1406 | { | |
7d63e5e3 | 1407 | Cursor cursor, nontext_cursor, mode_cursor, hand_cursor; |
dfc465d3 | 1408 | int count; |
ee78dc32 GV |
1409 | int mask_color; |
1410 | ||
1411 | if (!EQ (Qnil, arg)) | |
fbd6baed | 1412 | f->output_data.w32->mouse_pixel |
ee78dc32 | 1413 | = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); |
6fc2811b JR |
1414 | mask_color = FRAME_BACKGROUND_PIXEL (f); |
1415 | ||
1416 | /* Don't let pointers be invisible. */ | |
fbd6baed | 1417 | if (mask_color == f->output_data.w32->mouse_pixel |
6fc2811b JR |
1418 | && mask_color == FRAME_BACKGROUND_PIXEL (f)) |
1419 | f->output_data.w32->mouse_pixel = FRAME_FOREGROUND_PIXEL (f); | |
ee78dc32 | 1420 | |
767b1ff0 | 1421 | #if 0 /* TODO : cursor changes */ |
ee78dc32 GV |
1422 | BLOCK_INPUT; |
1423 | ||
1424 | /* It's not okay to crash if the user selects a screwy cursor. */ | |
fadca6c6 | 1425 | count = x_catch_errors (FRAME_W32_DISPLAY (f)); |
ee78dc32 GV |
1426 | |
1427 | if (!EQ (Qnil, Vx_pointer_shape)) | |
1428 | { | |
b7826503 | 1429 | CHECK_NUMBER (Vx_pointer_shape); |
fbd6baed | 1430 | cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XINT (Vx_pointer_shape)); |
ee78dc32 GV |
1431 | } |
1432 | else | |
fbd6baed GV |
1433 | cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XC_xterm); |
1434 | x_check_errors (FRAME_W32_DISPLAY (f), "bad text pointer cursor: %s"); | |
ee78dc32 GV |
1435 | |
1436 | if (!EQ (Qnil, Vx_nontext_pointer_shape)) | |
1437 | { | |
b7826503 | 1438 | CHECK_NUMBER (Vx_nontext_pointer_shape); |
fbd6baed | 1439 | nontext_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), |
ee78dc32 GV |
1440 | XINT (Vx_nontext_pointer_shape)); |
1441 | } | |
1442 | else | |
fbd6baed GV |
1443 | nontext_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XC_left_ptr); |
1444 | x_check_errors (FRAME_W32_DISPLAY (f), "bad nontext pointer cursor: %s"); | |
ee78dc32 | 1445 | |
0af913d7 | 1446 | if (!EQ (Qnil, Vx_hourglass_pointer_shape)) |
6fc2811b | 1447 | { |
b7826503 | 1448 | CHECK_NUMBER (Vx_hourglass_pointer_shape); |
0af913d7 GM |
1449 | hourglass_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), |
1450 | XINT (Vx_hourglass_pointer_shape)); | |
6fc2811b JR |
1451 | } |
1452 | else | |
0af913d7 | 1453 | hourglass_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XC_watch); |
6fc2811b | 1454 | x_check_errors (FRAME_W32_DISPLAY (f), "bad busy pointer cursor: %s"); |
7d0393cf | 1455 | |
6fc2811b | 1456 | x_check_errors (FRAME_W32_DISPLAY (f), "bad nontext pointer cursor: %s"); |
ee78dc32 GV |
1457 | if (!EQ (Qnil, Vx_mode_pointer_shape)) |
1458 | { | |
b7826503 | 1459 | CHECK_NUMBER (Vx_mode_pointer_shape); |
fbd6baed | 1460 | mode_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), |
ee78dc32 GV |
1461 | XINT (Vx_mode_pointer_shape)); |
1462 | } | |
1463 | else | |
fbd6baed GV |
1464 | mode_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XC_xterm); |
1465 | x_check_errors (FRAME_W32_DISPLAY (f), "bad modeline pointer cursor: %s"); | |
ee78dc32 GV |
1466 | |
1467 | if (!EQ (Qnil, Vx_sensitive_text_pointer_shape)) | |
1468 | { | |
b7826503 | 1469 | CHECK_NUMBER (Vx_sensitive_text_pointer_shape); |
7d63e5e3 | 1470 | hand_cursor |
fbd6baed | 1471 | = XCreateFontCursor (FRAME_W32_DISPLAY (f), |
ee78dc32 GV |
1472 | XINT (Vx_sensitive_text_pointer_shape)); |
1473 | } | |
1474 | else | |
7d63e5e3 | 1475 | hand_cursor = XCreateFontCursor (FRAME_W32_DISPLAY (f), XC_crosshair); |
ee78dc32 | 1476 | |
4694d762 JR |
1477 | if (!NILP (Vx_window_horizontal_drag_shape)) |
1478 | { | |
b7826503 | 1479 | CHECK_NUMBER (Vx_window_horizontal_drag_shape); |
4694d762 JR |
1480 | horizontal_drag_cursor |
1481 | = XCreateFontCursor (FRAME_X_DISPLAY (f), | |
1482 | XINT (Vx_window_horizontal_drag_shape)); | |
1483 | } | |
1484 | else | |
1485 | horizontal_drag_cursor | |
1486 | = XCreateFontCursor (FRAME_X_DISPLAY (f), XC_sb_h_double_arrow); | |
1487 | ||
ee78dc32 | 1488 | /* Check and report errors with the above calls. */ |
fbd6baed | 1489 | x_check_errors (FRAME_W32_DISPLAY (f), "can't set cursor shape: %s"); |
fadca6c6 | 1490 | x_uncatch_errors (FRAME_W32_DISPLAY (f), count); |
ee78dc32 GV |
1491 | |
1492 | { | |
1493 | XColor fore_color, back_color; | |
1494 | ||
fbd6baed | 1495 | fore_color.pixel = f->output_data.w32->mouse_pixel; |
ee78dc32 | 1496 | back_color.pixel = mask_color; |
fbd6baed GV |
1497 | XQueryColor (FRAME_W32_DISPLAY (f), |
1498 | DefaultColormap (FRAME_W32_DISPLAY (f), | |
1499 | DefaultScreen (FRAME_W32_DISPLAY (f))), | |
ee78dc32 | 1500 | &fore_color); |
fbd6baed GV |
1501 | XQueryColor (FRAME_W32_DISPLAY (f), |
1502 | DefaultColormap (FRAME_W32_DISPLAY (f), | |
1503 | DefaultScreen (FRAME_W32_DISPLAY (f))), | |
ee78dc32 | 1504 | &back_color); |
fbd6baed | 1505 | XRecolorCursor (FRAME_W32_DISPLAY (f), cursor, |
ee78dc32 | 1506 | &fore_color, &back_color); |
fbd6baed | 1507 | XRecolorCursor (FRAME_W32_DISPLAY (f), nontext_cursor, |
ee78dc32 | 1508 | &fore_color, &back_color); |
fbd6baed | 1509 | XRecolorCursor (FRAME_W32_DISPLAY (f), mode_cursor, |
ee78dc32 | 1510 | &fore_color, &back_color); |
7d63e5e3 | 1511 | XRecolorCursor (FRAME_W32_DISPLAY (f), hand_cursor, |
ee78dc32 | 1512 | &fore_color, &back_color); |
0af913d7 | 1513 | XRecolorCursor (FRAME_W32_DISPLAY (f), hourglass_cursor, |
6fc2811b | 1514 | &fore_color, &back_color); |
ee78dc32 GV |
1515 | } |
1516 | ||
fbd6baed | 1517 | if (FRAME_W32_WINDOW (f) != 0) |
6fc2811b | 1518 | XDefineCursor (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), cursor); |
ee78dc32 | 1519 | |
fbd6baed GV |
1520 | if (cursor != f->output_data.w32->text_cursor && f->output_data.w32->text_cursor != 0) |
1521 | XFreeCursor (FRAME_W32_DISPLAY (f), f->output_data.w32->text_cursor); | |
1522 | f->output_data.w32->text_cursor = cursor; | |
1523 | ||
1524 | if (nontext_cursor != f->output_data.w32->nontext_cursor | |
1525 | && f->output_data.w32->nontext_cursor != 0) | |
1526 | XFreeCursor (FRAME_W32_DISPLAY (f), f->output_data.w32->nontext_cursor); | |
1527 | f->output_data.w32->nontext_cursor = nontext_cursor; | |
1528 | ||
0af913d7 GM |
1529 | if (hourglass_cursor != f->output_data.w32->hourglass_cursor |
1530 | && f->output_data.w32->hourglass_cursor != 0) | |
1531 | XFreeCursor (FRAME_W32_DISPLAY (f), f->output_data.w32->hourglass_cursor); | |
1532 | f->output_data.w32->hourglass_cursor = hourglass_cursor; | |
6fc2811b | 1533 | |
fbd6baed GV |
1534 | if (mode_cursor != f->output_data.w32->modeline_cursor |
1535 | && f->output_data.w32->modeline_cursor != 0) | |
1536 | XFreeCursor (FRAME_W32_DISPLAY (f), f->output_data.w32->modeline_cursor); | |
1537 | f->output_data.w32->modeline_cursor = mode_cursor; | |
7d0393cf | 1538 | |
7d63e5e3 KS |
1539 | if (hand_cursor != f->output_data.w32->hand_cursor |
1540 | && f->output_data.w32->hand_cursor != 0) | |
1541 | XFreeCursor (FRAME_W32_DISPLAY (f), f->output_data.w32->hand_cursor); | |
1542 | f->output_data.w32->hand_cursor = hand_cursor; | |
fbd6baed GV |
1543 | |
1544 | XFlush (FRAME_W32_DISPLAY (f)); | |
ee78dc32 | 1545 | UNBLOCK_INPUT; |
6fc2811b JR |
1546 | |
1547 | update_face_from_frame_parameter (f, Qmouse_color, arg); | |
767b1ff0 | 1548 | #endif /* TODO */ |
ee78dc32 GV |
1549 | } |
1550 | ||
70a0239a | 1551 | /* Defined in w32term.c. */ |
ee78dc32 GV |
1552 | void |
1553 | x_set_cursor_color (f, arg, oldval) | |
1554 | struct frame *f; | |
1555 | Lisp_Object arg, oldval; | |
1556 | { | |
70a0239a | 1557 | unsigned long fore_pixel, pixel; |
ee78dc32 | 1558 | |
dfff8a69 | 1559 | if (!NILP (Vx_cursor_fore_pixel)) |
ee78dc32 | 1560 | fore_pixel = x_decode_color (f, Vx_cursor_fore_pixel, |
70a0239a | 1561 | WHITE_PIX_DEFAULT (f)); |
ee78dc32 | 1562 | else |
6fc2811b | 1563 | fore_pixel = FRAME_BACKGROUND_PIXEL (f); |
70a0239a | 1564 | |
6759f872 | 1565 | pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); |
7d0393cf | 1566 | |
ee78dc32 | 1567 | /* Make sure that the cursor color differs from the background color. */ |
70a0239a | 1568 | if (pixel == FRAME_BACKGROUND_PIXEL (f)) |
ee78dc32 | 1569 | { |
70a0239a JR |
1570 | pixel = f->output_data.w32->mouse_pixel; |
1571 | if (pixel == fore_pixel) | |
6fc2811b | 1572 | fore_pixel = FRAME_BACKGROUND_PIXEL (f); |
ee78dc32 | 1573 | } |
70a0239a | 1574 | |
ac849ba4 | 1575 | f->output_data.w32->cursor_foreground_pixel = fore_pixel; |
70a0239a | 1576 | f->output_data.w32->cursor_pixel = pixel; |
ee78dc32 | 1577 | |
fbd6baed | 1578 | if (FRAME_W32_WINDOW (f) != 0) |
ee78dc32 | 1579 | { |
0327b4cc JR |
1580 | BLOCK_INPUT; |
1581 | /* Update frame's cursor_gc. */ | |
1582 | f->output_data.w32->cursor_gc->foreground = fore_pixel; | |
1583 | f->output_data.w32->cursor_gc->background = pixel; | |
1584 | ||
1585 | UNBLOCK_INPUT; | |
1586 | ||
ee78dc32 GV |
1587 | if (FRAME_VISIBLE_P (f)) |
1588 | { | |
70a0239a JR |
1589 | x_update_cursor (f, 0); |
1590 | x_update_cursor (f, 1); | |
ee78dc32 GV |
1591 | } |
1592 | } | |
6fc2811b JR |
1593 | |
1594 | update_face_from_frame_parameter (f, Qcursor_color, arg); | |
ee78dc32 GV |
1595 | } |
1596 | ||
33d52f9c GV |
1597 | /* Set the border-color of frame F to pixel value PIX. |
1598 | Note that this does not fully take effect if done before | |
7d0393cf | 1599 | F has a window. */ |
6d906347 | 1600 | |
33d52f9c GV |
1601 | void |
1602 | x_set_border_pixel (f, pix) | |
1603 | struct frame *f; | |
1604 | int pix; | |
1605 | { | |
6d906347 | 1606 | |
33d52f9c GV |
1607 | f->output_data.w32->border_pixel = pix; |
1608 | ||
be786000 | 1609 | if (FRAME_W32_WINDOW (f) != 0 && f->border_width > 0) |
33d52f9c GV |
1610 | { |
1611 | if (FRAME_VISIBLE_P (f)) | |
1612 | redraw_frame (f); | |
1613 | } | |
1614 | } | |
1615 | ||
ee78dc32 GV |
1616 | /* Set the border-color of frame F to value described by ARG. |
1617 | ARG can be a string naming a color. | |
1618 | The border-color is used for the border that is drawn by the server. | |
1619 | Note that this does not fully take effect if done before | |
1620 | F has a window; it must be redone when the window is created. */ | |
1621 | ||
1622 | void | |
1623 | x_set_border_color (f, arg, oldval) | |
1624 | struct frame *f; | |
1625 | Lisp_Object arg, oldval; | |
1626 | { | |
ee78dc32 GV |
1627 | int pix; |
1628 | ||
b7826503 | 1629 | CHECK_STRING (arg); |
ee78dc32 | 1630 | pix = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); |
ee78dc32 | 1631 | x_set_border_pixel (f, pix); |
6fc2811b | 1632 | update_face_from_frame_parameter (f, Qborder_color, arg); |
ee78dc32 GV |
1633 | } |
1634 | ||
dfff8a69 JR |
1635 | |
1636 | void | |
1637 | x_set_cursor_type (f, arg, oldval) | |
1638 | FRAME_PTR f; | |
1639 | Lisp_Object arg, oldval; | |
1640 | { | |
50e363e6 | 1641 | set_frame_cursor_types (f, arg); |
ee78dc32 | 1642 | |
623cdbf2 | 1643 | /* Make sure the cursor gets redrawn. */ |
c922a224 | 1644 | cursor_type_changed = 1; |
ee78dc32 | 1645 | } |
dfff8a69 | 1646 | \f |
ee78dc32 GV |
1647 | void |
1648 | x_set_icon_type (f, arg, oldval) | |
1649 | struct frame *f; | |
1650 | Lisp_Object arg, oldval; | |
1651 | { | |
ee78dc32 GV |
1652 | int result; |
1653 | ||
eb7576ce GV |
1654 | if (NILP (arg) && NILP (oldval)) |
1655 | return; | |
1656 | ||
7d0393cf | 1657 | if (STRINGP (arg) && STRINGP (oldval) |
eb7576ce GV |
1658 | && EQ (Fstring_equal (oldval, arg), Qt)) |
1659 | return; | |
1660 | ||
1661 | if (SYMBOLP (arg) && SYMBOLP (oldval) && EQ (arg, oldval)) | |
ee78dc32 GV |
1662 | return; |
1663 | ||
1664 | BLOCK_INPUT; | |
ee78dc32 | 1665 | |
eb7576ce | 1666 | result = x_bitmap_icon (f, arg); |
ee78dc32 GV |
1667 | if (result) |
1668 | { | |
1669 | UNBLOCK_INPUT; | |
1670 | error ("No icon window available"); | |
1671 | } | |
1672 | ||
ee78dc32 | 1673 | UNBLOCK_INPUT; |
ee78dc32 GV |
1674 | } |
1675 | ||
ee78dc32 GV |
1676 | void |
1677 | x_set_icon_name (f, arg, oldval) | |
1678 | struct frame *f; | |
1679 | Lisp_Object arg, oldval; | |
1680 | { | |
ee78dc32 GV |
1681 | if (STRINGP (arg)) |
1682 | { | |
1683 | if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt)) | |
1684 | return; | |
1685 | } | |
1686 | else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil)) | |
1687 | return; | |
1688 | ||
1689 | f->icon_name = arg; | |
1690 | ||
1691 | #if 0 | |
fbd6baed | 1692 | if (f->output_data.w32->icon_bitmap != 0) |
ee78dc32 GV |
1693 | return; |
1694 | ||
1695 | BLOCK_INPUT; | |
1696 | ||
1697 | result = x_text_icon (f, | |
d5db4077 KR |
1698 | (char *) SDATA ((!NILP (f->icon_name) |
1699 | ? f->icon_name | |
1700 | : !NILP (f->title) | |
1701 | ? f->title | |
1702 | : f->name))); | |
ee78dc32 GV |
1703 | |
1704 | if (result) | |
1705 | { | |
1706 | UNBLOCK_INPUT; | |
1707 | error ("No icon window available"); | |
1708 | } | |
1709 | ||
1710 | /* If the window was unmapped (and its icon was mapped), | |
1711 | the new icon is not mapped, so map the window in its stead. */ | |
1712 | if (FRAME_VISIBLE_P (f)) | |
1713 | { | |
1714 | #ifdef USE_X_TOOLKIT | |
fbd6baed | 1715 | XtPopup (f->output_data.w32->widget, XtGrabNone); |
ee78dc32 | 1716 | #endif |
fbd6baed | 1717 | XMapWindow (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f)); |
ee78dc32 GV |
1718 | } |
1719 | ||
fbd6baed | 1720 | XFlush (FRAME_W32_DISPLAY (f)); |
ee78dc32 GV |
1721 | UNBLOCK_INPUT; |
1722 | #endif | |
1723 | } | |
1724 | ||
a1258667 | 1725 | \f |
ee78dc32 GV |
1726 | void |
1727 | x_set_menu_bar_lines (f, value, oldval) | |
1728 | struct frame *f; | |
1729 | Lisp_Object value, oldval; | |
1730 | { | |
1731 | int nlines; | |
1732 | int olines = FRAME_MENU_BAR_LINES (f); | |
1733 | ||
1734 | /* Right now, menu bars don't work properly in minibuf-only frames; | |
1735 | most of the commands try to apply themselves to the minibuffer | |
6fc2811b | 1736 | frame itself, and get an error because you can't switch buffers |
ee78dc32 GV |
1737 | in or split the minibuffer window. */ |
1738 | if (FRAME_MINIBUF_ONLY_P (f)) | |
1739 | return; | |
1740 | ||
1741 | if (INTEGERP (value)) | |
1742 | nlines = XINT (value); | |
1743 | else | |
1744 | nlines = 0; | |
1745 | ||
1746 | FRAME_MENU_BAR_LINES (f) = 0; | |
1747 | if (nlines) | |
1748 | FRAME_EXTERNAL_MENU_BAR (f) = 1; | |
1749 | else | |
1750 | { | |
1751 | if (FRAME_EXTERNAL_MENU_BAR (f) == 1) | |
1752 | free_frame_menubar (f); | |
1753 | FRAME_EXTERNAL_MENU_BAR (f) = 0; | |
1edf84e7 GV |
1754 | |
1755 | /* Adjust the frame size so that the client (text) dimensions | |
1756 | remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being | |
1757 | set correctly. */ | |
be786000 | 1758 | x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f)); |
6fc2811b | 1759 | do_pending_window_change (0); |
ee78dc32 | 1760 | } |
6fc2811b JR |
1761 | adjust_glyphs (f); |
1762 | } | |
1763 | ||
1764 | ||
1765 | /* Set the number of lines used for the tool bar of frame F to VALUE. | |
1766 | VALUE not an integer, or < 0 means set the lines to zero. OLDVAL | |
1767 | is the old number of tool bar lines. This function changes the | |
1768 | height of all windows on frame F to match the new tool bar height. | |
1769 | The frame's height doesn't change. */ | |
1770 | ||
1771 | void | |
1772 | x_set_tool_bar_lines (f, value, oldval) | |
1773 | struct frame *f; | |
1774 | Lisp_Object value, oldval; | |
1775 | { | |
36f8209a JR |
1776 | int delta, nlines, root_height; |
1777 | Lisp_Object root_window; | |
6fc2811b | 1778 | |
dc220243 JR |
1779 | /* Treat tool bars like menu bars. */ |
1780 | if (FRAME_MINIBUF_ONLY_P (f)) | |
1781 | return; | |
1782 | ||
6fc2811b JR |
1783 | /* Use VALUE only if an integer >= 0. */ |
1784 | if (INTEGERP (value) && XINT (value) >= 0) | |
1785 | nlines = XFASTINT (value); | |
1786 | else | |
1787 | nlines = 0; | |
1788 | ||
1789 | /* Make sure we redisplay all windows in this frame. */ | |
1790 | ++windows_or_buffers_changed; | |
1791 | ||
1792 | delta = nlines - FRAME_TOOL_BAR_LINES (f); | |
36f8209a JR |
1793 | |
1794 | /* Don't resize the tool-bar to more than we have room for. */ | |
1795 | root_window = FRAME_ROOT_WINDOW (f); | |
be786000 | 1796 | root_height = WINDOW_TOTAL_LINES (XWINDOW (root_window)); |
36f8209a JR |
1797 | if (root_height - delta < 1) |
1798 | { | |
1799 | delta = root_height - 1; | |
1800 | nlines = FRAME_TOOL_BAR_LINES (f) + delta; | |
1801 | } | |
1802 | ||
6fc2811b | 1803 | FRAME_TOOL_BAR_LINES (f) = nlines; |
6d906347 | 1804 | change_window_heights (root_window, delta); |
6fc2811b | 1805 | adjust_glyphs (f); |
36f8209a JR |
1806 | |
1807 | /* We also have to make sure that the internal border at the top of | |
1808 | the frame, below the menu bar or tool bar, is redrawn when the | |
1809 | tool bar disappears. This is so because the internal border is | |
1810 | below the tool bar if one is displayed, but is below the menu bar | |
1811 | if there isn't a tool bar. The tool bar draws into the area | |
1812 | below the menu bar. */ | |
1813 | if (FRAME_W32_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0) | |
1814 | { | |
1815 | updating_frame = f; | |
1816 | clear_frame (); | |
1817 | clear_current_matrices (f); | |
1818 | updating_frame = NULL; | |
1819 | } | |
1820 | ||
1821 | /* If the tool bar gets smaller, the internal border below it | |
1822 | has to be cleared. It was formerly part of the display | |
1823 | of the larger tool bar, and updating windows won't clear it. */ | |
1824 | if (delta < 0) | |
1825 | { | |
1826 | int height = FRAME_INTERNAL_BORDER_WIDTH (f); | |
be786000 KS |
1827 | int width = FRAME_PIXEL_WIDTH (f); |
1828 | int y = nlines * FRAME_LINE_HEIGHT (f); | |
36f8209a JR |
1829 | |
1830 | BLOCK_INPUT; | |
1831 | { | |
1832 | HDC hdc = get_frame_dc (f); | |
1833 | w32_clear_area (f, hdc, 0, y, width, height); | |
1834 | release_frame_dc (f, hdc); | |
1835 | } | |
1836 | UNBLOCK_INPUT; | |
3cf3436e JR |
1837 | |
1838 | if (WINDOWP (f->tool_bar_window)) | |
1839 | clear_glyph_matrix (XWINDOW (f->tool_bar_window)->current_matrix); | |
36f8209a | 1840 | } |
ee78dc32 GV |
1841 | } |
1842 | ||
6fc2811b | 1843 | |
ee78dc32 | 1844 | /* Change the name of frame F to NAME. If NAME is nil, set F's name to |
fbd6baed | 1845 | w32_id_name. |
ee78dc32 GV |
1846 | |
1847 | If EXPLICIT is non-zero, that indicates that lisp code is setting the | |
1848 | name; if NAME is a string, set F's name to NAME and set | |
1849 | F->explicit_name; if NAME is Qnil, then clear F->explicit_name. | |
1850 | ||
1851 | If EXPLICIT is zero, that indicates that Emacs redisplay code is | |
1852 | suggesting a new name, which lisp code should override; if | |
1853 | F->explicit_name is set, ignore the new name; otherwise, set it. */ | |
1854 | ||
1855 | void | |
1856 | x_set_name (f, name, explicit) | |
1857 | struct frame *f; | |
1858 | Lisp_Object name; | |
1859 | int explicit; | |
1860 | { | |
7d0393cf | 1861 | /* Make sure that requests from lisp code override requests from |
ee78dc32 GV |
1862 | Emacs redisplay code. */ |
1863 | if (explicit) | |
1864 | { | |
1865 | /* If we're switching from explicit to implicit, we had better | |
1866 | update the mode lines and thereby update the title. */ | |
1867 | if (f->explicit_name && NILP (name)) | |
1868 | update_mode_lines = 1; | |
1869 | ||
1870 | f->explicit_name = ! NILP (name); | |
1871 | } | |
1872 | else if (f->explicit_name) | |
1873 | return; | |
1874 | ||
fbd6baed | 1875 | /* If NAME is nil, set the name to the w32_id_name. */ |
ee78dc32 GV |
1876 | if (NILP (name)) |
1877 | { | |
1878 | /* Check for no change needed in this very common case | |
1879 | before we do any consing. */ | |
fbd6baed | 1880 | if (!strcmp (FRAME_W32_DISPLAY_INFO (f)->w32_id_name, |
d5db4077 | 1881 | SDATA (f->name))) |
ee78dc32 | 1882 | return; |
fbd6baed | 1883 | name = build_string (FRAME_W32_DISPLAY_INFO (f)->w32_id_name); |
ee78dc32 GV |
1884 | } |
1885 | else | |
b7826503 | 1886 | CHECK_STRING (name); |
ee78dc32 GV |
1887 | |
1888 | /* Don't change the name if it's already NAME. */ | |
1889 | if (! NILP (Fstring_equal (name, f->name))) | |
1890 | return; | |
1891 | ||
1edf84e7 GV |
1892 | f->name = name; |
1893 | ||
1894 | /* For setting the frame title, the title parameter should override | |
1895 | the name parameter. */ | |
1896 | if (! NILP (f->title)) | |
1897 | name = f->title; | |
1898 | ||
fbd6baed | 1899 | if (FRAME_W32_WINDOW (f)) |
ee78dc32 | 1900 | { |
6fc2811b | 1901 | if (STRING_MULTIBYTE (name)) |
dfff8a69 | 1902 | name = ENCODE_SYSTEM (name); |
6fc2811b | 1903 | |
ee78dc32 | 1904 | BLOCK_INPUT; |
d5db4077 | 1905 | SetWindowText(FRAME_W32_WINDOW (f), SDATA (name)); |
ee78dc32 GV |
1906 | UNBLOCK_INPUT; |
1907 | } | |
ee78dc32 GV |
1908 | } |
1909 | ||
1910 | /* This function should be called when the user's lisp code has | |
1911 | specified a name for the frame; the name will override any set by the | |
1912 | redisplay code. */ | |
1913 | void | |
1914 | x_explicitly_set_name (f, arg, oldval) | |
1915 | FRAME_PTR f; | |
1916 | Lisp_Object arg, oldval; | |
1917 | { | |
1918 | x_set_name (f, arg, 1); | |
1919 | } | |
1920 | ||
1921 | /* This function should be called by Emacs redisplay code to set the | |
1922 | name; names set this way will never override names set by the user's | |
1923 | lisp code. */ | |
1924 | void | |
1925 | x_implicitly_set_name (f, arg, oldval) | |
1926 | FRAME_PTR f; | |
1927 | Lisp_Object arg, oldval; | |
1928 | { | |
1929 | x_set_name (f, arg, 0); | |
1930 | } | |
1edf84e7 GV |
1931 | \f |
1932 | /* Change the title of frame F to NAME. | |
1933 | If NAME is nil, use the frame name as the title. | |
1934 | ||
1935 | If EXPLICIT is non-zero, that indicates that lisp code is setting the | |
1936 | name; if NAME is a string, set F's name to NAME and set | |
1937 | F->explicit_name; if NAME is Qnil, then clear F->explicit_name. | |
1938 | ||
1939 | If EXPLICIT is zero, that indicates that Emacs redisplay code is | |
1940 | suggesting a new name, which lisp code should override; if | |
1941 | F->explicit_name is set, ignore the new name; otherwise, set it. */ | |
ee78dc32 | 1942 | |
1edf84e7 | 1943 | void |
6fc2811b | 1944 | x_set_title (f, name, old_name) |
1edf84e7 | 1945 | struct frame *f; |
6fc2811b | 1946 | Lisp_Object name, old_name; |
1edf84e7 GV |
1947 | { |
1948 | /* Don't change the title if it's already NAME. */ | |
1949 | if (EQ (name, f->title)) | |
1950 | return; | |
1951 | ||
1952 | update_mode_lines = 1; | |
1953 | ||
1954 | f->title = name; | |
1955 | ||
1956 | if (NILP (name)) | |
1957 | name = f->name; | |
1958 | ||
1959 | if (FRAME_W32_WINDOW (f)) | |
1960 | { | |
6fc2811b | 1961 | if (STRING_MULTIBYTE (name)) |
dfff8a69 | 1962 | name = ENCODE_SYSTEM (name); |
6fc2811b | 1963 | |
1edf84e7 | 1964 | BLOCK_INPUT; |
d5db4077 | 1965 | SetWindowText(FRAME_W32_WINDOW (f), SDATA (name)); |
1edf84e7 GV |
1966 | UNBLOCK_INPUT; |
1967 | } | |
1968 | } | |
ee78dc32 | 1969 | |
ee78dc32 | 1970 | |
19f093e5 | 1971 | void x_set_scroll_bar_default_width (f) |
ee78dc32 | 1972 | struct frame *f; |
ee78dc32 | 1973 | { |
be786000 | 1974 | int wid = FRAME_COLUMN_WIDTH (f); |
6fc2811b | 1975 | |
be786000 KS |
1976 | FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = GetSystemMetrics (SM_CXVSCROLL); |
1977 | FRAME_CONFIG_SCROLL_BAR_COLS (f) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) + | |
1978 | wid - 1) / wid; | |
ee78dc32 | 1979 | } |
6d906347 | 1980 | |
ee78dc32 | 1981 | \f |
7d0393cf | 1982 | /* Subroutines of creating a frame. */ |
ee78dc32 | 1983 | |
ee78dc32 GV |
1984 | |
1985 | /* Return the value of parameter PARAM. | |
1986 | ||
1987 | First search ALIST, then Vdefault_frame_alist, then the X defaults | |
1988 | database, using ATTRIBUTE as the attribute name and CLASS as its class. | |
1989 | ||
1990 | Convert the resource to the type specified by desired_type. | |
1991 | ||
1992 | If no default is specified, return Qunbound. If you call | |
6fc2811b | 1993 | w32_get_arg, make sure you deal with Qunbound in a reasonable way, |
ee78dc32 GV |
1994 | and don't let it get stored in any Lisp-visible variables! */ |
1995 | ||
1996 | static Lisp_Object | |
6fc2811b | 1997 | w32_get_arg (alist, param, attribute, class, type) |
ee78dc32 GV |
1998 | Lisp_Object alist, param; |
1999 | char *attribute; | |
2000 | char *class; | |
2001 | enum resource_types type; | |
2002 | { | |
6d906347 KS |
2003 | return x_get_arg (check_x_display_info (Qnil), |
2004 | alist, param, attribute, class, type); | |
ee78dc32 GV |
2005 | } |
2006 | ||
2007 | \f | |
c9b2104d JR |
2008 | Cursor |
2009 | w32_load_cursor (LPCTSTR name) | |
2010 | { | |
2011 | /* Try first to load cursor from application resource. */ | |
2012 | Cursor cursor = LoadImage ((HINSTANCE) GetModuleHandle(NULL), | |
2013 | name, IMAGE_CURSOR, 0, 0, | |
2014 | LR_DEFAULTCOLOR | LR_DEFAULTSIZE | LR_SHARED); | |
2015 | if (!cursor) | |
2016 | { | |
2017 | /* Then try to load a shared predefined cursor. */ | |
2018 | cursor = LoadImage (NULL, name, IMAGE_CURSOR, 0, 0, | |
2019 | LR_DEFAULTCOLOR | LR_DEFAULTSIZE | LR_SHARED); | |
2020 | } | |
2021 | return cursor; | |
2022 | } | |
ee78dc32 | 2023 | |
fbd6baed | 2024 | extern LRESULT CALLBACK w32_wnd_proc (); |
ee78dc32 | 2025 | |
7d0393cf | 2026 | BOOL |
fbd6baed | 2027 | w32_init_class (hinst) |
ee78dc32 GV |
2028 | HINSTANCE hinst; |
2029 | { | |
2030 | WNDCLASS wc; | |
2031 | ||
5ac45f98 | 2032 | wc.style = CS_HREDRAW | CS_VREDRAW; |
fbd6baed | 2033 | wc.lpfnWndProc = (WNDPROC) w32_wnd_proc; |
ee78dc32 GV |
2034 | wc.cbClsExtra = 0; |
2035 | wc.cbWndExtra = WND_EXTRA_BYTES; | |
2036 | wc.hInstance = hinst; | |
2037 | wc.hIcon = LoadIcon (hinst, EMACS_CLASS); | |
c9b2104d | 2038 | wc.hCursor = w32_load_cursor (IDC_ARROW); |
4587b026 | 2039 | wc.hbrBackground = NULL; /* GetStockObject (WHITE_BRUSH); */ |
ee78dc32 GV |
2040 | wc.lpszMenuName = NULL; |
2041 | wc.lpszClassName = EMACS_CLASS; | |
2042 | ||
2043 | return (RegisterClass (&wc)); | |
2044 | } | |
2045 | ||
7d0393cf | 2046 | HWND |
fbd6baed | 2047 | w32_createscrollbar (f, bar) |
ee78dc32 GV |
2048 | struct frame *f; |
2049 | struct scroll_bar * bar; | |
2050 | { | |
2051 | return (CreateWindow ("SCROLLBAR", "", SBS_VERT | WS_CHILD | WS_VISIBLE, | |
2052 | /* Position and size of scroll bar. */ | |
6fc2811b | 2053 | XINT(bar->left) + VERTICAL_SCROLL_BAR_WIDTH_TRIM, |
7d0393cf | 2054 | XINT(bar->top), |
6fc2811b JR |
2055 | XINT(bar->width) - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2, |
2056 | XINT(bar->height), | |
fbd6baed | 2057 | FRAME_W32_WINDOW (f), |
ee78dc32 GV |
2058 | NULL, |
2059 | hinst, | |
2060 | NULL)); | |
2061 | } | |
2062 | ||
7d0393cf | 2063 | void |
fbd6baed | 2064 | w32_createwindow (f) |
ee78dc32 GV |
2065 | struct frame *f; |
2066 | { | |
2067 | HWND hwnd; | |
1edf84e7 GV |
2068 | RECT rect; |
2069 | ||
2070 | rect.left = rect.top = 0; | |
be786000 KS |
2071 | rect.right = FRAME_PIXEL_WIDTH (f); |
2072 | rect.bottom = FRAME_PIXEL_HEIGHT (f); | |
7d0393cf | 2073 | |
1edf84e7 GV |
2074 | AdjustWindowRect (&rect, f->output_data.w32->dwStyle, |
2075 | FRAME_EXTERNAL_MENU_BAR (f)); | |
7d0393cf | 2076 | |
ee78dc32 | 2077 | /* Do first time app init */ |
7d0393cf | 2078 | |
ee78dc32 GV |
2079 | if (!hprevinst) |
2080 | { | |
fbd6baed | 2081 | w32_init_class (hinst); |
ee78dc32 | 2082 | } |
7d0393cf | 2083 | |
1edf84e7 GV |
2084 | FRAME_W32_WINDOW (f) = hwnd |
2085 | = CreateWindow (EMACS_CLASS, | |
2086 | f->namebuf, | |
9ead1b60 | 2087 | f->output_data.w32->dwStyle | WS_CLIPCHILDREN, |
be786000 KS |
2088 | f->left_pos, |
2089 | f->top_pos, | |
1edf84e7 GV |
2090 | rect.right - rect.left, |
2091 | rect.bottom - rect.top, | |
2092 | NULL, | |
2093 | NULL, | |
2094 | hinst, | |
2095 | NULL); | |
2096 | ||
ee78dc32 GV |
2097 | if (hwnd) |
2098 | { | |
be786000 KS |
2099 | SetWindowLong (hwnd, WND_FONTWIDTH_INDEX, FRAME_COLUMN_WIDTH (f)); |
2100 | SetWindowLong (hwnd, WND_LINEHEIGHT_INDEX, FRAME_LINE_HEIGHT (f)); | |
2101 | SetWindowLong (hwnd, WND_BORDER_INDEX, FRAME_INTERNAL_BORDER_WIDTH (f)); | |
2102 | SetWindowLong (hwnd, WND_SCROLLBAR_INDEX, f->scroll_bar_actual_width); | |
6fc2811b | 2103 | SetWindowLong (hwnd, WND_BACKGROUND_INDEX, FRAME_BACKGROUND_PIXEL (f)); |
ee78dc32 | 2104 | |
cb9e33d4 RS |
2105 | /* Enable drag-n-drop. */ |
2106 | DragAcceptFiles (hwnd, TRUE); | |
7d0393cf | 2107 | |
5ac45f98 GV |
2108 | /* Do this to discard the default setting specified by our parent. */ |
2109 | ShowWindow (hwnd, SW_HIDE); | |
3c190163 | 2110 | } |
3c190163 GV |
2111 | } |
2112 | ||
7d0393cf | 2113 | void |
ee78dc32 | 2114 | my_post_msg (wmsg, hwnd, msg, wParam, lParam) |
fbd6baed | 2115 | W32Msg * wmsg; |
ee78dc32 GV |
2116 | HWND hwnd; |
2117 | UINT msg; | |
2118 | WPARAM wParam; | |
2119 | LPARAM lParam; | |
2120 | { | |
2121 | wmsg->msg.hwnd = hwnd; | |
2122 | wmsg->msg.message = msg; | |
2123 | wmsg->msg.wParam = wParam; | |
2124 | wmsg->msg.lParam = lParam; | |
2125 | wmsg->msg.time = GetMessageTime (); | |
2126 | ||
2127 | post_msg (wmsg); | |
2128 | } | |
2129 | ||
e9e23e23 | 2130 | /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish |
a1a80b40 GV |
2131 | between left and right keys as advertised. We test for this |
2132 | support dynamically, and set a flag when the support is absent. If | |
2133 | absent, we keep track of the left and right control and alt keys | |
2134 | ourselves. This is particularly necessary on keyboards that rely | |
2135 | upon the AltGr key, which is represented as having the left control | |
2136 | and right alt keys pressed. For these keyboards, we need to know | |
2137 | when the left alt key has been pressed in addition to the AltGr key | |
2138 | so that we can properly support M-AltGr-key sequences (such as M-@ | |
2139 | on Swedish keyboards). */ | |
2140 | ||
2141 | #define EMACS_LCONTROL 0 | |
2142 | #define EMACS_RCONTROL 1 | |
2143 | #define EMACS_LMENU 2 | |
2144 | #define EMACS_RMENU 3 | |
2145 | ||
2146 | static int modifiers[4]; | |
2147 | static int modifiers_recorded; | |
2148 | static int modifier_key_support_tested; | |
2149 | ||
2150 | static void | |
2151 | test_modifier_support (unsigned int wparam) | |
2152 | { | |
2153 | unsigned int l, r; | |
2154 | ||
2155 | if (wparam != VK_CONTROL && wparam != VK_MENU) | |
2156 | return; | |
2157 | if (wparam == VK_CONTROL) | |
2158 | { | |
2159 | l = VK_LCONTROL; | |
2160 | r = VK_RCONTROL; | |
2161 | } | |
2162 | else | |
2163 | { | |
2164 | l = VK_LMENU; | |
2165 | r = VK_RMENU; | |
2166 | } | |
2167 | if (!(GetKeyState (l) & 0x8000) && !(GetKeyState (r) & 0x8000)) | |
2168 | modifiers_recorded = 1; | |
2169 | else | |
2170 | modifiers_recorded = 0; | |
2171 | modifier_key_support_tested = 1; | |
2172 | } | |
2173 | ||
2174 | static void | |
2175 | record_keydown (unsigned int wparam, unsigned int lparam) | |
2176 | { | |
2177 | int i; | |
2178 | ||
2179 | if (!modifier_key_support_tested) | |
2180 | test_modifier_support (wparam); | |
2181 | ||
2182 | if ((wparam != VK_CONTROL && wparam != VK_MENU) || !modifiers_recorded) | |
2183 | return; | |
2184 | ||
2185 | if (wparam == VK_CONTROL) | |
2186 | i = (lparam & 0x1000000) ? EMACS_RCONTROL : EMACS_LCONTROL; | |
2187 | else | |
2188 | i = (lparam & 0x1000000) ? EMACS_RMENU : EMACS_LMENU; | |
2189 | ||
2190 | modifiers[i] = 1; | |
2191 | } | |
2192 | ||
2193 | static void | |
2194 | record_keyup (unsigned int wparam, unsigned int lparam) | |
2195 | { | |
2196 | int i; | |
2197 | ||
2198 | if ((wparam != VK_CONTROL && wparam != VK_MENU) || !modifiers_recorded) | |
2199 | return; | |
2200 | ||
2201 | if (wparam == VK_CONTROL) | |
2202 | i = (lparam & 0x1000000) ? EMACS_RCONTROL : EMACS_LCONTROL; | |
2203 | else | |
2204 | i = (lparam & 0x1000000) ? EMACS_RMENU : EMACS_LMENU; | |
2205 | ||
2206 | modifiers[i] = 0; | |
2207 | } | |
2208 | ||
da36a4d6 | 2209 | /* Emacs can lose focus while a modifier key has been pressed. When |
7d0393cf | 2210 | it regains focus, be conservative and clear all modifiers since |
da36a4d6 GV |
2211 | we cannot reconstruct the left and right modifier state. */ |
2212 | static void | |
2213 | reset_modifiers () | |
2214 | { | |
8681157a RS |
2215 | SHORT ctrl, alt; |
2216 | ||
adcc3809 GV |
2217 | if (GetFocus () == NULL) |
2218 | /* Emacs doesn't have keyboard focus. Do nothing. */ | |
da36a4d6 | 2219 | return; |
8681157a RS |
2220 | |
2221 | ctrl = GetAsyncKeyState (VK_CONTROL); | |
2222 | alt = GetAsyncKeyState (VK_MENU); | |
2223 | ||
8681157a RS |
2224 | if (!(ctrl & 0x08000)) |
2225 | /* Clear any recorded control modifier state. */ | |
2226 | modifiers[EMACS_RCONTROL] = modifiers[EMACS_LCONTROL] = 0; | |
2227 | ||
2228 | if (!(alt & 0x08000)) | |
2229 | /* Clear any recorded alt modifier state. */ | |
2230 | modifiers[EMACS_RMENU] = modifiers[EMACS_LMENU] = 0; | |
2231 | ||
adcc3809 GV |
2232 | /* Update the state of all modifier keys, because modifiers used in |
2233 | hot-key combinations can get stuck on if Emacs loses focus as a | |
2234 | result of a hot-key being pressed. */ | |
2235 | { | |
2236 | BYTE keystate[256]; | |
2237 | ||
2238 | #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8) | |
2239 | ||
2240 | GetKeyboardState (keystate); | |
2241 | keystate[VK_SHIFT] = CURRENT_STATE (VK_SHIFT); | |
2242 | keystate[VK_CONTROL] = CURRENT_STATE (VK_CONTROL); | |
2243 | keystate[VK_LCONTROL] = CURRENT_STATE (VK_LCONTROL); | |
2244 | keystate[VK_RCONTROL] = CURRENT_STATE (VK_RCONTROL); | |
2245 | keystate[VK_MENU] = CURRENT_STATE (VK_MENU); | |
2246 | keystate[VK_LMENU] = CURRENT_STATE (VK_LMENU); | |
2247 | keystate[VK_RMENU] = CURRENT_STATE (VK_RMENU); | |
2248 | keystate[VK_LWIN] = CURRENT_STATE (VK_LWIN); | |
2249 | keystate[VK_RWIN] = CURRENT_STATE (VK_RWIN); | |
2250 | keystate[VK_APPS] = CURRENT_STATE (VK_APPS); | |
2251 | SetKeyboardState (keystate); | |
2252 | } | |
da36a4d6 GV |
2253 | } |
2254 | ||
7830e24b RS |
2255 | /* Synchronize modifier state with what is reported with the current |
2256 | keystroke. Even if we cannot distinguish between left and right | |
2257 | modifier keys, we know that, if no modifiers are set, then neither | |
2258 | the left or right modifier should be set. */ | |
2259 | static void | |
2260 | sync_modifiers () | |
2261 | { | |
2262 | if (!modifiers_recorded) | |
2263 | return; | |
2264 | ||
7d0393cf | 2265 | if (!(GetKeyState (VK_CONTROL) & 0x8000)) |
7830e24b RS |
2266 | modifiers[EMACS_RCONTROL] = modifiers[EMACS_LCONTROL] = 0; |
2267 | ||
7d0393cf | 2268 | if (!(GetKeyState (VK_MENU) & 0x8000)) |
7830e24b RS |
2269 | modifiers[EMACS_RMENU] = modifiers[EMACS_LMENU] = 0; |
2270 | } | |
2271 | ||
a1a80b40 GV |
2272 | static int |
2273 | modifier_set (int vkey) | |
2274 | { | |
ccc2d29c | 2275 | if (vkey == VK_CAPITAL || vkey == VK_SCROLL) |
891560d6 | 2276 | return (GetKeyState (vkey) & 0x1); |
a1a80b40 GV |
2277 | if (!modifiers_recorded) |
2278 | return (GetKeyState (vkey) & 0x8000); | |
2279 | ||
2280 | switch (vkey) | |
2281 | { | |
2282 | case VK_LCONTROL: | |
2283 | return modifiers[EMACS_LCONTROL]; | |
2284 | case VK_RCONTROL: | |
2285 | return modifiers[EMACS_RCONTROL]; | |
2286 | case VK_LMENU: | |
2287 | return modifiers[EMACS_LMENU]; | |
2288 | case VK_RMENU: | |
2289 | return modifiers[EMACS_RMENU]; | |
a1a80b40 GV |
2290 | } |
2291 | return (GetKeyState (vkey) & 0x8000); | |
2292 | } | |
2293 | ||
ccc2d29c GV |
2294 | /* Convert between the modifier bits W32 uses and the modifier bits |
2295 | Emacs uses. */ | |
2296 | ||
2297 | unsigned int | |
2298 | w32_key_to_modifier (int key) | |
2299 | { | |
2300 | Lisp_Object key_mapping; | |
2301 | ||
2302 | switch (key) | |
2303 | { | |
2304 | case VK_LWIN: | |
2305 | key_mapping = Vw32_lwindow_modifier; | |
2306 | break; | |
2307 | case VK_RWIN: | |
2308 | key_mapping = Vw32_rwindow_modifier; | |
2309 | break; | |
2310 | case VK_APPS: | |
2311 | key_mapping = Vw32_apps_modifier; | |
2312 | break; | |
2313 | case VK_SCROLL: | |
2314 | key_mapping = Vw32_scroll_lock_modifier; | |
2315 | break; | |
2316 | default: | |
2317 | key_mapping = Qnil; | |
2318 | } | |
2319 | ||
adcc3809 GV |
2320 | /* NB. This code runs in the input thread, asychronously to the lisp |
2321 | thread, so we must be careful to ensure access to lisp data is | |
2322 | thread-safe. The following code is safe because the modifier | |
2323 | variable values are updated atomically from lisp and symbols are | |
2324 | not relocated by GC. Also, we don't have to worry about seeing GC | |
2325 | markbits here. */ | |
2326 | if (EQ (key_mapping, Qhyper)) | |
ccc2d29c | 2327 | return hyper_modifier; |
adcc3809 | 2328 | if (EQ (key_mapping, Qsuper)) |
ccc2d29c | 2329 | return super_modifier; |
adcc3809 | 2330 | if (EQ (key_mapping, Qmeta)) |
ccc2d29c | 2331 | return meta_modifier; |
adcc3809 | 2332 | if (EQ (key_mapping, Qalt)) |
ccc2d29c | 2333 | return alt_modifier; |
adcc3809 | 2334 | if (EQ (key_mapping, Qctrl)) |
ccc2d29c | 2335 | return ctrl_modifier; |
adcc3809 | 2336 | if (EQ (key_mapping, Qcontrol)) /* synonym for ctrl */ |
ccc2d29c | 2337 | return ctrl_modifier; |
adcc3809 | 2338 | if (EQ (key_mapping, Qshift)) |
ccc2d29c GV |
2339 | return shift_modifier; |
2340 | ||
2341 | /* Don't generate any modifier if not explicitly requested. */ | |
2342 | return 0; | |
2343 | } | |
2344 | ||
2345 | unsigned int | |
2346 | w32_get_modifiers () | |
2347 | { | |
2348 | return ((modifier_set (VK_SHIFT) ? shift_modifier : 0) | | |
2349 | (modifier_set (VK_CONTROL) ? ctrl_modifier : 0) | | |
2350 | (modifier_set (VK_LWIN) ? w32_key_to_modifier (VK_LWIN) : 0) | | |
2351 | (modifier_set (VK_RWIN) ? w32_key_to_modifier (VK_RWIN) : 0) | | |
2352 | (modifier_set (VK_APPS) ? w32_key_to_modifier (VK_APPS) : 0) | | |
2353 | (modifier_set (VK_SCROLL) ? w32_key_to_modifier (VK_SCROLL) : 0) | | |
2354 | (modifier_set (VK_MENU) ? | |
2355 | ((NILP (Vw32_alt_is_meta)) ? alt_modifier : meta_modifier) : 0)); | |
2356 | } | |
2357 | ||
a1a80b40 GV |
2358 | /* We map the VK_* modifiers into console modifier constants |
2359 | so that we can use the same routines to handle both console | |
2360 | and window input. */ | |
2361 | ||
2362 | static int | |
ccc2d29c | 2363 | construct_console_modifiers () |
a1a80b40 GV |
2364 | { |
2365 | int mods; | |
2366 | ||
a1a80b40 GV |
2367 | mods = 0; |
2368 | mods |= (modifier_set (VK_SHIFT)) ? SHIFT_PRESSED : 0; | |
2369 | mods |= (modifier_set (VK_CAPITAL)) ? CAPSLOCK_ON : 0; | |
ccc2d29c GV |
2370 | mods |= (modifier_set (VK_SCROLL)) ? SCROLLLOCK_ON : 0; |
2371 | mods |= (modifier_set (VK_NUMLOCK)) ? NUMLOCK_ON : 0; | |
a1a80b40 GV |
2372 | mods |= (modifier_set (VK_LCONTROL)) ? LEFT_CTRL_PRESSED : 0; |
2373 | mods |= (modifier_set (VK_RCONTROL)) ? RIGHT_CTRL_PRESSED : 0; | |
2374 | mods |= (modifier_set (VK_LMENU)) ? LEFT_ALT_PRESSED : 0; | |
2375 | mods |= (modifier_set (VK_RMENU)) ? RIGHT_ALT_PRESSED : 0; | |
ccc2d29c GV |
2376 | mods |= (modifier_set (VK_LWIN)) ? LEFT_WIN_PRESSED : 0; |
2377 | mods |= (modifier_set (VK_RWIN)) ? RIGHT_WIN_PRESSED : 0; | |
2378 | mods |= (modifier_set (VK_APPS)) ? APPS_PRESSED : 0; | |
a1a80b40 GV |
2379 | |
2380 | return mods; | |
2381 | } | |
2382 | ||
ccc2d29c GV |
2383 | static int |
2384 | w32_get_key_modifiers (unsigned int wparam, unsigned int lparam) | |
da36a4d6 | 2385 | { |
ccc2d29c GV |
2386 | int mods; |
2387 | ||
2388 | /* Convert to emacs modifiers. */ | |
2389 | mods = w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam); | |
2390 | ||
2391 | return mods; | |
2392 | } | |
da36a4d6 | 2393 | |
ccc2d29c GV |
2394 | unsigned int |
2395 | map_keypad_keys (unsigned int virt_key, unsigned int extended) | |
2396 | { | |
2397 | if (virt_key < VK_CLEAR || virt_key > VK_DELETE) | |
2398 | return virt_key; | |
da36a4d6 | 2399 | |
ccc2d29c | 2400 | if (virt_key == VK_RETURN) |
da36a4d6 GV |
2401 | return (extended ? VK_NUMPAD_ENTER : VK_RETURN); |
2402 | ||
ccc2d29c GV |
2403 | if (virt_key >= VK_PRIOR && virt_key <= VK_DOWN) |
2404 | return (!extended ? (VK_NUMPAD_PRIOR + (virt_key - VK_PRIOR)) : virt_key); | |
2405 | ||
2406 | if (virt_key == VK_INSERT || virt_key == VK_DELETE) | |
2407 | return (!extended ? (VK_NUMPAD_INSERT + (virt_key - VK_INSERT)) : virt_key); | |
2408 | ||
2409 | if (virt_key == VK_CLEAR) | |
2410 | return (!extended ? VK_NUMPAD_CLEAR : virt_key); | |
2411 | ||
2412 | return virt_key; | |
2413 | } | |
2414 | ||
2415 | /* List of special key combinations which w32 would normally capture, | |
2416 | but emacs should grab instead. Not directly visible to lisp, to | |
2417 | simplify synchronization. Each item is an integer encoding a virtual | |
2418 | key code and modifier combination to capture. */ | |
2419 | Lisp_Object w32_grabbed_keys; | |
2420 | ||
2421 | #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8)) | |
2422 | #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff) | |
2423 | #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255) | |
2424 | #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8) | |
2425 | ||
2ba49441 JR |
2426 | #define RAW_HOTKEY_ID(k) ((k) & 0xbfff) |
2427 | #define RAW_HOTKEY_VK_CODE(k) ((k) & 255) | |
2428 | #define RAW_HOTKEY_MODIFIERS(k) ((k) >> 8) | |
2429 | ||
ccc2d29c GV |
2430 | /* Register hot-keys for reserved key combinations when Emacs has |
2431 | keyboard focus, since this is the only way Emacs can receive key | |
2432 | combinations like Alt-Tab which are used by the system. */ | |
2433 | ||
2434 | static void | |
2435 | register_hot_keys (hwnd) | |
2436 | HWND hwnd; | |
2437 | { | |
2438 | Lisp_Object keylist; | |
2439 | ||
2440 | /* Use GC_CONSP, since we are called asynchronously. */ | |
2441 | for (keylist = w32_grabbed_keys; GC_CONSP (keylist); keylist = XCDR (keylist)) | |
2442 | { | |
2443 | Lisp_Object key = XCAR (keylist); | |
2444 | ||
2445 | /* Deleted entries get set to nil. */ | |
2446 | if (!INTEGERP (key)) | |
2447 | continue; | |
2448 | ||
2449 | RegisterHotKey (hwnd, HOTKEY_ID (key), | |
2450 | HOTKEY_MODIFIERS (key), HOTKEY_VK_CODE (key)); | |
2451 | } | |
2452 | } | |
2453 | ||
2454 | static void | |
2455 | unregister_hot_keys (hwnd) | |
2456 | HWND hwnd; | |
2457 | { | |
2458 | Lisp_Object keylist; | |
2459 | ||
2460 | /* Use GC_CONSP, since we are called asynchronously. */ | |
2461 | for (keylist = w32_grabbed_keys; GC_CONSP (keylist); keylist = XCDR (keylist)) | |
2462 | { | |
2463 | Lisp_Object key = XCAR (keylist); | |
2464 | ||
2465 | if (!INTEGERP (key)) | |
2466 | continue; | |
2467 | ||
2468 | UnregisterHotKey (hwnd, HOTKEY_ID (key)); | |
2469 | } | |
2470 | } | |
2471 | ||
5ac45f98 GV |
2472 | /* Main message dispatch loop. */ |
2473 | ||
1edf84e7 GV |
2474 | static void |
2475 | w32_msg_pump (deferred_msg * msg_buf) | |
5ac45f98 GV |
2476 | { |
2477 | MSG msg; | |
ccc2d29c GV |
2478 | int result; |
2479 | HWND focus_window; | |
93fbe8b7 GV |
2480 | |
2481 | msh_mousewheel = RegisterWindowMessage (MSH_MOUSEWHEEL); | |
7d0393cf | 2482 | |
5ac45f98 GV |
2483 | while (GetMessage (&msg, NULL, 0, 0)) |
2484 | { | |
2485 | if (msg.hwnd == NULL) | |
2486 | { | |
2487 | switch (msg.message) | |
2488 | { | |
3ef68e6b AI |
2489 | case WM_NULL: |
2490 | /* Produced by complete_deferred_msg; just ignore. */ | |
2491 | break; | |
5ac45f98 | 2492 | case WM_EMACS_CREATEWINDOW: |
fbd6baed | 2493 | w32_createwindow ((struct frame *) msg.wParam); |
1edf84e7 GV |
2494 | if (!PostThreadMessage (dwMainThreadId, WM_EMACS_DONE, 0, 0)) |
2495 | abort (); | |
5ac45f98 | 2496 | break; |
dfdb4047 GV |
2497 | case WM_EMACS_SETLOCALE: |
2498 | SetThreadLocale (msg.wParam); | |
2499 | /* Reply is not expected. */ | |
2500 | break; | |
ccc2d29c GV |
2501 | case WM_EMACS_SETKEYBOARDLAYOUT: |
2502 | result = (int) ActivateKeyboardLayout ((HKL) msg.wParam, 0); | |
2503 | if (!PostThreadMessage (dwMainThreadId, WM_EMACS_DONE, | |
2504 | result, 0)) | |
2505 | abort (); | |
2506 | break; | |
2507 | case WM_EMACS_REGISTER_HOT_KEY: | |
2508 | focus_window = GetFocus (); | |
2509 | if (focus_window != NULL) | |
2510 | RegisterHotKey (focus_window, | |
2ba49441 JR |
2511 | RAW_HOTKEY_ID (msg.wParam), |
2512 | RAW_HOTKEY_MODIFIERS (msg.wParam), | |
2513 | RAW_HOTKEY_VK_CODE (msg.wParam)); | |
ccc2d29c GV |
2514 | /* Reply is not expected. */ |
2515 | break; | |
2516 | case WM_EMACS_UNREGISTER_HOT_KEY: | |
2517 | focus_window = GetFocus (); | |
2518 | if (focus_window != NULL) | |
2ba49441 | 2519 | UnregisterHotKey (focus_window, RAW_HOTKEY_ID (msg.wParam)); |
adcc3809 GV |
2520 | /* Mark item as erased. NB: this code must be |
2521 | thread-safe. The next line is okay because the cons | |
2522 | cell is never made into garbage and is not relocated by | |
2523 | GC. */ | |
2ba49441 | 2524 | XSETCAR ((Lisp_Object) ((EMACS_INT) msg.lParam), Qnil); |
ccc2d29c GV |
2525 | if (!PostThreadMessage (dwMainThreadId, WM_EMACS_DONE, 0, 0)) |
2526 | abort (); | |
2527 | break; | |
adcc3809 GV |
2528 | case WM_EMACS_TOGGLE_LOCK_KEY: |
2529 | { | |
2530 | int vk_code = (int) msg.wParam; | |
2531 | int cur_state = (GetKeyState (vk_code) & 1); | |
2ba49441 | 2532 | Lisp_Object new_state = (Lisp_Object) ((EMACS_INT) msg.lParam); |
adcc3809 GV |
2533 | |
2534 | /* NB: This code must be thread-safe. It is safe to | |
2535 | call NILP because symbols are not relocated by GC, | |
2536 | and pointer here is not touched by GC (so the markbit | |
2537 | can't be set). Numbers are safe because they are | |
2538 | immediate values. */ | |
2539 | if (NILP (new_state) | |
2540 | || (NUMBERP (new_state) | |
8edb0a6f | 2541 | && ((XUINT (new_state)) & 1) != cur_state)) |
adcc3809 GV |
2542 | { |
2543 | one_w32_display_info.faked_key = vk_code; | |
2544 | ||
2545 | keybd_event ((BYTE) vk_code, | |
2546 | (BYTE) MapVirtualKey (vk_code, 0), | |
2547 | KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); | |
2548 | keybd_event ((BYTE) vk_code, | |
2549 | (BYTE) MapVirtualKey (vk_code, 0), | |
2550 | KEYEVENTF_EXTENDEDKEY | 0, 0); | |
2551 | keybd_event ((BYTE) vk_code, | |
2552 | (BYTE) MapVirtualKey (vk_code, 0), | |
2553 | KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); | |
2554 | cur_state = !cur_state; | |
2555 | } | |
2556 | if (!PostThreadMessage (dwMainThreadId, WM_EMACS_DONE, | |
2557 | cur_state, 0)) | |
2558 | abort (); | |
2559 | } | |
2560 | break; | |
1edf84e7 | 2561 | default: |
1edf84e7 | 2562 | DebPrint (("msg %x not expected by w32_msg_pump\n", msg.message)); |
5ac45f98 GV |
2563 | } |
2564 | } | |
2565 | else | |
2566 | { | |
2567 | DispatchMessage (&msg); | |
2568 | } | |
1edf84e7 GV |
2569 | |
2570 | /* Exit nested loop when our deferred message has completed. */ | |
2571 | if (msg_buf->completed) | |
2572 | break; | |
5ac45f98 | 2573 | } |
1edf84e7 GV |
2574 | } |
2575 | ||
2576 | deferred_msg * deferred_msg_head; | |
2577 | ||
2578 | static deferred_msg * | |
2579 | find_deferred_msg (HWND hwnd, UINT msg) | |
2580 | { | |
2581 | deferred_msg * item; | |
2582 | ||
2583 | /* Don't actually need synchronization for read access, since | |
2584 | modification of single pointer is always atomic. */ | |
2585 | /* enter_crit (); */ | |
2586 | ||
2587 | for (item = deferred_msg_head; item != NULL; item = item->next) | |
2588 | if (item->w32msg.msg.hwnd == hwnd | |
2589 | && item->w32msg.msg.message == msg) | |
2590 | break; | |
2591 | ||
2592 | /* leave_crit (); */ | |
2593 | ||
2594 | return item; | |
2595 | } | |
2596 | ||
2597 | static LRESULT | |
2598 | send_deferred_msg (deferred_msg * msg_buf, | |
2599 | HWND hwnd, | |
2600 | UINT msg, | |
2601 | WPARAM wParam, | |
2602 | LPARAM lParam) | |
2603 | { | |
2604 | /* Only input thread can send deferred messages. */ | |
2605 | if (GetCurrentThreadId () != dwWindowsThreadId) | |
2606 | abort (); | |
2607 | ||
2608 | /* It is an error to send a message that is already deferred. */ | |
2609 | if (find_deferred_msg (hwnd, msg) != NULL) | |
2610 | abort (); | |
2611 | ||
2612 | /* Enforced synchronization is not needed because this is the only | |
2613 | function that alters deferred_msg_head, and the following critical | |
2614 | section is guaranteed to only be serially reentered (since only the | |
2615 | input thread can call us). */ | |
2616 | ||
2617 | /* enter_crit (); */ | |
2618 | ||
2619 | msg_buf->completed = 0; | |
2620 | msg_buf->next = deferred_msg_head; | |
2621 | deferred_msg_head = msg_buf; | |
2622 | my_post_msg (&msg_buf->w32msg, hwnd, msg, wParam, lParam); | |
2623 | ||
2624 | /* leave_crit (); */ | |
2625 | ||
2626 | /* Start a new nested message loop to process other messages until | |
2627 | this one is completed. */ | |
2628 | w32_msg_pump (msg_buf); | |
2629 | ||
2630 | deferred_msg_head = msg_buf->next; | |
2631 | ||
2632 | return msg_buf->result; | |
2633 | } | |
2634 | ||
2635 | void | |
2636 | complete_deferred_msg (HWND hwnd, UINT msg, LRESULT result) | |
2637 | { | |
2638 | deferred_msg * msg_buf = find_deferred_msg (hwnd, msg); | |
2639 | ||
2640 | if (msg_buf == NULL) | |
3ef68e6b AI |
2641 | /* Message may have been cancelled, so don't abort(). */ |
2642 | return; | |
1edf84e7 GV |
2643 | |
2644 | msg_buf->result = result; | |
2645 | msg_buf->completed = 1; | |
2646 | ||
2647 | /* Ensure input thread is woken so it notices the completion. */ | |
2648 | PostThreadMessage (dwWindowsThreadId, WM_NULL, 0, 0); | |
2649 | } | |
2650 | ||
3ef68e6b AI |
2651 | void |
2652 | cancel_all_deferred_msgs () | |
2653 | { | |
2654 | deferred_msg * item; | |
2655 | ||
2656 | /* Don't actually need synchronization for read access, since | |
2657 | modification of single pointer is always atomic. */ | |
2658 | /* enter_crit (); */ | |
2659 | ||
2660 | for (item = deferred_msg_head; item != NULL; item = item->next) | |
2661 | { | |
2662 | item->result = 0; | |
2663 | item->completed = 1; | |
2664 | } | |
2665 | ||
2666 | /* leave_crit (); */ | |
2667 | ||
2668 | /* Ensure input thread is woken so it notices the completion. */ | |
2669 | PostThreadMessage (dwWindowsThreadId, WM_NULL, 0, 0); | |
2670 | } | |
1edf84e7 | 2671 | |
7d0393cf | 2672 | DWORD |
1edf84e7 GV |
2673 | w32_msg_worker (dw) |
2674 | DWORD dw; | |
2675 | { | |
2676 | MSG msg; | |
2677 | deferred_msg dummy_buf; | |
2678 | ||
2679 | /* Ensure our message queue is created */ | |
7d0393cf | 2680 | |
1edf84e7 | 2681 | PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE); |
7d0393cf | 2682 | |
1edf84e7 GV |
2683 | if (!PostThreadMessage (dwMainThreadId, WM_EMACS_DONE, 0, 0)) |
2684 | abort (); | |
2685 | ||
2686 | memset (&dummy_buf, 0, sizeof (dummy_buf)); | |
2687 | dummy_buf.w32msg.msg.hwnd = NULL; | |
2688 | dummy_buf.w32msg.msg.message = WM_NULL; | |
2689 | ||
2690 | /* This is the inital message loop which should only exit when the | |
2691 | application quits. */ | |
2692 | w32_msg_pump (&dummy_buf); | |
2693 | ||
2694 | return 0; | |
5ac45f98 GV |
2695 | } |
2696 | ||
3ef68e6b AI |
2697 | static void |
2698 | post_character_message (hwnd, msg, wParam, lParam, modifiers) | |
2699 | HWND hwnd; | |
2700 | UINT msg; | |
2701 | WPARAM wParam; | |
2702 | LPARAM lParam; | |
2703 | DWORD modifiers; | |
2704 | ||
2705 | { | |
2706 | W32Msg wmsg; | |
2707 | ||
2708 | wmsg.dwModifiers = modifiers; | |
2709 | ||
2710 | /* Detect quit_char and set quit-flag directly. Note that we | |
2711 | still need to post a message to ensure the main thread will be | |
2712 | woken up if blocked in sys_select(), but we do NOT want to post | |
2713 | the quit_char message itself (because it will usually be as if | |
2714 | the user had typed quit_char twice). Instead, we post a dummy | |
2715 | message that has no particular effect. */ | |
2716 | { | |
2717 | int c = wParam; | |
2718 | if (isalpha (c) && wmsg.dwModifiers == ctrl_modifier) | |
2719 | c = make_ctrl_char (c) & 0377; | |
7d081355 AI |
2720 | if (c == quit_char |
2721 | || (wmsg.dwModifiers == 0 && | |
2ba49441 | 2722 | w32_quit_key && wParam == w32_quit_key)) |
3ef68e6b AI |
2723 | { |
2724 | Vquit_flag = Qt; | |
2725 | ||
2726 | /* The choice of message is somewhat arbitrary, as long as | |
2727 | the main thread handler just ignores it. */ | |
2728 | msg = WM_NULL; | |
2729 | ||
2730 | /* Interrupt any blocking system calls. */ | |
2731 | signal_quit (); | |
2732 | ||
2733 | /* As a safety precaution, forcibly complete any deferred | |
2734 | messages. This is a kludge, but I don't see any particularly | |
2735 | clean way to handle the situation where a deferred message is | |
2736 | "dropped" in the lisp thread, and will thus never be | |
2737 | completed, eg. by the user trying to activate the menubar | |
2738 | when the lisp thread is busy, and then typing C-g when the | |
2739 | menubar doesn't open promptly (with the result that the | |
2740 | menubar never responds at all because the deferred | |
2741 | WM_INITMENU message is never completed). Another problem | |
2742 | situation is when the lisp thread calls SendMessage (to send | |
2743 | a window manager command) when a message has been deferred; | |
2744 | the lisp thread gets blocked indefinitely waiting for the | |
2745 | deferred message to be completed, which itself is waiting for | |
2746 | the lisp thread to respond. | |
2747 | ||
2748 | Note that we don't want to block the input thread waiting for | |
2749 | a reponse from the lisp thread (although that would at least | |
2750 | solve the deadlock problem above), because we want to be able | |
2751 | to receive C-g to interrupt the lisp thread. */ | |
2752 | cancel_all_deferred_msgs (); | |
2753 | } | |
2754 | } | |
2755 | ||
2756 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); | |
2757 | } | |
2758 | ||
ee78dc32 GV |
2759 | /* Main window procedure */ |
2760 | ||
7d0393cf | 2761 | LRESULT CALLBACK |
fbd6baed | 2762 | w32_wnd_proc (hwnd, msg, wParam, lParam) |
ee78dc32 GV |
2763 | HWND hwnd; |
2764 | UINT msg; | |
2765 | WPARAM wParam; | |
2766 | LPARAM lParam; | |
2767 | { | |
2768 | struct frame *f; | |
fbd6baed GV |
2769 | struct w32_display_info *dpyinfo = &one_w32_display_info; |
2770 | W32Msg wmsg; | |
84fb1139 | 2771 | int windows_translate; |
576ba81c | 2772 | int key; |
84fb1139 | 2773 | |
a6085637 KH |
2774 | /* Note that it is okay to call x_window_to_frame, even though we are |
2775 | not running in the main lisp thread, because frame deletion | |
2776 | requires the lisp thread to synchronize with this thread. Thus, if | |
2777 | a frame struct is returned, it can be used without concern that the | |
2778 | lisp thread might make it disappear while we are using it. | |
2779 | ||
2780 | NB. Walking the frame list in this thread is safe (as long as | |
2781 | writes of Lisp_Object slots are atomic, which they are on Windows). | |
2782 | Although delete-frame can destructively modify the frame list while | |
2783 | we are walking it, a garbage collection cannot occur until after | |
2784 | delete-frame has synchronized with this thread. | |
2785 | ||
2786 | It is also safe to use functions that make GDI calls, such as | |
fbd6baed | 2787 | w32_clear_rect, because these functions must obtain a DC handle |
a6085637 KH |
2788 | from the frame struct using get_frame_dc which is thread-aware. */ |
2789 | ||
7d0393cf | 2790 | switch (msg) |
ee78dc32 GV |
2791 | { |
2792 | case WM_ERASEBKGND: | |
a6085637 KH |
2793 | f = x_window_to_frame (dpyinfo, hwnd); |
2794 | if (f) | |
2795 | { | |
9badad41 | 2796 | HDC hdc = get_frame_dc (f); |
a6085637 | 2797 | GetUpdateRect (hwnd, &wmsg.rect, FALSE); |
9badad41 JR |
2798 | w32_clear_rect (f, hdc, &wmsg.rect); |
2799 | release_frame_dc (f, hdc); | |
ce6059da AI |
2800 | |
2801 | #if defined (W32_DEBUG_DISPLAY) | |
18f0b342 AI |
2802 | DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n", |
2803 | f, | |
2804 | wmsg.rect.left, wmsg.rect.top, | |
2805 | wmsg.rect.right, wmsg.rect.bottom)); | |
ce6059da | 2806 | #endif /* W32_DEBUG_DISPLAY */ |
a6085637 | 2807 | } |
5ac45f98 GV |
2808 | return 1; |
2809 | case WM_PALETTECHANGED: | |
2810 | /* ignore our own changes */ | |
2811 | if ((HWND)wParam != hwnd) | |
2812 | { | |
a6085637 KH |
2813 | f = x_window_to_frame (dpyinfo, hwnd); |
2814 | if (f) | |
2815 | /* get_frame_dc will realize our palette and force all | |
2816 | frames to be redrawn if needed. */ | |
2817 | release_frame_dc (f, get_frame_dc (f)); | |
5ac45f98 GV |
2818 | } |
2819 | return 0; | |
ee78dc32 | 2820 | case WM_PAINT: |
ce6059da | 2821 | { |
55dcfc15 AI |
2822 | PAINTSTRUCT paintStruct; |
2823 | RECT update_rect; | |
aa35b6ad | 2824 | bzero (&update_rect, sizeof (update_rect)); |
55dcfc15 | 2825 | |
18f0b342 AI |
2826 | f = x_window_to_frame (dpyinfo, hwnd); |
2827 | if (f == 0) | |
2828 | { | |
2829 | DebPrint (("WM_PAINT received for unknown window %p\n", hwnd)); | |
2830 | return 0; | |
2831 | } | |
2832 | ||
55dcfc15 AI |
2833 | /* MSDN Docs say not to call BeginPaint if GetUpdateRect |
2834 | fails. Apparently this can happen under some | |
2835 | circumstances. */ | |
aa35b6ad | 2836 | if (GetUpdateRect (hwnd, &update_rect, FALSE) || !w32_strict_painting) |
55dcfc15 AI |
2837 | { |
2838 | enter_crit (); | |
2839 | BeginPaint (hwnd, &paintStruct); | |
2840 | ||
aa35b6ad JR |
2841 | /* The rectangles returned by GetUpdateRect and BeginPaint |
2842 | do not always match. Play it safe by assuming both areas | |
2843 | are invalid. */ | |
2844 | UnionRect (&(wmsg.rect), &update_rect, &(paintStruct.rcPaint)); | |
55dcfc15 AI |
2845 | |
2846 | #if defined (W32_DEBUG_DISPLAY) | |
18f0b342 AI |
2847 | DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n", |
2848 | f, | |
2849 | wmsg.rect.left, wmsg.rect.top, | |
2850 | wmsg.rect.right, wmsg.rect.bottom)); | |
2851 | DebPrint ((" [update region is %d,%d-%d,%d]\n", | |
55dcfc15 AI |
2852 | update_rect.left, update_rect.top, |
2853 | update_rect.right, update_rect.bottom)); | |
2854 | #endif | |
2855 | EndPaint (hwnd, &paintStruct); | |
2856 | leave_crit (); | |
2857 | ||
2858 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); | |
7d0393cf | 2859 | |
55dcfc15 AI |
2860 | return 0; |
2861 | } | |
c0611964 AI |
2862 | |
2863 | /* If GetUpdateRect returns 0 (meaning there is no update | |
2864 | region), assume the whole window needs to be repainted. */ | |
2865 | GetClientRect(hwnd, &wmsg.rect); | |
2866 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); | |
2867 | return 0; | |
ee78dc32 | 2868 | } |
a1a80b40 | 2869 | |
ccc2d29c GV |
2870 | case WM_INPUTLANGCHANGE: |
2871 | /* Inform lisp thread of keyboard layout changes. */ | |
2872 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); | |
2873 | ||
2874 | /* Clear dead keys in the keyboard state; for simplicity only | |
2875 | preserve modifier key states. */ | |
2876 | { | |
2877 | int i; | |
2878 | BYTE keystate[256]; | |
2879 | ||
2880 | GetKeyboardState (keystate); | |
2881 | for (i = 0; i < 256; i++) | |
2882 | if (1 | |
2883 | && i != VK_SHIFT | |
2884 | && i != VK_LSHIFT | |
2885 | && i != VK_RSHIFT | |
2886 | && i != VK_CAPITAL | |
2887 | && i != VK_NUMLOCK | |
2888 | && i != VK_SCROLL | |
2889 | && i != VK_CONTROL | |
2890 | && i != VK_LCONTROL | |
2891 | && i != VK_RCONTROL | |
2892 | && i != VK_MENU | |
2893 | && i != VK_LMENU | |
2894 | && i != VK_RMENU | |
2895 | && i != VK_LWIN | |
2896 | && i != VK_RWIN) | |
2897 | keystate[i] = 0; | |
2898 | SetKeyboardState (keystate); | |
2899 | } | |
2900 | goto dflt; | |
2901 | ||
2902 | case WM_HOTKEY: | |
2903 | /* Synchronize hot keys with normal input. */ | |
2904 | PostMessage (hwnd, WM_KEYDOWN, HIWORD (lParam), 0); | |
2905 | return (0); | |
2906 | ||
a1a80b40 GV |
2907 | case WM_KEYUP: |
2908 | case WM_SYSKEYUP: | |
2909 | record_keyup (wParam, lParam); | |
2910 | goto dflt; | |
2911 | ||
ee78dc32 GV |
2912 | case WM_KEYDOWN: |
2913 | case WM_SYSKEYDOWN: | |
ccc2d29c GV |
2914 | /* Ignore keystrokes we fake ourself; see below. */ |
2915 | if (dpyinfo->faked_key == wParam) | |
2916 | { | |
2917 | dpyinfo->faked_key = 0; | |
576ba81c AI |
2918 | /* Make sure TranslateMessage sees them though (as long as |
2919 | they don't produce WM_CHAR messages). This ensures that | |
2920 | indicator lights are toggled promptly on Windows 9x, for | |
2921 | example. */ | |
2922 | if (lispy_function_keys[wParam] != 0) | |
2923 | { | |
2924 | windows_translate = 1; | |
2925 | goto translate; | |
2926 | } | |
2927 | return 0; | |
ccc2d29c GV |
2928 | } |
2929 | ||
7830e24b RS |
2930 | /* Synchronize modifiers with current keystroke. */ |
2931 | sync_modifiers (); | |
a1a80b40 | 2932 | record_keydown (wParam, lParam); |
ccc2d29c | 2933 | wParam = map_keypad_keys (wParam, (lParam & 0x1000000L) != 0); |
84fb1139 KH |
2934 | |
2935 | windows_translate = 0; | |
ccc2d29c GV |
2936 | |
2937 | switch (wParam) | |
2938 | { | |
2939 | case VK_LWIN: | |
2940 | if (NILP (Vw32_pass_lwindow_to_system)) | |
2941 | { | |
2942 | /* Prevent system from acting on keyup (which opens the | |
2943 | Start menu if no other key was pressed) by simulating a | |
2944 | press of Space which we will ignore. */ | |
2945 | if (GetAsyncKeyState (wParam) & 1) | |
2946 | { | |
adcc3809 | 2947 | if (NUMBERP (Vw32_phantom_key_code)) |
576ba81c | 2948 | key = XUINT (Vw32_phantom_key_code) & 255; |
adcc3809 | 2949 | else |
576ba81c AI |
2950 | key = VK_SPACE; |
2951 | dpyinfo->faked_key = key; | |
2952 | keybd_event (key, (BYTE) MapVirtualKey (key, 0), 0, 0); | |
ccc2d29c GV |
2953 | } |
2954 | } | |
2955 | if (!NILP (Vw32_lwindow_modifier)) | |
2956 | return 0; | |
2957 | break; | |
2958 | case VK_RWIN: | |
2959 | if (NILP (Vw32_pass_rwindow_to_system)) | |
2960 | { | |
2961 | if (GetAsyncKeyState (wParam) & 1) | |
2962 | { | |
adcc3809 | 2963 | if (NUMBERP (Vw32_phantom_key_code)) |
576ba81c | 2964 | key = XUINT (Vw32_phantom_key_code) & 255; |
adcc3809 | 2965 | else |
576ba81c AI |
2966 | key = VK_SPACE; |
2967 | dpyinfo->faked_key = key; | |
2968 | keybd_event (key, (BYTE) MapVirtualKey (key, 0), 0, 0); | |
ccc2d29c GV |
2969 | } |
2970 | } | |
2971 | if (!NILP (Vw32_rwindow_modifier)) | |
2972 | return 0; | |
2973 | break; | |
576ba81c | 2974 | case VK_APPS: |
ccc2d29c GV |
2975 | if (!NILP (Vw32_apps_modifier)) |
2976 | return 0; | |
2977 | break; | |
2978 | case VK_MENU: | |
7d0393cf | 2979 | if (NILP (Vw32_pass_alt_to_system)) |
adcc3809 GV |
2980 | /* Prevent DefWindowProc from activating the menu bar if an |
2981 | Alt key is pressed and released by itself. */ | |
ccc2d29c | 2982 | return 0; |
84fb1139 | 2983 | windows_translate = 1; |
ccc2d29c | 2984 | break; |
7d0393cf | 2985 | case VK_CAPITAL: |
ccc2d29c GV |
2986 | /* Decide whether to treat as modifier or function key. */ |
2987 | if (NILP (Vw32_enable_caps_lock)) | |
2988 | goto disable_lock_key; | |
adcc3809 GV |
2989 | windows_translate = 1; |
2990 | break; | |
ccc2d29c GV |
2991 | case VK_NUMLOCK: |
2992 | /* Decide whether to treat as modifier or function key. */ | |
2993 | if (NILP (Vw32_enable_num_lock)) | |
2994 | goto disable_lock_key; | |
adcc3809 GV |
2995 | windows_translate = 1; |
2996 | break; | |
ccc2d29c GV |
2997 | case VK_SCROLL: |
2998 | /* Decide whether to treat as modifier or function key. */ | |
2999 | if (NILP (Vw32_scroll_lock_modifier)) | |
3000 | goto disable_lock_key; | |
adcc3809 GV |
3001 | windows_translate = 1; |
3002 | break; | |
ccc2d29c | 3003 | disable_lock_key: |
adcc3809 GV |
3004 | /* Ensure the appropriate lock key state (and indicator light) |
3005 | remains in the same state. We do this by faking another | |
3006 | press of the relevant key. Apparently, this really is the | |
3007 | only way to toggle the state of the indicator lights. */ | |
3008 | dpyinfo->faked_key = wParam; | |
3009 | keybd_event ((BYTE) wParam, (BYTE) MapVirtualKey (wParam, 0), | |
3010 | KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); | |
3011 | keybd_event ((BYTE) wParam, (BYTE) MapVirtualKey (wParam, 0), | |
3012 | KEYEVENTF_EXTENDEDKEY | 0, 0); | |
3013 | keybd_event ((BYTE) wParam, (BYTE) MapVirtualKey (wParam, 0), | |
3014 | KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); | |
3015 | /* Ensure indicator lights are updated promptly on Windows 9x | |
3016 | (TranslateMessage apparently does this), after forwarding | |
3017 | input event. */ | |
3018 | post_character_message (hwnd, msg, wParam, lParam, | |
3019 | w32_get_key_modifiers (wParam, lParam)); | |
3020 | windows_translate = 1; | |
ccc2d29c | 3021 | break; |
7d0393cf | 3022 | case VK_CONTROL: |
ccc2d29c GV |
3023 | case VK_SHIFT: |
3024 | case VK_PROCESSKEY: /* Generated by IME. */ | |
3025 | windows_translate = 1; | |
3026 | break; | |
adcc3809 GV |
3027 | case VK_CANCEL: |
3028 | /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL, | |
3029 | which is confusing for purposes of key binding; convert | |
3030 | VK_CANCEL events into VK_PAUSE events. */ | |
3031 | wParam = VK_PAUSE; | |
3032 | break; | |
3033 | case VK_PAUSE: | |
3034 | /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing | |
3035 | for purposes of key binding; convert these back into | |
3036 | VK_NUMLOCK events, at least when we want to see NumLock key | |
3037 | presses. (Note that there is never any possibility that | |
3038 | VK_PAUSE with Ctrl really is C-Pause as per above.) */ | |
3039 | if (NILP (Vw32_enable_num_lock) && modifier_set (VK_CONTROL)) | |
3040 | wParam = VK_NUMLOCK; | |
3041 | break; | |
ccc2d29c GV |
3042 | default: |
3043 | /* If not defined as a function key, change it to a WM_CHAR message. */ | |
3044 | if (lispy_function_keys[wParam] == 0) | |
3045 | { | |
adcc3809 GV |
3046 | DWORD modifiers = construct_console_modifiers (); |
3047 | ||
ccc2d29c GV |
3048 | if (!NILP (Vw32_recognize_altgr) |
3049 | && modifier_set (VK_LCONTROL) && modifier_set (VK_RMENU)) | |
3050 | { | |
3051 | /* Always let TranslateMessage handle AltGr key chords; | |
3052 | for some reason, ToAscii doesn't always process AltGr | |
3053 | chords correctly. */ | |
3054 | windows_translate = 1; | |
3055 | } | |
adcc3809 | 3056 | else if ((modifiers & (~SHIFT_PRESSED & ~CAPSLOCK_ON)) != 0) |
ccc2d29c | 3057 | { |
adcc3809 GV |
3058 | /* Handle key chords including any modifiers other |
3059 | than shift directly, in order to preserve as much | |
3060 | modifier information as possible. */ | |
ccc2d29c GV |
3061 | if ('A' <= wParam && wParam <= 'Z') |
3062 | { | |
3063 | /* Don't translate modified alphabetic keystrokes, | |
3064 | so the user doesn't need to constantly switch | |
3065 | layout to type control or meta keystrokes when | |
3066 | the normal layout translates alphabetic | |
3067 | characters to non-ascii characters. */ | |
3068 | if (!modifier_set (VK_SHIFT)) | |
3069 | wParam += ('a' - 'A'); | |
3070 | msg = WM_CHAR; | |
3071 | } | |
3072 | else | |
3073 | { | |
3074 | /* Try to handle other keystrokes by determining the | |
3075 | base character (ie. translating the base key plus | |
3076 | shift modifier). */ | |
3077 | int add; | |
3078 | int isdead = 0; | |
3079 | KEY_EVENT_RECORD key; | |
7d0393cf | 3080 | |
ccc2d29c GV |
3081 | key.bKeyDown = TRUE; |
3082 | key.wRepeatCount = 1; | |
3083 | key.wVirtualKeyCode = wParam; | |
3084 | key.wVirtualScanCode = (lParam & 0xFF0000) >> 16; | |
3085 | key.uChar.AsciiChar = 0; | |
adcc3809 | 3086 | key.dwControlKeyState = modifiers; |
ccc2d29c GV |
3087 | |
3088 | add = w32_kbd_patch_key (&key); | |
3089 | /* 0 means an unrecognised keycode, negative means | |
3090 | dead key. Ignore both. */ | |
3091 | while (--add >= 0) | |
3092 | { | |
3093 | /* Forward asciified character sequence. */ | |
3094 | post_character_message | |
3095 | (hwnd, WM_CHAR, key.uChar.AsciiChar, lParam, | |
3096 | w32_get_key_modifiers (wParam, lParam)); | |
3097 | w32_kbd_patch_key (&key); | |
3098 | } | |
3099 | return 0; | |
3100 | } | |
3101 | } | |
3102 | else | |
3103 | { | |
3104 | /* Let TranslateMessage handle everything else. */ | |
3105 | windows_translate = 1; | |
3106 | } | |
3107 | } | |
3108 | } | |
a1a80b40 | 3109 | |
adcc3809 | 3110 | translate: |
84fb1139 KH |
3111 | if (windows_translate) |
3112 | { | |
e9e23e23 | 3113 | MSG windows_msg = { hwnd, msg, wParam, lParam, 0, {0,0} }; |
84fb1139 | 3114 | |
e9e23e23 GV |
3115 | windows_msg.time = GetMessageTime (); |
3116 | TranslateMessage (&windows_msg); | |
84fb1139 KH |
3117 | goto dflt; |
3118 | } | |
3119 | ||
ee78dc32 | 3120 | /* Fall through */ |
7d0393cf | 3121 | |
ee78dc32 GV |
3122 | case WM_SYSCHAR: |
3123 | case WM_CHAR: | |
ccc2d29c GV |
3124 | post_character_message (hwnd, msg, wParam, lParam, |
3125 | w32_get_key_modifiers (wParam, lParam)); | |
ee78dc32 | 3126 | break; |
da36a4d6 | 3127 | |
5ac45f98 GV |
3128 | /* Simulate middle mouse button events when left and right buttons |
3129 | are used together, but only if user has two button mouse. */ | |
ee78dc32 | 3130 | case WM_LBUTTONDOWN: |
5ac45f98 | 3131 | case WM_RBUTTONDOWN: |
2ba49441 | 3132 | if (w32_num_mouse_buttons > 2) |
5ac45f98 GV |
3133 | goto handle_plain_button; |
3134 | ||
3135 | { | |
3136 | int this = (msg == WM_LBUTTONDOWN) ? LMOUSE : RMOUSE; | |
3137 | int other = (msg == WM_LBUTTONDOWN) ? RMOUSE : LMOUSE; | |
3138 | ||
3cb20f4a RS |
3139 | if (button_state & this) |
3140 | return 0; | |
5ac45f98 GV |
3141 | |
3142 | if (button_state == 0) | |
3143 | SetCapture (hwnd); | |
3144 | ||
3145 | button_state |= this; | |
3146 | ||
3147 | if (button_state & other) | |
3148 | { | |
84fb1139 | 3149 | if (mouse_button_timer) |
5ac45f98 | 3150 | { |
84fb1139 KH |
3151 | KillTimer (hwnd, mouse_button_timer); |
3152 | mouse_button_timer = 0; | |
5ac45f98 GV |
3153 | |
3154 | /* Generate middle mouse event instead. */ | |
3155 | msg = WM_MBUTTONDOWN; | |
3156 | button_state |= MMOUSE; | |
3157 | } | |
3158 | else if (button_state & MMOUSE) | |
3159 | { | |
3160 | /* Ignore button event if we've already generated a | |
3161 | middle mouse down event. This happens if the | |
3162 | user releases and press one of the two buttons | |
3163 | after we've faked a middle mouse event. */ | |
3164 | return 0; | |
3165 | } | |
3166 | else | |
3167 | { | |
3168 | /* Flush out saved message. */ | |
84fb1139 | 3169 | post_msg (&saved_mouse_button_msg); |
5ac45f98 | 3170 | } |
fbd6baed | 3171 | wmsg.dwModifiers = w32_get_modifiers (); |
5ac45f98 GV |
3172 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); |
3173 | ||
3174 | /* Clear message buffer. */ | |
84fb1139 | 3175 | saved_mouse_button_msg.msg.hwnd = 0; |
5ac45f98 GV |
3176 | } |
3177 | else | |
3178 | { | |
3179 | /* Hold onto message for now. */ | |
84fb1139 | 3180 | mouse_button_timer = |
adcc3809 | 3181 | SetTimer (hwnd, MOUSE_BUTTON_ID, |
2ba49441 | 3182 | w32_mouse_button_tolerance, NULL); |
84fb1139 KH |
3183 | saved_mouse_button_msg.msg.hwnd = hwnd; |
3184 | saved_mouse_button_msg.msg.message = msg; | |
3185 | saved_mouse_button_msg.msg.wParam = wParam; | |
3186 | saved_mouse_button_msg.msg.lParam = lParam; | |
3187 | saved_mouse_button_msg.msg.time = GetMessageTime (); | |
fbd6baed | 3188 | saved_mouse_button_msg.dwModifiers = w32_get_modifiers (); |
5ac45f98 GV |
3189 | } |
3190 | } | |
3191 | return 0; | |
3192 | ||
ee78dc32 | 3193 | case WM_LBUTTONUP: |
5ac45f98 | 3194 | case WM_RBUTTONUP: |
2ba49441 | 3195 | if (w32_num_mouse_buttons > 2) |
5ac45f98 GV |
3196 | goto handle_plain_button; |
3197 | ||
3198 | { | |
3199 | int this = (msg == WM_LBUTTONUP) ? LMOUSE : RMOUSE; | |
3200 | int other = (msg == WM_LBUTTONUP) ? RMOUSE : LMOUSE; | |
3201 | ||
3cb20f4a RS |
3202 | if ((button_state & this) == 0) |
3203 | return 0; | |
5ac45f98 GV |
3204 | |
3205 | button_state &= ~this; | |
3206 | ||
3207 | if (button_state & MMOUSE) | |
3208 | { | |
3209 | /* Only generate event when second button is released. */ | |
3210 | if ((button_state & other) == 0) | |
3211 | { | |
3212 | msg = WM_MBUTTONUP; | |
3213 | button_state &= ~MMOUSE; | |
3214 | ||
3215 | if (button_state) abort (); | |
3216 | } | |
3217 | else | |
3218 | return 0; | |
3219 | } | |
3220 | else | |
3221 | { | |
3222 | /* Flush out saved message if necessary. */ | |
84fb1139 | 3223 | if (saved_mouse_button_msg.msg.hwnd) |
5ac45f98 | 3224 | { |
84fb1139 | 3225 | post_msg (&saved_mouse_button_msg); |
5ac45f98 GV |
3226 | } |
3227 | } | |
fbd6baed | 3228 | wmsg.dwModifiers = w32_get_modifiers (); |
5ac45f98 GV |
3229 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); |
3230 | ||
3231 | /* Always clear message buffer and cancel timer. */ | |
84fb1139 KH |
3232 | saved_mouse_button_msg.msg.hwnd = 0; |
3233 | KillTimer (hwnd, mouse_button_timer); | |
3234 | mouse_button_timer = 0; | |
5ac45f98 GV |
3235 | |
3236 | if (button_state == 0) | |
3237 | ReleaseCapture (); | |
3238 | } | |
3239 | return 0; | |
3240 | ||
74214547 JR |
3241 | case WM_XBUTTONDOWN: |
3242 | case WM_XBUTTONUP: | |
3243 | if (w32_pass_extra_mouse_buttons_to_system) | |
3244 | goto dflt; | |
3245 | /* else fall through and process them. */ | |
ee78dc32 GV |
3246 | case WM_MBUTTONDOWN: |
3247 | case WM_MBUTTONUP: | |
5ac45f98 | 3248 | handle_plain_button: |
ee78dc32 GV |
3249 | { |
3250 | BOOL up; | |
1edf84e7 | 3251 | int button; |
ee78dc32 | 3252 | |
74214547 | 3253 | if (parse_button (msg, HIWORD (wParam), &button, &up)) |
ee78dc32 GV |
3254 | { |
3255 | if (up) ReleaseCapture (); | |
3256 | else SetCapture (hwnd); | |
7d0393cf | 3257 | button = (button == 0) ? LMOUSE : |
1edf84e7 GV |
3258 | ((button == 1) ? MMOUSE : RMOUSE); |
3259 | if (up) | |
3260 | button_state &= ~button; | |
3261 | else | |
3262 | button_state |= button; | |
ee78dc32 GV |
3263 | } |
3264 | } | |
7d0393cf | 3265 | |
fbd6baed | 3266 | wmsg.dwModifiers = w32_get_modifiers (); |
ee78dc32 | 3267 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); |
74214547 JR |
3268 | |
3269 | /* Need to return true for XBUTTON messages, false for others, | |
3270 | to indicate that we processed the message. */ | |
3271 | return (msg == WM_XBUTTONDOWN || msg == WM_XBUTTONUP); | |
5ac45f98 | 3272 | |
5ac45f98 | 3273 | case WM_MOUSEMOVE: |
9eb16b62 JR |
3274 | /* If the mouse has just moved into the frame, start tracking |
3275 | it, so we will be notified when it leaves the frame. Mouse | |
3276 | tracking only works under W98 and NT4 and later. On earlier | |
3277 | versions, there is no way of telling when the mouse leaves the | |
3278 | frame, so we just have to put up with help-echo and mouse | |
3279 | highlighting remaining while the frame is not active. */ | |
3280 | if (track_mouse_event_fn && !track_mouse_window) | |
3281 | { | |
3282 | TRACKMOUSEEVENT tme; | |
3283 | tme.cbSize = sizeof (tme); | |
3284 | tme.dwFlags = TME_LEAVE; | |
3285 | tme.hwndTrack = hwnd; | |
3286 | ||
3287 | track_mouse_event_fn (&tme); | |
3288 | track_mouse_window = hwnd; | |
3289 | } | |
3290 | case WM_VSCROLL: | |
2ba49441 | 3291 | if (w32_mouse_move_interval <= 0 |
84fb1139 KH |
3292 | || (msg == WM_MOUSEMOVE && button_state == 0)) |
3293 | { | |
fbd6baed | 3294 | wmsg.dwModifiers = w32_get_modifiers (); |
84fb1139 KH |
3295 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); |
3296 | return 0; | |
3297 | } | |
7d0393cf | 3298 | |
84fb1139 KH |
3299 | /* Hang onto mouse move and scroll messages for a bit, to avoid |
3300 | sending such events to Emacs faster than it can process them. | |
3301 | If we get more events before the timer from the first message | |
3302 | expires, we just replace the first message. */ | |
3303 | ||
3304 | if (saved_mouse_move_msg.msg.hwnd == 0) | |
3305 | mouse_move_timer = | |
adcc3809 | 3306 | SetTimer (hwnd, MOUSE_MOVE_ID, |
2ba49441 | 3307 | w32_mouse_move_interval, NULL); |
84fb1139 KH |
3308 | |
3309 | /* Hold onto message for now. */ | |
3310 | saved_mouse_move_msg.msg.hwnd = hwnd; | |
3311 | saved_mouse_move_msg.msg.message = msg; | |
3312 | saved_mouse_move_msg.msg.wParam = wParam; | |
3313 | saved_mouse_move_msg.msg.lParam = lParam; | |
3314 | saved_mouse_move_msg.msg.time = GetMessageTime (); | |
fbd6baed | 3315 | saved_mouse_move_msg.dwModifiers = w32_get_modifiers (); |
7d0393cf | 3316 | |
84fb1139 KH |
3317 | return 0; |
3318 | ||
1edf84e7 GV |
3319 | case WM_MOUSEWHEEL: |
3320 | wmsg.dwModifiers = w32_get_modifiers (); | |
3321 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); | |
3322 | return 0; | |
3323 | ||
cb9e33d4 RS |
3324 | case WM_DROPFILES: |
3325 | wmsg.dwModifiers = w32_get_modifiers (); | |
3326 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); | |
3327 | return 0; | |
3328 | ||
84fb1139 KH |
3329 | case WM_TIMER: |
3330 | /* Flush out saved messages if necessary. */ | |
3331 | if (wParam == mouse_button_timer) | |
5ac45f98 | 3332 | { |
84fb1139 KH |
3333 | if (saved_mouse_button_msg.msg.hwnd) |
3334 | { | |
3335 | post_msg (&saved_mouse_button_msg); | |
3336 | saved_mouse_button_msg.msg.hwnd = 0; | |
3337 | } | |
3338 | KillTimer (hwnd, mouse_button_timer); | |
3339 | mouse_button_timer = 0; | |
3340 | } | |
3341 | else if (wParam == mouse_move_timer) | |
3342 | { | |
3343 | if (saved_mouse_move_msg.msg.hwnd) | |
3344 | { | |
3345 | post_msg (&saved_mouse_move_msg); | |
3346 | saved_mouse_move_msg.msg.hwnd = 0; | |
3347 | } | |
3348 | KillTimer (hwnd, mouse_move_timer); | |
3349 | mouse_move_timer = 0; | |
5ac45f98 | 3350 | } |
48094ace JR |
3351 | else if (wParam == menu_free_timer) |
3352 | { | |
3353 | KillTimer (hwnd, menu_free_timer); | |
3354 | menu_free_timer = 0; | |
27605fa7 | 3355 | f = x_window_to_frame (dpyinfo, hwnd); |
48094ace JR |
3356 | if (!f->output_data.w32->menu_command_in_progress) |
3357 | { | |
3358 | /* Free memory used by owner-drawn and help-echo strings. */ | |
3359 | w32_free_menu_strings (hwnd); | |
3360 | f->output_data.w32->menubar_active = 0; | |
3361 | } | |
3362 | } | |
5ac45f98 | 3363 | return 0; |
7d0393cf | 3364 | |
84fb1139 KH |
3365 | case WM_NCACTIVATE: |
3366 | /* Windows doesn't send us focus messages when putting up and | |
e9e23e23 | 3367 | taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95. |
84fb1139 KH |
3368 | The only indication we get that something happened is receiving |
3369 | this message afterwards. So this is a good time to reset our | |
3370 | keyboard modifiers' state. */ | |
3371 | reset_modifiers (); | |
3372 | goto dflt; | |
da36a4d6 | 3373 | |
1edf84e7 | 3374 | case WM_INITMENU: |
487163ac AI |
3375 | button_state = 0; |
3376 | ReleaseCapture (); | |
1edf84e7 GV |
3377 | /* We must ensure menu bar is fully constructed and up to date |
3378 | before allowing user interaction with it. To achieve this | |
3379 | we send this message to the lisp thread and wait for a | |
3380 | reply (whose value is not actually needed) to indicate that | |
3381 | the menu bar is now ready for use, so we can now return. | |
3382 | ||
3383 | To remain responsive in the meantime, we enter a nested message | |
3384 | loop that can process all other messages. | |
3385 | ||
3386 | However, we skip all this if the message results from calling | |
3387 | TrackPopupMenu - in fact, we must NOT attempt to send the lisp | |
3388 | thread a message because it is blocked on us at this point. We | |
3389 | set menubar_active before calling TrackPopupMenu to indicate | |
3390 | this (there is no possibility of confusion with real menubar | |
3391 | being active). */ | |
3392 | ||
3393 | f = x_window_to_frame (dpyinfo, hwnd); | |
3394 | if (f | |
3395 | && (f->output_data.w32->menubar_active | |
3396 | /* We can receive this message even in the absence of a | |
3397 | menubar (ie. when the system menu is activated) - in this | |
3398 | case we do NOT want to forward the message, otherwise it | |
3399 | will cause the menubar to suddenly appear when the user | |
3400 | had requested it to be turned off! */ | |
3401 | || f->output_data.w32->menubar_widget == NULL)) | |
3402 | return 0; | |
3403 | ||
3404 | { | |
3405 | deferred_msg msg_buf; | |
3406 | ||
3407 | /* Detect if message has already been deferred; in this case | |
3408 | we cannot return any sensible value to ignore this. */ | |
3409 | if (find_deferred_msg (hwnd, msg) != NULL) | |
3410 | abort (); | |
3411 | ||
3412 | return send_deferred_msg (&msg_buf, hwnd, msg, wParam, lParam); | |
3413 | } | |
3414 | ||
3415 | case WM_EXITMENULOOP: | |
3416 | f = x_window_to_frame (dpyinfo, hwnd); | |
3417 | ||
48094ace JR |
3418 | /* If a menu command is not already in progress, check again |
3419 | after a short delay, since Windows often (always?) sends the | |
3420 | WM_EXITMENULOOP before the corresponding WM_COMMAND message. */ | |
3421 | if (f && !f->output_data.w32->menu_command_in_progress) | |
3422 | menu_free_timer = SetTimer (hwnd, MENU_FREE_ID, MENU_FREE_DELAY, NULL); | |
1edf84e7 GV |
3423 | goto dflt; |
3424 | ||
126f2e35 | 3425 | case WM_MENUSELECT: |
4e3a1c61 JR |
3426 | /* Direct handling of help_echo in menus. Should be safe now |
3427 | that we generate the help_echo by placing a help event in the | |
3428 | keyboard buffer. */ | |
ca56d953 | 3429 | { |
ca56d953 JR |
3430 | HMENU menu = (HMENU) lParam; |
3431 | UINT menu_item = (UINT) LOWORD (wParam); | |
3432 | UINT flags = (UINT) HIWORD (wParam); | |
3433 | ||
4e3a1c61 | 3434 | w32_menu_display_help (hwnd, menu, menu_item, flags); |
ca56d953 | 3435 | } |
126f2e35 JR |
3436 | return 0; |
3437 | ||
87996783 GV |
3438 | case WM_MEASUREITEM: |
3439 | f = x_window_to_frame (dpyinfo, hwnd); | |
3440 | if (f) | |
3441 | { | |
3442 | MEASUREITEMSTRUCT * pMis = (MEASUREITEMSTRUCT *) lParam; | |
3443 | ||
3444 | if (pMis->CtlType == ODT_MENU) | |
3445 | { | |
3446 | /* Work out dimensions for popup menu titles. */ | |
3447 | char * title = (char *) pMis->itemData; | |
3448 | HDC hdc = GetDC (hwnd); | |
3449 | HFONT menu_font = GetCurrentObject (hdc, OBJ_FONT); | |
3450 | LOGFONT menu_logfont; | |
3451 | HFONT old_font; | |
3452 | SIZE size; | |
3453 | ||
3454 | GetObject (menu_font, sizeof (menu_logfont), &menu_logfont); | |
3455 | menu_logfont.lfWeight = FW_BOLD; | |
3456 | menu_font = CreateFontIndirect (&menu_logfont); | |
3457 | old_font = SelectObject (hdc, menu_font); | |
3458 | ||
dfff8a69 JR |
3459 | pMis->itemHeight = GetSystemMetrics (SM_CYMENUSIZE); |
3460 | if (title) | |
3461 | { | |
b4005349 JR |
3462 | if (unicode_append_menu) |
3463 | GetTextExtentPoint32W (hdc, (WCHAR *) title, | |
3464 | wcslen ((WCHAR *) title), | |
3465 | &size); | |
3466 | else | |
3467 | GetTextExtentPoint32 (hdc, title, strlen (title), &size); | |
3468 | ||
dfff8a69 JR |
3469 | pMis->itemWidth = size.cx; |
3470 | if (pMis->itemHeight < size.cy) | |
3471 | pMis->itemHeight = size.cy; | |
3472 | } | |
3473 | else | |
3474 | pMis->itemWidth = 0; | |
87996783 GV |
3475 | |
3476 | SelectObject (hdc, old_font); | |
3477 | DeleteObject (menu_font); | |
3478 | ReleaseDC (hwnd, hdc); | |
3479 | return TRUE; | |
3480 | } | |
3481 | } | |
3482 | return 0; | |
3483 | ||
3484 | case WM_DRAWITEM: | |
3485 | f = x_window_to_frame (dpyinfo, hwnd); | |
3486 | if (f) | |
3487 | { | |
3488 | DRAWITEMSTRUCT * pDis = (DRAWITEMSTRUCT *) lParam; | |
3489 | ||
3490 | if (pDis->CtlType == ODT_MENU) | |
3491 | { | |
3492 | /* Draw popup menu title. */ | |
3493 | char * title = (char *) pDis->itemData; | |
212da13b JR |
3494 | if (title) |
3495 | { | |
3496 | HDC hdc = pDis->hDC; | |
3497 | HFONT menu_font = GetCurrentObject (hdc, OBJ_FONT); | |
3498 | LOGFONT menu_logfont; | |
3499 | HFONT old_font; | |
3500 | ||
3501 | GetObject (menu_font, sizeof (menu_logfont), &menu_logfont); | |
3502 | menu_logfont.lfWeight = FW_BOLD; | |
3503 | menu_font = CreateFontIndirect (&menu_logfont); | |
3504 | old_font = SelectObject (hdc, menu_font); | |
3505 | ||
b4005349 JR |
3506 | /* Always draw title as if not selected. */ |
3507 | if (unicode_append_menu) | |
3508 | ExtTextOutW (hdc, | |
3509 | pDis->rcItem.left | |
3510 | + GetSystemMetrics (SM_CXMENUCHECK), | |
3511 | pDis->rcItem.top, | |
3512 | ETO_OPAQUE, &pDis->rcItem, | |
3513 | (WCHAR *) title, | |
3514 | wcslen ((WCHAR *) title), NULL); | |
3515 | else | |
3516 | ExtTextOut (hdc, | |
3517 | pDis->rcItem.left | |
3518 | + GetSystemMetrics (SM_CXMENUCHECK), | |
3519 | pDis->rcItem.top, | |
3520 | ETO_OPAQUE, &pDis->rcItem, | |
3521 | title, strlen (title), NULL); | |
212da13b JR |
3522 | |
3523 | SelectObject (hdc, old_font); | |
3524 | DeleteObject (menu_font); | |
3525 | } | |
87996783 GV |
3526 | return TRUE; |
3527 | } | |
3528 | } | |
3529 | return 0; | |
3530 | ||
1edf84e7 GV |
3531 | #if 0 |
3532 | /* Still not right - can't distinguish between clicks in the | |
3533 | client area of the frame from clicks forwarded from the scroll | |
3534 | bars - may have to hook WM_NCHITTEST to remember the mouse | |
3535 | position and then check if it is in the client area ourselves. */ | |
3536 | case WM_MOUSEACTIVATE: | |
3537 | /* Discard the mouse click that activates a frame, allowing the | |
3538 | user to click anywhere without changing point (or worse!). | |
3539 | Don't eat mouse clicks on scrollbars though!! */ | |
3540 | if (LOWORD (lParam) == HTCLIENT ) | |
3541 | return MA_ACTIVATEANDEAT; | |
3542 | goto dflt; | |
3543 | #endif | |
3544 | ||
9eb16b62 JR |
3545 | case WM_MOUSELEAVE: |
3546 | /* No longer tracking mouse. */ | |
3547 | track_mouse_window = NULL; | |
3548 | ||
1edf84e7 | 3549 | case WM_ACTIVATEAPP: |
ccc2d29c | 3550 | case WM_ACTIVATE: |
1edf84e7 GV |
3551 | case WM_WINDOWPOSCHANGED: |
3552 | case WM_SHOWWINDOW: | |
3553 | /* Inform lisp thread that a frame might have just been obscured | |
3554 | or exposed, so should recheck visibility of all frames. */ | |
3555 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); | |
3556 | goto dflt; | |
3557 | ||
da36a4d6 | 3558 | case WM_SETFOCUS: |
adcc3809 GV |
3559 | dpyinfo->faked_key = 0; |
3560 | reset_modifiers (); | |
ccc2d29c GV |
3561 | register_hot_keys (hwnd); |
3562 | goto command; | |
8681157a | 3563 | case WM_KILLFOCUS: |
ccc2d29c | 3564 | unregister_hot_keys (hwnd); |
487163ac AI |
3565 | button_state = 0; |
3566 | ReleaseCapture (); | |
65906840 JR |
3567 | /* Relinquish the system caret. */ |
3568 | if (w32_system_caret_hwnd) | |
3569 | { | |
93f2ca61 | 3570 | w32_visible_system_caret_hwnd = NULL; |
d285988b JR |
3571 | w32_system_caret_hwnd = NULL; |
3572 | DestroyCaret (); | |
65906840 | 3573 | } |
48094ace JR |
3574 | goto command; |
3575 | case WM_COMMAND: | |
3576 | f = x_window_to_frame (dpyinfo, hwnd); | |
3577 | if (f && HIWORD (wParam) == 0) | |
3578 | { | |
3579 | f->output_data.w32->menu_command_in_progress = 1; | |
3580 | if (menu_free_timer) | |
3581 | { | |
3582 | KillTimer (hwnd, menu_free_timer); | |
7d0393cf | 3583 | menu_free_timer = 0; |
48094ace JR |
3584 | } |
3585 | } | |
ee78dc32 GV |
3586 | case WM_MOVE: |
3587 | case WM_SIZE: | |
ccc2d29c | 3588 | command: |
fbd6baed | 3589 | wmsg.dwModifiers = w32_get_modifiers (); |
ee78dc32 GV |
3590 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); |
3591 | goto dflt; | |
8847d890 RS |
3592 | |
3593 | case WM_CLOSE: | |
fbd6baed | 3594 | wmsg.dwModifiers = w32_get_modifiers (); |
8847d890 RS |
3595 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); |
3596 | return 0; | |
3597 | ||
ee78dc32 | 3598 | case WM_WINDOWPOSCHANGING: |
bfd6edcc JR |
3599 | /* Don't restrict the sizing of tip frames. */ |
3600 | if (hwnd == tip_window) | |
3601 | return 0; | |
ee78dc32 GV |
3602 | { |
3603 | WINDOWPLACEMENT wp; | |
3604 | LPWINDOWPOS lppos = (WINDOWPOS *) lParam; | |
1edf84e7 GV |
3605 | |
3606 | wp.length = sizeof (WINDOWPLACEMENT); | |
ee78dc32 | 3607 | GetWindowPlacement (hwnd, &wp); |
7d0393cf | 3608 | |
1edf84e7 | 3609 | if (wp.showCmd != SW_SHOWMINIMIZED && (lppos->flags & SWP_NOSIZE) == 0) |
ee78dc32 GV |
3610 | { |
3611 | RECT rect; | |
3612 | int wdiff; | |
3613 | int hdiff; | |
1edf84e7 GV |
3614 | DWORD font_width; |
3615 | DWORD line_height; | |
3616 | DWORD internal_border; | |
3617 | DWORD scrollbar_extra; | |
ee78dc32 | 3618 | RECT wr; |
7d0393cf | 3619 | |
5ac45f98 | 3620 | wp.length = sizeof(wp); |
ee78dc32 | 3621 | GetWindowRect (hwnd, &wr); |
7d0393cf | 3622 | |
3c190163 | 3623 | enter_crit (); |
7d0393cf | 3624 | |
1edf84e7 GV |
3625 | font_width = GetWindowLong (hwnd, WND_FONTWIDTH_INDEX); |
3626 | line_height = GetWindowLong (hwnd, WND_LINEHEIGHT_INDEX); | |
3627 | internal_border = GetWindowLong (hwnd, WND_BORDER_INDEX); | |
3628 | scrollbar_extra = GetWindowLong (hwnd, WND_SCROLLBAR_INDEX); | |
7d0393cf | 3629 | |
3c190163 | 3630 | leave_crit (); |
7d0393cf | 3631 | |
ee78dc32 | 3632 | memset (&rect, 0, sizeof (rect)); |
7d0393cf | 3633 | AdjustWindowRect (&rect, GetWindowLong (hwnd, GWL_STYLE), |
ee78dc32 GV |
3634 | GetMenu (hwnd) != NULL); |
3635 | ||
1edf84e7 GV |
3636 | /* Force width and height of client area to be exact |
3637 | multiples of the character cell dimensions. */ | |
3638 | wdiff = (lppos->cx - (rect.right - rect.left) | |
3639 | - 2 * internal_border - scrollbar_extra) | |
3640 | % font_width; | |
3641 | hdiff = (lppos->cy - (rect.bottom - rect.top) | |
3642 | - 2 * internal_border) | |
3643 | % line_height; | |
7d0393cf | 3644 | |
ee78dc32 GV |
3645 | if (wdiff || hdiff) |
3646 | { | |
7d0393cf JB |
3647 | /* For right/bottom sizing we can just fix the sizes. |
3648 | However for top/left sizing we will need to fix the X | |
ee78dc32 | 3649 | and Y positions as well. */ |
7d0393cf | 3650 | |
ee78dc32 GV |
3651 | lppos->cx -= wdiff; |
3652 | lppos->cy -= hdiff; | |
7d0393cf JB |
3653 | |
3654 | if (wp.showCmd != SW_SHOWMAXIMIZED | |
1edf84e7 | 3655 | && (lppos->flags & SWP_NOMOVE) == 0) |
ee78dc32 GV |
3656 | { |
3657 | if (lppos->x != wr.left || lppos->y != wr.top) | |
3658 | { | |
3659 | lppos->x += wdiff; | |
3660 | lppos->y += hdiff; | |
3661 | } | |
3662 | else | |
3663 | { | |
3664 | lppos->flags |= SWP_NOMOVE; | |
3665 | } | |
3666 | } | |
7d0393cf | 3667 | |
1edf84e7 | 3668 | return 0; |
ee78dc32 GV |
3669 | } |
3670 | } | |
3671 | } | |
7d0393cf | 3672 | |
ee78dc32 | 3673 | goto dflt; |
1edf84e7 | 3674 | |
b1f918f8 GV |
3675 | case WM_GETMINMAXINFO: |
3676 | /* Hack to correct bug that allows Emacs frames to be resized | |
3677 | below the Minimum Tracking Size. */ | |
3678 | ((LPMINMAXINFO) lParam)->ptMinTrackSize.y++; | |
bf853fee AI |
3679 | /* Hack to allow resizing the Emacs frame above the screen size. |
3680 | Note that Windows 9x limits coordinates to 16-bits. */ | |
3681 | ((LPMINMAXINFO) lParam)->ptMaxTrackSize.x = 32767; | |
3682 | ((LPMINMAXINFO) lParam)->ptMaxTrackSize.y = 32767; | |
b1f918f8 GV |
3683 | return 0; |
3684 | ||
c9b2104d JR |
3685 | case WM_SETCURSOR: |
3686 | if (LOWORD (lParam) == HTCLIENT) | |
3687 | return 0; | |
3688 | ||
3689 | goto dflt; | |
c922a224 | 3690 | |
c9b2104d JR |
3691 | case WM_EMACS_SETCURSOR: |
3692 | { | |
3693 | Cursor cursor = (Cursor) wParam; | |
3694 | if (cursor) | |
3695 | SetCursor (cursor); | |
3696 | return 0; | |
3697 | } | |
c922a224 | 3698 | |
1edf84e7 GV |
3699 | case WM_EMACS_CREATESCROLLBAR: |
3700 | return (LRESULT) w32_createscrollbar ((struct frame *) wParam, | |
3701 | (struct scroll_bar *) lParam); | |
3702 | ||
5ac45f98 | 3703 | case WM_EMACS_SHOWWINDOW: |
1edf84e7 GV |
3704 | return ShowWindow ((HWND) wParam, (WPARAM) lParam); |
3705 | ||
dfdb4047 | 3706 | case WM_EMACS_SETFOREGROUND: |
ce6059da AI |
3707 | { |
3708 | HWND foreground_window; | |
3709 | DWORD foreground_thread, retval; | |
3710 | ||
3711 | /* On NT 5.0, and apparently Windows 98, it is necessary to | |
3712 | attach to the thread that currently has focus in order to | |
3713 | pull the focus away from it. */ | |
3714 | foreground_window = GetForegroundWindow (); | |
3715 | foreground_thread = GetWindowThreadProcessId (foreground_window, NULL); | |
3716 | if (!foreground_window | |
3717 | || foreground_thread == GetCurrentThreadId () | |
3718 | || !AttachThreadInput (GetCurrentThreadId (), | |
3719 | foreground_thread, TRUE)) | |
3720 | foreground_thread = 0; | |
3721 | ||
3722 | retval = SetForegroundWindow ((HWND) wParam); | |
3723 | ||
3724 | /* Detach from the previous foreground thread. */ | |
3725 | if (foreground_thread) | |
3726 | AttachThreadInput (GetCurrentThreadId (), | |
3727 | foreground_thread, FALSE); | |
3728 | ||
3729 | return retval; | |
3730 | } | |
dfdb4047 | 3731 | |
5ac45f98 GV |
3732 | case WM_EMACS_SETWINDOWPOS: |
3733 | { | |
1edf84e7 GV |
3734 | WINDOWPOS * pos = (WINDOWPOS *) wParam; |
3735 | return SetWindowPos (hwnd, pos->hwndInsertAfter, | |
5ac45f98 GV |
3736 | pos->x, pos->y, pos->cx, pos->cy, pos->flags); |
3737 | } | |
1edf84e7 | 3738 | |
ee78dc32 | 3739 | case WM_EMACS_DESTROYWINDOW: |
cb9e33d4 | 3740 | DragAcceptFiles ((HWND) wParam, FALSE); |
1edf84e7 GV |
3741 | return DestroyWindow ((HWND) wParam); |
3742 | ||
93f2ca61 JR |
3743 | case WM_EMACS_HIDE_CARET: |
3744 | return HideCaret (hwnd); | |
3745 | ||
3746 | case WM_EMACS_SHOW_CARET: | |
3747 | return ShowCaret (hwnd); | |
3748 | ||
65906840 JR |
3749 | case WM_EMACS_DESTROY_CARET: |
3750 | w32_system_caret_hwnd = NULL; | |
93f2ca61 | 3751 | w32_visible_system_caret_hwnd = NULL; |
65906840 JR |
3752 | return DestroyCaret (); |
3753 | ||
3754 | case WM_EMACS_TRACK_CARET: | |
3755 | /* If there is currently no system caret, create one. */ | |
3756 | if (w32_system_caret_hwnd == NULL) | |
3757 | { | |
93f2ca61 JR |
3758 | /* Use the default caret width, and avoid changing it |
3759 | unneccesarily, as it confuses screen reader software. */ | |
65906840 | 3760 | w32_system_caret_hwnd = hwnd; |
93f2ca61 | 3761 | CreateCaret (hwnd, NULL, 0, |
65906840 JR |
3762 | w32_system_caret_height); |
3763 | } | |
7d0393cf | 3764 | |
93f2ca61 JR |
3765 | if (!SetCaretPos (w32_system_caret_x, w32_system_caret_y)) |
3766 | return 0; | |
3767 | /* Ensure visible caret gets turned on when requested. */ | |
3768 | else if (w32_use_visible_system_caret | |
3769 | && w32_visible_system_caret_hwnd != hwnd) | |
3770 | { | |
3771 | w32_visible_system_caret_hwnd = hwnd; | |
3772 | return ShowCaret (hwnd); | |
3773 | } | |
3774 | /* Ensure visible caret gets turned off when requested. */ | |
3775 | else if (!w32_use_visible_system_caret | |
3776 | && w32_visible_system_caret_hwnd) | |
3777 | { | |
3778 | w32_visible_system_caret_hwnd = NULL; | |
3779 | return HideCaret (hwnd); | |
3780 | } | |
3781 | else | |
3782 | return 1; | |
65906840 | 3783 | |
1edf84e7 GV |
3784 | case WM_EMACS_TRACKPOPUPMENU: |
3785 | { | |
3786 | UINT flags; | |
3787 | POINT *pos; | |
3788 | int retval; | |
3789 | pos = (POINT *)lParam; | |
3790 | flags = TPM_CENTERALIGN; | |
3791 | if (button_state & LMOUSE) | |
3792 | flags |= TPM_LEFTBUTTON; | |
3793 | else if (button_state & RMOUSE) | |
3794 | flags |= TPM_RIGHTBUTTON; | |
7d0393cf | 3795 | |
87996783 GV |
3796 | /* Remember we did a SetCapture on the initial mouse down event, |
3797 | so for safety, we make sure the capture is cancelled now. */ | |
3798 | ReleaseCapture (); | |
490822ff | 3799 | button_state = 0; |
87996783 | 3800 | |
1edf84e7 GV |
3801 | /* Use menubar_active to indicate that WM_INITMENU is from |
3802 | TrackPopupMenu below, and should be ignored. */ | |
3803 | f = x_window_to_frame (dpyinfo, hwnd); | |
3804 | if (f) | |
3805 | f->output_data.w32->menubar_active = 1; | |
7d0393cf JB |
3806 | |
3807 | if (TrackPopupMenu ((HMENU)wParam, flags, pos->x, pos->y, | |
1edf84e7 GV |
3808 | 0, hwnd, NULL)) |
3809 | { | |
3810 | MSG amsg; | |
3811 | /* Eat any mouse messages during popupmenu */ | |
3812 | while (PeekMessage (&amsg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, | |
3813 | PM_REMOVE)); | |
3814 | /* Get the menu selection, if any */ | |
3815 | if (PeekMessage (&amsg, hwnd, WM_COMMAND, WM_COMMAND, PM_REMOVE)) | |
3816 | { | |
3817 | retval = LOWORD (amsg.wParam); | |
3818 | } | |
3819 | else | |
3820 | { | |
3821 | retval = 0; | |
3822 | } | |
1edf84e7 GV |
3823 | } |
3824 | else | |
3825 | { | |
3826 | retval = -1; | |
3827 | } | |
3828 | ||
3829 | return retval; | |
3830 | } | |
3831 | ||
ee78dc32 | 3832 | default: |
93fbe8b7 GV |
3833 | /* Check for messages registered at runtime. */ |
3834 | if (msg == msh_mousewheel) | |
3835 | { | |
3836 | wmsg.dwModifiers = w32_get_modifiers (); | |
3837 | my_post_msg (&wmsg, hwnd, msg, wParam, lParam); | |
3838 | return 0; | |
3839 | } | |
7d0393cf | 3840 | |
ee78dc32 GV |
3841 | dflt: |
3842 | return DefWindowProc (hwnd, msg, wParam, lParam); | |
3843 | } | |
7d0393cf | 3844 | |
1edf84e7 GV |
3845 | |
3846 | /* The most common default return code for handled messages is 0. */ | |
3847 | return 0; | |
ee78dc32 GV |
3848 | } |
3849 | ||
0962822d | 3850 | static void |
ee78dc32 GV |
3851 | my_create_window (f) |
3852 | struct frame * f; | |
3853 | { | |
3854 | MSG msg; | |
3855 | ||
1edf84e7 GV |
3856 | if (!PostThreadMessage (dwWindowsThreadId, WM_EMACS_CREATEWINDOW, (WPARAM)f, 0)) |
3857 | abort (); | |
ee78dc32 GV |
3858 | GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE); |
3859 | } | |
3860 | ||
ca56d953 JR |
3861 | |
3862 | /* Create a tooltip window. Unlike my_create_window, we do not do this | |
3863 | indirectly via the Window thread, as we do not need to process Window | |
3864 | messages for the tooltip. Creating tooltips indirectly also creates | |
3865 | deadlocks when tooltips are created for menu items. */ | |
0962822d | 3866 | static void |
ca56d953 JR |
3867 | my_create_tip_window (f) |
3868 | struct frame *f; | |
3869 | { | |
bfd6edcc | 3870 | RECT rect; |
ca56d953 | 3871 | |
bfd6edcc | 3872 | rect.left = rect.top = 0; |
be786000 KS |
3873 | rect.right = FRAME_PIXEL_WIDTH (f); |
3874 | rect.bottom = FRAME_PIXEL_HEIGHT (f); | |
bfd6edcc JR |
3875 | |
3876 | AdjustWindowRect (&rect, f->output_data.w32->dwStyle, | |
3877 | FRAME_EXTERNAL_MENU_BAR (f)); | |
3878 | ||
3879 | tip_window = FRAME_W32_WINDOW (f) | |
ca56d953 JR |
3880 | = CreateWindow (EMACS_CLASS, |
3881 | f->namebuf, | |
3882 | f->output_data.w32->dwStyle, | |
be786000 KS |
3883 | f->left_pos, |
3884 | f->top_pos, | |
bfd6edcc JR |
3885 | rect.right - rect.left, |
3886 | rect.bottom - rect.top, | |
ca56d953 JR |
3887 | FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */ |
3888 | NULL, | |
3889 | hinst, | |
3890 | NULL); | |
3891 | ||
bfd6edcc | 3892 | if (tip_window) |
ca56d953 | 3893 | { |
be786000 KS |
3894 | SetWindowLong (tip_window, WND_FONTWIDTH_INDEX, FRAME_COLUMN_WIDTH (f)); |
3895 | SetWindowLong (tip_window, WND_LINEHEIGHT_INDEX, FRAME_LINE_HEIGHT (f)); | |
3896 | SetWindowLong (tip_window, WND_BORDER_INDEX, FRAME_INTERNAL_BORDER_WIDTH (f)); | |
bfd6edcc JR |
3897 | SetWindowLong (tip_window, WND_BACKGROUND_INDEX, FRAME_BACKGROUND_PIXEL (f)); |
3898 | ||
3899 | /* Tip frames have no scrollbars. */ | |
3900 | SetWindowLong (tip_window, WND_SCROLLBAR_INDEX, 0); | |
ca56d953 JR |
3901 | |
3902 | /* Do this to discard the default setting specified by our parent. */ | |
bfd6edcc | 3903 | ShowWindow (tip_window, SW_HIDE); |
ca56d953 JR |
3904 | } |
3905 | } | |
3906 | ||
3907 | ||
fbd6baed | 3908 | /* Create and set up the w32 window for frame F. */ |
ee78dc32 GV |
3909 | |
3910 | static void | |
fbd6baed | 3911 | w32_window (f, window_prompting, minibuffer_only) |
ee78dc32 GV |
3912 | struct frame *f; |
3913 | long window_prompting; | |
3914 | int minibuffer_only; | |
3915 | { | |
3916 | BLOCK_INPUT; | |
3917 | ||
3918 | /* Use the resource name as the top-level window name | |
3919 | for looking up resources. Make a non-Lisp copy | |
3920 | for the window manager, so GC relocation won't bother it. | |
3921 | ||
3922 | Elsewhere we specify the window name for the window manager. */ | |
7d0393cf | 3923 | |
ee78dc32 | 3924 | { |
d5db4077 | 3925 | char *str = (char *) SDATA (Vx_resource_name); |
ee78dc32 GV |
3926 | f->namebuf = (char *) xmalloc (strlen (str) + 1); |
3927 | strcpy (f->namebuf, str); | |
3928 | } | |
3929 | ||
3930 | my_create_window (f); | |
3931 | ||
3932 | validate_x_resource_name (); | |
3933 | ||
3934 | /* x_set_name normally ignores requests to set the name if the | |
3935 | requested name is the same as the current name. This is the one | |
3936 | place where that assumption isn't correct; f->name is set, but | |
3937 | the server hasn't been told. */ | |
3938 | { | |
3939 | Lisp_Object name; | |
3940 | int explicit = f->explicit_name; | |
3941 | ||
3942 | f->explicit_name = 0; | |
3943 | name = f->name; | |
3944 | f->name = Qnil; | |
3945 | x_set_name (f, name, explicit); | |
3946 | } | |
3947 | ||
3948 | UNBLOCK_INPUT; | |
3949 | ||
3950 | if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f)) | |
3951 | initialize_frame_menubar (f); | |
3952 | ||
fbd6baed | 3953 | if (FRAME_W32_WINDOW (f) == 0) |
ee78dc32 GV |
3954 | error ("Unable to create window"); |
3955 | } | |
3956 | ||
3957 | /* Handle the icon stuff for this window. Perhaps later we might | |
3958 | want an x_set_icon_position which can be called interactively as | |
3959 | well. */ | |
3960 | ||
3961 | static void | |
3962 | x_icon (f, parms) | |
3963 | struct frame *f; | |
3964 | Lisp_Object parms; | |
3965 | { | |
3966 | Lisp_Object icon_x, icon_y; | |
3967 | ||
e9e23e23 | 3968 | /* Set the position of the icon. Note that Windows 95 groups all |
ee78dc32 | 3969 | icons in the tray. */ |
6fc2811b JR |
3970 | icon_x = w32_get_arg (parms, Qicon_left, 0, 0, RES_TYPE_NUMBER); |
3971 | icon_y = w32_get_arg (parms, Qicon_top, 0, 0, RES_TYPE_NUMBER); | |
ee78dc32 GV |
3972 | if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound)) |
3973 | { | |
b7826503 PJ |
3974 | CHECK_NUMBER (icon_x); |
3975 | CHECK_NUMBER (icon_y); | |
ee78dc32 GV |
3976 | } |
3977 | else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound)) | |
3978 | error ("Both left and top icon corners of icon must be specified"); | |
3979 | ||
3980 | BLOCK_INPUT; | |
3981 | ||
3982 | if (! EQ (icon_x, Qunbound)) | |
3983 | x_wm_set_icon_position (f, XINT (icon_x), XINT (icon_y)); | |
3984 | ||
1edf84e7 GV |
3985 | #if 0 /* TODO */ |
3986 | /* Start up iconic or window? */ | |
3987 | x_wm_set_window_state | |
6fc2811b | 3988 | (f, (EQ (w32_get_arg (parms, Qvisibility, 0, 0, RES_TYPE_SYMBOL), Qicon) |
1edf84e7 GV |
3989 | ? IconicState |
3990 | : NormalState)); | |
3991 | ||
d5db4077 | 3992 | x_text_icon (f, (char *) SDATA ((!NILP (f->icon_name) |
1edf84e7 | 3993 | ? f->icon_name |
d5db4077 | 3994 | : f->name))); |
1edf84e7 GV |
3995 | #endif |
3996 | ||
ee78dc32 GV |
3997 | UNBLOCK_INPUT; |
3998 | } | |
3999 | ||
6fc2811b JR |
4000 | |
4001 | static void | |
4002 | x_make_gc (f) | |
4003 | struct frame *f; | |
4004 | { | |
4005 | XGCValues gc_values; | |
4006 | ||
4007 | BLOCK_INPUT; | |
4008 | ||
4009 | /* Create the GC's of this frame. | |
4010 | Note that many default values are used. */ | |
4011 | ||
4012 | /* Normal video */ | |
be786000 | 4013 | gc_values.font = FRAME_FONT (f); |
6fc2811b JR |
4014 | |
4015 | /* Cursor has cursor-color background, background-color foreground. */ | |
4016 | gc_values.foreground = FRAME_BACKGROUND_PIXEL (f); | |
4017 | gc_values.background = f->output_data.w32->cursor_pixel; | |
4018 | f->output_data.w32->cursor_gc | |
4019 | = XCreateGC (NULL, FRAME_W32_WINDOW (f), | |
4020 | (GCFont | GCForeground | GCBackground), | |
4021 | &gc_values); | |
4022 | ||
4023 | /* Reliefs. */ | |
4024 | f->output_data.w32->white_relief.gc = 0; | |
4025 | f->output_data.w32->black_relief.gc = 0; | |
4026 | ||
4027 | UNBLOCK_INPUT; | |
4028 | } | |
4029 | ||
4030 | ||
937e601e AI |
4031 | /* Handler for signals raised during x_create_frame and |
4032 | x_create_top_frame. FRAME is the frame which is partially | |
4033 | constructed. */ | |
4034 | ||
4035 | static Lisp_Object | |
4036 | unwind_create_frame (frame) | |
4037 | Lisp_Object frame; | |
4038 | { | |
4039 | struct frame *f = XFRAME (frame); | |
4040 | ||
4041 | /* If frame is ``official'', nothing to do. */ | |
4042 | if (!CONSP (Vframe_list) || !EQ (XCAR (Vframe_list), frame)) | |
4043 | { | |
4044 | #ifdef GLYPH_DEBUG | |
4045 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); | |
4046 | #endif | |
7d0393cf | 4047 | |
937e601e AI |
4048 | x_free_frame_resources (f); |
4049 | ||
4050 | /* Check that reference counts are indeed correct. */ | |
4051 | xassert (dpyinfo->reference_count == dpyinfo_refcount); | |
4052 | xassert (dpyinfo->image_cache->refcount == image_cache_refcount); | |
c844a81a GM |
4053 | |
4054 | return Qt; | |
937e601e | 4055 | } |
7d0393cf | 4056 | |
937e601e AI |
4057 | return Qnil; |
4058 | } | |
4059 | ||
4060 | ||
ee78dc32 GV |
4061 | DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame, |
4062 | 1, 1, 0, | |
74e1aeec JR |
4063 | doc: /* Make a new window, which is called a \"frame\" in Emacs terms. |
4064 | Returns an Emacs frame object. | |
52deb19f | 4065 | PARAMETERS is an alist of frame parameters. |
74e1aeec JR |
4066 | If the parameters specify that the frame should not have a minibuffer, |
4067 | and do not specify a specific minibuffer window to use, | |
4068 | then `default-minibuffer-frame' must be a frame whose minibuffer can | |
4069 | be shared by the new frame. | |
4070 | ||
4071 | This function is an internal primitive--use `make-frame' instead. */) | |
52deb19f JB |
4072 | (parameters) |
4073 | Lisp_Object parameters; | |
ee78dc32 GV |
4074 | { |
4075 | struct frame *f; | |
4076 | Lisp_Object frame, tem; | |
4077 | Lisp_Object name; | |
4078 | int minibuffer_only = 0; | |
4079 | long window_prompting = 0; | |
4080 | int width, height; | |
331379bf | 4081 | int count = SPECPDL_INDEX (); |
1edf84e7 | 4082 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
ee78dc32 | 4083 | Lisp_Object display; |
6fc2811b | 4084 | struct w32_display_info *dpyinfo = NULL; |
ee78dc32 GV |
4085 | Lisp_Object parent; |
4086 | struct kboard *kb; | |
4087 | ||
4587b026 GV |
4088 | check_w32 (); |
4089 | ||
ee78dc32 GV |
4090 | /* Use this general default value to start with |
4091 | until we know if this frame has a specified name. */ | |
4092 | Vx_resource_name = Vinvocation_name; | |
4093 | ||
52deb19f | 4094 | display = w32_get_arg (parameters, Qdisplay, 0, 0, RES_TYPE_STRING); |
ee78dc32 GV |
4095 | if (EQ (display, Qunbound)) |
4096 | display = Qnil; | |
4097 | dpyinfo = check_x_display_info (display); | |
4098 | #ifdef MULTI_KBOARD | |
4099 | kb = dpyinfo->kboard; | |
4100 | #else | |
4101 | kb = &the_only_kboard; | |
4102 | #endif | |
4103 | ||
52deb19f | 4104 | name = w32_get_arg (parameters, Qname, "name", "Name", RES_TYPE_STRING); |
ee78dc32 GV |
4105 | if (!STRINGP (name) |
4106 | && ! EQ (name, Qunbound) | |
4107 | && ! NILP (name)) | |
4108 | error ("Invalid frame name--not a string or nil"); | |
4109 | ||
4110 | if (STRINGP (name)) | |
4111 | Vx_resource_name = name; | |
4112 | ||
4113 | /* See if parent window is specified. */ | |
52deb19f | 4114 | parent = w32_get_arg (parameters, Qparent_id, NULL, NULL, RES_TYPE_NUMBER); |
ee78dc32 GV |
4115 | if (EQ (parent, Qunbound)) |
4116 | parent = Qnil; | |
4117 | if (! NILP (parent)) | |
b7826503 | 4118 | CHECK_NUMBER (parent); |
ee78dc32 | 4119 | |
1edf84e7 GV |
4120 | /* make_frame_without_minibuffer can run Lisp code and garbage collect. */ |
4121 | /* No need to protect DISPLAY because that's not used after passing | |
4122 | it to make_frame_without_minibuffer. */ | |
4123 | frame = Qnil; | |
52deb19f JB |
4124 | GCPRO4 (parameters, parent, name, frame); |
4125 | tem = w32_get_arg (parameters, Qminibuffer, "minibuffer", "Minibuffer", | |
1660f34a | 4126 | RES_TYPE_SYMBOL); |
ee78dc32 GV |
4127 | if (EQ (tem, Qnone) || NILP (tem)) |
4128 | f = make_frame_without_minibuffer (Qnil, kb, display); | |
4129 | else if (EQ (tem, Qonly)) | |
4130 | { | |
4131 | f = make_minibuffer_frame (); | |
4132 | minibuffer_only = 1; | |
4133 | } | |
4134 | else if (WINDOWP (tem)) | |
4135 | f = make_frame_without_minibuffer (tem, kb, display); | |
4136 | else | |
4137 | f = make_frame (1); | |
4138 | ||
1edf84e7 GV |
4139 | XSETFRAME (frame, f); |
4140 | ||
ee78dc32 GV |
4141 | /* Note that Windows does support scroll bars. */ |
4142 | FRAME_CAN_HAVE_SCROLL_BARS (f) = 1; | |
6d906347 | 4143 | |
5ac45f98 | 4144 | /* By default, make scrollbars the system standard width. */ |
be786000 | 4145 | FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = GetSystemMetrics (SM_CXVSCROLL); |
ee78dc32 | 4146 | |
fbd6baed | 4147 | f->output_method = output_w32; |
6fc2811b JR |
4148 | f->output_data.w32 = |
4149 | (struct w32_output *) xmalloc (sizeof (struct w32_output)); | |
fbd6baed | 4150 | bzero (f->output_data.w32, sizeof (struct w32_output)); |
4587b026 | 4151 | FRAME_FONTSET (f) = -1; |
937e601e | 4152 | record_unwind_protect (unwind_create_frame, frame); |
4587b026 | 4153 | |
1edf84e7 | 4154 | f->icon_name |
52deb19f | 4155 | = w32_get_arg (parameters, Qicon_name, "iconName", "Title", RES_TYPE_STRING); |
1edf84e7 GV |
4156 | if (! STRINGP (f->icon_name)) |
4157 | f->icon_name = Qnil; | |
4158 | ||
fbd6baed | 4159 | /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */ |
ee78dc32 GV |
4160 | #ifdef MULTI_KBOARD |
4161 | FRAME_KBOARD (f) = kb; | |
4162 | #endif | |
4163 | ||
4164 | /* Specify the parent under which to make this window. */ | |
4165 | ||
4166 | if (!NILP (parent)) | |
4167 | { | |
1660f34a | 4168 | f->output_data.w32->parent_desc = (Window) XFASTINT (parent); |
fbd6baed | 4169 | f->output_data.w32->explicit_parent = 1; |
ee78dc32 GV |
4170 | } |
4171 | else | |
4172 | { | |
fbd6baed GV |
4173 | f->output_data.w32->parent_desc = FRAME_W32_DISPLAY_INFO (f)->root_window; |
4174 | f->output_data.w32->explicit_parent = 0; | |
ee78dc32 GV |
4175 | } |
4176 | ||
ee78dc32 GV |
4177 | /* Set the name; the functions to which we pass f expect the name to |
4178 | be set. */ | |
4179 | if (EQ (name, Qunbound) || NILP (name)) | |
4180 | { | |
fbd6baed | 4181 | f->name = build_string (dpyinfo->w32_id_name); |
ee78dc32 GV |
4182 | f->explicit_name = 0; |
4183 | } | |
4184 | else | |
4185 | { | |
4186 | f->name = name; | |
4187 | f->explicit_name = 1; | |
4188 | /* use the frame's title when getting resources for this frame. */ | |
4189 | specbind (Qx_resource_name, name); | |
4190 | } | |
4191 | ||
4192 | /* Extract the window parameters from the supplied values | |
4193 | that are needed to determine window geometry. */ | |
4194 | { | |
4195 | Lisp_Object font; | |
4196 | ||
52deb19f | 4197 | font = w32_get_arg (parameters, Qfont, "font", "Font", RES_TYPE_STRING); |
6fc2811b | 4198 | |
ee78dc32 GV |
4199 | BLOCK_INPUT; |
4200 | /* First, try whatever font the caller has specified. */ | |
4201 | if (STRINGP (font)) | |
4587b026 GV |
4202 | { |
4203 | tem = Fquery_fontset (font, Qnil); | |
4204 | if (STRINGP (tem)) | |
d5db4077 | 4205 | font = x_new_fontset (f, SDATA (tem)); |
4587b026 | 4206 | else |
d5db4077 | 4207 | font = x_new_font (f, SDATA (font)); |
4587b026 | 4208 | } |
ee78dc32 GV |
4209 | /* Try out a font which we hope has bold and italic variations. */ |
4210 | if (!STRINGP (font)) | |
e39649be | 4211 | font = x_new_font (f, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1"); |
ee78dc32 | 4212 | if (! STRINGP (font)) |
6fc2811b | 4213 | font = x_new_font (f, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1"); |
ee78dc32 GV |
4214 | /* If those didn't work, look for something which will at least work. */ |
4215 | if (! STRINGP (font)) | |
6fc2811b | 4216 | font = x_new_font (f, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1"); |
ee78dc32 GV |
4217 | UNBLOCK_INPUT; |
4218 | if (! STRINGP (font)) | |
1edf84e7 | 4219 | font = build_string ("Fixedsys"); |
ee78dc32 | 4220 | |
52deb19f | 4221 | x_default_parameter (f, parameters, Qfont, font, |
6fc2811b | 4222 | "font", "Font", RES_TYPE_STRING); |
ee78dc32 GV |
4223 | } |
4224 | ||
52deb19f | 4225 | x_default_parameter (f, parameters, Qborder_width, make_number (2), |
1660f34a | 4226 | "borderWidth", "BorderWidth", RES_TYPE_NUMBER); |
ee78dc32 GV |
4227 | /* This defaults to 2 in order to match xterm. We recognize either |
4228 | internalBorderWidth or internalBorder (which is what xterm calls | |
4229 | it). */ | |
52deb19f | 4230 | if (NILP (Fassq (Qinternal_border_width, parameters))) |
ee78dc32 GV |
4231 | { |
4232 | Lisp_Object value; | |
4233 | ||
52deb19f JB |
4234 | value = w32_get_arg (parameters, Qinternal_border_width, |
4235 | "internalBorder", "InternalBorder", RES_TYPE_NUMBER); | |
ee78dc32 | 4236 | if (! EQ (value, Qunbound)) |
52deb19f JB |
4237 | parameters = Fcons (Fcons (Qinternal_border_width, value), |
4238 | parameters); | |
ee78dc32 | 4239 | } |
1edf84e7 | 4240 | /* Default internalBorderWidth to 0 on Windows to match other programs. */ |
52deb19f | 4241 | x_default_parameter (f, parameters, Qinternal_border_width, make_number (0), |
1660f34a | 4242 | "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER); |
52deb19f | 4243 | x_default_parameter (f, parameters, Qvertical_scroll_bars, Qright, |
1660f34a | 4244 | "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL); |
ee78dc32 GV |
4245 | |
4246 | /* Also do the stuff which must be set before the window exists. */ | |
52deb19f | 4247 | x_default_parameter (f, parameters, Qforeground_color, build_string ("black"), |
6fc2811b | 4248 | "foreground", "Foreground", RES_TYPE_STRING); |
52deb19f | 4249 | x_default_parameter (f, parameters, Qbackground_color, build_string ("white"), |
6fc2811b | 4250 | "background", "Background", RES_TYPE_STRING); |
52deb19f | 4251 | x_default_parameter (f, parameters, Qmouse_color, build_string ("black"), |
6fc2811b | 4252 | "pointerColor", "Foreground", RES_TYPE_STRING); |
52deb19f | 4253 | x_default_parameter (f, parameters, Qcursor_color, build_string ("black"), |
6fc2811b | 4254 | "cursorColor", "Foreground", RES_TYPE_STRING); |
52deb19f | 4255 | x_default_parameter (f, parameters, Qborder_color, build_string ("black"), |
6fc2811b | 4256 | "borderColor", "BorderColor", RES_TYPE_STRING); |
52deb19f | 4257 | x_default_parameter (f, parameters, Qscreen_gamma, Qnil, |
6fc2811b | 4258 | "screenGamma", "ScreenGamma", RES_TYPE_FLOAT); |
52deb19f | 4259 | x_default_parameter (f, parameters, Qline_spacing, Qnil, |
dfff8a69 | 4260 | "lineSpacing", "LineSpacing", RES_TYPE_NUMBER); |
52deb19f | 4261 | x_default_parameter (f, parameters, Qleft_fringe, Qnil, |
41c1bdd9 | 4262 | "leftFringe", "LeftFringe", RES_TYPE_NUMBER); |
52deb19f | 4263 | x_default_parameter (f, parameters, Qright_fringe, Qnil, |
41c1bdd9 | 4264 | "rightFringe", "RightFringe", RES_TYPE_NUMBER); |
6fc2811b | 4265 | |
ee78dc32 | 4266 | |
6fc2811b JR |
4267 | /* Init faces before x_default_parameter is called for scroll-bar |
4268 | parameters because that function calls x_set_scroll_bar_width, | |
4269 | which calls change_frame_size, which calls Fset_window_buffer, | |
4270 | which runs hooks, which call Fvertical_motion. At the end, we | |
4271 | end up in init_iterator with a null face cache, which should not | |
4272 | happen. */ | |
4273 | init_frame_faces (f); | |
7d0393cf | 4274 | |
52deb19f | 4275 | x_default_parameter (f, parameters, Qmenu_bar_lines, make_number (1), |
6fc2811b | 4276 | "menuBar", "MenuBar", RES_TYPE_NUMBER); |
52deb19f | 4277 | x_default_parameter (f, parameters, Qtool_bar_lines, make_number (1), |
6fc2811b | 4278 | "toolBar", "ToolBar", RES_TYPE_NUMBER); |
919f1e88 | 4279 | |
52deb19f | 4280 | x_default_parameter (f, parameters, Qbuffer_predicate, Qnil, |
6fc2811b | 4281 | "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL); |
52deb19f | 4282 | x_default_parameter (f, parameters, Qtitle, Qnil, |
6fc2811b | 4283 | "title", "Title", RES_TYPE_STRING); |
52deb19f | 4284 | x_default_parameter (f, parameters, Qfullscreen, Qnil, |
f7b9d4d1 | 4285 | "fullscreen", "Fullscreen", RES_TYPE_SYMBOL); |
ee78dc32 | 4286 | |
fbd6baed GV |
4287 | f->output_data.w32->dwStyle = WS_OVERLAPPEDWINDOW; |
4288 | f->output_data.w32->parent_desc = FRAME_W32_DISPLAY_INFO (f)->root_window; | |
3cf3436e | 4289 | |
c9b2104d JR |
4290 | f->output_data.w32->text_cursor = w32_load_cursor (IDC_IBEAM); |
4291 | f->output_data.w32->nontext_cursor = w32_load_cursor (IDC_ARROW); | |
4292 | f->output_data.w32->modeline_cursor = w32_load_cursor (IDC_ARROW); | |
7d63e5e3 | 4293 | f->output_data.w32->hand_cursor = w32_load_cursor (IDC_HAND); |
c9b2104d JR |
4294 | f->output_data.w32->hourglass_cursor = w32_load_cursor (IDC_WAIT); |
4295 | f->output_data.w32->horizontal_drag_cursor = w32_load_cursor (IDC_SIZEWE); | |
c9b2104d | 4296 | |
52deb19f | 4297 | window_prompting = x_figure_window_size (f, parameters, 1); |
ee78dc32 | 4298 | |
52deb19f | 4299 | tem = w32_get_arg (parameters, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN); |
6fc2811b JR |
4300 | f->no_split = minibuffer_only || EQ (tem, Qt); |
4301 | ||
fbd6baed | 4302 | w32_window (f, window_prompting, minibuffer_only); |
52deb19f | 4303 | x_icon (f, parameters); |
6fc2811b JR |
4304 | |
4305 | x_make_gc (f); | |
4306 | ||
4307 | /* Now consider the frame official. */ | |
4308 | FRAME_W32_DISPLAY_INFO (f)->reference_count++; | |
4309 | Vframe_list = Fcons (frame, Vframe_list); | |
ee78dc32 GV |
4310 | |
4311 | /* We need to do this after creating the window, so that the | |
4312 | icon-creation functions can say whose icon they're describing. */ | |
52deb19f | 4313 | x_default_parameter (f, parameters, Qicon_type, Qnil, |
6fc2811b | 4314 | "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL); |
ee78dc32 | 4315 | |
52deb19f | 4316 | x_default_parameter (f, parameters, Qauto_raise, Qnil, |
6fc2811b | 4317 | "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN); |
52deb19f | 4318 | x_default_parameter (f, parameters, Qauto_lower, Qnil, |
6fc2811b | 4319 | "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN); |
52deb19f | 4320 | x_default_parameter (f, parameters, Qcursor_type, Qbox, |
6fc2811b | 4321 | "cursorType", "CursorType", RES_TYPE_SYMBOL); |
52deb19f | 4322 | x_default_parameter (f, parameters, Qscroll_bar_width, Qnil, |
6fc2811b | 4323 | "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER); |
ee78dc32 | 4324 | |
be786000 | 4325 | /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size. |
ee78dc32 | 4326 | Change will not be effected unless different from the current |
be786000 KS |
4327 | FRAME_LINES (f). */ |
4328 | width = FRAME_COLS (f); | |
4329 | height = FRAME_LINES (f); | |
dc220243 | 4330 | |
be786000 KS |
4331 | FRAME_LINES (f) = 0; |
4332 | SET_FRAME_COLS (f, 0); | |
6fc2811b JR |
4333 | change_frame_size (f, height, width, 1, 0, 0); |
4334 | ||
6fc2811b JR |
4335 | /* Tell the server what size and position, etc, we want, and how |
4336 | badly we want them. This should be done after we have the menu | |
4337 | bar so that its size can be taken into account. */ | |
ee78dc32 GV |
4338 | BLOCK_INPUT; |
4339 | x_wm_set_size_hint (f, window_prompting, 0); | |
4340 | UNBLOCK_INPUT; | |
4341 | ||
815d969e JR |
4342 | /* Avoid a bug that causes the new frame to never become visible if |
4343 | an echo area message is displayed during the following call1. */ | |
4344 | specbind(Qredisplay_dont_pause, Qt); | |
4345 | ||
4694d762 JR |
4346 | /* Set up faces after all frame parameters are known. This call |
4347 | also merges in face attributes specified for new frames. If we | |
4348 | don't do this, the `menu' face for instance won't have the right | |
4349 | colors, and the menu bar won't appear in the specified colors for | |
4350 | new frames. */ | |
4351 | call1 (Qface_set_after_frame_default, frame); | |
4352 | ||
6fc2811b JR |
4353 | /* Make the window appear on the frame and enable display, unless |
4354 | the caller says not to. However, with explicit parent, Emacs | |
4355 | cannot control visibility, so don't try. */ | |
fbd6baed | 4356 | if (! f->output_data.w32->explicit_parent) |
ee78dc32 GV |
4357 | { |
4358 | Lisp_Object visibility; | |
4359 | ||
52deb19f | 4360 | visibility = w32_get_arg (parameters, Qvisibility, 0, 0, RES_TYPE_SYMBOL); |
ee78dc32 GV |
4361 | if (EQ (visibility, Qunbound)) |
4362 | visibility = Qt; | |
4363 | ||
4364 | if (EQ (visibility, Qicon)) | |
4365 | x_iconify_frame (f); | |
4366 | else if (! NILP (visibility)) | |
4367 | x_make_frame_visible (f); | |
4368 | else | |
4369 | /* Must have been Qnil. */ | |
4370 | ; | |
4371 | } | |
6fc2811b | 4372 | UNGCPRO; |
7d0393cf | 4373 | |
9e57df62 GM |
4374 | /* Make sure windows on this frame appear in calls to next-window |
4375 | and similar functions. */ | |
4376 | Vwindow_list = Qnil; | |
7d0393cf | 4377 | |
ee78dc32 GV |
4378 | return unbind_to (count, frame); |
4379 | } | |
4380 | ||
4381 | /* FRAME is used only to get a handle on the X display. We don't pass the | |
4382 | display info directly because we're called from frame.c, which doesn't | |
4383 | know about that structure. */ | |
4384 | Lisp_Object | |
4385 | x_get_focus_frame (frame) | |
4386 | struct frame *frame; | |
4387 | { | |
fbd6baed | 4388 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (frame); |
ee78dc32 | 4389 | Lisp_Object xfocus; |
fbd6baed | 4390 | if (! dpyinfo->w32_focus_frame) |
ee78dc32 GV |
4391 | return Qnil; |
4392 | ||
fbd6baed | 4393 | XSETFRAME (xfocus, dpyinfo->w32_focus_frame); |
ee78dc32 GV |
4394 | return xfocus; |
4395 | } | |
1edf84e7 GV |
4396 | |
4397 | DEFUN ("w32-focus-frame", Fw32_focus_frame, Sw32_focus_frame, 1, 1, 0, | |
74e1aeec | 4398 | doc: /* Give FRAME input focus, raising to foreground if necessary. */) |
1edf84e7 GV |
4399 | (frame) |
4400 | Lisp_Object frame; | |
4401 | { | |
4402 | x_focus_on_frame (check_x_frame (frame)); | |
4403 | return Qnil; | |
4404 | } | |
4405 | ||
ee78dc32 | 4406 | \f |
767b1ff0 JR |
4407 | /* Return the charset portion of a font name. */ |
4408 | char * xlfd_charset_of_font (char * fontname) | |
4409 | { | |
4410 | char *charset, *encoding; | |
4411 | ||
4412 | encoding = strrchr(fontname, '-'); | |
ceb12877 | 4413 | if (!encoding || encoding == fontname) |
767b1ff0 JR |
4414 | return NULL; |
4415 | ||
478ea067 AI |
4416 | for (charset = encoding - 1; charset >= fontname; charset--) |
4417 | if (*charset == '-') | |
4418 | break; | |
767b1ff0 | 4419 | |
478ea067 | 4420 | if (charset == fontname || strcmp(charset, "-*-*") == 0) |
767b1ff0 JR |
4421 | return NULL; |
4422 | ||
4423 | return charset + 1; | |
4424 | } | |
4425 | ||
33d52f9c GV |
4426 | struct font_info *w32_load_bdf_font (struct frame *f, char *fontname, |
4427 | int size, char* filename); | |
8edb0a6f | 4428 | static Lisp_Object w32_list_bdf_fonts (Lisp_Object pattern, int max_names); |
c7501041 EZ |
4429 | static BOOL w32_to_x_font (LOGFONT * lplf, char * lpxstr, int len, |
4430 | char * charset); | |
4431 | static BOOL x_to_w32_font (char *lpxstr, LOGFONT *lplogfont); | |
33d52f9c | 4432 | |
8edb0a6f | 4433 | static struct font_info * |
33d52f9c | 4434 | w32_load_system_font (f,fontname,size) |
55dcfc15 AI |
4435 | struct frame *f; |
4436 | char * fontname; | |
4437 | int size; | |
ee78dc32 | 4438 | { |
4587b026 GV |
4439 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); |
4440 | Lisp_Object font_names; | |
4441 | ||
4587b026 GV |
4442 | /* Get a list of all the fonts that match this name. Once we |
4443 | have a list of matching fonts, we compare them against the fonts | |
4444 | we already have loaded by comparing names. */ | |
4445 | font_names = w32_list_fonts (f, build_string (fontname), size, 100); | |
4446 | ||
4447 | if (!NILP (font_names)) | |
3c190163 | 4448 | { |
4587b026 GV |
4449 | Lisp_Object tail; |
4450 | int i; | |
4587b026 GV |
4451 | |
4452 | /* First check if any are already loaded, as that is cheaper | |
4453 | than loading another one. */ | |
4454 | for (i = 0; i < dpyinfo->n_fonts; i++) | |
8e713be6 | 4455 | for (tail = font_names; CONSP (tail); tail = XCDR (tail)) |
6fc2811b JR |
4456 | if (dpyinfo->font_table[i].name |
4457 | && (!strcmp (dpyinfo->font_table[i].name, | |
d5db4077 | 4458 | SDATA (XCAR (tail))) |
6fc2811b | 4459 | || !strcmp (dpyinfo->font_table[i].full_name, |
d5db4077 | 4460 | SDATA (XCAR (tail))))) |
4587b026 | 4461 | return (dpyinfo->font_table + i); |
6fc2811b | 4462 | |
d5db4077 | 4463 | fontname = (char *) SDATA (XCAR (font_names)); |
4587b026 | 4464 | } |
1075afa9 | 4465 | else if (w32_strict_fontnames) |
5ca0cd71 GV |
4466 | { |
4467 | /* If EnumFontFamiliesEx was available, we got a full list of | |
4468 | fonts back so stop now to avoid the possibility of loading a | |
4469 | random font. If we had to fall back to EnumFontFamilies, the | |
4470 | list is incomplete, so continue whether the font we want was | |
4471 | listed or not. */ | |
4472 | HMODULE gdi32 = GetModuleHandle ("gdi32.dll"); | |
4473 | FARPROC enum_font_families_ex | |
1075afa9 | 4474 | = GetProcAddress (gdi32, "EnumFontFamiliesExA"); |
5ca0cd71 GV |
4475 | if (enum_font_families_ex) |
4476 | return NULL; | |
4477 | } | |
4587b026 GV |
4478 | |
4479 | /* Load the font and add it to the table. */ | |
4480 | { | |
767b1ff0 | 4481 | char *full_name, *encoding, *charset; |
4587b026 GV |
4482 | XFontStruct *font; |
4483 | struct font_info *fontp; | |
3c190163 | 4484 | LOGFONT lf; |
4587b026 | 4485 | BOOL ok; |
19c291d3 | 4486 | int codepage; |
6fc2811b | 4487 | int i; |
5ac45f98 | 4488 | |
4587b026 | 4489 | if (!fontname || !x_to_w32_font (fontname, &lf)) |
3c190163 | 4490 | return (NULL); |
5ac45f98 | 4491 | |
4587b026 GV |
4492 | if (!*lf.lfFaceName) |
4493 | /* If no name was specified for the font, we get a random font | |
4494 | from CreateFontIndirect - this is not particularly | |
4495 | desirable, especially since CreateFontIndirect does not | |
4496 | fill out the missing name in lf, so we never know what we | |
4497 | ended up with. */ | |
4498 | return NULL; | |
4499 | ||
c8d88d08 | 4500 | lf.lfQuality = DEFAULT_QUALITY; |
d65a9cdc | 4501 | |
3c190163 | 4502 | font = (XFontStruct *) xmalloc (sizeof (XFontStruct)); |
c6be3860 | 4503 | bzero (font, sizeof (*font)); |
5ac45f98 | 4504 | |
33d52f9c GV |
4505 | /* Set bdf to NULL to indicate that this is a Windows font. */ |
4506 | font->bdf = NULL; | |
5ac45f98 | 4507 | |
3c190163 | 4508 | BLOCK_INPUT; |
5ac45f98 GV |
4509 | |
4510 | font->hfont = CreateFontIndirect (&lf); | |
ee78dc32 | 4511 | |
7d0393cf | 4512 | if (font->hfont == NULL) |
1a292d24 AI |
4513 | { |
4514 | ok = FALSE; | |
7d0393cf JB |
4515 | } |
4516 | else | |
1a292d24 AI |
4517 | { |
4518 | HDC hdc; | |
4519 | HANDLE oldobj; | |
19c291d3 AI |
4520 | |
4521 | codepage = w32_codepage_for_font (fontname); | |
1a292d24 AI |
4522 | |
4523 | hdc = GetDC (dpyinfo->root_window); | |
4524 | oldobj = SelectObject (hdc, font->hfont); | |
5c6682be | 4525 | |
1a292d24 | 4526 | ok = GetTextMetrics (hdc, &font->tm); |
5c6682be JR |
4527 | if (codepage == CP_UNICODE) |
4528 | font->double_byte_p = 1; | |
4529 | else | |
8b77111c AI |
4530 | { |
4531 | /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font) | |
4532 | don't report themselves as double byte fonts, when | |
4533 | patently they are. So instead of trusting | |
4534 | GetFontLanguageInfo, we check the properties of the | |
4535 | codepage directly, since that is ultimately what we are | |
4536 | working from anyway. */ | |
4537 | /* font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS; */ | |
4538 | CPINFO cpi = {0}; | |
4539 | GetCPInfo (codepage, &cpi); | |
4540 | font->double_byte_p = cpi.MaxCharSize > 1; | |
4541 | } | |
5c6682be | 4542 | |
1a292d24 AI |
4543 | SelectObject (hdc, oldobj); |
4544 | ReleaseDC (dpyinfo->root_window, hdc); | |
6fc2811b JR |
4545 | /* Fill out details in lf according to the font that was |
4546 | actually loaded. */ | |
4547 | lf.lfHeight = font->tm.tmInternalLeading - font->tm.tmHeight; | |
ad5674f5 | 4548 | lf.lfWidth = font->tm.tmMaxCharWidth; |
6fc2811b JR |
4549 | lf.lfWeight = font->tm.tmWeight; |
4550 | lf.lfItalic = font->tm.tmItalic; | |
4551 | lf.lfCharSet = font->tm.tmCharSet; | |
4552 | lf.lfPitchAndFamily = ((font->tm.tmPitchAndFamily & TMPF_FIXED_PITCH) | |
d88c567c | 4553 | ? VARIABLE_PITCH : FIXED_PITCH); |
6fc2811b JR |
4554 | lf.lfOutPrecision = ((font->tm.tmPitchAndFamily & TMPF_VECTOR) |
4555 | ? OUT_STROKE_PRECIS : OUT_STRING_PRECIS); | |
c6be3860 AI |
4556 | |
4557 | w32_cache_char_metrics (font); | |
1a292d24 | 4558 | } |
5ac45f98 | 4559 | |
1a292d24 | 4560 | UNBLOCK_INPUT; |
5ac45f98 | 4561 | |
4587b026 GV |
4562 | if (!ok) |
4563 | { | |
1a292d24 AI |
4564 | w32_unload_font (dpyinfo, font); |
4565 | return (NULL); | |
4566 | } | |
ee78dc32 | 4567 | |
6fc2811b JR |
4568 | /* Find a free slot in the font table. */ |
4569 | for (i = 0; i < dpyinfo->n_fonts; ++i) | |
4570 | if (dpyinfo->font_table[i].name == NULL) | |
4571 | break; | |
4572 | ||
4573 | /* If no free slot found, maybe enlarge the font table. */ | |
4574 | if (i == dpyinfo->n_fonts | |
4575 | && dpyinfo->n_fonts == dpyinfo->font_table_size) | |
4587b026 | 4576 | { |
6fc2811b JR |
4577 | int sz; |
4578 | dpyinfo->font_table_size = max (16, 2 * dpyinfo->font_table_size); | |
4579 | sz = dpyinfo->font_table_size * sizeof *dpyinfo->font_table; | |
4587b026 | 4580 | dpyinfo->font_table |
6fc2811b | 4581 | = (struct font_info *) xrealloc (dpyinfo->font_table, sz); |
4587b026 GV |
4582 | } |
4583 | ||
6fc2811b JR |
4584 | fontp = dpyinfo->font_table + i; |
4585 | if (i == dpyinfo->n_fonts) | |
4586 | ++dpyinfo->n_fonts; | |
4587b026 GV |
4587 | |
4588 | /* Now fill in the slots of *FONTP. */ | |
4589 | BLOCK_INPUT; | |
0d4c2dc2 | 4590 | bzero (fontp, sizeof (*fontp)); |
4587b026 | 4591 | fontp->font = font; |
6fc2811b | 4592 | fontp->font_idx = i; |
4587b026 GV |
4593 | fontp->name = (char *) xmalloc (strlen (fontname) + 1); |
4594 | bcopy (fontname, fontp->name, strlen (fontname) + 1); | |
4595 | ||
ad5674f5 JR |
4596 | if (lf.lfPitchAndFamily == FIXED_PITCH) |
4597 | { | |
4598 | /* Fixed width font. */ | |
4599 | fontp->average_width = fontp->space_width = FONT_WIDTH (font); | |
4600 | } | |
4601 | else | |
4602 | { | |
4603 | wchar_t space = 32; | |
4604 | XCharStruct* pcm; | |
4605 | pcm = w32_per_char_metric (font, &space, ANSI_FONT); | |
4606 | if (pcm) | |
4607 | fontp->space_width = pcm->width; | |
4608 | else | |
4609 | fontp->space_width = FONT_WIDTH (font); | |
4610 | ||
4611 | fontp->average_width = font->tm.tmAveCharWidth; | |
4612 | } | |
4613 | ||
767b1ff0 JR |
4614 | charset = xlfd_charset_of_font (fontname); |
4615 | ||
19c291d3 AI |
4616 | /* Cache the W32 codepage for a font. This makes w32_encode_char |
4617 | (called for every glyph during redisplay) much faster. */ | |
4618 | fontp->codepage = codepage; | |
4619 | ||
4587b026 GV |
4620 | /* Work out the font's full name. */ |
4621 | full_name = (char *)xmalloc (100); | |
767b1ff0 | 4622 | if (full_name && w32_to_x_font (&lf, full_name, 100, charset)) |
4587b026 GV |
4623 | fontp->full_name = full_name; |
4624 | else | |
4625 | { | |
4626 | /* If all else fails - just use the name we used to load it. */ | |
4627 | xfree (full_name); | |
4628 | fontp->full_name = fontp->name; | |
4629 | } | |
4630 | ||
4631 | fontp->size = FONT_WIDTH (font); | |
4632 | fontp->height = FONT_HEIGHT (font); | |
4633 | ||
4634 | /* The slot `encoding' specifies how to map a character | |
4635 | code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to | |
126f2e35 JR |
4636 | the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or |
4637 | (0:0x20..0x7F, 1:0xA0..0xFF, | |
4638 | (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF, | |
4587b026 | 4639 | 2:0xA020..0xFF7F). For the moment, we don't know which charset |
6fc2811b | 4640 | uses this font. So, we set information in fontp->encoding[1] |
4587b026 GV |
4641 | which is never used by any charset. If mapping can't be |
4642 | decided, set FONT_ENCODING_NOT_DECIDED. */ | |
33d52f9c GV |
4643 | |
4644 | /* SJIS fonts need to be set to type 4, all others seem to work as | |
4645 | type FONT_ENCODING_NOT_DECIDED. */ | |
4646 | encoding = strrchr (fontp->name, '-'); | |
d84b082d | 4647 | if (encoding && strnicmp (encoding+1, "sjis", 4) == 0) |
1c885fe1 | 4648 | fontp->encoding[1] = 4; |
33d52f9c | 4649 | else |
1c885fe1 | 4650 | fontp->encoding[1] = FONT_ENCODING_NOT_DECIDED; |
4587b026 GV |
4651 | |
4652 | /* The following three values are set to 0 under W32, which is | |
4653 | what they get set to if XGetFontProperty fails under X. */ | |
4654 | fontp->baseline_offset = 0; | |
4655 | fontp->relative_compose = 0; | |
33d52f9c | 4656 | fontp->default_ascent = 0; |
4587b026 | 4657 | |
6fc2811b JR |
4658 | /* Set global flag fonts_changed_p to non-zero if the font loaded |
4659 | has a character with a smaller width than any other character | |
f7b9d4d1 | 4660 | before, or if the font loaded has a smaller height than any |
6fc2811b JR |
4661 | other font loaded before. If this happens, it will make a |
4662 | glyph matrix reallocation necessary. */ | |
f7b9d4d1 | 4663 | fonts_changed_p |= x_compute_min_glyph_bounds (f); |
4587b026 | 4664 | UNBLOCK_INPUT; |
4587b026 GV |
4665 | return fontp; |
4666 | } | |
4667 | } | |
4668 | ||
33d52f9c GV |
4669 | /* Load font named FONTNAME of size SIZE for frame F, and return a |
4670 | pointer to the structure font_info while allocating it dynamically. | |
4671 | If loading fails, return NULL. */ | |
4672 | struct font_info * | |
4673 | w32_load_font (f,fontname,size) | |
4674 | struct frame *f; | |
4675 | char * fontname; | |
4676 | int size; | |
4677 | { | |
4678 | Lisp_Object bdf_fonts; | |
4679 | struct font_info *retval = NULL; | |
63e50ea6 | 4680 | struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); |
33d52f9c | 4681 | |
8edb0a6f | 4682 | bdf_fonts = w32_list_bdf_fonts (build_string (fontname), 1); |
33d52f9c GV |
4683 | |
4684 | while (!retval && CONSP (bdf_fonts)) | |
4685 | { | |
4686 | char *bdf_name, *bdf_file; | |
4687 | Lisp_Object bdf_pair; | |
63e50ea6 | 4688 | int i; |
33d52f9c | 4689 | |
d5db4077 | 4690 | bdf_name = SDATA (XCAR (bdf_fonts)); |
8e713be6 | 4691 | bdf_pair = Fassoc (XCAR (bdf_fonts), Vw32_bdf_filename_alist); |
d5db4077 | 4692 | bdf_file = SDATA (XCDR (bdf_pair)); |
33d52f9c | 4693 | |
63e50ea6 JR |
4694 | // If the font is already loaded, do not load it again. |
4695 | for (i = 0; i < dpyinfo->n_fonts; i++) | |
4696 | { | |
4697 | if ((dpyinfo->font_table[i].name | |
4698 | && !strcmp (dpyinfo->font_table[i].name, bdf_name)) | |
4699 | || (dpyinfo->font_table[i].full_name | |
4700 | && !strcmp (dpyinfo->font_table[i].full_name, bdf_name))) | |
745e0c15 | 4701 | return dpyinfo->font_table + i; |
63e50ea6 JR |
4702 | } |
4703 | ||
33d52f9c GV |
4704 | retval = w32_load_bdf_font (f, bdf_name, size, bdf_file); |
4705 | ||
8e713be6 | 4706 | bdf_fonts = XCDR (bdf_fonts); |
33d52f9c GV |
4707 | } |
4708 | ||
4709 | if (retval) | |
4710 | return retval; | |
4711 | ||
4712 | return w32_load_system_font(f, fontname, size); | |
4713 | } | |
4714 | ||
4715 | ||
7d0393cf | 4716 | void |
fbd6baed GV |
4717 | w32_unload_font (dpyinfo, font) |
4718 | struct w32_display_info *dpyinfo; | |
ee78dc32 GV |
4719 | XFontStruct * font; |
4720 | { | |
7d0393cf | 4721 | if (font) |
ee78dc32 | 4722 | { |
c6be3860 | 4723 | if (font->per_char) xfree (font->per_char); |
33d52f9c GV |
4724 | if (font->bdf) w32_free_bdf_font (font->bdf); |
4725 | ||
3c190163 | 4726 | if (font->hfont) DeleteObject(font->hfont); |
ee78dc32 GV |
4727 | xfree (font); |
4728 | } | |
4729 | } | |
4730 | ||
fbd6baed | 4731 | /* The font conversion stuff between x and w32 */ |
ee78dc32 GV |
4732 | |
4733 | /* X font string is as follows (from faces.el) | |
4734 | * (let ((- "[-?]") | |
4735 | * (foundry "[^-]+") | |
4736 | * (family "[^-]+") | |
4737 | * (weight "\\(bold\\|demibold\\|medium\\)") ; 1 | |
4738 | * (weight\? "\\([^-]*\\)") ; 1 | |
4739 | * (slant "\\([ior]\\)") ; 2 | |
4740 | * (slant\? "\\([^-]?\\)") ; 2 | |
4741 | * (swidth "\\([^-]*\\)") ; 3 | |
4742 | * (adstyle "[^-]*") ; 4 | |
4743 | * (pixelsize "[0-9]+") | |
4744 | * (pointsize "[0-9][0-9]+") | |
4745 | * (resx "[0-9][0-9]+") | |
4746 | * (resy "[0-9][0-9]+") | |
4747 | * (spacing "[cmp?*]") | |
4748 | * (avgwidth "[0-9]+") | |
4749 | * (registry "[^-]+") | |
4750 | * (encoding "[^-]+") | |
4751 | * ) | |
ee78dc32 | 4752 | */ |
ee78dc32 | 4753 | |
7d0393cf | 4754 | static LONG |
fbd6baed | 4755 | x_to_w32_weight (lpw) |
ee78dc32 GV |
4756 | char * lpw; |
4757 | { | |
4758 | if (!lpw) return (FW_DONTCARE); | |
5ac45f98 GV |
4759 | |
4760 | if (stricmp (lpw,"heavy") == 0) return FW_HEAVY; | |
4761 | else if (stricmp (lpw,"extrabold") == 0) return FW_EXTRABOLD; | |
4762 | else if (stricmp (lpw,"bold") == 0) return FW_BOLD; | |
4763 | else if (stricmp (lpw,"demibold") == 0) return FW_SEMIBOLD; | |
1edf84e7 | 4764 | else if (stricmp (lpw,"semibold") == 0) return FW_SEMIBOLD; |
5ac45f98 GV |
4765 | else if (stricmp (lpw,"medium") == 0) return FW_MEDIUM; |
4766 | else if (stricmp (lpw,"normal") == 0) return FW_NORMAL; | |
4767 | else if (stricmp (lpw,"light") == 0) return FW_LIGHT; | |
4768 | else if (stricmp (lpw,"extralight") == 0) return FW_EXTRALIGHT; | |
4769 | else if (stricmp (lpw,"thin") == 0) return FW_THIN; | |
ee78dc32 | 4770 | else |
5ac45f98 | 4771 | return FW_DONTCARE; |
ee78dc32 GV |
4772 | } |
4773 | ||
5ac45f98 | 4774 | |
7d0393cf | 4775 | static char * |
fbd6baed | 4776 | w32_to_x_weight (fnweight) |
ee78dc32 GV |
4777 | int fnweight; |
4778 | { | |
5ac45f98 GV |
4779 | if (fnweight >= FW_HEAVY) return "heavy"; |
4780 | if (fnweight >= FW_EXTRABOLD) return "extrabold"; | |
4781 | if (fnweight >= FW_BOLD) return "bold"; | |
03f8fb34 | 4782 | if (fnweight >= FW_SEMIBOLD) return "demibold"; |
5ac45f98 GV |
4783 | if (fnweight >= FW_MEDIUM) return "medium"; |
4784 | if (fnweight >= FW_NORMAL) return "normal"; | |
4785 | if (fnweight >= FW_LIGHT) return "light"; | |
4786 | if (fnweight >= FW_EXTRALIGHT) return "extralight"; | |
4787 | if (fnweight >= FW_THIN) return "thin"; | |
4788 | else | |
4789 | return "*"; | |
4790 | } | |
4791 | ||
8edb0a6f | 4792 | static LONG |
fbd6baed | 4793 | x_to_w32_charset (lpcs) |
5ac45f98 GV |
4794 | char * lpcs; |
4795 | { | |
767b1ff0 | 4796 | Lisp_Object this_entry, w32_charset; |
8b77111c AI |
4797 | char *charset; |
4798 | int len = strlen (lpcs); | |
4799 | ||
4800 | /* Support "*-#nnn" format for unknown charsets. */ | |
4801 | if (strncmp (lpcs, "*-#", 3) == 0) | |
4802 | return atoi (lpcs + 3); | |
4803 | ||
4804 | /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */ | |
4805 | charset = alloca (len + 1); | |
4806 | strcpy (charset, lpcs); | |
4807 | lpcs = strchr (charset, '*'); | |
4808 | if (lpcs) | |
4809 | *lpcs = 0; | |
4587b026 | 4810 | |
dfff8a69 JR |
4811 | /* Look through w32-charset-info-alist for the character set. |
4812 | Format of each entry is | |
4813 | (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)). | |
4814 | */ | |
8b77111c | 4815 | this_entry = Fassoc (build_string(charset), Vw32_charset_info_alist); |
4587b026 | 4816 | |
767b1ff0 JR |
4817 | if (NILP(this_entry)) |
4818 | { | |
4819 | /* At startup, we want iso8859-1 fonts to come up properly. */ | |
8b77111c | 4820 | if (stricmp(charset, "iso8859-1") == 0) |
767b1ff0 JR |
4821 | return ANSI_CHARSET; |
4822 | else | |
4823 | return DEFAULT_CHARSET; | |
4824 | } | |
4825 | ||
4826 | w32_charset = Fcar (Fcdr (this_entry)); | |
4827 | ||
d84b082d | 4828 | /* Translate Lisp symbol to number. */ |
2ba49441 | 4829 | if (EQ (w32_charset, Qw32_charset_ansi)) |
767b1ff0 | 4830 | return ANSI_CHARSET; |
2ba49441 | 4831 | if (EQ (w32_charset, Qw32_charset_symbol)) |
767b1ff0 | 4832 | return SYMBOL_CHARSET; |
2ba49441 | 4833 | if (EQ (w32_charset, Qw32_charset_shiftjis)) |
767b1ff0 | 4834 | return SHIFTJIS_CHARSET; |
2ba49441 | 4835 | if (EQ (w32_charset, Qw32_charset_hangeul)) |
767b1ff0 | 4836 | return HANGEUL_CHARSET; |
2ba49441 | 4837 | if (EQ (w32_charset, Qw32_charset_chinesebig5)) |
767b1ff0 | 4838 | return CHINESEBIG5_CHARSET; |
2ba49441 | 4839 | if (EQ (w32_charset, Qw32_charset_gb2312)) |
767b1ff0 | 4840 | return GB2312_CHARSET; |
2ba49441 | 4841 | if (EQ (w32_charset, Qw32_charset_oem)) |
767b1ff0 | 4842 | return OEM_CHARSET; |
dfff8a69 | 4843 | #ifdef JOHAB_CHARSET |
2ba49441 | 4844 | if (EQ (w32_charset, Qw32_charset_johab)) |
767b1ff0 | 4845 | return JOHAB_CHARSET; |
2ba49441 | 4846 | if (EQ (w32_charset, Qw32_charset_easteurope)) |
767b1ff0 | 4847 | return EASTEUROPE_CHARSET; |
2ba49441 | 4848 | if (EQ (w32_charset, Qw32_charset_turkish)) |
767b1ff0 | 4849 | return TURKISH_CHARSET; |
2ba49441 | 4850 | if (EQ (w32_charset, Qw32_charset_baltic)) |
767b1ff0 | 4851 | return BALTIC_CHARSET; |
2ba49441 | 4852 | if (EQ (w32_charset, Qw32_charset_russian)) |
767b1ff0 | 4853 | return RUSSIAN_CHARSET; |
2ba49441 | 4854 | if (EQ (w32_charset, Qw32_charset_arabic)) |
767b1ff0 | 4855 | return ARABIC_CHARSET; |
2ba49441 | 4856 | if (EQ (w32_charset, Qw32_charset_greek)) |
767b1ff0 | 4857 | return GREEK_CHARSET; |
2ba49441 | 4858 | if (EQ (w32_charset, Qw32_charset_hebrew)) |
767b1ff0 | 4859 | return HEBREW_CHARSET; |
2ba49441 | 4860 | if (EQ (w32_charset, Qw32_charset_vietnamese)) |
767b1ff0 | 4861 | return VIETNAMESE_CHARSET; |
2ba49441 | 4862 | if (EQ (w32_charset, Qw32_charset_thai)) |
767b1ff0 | 4863 | return THAI_CHARSET; |
2ba49441 | 4864 | if (EQ (w32_charset, Qw32_charset_mac)) |
767b1ff0 | 4865 | return MAC_CHARSET; |
dfff8a69 | 4866 | #endif /* JOHAB_CHARSET */ |
5ac45f98 | 4867 | #ifdef UNICODE_CHARSET |
2ba49441 | 4868 | if (EQ (w32_charset, Qw32_charset_unicode)) |
767b1ff0 | 4869 | return UNICODE_CHARSET; |
5ac45f98 | 4870 | #endif |
dfff8a69 JR |
4871 | |
4872 | return DEFAULT_CHARSET; | |
5ac45f98 GV |
4873 | } |
4874 | ||
dfff8a69 | 4875 | |
8edb0a6f | 4876 | static char * |
fbd6baed | 4877 | w32_to_x_charset (fncharset) |
5ac45f98 GV |
4878 | int fncharset; |
4879 | { | |
5e905a57 | 4880 | static char buf[32]; |
767b1ff0 | 4881 | Lisp_Object charset_type; |
1edf84e7 | 4882 | |
5ac45f98 GV |
4883 | switch (fncharset) |
4884 | { | |
767b1ff0 JR |
4885 | case ANSI_CHARSET: |
4886 | /* Handle startup case of w32-charset-info-alist not | |
4887 | being set up yet. */ | |
4888 | if (NILP(Vw32_charset_info_alist)) | |
4889 | return "iso8859-1"; | |
4890 | charset_type = Qw32_charset_ansi; | |
4891 | break; | |
4892 | case DEFAULT_CHARSET: | |
4893 | charset_type = Qw32_charset_default; | |
4894 | break; | |
4895 | case SYMBOL_CHARSET: | |
4896 | charset_type = Qw32_charset_symbol; | |
4897 | break; | |
4898 | case SHIFTJIS_CHARSET: | |
4899 | charset_type = Qw32_charset_shiftjis; | |
4900 | break; | |
4901 | case HANGEUL_CHARSET: | |
4902 | charset_type = Qw32_charset_hangeul; | |
4903 | break; | |
4904 | case GB2312_CHARSET: | |
4905 | charset_type = Qw32_charset_gb2312; | |
4906 | break; | |
4907 | case CHINESEBIG5_CHARSET: | |
4908 | charset_type = Qw32_charset_chinesebig5; | |
4909 | break; | |
4910 | case OEM_CHARSET: | |
4911 | charset_type = Qw32_charset_oem; | |
4912 | break; | |
4587b026 GV |
4913 | |
4914 | /* More recent versions of Windows (95 and NT4.0) define more | |
4915 | character sets. */ | |
4916 | #ifdef EASTEUROPE_CHARSET | |
767b1ff0 JR |
4917 | case EASTEUROPE_CHARSET: |
4918 | charset_type = Qw32_charset_easteurope; | |
4919 | break; | |
4920 | case TURKISH_CHARSET: | |
4921 | charset_type = Qw32_charset_turkish; | |
4922 | break; | |
4923 | case BALTIC_CHARSET: | |
4924 | charset_type = Qw32_charset_baltic; | |
4925 | break; | |
33d52f9c | 4926 | case RUSSIAN_CHARSET: |
767b1ff0 JR |
4927 | charset_type = Qw32_charset_russian; |
4928 | break; | |
4929 | case ARABIC_CHARSET: | |
4930 | charset_type = Qw32_charset_arabic; | |
4931 | break; | |
4932 | case GREEK_CHARSET: | |
4933 | charset_type = Qw32_charset_greek; | |
4934 | break; | |
4935 | case HEBREW_CHARSET: | |
4936 | charset_type = Qw32_charset_hebrew; | |
4937 | break; | |
4938 | case VIETNAMESE_CHARSET: | |
4939 | charset_type = Qw32_charset_vietnamese; | |
4940 | break; | |
4941 | case THAI_CHARSET: | |
4942 | charset_type = Qw32_charset_thai; | |
4943 | break; | |
4944 | case MAC_CHARSET: | |
4945 | charset_type = Qw32_charset_mac; | |
4946 | break; | |
4947 | case JOHAB_CHARSET: | |
4948 | charset_type = Qw32_charset_johab; | |
4949 | break; | |
4587b026 GV |
4950 | #endif |
4951 | ||
5ac45f98 | 4952 | #ifdef UNICODE_CHARSET |
767b1ff0 JR |
4953 | case UNICODE_CHARSET: |
4954 | charset_type = Qw32_charset_unicode; | |
4955 | break; | |
5ac45f98 | 4956 | #endif |
767b1ff0 JR |
4957 | default: |
4958 | /* Encode numerical value of unknown charset. */ | |
4959 | sprintf (buf, "*-#%u", fncharset); | |
4960 | return buf; | |
5ac45f98 | 4961 | } |
7d0393cf | 4962 | |
767b1ff0 JR |
4963 | { |
4964 | Lisp_Object rest; | |
4965 | char * best_match = NULL; | |
4966 | ||
4967 | /* Look through w32-charset-info-alist for the character set. | |
4968 | Prefer ISO codepages, and prefer lower numbers in the ISO | |
4969 | range. Only return charsets for codepages which are installed. | |
4970 | ||
4971 | Format of each entry is | |
4972 | (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)). | |
4973 | */ | |
4974 | for (rest = Vw32_charset_info_alist; CONSP (rest); rest = XCDR (rest)) | |
4975 | { | |
4976 | char * x_charset; | |
4977 | Lisp_Object w32_charset; | |
4978 | Lisp_Object codepage; | |
4979 | ||
4980 | Lisp_Object this_entry = XCAR (rest); | |
4981 | ||
4982 | /* Skip invalid entries in alist. */ | |
4983 | if (!CONSP (this_entry) || !STRINGP (XCAR (this_entry)) | |
4984 | || !CONSP (XCDR (this_entry)) | |
4985 | || !SYMBOLP (XCAR (XCDR (this_entry)))) | |
4986 | continue; | |
4987 | ||
d5db4077 | 4988 | x_charset = SDATA (XCAR (this_entry)); |
767b1ff0 JR |
4989 | w32_charset = XCAR (XCDR (this_entry)); |
4990 | codepage = XCDR (XCDR (this_entry)); | |
4991 | ||
4992 | /* Look for Same charset and a valid codepage (or non-int | |
4993 | which means ignore). */ | |
2ba49441 JR |
4994 | if (EQ (w32_charset, charset_type) |
4995 | && (!INTEGERP (codepage) || XINT (codepage) == CP_DEFAULT | |
767b1ff0 JR |
4996 | || IsValidCodePage (XINT (codepage)))) |
4997 | { | |
4998 | /* If we don't have a match already, then this is the | |
4999 | best. */ | |
5000 | if (!best_match) | |
5001 | best_match = x_charset; | |
5002 | /* If this is an ISO codepage, and the best so far isn't, | |
5003 | then this is better. */ | |
d84b082d JR |
5004 | else if (strnicmp (best_match, "iso", 3) != 0 |
5005 | && strnicmp (x_charset, "iso", 3) == 0) | |
767b1ff0 JR |
5006 | best_match = x_charset; |
5007 | /* If both are ISO8859 codepages, choose the one with the | |
5008 | lowest number in the encoding field. */ | |
d84b082d JR |
5009 | else if (strnicmp (best_match, "iso8859-", 8) == 0 |
5010 | && strnicmp (x_charset, "iso8859-", 8) == 0) | |
767b1ff0 JR |
5011 | { |
5012 | int best_enc = atoi (best_match + 8); | |
5013 | int this_enc = atoi (x_charset + 8); | |
5014 | if (this_enc > 0 && this_enc < best_enc) | |
5015 | best_match = x_charset; | |
7d0393cf | 5016 | } |
767b1ff0 JR |
5017 | } |
5018 | } | |
5019 | ||
5020 | /* If no match, encode the numeric value. */ | |
5021 | if (!best_match) | |
5022 | { | |
5023 | sprintf (buf, "*-#%u", fncharset); | |
5024 | return buf; | |
5025 | } | |
5026 | ||
5e905a57 JR |
5027 | strncpy(buf, best_match, 31); |
5028 | buf[31] = '\0'; | |
767b1ff0 JR |
5029 | return buf; |
5030 | } | |
ee78dc32 GV |
5031 | } |
5032 | ||
dfff8a69 | 5033 | |
d84b082d JR |
5034 | /* Return all the X charsets that map to a font. */ |
5035 | static Lisp_Object | |
5036 | w32_to_all_x_charsets (fncharset) | |
5037 | int fncharset; | |
5038 | { | |
5039 | static char buf[32]; | |
5040 | Lisp_Object charset_type; | |
5041 | Lisp_Object retval = Qnil; | |
5042 | ||
5043 | switch (fncharset) | |
5044 | { | |
5045 | case ANSI_CHARSET: | |
5046 | /* Handle startup case of w32-charset-info-alist not | |
5047 | being set up yet. */ | |
5048 | if (NILP(Vw32_charset_info_alist)) | |
d86c35ee JR |
5049 | return Fcons (build_string ("iso8859-1"), Qnil); |
5050 | ||
d84b082d JR |
5051 | charset_type = Qw32_charset_ansi; |
5052 | break; | |
5053 | case DEFAULT_CHARSET: | |
5054 | charset_type = Qw32_charset_default; | |
5055 | break; | |
5056 | case SYMBOL_CHARSET: | |
5057 | charset_type = Qw32_charset_symbol; | |
5058 | break; | |
5059 | case SHIFTJIS_CHARSET: | |
5060 | charset_type = Qw32_charset_shiftjis; | |
5061 | break; | |
5062 | case HANGEUL_CHARSET: | |
5063 | charset_type = Qw32_charset_hangeul; | |
5064 | break; | |
5065 | case GB2312_CHARSET: | |
5066 | charset_type = Qw32_charset_gb2312; | |
5067 | break; | |
5068 | case CHINESEBIG5_CHARSET: | |
5069 | charset_type = Qw32_charset_chinesebig5; | |
5070 | break; | |
5071 | case OEM_CHARSET: | |
5072 | charset_type = Qw32_charset_oem; | |
5073 | break; | |
5074 | ||
5075 | /* More recent versions of Windows (95 and NT4.0) define more | |
5076 | character sets. */ | |
5077 | #ifdef EASTEUROPE_CHARSET | |
5078 | case EASTEUROPE_CHARSET: | |
5079 | charset_type = Qw32_charset_easteurope; | |
5080 | break; | |
5081 | case TURKISH_CHARSET: | |
5082 | charset_type = Qw32_charset_turkish; | |
5083 | break; | |
5084 | case BALTIC_CHARSET: | |
5085 | charset_type = Qw32_charset_baltic; | |
5086 | break; | |
5087 | case RUSSIAN_CHARSET: | |
5088 | charset_type = Qw32_charset_russian; | |
5089 | break; | |
5090 | case ARABIC_CHARSET: | |
5091 | charset_type = Qw32_charset_arabic; | |
5092 | break; | |
5093 | case GREEK_CHARSET: | |
5094 | charset_type = Qw32_charset_greek; | |
5095 | break; | |
5096 | case HEBREW_CHARSET: | |
5097 | charset_type = Qw32_charset_hebrew; | |
5098 | break; | |
5099 | case VIETNAMESE_CHARSET: | |
5100 | charset_type = Qw32_charset_vietnamese; | |
5101 | break; | |
5102 | case THAI_CHARSET: | |
5103 | charset_type = Qw32_charset_thai; | |
5104 | break; | |
5105 | case MAC_CHARSET: | |
5106 | charset_type = Qw32_charset_mac; | |
5107 | break; | |
5108 | case JOHAB_CHARSET: | |
5109 | charset_type = Qw32_charset_johab; | |
5110 | break; | |
5111 | #endif | |
5112 | ||
5113 | #ifdef UNICODE_CHARSET | |
5114 | case UNICODE_CHARSET: | |
5115 | charset_type = Qw32_charset_unicode; | |
5116 | break; | |
5117 | #endif | |
5118 | default: | |
5119 | /* Encode numerical value of unknown charset. */ | |
5120 | sprintf (buf, "*-#%u", fncharset); | |
5121 | return Fcons (build_string (buf), Qnil); | |
5122 | } | |
7d0393cf | 5123 | |
d84b082d JR |
5124 | { |
5125 | Lisp_Object rest; | |
5126 | /* Look through w32-charset-info-alist for the character set. | |
5127 | Only return charsets for codepages which are installed. | |
5128 | ||
5129 | Format of each entry in Vw32_charset_info_alist is | |
5130 | (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)). | |
5131 | */ | |
5132 | for (rest = Vw32_charset_info_alist; CONSP (rest); rest = XCDR (rest)) | |
5133 | { | |
5134 | Lisp_Object x_charset; | |
5135 | Lisp_Object w32_charset; | |
5136 | Lisp_Object codepage; | |
5137 | ||
5138 | Lisp_Object this_entry = XCAR (rest); | |
5139 | ||
5140 | /* Skip invalid entries in alist. */ | |
5141 | if (!CONSP (this_entry) || !STRINGP (XCAR (this_entry)) | |
5142 | || !CONSP (XCDR (this_entry)) | |
5143 | || !SYMBOLP (XCAR (XCDR (this_entry)))) | |
5144 | continue; | |
5145 | ||
5146 | x_charset = XCAR (this_entry); | |
5147 | w32_charset = XCAR (XCDR (this_entry)); | |
5148 | codepage = XCDR (XCDR (this_entry)); | |
5149 | ||
5150 | /* Look for Same charset and a valid codepage (or non-int | |
5151 | which means ignore). */ | |
2ba49441 JR |
5152 | if (EQ (w32_charset, charset_type) |
5153 | && (!INTEGERP (codepage) || XINT (codepage) == CP_DEFAULT | |
d84b082d JR |
5154 | || IsValidCodePage (XINT (codepage)))) |
5155 | { | |
5156 | retval = Fcons (x_charset, retval); | |
5157 | } | |
5158 | } | |
5159 | ||
5160 | /* If no match, encode the numeric value. */ | |
5161 | if (NILP (retval)) | |
5162 | { | |
5163 | sprintf (buf, "*-#%u", fncharset); | |
5164 | return Fcons (build_string (buf), Qnil); | |
5165 | } | |
5166 | ||
5167 | return retval; | |
5168 | } | |
5169 | } | |
5170 | ||
dfff8a69 JR |
5171 | /* Get the Windows codepage corresponding to the specified font. The |
5172 | charset info in the font name is used to look up | |
5173 | w32-charset-to-codepage-alist. */ | |
7d0393cf | 5174 | int |
dfff8a69 JR |
5175 | w32_codepage_for_font (char *fontname) |
5176 | { | |
767b1ff0 JR |
5177 | Lisp_Object codepage, entry; |
5178 | char *charset_str, *charset, *end; | |
dfff8a69 | 5179 | |
767b1ff0 | 5180 | if (NILP (Vw32_charset_info_alist)) |
dfff8a69 JR |
5181 | return CP_DEFAULT; |
5182 | ||
767b1ff0 JR |
5183 | /* Extract charset part of font string. */ |
5184 | charset = xlfd_charset_of_font (fontname); | |
5185 | ||
5186 | if (!charset) | |
ceb12877 | 5187 | return CP_UNKNOWN; |
767b1ff0 | 5188 | |
8b77111c | 5189 | charset_str = (char *) alloca (strlen (charset) + 1); |
767b1ff0 JR |
5190 | strcpy (charset_str, charset); |
5191 | ||
8b77111c | 5192 | #if 0 |
dfff8a69 JR |
5193 | /* Remove leading "*-". */ |
5194 | if (strncmp ("*-", charset_str, 2) == 0) | |
5195 | charset = charset_str + 2; | |
5196 | else | |
8b77111c | 5197 | #endif |
dfff8a69 JR |
5198 | charset = charset_str; |
5199 | ||
5200 | /* Stop match at wildcard (including preceding '-'). */ | |
5201 | if (end = strchr (charset, '*')) | |
5202 | { | |
5203 | if (end > charset && *(end-1) == '-') | |
5204 | end--; | |
5205 | *end = '\0'; | |
5206 | } | |
5207 | ||
767b1ff0 JR |
5208 | entry = Fassoc (build_string(charset), Vw32_charset_info_alist); |
5209 | if (NILP (entry)) | |
ceb12877 | 5210 | return CP_UNKNOWN; |
767b1ff0 JR |
5211 | |
5212 | codepage = Fcdr (Fcdr (entry)); | |
5213 | ||
5214 | if (NILP (codepage)) | |
5215 | return CP_8BIT; | |
5216 | else if (XFASTINT (codepage) == XFASTINT (Qt)) | |
5217 | return CP_UNICODE; | |
5218 | else if (INTEGERP (codepage)) | |
dfff8a69 JR |
5219 | return XINT (codepage); |
5220 | else | |
ceb12877 | 5221 | return CP_UNKNOWN; |
dfff8a69 JR |
5222 | } |
5223 | ||
5224 | ||
7d0393cf | 5225 | static BOOL |
767b1ff0 | 5226 | w32_to_x_font (lplogfont, lpxstr, len, specific_charset) |
ee78dc32 GV |
5227 | LOGFONT * lplogfont; |
5228 | char * lpxstr; | |
5229 | int len; | |
767b1ff0 | 5230 | char * specific_charset; |
ee78dc32 | 5231 | { |
6fc2811b | 5232 | char* fonttype; |
f46e6225 | 5233 | char *fontname; |
3cb20f4a RS |
5234 | char height_pixels[8]; |
5235 | char height_dpi[8]; | |
5236 | char width_pixels[8]; | |
4587b026 | 5237 | char *fontname_dash; |
ac849ba4 JR |
5238 | int display_resy = (int) one_w32_display_info.resy; |
5239 | int display_resx = (int) one_w32_display_info.resx; | |
f46e6225 GV |
5240 | int bufsz; |
5241 | struct coding_system coding; | |
3cb20f4a RS |
5242 | |
5243 | if (!lpxstr) abort (); | |
ee78dc32 | 5244 | |
3cb20f4a RS |
5245 | if (!lplogfont) |
5246 | return FALSE; | |
5247 | ||
6fc2811b JR |
5248 | if (lplogfont->lfOutPrecision == OUT_STRING_PRECIS) |
5249 | fonttype = "raster"; | |
5250 | else if (lplogfont->lfOutPrecision == OUT_STROKE_PRECIS) | |
5251 | fonttype = "outline"; | |
5252 | else | |
5253 | fonttype = "unknown"; | |
5254 | ||
1fa3a200 | 5255 | setup_coding_system (Fcheck_coding_system (Vlocale_coding_system), |
f46e6225 | 5256 | &coding); |
aab5ac44 KH |
5257 | coding.src_multibyte = 0; |
5258 | coding.dst_multibyte = 1; | |
f46e6225 | 5259 | coding.mode |= CODING_MODE_LAST_BLOCK; |
65413122 KH |
5260 | /* We explicitely disable composition handling because selection |
5261 | data should not contain any composition sequence. */ | |
5262 | coding.composing = COMPOSITION_DISABLED; | |
f46e6225 GV |
5263 | bufsz = decoding_buffer_size (&coding, LF_FACESIZE); |
5264 | ||
5265 | fontname = alloca(sizeof(*fontname) * bufsz); | |
5266 | decode_coding (&coding, lplogfont->lfFaceName, fontname, | |
5267 | strlen(lplogfont->lfFaceName), bufsz - 1); | |
5268 | *(fontname + coding.produced) = '\0'; | |
4587b026 GV |
5269 | |
5270 | /* Replace dashes with underscores so the dashes are not | |
f46e6225 | 5271 | misinterpreted. */ |
4587b026 GV |
5272 | fontname_dash = fontname; |
5273 | while (fontname_dash = strchr (fontname_dash, '-')) | |
5274 | *fontname_dash = '_'; | |
5275 | ||
3cb20f4a | 5276 | if (lplogfont->lfHeight) |
ee78dc32 | 5277 | { |
3cb20f4a RS |
5278 | sprintf (height_pixels, "%u", abs (lplogfont->lfHeight)); |
5279 | sprintf (height_dpi, "%u", | |
33d52f9c | 5280 | abs (lplogfont->lfHeight) * 720 / display_resy); |
5ac45f98 GV |
5281 | } |
5282 | else | |
ee78dc32 | 5283 | { |
3cb20f4a RS |
5284 | strcpy (height_pixels, "*"); |
5285 | strcpy (height_dpi, "*"); | |
ee78dc32 | 5286 | } |
813fa8a8 JR |
5287 | |
5288 | #if 0 /* Never put the width in the xfld. It fails on fonts with | |
5289 | double-width characters. */ | |
3cb20f4a RS |
5290 | if (lplogfont->lfWidth) |
5291 | sprintf (width_pixels, "%u", lplogfont->lfWidth * 10); | |
5292 | else | |
813fa8a8 | 5293 | #endif |
3cb20f4a RS |
5294 | strcpy (width_pixels, "*"); |
5295 | ||
5296 | _snprintf (lpxstr, len - 1, | |
6fc2811b JR |
5297 | "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s", |
5298 | fonttype, /* foundry */ | |
4587b026 GV |
5299 | fontname, /* family */ |
5300 | w32_to_x_weight (lplogfont->lfWeight), /* weight */ | |
5301 | lplogfont->lfItalic?'i':'r', /* slant */ | |
5302 | /* setwidth name */ | |
5303 | /* add style name */ | |
5304 | height_pixels, /* pixel size */ | |
5305 | height_dpi, /* point size */ | |
33d52f9c GV |
5306 | display_resx, /* resx */ |
5307 | display_resy, /* resy */ | |
4587b026 GV |
5308 | ((lplogfont->lfPitchAndFamily & 0x3) == VARIABLE_PITCH) |
5309 | ? 'p' : 'c', /* spacing */ | |
5310 | width_pixels, /* avg width */ | |
767b1ff0 | 5311 | specific_charset ? specific_charset |
7d0393cf | 5312 | : w32_to_x_charset (lplogfont->lfCharSet) |
767b1ff0 | 5313 | /* charset registry and encoding */ |
3cb20f4a RS |
5314 | ); |
5315 | ||
ee78dc32 GV |
5316 | lpxstr[len - 1] = 0; /* just to be sure */ |
5317 | return (TRUE); | |
5318 | } | |
5319 | ||
7d0393cf | 5320 | static BOOL |
fbd6baed | 5321 | x_to_w32_font (lpxstr, lplogfont) |
ee78dc32 GV |
5322 | char * lpxstr; |
5323 | LOGFONT * lplogfont; | |
5324 | { | |
f46e6225 GV |
5325 | struct coding_system coding; |
5326 | ||
ee78dc32 | 5327 | if (!lplogfont) return (FALSE); |
f46e6225 | 5328 | |
ee78dc32 | 5329 | memset (lplogfont, 0, sizeof (*lplogfont)); |
5ac45f98 | 5330 | |
1a292d24 | 5331 | /* Set default value for each field. */ |
771c47d5 | 5332 | #if 1 |
ee78dc32 GV |
5333 | lplogfont->lfOutPrecision = OUT_DEFAULT_PRECIS; |
5334 | lplogfont->lfClipPrecision = CLIP_DEFAULT_PRECIS; | |
5335 | lplogfont->lfQuality = DEFAULT_QUALITY; | |
5ac45f98 GV |
5336 | #else |
5337 | /* go for maximum quality */ | |
5338 | lplogfont->lfOutPrecision = OUT_STROKE_PRECIS; | |
5339 | lplogfont->lfClipPrecision = CLIP_STROKE_PRECIS; | |
5340 | lplogfont->lfQuality = PROOF_QUALITY; | |
5341 | #endif | |
5342 | ||
1a292d24 AI |
5343 | lplogfont->lfCharSet = DEFAULT_CHARSET; |
5344 | lplogfont->lfWeight = FW_DONTCARE; | |
5345 | lplogfont->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; | |
5346 | ||
5ac45f98 GV |
5347 | if (!lpxstr) |
5348 | return FALSE; | |
5349 | ||
5350 | /* Provide a simple escape mechanism for specifying Windows font names | |
5351 | * directly -- if font spec does not beginning with '-', assume this | |
5352 | * format: | |
5353 | * "<font name>[:height in pixels[:width in pixels[:weight]]]" | |
5354 | */ | |
7d0393cf | 5355 | |
5ac45f98 GV |
5356 | if (*lpxstr == '-') |
5357 | { | |
33d52f9c GV |
5358 | int fields, tem; |
5359 | char name[50], weight[20], slant, pitch, pixels[10], height[10], | |
8b77111c | 5360 | width[10], resy[10], remainder[50]; |
5ac45f98 | 5361 | char * encoding; |
ac849ba4 | 5362 | int dpi = (int) one_w32_display_info.resy; |
5ac45f98 GV |
5363 | |
5364 | fields = sscanf (lpxstr, | |
8b77111c | 5365 | "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s", |
33d52f9c | 5366 | name, weight, &slant, pixels, height, resy, &pitch, width, remainder); |
8b77111c AI |
5367 | if (fields == EOF) |
5368 | return (FALSE); | |
5369 | ||
5370 | /* In the general case when wildcards cover more than one field, | |
5371 | we don't know which field is which, so don't fill any in. | |
5372 | However, we need to cope with this particular form, which is | |
5373 | generated by font_list_1 (invoked by try_font_list): | |
5374 | "-raster-6x10-*-gb2312*-*" | |
5375 | and make sure to correctly parse the charset field. */ | |
5376 | if (fields == 3) | |
5377 | { | |
5378 | fields = sscanf (lpxstr, | |
5379 | "-%*[^-]-%49[^-]-*-%49s", | |
5380 | name, remainder); | |
5381 | } | |
5382 | else if (fields < 9) | |
5383 | { | |
5384 | fields = 0; | |
5385 | remainder[0] = 0; | |
5386 | } | |
6fc2811b | 5387 | |
5ac45f98 GV |
5388 | if (fields > 0 && name[0] != '*') |
5389 | { | |
8ea3e054 RS |
5390 | int bufsize; |
5391 | unsigned char *buf; | |
5392 | ||
f46e6225 | 5393 | setup_coding_system |
1fa3a200 | 5394 | (Fcheck_coding_system (Vlocale_coding_system), &coding); |
aab5ac44 | 5395 | coding.src_multibyte = 1; |
0424a1b0 | 5396 | coding.dst_multibyte = 0; |
2883d842 JR |
5397 | /* Need to set COMPOSITION_DISABLED, otherwise Emacs crashes in |
5398 | encode_coding_iso2022 trying to dereference a null pointer. */ | |
5399 | coding.composing = COMPOSITION_DISABLED; | |
5400 | if (coding.type == coding_type_iso2022) | |
5401 | coding.flags |= CODING_FLAG_ISO_SAFE; | |
8ea3e054 RS |
5402 | bufsize = encoding_buffer_size (&coding, strlen (name)); |
5403 | buf = (unsigned char *) alloca (bufsize); | |
f46e6225 | 5404 | coding.mode |= CODING_MODE_LAST_BLOCK; |
8ea3e054 RS |
5405 | encode_coding (&coding, name, buf, strlen (name), bufsize); |
5406 | if (coding.produced >= LF_FACESIZE) | |
5407 | coding.produced = LF_FACESIZE - 1; | |
5408 | buf[coding.produced] = 0; | |
5409 | strcpy (lplogfont->lfFaceName, buf); | |
5ac45f98 GV |
5410 | } |
5411 | else | |
5412 | { | |
6fc2811b | 5413 | lplogfont->lfFaceName[0] = '\0'; |
5ac45f98 GV |
5414 | } |
5415 | ||
5416 | fields--; | |
5417 | ||
fbd6baed | 5418 | lplogfont->lfWeight = x_to_w32_weight ((fields > 0 ? weight : "")); |
5ac45f98 GV |
5419 | |
5420 | fields--; | |
5421 | ||
c8874f14 | 5422 | lplogfont->lfItalic = (fields > 0 && slant == 'i'); |
5ac45f98 GV |
5423 | |
5424 | fields--; | |
5425 | ||
5426 | if (fields > 0 && pixels[0] != '*') | |
5427 | lplogfont->lfHeight = atoi (pixels); | |
5428 | ||
5429 | fields--; | |
5ac45f98 | 5430 | fields--; |
33d52f9c GV |
5431 | if (fields > 0 && resy[0] != '*') |
5432 | { | |
6fc2811b | 5433 | tem = atoi (resy); |
33d52f9c GV |
5434 | if (tem > 0) dpi = tem; |
5435 | } | |
5ac45f98 | 5436 | |
33d52f9c GV |
5437 | if (fields > -1 && lplogfont->lfHeight == 0 && height[0] != '*') |
5438 | lplogfont->lfHeight = atoi (height) * dpi / 720; | |
5439 | ||
5440 | if (fields > 0) | |
5ac45f98 GV |
5441 | lplogfont->lfPitchAndFamily = |
5442 | (fields > 0 && pitch == 'p') ? VARIABLE_PITCH : FIXED_PITCH; | |
5443 | ||
5444 | fields--; | |
5445 | ||
5446 | if (fields > 0 && width[0] != '*') | |
5447 | lplogfont->lfWidth = atoi (width) / 10; | |
5448 | ||
5449 | fields--; | |
5450 | ||
4587b026 | 5451 | /* Strip the trailing '-' if present. (it shouldn't be, as it |
d88c567c | 5452 | fails the test against xlfd-tight-regexp in fontset.el). */ |
3c190163 | 5453 | { |
5ac45f98 GV |
5454 | int len = strlen (remainder); |
5455 | if (len > 0 && remainder[len-1] == '-') | |
5456 | remainder[len-1] = 0; | |
ee78dc32 | 5457 | } |
5ac45f98 | 5458 | encoding = remainder; |
8b77111c | 5459 | #if 0 |
5ac45f98 GV |
5460 | if (strncmp (encoding, "*-", 2) == 0) |
5461 | encoding += 2; | |
8b77111c AI |
5462 | #endif |
5463 | lplogfont->lfCharSet = x_to_w32_charset (encoding); | |
5ac45f98 GV |
5464 | } |
5465 | else | |
5466 | { | |
5467 | int fields; | |
5468 | char name[100], height[10], width[10], weight[20]; | |
a1a80b40 | 5469 | |
5ac45f98 GV |
5470 | fields = sscanf (lpxstr, |
5471 | "%99[^:]:%9[^:]:%9[^:]:%19s", | |
5472 | name, height, width, weight); | |
5473 | ||
5474 | if (fields == EOF) return (FALSE); | |
5475 | ||
5476 | if (fields > 0) | |
5477 | { | |
5478 | strncpy (lplogfont->lfFaceName,name, LF_FACESIZE); | |
5479 | lplogfont->lfFaceName[LF_FACESIZE-1] = 0; | |
5480 | } | |
5481 | else | |
5482 | { | |
5483 | lplogfont->lfFaceName[0] = 0; | |
5484 | } | |
5485 | ||
5486 | fields--; | |
5487 | ||
5488 | if (fields > 0) | |
5489 | lplogfont->lfHeight = atoi (height); | |
5490 | ||
5491 | fields--; | |
5492 | ||
5493 | if (fields > 0) | |
5494 | lplogfont->lfWidth = atoi (width); | |
5495 | ||
5496 | fields--; | |
5497 | ||
fbd6baed | 5498 | lplogfont->lfWeight = x_to_w32_weight ((fields > 0 ? weight : "")); |
5ac45f98 GV |
5499 | } |
5500 | ||
5501 | /* This makes TrueType fonts work better. */ | |
5502 | lplogfont->lfHeight = - abs (lplogfont->lfHeight); | |
6fc2811b | 5503 | |
ee78dc32 GV |
5504 | return (TRUE); |
5505 | } | |
5506 | ||
d88c567c JR |
5507 | /* Strip the pixel height and point height from the given xlfd, and |
5508 | return the pixel height. If no pixel height is specified, calculate | |
5509 | one from the point height, or if that isn't defined either, return | |
5510 | 0 (which usually signifies a scalable font). | |
5511 | */ | |
8edb0a6f JR |
5512 | static int |
5513 | xlfd_strip_height (char *fontname) | |
d88c567c | 5514 | { |
8edb0a6f | 5515 | int pixel_height, field_number; |
d88c567c JR |
5516 | char *read_from, *write_to; |
5517 | ||
5518 | xassert (fontname); | |
5519 | ||
5520 | pixel_height = field_number = 0; | |
5521 | write_to = NULL; | |
5522 | ||
5523 | /* Look for height fields. */ | |
5524 | for (read_from = fontname; *read_from; read_from++) | |
5525 | { | |
5526 | if (*read_from == '-') | |
5527 | { | |
5528 | field_number++; | |
5529 | if (field_number == 7) /* Pixel height. */ | |
5530 | { | |
5531 | read_from++; | |
5532 | write_to = read_from; | |
5533 | ||
5534 | /* Find end of field. */ | |
5535 | for (;*read_from && *read_from != '-'; read_from++) | |
5536 | ; | |
5537 | ||
5538 | /* Split the fontname at end of field. */ | |
5539 | if (*read_from) | |
5540 | { | |
5541 | *read_from = '\0'; | |
5542 | read_from++; | |
5543 | } | |
5544 | pixel_height = atoi (write_to); | |
5545 | /* Blank out field. */ | |
5546 | if (read_from > write_to) | |
5547 | { | |
5548 | *write_to = '-'; | |
5549 | write_to++; | |
5550 | } | |
767b1ff0 | 5551 | /* If the pixel height field is at the end (partial xlfd), |
d88c567c JR |
5552 | return now. */ |
5553 | else | |
5554 | return pixel_height; | |
5555 | ||
5556 | /* If we got a pixel height, the point height can be | |
5557 | ignored. Just blank it out and break now. */ | |
5558 | if (pixel_height) | |
5559 | { | |
5560 | /* Find end of point size field. */ | |
5561 | for (; *read_from && *read_from != '-'; read_from++) | |
5562 | ; | |
5563 | ||
5564 | if (*read_from) | |
5565 | read_from++; | |
5566 | ||
5567 | /* Blank out the point size field. */ | |
5568 | if (read_from > write_to) | |
5569 | { | |
5570 | *write_to = '-'; | |
5571 | write_to++; | |
5572 | } | |
5573 | else | |
5574 | return pixel_height; | |
5575 | ||
5576 | break; | |
5577 | } | |
5578 | /* If the point height is already blank, break now. */ | |
5579 | if (*read_from == '-') | |
5580 | { | |
5581 | read_from++; | |
5582 | break; | |
5583 | } | |
5584 | } | |
5585 | else if (field_number == 8) | |
5586 | { | |
5587 | /* If we didn't get a pixel height, try to get the point | |
5588 | height and convert that. */ | |
5589 | int point_size; | |
5590 | char *point_size_start = read_from++; | |
5591 | ||
5592 | /* Find end of field. */ | |
5593 | for (; *read_from && *read_from != '-'; read_from++) | |
5594 | ; | |
5595 | ||
5596 | if (*read_from) | |
5597 | { | |
5598 | *read_from = '\0'; | |
5599 | read_from++; | |
5600 | } | |
5601 | ||
5602 | point_size = atoi (point_size_start); | |
5603 | ||
5604 | /* Convert to pixel height. */ | |
5605 | pixel_height = point_size | |
5606 | * one_w32_display_info.height_in / 720; | |
5607 | ||
5608 | /* Blank out this field and break. */ | |
5609 | *write_to = '-'; | |
5610 | write_to++; | |
5611 | break; | |
5612 | } | |
5613 | } | |
5614 | } | |
5615 | ||
5616 | /* Shift the rest of the font spec into place. */ | |
5617 | if (write_to && read_from > write_to) | |
5618 | { | |
5619 | for (; *read_from; read_from++, write_to++) | |
5620 | *write_to = *read_from; | |
5621 | *write_to = '\0'; | |
5622 | } | |
5623 | ||
5624 | return pixel_height; | |
5625 | } | |
5626 | ||
6fc2811b | 5627 | /* Assume parameter 1 is fully qualified, no wildcards. */ |
7d0393cf | 5628 | static BOOL |
6fc2811b JR |
5629 | w32_font_match (fontname, pattern) |
5630 | char * fontname; | |
5631 | char * pattern; | |
ee78dc32 | 5632 | { |
6fc2811b | 5633 | char *ptr; |
fe4dcb86 | 5634 | char *font_name_copy; |
0424a1b0 | 5635 | char *regex = alloca (strlen (pattern) * 2 + 3); |
ee78dc32 | 5636 | |
fe4dcb86 JR |
5637 | font_name_copy = alloca (strlen (fontname) + 1); |
5638 | strcpy (font_name_copy, fontname); | |
d88c567c | 5639 | |
6fc2811b JR |
5640 | ptr = regex; |
5641 | *ptr++ = '^'; | |
ee78dc32 | 5642 | |
6fc2811b JR |
5643 | /* Turn pattern into a regexp and do a regexp match. */ |
5644 | for (; *pattern; pattern++) | |
5645 | { | |
5646 | if (*pattern == '?') | |
5647 | *ptr++ = '.'; | |
5648 | else if (*pattern == '*') | |
5649 | { | |
5650 | *ptr++ = '.'; | |
5651 | *ptr++ = '*'; | |
5652 | } | |
33d52f9c | 5653 | else |
6fc2811b | 5654 | *ptr++ = *pattern; |
ee78dc32 | 5655 | } |
6fc2811b JR |
5656 | *ptr = '$'; |
5657 | *(ptr + 1) = '\0'; | |
5658 | ||
d88c567c JR |
5659 | /* Strip out font heights and compare them seperately, since |
5660 | rounding error can cause mismatches. This also allows a | |
5661 | comparison between a font that declares only a pixel height and a | |
5662 | pattern that declares the point height. | |
5663 | */ | |
5664 | { | |
5665 | int font_height, pattern_height; | |
5666 | ||
5667 | font_height = xlfd_strip_height (font_name_copy); | |
5668 | pattern_height = xlfd_strip_height (regex); | |
5669 | ||
5670 | /* Compare now, and don't bother doing expensive regexp matching | |
5671 | if the heights differ. */ | |
5672 | if (font_height && pattern_height && (font_height != pattern_height)) | |
5673 | return FALSE; | |
5674 | } | |
5675 | ||
fe4dcb86 JR |
5676 | return (fast_string_match_ignore_case (build_string (regex), |
5677 | build_string(font_name_copy)) >= 0); | |
ee78dc32 GV |
5678 | } |
5679 | ||
5ca0cd71 GV |
5680 | /* Callback functions, and a structure holding info they need, for |
5681 | listing system fonts on W32. We need one set of functions to do the | |
5682 | job properly, but these don't work on NT 3.51 and earlier, so we | |
5683 | have a second set which don't handle character sets properly to | |
5684 | fall back on. | |
5685 | ||
5686 | In both cases, there are two passes made. The first pass gets one | |
5687 | font from each family, the second pass lists all the fonts from | |
5688 | each family. */ | |
5689 | ||
7d0393cf | 5690 | typedef struct enumfont_t |
ee78dc32 GV |
5691 | { |
5692 | HDC hdc; | |
5693 | int numFonts; | |
3cb20f4a | 5694 | LOGFONT logfont; |
ee78dc32 | 5695 | XFontStruct *size_ref; |
23afac8f | 5696 | Lisp_Object pattern; |
d84b082d | 5697 | Lisp_Object list; |
ee78dc32 GV |
5698 | } enumfont_t; |
5699 | ||
d84b082d JR |
5700 | |
5701 | static void | |
5702 | enum_font_maybe_add_to_list (enumfont_t *, LOGFONT *, char *, Lisp_Object); | |
5703 | ||
5704 | ||
7d0393cf | 5705 | static int CALLBACK |
ee78dc32 GV |
5706 | enum_font_cb2 (lplf, lptm, FontType, lpef) |
5707 | ENUMLOGFONT * lplf; | |
5708 | NEWTEXTMETRIC * lptm; | |
5709 | int FontType; | |
5710 | enumfont_t * lpef; | |
5711 | { | |
66895301 JR |
5712 | /* Ignore struck out and underlined versions of fonts. */ |
5713 | if (lplf->elfLogFont.lfStrikeOut || lplf->elfLogFont.lfUnderline) | |
5714 | return 1; | |
5715 | ||
5716 | /* Only return fonts with names starting with @ if they were | |
5717 | explicitly specified, since Microsoft uses an initial @ to | |
5718 | denote fonts for vertical writing, without providing a more | |
5719 | convenient way of identifying them. */ | |
5720 | if (lplf->elfLogFont.lfFaceName[0] == '@' | |
5721 | && lpef->logfont.lfFaceName[0] != '@') | |
5e905a57 JR |
5722 | return 1; |
5723 | ||
4587b026 GV |
5724 | /* Check that the character set matches if it was specified */ |
5725 | if (lpef->logfont.lfCharSet != DEFAULT_CHARSET && | |
5726 | lplf->elfLogFont.lfCharSet != lpef->logfont.lfCharSet) | |
5e905a57 | 5727 | return 1; |
4587b026 | 5728 | |
6358474d JR |
5729 | if (FontType == RASTER_FONTTYPE) |
5730 | { | |
5731 | /* DBCS raster fonts have problems displaying, so skip them. */ | |
5732 | int charset = lplf->elfLogFont.lfCharSet; | |
5733 | if (charset == SHIFTJIS_CHARSET | |
5734 | || charset == HANGEUL_CHARSET | |
5735 | || charset == CHINESEBIG5_CHARSET | |
5736 | || charset == GB2312_CHARSET | |
5737 | #ifdef JOHAB_CHARSET | |
5738 | || charset == JOHAB_CHARSET | |
5739 | #endif | |
5740 | ) | |
5741 | return 1; | |
5742 | } | |
5743 | ||
ee78dc32 GV |
5744 | { |
5745 | char buf[100]; | |
4587b026 | 5746 | Lisp_Object width = Qnil; |
d84b082d | 5747 | Lisp_Object charset_list = Qnil; |
767b1ff0 | 5748 | char *charset = NULL; |
ee78dc32 | 5749 | |
6fc2811b JR |
5750 | /* Truetype fonts do not report their true metrics until loaded */ |
5751 | if (FontType != RASTER_FONTTYPE) | |
3cb20f4a | 5752 | { |
23afac8f | 5753 | if (!NILP (lpef->pattern)) |
6fc2811b JR |
5754 | { |
5755 | /* Scalable fonts are as big as you want them to be. */ | |
5756 | lplf->elfLogFont.lfHeight = lpef->logfont.lfHeight; | |
5757 | lplf->elfLogFont.lfWidth = lpef->logfont.lfWidth; | |
5758 | width = make_number (lpef->logfont.lfWidth); | |
5759 | } | |
5760 | else | |
5761 | { | |
5762 | lplf->elfLogFont.lfHeight = 0; | |
5763 | lplf->elfLogFont.lfWidth = 0; | |
5764 | } | |
3cb20f4a | 5765 | } |
6fc2811b | 5766 | |
f46e6225 GV |
5767 | /* Make sure the height used here is the same as everywhere |
5768 | else (ie character height, not cell height). */ | |
6fc2811b JR |
5769 | if (lplf->elfLogFont.lfHeight > 0) |
5770 | { | |
5771 | /* lptm can be trusted for RASTER fonts, but not scalable ones. */ | |
5772 | if (FontType == RASTER_FONTTYPE) | |
5773 | lplf->elfLogFont.lfHeight = lptm->tmInternalLeading - lptm->tmHeight; | |
5774 | else | |
5775 | lplf->elfLogFont.lfHeight = -lplf->elfLogFont.lfHeight; | |
5776 | } | |
4587b026 | 5777 | |
23afac8f | 5778 | if (!NILP (lpef->pattern)) |
767b1ff0 | 5779 | { |
d5db4077 | 5780 | charset = xlfd_charset_of_font (SDATA (lpef->pattern)); |
767b1ff0 | 5781 | |
644cefdf JR |
5782 | /* We already checked charsets above, but DEFAULT_CHARSET |
5783 | slipped through. So only allow exact matches for DEFAULT_CHARSET. */ | |
5784 | if (charset | |
5785 | && strncmp (charset, "*-*", 3) != 0 | |
5786 | && lpef->logfont.lfCharSet == DEFAULT_CHARSET | |
5787 | && strcmp (charset, w32_to_x_charset (DEFAULT_CHARSET)) != 0) | |
5788 | return 1; | |
767b1ff0 JR |
5789 | } |
5790 | ||
d84b082d JR |
5791 | if (charset) |
5792 | charset_list = Fcons (build_string (charset), Qnil); | |
5793 | else | |
5794 | charset_list = w32_to_all_x_charsets (lplf->elfLogFont.lfCharSet); | |
ee78dc32 | 5795 | |
d84b082d JR |
5796 | /* Loop through the charsets. */ |
5797 | for ( ; CONSP (charset_list); charset_list = Fcdr (charset_list)) | |
ee78dc32 | 5798 | { |
d84b082d | 5799 | Lisp_Object this_charset = Fcar (charset_list); |
d5db4077 | 5800 | charset = SDATA (this_charset); |
d84b082d JR |
5801 | |
5802 | /* List bold and italic variations if w32-enable-synthesized-fonts | |
5803 | is non-nil and this is a plain font. */ | |
5804 | if (w32_enable_synthesized_fonts | |
5805 | && lplf->elfLogFont.lfWeight == FW_NORMAL | |
5806 | && lplf->elfLogFont.lfItalic == FALSE) | |
5807 | { | |
5808 | enum_font_maybe_add_to_list (lpef, &(lplf->elfLogFont), | |
5809 | charset, width); | |
5810 | /* bold. */ | |
5811 | lplf->elfLogFont.lfWeight = FW_BOLD; | |
5812 | enum_font_maybe_add_to_list (lpef, &(lplf->elfLogFont), | |
5813 | charset, width); | |
5814 | /* bold italic. */ | |
5815 | lplf->elfLogFont.lfItalic = TRUE; | |
5816 | enum_font_maybe_add_to_list (lpef, &(lplf->elfLogFont), | |
5817 | charset, width); | |
5818 | /* italic. */ | |
5819 | lplf->elfLogFont.lfWeight = FW_NORMAL; | |
5820 | enum_font_maybe_add_to_list (lpef, &(lplf->elfLogFont), | |
5821 | charset, width); | |
5822 | } | |
5823 | else | |
5824 | enum_font_maybe_add_to_list (lpef, &(lplf->elfLogFont), | |
5825 | charset, width); | |
ee78dc32 GV |
5826 | } |
5827 | } | |
6fc2811b | 5828 | |
5e905a57 | 5829 | return 1; |
ee78dc32 GV |
5830 | } |
5831 | ||
d84b082d JR |
5832 | static void |
5833 | enum_font_maybe_add_to_list (lpef, logfont, match_charset, width) | |
5834 | enumfont_t * lpef; | |
5835 | LOGFONT * logfont; | |
5836 | char * match_charset; | |
5837 | Lisp_Object width; | |
5838 | { | |
5839 | char buf[100]; | |
5840 | ||
5841 | if (!w32_to_x_font (logfont, buf, 100, match_charset)) | |
5842 | return; | |
5843 | ||
23afac8f | 5844 | if (NILP (lpef->pattern) |
d5db4077 | 5845 | || w32_font_match (buf, SDATA (lpef->pattern))) |
d84b082d JR |
5846 | { |
5847 | /* Check if we already listed this font. This may happen if | |
5848 | w32_enable_synthesized_fonts is non-nil, and there are real | |
5849 | bold and italic versions of the font. */ | |
5850 | Lisp_Object font_name = build_string (buf); | |
5851 | if (NILP (Fmember (font_name, lpef->list))) | |
5852 | { | |
23afac8f JR |
5853 | Lisp_Object entry = Fcons (font_name, width); |
5854 | lpef->list = Fcons (entry, lpef->list); | |
d84b082d JR |
5855 | lpef->numFonts++; |
5856 | } | |
5857 | } | |
5858 | } | |
5859 | ||
5860 | ||
7d0393cf | 5861 | static int CALLBACK |
ee78dc32 GV |
5862 | enum_font_cb1 (lplf, lptm, FontType, lpef) |
5863 | ENUMLOGFONT * lplf; | |
5864 | NEWTEXTMETRIC * lptm; | |
5865 | int FontType; | |
5866 | enumfont_t * lpef; | |
5867 | { | |
5868 | return EnumFontFamilies (lpef->hdc, | |
5869 | lplf->elfLogFont.lfFaceName, | |
5870 | (FONTENUMPROC) enum_font_cb2, | |
5871 | (LPARAM) lpef); | |
5872 | } | |
5873 | ||
5874 | ||
8edb0a6f | 5875 | static int CALLBACK |
5ca0cd71 GV |
5876 | enum_fontex_cb2 (lplf, lptm, font_type, lpef) |
5877 | ENUMLOGFONTEX * lplf; | |
5878 | NEWTEXTMETRICEX * lptm; | |
5879 | int font_type; | |
5880 | enumfont_t * lpef; | |
5881 | { | |
5882 | /* We are not interested in the extra info we get back from the 'Ex | |
5883 | version - only the fact that we get character set variations | |
5884 | enumerated seperately. */ | |
5885 | return enum_font_cb2 ((ENUMLOGFONT *) lplf, (NEWTEXTMETRIC *) lptm, | |
5886 | font_type, lpef); | |
5887 | } | |
5888 | ||
8edb0a6f | 5889 | static int CALLBACK |
5ca0cd71 GV |
5890 | enum_fontex_cb1 (lplf, lptm, font_type, lpef) |
5891 | ENUMLOGFONTEX * lplf; | |
5892 | NEWTEXTMETRICEX * lptm; | |
5893 | int font_type; | |
5894 | enumfont_t * lpef; | |
5895 | { | |
5896 | HMODULE gdi32 = GetModuleHandle ("gdi32.dll"); | |
5897 | FARPROC enum_font_families_ex | |
5898 | = GetProcAddress ( gdi32, "EnumFontFamiliesExA"); | |
5899 | /* We don't really expect EnumFontFamiliesEx to disappear once we | |
5900 | get here, so don't bother handling it gracefully. */ | |
5901 | if (enum_font_families_ex == NULL) | |
5902 | error ("gdi32.dll has disappeared!"); | |
5903 | return enum_font_families_ex (lpef->hdc, | |
5904 | &lplf->elfLogFont, | |
5905 | (FONTENUMPROC) enum_fontex_cb2, | |
5906 | (LPARAM) lpef, 0); | |
5907 | } | |
5908 | ||
4587b026 GV |
5909 | /* Interface to fontset handler. (adapted from mw32font.c in Meadow |
5910 | and xterm.c in Emacs 20.3) */ | |
5911 | ||
8edb0a6f | 5912 | static Lisp_Object w32_list_bdf_fonts (Lisp_Object pattern, int max_names) |
33d52f9c GV |
5913 | { |
5914 | char *fontname, *ptnstr; | |
5915 | Lisp_Object list, tem, newlist = Qnil; | |
55dcfc15 | 5916 | int n_fonts = 0; |
33d52f9c GV |
5917 | |
5918 | list = Vw32_bdf_filename_alist; | |
d5db4077 | 5919 | ptnstr = SDATA (pattern); |
33d52f9c | 5920 | |
8e713be6 | 5921 | for ( ; CONSP (list); list = XCDR (list)) |
33d52f9c | 5922 | { |
8e713be6 | 5923 | tem = XCAR (list); |
33d52f9c | 5924 | if (CONSP (tem)) |
d5db4077 | 5925 | fontname = SDATA (XCAR (tem)); |
33d52f9c | 5926 | else if (STRINGP (tem)) |
d5db4077 | 5927 | fontname = SDATA (tem); |
33d52f9c GV |
5928 | else |
5929 | continue; | |
5930 | ||
5931 | if (w32_font_match (fontname, ptnstr)) | |
5ca0cd71 | 5932 | { |
8e713be6 | 5933 | newlist = Fcons (XCAR (tem), newlist); |
5ca0cd71 | 5934 | n_fonts++; |
bd11cc09 | 5935 | if (max_names >= 0 && n_fonts >= max_names) |
5ca0cd71 GV |
5936 | break; |
5937 | } | |
33d52f9c GV |
5938 | } |
5939 | ||
5940 | return newlist; | |
5941 | } | |
5942 | ||
5ca0cd71 | 5943 | |
4587b026 GV |
5944 | /* Return a list of names of available fonts matching PATTERN on frame |
5945 | F. If SIZE is not 0, it is the size (maximum bound width) of fonts | |
5946 | to be listed. Frame F NULL means we have not yet created any | |
5947 | frame, which means we can't get proper size info, as we don't have | |
5948 | a device context to use for GetTextMetrics. | |
bd11cc09 JR |
5949 | MAXNAMES sets a limit on how many fonts to match. If MAXNAMES is |
5950 | negative, then all matching fonts are returned. */ | |
4587b026 GV |
5951 | |
5952 | Lisp_Object | |
dc220243 JR |
5953 | w32_list_fonts (f, pattern, size, maxnames) |
5954 | struct frame *f; | |
5955 | Lisp_Object pattern; | |
5956 | int size; | |
5957 | int maxnames; | |
4587b026 | 5958 | { |
6fc2811b | 5959 | Lisp_Object patterns, key = Qnil, tem, tpat; |
4587b026 | 5960 | Lisp_Object list = Qnil, newlist = Qnil, second_best = Qnil; |
33d52f9c | 5961 | struct w32_display_info *dpyinfo = &one_w32_display_info; |
5ca0cd71 | 5962 | int n_fonts = 0; |
396594fe | 5963 | |
4587b026 GV |
5964 | patterns = Fassoc (pattern, Valternate_fontname_alist); |
5965 | if (NILP (patterns)) | |
5966 | patterns = Fcons (pattern, Qnil); | |
5967 | ||
8e713be6 | 5968 | for (; CONSP (patterns); patterns = XCDR (patterns)) |
4587b026 GV |
5969 | { |
5970 | enumfont_t ef; | |
767b1ff0 | 5971 | int codepage; |
4587b026 | 5972 | |
8e713be6 | 5973 | tpat = XCAR (patterns); |
4587b026 | 5974 | |
767b1ff0 JR |
5975 | if (!STRINGP (tpat)) |
5976 | continue; | |
5977 | ||
5978 | /* Avoid expensive EnumFontFamilies functions if we are not | |
5979 | going to be able to output one of these anyway. */ | |
d5db4077 | 5980 | codepage = w32_codepage_for_font (SDATA (tpat)); |
767b1ff0 | 5981 | if (codepage != CP_8BIT && codepage != CP_UNICODE |
ceb12877 AI |
5982 | && codepage != CP_DEFAULT && codepage != CP_UNKNOWN |
5983 | && !IsValidCodePage(codepage)) | |
767b1ff0 JR |
5984 | continue; |
5985 | ||
4587b026 GV |
5986 | /* See if we cached the result for this particular query. |
5987 | The cache is an alist of the form: | |
5988 | ((PATTERN (FONTNAME . WIDTH) ...) ...) | |
5989 | */ | |
8e713be6 | 5990 | if (tem = XCDR (dpyinfo->name_list_element), |
33d52f9c | 5991 | !NILP (list = Fassoc (tpat, tem))) |
4587b026 GV |
5992 | { |
5993 | list = Fcdr_safe (list); | |
5994 | /* We have a cached list. Don't have to get the list again. */ | |
5995 | goto label_cached; | |
5996 | } | |
5997 | ||
5998 | BLOCK_INPUT; | |
5999 | /* At first, put PATTERN in the cache. */ | |
23afac8f JR |
6000 | ef.pattern = tpat; |
6001 | ef.list = Qnil; | |
4587b026 | 6002 | ef.numFonts = 0; |
33d52f9c | 6003 | |
5ca0cd71 GV |
6004 | /* Use EnumFontFamiliesEx where it is available, as it knows |
6005 | about character sets. Fall back to EnumFontFamilies for | |
6006 | older versions of NT that don't support the 'Ex function. */ | |
d5db4077 | 6007 | x_to_w32_font (SDATA (tpat), &ef.logfont); |
4587b026 | 6008 | { |
5ca0cd71 GV |
6009 | LOGFONT font_match_pattern; |
6010 | HMODULE gdi32 = GetModuleHandle ("gdi32.dll"); | |
6011 | FARPROC enum_font_families_ex | |
6012 | = GetProcAddress ( gdi32, "EnumFontFamiliesExA"); | |
6013 | ||
6014 | /* We do our own pattern matching so we can handle wildcards. */ | |
6015 | font_match_pattern.lfFaceName[0] = 0; | |
6016 | font_match_pattern.lfPitchAndFamily = 0; | |
6017 | /* We can use the charset, because if it is a wildcard it will | |
6018 | be DEFAULT_CHARSET anyway. */ | |
6019 | font_match_pattern.lfCharSet = ef.logfont.lfCharSet; | |
6020 | ||
33d52f9c | 6021 | ef.hdc = GetDC (dpyinfo->root_window); |
4587b026 | 6022 | |
5ca0cd71 GV |
6023 | if (enum_font_families_ex) |
6024 | enum_font_families_ex (ef.hdc, | |
6025 | &font_match_pattern, | |
6026 | (FONTENUMPROC) enum_fontex_cb1, | |
6027 | (LPARAM) &ef, 0); | |
6028 | else | |
6029 | EnumFontFamilies (ef.hdc, NULL, (FONTENUMPROC) enum_font_cb1, | |
6030 | (LPARAM)&ef); | |
4587b026 | 6031 | |
33d52f9c | 6032 | ReleaseDC (dpyinfo->root_window, ef.hdc); |
4587b026 GV |
6033 | } |
6034 | ||
6035 | UNBLOCK_INPUT; | |
23afac8f | 6036 | list = ef.list; |
4587b026 GV |
6037 | |
6038 | /* Make a list of the fonts we got back. | |
6039 | Store that in the font cache for the display. */ | |
f3fbd155 KR |
6040 | XSETCDR (dpyinfo->name_list_element, |
6041 | Fcons (Fcons (tpat, list), | |
6042 | XCDR (dpyinfo->name_list_element))); | |
4587b026 GV |
6043 | |
6044 | label_cached: | |
6045 | if (NILP (list)) continue; /* Try the remaining alternatives. */ | |
6046 | ||
6047 | newlist = second_best = Qnil; | |
6048 | ||
7d0393cf | 6049 | /* Make a list of the fonts that have the right width. */ |
8e713be6 | 6050 | for (; CONSP (list); list = XCDR (list)) |
4587b026 GV |
6051 | { |
6052 | int found_size; | |
8e713be6 | 6053 | tem = XCAR (list); |
4587b026 GV |
6054 | |
6055 | if (!CONSP (tem)) | |
6056 | continue; | |
8e713be6 | 6057 | if (NILP (XCAR (tem))) |
4587b026 GV |
6058 | continue; |
6059 | if (!size) | |
6060 | { | |
8e713be6 | 6061 | newlist = Fcons (XCAR (tem), newlist); |
5ca0cd71 | 6062 | n_fonts++; |
bd11cc09 | 6063 | if (maxnames >= 0 && n_fonts >= maxnames) |
5ca0cd71 GV |
6064 | break; |
6065 | else | |
6066 | continue; | |
4587b026 | 6067 | } |
8e713be6 | 6068 | if (!INTEGERP (XCDR (tem))) |
4587b026 GV |
6069 | { |
6070 | /* Since we don't yet know the size of the font, we must | |
6071 | load it and try GetTextMetrics. */ | |
4587b026 GV |
6072 | W32FontStruct thisinfo; |
6073 | LOGFONT lf; | |
6074 | HDC hdc; | |
6075 | HANDLE oldobj; | |
6076 | ||
d5db4077 | 6077 | if (!x_to_w32_font (SDATA (XCAR (tem)), &lf)) |
4587b026 GV |
6078 | continue; |
6079 | ||
6080 | BLOCK_INPUT; | |
33d52f9c | 6081 | thisinfo.bdf = NULL; |
4587b026 GV |
6082 | thisinfo.hfont = CreateFontIndirect (&lf); |
6083 | if (thisinfo.hfont == NULL) | |
6084 | continue; | |
6085 | ||
6086 | hdc = GetDC (dpyinfo->root_window); | |
6087 | oldobj = SelectObject (hdc, thisinfo.hfont); | |
6088 | if (GetTextMetrics (hdc, &thisinfo.tm)) | |
f3fbd155 | 6089 | XSETCDR (tem, make_number (FONT_WIDTH (&thisinfo))); |
4587b026 | 6090 | else |
f3fbd155 | 6091 | XSETCDR (tem, make_number (0)); |
4587b026 GV |
6092 | SelectObject (hdc, oldobj); |
6093 | ReleaseDC (dpyinfo->root_window, hdc); | |
6094 | DeleteObject(thisinfo.hfont); | |
6095 | UNBLOCK_INPUT; | |
6096 | } | |
8e713be6 | 6097 | found_size = XINT (XCDR (tem)); |
4587b026 | 6098 | if (found_size == size) |
5ca0cd71 | 6099 | { |
8e713be6 | 6100 | newlist = Fcons (XCAR (tem), newlist); |
5ca0cd71 | 6101 | n_fonts++; |
bd11cc09 | 6102 | if (maxnames >= 0 && n_fonts >= maxnames) |
5ca0cd71 GV |
6103 | break; |
6104 | } | |
4587b026 GV |
6105 | /* keep track of the closest matching size in case |
6106 | no exact match is found. */ | |
6107 | else if (found_size > 0) | |
6108 | { | |
6109 | if (NILP (second_best)) | |
6110 | second_best = tem; | |
7d0393cf | 6111 | |
4587b026 GV |
6112 | else if (found_size < size) |
6113 | { | |
8e713be6 KR |
6114 | if (XINT (XCDR (second_best)) > size |
6115 | || XINT (XCDR (second_best)) < found_size) | |
4587b026 GV |
6116 | second_best = tem; |
6117 | } | |
6118 | else | |
6119 | { | |
8e713be6 KR |
6120 | if (XINT (XCDR (second_best)) > size |
6121 | && XINT (XCDR (second_best)) > | |
4587b026 GV |
6122 | found_size) |
6123 | second_best = tem; | |
6124 | } | |
6125 | } | |
6126 | } | |
6127 | ||
6128 | if (!NILP (newlist)) | |
6129 | break; | |
6130 | else if (!NILP (second_best)) | |
6131 | { | |
8e713be6 | 6132 | newlist = Fcons (XCAR (second_best), Qnil); |
4587b026 GV |
6133 | break; |
6134 | } | |
6135 | } | |
6136 | ||
33d52f9c | 6137 | /* Include any bdf fonts. */ |
bd11cc09 | 6138 | if (n_fonts < maxnames || maxnames < 0) |
33d52f9c GV |
6139 | { |
6140 | Lisp_Object combined[2]; | |
5ca0cd71 | 6141 | combined[0] = w32_list_bdf_fonts (pattern, maxnames - n_fonts); |
33d52f9c GV |
6142 | combined[1] = newlist; |
6143 | newlist = Fnconc(2, combined); | |
6144 | } | |
6145 | ||
4587b026 GV |
6146 | return newlist; |
6147 | } | |
6148 | ||
5ca0cd71 | 6149 | |
4587b026 GV |
6150 | /* Return a pointer to struct font_info of font FONT_IDX of frame F. */ |
6151 | struct font_info * | |
6152 | w32_get_font_info (f, font_idx) | |
6153 | FRAME_PTR f; | |
6154 | int font_idx; | |
6155 | { | |
6156 | return (FRAME_W32_FONT_TABLE (f) + font_idx); | |
6157 | } | |
6158 | ||
6159 | ||
6160 | struct font_info* | |
6161 | w32_query_font (struct frame *f, char *fontname) | |
6162 | { | |
6163 | int i; | |
6164 | struct font_info *pfi; | |
6165 | ||
6166 | pfi = FRAME_W32_FONT_TABLE (f); | |
6167 | ||
6168 | for (i = 0; i < one_w32_display_info.n_fonts ;i++, pfi++) | |
6169 | { | |
6170 | if (strcmp(pfi->name, fontname) == 0) return pfi; | |
6171 | } | |
6172 | ||
6173 | return NULL; | |
6174 | } | |
6175 | ||
6176 | /* Find a CCL program for a font specified by FONTP, and set the member | |
6177 | `encoder' of the structure. */ | |
6178 | ||
6179 | void | |
6180 | w32_find_ccl_program (fontp) | |
6181 | struct font_info *fontp; | |
6182 | { | |
3545439c | 6183 | Lisp_Object list, elt; |
4587b026 | 6184 | |
8e713be6 | 6185 | for (list = Vfont_ccl_encoder_alist; CONSP (list); list = XCDR (list)) |
4587b026 | 6186 | { |
8e713be6 | 6187 | elt = XCAR (list); |
4587b026 | 6188 | if (CONSP (elt) |
8e713be6 KR |
6189 | && STRINGP (XCAR (elt)) |
6190 | && (fast_c_string_match_ignore_case (XCAR (elt), fontp->name) | |
4587b026 | 6191 | >= 0)) |
3545439c KH |
6192 | break; |
6193 | } | |
6194 | if (! NILP (list)) | |
6195 | { | |
17eedd00 KH |
6196 | struct ccl_program *ccl |
6197 | = (struct ccl_program *) xmalloc (sizeof (struct ccl_program)); | |
3545439c | 6198 | |
8e713be6 | 6199 | if (setup_ccl_program (ccl, XCDR (elt)) < 0) |
3545439c KH |
6200 | xfree (ccl); |
6201 | else | |
6202 | fontp->font_encoder = ccl; | |
4587b026 GV |
6203 | } |
6204 | } | |
6205 | ||
2ba49441 JR |
6206 | /* directory-files from dired.c. */ |
6207 | Lisp_Object Fdirectory_files P_((Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)); | |
6208 | ||
4587b026 | 6209 | \f |
8edb0a6f JR |
6210 | /* Find BDF files in a specified directory. (use GCPRO when calling, |
6211 | as this calls lisp to get a directory listing). */ | |
6212 | static Lisp_Object | |
6213 | w32_find_bdf_fonts_in_dir (Lisp_Object directory) | |
6214 | { | |
6215 | Lisp_Object filelist, list = Qnil; | |
6216 | char fontname[100]; | |
6217 | ||
6218 | if (!STRINGP(directory)) | |
6219 | return Qnil; | |
6220 | ||
6221 | filelist = Fdirectory_files (directory, Qt, | |
2ba49441 | 6222 | build_string (".*\\.[bB][dD][fF]"), Qt); |
8edb0a6f JR |
6223 | |
6224 | for ( ; CONSP(filelist); filelist = XCDR (filelist)) | |
6225 | { | |
6226 | Lisp_Object filename = XCAR (filelist); | |
d5db4077 | 6227 | if (w32_BDF_to_x_font (SDATA (filename), fontname, 100)) |
8edb0a6f JR |
6228 | store_in_alist (&list, build_string (fontname), filename); |
6229 | } | |
6230 | return list; | |
6231 | } | |
6232 | ||
6fc2811b JR |
6233 | DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts, Sw32_find_bdf_fonts, |
6234 | 1, 1, 0, | |
52deb19f JB |
6235 | doc: /* Return a list of BDF fonts in DIRECTORY. |
6236 | The list is suitable for appending to `w32-bdf-filename-alist'. | |
6237 | Fonts which do not contain an xlfd description will not be included | |
6238 | in the list. DIRECTORY may be a list of directories. */) | |
6fc2811b JR |
6239 | (directory) |
6240 | Lisp_Object directory; | |
6241 | { | |
6242 | Lisp_Object list = Qnil; | |
6243 | struct gcpro gcpro1, gcpro2; | |
ee78dc32 | 6244 | |
6fc2811b JR |
6245 | if (!CONSP (directory)) |
6246 | return w32_find_bdf_fonts_in_dir (directory); | |
ee78dc32 | 6247 | |
6fc2811b | 6248 | for ( ; CONSP (directory); directory = XCDR (directory)) |
ee78dc32 | 6249 | { |
6fc2811b JR |
6250 | Lisp_Object pair[2]; |
6251 | pair[0] = list; | |
6252 | pair[1] = Qnil; | |
6253 | GCPRO2 (directory, list); | |
6254 | pair[1] = w32_find_bdf_fonts_in_dir( XCAR (directory) ); | |
6255 | list = Fnconc( 2, pair ); | |
6256 | UNGCPRO; | |
6257 | } | |
6258 | return list; | |
6259 | } | |
ee78dc32 | 6260 | |
6fc2811b JR |
6261 | \f |
6262 | DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0, | |
74e1aeec | 6263 | doc: /* Internal function called by `color-defined-p', which see. */) |
6fc2811b JR |
6264 | (color, frame) |
6265 | Lisp_Object color, frame; | |
6266 | { | |
6267 | XColor foo; | |
6268 | FRAME_PTR f = check_x_frame (frame); | |
ee78dc32 | 6269 | |
b7826503 | 6270 | CHECK_STRING (color); |
ee78dc32 | 6271 | |
d5db4077 | 6272 | if (w32_defined_color (f, SDATA (color), &foo, 0)) |
6fc2811b JR |
6273 | return Qt; |
6274 | else | |
6275 | return Qnil; | |
6276 | } | |
ee78dc32 | 6277 | |
2d764c78 | 6278 | DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0, |
74e1aeec | 6279 | doc: /* Internal function called by `color-values', which see. */) |
ee78dc32 GV |
6280 | (color, frame) |
6281 | Lisp_Object color, frame; | |
6282 | { | |
6fc2811b | 6283 | XColor foo; |
ee78dc32 GV |
6284 | FRAME_PTR f = check_x_frame (frame); |
6285 | ||
b7826503 | 6286 | CHECK_STRING (color); |
ee78dc32 | 6287 | |
d5db4077 | 6288 | if (w32_defined_color (f, SDATA (color), &foo, 0)) |
ee78dc32 GV |
6289 | { |
6290 | Lisp_Object rgb[3]; | |
6291 | ||
6fc2811b JR |
6292 | rgb[0] = make_number ((GetRValue (foo.pixel) << 8) |
6293 | | GetRValue (foo.pixel)); | |
6294 | rgb[1] = make_number ((GetGValue (foo.pixel) << 8) | |
6295 | | GetGValue (foo.pixel)); | |
6296 | rgb[2] = make_number ((GetBValue (foo.pixel) << 8) | |
6297 | | GetBValue (foo.pixel)); | |
ee78dc32 GV |
6298 | return Flist (3, rgb); |
6299 | } | |
6300 | else | |
6301 | return Qnil; | |
6302 | } | |
6303 | ||
2d764c78 | 6304 | DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0, |
74e1aeec | 6305 | doc: /* Internal function called by `display-color-p', which see. */) |
ee78dc32 GV |
6306 | (display) |
6307 | Lisp_Object display; | |
6308 | { | |
fbd6baed | 6309 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 GV |
6310 | |
6311 | if ((dpyinfo->n_planes * dpyinfo->n_cbits) <= 2) | |
6312 | return Qnil; | |
6313 | ||
6314 | return Qt; | |
6315 | } | |
6316 | ||
74e1aeec JR |
6317 | DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, |
6318 | Sx_display_grayscale_p, 0, 1, 0, | |
52deb19f | 6319 | doc: /* Return t if DISPLAY supports shades of gray. |
74e1aeec JR |
6320 | Note that color displays do support shades of gray. |
6321 | The optional argument DISPLAY specifies which display to ask about. | |
6322 | DISPLAY should be either a frame or a display name (a string). | |
6323 | If omitted or nil, that stands for the selected frame's display. */) | |
ee78dc32 GV |
6324 | (display) |
6325 | Lisp_Object display; | |
6326 | { | |
fbd6baed | 6327 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 GV |
6328 | |
6329 | if ((dpyinfo->n_planes * dpyinfo->n_cbits) <= 1) | |
6330 | return Qnil; | |
6331 | ||
6332 | return Qt; | |
6333 | } | |
6334 | ||
74e1aeec JR |
6335 | DEFUN ("x-display-pixel-width", Fx_display_pixel_width, |
6336 | Sx_display_pixel_width, 0, 1, 0, | |
6337 | doc: /* Returns the width in pixels of DISPLAY. | |
6338 | The optional argument DISPLAY specifies which display to ask about. | |
6339 | DISPLAY should be either a frame or a display name (a string). | |
6340 | If omitted or nil, that stands for the selected frame's display. */) | |
ee78dc32 GV |
6341 | (display) |
6342 | Lisp_Object display; | |
6343 | { | |
fbd6baed | 6344 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 GV |
6345 | |
6346 | return make_number (dpyinfo->width); | |
6347 | } | |
6348 | ||
6349 | DEFUN ("x-display-pixel-height", Fx_display_pixel_height, | |
74e1aeec JR |
6350 | Sx_display_pixel_height, 0, 1, 0, |
6351 | doc: /* Returns the height in pixels of DISPLAY. | |
6352 | The optional argument DISPLAY specifies which display to ask about. | |
6353 | DISPLAY should be either a frame or a display name (a string). | |
6354 | If omitted or nil, that stands for the selected frame's display. */) | |
ee78dc32 GV |
6355 | (display) |
6356 | Lisp_Object display; | |
6357 | { | |
fbd6baed | 6358 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 GV |
6359 | |
6360 | return make_number (dpyinfo->height); | |
6361 | } | |
6362 | ||
6363 | DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes, | |
74e1aeec JR |
6364 | 0, 1, 0, |
6365 | doc: /* Returns the number of bitplanes of DISPLAY. | |
6366 | The optional argument DISPLAY specifies which display to ask about. | |
6367 | DISPLAY should be either a frame or a display name (a string). | |
6368 | If omitted or nil, that stands for the selected frame's display. */) | |
ee78dc32 GV |
6369 | (display) |
6370 | Lisp_Object display; | |
6371 | { | |
fbd6baed | 6372 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 GV |
6373 | |
6374 | return make_number (dpyinfo->n_planes * dpyinfo->n_cbits); | |
6375 | } | |
6376 | ||
6377 | DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells, | |
74e1aeec JR |
6378 | 0, 1, 0, |
6379 | doc: /* Returns the number of color cells of DISPLAY. | |
6380 | The optional argument DISPLAY specifies which display to ask about. | |
6381 | DISPLAY should be either a frame or a display name (a string). | |
6382 | If omitted or nil, that stands for the selected frame's display. */) | |
ee78dc32 GV |
6383 | (display) |
6384 | Lisp_Object display; | |
6385 | { | |
fbd6baed | 6386 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 GV |
6387 | HDC hdc; |
6388 | int cap; | |
6389 | ||
5ac45f98 GV |
6390 | hdc = GetDC (dpyinfo->root_window); |
6391 | if (dpyinfo->has_palette) | |
52deb19f | 6392 | cap = GetDeviceCaps (hdc, SIZEPALETTE); |
5ac45f98 | 6393 | else |
52deb19f | 6394 | cap = GetDeviceCaps (hdc, NUMCOLORS); |
abf8c61b | 6395 | |
007776bc JB |
6396 | /* We force 24+ bit depths to 24-bit, both to prevent an overflow |
6397 | and because probably is more meaningful on Windows anyway */ | |
abf8c61b | 6398 | if (cap < 0) |
007776bc | 6399 | cap = 1 << min(dpyinfo->n_planes * dpyinfo->n_cbits, 24); |
7d0393cf | 6400 | |
ee78dc32 | 6401 | ReleaseDC (dpyinfo->root_window, hdc); |
7d0393cf | 6402 | |
ee78dc32 GV |
6403 | return make_number (cap); |
6404 | } | |
6405 | ||
6406 | DEFUN ("x-server-max-request-size", Fx_server_max_request_size, | |
6407 | Sx_server_max_request_size, | |
74e1aeec JR |
6408 | 0, 1, 0, |
6409 | doc: /* Returns the maximum request size of the server of DISPLAY. | |
6410 | The optional argument DISPLAY specifies which display to ask about. | |
6411 | DISPLAY should be either a frame or a display name (a string). | |
6412 | If omitted or nil, that stands for the selected frame's display. */) | |
ee78dc32 GV |
6413 | (display) |
6414 | Lisp_Object display; | |
6415 | { | |
fbd6baed | 6416 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 GV |
6417 | |
6418 | return make_number (1); | |
6419 | } | |
6420 | ||
6421 | DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0, | |
95d62d8a | 6422 | doc: /* Returns the "vendor ID" string of the W32 system (Microsoft). |
74e1aeec JR |
6423 | The optional argument DISPLAY specifies which display to ask about. |
6424 | DISPLAY should be either a frame or a display name (a string). | |
6425 | If omitted or nil, that stands for the selected frame's display. */) | |
ee78dc32 GV |
6426 | (display) |
6427 | Lisp_Object display; | |
6428 | { | |
dfff8a69 | 6429 | return build_string ("Microsoft Corp."); |
ee78dc32 GV |
6430 | } |
6431 | ||
6432 | DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0, | |
74e1aeec JR |
6433 | doc: /* Returns the version numbers of the server of DISPLAY. |
6434 | The value is a list of three integers: the major and minor | |
95d62d8a | 6435 | version numbers of the X Protocol in use, and the distributor-specific release |
74e1aeec JR |
6436 | number. See also the function `x-server-vendor'. |
6437 | ||
6438 | The optional argument DISPLAY specifies which display to ask about. | |
6439 | DISPLAY should be either a frame or a display name (a string). | |
6440 | If omitted or nil, that stands for the selected frame's display. */) | |
ee78dc32 GV |
6441 | (display) |
6442 | Lisp_Object display; | |
6443 | { | |
fbd6baed | 6444 | return Fcons (make_number (w32_major_version), |
58e0f0e4 AI |
6445 | Fcons (make_number (w32_minor_version), |
6446 | Fcons (make_number (w32_build_number), Qnil))); | |
ee78dc32 GV |
6447 | } |
6448 | ||
6449 | DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0, | |
74e1aeec JR |
6450 | doc: /* Returns the number of screens on the server of DISPLAY. |
6451 | The optional argument DISPLAY specifies which display to ask about. | |
6452 | DISPLAY should be either a frame or a display name (a string). | |
6453 | If omitted or nil, that stands for the selected frame's display. */) | |
ee78dc32 GV |
6454 | (display) |
6455 | Lisp_Object display; | |
6456 | { | |
ee78dc32 GV |
6457 | return make_number (1); |
6458 | } | |
6459 | ||
74e1aeec JR |
6460 | DEFUN ("x-display-mm-height", Fx_display_mm_height, |
6461 | Sx_display_mm_height, 0, 1, 0, | |
6462 | doc: /* Returns the height in millimeters of DISPLAY. | |
6463 | The optional argument DISPLAY specifies which display to ask about. | |
6464 | DISPLAY should be either a frame or a display name (a string). | |
6465 | If omitted or nil, that stands for the selected frame's display. */) | |
ee78dc32 GV |
6466 | (display) |
6467 | Lisp_Object display; | |
6468 | { | |
fbd6baed | 6469 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 GV |
6470 | HDC hdc; |
6471 | int cap; | |
6472 | ||
5ac45f98 | 6473 | hdc = GetDC (dpyinfo->root_window); |
7d0393cf | 6474 | |
ee78dc32 | 6475 | cap = GetDeviceCaps (hdc, VERTSIZE); |
7d0393cf | 6476 | |
ee78dc32 | 6477 | ReleaseDC (dpyinfo->root_window, hdc); |
7d0393cf | 6478 | |
ee78dc32 GV |
6479 | return make_number (cap); |
6480 | } | |
6481 | ||
6482 | DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0, | |
74e1aeec JR |
6483 | doc: /* Returns the width in millimeters of DISPLAY. |
6484 | The optional argument DISPLAY specifies which display to ask about. | |
6485 | DISPLAY should be either a frame or a display name (a string). | |
6486 | If omitted or nil, that stands for the selected frame's display. */) | |
ee78dc32 GV |
6487 | (display) |
6488 | Lisp_Object display; | |
6489 | { | |
fbd6baed | 6490 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
ee78dc32 GV |
6491 | |
6492 | HDC hdc; | |
6493 | int cap; | |
6494 | ||
5ac45f98 | 6495 | hdc = GetDC (dpyinfo->root_window); |
7d0393cf | 6496 | |
ee78dc32 | 6497 | cap = GetDeviceCaps (hdc, HORZSIZE); |
7d0393cf | 6498 | |
ee78dc32 | 6499 | ReleaseDC (dpyinfo->root_window, hdc); |
7d0393cf | 6500 | |
ee78dc32 GV |
6501 | return make_number (cap); |
6502 | } | |
6503 | ||
6504 | DEFUN ("x-display-backing-store", Fx_display_backing_store, | |
74e1aeec JR |
6505 | Sx_display_backing_store, 0, 1, 0, |
6506 | doc: /* Returns an indication of whether DISPLAY does backing store. | |
6507 | The value may be `always', `when-mapped', or `not-useful'. | |
6508 | The optional argument DISPLAY specifies which display to ask about. | |
6509 | DISPLAY should be either a frame or a display name (a string). | |
6510 | If omitted or nil, that stands for the selected frame's display. */) | |
ee78dc32 GV |
6511 | (display) |
6512 | Lisp_Object display; | |
6513 | { | |
6514 | return intern ("not-useful"); | |
6515 | } | |
6516 | ||
6517 | DEFUN ("x-display-visual-class", Fx_display_visual_class, | |
74e1aeec JR |
6518 | Sx_display_visual_class, 0, 1, 0, |
6519 | doc: /* Returns the visual class of DISPLAY. | |
6520 | The value is one of the symbols `static-gray', `gray-scale', | |
6521 | `static-color', `pseudo-color', `true-color', or `direct-color'. | |
6522 | ||
6523 | The optional argument DISPLAY specifies which display to ask about. | |
6524 | DISPLAY should be either a frame or a display name (a string). | |
6525 | If omitted or nil, that stands for the selected frame's display. */) | |
ee78dc32 GV |
6526 | (display) |
6527 | Lisp_Object display; | |
6528 | { | |
fbd6baed | 6529 | struct w32_display_info *dpyinfo = check_x_display_info (display); |
abf8c61b | 6530 | Lisp_Object result = Qnil; |
ee78dc32 | 6531 | |
abf8c61b AI |
6532 | if (dpyinfo->has_palette) |
6533 | result = intern ("pseudo-color"); | |
6534 | else if (dpyinfo->n_planes * dpyinfo->n_cbits == 1) | |
6535 | result = intern ("static-grey"); | |
6536 | else if (dpyinfo->n_planes * dpyinfo->n_cbits == 4) | |
6537 | result = intern ("static-color"); | |
6538 | else if (dpyinfo->n_planes * dpyinfo->n_cbits > 8) | |
6539 | result = intern ("true-color"); | |
ee78dc32 | 6540 | |
abf8c61b | 6541 | return result; |
ee78dc32 GV |
6542 | } |
6543 | ||
6544 | DEFUN ("x-display-save-under", Fx_display_save_under, | |
74e1aeec JR |
6545 | Sx_display_save_under, 0, 1, 0, |
6546 | doc: /* Returns t if DISPLAY supports the save-under feature. | |
6547 | The optional argument DISPLAY specifies which display to ask about. | |
6548 | DISPLAY should be either a frame or a display name (a string). | |
6549 | If omitted or nil, that stands for the selected frame's display. */) | |
ee78dc32 GV |
6550 | (display) |
6551 | Lisp_Object display; | |
6552 | { | |
6fc2811b JR |
6553 | return Qnil; |
6554 | } | |
6555 | \f | |
6556 | int | |
6557 | x_pixel_width (f) | |
6558 | register struct frame *f; | |
6559 | { | |
be786000 | 6560 | return FRAME_PIXEL_WIDTH (f); |
6fc2811b JR |
6561 | } |
6562 | ||
6563 | int | |
6564 | x_pixel_height (f) | |
6565 | register struct frame *f; | |
6566 | { | |
be786000 | 6567 | return FRAME_PIXEL_HEIGHT (f); |
6fc2811b JR |
6568 | } |
6569 | ||
6570 | int | |
6571 | x_char_width (f) | |
6572 | register struct frame *f; | |
6573 | { | |
be786000 | 6574 | return FRAME_COLUMN_WIDTH (f); |
6fc2811b JR |
6575 | } |
6576 | ||
6577 | int | |
6578 | x_char_height (f) | |
6579 | register struct frame *f; | |
6580 | { | |
be786000 | 6581 | return FRAME_LINE_HEIGHT (f); |
6fc2811b JR |
6582 | } |
6583 | ||
6584 | int | |
6585 | x_screen_planes (f) | |
6586 | register struct frame *f; | |
6587 | { | |
6588 | return FRAME_W32_DISPLAY_INFO (f)->n_planes; | |
6589 | } | |
6590 | \f | |
6591 | /* Return the display structure for the display named NAME. | |
6592 | Open a new connection if necessary. */ | |
6593 | ||
6594 | struct w32_display_info * | |
6595 | x_display_info_for_name (name) | |
6596 | Lisp_Object name; | |
6597 | { | |
6598 | Lisp_Object names; | |
6599 | struct w32_display_info *dpyinfo; | |
6600 | ||
b7826503 | 6601 | CHECK_STRING (name); |
6fc2811b JR |
6602 | |
6603 | for (dpyinfo = &one_w32_display_info, names = w32_display_name_list; | |
6604 | dpyinfo; | |
6605 | dpyinfo = dpyinfo->next, names = XCDR (names)) | |
6606 | { | |
6607 | Lisp_Object tem; | |
6608 | tem = Fstring_equal (XCAR (XCAR (names)), name); | |
6609 | if (!NILP (tem)) | |
6610 | return dpyinfo; | |
6611 | } | |
6612 | ||
6613 | /* Use this general default value to start with. */ | |
6614 | Vx_resource_name = Vinvocation_name; | |
6615 | ||
6616 | validate_x_resource_name (); | |
6617 | ||
6618 | dpyinfo = w32_term_init (name, (unsigned char *)0, | |
d5db4077 | 6619 | (char *) SDATA (Vx_resource_name)); |
6fc2811b JR |
6620 | |
6621 | if (dpyinfo == 0) | |
d5db4077 | 6622 | error ("Cannot connect to server %s", SDATA (name)); |
6fc2811b JR |
6623 | |
6624 | w32_in_use = 1; | |
6625 | XSETFASTINT (Vwindow_system_version, 3); | |
6626 | ||
6627 | return dpyinfo; | |
6628 | } | |
6629 | ||
6630 | DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection, | |
74e1aeec JR |
6631 | 1, 3, 0, doc: /* Open a connection to a server. |
6632 | DISPLAY is the name of the display to connect to. | |
6633 | Optional second arg XRM-STRING is a string of resources in xrdb format. | |
6634 | If the optional third arg MUST-SUCCEED is non-nil, | |
6635 | terminate Emacs if we can't open the connection. */) | |
6fc2811b JR |
6636 | (display, xrm_string, must_succeed) |
6637 | Lisp_Object display, xrm_string, must_succeed; | |
6638 | { | |
6639 | unsigned char *xrm_option; | |
6640 | struct w32_display_info *dpyinfo; | |
6641 | ||
74e1aeec JR |
6642 | /* If initialization has already been done, return now to avoid |
6643 | overwriting critical parts of one_w32_display_info. */ | |
6644 | if (w32_in_use) | |
6645 | return Qnil; | |
6646 | ||
b7826503 | 6647 | CHECK_STRING (display); |
6fc2811b | 6648 | if (! NILP (xrm_string)) |
b7826503 | 6649 | CHECK_STRING (xrm_string); |
6fc2811b JR |
6650 | |
6651 | if (! EQ (Vwindow_system, intern ("w32"))) | |
6652 | error ("Not using Microsoft Windows"); | |
6653 | ||
6654 | /* Allow color mapping to be defined externally; first look in user's | |
6655 | HOME directory, then in Emacs etc dir for a file called rgb.txt. */ | |
6656 | { | |
6657 | Lisp_Object color_file; | |
6658 | struct gcpro gcpro1; | |
6659 | ||
6660 | color_file = build_string("~/rgb.txt"); | |
6661 | ||
6662 | GCPRO1 (color_file); | |
6663 | ||
6664 | if (NILP (Ffile_readable_p (color_file))) | |
6665 | color_file = | |
6666 | Fexpand_file_name (build_string ("rgb.txt"), | |
6667 | Fsymbol_value (intern ("data-directory"))); | |
6668 | ||
6669 | Vw32_color_map = Fw32_load_color_file (color_file); | |
6670 | ||
6671 | UNGCPRO; | |
6672 | } | |
6673 | if (NILP (Vw32_color_map)) | |
6674 | Vw32_color_map = Fw32_default_color_map (); | |
6675 | ||
5a8a15ec JR |
6676 | /* Merge in system logical colors. */ |
6677 | add_system_logical_colors_to_map (&Vw32_color_map); | |
6678 | ||
6fc2811b | 6679 | if (! NILP (xrm_string)) |
d5db4077 | 6680 | xrm_option = (unsigned char *) SDATA (xrm_string); |
6fc2811b JR |
6681 | else |
6682 | xrm_option = (unsigned char *) 0; | |
6683 | ||
6684 | /* Use this general default value to start with. */ | |
6685 | /* First remove .exe suffix from invocation-name - it looks ugly. */ | |
6686 | { | |
6687 | char basename[ MAX_PATH ], *str; | |
6688 | ||
d5db4077 | 6689 | strcpy (basename, SDATA (Vinvocation_name)); |
6fc2811b JR |
6690 | str = strrchr (basename, '.'); |
6691 | if (str) *str = 0; | |
6692 | Vinvocation_name = build_string (basename); | |
6693 | } | |
6694 | Vx_resource_name = Vinvocation_name; | |
6695 | ||
6696 | validate_x_resource_name (); | |
6697 | ||
6698 | /* This is what opens the connection and sets x_current_display. | |
6699 | This also initializes many symbols, such as those used for input. */ | |
6700 | dpyinfo = w32_term_init (display, xrm_option, | |
d5db4077 | 6701 | (char *) SDATA (Vx_resource_name)); |
6fc2811b JR |
6702 | |
6703 | if (dpyinfo == 0) | |
6704 | { | |
6705 | if (!NILP (must_succeed)) | |
6706 | fatal ("Cannot connect to server %s.\n", | |
d5db4077 | 6707 | SDATA (display)); |
6fc2811b | 6708 | else |
d5db4077 | 6709 | error ("Cannot connect to server %s", SDATA (display)); |
6fc2811b JR |
6710 | } |
6711 | ||
6712 | w32_in_use = 1; | |
6713 | ||
6714 | XSETFASTINT (Vwindow_system_version, 3); | |
6715 | return Qnil; | |
6716 | } | |
6717 | ||
6718 | DEFUN ("x-close-connection", Fx_close_connection, | |
6719 | Sx_close_connection, 1, 1, 0, | |
74e1aeec JR |
6720 | doc: /* Close the connection to DISPLAY's server. |
6721 | For DISPLAY, specify either a frame or a display name (a string). | |
6722 | If DISPLAY is nil, that stands for the selected frame's display. */) | |
6fc2811b JR |
6723 | (display) |
6724 | Lisp_Object display; | |
6725 | { | |
6726 | struct w32_display_info *dpyinfo = check_x_display_info (display); | |
6727 | int i; | |
6728 | ||
6729 | if (dpyinfo->reference_count > 0) | |
6730 | error ("Display still has frames on it"); | |
6731 | ||
6732 | BLOCK_INPUT; | |
6733 | /* Free the fonts in the font table. */ | |
6734 | for (i = 0; i < dpyinfo->n_fonts; i++) | |
6735 | if (dpyinfo->font_table[i].name) | |
6736 | { | |
126f2e35 JR |
6737 | if (dpyinfo->font_table[i].name != dpyinfo->font_table[i].full_name) |
6738 | xfree (dpyinfo->font_table[i].full_name); | |
6fc2811b | 6739 | xfree (dpyinfo->font_table[i].name); |
6fc2811b JR |
6740 | w32_unload_font (dpyinfo, dpyinfo->font_table[i].font); |
6741 | } | |
6742 | x_destroy_all_bitmaps (dpyinfo); | |
6743 | ||
6744 | x_delete_display (dpyinfo); | |
6745 | UNBLOCK_INPUT; | |
6746 | ||
6747 | return Qnil; | |
6748 | } | |
6749 | ||
6750 | DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0, | |
74e1aeec | 6751 | doc: /* Return the list of display names that Emacs has connections to. */) |
6fc2811b JR |
6752 | () |
6753 | { | |
6754 | Lisp_Object tail, result; | |
6755 | ||
6756 | result = Qnil; | |
6757 | for (tail = w32_display_name_list; ! NILP (tail); tail = XCDR (tail)) | |
6758 | result = Fcons (XCAR (XCAR (tail)), result); | |
6759 | ||
6760 | return result; | |
6761 | } | |
6762 | ||
6763 | DEFUN ("x-synchronize", Fx_synchronize, Sx_synchronize, 1, 2, 0, | |
0a332240 PJ |
6764 | doc: /* This is a noop on W32 systems. */) |
6765 | (on, display) | |
6766 | Lisp_Object display, on; | |
6fc2811b | 6767 | { |
6fc2811b JR |
6768 | return Qnil; |
6769 | } | |
6770 | ||
8eaae3d4 | 6771 | |
6fc2811b | 6772 | \f |
6fc2811b | 6773 | /*********************************************************************** |
8eaae3d4 | 6774 | Window properties |
6fc2811b JR |
6775 | ***********************************************************************/ |
6776 | ||
8eaae3d4 KS |
6777 | DEFUN ("x-change-window-property", Fx_change_window_property, |
6778 | Sx_change_window_property, 2, 6, 0, | |
6779 | doc: /* Change window property PROP to VALUE on the X window of FRAME. | |
6780 | VALUE may be a string or a list of conses, numbers and/or strings. | |
6781 | If an element in the list is a string, it is converted to | |
6782 | an Atom and the value of the Atom is used. If an element is a cons, | |
6783 | it is converted to a 32 bit number where the car is the 16 top bits and the | |
6784 | cdr is the lower 16 bits. | |
6785 | FRAME nil or omitted means use the selected frame. | |
6786 | If TYPE is given and non-nil, it is the name of the type of VALUE. | |
6787 | If TYPE is not given or nil, the type is STRING. | |
6788 | FORMAT gives the size in bits of each element if VALUE is a list. | |
6789 | It must be one of 8, 16 or 32. | |
6790 | If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8. | |
6791 | If OUTER_P is non-nil, the property is changed for the outer X window of | |
6792 | FRAME. Default is to change on the edit X window. | |
6fc2811b | 6793 | |
8eaae3d4 KS |
6794 | Value is VALUE. */) |
6795 | (prop, value, frame, type, format, outer_p) | |
6796 | Lisp_Object prop, value, frame, type, format, outer_p; | |
6797 | { | |
6798 | #if 0 /* TODO : port window properties to W32 */ | |
6799 | struct frame *f = check_x_frame (frame); | |
6800 | Atom prop_atom; | |
6fc2811b | 6801 | |
8eaae3d4 KS |
6802 | CHECK_STRING (prop); |
6803 | CHECK_STRING (value); | |
6fc2811b | 6804 | |
8eaae3d4 KS |
6805 | BLOCK_INPUT; |
6806 | prop_atom = XInternAtom (FRAME_W32_DISPLAY (f), SDATA (prop), False); | |
6807 | XChangeProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), | |
6808 | prop_atom, XA_STRING, 8, PropModeReplace, | |
6809 | SDATA (value), SCHARS (value)); | |
6fc2811b | 6810 | |
8eaae3d4 KS |
6811 | /* Make sure the property is set when we return. */ |
6812 | XFlush (FRAME_W32_DISPLAY (f)); | |
6813 | UNBLOCK_INPUT; | |
6fc2811b | 6814 | |
8eaae3d4 | 6815 | #endif /* TODO */ |
6fc2811b | 6816 | |
8eaae3d4 KS |
6817 | return value; |
6818 | } | |
dfff8a69 | 6819 | |
6fc2811b | 6820 | |
8eaae3d4 KS |
6821 | DEFUN ("x-delete-window-property", Fx_delete_window_property, |
6822 | Sx_delete_window_property, 1, 2, 0, | |
6823 | doc: /* Remove window property PROP from X window of FRAME. | |
6824 | FRAME nil or omitted means use the selected frame. Value is PROP. */) | |
6825 | (prop, frame) | |
6826 | Lisp_Object prop, frame; | |
6fc2811b | 6827 | { |
8eaae3d4 | 6828 | #if 0 /* TODO : port window properties to W32 */ |
6fc2811b | 6829 | |
8eaae3d4 KS |
6830 | struct frame *f = check_x_frame (frame); |
6831 | Atom prop_atom; | |
6fc2811b | 6832 | |
8eaae3d4 KS |
6833 | CHECK_STRING (prop); |
6834 | BLOCK_INPUT; | |
6835 | prop_atom = XInternAtom (FRAME_W32_DISPLAY (f), SDATA (prop), False); | |
6836 | XDeleteProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), prop_atom); | |
6fc2811b | 6837 | |
8eaae3d4 KS |
6838 | /* Make sure the property is removed when we return. */ |
6839 | XFlush (FRAME_W32_DISPLAY (f)); | |
6840 | UNBLOCK_INPUT; | |
6841 | #endif /* TODO */ | |
6fc2811b | 6842 | |
8eaae3d4 | 6843 | return prop; |
6fc2811b JR |
6844 | } |
6845 | ||
6846 | ||
8eaae3d4 KS |
6847 | DEFUN ("x-window-property", Fx_window_property, Sx_window_property, |
6848 | 1, 2, 0, | |
6849 | doc: /* Value is the value of window property PROP on FRAME. | |
6850 | If FRAME is nil or omitted, use the selected frame. Value is nil | |
6851 | if FRAME hasn't a property with name PROP or if PROP has no string | |
6852 | value. */) | |
6853 | (prop, frame) | |
6854 | Lisp_Object prop, frame; | |
6fc2811b | 6855 | { |
8eaae3d4 KS |
6856 | #if 0 /* TODO : port window properties to W32 */ |
6857 | ||
6858 | struct frame *f = check_x_frame (frame); | |
6859 | Atom prop_atom; | |
6860 | int rc; | |
6861 | Lisp_Object prop_value = Qnil; | |
6862 | char *tmp_data = NULL; | |
6863 | Atom actual_type; | |
6864 | int actual_format; | |
6865 | unsigned long actual_size, bytes_remaining; | |
7d0393cf | 6866 | |
8eaae3d4 KS |
6867 | CHECK_STRING (prop); |
6868 | BLOCK_INPUT; | |
6869 | prop_atom = XInternAtom (FRAME_W32_DISPLAY (f), SDATA (prop), False); | |
6870 | rc = XGetWindowProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), | |
6871 | prop_atom, 0, 0, False, XA_STRING, | |
6872 | &actual_type, &actual_format, &actual_size, | |
6873 | &bytes_remaining, (unsigned char **) &tmp_data); | |
6874 | if (rc == Success) | |
6fc2811b | 6875 | { |
8eaae3d4 | 6876 | int size = bytes_remaining; |
3cf3436e | 6877 | |
8eaae3d4 KS |
6878 | XFree (tmp_data); |
6879 | tmp_data = NULL; | |
3cf3436e | 6880 | |
8eaae3d4 KS |
6881 | rc = XGetWindowProperty (FRAME_W32_DISPLAY (f), FRAME_W32_WINDOW (f), |
6882 | prop_atom, 0, bytes_remaining, | |
6883 | False, XA_STRING, | |
6884 | &actual_type, &actual_format, | |
6885 | &actual_size, &bytes_remaining, | |
6886 | (unsigned char **) &tmp_data); | |
6887 | if (rc == Success) | |
6888 | prop_value = make_string (tmp_data, size); | |
6fc2811b | 6889 | |
8eaae3d4 KS |
6890 | XFree (tmp_data); |
6891 | } | |
6fc2811b | 6892 | |
8eaae3d4 | 6893 | UNBLOCK_INPUT; |
6fc2811b | 6894 | |
8eaae3d4 | 6895 | return prop_value; |
6fc2811b | 6896 | |
8eaae3d4 KS |
6897 | #endif /* TODO */ |
6898 | return Qnil; | |
6fc2811b JR |
6899 | } |
6900 | ||
6901 | ||
6902 | \f | |
6903 | /*********************************************************************** | |
8eaae3d4 | 6904 | Busy cursor |
6fc2811b JR |
6905 | ***********************************************************************/ |
6906 | ||
8eaae3d4 KS |
6907 | /* If non-null, an asynchronous timer that, when it expires, displays |
6908 | an hourglass cursor on all frames. */ | |
6fc2811b | 6909 | |
8eaae3d4 | 6910 | static struct atimer *hourglass_atimer; |
6fc2811b | 6911 | |
8eaae3d4 | 6912 | /* Non-zero means an hourglass cursor is currently shown. */ |
6fc2811b | 6913 | |
8eaae3d4 | 6914 | static int hourglass_shown_p; |
6fc2811b | 6915 | |
8eaae3d4 | 6916 | /* Number of seconds to wait before displaying an hourglass cursor. */ |
6fc2811b | 6917 | |
8eaae3d4 | 6918 | static Lisp_Object Vhourglass_delay; |
6fc2811b | 6919 | |
8eaae3d4 KS |
6920 | /* Default number of seconds to wait before displaying an hourglass |
6921 | cursor. */ | |
6fc2811b | 6922 | |
8eaae3d4 | 6923 | #define DEFAULT_HOURGLASS_DELAY 1 |
6fc2811b | 6924 | |
8eaae3d4 | 6925 | /* Function prototypes. */ |
6fc2811b | 6926 | |
8eaae3d4 KS |
6927 | static void show_hourglass P_ ((struct atimer *)); |
6928 | static void hide_hourglass P_ ((void)); | |
6fc2811b | 6929 | |
6fc2811b | 6930 | |
8eaae3d4 KS |
6931 | /* Cancel a currently active hourglass timer, and start a new one. */ |
6932 | ||
6933 | void | |
6934 | start_hourglass () | |
6fc2811b | 6935 | { |
8eaae3d4 KS |
6936 | #if 0 /* TODO: cursor shape changes. */ |
6937 | EMACS_TIME delay; | |
6938 | int secs, usecs = 0; | |
6fc2811b | 6939 | |
8eaae3d4 | 6940 | cancel_hourglass (); |
f79e6790 | 6941 | |
0af913d7 GM |
6942 | if (INTEGERP (Vhourglass_delay) |
6943 | && XINT (Vhourglass_delay) > 0) | |
6944 | secs = XFASTINT (Vhourglass_delay); | |
6945 | else if (FLOATP (Vhourglass_delay) | |
6946 | && XFLOAT_DATA (Vhourglass_delay) > 0) | |
dfff8a69 JR |
6947 | { |
6948 | Lisp_Object tem; | |
0af913d7 | 6949 | tem = Ftruncate (Vhourglass_delay, Qnil); |
dfff8a69 | 6950 | secs = XFASTINT (tem); |
0af913d7 | 6951 | usecs = (XFLOAT_DATA (Vhourglass_delay) - secs) * 1000000; |
dfff8a69 | 6952 | } |
f79e6790 | 6953 | else |
0af913d7 | 6954 | secs = DEFAULT_HOURGLASS_DELAY; |
7d0393cf | 6955 | |
dfff8a69 | 6956 | EMACS_SET_SECS_USECS (delay, secs, usecs); |
0af913d7 GM |
6957 | hourglass_atimer = start_atimer (ATIMER_RELATIVE, delay, |
6958 | show_hourglass, NULL); | |
f79e6790 JR |
6959 | #endif |
6960 | } | |
6961 | ||
6962 | ||
0af913d7 GM |
6963 | /* Cancel the hourglass cursor timer if active, hide an hourglass |
6964 | cursor if shown. */ | |
f79e6790 JR |
6965 | |
6966 | void | |
0af913d7 | 6967 | cancel_hourglass () |
f79e6790 | 6968 | { |
0af913d7 | 6969 | if (hourglass_atimer) |
dfff8a69 | 6970 | { |
0af913d7 GM |
6971 | cancel_atimer (hourglass_atimer); |
6972 | hourglass_atimer = NULL; | |
dfff8a69 | 6973 | } |
7d0393cf | 6974 | |
0af913d7 GM |
6975 | if (hourglass_shown_p) |
6976 | hide_hourglass (); | |
f79e6790 JR |
6977 | } |
6978 | ||
6979 | ||
0af913d7 GM |
6980 | /* Timer function of hourglass_atimer. TIMER is equal to |
6981 | hourglass_atimer. | |
f79e6790 | 6982 | |
0af913d7 GM |
6983 | Display an hourglass cursor on all frames by mapping the frames' |
6984 | hourglass_window. Set the hourglass_p flag in the frames' | |
6985 | output_data.x structure to indicate that an hourglass cursor is | |
6986 | shown on the frames. */ | |
f79e6790 JR |
6987 | |
6988 | static void | |
0af913d7 | 6989 | show_hourglass (timer) |
f79e6790 | 6990 | struct atimer *timer; |
6fc2811b | 6991 | { |
767b1ff0 | 6992 | #if 0 /* TODO: cursor shape changes. */ |
f79e6790 | 6993 | /* The timer implementation will cancel this timer automatically |
0af913d7 | 6994 | after this function has run. Set hourglass_atimer to null |
f79e6790 | 6995 | so that we know the timer doesn't have to be canceled. */ |
0af913d7 | 6996 | hourglass_atimer = NULL; |
f79e6790 | 6997 | |
0af913d7 | 6998 | if (!hourglass_shown_p) |
6fc2811b JR |
6999 | { |
7000 | Lisp_Object rest, frame; | |
7d0393cf | 7001 | |
f79e6790 | 7002 | BLOCK_INPUT; |
7d0393cf | 7003 | |
6fc2811b | 7004 | FOR_EACH_FRAME (rest, frame) |
dc220243 | 7005 | if (FRAME_W32_P (XFRAME (frame))) |
6fc2811b JR |
7006 | { |
7007 | struct frame *f = XFRAME (frame); | |
7d0393cf | 7008 | |
0af913d7 | 7009 | f->output_data.w32->hourglass_p = 1; |
7d0393cf | 7010 | |
0af913d7 | 7011 | if (!f->output_data.w32->hourglass_window) |
6fc2811b JR |
7012 | { |
7013 | unsigned long mask = CWCursor; | |
7014 | XSetWindowAttributes attrs; | |
7d0393cf | 7015 | |
0af913d7 | 7016 | attrs.cursor = f->output_data.w32->hourglass_cursor; |
7d0393cf | 7017 | |
0af913d7 | 7018 | f->output_data.w32->hourglass_window |
f79e6790 | 7019 | = XCreateWindow (FRAME_X_DISPLAY (f), |
6fc2811b JR |
7020 | FRAME_OUTER_WINDOW (f), |
7021 | 0, 0, 32000, 32000, 0, 0, | |
f79e6790 JR |
7022 | InputOnly, |
7023 | CopyFromParent, | |
6fc2811b JR |
7024 | mask, &attrs); |
7025 | } | |
7d0393cf | 7026 | |
0af913d7 GM |
7027 | XMapRaised (FRAME_X_DISPLAY (f), |
7028 | f->output_data.w32->hourglass_window); | |
f79e6790 | 7029 | XFlush (FRAME_X_DISPLAY (f)); |
6fc2811b | 7030 | } |
6fc2811b | 7031 | |
0af913d7 | 7032 | hourglass_shown_p = 1; |
f79e6790 JR |
7033 | UNBLOCK_INPUT; |
7034 | } | |
7035 | #endif | |
6fc2811b JR |
7036 | } |
7037 | ||
7038 | ||
0af913d7 | 7039 | /* Hide the hourglass cursor on all frames, if it is currently shown. */ |
6fc2811b | 7040 | |
f79e6790 | 7041 | static void |
0af913d7 | 7042 | hide_hourglass () |
f79e6790 | 7043 | { |
767b1ff0 | 7044 | #if 0 /* TODO: cursor shape changes. */ |
0af913d7 | 7045 | if (hourglass_shown_p) |
6fc2811b | 7046 | { |
f79e6790 JR |
7047 | Lisp_Object rest, frame; |
7048 | ||
7049 | BLOCK_INPUT; | |
7050 | FOR_EACH_FRAME (rest, frame) | |
6fc2811b | 7051 | { |
f79e6790 | 7052 | struct frame *f = XFRAME (frame); |
7d0393cf | 7053 | |
dc220243 | 7054 | if (FRAME_W32_P (f) |
f79e6790 | 7055 | /* Watch out for newly created frames. */ |
0af913d7 | 7056 | && f->output_data.x->hourglass_window) |
f79e6790 | 7057 | { |
0af913d7 GM |
7058 | XUnmapWindow (FRAME_X_DISPLAY (f), |
7059 | f->output_data.x->hourglass_window); | |
7060 | /* Sync here because XTread_socket looks at the | |
7061 | hourglass_p flag that is reset to zero below. */ | |
f79e6790 | 7062 | XSync (FRAME_X_DISPLAY (f), False); |
0af913d7 | 7063 | f->output_data.x->hourglass_p = 0; |
f79e6790 | 7064 | } |
6fc2811b | 7065 | } |
6fc2811b | 7066 | |
0af913d7 | 7067 | hourglass_shown_p = 0; |
f79e6790 JR |
7068 | UNBLOCK_INPUT; |
7069 | } | |
7070 | #endif | |
6fc2811b JR |
7071 | } |
7072 | ||
7073 | ||
7074 | \f | |
7075 | /*********************************************************************** | |
7076 | Tool tips | |
7077 | ***********************************************************************/ | |
7078 | ||
7079 | static Lisp_Object x_create_tip_frame P_ ((struct w32_display_info *, | |
3cf3436e JR |
7080 | Lisp_Object, Lisp_Object)); |
7081 | static void compute_tip_xy P_ ((struct frame *, Lisp_Object, Lisp_Object, | |
7082 | Lisp_Object, int, int, int *, int *)); | |
7d0393cf | 7083 | |
3cf3436e | 7084 | /* The frame of a currently visible tooltip. */ |
6fc2811b | 7085 | |
937e601e | 7086 | Lisp_Object tip_frame; |
6fc2811b JR |
7087 | |
7088 | /* If non-nil, a timer started that hides the last tooltip when it | |
7089 | fires. */ | |
7090 | ||
7091 | Lisp_Object tip_timer; | |
7092 | Window tip_window; | |
7093 | ||
3cf3436e JR |
7094 | /* If non-nil, a vector of 3 elements containing the last args |
7095 | with which x-show-tip was called. See there. */ | |
7096 | ||
7097 | Lisp_Object last_show_tip_args; | |
7098 | ||
7099 | /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */ | |
7100 | ||
7101 | Lisp_Object Vx_max_tooltip_size; | |
7102 | ||
7103 | ||
937e601e AI |
7104 | static Lisp_Object |
7105 | unwind_create_tip_frame (frame) | |
7106 | Lisp_Object frame; | |
7107 | { | |
c844a81a GM |
7108 | Lisp_Object deleted; |
7109 | ||
7110 | deleted = unwind_create_frame (frame); | |
7111 | if (EQ (deleted, Qt)) | |
7112 | { | |
7113 | tip_window = NULL; | |
7114 | tip_frame = Qnil; | |
7115 | } | |
7d0393cf | 7116 | |
c844a81a | 7117 | return deleted; |
937e601e AI |
7118 | } |
7119 | ||
7120 | ||
6fc2811b | 7121 | /* Create a frame for a tooltip on the display described by DPYINFO. |
3cf3436e JR |
7122 | PARMS is a list of frame parameters. TEXT is the string to |
7123 | display in the tip frame. Value is the frame. | |
937e601e AI |
7124 | |
7125 | Note that functions called here, esp. x_default_parameter can | |
7126 | signal errors, for instance when a specified color name is | |
7127 | undefined. We have to make sure that we're in a consistent state | |
7128 | when this happens. */ | |
6fc2811b JR |
7129 | |
7130 | static Lisp_Object | |
3cf3436e | 7131 | x_create_tip_frame (dpyinfo, parms, text) |
6fc2811b | 7132 | struct w32_display_info *dpyinfo; |
3cf3436e | 7133 | Lisp_Object parms, text; |
6fc2811b | 7134 | { |
6fc2811b JR |
7135 | struct frame *f; |
7136 | Lisp_Object frame, tem; | |
7137 | Lisp_Object name; | |
7138 | long window_prompting = 0; | |
7139 | int width, height; | |
331379bf | 7140 | int count = SPECPDL_INDEX (); |
6fc2811b JR |
7141 | struct gcpro gcpro1, gcpro2, gcpro3; |
7142 | struct kboard *kb; | |
3cf3436e JR |
7143 | int face_change_count_before = face_change_count; |
7144 | Lisp_Object buffer; | |
7145 | struct buffer *old_buffer; | |
6fc2811b | 7146 | |
ca56d953 | 7147 | check_w32 (); |
6fc2811b JR |
7148 | |
7149 | /* Use this general default value to start with until we know if | |
7150 | this frame has a specified name. */ | |
7151 | Vx_resource_name = Vinvocation_name; | |
7152 | ||
7153 | #ifdef MULTI_KBOARD | |
7154 | kb = dpyinfo->kboard; | |
7155 | #else | |
7156 | kb = &the_only_kboard; | |
7157 | #endif | |
7158 | ||
7159 | /* Get the name of the frame to use for resource lookup. */ | |
7160 | name = w32_get_arg (parms, Qname, "name", "Name", RES_TYPE_STRING); | |
7161 | if (!STRINGP (name) | |
7162 | && !EQ (name, Qunbound) | |
7163 | && !NILP (name)) | |
7164 | error ("Invalid frame name--not a string or nil"); | |
7165 | Vx_resource_name = name; | |
7166 | ||
7167 | frame = Qnil; | |
7168 | GCPRO3 (parms, name, frame); | |
9eb16b62 JR |
7169 | /* Make a frame without minibuffer nor mode-line. */ |
7170 | f = make_frame (0); | |
7171 | f->wants_modeline = 0; | |
6fc2811b | 7172 | XSETFRAME (frame, f); |
3cf3436e JR |
7173 | |
7174 | buffer = Fget_buffer_create (build_string (" *tip*")); | |
be786000 | 7175 | Fset_window_buffer (FRAME_ROOT_WINDOW (f), buffer, Qnil); |
3cf3436e JR |
7176 | old_buffer = current_buffer; |
7177 | set_buffer_internal_1 (XBUFFER (buffer)); | |
7178 | current_buffer->truncate_lines = Qnil; | |
5c2a995d KH |
7179 | specbind (Qinhibit_read_only, Qt); |
7180 | specbind (Qinhibit_modification_hooks, Qt); | |
3cf3436e JR |
7181 | Ferase_buffer (); |
7182 | Finsert (1, &text); | |
7183 | set_buffer_internal_1 (old_buffer); | |
7d0393cf | 7184 | |
6fc2811b | 7185 | FRAME_CAN_HAVE_SCROLL_BARS (f) = 0; |
937e601e | 7186 | record_unwind_protect (unwind_create_tip_frame, frame); |
6fc2811b | 7187 | |
3cf3436e JR |
7188 | /* By setting the output method, we're essentially saying that |
7189 | the frame is live, as per FRAME_LIVE_P. If we get a signal | |
7190 | from this point on, x_destroy_window might screw up reference | |
7191 | counts etc. */ | |
d88c567c | 7192 | f->output_method = output_w32; |
6fc2811b JR |
7193 | f->output_data.w32 = |
7194 | (struct w32_output *) xmalloc (sizeof (struct w32_output)); | |
7195 | bzero (f->output_data.w32, sizeof (struct w32_output)); | |
ca56d953 JR |
7196 | |
7197 | FRAME_FONTSET (f) = -1; | |
6fc2811b JR |
7198 | f->icon_name = Qnil; |
7199 | ||
ca56d953 | 7200 | #if 0 /* GLYPH_DEBUG TODO: image support. */ |
937e601e AI |
7201 | image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount; |
7202 | dpyinfo_refcount = dpyinfo->reference_count; | |
7203 | #endif /* GLYPH_DEBUG */ | |
6fc2811b JR |
7204 | #ifdef MULTI_KBOARD |
7205 | FRAME_KBOARD (f) = kb; | |
7206 | #endif | |
7207 | f->output_data.w32->parent_desc = FRAME_W32_DISPLAY_INFO (f)->root_window; | |
7208 | f->output_data.w32->explicit_parent = 0; | |
7209 | ||
7210 | /* Set the name; the functions to which we pass f expect the name to | |
7211 | be set. */ | |
7212 | if (EQ (name, Qunbound) || NILP (name)) | |
7213 | { | |
ca56d953 | 7214 | f->name = build_string (dpyinfo->w32_id_name); |
6fc2811b JR |
7215 | f->explicit_name = 0; |
7216 | } | |
7217 | else | |
7218 | { | |
7219 | f->name = name; | |
7220 | f->explicit_name = 1; | |
7221 | /* use the frame's title when getting resources for this frame. */ | |
7222 | specbind (Qx_resource_name, name); | |
7223 | } | |
7224 | ||
6fc2811b JR |
7225 | /* Extract the window parameters from the supplied values |
7226 | that are needed to determine window geometry. */ | |
7227 | { | |
7228 | Lisp_Object font; | |
7229 | ||
7230 | font = w32_get_arg (parms, Qfont, "font", "Font", RES_TYPE_STRING); | |
7231 | ||
7232 | BLOCK_INPUT; | |
7233 | /* First, try whatever font the caller has specified. */ | |
7234 | if (STRINGP (font)) | |
7235 | { | |
7236 | tem = Fquery_fontset (font, Qnil); | |
7237 | if (STRINGP (tem)) | |
d5db4077 | 7238 | font = x_new_fontset (f, SDATA (tem)); |
6fc2811b | 7239 | else |
d5db4077 | 7240 | font = x_new_font (f, SDATA (font)); |
6fc2811b | 7241 | } |
7d0393cf | 7242 | |
6fc2811b JR |
7243 | /* Try out a font which we hope has bold and italic variations. */ |
7244 | if (!STRINGP (font)) | |
ca56d953 | 7245 | font = x_new_font (f, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1"); |
6fc2811b | 7246 | if (! STRINGP (font)) |
ca56d953 | 7247 | font = x_new_font (f, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1"); |
6fc2811b JR |
7248 | /* If those didn't work, look for something which will at least work. */ |
7249 | if (! STRINGP (font)) | |
ca56d953 | 7250 | font = x_new_font (f, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1"); |
6fc2811b JR |
7251 | UNBLOCK_INPUT; |
7252 | if (! STRINGP (font)) | |
ca56d953 | 7253 | font = build_string ("Fixedsys"); |
6fc2811b JR |
7254 | |
7255 | x_default_parameter (f, parms, Qfont, font, | |
7256 | "font", "Font", RES_TYPE_STRING); | |
7257 | } | |
7258 | ||
7259 | x_default_parameter (f, parms, Qborder_width, make_number (2), | |
7260 | "borderWidth", "BorderWidth", RES_TYPE_NUMBER); | |
6fc2811b JR |
7261 | /* This defaults to 2 in order to match xterm. We recognize either |
7262 | internalBorderWidth or internalBorder (which is what xterm calls | |
7263 | it). */ | |
7264 | if (NILP (Fassq (Qinternal_border_width, parms))) | |
7265 | { | |
7266 | Lisp_Object value; | |
7267 | ||
7268 | value = w32_get_arg (parms, Qinternal_border_width, | |
7269 | "internalBorder", "internalBorder", RES_TYPE_NUMBER); | |
7270 | if (! EQ (value, Qunbound)) | |
7271 | parms = Fcons (Fcons (Qinternal_border_width, value), | |
7272 | parms); | |
7273 | } | |
bfd6edcc | 7274 | x_default_parameter (f, parms, Qinternal_border_width, make_number (1), |
6fc2811b JR |
7275 | "internalBorderWidth", "internalBorderWidth", |
7276 | RES_TYPE_NUMBER); | |
7277 | ||
7278 | /* Also do the stuff which must be set before the window exists. */ | |
7279 | x_default_parameter (f, parms, Qforeground_color, build_string ("black"), | |
7280 | "foreground", "Foreground", RES_TYPE_STRING); | |
7281 | x_default_parameter (f, parms, Qbackground_color, build_string ("white"), | |
7282 | "background", "Background", RES_TYPE_STRING); | |
7283 | x_default_parameter (f, parms, Qmouse_color, build_string ("black"), | |
7284 | "pointerColor", "Foreground", RES_TYPE_STRING); | |
7285 | x_default_parameter (f, parms, Qcursor_color, build_string ("black"), | |
7286 | "cursorColor", "Foreground", RES_TYPE_STRING); | |
7287 | x_default_parameter (f, parms, Qborder_color, build_string ("black"), | |
7288 | "borderColor", "BorderColor", RES_TYPE_STRING); | |
7289 | ||
7290 | /* Init faces before x_default_parameter is called for scroll-bar | |
7291 | parameters because that function calls x_set_scroll_bar_width, | |
7292 | which calls change_frame_size, which calls Fset_window_buffer, | |
7293 | which runs hooks, which call Fvertical_motion. At the end, we | |
7294 | end up in init_iterator with a null face cache, which should not | |
7295 | happen. */ | |
7296 | init_frame_faces (f); | |
ca56d953 JR |
7297 | |
7298 | f->output_data.w32->dwStyle = WS_BORDER | WS_POPUP | WS_DISABLED; | |
6fc2811b | 7299 | f->output_data.w32->parent_desc = FRAME_W32_DISPLAY_INFO (f)->root_window; |
9eb16b62 | 7300 | |
6d906347 | 7301 | window_prompting = x_figure_window_size (f, parms, 0); |
6fc2811b | 7302 | |
9eb16b62 | 7303 | /* No fringes on tip frame. */ |
be786000 KS |
7304 | f->fringe_cols = 0; |
7305 | f->left_fringe_width = 0; | |
7306 | f->right_fringe_width = 0; | |
9eb16b62 | 7307 | |
ca56d953 JR |
7308 | BLOCK_INPUT; |
7309 | my_create_tip_window (f); | |
7310 | UNBLOCK_INPUT; | |
6fc2811b JR |
7311 | |
7312 | x_make_gc (f); | |
7313 | ||
7314 | x_default_parameter (f, parms, Qauto_raise, Qnil, | |
7315 | "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN); | |
7316 | x_default_parameter (f, parms, Qauto_lower, Qnil, | |
7317 | "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN); | |
7318 | x_default_parameter (f, parms, Qcursor_type, Qbox, | |
7319 | "cursorType", "CursorType", RES_TYPE_SYMBOL); | |
7320 | ||
be786000 | 7321 | /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size. |
6fc2811b | 7322 | Change will not be effected unless different from the current |
be786000 KS |
7323 | FRAME_LINES (f). */ |
7324 | width = FRAME_COLS (f); | |
7325 | height = FRAME_LINES (f); | |
7326 | FRAME_LINES (f) = 0; | |
7327 | SET_FRAME_COLS (f, 0); | |
6fc2811b JR |
7328 | change_frame_size (f, height, width, 1, 0, 0); |
7329 | ||
cd1d850f JPW |
7330 | /* Add `tooltip' frame parameter's default value. */ |
7331 | if (NILP (Fframe_parameter (frame, intern ("tooltip")))) | |
7332 | Fmodify_frame_parameters (frame, Fcons (Fcons (intern ("tooltip"), Qt), | |
7333 | Qnil)); | |
7d0393cf | 7334 | |
3cf3436e JR |
7335 | /* Set up faces after all frame parameters are known. This call |
7336 | also merges in face attributes specified for new frames. | |
7337 | ||
7338 | Frame parameters may be changed if .Xdefaults contains | |
7339 | specifications for the default font. For example, if there is an | |
7340 | `Emacs.default.attributeBackground: pink', the `background-color' | |
7341 | attribute of the frame get's set, which let's the internal border | |
7342 | of the tooltip frame appear in pink. Prevent this. */ | |
7343 | { | |
7344 | Lisp_Object bg = Fframe_parameter (frame, Qbackground_color); | |
7345 | ||
7346 | /* Set tip_frame here, so that */ | |
7347 | tip_frame = frame; | |
7348 | call1 (Qface_set_after_frame_default, frame); | |
7d0393cf | 7349 | |
3cf3436e JR |
7350 | if (!EQ (bg, Fframe_parameter (frame, Qbackground_color))) |
7351 | Fmodify_frame_parameters (frame, Fcons (Fcons (Qbackground_color, bg), | |
7352 | Qnil)); | |
7353 | } | |
7d0393cf | 7354 | |
6fc2811b JR |
7355 | f->no_split = 1; |
7356 | ||
7357 | UNGCPRO; | |
7358 | ||
7359 | /* It is now ok to make the frame official even if we get an error | |
7360 | below. And the frame needs to be on Vframe_list or making it | |
7361 | visible won't work. */ | |
7362 | Vframe_list = Fcons (frame, Vframe_list); | |
7363 | ||
7364 | /* Now that the frame is official, it counts as a reference to | |
7365 | its display. */ | |
7366 | FRAME_W32_DISPLAY_INFO (f)->reference_count++; | |
ee78dc32 | 7367 | |
3cf3436e JR |
7368 | /* Setting attributes of faces of the tooltip frame from resources |
7369 | and similar will increment face_change_count, which leads to the | |
7370 | clearing of all current matrices. Since this isn't necessary | |
7371 | here, avoid it by resetting face_change_count to the value it | |
7372 | had before we created the tip frame. */ | |
7373 | face_change_count = face_change_count_before; | |
7374 | ||
7375 | /* Discard the unwind_protect. */ | |
6fc2811b | 7376 | return unbind_to (count, frame); |
ee78dc32 GV |
7377 | } |
7378 | ||
3cf3436e JR |
7379 | |
7380 | /* Compute where to display tip frame F. PARMS is the list of frame | |
7381 | parameters for F. DX and DY are specified offsets from the current | |
7382 | location of the mouse. WIDTH and HEIGHT are the width and height | |
7383 | of the tooltip. Return coordinates relative to the root window of | |
7384 | the display in *ROOT_X, and *ROOT_Y. */ | |
7385 | ||
7386 | static void | |
7387 | compute_tip_xy (f, parms, dx, dy, width, height, root_x, root_y) | |
7388 | struct frame *f; | |
7389 | Lisp_Object parms, dx, dy; | |
7390 | int width, height; | |
7391 | int *root_x, *root_y; | |
7392 | { | |
3cf3436e | 7393 | Lisp_Object left, top; |
7d0393cf | 7394 | |
3cf3436e JR |
7395 | /* User-specified position? */ |
7396 | left = Fcdr (Fassq (Qleft, parms)); | |
7397 | top = Fcdr (Fassq (Qtop, parms)); | |
7d0393cf | 7398 | |
3cf3436e JR |
7399 | /* Move the tooltip window where the mouse pointer is. Resize and |
7400 | show it. */ | |
ca56d953 | 7401 | if (!INTEGERP (left) || !INTEGERP (top)) |
3cf3436e | 7402 | { |
ca56d953 JR |
7403 | POINT pt; |
7404 | ||
3cf3436e | 7405 | BLOCK_INPUT; |
ca56d953 JR |
7406 | GetCursorPos (&pt); |
7407 | *root_x = pt.x; | |
7408 | *root_y = pt.y; | |
3cf3436e JR |
7409 | UNBLOCK_INPUT; |
7410 | } | |
7411 | ||
7412 | if (INTEGERP (top)) | |
7413 | *root_y = XINT (top); | |
bf63eb69 JD |
7414 | else if (*root_y + XINT (dy) <= 0) |
7415 | *root_y = 0; /* Can happen for negative dy */ | |
7e8410d1 JD |
7416 | else if (*root_y + XINT (dy) + height <= FRAME_W32_DISPLAY_INFO (f)->height) |
7417 | /* It fits below the pointer */ | |
3cf3436e | 7418 | *root_y += XINT (dy); |
7e8410d1 JD |
7419 | else if (height + XINT (dy) <= *root_y) |
7420 | /* It fits above the pointer. */ | |
7421 | *root_y -= height + XINT (dy); | |
7422 | else | |
7423 | /* Put it on the top. */ | |
7424 | *root_y = 0; | |
3cf3436e JR |
7425 | |
7426 | if (INTEGERP (left)) | |
7427 | *root_x = XINT (left); | |
bf63eb69 JD |
7428 | else if (*root_x + XINT (dx) <= 0) |
7429 | *root_x = 0; /* Can happen for negative dx */ | |
72e4adef JR |
7430 | else if (*root_x + XINT (dx) + width <= FRAME_W32_DISPLAY_INFO (f)->width) |
7431 | /* It fits to the right of the pointer. */ | |
7432 | *root_x += XINT (dx); | |
7433 | else if (width + XINT (dx) <= *root_x) | |
7434 | /* It fits to the left of the pointer. */ | |
3cf3436e JR |
7435 | *root_x -= width + XINT (dx); |
7436 | else | |
72e4adef JR |
7437 | /* Put it left justified on the screen -- it ought to fit that way. */ |
7438 | *root_x = 0; | |
3cf3436e JR |
7439 | } |
7440 | ||
7441 | ||
71eab8d1 | 7442 | DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0, |
74e1aeec JR |
7443 | doc: /* Show STRING in a \"tooltip\" window on frame FRAME. |
7444 | A tooltip window is a small window displaying a string. | |
7445 | ||
7446 | FRAME nil or omitted means use the selected frame. | |
7447 | ||
7448 | PARMS is an optional list of frame parameters which can be | |
7449 | used to change the tooltip's appearance. | |
7450 | ||
ca56d953 JR |
7451 | Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil |
7452 | means use the default timeout of 5 seconds. | |
74e1aeec | 7453 | |
52deb19f | 7454 | If the list of frame parameters PARMS contains a `left' parameter, |
74e1aeec JR |
7455 | the tooltip is displayed at that x-position. Otherwise it is |
7456 | displayed at the mouse position, with offset DX added (default is 5 if | |
7457 | DX isn't specified). Likewise for the y-position; if a `top' frame | |
7458 | parameter is specified, it determines the y-position of the tooltip | |
7459 | window, otherwise it is displayed at the mouse position, with offset | |
7460 | DY added (default is -10). | |
7461 | ||
7462 | A tooltip's maximum size is specified by `x-max-tooltip-size'. | |
7463 | Text larger than the specified size is clipped. */) | |
71eab8d1 AI |
7464 | (string, frame, parms, timeout, dx, dy) |
7465 | Lisp_Object string, frame, parms, timeout, dx, dy; | |
ee78dc32 | 7466 | { |
6fc2811b JR |
7467 | struct frame *f; |
7468 | struct window *w; | |
3cf3436e | 7469 | int root_x, root_y; |
6fc2811b JR |
7470 | struct buffer *old_buffer; |
7471 | struct text_pos pos; | |
7472 | int i, width, height; | |
6fc2811b JR |
7473 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
7474 | int old_windows_or_buffers_changed = windows_or_buffers_changed; | |
331379bf | 7475 | int count = SPECPDL_INDEX (); |
7d0393cf | 7476 | |
6fc2811b | 7477 | specbind (Qinhibit_redisplay, Qt); |
ee78dc32 | 7478 | |
dfff8a69 | 7479 | GCPRO4 (string, parms, frame, timeout); |
ee78dc32 | 7480 | |
b7826503 | 7481 | CHECK_STRING (string); |
6fc2811b JR |
7482 | f = check_x_frame (frame); |
7483 | if (NILP (timeout)) | |
7484 | timeout = make_number (5); | |
7485 | else | |
b7826503 | 7486 | CHECK_NATNUM (timeout); |
ee78dc32 | 7487 | |
71eab8d1 AI |
7488 | if (NILP (dx)) |
7489 | dx = make_number (5); | |
7490 | else | |
b7826503 | 7491 | CHECK_NUMBER (dx); |
7d0393cf | 7492 | |
71eab8d1 | 7493 | if (NILP (dy)) |
dc220243 | 7494 | dy = make_number (-10); |
71eab8d1 | 7495 | else |
b7826503 | 7496 | CHECK_NUMBER (dy); |
71eab8d1 | 7497 | |
dc220243 JR |
7498 | if (NILP (last_show_tip_args)) |
7499 | last_show_tip_args = Fmake_vector (make_number (3), Qnil); | |
7500 | ||
7501 | if (!NILP (tip_frame)) | |
7502 | { | |
7503 | Lisp_Object last_string = AREF (last_show_tip_args, 0); | |
7504 | Lisp_Object last_frame = AREF (last_show_tip_args, 1); | |
7505 | Lisp_Object last_parms = AREF (last_show_tip_args, 2); | |
7506 | ||
7507 | if (EQ (frame, last_frame) | |
7508 | && !NILP (Fequal (last_string, string)) | |
7509 | && !NILP (Fequal (last_parms, parms))) | |
7510 | { | |
7511 | struct frame *f = XFRAME (tip_frame); | |
7d0393cf | 7512 | |
dc220243 JR |
7513 | /* Only DX and DY have changed. */ |
7514 | if (!NILP (tip_timer)) | |
7515 | { | |
7516 | Lisp_Object timer = tip_timer; | |
7517 | tip_timer = Qnil; | |
7518 | call1 (Qcancel_timer, timer); | |
7519 | } | |
7520 | ||
7521 | BLOCK_INPUT; | |
be786000 KS |
7522 | compute_tip_xy (f, parms, dx, dy, FRAME_PIXEL_WIDTH (f), |
7523 | FRAME_PIXEL_HEIGHT (f), &root_x, &root_y); | |
d65a9cdc JR |
7524 | |
7525 | /* Put tooltip in topmost group and in position. */ | |
ca56d953 JR |
7526 | SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOPMOST, |
7527 | root_x, root_y, 0, 0, | |
7528 | SWP_NOSIZE | SWP_NOACTIVATE); | |
d65a9cdc JR |
7529 | |
7530 | /* Ensure tooltip is on top of other topmost windows (eg menus). */ | |
7531 | SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOP, | |
7532 | 0, 0, 0, 0, | |
7533 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); | |
7534 | ||
dc220243 JR |
7535 | UNBLOCK_INPUT; |
7536 | goto start_timer; | |
7537 | } | |
7538 | } | |
7539 | ||
6fc2811b JR |
7540 | /* Hide a previous tip, if any. */ |
7541 | Fx_hide_tip (); | |
ee78dc32 | 7542 | |
dc220243 JR |
7543 | ASET (last_show_tip_args, 0, string); |
7544 | ASET (last_show_tip_args, 1, frame); | |
7545 | ASET (last_show_tip_args, 2, parms); | |
7546 | ||
6fc2811b JR |
7547 | /* Add default values to frame parameters. */ |
7548 | if (NILP (Fassq (Qname, parms))) | |
7549 | parms = Fcons (Fcons (Qname, build_string ("tooltip")), parms); | |
7550 | if (NILP (Fassq (Qinternal_border_width, parms))) | |
7551 | parms = Fcons (Fcons (Qinternal_border_width, make_number (3)), parms); | |
7552 | if (NILP (Fassq (Qborder_width, parms))) | |
7553 | parms = Fcons (Fcons (Qborder_width, make_number (1)), parms); | |
7554 | if (NILP (Fassq (Qborder_color, parms))) | |
7555 | parms = Fcons (Fcons (Qborder_color, build_string ("lightyellow")), parms); | |
7556 | if (NILP (Fassq (Qbackground_color, parms))) | |
7557 | parms = Fcons (Fcons (Qbackground_color, build_string ("lightyellow")), | |
7558 | parms); | |
7559 | ||
0e3fcdef JR |
7560 | /* Block input until the tip has been fully drawn, to avoid crashes |
7561 | when drawing tips in menus. */ | |
7562 | BLOCK_INPUT; | |
7563 | ||
6fc2811b JR |
7564 | /* Create a frame for the tooltip, and record it in the global |
7565 | variable tip_frame. */ | |
ca56d953 | 7566 | frame = x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f), parms, string); |
937e601e | 7567 | f = XFRAME (frame); |
6fc2811b | 7568 | |
3cf3436e | 7569 | /* Set up the frame's root window. */ |
6fc2811b | 7570 | w = XWINDOW (FRAME_ROOT_WINDOW (f)); |
be786000 | 7571 | w->left_col = w->top_line = make_number (0); |
3cf3436e JR |
7572 | |
7573 | if (CONSP (Vx_max_tooltip_size) | |
7574 | && INTEGERP (XCAR (Vx_max_tooltip_size)) | |
7575 | && XINT (XCAR (Vx_max_tooltip_size)) > 0 | |
7576 | && INTEGERP (XCDR (Vx_max_tooltip_size)) | |
7577 | && XINT (XCDR (Vx_max_tooltip_size)) > 0) | |
7578 | { | |
be786000 KS |
7579 | w->total_cols = XCAR (Vx_max_tooltip_size); |
7580 | w->total_lines = XCDR (Vx_max_tooltip_size); | |
3cf3436e JR |
7581 | } |
7582 | else | |
7583 | { | |
be786000 KS |
7584 | w->total_cols = make_number (80); |
7585 | w->total_lines = make_number (40); | |
3cf3436e | 7586 | } |
7d0393cf | 7587 | |
be786000 | 7588 | FRAME_TOTAL_COLS (f) = XINT (w->total_cols); |
6fc2811b JR |
7589 | adjust_glyphs (f); |
7590 | w->pseudo_window_p = 1; | |
7591 | ||
7592 | /* Display the tooltip text in a temporary buffer. */ | |
6fc2811b | 7593 | old_buffer = current_buffer; |
3cf3436e JR |
7594 | set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f))->buffer)); |
7595 | current_buffer->truncate_lines = Qnil; | |
6fc2811b JR |
7596 | clear_glyph_matrix (w->desired_matrix); |
7597 | clear_glyph_matrix (w->current_matrix); | |
7598 | SET_TEXT_POS (pos, BEGV, BEGV_BYTE); | |
29e95254 | 7599 | try_window (FRAME_ROOT_WINDOW (f), pos, 0); |
6fc2811b JR |
7600 | |
7601 | /* Compute width and height of the tooltip. */ | |
7602 | width = height = 0; | |
7603 | for (i = 0; i < w->desired_matrix->nrows; ++i) | |
ee78dc32 | 7604 | { |
6fc2811b JR |
7605 | struct glyph_row *row = &w->desired_matrix->rows[i]; |
7606 | struct glyph *last; | |
7607 | int row_width; | |
7608 | ||
7609 | /* Stop at the first empty row at the end. */ | |
7610 | if (!row->enabled_p || !row->displays_text_p) | |
7611 | break; | |
7612 | ||
7613 | /* Let the row go over the full width of the frame. */ | |
7614 | row->full_width_p = 1; | |
7615 | ||
4e3a1c61 JR |
7616 | #ifdef TODO /* Investigate why some fonts need more width than is |
7617 | calculated for some tooltips. */ | |
6fc2811b JR |
7618 | /* There's a glyph at the end of rows that is use to place |
7619 | the cursor there. Don't include the width of this glyph. */ | |
7620 | if (row->used[TEXT_AREA]) | |
7621 | { | |
7622 | last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1]; | |
7623 | row_width = row->pixel_width - last->pixel_width; | |
7624 | } | |
7625 | else | |
4e3a1c61 | 7626 | #endif |
6fc2811b | 7627 | row_width = row->pixel_width; |
7d0393cf | 7628 | |
ca56d953 | 7629 | /* TODO: find why tips do not draw along baseline as instructed. */ |
bfd6edcc | 7630 | height += row->height; |
6fc2811b | 7631 | width = max (width, row_width); |
ee78dc32 GV |
7632 | } |
7633 | ||
6fc2811b JR |
7634 | /* Add the frame's internal border to the width and height the X |
7635 | window should have. */ | |
7636 | height += 2 * FRAME_INTERNAL_BORDER_WIDTH (f); | |
7637 | width += 2 * FRAME_INTERNAL_BORDER_WIDTH (f); | |
ee78dc32 | 7638 | |
6fc2811b JR |
7639 | /* Move the tooltip window where the mouse pointer is. Resize and |
7640 | show it. */ | |
3cf3436e | 7641 | compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y); |
71eab8d1 | 7642 | |
bfd6edcc JR |
7643 | { |
7644 | /* Adjust Window size to take border into account. */ | |
7645 | RECT rect; | |
7646 | rect.left = rect.top = 0; | |
7647 | rect.right = width; | |
7648 | rect.bottom = height; | |
7649 | AdjustWindowRect (&rect, f->output_data.w32->dwStyle, | |
7650 | FRAME_EXTERNAL_MENU_BAR (f)); | |
7651 | ||
d65a9cdc | 7652 | /* Position and size tooltip, and put it in the topmost group. */ |
bfd6edcc JR |
7653 | SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOPMOST, |
7654 | root_x, root_y, rect.right - rect.left, | |
7655 | rect.bottom - rect.top, SWP_NOACTIVATE); | |
7656 | ||
d65a9cdc JR |
7657 | /* Ensure tooltip is on top of other topmost windows (eg menus). */ |
7658 | SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOP, | |
7659 | 0, 0, 0, 0, | |
7660 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); | |
7661 | ||
bfd6edcc JR |
7662 | /* Let redisplay know that we have made the frame visible already. */ |
7663 | f->async_visible = 1; | |
7664 | ||
7665 | ShowWindow (FRAME_W32_WINDOW (f), SW_SHOWNOACTIVATE); | |
7666 | } | |
ee78dc32 | 7667 | |
6fc2811b JR |
7668 | /* Draw into the window. */ |
7669 | w->must_be_updated_p = 1; | |
7670 | update_single_window (w, 1); | |
ee78dc32 | 7671 | |
0e3fcdef JR |
7672 | UNBLOCK_INPUT; |
7673 | ||
6fc2811b JR |
7674 | /* Restore original current buffer. */ |
7675 | set_buffer_internal_1 (old_buffer); | |
7676 | windows_or_buffers_changed = old_windows_or_buffers_changed; | |
ee78dc32 | 7677 | |
dc220243 | 7678 | start_timer: |
6fc2811b JR |
7679 | /* Let the tip disappear after timeout seconds. */ |
7680 | tip_timer = call3 (intern ("run-at-time"), timeout, Qnil, | |
7681 | intern ("x-hide-tip")); | |
ee78dc32 | 7682 | |
dfff8a69 | 7683 | UNGCPRO; |
6fc2811b | 7684 | return unbind_to (count, Qnil); |
ee78dc32 GV |
7685 | } |
7686 | ||
ee78dc32 | 7687 | |
6fc2811b | 7688 | DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0, |
74e1aeec JR |
7689 | doc: /* Hide the current tooltip window, if there is any. |
7690 | Value is t if tooltip was open, nil otherwise. */) | |
6fc2811b JR |
7691 | () |
7692 | { | |
937e601e AI |
7693 | int count; |
7694 | Lisp_Object deleted, frame, timer; | |
7695 | struct gcpro gcpro1, gcpro2; | |
7696 | ||
7697 | /* Return quickly if nothing to do. */ | |
7698 | if (NILP (tip_timer) && NILP (tip_frame)) | |
7699 | return Qnil; | |
7d0393cf | 7700 | |
937e601e AI |
7701 | frame = tip_frame; |
7702 | timer = tip_timer; | |
7703 | GCPRO2 (frame, timer); | |
7704 | tip_frame = tip_timer = deleted = Qnil; | |
7d0393cf | 7705 | |
331379bf | 7706 | count = SPECPDL_INDEX (); |
6fc2811b | 7707 | specbind (Qinhibit_redisplay, Qt); |
937e601e | 7708 | specbind (Qinhibit_quit, Qt); |
7d0393cf | 7709 | |
937e601e | 7710 | if (!NILP (timer)) |
dc220243 | 7711 | call1 (Qcancel_timer, timer); |
ee78dc32 | 7712 | |
937e601e | 7713 | if (FRAMEP (frame)) |
6fc2811b | 7714 | { |
937e601e AI |
7715 | Fdelete_frame (frame, Qnil); |
7716 | deleted = Qt; | |
6fc2811b | 7717 | } |
1edf84e7 | 7718 | |
937e601e AI |
7719 | UNGCPRO; |
7720 | return unbind_to (count, deleted); | |
6fc2811b | 7721 | } |
5ac45f98 | 7722 | |
5ac45f98 | 7723 | |
6fc2811b JR |
7724 | \f |
7725 | /*********************************************************************** | |
7726 | File selection dialog | |
7727 | ***********************************************************************/ | |
6fc2811b JR |
7728 | extern Lisp_Object Qfile_name_history; |
7729 | ||
1030b26b JR |
7730 | /* Callback for altering the behaviour of the Open File dialog. |
7731 | Makes the Filename text field contain "Current Directory" and be | |
7732 | read-only when "Directories" is selected in the filter. This | |
7733 | allows us to work around the fact that the standard Open File | |
7734 | dialog does not support directories. */ | |
7735 | UINT CALLBACK | |
7736 | file_dialog_callback (hwnd, msg, wParam, lParam) | |
7737 | HWND hwnd; | |
7738 | UINT msg; | |
7739 | WPARAM wParam; | |
7740 | LPARAM lParam; | |
7741 | { | |
7742 | if (msg == WM_NOTIFY) | |
7743 | { | |
7744 | OFNOTIFY * notify = (OFNOTIFY *)lParam; | |
7745 | /* Detect when the Filter dropdown is changed. */ | |
ef544dc8 JR |
7746 | if (notify->hdr.code == CDN_TYPECHANGE |
7747 | || notify->hdr.code == CDN_INITDONE) | |
1030b26b JR |
7748 | { |
7749 | HWND dialog = GetParent (hwnd); | |
7750 | HWND edit_control = GetDlgItem (dialog, FILE_NAME_TEXT_FIELD); | |
7751 | ||
7752 | /* Directories is in index 2. */ | |
7753 | if (notify->lpOFN->nFilterIndex == 2) | |
7754 | { | |
7755 | CommDlg_OpenSave_SetControlText (dialog, FILE_NAME_TEXT_FIELD, | |
7756 | "Current Directory"); | |
7757 | EnableWindow (edit_control, FALSE); | |
7758 | } | |
7759 | else | |
7760 | { | |
ef544dc8 JR |
7761 | /* Don't override default filename on init done. */ |
7762 | if (notify->hdr.code == CDN_TYPECHANGE) | |
7763 | CommDlg_OpenSave_SetControlText (dialog, | |
7764 | FILE_NAME_TEXT_FIELD, ""); | |
1030b26b JR |
7765 | EnableWindow (edit_control, TRUE); |
7766 | } | |
7767 | } | |
7768 | } | |
7769 | return 0; | |
7770 | } | |
7771 | ||
7f2b4738 JR |
7772 | /* Since we compile with _WIN32_WINNT set to 0x0400 (for NT4 compatibility) |
7773 | we end up with the old file dialogs. Define a big enough struct for the | |
7774 | new dialog to trick GetOpenFileName into giving us the new dialogs on | |
7775 | Windows 2000 and XP. */ | |
7776 | typedef struct | |
7777 | { | |
7778 | OPENFILENAME real_details; | |
7779 | void * pReserved; | |
7780 | DWORD dwReserved; | |
7781 | DWORD FlagsEx; | |
7782 | } NEWOPENFILENAME; | |
7783 | ||
21517c3d | 7784 | |
f9d64bb3 | 7785 | DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0, |
74e1aeec JR |
7786 | doc: /* Read file name, prompting with PROMPT in directory DIR. |
7787 | Use a file selection dialog. | |
7788 | Select DEFAULT-FILENAME in the dialog's file selection box, if | |
f9d64bb3 JD |
7789 | specified. Ensure that file exists if MUSTMATCH is non-nil. |
7790 | If ONLY-DIR-P is non-nil, the user can only select directories. */) | |
7791 | (prompt, dir, default_filename, mustmatch, only_dir_p) | |
7792 | Lisp_Object prompt, dir, default_filename, mustmatch, only_dir_p; | |
6fc2811b JR |
7793 | { |
7794 | struct frame *f = SELECTED_FRAME (); | |
7795 | Lisp_Object file = Qnil; | |
aed13378 | 7796 | int count = SPECPDL_INDEX (); |
f9d64bb3 | 7797 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; |
6fc2811b JR |
7798 | char filename[MAX_PATH + 1]; |
7799 | char init_dir[MAX_PATH + 1]; | |
ef544dc8 | 7800 | int default_filter_index = 1; /* 1: All Files, 2: Directories only */ |
6fc2811b | 7801 | |
f9d64bb3 | 7802 | GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file); |
b7826503 PJ |
7803 | CHECK_STRING (prompt); |
7804 | CHECK_STRING (dir); | |
6fc2811b JR |
7805 | |
7806 | /* Create the dialog with PROMPT as title, using DIR as initial | |
7807 | directory and using "*" as pattern. */ | |
7808 | dir = Fexpand_file_name (dir, Qnil); | |
dda741ec | 7809 | strncpy (init_dir, SDATA (ENCODE_FILE (dir)), MAX_PATH); |
6fc2811b JR |
7810 | init_dir[MAX_PATH] = '\0'; |
7811 | unixtodos_filename (init_dir); | |
7812 | ||
7813 | if (STRINGP (default_filename)) | |
7814 | { | |
7815 | char *file_name_only; | |
dda741ec | 7816 | char *full_path_name = SDATA (ENCODE_FILE (default_filename)); |
5ac45f98 | 7817 | |
6fc2811b | 7818 | unixtodos_filename (full_path_name); |
5ac45f98 | 7819 | |
6fc2811b JR |
7820 | file_name_only = strrchr (full_path_name, '\\'); |
7821 | if (!file_name_only) | |
7822 | file_name_only = full_path_name; | |
7823 | else | |
ef544dc8 | 7824 | file_name_only++; |
ee78dc32 | 7825 | |
6fc2811b JR |
7826 | strncpy (filename, file_name_only, MAX_PATH); |
7827 | filename[MAX_PATH] = '\0'; | |
7828 | } | |
ee78dc32 | 7829 | else |
6fc2811b | 7830 | filename[0] = '\0'; |
ee78dc32 | 7831 | |
1030b26b | 7832 | { |
7f2b4738 | 7833 | NEWOPENFILENAME new_file_details; |
ba6f3859 | 7834 | BOOL file_opened = FALSE; |
7f2b4738 | 7835 | OPENFILENAME * file_details = &new_file_details.real_details; |
21517c3d | 7836 | |
1030b26b JR |
7837 | /* Prevent redisplay. */ |
7838 | specbind (Qinhibit_redisplay, Qt); | |
7839 | BLOCK_INPUT; | |
ee78dc32 | 7840 | |
7f2b4738 JR |
7841 | bzero (&new_file_details, sizeof (new_file_details)); |
7842 | /* Apparently NT4 crashes if you give it an unexpected size. | |
7843 | I'm not sure about Windows 9x, so play it safe. */ | |
7844 | if (w32_major_version > 4 && w32_major_version < 95) | |
7845 | file_details->lStructSize = sizeof (new_file_details); | |
7846 | else | |
7847 | file_details->lStructSize = sizeof (file_details); | |
7848 | ||
7849 | file_details->hwndOwner = FRAME_W32_WINDOW (f); | |
1030b26b JR |
7850 | /* Undocumented Bug in Common File Dialog: |
7851 | If a filter is not specified, shell links are not resolved. */ | |
7f2b4738 JR |
7852 | file_details->lpstrFilter = "All Files (*.*)\0*.*\0Directories\0*|*\0\0"; |
7853 | file_details->lpstrFile = filename; | |
7854 | file_details->nMaxFile = sizeof (filename); | |
7855 | file_details->lpstrInitialDir = init_dir; | |
7856 | file_details->lpstrTitle = SDATA (prompt); | |
ef544dc8 | 7857 | |
f9d64bb3 | 7858 | if (! NILP (only_dir_p)) |
ef544dc8 JR |
7859 | default_filter_index = 2; |
7860 | ||
7f2b4738 | 7861 | file_details->nFilterIndex = default_filter_index; |
ef544dc8 | 7862 | |
7f2b4738 | 7863 | file_details->Flags = (OFN_HIDEREADONLY | OFN_NOCHANGEDIR |
1030b26b JR |
7864 | | OFN_EXPLORER | OFN_ENABLEHOOK); |
7865 | if (!NILP (mustmatch)) | |
7f2b4738 JR |
7866 | { |
7867 | /* Require that the path to the parent directory exists. */ | |
7868 | file_details->Flags |= OFN_PATHMUSTEXIST; | |
7869 | /* If we are looking for a file, require that it exists. */ | |
7870 | if (NILP (only_dir_p)) | |
7871 | file_details->Flags |= OFN_FILEMUSTEXIST; | |
7872 | } | |
1030b26b | 7873 | |
7f2b4738 | 7874 | file_details->lpfnHook = (LPOFNHOOKPROC) file_dialog_callback; |
1030b26b | 7875 | |
7f2b4738 | 7876 | file_opened = GetOpenFileName (file_details); |
ba6f3859 JR |
7877 | |
7878 | UNBLOCK_INPUT; | |
7879 | ||
7880 | if (file_opened) | |
1030b26b JR |
7881 | { |
7882 | dostounix_filename (filename); | |
7f2b4738 JR |
7883 | |
7884 | if (file_details->nFilterIndex == 2) | |
1030b26b | 7885 | { |
ef544dc8 | 7886 | /* "Directories" selected - strip dummy file name. */ |
1030b26b JR |
7887 | char * last = strrchr (filename, '/'); |
7888 | *last = '\0'; | |
7889 | } | |
6fc2811b | 7890 | |
1030b26b JR |
7891 | file = DECODE_FILE(build_string (filename)); |
7892 | } | |
7893 | /* User cancelled the dialog without making a selection. */ | |
7894 | else if (!CommDlgExtendedError ()) | |
7895 | file = Qnil; | |
7896 | /* An error occurred, fallback on reading from the mini-buffer. */ | |
7897 | else | |
7898 | file = Fcompleting_read (prompt, intern ("read-file-name-internal"), | |
7899 | dir, mustmatch, dir, Qfile_name_history, | |
7900 | default_filename, Qnil); | |
7901 | ||
1030b26b JR |
7902 | file = unbind_to (count, file); |
7903 | } | |
ee78dc32 | 7904 | |
6fc2811b | 7905 | UNGCPRO; |
1edf84e7 | 7906 | |
6fc2811b JR |
7907 | /* Make "Cancel" equivalent to C-g. */ |
7908 | if (NILP (file)) | |
7909 | Fsignal (Qquit, Qnil); | |
ee78dc32 | 7910 | |
dfff8a69 | 7911 | return unbind_to (count, file); |
6fc2811b | 7912 | } |
ee78dc32 | 7913 | |
ee78dc32 | 7914 | |
6fc2811b | 7915 | \f |
6fc2811b JR |
7916 | /*********************************************************************** |
7917 | w32 specialized functions | |
7918 | ***********************************************************************/ | |
ee78dc32 | 7919 | |
d84b082d | 7920 | DEFUN ("w32-select-font", Fw32_select_font, Sw32_select_font, 0, 2, 0, |
74e1aeec JR |
7921 | doc: /* Select a font using the W32 font dialog. |
7922 | Returns an X font string corresponding to the selection. */) | |
d84b082d JR |
7923 | (frame, include_proportional) |
7924 | Lisp_Object frame, include_proportional; | |
ee78dc32 GV |
7925 | { |
7926 | FRAME_PTR f = check_x_frame (frame); | |
7927 | CHOOSEFONT cf; | |
7928 | LOGFONT lf; | |
f46e6225 GV |
7929 | TEXTMETRIC tm; |
7930 | HDC hdc; | |
7931 | HANDLE oldobj; | |
ee78dc32 GV |
7932 | char buf[100]; |
7933 | ||
7934 | bzero (&cf, sizeof (cf)); | |
f46e6225 | 7935 | bzero (&lf, sizeof (lf)); |
ee78dc32 GV |
7936 | |
7937 | cf.lStructSize = sizeof (cf); | |
fbd6baed | 7938 | cf.hwndOwner = FRAME_W32_WINDOW (f); |
d84b082d JR |
7939 | cf.Flags = CF_FORCEFONTEXIST | CF_SCREENFONTS | CF_NOVERTFONTS; |
7940 | ||
7941 | /* Unless include_proportional is non-nil, limit the selection to | |
7942 | monospaced fonts. */ | |
7943 | if (NILP (include_proportional)) | |
7944 | cf.Flags |= CF_FIXEDPITCHONLY; | |
7945 | ||
ee78dc32 GV |
7946 | cf.lpLogFont = &lf; |
7947 | ||
f46e6225 GV |
7948 | /* Initialize as much of the font details as we can from the current |
7949 | default font. */ | |
7950 | hdc = GetDC (FRAME_W32_WINDOW (f)); | |
7951 | oldobj = SelectObject (hdc, FRAME_FONT (f)->hfont); | |
7952 | GetTextFace (hdc, LF_FACESIZE, lf.lfFaceName); | |
7953 | if (GetTextMetrics (hdc, &tm)) | |
7954 | { | |
7955 | lf.lfHeight = tm.tmInternalLeading - tm.tmHeight; | |
7956 | lf.lfWeight = tm.tmWeight; | |
7957 | lf.lfItalic = tm.tmItalic; | |
7958 | lf.lfUnderline = tm.tmUnderlined; | |
7959 | lf.lfStrikeOut = tm.tmStruckOut; | |
f46e6225 GV |
7960 | lf.lfCharSet = tm.tmCharSet; |
7961 | cf.Flags |= CF_INITTOLOGFONTSTRUCT; | |
7962 | } | |
7963 | SelectObject (hdc, oldobj); | |
6fc2811b | 7964 | ReleaseDC (FRAME_W32_WINDOW (f), hdc); |
f46e6225 | 7965 | |
767b1ff0 | 7966 | if (!ChooseFont (&cf) || !w32_to_x_font (&lf, buf, 100, NULL)) |
3c190163 | 7967 | return Qnil; |
ee78dc32 GV |
7968 | |
7969 | return build_string (buf); | |
7970 | } | |
7971 | ||
74e1aeec JR |
7972 | DEFUN ("w32-send-sys-command", Fw32_send_sys_command, |
7973 | Sw32_send_sys_command, 1, 2, 0, | |
7974 | doc: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND. | |
52deb19f | 7975 | Some useful values for COMMAND are #xf030 to maximize frame (#xf020 |
d84b082d JR |
7976 | to minimize), #xf120 to restore frame to original size, and #xf100 |
7977 | to activate the menubar for keyboard access. #xf140 activates the | |
74e1aeec JR |
7978 | screen saver if defined. |
7979 | ||
7980 | If optional parameter FRAME is not specified, use selected frame. */) | |
1edf84e7 GV |
7981 | (command, frame) |
7982 | Lisp_Object command, frame; | |
7983 | { | |
1edf84e7 GV |
7984 | FRAME_PTR f = check_x_frame (frame); |
7985 | ||
b7826503 | 7986 | CHECK_NUMBER (command); |
1edf84e7 | 7987 | |
ce6059da | 7988 | PostMessage (FRAME_W32_WINDOW (f), WM_SYSCOMMAND, XINT (command), 0); |
1edf84e7 GV |
7989 | |
7990 | return Qnil; | |
7991 | } | |
7992 | ||
55dcfc15 | 7993 | DEFUN ("w32-shell-execute", Fw32_shell_execute, Sw32_shell_execute, 2, 4, 0, |
74e1aeec JR |
7994 | doc: /* Get Windows to perform OPERATION on DOCUMENT. |
7995 | This is a wrapper around the ShellExecute system function, which | |
7996 | invokes the application registered to handle OPERATION for DOCUMENT. | |
7997 | OPERATION is typically \"open\", \"print\" or \"explore\" (but can be | |
7998 | nil for the default action), and DOCUMENT is typically the name of a | |
7999 | document file or URL, but can also be a program executable to run or | |
8000 | a directory to open in the Windows Explorer. | |
8001 | ||
8002 | If DOCUMENT is a program executable, PARAMETERS can be a string | |
8003 | containing command line parameters, but otherwise should be nil. | |
8004 | ||
8005 | SHOW-FLAG can be used to control whether the invoked application is hidden | |
8006 | or minimized. If SHOW-FLAG is nil, the application is displayed normally, | |
8007 | otherwise it is an integer representing a ShowWindow flag: | |
8008 | ||
8009 | 0 - start hidden | |
8010 | 1 - start normally | |
8011 | 3 - start maximized | |
8012 | 6 - start minimized */) | |
55dcfc15 AI |
8013 | (operation, document, parameters, show_flag) |
8014 | Lisp_Object operation, document, parameters, show_flag; | |
8015 | { | |
8016 | Lisp_Object current_dir; | |
8017 | ||
b7826503 | 8018 | CHECK_STRING (document); |
55dcfc15 AI |
8019 | |
8020 | /* Encode filename and current directory. */ | |
8021 | current_dir = ENCODE_FILE (current_buffer->directory); | |
8022 | document = ENCODE_FILE (document); | |
8023 | if ((int) ShellExecute (NULL, | |
6fc2811b | 8024 | (STRINGP (operation) ? |
d5db4077 KR |
8025 | SDATA (operation) : NULL), |
8026 | SDATA (document), | |
55dcfc15 | 8027 | (STRINGP (parameters) ? |
d5db4077 KR |
8028 | SDATA (parameters) : NULL), |
8029 | SDATA (current_dir), | |
55dcfc15 AI |
8030 | (INTEGERP (show_flag) ? |
8031 | XINT (show_flag) : SW_SHOWDEFAULT)) | |
8032 | > 32) | |
8033 | return Qt; | |
90d97e64 | 8034 | error ("ShellExecute failed: %s", w32_strerror (0)); |
55dcfc15 AI |
8035 | } |
8036 | ||
ccc2d29c GV |
8037 | /* Lookup virtual keycode from string representing the name of a |
8038 | non-ascii keystroke into the corresponding virtual key, using | |
8039 | lispy_function_keys. */ | |
8040 | static int | |
8041 | lookup_vk_code (char *key) | |
8042 | { | |
8043 | int i; | |
8044 | ||
8045 | for (i = 0; i < 256; i++) | |
8046 | if (lispy_function_keys[i] != 0 | |
8047 | && strcmp (lispy_function_keys[i], key) == 0) | |
8048 | return i; | |
8049 | ||
8050 | return -1; | |
8051 | } | |
8052 | ||
8053 | /* Convert a one-element vector style key sequence to a hot key | |
8054 | definition. */ | |
2ba49441 | 8055 | static Lisp_Object |
ccc2d29c GV |
8056 | w32_parse_hot_key (key) |
8057 | Lisp_Object key; | |
8058 | { | |
8059 | /* Copied from Fdefine_key and store_in_keymap. */ | |
8060 | register Lisp_Object c; | |
8061 | int vk_code; | |
8062 | int lisp_modifiers; | |
8063 | int w32_modifiers; | |
8064 | struct gcpro gcpro1; | |
8065 | ||
b7826503 | 8066 | CHECK_VECTOR (key); |
ccc2d29c GV |
8067 | |
8068 | if (XFASTINT (Flength (key)) != 1) | |
8069 | return Qnil; | |
8070 | ||
8071 | GCPRO1 (key); | |
8072 | ||
8073 | c = Faref (key, make_number (0)); | |
8074 | ||
8075 | if (CONSP (c) && lucid_event_type_list_p (c)) | |
8076 | c = Fevent_convert_list (c); | |
8077 | ||
8078 | UNGCPRO; | |
8079 | ||
8080 | if (! INTEGERP (c) && ! SYMBOLP (c)) | |
8081 | error ("Key definition is invalid"); | |
8082 | ||
8083 | /* Work out the base key and the modifiers. */ | |
8084 | if (SYMBOLP (c)) | |
8085 | { | |
8086 | c = parse_modifiers (c); | |
2ba49441 | 8087 | lisp_modifiers = XINT (Fcar (Fcdr (c))); |
ccc2d29c GV |
8088 | c = Fcar (c); |
8089 | if (!SYMBOLP (c)) | |
8090 | abort (); | |
d5db4077 | 8091 | vk_code = lookup_vk_code (SDATA (SYMBOL_NAME (c))); |
ccc2d29c GV |
8092 | } |
8093 | else if (INTEGERP (c)) | |
8094 | { | |
8095 | lisp_modifiers = XINT (c) & ~CHARACTERBITS; | |
8096 | /* Many ascii characters are their own virtual key code. */ | |
8097 | vk_code = XINT (c) & CHARACTERBITS; | |
8098 | } | |
8099 | ||
8100 | if (vk_code < 0 || vk_code > 255) | |
8101 | return Qnil; | |
8102 | ||
8103 | if ((lisp_modifiers & meta_modifier) != 0 | |
8104 | && !NILP (Vw32_alt_is_meta)) | |
8105 | lisp_modifiers |= alt_modifier; | |
8106 | ||
71eab8d1 AI |
8107 | /* Supply defs missing from mingw32. */ |
8108 | #ifndef MOD_ALT | |
8109 | #define MOD_ALT 0x0001 | |
8110 | #define MOD_CONTROL 0x0002 | |
8111 | #define MOD_SHIFT 0x0004 | |
8112 | #define MOD_WIN 0x0008 | |
8113 | #endif | |
8114 | ||
ccc2d29c GV |
8115 | /* Convert lisp modifiers to Windows hot-key form. */ |
8116 | w32_modifiers = (lisp_modifiers & hyper_modifier) ? MOD_WIN : 0; | |
8117 | w32_modifiers |= (lisp_modifiers & alt_modifier) ? MOD_ALT : 0; | |
8118 | w32_modifiers |= (lisp_modifiers & ctrl_modifier) ? MOD_CONTROL : 0; | |
8119 | w32_modifiers |= (lisp_modifiers & shift_modifier) ? MOD_SHIFT : 0; | |
8120 | ||
8121 | return HOTKEY (vk_code, w32_modifiers); | |
8122 | } | |
8123 | ||
74e1aeec JR |
8124 | DEFUN ("w32-register-hot-key", Fw32_register_hot_key, |
8125 | Sw32_register_hot_key, 1, 1, 0, | |
8126 | doc: /* Register KEY as a hot-key combination. | |
8127 | Certain key combinations like Alt-Tab are reserved for system use on | |
8128 | Windows, and therefore are normally intercepted by the system. However, | |
8129 | most of these key combinations can be received by registering them as | |
8130 | hot-keys, overriding their special meaning. | |
8131 | ||
8132 | KEY must be a one element key definition in vector form that would be | |
8133 | acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta | |
8134 | modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper | |
8135 | is always interpreted as the Windows modifier keys. | |
8136 | ||
8137 | The return value is the hotkey-id if registered, otherwise nil. */) | |
ccc2d29c GV |
8138 | (key) |
8139 | Lisp_Object key; | |
8140 | { | |
8141 | key = w32_parse_hot_key (key); | |
8142 | ||
8143 | if (NILP (Fmemq (key, w32_grabbed_keys))) | |
8144 | { | |
8145 | /* Reuse an empty slot if possible. */ | |
8146 | Lisp_Object item = Fmemq (Qnil, w32_grabbed_keys); | |
8147 | ||
8148 | /* Safe to add new key to list, even if we have focus. */ | |
8149 | if (NILP (item)) | |
8150 | w32_grabbed_keys = Fcons (key, w32_grabbed_keys); | |
8151 | else | |
f3fbd155 | 8152 | XSETCAR (item, key); |
ccc2d29c GV |
8153 | |
8154 | /* Notify input thread about new hot-key definition, so that it | |
8155 | takes effect without needing to switch focus. */ | |
2ba49441 JR |
8156 | #ifdef USE_LISP_UNION_TYPE |
8157 | PostThreadMessage (dwWindowsThreadId, WM_EMACS_REGISTER_HOT_KEY, | |
8158 | (WPARAM) key.i, 0); | |
8159 | #else | |
ccc2d29c GV |
8160 | PostThreadMessage (dwWindowsThreadId, WM_EMACS_REGISTER_HOT_KEY, |
8161 | (WPARAM) key, 0); | |
2ba49441 | 8162 | #endif |
ccc2d29c GV |
8163 | } |
8164 | ||
8165 | return key; | |
8166 | } | |
8167 | ||
74e1aeec JR |
8168 | DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key, |
8169 | Sw32_unregister_hot_key, 1, 1, 0, | |
52deb19f | 8170 | doc: /* Unregister KEY as a hot-key combination. */) |
ccc2d29c GV |
8171 | (key) |
8172 | Lisp_Object key; | |
8173 | { | |
8174 | Lisp_Object item; | |
8175 | ||
8176 | if (!INTEGERP (key)) | |
8177 | key = w32_parse_hot_key (key); | |
8178 | ||
8179 | item = Fmemq (key, w32_grabbed_keys); | |
8180 | ||
8181 | if (!NILP (item)) | |
8182 | { | |
8183 | /* Notify input thread about hot-key definition being removed, so | |
8184 | that it takes effect without needing focus switch. */ | |
2ba49441 JR |
8185 | #ifdef USE_LISP_UNION_TYPE |
8186 | if (PostThreadMessage (dwWindowsThreadId, WM_EMACS_UNREGISTER_HOT_KEY, | |
8187 | (WPARAM) XINT (XCAR (item)), (LPARAM) item.i)) | |
8188 | #else | |
ccc2d29c | 8189 | if (PostThreadMessage (dwWindowsThreadId, WM_EMACS_UNREGISTER_HOT_KEY, |
6dd6baa5 | 8190 | (WPARAM) XINT (XCAR (item)), (LPARAM) item)) |
2ba49441 JR |
8191 | |
8192 | #endif | |
ccc2d29c GV |
8193 | { |
8194 | MSG msg; | |
8195 | GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE); | |
8196 | } | |
8197 | return Qt; | |
8198 | } | |
8199 | return Qnil; | |
8200 | } | |
8201 | ||
74e1aeec JR |
8202 | DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys, |
8203 | Sw32_registered_hot_keys, 0, 0, 0, | |
8204 | doc: /* Return list of registered hot-key IDs. */) | |
ccc2d29c GV |
8205 | () |
8206 | { | |
8207 | return Fcopy_sequence (w32_grabbed_keys); | |
8208 | } | |
8209 | ||
74e1aeec JR |
8210 | DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key, |
8211 | Sw32_reconstruct_hot_key, 1, 1, 0, | |
52deb19f JB |
8212 | doc: /* Convert hot-key ID to a lisp key combination. |
8213 | usage: (w32-reconstruct-hot-key ID) */) | |
ccc2d29c GV |
8214 | (hotkeyid) |
8215 | Lisp_Object hotkeyid; | |
8216 | { | |
8217 | int vk_code, w32_modifiers; | |
8218 | Lisp_Object key; | |
8219 | ||
b7826503 | 8220 | CHECK_NUMBER (hotkeyid); |
ccc2d29c GV |
8221 | |
8222 | vk_code = HOTKEY_VK_CODE (hotkeyid); | |
8223 | w32_modifiers = HOTKEY_MODIFIERS (hotkeyid); | |
8224 | ||
8225 | if (lispy_function_keys[vk_code]) | |
8226 | key = intern (lispy_function_keys[vk_code]); | |
8227 | else | |
8228 | key = make_number (vk_code); | |
8229 | ||
8230 | key = Fcons (key, Qnil); | |
8231 | if (w32_modifiers & MOD_SHIFT) | |
3ef68e6b | 8232 | key = Fcons (Qshift, key); |
ccc2d29c | 8233 | if (w32_modifiers & MOD_CONTROL) |
3ef68e6b | 8234 | key = Fcons (Qctrl, key); |
ccc2d29c | 8235 | if (w32_modifiers & MOD_ALT) |
3ef68e6b | 8236 | key = Fcons (NILP (Vw32_alt_is_meta) ? Qalt : Qmeta, key); |
ccc2d29c | 8237 | if (w32_modifiers & MOD_WIN) |
3ef68e6b | 8238 | key = Fcons (Qhyper, key); |
ccc2d29c GV |
8239 | |
8240 | return key; | |
8241 | } | |
adcc3809 | 8242 | |
74e1aeec JR |
8243 | DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key, |
8244 | Sw32_toggle_lock_key, 1, 2, 0, | |
8245 | doc: /* Toggle the state of the lock key KEY. | |
8246 | KEY can be `capslock', `kp-numlock', or `scroll'. | |
8247 | If the optional parameter NEW-STATE is a number, then the state of KEY | |
8248 | is set to off if the low bit of NEW-STATE is zero, otherwise on. */) | |
adcc3809 GV |
8249 | (key, new_state) |
8250 | Lisp_Object key, new_state; | |
8251 | { | |
8252 | int vk_code; | |
adcc3809 GV |
8253 | |
8254 | if (EQ (key, intern ("capslock"))) | |
8255 | vk_code = VK_CAPITAL; | |
8256 | else if (EQ (key, intern ("kp-numlock"))) | |
8257 | vk_code = VK_NUMLOCK; | |
8258 | else if (EQ (key, intern ("scroll"))) | |
8259 | vk_code = VK_SCROLL; | |
8260 | else | |
8261 | return Qnil; | |
8262 | ||
8263 | if (!dwWindowsThreadId) | |
8264 | return make_number (w32_console_toggle_lock_key (vk_code, new_state)); | |
8265 | ||
2ba49441 JR |
8266 | #ifdef USE_LISP_UNION_TYPE |
8267 | if (PostThreadMessage (dwWindowsThreadId, WM_EMACS_TOGGLE_LOCK_KEY, | |
8268 | (WPARAM) vk_code, (LPARAM) new_state.i)) | |
8269 | #else | |
adcc3809 | 8270 | if (PostThreadMessage (dwWindowsThreadId, WM_EMACS_TOGGLE_LOCK_KEY, |
6dd6baa5 | 8271 | (WPARAM) vk_code, (LPARAM) new_state)) |
2ba49441 | 8272 | #endif |
adcc3809 GV |
8273 | { |
8274 | MSG msg; | |
8275 | GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE); | |
8276 | return make_number (msg.wParam); | |
8277 | } | |
8278 | return Qnil; | |
8279 | } | |
ee78dc32 | 8280 | \f |
2254bcde | 8281 | DEFUN ("file-system-info", Ffile_system_info, Sfile_system_info, 1, 1, 0, |
74e1aeec JR |
8282 | doc: /* Return storage information about the file system FILENAME is on. |
8283 | Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total | |
8284 | storage of the file system, FREE is the free storage, and AVAIL is the | |
8285 | storage available to a non-superuser. All 3 numbers are in bytes. | |
8286 | If the underlying system call fails, value is nil. */) | |
2254bcde AI |
8287 | (filename) |
8288 | Lisp_Object filename; | |
8289 | { | |
8290 | Lisp_Object encoded, value; | |
8291 | ||
b7826503 | 8292 | CHECK_STRING (filename); |
2254bcde AI |
8293 | filename = Fexpand_file_name (filename, Qnil); |
8294 | encoded = ENCODE_FILE (filename); | |
8295 | ||
8296 | value = Qnil; | |
8297 | ||
8298 | /* Determining the required information on Windows turns out, sadly, | |
8299 | to be more involved than one would hope. The original Win32 api | |
8300 | call for this will return bogus information on some systems, but we | |
8301 | must dynamically probe for the replacement api, since that was | |
8302 | added rather late on. */ | |
8303 | { | |
8304 | HMODULE hKernel = GetModuleHandle ("kernel32"); | |
8305 | BOOL (*pfn_GetDiskFreeSpaceEx) | |
8306 | (char *, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER) | |
8307 | = (void *) GetProcAddress (hKernel, "GetDiskFreeSpaceEx"); | |
8308 | ||
8309 | /* On Windows, we may need to specify the root directory of the | |
8310 | volume holding FILENAME. */ | |
8311 | char rootname[MAX_PATH]; | |
d5db4077 | 8312 | char *name = SDATA (encoded); |
2254bcde AI |
8313 | |
8314 | /* find the root name of the volume if given */ | |
8315 | if (isalpha (name[0]) && name[1] == ':') | |
8316 | { | |
8317 | rootname[0] = name[0]; | |
8318 | rootname[1] = name[1]; | |
8319 | rootname[2] = '\\'; | |
8320 | rootname[3] = 0; | |
8321 | } | |
8322 | else if (IS_DIRECTORY_SEP (name[0]) && IS_DIRECTORY_SEP (name[1])) | |
8323 | { | |
8324 | char *str = rootname; | |
8325 | int slashes = 4; | |
8326 | do | |
8327 | { | |
8328 | if (IS_DIRECTORY_SEP (*name) && --slashes == 0) | |
8329 | break; | |
8330 | *str++ = *name++; | |
8331 | } | |
8332 | while ( *name ); | |
8333 | ||
8334 | *str++ = '\\'; | |
8335 | *str = 0; | |
8336 | } | |
8337 | ||
8338 | if (pfn_GetDiskFreeSpaceEx) | |
8339 | { | |
ac849ba4 JR |
8340 | /* Unsigned large integers cannot be cast to double, so |
8341 | use signed ones instead. */ | |
2254bcde AI |
8342 | LARGE_INTEGER availbytes; |
8343 | LARGE_INTEGER freebytes; | |
8344 | LARGE_INTEGER totalbytes; | |
8345 | ||
8346 | if (pfn_GetDiskFreeSpaceEx(rootname, | |
ac849ba4 JR |
8347 | (ULARGE_INTEGER *)&availbytes, |
8348 | (ULARGE_INTEGER *)&totalbytes, | |
8349 | (ULARGE_INTEGER *)&freebytes)) | |
2254bcde AI |
8350 | value = list3 (make_float ((double) totalbytes.QuadPart), |
8351 | make_float ((double) freebytes.QuadPart), | |
8352 | make_float ((double) availbytes.QuadPart)); | |
8353 | } | |
8354 | else | |
8355 | { | |
8356 | DWORD sectors_per_cluster; | |
8357 | DWORD bytes_per_sector; | |
8358 | DWORD free_clusters; | |
8359 | DWORD total_clusters; | |
8360 | ||
8361 | if (GetDiskFreeSpace(rootname, | |
8362 | §ors_per_cluster, | |
8363 | &bytes_per_sector, | |
8364 | &free_clusters, | |
8365 | &total_clusters)) | |
8366 | value = list3 (make_float ((double) total_clusters | |
8367 | * sectors_per_cluster * bytes_per_sector), | |
8368 | make_float ((double) free_clusters | |
8369 | * sectors_per_cluster * bytes_per_sector), | |
8370 | make_float ((double) free_clusters | |
8371 | * sectors_per_cluster * bytes_per_sector)); | |
8372 | } | |
8373 | } | |
8374 | ||
8375 | return value; | |
8376 | } | |
8377 | \f | |
39a0e135 JR |
8378 | DEFUN ("default-printer-name", Fdefault_printer_name, Sdefault_printer_name, |
8379 | 0, 0, 0, doc: /* Return the name of Windows default printer device. */) | |
8380 | () | |
8381 | { | |
8382 | static char pname_buf[256]; | |
8383 | int err; | |
8384 | HANDLE hPrn; | |
8385 | PRINTER_INFO_2 *ppi2 = NULL; | |
8386 | DWORD dwNeeded = 0, dwReturned = 0; | |
8387 | ||
8388 | /* Retrieve the default string from Win.ini (the registry). | |
8389 | * String will be in form "printername,drivername,portname". | |
8390 | * This is the most portable way to get the default printer. */ | |
8391 | if (GetProfileString ("windows", "device", ",,", pname_buf, sizeof (pname_buf)) <= 0) | |
8392 | return Qnil; | |
8393 | /* printername precedes first "," character */ | |
8394 | strtok (pname_buf, ","); | |
8395 | /* We want to know more than the printer name */ | |
8396 | if (!OpenPrinter (pname_buf, &hPrn, NULL)) | |
8397 | return Qnil; | |
8398 | GetPrinter (hPrn, 2, NULL, 0, &dwNeeded); | |
8399 | if (dwNeeded == 0) | |
8400 | { | |
8401 | ClosePrinter (hPrn); | |
8402 | return Qnil; | |
8403 | } | |
8404 | /* Allocate memory for the PRINTER_INFO_2 struct */ | |
8405 | ppi2 = (PRINTER_INFO_2 *) xmalloc (dwNeeded); | |
8406 | if (!ppi2) | |
8407 | { | |
8408 | ClosePrinter (hPrn); | |
8409 | return Qnil; | |
8410 | } | |
8411 | /* Call GetPrinter() again with big enouth memory block */ | |
8412 | err = GetPrinter (hPrn, 2, (LPBYTE)ppi2, dwNeeded, &dwReturned); | |
8413 | ClosePrinter (hPrn); | |
8414 | if (!err) | |
8415 | { | |
8416 | xfree(ppi2); | |
8417 | return Qnil; | |
8418 | } | |
8419 | ||
8420 | if (ppi2) | |
8421 | { | |
8422 | if (ppi2->Attributes & PRINTER_ATTRIBUTE_SHARED && ppi2->pServerName) | |
8423 | { | |
8424 | /* a remote printer */ | |
8425 | if (*ppi2->pServerName == '\\') | |
8426 | _snprintf(pname_buf, sizeof (pname_buf), "%s\\%s", ppi2->pServerName, | |
8427 | ppi2->pShareName); | |
8428 | else | |
8429 | _snprintf(pname_buf, sizeof (pname_buf), "\\\\%s\\%s", ppi2->pServerName, | |
8430 | ppi2->pShareName); | |
8431 | pname_buf[sizeof (pname_buf) - 1] = '\0'; | |
8432 | } | |
8433 | else | |
8434 | { | |
8435 | /* a local printer */ | |
8436 | strncpy(pname_buf, ppi2->pPortName, sizeof (pname_buf)); | |
8437 | pname_buf[sizeof (pname_buf) - 1] = '\0'; | |
8438 | /* `pPortName' can include several ports, delimited by ','. | |
8439 | * we only use the first one. */ | |
8440 | strtok(pname_buf, ","); | |
8441 | } | |
8442 | xfree(ppi2); | |
8443 | } | |
8444 | ||
8445 | return build_string (pname_buf); | |
8446 | } | |
8447 | \f | |
0e3fcdef JR |
8448 | /*********************************************************************** |
8449 | Initialization | |
8450 | ***********************************************************************/ | |
8451 | ||
52deb19f | 8452 | /* Keep this list in the same order as frame_parms in frame.c. |
6d906347 KS |
8453 | Use 0 for unsupported frame parameters. */ |
8454 | ||
8455 | frame_parm_handler w32_frame_parm_handlers[] = | |
8456 | { | |
8457 | x_set_autoraise, | |
8458 | x_set_autolower, | |
8459 | x_set_background_color, | |
8460 | x_set_border_color, | |
8461 | x_set_border_width, | |
8462 | x_set_cursor_color, | |
8463 | x_set_cursor_type, | |
8464 | x_set_font, | |
8465 | x_set_foreground_color, | |
8466 | x_set_icon_name, | |
8467 | x_set_icon_type, | |
8468 | x_set_internal_border_width, | |
8469 | x_set_menu_bar_lines, | |
8470 | x_set_mouse_color, | |
8471 | x_explicitly_set_name, | |
8472 | x_set_scroll_bar_width, | |
8473 | x_set_title, | |
8474 | x_set_unsplittable, | |
8475 | x_set_vertical_scroll_bars, | |
8476 | x_set_visibility, | |
8477 | x_set_tool_bar_lines, | |
8478 | 0, /* x_set_scroll_bar_foreground, */ | |
8479 | 0, /* x_set_scroll_bar_background, */ | |
8480 | x_set_screen_gamma, | |
8481 | x_set_line_spacing, | |
8482 | x_set_fringe_width, | |
8483 | x_set_fringe_width, | |
8484 | 0, /* x_set_wait_for_wm, */ | |
8485 | x_set_fullscreen, | |
8486 | }; | |
8487 | ||
0e3fcdef | 8488 | void |
fbd6baed | 8489 | syms_of_w32fns () |
ee78dc32 | 8490 | { |
afc390dc JR |
8491 | globals_of_w32fns (); |
8492 | /* This is zero if not using MS-Windows. */ | |
1edf84e7 | 8493 | w32_in_use = 0; |
9eb16b62 JR |
8494 | track_mouse_window = NULL; |
8495 | ||
d285988b JR |
8496 | w32_visible_system_caret_hwnd = NULL; |
8497 | ||
ee78dc32 GV |
8498 | Qnone = intern ("none"); |
8499 | staticpro (&Qnone); | |
ee78dc32 GV |
8500 | Qsuppress_icon = intern ("suppress-icon"); |
8501 | staticpro (&Qsuppress_icon); | |
ee78dc32 GV |
8502 | Qundefined_color = intern ("undefined-color"); |
8503 | staticpro (&Qundefined_color); | |
dc220243 JR |
8504 | Qcancel_timer = intern ("cancel-timer"); |
8505 | staticpro (&Qcancel_timer); | |
ee78dc32 | 8506 | |
adcc3809 GV |
8507 | Qhyper = intern ("hyper"); |
8508 | staticpro (&Qhyper); | |
8509 | Qsuper = intern ("super"); | |
8510 | staticpro (&Qsuper); | |
8511 | Qmeta = intern ("meta"); | |
8512 | staticpro (&Qmeta); | |
8513 | Qalt = intern ("alt"); | |
8514 | staticpro (&Qalt); | |
8515 | Qctrl = intern ("ctrl"); | |
8516 | staticpro (&Qctrl); | |
8517 | Qcontrol = intern ("control"); | |
8518 | staticpro (&Qcontrol); | |
8519 | Qshift = intern ("shift"); | |
8520 | staticpro (&Qshift); | |
f7b9d4d1 | 8521 | /* This is the end of symbol initialization. */ |
adcc3809 | 8522 | |
6fc2811b JR |
8523 | /* Text property `display' should be nonsticky by default. */ |
8524 | Vtext_property_default_nonsticky | |
8525 | = Fcons (Fcons (Qdisplay, Qt), Vtext_property_default_nonsticky); | |
8526 | ||
8527 | ||
ee78dc32 GV |
8528 | Fput (Qundefined_color, Qerror_conditions, |
8529 | Fcons (Qundefined_color, Fcons (Qerror, Qnil))); | |
8530 | Fput (Qundefined_color, Qerror_message, | |
8531 | build_string ("Undefined color")); | |
8532 | ||
ccc2d29c GV |
8533 | staticpro (&w32_grabbed_keys); |
8534 | w32_grabbed_keys = Qnil; | |
8535 | ||
fbd6baed | 8536 | DEFVAR_LISP ("w32-color-map", &Vw32_color_map, |
52deb19f | 8537 | doc: /* An array of color name mappings for Windows. */); |
fbd6baed | 8538 | Vw32_color_map = Qnil; |
ee78dc32 | 8539 | |
fbd6baed | 8540 | DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system, |
74e1aeec JR |
8541 | doc: /* Non-nil if alt key presses are passed on to Windows. |
8542 | When non-nil, for example, alt pressed and released and then space will | |
8543 | open the System menu. When nil, Emacs silently swallows alt key events. */); | |
fbd6baed | 8544 | Vw32_pass_alt_to_system = Qnil; |
da36a4d6 | 8545 | |
fbd6baed | 8546 | DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta, |
74e1aeec JR |
8547 | doc: /* Non-nil if the alt key is to be considered the same as the meta key. |
8548 | When nil, Emacs will translate the alt key to the Alt modifier, and not Meta. */); | |
fbd6baed | 8549 | Vw32_alt_is_meta = Qt; |
8c205c63 | 8550 | |
2ba49441 JR |
8551 | DEFVAR_INT ("w32-quit-key", &w32_quit_key, |
8552 | doc: /* If non-zero, the virtual key code for an alternative quit key. */); | |
8553 | w32_quit_key = 0; | |
7d081355 | 8554 | |
7d0393cf | 8555 | DEFVAR_LISP ("w32-pass-lwindow-to-system", |
ccc2d29c | 8556 | &Vw32_pass_lwindow_to_system, |
74e1aeec JR |
8557 | doc: /* Non-nil if the left \"Windows\" key is passed on to Windows. |
8558 | When non-nil, the Start menu is opened by tapping the key. */); | |
ccc2d29c GV |
8559 | Vw32_pass_lwindow_to_system = Qt; |
8560 | ||
7d0393cf | 8561 | DEFVAR_LISP ("w32-pass-rwindow-to-system", |
ccc2d29c | 8562 | &Vw32_pass_rwindow_to_system, |
74e1aeec JR |
8563 | doc: /* Non-nil if the right \"Windows\" key is passed on to Windows. |
8564 | When non-nil, the Start menu is opened by tapping the key. */); | |
ccc2d29c GV |
8565 | Vw32_pass_rwindow_to_system = Qt; |
8566 | ||
2ba49441 | 8567 | DEFVAR_LISP ("w32-phantom-key-code", |
adcc3809 | 8568 | &Vw32_phantom_key_code, |
2ba49441 | 8569 | doc: /* Virtual key code used to generate \"phantom\" key presses. |
74e1aeec JR |
8570 | Value is a number between 0 and 255. |
8571 | ||
8572 | Phantom key presses are generated in order to stop the system from | |
8573 | acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or | |
8574 | `w32-pass-rwindow-to-system' is nil. */); | |
ce6059da AI |
8575 | /* Although 255 is technically not a valid key code, it works and |
8576 | means that this hack won't interfere with any real key code. */ | |
2ba49441 | 8577 | XSETINT (Vw32_phantom_key_code, 255); |
adcc3809 | 8578 | |
7d0393cf | 8579 | DEFVAR_LISP ("w32-enable-num-lock", |
ccc2d29c | 8580 | &Vw32_enable_num_lock, |
74e1aeec JR |
8581 | doc: /* Non-nil if Num Lock should act normally. |
8582 | Set to nil to see Num Lock as the key `kp-numlock'. */); | |
ccc2d29c GV |
8583 | Vw32_enable_num_lock = Qt; |
8584 | ||
7d0393cf | 8585 | DEFVAR_LISP ("w32-enable-caps-lock", |
ccc2d29c | 8586 | &Vw32_enable_caps_lock, |
74e1aeec JR |
8587 | doc: /* Non-nil if Caps Lock should act normally. |
8588 | Set to nil to see Caps Lock as the key `capslock'. */); | |
ccc2d29c GV |
8589 | Vw32_enable_caps_lock = Qt; |
8590 | ||
8591 | DEFVAR_LISP ("w32-scroll-lock-modifier", | |
8592 | &Vw32_scroll_lock_modifier, | |
74e1aeec JR |
8593 | doc: /* Modifier to use for the Scroll Lock on state. |
8594 | The value can be hyper, super, meta, alt, control or shift for the | |
8595 | respective modifier, or nil to see Scroll Lock as the key `scroll'. | |
8596 | Any other value will cause the key to be ignored. */); | |
ccc2d29c GV |
8597 | Vw32_scroll_lock_modifier = Qt; |
8598 | ||
8599 | DEFVAR_LISP ("w32-lwindow-modifier", | |
8600 | &Vw32_lwindow_modifier, | |
74e1aeec JR |
8601 | doc: /* Modifier to use for the left \"Windows\" key. |
8602 | The value can be hyper, super, meta, alt, control or shift for the | |
8603 | respective modifier, or nil to appear as the key `lwindow'. | |
8604 | Any other value will cause the key to be ignored. */); | |
ccc2d29c GV |
8605 | Vw32_lwindow_modifier = Qnil; |
8606 | ||
8607 | DEFVAR_LISP ("w32-rwindow-modifier", | |
8608 | &Vw32_rwindow_modifier, | |
74e1aeec JR |
8609 | doc: /* Modifier to use for the right \"Windows\" key. |
8610 | The value can be hyper, super, meta, alt, control or shift for the | |
8611 | respective modifier, or nil to appear as the key `rwindow'. | |
8612 | Any other value will cause the key to be ignored. */); | |
ccc2d29c GV |
8613 | Vw32_rwindow_modifier = Qnil; |
8614 | ||
8615 | DEFVAR_LISP ("w32-apps-modifier", | |
8616 | &Vw32_apps_modifier, | |
74e1aeec JR |
8617 | doc: /* Modifier to use for the \"Apps\" key. |
8618 | The value can be hyper, super, meta, alt, control or shift for the | |
8619 | respective modifier, or nil to appear as the key `apps'. | |
8620 | Any other value will cause the key to be ignored. */); | |
ccc2d29c | 8621 | Vw32_apps_modifier = Qnil; |
da36a4d6 | 8622 | |
d84b082d | 8623 | DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts, |
74e1aeec | 8624 | doc: /* Non-nil enables selection of artificially italicized and bold fonts. */); |
d84b082d | 8625 | w32_enable_synthesized_fonts = 0; |
5ac45f98 | 8626 | |
fbd6baed | 8627 | DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette, |
74e1aeec | 8628 | doc: /* Non-nil enables Windows palette management to map colors exactly. */); |
fbd6baed | 8629 | Vw32_enable_palette = Qt; |
5ac45f98 | 8630 | |
fbd6baed | 8631 | DEFVAR_INT ("w32-mouse-button-tolerance", |
2ba49441 | 8632 | &w32_mouse_button_tolerance, |
74e1aeec JR |
8633 | doc: /* Analogue of double click interval for faking middle mouse events. |
8634 | The value is the minimum time in milliseconds that must elapse between | |
8635 | left/right button down events before they are considered distinct events. | |
8636 | If both mouse buttons are depressed within this interval, a middle mouse | |
8637 | button down event is generated instead. */); | |
2ba49441 | 8638 | w32_mouse_button_tolerance = GetDoubleClickTime () / 2; |
5ac45f98 | 8639 | |
fbd6baed | 8640 | DEFVAR_INT ("w32-mouse-move-interval", |
2ba49441 | 8641 | &w32_mouse_move_interval, |
74e1aeec JR |
8642 | doc: /* Minimum interval between mouse move events. |
8643 | The value is the minimum time in milliseconds that must elapse between | |
8644 | successive mouse move (or scroll bar drag) events before they are | |
8645 | reported as lisp events. */); | |
2ba49441 | 8646 | w32_mouse_move_interval = 0; |
84fb1139 | 8647 | |
74214547 JR |
8648 | DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system", |
8649 | &w32_pass_extra_mouse_buttons_to_system, | |
8650 | doc: /* Non-nil if the fourth and fifth mouse buttons are passed to Windows. | |
8651 | Recent versions of Windows support mice with up to five buttons. | |
8652 | Since most applications don't support these extra buttons, most mouse | |
8653 | drivers will allow you to map them to functions at the system level. | |
8654 | If this variable is non-nil, Emacs will pass them on, allowing the | |
8655 | system to handle them. */); | |
8656 | w32_pass_extra_mouse_buttons_to_system = 0; | |
8657 | ||
ee78dc32 | 8658 | DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape, |
74e1aeec JR |
8659 | doc: /* The shape of the pointer when over text. |
8660 | Changing the value does not affect existing frames | |
8661 | unless you set the mouse color. */); | |
ee78dc32 GV |
8662 | Vx_pointer_shape = Qnil; |
8663 | ||
ee78dc32 GV |
8664 | Vx_nontext_pointer_shape = Qnil; |
8665 | ||
8666 | Vx_mode_pointer_shape = Qnil; | |
8667 | ||
0af913d7 | 8668 | DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape, |
74e1aeec JR |
8669 | doc: /* The shape of the pointer when Emacs is busy. |
8670 | This variable takes effect when you create a new frame | |
8671 | or when you set the mouse color. */); | |
0af913d7 | 8672 | Vx_hourglass_pointer_shape = Qnil; |
6fc2811b | 8673 | |
0af913d7 | 8674 | DEFVAR_BOOL ("display-hourglass", &display_hourglass_p, |
74e1aeec | 8675 | doc: /* Non-zero means Emacs displays an hourglass pointer on window systems. */); |
0af913d7 | 8676 | display_hourglass_p = 1; |
7d0393cf | 8677 | |
0af913d7 | 8678 | DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay, |
74e1aeec JR |
8679 | doc: /* *Seconds to wait before displaying an hourglass pointer. |
8680 | Value must be an integer or float. */); | |
0af913d7 | 8681 | Vhourglass_delay = make_number (DEFAULT_HOURGLASS_DELAY); |
f79e6790 | 8682 | |
6fc2811b | 8683 | DEFVAR_LISP ("x-sensitive-text-pointer-shape", |
ee78dc32 | 8684 | &Vx_sensitive_text_pointer_shape, |
74e1aeec JR |
8685 | doc: /* The shape of the pointer when over mouse-sensitive text. |
8686 | This variable takes effect when you create a new frame | |
8687 | or when you set the mouse color. */); | |
ee78dc32 GV |
8688 | Vx_sensitive_text_pointer_shape = Qnil; |
8689 | ||
4694d762 JR |
8690 | DEFVAR_LISP ("x-window-horizontal-drag-cursor", |
8691 | &Vx_window_horizontal_drag_shape, | |
74e1aeec JR |
8692 | doc: /* Pointer shape to use for indicating a window can be dragged horizontally. |
8693 | This variable takes effect when you create a new frame | |
8694 | or when you set the mouse color. */); | |
4694d762 JR |
8695 | Vx_window_horizontal_drag_shape = Qnil; |
8696 | ||
ee78dc32 | 8697 | DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel, |
74e1aeec | 8698 | doc: /* A string indicating the foreground color of the cursor box. */); |
ee78dc32 GV |
8699 | Vx_cursor_fore_pixel = Qnil; |
8700 | ||
3cf3436e | 8701 | DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size, |
b3700ae7 JR |
8702 | doc: /* Maximum size for tooltips. |
8703 | Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */); | |
3cf3436e | 8704 | Vx_max_tooltip_size = Fcons (make_number (80), make_number (40)); |
7d0393cf | 8705 | |
ee78dc32 | 8706 | DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager, |
74e1aeec JR |
8707 | doc: /* Non-nil if no window manager is in use. |
8708 | Emacs doesn't try to figure this out; this is always nil | |
8709 | unless you set it to something else. */); | |
ee78dc32 GV |
8710 | /* We don't have any way to find this out, so set it to nil |
8711 | and maybe the user would like to set it to t. */ | |
8712 | Vx_no_window_manager = Qnil; | |
8713 | ||
4587b026 GV |
8714 | DEFVAR_LISP ("x-pixel-size-width-font-regexp", |
8715 | &Vx_pixel_size_width_font_regexp, | |
74e1aeec JR |
8716 | doc: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. |
8717 | ||
8718 | Since Emacs gets width of a font matching with this regexp from | |
8719 | PIXEL_SIZE field of the name, font finding mechanism gets faster for | |
8720 | such a font. This is especially effective for such large fonts as | |
8721 | Chinese, Japanese, and Korean. */); | |
4587b026 GV |
8722 | Vx_pixel_size_width_font_regexp = Qnil; |
8723 | ||
33d52f9c GV |
8724 | DEFVAR_LISP ("w32-bdf-filename-alist", |
8725 | &Vw32_bdf_filename_alist, | |
74e1aeec | 8726 | doc: /* List of bdf fonts and their corresponding filenames. */); |
33d52f9c GV |
8727 | Vw32_bdf_filename_alist = Qnil; |
8728 | ||
1075afa9 GV |
8729 | DEFVAR_BOOL ("w32-strict-fontnames", |
8730 | &w32_strict_fontnames, | |
74e1aeec JR |
8731 | doc: /* Non-nil means only use fonts that are exact matches for those requested. |
8732 | Default is nil, which allows old fontnames that are not XLFD compliant, | |
8733 | and allows third-party CJK display to work by specifying false charset | |
8734 | fields to trick Emacs into translating to Big5, SJIS etc. | |
8735 | Setting this to t will prevent wrong fonts being selected when | |
8736 | fontsets are automatically created. */); | |
1075afa9 GV |
8737 | w32_strict_fontnames = 0; |
8738 | ||
c0611964 AI |
8739 | DEFVAR_BOOL ("w32-strict-painting", |
8740 | &w32_strict_painting, | |
74e1aeec | 8741 | doc: /* Non-nil means use strict rules for repainting frames. |
a8ab3e96 | 8742 | Set this to nil to get the old behavior for repainting; this should |
74e1aeec | 8743 | only be necessary if the default setting causes problems. */); |
c0611964 AI |
8744 | w32_strict_painting = 1; |
8745 | ||
dfff8a69 JR |
8746 | DEFVAR_LISP ("w32-charset-info-alist", |
8747 | &Vw32_charset_info_alist, | |
b3700ae7 JR |
8748 | doc: /* Alist linking Emacs character sets to Windows fonts and codepages. |
8749 | Each entry should be of the form: | |
74e1aeec JR |
8750 | |
8751 | (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)) | |
8752 | ||
8753 | where CHARSET_NAME is a string used in font names to identify the charset, | |
8754 | WINDOWS_CHARSET is a symbol that can be one of: | |
8755 | w32-charset-ansi, w32-charset-default, w32-charset-symbol, | |
8756 | w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312, | |
8757 | w32-charset-chinesebig5, | |
74e1aeec JR |
8758 | w32-charset-johab, w32-charset-hebrew, |
8759 | w32-charset-arabic, w32-charset-greek, w32-charset-turkish, | |
8760 | w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope, | |
8761 | w32-charset-russian, w32-charset-mac, w32-charset-baltic, | |
74e1aeec | 8762 | w32-charset-unicode, |
74e1aeec JR |
8763 | or w32-charset-oem. |
8764 | CODEPAGE should be an integer specifying the codepage that should be used | |
8765 | to display the character set, t to do no translation and output as Unicode, | |
8766 | or nil to do no translation and output as 8 bit (or multibyte on far-east | |
8767 | versions of Windows) characters. */); | |
dfff8a69 JR |
8768 | Vw32_charset_info_alist = Qnil; |
8769 | ||
8770 | staticpro (&Qw32_charset_ansi); | |
8771 | Qw32_charset_ansi = intern ("w32-charset-ansi"); | |
8772 | staticpro (&Qw32_charset_symbol); | |
829b13e2 KS |
8773 | Qw32_charset_default = intern ("w32-charset-default"); |
8774 | staticpro (&Qw32_charset_default); | |
dfff8a69 JR |
8775 | Qw32_charset_symbol = intern ("w32-charset-symbol"); |
8776 | staticpro (&Qw32_charset_shiftjis); | |
8777 | Qw32_charset_shiftjis = intern ("w32-charset-shiftjis"); | |
767b1ff0 JR |
8778 | staticpro (&Qw32_charset_hangeul); |
8779 | Qw32_charset_hangeul = intern ("w32-charset-hangeul"); | |
dfff8a69 JR |
8780 | staticpro (&Qw32_charset_chinesebig5); |
8781 | Qw32_charset_chinesebig5 = intern ("w32-charset-chinesebig5"); | |
8782 | staticpro (&Qw32_charset_gb2312); | |
8783 | Qw32_charset_gb2312 = intern ("w32-charset-gb2312"); | |
8784 | staticpro (&Qw32_charset_oem); | |
8785 | Qw32_charset_oem = intern ("w32-charset-oem"); | |
8786 | ||
8787 | #ifdef JOHAB_CHARSET | |
8788 | { | |
8789 | static int w32_extra_charsets_defined = 1; | |
74e1aeec JR |
8790 | DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined, |
8791 | doc: /* Internal variable. */); | |
dfff8a69 JR |
8792 | |
8793 | staticpro (&Qw32_charset_johab); | |
8794 | Qw32_charset_johab = intern ("w32-charset-johab"); | |
8795 | staticpro (&Qw32_charset_easteurope); | |
8796 | Qw32_charset_easteurope = intern ("w32-charset-easteurope"); | |
8797 | staticpro (&Qw32_charset_turkish); | |
8798 | Qw32_charset_turkish = intern ("w32-charset-turkish"); | |
8799 | staticpro (&Qw32_charset_baltic); | |
8800 | Qw32_charset_baltic = intern ("w32-charset-baltic"); | |
8801 | staticpro (&Qw32_charset_russian); | |
8802 | Qw32_charset_russian = intern ("w32-charset-russian"); | |
8803 | staticpro (&Qw32_charset_arabic); | |
8804 | Qw32_charset_arabic = intern ("w32-charset-arabic"); | |
8805 | staticpro (&Qw32_charset_greek); | |
8806 | Qw32_charset_greek = intern ("w32-charset-greek"); | |
8807 | staticpro (&Qw32_charset_hebrew); | |
8808 | Qw32_charset_hebrew = intern ("w32-charset-hebrew"); | |
767b1ff0 JR |
8809 | staticpro (&Qw32_charset_vietnamese); |
8810 | Qw32_charset_vietnamese = intern ("w32-charset-vietnamese"); | |
dfff8a69 JR |
8811 | staticpro (&Qw32_charset_thai); |
8812 | Qw32_charset_thai = intern ("w32-charset-thai"); | |
8813 | staticpro (&Qw32_charset_mac); | |
8814 | Qw32_charset_mac = intern ("w32-charset-mac"); | |
8815 | } | |
8816 | #endif | |
8817 | ||
8818 | #ifdef UNICODE_CHARSET | |
8819 | { | |
8820 | static int w32_unicode_charset_defined = 1; | |
8821 | DEFVAR_BOOL ("w32-unicode-charset-defined", | |
74e1aeec JR |
8822 | &w32_unicode_charset_defined, |
8823 | doc: /* Internal variable. */); | |
dfff8a69 JR |
8824 | |
8825 | staticpro (&Qw32_charset_unicode); | |
8826 | Qw32_charset_unicode = intern ("w32-charset-unicode"); | |
8827 | #endif | |
8828 | ||
767b1ff0 | 8829 | #if 0 /* TODO: Port to W32 */ |
6fc2811b JR |
8830 | defsubr (&Sx_change_window_property); |
8831 | defsubr (&Sx_delete_window_property); | |
8832 | defsubr (&Sx_window_property); | |
8833 | #endif | |
2d764c78 | 8834 | defsubr (&Sxw_display_color_p); |
ee78dc32 | 8835 | defsubr (&Sx_display_grayscale_p); |
2d764c78 EZ |
8836 | defsubr (&Sxw_color_defined_p); |
8837 | defsubr (&Sxw_color_values); | |
ee78dc32 GV |
8838 | defsubr (&Sx_server_max_request_size); |
8839 | defsubr (&Sx_server_vendor); | |
8840 | defsubr (&Sx_server_version); | |
8841 | defsubr (&Sx_display_pixel_width); | |
8842 | defsubr (&Sx_display_pixel_height); | |
8843 | defsubr (&Sx_display_mm_width); | |
8844 | defsubr (&Sx_display_mm_height); | |
8845 | defsubr (&Sx_display_screens); | |
8846 | defsubr (&Sx_display_planes); | |
8847 | defsubr (&Sx_display_color_cells); | |
8848 | defsubr (&Sx_display_visual_class); | |
8849 | defsubr (&Sx_display_backing_store); | |
8850 | defsubr (&Sx_display_save_under); | |
ee78dc32 | 8851 | defsubr (&Sx_create_frame); |
ee78dc32 GV |
8852 | defsubr (&Sx_open_connection); |
8853 | defsubr (&Sx_close_connection); | |
8854 | defsubr (&Sx_display_list); | |
8855 | defsubr (&Sx_synchronize); | |
8856 | ||
fbd6baed | 8857 | /* W32 specific functions */ |
ee78dc32 | 8858 | |
1edf84e7 | 8859 | defsubr (&Sw32_focus_frame); |
fbd6baed GV |
8860 | defsubr (&Sw32_select_font); |
8861 | defsubr (&Sw32_define_rgb_color); | |
8862 | defsubr (&Sw32_default_color_map); | |
8863 | defsubr (&Sw32_load_color_file); | |
1edf84e7 | 8864 | defsubr (&Sw32_send_sys_command); |
55dcfc15 | 8865 | defsubr (&Sw32_shell_execute); |
ccc2d29c GV |
8866 | defsubr (&Sw32_register_hot_key); |
8867 | defsubr (&Sw32_unregister_hot_key); | |
8868 | defsubr (&Sw32_registered_hot_keys); | |
8869 | defsubr (&Sw32_reconstruct_hot_key); | |
adcc3809 | 8870 | defsubr (&Sw32_toggle_lock_key); |
33d52f9c | 8871 | defsubr (&Sw32_find_bdf_fonts); |
4587b026 | 8872 | |
2254bcde | 8873 | defsubr (&Sfile_system_info); |
39a0e135 | 8874 | defsubr (&Sdefault_printer_name); |
2254bcde | 8875 | |
4587b026 GV |
8876 | /* Setting callback functions for fontset handler. */ |
8877 | get_font_info_func = w32_get_font_info; | |
6fc2811b JR |
8878 | |
8879 | #if 0 /* This function pointer doesn't seem to be used anywhere. | |
8880 | And the pointer assigned has the wrong type, anyway. */ | |
4587b026 | 8881 | list_fonts_func = w32_list_fonts; |
6fc2811b JR |
8882 | #endif |
8883 | ||
4587b026 GV |
8884 | load_font_func = w32_load_font; |
8885 | find_ccl_program_func = w32_find_ccl_program; | |
8886 | query_font_func = w32_query_font; | |
8887 | set_frame_fontset_func = x_set_font; | |
8888 | check_window_system_func = check_w32; | |
6fc2811b | 8889 | |
6fc2811b | 8890 | |
0af913d7 GM |
8891 | hourglass_atimer = NULL; |
8892 | hourglass_shown_p = 0; | |
6fc2811b JR |
8893 | defsubr (&Sx_show_tip); |
8894 | defsubr (&Sx_hide_tip); | |
6fc2811b | 8895 | tip_timer = Qnil; |
57fa2774 JR |
8896 | staticpro (&tip_timer); |
8897 | tip_frame = Qnil; | |
8898 | staticpro (&tip_frame); | |
6fc2811b | 8899 | |
ca56d953 JR |
8900 | last_show_tip_args = Qnil; |
8901 | staticpro (&last_show_tip_args); | |
8902 | ||
6fc2811b JR |
8903 | defsubr (&Sx_file_dialog); |
8904 | } | |
8905 | ||
c922a224 | 8906 | |
9785d95b BK |
8907 | /* |
8908 | globals_of_w32fns is used to initialize those global variables that | |
8909 | must always be initialized on startup even when the global variable | |
8910 | initialized is non zero (see the function main in emacs.c). | |
8911 | globals_of_w32fns is called from syms_of_w32fns when the global | |
8912 | variable initialized is 0 and directly from main when initialized | |
8913 | is non zero. | |
8914 | */ | |
8915 | void globals_of_w32fns () | |
8916 | { | |
8917 | HMODULE user32_lib = GetModuleHandle ("user32.dll"); | |
ccc0fdaa JR |
8918 | /* |
8919 | TrackMouseEvent not available in all versions of Windows, so must load | |
8920 | it dynamically. Do it once, here, instead of every time it is used. | |
9785d95b | 8921 | */ |
ccc0fdaa JR |
8922 | track_mouse_event_fn = (TrackMouseEvent_Proc) |
8923 | GetProcAddress (user32_lib, "TrackMouseEvent"); | |
8924 | /* ditto for GetClipboardSequenceNumber. */ | |
8925 | clipboard_sequence_fn = (ClipboardSequence_Proc) | |
8926 | GetProcAddress (user32_lib, "GetClipboardSequenceNumber"); | |
4bf91535 JR |
8927 | |
8928 | DEFVAR_INT ("w32-ansi-code-page", | |
2ba49441 | 8929 | &w32_ansi_code_page, |
4bf91535 | 8930 | doc: /* The ANSI code page used by the system. */); |
2ba49441 | 8931 | w32_ansi_code_page = GetACP (); |
9785d95b | 8932 | } |
6fc2811b | 8933 | |
ee78dc32 GV |
8934 | #undef abort |
8935 | ||
c52e1638 EZ |
8936 | void w32_abort (void) NO_RETURN; |
8937 | ||
7d0393cf | 8938 | void |
fbd6baed | 8939 | w32_abort() |
ee78dc32 | 8940 | { |
5ac45f98 GV |
8941 | int button; |
8942 | button = MessageBox (NULL, | |
8943 | "A fatal error has occurred!\n\n" | |
c52e1638 | 8944 | "Would you like to attach a debugger?\n\n" |
cb91d111 EZ |
8945 | "Select YES to debug, NO to abort Emacs" |
8946 | #if __GNUC__ | |
8947 | "\n\n(type \"gdb -p <emacs-PID>\" and\n" | |
8948 | "\"continue\" inside GDB before clicking YES.)" | |
8949 | #endif | |
8950 | , "Emacs Abort Dialog", | |
5ac45f98 | 8951 | MB_ICONEXCLAMATION | MB_TASKMODAL |
c52e1638 | 8952 | | MB_SETFOREGROUND | MB_YESNO); |
5ac45f98 GV |
8953 | switch (button) |
8954 | { | |
c52e1638 | 8955 | case IDYES: |
5ac45f98 | 8956 | DebugBreak (); |
c52e1638 EZ |
8957 | exit (2); /* tell the compiler we will never return */ |
8958 | case IDNO: | |
5ac45f98 GV |
8959 | default: |
8960 | abort (); | |
8961 | break; | |
8962 | } | |
ee78dc32 | 8963 | } |
d573caac | 8964 | |
83c75055 GV |
8965 | /* For convenience when debugging. */ |
8966 | int | |
8967 | w32_last_error() | |
8968 | { | |
8969 | return GetLastError (); | |
8970 | } | |
ab5796a9 MB |
8971 | |
8972 | /* arch-tag: 707589ab-b9be-4638-8cdd-74629cc9b446 | |
8973 | (do not change this comment) */ |