1 /* Graphical user interface functions for the Microsoft W32 API.
2 Copyright (C) 1989, 92, 93, 94, 95, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
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)
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.
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
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Added by Kevin Gallo */
33 #include "dispextern.h"
40 #include "intervals.h"
41 #include "blockinput.h"
44 #include "termhooks.h"
49 #include "bitmaps/gray.xbm"
55 extern void free_frame_menubar ();
56 extern void x_compute_fringe_widths
P_ ((struct frame
*, int));
57 extern double atof ();
58 extern int w32_console_toggle_lock_key
P_ ((int, Lisp_Object
));
59 extern void w32_menu_display_help
P_ ((HWND
, HMENU
, UINT
, UINT
));
60 extern void w32_free_menu_strings
P_ ((HWND
));
64 /* A definition of XColor for non-X frames. */
65 #ifndef HAVE_X_WINDOWS
68 unsigned short red
, green
, blue
;
74 extern char *lispy_function_keys
[];
76 /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses
77 it, and including `bitmaps/gray' more than once is a problem when
78 config.h defines `static' as an empty replacement string. */
80 int gray_bitmap_width
= gray_width
;
81 int gray_bitmap_height
= gray_height
;
82 unsigned char *gray_bitmap_bits
= gray_bits
;
84 /* The colormap for converting color names to RGB values */
85 Lisp_Object Vw32_color_map
;
87 /* Non nil if alt key presses are passed on to Windows. */
88 Lisp_Object Vw32_pass_alt_to_system
;
90 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
92 Lisp_Object Vw32_alt_is_meta
;
94 /* If non-zero, the windows virtual key code for an alternative quit key. */
95 Lisp_Object Vw32_quit_key
;
97 /* Non nil if left window key events are passed on to Windows (this only
98 affects whether "tapping" the key opens the Start menu). */
99 Lisp_Object Vw32_pass_lwindow_to_system
;
101 /* Non nil if right window key events are passed on to Windows (this
102 only affects whether "tapping" the key opens the Start menu). */
103 Lisp_Object Vw32_pass_rwindow_to_system
;
105 /* Virtual key code used to generate "phantom" key presses in order
106 to stop system from acting on Windows key events. */
107 Lisp_Object Vw32_phantom_key_code
;
109 /* Modifier associated with the left "Windows" key, or nil to act as a
111 Lisp_Object Vw32_lwindow_modifier
;
113 /* Modifier associated with the right "Windows" key, or nil to act as a
115 Lisp_Object Vw32_rwindow_modifier
;
117 /* Modifier associated with the "Apps" key, or nil to act as a normal
119 Lisp_Object Vw32_apps_modifier
;
121 /* Value is nil if Num Lock acts as a function key. */
122 Lisp_Object Vw32_enable_num_lock
;
124 /* Value is nil if Caps Lock acts as a function key. */
125 Lisp_Object Vw32_enable_caps_lock
;
127 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
128 Lisp_Object Vw32_scroll_lock_modifier
;
130 /* Switch to control whether we inhibit requests for synthesized bold
131 and italic versions of fonts. */
132 int w32_enable_synthesized_fonts
;
134 /* Enable palette management. */
135 Lisp_Object Vw32_enable_palette
;
137 /* Control how close left/right button down events must be to
138 be converted to a middle button down event. */
139 Lisp_Object Vw32_mouse_button_tolerance
;
141 /* Minimum interval between mouse movement (and scroll bar drag)
142 events that are passed on to the event loop. */
143 Lisp_Object Vw32_mouse_move_interval
;
145 /* Flag to indicate if XBUTTON events should be passed on to Windows. */
146 int w32_pass_extra_mouse_buttons_to_system
;
148 /* The name we're using in resource queries. */
149 Lisp_Object Vx_resource_name
;
151 /* Non nil if no window manager is in use. */
152 Lisp_Object Vx_no_window_manager
;
154 /* Non-zero means we're allowed to display a hourglass pointer. */
156 int display_hourglass_p
;
158 /* The background and shape of the mouse pointer, and shape when not
159 over text or in the modeline. */
161 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
162 Lisp_Object Vx_hourglass_pointer_shape
, Vx_window_horizontal_drag_shape
;
164 /* The shape when over mouse-sensitive text. */
166 Lisp_Object Vx_sensitive_text_pointer_shape
;
168 /* Color of chars displayed in cursor box. */
170 Lisp_Object Vx_cursor_fore_pixel
;
172 /* Nonzero if using Windows. */
174 static int w32_in_use
;
176 /* Search path for bitmap files. */
178 Lisp_Object Vx_bitmap_file_path
;
180 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
182 Lisp_Object Vx_pixel_size_width_font_regexp
;
184 /* Alist of bdf fonts and the files that define them. */
185 Lisp_Object Vw32_bdf_filename_alist
;
187 /* A flag to control whether fonts are matched strictly or not. */
188 int w32_strict_fontnames
;
190 /* A flag to control whether we should only repaint if GetUpdateRect
191 indicates there is an update region. */
192 int w32_strict_painting
;
194 /* Associative list linking character set strings to Windows codepages. */
195 Lisp_Object Vw32_charset_info_alist
;
197 /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */
198 #ifndef VIETNAMESE_CHARSET
199 #define VIETNAMESE_CHARSET 163
202 Lisp_Object Qauto_raise
;
203 Lisp_Object Qauto_lower
;
205 Lisp_Object Qborder_color
;
206 Lisp_Object Qborder_width
;
208 Lisp_Object Qcursor_color
;
209 Lisp_Object Qcursor_type
;
210 Lisp_Object Qgeometry
;
211 Lisp_Object Qicon_left
;
212 Lisp_Object Qicon_top
;
213 Lisp_Object Qicon_type
;
214 Lisp_Object Qicon_name
;
215 Lisp_Object Qinternal_border_width
;
218 Lisp_Object Qmouse_color
;
220 Lisp_Object Qparent_id
;
221 Lisp_Object Qscroll_bar_width
;
222 Lisp_Object Qsuppress_icon
;
223 Lisp_Object Qundefined_color
;
224 Lisp_Object Qvertical_scroll_bars
;
225 Lisp_Object Qvisibility
;
226 Lisp_Object Qwindow_id
;
227 Lisp_Object Qx_frame_parameter
;
228 Lisp_Object Qx_resource_name
;
229 Lisp_Object Quser_position
;
230 Lisp_Object Quser_size
;
231 Lisp_Object Qscreen_gamma
;
232 Lisp_Object Qline_spacing
;
234 Lisp_Object Qcancel_timer
;
240 Lisp_Object Qcontrol
;
243 Lisp_Object Qw32_charset_ansi
;
244 Lisp_Object Qw32_charset_default
;
245 Lisp_Object Qw32_charset_symbol
;
246 Lisp_Object Qw32_charset_shiftjis
;
247 Lisp_Object Qw32_charset_hangeul
;
248 Lisp_Object Qw32_charset_gb2312
;
249 Lisp_Object Qw32_charset_chinesebig5
;
250 Lisp_Object Qw32_charset_oem
;
252 #ifndef JOHAB_CHARSET
253 #define JOHAB_CHARSET 130
256 Lisp_Object Qw32_charset_easteurope
;
257 Lisp_Object Qw32_charset_turkish
;
258 Lisp_Object Qw32_charset_baltic
;
259 Lisp_Object Qw32_charset_russian
;
260 Lisp_Object Qw32_charset_arabic
;
261 Lisp_Object Qw32_charset_greek
;
262 Lisp_Object Qw32_charset_hebrew
;
263 Lisp_Object Qw32_charset_vietnamese
;
264 Lisp_Object Qw32_charset_thai
;
265 Lisp_Object Qw32_charset_johab
;
266 Lisp_Object Qw32_charset_mac
;
269 #ifdef UNICODE_CHARSET
270 Lisp_Object Qw32_charset_unicode
;
273 Lisp_Object Qfullscreen
;
274 Lisp_Object Qfullwidth
;
275 Lisp_Object Qfullheight
;
276 Lisp_Object Qfullboth
;
278 extern Lisp_Object Qtop
;
279 extern Lisp_Object Qdisplay
;
281 /* State variables for emulating a three button mouse. */
286 static int button_state
= 0;
287 static W32Msg saved_mouse_button_msg
;
288 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
289 static W32Msg saved_mouse_move_msg
;
290 static unsigned mouse_move_timer
= 0;
292 /* Window that is tracking the mouse. */
293 static HWND track_mouse_window
;
294 FARPROC track_mouse_event_fn
;
296 /* W95 mousewheel handler */
297 unsigned int msh_mousewheel
= 0;
300 #define MOUSE_BUTTON_ID 1
301 #define MOUSE_MOVE_ID 2
302 #define MENU_FREE_ID 3
303 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
305 #define MENU_FREE_DELAY 1000
306 static unsigned menu_free_timer
= 0;
308 /* The below are defined in frame.c. */
310 extern Lisp_Object Qheight
, Qminibuffer
, Qname
, Qonly
, Qwidth
;
311 extern Lisp_Object Qunsplittable
, Qmenu_bar_lines
, Qbuffer_predicate
, Qtitle
;
312 extern Lisp_Object Qtool_bar_lines
;
314 extern Lisp_Object Vwindow_system_version
;
316 Lisp_Object Qface_set_after_frame_default
;
319 int image_cache_refcount
, dpyinfo_refcount
;
323 /* From w32term.c. */
324 extern Lisp_Object Vw32_num_mouse_buttons
;
325 extern Lisp_Object Vw32_recognize_altgr
;
327 extern HWND w32_system_caret_hwnd
;
329 extern int w32_system_caret_height
;
330 extern int w32_system_caret_x
;
331 extern int w32_system_caret_y
;
332 extern int w32_use_visible_system_caret
;
334 static HWND w32_visible_system_caret_hwnd
;
337 /* Error if we are not connected to MS-Windows. */
342 error ("MS-Windows not in use or not initialized");
345 /* Nonzero if we can use mouse menus.
346 You should not call this unless HAVE_MENUS is defined. */
354 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
355 and checking validity for W32. */
358 check_x_frame (frame
)
364 frame
= selected_frame
;
365 CHECK_LIVE_FRAME (frame
);
367 if (! FRAME_W32_P (f
))
368 error ("non-w32 frame used");
372 /* Let the user specify an display with a frame.
373 nil stands for the selected frame--or, if that is not a w32 frame,
374 the first display on the list. */
376 static struct w32_display_info
*
377 check_x_display_info (frame
)
382 struct frame
*sf
= XFRAME (selected_frame
);
384 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
385 return FRAME_W32_DISPLAY_INFO (sf
);
387 return &one_w32_display_info
;
389 else if (STRINGP (frame
))
390 return x_display_info_for_name (frame
);
395 CHECK_LIVE_FRAME (frame
);
397 if (! FRAME_W32_P (f
))
398 error ("non-w32 frame used");
399 return FRAME_W32_DISPLAY_INFO (f
);
403 /* Return the Emacs frame-object corresponding to an w32 window.
404 It could be the frame's main window or an icon window. */
406 /* This function can be called during GC, so use GC_xxx type test macros. */
409 x_window_to_frame (dpyinfo
, wdesc
)
410 struct w32_display_info
*dpyinfo
;
413 Lisp_Object tail
, frame
;
416 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
419 if (!GC_FRAMEP (frame
))
422 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
424 if (f
->output_data
.w32
->hourglass_window
== wdesc
)
427 if (FRAME_W32_WINDOW (f
) == wdesc
)
435 /* Code to deal with bitmaps. Bitmaps are referenced by their bitmap
436 id, which is just an int that this section returns. Bitmaps are
437 reference counted so they can be shared among frames.
439 Bitmap indices are guaranteed to be > 0, so a negative number can
440 be used to indicate no bitmap.
442 If you use x_create_bitmap_from_data, then you must keep track of
443 the bitmaps yourself. That is, creating a bitmap from the same
444 data more than once will not be caught. */
447 /* Functions to access the contents of a bitmap, given an id. */
450 x_bitmap_height (f
, id
)
454 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].height
;
458 x_bitmap_width (f
, id
)
462 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].width
;
466 x_bitmap_pixmap (f
, id
)
470 return (int) FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].pixmap
;
474 /* Allocate a new bitmap record. Returns index of new record. */
477 x_allocate_bitmap_record (f
)
480 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
483 if (dpyinfo
->bitmaps
== NULL
)
485 dpyinfo
->bitmaps_size
= 10;
487 = (struct w32_bitmap_record
*) xmalloc (dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
488 dpyinfo
->bitmaps_last
= 1;
492 if (dpyinfo
->bitmaps_last
< dpyinfo
->bitmaps_size
)
493 return ++dpyinfo
->bitmaps_last
;
495 for (i
= 0; i
< dpyinfo
->bitmaps_size
; ++i
)
496 if (dpyinfo
->bitmaps
[i
].refcount
== 0)
499 dpyinfo
->bitmaps_size
*= 2;
501 = (struct w32_bitmap_record
*) xrealloc (dpyinfo
->bitmaps
,
502 dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
503 return ++dpyinfo
->bitmaps_last
;
506 /* Add one reference to the reference count of the bitmap with id ID. */
509 x_reference_bitmap (f
, id
)
513 ++FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].refcount
;
516 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
519 x_create_bitmap_from_data (f
, bits
, width
, height
)
522 unsigned int width
, height
;
524 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
528 bitmap
= CreateBitmap (width
, height
,
529 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_planes
,
530 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_cbits
,
536 id
= x_allocate_bitmap_record (f
);
537 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
538 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
539 dpyinfo
->bitmaps
[id
- 1].hinst
= NULL
;
540 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
541 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
542 dpyinfo
->bitmaps
[id
- 1].height
= height
;
543 dpyinfo
->bitmaps
[id
- 1].width
= width
;
548 /* Create bitmap from file FILE for frame F. */
551 x_create_bitmap_from_file (f
, file
)
556 #if 0 /* TODO : bitmap support */
557 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
558 unsigned int width
, height
;
560 int xhot
, yhot
, result
, id
;
566 /* Look for an existing bitmap with the same name. */
567 for (id
= 0; id
< dpyinfo
->bitmaps_last
; ++id
)
569 if (dpyinfo
->bitmaps
[id
].refcount
570 && dpyinfo
->bitmaps
[id
].file
571 && !strcmp (dpyinfo
->bitmaps
[id
].file
, (char *) XSTRING (file
)->data
))
573 ++dpyinfo
->bitmaps
[id
].refcount
;
578 /* Search bitmap-file-path for the file, if appropriate. */
579 fd
= openp (Vx_bitmap_file_path
, file
, Qnil
, &found
, 0);
584 filename
= (char *) XSTRING (found
)->data
;
586 hinst
= LoadLibraryEx (filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
592 result
= XReadBitmapFile (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
593 filename
, &width
, &height
, &bitmap
, &xhot
, &yhot
);
594 if (result
!= BitmapSuccess
)
597 id
= x_allocate_bitmap_record (f
);
598 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
599 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
600 dpyinfo
->bitmaps
[id
- 1].file
= (char *) xmalloc (XSTRING (file
)->size
+ 1);
601 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
602 dpyinfo
->bitmaps
[id
- 1].height
= height
;
603 dpyinfo
->bitmaps
[id
- 1].width
= width
;
604 strcpy (dpyinfo
->bitmaps
[id
- 1].file
, XSTRING (file
)->data
);
610 /* Remove reference to bitmap with id number ID. */
613 x_destroy_bitmap (f
, id
)
617 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
621 --dpyinfo
->bitmaps
[id
- 1].refcount
;
622 if (dpyinfo
->bitmaps
[id
- 1].refcount
== 0)
625 DeleteObject (dpyinfo
->bitmaps
[id
- 1].pixmap
);
626 if (dpyinfo
->bitmaps
[id
- 1].file
)
628 xfree (dpyinfo
->bitmaps
[id
- 1].file
);
629 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
636 /* Free all the bitmaps for the display specified by DPYINFO. */
639 x_destroy_all_bitmaps (dpyinfo
)
640 struct w32_display_info
*dpyinfo
;
643 for (i
= 0; i
< dpyinfo
->bitmaps_last
; i
++)
644 if (dpyinfo
->bitmaps
[i
].refcount
> 0)
646 DeleteObject (dpyinfo
->bitmaps
[i
].pixmap
);
647 if (dpyinfo
->bitmaps
[i
].file
)
648 xfree (dpyinfo
->bitmaps
[i
].file
);
650 dpyinfo
->bitmaps_last
= 0;
653 /* Connect the frame-parameter names for W32 frames
654 to the ways of passing the parameter values to the window system.
656 The name of a parameter, as a Lisp symbol,
657 has an `x-frame-parameter' property which is an integer in Lisp
658 but can be interpreted as an `enum x_frame_parm' in C. */
662 X_PARM_FOREGROUND_COLOR
,
663 X_PARM_BACKGROUND_COLOR
,
670 X_PARM_INTERNAL_BORDER_WIDTH
,
674 X_PARM_VERT_SCROLL_BAR
,
676 X_PARM_MENU_BAR_LINES
680 struct x_frame_parm_table
683 void (*setter
) P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
686 BOOL my_show_window
P_ ((struct frame
*, HWND
, int));
687 void my_set_window_pos
P_ ((HWND
, HWND
, int, int, int, int, UINT
));
688 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
689 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
690 static void x_change_window_heights
P_ ((Lisp_Object
, int));
691 /* TODO: Native Input Method support; see x_create_im. */
692 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
693 static void x_set_line_spacing
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
694 static void x_set_fullscreen
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
695 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
696 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
697 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
698 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
699 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
700 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
701 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
702 void x_set_font
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
703 static void x_set_fringe_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
704 void x_set_border_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
705 void x_set_internal_border_width
P_ ((struct frame
*, Lisp_Object
,
707 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
708 void x_set_autoraise
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
709 void x_set_autolower
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
710 void x_set_vertical_scroll_bars
P_ ((struct frame
*, Lisp_Object
,
712 void x_set_visibility
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
713 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
714 void x_set_scroll_bar_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
715 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
716 void x_set_unsplittable
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
717 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
718 static void x_set_screen_gamma
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
719 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
722 static struct x_frame_parm_table x_frame_parms
[] =
724 {"auto-raise", x_set_autoraise
},
725 {"auto-lower", x_set_autolower
},
726 {"background-color", x_set_background_color
},
727 {"border-color", x_set_border_color
},
728 {"border-width", x_set_border_width
},
729 {"cursor-color", x_set_cursor_color
},
730 {"cursor-type", x_set_cursor_type
},
731 {"font", x_set_font
},
732 {"foreground-color", x_set_foreground_color
},
733 {"icon-name", x_set_icon_name
},
734 {"icon-type", x_set_icon_type
},
735 {"internal-border-width", x_set_internal_border_width
},
736 {"menu-bar-lines", x_set_menu_bar_lines
},
737 {"mouse-color", x_set_mouse_color
},
738 {"name", x_explicitly_set_name
},
739 {"scroll-bar-width", x_set_scroll_bar_width
},
740 {"title", x_set_title
},
741 {"unsplittable", x_set_unsplittable
},
742 {"vertical-scroll-bars", x_set_vertical_scroll_bars
},
743 {"visibility", x_set_visibility
},
744 {"tool-bar-lines", x_set_tool_bar_lines
},
745 {"screen-gamma", x_set_screen_gamma
},
746 {"line-spacing", x_set_line_spacing
},
747 {"left-fringe", x_set_fringe_width
},
748 {"right-fringe", x_set_fringe_width
},
749 {"fullscreen", x_set_fullscreen
},
752 /* Attach the `x-frame-parameter' properties to
753 the Lisp symbol names of parameters relevant to W32. */
756 init_x_parm_symbols ()
760 for (i
= 0; i
< sizeof (x_frame_parms
) / sizeof (x_frame_parms
[0]); i
++)
761 Fput (intern (x_frame_parms
[i
].name
), Qx_frame_parameter
,
765 /* Really try to move where we want to be in case of fullscreen. Some WMs
766 moves the window where we tell them. Some (mwm, twm) moves the outer
767 window manager window there instead.
768 Try to compensate for those WM here. */
770 x_fullscreen_move (f
, new_top
, new_left
)
775 if (new_top
!= f
->output_data
.w32
->top_pos
776 || new_left
!= f
->output_data
.w32
->left_pos
)
778 int move_x
= new_left
;
779 int move_y
= new_top
;
781 f
->output_data
.w32
->want_fullscreen
|= FULLSCREEN_MOVE_WAIT
;
782 x_set_offset (f
, move_x
, move_y
, 1);
786 /* Change the parameters of frame F as specified by ALIST.
787 If a parameter is not specially recognized, do nothing;
788 otherwise call the `x_set_...' function for that parameter. */
791 x_set_frame_parameters (f
, alist
)
797 /* If both of these parameters are present, it's more efficient to
798 set them both at once. So we wait until we've looked at the
799 entire list before we set them. */
803 Lisp_Object left
, top
;
805 /* Same with these. */
806 Lisp_Object icon_left
, icon_top
;
808 /* Record in these vectors all the parms specified. */
812 int left_no_change
= 0, top_no_change
= 0;
813 int icon_left_no_change
= 0, icon_top_no_change
= 0;
814 int fullscreen_is_being_set
= 0;
816 struct gcpro gcpro1
, gcpro2
;
819 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
822 parms
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
823 values
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
825 /* Extract parm names and values into those vectors. */
828 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
833 parms
[i
] = Fcar (elt
);
834 values
[i
] = Fcdr (elt
);
837 /* TAIL and ALIST are not used again below here. */
840 GCPRO2 (*parms
, *values
);
844 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
845 because their values appear in VALUES and strings are not valid. */
846 top
= left
= Qunbound
;
847 icon_left
= icon_top
= Qunbound
;
849 /* Provide default values for HEIGHT and WIDTH. */
850 if (FRAME_NEW_WIDTH (f
))
851 width
= FRAME_NEW_WIDTH (f
);
853 width
= FRAME_WIDTH (f
);
855 if (FRAME_NEW_HEIGHT (f
))
856 height
= FRAME_NEW_HEIGHT (f
);
858 height
= FRAME_HEIGHT (f
);
860 /* Process foreground_color and background_color before anything else.
861 They are independent of other properties, but other properties (e.g.,
862 cursor_color) are dependent upon them. */
863 /* Process default font as well, since fringe widths depends on it. */
864 for (p
= 0; p
< i
; p
++)
866 Lisp_Object prop
, val
;
870 if (EQ (prop
, Qforeground_color
)
871 || EQ (prop
, Qbackground_color
)
873 || EQ (prop
, Qfullscreen
))
875 register Lisp_Object param_index
, old_value
;
877 old_value
= get_frame_param (f
, prop
);
878 fullscreen_is_being_set
|= EQ (prop
, Qfullscreen
);
880 if (NILP (Fequal (val
, old_value
)))
882 store_frame_param (f
, prop
, val
);
884 param_index
= Fget (prop
, Qx_frame_parameter
);
885 if (NATNUMP (param_index
)
886 && (XFASTINT (param_index
)
887 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
888 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
893 /* Now process them in reverse of specified order. */
894 for (i
--; i
>= 0; i
--)
896 Lisp_Object prop
, val
;
901 if (EQ (prop
, Qwidth
) && NUMBERP (val
))
902 width
= XFASTINT (val
);
903 else if (EQ (prop
, Qheight
) && NUMBERP (val
))
904 height
= XFASTINT (val
);
905 else if (EQ (prop
, Qtop
))
907 else if (EQ (prop
, Qleft
))
909 else if (EQ (prop
, Qicon_top
))
911 else if (EQ (prop
, Qicon_left
))
913 else if (EQ (prop
, Qforeground_color
)
914 || EQ (prop
, Qbackground_color
)
916 || EQ (prop
, Qfullscreen
))
917 /* Processed above. */
921 register Lisp_Object param_index
, old_value
;
923 old_value
= get_frame_param (f
, prop
);
925 store_frame_param (f
, prop
, val
);
927 param_index
= Fget (prop
, Qx_frame_parameter
);
928 if (NATNUMP (param_index
)
929 && (XFASTINT (param_index
)
930 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
931 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
935 /* Don't die if just one of these was set. */
936 if (EQ (left
, Qunbound
))
939 if (f
->output_data
.w32
->left_pos
< 0)
940 left
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->left_pos
), Qnil
));
942 XSETINT (left
, f
->output_data
.w32
->left_pos
);
944 if (EQ (top
, Qunbound
))
947 if (f
->output_data
.w32
->top_pos
< 0)
948 top
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->top_pos
), Qnil
));
950 XSETINT (top
, f
->output_data
.w32
->top_pos
);
953 /* If one of the icon positions was not set, preserve or default it. */
954 if (EQ (icon_left
, Qunbound
) || ! INTEGERP (icon_left
))
956 icon_left_no_change
= 1;
957 icon_left
= Fcdr (Fassq (Qicon_left
, f
->param_alist
));
958 if (NILP (icon_left
))
959 XSETINT (icon_left
, 0);
961 if (EQ (icon_top
, Qunbound
) || ! INTEGERP (icon_top
))
963 icon_top_no_change
= 1;
964 icon_top
= Fcdr (Fassq (Qicon_top
, f
->param_alist
));
966 XSETINT (icon_top
, 0);
969 if (FRAME_VISIBLE_P (f
) && fullscreen_is_being_set
)
971 /* If the frame is visible already and the fullscreen parameter is
972 being set, it is too late to set WM manager hints to specify
974 Here we first get the width, height and position that applies to
975 fullscreen. We then move the frame to the appropriate
976 position. Resize of the frame is taken care of in the code after
977 this if-statement. */
978 int new_left
, new_top
;
980 x_fullscreen_adjust (f
, &width
, &height
, &new_top
, &new_left
);
981 x_fullscreen_move (f
, new_top
, new_left
);
984 /* Don't set these parameters unless they've been explicitly
985 specified. The window might be mapped or resized while we're in
986 this function, and we don't want to override that unless the lisp
987 code has asked for it.
989 Don't set these parameters unless they actually differ from the
990 window's current parameters; the window may not actually exist
995 check_frame_size (f
, &height
, &width
);
997 XSETFRAME (frame
, f
);
999 if (width
!= FRAME_WIDTH (f
)
1000 || height
!= FRAME_HEIGHT (f
)
1001 || FRAME_NEW_HEIGHT (f
) || FRAME_NEW_WIDTH (f
))
1002 Fset_frame_size (frame
, make_number (width
), make_number (height
));
1004 if ((!NILP (left
) || !NILP (top
))
1005 && ! (left_no_change
&& top_no_change
)
1006 && ! (NUMBERP (left
) && XINT (left
) == f
->output_data
.w32
->left_pos
1007 && NUMBERP (top
) && XINT (top
) == f
->output_data
.w32
->top_pos
))
1012 /* Record the signs. */
1013 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
1014 if (EQ (left
, Qminus
))
1015 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
1016 else if (INTEGERP (left
))
1018 leftpos
= XINT (left
);
1020 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
1022 else if (CONSP (left
) && EQ (XCAR (left
), Qminus
)
1023 && CONSP (XCDR (left
))
1024 && INTEGERP (XCAR (XCDR (left
))))
1026 leftpos
= - XINT (XCAR (XCDR (left
)));
1027 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
1029 else if (CONSP (left
) && EQ (XCAR (left
), Qplus
)
1030 && CONSP (XCDR (left
))
1031 && INTEGERP (XCAR (XCDR (left
))))
1033 leftpos
= XINT (XCAR (XCDR (left
)));
1036 if (EQ (top
, Qminus
))
1037 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
1038 else if (INTEGERP (top
))
1040 toppos
= XINT (top
);
1042 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
1044 else if (CONSP (top
) && EQ (XCAR (top
), Qminus
)
1045 && CONSP (XCDR (top
))
1046 && INTEGERP (XCAR (XCDR (top
))))
1048 toppos
= - XINT (XCAR (XCDR (top
)));
1049 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
1051 else if (CONSP (top
) && EQ (XCAR (top
), Qplus
)
1052 && CONSP (XCDR (top
))
1053 && INTEGERP (XCAR (XCDR (top
))))
1055 toppos
= XINT (XCAR (XCDR (top
)));
1059 /* Store the numeric value of the position. */
1060 f
->output_data
.w32
->top_pos
= toppos
;
1061 f
->output_data
.w32
->left_pos
= leftpos
;
1063 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
1065 /* Actually set that position, and convert to absolute. */
1066 x_set_offset (f
, leftpos
, toppos
, -1);
1069 if ((!NILP (icon_left
) || !NILP (icon_top
))
1070 && ! (icon_left_no_change
&& icon_top_no_change
))
1071 x_wm_set_icon_position (f
, XINT (icon_left
), XINT (icon_top
));
1077 /* Store the screen positions of frame F into XPTR and YPTR.
1078 These are the positions of the containing window manager window,
1079 not Emacs's own window. */
1082 x_real_positions (f
, xptr
, yptr
)
1089 GetClientRect(FRAME_W32_WINDOW(f
), &rect
);
1090 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
, FRAME_EXTERNAL_MENU_BAR(f
));
1095 ClientToScreen (FRAME_W32_WINDOW(f
), &pt
);
1097 /* Remember x_pixels_diff and y_pixels_diff. */
1098 f
->output_data
.w32
->x_pixels_diff
= pt
.x
- rect
.left
;
1099 f
->output_data
.w32
->y_pixels_diff
= pt
.y
- rect
.top
;
1105 /* Insert a description of internally-recorded parameters of frame X
1106 into the parameter alist *ALISTPTR that is to be given to the user.
1107 Only parameters that are specific to W32
1108 and whose values are not correctly recorded in the frame's
1109 param_alist need to be considered here. */
1112 x_report_frame_params (f
, alistptr
)
1114 Lisp_Object
*alistptr
;
1119 /* Represent negative positions (off the top or left screen edge)
1120 in a way that Fmodify_frame_parameters will understand correctly. */
1121 XSETINT (tem
, f
->output_data
.w32
->left_pos
);
1122 if (f
->output_data
.w32
->left_pos
>= 0)
1123 store_in_alist (alistptr
, Qleft
, tem
);
1125 store_in_alist (alistptr
, Qleft
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1127 XSETINT (tem
, f
->output_data
.w32
->top_pos
);
1128 if (f
->output_data
.w32
->top_pos
>= 0)
1129 store_in_alist (alistptr
, Qtop
, tem
);
1131 store_in_alist (alistptr
, Qtop
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1133 store_in_alist (alistptr
, Qborder_width
,
1134 make_number (f
->output_data
.w32
->border_width
));
1135 store_in_alist (alistptr
, Qinternal_border_width
,
1136 make_number (f
->output_data
.w32
->internal_border_width
));
1137 store_in_alist (alistptr
, Qleft_fringe
,
1138 make_number (f
->output_data
.w32
->left_fringe_width
));
1139 store_in_alist (alistptr
, Qright_fringe
,
1140 make_number (f
->output_data
.w32
->right_fringe_width
));
1141 store_in_alist (alistptr
, Qscroll_bar_width
,
1142 make_number (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
1143 ? FRAME_SCROLL_BAR_PIXEL_WIDTH(f
)
1145 sprintf (buf
, "%ld", (long) FRAME_W32_WINDOW (f
));
1146 store_in_alist (alistptr
, Qwindow_id
,
1147 build_string (buf
));
1148 store_in_alist (alistptr
, Qicon_name
, f
->icon_name
);
1149 FRAME_SAMPLE_VISIBILITY (f
);
1150 store_in_alist (alistptr
, Qvisibility
,
1151 (FRAME_VISIBLE_P (f
) ? Qt
1152 : FRAME_ICONIFIED_P (f
) ? Qicon
: Qnil
));
1153 store_in_alist (alistptr
, Qdisplay
,
1154 XCAR (FRAME_W32_DISPLAY_INFO (f
)->name_list_element
));
1158 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
1159 Sw32_define_rgb_color
, 4, 4, 0,
1160 doc
: /* Convert RGB numbers to a windows color reference and associate with NAME.
1161 This adds or updates a named color to w32-color-map, making it
1162 available for use. The original entry's RGB ref is returned, or nil
1163 if the entry is new. */)
1164 (red
, green
, blue
, name
)
1165 Lisp_Object red
, green
, blue
, name
;
1168 Lisp_Object oldrgb
= Qnil
;
1172 CHECK_NUMBER (green
);
1173 CHECK_NUMBER (blue
);
1174 CHECK_STRING (name
);
1176 XSET (rgb
, Lisp_Int
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
1180 /* replace existing entry in w32-color-map or add new entry. */
1181 entry
= Fassoc (name
, Vw32_color_map
);
1184 entry
= Fcons (name
, rgb
);
1185 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
1189 oldrgb
= Fcdr (entry
);
1190 Fsetcdr (entry
, rgb
);
1198 DEFUN ("w32-load-color-file", Fw32_load_color_file
,
1199 Sw32_load_color_file
, 1, 1, 0,
1200 doc
: /* Create an alist of color entries from an external file.
1201 Assign this value to w32-color-map to replace the existing color map.
1203 The file should define one named RGB color per line like so:
1205 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
1207 Lisp_Object filename
;
1210 Lisp_Object cmap
= Qnil
;
1211 Lisp_Object abspath
;
1213 CHECK_STRING (filename
);
1214 abspath
= Fexpand_file_name (filename
, Qnil
);
1216 fp
= fopen (XSTRING (filename
)->data
, "rt");
1220 int red
, green
, blue
;
1225 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
1226 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
1228 char *name
= buf
+ num
;
1229 num
= strlen (name
) - 1;
1230 if (name
[num
] == '\n')
1232 cmap
= Fcons (Fcons (build_string (name
),
1233 make_number (RGB (red
, green
, blue
))),
1245 /* The default colors for the w32 color map */
1246 typedef struct colormap_t
1252 colormap_t w32_color_map
[] =
1254 {"snow" , PALETTERGB (255,250,250)},
1255 {"ghost white" , PALETTERGB (248,248,255)},
1256 {"GhostWhite" , PALETTERGB (248,248,255)},
1257 {"white smoke" , PALETTERGB (245,245,245)},
1258 {"WhiteSmoke" , PALETTERGB (245,245,245)},
1259 {"gainsboro" , PALETTERGB (220,220,220)},
1260 {"floral white" , PALETTERGB (255,250,240)},
1261 {"FloralWhite" , PALETTERGB (255,250,240)},
1262 {"old lace" , PALETTERGB (253,245,230)},
1263 {"OldLace" , PALETTERGB (253,245,230)},
1264 {"linen" , PALETTERGB (250,240,230)},
1265 {"antique white" , PALETTERGB (250,235,215)},
1266 {"AntiqueWhite" , PALETTERGB (250,235,215)},
1267 {"papaya whip" , PALETTERGB (255,239,213)},
1268 {"PapayaWhip" , PALETTERGB (255,239,213)},
1269 {"blanched almond" , PALETTERGB (255,235,205)},
1270 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
1271 {"bisque" , PALETTERGB (255,228,196)},
1272 {"peach puff" , PALETTERGB (255,218,185)},
1273 {"PeachPuff" , PALETTERGB (255,218,185)},
1274 {"navajo white" , PALETTERGB (255,222,173)},
1275 {"NavajoWhite" , PALETTERGB (255,222,173)},
1276 {"moccasin" , PALETTERGB (255,228,181)},
1277 {"cornsilk" , PALETTERGB (255,248,220)},
1278 {"ivory" , PALETTERGB (255,255,240)},
1279 {"lemon chiffon" , PALETTERGB (255,250,205)},
1280 {"LemonChiffon" , PALETTERGB (255,250,205)},
1281 {"seashell" , PALETTERGB (255,245,238)},
1282 {"honeydew" , PALETTERGB (240,255,240)},
1283 {"mint cream" , PALETTERGB (245,255,250)},
1284 {"MintCream" , PALETTERGB (245,255,250)},
1285 {"azure" , PALETTERGB (240,255,255)},
1286 {"alice blue" , PALETTERGB (240,248,255)},
1287 {"AliceBlue" , PALETTERGB (240,248,255)},
1288 {"lavender" , PALETTERGB (230,230,250)},
1289 {"lavender blush" , PALETTERGB (255,240,245)},
1290 {"LavenderBlush" , PALETTERGB (255,240,245)},
1291 {"misty rose" , PALETTERGB (255,228,225)},
1292 {"MistyRose" , PALETTERGB (255,228,225)},
1293 {"white" , PALETTERGB (255,255,255)},
1294 {"black" , PALETTERGB ( 0, 0, 0)},
1295 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
1296 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
1297 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
1298 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
1299 {"dim gray" , PALETTERGB (105,105,105)},
1300 {"DimGray" , PALETTERGB (105,105,105)},
1301 {"dim grey" , PALETTERGB (105,105,105)},
1302 {"DimGrey" , PALETTERGB (105,105,105)},
1303 {"slate gray" , PALETTERGB (112,128,144)},
1304 {"SlateGray" , PALETTERGB (112,128,144)},
1305 {"slate grey" , PALETTERGB (112,128,144)},
1306 {"SlateGrey" , PALETTERGB (112,128,144)},
1307 {"light slate gray" , PALETTERGB (119,136,153)},
1308 {"LightSlateGray" , PALETTERGB (119,136,153)},
1309 {"light slate grey" , PALETTERGB (119,136,153)},
1310 {"LightSlateGrey" , PALETTERGB (119,136,153)},
1311 {"gray" , PALETTERGB (190,190,190)},
1312 {"grey" , PALETTERGB (190,190,190)},
1313 {"light grey" , PALETTERGB (211,211,211)},
1314 {"LightGrey" , PALETTERGB (211,211,211)},
1315 {"light gray" , PALETTERGB (211,211,211)},
1316 {"LightGray" , PALETTERGB (211,211,211)},
1317 {"midnight blue" , PALETTERGB ( 25, 25,112)},
1318 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
1319 {"navy" , PALETTERGB ( 0, 0,128)},
1320 {"navy blue" , PALETTERGB ( 0, 0,128)},
1321 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
1322 {"cornflower blue" , PALETTERGB (100,149,237)},
1323 {"CornflowerBlue" , PALETTERGB (100,149,237)},
1324 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
1325 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
1326 {"slate blue" , PALETTERGB (106, 90,205)},
1327 {"SlateBlue" , PALETTERGB (106, 90,205)},
1328 {"medium slate blue" , PALETTERGB (123,104,238)},
1329 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
1330 {"light slate blue" , PALETTERGB (132,112,255)},
1331 {"LightSlateBlue" , PALETTERGB (132,112,255)},
1332 {"medium blue" , PALETTERGB ( 0, 0,205)},
1333 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
1334 {"royal blue" , PALETTERGB ( 65,105,225)},
1335 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
1336 {"blue" , PALETTERGB ( 0, 0,255)},
1337 {"dodger blue" , PALETTERGB ( 30,144,255)},
1338 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
1339 {"deep sky blue" , PALETTERGB ( 0,191,255)},
1340 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
1341 {"sky blue" , PALETTERGB (135,206,235)},
1342 {"SkyBlue" , PALETTERGB (135,206,235)},
1343 {"light sky blue" , PALETTERGB (135,206,250)},
1344 {"LightSkyBlue" , PALETTERGB (135,206,250)},
1345 {"steel blue" , PALETTERGB ( 70,130,180)},
1346 {"SteelBlue" , PALETTERGB ( 70,130,180)},
1347 {"light steel blue" , PALETTERGB (176,196,222)},
1348 {"LightSteelBlue" , PALETTERGB (176,196,222)},
1349 {"light blue" , PALETTERGB (173,216,230)},
1350 {"LightBlue" , PALETTERGB (173,216,230)},
1351 {"powder blue" , PALETTERGB (176,224,230)},
1352 {"PowderBlue" , PALETTERGB (176,224,230)},
1353 {"pale turquoise" , PALETTERGB (175,238,238)},
1354 {"PaleTurquoise" , PALETTERGB (175,238,238)},
1355 {"dark turquoise" , PALETTERGB ( 0,206,209)},
1356 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
1357 {"medium turquoise" , PALETTERGB ( 72,209,204)},
1358 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
1359 {"turquoise" , PALETTERGB ( 64,224,208)},
1360 {"cyan" , PALETTERGB ( 0,255,255)},
1361 {"light cyan" , PALETTERGB (224,255,255)},
1362 {"LightCyan" , PALETTERGB (224,255,255)},
1363 {"cadet blue" , PALETTERGB ( 95,158,160)},
1364 {"CadetBlue" , PALETTERGB ( 95,158,160)},
1365 {"medium aquamarine" , PALETTERGB (102,205,170)},
1366 {"MediumAquamarine" , PALETTERGB (102,205,170)},
1367 {"aquamarine" , PALETTERGB (127,255,212)},
1368 {"dark green" , PALETTERGB ( 0,100, 0)},
1369 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
1370 {"dark olive green" , PALETTERGB ( 85,107, 47)},
1371 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
1372 {"dark sea green" , PALETTERGB (143,188,143)},
1373 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
1374 {"sea green" , PALETTERGB ( 46,139, 87)},
1375 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
1376 {"medium sea green" , PALETTERGB ( 60,179,113)},
1377 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
1378 {"light sea green" , PALETTERGB ( 32,178,170)},
1379 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
1380 {"pale green" , PALETTERGB (152,251,152)},
1381 {"PaleGreen" , PALETTERGB (152,251,152)},
1382 {"spring green" , PALETTERGB ( 0,255,127)},
1383 {"SpringGreen" , PALETTERGB ( 0,255,127)},
1384 {"lawn green" , PALETTERGB (124,252, 0)},
1385 {"LawnGreen" , PALETTERGB (124,252, 0)},
1386 {"green" , PALETTERGB ( 0,255, 0)},
1387 {"chartreuse" , PALETTERGB (127,255, 0)},
1388 {"medium spring green" , PALETTERGB ( 0,250,154)},
1389 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
1390 {"green yellow" , PALETTERGB (173,255, 47)},
1391 {"GreenYellow" , PALETTERGB (173,255, 47)},
1392 {"lime green" , PALETTERGB ( 50,205, 50)},
1393 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
1394 {"yellow green" , PALETTERGB (154,205, 50)},
1395 {"YellowGreen" , PALETTERGB (154,205, 50)},
1396 {"forest green" , PALETTERGB ( 34,139, 34)},
1397 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
1398 {"olive drab" , PALETTERGB (107,142, 35)},
1399 {"OliveDrab" , PALETTERGB (107,142, 35)},
1400 {"dark khaki" , PALETTERGB (189,183,107)},
1401 {"DarkKhaki" , PALETTERGB (189,183,107)},
1402 {"khaki" , PALETTERGB (240,230,140)},
1403 {"pale goldenrod" , PALETTERGB (238,232,170)},
1404 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
1405 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
1406 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
1407 {"light yellow" , PALETTERGB (255,255,224)},
1408 {"LightYellow" , PALETTERGB (255,255,224)},
1409 {"yellow" , PALETTERGB (255,255, 0)},
1410 {"gold" , PALETTERGB (255,215, 0)},
1411 {"light goldenrod" , PALETTERGB (238,221,130)},
1412 {"LightGoldenrod" , PALETTERGB (238,221,130)},
1413 {"goldenrod" , PALETTERGB (218,165, 32)},
1414 {"dark goldenrod" , PALETTERGB (184,134, 11)},
1415 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
1416 {"rosy brown" , PALETTERGB (188,143,143)},
1417 {"RosyBrown" , PALETTERGB (188,143,143)},
1418 {"indian red" , PALETTERGB (205, 92, 92)},
1419 {"IndianRed" , PALETTERGB (205, 92, 92)},
1420 {"saddle brown" , PALETTERGB (139, 69, 19)},
1421 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
1422 {"sienna" , PALETTERGB (160, 82, 45)},
1423 {"peru" , PALETTERGB (205,133, 63)},
1424 {"burlywood" , PALETTERGB (222,184,135)},
1425 {"beige" , PALETTERGB (245,245,220)},
1426 {"wheat" , PALETTERGB (245,222,179)},
1427 {"sandy brown" , PALETTERGB (244,164, 96)},
1428 {"SandyBrown" , PALETTERGB (244,164, 96)},
1429 {"tan" , PALETTERGB (210,180,140)},
1430 {"chocolate" , PALETTERGB (210,105, 30)},
1431 {"firebrick" , PALETTERGB (178,34, 34)},
1432 {"brown" , PALETTERGB (165,42, 42)},
1433 {"dark salmon" , PALETTERGB (233,150,122)},
1434 {"DarkSalmon" , PALETTERGB (233,150,122)},
1435 {"salmon" , PALETTERGB (250,128,114)},
1436 {"light salmon" , PALETTERGB (255,160,122)},
1437 {"LightSalmon" , PALETTERGB (255,160,122)},
1438 {"orange" , PALETTERGB (255,165, 0)},
1439 {"dark orange" , PALETTERGB (255,140, 0)},
1440 {"DarkOrange" , PALETTERGB (255,140, 0)},
1441 {"coral" , PALETTERGB (255,127, 80)},
1442 {"light coral" , PALETTERGB (240,128,128)},
1443 {"LightCoral" , PALETTERGB (240,128,128)},
1444 {"tomato" , PALETTERGB (255, 99, 71)},
1445 {"orange red" , PALETTERGB (255, 69, 0)},
1446 {"OrangeRed" , PALETTERGB (255, 69, 0)},
1447 {"red" , PALETTERGB (255, 0, 0)},
1448 {"hot pink" , PALETTERGB (255,105,180)},
1449 {"HotPink" , PALETTERGB (255,105,180)},
1450 {"deep pink" , PALETTERGB (255, 20,147)},
1451 {"DeepPink" , PALETTERGB (255, 20,147)},
1452 {"pink" , PALETTERGB (255,192,203)},
1453 {"light pink" , PALETTERGB (255,182,193)},
1454 {"LightPink" , PALETTERGB (255,182,193)},
1455 {"pale violet red" , PALETTERGB (219,112,147)},
1456 {"PaleVioletRed" , PALETTERGB (219,112,147)},
1457 {"maroon" , PALETTERGB (176, 48, 96)},
1458 {"medium violet red" , PALETTERGB (199, 21,133)},
1459 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
1460 {"violet red" , PALETTERGB (208, 32,144)},
1461 {"VioletRed" , PALETTERGB (208, 32,144)},
1462 {"magenta" , PALETTERGB (255, 0,255)},
1463 {"violet" , PALETTERGB (238,130,238)},
1464 {"plum" , PALETTERGB (221,160,221)},
1465 {"orchid" , PALETTERGB (218,112,214)},
1466 {"medium orchid" , PALETTERGB (186, 85,211)},
1467 {"MediumOrchid" , PALETTERGB (186, 85,211)},
1468 {"dark orchid" , PALETTERGB (153, 50,204)},
1469 {"DarkOrchid" , PALETTERGB (153, 50,204)},
1470 {"dark violet" , PALETTERGB (148, 0,211)},
1471 {"DarkViolet" , PALETTERGB (148, 0,211)},
1472 {"blue violet" , PALETTERGB (138, 43,226)},
1473 {"BlueViolet" , PALETTERGB (138, 43,226)},
1474 {"purple" , PALETTERGB (160, 32,240)},
1475 {"medium purple" , PALETTERGB (147,112,219)},
1476 {"MediumPurple" , PALETTERGB (147,112,219)},
1477 {"thistle" , PALETTERGB (216,191,216)},
1478 {"gray0" , PALETTERGB ( 0, 0, 0)},
1479 {"grey0" , PALETTERGB ( 0, 0, 0)},
1480 {"dark grey" , PALETTERGB (169,169,169)},
1481 {"DarkGrey" , PALETTERGB (169,169,169)},
1482 {"dark gray" , PALETTERGB (169,169,169)},
1483 {"DarkGray" , PALETTERGB (169,169,169)},
1484 {"dark blue" , PALETTERGB ( 0, 0,139)},
1485 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
1486 {"dark cyan" , PALETTERGB ( 0,139,139)},
1487 {"DarkCyan" , PALETTERGB ( 0,139,139)},
1488 {"dark magenta" , PALETTERGB (139, 0,139)},
1489 {"DarkMagenta" , PALETTERGB (139, 0,139)},
1490 {"dark red" , PALETTERGB (139, 0, 0)},
1491 {"DarkRed" , PALETTERGB (139, 0, 0)},
1492 {"light green" , PALETTERGB (144,238,144)},
1493 {"LightGreen" , PALETTERGB (144,238,144)},
1496 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
1497 0, 0, 0, doc
: /* Return the default color map. */)
1501 colormap_t
*pc
= w32_color_map
;
1508 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
1510 cmap
= Fcons (Fcons (build_string (pc
->name
),
1511 make_number (pc
->colorref
)),
1520 w32_to_x_color (rgb
)
1529 color
= Frassq (rgb
, Vw32_color_map
);
1534 return (Fcar (color
));
1540 w32_color_map_lookup (colorname
)
1543 Lisp_Object tail
, ret
= Qnil
;
1547 for (tail
= Vw32_color_map
; !NILP (tail
); tail
= Fcdr (tail
))
1549 register Lisp_Object elt
, tem
;
1552 if (!CONSP (elt
)) continue;
1556 if (lstrcmpi (XSTRING (tem
)->data
, colorname
) == 0)
1558 ret
= XUINT (Fcdr (elt
));
1572 x_to_w32_color (colorname
)
1575 register Lisp_Object ret
= Qnil
;
1579 if (colorname
[0] == '#')
1581 /* Could be an old-style RGB Device specification. */
1584 color
= colorname
+ 1;
1586 size
= strlen(color
);
1587 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
1595 for (i
= 0; i
< 3; i
++)
1599 unsigned long value
;
1601 /* The check for 'x' in the following conditional takes into
1602 account the fact that strtol allows a "0x" in front of
1603 our numbers, and we don't. */
1604 if (!isxdigit(color
[0]) || color
[1] == 'x')
1608 value
= strtoul(color
, &end
, 16);
1610 if (errno
== ERANGE
|| end
- color
!= size
)
1615 value
= value
* 0x10;
1626 colorval
|= (value
<< pos
);
1637 else if (strnicmp(colorname
, "rgb:", 4) == 0)
1645 color
= colorname
+ 4;
1646 for (i
= 0; i
< 3; i
++)
1649 unsigned long value
;
1651 /* The check for 'x' in the following conditional takes into
1652 account the fact that strtol allows a "0x" in front of
1653 our numbers, and we don't. */
1654 if (!isxdigit(color
[0]) || color
[1] == 'x')
1656 value
= strtoul(color
, &end
, 16);
1657 if (errno
== ERANGE
)
1659 switch (end
- color
)
1662 value
= value
* 0x10 + value
;
1675 if (value
== ULONG_MAX
)
1677 colorval
|= (value
<< pos
);
1691 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1693 /* This is an RGB Intensity specification. */
1700 color
= colorname
+ 5;
1701 for (i
= 0; i
< 3; i
++)
1707 value
= strtod(color
, &end
);
1708 if (errno
== ERANGE
)
1710 if (value
< 0.0 || value
> 1.0)
1712 val
= (UINT
)(0x100 * value
);
1713 /* We used 0x100 instead of 0xFF to give an continuous
1714 range between 0.0 and 1.0 inclusive. The next statement
1715 fixes the 1.0 case. */
1718 colorval
|= (val
<< pos
);
1732 /* I am not going to attempt to handle any of the CIE color schemes
1733 or TekHVC, since I don't know the algorithms for conversion to
1736 /* If we fail to lookup the color name in w32_color_map, then check the
1737 colorname to see if it can be crudely approximated: If the X color
1738 ends in a number (e.g., "darkseagreen2"), strip the number and
1739 return the result of looking up the base color name. */
1740 ret
= w32_color_map_lookup (colorname
);
1743 int len
= strlen (colorname
);
1745 if (isdigit (colorname
[len
- 1]))
1747 char *ptr
, *approx
= alloca (len
+ 1);
1749 strcpy (approx
, colorname
);
1750 ptr
= &approx
[len
- 1];
1751 while (ptr
> approx
&& isdigit (*ptr
))
1754 ret
= w32_color_map_lookup (approx
);
1764 w32_regenerate_palette (FRAME_PTR f
)
1766 struct w32_palette_entry
* list
;
1767 LOGPALETTE
* log_palette
;
1768 HPALETTE new_palette
;
1771 /* don't bother trying to create palette if not supported */
1772 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1775 log_palette
= (LOGPALETTE
*)
1776 alloca (sizeof (LOGPALETTE
) +
1777 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1778 log_palette
->palVersion
= 0x300;
1779 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1781 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1783 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1784 i
++, list
= list
->next
)
1785 log_palette
->palPalEntry
[i
] = list
->entry
;
1787 new_palette
= CreatePalette (log_palette
);
1791 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1792 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1793 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1795 /* Realize display palette and garbage all frames. */
1796 release_frame_dc (f
, get_frame_dc (f
));
1801 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1802 #define SET_W32_COLOR(pe, color) \
1805 pe.peRed = GetRValue (color); \
1806 pe.peGreen = GetGValue (color); \
1807 pe.peBlue = GetBValue (color); \
1812 /* Keep these around in case we ever want to track color usage. */
1814 w32_map_color (FRAME_PTR f
, COLORREF color
)
1816 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1818 if (NILP (Vw32_enable_palette
))
1821 /* check if color is already mapped */
1824 if (W32_COLOR (list
->entry
) == color
)
1832 /* not already mapped, so add to list and recreate Windows palette */
1833 list
= (struct w32_palette_entry
*)
1834 xmalloc (sizeof (struct w32_palette_entry
));
1835 SET_W32_COLOR (list
->entry
, color
);
1837 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1838 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1839 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1841 /* set flag that palette must be regenerated */
1842 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1846 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1848 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1849 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1851 if (NILP (Vw32_enable_palette
))
1854 /* check if color is already mapped */
1857 if (W32_COLOR (list
->entry
) == color
)
1859 if (--list
->refcount
== 0)
1863 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1873 /* set flag that palette must be regenerated */
1874 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1879 /* Gamma-correct COLOR on frame F. */
1882 gamma_correct (f
, color
)
1888 *color
= PALETTERGB (
1889 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1890 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1891 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1896 /* Decide if color named COLOR is valid for the display associated with
1897 the selected frame; if so, return the rgb values in COLOR_DEF.
1898 If ALLOC is nonzero, allocate a new colormap cell. */
1901 w32_defined_color (f
, color
, color_def
, alloc
)
1907 register Lisp_Object tem
;
1908 COLORREF w32_color_ref
;
1910 tem
= x_to_w32_color (color
);
1916 /* Apply gamma correction. */
1917 w32_color_ref
= XUINT (tem
);
1918 gamma_correct (f
, &w32_color_ref
);
1919 XSETINT (tem
, w32_color_ref
);
1922 /* Map this color to the palette if it is enabled. */
1923 if (!NILP (Vw32_enable_palette
))
1925 struct w32_palette_entry
* entry
=
1926 one_w32_display_info
.color_list
;
1927 struct w32_palette_entry
** prev
=
1928 &one_w32_display_info
.color_list
;
1930 /* check if color is already mapped */
1933 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1935 prev
= &entry
->next
;
1936 entry
= entry
->next
;
1939 if (entry
== NULL
&& alloc
)
1941 /* not already mapped, so add to list */
1942 entry
= (struct w32_palette_entry
*)
1943 xmalloc (sizeof (struct w32_palette_entry
));
1944 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1947 one_w32_display_info
.num_colors
++;
1949 /* set flag that palette must be regenerated */
1950 one_w32_display_info
.regen_palette
= TRUE
;
1953 /* Ensure COLORREF value is snapped to nearest color in (default)
1954 palette by simulating the PALETTERGB macro. This works whether
1955 or not the display device has a palette. */
1956 w32_color_ref
= XUINT (tem
) | 0x2000000;
1958 color_def
->pixel
= w32_color_ref
;
1959 color_def
->red
= GetRValue (w32_color_ref
);
1960 color_def
->green
= GetGValue (w32_color_ref
);
1961 color_def
->blue
= GetBValue (w32_color_ref
);
1971 /* Given a string ARG naming a color, compute a pixel value from it
1972 suitable for screen F.
1973 If F is not a color screen, return DEF (default) regardless of what
1977 x_decode_color (f
, arg
, def
)
1986 if (strcmp (XSTRING (arg
)->data
, "black") == 0)
1987 return BLACK_PIX_DEFAULT (f
);
1988 else if (strcmp (XSTRING (arg
)->data
, "white") == 0)
1989 return WHITE_PIX_DEFAULT (f
);
1991 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1994 /* w32_defined_color is responsible for coping with failures
1995 by looking for a near-miss. */
1996 if (w32_defined_color (f
, XSTRING (arg
)->data
, &cdef
, 1))
1999 /* defined_color failed; return an ultimate default. */
2003 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
2004 the previous value of that parameter, NEW_VALUE is the new value. */
2007 x_set_line_spacing (f
, new_value
, old_value
)
2009 Lisp_Object new_value
, old_value
;
2011 if (NILP (new_value
))
2012 f
->extra_line_spacing
= 0;
2013 else if (NATNUMP (new_value
))
2014 f
->extra_line_spacing
= XFASTINT (new_value
);
2016 Fsignal (Qerror
, Fcons (build_string ("Invalid line-spacing"),
2017 Fcons (new_value
, Qnil
)));
2018 if (FRAME_VISIBLE_P (f
))
2023 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
2024 the previous value of that parameter, NEW_VALUE is the new value. */
2027 x_set_fullscreen (f
, new_value
, old_value
)
2029 Lisp_Object new_value
, old_value
;
2031 if (NILP (new_value
))
2032 f
->output_data
.w32
->want_fullscreen
= FULLSCREEN_NONE
;
2033 else if (EQ (new_value
, Qfullboth
))
2034 f
->output_data
.w32
->want_fullscreen
= FULLSCREEN_BOTH
;
2035 else if (EQ (new_value
, Qfullwidth
))
2036 f
->output_data
.w32
->want_fullscreen
= FULLSCREEN_WIDTH
;
2037 else if (EQ (new_value
, Qfullheight
))
2038 f
->output_data
.w32
->want_fullscreen
= FULLSCREEN_HEIGHT
;
2042 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
2043 the previous value of that parameter, NEW_VALUE is the new value. */
2046 x_set_screen_gamma (f
, new_value
, old_value
)
2048 Lisp_Object new_value
, old_value
;
2050 if (NILP (new_value
))
2052 else if (NUMBERP (new_value
) && XFLOATINT (new_value
) > 0)
2053 /* The value 0.4545 is the normal viewing gamma. */
2054 f
->gamma
= 1.0 / (0.4545 * XFLOATINT (new_value
));
2056 Fsignal (Qerror
, Fcons (build_string ("Invalid screen-gamma"),
2057 Fcons (new_value
, Qnil
)));
2059 clear_face_cache (0);
2063 /* Functions called only from `x_set_frame_param'
2064 to set individual parameters.
2066 If FRAME_W32_WINDOW (f) is 0,
2067 the frame is being created and its window does not exist yet.
2068 In that case, just record the parameter's new value
2069 in the standard place; do not attempt to change the window. */
2072 x_set_foreground_color (f
, arg
, oldval
)
2074 Lisp_Object arg
, oldval
;
2076 struct w32_output
*x
= f
->output_data
.w32
;
2077 PIX_TYPE fg
, old_fg
;
2079 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2080 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
2081 FRAME_FOREGROUND_PIXEL (f
) = fg
;
2083 if (FRAME_W32_WINDOW (f
) != 0)
2085 if (x
->cursor_pixel
== old_fg
)
2086 x
->cursor_pixel
= fg
;
2088 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
2089 if (FRAME_VISIBLE_P (f
))
2095 x_set_background_color (f
, arg
, oldval
)
2097 Lisp_Object arg
, oldval
;
2099 FRAME_BACKGROUND_PIXEL (f
)
2100 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
2102 if (FRAME_W32_WINDOW (f
) != 0)
2104 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
2105 FRAME_BACKGROUND_PIXEL (f
));
2107 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
2109 if (FRAME_VISIBLE_P (f
))
2115 x_set_mouse_color (f
, arg
, oldval
)
2117 Lisp_Object arg
, oldval
;
2119 Cursor cursor
, nontext_cursor
, mode_cursor
, cross_cursor
;
2123 if (!EQ (Qnil
, arg
))
2124 f
->output_data
.w32
->mouse_pixel
2125 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2126 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
2128 /* Don't let pointers be invisible. */
2129 if (mask_color
== f
->output_data
.w32
->mouse_pixel
2130 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
2131 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
2133 #if 0 /* TODO : cursor changes */
2136 /* It's not okay to crash if the user selects a screwy cursor. */
2137 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
2139 if (!EQ (Qnil
, Vx_pointer_shape
))
2141 CHECK_NUMBER (Vx_pointer_shape
);
2142 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
2145 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2146 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
2148 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
2150 CHECK_NUMBER (Vx_nontext_pointer_shape
);
2151 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2152 XINT (Vx_nontext_pointer_shape
));
2155 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
2156 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2158 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
2160 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
2161 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2162 XINT (Vx_hourglass_pointer_shape
));
2165 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
2166 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
2168 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2169 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
2171 CHECK_NUMBER (Vx_mode_pointer_shape
);
2172 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2173 XINT (Vx_mode_pointer_shape
));
2176 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2177 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
2179 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
2181 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
2183 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2184 XINT (Vx_sensitive_text_pointer_shape
));
2187 cross_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
2189 if (!NILP (Vx_window_horizontal_drag_shape
))
2191 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
2192 horizontal_drag_cursor
2193 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
2194 XINT (Vx_window_horizontal_drag_shape
));
2197 horizontal_drag_cursor
2198 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
2200 /* Check and report errors with the above calls. */
2201 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
2202 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
2205 XColor fore_color
, back_color
;
2207 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
2208 back_color
.pixel
= mask_color
;
2209 XQueryColor (FRAME_W32_DISPLAY (f
),
2210 DefaultColormap (FRAME_W32_DISPLAY (f
),
2211 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2213 XQueryColor (FRAME_W32_DISPLAY (f
),
2214 DefaultColormap (FRAME_W32_DISPLAY (f
),
2215 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2217 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
2218 &fore_color
, &back_color
);
2219 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
2220 &fore_color
, &back_color
);
2221 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
2222 &fore_color
, &back_color
);
2223 XRecolorCursor (FRAME_W32_DISPLAY (f
), cross_cursor
,
2224 &fore_color
, &back_color
);
2225 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
2226 &fore_color
, &back_color
);
2229 if (FRAME_W32_WINDOW (f
) != 0)
2230 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
2232 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
2233 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
2234 f
->output_data
.w32
->text_cursor
= cursor
;
2236 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
2237 && f
->output_data
.w32
->nontext_cursor
!= 0)
2238 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
2239 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
2241 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
2242 && f
->output_data
.w32
->hourglass_cursor
!= 0)
2243 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
2244 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
2246 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
2247 && f
->output_data
.w32
->modeline_cursor
!= 0)
2248 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
2249 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
2251 if (cross_cursor
!= f
->output_data
.w32
->cross_cursor
2252 && f
->output_data
.w32
->cross_cursor
!= 0)
2253 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->cross_cursor
);
2254 f
->output_data
.w32
->cross_cursor
= cross_cursor
;
2256 XFlush (FRAME_W32_DISPLAY (f
));
2259 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
2263 /* Defined in w32term.c. */
2264 void x_update_cursor (struct frame
*f
, int on_p
);
2267 x_set_cursor_color (f
, arg
, oldval
)
2269 Lisp_Object arg
, oldval
;
2271 unsigned long fore_pixel
, pixel
;
2273 if (!NILP (Vx_cursor_fore_pixel
))
2274 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
2275 WHITE_PIX_DEFAULT (f
));
2277 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2279 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2281 /* Make sure that the cursor color differs from the background color. */
2282 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
2284 pixel
= f
->output_data
.w32
->mouse_pixel
;
2285 if (pixel
== fore_pixel
)
2286 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2289 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
2290 f
->output_data
.w32
->cursor_pixel
= pixel
;
2292 if (FRAME_W32_WINDOW (f
) != 0)
2295 /* Update frame's cursor_gc. */
2296 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
2297 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
2301 if (FRAME_VISIBLE_P (f
))
2303 x_update_cursor (f
, 0);
2304 x_update_cursor (f
, 1);
2308 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
2311 /* Set the border-color of frame F to pixel value PIX.
2312 Note that this does not fully take effect if done before
2315 x_set_border_pixel (f
, pix
)
2319 f
->output_data
.w32
->border_pixel
= pix
;
2321 if (FRAME_W32_WINDOW (f
) != 0 && f
->output_data
.w32
->border_width
> 0)
2323 if (FRAME_VISIBLE_P (f
))
2328 /* Set the border-color of frame F to value described by ARG.
2329 ARG can be a string naming a color.
2330 The border-color is used for the border that is drawn by the server.
2331 Note that this does not fully take effect if done before
2332 F has a window; it must be redone when the window is created. */
2335 x_set_border_color (f
, arg
, oldval
)
2337 Lisp_Object arg
, oldval
;
2342 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2343 x_set_border_pixel (f
, pix
);
2344 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
2347 /* Value is the internal representation of the specified cursor type
2348 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
2349 of the bar cursor. */
2351 enum text_cursor_kinds
2352 x_specified_cursor_type (arg
, width
)
2356 enum text_cursor_kinds type
;
2363 else if (CONSP (arg
)
2364 && EQ (XCAR (arg
), Qbar
)
2365 && INTEGERP (XCDR (arg
))
2366 && XINT (XCDR (arg
)) >= 0)
2369 *width
= XINT (XCDR (arg
));
2371 else if (NILP (arg
))
2374 /* Treat anything unknown as "box cursor".
2375 It was bad to signal an error; people have trouble fixing
2376 .Xdefaults with Emacs, when it has something bad in it. */
2377 type
= FILLED_BOX_CURSOR
;
2383 x_set_cursor_type (f
, arg
, oldval
)
2385 Lisp_Object arg
, oldval
;
2389 FRAME_DESIRED_CURSOR (f
) = x_specified_cursor_type (arg
, &width
);
2390 f
->output_data
.w32
->cursor_width
= width
;
2392 /* Make sure the cursor gets redrawn. This is overkill, but how
2393 often do people change cursor types? */
2394 update_mode_lines
++;
2398 x_set_icon_type (f
, arg
, oldval
)
2400 Lisp_Object arg
, oldval
;
2404 if (NILP (arg
) && NILP (oldval
))
2407 if (STRINGP (arg
) && STRINGP (oldval
)
2408 && EQ (Fstring_equal (oldval
, arg
), Qt
))
2411 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
2416 result
= x_bitmap_icon (f
, arg
);
2420 error ("No icon window available");
2426 /* Return non-nil if frame F wants a bitmap icon. */
2434 tem
= assq_no_quit (Qicon_type
, f
->param_alist
);
2442 x_set_icon_name (f
, arg
, oldval
)
2444 Lisp_Object arg
, oldval
;
2448 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
2451 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
2457 if (f
->output_data
.w32
->icon_bitmap
!= 0)
2462 result
= x_text_icon (f
,
2463 (char *) XSTRING ((!NILP (f
->icon_name
)
2472 error ("No icon window available");
2475 /* If the window was unmapped (and its icon was mapped),
2476 the new icon is not mapped, so map the window in its stead. */
2477 if (FRAME_VISIBLE_P (f
))
2479 #ifdef USE_X_TOOLKIT
2480 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
2482 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
2485 XFlush (FRAME_W32_DISPLAY (f
));
2490 extern Lisp_Object
x_new_font ();
2491 extern Lisp_Object
x_new_fontset();
2494 x_set_font (f
, arg
, oldval
)
2496 Lisp_Object arg
, oldval
;
2499 Lisp_Object fontset_name
;
2501 int old_fontset
= FRAME_FONTSET(f
);
2505 fontset_name
= Fquery_fontset (arg
, Qnil
);
2508 result
= (STRINGP (fontset_name
)
2509 ? x_new_fontset (f
, XSTRING (fontset_name
)->data
)
2510 : x_new_font (f
, XSTRING (arg
)->data
));
2513 if (EQ (result
, Qnil
))
2514 error ("Font `%s' is not defined", XSTRING (arg
)->data
);
2515 else if (EQ (result
, Qt
))
2516 error ("The characters of the given font have varying widths");
2517 else if (STRINGP (result
))
2519 if (STRINGP (fontset_name
))
2521 /* Fontset names are built from ASCII font names, so the
2522 names may be equal despite there was a change. */
2523 if (old_fontset
== FRAME_FONTSET (f
))
2526 else if (!NILP (Fequal (result
, oldval
)))
2529 store_frame_param (f
, Qfont
, result
);
2530 recompute_basic_faces (f
);
2535 do_pending_window_change (0);
2537 /* Don't call `face-set-after-frame-default' when faces haven't been
2538 initialized yet. This is the case when called from
2539 Fx_create_frame. In that case, the X widget or window doesn't
2540 exist either, and we can end up in x_report_frame_params with a
2541 null widget which gives a segfault. */
2542 if (FRAME_FACE_CACHE (f
))
2544 XSETFRAME (frame
, f
);
2545 call1 (Qface_set_after_frame_default
, frame
);
2550 x_set_fringe_width (f
, new_value
, old_value
)
2552 Lisp_Object new_value
, old_value
;
2554 x_compute_fringe_widths (f
, 1);
2558 x_set_border_width (f
, arg
, oldval
)
2560 Lisp_Object arg
, oldval
;
2564 if (XINT (arg
) == f
->output_data
.w32
->border_width
)
2567 if (FRAME_W32_WINDOW (f
) != 0)
2568 error ("Cannot change the border width of a window");
2570 f
->output_data
.w32
->border_width
= XINT (arg
);
2574 x_set_internal_border_width (f
, arg
, oldval
)
2576 Lisp_Object arg
, oldval
;
2578 int old
= f
->output_data
.w32
->internal_border_width
;
2581 f
->output_data
.w32
->internal_border_width
= XINT (arg
);
2582 if (f
->output_data
.w32
->internal_border_width
< 0)
2583 f
->output_data
.w32
->internal_border_width
= 0;
2585 if (f
->output_data
.w32
->internal_border_width
== old
)
2588 if (FRAME_W32_WINDOW (f
) != 0)
2590 x_set_window_size (f
, 0, f
->width
, f
->height
);
2591 SET_FRAME_GARBAGED (f
);
2592 do_pending_window_change (0);
2595 SET_FRAME_GARBAGED (f
);
2599 x_set_visibility (f
, value
, oldval
)
2601 Lisp_Object value
, oldval
;
2604 XSETFRAME (frame
, f
);
2607 Fmake_frame_invisible (frame
, Qt
);
2608 else if (EQ (value
, Qicon
))
2609 Ficonify_frame (frame
);
2611 Fmake_frame_visible (frame
);
2615 /* Change window heights in windows rooted in WINDOW by N lines. */
2618 x_change_window_heights (window
, n
)
2622 struct window
*w
= XWINDOW (window
);
2624 XSETFASTINT (w
->top
, XFASTINT (w
->top
) + n
);
2625 XSETFASTINT (w
->height
, XFASTINT (w
->height
) - n
);
2627 if (INTEGERP (w
->orig_top
))
2628 XSETFASTINT (w
->orig_top
, XFASTINT (w
->orig_top
) + n
);
2629 if (INTEGERP (w
->orig_height
))
2630 XSETFASTINT (w
->orig_height
, XFASTINT (w
->orig_height
) - n
);
2632 /* Handle just the top child in a vertical split. */
2633 if (!NILP (w
->vchild
))
2634 x_change_window_heights (w
->vchild
, n
);
2636 /* Adjust all children in a horizontal split. */
2637 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
2639 w
= XWINDOW (window
);
2640 x_change_window_heights (window
, n
);
2645 x_set_menu_bar_lines (f
, value
, oldval
)
2647 Lisp_Object value
, oldval
;
2650 int olines
= FRAME_MENU_BAR_LINES (f
);
2652 /* Right now, menu bars don't work properly in minibuf-only frames;
2653 most of the commands try to apply themselves to the minibuffer
2654 frame itself, and get an error because you can't switch buffers
2655 in or split the minibuffer window. */
2656 if (FRAME_MINIBUF_ONLY_P (f
))
2659 if (INTEGERP (value
))
2660 nlines
= XINT (value
);
2664 FRAME_MENU_BAR_LINES (f
) = 0;
2666 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
2669 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
2670 free_frame_menubar (f
);
2671 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
2673 /* Adjust the frame size so that the client (text) dimensions
2674 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
2676 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2677 do_pending_window_change (0);
2683 /* Set the number of lines used for the tool bar of frame F to VALUE.
2684 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
2685 is the old number of tool bar lines. This function changes the
2686 height of all windows on frame F to match the new tool bar height.
2687 The frame's height doesn't change. */
2690 x_set_tool_bar_lines (f
, value
, oldval
)
2692 Lisp_Object value
, oldval
;
2694 int delta
, nlines
, root_height
;
2695 Lisp_Object root_window
;
2697 /* Treat tool bars like menu bars. */
2698 if (FRAME_MINIBUF_ONLY_P (f
))
2701 /* Use VALUE only if an integer >= 0. */
2702 if (INTEGERP (value
) && XINT (value
) >= 0)
2703 nlines
= XFASTINT (value
);
2707 /* Make sure we redisplay all windows in this frame. */
2708 ++windows_or_buffers_changed
;
2710 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
2712 /* Don't resize the tool-bar to more than we have room for. */
2713 root_window
= FRAME_ROOT_WINDOW (f
);
2714 root_height
= XINT (XWINDOW (root_window
)->height
);
2715 if (root_height
- delta
< 1)
2717 delta
= root_height
- 1;
2718 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
2721 FRAME_TOOL_BAR_LINES (f
) = nlines
;
2722 x_change_window_heights (root_window
, delta
);
2725 /* We also have to make sure that the internal border at the top of
2726 the frame, below the menu bar or tool bar, is redrawn when the
2727 tool bar disappears. This is so because the internal border is
2728 below the tool bar if one is displayed, but is below the menu bar
2729 if there isn't a tool bar. The tool bar draws into the area
2730 below the menu bar. */
2731 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
2735 clear_current_matrices (f
);
2736 updating_frame
= NULL
;
2739 /* If the tool bar gets smaller, the internal border below it
2740 has to be cleared. It was formerly part of the display
2741 of the larger tool bar, and updating windows won't clear it. */
2744 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2745 int width
= PIXEL_WIDTH (f
);
2746 int y
= nlines
* CANON_Y_UNIT (f
);
2750 HDC hdc
= get_frame_dc (f
);
2751 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
2752 release_frame_dc (f
, hdc
);
2756 if (WINDOWP (f
->tool_bar_window
))
2757 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
2762 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
2765 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2766 name; if NAME is a string, set F's name to NAME and set
2767 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2769 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2770 suggesting a new name, which lisp code should override; if
2771 F->explicit_name is set, ignore the new name; otherwise, set it. */
2774 x_set_name (f
, name
, explicit)
2779 /* Make sure that requests from lisp code override requests from
2780 Emacs redisplay code. */
2783 /* If we're switching from explicit to implicit, we had better
2784 update the mode lines and thereby update the title. */
2785 if (f
->explicit_name
&& NILP (name
))
2786 update_mode_lines
= 1;
2788 f
->explicit_name
= ! NILP (name
);
2790 else if (f
->explicit_name
)
2793 /* If NAME is nil, set the name to the w32_id_name. */
2796 /* Check for no change needed in this very common case
2797 before we do any consing. */
2798 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
2799 XSTRING (f
->name
)->data
))
2801 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
2804 CHECK_STRING (name
);
2806 /* Don't change the name if it's already NAME. */
2807 if (! NILP (Fstring_equal (name
, f
->name
)))
2812 /* For setting the frame title, the title parameter should override
2813 the name parameter. */
2814 if (! NILP (f
->title
))
2817 if (FRAME_W32_WINDOW (f
))
2819 if (STRING_MULTIBYTE (name
))
2820 name
= ENCODE_SYSTEM (name
);
2823 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2828 /* This function should be called when the user's lisp code has
2829 specified a name for the frame; the name will override any set by the
2832 x_explicitly_set_name (f
, arg
, oldval
)
2834 Lisp_Object arg
, oldval
;
2836 x_set_name (f
, arg
, 1);
2839 /* This function should be called by Emacs redisplay code to set the
2840 name; names set this way will never override names set by the user's
2843 x_implicitly_set_name (f
, arg
, oldval
)
2845 Lisp_Object arg
, oldval
;
2847 x_set_name (f
, arg
, 0);
2850 /* Change the title of frame F to NAME.
2851 If NAME is nil, use the frame name as the title.
2853 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2854 name; if NAME is a string, set F's name to NAME and set
2855 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2857 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2858 suggesting a new name, which lisp code should override; if
2859 F->explicit_name is set, ignore the new name; otherwise, set it. */
2862 x_set_title (f
, name
, old_name
)
2864 Lisp_Object name
, old_name
;
2866 /* Don't change the title if it's already NAME. */
2867 if (EQ (name
, f
->title
))
2870 update_mode_lines
= 1;
2877 if (FRAME_W32_WINDOW (f
))
2879 if (STRING_MULTIBYTE (name
))
2880 name
= ENCODE_SYSTEM (name
);
2883 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2889 x_set_autoraise (f
, arg
, oldval
)
2891 Lisp_Object arg
, oldval
;
2893 f
->auto_raise
= !EQ (Qnil
, arg
);
2897 x_set_autolower (f
, arg
, oldval
)
2899 Lisp_Object arg
, oldval
;
2901 f
->auto_lower
= !EQ (Qnil
, arg
);
2905 x_set_unsplittable (f
, arg
, oldval
)
2907 Lisp_Object arg
, oldval
;
2909 f
->no_split
= !NILP (arg
);
2913 x_set_vertical_scroll_bars (f
, arg
, oldval
)
2915 Lisp_Object arg
, oldval
;
2917 if ((EQ (arg
, Qleft
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
2918 || (EQ (arg
, Qright
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
2919 || (NILP (arg
) && FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2920 || (!NILP (arg
) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)))
2922 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = NILP (arg
) ?
2923 vertical_scroll_bar_none
:
2924 /* Put scroll bars on the right by default, as is conventional
2927 ? vertical_scroll_bar_left
2928 : vertical_scroll_bar_right
;
2930 /* We set this parameter before creating the window for the
2931 frame, so we can get the geometry right from the start.
2932 However, if the window hasn't been created yet, we shouldn't
2933 call x_set_window_size. */
2934 if (FRAME_W32_WINDOW (f
))
2935 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2936 do_pending_window_change (0);
2941 x_set_scroll_bar_width (f
, arg
, oldval
)
2943 Lisp_Object arg
, oldval
;
2945 int wid
= FONT_WIDTH (f
->output_data
.w32
->font
);
2949 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
2950 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) +
2952 if (FRAME_W32_WINDOW (f
))
2953 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2954 do_pending_window_change (0);
2956 else if (INTEGERP (arg
) && XINT (arg
) > 0
2957 && XFASTINT (arg
) != FRAME_SCROLL_BAR_PIXEL_WIDTH (f
))
2959 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = XFASTINT (arg
);
2960 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
2962 if (FRAME_W32_WINDOW (f
))
2963 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2964 do_pending_window_change (0);
2966 change_frame_size (f
, 0, FRAME_WIDTH (f
), 0, 0, 0);
2967 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.hpos
= 0;
2968 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.x
= 0;
2971 /* Subroutines of creating an frame. */
2973 /* Make sure that Vx_resource_name is set to a reasonable value.
2974 Fix it up, or set it to `emacs' if it is too hopeless. */
2977 validate_x_resource_name ()
2980 /* Number of valid characters in the resource name. */
2982 /* Number of invalid characters in the resource name. */
2987 if (STRINGP (Vx_resource_name
))
2989 unsigned char *p
= XSTRING (Vx_resource_name
)->data
;
2992 len
= STRING_BYTES (XSTRING (Vx_resource_name
));
2994 /* Only letters, digits, - and _ are valid in resource names.
2995 Count the valid characters and count the invalid ones. */
2996 for (i
= 0; i
< len
; i
++)
2999 if (! ((c
>= 'a' && c
<= 'z')
3000 || (c
>= 'A' && c
<= 'Z')
3001 || (c
>= '0' && c
<= '9')
3002 || c
== '-' || c
== '_'))
3009 /* Not a string => completely invalid. */
3010 bad_count
= 5, good_count
= 0;
3012 /* If name is valid already, return. */
3016 /* If name is entirely invalid, or nearly so, use `emacs'. */
3018 || (good_count
== 1 && bad_count
> 0))
3020 Vx_resource_name
= build_string ("emacs");
3024 /* Name is partly valid. Copy it and replace the invalid characters
3025 with underscores. */
3027 Vx_resource_name
= new = Fcopy_sequence (Vx_resource_name
);
3029 for (i
= 0; i
< len
; i
++)
3031 int c
= XSTRING (new)->data
[i
];
3032 if (! ((c
>= 'a' && c
<= 'z')
3033 || (c
>= 'A' && c
<= 'Z')
3034 || (c
>= '0' && c
<= '9')
3035 || c
== '-' || c
== '_'))
3036 XSTRING (new)->data
[i
] = '_';
3041 extern char *x_get_string_resource ();
3043 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
3044 doc
: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3045 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3046 class, where INSTANCE is the name under which Emacs was invoked, or
3047 the name specified by the `-name' or `-rn' command-line arguments.
3049 The optional arguments COMPONENT and SUBCLASS add to the key and the
3050 class, respectively. You must specify both of them or neither.
3051 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3052 and the class is `Emacs.CLASS.SUBCLASS'. */)
3053 (attribute
, class, component
, subclass
)
3054 Lisp_Object attribute
, class, component
, subclass
;
3056 register char *value
;
3060 CHECK_STRING (attribute
);
3061 CHECK_STRING (class);
3063 if (!NILP (component
))
3064 CHECK_STRING (component
);
3065 if (!NILP (subclass
))
3066 CHECK_STRING (subclass
);
3067 if (NILP (component
) != NILP (subclass
))
3068 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3070 validate_x_resource_name ();
3072 /* Allocate space for the components, the dots which separate them,
3073 and the final '\0'. Make them big enough for the worst case. */
3074 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vx_resource_name
))
3075 + (STRINGP (component
)
3076 ? STRING_BYTES (XSTRING (component
)) : 0)
3077 + STRING_BYTES (XSTRING (attribute
))
3080 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
3081 + STRING_BYTES (XSTRING (class))
3082 + (STRINGP (subclass
)
3083 ? STRING_BYTES (XSTRING (subclass
)) : 0)
3086 /* Start with emacs.FRAMENAME for the name (the specific one)
3087 and with `Emacs' for the class key (the general one). */
3088 strcpy (name_key
, XSTRING (Vx_resource_name
)->data
);
3089 strcpy (class_key
, EMACS_CLASS
);
3091 strcat (class_key
, ".");
3092 strcat (class_key
, XSTRING (class)->data
);
3094 if (!NILP (component
))
3096 strcat (class_key
, ".");
3097 strcat (class_key
, XSTRING (subclass
)->data
);
3099 strcat (name_key
, ".");
3100 strcat (name_key
, XSTRING (component
)->data
);
3103 strcat (name_key
, ".");
3104 strcat (name_key
, XSTRING (attribute
)->data
);
3106 value
= x_get_string_resource (Qnil
,
3107 name_key
, class_key
);
3109 if (value
!= (char *) 0)
3110 return build_string (value
);
3115 /* Used when C code wants a resource value. */
3118 x_get_resource_string (attribute
, class)
3119 char *attribute
, *class;
3123 struct frame
*sf
= SELECTED_FRAME ();
3125 /* Allocate space for the components, the dots which separate them,
3126 and the final '\0'. */
3127 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vinvocation_name
))
3128 + strlen (attribute
) + 2);
3129 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
3130 + strlen (class) + 2);
3132 sprintf (name_key
, "%s.%s",
3133 XSTRING (Vinvocation_name
)->data
,
3135 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
3137 return x_get_string_resource (sf
, name_key
, class_key
);
3140 /* Types we might convert a resource string into. */
3150 /* Return the value of parameter PARAM.
3152 First search ALIST, then Vdefault_frame_alist, then the X defaults
3153 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3155 Convert the resource to the type specified by desired_type.
3157 If no default is specified, return Qunbound. If you call
3158 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
3159 and don't let it get stored in any Lisp-visible variables! */
3162 w32_get_arg (alist
, param
, attribute
, class, type
)
3163 Lisp_Object alist
, param
;
3166 enum resource_types type
;
3168 register Lisp_Object tem
;
3170 tem
= Fassq (param
, alist
);
3172 tem
= Fassq (param
, Vdefault_frame_alist
);
3178 tem
= Fx_get_resource (build_string (attribute
),
3179 build_string (class),
3187 case RES_TYPE_NUMBER
:
3188 return make_number (atoi (XSTRING (tem
)->data
));
3190 case RES_TYPE_FLOAT
:
3191 return make_float (atof (XSTRING (tem
)->data
));
3193 case RES_TYPE_BOOLEAN
:
3194 tem
= Fdowncase (tem
);
3195 if (!strcmp (XSTRING (tem
)->data
, "on")
3196 || !strcmp (XSTRING (tem
)->data
, "true"))
3201 case RES_TYPE_STRING
:
3204 case RES_TYPE_SYMBOL
:
3205 /* As a special case, we map the values `true' and `on'
3206 to Qt, and `false' and `off' to Qnil. */
3209 lower
= Fdowncase (tem
);
3210 if (!strcmp (XSTRING (lower
)->data
, "on")
3211 || !strcmp (XSTRING (lower
)->data
, "true"))
3213 else if (!strcmp (XSTRING (lower
)->data
, "off")
3214 || !strcmp (XSTRING (lower
)->data
, "false"))
3217 return Fintern (tem
, Qnil
);
3230 /* Record in frame F the specified or default value according to ALIST
3231 of the parameter named PROP (a Lisp symbol).
3232 If no value is specified for PROP, look for an X default for XPROP
3233 on the frame named NAME.
3234 If that is not found either, use the value DEFLT. */
3237 x_default_parameter (f
, alist
, prop
, deflt
, xprop
, xclass
, type
)
3244 enum resource_types type
;
3248 tem
= w32_get_arg (alist
, prop
, xprop
, xclass
, type
);
3249 if (EQ (tem
, Qunbound
))
3251 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
3255 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
3256 doc
: /* Parse an X-style geometry string STRING.
3257 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3258 The properties returned may include `top', `left', `height', and `width'.
3259 The value of `left' or `top' may be an integer,
3260 or a list (+ N) meaning N pixels relative to top/left corner,
3261 or a list (- N) meaning -N pixels relative to bottom/right corner. */)
3266 unsigned int width
, height
;
3269 CHECK_STRING (string
);
3271 geometry
= XParseGeometry ((char *) XSTRING (string
)->data
,
3272 &x
, &y
, &width
, &height
);
3275 if (geometry
& XValue
)
3277 Lisp_Object element
;
3279 if (x
>= 0 && (geometry
& XNegative
))
3280 element
= Fcons (Qleft
, Fcons (Qminus
, Fcons (make_number (-x
), Qnil
)));
3281 else if (x
< 0 && ! (geometry
& XNegative
))
3282 element
= Fcons (Qleft
, Fcons (Qplus
, Fcons (make_number (x
), Qnil
)));
3284 element
= Fcons (Qleft
, make_number (x
));
3285 result
= Fcons (element
, result
);
3288 if (geometry
& YValue
)
3290 Lisp_Object element
;
3292 if (y
>= 0 && (geometry
& YNegative
))
3293 element
= Fcons (Qtop
, Fcons (Qminus
, Fcons (make_number (-y
), Qnil
)));
3294 else if (y
< 0 && ! (geometry
& YNegative
))
3295 element
= Fcons (Qtop
, Fcons (Qplus
, Fcons (make_number (y
), Qnil
)));
3297 element
= Fcons (Qtop
, make_number (y
));
3298 result
= Fcons (element
, result
);
3301 if (geometry
& WidthValue
)
3302 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
3303 if (geometry
& HeightValue
)
3304 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
3309 /* Calculate the desired size and position of this window,
3310 and return the flags saying which aspects were specified.
3312 This function does not make the coordinates positive. */
3314 #define DEFAULT_ROWS 40
3315 #define DEFAULT_COLS 80
3318 x_figure_window_size (f
, parms
)
3322 register Lisp_Object tem0
, tem1
, tem2
;
3323 long window_prompting
= 0;
3325 /* Default values if we fall through.
3326 Actually, if that happens we should get
3327 window manager prompting. */
3328 SET_FRAME_WIDTH (f
, DEFAULT_COLS
);
3329 f
->height
= DEFAULT_ROWS
;
3330 /* Window managers expect that if program-specified
3331 positions are not (0,0), they're intentional, not defaults. */
3332 f
->output_data
.w32
->top_pos
= 0;
3333 f
->output_data
.w32
->left_pos
= 0;
3335 /* Ensure that old new_width and new_height will not override the
3337 FRAME_NEW_WIDTH (f
) = 0;
3338 FRAME_NEW_HEIGHT (f
) = 0;
3340 tem0
= w32_get_arg (parms
, Qheight
, 0, 0, RES_TYPE_NUMBER
);
3341 tem1
= w32_get_arg (parms
, Qwidth
, 0, 0, RES_TYPE_NUMBER
);
3342 tem2
= w32_get_arg (parms
, Quser_size
, 0, 0, RES_TYPE_NUMBER
);
3343 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3345 if (!EQ (tem0
, Qunbound
))
3347 CHECK_NUMBER (tem0
);
3348 f
->height
= XINT (tem0
);
3350 if (!EQ (tem1
, Qunbound
))
3352 CHECK_NUMBER (tem1
);
3353 SET_FRAME_WIDTH (f
, XINT (tem1
));
3355 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
3356 window_prompting
|= USSize
;
3358 window_prompting
|= PSize
;
3361 f
->output_data
.w32
->vertical_scroll_bar_extra
3362 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
3364 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
3365 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
3366 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.w32
->font
)));
3368 x_compute_fringe_widths (f
, 0);
3370 f
->output_data
.w32
->pixel_width
= CHAR_TO_PIXEL_WIDTH (f
, f
->width
);
3371 f
->output_data
.w32
->pixel_height
= CHAR_TO_PIXEL_HEIGHT (f
, f
->height
);
3373 tem0
= w32_get_arg (parms
, Qtop
, 0, 0, RES_TYPE_NUMBER
);
3374 tem1
= w32_get_arg (parms
, Qleft
, 0, 0, RES_TYPE_NUMBER
);
3375 tem2
= w32_get_arg (parms
, Quser_position
, 0, 0, RES_TYPE_NUMBER
);
3376 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3378 if (EQ (tem0
, Qminus
))
3380 f
->output_data
.w32
->top_pos
= 0;
3381 window_prompting
|= YNegative
;
3383 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qminus
)
3384 && CONSP (XCDR (tem0
))
3385 && INTEGERP (XCAR (XCDR (tem0
))))
3387 f
->output_data
.w32
->top_pos
= - XINT (XCAR (XCDR (tem0
)));
3388 window_prompting
|= YNegative
;
3390 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qplus
)
3391 && CONSP (XCDR (tem0
))
3392 && INTEGERP (XCAR (XCDR (tem0
))))
3394 f
->output_data
.w32
->top_pos
= XINT (XCAR (XCDR (tem0
)));
3396 else if (EQ (tem0
, Qunbound
))
3397 f
->output_data
.w32
->top_pos
= 0;
3400 CHECK_NUMBER (tem0
);
3401 f
->output_data
.w32
->top_pos
= XINT (tem0
);
3402 if (f
->output_data
.w32
->top_pos
< 0)
3403 window_prompting
|= YNegative
;
3406 if (EQ (tem1
, Qminus
))
3408 f
->output_data
.w32
->left_pos
= 0;
3409 window_prompting
|= XNegative
;
3411 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qminus
)
3412 && CONSP (XCDR (tem1
))
3413 && INTEGERP (XCAR (XCDR (tem1
))))
3415 f
->output_data
.w32
->left_pos
= - XINT (XCAR (XCDR (tem1
)));
3416 window_prompting
|= XNegative
;
3418 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qplus
)
3419 && CONSP (XCDR (tem1
))
3420 && INTEGERP (XCAR (XCDR (tem1
))))
3422 f
->output_data
.w32
->left_pos
= XINT (XCAR (XCDR (tem1
)));
3424 else if (EQ (tem1
, Qunbound
))
3425 f
->output_data
.w32
->left_pos
= 0;
3428 CHECK_NUMBER (tem1
);
3429 f
->output_data
.w32
->left_pos
= XINT (tem1
);
3430 if (f
->output_data
.w32
->left_pos
< 0)
3431 window_prompting
|= XNegative
;
3434 if (!NILP (tem2
) && ! EQ (tem2
, Qunbound
))
3435 window_prompting
|= USPosition
;
3437 window_prompting
|= PPosition
;
3440 if (f
->output_data
.w32
->want_fullscreen
!= FULLSCREEN_NONE
)
3445 /* It takes both for some WM:s to place it where we want */
3446 window_prompting
= USPosition
| PPosition
;
3447 x_fullscreen_adjust (f
, &width
, &height
, &top
, &left
);
3450 f
->output_data
.w32
->pixel_width
= CHAR_TO_PIXEL_WIDTH (f
, f
->width
);
3451 f
->output_data
.w32
->pixel_height
= CHAR_TO_PIXEL_HEIGHT (f
, f
->height
);
3452 f
->output_data
.w32
->left_pos
= left
;
3453 f
->output_data
.w32
->top_pos
= top
;
3456 return window_prompting
;
3461 extern LRESULT CALLBACK
w32_wnd_proc ();
3464 w32_init_class (hinst
)
3469 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
3470 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
3472 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
3473 wc
.hInstance
= hinst
;
3474 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
3475 wc
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
3476 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
3477 wc
.lpszMenuName
= NULL
;
3478 wc
.lpszClassName
= EMACS_CLASS
;
3480 return (RegisterClass (&wc
));
3484 w32_createscrollbar (f
, bar
)
3486 struct scroll_bar
* bar
;
3488 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
3489 /* Position and size of scroll bar. */
3490 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
3492 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
3494 FRAME_W32_WINDOW (f
),
3501 w32_createwindow (f
)
3507 rect
.left
= rect
.top
= 0;
3508 rect
.right
= PIXEL_WIDTH (f
);
3509 rect
.bottom
= PIXEL_HEIGHT (f
);
3511 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3512 FRAME_EXTERNAL_MENU_BAR (f
));
3514 /* Do first time app init */
3518 w32_init_class (hinst
);
3521 FRAME_W32_WINDOW (f
) = hwnd
3522 = CreateWindow (EMACS_CLASS
,
3524 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
3525 f
->output_data
.w32
->left_pos
,
3526 f
->output_data
.w32
->top_pos
,
3527 rect
.right
- rect
.left
,
3528 rect
.bottom
- rect
.top
,
3536 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
3537 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
3538 SetWindowLong (hwnd
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
3539 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->output_data
.w32
->vertical_scroll_bar_extra
);
3540 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3542 /* Enable drag-n-drop. */
3543 DragAcceptFiles (hwnd
, TRUE
);
3545 /* Do this to discard the default setting specified by our parent. */
3546 ShowWindow (hwnd
, SW_HIDE
);
3551 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
3558 wmsg
->msg
.hwnd
= hwnd
;
3559 wmsg
->msg
.message
= msg
;
3560 wmsg
->msg
.wParam
= wParam
;
3561 wmsg
->msg
.lParam
= lParam
;
3562 wmsg
->msg
.time
= GetMessageTime ();
3567 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
3568 between left and right keys as advertised. We test for this
3569 support dynamically, and set a flag when the support is absent. If
3570 absent, we keep track of the left and right control and alt keys
3571 ourselves. This is particularly necessary on keyboards that rely
3572 upon the AltGr key, which is represented as having the left control
3573 and right alt keys pressed. For these keyboards, we need to know
3574 when the left alt key has been pressed in addition to the AltGr key
3575 so that we can properly support M-AltGr-key sequences (such as M-@
3576 on Swedish keyboards). */
3578 #define EMACS_LCONTROL 0
3579 #define EMACS_RCONTROL 1
3580 #define EMACS_LMENU 2
3581 #define EMACS_RMENU 3
3583 static int modifiers
[4];
3584 static int modifiers_recorded
;
3585 static int modifier_key_support_tested
;
3588 test_modifier_support (unsigned int wparam
)
3592 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
3594 if (wparam
== VK_CONTROL
)
3604 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
3605 modifiers_recorded
= 1;
3607 modifiers_recorded
= 0;
3608 modifier_key_support_tested
= 1;
3612 record_keydown (unsigned int wparam
, unsigned int lparam
)
3616 if (!modifier_key_support_tested
)
3617 test_modifier_support (wparam
);
3619 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3622 if (wparam
== VK_CONTROL
)
3623 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3625 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3631 record_keyup (unsigned int wparam
, unsigned int lparam
)
3635 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3638 if (wparam
== VK_CONTROL
)
3639 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3641 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3646 /* Emacs can lose focus while a modifier key has been pressed. When
3647 it regains focus, be conservative and clear all modifiers since
3648 we cannot reconstruct the left and right modifier state. */
3654 if (GetFocus () == NULL
)
3655 /* Emacs doesn't have keyboard focus. Do nothing. */
3658 ctrl
= GetAsyncKeyState (VK_CONTROL
);
3659 alt
= GetAsyncKeyState (VK_MENU
);
3661 if (!(ctrl
& 0x08000))
3662 /* Clear any recorded control modifier state. */
3663 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3665 if (!(alt
& 0x08000))
3666 /* Clear any recorded alt modifier state. */
3667 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3669 /* Update the state of all modifier keys, because modifiers used in
3670 hot-key combinations can get stuck on if Emacs loses focus as a
3671 result of a hot-key being pressed. */
3675 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
3677 GetKeyboardState (keystate
);
3678 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
3679 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
3680 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
3681 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
3682 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
3683 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
3684 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
3685 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
3686 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
3687 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
3688 SetKeyboardState (keystate
);
3692 /* Synchronize modifier state with what is reported with the current
3693 keystroke. Even if we cannot distinguish between left and right
3694 modifier keys, we know that, if no modifiers are set, then neither
3695 the left or right modifier should be set. */
3699 if (!modifiers_recorded
)
3702 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
3703 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3705 if (!(GetKeyState (VK_MENU
) & 0x8000))
3706 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3710 modifier_set (int vkey
)
3712 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
3713 return (GetKeyState (vkey
) & 0x1);
3714 if (!modifiers_recorded
)
3715 return (GetKeyState (vkey
) & 0x8000);
3720 return modifiers
[EMACS_LCONTROL
];
3722 return modifiers
[EMACS_RCONTROL
];
3724 return modifiers
[EMACS_LMENU
];
3726 return modifiers
[EMACS_RMENU
];
3728 return (GetKeyState (vkey
) & 0x8000);
3731 /* Convert between the modifier bits W32 uses and the modifier bits
3735 w32_key_to_modifier (int key
)
3737 Lisp_Object key_mapping
;
3742 key_mapping
= Vw32_lwindow_modifier
;
3745 key_mapping
= Vw32_rwindow_modifier
;
3748 key_mapping
= Vw32_apps_modifier
;
3751 key_mapping
= Vw32_scroll_lock_modifier
;
3757 /* NB. This code runs in the input thread, asychronously to the lisp
3758 thread, so we must be careful to ensure access to lisp data is
3759 thread-safe. The following code is safe because the modifier
3760 variable values are updated atomically from lisp and symbols are
3761 not relocated by GC. Also, we don't have to worry about seeing GC
3763 if (EQ (key_mapping
, Qhyper
))
3764 return hyper_modifier
;
3765 if (EQ (key_mapping
, Qsuper
))
3766 return super_modifier
;
3767 if (EQ (key_mapping
, Qmeta
))
3768 return meta_modifier
;
3769 if (EQ (key_mapping
, Qalt
))
3770 return alt_modifier
;
3771 if (EQ (key_mapping
, Qctrl
))
3772 return ctrl_modifier
;
3773 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
3774 return ctrl_modifier
;
3775 if (EQ (key_mapping
, Qshift
))
3776 return shift_modifier
;
3778 /* Don't generate any modifier if not explicitly requested. */
3783 w32_get_modifiers ()
3785 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
3786 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
3787 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
3788 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
3789 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
3790 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
3791 (modifier_set (VK_MENU
) ?
3792 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
3795 /* We map the VK_* modifiers into console modifier constants
3796 so that we can use the same routines to handle both console
3797 and window input. */
3800 construct_console_modifiers ()
3805 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
3806 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
3807 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
3808 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
3809 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
3810 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
3811 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
3812 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
3813 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
3814 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
3815 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
3821 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
3825 /* Convert to emacs modifiers. */
3826 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
3832 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
3834 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
3837 if (virt_key
== VK_RETURN
)
3838 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
3840 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
3841 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
3843 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
3844 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
3846 if (virt_key
== VK_CLEAR
)
3847 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
3852 /* List of special key combinations which w32 would normally capture,
3853 but emacs should grab instead. Not directly visible to lisp, to
3854 simplify synchronization. Each item is an integer encoding a virtual
3855 key code and modifier combination to capture. */
3856 Lisp_Object w32_grabbed_keys
;
3858 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
3859 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
3860 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
3861 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
3863 /* Register hot-keys for reserved key combinations when Emacs has
3864 keyboard focus, since this is the only way Emacs can receive key
3865 combinations like Alt-Tab which are used by the system. */
3868 register_hot_keys (hwnd
)
3871 Lisp_Object keylist
;
3873 /* Use GC_CONSP, since we are called asynchronously. */
3874 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3876 Lisp_Object key
= XCAR (keylist
);
3878 /* Deleted entries get set to nil. */
3879 if (!INTEGERP (key
))
3882 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
3883 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
3888 unregister_hot_keys (hwnd
)
3891 Lisp_Object keylist
;
3893 /* Use GC_CONSP, since we are called asynchronously. */
3894 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3896 Lisp_Object key
= XCAR (keylist
);
3898 if (!INTEGERP (key
))
3901 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
3905 /* Main message dispatch loop. */
3908 w32_msg_pump (deferred_msg
* msg_buf
)
3914 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
3916 while (GetMessage (&msg
, NULL
, 0, 0))
3918 if (msg
.hwnd
== NULL
)
3920 switch (msg
.message
)
3923 /* Produced by complete_deferred_msg; just ignore. */
3925 case WM_EMACS_CREATEWINDOW
:
3926 w32_createwindow ((struct frame
*) msg
.wParam
);
3927 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3930 case WM_EMACS_SETLOCALE
:
3931 SetThreadLocale (msg
.wParam
);
3932 /* Reply is not expected. */
3934 case WM_EMACS_SETKEYBOARDLAYOUT
:
3935 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
3936 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3940 case WM_EMACS_REGISTER_HOT_KEY
:
3941 focus_window
= GetFocus ();
3942 if (focus_window
!= NULL
)
3943 RegisterHotKey (focus_window
,
3944 HOTKEY_ID (msg
.wParam
),
3945 HOTKEY_MODIFIERS (msg
.wParam
),
3946 HOTKEY_VK_CODE (msg
.wParam
));
3947 /* Reply is not expected. */
3949 case WM_EMACS_UNREGISTER_HOT_KEY
:
3950 focus_window
= GetFocus ();
3951 if (focus_window
!= NULL
)
3952 UnregisterHotKey (focus_window
, HOTKEY_ID (msg
.wParam
));
3953 /* Mark item as erased. NB: this code must be
3954 thread-safe. The next line is okay because the cons
3955 cell is never made into garbage and is not relocated by
3957 XSETCAR ((Lisp_Object
) msg
.lParam
, Qnil
);
3958 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3961 case WM_EMACS_TOGGLE_LOCK_KEY
:
3963 int vk_code
= (int) msg
.wParam
;
3964 int cur_state
= (GetKeyState (vk_code
) & 1);
3965 Lisp_Object new_state
= (Lisp_Object
) msg
.lParam
;
3967 /* NB: This code must be thread-safe. It is safe to
3968 call NILP because symbols are not relocated by GC,
3969 and pointer here is not touched by GC (so the markbit
3970 can't be set). Numbers are safe because they are
3971 immediate values. */
3972 if (NILP (new_state
)
3973 || (NUMBERP (new_state
)
3974 && ((XUINT (new_state
)) & 1) != cur_state
))
3976 one_w32_display_info
.faked_key
= vk_code
;
3978 keybd_event ((BYTE
) vk_code
,
3979 (BYTE
) MapVirtualKey (vk_code
, 0),
3980 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3981 keybd_event ((BYTE
) vk_code
,
3982 (BYTE
) MapVirtualKey (vk_code
, 0),
3983 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3984 keybd_event ((BYTE
) vk_code
,
3985 (BYTE
) MapVirtualKey (vk_code
, 0),
3986 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3987 cur_state
= !cur_state
;
3989 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3995 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
4000 DispatchMessage (&msg
);
4003 /* Exit nested loop when our deferred message has completed. */
4004 if (msg_buf
->completed
)
4009 deferred_msg
* deferred_msg_head
;
4011 static deferred_msg
*
4012 find_deferred_msg (HWND hwnd
, UINT msg
)
4014 deferred_msg
* item
;
4016 /* Don't actually need synchronization for read access, since
4017 modification of single pointer is always atomic. */
4018 /* enter_crit (); */
4020 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
4021 if (item
->w32msg
.msg
.hwnd
== hwnd
4022 && item
->w32msg
.msg
.message
== msg
)
4025 /* leave_crit (); */
4031 send_deferred_msg (deferred_msg
* msg_buf
,
4037 /* Only input thread can send deferred messages. */
4038 if (GetCurrentThreadId () != dwWindowsThreadId
)
4041 /* It is an error to send a message that is already deferred. */
4042 if (find_deferred_msg (hwnd
, msg
) != NULL
)
4045 /* Enforced synchronization is not needed because this is the only
4046 function that alters deferred_msg_head, and the following critical
4047 section is guaranteed to only be serially reentered (since only the
4048 input thread can call us). */
4050 /* enter_crit (); */
4052 msg_buf
->completed
= 0;
4053 msg_buf
->next
= deferred_msg_head
;
4054 deferred_msg_head
= msg_buf
;
4055 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
4057 /* leave_crit (); */
4059 /* Start a new nested message loop to process other messages until
4060 this one is completed. */
4061 w32_msg_pump (msg_buf
);
4063 deferred_msg_head
= msg_buf
->next
;
4065 return msg_buf
->result
;
4069 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
4071 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
4073 if (msg_buf
== NULL
)
4074 /* Message may have been cancelled, so don't abort(). */
4077 msg_buf
->result
= result
;
4078 msg_buf
->completed
= 1;
4080 /* Ensure input thread is woken so it notices the completion. */
4081 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
4085 cancel_all_deferred_msgs ()
4087 deferred_msg
* item
;
4089 /* Don't actually need synchronization for read access, since
4090 modification of single pointer is always atomic. */
4091 /* enter_crit (); */
4093 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
4096 item
->completed
= 1;
4099 /* leave_crit (); */
4101 /* Ensure input thread is woken so it notices the completion. */
4102 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
4110 deferred_msg dummy_buf
;
4112 /* Ensure our message queue is created */
4114 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
4116 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
4119 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
4120 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
4121 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
4123 /* This is the inital message loop which should only exit when the
4124 application quits. */
4125 w32_msg_pump (&dummy_buf
);
4131 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
4141 wmsg
.dwModifiers
= modifiers
;
4143 /* Detect quit_char and set quit-flag directly. Note that we
4144 still need to post a message to ensure the main thread will be
4145 woken up if blocked in sys_select(), but we do NOT want to post
4146 the quit_char message itself (because it will usually be as if
4147 the user had typed quit_char twice). Instead, we post a dummy
4148 message that has no particular effect. */
4151 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
4152 c
= make_ctrl_char (c
) & 0377;
4154 || (wmsg
.dwModifiers
== 0 &&
4155 XFASTINT (Vw32_quit_key
) && wParam
== XFASTINT (Vw32_quit_key
)))
4159 /* The choice of message is somewhat arbitrary, as long as
4160 the main thread handler just ignores it. */
4163 /* Interrupt any blocking system calls. */
4166 /* As a safety precaution, forcibly complete any deferred
4167 messages. This is a kludge, but I don't see any particularly
4168 clean way to handle the situation where a deferred message is
4169 "dropped" in the lisp thread, and will thus never be
4170 completed, eg. by the user trying to activate the menubar
4171 when the lisp thread is busy, and then typing C-g when the
4172 menubar doesn't open promptly (with the result that the
4173 menubar never responds at all because the deferred
4174 WM_INITMENU message is never completed). Another problem
4175 situation is when the lisp thread calls SendMessage (to send
4176 a window manager command) when a message has been deferred;
4177 the lisp thread gets blocked indefinitely waiting for the
4178 deferred message to be completed, which itself is waiting for
4179 the lisp thread to respond.
4181 Note that we don't want to block the input thread waiting for
4182 a reponse from the lisp thread (although that would at least
4183 solve the deadlock problem above), because we want to be able
4184 to receive C-g to interrupt the lisp thread. */
4185 cancel_all_deferred_msgs ();
4189 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4192 /* Main window procedure */
4195 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
4202 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4204 int windows_translate
;
4207 /* Note that it is okay to call x_window_to_frame, even though we are
4208 not running in the main lisp thread, because frame deletion
4209 requires the lisp thread to synchronize with this thread. Thus, if
4210 a frame struct is returned, it can be used without concern that the
4211 lisp thread might make it disappear while we are using it.
4213 NB. Walking the frame list in this thread is safe (as long as
4214 writes of Lisp_Object slots are atomic, which they are on Windows).
4215 Although delete-frame can destructively modify the frame list while
4216 we are walking it, a garbage collection cannot occur until after
4217 delete-frame has synchronized with this thread.
4219 It is also safe to use functions that make GDI calls, such as
4220 w32_clear_rect, because these functions must obtain a DC handle
4221 from the frame struct using get_frame_dc which is thread-aware. */
4226 f
= x_window_to_frame (dpyinfo
, hwnd
);
4229 HDC hdc
= get_frame_dc (f
);
4230 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
4231 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
4232 release_frame_dc (f
, hdc
);
4234 #if defined (W32_DEBUG_DISPLAY)
4235 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
4237 wmsg
.rect
.left
, wmsg
.rect
.top
,
4238 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
4239 #endif /* W32_DEBUG_DISPLAY */
4242 case WM_PALETTECHANGED
:
4243 /* ignore our own changes */
4244 if ((HWND
)wParam
!= hwnd
)
4246 f
= x_window_to_frame (dpyinfo
, hwnd
);
4248 /* get_frame_dc will realize our palette and force all
4249 frames to be redrawn if needed. */
4250 release_frame_dc (f
, get_frame_dc (f
));
4255 PAINTSTRUCT paintStruct
;
4257 bzero (&update_rect
, sizeof (update_rect
));
4259 f
= x_window_to_frame (dpyinfo
, hwnd
);
4262 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
4266 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
4267 fails. Apparently this can happen under some
4269 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
4272 BeginPaint (hwnd
, &paintStruct
);
4274 /* The rectangles returned by GetUpdateRect and BeginPaint
4275 do not always match. Play it safe by assuming both areas
4277 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
4279 #if defined (W32_DEBUG_DISPLAY)
4280 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
4282 wmsg
.rect
.left
, wmsg
.rect
.top
,
4283 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
4284 DebPrint ((" [update region is %d,%d-%d,%d]\n",
4285 update_rect
.left
, update_rect
.top
,
4286 update_rect
.right
, update_rect
.bottom
));
4288 EndPaint (hwnd
, &paintStruct
);
4291 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4296 /* If GetUpdateRect returns 0 (meaning there is no update
4297 region), assume the whole window needs to be repainted. */
4298 GetClientRect(hwnd
, &wmsg
.rect
);
4299 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4303 case WM_INPUTLANGCHANGE
:
4304 /* Inform lisp thread of keyboard layout changes. */
4305 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4307 /* Clear dead keys in the keyboard state; for simplicity only
4308 preserve modifier key states. */
4313 GetKeyboardState (keystate
);
4314 for (i
= 0; i
< 256; i
++)
4331 SetKeyboardState (keystate
);
4336 /* Synchronize hot keys with normal input. */
4337 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
4342 record_keyup (wParam
, lParam
);
4347 /* Ignore keystrokes we fake ourself; see below. */
4348 if (dpyinfo
->faked_key
== wParam
)
4350 dpyinfo
->faked_key
= 0;
4351 /* Make sure TranslateMessage sees them though (as long as
4352 they don't produce WM_CHAR messages). This ensures that
4353 indicator lights are toggled promptly on Windows 9x, for
4355 if (lispy_function_keys
[wParam
] != 0)
4357 windows_translate
= 1;
4363 /* Synchronize modifiers with current keystroke. */
4365 record_keydown (wParam
, lParam
);
4366 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
4368 windows_translate
= 0;
4373 if (NILP (Vw32_pass_lwindow_to_system
))
4375 /* Prevent system from acting on keyup (which opens the
4376 Start menu if no other key was pressed) by simulating a
4377 press of Space which we will ignore. */
4378 if (GetAsyncKeyState (wParam
) & 1)
4380 if (NUMBERP (Vw32_phantom_key_code
))
4381 key
= XUINT (Vw32_phantom_key_code
) & 255;
4384 dpyinfo
->faked_key
= key
;
4385 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4388 if (!NILP (Vw32_lwindow_modifier
))
4392 if (NILP (Vw32_pass_rwindow_to_system
))
4394 if (GetAsyncKeyState (wParam
) & 1)
4396 if (NUMBERP (Vw32_phantom_key_code
))
4397 key
= XUINT (Vw32_phantom_key_code
) & 255;
4400 dpyinfo
->faked_key
= key
;
4401 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4404 if (!NILP (Vw32_rwindow_modifier
))
4408 if (!NILP (Vw32_apps_modifier
))
4412 if (NILP (Vw32_pass_alt_to_system
))
4413 /* Prevent DefWindowProc from activating the menu bar if an
4414 Alt key is pressed and released by itself. */
4416 windows_translate
= 1;
4419 /* Decide whether to treat as modifier or function key. */
4420 if (NILP (Vw32_enable_caps_lock
))
4421 goto disable_lock_key
;
4422 windows_translate
= 1;
4425 /* Decide whether to treat as modifier or function key. */
4426 if (NILP (Vw32_enable_num_lock
))
4427 goto disable_lock_key
;
4428 windows_translate
= 1;
4431 /* Decide whether to treat as modifier or function key. */
4432 if (NILP (Vw32_scroll_lock_modifier
))
4433 goto disable_lock_key
;
4434 windows_translate
= 1;
4437 /* Ensure the appropriate lock key state (and indicator light)
4438 remains in the same state. We do this by faking another
4439 press of the relevant key. Apparently, this really is the
4440 only way to toggle the state of the indicator lights. */
4441 dpyinfo
->faked_key
= wParam
;
4442 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4443 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4444 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4445 KEYEVENTF_EXTENDEDKEY
| 0, 0);
4446 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4447 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4448 /* Ensure indicator lights are updated promptly on Windows 9x
4449 (TranslateMessage apparently does this), after forwarding
4451 post_character_message (hwnd
, msg
, wParam
, lParam
,
4452 w32_get_key_modifiers (wParam
, lParam
));
4453 windows_translate
= 1;
4457 case VK_PROCESSKEY
: /* Generated by IME. */
4458 windows_translate
= 1;
4461 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
4462 which is confusing for purposes of key binding; convert
4463 VK_CANCEL events into VK_PAUSE events. */
4467 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
4468 for purposes of key binding; convert these back into
4469 VK_NUMLOCK events, at least when we want to see NumLock key
4470 presses. (Note that there is never any possibility that
4471 VK_PAUSE with Ctrl really is C-Pause as per above.) */
4472 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
4473 wParam
= VK_NUMLOCK
;
4476 /* If not defined as a function key, change it to a WM_CHAR message. */
4477 if (lispy_function_keys
[wParam
] == 0)
4479 DWORD modifiers
= construct_console_modifiers ();
4481 if (!NILP (Vw32_recognize_altgr
)
4482 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
4484 /* Always let TranslateMessage handle AltGr key chords;
4485 for some reason, ToAscii doesn't always process AltGr
4486 chords correctly. */
4487 windows_translate
= 1;
4489 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
4491 /* Handle key chords including any modifiers other
4492 than shift directly, in order to preserve as much
4493 modifier information as possible. */
4494 if ('A' <= wParam
&& wParam
<= 'Z')
4496 /* Don't translate modified alphabetic keystrokes,
4497 so the user doesn't need to constantly switch
4498 layout to type control or meta keystrokes when
4499 the normal layout translates alphabetic
4500 characters to non-ascii characters. */
4501 if (!modifier_set (VK_SHIFT
))
4502 wParam
+= ('a' - 'A');
4507 /* Try to handle other keystrokes by determining the
4508 base character (ie. translating the base key plus
4512 KEY_EVENT_RECORD key
;
4514 key
.bKeyDown
= TRUE
;
4515 key
.wRepeatCount
= 1;
4516 key
.wVirtualKeyCode
= wParam
;
4517 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
4518 key
.uChar
.AsciiChar
= 0;
4519 key
.dwControlKeyState
= modifiers
;
4521 add
= w32_kbd_patch_key (&key
);
4522 /* 0 means an unrecognised keycode, negative means
4523 dead key. Ignore both. */
4526 /* Forward asciified character sequence. */
4527 post_character_message
4528 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
4529 w32_get_key_modifiers (wParam
, lParam
));
4530 w32_kbd_patch_key (&key
);
4537 /* Let TranslateMessage handle everything else. */
4538 windows_translate
= 1;
4544 if (windows_translate
)
4546 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
4548 windows_msg
.time
= GetMessageTime ();
4549 TranslateMessage (&windows_msg
);
4557 post_character_message (hwnd
, msg
, wParam
, lParam
,
4558 w32_get_key_modifiers (wParam
, lParam
));
4561 /* Simulate middle mouse button events when left and right buttons
4562 are used together, but only if user has two button mouse. */
4563 case WM_LBUTTONDOWN
:
4564 case WM_RBUTTONDOWN
:
4565 if (XINT (Vw32_num_mouse_buttons
) > 2)
4566 goto handle_plain_button
;
4569 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
4570 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
4572 if (button_state
& this)
4575 if (button_state
== 0)
4578 button_state
|= this;
4580 if (button_state
& other
)
4582 if (mouse_button_timer
)
4584 KillTimer (hwnd
, mouse_button_timer
);
4585 mouse_button_timer
= 0;
4587 /* Generate middle mouse event instead. */
4588 msg
= WM_MBUTTONDOWN
;
4589 button_state
|= MMOUSE
;
4591 else if (button_state
& MMOUSE
)
4593 /* Ignore button event if we've already generated a
4594 middle mouse down event. This happens if the
4595 user releases and press one of the two buttons
4596 after we've faked a middle mouse event. */
4601 /* Flush out saved message. */
4602 post_msg (&saved_mouse_button_msg
);
4604 wmsg
.dwModifiers
= w32_get_modifiers ();
4605 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4607 /* Clear message buffer. */
4608 saved_mouse_button_msg
.msg
.hwnd
= 0;
4612 /* Hold onto message for now. */
4613 mouse_button_timer
=
4614 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
4615 XINT (Vw32_mouse_button_tolerance
), NULL
);
4616 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
4617 saved_mouse_button_msg
.msg
.message
= msg
;
4618 saved_mouse_button_msg
.msg
.wParam
= wParam
;
4619 saved_mouse_button_msg
.msg
.lParam
= lParam
;
4620 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
4621 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
4628 if (XINT (Vw32_num_mouse_buttons
) > 2)
4629 goto handle_plain_button
;
4632 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
4633 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
4635 if ((button_state
& this) == 0)
4638 button_state
&= ~this;
4640 if (button_state
& MMOUSE
)
4642 /* Only generate event when second button is released. */
4643 if ((button_state
& other
) == 0)
4646 button_state
&= ~MMOUSE
;
4648 if (button_state
) abort ();
4655 /* Flush out saved message if necessary. */
4656 if (saved_mouse_button_msg
.msg
.hwnd
)
4658 post_msg (&saved_mouse_button_msg
);
4661 wmsg
.dwModifiers
= w32_get_modifiers ();
4662 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4664 /* Always clear message buffer and cancel timer. */
4665 saved_mouse_button_msg
.msg
.hwnd
= 0;
4666 KillTimer (hwnd
, mouse_button_timer
);
4667 mouse_button_timer
= 0;
4669 if (button_state
== 0)
4674 case WM_XBUTTONDOWN
:
4676 if (w32_pass_extra_mouse_buttons_to_system
)
4678 /* else fall through and process them. */
4679 case WM_MBUTTONDOWN
:
4681 handle_plain_button
:
4686 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
4688 if (up
) ReleaseCapture ();
4689 else SetCapture (hwnd
);
4690 button
= (button
== 0) ? LMOUSE
:
4691 ((button
== 1) ? MMOUSE
: RMOUSE
);
4693 button_state
&= ~button
;
4695 button_state
|= button
;
4699 wmsg
.dwModifiers
= w32_get_modifiers ();
4700 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4702 /* Need to return true for XBUTTON messages, false for others,
4703 to indicate that we processed the message. */
4704 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
4707 /* If the mouse has just moved into the frame, start tracking
4708 it, so we will be notified when it leaves the frame. Mouse
4709 tracking only works under W98 and NT4 and later. On earlier
4710 versions, there is no way of telling when the mouse leaves the
4711 frame, so we just have to put up with help-echo and mouse
4712 highlighting remaining while the frame is not active. */
4713 if (track_mouse_event_fn
&& !track_mouse_window
)
4715 TRACKMOUSEEVENT tme
;
4716 tme
.cbSize
= sizeof (tme
);
4717 tme
.dwFlags
= TME_LEAVE
;
4718 tme
.hwndTrack
= hwnd
;
4720 track_mouse_event_fn (&tme
);
4721 track_mouse_window
= hwnd
;
4724 if (XINT (Vw32_mouse_move_interval
) <= 0
4725 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
4727 wmsg
.dwModifiers
= w32_get_modifiers ();
4728 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4732 /* Hang onto mouse move and scroll messages for a bit, to avoid
4733 sending such events to Emacs faster than it can process them.
4734 If we get more events before the timer from the first message
4735 expires, we just replace the first message. */
4737 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
4739 SetTimer (hwnd
, MOUSE_MOVE_ID
,
4740 XINT (Vw32_mouse_move_interval
), NULL
);
4742 /* Hold onto message for now. */
4743 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
4744 saved_mouse_move_msg
.msg
.message
= msg
;
4745 saved_mouse_move_msg
.msg
.wParam
= wParam
;
4746 saved_mouse_move_msg
.msg
.lParam
= lParam
;
4747 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
4748 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
4753 wmsg
.dwModifiers
= w32_get_modifiers ();
4754 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4758 wmsg
.dwModifiers
= w32_get_modifiers ();
4759 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4763 /* Flush out saved messages if necessary. */
4764 if (wParam
== mouse_button_timer
)
4766 if (saved_mouse_button_msg
.msg
.hwnd
)
4768 post_msg (&saved_mouse_button_msg
);
4769 saved_mouse_button_msg
.msg
.hwnd
= 0;
4771 KillTimer (hwnd
, mouse_button_timer
);
4772 mouse_button_timer
= 0;
4774 else if (wParam
== mouse_move_timer
)
4776 if (saved_mouse_move_msg
.msg
.hwnd
)
4778 post_msg (&saved_mouse_move_msg
);
4779 saved_mouse_move_msg
.msg
.hwnd
= 0;
4781 KillTimer (hwnd
, mouse_move_timer
);
4782 mouse_move_timer
= 0;
4784 else if (wParam
== menu_free_timer
)
4786 KillTimer (hwnd
, menu_free_timer
);
4787 menu_free_timer
= 0;
4788 f
= x_window_to_frame (dpyinfo
, hwnd
);
4789 if (!f
->output_data
.w32
->menu_command_in_progress
)
4791 /* Free memory used by owner-drawn and help-echo strings. */
4792 w32_free_menu_strings (hwnd
);
4793 f
->output_data
.w32
->menubar_active
= 0;
4799 /* Windows doesn't send us focus messages when putting up and
4800 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
4801 The only indication we get that something happened is receiving
4802 this message afterwards. So this is a good time to reset our
4803 keyboard modifiers' state. */
4810 /* We must ensure menu bar is fully constructed and up to date
4811 before allowing user interaction with it. To achieve this
4812 we send this message to the lisp thread and wait for a
4813 reply (whose value is not actually needed) to indicate that
4814 the menu bar is now ready for use, so we can now return.
4816 To remain responsive in the meantime, we enter a nested message
4817 loop that can process all other messages.
4819 However, we skip all this if the message results from calling
4820 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
4821 thread a message because it is blocked on us at this point. We
4822 set menubar_active before calling TrackPopupMenu to indicate
4823 this (there is no possibility of confusion with real menubar
4826 f
= x_window_to_frame (dpyinfo
, hwnd
);
4828 && (f
->output_data
.w32
->menubar_active
4829 /* We can receive this message even in the absence of a
4830 menubar (ie. when the system menu is activated) - in this
4831 case we do NOT want to forward the message, otherwise it
4832 will cause the menubar to suddenly appear when the user
4833 had requested it to be turned off! */
4834 || f
->output_data
.w32
->menubar_widget
== NULL
))
4838 deferred_msg msg_buf
;
4840 /* Detect if message has already been deferred; in this case
4841 we cannot return any sensible value to ignore this. */
4842 if (find_deferred_msg (hwnd
, msg
) != NULL
)
4845 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
4848 case WM_EXITMENULOOP
:
4849 f
= x_window_to_frame (dpyinfo
, hwnd
);
4851 /* If a menu command is not already in progress, check again
4852 after a short delay, since Windows often (always?) sends the
4853 WM_EXITMENULOOP before the corresponding WM_COMMAND message. */
4854 if (f
&& !f
->output_data
.w32
->menu_command_in_progress
)
4855 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
4859 /* Direct handling of help_echo in menus. Should be safe now
4860 that we generate the help_echo by placing a help event in the
4863 HMENU menu
= (HMENU
) lParam
;
4864 UINT menu_item
= (UINT
) LOWORD (wParam
);
4865 UINT flags
= (UINT
) HIWORD (wParam
);
4867 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
4871 case WM_MEASUREITEM
:
4872 f
= x_window_to_frame (dpyinfo
, hwnd
);
4875 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
4877 if (pMis
->CtlType
== ODT_MENU
)
4879 /* Work out dimensions for popup menu titles. */
4880 char * title
= (char *) pMis
->itemData
;
4881 HDC hdc
= GetDC (hwnd
);
4882 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4883 LOGFONT menu_logfont
;
4887 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4888 menu_logfont
.lfWeight
= FW_BOLD
;
4889 menu_font
= CreateFontIndirect (&menu_logfont
);
4890 old_font
= SelectObject (hdc
, menu_font
);
4892 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
4895 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
4896 pMis
->itemWidth
= size
.cx
;
4897 if (pMis
->itemHeight
< size
.cy
)
4898 pMis
->itemHeight
= size
.cy
;
4901 pMis
->itemWidth
= 0;
4903 SelectObject (hdc
, old_font
);
4904 DeleteObject (menu_font
);
4905 ReleaseDC (hwnd
, hdc
);
4912 f
= x_window_to_frame (dpyinfo
, hwnd
);
4915 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
4917 if (pDis
->CtlType
== ODT_MENU
)
4919 /* Draw popup menu title. */
4920 char * title
= (char *) pDis
->itemData
;
4923 HDC hdc
= pDis
->hDC
;
4924 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4925 LOGFONT menu_logfont
;
4928 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4929 menu_logfont
.lfWeight
= FW_BOLD
;
4930 menu_font
= CreateFontIndirect (&menu_logfont
);
4931 old_font
= SelectObject (hdc
, menu_font
);
4933 /* Always draw title as if not selected. */
4936 + GetSystemMetrics (SM_CXMENUCHECK
),
4938 ETO_OPAQUE
, &pDis
->rcItem
,
4939 title
, strlen (title
), NULL
);
4941 SelectObject (hdc
, old_font
);
4942 DeleteObject (menu_font
);
4950 /* Still not right - can't distinguish between clicks in the
4951 client area of the frame from clicks forwarded from the scroll
4952 bars - may have to hook WM_NCHITTEST to remember the mouse
4953 position and then check if it is in the client area ourselves. */
4954 case WM_MOUSEACTIVATE
:
4955 /* Discard the mouse click that activates a frame, allowing the
4956 user to click anywhere without changing point (or worse!).
4957 Don't eat mouse clicks on scrollbars though!! */
4958 if (LOWORD (lParam
) == HTCLIENT
)
4959 return MA_ACTIVATEANDEAT
;
4964 /* No longer tracking mouse. */
4965 track_mouse_window
= NULL
;
4967 case WM_ACTIVATEAPP
:
4969 case WM_WINDOWPOSCHANGED
:
4971 /* Inform lisp thread that a frame might have just been obscured
4972 or exposed, so should recheck visibility of all frames. */
4973 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4977 dpyinfo
->faked_key
= 0;
4979 register_hot_keys (hwnd
);
4982 unregister_hot_keys (hwnd
);
4985 /* Relinquish the system caret. */
4986 if (w32_system_caret_hwnd
)
4988 w32_visible_system_caret_hwnd
= NULL
;
4989 w32_system_caret_hwnd
= NULL
;
4994 f
= x_window_to_frame (dpyinfo
, hwnd
);
4995 if (f
&& HIWORD (wParam
) == 0)
4997 f
->output_data
.w32
->menu_command_in_progress
= 1;
4998 if (menu_free_timer
)
5000 KillTimer (hwnd
, menu_free_timer
);
5001 menu_free_timer
= 0;
5007 wmsg
.dwModifiers
= w32_get_modifiers ();
5008 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
5012 wmsg
.dwModifiers
= w32_get_modifiers ();
5013 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
5016 case WM_WINDOWPOSCHANGING
:
5017 /* Don't restrict the sizing of tip frames. */
5018 if (hwnd
== tip_window
)
5022 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
5024 wp
.length
= sizeof (WINDOWPLACEMENT
);
5025 GetWindowPlacement (hwnd
, &wp
);
5027 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
5034 DWORD internal_border
;
5035 DWORD scrollbar_extra
;
5038 wp
.length
= sizeof(wp
);
5039 GetWindowRect (hwnd
, &wr
);
5043 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
5044 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
5045 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
5046 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
5050 memset (&rect
, 0, sizeof (rect
));
5051 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
5052 GetMenu (hwnd
) != NULL
);
5054 /* Force width and height of client area to be exact
5055 multiples of the character cell dimensions. */
5056 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
5057 - 2 * internal_border
- scrollbar_extra
)
5059 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
5060 - 2 * internal_border
)
5065 /* For right/bottom sizing we can just fix the sizes.
5066 However for top/left sizing we will need to fix the X
5067 and Y positions as well. */
5072 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
5073 && (lppos
->flags
& SWP_NOMOVE
) == 0)
5075 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
5082 lppos
->flags
|= SWP_NOMOVE
;
5093 case WM_GETMINMAXINFO
:
5094 /* Hack to correct bug that allows Emacs frames to be resized
5095 below the Minimum Tracking Size. */
5096 ((LPMINMAXINFO
) lParam
)->ptMinTrackSize
.y
++;
5097 /* Hack to allow resizing the Emacs frame above the screen size.
5098 Note that Windows 9x limits coordinates to 16-bits. */
5099 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
5100 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
5103 case WM_EMACS_CREATESCROLLBAR
:
5104 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
5105 (struct scroll_bar
*) lParam
);
5107 case WM_EMACS_SHOWWINDOW
:
5108 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
5110 case WM_EMACS_SETFOREGROUND
:
5112 HWND foreground_window
;
5113 DWORD foreground_thread
, retval
;
5115 /* On NT 5.0, and apparently Windows 98, it is necessary to
5116 attach to the thread that currently has focus in order to
5117 pull the focus away from it. */
5118 foreground_window
= GetForegroundWindow ();
5119 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
5120 if (!foreground_window
5121 || foreground_thread
== GetCurrentThreadId ()
5122 || !AttachThreadInput (GetCurrentThreadId (),
5123 foreground_thread
, TRUE
))
5124 foreground_thread
= 0;
5126 retval
= SetForegroundWindow ((HWND
) wParam
);
5128 /* Detach from the previous foreground thread. */
5129 if (foreground_thread
)
5130 AttachThreadInput (GetCurrentThreadId (),
5131 foreground_thread
, FALSE
);
5136 case WM_EMACS_SETWINDOWPOS
:
5138 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
5139 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
5140 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
5143 case WM_EMACS_DESTROYWINDOW
:
5144 DragAcceptFiles ((HWND
) wParam
, FALSE
);
5145 return DestroyWindow ((HWND
) wParam
);
5147 case WM_EMACS_HIDE_CARET
:
5148 return HideCaret (hwnd
);
5150 case WM_EMACS_SHOW_CARET
:
5151 return ShowCaret (hwnd
);
5153 case WM_EMACS_DESTROY_CARET
:
5154 w32_system_caret_hwnd
= NULL
;
5155 w32_visible_system_caret_hwnd
= NULL
;
5156 return DestroyCaret ();
5158 case WM_EMACS_TRACK_CARET
:
5159 /* If there is currently no system caret, create one. */
5160 if (w32_system_caret_hwnd
== NULL
)
5162 /* Use the default caret width, and avoid changing it
5163 unneccesarily, as it confuses screen reader software. */
5164 w32_system_caret_hwnd
= hwnd
;
5165 CreateCaret (hwnd
, NULL
, 0,
5166 w32_system_caret_height
);
5169 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
5171 /* Ensure visible caret gets turned on when requested. */
5172 else if (w32_use_visible_system_caret
5173 && w32_visible_system_caret_hwnd
!= hwnd
)
5175 w32_visible_system_caret_hwnd
= hwnd
;
5176 return ShowCaret (hwnd
);
5178 /* Ensure visible caret gets turned off when requested. */
5179 else if (!w32_use_visible_system_caret
5180 && w32_visible_system_caret_hwnd
)
5182 w32_visible_system_caret_hwnd
= NULL
;
5183 return HideCaret (hwnd
);
5188 case WM_EMACS_TRACKPOPUPMENU
:
5193 pos
= (POINT
*)lParam
;
5194 flags
= TPM_CENTERALIGN
;
5195 if (button_state
& LMOUSE
)
5196 flags
|= TPM_LEFTBUTTON
;
5197 else if (button_state
& RMOUSE
)
5198 flags
|= TPM_RIGHTBUTTON
;
5200 /* Remember we did a SetCapture on the initial mouse down event,
5201 so for safety, we make sure the capture is cancelled now. */
5205 /* Use menubar_active to indicate that WM_INITMENU is from
5206 TrackPopupMenu below, and should be ignored. */
5207 f
= x_window_to_frame (dpyinfo
, hwnd
);
5209 f
->output_data
.w32
->menubar_active
= 1;
5211 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
5215 /* Eat any mouse messages during popupmenu */
5216 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
5218 /* Get the menu selection, if any */
5219 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
5221 retval
= LOWORD (amsg
.wParam
);
5237 /* Check for messages registered at runtime. */
5238 if (msg
== msh_mousewheel
)
5240 wmsg
.dwModifiers
= w32_get_modifiers ();
5241 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
5246 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
5250 /* The most common default return code for handled messages is 0. */
5255 my_create_window (f
)
5260 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
5262 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
5266 /* Create a tooltip window. Unlike my_create_window, we do not do this
5267 indirectly via the Window thread, as we do not need to process Window
5268 messages for the tooltip. Creating tooltips indirectly also creates
5269 deadlocks when tooltips are created for menu items. */
5271 my_create_tip_window (f
)
5276 rect
.left
= rect
.top
= 0;
5277 rect
.right
= PIXEL_WIDTH (f
);
5278 rect
.bottom
= PIXEL_HEIGHT (f
);
5280 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
5281 FRAME_EXTERNAL_MENU_BAR (f
));
5283 tip_window
= FRAME_W32_WINDOW (f
)
5284 = CreateWindow (EMACS_CLASS
,
5286 f
->output_data
.w32
->dwStyle
,
5287 f
->output_data
.w32
->left_pos
,
5288 f
->output_data
.w32
->top_pos
,
5289 rect
.right
- rect
.left
,
5290 rect
.bottom
- rect
.top
,
5291 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
5298 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
5299 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
5300 SetWindowLong (tip_window
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
5301 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
5303 /* Tip frames have no scrollbars. */
5304 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
5306 /* Do this to discard the default setting specified by our parent. */
5307 ShowWindow (tip_window
, SW_HIDE
);
5312 /* Create and set up the w32 window for frame F. */
5315 w32_window (f
, window_prompting
, minibuffer_only
)
5317 long window_prompting
;
5318 int minibuffer_only
;
5322 /* Use the resource name as the top-level window name
5323 for looking up resources. Make a non-Lisp copy
5324 for the window manager, so GC relocation won't bother it.
5326 Elsewhere we specify the window name for the window manager. */
5329 char *str
= (char *) XSTRING (Vx_resource_name
)->data
;
5330 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
5331 strcpy (f
->namebuf
, str
);
5334 my_create_window (f
);
5336 validate_x_resource_name ();
5338 /* x_set_name normally ignores requests to set the name if the
5339 requested name is the same as the current name. This is the one
5340 place where that assumption isn't correct; f->name is set, but
5341 the server hasn't been told. */
5344 int explicit = f
->explicit_name
;
5346 f
->explicit_name
= 0;
5349 x_set_name (f
, name
, explicit);
5354 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
5355 initialize_frame_menubar (f
);
5357 if (FRAME_W32_WINDOW (f
) == 0)
5358 error ("Unable to create window");
5361 /* Handle the icon stuff for this window. Perhaps later we might
5362 want an x_set_icon_position which can be called interactively as
5370 Lisp_Object icon_x
, icon_y
;
5372 /* Set the position of the icon. Note that Windows 95 groups all
5373 icons in the tray. */
5374 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
5375 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
5376 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
5378 CHECK_NUMBER (icon_x
);
5379 CHECK_NUMBER (icon_y
);
5381 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
5382 error ("Both left and top icon corners of icon must be specified");
5386 if (! EQ (icon_x
, Qunbound
))
5387 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
5390 /* Start up iconic or window? */
5391 x_wm_set_window_state
5392 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
5396 x_text_icon (f
, (char *) XSTRING ((!NILP (f
->icon_name
)
5409 XGCValues gc_values
;
5413 /* Create the GC's of this frame.
5414 Note that many default values are used. */
5417 gc_values
.font
= f
->output_data
.w32
->font
;
5419 /* Cursor has cursor-color background, background-color foreground. */
5420 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
5421 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
5422 f
->output_data
.w32
->cursor_gc
5423 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
5424 (GCFont
| GCForeground
| GCBackground
),
5428 f
->output_data
.w32
->white_relief
.gc
= 0;
5429 f
->output_data
.w32
->black_relief
.gc
= 0;
5435 /* Handler for signals raised during x_create_frame and
5436 x_create_top_frame. FRAME is the frame which is partially
5440 unwind_create_frame (frame
)
5443 struct frame
*f
= XFRAME (frame
);
5445 /* If frame is ``official'', nothing to do. */
5446 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
5449 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5452 x_free_frame_resources (f
);
5454 /* Check that reference counts are indeed correct. */
5455 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
5456 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
5465 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
5467 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
5468 Returns an Emacs frame object.
5469 ALIST is an alist of frame parameters.
5470 If the parameters specify that the frame should not have a minibuffer,
5471 and do not specify a specific minibuffer window to use,
5472 then `default-minibuffer-frame' must be a frame whose minibuffer can
5473 be shared by the new frame.
5475 This function is an internal primitive--use `make-frame' instead. */)
5480 Lisp_Object frame
, tem
;
5482 int minibuffer_only
= 0;
5483 long window_prompting
= 0;
5485 int count
= BINDING_STACK_SIZE ();
5486 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5487 Lisp_Object display
;
5488 struct w32_display_info
*dpyinfo
= NULL
;
5494 /* Use this general default value to start with
5495 until we know if this frame has a specified name. */
5496 Vx_resource_name
= Vinvocation_name
;
5498 display
= w32_get_arg (parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
5499 if (EQ (display
, Qunbound
))
5501 dpyinfo
= check_x_display_info (display
);
5503 kb
= dpyinfo
->kboard
;
5505 kb
= &the_only_kboard
;
5508 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5510 && ! EQ (name
, Qunbound
)
5512 error ("Invalid frame name--not a string or nil");
5515 Vx_resource_name
= name
;
5517 /* See if parent window is specified. */
5518 parent
= w32_get_arg (parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
5519 if (EQ (parent
, Qunbound
))
5521 if (! NILP (parent
))
5522 CHECK_NUMBER (parent
);
5524 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
5525 /* No need to protect DISPLAY because that's not used after passing
5526 it to make_frame_without_minibuffer. */
5528 GCPRO4 (parms
, parent
, name
, frame
);
5529 tem
= w32_get_arg (parms
, Qminibuffer
, "minibuffer", "Minibuffer",
5531 if (EQ (tem
, Qnone
) || NILP (tem
))
5532 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
5533 else if (EQ (tem
, Qonly
))
5535 f
= make_minibuffer_frame ();
5536 minibuffer_only
= 1;
5538 else if (WINDOWP (tem
))
5539 f
= make_frame_without_minibuffer (tem
, kb
, display
);
5543 XSETFRAME (frame
, f
);
5545 /* Note that Windows does support scroll bars. */
5546 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
5547 /* By default, make scrollbars the system standard width. */
5548 f
->scroll_bar_pixel_width
= GetSystemMetrics (SM_CXVSCROLL
);
5550 f
->output_method
= output_w32
;
5551 f
->output_data
.w32
=
5552 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
5553 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
5554 FRAME_FONTSET (f
) = -1;
5555 record_unwind_protect (unwind_create_frame
, frame
);
5558 = w32_get_arg (parms
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
5559 if (! STRINGP (f
->icon_name
))
5560 f
->icon_name
= Qnil
;
5562 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
5564 FRAME_KBOARD (f
) = kb
;
5567 /* Specify the parent under which to make this window. */
5571 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
5572 f
->output_data
.w32
->explicit_parent
= 1;
5576 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5577 f
->output_data
.w32
->explicit_parent
= 0;
5580 /* Set the name; the functions to which we pass f expect the name to
5582 if (EQ (name
, Qunbound
) || NILP (name
))
5584 f
->name
= build_string (dpyinfo
->w32_id_name
);
5585 f
->explicit_name
= 0;
5590 f
->explicit_name
= 1;
5591 /* use the frame's title when getting resources for this frame. */
5592 specbind (Qx_resource_name
, name
);
5595 /* Extract the window parameters from the supplied values
5596 that are needed to determine window geometry. */
5600 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
5603 /* First, try whatever font the caller has specified. */
5606 tem
= Fquery_fontset (font
, Qnil
);
5608 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
5610 font
= x_new_font (f
, XSTRING (font
)->data
);
5612 /* Try out a font which we hope has bold and italic variations. */
5613 if (!STRINGP (font
))
5614 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
5615 if (! STRINGP (font
))
5616 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
5617 /* If those didn't work, look for something which will at least work. */
5618 if (! STRINGP (font
))
5619 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
5621 if (! STRINGP (font
))
5622 font
= build_string ("Fixedsys");
5624 x_default_parameter (f
, parms
, Qfont
, font
,
5625 "font", "Font", RES_TYPE_STRING
);
5628 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5629 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5630 /* This defaults to 2 in order to match xterm. We recognize either
5631 internalBorderWidth or internalBorder (which is what xterm calls
5633 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5637 value
= w32_get_arg (parms
, Qinternal_border_width
,
5638 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
5639 if (! EQ (value
, Qunbound
))
5640 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5643 /* Default internalBorderWidth to 0 on Windows to match other programs. */
5644 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (0),
5645 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
5646 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qright
,
5647 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
5649 /* Also do the stuff which must be set before the window exists. */
5650 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5651 "foreground", "Foreground", RES_TYPE_STRING
);
5652 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5653 "background", "Background", RES_TYPE_STRING
);
5654 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5655 "pointerColor", "Foreground", RES_TYPE_STRING
);
5656 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5657 "cursorColor", "Foreground", RES_TYPE_STRING
);
5658 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5659 "borderColor", "BorderColor", RES_TYPE_STRING
);
5660 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
5661 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
5662 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
5663 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
5664 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
5665 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
5666 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
5667 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
5670 /* Init faces before x_default_parameter is called for scroll-bar
5671 parameters because that function calls x_set_scroll_bar_width,
5672 which calls change_frame_size, which calls Fset_window_buffer,
5673 which runs hooks, which call Fvertical_motion. At the end, we
5674 end up in init_iterator with a null face cache, which should not
5676 init_frame_faces (f
);
5678 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
5679 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
5680 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (1),
5681 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
5683 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
5684 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
5685 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
5686 "title", "Title", RES_TYPE_STRING
);
5687 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
5688 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
5690 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
5691 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5693 /* Add the tool-bar height to the initial frame height so that the
5694 user gets a text display area of the size he specified with -g or
5695 via .Xdefaults. Later changes of the tool-bar height don't
5696 change the frame size. This is done so that users can create
5697 tall Emacs frames without having to guess how tall the tool-bar
5699 if (FRAME_TOOL_BAR_LINES (f
))
5701 int margin
, relief
, bar_height
;
5703 relief
= (tool_bar_button_relief
>= 0
5704 ? tool_bar_button_relief
5705 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
5707 if (INTEGERP (Vtool_bar_button_margin
)
5708 && XINT (Vtool_bar_button_margin
) > 0)
5709 margin
= XFASTINT (Vtool_bar_button_margin
);
5710 else if (CONSP (Vtool_bar_button_margin
)
5711 && INTEGERP (XCDR (Vtool_bar_button_margin
))
5712 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
5713 margin
= XFASTINT (XCDR (Vtool_bar_button_margin
));
5717 bar_height
= DEFAULT_TOOL_BAR_IMAGE_HEIGHT
+ 2 * margin
+ 2 * relief
;
5718 f
->height
+= (bar_height
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
5721 window_prompting
= x_figure_window_size (f
, parms
);
5723 if (window_prompting
& XNegative
)
5725 if (window_prompting
& YNegative
)
5726 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
5728 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
5732 if (window_prompting
& YNegative
)
5733 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
5735 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
5738 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
5740 tem
= w32_get_arg (parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
5741 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
5743 w32_window (f
, window_prompting
, minibuffer_only
);
5748 /* Now consider the frame official. */
5749 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5750 Vframe_list
= Fcons (frame
, Vframe_list
);
5752 /* We need to do this after creating the window, so that the
5753 icon-creation functions can say whose icon they're describing. */
5754 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
5755 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
5757 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5758 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5759 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5760 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5761 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5762 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5763 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
5764 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
5766 /* Dimensions, especially f->height, must be done via change_frame_size.
5767 Change will not be effected unless different from the current
5773 SET_FRAME_WIDTH (f
, 0);
5774 change_frame_size (f
, height
, width
, 1, 0, 0);
5776 /* Tell the server what size and position, etc, we want, and how
5777 badly we want them. This should be done after we have the menu
5778 bar so that its size can be taken into account. */
5780 x_wm_set_size_hint (f
, window_prompting
, 0);
5783 /* Avoid a bug that causes the new frame to never become visible if
5784 an echo area message is displayed during the following call1. */
5785 specbind(Qredisplay_dont_pause
, Qt
);
5787 /* Set up faces after all frame parameters are known. This call
5788 also merges in face attributes specified for new frames. If we
5789 don't do this, the `menu' face for instance won't have the right
5790 colors, and the menu bar won't appear in the specified colors for
5792 call1 (Qface_set_after_frame_default
, frame
);
5794 /* Make the window appear on the frame and enable display, unless
5795 the caller says not to. However, with explicit parent, Emacs
5796 cannot control visibility, so don't try. */
5797 if (! f
->output_data
.w32
->explicit_parent
)
5799 Lisp_Object visibility
;
5801 visibility
= w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
5802 if (EQ (visibility
, Qunbound
))
5805 if (EQ (visibility
, Qicon
))
5806 x_iconify_frame (f
);
5807 else if (! NILP (visibility
))
5808 x_make_frame_visible (f
);
5810 /* Must have been Qnil. */
5815 /* Make sure windows on this frame appear in calls to next-window
5816 and similar functions. */
5817 Vwindow_list
= Qnil
;
5819 return unbind_to (count
, frame
);
5822 /* FRAME is used only to get a handle on the X display. We don't pass the
5823 display info directly because we're called from frame.c, which doesn't
5824 know about that structure. */
5826 x_get_focus_frame (frame
)
5827 struct frame
*frame
;
5829 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
5831 if (! dpyinfo
->w32_focus_frame
)
5834 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
5838 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
5839 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
5843 x_focus_on_frame (check_x_frame (frame
));
5848 /* Return the charset portion of a font name. */
5849 char * xlfd_charset_of_font (char * fontname
)
5851 char *charset
, *encoding
;
5853 encoding
= strrchr(fontname
, '-');
5854 if (!encoding
|| encoding
== fontname
)
5857 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
5858 if (*charset
== '-')
5861 if (charset
== fontname
|| strcmp(charset
, "-*-*") == 0)
5867 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
5868 int size
, char* filename
);
5869 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
5870 static BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
,
5872 static BOOL
x_to_w32_font (char *lpxstr
, LOGFONT
*lplogfont
);
5874 static struct font_info
*
5875 w32_load_system_font (f
,fontname
,size
)
5880 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5881 Lisp_Object font_names
;
5883 /* Get a list of all the fonts that match this name. Once we
5884 have a list of matching fonts, we compare them against the fonts
5885 we already have loaded by comparing names. */
5886 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
5888 if (!NILP (font_names
))
5893 /* First check if any are already loaded, as that is cheaper
5894 than loading another one. */
5895 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
5896 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
5897 if (dpyinfo
->font_table
[i
].name
5898 && (!strcmp (dpyinfo
->font_table
[i
].name
,
5899 XSTRING (XCAR (tail
))->data
)
5900 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
5901 XSTRING (XCAR (tail
))->data
)))
5902 return (dpyinfo
->font_table
+ i
);
5904 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
5906 else if (w32_strict_fontnames
)
5908 /* If EnumFontFamiliesEx was available, we got a full list of
5909 fonts back so stop now to avoid the possibility of loading a
5910 random font. If we had to fall back to EnumFontFamilies, the
5911 list is incomplete, so continue whether the font we want was
5913 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5914 FARPROC enum_font_families_ex
5915 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
5916 if (enum_font_families_ex
)
5920 /* Load the font and add it to the table. */
5922 char *full_name
, *encoding
, *charset
;
5924 struct font_info
*fontp
;
5930 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
5933 if (!*lf
.lfFaceName
)
5934 /* If no name was specified for the font, we get a random font
5935 from CreateFontIndirect - this is not particularly
5936 desirable, especially since CreateFontIndirect does not
5937 fill out the missing name in lf, so we never know what we
5941 /* Specify anti-aliasing to prevent Cleartype fonts being used,
5942 since those fonts leave garbage behind. */
5943 lf
.lfQuality
= ANTIALIASED_QUALITY
;
5945 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
5946 bzero (font
, sizeof (*font
));
5948 /* Set bdf to NULL to indicate that this is a Windows font. */
5953 font
->hfont
= CreateFontIndirect (&lf
);
5955 if (font
->hfont
== NULL
)
5964 codepage
= w32_codepage_for_font (fontname
);
5966 hdc
= GetDC (dpyinfo
->root_window
);
5967 oldobj
= SelectObject (hdc
, font
->hfont
);
5969 ok
= GetTextMetrics (hdc
, &font
->tm
);
5970 if (codepage
== CP_UNICODE
)
5971 font
->double_byte_p
= 1;
5974 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
5975 don't report themselves as double byte fonts, when
5976 patently they are. So instead of trusting
5977 GetFontLanguageInfo, we check the properties of the
5978 codepage directly, since that is ultimately what we are
5979 working from anyway. */
5980 /* font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS; */
5982 GetCPInfo (codepage
, &cpi
);
5983 font
->double_byte_p
= cpi
.MaxCharSize
> 1;
5986 SelectObject (hdc
, oldobj
);
5987 ReleaseDC (dpyinfo
->root_window
, hdc
);
5988 /* Fill out details in lf according to the font that was
5990 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
5991 lf
.lfWidth
= font
->tm
.tmAveCharWidth
;
5992 lf
.lfWeight
= font
->tm
.tmWeight
;
5993 lf
.lfItalic
= font
->tm
.tmItalic
;
5994 lf
.lfCharSet
= font
->tm
.tmCharSet
;
5995 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
5996 ? VARIABLE_PITCH
: FIXED_PITCH
);
5997 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
5998 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
6000 w32_cache_char_metrics (font
);
6007 w32_unload_font (dpyinfo
, font
);
6011 /* Find a free slot in the font table. */
6012 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
6013 if (dpyinfo
->font_table
[i
].name
== NULL
)
6016 /* If no free slot found, maybe enlarge the font table. */
6017 if (i
== dpyinfo
->n_fonts
6018 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
6021 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
6022 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
6024 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
6027 fontp
= dpyinfo
->font_table
+ i
;
6028 if (i
== dpyinfo
->n_fonts
)
6031 /* Now fill in the slots of *FONTP. */
6034 fontp
->font_idx
= i
;
6035 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
6036 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
6038 charset
= xlfd_charset_of_font (fontname
);
6040 /* Cache the W32 codepage for a font. This makes w32_encode_char
6041 (called for every glyph during redisplay) much faster. */
6042 fontp
->codepage
= codepage
;
6044 /* Work out the font's full name. */
6045 full_name
= (char *)xmalloc (100);
6046 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
6047 fontp
->full_name
= full_name
;
6050 /* If all else fails - just use the name we used to load it. */
6052 fontp
->full_name
= fontp
->name
;
6055 fontp
->size
= FONT_WIDTH (font
);
6056 fontp
->height
= FONT_HEIGHT (font
);
6058 /* The slot `encoding' specifies how to map a character
6059 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
6060 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
6061 (0:0x20..0x7F, 1:0xA0..0xFF,
6062 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
6063 2:0xA020..0xFF7F). For the moment, we don't know which charset
6064 uses this font. So, we set information in fontp->encoding[1]
6065 which is never used by any charset. If mapping can't be
6066 decided, set FONT_ENCODING_NOT_DECIDED. */
6068 /* SJIS fonts need to be set to type 4, all others seem to work as
6069 type FONT_ENCODING_NOT_DECIDED. */
6070 encoding
= strrchr (fontp
->name
, '-');
6071 if (encoding
&& strnicmp (encoding
+1, "sjis", 4) == 0)
6072 fontp
->encoding
[1] = 4;
6074 fontp
->encoding
[1] = FONT_ENCODING_NOT_DECIDED
;
6076 /* The following three values are set to 0 under W32, which is
6077 what they get set to if XGetFontProperty fails under X. */
6078 fontp
->baseline_offset
= 0;
6079 fontp
->relative_compose
= 0;
6080 fontp
->default_ascent
= 0;
6082 /* Set global flag fonts_changed_p to non-zero if the font loaded
6083 has a character with a smaller width than any other character
6084 before, or if the font loaded has a smaller height than any
6085 other font loaded before. If this happens, it will make a
6086 glyph matrix reallocation necessary. */
6087 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
6093 /* Load font named FONTNAME of size SIZE for frame F, and return a
6094 pointer to the structure font_info while allocating it dynamically.
6095 If loading fails, return NULL. */
6097 w32_load_font (f
,fontname
,size
)
6102 Lisp_Object bdf_fonts
;
6103 struct font_info
*retval
= NULL
;
6105 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
6107 while (!retval
&& CONSP (bdf_fonts
))
6109 char *bdf_name
, *bdf_file
;
6110 Lisp_Object bdf_pair
;
6112 bdf_name
= XSTRING (XCAR (bdf_fonts
))->data
;
6113 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
6114 bdf_file
= XSTRING (XCDR (bdf_pair
))->data
;
6116 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
6118 bdf_fonts
= XCDR (bdf_fonts
);
6124 return w32_load_system_font(f
, fontname
, size
);
6129 w32_unload_font (dpyinfo
, font
)
6130 struct w32_display_info
*dpyinfo
;
6135 if (font
->per_char
) xfree (font
->per_char
);
6136 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
6138 if (font
->hfont
) DeleteObject(font
->hfont
);
6143 /* The font conversion stuff between x and w32 */
6145 /* X font string is as follows (from faces.el)
6149 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
6150 * (weight\? "\\([^-]*\\)") ; 1
6151 * (slant "\\([ior]\\)") ; 2
6152 * (slant\? "\\([^-]?\\)") ; 2
6153 * (swidth "\\([^-]*\\)") ; 3
6154 * (adstyle "[^-]*") ; 4
6155 * (pixelsize "[0-9]+")
6156 * (pointsize "[0-9][0-9]+")
6157 * (resx "[0-9][0-9]+")
6158 * (resy "[0-9][0-9]+")
6159 * (spacing "[cmp?*]")
6160 * (avgwidth "[0-9]+")
6161 * (registry "[^-]+")
6162 * (encoding "[^-]+")
6167 x_to_w32_weight (lpw
)
6170 if (!lpw
) return (FW_DONTCARE
);
6172 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
6173 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
6174 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
6175 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
6176 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
6177 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
6178 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
6179 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
6180 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
6181 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
6188 w32_to_x_weight (fnweight
)
6191 if (fnweight
>= FW_HEAVY
) return "heavy";
6192 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
6193 if (fnweight
>= FW_BOLD
) return "bold";
6194 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
6195 if (fnweight
>= FW_MEDIUM
) return "medium";
6196 if (fnweight
>= FW_NORMAL
) return "normal";
6197 if (fnweight
>= FW_LIGHT
) return "light";
6198 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
6199 if (fnweight
>= FW_THIN
) return "thin";
6205 x_to_w32_charset (lpcs
)
6208 Lisp_Object this_entry
, w32_charset
;
6210 int len
= strlen (lpcs
);
6212 /* Support "*-#nnn" format for unknown charsets. */
6213 if (strncmp (lpcs
, "*-#", 3) == 0)
6214 return atoi (lpcs
+ 3);
6216 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
6217 charset
= alloca (len
+ 1);
6218 strcpy (charset
, lpcs
);
6219 lpcs
= strchr (charset
, '*');
6223 /* Look through w32-charset-info-alist for the character set.
6224 Format of each entry is
6225 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
6227 this_entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
6229 if (NILP(this_entry
))
6231 /* At startup, we want iso8859-1 fonts to come up properly. */
6232 if (stricmp(charset
, "iso8859-1") == 0)
6233 return ANSI_CHARSET
;
6235 return DEFAULT_CHARSET
;
6238 w32_charset
= Fcar (Fcdr (this_entry
));
6240 /* Translate Lisp symbol to number. */
6241 if (w32_charset
== Qw32_charset_ansi
)
6242 return ANSI_CHARSET
;
6243 if (w32_charset
== Qw32_charset_symbol
)
6244 return SYMBOL_CHARSET
;
6245 if (w32_charset
== Qw32_charset_shiftjis
)
6246 return SHIFTJIS_CHARSET
;
6247 if (w32_charset
== Qw32_charset_hangeul
)
6248 return HANGEUL_CHARSET
;
6249 if (w32_charset
== Qw32_charset_chinesebig5
)
6250 return CHINESEBIG5_CHARSET
;
6251 if (w32_charset
== Qw32_charset_gb2312
)
6252 return GB2312_CHARSET
;
6253 if (w32_charset
== Qw32_charset_oem
)
6255 #ifdef JOHAB_CHARSET
6256 if (w32_charset
== Qw32_charset_johab
)
6257 return JOHAB_CHARSET
;
6258 if (w32_charset
== Qw32_charset_easteurope
)
6259 return EASTEUROPE_CHARSET
;
6260 if (w32_charset
== Qw32_charset_turkish
)
6261 return TURKISH_CHARSET
;
6262 if (w32_charset
== Qw32_charset_baltic
)
6263 return BALTIC_CHARSET
;
6264 if (w32_charset
== Qw32_charset_russian
)
6265 return RUSSIAN_CHARSET
;
6266 if (w32_charset
== Qw32_charset_arabic
)
6267 return ARABIC_CHARSET
;
6268 if (w32_charset
== Qw32_charset_greek
)
6269 return GREEK_CHARSET
;
6270 if (w32_charset
== Qw32_charset_hebrew
)
6271 return HEBREW_CHARSET
;
6272 if (w32_charset
== Qw32_charset_vietnamese
)
6273 return VIETNAMESE_CHARSET
;
6274 if (w32_charset
== Qw32_charset_thai
)
6275 return THAI_CHARSET
;
6276 if (w32_charset
== Qw32_charset_mac
)
6278 #endif /* JOHAB_CHARSET */
6279 #ifdef UNICODE_CHARSET
6280 if (w32_charset
== Qw32_charset_unicode
)
6281 return UNICODE_CHARSET
;
6284 return DEFAULT_CHARSET
;
6289 w32_to_x_charset (fncharset
)
6292 static char buf
[32];
6293 Lisp_Object charset_type
;
6298 /* Handle startup case of w32-charset-info-alist not
6299 being set up yet. */
6300 if (NILP(Vw32_charset_info_alist
))
6302 charset_type
= Qw32_charset_ansi
;
6304 case DEFAULT_CHARSET
:
6305 charset_type
= Qw32_charset_default
;
6307 case SYMBOL_CHARSET
:
6308 charset_type
= Qw32_charset_symbol
;
6310 case SHIFTJIS_CHARSET
:
6311 charset_type
= Qw32_charset_shiftjis
;
6313 case HANGEUL_CHARSET
:
6314 charset_type
= Qw32_charset_hangeul
;
6316 case GB2312_CHARSET
:
6317 charset_type
= Qw32_charset_gb2312
;
6319 case CHINESEBIG5_CHARSET
:
6320 charset_type
= Qw32_charset_chinesebig5
;
6323 charset_type
= Qw32_charset_oem
;
6326 /* More recent versions of Windows (95 and NT4.0) define more
6328 #ifdef EASTEUROPE_CHARSET
6329 case EASTEUROPE_CHARSET
:
6330 charset_type
= Qw32_charset_easteurope
;
6332 case TURKISH_CHARSET
:
6333 charset_type
= Qw32_charset_turkish
;
6335 case BALTIC_CHARSET
:
6336 charset_type
= Qw32_charset_baltic
;
6338 case RUSSIAN_CHARSET
:
6339 charset_type
= Qw32_charset_russian
;
6341 case ARABIC_CHARSET
:
6342 charset_type
= Qw32_charset_arabic
;
6345 charset_type
= Qw32_charset_greek
;
6347 case HEBREW_CHARSET
:
6348 charset_type
= Qw32_charset_hebrew
;
6350 case VIETNAMESE_CHARSET
:
6351 charset_type
= Qw32_charset_vietnamese
;
6354 charset_type
= Qw32_charset_thai
;
6357 charset_type
= Qw32_charset_mac
;
6360 charset_type
= Qw32_charset_johab
;
6364 #ifdef UNICODE_CHARSET
6365 case UNICODE_CHARSET
:
6366 charset_type
= Qw32_charset_unicode
;
6370 /* Encode numerical value of unknown charset. */
6371 sprintf (buf
, "*-#%u", fncharset
);
6377 char * best_match
= NULL
;
6379 /* Look through w32-charset-info-alist for the character set.
6380 Prefer ISO codepages, and prefer lower numbers in the ISO
6381 range. Only return charsets for codepages which are installed.
6383 Format of each entry is
6384 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
6386 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
6389 Lisp_Object w32_charset
;
6390 Lisp_Object codepage
;
6392 Lisp_Object this_entry
= XCAR (rest
);
6394 /* Skip invalid entries in alist. */
6395 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
6396 || !CONSP (XCDR (this_entry
))
6397 || !SYMBOLP (XCAR (XCDR (this_entry
))))
6400 x_charset
= XSTRING (XCAR (this_entry
))->data
;
6401 w32_charset
= XCAR (XCDR (this_entry
));
6402 codepage
= XCDR (XCDR (this_entry
));
6404 /* Look for Same charset and a valid codepage (or non-int
6405 which means ignore). */
6406 if (w32_charset
== charset_type
6407 && (!INTEGERP (codepage
) || codepage
== CP_DEFAULT
6408 || IsValidCodePage (XINT (codepage
))))
6410 /* If we don't have a match already, then this is the
6413 best_match
= x_charset
;
6414 /* If this is an ISO codepage, and the best so far isn't,
6415 then this is better. */
6416 else if (strnicmp (best_match
, "iso", 3) != 0
6417 && strnicmp (x_charset
, "iso", 3) == 0)
6418 best_match
= x_charset
;
6419 /* If both are ISO8859 codepages, choose the one with the
6420 lowest number in the encoding field. */
6421 else if (strnicmp (best_match
, "iso8859-", 8) == 0
6422 && strnicmp (x_charset
, "iso8859-", 8) == 0)
6424 int best_enc
= atoi (best_match
+ 8);
6425 int this_enc
= atoi (x_charset
+ 8);
6426 if (this_enc
> 0 && this_enc
< best_enc
)
6427 best_match
= x_charset
;
6432 /* If no match, encode the numeric value. */
6435 sprintf (buf
, "*-#%u", fncharset
);
6439 strncpy(buf
, best_match
, 31);
6446 /* Return all the X charsets that map to a font. */
6448 w32_to_all_x_charsets (fncharset
)
6451 static char buf
[32];
6452 Lisp_Object charset_type
;
6453 Lisp_Object retval
= Qnil
;
6458 /* Handle startup case of w32-charset-info-alist not
6459 being set up yet. */
6460 if (NILP(Vw32_charset_info_alist
))
6461 return Fcons (build_string ("iso8859-1"), Qnil
);
6463 charset_type
= Qw32_charset_ansi
;
6465 case DEFAULT_CHARSET
:
6466 charset_type
= Qw32_charset_default
;
6468 case SYMBOL_CHARSET
:
6469 charset_type
= Qw32_charset_symbol
;
6471 case SHIFTJIS_CHARSET
:
6472 charset_type
= Qw32_charset_shiftjis
;
6474 case HANGEUL_CHARSET
:
6475 charset_type
= Qw32_charset_hangeul
;
6477 case GB2312_CHARSET
:
6478 charset_type
= Qw32_charset_gb2312
;
6480 case CHINESEBIG5_CHARSET
:
6481 charset_type
= Qw32_charset_chinesebig5
;
6484 charset_type
= Qw32_charset_oem
;
6487 /* More recent versions of Windows (95 and NT4.0) define more
6489 #ifdef EASTEUROPE_CHARSET
6490 case EASTEUROPE_CHARSET
:
6491 charset_type
= Qw32_charset_easteurope
;
6493 case TURKISH_CHARSET
:
6494 charset_type
= Qw32_charset_turkish
;
6496 case BALTIC_CHARSET
:
6497 charset_type
= Qw32_charset_baltic
;
6499 case RUSSIAN_CHARSET
:
6500 charset_type
= Qw32_charset_russian
;
6502 case ARABIC_CHARSET
:
6503 charset_type
= Qw32_charset_arabic
;
6506 charset_type
= Qw32_charset_greek
;
6508 case HEBREW_CHARSET
:
6509 charset_type
= Qw32_charset_hebrew
;
6511 case VIETNAMESE_CHARSET
:
6512 charset_type
= Qw32_charset_vietnamese
;
6515 charset_type
= Qw32_charset_thai
;
6518 charset_type
= Qw32_charset_mac
;
6521 charset_type
= Qw32_charset_johab
;
6525 #ifdef UNICODE_CHARSET
6526 case UNICODE_CHARSET
:
6527 charset_type
= Qw32_charset_unicode
;
6531 /* Encode numerical value of unknown charset. */
6532 sprintf (buf
, "*-#%u", fncharset
);
6533 return Fcons (build_string (buf
), Qnil
);
6538 /* Look through w32-charset-info-alist for the character set.
6539 Only return charsets for codepages which are installed.
6541 Format of each entry in Vw32_charset_info_alist is
6542 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
6544 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
6546 Lisp_Object x_charset
;
6547 Lisp_Object w32_charset
;
6548 Lisp_Object codepage
;
6550 Lisp_Object this_entry
= XCAR (rest
);
6552 /* Skip invalid entries in alist. */
6553 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
6554 || !CONSP (XCDR (this_entry
))
6555 || !SYMBOLP (XCAR (XCDR (this_entry
))))
6558 x_charset
= XCAR (this_entry
);
6559 w32_charset
= XCAR (XCDR (this_entry
));
6560 codepage
= XCDR (XCDR (this_entry
));
6562 /* Look for Same charset and a valid codepage (or non-int
6563 which means ignore). */
6564 if (w32_charset
== charset_type
6565 && (!INTEGERP (codepage
) || codepage
== CP_DEFAULT
6566 || IsValidCodePage (XINT (codepage
))))
6568 retval
= Fcons (x_charset
, retval
);
6572 /* If no match, encode the numeric value. */
6575 sprintf (buf
, "*-#%u", fncharset
);
6576 return Fcons (build_string (buf
), Qnil
);
6583 /* Get the Windows codepage corresponding to the specified font. The
6584 charset info in the font name is used to look up
6585 w32-charset-to-codepage-alist. */
6587 w32_codepage_for_font (char *fontname
)
6589 Lisp_Object codepage
, entry
;
6590 char *charset_str
, *charset
, *end
;
6592 if (NILP (Vw32_charset_info_alist
))
6595 /* Extract charset part of font string. */
6596 charset
= xlfd_charset_of_font (fontname
);
6601 charset_str
= (char *) alloca (strlen (charset
) + 1);
6602 strcpy (charset_str
, charset
);
6605 /* Remove leading "*-". */
6606 if (strncmp ("*-", charset_str
, 2) == 0)
6607 charset
= charset_str
+ 2;
6610 charset
= charset_str
;
6612 /* Stop match at wildcard (including preceding '-'). */
6613 if (end
= strchr (charset
, '*'))
6615 if (end
> charset
&& *(end
-1) == '-')
6620 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
6624 codepage
= Fcdr (Fcdr (entry
));
6626 if (NILP (codepage
))
6628 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
6630 else if (INTEGERP (codepage
))
6631 return XINT (codepage
);
6638 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
6639 LOGFONT
* lplogfont
;
6642 char * specific_charset
;
6646 char height_pixels
[8];
6648 char width_pixels
[8];
6649 char *fontname_dash
;
6650 int display_resy
= (int) one_w32_display_info
.resy
;
6651 int display_resx
= (int) one_w32_display_info
.resx
;
6653 struct coding_system coding
;
6655 if (!lpxstr
) abort ();
6660 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
6661 fonttype
= "raster";
6662 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
6663 fonttype
= "outline";
6665 fonttype
= "unknown";
6667 setup_coding_system (Fcheck_coding_system (Vlocale_coding_system
),
6669 coding
.src_multibyte
= 0;
6670 coding
.dst_multibyte
= 1;
6671 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6672 bufsz
= decoding_buffer_size (&coding
, LF_FACESIZE
);
6674 fontname
= alloca(sizeof(*fontname
) * bufsz
);
6675 decode_coding (&coding
, lplogfont
->lfFaceName
, fontname
,
6676 strlen(lplogfont
->lfFaceName
), bufsz
- 1);
6677 *(fontname
+ coding
.produced
) = '\0';
6679 /* Replace dashes with underscores so the dashes are not
6681 fontname_dash
= fontname
;
6682 while (fontname_dash
= strchr (fontname_dash
, '-'))
6683 *fontname_dash
= '_';
6685 if (lplogfont
->lfHeight
)
6687 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
6688 sprintf (height_dpi
, "%u",
6689 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
6693 strcpy (height_pixels
, "*");
6694 strcpy (height_dpi
, "*");
6696 if (lplogfont
->lfWidth
)
6697 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
6699 strcpy (width_pixels
, "*");
6701 _snprintf (lpxstr
, len
- 1,
6702 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
6703 fonttype
, /* foundry */
6704 fontname
, /* family */
6705 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
6706 lplogfont
->lfItalic
?'i':'r', /* slant */
6708 /* add style name */
6709 height_pixels
, /* pixel size */
6710 height_dpi
, /* point size */
6711 display_resx
, /* resx */
6712 display_resy
, /* resy */
6713 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
6714 ? 'p' : 'c', /* spacing */
6715 width_pixels
, /* avg width */
6716 specific_charset
? specific_charset
6717 : w32_to_x_charset (lplogfont
->lfCharSet
)
6718 /* charset registry and encoding */
6721 lpxstr
[len
- 1] = 0; /* just to be sure */
6726 x_to_w32_font (lpxstr
, lplogfont
)
6728 LOGFONT
* lplogfont
;
6730 struct coding_system coding
;
6732 if (!lplogfont
) return (FALSE
);
6734 memset (lplogfont
, 0, sizeof (*lplogfont
));
6736 /* Set default value for each field. */
6738 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
6739 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
6740 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
6742 /* go for maximum quality */
6743 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
6744 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
6745 lplogfont
->lfQuality
= PROOF_QUALITY
;
6748 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
6749 lplogfont
->lfWeight
= FW_DONTCARE
;
6750 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
6755 /* Provide a simple escape mechanism for specifying Windows font names
6756 * directly -- if font spec does not beginning with '-', assume this
6758 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
6764 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
6765 width
[10], resy
[10], remainder
[50];
6767 int dpi
= (int) one_w32_display_info
.resy
;
6769 fields
= sscanf (lpxstr
,
6770 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
6771 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
6775 /* In the general case when wildcards cover more than one field,
6776 we don't know which field is which, so don't fill any in.
6777 However, we need to cope with this particular form, which is
6778 generated by font_list_1 (invoked by try_font_list):
6779 "-raster-6x10-*-gb2312*-*"
6780 and make sure to correctly parse the charset field. */
6783 fields
= sscanf (lpxstr
,
6784 "-%*[^-]-%49[^-]-*-%49s",
6787 else if (fields
< 9)
6793 if (fields
> 0 && name
[0] != '*')
6799 (Fcheck_coding_system (Vlocale_coding_system
), &coding
);
6800 coding
.src_multibyte
= 1;
6801 coding
.dst_multibyte
= 1;
6802 bufsize
= encoding_buffer_size (&coding
, strlen (name
));
6803 buf
= (unsigned char *) alloca (bufsize
);
6804 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6805 encode_coding (&coding
, name
, buf
, strlen (name
), bufsize
);
6806 if (coding
.produced
>= LF_FACESIZE
)
6807 coding
.produced
= LF_FACESIZE
- 1;
6808 buf
[coding
.produced
] = 0;
6809 strcpy (lplogfont
->lfFaceName
, buf
);
6813 lplogfont
->lfFaceName
[0] = '\0';
6818 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6822 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
6826 if (fields
> 0 && pixels
[0] != '*')
6827 lplogfont
->lfHeight
= atoi (pixels
);
6831 if (fields
> 0 && resy
[0] != '*')
6834 if (tem
> 0) dpi
= tem
;
6837 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
6838 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
6841 lplogfont
->lfPitchAndFamily
=
6842 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
6846 if (fields
> 0 && width
[0] != '*')
6847 lplogfont
->lfWidth
= atoi (width
) / 10;
6851 /* Strip the trailing '-' if present. (it shouldn't be, as it
6852 fails the test against xlfd-tight-regexp in fontset.el). */
6854 int len
= strlen (remainder
);
6855 if (len
> 0 && remainder
[len
-1] == '-')
6856 remainder
[len
-1] = 0;
6858 encoding
= remainder
;
6860 if (strncmp (encoding
, "*-", 2) == 0)
6863 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
6868 char name
[100], height
[10], width
[10], weight
[20];
6870 fields
= sscanf (lpxstr
,
6871 "%99[^:]:%9[^:]:%9[^:]:%19s",
6872 name
, height
, width
, weight
);
6874 if (fields
== EOF
) return (FALSE
);
6878 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
6879 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
6883 lplogfont
->lfFaceName
[0] = 0;
6889 lplogfont
->lfHeight
= atoi (height
);
6894 lplogfont
->lfWidth
= atoi (width
);
6898 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6901 /* This makes TrueType fonts work better. */
6902 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
6907 /* Strip the pixel height and point height from the given xlfd, and
6908 return the pixel height. If no pixel height is specified, calculate
6909 one from the point height, or if that isn't defined either, return
6910 0 (which usually signifies a scalable font).
6913 xlfd_strip_height (char *fontname
)
6915 int pixel_height
, field_number
;
6916 char *read_from
, *write_to
;
6920 pixel_height
= field_number
= 0;
6923 /* Look for height fields. */
6924 for (read_from
= fontname
; *read_from
; read_from
++)
6926 if (*read_from
== '-')
6929 if (field_number
== 7) /* Pixel height. */
6932 write_to
= read_from
;
6934 /* Find end of field. */
6935 for (;*read_from
&& *read_from
!= '-'; read_from
++)
6938 /* Split the fontname at end of field. */
6944 pixel_height
= atoi (write_to
);
6945 /* Blank out field. */
6946 if (read_from
> write_to
)
6951 /* If the pixel height field is at the end (partial xlfd),
6954 return pixel_height
;
6956 /* If we got a pixel height, the point height can be
6957 ignored. Just blank it out and break now. */
6960 /* Find end of point size field. */
6961 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6967 /* Blank out the point size field. */
6968 if (read_from
> write_to
)
6974 return pixel_height
;
6978 /* If the point height is already blank, break now. */
6979 if (*read_from
== '-')
6985 else if (field_number
== 8)
6987 /* If we didn't get a pixel height, try to get the point
6988 height and convert that. */
6990 char *point_size_start
= read_from
++;
6992 /* Find end of field. */
6993 for (; *read_from
&& *read_from
!= '-'; read_from
++)
7002 point_size
= atoi (point_size_start
);
7004 /* Convert to pixel height. */
7005 pixel_height
= point_size
7006 * one_w32_display_info
.height_in
/ 720;
7008 /* Blank out this field and break. */
7016 /* Shift the rest of the font spec into place. */
7017 if (write_to
&& read_from
> write_to
)
7019 for (; *read_from
; read_from
++, write_to
++)
7020 *write_to
= *read_from
;
7024 return pixel_height
;
7027 /* Assume parameter 1 is fully qualified, no wildcards. */
7029 w32_font_match (fontname
, pattern
)
7033 char *regex
= alloca (strlen (pattern
) * 2 + 3);
7034 char *font_name_copy
= alloca (strlen (fontname
) + 1);
7037 /* Copy fontname so we can modify it during comparison. */
7038 strcpy (font_name_copy
, fontname
);
7043 /* Turn pattern into a regexp and do a regexp match. */
7044 for (; *pattern
; pattern
++)
7046 if (*pattern
== '?')
7048 else if (*pattern
== '*')
7059 /* Strip out font heights and compare them seperately, since
7060 rounding error can cause mismatches. This also allows a
7061 comparison between a font that declares only a pixel height and a
7062 pattern that declares the point height.
7065 int font_height
, pattern_height
;
7067 font_height
= xlfd_strip_height (font_name_copy
);
7068 pattern_height
= xlfd_strip_height (regex
);
7070 /* Compare now, and don't bother doing expensive regexp matching
7071 if the heights differ. */
7072 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
7076 return (fast_c_string_match_ignore_case (build_string (regex
),
7077 font_name_copy
) >= 0);
7080 /* Callback functions, and a structure holding info they need, for
7081 listing system fonts on W32. We need one set of functions to do the
7082 job properly, but these don't work on NT 3.51 and earlier, so we
7083 have a second set which don't handle character sets properly to
7086 In both cases, there are two passes made. The first pass gets one
7087 font from each family, the second pass lists all the fonts from
7090 typedef struct enumfont_t
7095 XFontStruct
*size_ref
;
7096 Lisp_Object
*pattern
;
7103 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
7107 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
7109 NEWTEXTMETRIC
* lptm
;
7113 /* Ignore struck out and underlined versions of fonts. */
7114 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
7117 /* Only return fonts with names starting with @ if they were
7118 explicitly specified, since Microsoft uses an initial @ to
7119 denote fonts for vertical writing, without providing a more
7120 convenient way of identifying them. */
7121 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
7122 && lpef
->logfont
.lfFaceName
[0] != '@')
7125 /* Check that the character set matches if it was specified */
7126 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
7127 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
7132 Lisp_Object width
= Qnil
;
7133 Lisp_Object charset_list
= Qnil
;
7134 char *charset
= NULL
;
7136 /* Truetype fonts do not report their true metrics until loaded */
7137 if (FontType
!= RASTER_FONTTYPE
)
7139 if (!NILP (*(lpef
->pattern
)))
7141 /* Scalable fonts are as big as you want them to be. */
7142 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
7143 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
7144 width
= make_number (lpef
->logfont
.lfWidth
);
7148 lplf
->elfLogFont
.lfHeight
= 0;
7149 lplf
->elfLogFont
.lfWidth
= 0;
7153 /* Make sure the height used here is the same as everywhere
7154 else (ie character height, not cell height). */
7155 if (lplf
->elfLogFont
.lfHeight
> 0)
7157 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
7158 if (FontType
== RASTER_FONTTYPE
)
7159 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
7161 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
7164 if (!NILP (*(lpef
->pattern
)))
7166 charset
= xlfd_charset_of_font (XSTRING(*(lpef
->pattern
))->data
);
7168 /* We already checked charsets above, but DEFAULT_CHARSET
7169 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
7171 && strncmp (charset
, "*-*", 3) != 0
7172 && lpef
->logfont
.lfCharSet
== DEFAULT_CHARSET
7173 && strcmp (charset
, w32_to_x_charset (DEFAULT_CHARSET
)) != 0)
7178 charset_list
= Fcons (build_string (charset
), Qnil
);
7180 charset_list
= w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
);
7182 /* Loop through the charsets. */
7183 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
7185 Lisp_Object this_charset
= Fcar (charset_list
);
7186 charset
= XSTRING (this_charset
)->data
;
7188 /* List bold and italic variations if w32-enable-synthesized-fonts
7189 is non-nil and this is a plain font. */
7190 if (w32_enable_synthesized_fonts
7191 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
7192 && lplf
->elfLogFont
.lfItalic
== FALSE
)
7194 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
7197 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
7198 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
7201 lplf
->elfLogFont
.lfItalic
= TRUE
;
7202 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
7205 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
7206 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
7210 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
7219 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
7222 char * match_charset
;
7227 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
7230 if (NILP (*(lpef
->pattern
))
7231 || w32_font_match (buf
, XSTRING (*(lpef
->pattern
))->data
))
7233 /* Check if we already listed this font. This may happen if
7234 w32_enable_synthesized_fonts is non-nil, and there are real
7235 bold and italic versions of the font. */
7236 Lisp_Object font_name
= build_string (buf
);
7237 if (NILP (Fmember (font_name
, lpef
->list
)))
7239 *lpef
->tail
= Fcons (Fcons (build_string (buf
), width
), Qnil
);
7240 lpef
->tail
= &(XCDR (*lpef
->tail
));
7248 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
7250 NEWTEXTMETRIC
* lptm
;
7254 return EnumFontFamilies (lpef
->hdc
,
7255 lplf
->elfLogFont
.lfFaceName
,
7256 (FONTENUMPROC
) enum_font_cb2
,
7262 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
7263 ENUMLOGFONTEX
* lplf
;
7264 NEWTEXTMETRICEX
* lptm
;
7268 /* We are not interested in the extra info we get back from the 'Ex
7269 version - only the fact that we get character set variations
7270 enumerated seperately. */
7271 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
7276 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
7277 ENUMLOGFONTEX
* lplf
;
7278 NEWTEXTMETRICEX
* lptm
;
7282 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
7283 FARPROC enum_font_families_ex
7284 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
7285 /* We don't really expect EnumFontFamiliesEx to disappear once we
7286 get here, so don't bother handling it gracefully. */
7287 if (enum_font_families_ex
== NULL
)
7288 error ("gdi32.dll has disappeared!");
7289 return enum_font_families_ex (lpef
->hdc
,
7291 (FONTENUMPROC
) enum_fontex_cb2
,
7295 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
7296 and xterm.c in Emacs 20.3) */
7298 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
7300 char *fontname
, *ptnstr
;
7301 Lisp_Object list
, tem
, newlist
= Qnil
;
7304 list
= Vw32_bdf_filename_alist
;
7305 ptnstr
= XSTRING (pattern
)->data
;
7307 for ( ; CONSP (list
); list
= XCDR (list
))
7311 fontname
= XSTRING (XCAR (tem
))->data
;
7312 else if (STRINGP (tem
))
7313 fontname
= XSTRING (tem
)->data
;
7317 if (w32_font_match (fontname
, ptnstr
))
7319 newlist
= Fcons (XCAR (tem
), newlist
);
7321 if (n_fonts
>= max_names
)
7330 /* Return a list of names of available fonts matching PATTERN on frame
7331 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
7332 to be listed. Frame F NULL means we have not yet created any
7333 frame, which means we can't get proper size info, as we don't have
7334 a device context to use for GetTextMetrics.
7335 MAXNAMES sets a limit on how many fonts to match. */
7338 w32_list_fonts (f
, pattern
, size
, maxnames
)
7340 Lisp_Object pattern
;
7344 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
7345 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
7346 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
7349 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
7350 if (NILP (patterns
))
7351 patterns
= Fcons (pattern
, Qnil
);
7353 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
7358 tpat
= XCAR (patterns
);
7360 if (!STRINGP (tpat
))
7363 /* Avoid expensive EnumFontFamilies functions if we are not
7364 going to be able to output one of these anyway. */
7365 codepage
= w32_codepage_for_font (XSTRING (tpat
)->data
);
7366 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
7367 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
7368 && !IsValidCodePage(codepage
))
7371 /* See if we cached the result for this particular query.
7372 The cache is an alist of the form:
7373 ((PATTERN (FONTNAME . WIDTH) ...) ...)
7375 if (tem
= XCDR (dpyinfo
->name_list_element
),
7376 !NILP (list
= Fassoc (tpat
, tem
)))
7378 list
= Fcdr_safe (list
);
7379 /* We have a cached list. Don't have to get the list again. */
7384 /* At first, put PATTERN in the cache. */
7391 /* Use EnumFontFamiliesEx where it is available, as it knows
7392 about character sets. Fall back to EnumFontFamilies for
7393 older versions of NT that don't support the 'Ex function. */
7394 x_to_w32_font (XSTRING (tpat
)->data
, &ef
.logfont
);
7396 LOGFONT font_match_pattern
;
7397 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
7398 FARPROC enum_font_families_ex
7399 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
7401 /* We do our own pattern matching so we can handle wildcards. */
7402 font_match_pattern
.lfFaceName
[0] = 0;
7403 font_match_pattern
.lfPitchAndFamily
= 0;
7404 /* We can use the charset, because if it is a wildcard it will
7405 be DEFAULT_CHARSET anyway. */
7406 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
7408 ef
.hdc
= GetDC (dpyinfo
->root_window
);
7410 if (enum_font_families_ex
)
7411 enum_font_families_ex (ef
.hdc
,
7412 &font_match_pattern
,
7413 (FONTENUMPROC
) enum_fontex_cb1
,
7416 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
7419 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
7424 /* Make a list of the fonts we got back.
7425 Store that in the font cache for the display. */
7426 XSETCDR (dpyinfo
->name_list_element
,
7427 Fcons (Fcons (tpat
, list
),
7428 XCDR (dpyinfo
->name_list_element
)));
7431 if (NILP (list
)) continue; /* Try the remaining alternatives. */
7433 newlist
= second_best
= Qnil
;
7435 /* Make a list of the fonts that have the right width. */
7436 for (; CONSP (list
); list
= XCDR (list
))
7443 if (NILP (XCAR (tem
)))
7447 newlist
= Fcons (XCAR (tem
), newlist
);
7449 if (n_fonts
>= maxnames
)
7454 if (!INTEGERP (XCDR (tem
)))
7456 /* Since we don't yet know the size of the font, we must
7457 load it and try GetTextMetrics. */
7458 W32FontStruct thisinfo
;
7463 if (!x_to_w32_font (XSTRING (XCAR (tem
))->data
, &lf
))
7467 thisinfo
.bdf
= NULL
;
7468 thisinfo
.hfont
= CreateFontIndirect (&lf
);
7469 if (thisinfo
.hfont
== NULL
)
7472 hdc
= GetDC (dpyinfo
->root_window
);
7473 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
7474 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
7475 XSETCDR (tem
, make_number (FONT_WIDTH (&thisinfo
)));
7477 XSETCDR (tem
, make_number (0));
7478 SelectObject (hdc
, oldobj
);
7479 ReleaseDC (dpyinfo
->root_window
, hdc
);
7480 DeleteObject(thisinfo
.hfont
);
7483 found_size
= XINT (XCDR (tem
));
7484 if (found_size
== size
)
7486 newlist
= Fcons (XCAR (tem
), newlist
);
7488 if (n_fonts
>= maxnames
)
7491 /* keep track of the closest matching size in case
7492 no exact match is found. */
7493 else if (found_size
> 0)
7495 if (NILP (second_best
))
7498 else if (found_size
< size
)
7500 if (XINT (XCDR (second_best
)) > size
7501 || XINT (XCDR (second_best
)) < found_size
)
7506 if (XINT (XCDR (second_best
)) > size
7507 && XINT (XCDR (second_best
)) >
7514 if (!NILP (newlist
))
7516 else if (!NILP (second_best
))
7518 newlist
= Fcons (XCAR (second_best
), Qnil
);
7523 /* Include any bdf fonts. */
7524 if (n_fonts
< maxnames
)
7526 Lisp_Object combined
[2];
7527 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
7528 combined
[1] = newlist
;
7529 newlist
= Fnconc(2, combined
);
7536 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
7538 w32_get_font_info (f
, font_idx
)
7542 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
7547 w32_query_font (struct frame
*f
, char *fontname
)
7550 struct font_info
*pfi
;
7552 pfi
= FRAME_W32_FONT_TABLE (f
);
7554 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
7556 if (strcmp(pfi
->name
, fontname
) == 0) return pfi
;
7562 /* Find a CCL program for a font specified by FONTP, and set the member
7563 `encoder' of the structure. */
7566 w32_find_ccl_program (fontp
)
7567 struct font_info
*fontp
;
7569 Lisp_Object list
, elt
;
7571 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
7575 && STRINGP (XCAR (elt
))
7576 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
7582 struct ccl_program
*ccl
7583 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
7585 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
7588 fontp
->font_encoder
= ccl
;
7593 /* Find BDF files in a specified directory. (use GCPRO when calling,
7594 as this calls lisp to get a directory listing). */
7596 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
7598 Lisp_Object filelist
, list
= Qnil
;
7601 if (!STRINGP(directory
))
7604 filelist
= Fdirectory_files (directory
, Qt
,
7605 build_string (".*\\.[bB][dD][fF]"), Qt
);
7607 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
7609 Lisp_Object filename
= XCAR (filelist
);
7610 if (w32_BDF_to_x_font (XSTRING (filename
)->data
, fontname
, 100))
7611 store_in_alist (&list
, build_string (fontname
), filename
);
7616 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
7618 doc
: /* Return a list of BDF fonts in DIR.
7619 The list is suitable for appending to w32-bdf-filename-alist. Fonts
7620 which do not contain an xlfd description will not be included in the
7621 list. DIR may be a list of directories. */)
7623 Lisp_Object directory
;
7625 Lisp_Object list
= Qnil
;
7626 struct gcpro gcpro1
, gcpro2
;
7628 if (!CONSP (directory
))
7629 return w32_find_bdf_fonts_in_dir (directory
);
7631 for ( ; CONSP (directory
); directory
= XCDR (directory
))
7633 Lisp_Object pair
[2];
7636 GCPRO2 (directory
, list
);
7637 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
7638 list
= Fnconc( 2, pair
);
7645 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
7646 doc
: /* Internal function called by `color-defined-p', which see. */)
7648 Lisp_Object color
, frame
;
7651 FRAME_PTR f
= check_x_frame (frame
);
7653 CHECK_STRING (color
);
7655 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7661 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
7662 doc
: /* Internal function called by `color-values', which see. */)
7664 Lisp_Object color
, frame
;
7667 FRAME_PTR f
= check_x_frame (frame
);
7669 CHECK_STRING (color
);
7671 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7675 rgb
[0] = make_number ((GetRValue (foo
.pixel
) << 8)
7676 | GetRValue (foo
.pixel
));
7677 rgb
[1] = make_number ((GetGValue (foo
.pixel
) << 8)
7678 | GetGValue (foo
.pixel
));
7679 rgb
[2] = make_number ((GetBValue (foo
.pixel
) << 8)
7680 | GetBValue (foo
.pixel
));
7681 return Flist (3, rgb
);
7687 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
7688 doc
: /* Internal function called by `display-color-p', which see. */)
7690 Lisp_Object display
;
7692 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7694 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
7700 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
7701 Sx_display_grayscale_p
, 0, 1, 0,
7702 doc
: /* Return t if the X display supports shades of gray.
7703 Note that color displays do support shades of gray.
7704 The optional argument DISPLAY specifies which display to ask about.
7705 DISPLAY should be either a frame or a display name (a string).
7706 If omitted or nil, that stands for the selected frame's display. */)
7708 Lisp_Object display
;
7710 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7712 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
7718 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
7719 Sx_display_pixel_width
, 0, 1, 0,
7720 doc
: /* Returns the width in pixels of DISPLAY.
7721 The optional argument DISPLAY specifies which display to ask about.
7722 DISPLAY should be either a frame or a display name (a string).
7723 If omitted or nil, that stands for the selected frame's display. */)
7725 Lisp_Object display
;
7727 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7729 return make_number (dpyinfo
->width
);
7732 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
7733 Sx_display_pixel_height
, 0, 1, 0,
7734 doc
: /* Returns the height in pixels of DISPLAY.
7735 The optional argument DISPLAY specifies which display to ask about.
7736 DISPLAY should be either a frame or a display name (a string).
7737 If omitted or nil, that stands for the selected frame's display. */)
7739 Lisp_Object display
;
7741 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7743 return make_number (dpyinfo
->height
);
7746 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
7748 doc
: /* Returns the number of bitplanes of DISPLAY.
7749 The optional argument DISPLAY specifies which display to ask about.
7750 DISPLAY should be either a frame or a display name (a string).
7751 If omitted or nil, that stands for the selected frame's display. */)
7753 Lisp_Object display
;
7755 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7757 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
7760 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
7762 doc
: /* Returns the number of color cells of DISPLAY.
7763 The optional argument DISPLAY specifies which display to ask about.
7764 DISPLAY should be either a frame or a display name (a string).
7765 If omitted or nil, that stands for the selected frame's display. */)
7767 Lisp_Object display
;
7769 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7773 hdc
= GetDC (dpyinfo
->root_window
);
7774 if (dpyinfo
->has_palette
)
7775 cap
= GetDeviceCaps (hdc
,SIZEPALETTE
);
7777 cap
= GetDeviceCaps (hdc
,NUMCOLORS
);
7779 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
7780 and because probably is more meaningful on Windows anyway */
7782 cap
= 1 << min(dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
7784 ReleaseDC (dpyinfo
->root_window
, hdc
);
7786 return make_number (cap
);
7789 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
7790 Sx_server_max_request_size
,
7792 doc
: /* Returns the maximum request size of the server of DISPLAY.
7793 The optional argument DISPLAY specifies which display to ask about.
7794 DISPLAY should be either a frame or a display name (a string).
7795 If omitted or nil, that stands for the selected frame's display. */)
7797 Lisp_Object display
;
7799 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7801 return make_number (1);
7804 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
7805 doc
: /* Returns the vendor ID string of the W32 system (Microsoft).
7806 The optional argument DISPLAY specifies which display to ask about.
7807 DISPLAY should be either a frame or a display name (a string).
7808 If omitted or nil, that stands for the selected frame's display. */)
7810 Lisp_Object display
;
7812 return build_string ("Microsoft Corp.");
7815 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
7816 doc
: /* Returns the version numbers of the server of DISPLAY.
7817 The value is a list of three integers: the major and minor
7818 version numbers, and the vendor-specific release
7819 number. See also the function `x-server-vendor'.
7821 The optional argument DISPLAY specifies which display to ask about.
7822 DISPLAY should be either a frame or a display name (a string).
7823 If omitted or nil, that stands for the selected frame's display. */)
7825 Lisp_Object display
;
7827 return Fcons (make_number (w32_major_version
),
7828 Fcons (make_number (w32_minor_version
),
7829 Fcons (make_number (w32_build_number
), Qnil
)));
7832 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
7833 doc
: /* Returns the number of screens on the server of DISPLAY.
7834 The optional argument DISPLAY specifies which display to ask about.
7835 DISPLAY should be either a frame or a display name (a string).
7836 If omitted or nil, that stands for the selected frame's display. */)
7838 Lisp_Object display
;
7840 return make_number (1);
7843 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
7844 Sx_display_mm_height
, 0, 1, 0,
7845 doc
: /* Returns the height in millimeters of DISPLAY.
7846 The optional argument DISPLAY specifies which display to ask about.
7847 DISPLAY should be either a frame or a display name (a string).
7848 If omitted or nil, that stands for the selected frame's display. */)
7850 Lisp_Object display
;
7852 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7856 hdc
= GetDC (dpyinfo
->root_window
);
7858 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
7860 ReleaseDC (dpyinfo
->root_window
, hdc
);
7862 return make_number (cap
);
7865 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
7866 doc
: /* Returns the width in millimeters of DISPLAY.
7867 The optional argument DISPLAY specifies which display to ask about.
7868 DISPLAY should be either a frame or a display name (a string).
7869 If omitted or nil, that stands for the selected frame's display. */)
7871 Lisp_Object display
;
7873 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7878 hdc
= GetDC (dpyinfo
->root_window
);
7880 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
7882 ReleaseDC (dpyinfo
->root_window
, hdc
);
7884 return make_number (cap
);
7887 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
7888 Sx_display_backing_store
, 0, 1, 0,
7889 doc
: /* Returns an indication of whether DISPLAY does backing store.
7890 The value may be `always', `when-mapped', or `not-useful'.
7891 The optional argument DISPLAY specifies which display to ask about.
7892 DISPLAY should be either a frame or a display name (a string).
7893 If omitted or nil, that stands for the selected frame's display. */)
7895 Lisp_Object display
;
7897 return intern ("not-useful");
7900 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
7901 Sx_display_visual_class
, 0, 1, 0,
7902 doc
: /* Returns the visual class of DISPLAY.
7903 The value is one of the symbols `static-gray', `gray-scale',
7904 `static-color', `pseudo-color', `true-color', or `direct-color'.
7906 The optional argument DISPLAY specifies which display to ask about.
7907 DISPLAY should be either a frame or a display name (a string).
7908 If omitted or nil, that stands for the selected frame's display. */)
7910 Lisp_Object display
;
7912 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7913 Lisp_Object result
= Qnil
;
7915 if (dpyinfo
->has_palette
)
7916 result
= intern ("pseudo-color");
7917 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
7918 result
= intern ("static-grey");
7919 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
7920 result
= intern ("static-color");
7921 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
7922 result
= intern ("true-color");
7927 DEFUN ("x-display-save-under", Fx_display_save_under
,
7928 Sx_display_save_under
, 0, 1, 0,
7929 doc
: /* Returns t if DISPLAY supports the save-under feature.
7930 The optional argument DISPLAY specifies which display to ask about.
7931 DISPLAY should be either a frame or a display name (a string).
7932 If omitted or nil, that stands for the selected frame's display. */)
7934 Lisp_Object display
;
7941 register struct frame
*f
;
7943 return PIXEL_WIDTH (f
);
7948 register struct frame
*f
;
7950 return PIXEL_HEIGHT (f
);
7955 register struct frame
*f
;
7957 return FONT_WIDTH (f
->output_data
.w32
->font
);
7962 register struct frame
*f
;
7964 return f
->output_data
.w32
->line_height
;
7969 register struct frame
*f
;
7971 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
7974 /* Return the display structure for the display named NAME.
7975 Open a new connection if necessary. */
7977 struct w32_display_info
*
7978 x_display_info_for_name (name
)
7982 struct w32_display_info
*dpyinfo
;
7984 CHECK_STRING (name
);
7986 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
7988 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
7991 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
7996 /* Use this general default value to start with. */
7997 Vx_resource_name
= Vinvocation_name
;
7999 validate_x_resource_name ();
8001 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
8002 (char *) XSTRING (Vx_resource_name
)->data
);
8005 error ("Cannot connect to server %s", XSTRING (name
)->data
);
8008 XSETFASTINT (Vwindow_system_version
, 3);
8013 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
8014 1, 3, 0, doc
: /* Open a connection to a server.
8015 DISPLAY is the name of the display to connect to.
8016 Optional second arg XRM-STRING is a string of resources in xrdb format.
8017 If the optional third arg MUST-SUCCEED is non-nil,
8018 terminate Emacs if we can't open the connection. */)
8019 (display
, xrm_string
, must_succeed
)
8020 Lisp_Object display
, xrm_string
, must_succeed
;
8022 unsigned char *xrm_option
;
8023 struct w32_display_info
*dpyinfo
;
8025 /* If initialization has already been done, return now to avoid
8026 overwriting critical parts of one_w32_display_info. */
8030 CHECK_STRING (display
);
8031 if (! NILP (xrm_string
))
8032 CHECK_STRING (xrm_string
);
8034 if (! EQ (Vwindow_system
, intern ("w32")))
8035 error ("Not using Microsoft Windows");
8037 /* Allow color mapping to be defined externally; first look in user's
8038 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
8040 Lisp_Object color_file
;
8041 struct gcpro gcpro1
;
8043 color_file
= build_string("~/rgb.txt");
8045 GCPRO1 (color_file
);
8047 if (NILP (Ffile_readable_p (color_file
)))
8049 Fexpand_file_name (build_string ("rgb.txt"),
8050 Fsymbol_value (intern ("data-directory")));
8052 Vw32_color_map
= Fw32_load_color_file (color_file
);
8056 if (NILP (Vw32_color_map
))
8057 Vw32_color_map
= Fw32_default_color_map ();
8059 if (! NILP (xrm_string
))
8060 xrm_option
= (unsigned char *) XSTRING (xrm_string
)->data
;
8062 xrm_option
= (unsigned char *) 0;
8064 /* Use this general default value to start with. */
8065 /* First remove .exe suffix from invocation-name - it looks ugly. */
8067 char basename
[ MAX_PATH
], *str
;
8069 strcpy (basename
, XSTRING (Vinvocation_name
)->data
);
8070 str
= strrchr (basename
, '.');
8072 Vinvocation_name
= build_string (basename
);
8074 Vx_resource_name
= Vinvocation_name
;
8076 validate_x_resource_name ();
8078 /* This is what opens the connection and sets x_current_display.
8079 This also initializes many symbols, such as those used for input. */
8080 dpyinfo
= w32_term_init (display
, xrm_option
,
8081 (char *) XSTRING (Vx_resource_name
)->data
);
8085 if (!NILP (must_succeed
))
8086 fatal ("Cannot connect to server %s.\n",
8087 XSTRING (display
)->data
);
8089 error ("Cannot connect to server %s", XSTRING (display
)->data
);
8094 XSETFASTINT (Vwindow_system_version
, 3);
8098 DEFUN ("x-close-connection", Fx_close_connection
,
8099 Sx_close_connection
, 1, 1, 0,
8100 doc
: /* Close the connection to DISPLAY's server.
8101 For DISPLAY, specify either a frame or a display name (a string).
8102 If DISPLAY is nil, that stands for the selected frame's display. */)
8104 Lisp_Object display
;
8106 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
8109 if (dpyinfo
->reference_count
> 0)
8110 error ("Display still has frames on it");
8113 /* Free the fonts in the font table. */
8114 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
8115 if (dpyinfo
->font_table
[i
].name
)
8117 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
8118 xfree (dpyinfo
->font_table
[i
].full_name
);
8119 xfree (dpyinfo
->font_table
[i
].name
);
8120 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
8122 x_destroy_all_bitmaps (dpyinfo
);
8124 x_delete_display (dpyinfo
);
8130 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
8131 doc
: /* Return the list of display names that Emacs has connections to. */)
8134 Lisp_Object tail
, result
;
8137 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
8138 result
= Fcons (XCAR (XCAR (tail
)), result
);
8143 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
8144 doc
: /* This is a noop on W32 systems. */)
8146 Lisp_Object display
, on
;
8152 /***********************************************************************
8154 ***********************************************************************/
8156 /* Value is the number of elements of vector VECTOR. */
8158 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
8160 /* List of supported image types. Use define_image_type to add new
8161 types. Use lookup_image_type to find a type for a given symbol. */
8163 static struct image_type
*image_types
;
8165 /* The symbol `image' which is the car of the lists used to represent
8168 extern Lisp_Object Qimage
;
8170 /* The symbol `xbm' which is used as the type symbol for XBM images. */
8176 extern Lisp_Object QCwidth
, QCheight
, QCforeground
, QCbackground
, QCfile
;
8177 extern Lisp_Object QCdata
, QCtype
;
8178 Lisp_Object QCascent
, QCmargin
, QCrelief
;
8179 Lisp_Object QCconversion
, QCcolor_symbols
, QCheuristic_mask
;
8180 Lisp_Object QCindex
, QCmatrix
, QCcolor_adjustment
, QCmask
;
8182 /* Other symbols. */
8184 Lisp_Object Qlaplace
, Qemboss
, Qedge_detection
, Qheuristic
;
8186 /* Time in seconds after which images should be removed from the cache
8187 if not displayed. */
8189 Lisp_Object Vimage_cache_eviction_delay
;
8191 /* Function prototypes. */
8193 static void define_image_type
P_ ((struct image_type
*type
));
8194 static struct image_type
*lookup_image_type
P_ ((Lisp_Object symbol
));
8195 static void image_error
P_ ((char *format
, Lisp_Object
, Lisp_Object
));
8196 static void x_laplace
P_ ((struct frame
*, struct image
*));
8197 static void x_emboss
P_ ((struct frame
*, struct image
*));
8198 static int x_build_heuristic_mask
P_ ((struct frame
*, struct image
*,
8202 /* Define a new image type from TYPE. This adds a copy of TYPE to
8203 image_types and adds the symbol *TYPE->type to Vimage_types. */
8206 define_image_type (type
)
8207 struct image_type
*type
;
8209 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
8210 The initialized data segment is read-only. */
8211 struct image_type
*p
= (struct image_type
*) xmalloc (sizeof *p
);
8212 bcopy (type
, p
, sizeof *p
);
8213 p
->next
= image_types
;
8215 Vimage_types
= Fcons (*p
->type
, Vimage_types
);
8219 /* Look up image type SYMBOL, and return a pointer to its image_type
8220 structure. Value is null if SYMBOL is not a known image type. */
8222 static INLINE
struct image_type
*
8223 lookup_image_type (symbol
)
8226 struct image_type
*type
;
8228 for (type
= image_types
; type
; type
= type
->next
)
8229 if (EQ (symbol
, *type
->type
))
8236 /* Value is non-zero if OBJECT is a valid Lisp image specification. A
8237 valid image specification is a list whose car is the symbol
8238 `image', and whose rest is a property list. The property list must
8239 contain a value for key `:type'. That value must be the name of a
8240 supported image type. The rest of the property list depends on the
8244 valid_image_p (object
)
8249 if (CONSP (object
) && EQ (XCAR (object
), Qimage
))
8253 for (tem
= XCDR (object
); CONSP (tem
); tem
= XCDR (tem
))
8254 if (EQ (XCAR (tem
), QCtype
))
8257 if (CONSP (tem
) && SYMBOLP (XCAR (tem
)))
8259 struct image_type
*type
;
8260 type
= lookup_image_type (XCAR (tem
));
8262 valid_p
= type
->valid_p (object
);
8273 /* Log error message with format string FORMAT and argument ARG.
8274 Signaling an error, e.g. when an image cannot be loaded, is not a
8275 good idea because this would interrupt redisplay, and the error
8276 message display would lead to another redisplay. This function
8277 therefore simply displays a message. */
8280 image_error (format
, arg1
, arg2
)
8282 Lisp_Object arg1
, arg2
;
8284 add_to_log (format
, arg1
, arg2
);
8289 /***********************************************************************
8290 Image specifications
8291 ***********************************************************************/
8293 enum image_value_type
8295 IMAGE_DONT_CHECK_VALUE_TYPE
,
8297 IMAGE_STRING_OR_NIL_VALUE
,
8299 IMAGE_POSITIVE_INTEGER_VALUE
,
8300 IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
,
8301 IMAGE_NON_NEGATIVE_INTEGER_VALUE
,
8303 IMAGE_INTEGER_VALUE
,
8304 IMAGE_FUNCTION_VALUE
,
8309 /* Structure used when parsing image specifications. */
8311 struct image_keyword
8313 /* Name of keyword. */
8316 /* The type of value allowed. */
8317 enum image_value_type type
;
8319 /* Non-zero means key must be present. */
8322 /* Used to recognize duplicate keywords in a property list. */
8325 /* The value that was found. */
8330 static int parse_image_spec
P_ ((Lisp_Object
, struct image_keyword
*,
8332 static Lisp_Object image_spec_value
P_ ((Lisp_Object
, Lisp_Object
, int *));
8335 /* Parse image spec SPEC according to KEYWORDS. A valid image spec
8336 has the format (image KEYWORD VALUE ...). One of the keyword/
8337 value pairs must be `:type TYPE'. KEYWORDS is a vector of
8338 image_keywords structures of size NKEYWORDS describing other
8339 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */
8342 parse_image_spec (spec
, keywords
, nkeywords
, type
)
8344 struct image_keyword
*keywords
;
8351 if (!CONSP (spec
) || !EQ (XCAR (spec
), Qimage
))
8354 plist
= XCDR (spec
);
8355 while (CONSP (plist
))
8357 Lisp_Object key
, value
;
8359 /* First element of a pair must be a symbol. */
8361 plist
= XCDR (plist
);
8365 /* There must follow a value. */
8368 value
= XCAR (plist
);
8369 plist
= XCDR (plist
);
8371 /* Find key in KEYWORDS. Error if not found. */
8372 for (i
= 0; i
< nkeywords
; ++i
)
8373 if (strcmp (keywords
[i
].name
, XSYMBOL (key
)->name
->data
) == 0)
8379 /* Record that we recognized the keyword. If a keywords
8380 was found more than once, it's an error. */
8381 keywords
[i
].value
= value
;
8382 ++keywords
[i
].count
;
8384 if (keywords
[i
].count
> 1)
8387 /* Check type of value against allowed type. */
8388 switch (keywords
[i
].type
)
8390 case IMAGE_STRING_VALUE
:
8391 if (!STRINGP (value
))
8395 case IMAGE_STRING_OR_NIL_VALUE
:
8396 if (!STRINGP (value
) && !NILP (value
))
8400 case IMAGE_SYMBOL_VALUE
:
8401 if (!SYMBOLP (value
))
8405 case IMAGE_POSITIVE_INTEGER_VALUE
:
8406 if (!INTEGERP (value
) || XINT (value
) <= 0)
8410 case IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
:
8411 if (INTEGERP (value
) && XINT (value
) >= 0)
8414 && INTEGERP (XCAR (value
)) && INTEGERP (XCDR (value
))
8415 && XINT (XCAR (value
)) >= 0 && XINT (XCDR (value
)) >= 0)
8419 case IMAGE_ASCENT_VALUE
:
8420 if (SYMBOLP (value
) && EQ (value
, Qcenter
))
8422 else if (INTEGERP (value
)
8423 && XINT (value
) >= 0
8424 && XINT (value
) <= 100)
8428 case IMAGE_NON_NEGATIVE_INTEGER_VALUE
:
8429 if (!INTEGERP (value
) || XINT (value
) < 0)
8433 case IMAGE_DONT_CHECK_VALUE_TYPE
:
8436 case IMAGE_FUNCTION_VALUE
:
8437 value
= indirect_function (value
);
8439 || COMPILEDP (value
)
8440 || (CONSP (value
) && EQ (XCAR (value
), Qlambda
)))
8444 case IMAGE_NUMBER_VALUE
:
8445 if (!INTEGERP (value
) && !FLOATP (value
))
8449 case IMAGE_INTEGER_VALUE
:
8450 if (!INTEGERP (value
))
8454 case IMAGE_BOOL_VALUE
:
8455 if (!NILP (value
) && !EQ (value
, Qt
))
8464 if (EQ (key
, QCtype
) && !EQ (type
, value
))
8468 /* Check that all mandatory fields are present. */
8469 for (i
= 0; i
< nkeywords
; ++i
)
8470 if (keywords
[i
].mandatory_p
&& keywords
[i
].count
== 0)
8473 return NILP (plist
);
8477 /* Return the value of KEY in image specification SPEC. Value is nil
8478 if KEY is not present in SPEC. if FOUND is not null, set *FOUND
8479 to 1 if KEY was found in SPEC, set it to 0 otherwise. */
8482 image_spec_value (spec
, key
, found
)
8483 Lisp_Object spec
, key
;
8488 xassert (valid_image_p (spec
));
8490 for (tail
= XCDR (spec
);
8491 CONSP (tail
) && CONSP (XCDR (tail
));
8492 tail
= XCDR (XCDR (tail
)))
8494 if (EQ (XCAR (tail
), key
))
8498 return XCAR (XCDR (tail
));
8508 DEFUN ("image-size", Fimage_size
, Simage_size
, 1, 3, 0,
8509 doc
: /* Return the size of image SPEC as pair (WIDTH . HEIGHT).
8510 PIXELS non-nil means return the size in pixels, otherwise return the
8511 size in canonical character units.
8512 FRAME is the frame on which the image will be displayed. FRAME nil
8513 or omitted means use the selected frame. */)
8514 (spec
, pixels
, frame
)
8515 Lisp_Object spec
, pixels
, frame
;
8520 if (valid_image_p (spec
))
8522 struct frame
*f
= check_x_frame (frame
);
8523 int id
= lookup_image (f
, spec
);
8524 struct image
*img
= IMAGE_FROM_ID (f
, id
);
8525 int width
= img
->width
+ 2 * img
->hmargin
;
8526 int height
= img
->height
+ 2 * img
->vmargin
;
8529 size
= Fcons (make_float ((double) width
/ CANON_X_UNIT (f
)),
8530 make_float ((double) height
/ CANON_Y_UNIT (f
)));
8532 size
= Fcons (make_number (width
), make_number (height
));
8535 error ("Invalid image specification");
8541 DEFUN ("image-mask-p", Fimage_mask_p
, Simage_mask_p
, 1, 2, 0,
8542 doc
: /* Return t if image SPEC has a mask bitmap.
8543 FRAME is the frame on which the image will be displayed. FRAME nil
8544 or omitted means use the selected frame. */)
8546 Lisp_Object spec
, frame
;
8551 if (valid_image_p (spec
))
8553 struct frame
*f
= check_x_frame (frame
);
8554 int id
= lookup_image (f
, spec
);
8555 struct image
*img
= IMAGE_FROM_ID (f
, id
);
8560 error ("Invalid image specification");
8566 /***********************************************************************
8567 Image type independent image structures
8568 ***********************************************************************/
8570 static struct image
*make_image
P_ ((Lisp_Object spec
, unsigned hash
));
8571 static void free_image
P_ ((struct frame
*f
, struct image
*img
));
8574 /* Allocate and return a new image structure for image specification
8575 SPEC. SPEC has a hash value of HASH. */
8577 static struct image
*
8578 make_image (spec
, hash
)
8582 struct image
*img
= (struct image
*) xmalloc (sizeof *img
);
8584 xassert (valid_image_p (spec
));
8585 bzero (img
, sizeof *img
);
8586 img
->type
= lookup_image_type (image_spec_value (spec
, QCtype
, NULL
));
8587 xassert (img
->type
!= NULL
);
8589 img
->data
.lisp_val
= Qnil
;
8590 img
->ascent
= DEFAULT_IMAGE_ASCENT
;
8596 /* Free image IMG which was used on frame F, including its resources. */
8605 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8607 /* Remove IMG from the hash table of its cache. */
8609 img
->prev
->next
= img
->next
;
8611 c
->buckets
[img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
] = img
->next
;
8614 img
->next
->prev
= img
->prev
;
8616 c
->images
[img
->id
] = NULL
;
8618 /* Free resources, then free IMG. */
8619 img
->type
->free (f
, img
);
8625 /* Prepare image IMG for display on frame F. Must be called before
8626 drawing an image. */
8629 prepare_image_for_display (f
, img
)
8635 /* We're about to display IMG, so set its timestamp to `now'. */
8637 img
->timestamp
= EMACS_SECS (t
);
8639 /* If IMG doesn't have a pixmap yet, load it now, using the image
8640 type dependent loader function. */
8641 if (img
->pixmap
== 0 && !img
->load_failed_p
)
8642 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
8646 /* Value is the number of pixels for the ascent of image IMG when
8647 drawn in face FACE. */
8650 image_ascent (img
, face
)
8654 int height
= img
->height
+ img
->vmargin
;
8657 if (img
->ascent
== CENTERED_IMAGE_ASCENT
)
8660 ascent
= height
/ 2 - (FONT_DESCENT(face
->font
)
8661 - FONT_BASE(face
->font
)) / 2;
8663 ascent
= height
/ 2;
8666 ascent
= (int) (height
* img
->ascent
/ 100.0);
8673 /* Image background colors. */
8675 /* Find the "best" corner color of a bitmap. XIMG is assumed to a device
8676 context with the bitmap selected. */
8678 four_corners_best (ximg
, width
, height
)
8680 unsigned long width
, height
;
8682 COLORREF corners
[4], best
;
8685 /* Get the colors at the corners of ximg. */
8686 corners
[0] = GetPixel (ximg
, 0, 0);
8687 corners
[1] = GetPixel (ximg
, width
- 1, 0);
8688 corners
[2] = GetPixel (ximg
, width
- 1, height
- 1);
8689 corners
[3] = GetPixel (ximg
, 0, height
- 1);
8691 /* Choose the most frequently found color as background. */
8692 for (i
= best_count
= 0; i
< 4; ++i
)
8696 for (j
= n
= 0; j
< 4; ++j
)
8697 if (corners
[i
] == corners
[j
])
8701 best
= corners
[i
], best_count
= n
;
8707 /* Return the `background' field of IMG. If IMG doesn't have one yet,
8708 it is guessed heuristically. If non-zero, XIMG is an existing XImage
8709 object to use for the heuristic. */
8712 image_background (img
, f
, ximg
)
8717 if (! img
->background_valid
)
8718 /* IMG doesn't have a background yet, try to guess a reasonable value. */
8720 #if 0 /* TODO: Image support. */
8721 int free_ximg
= !ximg
;
8724 ximg
= XGetImage (FRAME_X_DISPLAY (f
), img
->pixmap
,
8725 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
8727 img
->background
= four_corners_best (ximg
, img
->width
, img
->height
);
8730 XDestroyImage (ximg
);
8732 img
->background_valid
= 1;
8736 return img
->background
;
8739 /* Return the `background_transparent' field of IMG. If IMG doesn't
8740 have one yet, it is guessed heuristically. If non-zero, MASK is an
8741 existing XImage object to use for the heuristic. */
8744 image_background_transparent (img
, f
, mask
)
8749 if (! img
->background_transparent_valid
)
8750 /* IMG doesn't have a background yet, try to guess a reasonable value. */
8752 #if 0 /* TODO: Image support. */
8755 int free_mask
= !mask
;
8758 mask
= XGetImage (FRAME_X_DISPLAY (f
), img
->mask
,
8759 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
8761 img
->background_transparent
8762 = !four_corners_best (mask
, img
->width
, img
->height
);
8765 XDestroyImage (mask
);
8769 img
->background_transparent
= 0;
8771 img
->background_transparent_valid
= 1;
8774 return img
->background_transparent
;
8778 /***********************************************************************
8779 Helper functions for X image types
8780 ***********************************************************************/
8782 static void x_clear_image_1
P_ ((struct frame
*, struct image
*, int,
8784 static void x_clear_image
P_ ((struct frame
*f
, struct image
*img
));
8785 static unsigned long x_alloc_image_color
P_ ((struct frame
*f
,
8787 Lisp_Object color_name
,
8788 unsigned long dflt
));
8791 /* Clear X resources of image IMG on frame F. PIXMAP_P non-zero means
8792 free the pixmap if any. MASK_P non-zero means clear the mask
8793 pixmap if any. COLORS_P non-zero means free colors allocated for
8794 the image, if any. */
8797 x_clear_image_1 (f
, img
, pixmap_p
, mask_p
, colors_p
)
8800 int pixmap_p
, mask_p
, colors_p
;
8802 if (pixmap_p
&& img
->pixmap
)
8804 DeleteObject (img
->pixmap
);
8806 img
->background_valid
= 0;
8809 if (mask_p
&& img
->mask
)
8811 DeleteObject (img
->mask
);
8813 img
->background_transparent_valid
= 0;
8816 if (colors_p
&& img
->ncolors
)
8818 #if 0 /* TODO: color table support. */
8819 x_free_colors (f
, img
->colors
, img
->ncolors
);
8821 xfree (img
->colors
);
8827 /* Free X resources of image IMG which is used on frame F. */
8830 x_clear_image (f
, img
)
8837 DeleteObject (img
->pixmap
);
8844 #if 0 /* TODO: color table support */
8846 int class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
8848 /* If display has an immutable color map, freeing colors is not
8849 necessary and some servers don't allow it. So don't do it. */
8850 if (class != StaticColor
8851 && class != StaticGray
8852 && class != TrueColor
)
8856 cmap
= DefaultColormapOfScreen (FRAME_W32_DISPLAY_INFO (f
)->screen
);
8857 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
, img
->colors
,
8863 xfree (img
->colors
);
8870 /* Allocate color COLOR_NAME for image IMG on frame F. If color
8871 cannot be allocated, use DFLT. Add a newly allocated color to
8872 IMG->colors, so that it can be freed again. Value is the pixel
8875 static unsigned long
8876 x_alloc_image_color (f
, img
, color_name
, dflt
)
8879 Lisp_Object color_name
;
8883 unsigned long result
;
8885 xassert (STRINGP (color_name
));
8887 if (w32_defined_color (f
, XSTRING (color_name
)->data
, &color
, 1))
8889 /* This isn't called frequently so we get away with simply
8890 reallocating the color vector to the needed size, here. */
8893 (unsigned long *) xrealloc (img
->colors
,
8894 img
->ncolors
* sizeof *img
->colors
);
8895 img
->colors
[img
->ncolors
- 1] = color
.pixel
;
8896 result
= color
.pixel
;
8905 /***********************************************************************
8907 ***********************************************************************/
8909 static void cache_image
P_ ((struct frame
*f
, struct image
*img
));
8910 static void postprocess_image
P_ ((struct frame
*, struct image
*));
8913 /* Return a new, initialized image cache that is allocated from the
8914 heap. Call free_image_cache to free an image cache. */
8916 struct image_cache
*
8919 struct image_cache
*c
= (struct image_cache
*) xmalloc (sizeof *c
);
8922 bzero (c
, sizeof *c
);
8924 c
->images
= (struct image
**) xmalloc (c
->size
* sizeof *c
->images
);
8925 size
= IMAGE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
8926 c
->buckets
= (struct image
**) xmalloc (size
);
8927 bzero (c
->buckets
, size
);
8932 /* Free image cache of frame F. Be aware that X frames share images
8936 free_image_cache (f
)
8939 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8944 /* Cache should not be referenced by any frame when freed. */
8945 xassert (c
->refcount
== 0);
8947 for (i
= 0; i
< c
->used
; ++i
)
8948 free_image (f
, c
->images
[i
]);
8952 FRAME_X_IMAGE_CACHE (f
) = NULL
;
8957 /* Clear image cache of frame F. FORCE_P non-zero means free all
8958 images. FORCE_P zero means clear only images that haven't been
8959 displayed for some time. Should be called from time to time to
8960 reduce the number of loaded images. If image-eviction-seconds is
8961 non-nil, this frees images in the cache which weren't displayed for
8962 at least that many seconds. */
8965 clear_image_cache (f
, force_p
)
8969 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8971 if (c
&& INTEGERP (Vimage_cache_eviction_delay
))
8978 old
= EMACS_SECS (t
) - XFASTINT (Vimage_cache_eviction_delay
);
8980 /* Block input so that we won't be interrupted by a SIGIO
8981 while being in an inconsistent state. */
8984 for (i
= nfreed
= 0; i
< c
->used
; ++i
)
8986 struct image
*img
= c
->images
[i
];
8988 && (force_p
|| (img
->timestamp
< old
)))
8990 free_image (f
, img
);
8995 /* We may be clearing the image cache because, for example,
8996 Emacs was iconified for a longer period of time. In that
8997 case, current matrices may still contain references to
8998 images freed above. So, clear these matrices. */
9001 Lisp_Object tail
, frame
;
9003 FOR_EACH_FRAME (tail
, frame
)
9005 struct frame
*f
= XFRAME (frame
);
9007 && FRAME_X_IMAGE_CACHE (f
) == c
)
9008 clear_current_matrices (f
);
9011 ++windows_or_buffers_changed
;
9019 DEFUN ("clear-image-cache", Fclear_image_cache
, Sclear_image_cache
,
9021 doc
: /* Clear the image cache of FRAME.
9022 FRAME nil or omitted means use the selected frame.
9023 FRAME t means clear the image caches of all frames. */)
9031 FOR_EACH_FRAME (tail
, frame
)
9032 if (FRAME_W32_P (XFRAME (frame
)))
9033 clear_image_cache (XFRAME (frame
), 1);
9036 clear_image_cache (check_x_frame (frame
), 1);
9042 /* Compute masks and transform image IMG on frame F, as specified
9043 by the image's specification, */
9046 postprocess_image (f
, img
)
9050 #if 0 /* TODO: image support. */
9051 /* Manipulation of the image's mask. */
9054 Lisp_Object conversion
, spec
;
9059 /* `:heuristic-mask t'
9061 means build a mask heuristically.
9062 `:heuristic-mask (R G B)'
9063 `:mask (heuristic (R G B))'
9064 means build a mask from color (R G B) in the
9067 means remove a mask, if any. */
9069 mask
= image_spec_value (spec
, QCheuristic_mask
, NULL
);
9071 x_build_heuristic_mask (f
, img
, mask
);
9076 mask
= image_spec_value (spec
, QCmask
, &found_p
);
9078 if (EQ (mask
, Qheuristic
))
9079 x_build_heuristic_mask (f
, img
, Qt
);
9080 else if (CONSP (mask
)
9081 && EQ (XCAR (mask
), Qheuristic
))
9083 if (CONSP (XCDR (mask
)))
9084 x_build_heuristic_mask (f
, img
, XCAR (XCDR (mask
)));
9086 x_build_heuristic_mask (f
, img
, XCDR (mask
));
9088 else if (NILP (mask
) && found_p
&& img
->mask
)
9090 DeleteObject (img
->mask
);
9096 /* Should we apply an image transformation algorithm? */
9097 conversion
= image_spec_value (spec
, QCconversion
, NULL
);
9098 if (EQ (conversion
, Qdisabled
))
9099 x_disable_image (f
, img
);
9100 else if (EQ (conversion
, Qlaplace
))
9102 else if (EQ (conversion
, Qemboss
))
9104 else if (CONSP (conversion
)
9105 && EQ (XCAR (conversion
), Qedge_detection
))
9108 tem
= XCDR (conversion
);
9110 x_edge_detection (f
, img
,
9111 Fplist_get (tem
, QCmatrix
),
9112 Fplist_get (tem
, QCcolor_adjustment
));
9119 /* Return the id of image with Lisp specification SPEC on frame F.
9120 SPEC must be a valid Lisp image specification (see valid_image_p). */
9123 lookup_image (f
, spec
)
9127 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
9131 struct gcpro gcpro1
;
9134 /* F must be a window-system frame, and SPEC must be a valid image
9136 xassert (FRAME_WINDOW_P (f
));
9137 xassert (valid_image_p (spec
));
9141 /* Look up SPEC in the hash table of the image cache. */
9142 hash
= sxhash (spec
, 0);
9143 i
= hash
% IMAGE_CACHE_BUCKETS_SIZE
;
9145 for (img
= c
->buckets
[i
]; img
; img
= img
->next
)
9146 if (img
->hash
== hash
&& !NILP (Fequal (img
->spec
, spec
)))
9149 /* If not found, create a new image and cache it. */
9152 extern Lisp_Object Qpostscript
;
9155 img
= make_image (spec
, hash
);
9156 cache_image (f
, img
);
9157 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
9159 /* If we can't load the image, and we don't have a width and
9160 height, use some arbitrary width and height so that we can
9161 draw a rectangle for it. */
9162 if (img
->load_failed_p
)
9166 value
= image_spec_value (spec
, QCwidth
, NULL
);
9167 img
->width
= (INTEGERP (value
)
9168 ? XFASTINT (value
) : DEFAULT_IMAGE_WIDTH
);
9169 value
= image_spec_value (spec
, QCheight
, NULL
);
9170 img
->height
= (INTEGERP (value
)
9171 ? XFASTINT (value
) : DEFAULT_IMAGE_HEIGHT
);
9175 /* Handle image type independent image attributes
9176 `:ascent PERCENT', `:margin MARGIN', `:relief RELIEF',
9177 `:background COLOR'. */
9178 Lisp_Object ascent
, margin
, relief
, bg
;
9180 ascent
= image_spec_value (spec
, QCascent
, NULL
);
9181 if (INTEGERP (ascent
))
9182 img
->ascent
= XFASTINT (ascent
);
9183 else if (EQ (ascent
, Qcenter
))
9184 img
->ascent
= CENTERED_IMAGE_ASCENT
;
9186 margin
= image_spec_value (spec
, QCmargin
, NULL
);
9187 if (INTEGERP (margin
) && XINT (margin
) >= 0)
9188 img
->vmargin
= img
->hmargin
= XFASTINT (margin
);
9189 else if (CONSP (margin
) && INTEGERP (XCAR (margin
))
9190 && INTEGERP (XCDR (margin
)))
9192 if (XINT (XCAR (margin
)) > 0)
9193 img
->hmargin
= XFASTINT (XCAR (margin
));
9194 if (XINT (XCDR (margin
)) > 0)
9195 img
->vmargin
= XFASTINT (XCDR (margin
));
9198 relief
= image_spec_value (spec
, QCrelief
, NULL
);
9199 if (INTEGERP (relief
))
9201 img
->relief
= XINT (relief
);
9202 img
->hmargin
+= abs (img
->relief
);
9203 img
->vmargin
+= abs (img
->relief
);
9206 if (! img
->background_valid
)
9208 bg
= image_spec_value (img
->spec
, QCbackground
, NULL
);
9212 = x_alloc_image_color (f
, img
, bg
,
9213 FRAME_BACKGROUND_PIXEL (f
));
9214 img
->background_valid
= 1;
9218 /* Do image transformations and compute masks, unless we
9219 don't have the image yet. */
9220 if (!EQ (*img
->type
->type
, Qpostscript
))
9221 postprocess_image (f
, img
);
9225 xassert (!interrupt_input_blocked
);
9228 /* We're using IMG, so set its timestamp to `now'. */
9229 EMACS_GET_TIME (now
);
9230 img
->timestamp
= EMACS_SECS (now
);
9234 /* Value is the image id. */
9239 /* Cache image IMG in the image cache of frame F. */
9242 cache_image (f
, img
)
9246 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
9249 /* Find a free slot in c->images. */
9250 for (i
= 0; i
< c
->used
; ++i
)
9251 if (c
->images
[i
] == NULL
)
9254 /* If no free slot found, maybe enlarge c->images. */
9255 if (i
== c
->used
&& c
->used
== c
->size
)
9258 c
->images
= (struct image
**) xrealloc (c
->images
,
9259 c
->size
* sizeof *c
->images
);
9262 /* Add IMG to c->images, and assign IMG an id. */
9268 /* Add IMG to the cache's hash table. */
9269 i
= img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
;
9270 img
->next
= c
->buckets
[i
];
9272 img
->next
->prev
= img
;
9274 c
->buckets
[i
] = img
;
9278 /* Call FN on every image in the image cache of frame F. Used to mark
9279 Lisp Objects in the image cache. */
9282 forall_images_in_image_cache (f
, fn
)
9284 void (*fn
) P_ ((struct image
*img
));
9286 if (FRAME_LIVE_P (f
) && FRAME_W32_P (f
))
9288 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
9292 for (i
= 0; i
< c
->used
; ++i
)
9301 /***********************************************************************
9303 ***********************************************************************/
9305 static int x_create_x_image_and_pixmap
P_ ((struct frame
*, int, int, int,
9306 XImage
**, Pixmap
*));
9307 static void x_destroy_x_image
P_ ((XImage
*));
9308 static void x_put_x_image
P_ ((struct frame
*, XImage
*, Pixmap
, int, int));
9311 /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on
9312 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
9313 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
9314 via xmalloc. DEPTH of zero signifies a 24 bit image, otherwise
9315 DEPTH should indicate the bit depth of the image. Print error
9316 messages via image_error if an error occurs. Value is non-zero if
9320 x_create_x_image_and_pixmap (f
, width
, height
, depth
, ximg
, pixmap
)
9322 int width
, height
, depth
;
9326 BITMAPINFOHEADER
*header
;
9328 int scanline_width_bits
;
9330 int palette_colors
= 0;
9335 if (depth
!= 1 && depth
!= 4 && depth
!= 8
9336 && depth
!= 16 && depth
!= 24 && depth
!= 32)
9338 image_error ("Invalid image bit depth specified", Qnil
, Qnil
);
9342 scanline_width_bits
= width
* depth
;
9343 remainder
= scanline_width_bits
% 32;
9346 scanline_width_bits
+= 32 - remainder
;
9348 /* Bitmaps with a depth less than 16 need a palette. */
9349 /* BITMAPINFO structure already contains the first RGBQUAD. */
9351 palette_colors
= 1 << depth
- 1;
9353 *ximg
= xmalloc (sizeof (XImage
) + palette_colors
* sizeof (RGBQUAD
));
9356 image_error ("Unable to allocate memory for XImage", Qnil
, Qnil
);
9360 header
= &((*ximg
)->info
.bmiHeader
);
9361 bzero (&((*ximg
)->info
), sizeof (BITMAPINFO
));
9362 header
->biSize
= sizeof (*header
);
9363 header
->biWidth
= width
;
9364 header
->biHeight
= -height
; /* negative indicates a top-down bitmap. */
9365 header
->biPlanes
= 1;
9366 header
->biBitCount
= depth
;
9367 header
->biCompression
= BI_RGB
;
9368 header
->biClrUsed
= palette_colors
;
9370 hdc
= get_frame_dc (f
);
9372 /* Create a DIBSection and raster array for the bitmap,
9373 and store its handle in *pixmap. */
9374 *pixmap
= CreateDIBSection (hdc
, &((*ximg
)->info
), DIB_RGB_COLORS
,
9375 &((*ximg
)->data
), NULL
, 0);
9377 /* Realize display palette and garbage all frames. */
9378 release_frame_dc (f
, hdc
);
9380 if (*pixmap
== NULL
)
9382 DWORD err
= GetLastError();
9383 Lisp_Object errcode
;
9384 /* All system errors are < 10000, so the following is safe. */
9385 XSETINT (errcode
, (int) err
);
9386 image_error ("Unable to create bitmap, error code %d", errcode
, Qnil
);
9387 x_destroy_x_image (*ximg
);
9395 /* Destroy XImage XIMG. Free XIMG->data. */
9398 x_destroy_x_image (ximg
)
9401 xassert (interrupt_input_blocked
);
9404 /* Data will be freed by DestroyObject. */
9411 /* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT
9412 are width and height of both the image and pixmap. */
9415 x_put_x_image (f
, ximg
, pixmap
, width
, height
)
9421 #if TODO /* W32 specific image code. */
9424 xassert (interrupt_input_blocked
);
9425 gc
= XCreateGC (NULL
, pixmap
, 0, NULL
);
9426 XPutImage (NULL
, pixmap
, gc
, ximg
, 0, 0, 0, 0, width
, height
);
9432 /***********************************************************************
9434 ***********************************************************************/
9436 static Lisp_Object x_find_image_file
P_ ((Lisp_Object
));
9437 static char *slurp_file
P_ ((char *, int *));
9440 /* Find image file FILE. Look in data-directory, then
9441 x-bitmap-file-path. Value is the full name of the file found, or
9442 nil if not found. */
9445 x_find_image_file (file
)
9448 Lisp_Object file_found
, search_path
;
9449 struct gcpro gcpro1
, gcpro2
;
9453 search_path
= Fcons (Vdata_directory
, Vx_bitmap_file_path
);
9454 GCPRO2 (file_found
, search_path
);
9456 /* Try to find FILE in data-directory, then x-bitmap-file-path. */
9457 fd
= openp (search_path
, file
, Qnil
, &file_found
, 0);
9469 /* Read FILE into memory. Value is a pointer to a buffer allocated
9470 with xmalloc holding FILE's contents. Value is null if an error
9471 occurred. *SIZE is set to the size of the file. */
9474 slurp_file (file
, size
)
9482 if (stat (file
, &st
) == 0
9483 && (fp
= fopen (file
, "r")) != NULL
9484 && (buf
= (char *) xmalloc (st
.st_size
),
9485 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
9506 /***********************************************************************
9508 ***********************************************************************/
9510 static int xbm_scan
P_ ((char **, char *, char *, int *));
9511 static int xbm_load
P_ ((struct frame
*f
, struct image
*img
));
9512 static int xbm_load_image
P_ ((struct frame
*f
, struct image
*img
,
9514 static int xbm_image_p
P_ ((Lisp_Object object
));
9515 static int xbm_read_bitmap_data
P_ ((char *, char *, int *, int *,
9517 static int xbm_file_p
P_ ((Lisp_Object
));
9520 /* Indices of image specification fields in xbm_format, below. */
9522 enum xbm_keyword_index
9540 /* Vector of image_keyword structures describing the format
9541 of valid XBM image specifications. */
9543 static struct image_keyword xbm_format
[XBM_LAST
] =
9545 {":type", IMAGE_SYMBOL_VALUE
, 1},
9546 {":file", IMAGE_STRING_VALUE
, 0},
9547 {":width", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9548 {":height", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9549 {":data", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9550 {":foreground", IMAGE_STRING_OR_NIL_VALUE
, 0},
9551 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0},
9552 {":ascent", IMAGE_ASCENT_VALUE
, 0},
9553 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
9554 {":relief", IMAGE_INTEGER_VALUE
, 0},
9555 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9556 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9557 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9560 /* Structure describing the image type XBM. */
9562 static struct image_type xbm_type
=
9571 /* Tokens returned from xbm_scan. */
9580 /* Return non-zero if OBJECT is a valid XBM-type image specification.
9581 A valid specification is a list starting with the symbol `image'
9582 The rest of the list is a property list which must contain an
9585 If the specification specifies a file to load, it must contain
9586 an entry `:file FILENAME' where FILENAME is a string.
9588 If the specification is for a bitmap loaded from memory it must
9589 contain `:width WIDTH', `:height HEIGHT', and `:data DATA', where
9590 WIDTH and HEIGHT are integers > 0. DATA may be:
9592 1. a string large enough to hold the bitmap data, i.e. it must
9593 have a size >= (WIDTH + 7) / 8 * HEIGHT
9595 2. a bool-vector of size >= WIDTH * HEIGHT
9597 3. a vector of strings or bool-vectors, one for each line of the
9600 4. A string containing an in-memory XBM file. WIDTH and HEIGHT
9601 may not be specified in this case because they are defined in the
9604 Both the file and data forms may contain the additional entries
9605 `:background COLOR' and `:foreground COLOR'. If not present,
9606 foreground and background of the frame on which the image is
9607 displayed is used. */
9610 xbm_image_p (object
)
9613 struct image_keyword kw
[XBM_LAST
];
9615 bcopy (xbm_format
, kw
, sizeof kw
);
9616 if (!parse_image_spec (object
, kw
, XBM_LAST
, Qxbm
))
9619 xassert (EQ (kw
[XBM_TYPE
].value
, Qxbm
));
9621 if (kw
[XBM_FILE
].count
)
9623 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_DATA
].count
)
9626 else if (kw
[XBM_DATA
].count
&& xbm_file_p (kw
[XBM_DATA
].value
))
9628 /* In-memory XBM file. */
9629 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_FILE
].count
)
9637 /* Entries for `:width', `:height' and `:data' must be present. */
9638 if (!kw
[XBM_WIDTH
].count
9639 || !kw
[XBM_HEIGHT
].count
9640 || !kw
[XBM_DATA
].count
)
9643 data
= kw
[XBM_DATA
].value
;
9644 width
= XFASTINT (kw
[XBM_WIDTH
].value
);
9645 height
= XFASTINT (kw
[XBM_HEIGHT
].value
);
9647 /* Check type of data, and width and height against contents of
9653 /* Number of elements of the vector must be >= height. */
9654 if (XVECTOR (data
)->size
< height
)
9657 /* Each string or bool-vector in data must be large enough
9658 for one line of the image. */
9659 for (i
= 0; i
< height
; ++i
)
9661 Lisp_Object elt
= XVECTOR (data
)->contents
[i
];
9665 if (XSTRING (elt
)->size
9666 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
)
9669 else if (BOOL_VECTOR_P (elt
))
9671 if (XBOOL_VECTOR (elt
)->size
< width
)
9678 else if (STRINGP (data
))
9680 if (XSTRING (data
)->size
9681 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
* height
)
9684 else if (BOOL_VECTOR_P (data
))
9686 if (XBOOL_VECTOR (data
)->size
< width
* height
)
9697 /* Scan a bitmap file. FP is the stream to read from. Value is
9698 either an enumerator from enum xbm_token, or a character for a
9699 single-character token, or 0 at end of file. If scanning an
9700 identifier, store the lexeme of the identifier in SVAL. If
9701 scanning a number, store its value in *IVAL. */
9704 xbm_scan (s
, end
, sval
, ival
)
9713 /* Skip white space. */
9714 while (*s
< end
&&(c
= *(*s
)++, isspace (c
)))
9719 else if (isdigit (c
))
9721 int value
= 0, digit
;
9723 if (c
== '0' && *s
< end
)
9726 if (c
== 'x' || c
== 'X')
9733 else if (c
>= 'a' && c
<= 'f')
9734 digit
= c
- 'a' + 10;
9735 else if (c
>= 'A' && c
<= 'F')
9736 digit
= c
- 'A' + 10;
9739 value
= 16 * value
+ digit
;
9742 else if (isdigit (c
))
9746 && (c
= *(*s
)++, isdigit (c
)))
9747 value
= 8 * value
+ c
- '0';
9754 && (c
= *(*s
)++, isdigit (c
)))
9755 value
= 10 * value
+ c
- '0';
9763 else if (isalpha (c
) || c
== '_')
9767 && (c
= *(*s
)++, (isalnum (c
) || c
== '_')))
9774 else if (c
== '/' && **s
== '*')
9776 /* C-style comment. */
9778 while (**s
&& (**s
!= '*' || *(*s
+ 1) != '/'))
9791 /* XBM bits seem to be backward within bytes compared with how
9792 Windows does things. */
9793 static unsigned char reflect_byte (unsigned char orig
)
9796 unsigned char reflected
= 0x00;
9797 for (i
= 0; i
< 8; i
++)
9799 if (orig
& (0x01 << i
))
9800 reflected
|= 0x80 >> i
;
9806 /* Replacement for XReadBitmapFileData which isn't available under old
9807 X versions. CONTENTS is a pointer to a buffer to parse; END is the
9808 buffer's end. Set *WIDTH and *HEIGHT to the width and height of
9809 the image. Return in *DATA the bitmap data allocated with xmalloc.
9810 Value is non-zero if successful. DATA null means just test if
9811 CONTENTS looks like an in-memory XBM file. */
9814 xbm_read_bitmap_data (contents
, end
, width
, height
, data
)
9815 char *contents
, *end
;
9816 int *width
, *height
;
9817 unsigned char **data
;
9820 char buffer
[BUFSIZ
];
9823 int bytes_in_per_line
, bytes_out_per_line
, i
, nbytes
;
9829 LA1 = xbm_scan (&s, end, buffer, &value)
9831 #define expect(TOKEN) \
9832 if (LA1 != (TOKEN)) \
9837 #define expect_ident(IDENT) \
9838 if (LA1 == XBM_TK_IDENT && strcmp (buffer, (IDENT)) == 0) \
9843 *width
= *height
= -1;
9846 LA1
= xbm_scan (&s
, end
, buffer
, &value
);
9848 /* Parse defines for width, height and hot-spots. */
9852 expect_ident ("define");
9853 expect (XBM_TK_IDENT
);
9855 if (LA1
== XBM_TK_NUMBER
);
9857 char *p
= strrchr (buffer
, '_');
9858 p
= p
? p
+ 1 : buffer
;
9859 if (strcmp (p
, "width") == 0)
9861 else if (strcmp (p
, "height") == 0)
9864 expect (XBM_TK_NUMBER
);
9867 if (*width
< 0 || *height
< 0)
9869 else if (data
== NULL
)
9872 /* Parse bits. Must start with `static'. */
9873 expect_ident ("static");
9874 if (LA1
== XBM_TK_IDENT
)
9876 /* On Windows, all images need padding to 16 bit boundaries. */
9877 if (*width
% 16 && *width
% 16 < 9)
9880 if (strcmp (buffer
, "unsigned") == 0)
9883 expect_ident ("char");
9885 else if (strcmp (buffer
, "short") == 0)
9890 else if (strcmp (buffer
, "char") == 0)
9898 expect (XBM_TK_IDENT
);
9904 /* Bytes per line on input. Only count padding for v10 XBMs. */
9905 bytes_in_per_line
= (*width
+ 7) / 8 + (v10
? padding_p
: 0);
9906 bytes_out_per_line
= (*width
+ 7) / 8 + padding_p
;
9908 nbytes
= bytes_in_per_line
* *height
;
9909 p
= *data
= (char *) xmalloc (bytes_out_per_line
* *height
);
9913 for (i
= 0; i
< nbytes
; i
+= 2)
9916 expect (XBM_TK_NUMBER
);
9918 *p
++ = reflect_byte (val
);
9919 if (!padding_p
|| ((i
+ 2) % bytes_in_per_line
))
9920 *p
++ = reflect_byte (value
>> 8);
9922 if (LA1
== ',' || LA1
== '}')
9930 for (i
= 0; i
< nbytes
; ++i
)
9933 expect (XBM_TK_NUMBER
);
9935 *p
++ = reflect_byte (val
);
9936 if (padding_p
&& ((i
+ 1) % bytes_in_per_line
) == 0)
9939 if (LA1
== ',' || LA1
== '}')
9964 /* Load XBM image IMG which will be displayed on frame F from buffer
9965 CONTENTS. END is the end of the buffer. Value is non-zero if
9969 xbm_load_image (f
, img
, contents
, end
)
9972 char *contents
, *end
;
9975 unsigned char *data
;
9978 rc
= xbm_read_bitmap_data (contents
, end
, &img
->width
, &img
->height
, &data
);
9981 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
9982 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
9985 xassert (img
->width
> 0 && img
->height
> 0);
9987 /* Get foreground and background colors, maybe allocate colors. */
9988 value
= image_spec_value (img
->spec
, QCforeground
, NULL
);
9990 foreground
= x_alloc_image_color (f
, img
, value
, foreground
);
9991 value
= image_spec_value (img
->spec
, QCbackground
, NULL
);
9994 background
= x_alloc_image_color (f
, img
, value
, background
);
9995 img
->background
= background
;
9996 img
->background_valid
= 1;
9999 = CreateBitmap (img
->width
, img
->height
, 1, 1, data
);
10003 if (img
->pixmap
== 0)
10005 x_clear_image (f
, img
);
10006 image_error ("Unable to create X pixmap for `%s'", img
->spec
, Qnil
);
10012 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
10018 /* Value is non-zero if DATA looks like an in-memory XBM file. */
10025 return (STRINGP (data
)
10026 && xbm_read_bitmap_data (XSTRING (data
)->data
,
10027 (XSTRING (data
)->data
10028 + STRING_BYTES (XSTRING (data
))),
10033 /* Fill image IMG which is used on frame F with pixmap data. Value is
10034 non-zero if successful. */
10042 Lisp_Object file_name
;
10044 xassert (xbm_image_p (img
->spec
));
10046 /* If IMG->spec specifies a file name, create a non-file spec from it. */
10047 file_name
= image_spec_value (img
->spec
, QCfile
, NULL
);
10048 if (STRINGP (file_name
))
10053 struct gcpro gcpro1
;
10055 file
= x_find_image_file (file_name
);
10057 if (!STRINGP (file
))
10059 image_error ("Cannot find image file `%s'", file_name
, Qnil
);
10064 contents
= slurp_file (XSTRING (file
)->data
, &size
);
10065 if (contents
== NULL
)
10067 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
10072 success_p
= xbm_load_image (f
, img
, contents
, contents
+ size
);
10077 struct image_keyword fmt
[XBM_LAST
];
10080 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
10081 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
10084 int in_memory_file_p
= 0;
10086 /* See if data looks like an in-memory XBM file. */
10087 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10088 in_memory_file_p
= xbm_file_p (data
);
10090 /* Parse the image specification. */
10091 bcopy (xbm_format
, fmt
, sizeof fmt
);
10092 parsed_p
= parse_image_spec (img
->spec
, fmt
, XBM_LAST
, Qxbm
);
10093 xassert (parsed_p
);
10095 /* Get specified width, and height. */
10096 if (!in_memory_file_p
)
10098 img
->width
= XFASTINT (fmt
[XBM_WIDTH
].value
);
10099 img
->height
= XFASTINT (fmt
[XBM_HEIGHT
].value
);
10100 xassert (img
->width
> 0 && img
->height
> 0);
10103 /* Get foreground and background colors, maybe allocate colors. */
10104 if (fmt
[XBM_FOREGROUND
].count
10105 && STRINGP (fmt
[XBM_FOREGROUND
].value
))
10106 foreground
= x_alloc_image_color (f
, img
, fmt
[XBM_FOREGROUND
].value
,
10108 if (fmt
[XBM_BACKGROUND
].count
10109 && STRINGP (fmt
[XBM_BACKGROUND
].value
))
10110 background
= x_alloc_image_color (f
, img
, fmt
[XBM_BACKGROUND
].value
,
10113 if (in_memory_file_p
)
10114 success_p
= xbm_load_image (f
, img
, XSTRING (data
)->data
,
10115 (XSTRING (data
)->data
10116 + STRING_BYTES (XSTRING (data
))));
10119 if (VECTORP (data
))
10123 int nbytes
= (img
->width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
;
10125 p
= bits
= (char *) alloca (nbytes
* img
->height
);
10126 for (i
= 0; i
< img
->height
; ++i
, p
+= nbytes
)
10128 Lisp_Object line
= XVECTOR (data
)->contents
[i
];
10129 if (STRINGP (line
))
10130 bcopy (XSTRING (line
)->data
, p
, nbytes
);
10132 bcopy (XBOOL_VECTOR (line
)->data
, p
, nbytes
);
10135 else if (STRINGP (data
))
10136 bits
= XSTRING (data
)->data
;
10138 bits
= XBOOL_VECTOR (data
)->data
;
10139 #ifdef TODO /* full image support. */
10140 /* Create the pixmap. */
10141 depth
= one_w32_display_info
.n_cbits
;
10143 = XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f
),
10144 FRAME_X_WINDOW (f
),
10146 img
->width
, img
->height
,
10147 foreground
, background
,
10154 image_error ("Unable to create pixmap for XBM image `%s'",
10156 x_clear_image (f
, img
);
10166 /***********************************************************************
10168 ***********************************************************************/
10172 static int xpm_image_p
P_ ((Lisp_Object object
));
10173 static int xpm_load
P_ ((struct frame
*f
, struct image
*img
));
10174 static int xpm_valid_color_symbols_p
P_ ((Lisp_Object
));
10176 #include "X11/xpm.h"
10178 /* The symbol `xpm' identifying XPM-format images. */
10182 /* Indices of image specification fields in xpm_format, below. */
10184 enum xpm_keyword_index
10193 XPM_HEURISTIC_MASK
,
10200 /* Vector of image_keyword structures describing the format
10201 of valid XPM image specifications. */
10203 static struct image_keyword xpm_format
[XPM_LAST
] =
10205 {":type", IMAGE_SYMBOL_VALUE
, 1},
10206 {":file", IMAGE_STRING_VALUE
, 0},
10207 {":data", IMAGE_STRING_VALUE
, 0},
10208 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10209 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
10210 {":relief", IMAGE_INTEGER_VALUE
, 0},
10211 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10212 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10213 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10214 {":color-symbols", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10215 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
10218 /* Structure describing the image type XBM. */
10220 static struct image_type xpm_type
=
10230 /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
10231 for XPM images. Such a list must consist of conses whose car and
10232 cdr are strings. */
10235 xpm_valid_color_symbols_p (color_symbols
)
10236 Lisp_Object color_symbols
;
10238 while (CONSP (color_symbols
))
10240 Lisp_Object sym
= XCAR (color_symbols
);
10242 || !STRINGP (XCAR (sym
))
10243 || !STRINGP (XCDR (sym
)))
10245 color_symbols
= XCDR (color_symbols
);
10248 return NILP (color_symbols
);
10252 /* Value is non-zero if OBJECT is a valid XPM image specification. */
10255 xpm_image_p (object
)
10256 Lisp_Object object
;
10258 struct image_keyword fmt
[XPM_LAST
];
10259 bcopy (xpm_format
, fmt
, sizeof fmt
);
10260 return (parse_image_spec (object
, fmt
, XPM_LAST
, Qxpm
)
10261 /* Either `:file' or `:data' must be present. */
10262 && fmt
[XPM_FILE
].count
+ fmt
[XPM_DATA
].count
== 1
10263 /* Either no `:color-symbols' or it's a list of conses
10264 whose car and cdr are strings. */
10265 && (fmt
[XPM_COLOR_SYMBOLS
].count
== 0
10266 || xpm_valid_color_symbols_p (fmt
[XPM_COLOR_SYMBOLS
].value
))
10267 && (fmt
[XPM_ASCENT
].count
== 0
10268 || XFASTINT (fmt
[XPM_ASCENT
].value
) < 100));
10272 /* Load image IMG which will be displayed on frame F. Value is
10273 non-zero if successful. */
10281 XpmAttributes attrs
;
10282 Lisp_Object specified_file
, color_symbols
;
10284 /* Configure the XPM lib. Use the visual of frame F. Allocate
10285 close colors. Return colors allocated. */
10286 bzero (&attrs
, sizeof attrs
);
10287 attrs
.visual
= FRAME_X_VISUAL (f
);
10288 attrs
.colormap
= FRAME_X_COLORMAP (f
);
10289 attrs
.valuemask
|= XpmVisual
;
10290 attrs
.valuemask
|= XpmColormap
;
10291 attrs
.valuemask
|= XpmReturnAllocPixels
;
10292 #ifdef XpmAllocCloseColors
10293 attrs
.alloc_close_colors
= 1;
10294 attrs
.valuemask
|= XpmAllocCloseColors
;
10296 attrs
.closeness
= 600;
10297 attrs
.valuemask
|= XpmCloseness
;
10300 /* If image specification contains symbolic color definitions, add
10301 these to `attrs'. */
10302 color_symbols
= image_spec_value (img
->spec
, QCcolor_symbols
, NULL
);
10303 if (CONSP (color_symbols
))
10306 XpmColorSymbol
*xpm_syms
;
10309 attrs
.valuemask
|= XpmColorSymbols
;
10311 /* Count number of symbols. */
10312 attrs
.numsymbols
= 0;
10313 for (tail
= color_symbols
; CONSP (tail
); tail
= XCDR (tail
))
10314 ++attrs
.numsymbols
;
10316 /* Allocate an XpmColorSymbol array. */
10317 size
= attrs
.numsymbols
* sizeof *xpm_syms
;
10318 xpm_syms
= (XpmColorSymbol
*) alloca (size
);
10319 bzero (xpm_syms
, size
);
10320 attrs
.colorsymbols
= xpm_syms
;
10322 /* Fill the color symbol array. */
10323 for (tail
= color_symbols
, i
= 0;
10325 ++i
, tail
= XCDR (tail
))
10327 Lisp_Object name
= XCAR (XCAR (tail
));
10328 Lisp_Object color
= XCDR (XCAR (tail
));
10329 xpm_syms
[i
].name
= (char *) alloca (XSTRING (name
)->size
+ 1);
10330 strcpy (xpm_syms
[i
].name
, XSTRING (name
)->data
);
10331 xpm_syms
[i
].value
= (char *) alloca (XSTRING (color
)->size
+ 1);
10332 strcpy (xpm_syms
[i
].value
, XSTRING (color
)->data
);
10336 /* Create a pixmap for the image, either from a file, or from a
10337 string buffer containing data in the same format as an XPM file. */
10339 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10340 if (STRINGP (specified_file
))
10342 Lisp_Object file
= x_find_image_file (specified_file
);
10343 if (!STRINGP (file
))
10345 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10350 rc
= XpmReadFileToPixmap (NULL
, FRAME_W32_WINDOW (f
),
10351 XSTRING (file
)->data
, &img
->pixmap
, &img
->mask
,
10356 Lisp_Object buffer
= image_spec_value (img
->spec
, QCdata
, NULL
);
10357 rc
= XpmCreatePixmapFromBuffer (NULL
, FRAME_W32_WINDOW (f
),
10358 XSTRING (buffer
)->data
,
10359 &img
->pixmap
, &img
->mask
,
10364 if (rc
== XpmSuccess
)
10366 /* Remember allocated colors. */
10367 img
->ncolors
= attrs
.nalloc_pixels
;
10368 img
->colors
= (unsigned long *) xmalloc (img
->ncolors
10369 * sizeof *img
->colors
);
10370 for (i
= 0; i
< attrs
.nalloc_pixels
; ++i
)
10371 img
->colors
[i
] = attrs
.alloc_pixels
[i
];
10373 img
->width
= attrs
.width
;
10374 img
->height
= attrs
.height
;
10375 xassert (img
->width
> 0 && img
->height
> 0);
10377 /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */
10379 XpmFreeAttributes (&attrs
);
10386 case XpmOpenFailed
:
10387 image_error ("Error opening XPM file (%s)", img
->spec
, Qnil
);
10390 case XpmFileInvalid
:
10391 image_error ("Invalid XPM file (%s)", img
->spec
, Qnil
);
10395 image_error ("Out of memory (%s)", img
->spec
, Qnil
);
10398 case XpmColorFailed
:
10399 image_error ("Color allocation error (%s)", img
->spec
, Qnil
);
10403 image_error ("Unknown error (%s)", img
->spec
, Qnil
);
10408 return rc
== XpmSuccess
;
10411 #endif /* HAVE_XPM != 0 */
10414 #if 0 /* TODO : Color tables on W32. */
10415 /***********************************************************************
10417 ***********************************************************************/
10419 /* An entry in the color table mapping an RGB color to a pixel color. */
10424 unsigned long pixel
;
10426 /* Next in color table collision list. */
10427 struct ct_color
*next
;
10430 /* The bucket vector size to use. Must be prime. */
10432 #define CT_SIZE 101
10434 /* Value is a hash of the RGB color given by R, G, and B. */
10436 #define CT_HASH_RGB(R, G, B) (((R) << 16) ^ ((G) << 8) ^ (B))
10438 /* The color hash table. */
10440 struct ct_color
**ct_table
;
10442 /* Number of entries in the color table. */
10444 int ct_colors_allocated
;
10446 /* Function prototypes. */
10448 static void init_color_table
P_ ((void));
10449 static void free_color_table
P_ ((void));
10450 static unsigned long *colors_in_color_table
P_ ((int *n
));
10451 static unsigned long lookup_rgb_color
P_ ((struct frame
*f
, int r
, int g
, int b
));
10452 static unsigned long lookup_pixel_color
P_ ((struct frame
*f
, unsigned long p
));
10455 /* Initialize the color table. */
10458 init_color_table ()
10460 int size
= CT_SIZE
* sizeof (*ct_table
);
10461 ct_table
= (struct ct_color
**) xmalloc (size
);
10462 bzero (ct_table
, size
);
10463 ct_colors_allocated
= 0;
10467 /* Free memory associated with the color table. */
10470 free_color_table ()
10473 struct ct_color
*p
, *next
;
10475 for (i
= 0; i
< CT_SIZE
; ++i
)
10476 for (p
= ct_table
[i
]; p
; p
= next
)
10487 /* Value is a pixel color for RGB color R, G, B on frame F. If an
10488 entry for that color already is in the color table, return the
10489 pixel color of that entry. Otherwise, allocate a new color for R,
10490 G, B, and make an entry in the color table. */
10492 static unsigned long
10493 lookup_rgb_color (f
, r
, g
, b
)
10497 unsigned hash
= CT_HASH_RGB (r
, g
, b
);
10498 int i
= hash
% CT_SIZE
;
10499 struct ct_color
*p
;
10501 for (p
= ct_table
[i
]; p
; p
= p
->next
)
10502 if (p
->r
== r
&& p
->g
== g
&& p
->b
== b
)
10511 color
= PALETTERGB (r
, g
, b
);
10513 ++ct_colors_allocated
;
10515 p
= (struct ct_color
*) xmalloc (sizeof *p
);
10520 p
->next
= ct_table
[i
];
10528 /* Look up pixel color PIXEL which is used on frame F in the color
10529 table. If not already present, allocate it. Value is PIXEL. */
10531 static unsigned long
10532 lookup_pixel_color (f
, pixel
)
10534 unsigned long pixel
;
10536 int i
= pixel
% CT_SIZE
;
10537 struct ct_color
*p
;
10539 for (p
= ct_table
[i
]; p
; p
= p
->next
)
10540 if (p
->pixel
== pixel
)
10551 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
10552 color
.pixel
= pixel
;
10553 XQueryColor (NULL
, cmap
, &color
);
10554 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
10559 ++ct_colors_allocated
;
10561 p
= (struct ct_color
*) xmalloc (sizeof *p
);
10563 p
->g
= color
.green
;
10566 p
->next
= ct_table
[i
];
10570 return FRAME_FOREGROUND_PIXEL (f
);
10576 /* Value is a vector of all pixel colors contained in the color table,
10577 allocated via xmalloc. Set *N to the number of colors. */
10579 static unsigned long *
10580 colors_in_color_table (n
)
10584 struct ct_color
*p
;
10585 unsigned long *colors
;
10587 if (ct_colors_allocated
== 0)
10594 colors
= (unsigned long *) xmalloc (ct_colors_allocated
10596 *n
= ct_colors_allocated
;
10598 for (i
= j
= 0; i
< CT_SIZE
; ++i
)
10599 for (p
= ct_table
[i
]; p
; p
= p
->next
)
10600 colors
[j
++] = p
->pixel
;
10609 /***********************************************************************
10611 ***********************************************************************/
10612 static XColor
*x_to_xcolors
P_ ((struct frame
*, struct image
*, int));
10613 static void x_from_xcolors
P_ ((struct frame
*, struct image
*, XColor
*));
10614 static void x_detect_edges
P_ ((struct frame
*, struct image
*, int[9], int));
10615 static void XPutPixel (XImage
*, int, int, COLORREF
);
10617 /* Non-zero means draw a cross on images having `:conversion
10620 int cross_disabled_images
;
10622 /* Edge detection matrices for different edge-detection
10625 static int emboss_matrix
[9] = {
10626 /* x - 1 x x + 1 */
10627 2, -1, 0, /* y - 1 */
10629 0, 1, -2 /* y + 1 */
10632 static int laplace_matrix
[9] = {
10633 /* x - 1 x x + 1 */
10634 1, 0, 0, /* y - 1 */
10636 0, 0, -1 /* y + 1 */
10639 /* Value is the intensity of the color whose red/green/blue values
10640 are R, G, and B. */
10642 #define COLOR_INTENSITY(R, G, B) ((2 * (R) + 3 * (G) + (B)) / 6)
10645 /* On frame F, return an array of XColor structures describing image
10646 IMG->pixmap. Each XColor structure has its pixel color set. RGB_P
10647 non-zero means also fill the red/green/blue members of the XColor
10648 structures. Value is a pointer to the array of XColors structures,
10649 allocated with xmalloc; it must be freed by the caller. */
10652 x_to_xcolors (f
, img
, rgb_p
)
10658 XColor
*colors
, *p
;
10661 colors
= (XColor
*) xmalloc (img
->width
* img
->height
* sizeof *colors
);
10662 #if 0 /* TODO: implement image colors. */
10663 /* Get the X image IMG->pixmap. */
10664 ximg
= XGetImage (FRAME_X_DISPLAY (f
), img
->pixmap
,
10665 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
10667 /* Fill the `pixel' members of the XColor array. I wished there
10668 were an easy and portable way to circumvent XGetPixel. */
10670 for (y
= 0; y
< img
->height
; ++y
)
10674 for (x
= 0; x
< img
->width
; ++x
, ++p
)
10675 p
->pixel
= XGetPixel (ximg
, x
, y
);
10678 x_query_colors (f
, row
, img
->width
);
10681 XDestroyImage (ximg
);
10686 /* Put a pixel of COLOR at position X, Y in XIMG. XIMG must have been
10687 created with CreateDIBSection, with the pointer to the bit values
10688 stored in ximg->data. */
10690 static void XPutPixel (ximg
, x
, y
, color
)
10695 int width
= ximg
->info
.bmiHeader
.biWidth
;
10696 int height
= ximg
->info
.bmiHeader
.biHeight
;
10697 int rowbytes
= width
* 3;
10698 unsigned char * pixel
;
10700 /* Don't support putting pixels in images with palettes. */
10701 xassert (ximg
->info
.bmiHeader
.biBitCount
== 24);
10703 /* Ensure scanlines are aligned on 4 byte boundaries. */
10705 rowbytes
+= 4 - (rowbytes
% 4);
10707 pixel
= ximg
->data
+ y
* rowbytes
+ x
* 3;
10708 *pixel
= 255 - GetRValue (color
);
10709 *(pixel
+ 1) = 255 - GetGValue (color
);
10710 *(pixel
+ 2) = 255 - GetBValue (color
);
10714 /* Create IMG->pixmap from an array COLORS of XColor structures, whose
10715 RGB members are set. F is the frame on which this all happens.
10716 COLORS will be freed; an existing IMG->pixmap will be freed, too. */
10719 x_from_xcolors (f
, img
, colors
)
10728 #if 0 /* TODO: color tables. */
10729 init_color_table ();
10731 x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 0,
10734 for (y
= 0; y
< img
->height
; ++y
)
10735 for (x
= 0; x
< img
->width
; ++x
, ++p
)
10737 unsigned long pixel
;
10738 #if 0 /* TODO: color tables. */
10739 pixel
= lookup_rgb_color (f
, p
->red
, p
->green
, p
->blue
);
10741 pixel
= PALETTERGB (p
->red
, p
->green
, p
->blue
);
10743 XPutPixel (oimg
, x
, y
, pixel
);
10747 x_clear_image_1 (f
, img
, 1, 0, 1);
10749 x_put_x_image (f
, oimg
, pixmap
, img
->width
, img
->height
);
10750 x_destroy_x_image (oimg
);
10751 img
->pixmap
= pixmap
;
10752 #if 0 /* TODO: color tables. */
10753 img
->colors
= colors_in_color_table (&img
->ncolors
);
10754 free_color_table ();
10759 /* On frame F, perform edge-detection on image IMG.
10761 MATRIX is a nine-element array specifying the transformation
10762 matrix. See emboss_matrix for an example.
10764 COLOR_ADJUST is a color adjustment added to each pixel of the
10768 x_detect_edges (f
, img
, matrix
, color_adjust
)
10771 int matrix
[9], color_adjust
;
10773 XColor
*colors
= x_to_xcolors (f
, img
, 1);
10777 for (i
= sum
= 0; i
< 9; ++i
)
10778 sum
+= abs (matrix
[i
]);
10780 #define COLOR(A, X, Y) ((A) + (Y) * img->width + (X))
10782 new = (XColor
*) xmalloc (img
->width
* img
->height
* sizeof *new);
10784 for (y
= 0; y
< img
->height
; ++y
)
10786 p
= COLOR (new, 0, y
);
10787 p
->red
= p
->green
= p
->blue
= 0xffff/2;
10788 p
= COLOR (new, img
->width
- 1, y
);
10789 p
->red
= p
->green
= p
->blue
= 0xffff/2;
10792 for (x
= 1; x
< img
->width
- 1; ++x
)
10794 p
= COLOR (new, x
, 0);
10795 p
->red
= p
->green
= p
->blue
= 0xffff/2;
10796 p
= COLOR (new, x
, img
->height
- 1);
10797 p
->red
= p
->green
= p
->blue
= 0xffff/2;
10800 for (y
= 1; y
< img
->height
- 1; ++y
)
10802 p
= COLOR (new, 1, y
);
10804 for (x
= 1; x
< img
->width
- 1; ++x
, ++p
)
10806 int r
, g
, b
, y1
, x1
;
10809 for (y1
= y
- 1; y1
< y
+ 2; ++y1
)
10810 for (x1
= x
- 1; x1
< x
+ 2; ++x1
, ++i
)
10813 XColor
*t
= COLOR (colors
, x1
, y1
);
10814 r
+= matrix
[i
] * t
->red
;
10815 g
+= matrix
[i
] * t
->green
;
10816 b
+= matrix
[i
] * t
->blue
;
10819 r
= (r
/ sum
+ color_adjust
) & 0xffff;
10820 g
= (g
/ sum
+ color_adjust
) & 0xffff;
10821 b
= (b
/ sum
+ color_adjust
) & 0xffff;
10822 p
->red
= p
->green
= p
->blue
= COLOR_INTENSITY (r
, g
, b
);
10827 x_from_xcolors (f
, img
, new);
10833 /* Perform the pre-defined `emboss' edge-detection on image IMG
10841 x_detect_edges (f
, img
, emboss_matrix
, 0xffff / 2);
10845 /* Transform image IMG which is used on frame F with a Laplace
10846 edge-detection algorithm. The result is an image that can be used
10847 to draw disabled buttons, for example. */
10854 x_detect_edges (f
, img
, laplace_matrix
, 45000);
10858 /* Perform edge-detection on image IMG on frame F, with specified
10859 transformation matrix MATRIX and color-adjustment COLOR_ADJUST.
10861 MATRIX must be either
10863 - a list of at least 9 numbers in row-major form
10864 - a vector of at least 9 numbers
10866 COLOR_ADJUST nil means use a default; otherwise it must be a
10870 x_edge_detection (f
, img
, matrix
, color_adjust
)
10873 Lisp_Object matrix
, color_adjust
;
10878 if (CONSP (matrix
))
10881 i
< 9 && CONSP (matrix
) && NUMBERP (XCAR (matrix
));
10882 ++i
, matrix
= XCDR (matrix
))
10883 trans
[i
] = XFLOATINT (XCAR (matrix
));
10885 else if (VECTORP (matrix
) && ASIZE (matrix
) >= 9)
10887 for (i
= 0; i
< 9 && NUMBERP (AREF (matrix
, i
)); ++i
)
10888 trans
[i
] = XFLOATINT (AREF (matrix
, i
));
10891 if (NILP (color_adjust
))
10892 color_adjust
= make_number (0xffff / 2);
10894 if (i
== 9 && NUMBERP (color_adjust
))
10895 x_detect_edges (f
, img
, trans
, (int) XFLOATINT (color_adjust
));
10899 /* Transform image IMG on frame F so that it looks disabled. */
10902 x_disable_image (f
, img
)
10906 struct w32_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10908 if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
>= 2)
10910 /* Color (or grayscale). Convert to gray, and equalize. Just
10911 drawing such images with a stipple can look very odd, so
10912 we're using this method instead. */
10913 XColor
*colors
= x_to_xcolors (f
, img
, 1);
10915 const int h
= 15000;
10916 const int l
= 30000;
10918 for (p
= colors
, end
= colors
+ img
->width
* img
->height
;
10922 int i
= COLOR_INTENSITY (p
->red
, p
->green
, p
->blue
);
10923 int i2
= (0xffff - h
- l
) * i
/ 0xffff + l
;
10924 p
->red
= p
->green
= p
->blue
= i2
;
10927 x_from_xcolors (f
, img
, colors
);
10930 /* Draw a cross over the disabled image, if we must or if we
10932 if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
< 2 || cross_disabled_images
)
10934 #if 0 /* TODO: full image support */
10935 Display
*dpy
= FRAME_X_DISPLAY (f
);
10938 gc
= XCreateGC (dpy
, img
->pixmap
, 0, NULL
);
10939 XSetForeground (dpy
, gc
, BLACK_PIX_DEFAULT (f
));
10940 XDrawLine (dpy
, img
->pixmap
, gc
, 0, 0,
10941 img
->width
- 1, img
->height
- 1);
10942 XDrawLine (dpy
, img
->pixmap
, gc
, 0, img
->height
- 1,
10943 img
->width
- 1, 0);
10948 gc
= XCreateGC (dpy
, img
->mask
, 0, NULL
);
10949 XSetForeground (dpy
, gc
, WHITE_PIX_DEFAULT (f
));
10950 XDrawLine (dpy
, img
->mask
, gc
, 0, 0,
10951 img
->width
- 1, img
->height
- 1);
10952 XDrawLine (dpy
, img
->mask
, gc
, 0, img
->height
- 1,
10953 img
->width
- 1, 0);
10961 /* Build a mask for image IMG which is used on frame F. FILE is the
10962 name of an image file, for error messages. HOW determines how to
10963 determine the background color of IMG. If it is a list '(R G B)',
10964 with R, G, and B being integers >= 0, take that as the color of the
10965 background. Otherwise, determine the background color of IMG
10966 heuristically. Value is non-zero if successful. */
10969 x_build_heuristic_mask (f
, img
, how
)
10974 #if 0 /* TODO: full image support. */
10975 Display
*dpy
= FRAME_W32_DISPLAY (f
);
10976 XImage
*ximg
, *mask_img
;
10977 int x
, y
, rc
, use_img_background
;
10978 unsigned long bg
= 0;
10982 XFreePixmap (FRAME_X_DISPLAY (f
), img
->mask
);
10984 img
->background_transparent_valid
= 0;
10987 /* Create an image and pixmap serving as mask. */
10988 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 1,
10989 &mask_img
, &img
->mask
);
10993 /* Get the X image of IMG->pixmap. */
10994 ximg
= XGetImage (dpy
, img
->pixmap
, 0, 0, img
->width
, img
->height
,
10997 /* Determine the background color of ximg. If HOW is `(R G B)'
10998 take that as color. Otherwise, use the image's background color. */
10999 use_img_background
= 1;
11005 for (i
= 0; i
< 3 && CONSP (how
) && NATNUMP (XCAR (how
)); ++i
)
11007 rgb
[i
] = XFASTINT (XCAR (how
)) & 0xffff;
11011 if (i
== 3 && NILP (how
))
11013 char color_name
[30];
11014 sprintf (color_name
, "#%04x%04x%04x", rgb
[0], rgb
[1], rgb
[2]);
11015 bg
= x_alloc_image_color (f
, img
, build_string (color_name
), 0);
11016 use_img_background
= 0;
11020 if (use_img_background
)
11021 bg
= four_corners_best (ximg
, img
->width
, img
->height
);
11023 /* Set all bits in mask_img to 1 whose color in ximg is different
11024 from the background color bg. */
11025 for (y
= 0; y
< img
->height
; ++y
)
11026 for (x
= 0; x
< img
->width
; ++x
)
11027 XPutPixel (mask_img
, x
, y
, XGetPixel (ximg
, x
, y
) != bg
);
11029 /* Fill in the background_transparent field while we have the mask handy. */
11030 image_background_transparent (img
, f
, mask_img
);
11032 /* Put mask_img into img->mask. */
11033 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
11034 x_destroy_x_image (mask_img
);
11035 XDestroyImage (ximg
);
11044 /***********************************************************************
11045 PBM (mono, gray, color)
11046 ***********************************************************************/
11048 static int pbm_image_p
P_ ((Lisp_Object object
));
11049 static int pbm_load
P_ ((struct frame
*f
, struct image
*img
));
11050 static int pbm_scan_number
P_ ((unsigned char **, unsigned char *));
11052 /* The symbol `pbm' identifying images of this type. */
11056 /* Indices of image specification fields in gs_format, below. */
11058 enum pbm_keyword_index
11067 PBM_HEURISTIC_MASK
,
11074 /* Vector of image_keyword structures describing the format
11075 of valid user-defined image specifications. */
11077 static struct image_keyword pbm_format
[PBM_LAST
] =
11079 {":type", IMAGE_SYMBOL_VALUE
, 1},
11080 {":file", IMAGE_STRING_VALUE
, 0},
11081 {":data", IMAGE_STRING_VALUE
, 0},
11082 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11083 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
11084 {":relief", IMAGE_INTEGER_VALUE
, 0},
11085 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11086 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11087 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11088 {":foreground", IMAGE_STRING_OR_NIL_VALUE
, 0},
11089 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
11092 /* Structure describing the image type `pbm'. */
11094 static struct image_type pbm_type
=
11104 /* Return non-zero if OBJECT is a valid PBM image specification. */
11107 pbm_image_p (object
)
11108 Lisp_Object object
;
11110 struct image_keyword fmt
[PBM_LAST
];
11112 bcopy (pbm_format
, fmt
, sizeof fmt
);
11114 if (!parse_image_spec (object
, fmt
, PBM_LAST
, Qpbm
)
11115 || (fmt
[PBM_ASCENT
].count
11116 && XFASTINT (fmt
[PBM_ASCENT
].value
) > 100))
11119 /* Must specify either :data or :file. */
11120 return fmt
[PBM_DATA
].count
+ fmt
[PBM_FILE
].count
== 1;
11124 /* Scan a decimal number from *S and return it. Advance *S while
11125 reading the number. END is the end of the string. Value is -1 at
11129 pbm_scan_number (s
, end
)
11130 unsigned char **s
, *end
;
11136 /* Skip white-space. */
11137 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
11142 /* Skip comment to end of line. */
11143 while (*s
< end
&& (c
= *(*s
)++, c
!= '\n'))
11146 else if (isdigit (c
))
11148 /* Read decimal number. */
11150 while (*s
< end
&& (c
= *(*s
)++, isdigit (c
)))
11151 val
= 10 * val
+ c
- '0';
11162 /* Read FILE into memory. Value is a pointer to a buffer allocated
11163 with xmalloc holding FILE's contents. Value is null if an error
11164 occured. *SIZE is set to the size of the file. */
11167 pbm_read_file (file
, size
)
11175 if (stat (XSTRING (file
)->data
, &st
) == 0
11176 && (fp
= fopen (XSTRING (file
)->data
, "r")) != NULL
11177 && (buf
= (char *) xmalloc (st
.st_size
),
11178 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
11180 *size
= st
.st_size
;
11198 /* Load PBM image IMG for use on frame F. */
11206 int width
, height
, max_color_idx
= 0;
11208 Lisp_Object file
, specified_file
;
11209 enum {PBM_MONO
, PBM_GRAY
, PBM_COLOR
} type
;
11210 struct gcpro gcpro1
;
11211 unsigned char *contents
= NULL
;
11212 unsigned char *end
, *p
;
11215 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11219 if (STRINGP (specified_file
))
11221 file
= x_find_image_file (specified_file
);
11222 if (!STRINGP (file
))
11224 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
11229 contents
= slurp_file (XSTRING (file
)->data
, &size
);
11230 if (contents
== NULL
)
11232 image_error ("Error reading `%s'", file
, Qnil
);
11238 end
= contents
+ size
;
11243 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11244 p
= XSTRING (data
)->data
;
11245 end
= p
+ STRING_BYTES (XSTRING (data
));
11248 /* Check magic number. */
11249 if (end
- p
< 2 || *p
++ != 'P')
11251 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
11261 raw_p
= 0, type
= PBM_MONO
;
11265 raw_p
= 0, type
= PBM_GRAY
;
11269 raw_p
= 0, type
= PBM_COLOR
;
11273 raw_p
= 1, type
= PBM_MONO
;
11277 raw_p
= 1, type
= PBM_GRAY
;
11281 raw_p
= 1, type
= PBM_COLOR
;
11285 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
11289 /* Read width, height, maximum color-component. Characters
11290 starting with `#' up to the end of a line are ignored. */
11291 width
= pbm_scan_number (&p
, end
);
11292 height
= pbm_scan_number (&p
, end
);
11294 if (type
!= PBM_MONO
)
11296 max_color_idx
= pbm_scan_number (&p
, end
);
11297 if (raw_p
&& max_color_idx
> 255)
11298 max_color_idx
= 255;
11303 || (type
!= PBM_MONO
&& max_color_idx
< 0))
11306 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11309 #if 0 /* TODO: color tables. */
11310 /* Initialize the color hash table. */
11311 init_color_table ();
11314 if (type
== PBM_MONO
)
11317 struct image_keyword fmt
[PBM_LAST
];
11318 unsigned long fg
= FRAME_FOREGROUND_PIXEL (f
);
11319 unsigned long bg
= FRAME_BACKGROUND_PIXEL (f
);
11321 /* Parse the image specification. */
11322 bcopy (pbm_format
, fmt
, sizeof fmt
);
11323 parse_image_spec (img
->spec
, fmt
, PBM_LAST
, Qpbm
);
11325 /* Get foreground and background colors, maybe allocate colors. */
11326 if (fmt
[PBM_FOREGROUND
].count
11327 && STRINGP (fmt
[PBM_FOREGROUND
].value
))
11328 fg
= x_alloc_image_color (f
, img
, fmt
[PBM_FOREGROUND
].value
, fg
);
11329 if (fmt
[PBM_BACKGROUND
].count
11330 && STRINGP (fmt
[PBM_BACKGROUND
].value
))
11332 bg
= x_alloc_image_color (f
, img
, fmt
[PBM_BACKGROUND
].value
, bg
);
11333 img
->background
= bg
;
11334 img
->background_valid
= 1;
11337 for (y
= 0; y
< height
; ++y
)
11338 for (x
= 0; x
< width
; ++x
)
11348 g
= pbm_scan_number (&p
, end
);
11350 XPutPixel (ximg
, x
, y
, g
? fg
: bg
);
11355 for (y
= 0; y
< height
; ++y
)
11356 for (x
= 0; x
< width
; ++x
)
11360 if (type
== PBM_GRAY
)
11361 r
= g
= b
= raw_p
? *p
++ : pbm_scan_number (&p
, end
);
11370 r
= pbm_scan_number (&p
, end
);
11371 g
= pbm_scan_number (&p
, end
);
11372 b
= pbm_scan_number (&p
, end
);
11375 if (r
< 0 || g
< 0 || b
< 0)
11377 x_destroy_x_image (ximg
);
11378 image_error ("Invalid pixel value in image `%s'",
11383 /* RGB values are now in the range 0..max_color_idx.
11384 Scale this to the range 0..0xff supported by W32. */
11385 r
= (int) ((double) r
* 255 / max_color_idx
);
11386 g
= (int) ((double) g
* 255 / max_color_idx
);
11387 b
= (int) ((double) b
* 255 / max_color_idx
);
11388 XPutPixel (ximg
, x
, y
,
11389 #if 0 /* TODO: color tables. */
11390 lookup_rgb_color (f
, r
, g
, b
));
11392 PALETTERGB (r
, g
, b
));
11397 #if 0 /* TODO: color tables. */
11398 /* Store in IMG->colors the colors allocated for the image, and
11399 free the color table. */
11400 img
->colors
= colors_in_color_table (&img
->ncolors
);
11401 free_color_table ();
11403 /* Maybe fill in the background field while we have ximg handy. */
11404 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
11405 IMAGE_BACKGROUND (img
, f
, ximg
);
11407 /* Put the image into a pixmap. */
11408 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11409 x_destroy_x_image (ximg
);
11411 img
->width
= width
;
11412 img
->height
= height
;
11420 /***********************************************************************
11422 ***********************************************************************/
11428 /* Function prototypes. */
11430 static int png_image_p
P_ ((Lisp_Object object
));
11431 static int png_load
P_ ((struct frame
*f
, struct image
*img
));
11433 /* The symbol `png' identifying images of this type. */
11437 /* Indices of image specification fields in png_format, below. */
11439 enum png_keyword_index
11448 PNG_HEURISTIC_MASK
,
11454 /* Vector of image_keyword structures describing the format
11455 of valid user-defined image specifications. */
11457 static struct image_keyword png_format
[PNG_LAST
] =
11459 {":type", IMAGE_SYMBOL_VALUE
, 1},
11460 {":data", IMAGE_STRING_VALUE
, 0},
11461 {":file", IMAGE_STRING_VALUE
, 0},
11462 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11463 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
11464 {":relief", IMAGE_INTEGER_VALUE
, 0},
11465 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11466 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11467 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11468 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
11471 /* Structure describing the image type `png'. */
11473 static struct image_type png_type
=
11483 /* Return non-zero if OBJECT is a valid PNG image specification. */
11486 png_image_p (object
)
11487 Lisp_Object object
;
11489 struct image_keyword fmt
[PNG_LAST
];
11490 bcopy (png_format
, fmt
, sizeof fmt
);
11492 if (!parse_image_spec (object
, fmt
, PNG_LAST
, Qpng
)
11493 || (fmt
[PNG_ASCENT
].count
11494 && XFASTINT (fmt
[PNG_ASCENT
].value
) > 100))
11497 /* Must specify either the :data or :file keyword. */
11498 return fmt
[PNG_FILE
].count
+ fmt
[PNG_DATA
].count
== 1;
11502 /* Error and warning handlers installed when the PNG library
11506 my_png_error (png_ptr
, msg
)
11507 png_struct
*png_ptr
;
11510 xassert (png_ptr
!= NULL
);
11511 image_error ("PNG error: %s", build_string (msg
), Qnil
);
11512 longjmp (png_ptr
->jmpbuf
, 1);
11517 my_png_warning (png_ptr
, msg
)
11518 png_struct
*png_ptr
;
11521 xassert (png_ptr
!= NULL
);
11522 image_error ("PNG warning: %s", build_string (msg
), Qnil
);
11525 /* Memory source for PNG decoding. */
11527 struct png_memory_storage
11529 unsigned char *bytes
; /* The data */
11530 size_t len
; /* How big is it? */
11531 int index
; /* Where are we? */
11535 /* Function set as reader function when reading PNG image from memory.
11536 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH
11537 bytes from the input to DATA. */
11540 png_read_from_memory (png_ptr
, data
, length
)
11541 png_structp png_ptr
;
11545 struct png_memory_storage
*tbr
11546 = (struct png_memory_storage
*) png_get_io_ptr (png_ptr
);
11548 if (length
> tbr
->len
- tbr
->index
)
11549 png_error (png_ptr
, "Read error");
11551 bcopy (tbr
->bytes
+ tbr
->index
, data
, length
);
11552 tbr
->index
= tbr
->index
+ length
;
11555 /* Load PNG image IMG for use on frame F. Value is non-zero if
11563 Lisp_Object file
, specified_file
;
11564 Lisp_Object specified_data
;
11566 XImage
*ximg
, *mask_img
= NULL
;
11567 struct gcpro gcpro1
;
11568 png_struct
*png_ptr
= NULL
;
11569 png_info
*info_ptr
= NULL
, *end_info
= NULL
;
11570 FILE *volatile fp
= NULL
;
11572 png_byte
*volatile pixels
= NULL
;
11573 png_byte
**volatile rows
= NULL
;
11574 png_uint_32 width
, height
;
11575 int bit_depth
, color_type
, interlace_type
;
11577 png_uint_32 row_bytes
;
11580 double screen_gamma
, image_gamma
;
11582 struct png_memory_storage tbr
; /* Data to be read */
11584 /* Find out what file to load. */
11585 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11586 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11590 if (NILP (specified_data
))
11592 file
= x_find_image_file (specified_file
);
11593 if (!STRINGP (file
))
11595 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
11600 /* Open the image file. */
11601 fp
= fopen (XSTRING (file
)->data
, "rb");
11604 image_error ("Cannot open image file `%s'", file
, Qnil
);
11610 /* Check PNG signature. */
11611 if (fread (sig
, 1, sizeof sig
, fp
) != sizeof sig
11612 || !png_check_sig (sig
, sizeof sig
))
11614 image_error ("Not a PNG file:` %s'", file
, Qnil
);
11622 /* Read from memory. */
11623 tbr
.bytes
= XSTRING (specified_data
)->data
;
11624 tbr
.len
= STRING_BYTES (XSTRING (specified_data
));
11627 /* Check PNG signature. */
11628 if (tbr
.len
< sizeof sig
11629 || !png_check_sig (tbr
.bytes
, sizeof sig
))
11631 image_error ("Not a PNG image: `%s'", img
->spec
, Qnil
);
11636 /* Need to skip past the signature. */
11637 tbr
.bytes
+= sizeof (sig
);
11640 /* Initialize read and info structs for PNG lib. */
11641 png_ptr
= png_create_read_struct (PNG_LIBPNG_VER_STRING
, NULL
,
11642 my_png_error
, my_png_warning
);
11645 if (fp
) fclose (fp
);
11650 info_ptr
= png_create_info_struct (png_ptr
);
11653 png_destroy_read_struct (&png_ptr
, NULL
, NULL
);
11654 if (fp
) fclose (fp
);
11659 end_info
= png_create_info_struct (png_ptr
);
11662 png_destroy_read_struct (&png_ptr
, &info_ptr
, NULL
);
11663 if (fp
) fclose (fp
);
11668 /* Set error jump-back. We come back here when the PNG library
11669 detects an error. */
11670 if (setjmp (png_ptr
->jmpbuf
))
11674 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
11677 if (fp
) fclose (fp
);
11682 /* Read image info. */
11683 if (!NILP (specified_data
))
11684 png_set_read_fn (png_ptr
, (void *) &tbr
, png_read_from_memory
);
11686 png_init_io (png_ptr
, fp
);
11688 png_set_sig_bytes (png_ptr
, sizeof sig
);
11689 png_read_info (png_ptr
, info_ptr
);
11690 png_get_IHDR (png_ptr
, info_ptr
, &width
, &height
, &bit_depth
, &color_type
,
11691 &interlace_type
, NULL
, NULL
);
11693 /* If image contains simply transparency data, we prefer to
11694 construct a clipping mask. */
11695 if (png_get_valid (png_ptr
, info_ptr
, PNG_INFO_tRNS
))
11700 /* This function is easier to write if we only have to handle
11701 one data format: RGB or RGBA with 8 bits per channel. Let's
11702 transform other formats into that format. */
11704 /* Strip more than 8 bits per channel. */
11705 if (bit_depth
== 16)
11706 png_set_strip_16 (png_ptr
);
11708 /* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha channel
11710 png_set_expand (png_ptr
);
11712 /* Convert grayscale images to RGB. */
11713 if (color_type
== PNG_COLOR_TYPE_GRAY
11714 || color_type
== PNG_COLOR_TYPE_GRAY_ALPHA
)
11715 png_set_gray_to_rgb (png_ptr
);
11717 /* The value 2.2 is a guess for PC monitors from PNG example.c. */
11718 gamma_str
= getenv ("SCREEN_GAMMA");
11719 screen_gamma
= gamma_str
? atof (gamma_str
) : 2.2;
11721 /* Tell the PNG lib to handle gamma correction for us. */
11723 #if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
11724 if (png_get_sRGB (png_ptr
, info_ptr
, &intent
))
11725 /* There is a special chunk in the image specifying the gamma. */
11726 png_set_sRGB (png_ptr
, info_ptr
, intent
);
11729 if (png_get_gAMA (png_ptr
, info_ptr
, &image_gamma
))
11730 /* Image contains gamma information. */
11731 png_set_gamma (png_ptr
, screen_gamma
, image_gamma
);
11733 /* Use a default of 0.5 for the image gamma. */
11734 png_set_gamma (png_ptr
, screen_gamma
, 0.5);
11736 /* Handle alpha channel by combining the image with a background
11737 color. Do this only if a real alpha channel is supplied. For
11738 simple transparency, we prefer a clipping mask. */
11739 if (!transparent_p
)
11741 png_color_16
*image_background
;
11742 Lisp_Object specified_bg
11743 = image_spec_value (img
->spec
, QCbackground
, NULL
);
11746 if (STRINGP (specified_bg
))
11747 /* The user specified `:background', use that. */
11750 if (w32_defined_color (f
, XSTRING (specified_bg
)->data
, &color
, 0))
11752 png_color_16 user_bg
;
11754 bzero (&user_bg
, sizeof user_bg
);
11755 user_bg
.red
= color
.red
;
11756 user_bg
.green
= color
.green
;
11757 user_bg
.blue
= color
.blue
;
11759 png_set_background (png_ptr
, &user_bg
,
11760 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
11763 else if (png_get_bKGD (png_ptr
, info_ptr
, &image_background
))
11764 /* Image contains a background color with which to
11765 combine the image. */
11766 png_set_background (png_ptr
, image_background
,
11767 PNG_BACKGROUND_GAMMA_FILE
, 1, 1.0);
11770 /* Image does not contain a background color with which
11771 to combine the image data via an alpha channel. Use
11772 the frame's background instead. */
11775 png_color_16 frame_background
;
11777 cmap
= FRAME_X_COLORMAP (f
);
11778 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
11779 x_query_color (f
, &color
);
11781 bzero (&frame_background
, sizeof frame_background
);
11782 frame_background
.red
= color
.red
;
11783 frame_background
.green
= color
.green
;
11784 frame_background
.blue
= color
.blue
;
11786 png_set_background (png_ptr
, &frame_background
,
11787 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
11791 /* Update info structure. */
11792 png_read_update_info (png_ptr
, info_ptr
);
11794 /* Get number of channels. Valid values are 1 for grayscale images
11795 and images with a palette, 2 for grayscale images with transparency
11796 information (alpha channel), 3 for RGB images, and 4 for RGB
11797 images with alpha channel, i.e. RGBA. If conversions above were
11798 sufficient we should only have 3 or 4 channels here. */
11799 channels
= png_get_channels (png_ptr
, info_ptr
);
11800 xassert (channels
== 3 || channels
== 4);
11802 /* Number of bytes needed for one row of the image. */
11803 row_bytes
= png_get_rowbytes (png_ptr
, info_ptr
);
11805 /* Allocate memory for the image. */
11806 pixels
= (png_byte
*) xmalloc (row_bytes
* height
* sizeof *pixels
);
11807 rows
= (png_byte
**) xmalloc (height
* sizeof *rows
);
11808 for (i
= 0; i
< height
; ++i
)
11809 rows
[i
] = pixels
+ i
* row_bytes
;
11811 /* Read the entire image. */
11812 png_read_image (png_ptr
, rows
);
11813 png_read_end (png_ptr
, info_ptr
);
11820 /* Create the X image and pixmap. */
11821 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
11825 /* Create an image and pixmap serving as mask if the PNG image
11826 contains an alpha channel. */
11829 && !x_create_x_image_and_pixmap (f
, width
, height
, 1,
11830 &mask_img
, &img
->mask
))
11832 x_destroy_x_image (ximg
);
11833 XFreePixmap (FRAME_W32_DISPLAY (f
), img
->pixmap
);
11838 /* Fill the X image and mask from PNG data. */
11839 init_color_table ();
11841 for (y
= 0; y
< height
; ++y
)
11843 png_byte
*p
= rows
[y
];
11845 for (x
= 0; x
< width
; ++x
)
11852 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
11854 /* An alpha channel, aka mask channel, associates variable
11855 transparency with an image. Where other image formats
11856 support binary transparency---fully transparent or fully
11857 opaque---PNG allows up to 254 levels of partial transparency.
11858 The PNG library implements partial transparency by combining
11859 the image with a specified background color.
11861 I'm not sure how to handle this here nicely: because the
11862 background on which the image is displayed may change, for
11863 real alpha channel support, it would be necessary to create
11864 a new image for each possible background.
11866 What I'm doing now is that a mask is created if we have
11867 boolean transparency information. Otherwise I'm using
11868 the frame's background color to combine the image with. */
11873 XPutPixel (mask_img
, x
, y
, *p
> 0);
11879 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
11880 /* Set IMG's background color from the PNG image, unless the user
11884 if (png_get_bKGD (png_ptr
, info_ptr
, &bg
))
11886 img
->background
= lookup_rgb_color (f
, bg
->red
, bg
->green
, bg
->blue
);
11887 img
->background_valid
= 1;
11891 /* Remember colors allocated for this image. */
11892 img
->colors
= colors_in_color_table (&img
->ncolors
);
11893 free_color_table ();
11896 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
11900 img
->width
= width
;
11901 img
->height
= height
;
11903 /* Maybe fill in the background field while we have ximg handy. */
11904 IMAGE_BACKGROUND (img
, f
, ximg
);
11906 /* Put the image into the pixmap, then free the X image and its buffer. */
11907 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11908 x_destroy_x_image (ximg
);
11910 /* Same for the mask. */
11913 /* Fill in the background_transparent field while we have the mask
11915 image_background_transparent (img
, f
, mask_img
);
11917 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
11918 x_destroy_x_image (mask_img
);
11925 #endif /* HAVE_PNG != 0 */
11929 /***********************************************************************
11931 ***********************************************************************/
11935 /* Work around a warning about HAVE_STDLIB_H being redefined in
11937 #ifdef HAVE_STDLIB_H
11938 #define HAVE_STDLIB_H_1
11939 #undef HAVE_STDLIB_H
11940 #endif /* HAVE_STLIB_H */
11942 #include <jpeglib.h>
11943 #include <jerror.h>
11944 #include <setjmp.h>
11946 #ifdef HAVE_STLIB_H_1
11947 #define HAVE_STDLIB_H 1
11950 static int jpeg_image_p
P_ ((Lisp_Object object
));
11951 static int jpeg_load
P_ ((struct frame
*f
, struct image
*img
));
11953 /* The symbol `jpeg' identifying images of this type. */
11957 /* Indices of image specification fields in gs_format, below. */
11959 enum jpeg_keyword_index
11968 JPEG_HEURISTIC_MASK
,
11974 /* Vector of image_keyword structures describing the format
11975 of valid user-defined image specifications. */
11977 static struct image_keyword jpeg_format
[JPEG_LAST
] =
11979 {":type", IMAGE_SYMBOL_VALUE
, 1},
11980 {":data", IMAGE_STRING_VALUE
, 0},
11981 {":file", IMAGE_STRING_VALUE
, 0},
11982 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11983 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
11984 {":relief", IMAGE_INTEGER_VALUE
, 0},
11985 {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11986 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11987 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11988 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
11991 /* Structure describing the image type `jpeg'. */
11993 static struct image_type jpeg_type
=
12003 /* Return non-zero if OBJECT is a valid JPEG image specification. */
12006 jpeg_image_p (object
)
12007 Lisp_Object object
;
12009 struct image_keyword fmt
[JPEG_LAST
];
12011 bcopy (jpeg_format
, fmt
, sizeof fmt
);
12013 if (!parse_image_spec (object
, fmt
, JPEG_LAST
, Qjpeg
)
12014 || (fmt
[JPEG_ASCENT
].count
12015 && XFASTINT (fmt
[JPEG_ASCENT
].value
) > 100))
12018 /* Must specify either the :data or :file keyword. */
12019 return fmt
[JPEG_FILE
].count
+ fmt
[JPEG_DATA
].count
== 1;
12023 struct my_jpeg_error_mgr
12025 struct jpeg_error_mgr pub
;
12026 jmp_buf setjmp_buffer
;
12030 my_error_exit (cinfo
)
12031 j_common_ptr cinfo
;
12033 struct my_jpeg_error_mgr
*mgr
= (struct my_jpeg_error_mgr
*) cinfo
->err
;
12034 longjmp (mgr
->setjmp_buffer
, 1);
12037 /* Init source method for JPEG data source manager. Called by
12038 jpeg_read_header() before any data is actually read. See
12039 libjpeg.doc from the JPEG lib distribution. */
12042 our_init_source (cinfo
)
12043 j_decompress_ptr cinfo
;
12048 /* Fill input buffer method for JPEG data source manager. Called
12049 whenever more data is needed. We read the whole image in one step,
12050 so this only adds a fake end of input marker at the end. */
12053 our_fill_input_buffer (cinfo
)
12054 j_decompress_ptr cinfo
;
12056 /* Insert a fake EOI marker. */
12057 struct jpeg_source_mgr
*src
= cinfo
->src
;
12058 static JOCTET buffer
[2];
12060 buffer
[0] = (JOCTET
) 0xFF;
12061 buffer
[1] = (JOCTET
) JPEG_EOI
;
12063 src
->next_input_byte
= buffer
;
12064 src
->bytes_in_buffer
= 2;
12069 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src
12070 is the JPEG data source manager. */
12073 our_skip_input_data (cinfo
, num_bytes
)
12074 j_decompress_ptr cinfo
;
12077 struct jpeg_source_mgr
*src
= (struct jpeg_source_mgr
*) cinfo
->src
;
12081 if (num_bytes
> src
->bytes_in_buffer
)
12082 ERREXIT (cinfo
, JERR_INPUT_EOF
);
12084 src
->bytes_in_buffer
-= num_bytes
;
12085 src
->next_input_byte
+= num_bytes
;
12090 /* Method to terminate data source. Called by
12091 jpeg_finish_decompress() after all data has been processed. */
12094 our_term_source (cinfo
)
12095 j_decompress_ptr cinfo
;
12100 /* Set up the JPEG lib for reading an image from DATA which contains
12101 LEN bytes. CINFO is the decompression info structure created for
12102 reading the image. */
12105 jpeg_memory_src (cinfo
, data
, len
)
12106 j_decompress_ptr cinfo
;
12110 struct jpeg_source_mgr
*src
;
12112 if (cinfo
->src
== NULL
)
12114 /* First time for this JPEG object? */
12115 cinfo
->src
= (struct jpeg_source_mgr
*)
12116 (*cinfo
->mem
->alloc_small
) ((j_common_ptr
) cinfo
, JPOOL_PERMANENT
,
12117 sizeof (struct jpeg_source_mgr
));
12118 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
12119 src
->next_input_byte
= data
;
12122 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
12123 src
->init_source
= our_init_source
;
12124 src
->fill_input_buffer
= our_fill_input_buffer
;
12125 src
->skip_input_data
= our_skip_input_data
;
12126 src
->resync_to_restart
= jpeg_resync_to_restart
; /* Use default method. */
12127 src
->term_source
= our_term_source
;
12128 src
->bytes_in_buffer
= len
;
12129 src
->next_input_byte
= data
;
12133 /* Load image IMG for use on frame F. Patterned after example.c
12134 from the JPEG lib. */
12141 struct jpeg_decompress_struct cinfo
;
12142 struct my_jpeg_error_mgr mgr
;
12143 Lisp_Object file
, specified_file
;
12144 Lisp_Object specified_data
;
12145 FILE * volatile fp
= NULL
;
12147 int row_stride
, x
, y
;
12148 XImage
*ximg
= NULL
;
12150 unsigned long *colors
;
12152 struct gcpro gcpro1
;
12154 /* Open the JPEG file. */
12155 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
12156 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
12160 if (NILP (specified_data
))
12162 file
= x_find_image_file (specified_file
);
12163 if (!STRINGP (file
))
12165 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
12170 fp
= fopen (XSTRING (file
)->data
, "r");
12173 image_error ("Cannot open `%s'", file
, Qnil
);
12179 /* Customize libjpeg's error handling to call my_error_exit when an
12180 error is detected. This function will perform a longjmp. */
12181 cinfo
.err
= jpeg_std_error (&mgr
.pub
);
12182 mgr
.pub
.error_exit
= my_error_exit
;
12184 if ((rc
= setjmp (mgr
.setjmp_buffer
)) != 0)
12188 /* Called from my_error_exit. Display a JPEG error. */
12189 char buffer
[JMSG_LENGTH_MAX
];
12190 cinfo
.err
->format_message ((j_common_ptr
) &cinfo
, buffer
);
12191 image_error ("Error reading JPEG image `%s': %s", img
->spec
,
12192 build_string (buffer
));
12195 /* Close the input file and destroy the JPEG object. */
12198 jpeg_destroy_decompress (&cinfo
);
12200 /* If we already have an XImage, free that. */
12201 x_destroy_x_image (ximg
);
12203 /* Free pixmap and colors. */
12204 x_clear_image (f
, img
);
12210 /* Create the JPEG decompression object. Let it read from fp.
12211 Read the JPEG image header. */
12212 jpeg_create_decompress (&cinfo
);
12214 if (NILP (specified_data
))
12215 jpeg_stdio_src (&cinfo
, fp
);
12217 jpeg_memory_src (&cinfo
, XSTRING (specified_data
)->data
,
12218 STRING_BYTES (XSTRING (specified_data
)));
12220 jpeg_read_header (&cinfo
, TRUE
);
12222 /* Customize decompression so that color quantization will be used.
12223 Start decompression. */
12224 cinfo
.quantize_colors
= TRUE
;
12225 jpeg_start_decompress (&cinfo
);
12226 width
= img
->width
= cinfo
.output_width
;
12227 height
= img
->height
= cinfo
.output_height
;
12229 /* Create X image and pixmap. */
12230 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
12232 longjmp (mgr
.setjmp_buffer
, 2);
12234 /* Allocate colors. When color quantization is used,
12235 cinfo.actual_number_of_colors has been set with the number of
12236 colors generated, and cinfo.colormap is a two-dimensional array
12237 of color indices in the range 0..cinfo.actual_number_of_colors.
12238 No more than 255 colors will be generated. */
12242 if (cinfo
.out_color_components
> 2)
12243 ir
= 0, ig
= 1, ib
= 2;
12244 else if (cinfo
.out_color_components
> 1)
12245 ir
= 0, ig
= 1, ib
= 0;
12247 ir
= 0, ig
= 0, ib
= 0;
12249 /* Use the color table mechanism because it handles colors that
12250 cannot be allocated nicely. Such colors will be replaced with
12251 a default color, and we don't have to care about which colors
12252 can be freed safely, and which can't. */
12253 init_color_table ();
12254 colors
= (unsigned long *) alloca (cinfo
.actual_number_of_colors
12257 for (i
= 0; i
< cinfo
.actual_number_of_colors
; ++i
)
12259 /* Multiply RGB values with 255 because X expects RGB values
12260 in the range 0..0xffff. */
12261 int r
= cinfo
.colormap
[ir
][i
] << 8;
12262 int g
= cinfo
.colormap
[ig
][i
] << 8;
12263 int b
= cinfo
.colormap
[ib
][i
] << 8;
12264 colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
12267 /* Remember those colors actually allocated. */
12268 img
->colors
= colors_in_color_table (&img
->ncolors
);
12269 free_color_table ();
12273 row_stride
= width
* cinfo
.output_components
;
12274 buffer
= cinfo
.mem
->alloc_sarray ((j_common_ptr
) &cinfo
, JPOOL_IMAGE
,
12276 for (y
= 0; y
< height
; ++y
)
12278 jpeg_read_scanlines (&cinfo
, buffer
, 1);
12279 for (x
= 0; x
< cinfo
.output_width
; ++x
)
12280 XPutPixel (ximg
, x
, y
, colors
[buffer
[0][x
]]);
12284 jpeg_finish_decompress (&cinfo
);
12285 jpeg_destroy_decompress (&cinfo
);
12289 /* Maybe fill in the background field while we have ximg handy. */
12290 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
12291 IMAGE_BACKGROUND (img
, f
, ximg
);
12293 /* Put the image into the pixmap. */
12294 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
12295 x_destroy_x_image (ximg
);
12301 #endif /* HAVE_JPEG */
12305 /***********************************************************************
12307 ***********************************************************************/
12311 #include <tiffio.h>
12313 static int tiff_image_p
P_ ((Lisp_Object object
));
12314 static int tiff_load
P_ ((struct frame
*f
, struct image
*img
));
12316 /* The symbol `tiff' identifying images of this type. */
12320 /* Indices of image specification fields in tiff_format, below. */
12322 enum tiff_keyword_index
12331 TIFF_HEURISTIC_MASK
,
12337 /* Vector of image_keyword structures describing the format
12338 of valid user-defined image specifications. */
12340 static struct image_keyword tiff_format
[TIFF_LAST
] =
12342 {":type", IMAGE_SYMBOL_VALUE
, 1},
12343 {":data", IMAGE_STRING_VALUE
, 0},
12344 {":file", IMAGE_STRING_VALUE
, 0},
12345 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
12346 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
12347 {":relief", IMAGE_INTEGER_VALUE
, 0},
12348 {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12349 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12350 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12351 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
12354 /* Structure describing the image type `tiff'. */
12356 static struct image_type tiff_type
=
12366 /* Return non-zero if OBJECT is a valid TIFF image specification. */
12369 tiff_image_p (object
)
12370 Lisp_Object object
;
12372 struct image_keyword fmt
[TIFF_LAST
];
12373 bcopy (tiff_format
, fmt
, sizeof fmt
);
12375 if (!parse_image_spec (object
, fmt
, TIFF_LAST
, Qtiff
)
12376 || (fmt
[TIFF_ASCENT
].count
12377 && XFASTINT (fmt
[TIFF_ASCENT
].value
) > 100))
12380 /* Must specify either the :data or :file keyword. */
12381 return fmt
[TIFF_FILE
].count
+ fmt
[TIFF_DATA
].count
== 1;
12385 /* Reading from a memory buffer for TIFF images Based on the PNG
12386 memory source, but we have to provide a lot of extra functions.
12389 We really only need to implement read and seek, but I am not
12390 convinced that the TIFF library is smart enough not to destroy
12391 itself if we only hand it the function pointers we need to
12396 unsigned char *bytes
;
12400 tiff_memory_source
;
12403 tiff_read_from_memory (data
, buf
, size
)
12408 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
12410 if (size
> src
->len
- src
->index
)
12411 return (size_t) -1;
12412 bcopy (src
->bytes
+ src
->index
, buf
, size
);
12413 src
->index
+= size
;
12418 tiff_write_from_memory (data
, buf
, size
)
12423 return (size_t) -1;
12427 tiff_seek_in_memory (data
, off
, whence
)
12432 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
12437 case SEEK_SET
: /* Go from beginning of source. */
12441 case SEEK_END
: /* Go from end of source. */
12442 idx
= src
->len
+ off
;
12445 case SEEK_CUR
: /* Go from current position. */
12446 idx
= src
->index
+ off
;
12449 default: /* Invalid `whence'. */
12453 if (idx
> src
->len
|| idx
< 0)
12461 tiff_close_memory (data
)
12469 tiff_mmap_memory (data
, pbase
, psize
)
12474 /* It is already _IN_ memory. */
12479 tiff_unmap_memory (data
, base
, size
)
12484 /* We don't need to do this. */
12488 tiff_size_of_memory (data
)
12491 return ((tiff_memory_source
*) data
)->len
;
12496 tiff_error_handler (title
, format
, ap
)
12497 const char *title
, *format
;
12503 len
= sprintf (buf
, "TIFF error: %s ", title
);
12504 vsprintf (buf
+ len
, format
, ap
);
12505 add_to_log (buf
, Qnil
, Qnil
);
12510 tiff_warning_handler (title
, format
, ap
)
12511 const char *title
, *format
;
12517 len
= sprintf (buf
, "TIFF warning: %s ", title
);
12518 vsprintf (buf
+ len
, format
, ap
);
12519 add_to_log (buf
, Qnil
, Qnil
);
12523 /* Load TIFF image IMG for use on frame F. Value is non-zero if
12531 Lisp_Object file
, specified_file
;
12532 Lisp_Object specified_data
;
12534 int width
, height
, x
, y
;
12538 struct gcpro gcpro1
;
12539 tiff_memory_source memsrc
;
12541 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
12542 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
12546 TIFFSetErrorHandler (tiff_error_handler
);
12547 TIFFSetWarningHandler (tiff_warning_handler
);
12549 if (NILP (specified_data
))
12551 /* Read from a file */
12552 file
= x_find_image_file (specified_file
);
12553 if (!STRINGP (file
))
12555 image_error ("Cannot find image file `%s'", file
, Qnil
);
12560 /* Try to open the image file. */
12561 tiff
= TIFFOpen (XSTRING (file
)->data
, "r");
12564 image_error ("Cannot open `%s'", file
, Qnil
);
12571 /* Memory source! */
12572 memsrc
.bytes
= XSTRING (specified_data
)->data
;
12573 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
12576 tiff
= TIFFClientOpen ("memory_source", "r", &memsrc
,
12577 (TIFFReadWriteProc
) tiff_read_from_memory
,
12578 (TIFFReadWriteProc
) tiff_write_from_memory
,
12579 tiff_seek_in_memory
,
12581 tiff_size_of_memory
,
12583 tiff_unmap_memory
);
12587 image_error ("Cannot open memory source for `%s'", img
->spec
, Qnil
);
12593 /* Get width and height of the image, and allocate a raster buffer
12594 of width x height 32-bit values. */
12595 TIFFGetField (tiff
, TIFFTAG_IMAGEWIDTH
, &width
);
12596 TIFFGetField (tiff
, TIFFTAG_IMAGELENGTH
, &height
);
12597 buf
= (uint32
*) xmalloc (width
* height
* sizeof *buf
);
12599 rc
= TIFFReadRGBAImage (tiff
, width
, height
, buf
, 0);
12603 image_error ("Error reading TIFF image `%s'", img
->spec
, Qnil
);
12609 /* Create the X image and pixmap. */
12610 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
12617 /* Initialize the color table. */
12618 init_color_table ();
12620 /* Process the pixel raster. Origin is in the lower-left corner. */
12621 for (y
= 0; y
< height
; ++y
)
12623 uint32
*row
= buf
+ y
* width
;
12625 for (x
= 0; x
< width
; ++x
)
12627 uint32 abgr
= row
[x
];
12628 int r
= TIFFGetR (abgr
) << 8;
12629 int g
= TIFFGetG (abgr
) << 8;
12630 int b
= TIFFGetB (abgr
) << 8;
12631 XPutPixel (ximg
, x
, height
- 1 - y
, lookup_rgb_color (f
, r
, g
, b
));
12635 /* Remember the colors allocated for the image. Free the color table. */
12636 img
->colors
= colors_in_color_table (&img
->ncolors
);
12637 free_color_table ();
12639 img
->width
= width
;
12640 img
->height
= height
;
12642 /* Maybe fill in the background field while we have ximg handy. */
12643 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
12644 IMAGE_BACKGROUND (img
, f
, ximg
);
12646 /* Put the image into the pixmap, then free the X image and its buffer. */
12647 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
12648 x_destroy_x_image (ximg
);
12655 #endif /* HAVE_TIFF != 0 */
12659 /***********************************************************************
12661 ***********************************************************************/
12665 #include <gif_lib.h>
12667 static int gif_image_p
P_ ((Lisp_Object object
));
12668 static int gif_load
P_ ((struct frame
*f
, struct image
*img
));
12670 /* The symbol `gif' identifying images of this type. */
12674 /* Indices of image specification fields in gif_format, below. */
12676 enum gif_keyword_index
12685 GIF_HEURISTIC_MASK
,
12692 /* Vector of image_keyword structures describing the format
12693 of valid user-defined image specifications. */
12695 static struct image_keyword gif_format
[GIF_LAST
] =
12697 {":type", IMAGE_SYMBOL_VALUE
, 1},
12698 {":data", IMAGE_STRING_VALUE
, 0},
12699 {":file", IMAGE_STRING_VALUE
, 0},
12700 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
12701 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
12702 {":relief", IMAGE_INTEGER_VALUE
, 0},
12703 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12704 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12705 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12706 {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
12707 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
12710 /* Structure describing the image type `gif'. */
12712 static struct image_type gif_type
=
12721 /* Return non-zero if OBJECT is a valid GIF image specification. */
12724 gif_image_p (object
)
12725 Lisp_Object object
;
12727 struct image_keyword fmt
[GIF_LAST
];
12728 bcopy (gif_format
, fmt
, sizeof fmt
);
12730 if (!parse_image_spec (object
, fmt
, GIF_LAST
, Qgif
)
12731 || (fmt
[GIF_ASCENT
].count
12732 && XFASTINT (fmt
[GIF_ASCENT
].value
) > 100))
12735 /* Must specify either the :data or :file keyword. */
12736 return fmt
[GIF_FILE
].count
+ fmt
[GIF_DATA
].count
== 1;
12739 /* Reading a GIF image from memory
12740 Based on the PNG memory stuff to a certain extent. */
12744 unsigned char *bytes
;
12750 /* Make the current memory source available to gif_read_from_memory.
12751 It's done this way because not all versions of libungif support
12752 a UserData field in the GifFileType structure. */
12753 static gif_memory_source
*current_gif_memory_src
;
12756 gif_read_from_memory (file
, buf
, len
)
12761 gif_memory_source
*src
= current_gif_memory_src
;
12763 if (len
> src
->len
- src
->index
)
12766 bcopy (src
->bytes
+ src
->index
, buf
, len
);
12772 /* Load GIF image IMG for use on frame F. Value is non-zero if
12780 Lisp_Object file
, specified_file
;
12781 Lisp_Object specified_data
;
12782 int rc
, width
, height
, x
, y
, i
;
12784 ColorMapObject
*gif_color_map
;
12785 unsigned long pixel_colors
[256];
12787 struct gcpro gcpro1
;
12789 int ino
, image_left
, image_top
, image_width
, image_height
;
12790 gif_memory_source memsrc
;
12791 unsigned char *raster
;
12793 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
12794 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
12798 if (NILP (specified_data
))
12800 file
= x_find_image_file (specified_file
);
12801 if (!STRINGP (file
))
12803 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
12808 /* Open the GIF file. */
12809 gif
= DGifOpenFileName (XSTRING (file
)->data
);
12812 image_error ("Cannot open `%s'", file
, Qnil
);
12819 /* Read from memory! */
12820 current_gif_memory_src
= &memsrc
;
12821 memsrc
.bytes
= XSTRING (specified_data
)->data
;
12822 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
12825 gif
= DGifOpen(&memsrc
, gif_read_from_memory
);
12828 image_error ("Cannot open memory source `%s'", img
->spec
, Qnil
);
12834 /* Read entire contents. */
12835 rc
= DGifSlurp (gif
);
12836 if (rc
== GIF_ERROR
)
12838 image_error ("Error reading `%s'", img
->spec
, Qnil
);
12839 DGifCloseFile (gif
);
12844 image
= image_spec_value (img
->spec
, QCindex
, NULL
);
12845 ino
= INTEGERP (image
) ? XFASTINT (image
) : 0;
12846 if (ino
>= gif
->ImageCount
)
12848 image_error ("Invalid image number `%s' in image `%s'",
12850 DGifCloseFile (gif
);
12855 width
= img
->width
= gif
->SWidth
;
12856 height
= img
->height
= gif
->SHeight
;
12858 /* Create the X image and pixmap. */
12859 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
12861 DGifCloseFile (gif
);
12866 /* Allocate colors. */
12867 gif_color_map
= gif
->SavedImages
[ino
].ImageDesc
.ColorMap
;
12868 if (!gif_color_map
)
12869 gif_color_map
= gif
->SColorMap
;
12870 init_color_table ();
12871 bzero (pixel_colors
, sizeof pixel_colors
);
12873 for (i
= 0; i
< gif_color_map
->ColorCount
; ++i
)
12875 int r
= gif_color_map
->Colors
[i
].Red
<< 8;
12876 int g
= gif_color_map
->Colors
[i
].Green
<< 8;
12877 int b
= gif_color_map
->Colors
[i
].Blue
<< 8;
12878 pixel_colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
12881 img
->colors
= colors_in_color_table (&img
->ncolors
);
12882 free_color_table ();
12884 /* Clear the part of the screen image that are not covered by
12885 the image from the GIF file. Full animated GIF support
12886 requires more than can be done here (see the gif89 spec,
12887 disposal methods). Let's simply assume that the part
12888 not covered by a sub-image is in the frame's background color. */
12889 image_top
= gif
->SavedImages
[ino
].ImageDesc
.Top
;
12890 image_left
= gif
->SavedImages
[ino
].ImageDesc
.Left
;
12891 image_width
= gif
->SavedImages
[ino
].ImageDesc
.Width
;
12892 image_height
= gif
->SavedImages
[ino
].ImageDesc
.Height
;
12894 for (y
= 0; y
< image_top
; ++y
)
12895 for (x
= 0; x
< width
; ++x
)
12896 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
12898 for (y
= image_top
+ image_height
; y
< height
; ++y
)
12899 for (x
= 0; x
< width
; ++x
)
12900 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
12902 for (y
= image_top
; y
< image_top
+ image_height
; ++y
)
12904 for (x
= 0; x
< image_left
; ++x
)
12905 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
12906 for (x
= image_left
+ image_width
; x
< width
; ++x
)
12907 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
12910 /* Read the GIF image into the X image. We use a local variable
12911 `raster' here because RasterBits below is a char *, and invites
12912 problems with bytes >= 0x80. */
12913 raster
= (unsigned char *) gif
->SavedImages
[ino
].RasterBits
;
12915 if (gif
->SavedImages
[ino
].ImageDesc
.Interlace
)
12917 static int interlace_start
[] = {0, 4, 2, 1};
12918 static int interlace_increment
[] = {8, 8, 4, 2};
12920 int row
= interlace_start
[0];
12924 for (y
= 0; y
< image_height
; y
++)
12926 if (row
>= image_height
)
12928 row
= interlace_start
[++pass
];
12929 while (row
>= image_height
)
12930 row
= interlace_start
[++pass
];
12933 for (x
= 0; x
< image_width
; x
++)
12935 int i
= raster
[(y
* image_width
) + x
];
12936 XPutPixel (ximg
, x
+ image_left
, row
+ image_top
,
12940 row
+= interlace_increment
[pass
];
12945 for (y
= 0; y
< image_height
; ++y
)
12946 for (x
= 0; x
< image_width
; ++x
)
12948 int i
= raster
[y
* image_width
+ x
];
12949 XPutPixel (ximg
, x
+ image_left
, y
+ image_top
, pixel_colors
[i
]);
12953 DGifCloseFile (gif
);
12955 /* Maybe fill in the background field while we have ximg handy. */
12956 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
12957 IMAGE_BACKGROUND (img
, f
, ximg
);
12959 /* Put the image into the pixmap, then free the X image and its buffer. */
12960 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
12961 x_destroy_x_image (ximg
);
12967 #endif /* HAVE_GIF != 0 */
12971 /***********************************************************************
12973 ***********************************************************************/
12975 Lisp_Object Qpostscript
;
12977 #ifdef HAVE_GHOSTSCRIPT
12978 static int gs_image_p
P_ ((Lisp_Object object
));
12979 static int gs_load
P_ ((struct frame
*f
, struct image
*img
));
12980 static void gs_clear_image
P_ ((struct frame
*f
, struct image
*img
));
12982 /* The symbol `postscript' identifying images of this type. */
12984 /* Keyword symbols. */
12986 Lisp_Object QCloader
, QCbounding_box
, QCpt_width
, QCpt_height
;
12988 /* Indices of image specification fields in gs_format, below. */
12990 enum gs_keyword_index
13008 /* Vector of image_keyword structures describing the format
13009 of valid user-defined image specifications. */
13011 static struct image_keyword gs_format
[GS_LAST
] =
13013 {":type", IMAGE_SYMBOL_VALUE
, 1},
13014 {":pt-width", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
13015 {":pt-height", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
13016 {":file", IMAGE_STRING_VALUE
, 1},
13017 {":loader", IMAGE_FUNCTION_VALUE
, 0},
13018 {":bounding-box", IMAGE_DONT_CHECK_VALUE_TYPE
, 1},
13019 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
13020 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
13021 {":relief", IMAGE_INTEGER_VALUE
, 0},
13022 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
13023 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
13024 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
13025 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
13028 /* Structure describing the image type `ghostscript'. */
13030 static struct image_type gs_type
=
13040 /* Free X resources of Ghostscript image IMG which is used on frame F. */
13043 gs_clear_image (f
, img
)
13047 /* IMG->data.ptr_val may contain a recorded colormap. */
13048 xfree (img
->data
.ptr_val
);
13049 x_clear_image (f
, img
);
13053 /* Return non-zero if OBJECT is a valid Ghostscript image
13057 gs_image_p (object
)
13058 Lisp_Object object
;
13060 struct image_keyword fmt
[GS_LAST
];
13064 bcopy (gs_format
, fmt
, sizeof fmt
);
13066 if (!parse_image_spec (object
, fmt
, GS_LAST
, Qpostscript
)
13067 || (fmt
[GS_ASCENT
].count
13068 && XFASTINT (fmt
[GS_ASCENT
].value
) > 100))
13071 /* Bounding box must be a list or vector containing 4 integers. */
13072 tem
= fmt
[GS_BOUNDING_BOX
].value
;
13075 for (i
= 0; i
< 4; ++i
, tem
= XCDR (tem
))
13076 if (!CONSP (tem
) || !INTEGERP (XCAR (tem
)))
13081 else if (VECTORP (tem
))
13083 if (XVECTOR (tem
)->size
!= 4)
13085 for (i
= 0; i
< 4; ++i
)
13086 if (!INTEGERP (XVECTOR (tem
)->contents
[i
]))
13096 /* Load Ghostscript image IMG for use on frame F. Value is non-zero
13105 Lisp_Object window_and_pixmap_id
= Qnil
, loader
, pt_height
, pt_width
;
13106 struct gcpro gcpro1
, gcpro2
;
13108 double in_width
, in_height
;
13109 Lisp_Object pixel_colors
= Qnil
;
13111 /* Compute pixel size of pixmap needed from the given size in the
13112 image specification. Sizes in the specification are in pt. 1 pt
13113 = 1/72 in, xdpi and ydpi are stored in the frame's X display
13115 pt_width
= image_spec_value (img
->spec
, QCpt_width
, NULL
);
13116 in_width
= XFASTINT (pt_width
) / 72.0;
13117 img
->width
= in_width
* FRAME_W32_DISPLAY_INFO (f
)->resx
;
13118 pt_height
= image_spec_value (img
->spec
, QCpt_height
, NULL
);
13119 in_height
= XFASTINT (pt_height
) / 72.0;
13120 img
->height
= in_height
* FRAME_W32_DISPLAY_INFO (f
)->resy
;
13122 /* Create the pixmap. */
13124 xassert (img
->pixmap
== 0);
13125 img
->pixmap
= XCreatePixmap (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
13126 img
->width
, img
->height
,
13127 one_w32_display_info
.n_cbits
);
13132 image_error ("Unable to create pixmap for `%s'", img
->spec
, Qnil
);
13136 /* Call the loader to fill the pixmap. It returns a process object
13137 if successful. We do not record_unwind_protect here because
13138 other places in redisplay like calling window scroll functions
13139 don't either. Let the Lisp loader use `unwind-protect' instead. */
13140 GCPRO2 (window_and_pixmap_id
, pixel_colors
);
13142 sprintf (buffer
, "%lu %lu",
13143 (unsigned long) FRAME_W32_WINDOW (f
),
13144 (unsigned long) img
->pixmap
);
13145 window_and_pixmap_id
= build_string (buffer
);
13147 sprintf (buffer
, "%lu %lu",
13148 FRAME_FOREGROUND_PIXEL (f
),
13149 FRAME_BACKGROUND_PIXEL (f
));
13150 pixel_colors
= build_string (buffer
);
13152 XSETFRAME (frame
, f
);
13153 loader
= image_spec_value (img
->spec
, QCloader
, NULL
);
13155 loader
= intern ("gs-load-image");
13157 img
->data
.lisp_val
= call6 (loader
, frame
, img
->spec
,
13158 make_number (img
->width
),
13159 make_number (img
->height
),
13160 window_and_pixmap_id
,
13163 return PROCESSP (img
->data
.lisp_val
);
13167 /* Kill the Ghostscript process that was started to fill PIXMAP on
13168 frame F. Called from XTread_socket when receiving an event
13169 telling Emacs that Ghostscript has finished drawing. */
13172 x_kill_gs_process (pixmap
, f
)
13176 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
13180 /* Find the image containing PIXMAP. */
13181 for (i
= 0; i
< c
->used
; ++i
)
13182 if (c
->images
[i
]->pixmap
== pixmap
)
13185 /* Should someone in between have cleared the image cache, for
13186 instance, give up. */
13190 /* Kill the GS process. We should have found PIXMAP in the image
13191 cache and its image should contain a process object. */
13192 img
= c
->images
[i
];
13193 xassert (PROCESSP (img
->data
.lisp_val
));
13194 Fkill_process (img
->data
.lisp_val
, Qnil
);
13195 img
->data
.lisp_val
= Qnil
;
13197 /* On displays with a mutable colormap, figure out the colors
13198 allocated for the image by looking at the pixels of an XImage for
13200 class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
13201 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
13207 /* Try to get an XImage for img->pixmep. */
13208 ximg
= XGetImage (FRAME_W32_DISPLAY (f
), img
->pixmap
,
13209 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
13214 /* Initialize the color table. */
13215 init_color_table ();
13217 /* For each pixel of the image, look its color up in the
13218 color table. After having done so, the color table will
13219 contain an entry for each color used by the image. */
13220 for (y
= 0; y
< img
->height
; ++y
)
13221 for (x
= 0; x
< img
->width
; ++x
)
13223 unsigned long pixel
= XGetPixel (ximg
, x
, y
);
13224 lookup_pixel_color (f
, pixel
);
13227 /* Record colors in the image. Free color table and XImage. */
13228 img
->colors
= colors_in_color_table (&img
->ncolors
);
13229 free_color_table ();
13230 XDestroyImage (ximg
);
13232 #if 0 /* This doesn't seem to be the case. If we free the colors
13233 here, we get a BadAccess later in x_clear_image when
13234 freeing the colors. */
13235 /* We have allocated colors once, but Ghostscript has also
13236 allocated colors on behalf of us. So, to get the
13237 reference counts right, free them once. */
13239 x_free_colors (FRAME_W32_DISPLAY (f
), cmap
,
13240 img
->colors
, img
->ncolors
, 0);
13244 image_error ("Cannot get X image of `%s'; colors will not be freed",
13250 /* Now that we have the pixmap, compute mask and transform the
13251 image if requested. */
13253 postprocess_image (f
, img
);
13257 #endif /* HAVE_GHOSTSCRIPT */
13260 /***********************************************************************
13262 ***********************************************************************/
13264 DEFUN ("x-change-window-property", Fx_change_window_property
,
13265 Sx_change_window_property
, 2, 3, 0,
13266 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
13267 PROP and VALUE must be strings. FRAME nil or omitted means use the
13268 selected frame. Value is VALUE. */)
13269 (prop
, value
, frame
)
13270 Lisp_Object frame
, prop
, value
;
13272 #if 0 /* TODO : port window properties to W32 */
13273 struct frame
*f
= check_x_frame (frame
);
13276 CHECK_STRING (prop
);
13277 CHECK_STRING (value
);
13280 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
13281 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
13282 prop_atom
, XA_STRING
, 8, PropModeReplace
,
13283 XSTRING (value
)->data
, XSTRING (value
)->size
);
13285 /* Make sure the property is set when we return. */
13286 XFlush (FRAME_W32_DISPLAY (f
));
13295 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
13296 Sx_delete_window_property
, 1, 2, 0,
13297 doc
: /* Remove window property PROP from X window of FRAME.
13298 FRAME nil or omitted means use the selected frame. Value is PROP. */)
13300 Lisp_Object prop
, frame
;
13302 #if 0 /* TODO : port window properties to W32 */
13304 struct frame
*f
= check_x_frame (frame
);
13307 CHECK_STRING (prop
);
13309 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
13310 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
13312 /* Make sure the property is removed when we return. */
13313 XFlush (FRAME_W32_DISPLAY (f
));
13321 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
13323 doc
: /* Value is the value of window property PROP on FRAME.
13324 If FRAME is nil or omitted, use the selected frame. Value is nil
13325 if FRAME hasn't a property with name PROP or if PROP has no string
13328 Lisp_Object prop
, frame
;
13330 #if 0 /* TODO : port window properties to W32 */
13332 struct frame
*f
= check_x_frame (frame
);
13335 Lisp_Object prop_value
= Qnil
;
13336 char *tmp_data
= NULL
;
13339 unsigned long actual_size
, bytes_remaining
;
13341 CHECK_STRING (prop
);
13343 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
13344 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
13345 prop_atom
, 0, 0, False
, XA_STRING
,
13346 &actual_type
, &actual_format
, &actual_size
,
13347 &bytes_remaining
, (unsigned char **) &tmp_data
);
13350 int size
= bytes_remaining
;
13355 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
13356 prop_atom
, 0, bytes_remaining
,
13358 &actual_type
, &actual_format
,
13359 &actual_size
, &bytes_remaining
,
13360 (unsigned char **) &tmp_data
);
13362 prop_value
= make_string (tmp_data
, size
);
13377 /***********************************************************************
13379 ***********************************************************************/
13381 /* If non-null, an asynchronous timer that, when it expires, displays
13382 an hourglass cursor on all frames. */
13384 static struct atimer
*hourglass_atimer
;
13386 /* Non-zero means an hourglass cursor is currently shown. */
13388 static int hourglass_shown_p
;
13390 /* Number of seconds to wait before displaying an hourglass cursor. */
13392 static Lisp_Object Vhourglass_delay
;
13394 /* Default number of seconds to wait before displaying an hourglass
13397 #define DEFAULT_HOURGLASS_DELAY 1
13399 /* Function prototypes. */
13401 static void show_hourglass
P_ ((struct atimer
*));
13402 static void hide_hourglass
P_ ((void));
13405 /* Cancel a currently active hourglass timer, and start a new one. */
13410 #if 0 /* TODO: cursor shape changes. */
13412 int secs
, usecs
= 0;
13414 cancel_hourglass ();
13416 if (INTEGERP (Vhourglass_delay
)
13417 && XINT (Vhourglass_delay
) > 0)
13418 secs
= XFASTINT (Vhourglass_delay
);
13419 else if (FLOATP (Vhourglass_delay
)
13420 && XFLOAT_DATA (Vhourglass_delay
) > 0)
13423 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
13424 secs
= XFASTINT (tem
);
13425 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
13428 secs
= DEFAULT_HOURGLASS_DELAY
;
13430 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
13431 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
13432 show_hourglass
, NULL
);
13437 /* Cancel the hourglass cursor timer if active, hide an hourglass
13438 cursor if shown. */
13441 cancel_hourglass ()
13443 if (hourglass_atimer
)
13445 cancel_atimer (hourglass_atimer
);
13446 hourglass_atimer
= NULL
;
13449 if (hourglass_shown_p
)
13454 /* Timer function of hourglass_atimer. TIMER is equal to
13457 Display an hourglass cursor on all frames by mapping the frames'
13458 hourglass_window. Set the hourglass_p flag in the frames'
13459 output_data.x structure to indicate that an hourglass cursor is
13460 shown on the frames. */
13463 show_hourglass (timer
)
13464 struct atimer
*timer
;
13466 #if 0 /* TODO: cursor shape changes. */
13467 /* The timer implementation will cancel this timer automatically
13468 after this function has run. Set hourglass_atimer to null
13469 so that we know the timer doesn't have to be canceled. */
13470 hourglass_atimer
= NULL
;
13472 if (!hourglass_shown_p
)
13474 Lisp_Object rest
, frame
;
13478 FOR_EACH_FRAME (rest
, frame
)
13479 if (FRAME_W32_P (XFRAME (frame
)))
13481 struct frame
*f
= XFRAME (frame
);
13483 f
->output_data
.w32
->hourglass_p
= 1;
13485 if (!f
->output_data
.w32
->hourglass_window
)
13487 unsigned long mask
= CWCursor
;
13488 XSetWindowAttributes attrs
;
13490 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
13492 f
->output_data
.w32
->hourglass_window
13493 = XCreateWindow (FRAME_X_DISPLAY (f
),
13494 FRAME_OUTER_WINDOW (f
),
13495 0, 0, 32000, 32000, 0, 0,
13501 XMapRaised (FRAME_X_DISPLAY (f
),
13502 f
->output_data
.w32
->hourglass_window
);
13503 XFlush (FRAME_X_DISPLAY (f
));
13506 hourglass_shown_p
= 1;
13513 /* Hide the hourglass cursor on all frames, if it is currently shown. */
13518 #if 0 /* TODO: cursor shape changes. */
13519 if (hourglass_shown_p
)
13521 Lisp_Object rest
, frame
;
13524 FOR_EACH_FRAME (rest
, frame
)
13526 struct frame
*f
= XFRAME (frame
);
13528 if (FRAME_W32_P (f
)
13529 /* Watch out for newly created frames. */
13530 && f
->output_data
.x
->hourglass_window
)
13532 XUnmapWindow (FRAME_X_DISPLAY (f
),
13533 f
->output_data
.x
->hourglass_window
);
13534 /* Sync here because XTread_socket looks at the
13535 hourglass_p flag that is reset to zero below. */
13536 XSync (FRAME_X_DISPLAY (f
), False
);
13537 f
->output_data
.x
->hourglass_p
= 0;
13541 hourglass_shown_p
= 0;
13549 /***********************************************************************
13551 ***********************************************************************/
13553 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
13554 Lisp_Object
, Lisp_Object
));
13555 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
13556 Lisp_Object
, int, int, int *, int *));
13558 /* The frame of a currently visible tooltip. */
13560 Lisp_Object tip_frame
;
13562 /* If non-nil, a timer started that hides the last tooltip when it
13565 Lisp_Object tip_timer
;
13568 /* If non-nil, a vector of 3 elements containing the last args
13569 with which x-show-tip was called. See there. */
13571 Lisp_Object last_show_tip_args
;
13573 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
13575 Lisp_Object Vx_max_tooltip_size
;
13579 unwind_create_tip_frame (frame
)
13582 Lisp_Object deleted
;
13584 deleted
= unwind_create_frame (frame
);
13585 if (EQ (deleted
, Qt
))
13595 /* Create a frame for a tooltip on the display described by DPYINFO.
13596 PARMS is a list of frame parameters. TEXT is the string to
13597 display in the tip frame. Value is the frame.
13599 Note that functions called here, esp. x_default_parameter can
13600 signal errors, for instance when a specified color name is
13601 undefined. We have to make sure that we're in a consistent state
13602 when this happens. */
13605 x_create_tip_frame (dpyinfo
, parms
, text
)
13606 struct w32_display_info
*dpyinfo
;
13607 Lisp_Object parms
, text
;
13610 Lisp_Object frame
, tem
;
13612 long window_prompting
= 0;
13614 int count
= BINDING_STACK_SIZE ();
13615 struct gcpro gcpro1
, gcpro2
, gcpro3
;
13617 int face_change_count_before
= face_change_count
;
13618 Lisp_Object buffer
;
13619 struct buffer
*old_buffer
;
13623 /* Use this general default value to start with until we know if
13624 this frame has a specified name. */
13625 Vx_resource_name
= Vinvocation_name
;
13627 #ifdef MULTI_KBOARD
13628 kb
= dpyinfo
->kboard
;
13630 kb
= &the_only_kboard
;
13633 /* Get the name of the frame to use for resource lookup. */
13634 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
13635 if (!STRINGP (name
)
13636 && !EQ (name
, Qunbound
)
13638 error ("Invalid frame name--not a string or nil");
13639 Vx_resource_name
= name
;
13642 GCPRO3 (parms
, name
, frame
);
13643 /* Make a frame without minibuffer nor mode-line. */
13644 f
= make_frame (0);
13645 f
->wants_modeline
= 0;
13646 XSETFRAME (frame
, f
);
13648 buffer
= Fget_buffer_create (build_string (" *tip*"));
13649 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
);
13650 old_buffer
= current_buffer
;
13651 set_buffer_internal_1 (XBUFFER (buffer
));
13652 current_buffer
->truncate_lines
= Qnil
;
13654 Finsert (1, &text
);
13655 set_buffer_internal_1 (old_buffer
);
13657 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
13658 record_unwind_protect (unwind_create_tip_frame
, frame
);
13660 /* By setting the output method, we're essentially saying that
13661 the frame is live, as per FRAME_LIVE_P. If we get a signal
13662 from this point on, x_destroy_window might screw up reference
13664 f
->output_method
= output_w32
;
13665 f
->output_data
.w32
=
13666 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
13667 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
13669 FRAME_FONTSET (f
) = -1;
13670 f
->icon_name
= Qnil
;
13672 #if 0 /* GLYPH_DEBUG TODO: image support. */
13673 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
13674 dpyinfo_refcount
= dpyinfo
->reference_count
;
13675 #endif /* GLYPH_DEBUG */
13676 #ifdef MULTI_KBOARD
13677 FRAME_KBOARD (f
) = kb
;
13679 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
13680 f
->output_data
.w32
->explicit_parent
= 0;
13682 /* Set the name; the functions to which we pass f expect the name to
13684 if (EQ (name
, Qunbound
) || NILP (name
))
13686 f
->name
= build_string (dpyinfo
->w32_id_name
);
13687 f
->explicit_name
= 0;
13692 f
->explicit_name
= 1;
13693 /* use the frame's title when getting resources for this frame. */
13694 specbind (Qx_resource_name
, name
);
13697 /* Extract the window parameters from the supplied values
13698 that are needed to determine window geometry. */
13702 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
13705 /* First, try whatever font the caller has specified. */
13706 if (STRINGP (font
))
13708 tem
= Fquery_fontset (font
, Qnil
);
13710 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
13712 font
= x_new_font (f
, XSTRING (font
)->data
);
13715 /* Try out a font which we hope has bold and italic variations. */
13716 if (!STRINGP (font
))
13717 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
13718 if (! STRINGP (font
))
13719 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
13720 /* If those didn't work, look for something which will at least work. */
13721 if (! STRINGP (font
))
13722 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
13724 if (! STRINGP (font
))
13725 font
= build_string ("Fixedsys");
13727 x_default_parameter (f
, parms
, Qfont
, font
,
13728 "font", "Font", RES_TYPE_STRING
);
13731 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
13732 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
13733 /* This defaults to 2 in order to match xterm. We recognize either
13734 internalBorderWidth or internalBorder (which is what xterm calls
13736 if (NILP (Fassq (Qinternal_border_width
, parms
)))
13740 value
= w32_get_arg (parms
, Qinternal_border_width
,
13741 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
13742 if (! EQ (value
, Qunbound
))
13743 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
13746 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
13747 "internalBorderWidth", "internalBorderWidth",
13750 /* Also do the stuff which must be set before the window exists. */
13751 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
13752 "foreground", "Foreground", RES_TYPE_STRING
);
13753 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
13754 "background", "Background", RES_TYPE_STRING
);
13755 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
13756 "pointerColor", "Foreground", RES_TYPE_STRING
);
13757 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
13758 "cursorColor", "Foreground", RES_TYPE_STRING
);
13759 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
13760 "borderColor", "BorderColor", RES_TYPE_STRING
);
13762 /* Init faces before x_default_parameter is called for scroll-bar
13763 parameters because that function calls x_set_scroll_bar_width,
13764 which calls change_frame_size, which calls Fset_window_buffer,
13765 which runs hooks, which call Fvertical_motion. At the end, we
13766 end up in init_iterator with a null face cache, which should not
13768 init_frame_faces (f
);
13770 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
13771 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
13773 window_prompting
= x_figure_window_size (f
, parms
);
13775 /* No fringes on tip frame. */
13776 f
->output_data
.w32
->fringes_extra
= 0;
13777 f
->output_data
.w32
->fringe_cols
= 0;
13778 f
->output_data
.w32
->left_fringe_width
= 0;
13779 f
->output_data
.w32
->right_fringe_width
= 0;
13781 if (window_prompting
& XNegative
)
13783 if (window_prompting
& YNegative
)
13784 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
13786 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
13790 if (window_prompting
& YNegative
)
13791 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
13793 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
13796 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
13799 my_create_tip_window (f
);
13804 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
13805 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
13806 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
13807 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
13808 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
13809 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
13811 /* Dimensions, especially f->height, must be done via change_frame_size.
13812 Change will not be effected unless different from the current
13815 height
= f
->height
;
13817 SET_FRAME_WIDTH (f
, 0);
13818 change_frame_size (f
, height
, width
, 1, 0, 0);
13820 /* Set up faces after all frame parameters are known. This call
13821 also merges in face attributes specified for new frames.
13823 Frame parameters may be changed if .Xdefaults contains
13824 specifications for the default font. For example, if there is an
13825 `Emacs.default.attributeBackground: pink', the `background-color'
13826 attribute of the frame get's set, which let's the internal border
13827 of the tooltip frame appear in pink. Prevent this. */
13829 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
13831 /* Set tip_frame here, so that */
13833 call1 (Qface_set_after_frame_default
, frame
);
13835 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
13836 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
13844 /* It is now ok to make the frame official even if we get an error
13845 below. And the frame needs to be on Vframe_list or making it
13846 visible won't work. */
13847 Vframe_list
= Fcons (frame
, Vframe_list
);
13849 /* Now that the frame is official, it counts as a reference to
13851 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
13853 /* Setting attributes of faces of the tooltip frame from resources
13854 and similar will increment face_change_count, which leads to the
13855 clearing of all current matrices. Since this isn't necessary
13856 here, avoid it by resetting face_change_count to the value it
13857 had before we created the tip frame. */
13858 face_change_count
= face_change_count_before
;
13860 /* Discard the unwind_protect. */
13861 return unbind_to (count
, frame
);
13865 /* Compute where to display tip frame F. PARMS is the list of frame
13866 parameters for F. DX and DY are specified offsets from the current
13867 location of the mouse. WIDTH and HEIGHT are the width and height
13868 of the tooltip. Return coordinates relative to the root window of
13869 the display in *ROOT_X, and *ROOT_Y. */
13872 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
13874 Lisp_Object parms
, dx
, dy
;
13876 int *root_x
, *root_y
;
13878 Lisp_Object left
, top
;
13880 /* User-specified position? */
13881 left
= Fcdr (Fassq (Qleft
, parms
));
13882 top
= Fcdr (Fassq (Qtop
, parms
));
13884 /* Move the tooltip window where the mouse pointer is. Resize and
13886 if (!INTEGERP (left
) || !INTEGERP (top
))
13891 GetCursorPos (&pt
);
13897 if (INTEGERP (top
))
13898 *root_y
= XINT (top
);
13899 else if (*root_y
+ XINT (dy
) - height
< 0)
13900 *root_y
-= XINT (dy
);
13904 *root_y
+= XINT (dy
);
13907 if (INTEGERP (left
))
13908 *root_x
= XINT (left
);
13909 else if (*root_x
+ XINT (dx
) + width
<= FRAME_W32_DISPLAY_INFO (f
)->width
)
13910 /* It fits to the right of the pointer. */
13911 *root_x
+= XINT (dx
);
13912 else if (width
+ XINT (dx
) <= *root_x
)
13913 /* It fits to the left of the pointer. */
13914 *root_x
-= width
+ XINT (dx
);
13916 /* Put it left justified on the screen -- it ought to fit that way. */
13921 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
13922 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
13923 A tooltip window is a small window displaying a string.
13925 FRAME nil or omitted means use the selected frame.
13927 PARMS is an optional list of frame parameters which can be
13928 used to change the tooltip's appearance.
13930 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
13931 means use the default timeout of 5 seconds.
13933 If the list of frame parameters PARAMS contains a `left' parameter,
13934 the tooltip is displayed at that x-position. Otherwise it is
13935 displayed at the mouse position, with offset DX added (default is 5 if
13936 DX isn't specified). Likewise for the y-position; if a `top' frame
13937 parameter is specified, it determines the y-position of the tooltip
13938 window, otherwise it is displayed at the mouse position, with offset
13939 DY added (default is -10).
13941 A tooltip's maximum size is specified by `x-max-tooltip-size'.
13942 Text larger than the specified size is clipped. */)
13943 (string
, frame
, parms
, timeout
, dx
, dy
)
13944 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
13948 int root_x
, root_y
;
13949 struct buffer
*old_buffer
;
13950 struct text_pos pos
;
13951 int i
, width
, height
;
13952 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
13953 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
13954 int count
= BINDING_STACK_SIZE ();
13956 specbind (Qinhibit_redisplay
, Qt
);
13958 GCPRO4 (string
, parms
, frame
, timeout
);
13960 CHECK_STRING (string
);
13961 f
= check_x_frame (frame
);
13962 if (NILP (timeout
))
13963 timeout
= make_number (5);
13965 CHECK_NATNUM (timeout
);
13968 dx
= make_number (5);
13973 dy
= make_number (-10);
13977 if (NILP (last_show_tip_args
))
13978 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
13980 if (!NILP (tip_frame
))
13982 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
13983 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
13984 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
13986 if (EQ (frame
, last_frame
)
13987 && !NILP (Fequal (last_string
, string
))
13988 && !NILP (Fequal (last_parms
, parms
)))
13990 struct frame
*f
= XFRAME (tip_frame
);
13992 /* Only DX and DY have changed. */
13993 if (!NILP (tip_timer
))
13995 Lisp_Object timer
= tip_timer
;
13997 call1 (Qcancel_timer
, timer
);
14001 compute_tip_xy (f
, parms
, dx
, dy
, PIXEL_WIDTH (f
),
14002 PIXEL_HEIGHT (f
), &root_x
, &root_y
);
14004 /* Put tooltip in topmost group and in position. */
14005 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
14006 root_x
, root_y
, 0, 0,
14007 SWP_NOSIZE
| SWP_NOACTIVATE
);
14009 /* Ensure tooltip is on top of other topmost windows (eg menus). */
14010 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
14012 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
14019 /* Hide a previous tip, if any. */
14022 ASET (last_show_tip_args
, 0, string
);
14023 ASET (last_show_tip_args
, 1, frame
);
14024 ASET (last_show_tip_args
, 2, parms
);
14026 /* Add default values to frame parameters. */
14027 if (NILP (Fassq (Qname
, parms
)))
14028 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
14029 if (NILP (Fassq (Qinternal_border_width
, parms
)))
14030 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
14031 if (NILP (Fassq (Qborder_width
, parms
)))
14032 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
14033 if (NILP (Fassq (Qborder_color
, parms
)))
14034 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
14035 if (NILP (Fassq (Qbackground_color
, parms
)))
14036 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
14039 /* Block input until the tip has been fully drawn, to avoid crashes
14040 when drawing tips in menus. */
14043 /* Create a frame for the tooltip, and record it in the global
14044 variable tip_frame. */
14045 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
14046 f
= XFRAME (frame
);
14048 /* Set up the frame's root window. */
14049 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
14050 w
->left
= w
->top
= make_number (0);
14052 if (CONSP (Vx_max_tooltip_size
)
14053 && INTEGERP (XCAR (Vx_max_tooltip_size
))
14054 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
14055 && INTEGERP (XCDR (Vx_max_tooltip_size
))
14056 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
14058 w
->width
= XCAR (Vx_max_tooltip_size
);
14059 w
->height
= XCDR (Vx_max_tooltip_size
);
14063 w
->width
= make_number (80);
14064 w
->height
= make_number (40);
14067 f
->window_width
= XINT (w
->width
);
14069 w
->pseudo_window_p
= 1;
14071 /* Display the tooltip text in a temporary buffer. */
14072 old_buffer
= current_buffer
;
14073 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
14074 current_buffer
->truncate_lines
= Qnil
;
14075 clear_glyph_matrix (w
->desired_matrix
);
14076 clear_glyph_matrix (w
->current_matrix
);
14077 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
14078 try_window (FRAME_ROOT_WINDOW (f
), pos
);
14080 /* Compute width and height of the tooltip. */
14081 width
= height
= 0;
14082 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
14084 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
14085 struct glyph
*last
;
14088 /* Stop at the first empty row at the end. */
14089 if (!row
->enabled_p
|| !row
->displays_text_p
)
14092 /* Let the row go over the full width of the frame. */
14093 row
->full_width_p
= 1;
14095 #ifdef TODO /* Investigate why some fonts need more width than is
14096 calculated for some tooltips. */
14097 /* There's a glyph at the end of rows that is use to place
14098 the cursor there. Don't include the width of this glyph. */
14099 if (row
->used
[TEXT_AREA
])
14101 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
14102 row_width
= row
->pixel_width
- last
->pixel_width
;
14106 row_width
= row
->pixel_width
;
14108 /* TODO: find why tips do not draw along baseline as instructed. */
14109 height
+= row
->height
;
14110 width
= max (width
, row_width
);
14113 /* Add the frame's internal border to the width and height the X
14114 window should have. */
14115 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
14116 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
14118 /* Move the tooltip window where the mouse pointer is. Resize and
14120 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
14123 /* Adjust Window size to take border into account. */
14125 rect
.left
= rect
.top
= 0;
14126 rect
.right
= width
;
14127 rect
.bottom
= height
;
14128 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
14129 FRAME_EXTERNAL_MENU_BAR (f
));
14131 /* Position and size tooltip, and put it in the topmost group. */
14132 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
14133 root_x
, root_y
, rect
.right
- rect
.left
,
14134 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
14136 /* Ensure tooltip is on top of other topmost windows (eg menus). */
14137 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
14139 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
14141 /* Let redisplay know that we have made the frame visible already. */
14142 f
->async_visible
= 1;
14144 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
14147 /* Draw into the window. */
14148 w
->must_be_updated_p
= 1;
14149 update_single_window (w
, 1);
14153 /* Restore original current buffer. */
14154 set_buffer_internal_1 (old_buffer
);
14155 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
14158 /* Let the tip disappear after timeout seconds. */
14159 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
14160 intern ("x-hide-tip"));
14163 return unbind_to (count
, Qnil
);
14167 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
14168 doc
: /* Hide the current tooltip window, if there is any.
14169 Value is t if tooltip was open, nil otherwise. */)
14173 Lisp_Object deleted
, frame
, timer
;
14174 struct gcpro gcpro1
, gcpro2
;
14176 /* Return quickly if nothing to do. */
14177 if (NILP (tip_timer
) && NILP (tip_frame
))
14182 GCPRO2 (frame
, timer
);
14183 tip_frame
= tip_timer
= deleted
= Qnil
;
14185 count
= BINDING_STACK_SIZE ();
14186 specbind (Qinhibit_redisplay
, Qt
);
14187 specbind (Qinhibit_quit
, Qt
);
14190 call1 (Qcancel_timer
, timer
);
14192 if (FRAMEP (frame
))
14194 Fdelete_frame (frame
, Qnil
);
14199 return unbind_to (count
, deleted
);
14204 /***********************************************************************
14205 File selection dialog
14206 ***********************************************************************/
14208 extern Lisp_Object Qfile_name_history
;
14210 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
14211 doc
: /* Read file name, prompting with PROMPT in directory DIR.
14212 Use a file selection dialog.
14213 Select DEFAULT-FILENAME in the dialog's file selection box, if
14214 specified. Ensure that file exists if MUSTMATCH is non-nil. */)
14215 (prompt
, dir
, default_filename
, mustmatch
)
14216 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
14218 struct frame
*f
= SELECTED_FRAME ();
14219 Lisp_Object file
= Qnil
;
14220 int count
= specpdl_ptr
- specpdl
;
14221 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
14222 char filename
[MAX_PATH
+ 1];
14223 char init_dir
[MAX_PATH
+ 1];
14224 int use_dialog_p
= 1;
14226 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
14227 CHECK_STRING (prompt
);
14228 CHECK_STRING (dir
);
14230 /* Create the dialog with PROMPT as title, using DIR as initial
14231 directory and using "*" as pattern. */
14232 dir
= Fexpand_file_name (dir
, Qnil
);
14233 strncpy (init_dir
, XSTRING (dir
)->data
, MAX_PATH
);
14234 init_dir
[MAX_PATH
] = '\0';
14235 unixtodos_filename (init_dir
);
14237 if (STRINGP (default_filename
))
14239 char *file_name_only
;
14240 char *full_path_name
= XSTRING (default_filename
)->data
;
14242 unixtodos_filename (full_path_name
);
14244 file_name_only
= strrchr (full_path_name
, '\\');
14245 if (!file_name_only
)
14246 file_name_only
= full_path_name
;
14251 /* If default_file_name is a directory, don't use the open
14252 file dialog, as it does not support selecting
14254 if (!(*file_name_only
))
14258 strncpy (filename
, file_name_only
, MAX_PATH
);
14259 filename
[MAX_PATH
] = '\0';
14262 filename
[0] = '\0';
14266 OPENFILENAME file_details
;
14268 /* Prevent redisplay. */
14269 specbind (Qinhibit_redisplay
, Qt
);
14272 bzero (&file_details
, sizeof (file_details
));
14273 file_details
.lStructSize
= sizeof (file_details
);
14274 file_details
.hwndOwner
= FRAME_W32_WINDOW (f
);
14275 /* Undocumented Bug in Common File Dialog:
14276 If a filter is not specified, shell links are not resolved. */
14277 file_details
.lpstrFilter
= "ALL Files (*.*)\0*.*\0\0";
14278 file_details
.lpstrFile
= filename
;
14279 file_details
.nMaxFile
= sizeof (filename
);
14280 file_details
.lpstrInitialDir
= init_dir
;
14281 file_details
.lpstrTitle
= XSTRING (prompt
)->data
;
14282 file_details
.Flags
= OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
;
14284 if (!NILP (mustmatch
))
14285 file_details
.Flags
|= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
14287 if (GetOpenFileName (&file_details
))
14289 dostounix_filename (filename
);
14290 file
= DECODE_FILE(build_string (filename
));
14296 file
= unbind_to (count
, file
);
14298 /* Open File dialog will not allow folders to be selected, so resort
14299 to minibuffer completing reads for directories. */
14301 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
14302 dir
, mustmatch
, dir
, Qfile_name_history
,
14303 default_filename
, Qnil
);
14307 /* Make "Cancel" equivalent to C-g. */
14309 Fsignal (Qquit
, Qnil
);
14311 return unbind_to (count
, file
);
14316 /***********************************************************************
14317 w32 specialized functions
14318 ***********************************************************************/
14320 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 2, 0,
14321 doc
: /* Select a font using the W32 font dialog.
14322 Returns an X font string corresponding to the selection. */)
14323 (frame
, include_proportional
)
14324 Lisp_Object frame
, include_proportional
;
14326 FRAME_PTR f
= check_x_frame (frame
);
14334 bzero (&cf
, sizeof (cf
));
14335 bzero (&lf
, sizeof (lf
));
14337 cf
.lStructSize
= sizeof (cf
);
14338 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
14339 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
14341 /* Unless include_proportional is non-nil, limit the selection to
14342 monospaced fonts. */
14343 if (NILP (include_proportional
))
14344 cf
.Flags
|= CF_FIXEDPITCHONLY
;
14346 cf
.lpLogFont
= &lf
;
14348 /* Initialize as much of the font details as we can from the current
14350 hdc
= GetDC (FRAME_W32_WINDOW (f
));
14351 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
14352 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
14353 if (GetTextMetrics (hdc
, &tm
))
14355 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
14356 lf
.lfWeight
= tm
.tmWeight
;
14357 lf
.lfItalic
= tm
.tmItalic
;
14358 lf
.lfUnderline
= tm
.tmUnderlined
;
14359 lf
.lfStrikeOut
= tm
.tmStruckOut
;
14360 lf
.lfCharSet
= tm
.tmCharSet
;
14361 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
14363 SelectObject (hdc
, oldobj
);
14364 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
14366 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
14369 return build_string (buf
);
14372 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
14373 Sw32_send_sys_command
, 1, 2, 0,
14374 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
14375 Some useful values for command are #xf030 to maximise frame (#xf020
14376 to minimize), #xf120 to restore frame to original size, and #xf100
14377 to activate the menubar for keyboard access. #xf140 activates the
14378 screen saver if defined.
14380 If optional parameter FRAME is not specified, use selected frame. */)
14382 Lisp_Object command
, frame
;
14384 FRAME_PTR f
= check_x_frame (frame
);
14386 CHECK_NUMBER (command
);
14388 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
14393 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
14394 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
14395 This is a wrapper around the ShellExecute system function, which
14396 invokes the application registered to handle OPERATION for DOCUMENT.
14397 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be
14398 nil for the default action), and DOCUMENT is typically the name of a
14399 document file or URL, but can also be a program executable to run or
14400 a directory to open in the Windows Explorer.
14402 If DOCUMENT is a program executable, PARAMETERS can be a string
14403 containing command line parameters, but otherwise should be nil.
14405 SHOW-FLAG can be used to control whether the invoked application is hidden
14406 or minimized. If SHOW-FLAG is nil, the application is displayed normally,
14407 otherwise it is an integer representing a ShowWindow flag:
14411 3 - start maximized
14412 6 - start minimized */)
14413 (operation
, document
, parameters
, show_flag
)
14414 Lisp_Object operation
, document
, parameters
, show_flag
;
14416 Lisp_Object current_dir
;
14418 CHECK_STRING (document
);
14420 /* Encode filename and current directory. */
14421 current_dir
= ENCODE_FILE (current_buffer
->directory
);
14422 document
= ENCODE_FILE (document
);
14423 if ((int) ShellExecute (NULL
,
14424 (STRINGP (operation
) ?
14425 XSTRING (operation
)->data
: NULL
),
14426 XSTRING (document
)->data
,
14427 (STRINGP (parameters
) ?
14428 XSTRING (parameters
)->data
: NULL
),
14429 XSTRING (current_dir
)->data
,
14430 (INTEGERP (show_flag
) ?
14431 XINT (show_flag
) : SW_SHOWDEFAULT
))
14434 error ("ShellExecute failed: %s", w32_strerror (0));
14437 /* Lookup virtual keycode from string representing the name of a
14438 non-ascii keystroke into the corresponding virtual key, using
14439 lispy_function_keys. */
14441 lookup_vk_code (char *key
)
14445 for (i
= 0; i
< 256; i
++)
14446 if (lispy_function_keys
[i
] != 0
14447 && strcmp (lispy_function_keys
[i
], key
) == 0)
14453 /* Convert a one-element vector style key sequence to a hot key
14456 w32_parse_hot_key (key
)
14459 /* Copied from Fdefine_key and store_in_keymap. */
14460 register Lisp_Object c
;
14462 int lisp_modifiers
;
14464 struct gcpro gcpro1
;
14466 CHECK_VECTOR (key
);
14468 if (XFASTINT (Flength (key
)) != 1)
14473 c
= Faref (key
, make_number (0));
14475 if (CONSP (c
) && lucid_event_type_list_p (c
))
14476 c
= Fevent_convert_list (c
);
14480 if (! INTEGERP (c
) && ! SYMBOLP (c
))
14481 error ("Key definition is invalid");
14483 /* Work out the base key and the modifiers. */
14486 c
= parse_modifiers (c
);
14487 lisp_modifiers
= Fcar (Fcdr (c
));
14491 vk_code
= lookup_vk_code (XSYMBOL (c
)->name
->data
);
14493 else if (INTEGERP (c
))
14495 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
14496 /* Many ascii characters are their own virtual key code. */
14497 vk_code
= XINT (c
) & CHARACTERBITS
;
14500 if (vk_code
< 0 || vk_code
> 255)
14503 if ((lisp_modifiers
& meta_modifier
) != 0
14504 && !NILP (Vw32_alt_is_meta
))
14505 lisp_modifiers
|= alt_modifier
;
14507 /* Supply defs missing from mingw32. */
14509 #define MOD_ALT 0x0001
14510 #define MOD_CONTROL 0x0002
14511 #define MOD_SHIFT 0x0004
14512 #define MOD_WIN 0x0008
14515 /* Convert lisp modifiers to Windows hot-key form. */
14516 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
14517 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
14518 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
14519 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
14521 return HOTKEY (vk_code
, w32_modifiers
);
14524 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
14525 Sw32_register_hot_key
, 1, 1, 0,
14526 doc
: /* Register KEY as a hot-key combination.
14527 Certain key combinations like Alt-Tab are reserved for system use on
14528 Windows, and therefore are normally intercepted by the system. However,
14529 most of these key combinations can be received by registering them as
14530 hot-keys, overriding their special meaning.
14532 KEY must be a one element key definition in vector form that would be
14533 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
14534 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
14535 is always interpreted as the Windows modifier keys.
14537 The return value is the hotkey-id if registered, otherwise nil. */)
14541 key
= w32_parse_hot_key (key
);
14543 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
14545 /* Reuse an empty slot if possible. */
14546 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
14548 /* Safe to add new key to list, even if we have focus. */
14550 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
14552 XSETCAR (item
, key
);
14554 /* Notify input thread about new hot-key definition, so that it
14555 takes effect without needing to switch focus. */
14556 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
14563 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
14564 Sw32_unregister_hot_key
, 1, 1, 0,
14565 doc
: /* Unregister HOTKEY as a hot-key combination. */)
14571 if (!INTEGERP (key
))
14572 key
= w32_parse_hot_key (key
);
14574 item
= Fmemq (key
, w32_grabbed_keys
);
14578 /* Notify input thread about hot-key definition being removed, so
14579 that it takes effect without needing focus switch. */
14580 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
14581 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
14584 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
14591 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
14592 Sw32_registered_hot_keys
, 0, 0, 0,
14593 doc
: /* Return list of registered hot-key IDs. */)
14596 return Fcopy_sequence (w32_grabbed_keys
);
14599 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
14600 Sw32_reconstruct_hot_key
, 1, 1, 0,
14601 doc
: /* Convert hot-key ID to a lisp key combination. */)
14603 Lisp_Object hotkeyid
;
14605 int vk_code
, w32_modifiers
;
14608 CHECK_NUMBER (hotkeyid
);
14610 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
14611 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
14613 if (lispy_function_keys
[vk_code
])
14614 key
= intern (lispy_function_keys
[vk_code
]);
14616 key
= make_number (vk_code
);
14618 key
= Fcons (key
, Qnil
);
14619 if (w32_modifiers
& MOD_SHIFT
)
14620 key
= Fcons (Qshift
, key
);
14621 if (w32_modifiers
& MOD_CONTROL
)
14622 key
= Fcons (Qctrl
, key
);
14623 if (w32_modifiers
& MOD_ALT
)
14624 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
14625 if (w32_modifiers
& MOD_WIN
)
14626 key
= Fcons (Qhyper
, key
);
14631 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
14632 Sw32_toggle_lock_key
, 1, 2, 0,
14633 doc
: /* Toggle the state of the lock key KEY.
14634 KEY can be `capslock', `kp-numlock', or `scroll'.
14635 If the optional parameter NEW-STATE is a number, then the state of KEY
14636 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
14638 Lisp_Object key
, new_state
;
14642 if (EQ (key
, intern ("capslock")))
14643 vk_code
= VK_CAPITAL
;
14644 else if (EQ (key
, intern ("kp-numlock")))
14645 vk_code
= VK_NUMLOCK
;
14646 else if (EQ (key
, intern ("scroll")))
14647 vk_code
= VK_SCROLL
;
14651 if (!dwWindowsThreadId
)
14652 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
14654 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
14655 (WPARAM
) vk_code
, (LPARAM
) new_state
))
14658 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
14659 return make_number (msg
.wParam
);
14664 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
14665 doc
: /* Return storage information about the file system FILENAME is on.
14666 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
14667 storage of the file system, FREE is the free storage, and AVAIL is the
14668 storage available to a non-superuser. All 3 numbers are in bytes.
14669 If the underlying system call fails, value is nil. */)
14671 Lisp_Object filename
;
14673 Lisp_Object encoded
, value
;
14675 CHECK_STRING (filename
);
14676 filename
= Fexpand_file_name (filename
, Qnil
);
14677 encoded
= ENCODE_FILE (filename
);
14681 /* Determining the required information on Windows turns out, sadly,
14682 to be more involved than one would hope. The original Win32 api
14683 call for this will return bogus information on some systems, but we
14684 must dynamically probe for the replacement api, since that was
14685 added rather late on. */
14687 HMODULE hKernel
= GetModuleHandle ("kernel32");
14688 BOOL (*pfn_GetDiskFreeSpaceEx
)
14689 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
14690 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
14692 /* On Windows, we may need to specify the root directory of the
14693 volume holding FILENAME. */
14694 char rootname
[MAX_PATH
];
14695 char *name
= XSTRING (encoded
)->data
;
14697 /* find the root name of the volume if given */
14698 if (isalpha (name
[0]) && name
[1] == ':')
14700 rootname
[0] = name
[0];
14701 rootname
[1] = name
[1];
14702 rootname
[2] = '\\';
14705 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
14707 char *str
= rootname
;
14711 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
14721 if (pfn_GetDiskFreeSpaceEx
)
14723 /* Unsigned large integers cannot be cast to double, so
14724 use signed ones instead. */
14725 LARGE_INTEGER availbytes
;
14726 LARGE_INTEGER freebytes
;
14727 LARGE_INTEGER totalbytes
;
14729 if (pfn_GetDiskFreeSpaceEx(rootname
,
14730 (ULARGE_INTEGER
*)&availbytes
,
14731 (ULARGE_INTEGER
*)&totalbytes
,
14732 (ULARGE_INTEGER
*)&freebytes
))
14733 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
14734 make_float ((double) freebytes
.QuadPart
),
14735 make_float ((double) availbytes
.QuadPart
));
14739 DWORD sectors_per_cluster
;
14740 DWORD bytes_per_sector
;
14741 DWORD free_clusters
;
14742 DWORD total_clusters
;
14744 if (GetDiskFreeSpace(rootname
,
14745 §ors_per_cluster
,
14749 value
= list3 (make_float ((double) total_clusters
14750 * sectors_per_cluster
* bytes_per_sector
),
14751 make_float ((double) free_clusters
14752 * sectors_per_cluster
* bytes_per_sector
),
14753 make_float ((double) free_clusters
14754 * sectors_per_cluster
* bytes_per_sector
));
14761 /***********************************************************************
14763 ***********************************************************************/
14768 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
14770 /* This is zero if not using MS-Windows. */
14773 /* TrackMouseEvent not available in all versions of Windows, so must load
14774 it dynamically. Do it once, here, instead of every time it is used. */
14775 track_mouse_event_fn
= GetProcAddress (user32_lib
, "TrackMouseEvent");
14776 track_mouse_window
= NULL
;
14778 w32_visible_system_caret_hwnd
= NULL
;
14780 Qauto_raise
= intern ("auto-raise");
14781 staticpro (&Qauto_raise
);
14782 Qauto_lower
= intern ("auto-lower");
14783 staticpro (&Qauto_lower
);
14784 Qbar
= intern ("bar");
14786 Qborder_color
= intern ("border-color");
14787 staticpro (&Qborder_color
);
14788 Qborder_width
= intern ("border-width");
14789 staticpro (&Qborder_width
);
14790 Qbox
= intern ("box");
14792 Qcursor_color
= intern ("cursor-color");
14793 staticpro (&Qcursor_color
);
14794 Qcursor_type
= intern ("cursor-type");
14795 staticpro (&Qcursor_type
);
14796 Qgeometry
= intern ("geometry");
14797 staticpro (&Qgeometry
);
14798 Qicon_left
= intern ("icon-left");
14799 staticpro (&Qicon_left
);
14800 Qicon_top
= intern ("icon-top");
14801 staticpro (&Qicon_top
);
14802 Qicon_type
= intern ("icon-type");
14803 staticpro (&Qicon_type
);
14804 Qicon_name
= intern ("icon-name");
14805 staticpro (&Qicon_name
);
14806 Qinternal_border_width
= intern ("internal-border-width");
14807 staticpro (&Qinternal_border_width
);
14808 Qleft
= intern ("left");
14809 staticpro (&Qleft
);
14810 Qright
= intern ("right");
14811 staticpro (&Qright
);
14812 Qmouse_color
= intern ("mouse-color");
14813 staticpro (&Qmouse_color
);
14814 Qnone
= intern ("none");
14815 staticpro (&Qnone
);
14816 Qparent_id
= intern ("parent-id");
14817 staticpro (&Qparent_id
);
14818 Qscroll_bar_width
= intern ("scroll-bar-width");
14819 staticpro (&Qscroll_bar_width
);
14820 Qsuppress_icon
= intern ("suppress-icon");
14821 staticpro (&Qsuppress_icon
);
14822 Qundefined_color
= intern ("undefined-color");
14823 staticpro (&Qundefined_color
);
14824 Qvertical_scroll_bars
= intern ("vertical-scroll-bars");
14825 staticpro (&Qvertical_scroll_bars
);
14826 Qvisibility
= intern ("visibility");
14827 staticpro (&Qvisibility
);
14828 Qwindow_id
= intern ("window-id");
14829 staticpro (&Qwindow_id
);
14830 Qx_frame_parameter
= intern ("x-frame-parameter");
14831 staticpro (&Qx_frame_parameter
);
14832 Qx_resource_name
= intern ("x-resource-name");
14833 staticpro (&Qx_resource_name
);
14834 Quser_position
= intern ("user-position");
14835 staticpro (&Quser_position
);
14836 Quser_size
= intern ("user-size");
14837 staticpro (&Quser_size
);
14838 Qscreen_gamma
= intern ("screen-gamma");
14839 staticpro (&Qscreen_gamma
);
14840 Qline_spacing
= intern ("line-spacing");
14841 staticpro (&Qline_spacing
);
14842 Qcenter
= intern ("center");
14843 staticpro (&Qcenter
);
14844 Qcancel_timer
= intern ("cancel-timer");
14845 staticpro (&Qcancel_timer
);
14846 Qfullscreen
= intern ("fullscreen");
14847 staticpro (&Qfullscreen
);
14848 Qfullwidth
= intern ("fullwidth");
14849 staticpro (&Qfullwidth
);
14850 Qfullheight
= intern ("fullheight");
14851 staticpro (&Qfullheight
);
14852 Qfullboth
= intern ("fullboth");
14853 staticpro (&Qfullboth
);
14855 Qhyper
= intern ("hyper");
14856 staticpro (&Qhyper
);
14857 Qsuper
= intern ("super");
14858 staticpro (&Qsuper
);
14859 Qmeta
= intern ("meta");
14860 staticpro (&Qmeta
);
14861 Qalt
= intern ("alt");
14863 Qctrl
= intern ("ctrl");
14864 staticpro (&Qctrl
);
14865 Qcontrol
= intern ("control");
14866 staticpro (&Qcontrol
);
14867 Qshift
= intern ("shift");
14868 staticpro (&Qshift
);
14869 /* This is the end of symbol initialization. */
14871 /* Text property `display' should be nonsticky by default. */
14872 Vtext_property_default_nonsticky
14873 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
14876 Qlaplace
= intern ("laplace");
14877 staticpro (&Qlaplace
);
14878 Qemboss
= intern ("emboss");
14879 staticpro (&Qemboss
);
14880 Qedge_detection
= intern ("edge-detection");
14881 staticpro (&Qedge_detection
);
14882 Qheuristic
= intern ("heuristic");
14883 staticpro (&Qheuristic
);
14884 QCmatrix
= intern (":matrix");
14885 staticpro (&QCmatrix
);
14886 QCcolor_adjustment
= intern (":color-adjustment");
14887 staticpro (&QCcolor_adjustment
);
14888 QCmask
= intern (":mask");
14889 staticpro (&QCmask
);
14891 Qface_set_after_frame_default
= intern ("face-set-after-frame-default");
14892 staticpro (&Qface_set_after_frame_default
);
14894 Fput (Qundefined_color
, Qerror_conditions
,
14895 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
14896 Fput (Qundefined_color
, Qerror_message
,
14897 build_string ("Undefined color"));
14899 staticpro (&w32_grabbed_keys
);
14900 w32_grabbed_keys
= Qnil
;
14902 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
14903 doc
: /* An array of color name mappings for windows. */);
14904 Vw32_color_map
= Qnil
;
14906 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
14907 doc
: /* Non-nil if alt key presses are passed on to Windows.
14908 When non-nil, for example, alt pressed and released and then space will
14909 open the System menu. When nil, Emacs silently swallows alt key events. */);
14910 Vw32_pass_alt_to_system
= Qnil
;
14912 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
14913 doc
: /* Non-nil if the alt key is to be considered the same as the meta key.
14914 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta. */);
14915 Vw32_alt_is_meta
= Qt
;
14917 DEFVAR_INT ("w32-quit-key", &Vw32_quit_key
,
14918 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
14919 XSETINT (Vw32_quit_key
, 0);
14921 DEFVAR_LISP ("w32-pass-lwindow-to-system",
14922 &Vw32_pass_lwindow_to_system
,
14923 doc
: /* Non-nil if the left \"Windows\" key is passed on to Windows.
14924 When non-nil, the Start menu is opened by tapping the key. */);
14925 Vw32_pass_lwindow_to_system
= Qt
;
14927 DEFVAR_LISP ("w32-pass-rwindow-to-system",
14928 &Vw32_pass_rwindow_to_system
,
14929 doc
: /* Non-nil if the right \"Windows\" key is passed on to Windows.
14930 When non-nil, the Start menu is opened by tapping the key. */);
14931 Vw32_pass_rwindow_to_system
= Qt
;
14933 DEFVAR_INT ("w32-phantom-key-code",
14934 &Vw32_phantom_key_code
,
14935 doc
: /* Virtual key code used to generate \"phantom\" key presses.
14936 Value is a number between 0 and 255.
14938 Phantom key presses are generated in order to stop the system from
14939 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
14940 `w32-pass-rwindow-to-system' is nil. */);
14941 /* Although 255 is technically not a valid key code, it works and
14942 means that this hack won't interfere with any real key code. */
14943 Vw32_phantom_key_code
= 255;
14945 DEFVAR_LISP ("w32-enable-num-lock",
14946 &Vw32_enable_num_lock
,
14947 doc
: /* Non-nil if Num Lock should act normally.
14948 Set to nil to see Num Lock as the key `kp-numlock'. */);
14949 Vw32_enable_num_lock
= Qt
;
14951 DEFVAR_LISP ("w32-enable-caps-lock",
14952 &Vw32_enable_caps_lock
,
14953 doc
: /* Non-nil if Caps Lock should act normally.
14954 Set to nil to see Caps Lock as the key `capslock'. */);
14955 Vw32_enable_caps_lock
= Qt
;
14957 DEFVAR_LISP ("w32-scroll-lock-modifier",
14958 &Vw32_scroll_lock_modifier
,
14959 doc
: /* Modifier to use for the Scroll Lock on state.
14960 The value can be hyper, super, meta, alt, control or shift for the
14961 respective modifier, or nil to see Scroll Lock as the key `scroll'.
14962 Any other value will cause the key to be ignored. */);
14963 Vw32_scroll_lock_modifier
= Qt
;
14965 DEFVAR_LISP ("w32-lwindow-modifier",
14966 &Vw32_lwindow_modifier
,
14967 doc
: /* Modifier to use for the left \"Windows\" key.
14968 The value can be hyper, super, meta, alt, control or shift for the
14969 respective modifier, or nil to appear as the key `lwindow'.
14970 Any other value will cause the key to be ignored. */);
14971 Vw32_lwindow_modifier
= Qnil
;
14973 DEFVAR_LISP ("w32-rwindow-modifier",
14974 &Vw32_rwindow_modifier
,
14975 doc
: /* Modifier to use for the right \"Windows\" key.
14976 The value can be hyper, super, meta, alt, control or shift for the
14977 respective modifier, or nil to appear as the key `rwindow'.
14978 Any other value will cause the key to be ignored. */);
14979 Vw32_rwindow_modifier
= Qnil
;
14981 DEFVAR_LISP ("w32-apps-modifier",
14982 &Vw32_apps_modifier
,
14983 doc
: /* Modifier to use for the \"Apps\" key.
14984 The value can be hyper, super, meta, alt, control or shift for the
14985 respective modifier, or nil to appear as the key `apps'.
14986 Any other value will cause the key to be ignored. */);
14987 Vw32_apps_modifier
= Qnil
;
14989 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
14990 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
14991 w32_enable_synthesized_fonts
= 0;
14993 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
14994 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
14995 Vw32_enable_palette
= Qt
;
14997 DEFVAR_INT ("w32-mouse-button-tolerance",
14998 &Vw32_mouse_button_tolerance
,
14999 doc
: /* Analogue of double click interval for faking middle mouse events.
15000 The value is the minimum time in milliseconds that must elapse between
15001 left/right button down events before they are considered distinct events.
15002 If both mouse buttons are depressed within this interval, a middle mouse
15003 button down event is generated instead. */);
15004 XSETINT (Vw32_mouse_button_tolerance
, GetDoubleClickTime () / 2);
15006 DEFVAR_INT ("w32-mouse-move-interval",
15007 &Vw32_mouse_move_interval
,
15008 doc
: /* Minimum interval between mouse move events.
15009 The value is the minimum time in milliseconds that must elapse between
15010 successive mouse move (or scroll bar drag) events before they are
15011 reported as lisp events. */);
15012 XSETINT (Vw32_mouse_move_interval
, 0);
15014 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
15015 &w32_pass_extra_mouse_buttons_to_system
,
15016 doc
: /* Non-nil if the fourth and fifth mouse buttons are passed to Windows.
15017 Recent versions of Windows support mice with up to five buttons.
15018 Since most applications don't support these extra buttons, most mouse
15019 drivers will allow you to map them to functions at the system level.
15020 If this variable is non-nil, Emacs will pass them on, allowing the
15021 system to handle them. */);
15022 w32_pass_extra_mouse_buttons_to_system
= 0;
15024 init_x_parm_symbols ();
15026 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
15027 doc
: /* List of directories to search for bitmap files for w32. */);
15028 Vx_bitmap_file_path
= decode_env_path ((char *) 0, "PATH");
15030 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
15031 doc
: /* The shape of the pointer when over text.
15032 Changing the value does not affect existing frames
15033 unless you set the mouse color. */);
15034 Vx_pointer_shape
= Qnil
;
15036 DEFVAR_LISP ("x-resource-name", &Vx_resource_name
,
15037 doc
: /* The name Emacs uses to look up resources; for internal use only.
15038 `x-get-resource' uses this as the first component of the instance name
15039 when requesting resource values.
15040 Emacs initially sets `x-resource-name' to the name under which Emacs
15041 was invoked, or to the value specified with the `-name' or `-rn'
15042 switches, if present. */);
15043 Vx_resource_name
= Qnil
;
15045 Vx_nontext_pointer_shape
= Qnil
;
15047 Vx_mode_pointer_shape
= Qnil
;
15049 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
15050 doc
: /* The shape of the pointer when Emacs is busy.
15051 This variable takes effect when you create a new frame
15052 or when you set the mouse color. */);
15053 Vx_hourglass_pointer_shape
= Qnil
;
15055 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
15056 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
15057 display_hourglass_p
= 1;
15059 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
15060 doc
: /* *Seconds to wait before displaying an hourglass pointer.
15061 Value must be an integer or float. */);
15062 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
15064 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
15065 &Vx_sensitive_text_pointer_shape
,
15066 doc
: /* The shape of the pointer when over mouse-sensitive text.
15067 This variable takes effect when you create a new frame
15068 or when you set the mouse color. */);
15069 Vx_sensitive_text_pointer_shape
= Qnil
;
15071 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
15072 &Vx_window_horizontal_drag_shape
,
15073 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
15074 This variable takes effect when you create a new frame
15075 or when you set the mouse color. */);
15076 Vx_window_horizontal_drag_shape
= Qnil
;
15078 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
15079 doc
: /* A string indicating the foreground color of the cursor box. */);
15080 Vx_cursor_fore_pixel
= Qnil
;
15082 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
15083 doc
: /* Maximum size for tooltips.
15084 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
15085 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
15087 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
15088 doc
: /* Non-nil if no window manager is in use.
15089 Emacs doesn't try to figure this out; this is always nil
15090 unless you set it to something else. */);
15091 /* We don't have any way to find this out, so set it to nil
15092 and maybe the user would like to set it to t. */
15093 Vx_no_window_manager
= Qnil
;
15095 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
15096 &Vx_pixel_size_width_font_regexp
,
15097 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
15099 Since Emacs gets width of a font matching with this regexp from
15100 PIXEL_SIZE field of the name, font finding mechanism gets faster for
15101 such a font. This is especially effective for such large fonts as
15102 Chinese, Japanese, and Korean. */);
15103 Vx_pixel_size_width_font_regexp
= Qnil
;
15105 DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay
,
15106 doc
: /* Time after which cached images are removed from the cache.
15107 When an image has not been displayed this many seconds, remove it
15108 from the image cache. Value must be an integer or nil with nil
15109 meaning don't clear the cache. */);
15110 Vimage_cache_eviction_delay
= make_number (30 * 60);
15112 DEFVAR_LISP ("w32-bdf-filename-alist",
15113 &Vw32_bdf_filename_alist
,
15114 doc
: /* List of bdf fonts and their corresponding filenames. */);
15115 Vw32_bdf_filename_alist
= Qnil
;
15117 DEFVAR_BOOL ("w32-strict-fontnames",
15118 &w32_strict_fontnames
,
15119 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
15120 Default is nil, which allows old fontnames that are not XLFD compliant,
15121 and allows third-party CJK display to work by specifying false charset
15122 fields to trick Emacs into translating to Big5, SJIS etc.
15123 Setting this to t will prevent wrong fonts being selected when
15124 fontsets are automatically created. */);
15125 w32_strict_fontnames
= 0;
15127 DEFVAR_BOOL ("w32-strict-painting",
15128 &w32_strict_painting
,
15129 doc
: /* Non-nil means use strict rules for repainting frames.
15130 Set this to nil to get the old behaviour for repainting; this should
15131 only be necessary if the default setting causes problems. */);
15132 w32_strict_painting
= 1;
15134 DEFVAR_LISP ("w32-charset-info-alist",
15135 &Vw32_charset_info_alist
,
15136 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
15137 Each entry should be of the form:
15139 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
15141 where CHARSET_NAME is a string used in font names to identify the charset,
15142 WINDOWS_CHARSET is a symbol that can be one of:
15143 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
15144 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
15145 w32-charset-chinesebig5,
15146 #ifdef JOHAB_CHARSET
15147 w32-charset-johab, w32-charset-hebrew,
15148 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
15149 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
15150 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
15152 #ifdef UNICODE_CHARSET
15153 w32-charset-unicode,
15155 or w32-charset-oem.
15156 CODEPAGE should be an integer specifying the codepage that should be used
15157 to display the character set, t to do no translation and output as Unicode,
15158 or nil to do no translation and output as 8 bit (or multibyte on far-east
15159 versions of Windows) characters. */);
15160 Vw32_charset_info_alist
= Qnil
;
15162 staticpro (&Qw32_charset_ansi
);
15163 Qw32_charset_ansi
= intern ("w32-charset-ansi");
15164 staticpro (&Qw32_charset_symbol
);
15165 Qw32_charset_symbol
= intern ("w32-charset-symbol");
15166 staticpro (&Qw32_charset_shiftjis
);
15167 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
15168 staticpro (&Qw32_charset_hangeul
);
15169 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
15170 staticpro (&Qw32_charset_chinesebig5
);
15171 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
15172 staticpro (&Qw32_charset_gb2312
);
15173 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
15174 staticpro (&Qw32_charset_oem
);
15175 Qw32_charset_oem
= intern ("w32-charset-oem");
15177 #ifdef JOHAB_CHARSET
15179 static int w32_extra_charsets_defined
= 1;
15180 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
,
15181 doc
: /* Internal variable. */);
15183 staticpro (&Qw32_charset_johab
);
15184 Qw32_charset_johab
= intern ("w32-charset-johab");
15185 staticpro (&Qw32_charset_easteurope
);
15186 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
15187 staticpro (&Qw32_charset_turkish
);
15188 Qw32_charset_turkish
= intern ("w32-charset-turkish");
15189 staticpro (&Qw32_charset_baltic
);
15190 Qw32_charset_baltic
= intern ("w32-charset-baltic");
15191 staticpro (&Qw32_charset_russian
);
15192 Qw32_charset_russian
= intern ("w32-charset-russian");
15193 staticpro (&Qw32_charset_arabic
);
15194 Qw32_charset_arabic
= intern ("w32-charset-arabic");
15195 staticpro (&Qw32_charset_greek
);
15196 Qw32_charset_greek
= intern ("w32-charset-greek");
15197 staticpro (&Qw32_charset_hebrew
);
15198 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
15199 staticpro (&Qw32_charset_vietnamese
);
15200 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
15201 staticpro (&Qw32_charset_thai
);
15202 Qw32_charset_thai
= intern ("w32-charset-thai");
15203 staticpro (&Qw32_charset_mac
);
15204 Qw32_charset_mac
= intern ("w32-charset-mac");
15208 #ifdef UNICODE_CHARSET
15210 static int w32_unicode_charset_defined
= 1;
15211 DEFVAR_BOOL ("w32-unicode-charset-defined",
15212 &w32_unicode_charset_defined
,
15213 doc
: /* Internal variable. */);
15215 staticpro (&Qw32_charset_unicode
);
15216 Qw32_charset_unicode
= intern ("w32-charset-unicode");
15219 defsubr (&Sx_get_resource
);
15220 #if 0 /* TODO: Port to W32 */
15221 defsubr (&Sx_change_window_property
);
15222 defsubr (&Sx_delete_window_property
);
15223 defsubr (&Sx_window_property
);
15225 defsubr (&Sxw_display_color_p
);
15226 defsubr (&Sx_display_grayscale_p
);
15227 defsubr (&Sxw_color_defined_p
);
15228 defsubr (&Sxw_color_values
);
15229 defsubr (&Sx_server_max_request_size
);
15230 defsubr (&Sx_server_vendor
);
15231 defsubr (&Sx_server_version
);
15232 defsubr (&Sx_display_pixel_width
);
15233 defsubr (&Sx_display_pixel_height
);
15234 defsubr (&Sx_display_mm_width
);
15235 defsubr (&Sx_display_mm_height
);
15236 defsubr (&Sx_display_screens
);
15237 defsubr (&Sx_display_planes
);
15238 defsubr (&Sx_display_color_cells
);
15239 defsubr (&Sx_display_visual_class
);
15240 defsubr (&Sx_display_backing_store
);
15241 defsubr (&Sx_display_save_under
);
15242 defsubr (&Sx_parse_geometry
);
15243 defsubr (&Sx_create_frame
);
15244 defsubr (&Sx_open_connection
);
15245 defsubr (&Sx_close_connection
);
15246 defsubr (&Sx_display_list
);
15247 defsubr (&Sx_synchronize
);
15249 /* W32 specific functions */
15251 defsubr (&Sw32_focus_frame
);
15252 defsubr (&Sw32_select_font
);
15253 defsubr (&Sw32_define_rgb_color
);
15254 defsubr (&Sw32_default_color_map
);
15255 defsubr (&Sw32_load_color_file
);
15256 defsubr (&Sw32_send_sys_command
);
15257 defsubr (&Sw32_shell_execute
);
15258 defsubr (&Sw32_register_hot_key
);
15259 defsubr (&Sw32_unregister_hot_key
);
15260 defsubr (&Sw32_registered_hot_keys
);
15261 defsubr (&Sw32_reconstruct_hot_key
);
15262 defsubr (&Sw32_toggle_lock_key
);
15263 defsubr (&Sw32_find_bdf_fonts
);
15265 defsubr (&Sfile_system_info
);
15267 /* Setting callback functions for fontset handler. */
15268 get_font_info_func
= w32_get_font_info
;
15270 #if 0 /* This function pointer doesn't seem to be used anywhere.
15271 And the pointer assigned has the wrong type, anyway. */
15272 list_fonts_func
= w32_list_fonts
;
15275 load_font_func
= w32_load_font
;
15276 find_ccl_program_func
= w32_find_ccl_program
;
15277 query_font_func
= w32_query_font
;
15278 set_frame_fontset_func
= x_set_font
;
15279 check_window_system_func
= check_w32
;
15282 Qxbm
= intern ("xbm");
15284 QCconversion
= intern (":conversion");
15285 staticpro (&QCconversion
);
15286 QCheuristic_mask
= intern (":heuristic-mask");
15287 staticpro (&QCheuristic_mask
);
15288 QCcolor_symbols
= intern (":color-symbols");
15289 staticpro (&QCcolor_symbols
);
15290 QCascent
= intern (":ascent");
15291 staticpro (&QCascent
);
15292 QCmargin
= intern (":margin");
15293 staticpro (&QCmargin
);
15294 QCrelief
= intern (":relief");
15295 staticpro (&QCrelief
);
15296 Qpostscript
= intern ("postscript");
15297 staticpro (&Qpostscript
);
15298 #if 0 /* TODO: These need entries at top of file. */
15299 QCloader
= intern (":loader");
15300 staticpro (&QCloader
);
15301 QCbounding_box
= intern (":bounding-box");
15302 staticpro (&QCbounding_box
);
15303 QCpt_width
= intern (":pt-width");
15304 staticpro (&QCpt_width
);
15305 QCpt_height
= intern (":pt-height");
15306 staticpro (&QCpt_height
);
15308 QCindex
= intern (":index");
15309 staticpro (&QCindex
);
15310 Qpbm
= intern ("pbm");
15314 Qxpm
= intern ("xpm");
15319 Qjpeg
= intern ("jpeg");
15320 staticpro (&Qjpeg
);
15324 Qtiff
= intern ("tiff");
15325 staticpro (&Qtiff
);
15329 Qgif
= intern ("gif");
15334 Qpng
= intern ("png");
15338 defsubr (&Sclear_image_cache
);
15339 defsubr (&Simage_size
);
15340 defsubr (&Simage_mask_p
);
15343 defsubr (&Simagep
);
15344 defsubr (&Slookup_image
);
15347 hourglass_atimer
= NULL
;
15348 hourglass_shown_p
= 0;
15349 defsubr (&Sx_show_tip
);
15350 defsubr (&Sx_hide_tip
);
15352 staticpro (&tip_timer
);
15354 staticpro (&tip_frame
);
15356 last_show_tip_args
= Qnil
;
15357 staticpro (&last_show_tip_args
);
15359 defsubr (&Sx_file_dialog
);
15366 image_types
= NULL
;
15367 Vimage_types
= Qnil
;
15369 define_image_type (&pbm_type
);
15370 define_image_type (&xbm_type
);
15371 #if 0 /* TODO : Image support for W32 */
15372 define_image_type (&gs_type
);
15376 define_image_type (&xpm_type
);
15380 define_image_type (&jpeg_type
);
15384 define_image_type (&tiff_type
);
15388 define_image_type (&gif_type
);
15392 define_image_type (&png_type
);
15402 button
= MessageBox (NULL
,
15403 "A fatal error has occurred!\n\n"
15404 "Select Abort to exit, Retry to debug, Ignore to continue",
15405 "Emacs Abort Dialog",
15406 MB_ICONEXCLAMATION
| MB_TASKMODAL
15407 | MB_SETFOREGROUND
| MB_ABORTRETRYIGNORE
);
15422 /* For convenience when debugging. */
15426 return GetLastError ();