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"
56 #define FILE_NAME_TEXT_FIELD edt1
58 extern void free_frame_menubar ();
59 extern void x_compute_fringe_widths
P_ ((struct frame
*, int));
60 extern double atof ();
61 extern int w32_console_toggle_lock_key
P_ ((int, Lisp_Object
));
62 extern void w32_menu_display_help
P_ ((HWND
, HMENU
, UINT
, UINT
));
63 extern void w32_free_menu_strings
P_ ((HWND
));
67 /* A definition of XColor for non-X frames. */
68 #ifndef HAVE_X_WINDOWS
71 unsigned short red
, green
, blue
;
77 extern char *lispy_function_keys
[];
79 /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses
80 it, and including `bitmaps/gray' more than once is a problem when
81 config.h defines `static' as an empty replacement string. */
83 int gray_bitmap_width
= gray_width
;
84 int gray_bitmap_height
= gray_height
;
85 unsigned char *gray_bitmap_bits
= gray_bits
;
87 /* The colormap for converting color names to RGB values */
88 Lisp_Object Vw32_color_map
;
90 /* Non nil if alt key presses are passed on to Windows. */
91 Lisp_Object Vw32_pass_alt_to_system
;
93 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
95 Lisp_Object Vw32_alt_is_meta
;
97 /* If non-zero, the windows virtual key code for an alternative quit key. */
98 Lisp_Object Vw32_quit_key
;
100 /* Non nil if left window key events are passed on to Windows (this only
101 affects whether "tapping" the key opens the Start menu). */
102 Lisp_Object Vw32_pass_lwindow_to_system
;
104 /* Non nil if right window key events are passed on to Windows (this
105 only affects whether "tapping" the key opens the Start menu). */
106 Lisp_Object Vw32_pass_rwindow_to_system
;
108 /* Virtual key code used to generate "phantom" key presses in order
109 to stop system from acting on Windows key events. */
110 Lisp_Object Vw32_phantom_key_code
;
112 /* Modifier associated with the left "Windows" key, or nil to act as a
114 Lisp_Object Vw32_lwindow_modifier
;
116 /* Modifier associated with the right "Windows" key, or nil to act as a
118 Lisp_Object Vw32_rwindow_modifier
;
120 /* Modifier associated with the "Apps" key, or nil to act as a normal
122 Lisp_Object Vw32_apps_modifier
;
124 /* Value is nil if Num Lock acts as a function key. */
125 Lisp_Object Vw32_enable_num_lock
;
127 /* Value is nil if Caps Lock acts as a function key. */
128 Lisp_Object Vw32_enable_caps_lock
;
130 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
131 Lisp_Object Vw32_scroll_lock_modifier
;
133 /* Switch to control whether we inhibit requests for synthesized bold
134 and italic versions of fonts. */
135 int w32_enable_synthesized_fonts
;
137 /* Enable palette management. */
138 Lisp_Object Vw32_enable_palette
;
140 /* Control how close left/right button down events must be to
141 be converted to a middle button down event. */
142 Lisp_Object Vw32_mouse_button_tolerance
;
144 /* Minimum interval between mouse movement (and scroll bar drag)
145 events that are passed on to the event loop. */
146 Lisp_Object Vw32_mouse_move_interval
;
148 /* Flag to indicate if XBUTTON events should be passed on to Windows. */
149 int w32_pass_extra_mouse_buttons_to_system
;
151 /* The name we're using in resource queries. */
152 Lisp_Object Vx_resource_name
;
154 /* Non nil if no window manager is in use. */
155 Lisp_Object Vx_no_window_manager
;
157 /* Non-zero means we're allowed to display a hourglass pointer. */
159 int display_hourglass_p
;
161 /* The background and shape of the mouse pointer, and shape when not
162 over text or in the modeline. */
164 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
165 Lisp_Object Vx_hourglass_pointer_shape
, Vx_window_horizontal_drag_shape
;
167 /* The shape when over mouse-sensitive text. */
169 Lisp_Object Vx_sensitive_text_pointer_shape
;
171 /* Color of chars displayed in cursor box. */
173 Lisp_Object Vx_cursor_fore_pixel
;
175 /* Nonzero if using Windows. */
177 static int w32_in_use
;
179 /* Search path for bitmap files. */
181 Lisp_Object Vx_bitmap_file_path
;
183 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
185 Lisp_Object Vx_pixel_size_width_font_regexp
;
187 /* Alist of bdf fonts and the files that define them. */
188 Lisp_Object Vw32_bdf_filename_alist
;
190 /* A flag to control whether fonts are matched strictly or not. */
191 int w32_strict_fontnames
;
193 /* A flag to control whether we should only repaint if GetUpdateRect
194 indicates there is an update region. */
195 int w32_strict_painting
;
197 /* Associative list linking character set strings to Windows codepages. */
198 Lisp_Object Vw32_charset_info_alist
;
200 /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */
201 #ifndef VIETNAMESE_CHARSET
202 #define VIETNAMESE_CHARSET 163
205 Lisp_Object Qauto_raise
;
206 Lisp_Object Qauto_lower
;
207 Lisp_Object Qbar
, Qhbar
;
208 Lisp_Object Qborder_color
;
209 Lisp_Object Qborder_width
;
211 Lisp_Object Qcursor_color
;
212 Lisp_Object Qcursor_type
;
213 Lisp_Object Qgeometry
;
214 Lisp_Object Qicon_left
;
215 Lisp_Object Qicon_top
;
216 Lisp_Object Qicon_type
;
217 Lisp_Object Qicon_name
;
218 Lisp_Object Qinternal_border_width
;
221 Lisp_Object Qmouse_color
;
223 Lisp_Object Qparent_id
;
224 Lisp_Object Qscroll_bar_width
;
225 Lisp_Object Qsuppress_icon
;
226 Lisp_Object Qundefined_color
;
227 Lisp_Object Qvertical_scroll_bars
;
228 Lisp_Object Qvisibility
;
229 Lisp_Object Qwindow_id
;
230 Lisp_Object Qx_frame_parameter
;
231 Lisp_Object Qx_resource_name
;
232 Lisp_Object Quser_position
;
233 Lisp_Object Quser_size
;
234 Lisp_Object Qscreen_gamma
;
235 Lisp_Object Qline_spacing
;
237 Lisp_Object Qcancel_timer
;
243 Lisp_Object Qcontrol
;
246 Lisp_Object Qw32_charset_ansi
;
247 Lisp_Object Qw32_charset_default
;
248 Lisp_Object Qw32_charset_symbol
;
249 Lisp_Object Qw32_charset_shiftjis
;
250 Lisp_Object Qw32_charset_hangeul
;
251 Lisp_Object Qw32_charset_gb2312
;
252 Lisp_Object Qw32_charset_chinesebig5
;
253 Lisp_Object Qw32_charset_oem
;
255 #ifndef JOHAB_CHARSET
256 #define JOHAB_CHARSET 130
259 Lisp_Object Qw32_charset_easteurope
;
260 Lisp_Object Qw32_charset_turkish
;
261 Lisp_Object Qw32_charset_baltic
;
262 Lisp_Object Qw32_charset_russian
;
263 Lisp_Object Qw32_charset_arabic
;
264 Lisp_Object Qw32_charset_greek
;
265 Lisp_Object Qw32_charset_hebrew
;
266 Lisp_Object Qw32_charset_vietnamese
;
267 Lisp_Object Qw32_charset_thai
;
268 Lisp_Object Qw32_charset_johab
;
269 Lisp_Object Qw32_charset_mac
;
272 #ifdef UNICODE_CHARSET
273 Lisp_Object Qw32_charset_unicode
;
276 Lisp_Object Qfullscreen
;
277 Lisp_Object Qfullwidth
;
278 Lisp_Object Qfullheight
;
279 Lisp_Object Qfullboth
;
281 extern Lisp_Object Qtop
;
282 extern Lisp_Object Qdisplay
;
284 /* State variables for emulating a three button mouse. */
289 static int button_state
= 0;
290 static W32Msg saved_mouse_button_msg
;
291 static unsigned mouse_button_timer
= 0; /* non-zero when timer is active */
292 static W32Msg saved_mouse_move_msg
;
293 static unsigned mouse_move_timer
= 0;
295 /* Window that is tracking the mouse. */
296 static HWND track_mouse_window
;
297 FARPROC track_mouse_event_fn
;
299 /* W95 mousewheel handler */
300 unsigned int msh_mousewheel
= 0;
303 #define MOUSE_BUTTON_ID 1
304 #define MOUSE_MOVE_ID 2
305 #define MENU_FREE_ID 3
306 /* The delay (milliseconds) before a menu is freed after WM_EXITMENULOOP
308 #define MENU_FREE_DELAY 1000
309 static unsigned menu_free_timer
= 0;
311 /* The below are defined in frame.c. */
313 extern Lisp_Object Qheight
, Qminibuffer
, Qname
, Qonly
, Qwidth
;
314 extern Lisp_Object Qunsplittable
, Qmenu_bar_lines
, Qbuffer_predicate
, Qtitle
;
315 extern Lisp_Object Qtool_bar_lines
;
317 extern Lisp_Object Vwindow_system_version
;
319 Lisp_Object Qface_set_after_frame_default
;
322 int image_cache_refcount
, dpyinfo_refcount
;
326 /* From w32term.c. */
327 extern Lisp_Object Vw32_num_mouse_buttons
;
328 extern Lisp_Object Vw32_recognize_altgr
;
330 extern HWND w32_system_caret_hwnd
;
332 extern int w32_system_caret_height
;
333 extern int w32_system_caret_x
;
334 extern int w32_system_caret_y
;
335 extern int w32_use_visible_system_caret
;
337 static HWND w32_visible_system_caret_hwnd
;
340 /* Error if we are not connected to MS-Windows. */
345 error ("MS-Windows not in use or not initialized");
348 /* Nonzero if we can use mouse menus.
349 You should not call this unless HAVE_MENUS is defined. */
357 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
358 and checking validity for W32. */
361 check_x_frame (frame
)
367 frame
= selected_frame
;
368 CHECK_LIVE_FRAME (frame
);
370 if (! FRAME_W32_P (f
))
371 error ("non-w32 frame used");
375 /* Let the user specify an display with a frame.
376 nil stands for the selected frame--or, if that is not a w32 frame,
377 the first display on the list. */
379 static struct w32_display_info
*
380 check_x_display_info (frame
)
385 struct frame
*sf
= XFRAME (selected_frame
);
387 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
388 return FRAME_W32_DISPLAY_INFO (sf
);
390 return &one_w32_display_info
;
392 else if (STRINGP (frame
))
393 return x_display_info_for_name (frame
);
398 CHECK_LIVE_FRAME (frame
);
400 if (! FRAME_W32_P (f
))
401 error ("non-w32 frame used");
402 return FRAME_W32_DISPLAY_INFO (f
);
406 /* Return the Emacs frame-object corresponding to an w32 window.
407 It could be the frame's main window or an icon window. */
409 /* This function can be called during GC, so use GC_xxx type test macros. */
412 x_window_to_frame (dpyinfo
, wdesc
)
413 struct w32_display_info
*dpyinfo
;
416 Lisp_Object tail
, frame
;
419 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
422 if (!GC_FRAMEP (frame
))
425 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
427 if (f
->output_data
.w32
->hourglass_window
== wdesc
)
430 if (FRAME_W32_WINDOW (f
) == wdesc
)
438 /* Code to deal with bitmaps. Bitmaps are referenced by their bitmap
439 id, which is just an int that this section returns. Bitmaps are
440 reference counted so they can be shared among frames.
442 Bitmap indices are guaranteed to be > 0, so a negative number can
443 be used to indicate no bitmap.
445 If you use x_create_bitmap_from_data, then you must keep track of
446 the bitmaps yourself. That is, creating a bitmap from the same
447 data more than once will not be caught. */
450 /* Functions to access the contents of a bitmap, given an id. */
453 x_bitmap_height (f
, id
)
457 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].height
;
461 x_bitmap_width (f
, id
)
465 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].width
;
469 x_bitmap_pixmap (f
, id
)
473 return (int) FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].pixmap
;
477 /* Allocate a new bitmap record. Returns index of new record. */
480 x_allocate_bitmap_record (f
)
483 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
486 if (dpyinfo
->bitmaps
== NULL
)
488 dpyinfo
->bitmaps_size
= 10;
490 = (struct w32_bitmap_record
*) xmalloc (dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
491 dpyinfo
->bitmaps_last
= 1;
495 if (dpyinfo
->bitmaps_last
< dpyinfo
->bitmaps_size
)
496 return ++dpyinfo
->bitmaps_last
;
498 for (i
= 0; i
< dpyinfo
->bitmaps_size
; ++i
)
499 if (dpyinfo
->bitmaps
[i
].refcount
== 0)
502 dpyinfo
->bitmaps_size
*= 2;
504 = (struct w32_bitmap_record
*) xrealloc (dpyinfo
->bitmaps
,
505 dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
506 return ++dpyinfo
->bitmaps_last
;
509 /* Add one reference to the reference count of the bitmap with id ID. */
512 x_reference_bitmap (f
, id
)
516 ++FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].refcount
;
519 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
522 x_create_bitmap_from_data (f
, bits
, width
, height
)
525 unsigned int width
, height
;
527 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
531 bitmap
= CreateBitmap (width
, height
,
532 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_planes
,
533 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_cbits
,
539 id
= x_allocate_bitmap_record (f
);
540 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
541 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
542 dpyinfo
->bitmaps
[id
- 1].hinst
= NULL
;
543 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
544 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
545 dpyinfo
->bitmaps
[id
- 1].height
= height
;
546 dpyinfo
->bitmaps
[id
- 1].width
= width
;
551 /* Create bitmap from file FILE for frame F. */
554 x_create_bitmap_from_file (f
, file
)
559 #if 0 /* TODO : bitmap support */
560 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
561 unsigned int width
, height
;
563 int xhot
, yhot
, result
, id
;
569 /* Look for an existing bitmap with the same name. */
570 for (id
= 0; id
< dpyinfo
->bitmaps_last
; ++id
)
572 if (dpyinfo
->bitmaps
[id
].refcount
573 && dpyinfo
->bitmaps
[id
].file
574 && !strcmp (dpyinfo
->bitmaps
[id
].file
, (char *) XSTRING (file
)->data
))
576 ++dpyinfo
->bitmaps
[id
].refcount
;
581 /* Search bitmap-file-path for the file, if appropriate. */
582 fd
= openp (Vx_bitmap_file_path
, file
, Qnil
, &found
, Qnil
);
587 filename
= (char *) XSTRING (found
)->data
;
589 hinst
= LoadLibraryEx (filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
595 result
= XReadBitmapFile (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
596 filename
, &width
, &height
, &bitmap
, &xhot
, &yhot
);
597 if (result
!= BitmapSuccess
)
600 id
= x_allocate_bitmap_record (f
);
601 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
602 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
603 dpyinfo
->bitmaps
[id
- 1].file
= (char *) xmalloc (XSTRING (file
)->size
+ 1);
604 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
605 dpyinfo
->bitmaps
[id
- 1].height
= height
;
606 dpyinfo
->bitmaps
[id
- 1].width
= width
;
607 strcpy (dpyinfo
->bitmaps
[id
- 1].file
, XSTRING (file
)->data
);
613 /* Remove reference to bitmap with id number ID. */
616 x_destroy_bitmap (f
, id
)
620 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
624 --dpyinfo
->bitmaps
[id
- 1].refcount
;
625 if (dpyinfo
->bitmaps
[id
- 1].refcount
== 0)
628 DeleteObject (dpyinfo
->bitmaps
[id
- 1].pixmap
);
629 if (dpyinfo
->bitmaps
[id
- 1].file
)
631 xfree (dpyinfo
->bitmaps
[id
- 1].file
);
632 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
639 /* Free all the bitmaps for the display specified by DPYINFO. */
642 x_destroy_all_bitmaps (dpyinfo
)
643 struct w32_display_info
*dpyinfo
;
646 for (i
= 0; i
< dpyinfo
->bitmaps_last
; i
++)
647 if (dpyinfo
->bitmaps
[i
].refcount
> 0)
649 DeleteObject (dpyinfo
->bitmaps
[i
].pixmap
);
650 if (dpyinfo
->bitmaps
[i
].file
)
651 xfree (dpyinfo
->bitmaps
[i
].file
);
653 dpyinfo
->bitmaps_last
= 0;
656 /* Connect the frame-parameter names for W32 frames
657 to the ways of passing the parameter values to the window system.
659 The name of a parameter, as a Lisp symbol,
660 has an `x-frame-parameter' property which is an integer in Lisp
661 but can be interpreted as an `enum x_frame_parm' in C. */
665 X_PARM_FOREGROUND_COLOR
,
666 X_PARM_BACKGROUND_COLOR
,
673 X_PARM_INTERNAL_BORDER_WIDTH
,
677 X_PARM_VERT_SCROLL_BAR
,
679 X_PARM_MENU_BAR_LINES
683 struct x_frame_parm_table
686 void (*setter
) P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
689 BOOL my_show_window
P_ ((struct frame
*, HWND
, int));
690 void my_set_window_pos
P_ ((HWND
, HWND
, int, int, int, int, UINT
));
691 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
692 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
693 static void x_change_window_heights
P_ ((Lisp_Object
, int));
694 /* TODO: Native Input Method support; see x_create_im. */
695 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
696 static void x_set_line_spacing
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
697 static void x_set_fullscreen
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
698 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
699 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
700 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
701 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
702 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
703 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
704 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
705 void x_set_font
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
706 static void x_set_fringe_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
707 void x_set_border_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
708 void x_set_internal_border_width
P_ ((struct frame
*, Lisp_Object
,
710 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
711 void x_set_autoraise
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
712 void x_set_autolower
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
713 void x_set_vertical_scroll_bars
P_ ((struct frame
*, Lisp_Object
,
715 void x_set_visibility
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
716 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
717 void x_set_scroll_bar_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
718 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
719 void x_set_unsplittable
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
720 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
721 static void x_set_screen_gamma
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
722 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
725 static struct x_frame_parm_table x_frame_parms
[] =
727 {"auto-raise", x_set_autoraise
},
728 {"auto-lower", x_set_autolower
},
729 {"background-color", x_set_background_color
},
730 {"border-color", x_set_border_color
},
731 {"border-width", x_set_border_width
},
732 {"cursor-color", x_set_cursor_color
},
733 {"cursor-type", x_set_cursor_type
},
734 {"font", x_set_font
},
735 {"foreground-color", x_set_foreground_color
},
736 {"icon-name", x_set_icon_name
},
737 {"icon-type", x_set_icon_type
},
738 {"internal-border-width", x_set_internal_border_width
},
739 {"menu-bar-lines", x_set_menu_bar_lines
},
740 {"mouse-color", x_set_mouse_color
},
741 {"name", x_explicitly_set_name
},
742 {"scroll-bar-width", x_set_scroll_bar_width
},
743 {"title", x_set_title
},
744 {"unsplittable", x_set_unsplittable
},
745 {"vertical-scroll-bars", x_set_vertical_scroll_bars
},
746 {"visibility", x_set_visibility
},
747 {"tool-bar-lines", x_set_tool_bar_lines
},
748 {"screen-gamma", x_set_screen_gamma
},
749 {"line-spacing", x_set_line_spacing
},
750 {"left-fringe", x_set_fringe_width
},
751 {"right-fringe", x_set_fringe_width
},
752 {"fullscreen", x_set_fullscreen
},
755 /* Attach the `x-frame-parameter' properties to
756 the Lisp symbol names of parameters relevant to W32. */
759 init_x_parm_symbols ()
763 for (i
= 0; i
< sizeof (x_frame_parms
) / sizeof (x_frame_parms
[0]); i
++)
764 Fput (intern (x_frame_parms
[i
].name
), Qx_frame_parameter
,
768 /* Really try to move where we want to be in case of fullscreen. Some WMs
769 moves the window where we tell them. Some (mwm, twm) moves the outer
770 window manager window there instead.
771 Try to compensate for those WM here. */
773 x_fullscreen_move (f
, new_top
, new_left
)
778 if (new_top
!= f
->output_data
.w32
->top_pos
779 || new_left
!= f
->output_data
.w32
->left_pos
)
781 int move_x
= new_left
;
782 int move_y
= new_top
;
784 f
->output_data
.w32
->want_fullscreen
|= FULLSCREEN_MOVE_WAIT
;
785 x_set_offset (f
, move_x
, move_y
, 1);
789 /* Change the parameters of frame F as specified by ALIST.
790 If a parameter is not specially recognized, do nothing;
791 otherwise call the `x_set_...' function for that parameter. */
794 x_set_frame_parameters (f
, alist
)
800 /* If both of these parameters are present, it's more efficient to
801 set them both at once. So we wait until we've looked at the
802 entire list before we set them. */
806 Lisp_Object left
, top
;
808 /* Same with these. */
809 Lisp_Object icon_left
, icon_top
;
811 /* Record in these vectors all the parms specified. */
815 int left_no_change
= 0, top_no_change
= 0;
816 int icon_left_no_change
= 0, icon_top_no_change
= 0;
817 int fullscreen_is_being_set
= 0;
819 struct gcpro gcpro1
, gcpro2
;
822 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
825 parms
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
826 values
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
828 /* Extract parm names and values into those vectors. */
831 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
836 parms
[i
] = Fcar (elt
);
837 values
[i
] = Fcdr (elt
);
840 /* TAIL and ALIST are not used again below here. */
843 GCPRO2 (*parms
, *values
);
847 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
848 because their values appear in VALUES and strings are not valid. */
849 top
= left
= Qunbound
;
850 icon_left
= icon_top
= Qunbound
;
852 /* Provide default values for HEIGHT and WIDTH. */
853 if (FRAME_NEW_WIDTH (f
))
854 width
= FRAME_NEW_WIDTH (f
);
856 width
= FRAME_WIDTH (f
);
858 if (FRAME_NEW_HEIGHT (f
))
859 height
= FRAME_NEW_HEIGHT (f
);
861 height
= FRAME_HEIGHT (f
);
863 /* Process foreground_color and background_color before anything else.
864 They are independent of other properties, but other properties (e.g.,
865 cursor_color) are dependent upon them. */
866 /* Process default font as well, since fringe widths depends on it. */
867 for (p
= 0; p
< i
; p
++)
869 Lisp_Object prop
, val
;
873 if (EQ (prop
, Qforeground_color
)
874 || EQ (prop
, Qbackground_color
)
876 || EQ (prop
, Qfullscreen
))
878 register Lisp_Object param_index
, old_value
;
880 old_value
= get_frame_param (f
, prop
);
881 fullscreen_is_being_set
|= EQ (prop
, Qfullscreen
);
883 if (NILP (Fequal (val
, old_value
)))
885 store_frame_param (f
, prop
, val
);
887 param_index
= Fget (prop
, Qx_frame_parameter
);
888 if (NATNUMP (param_index
)
889 && (XFASTINT (param_index
)
890 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
891 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
896 /* Now process them in reverse of specified order. */
897 for (i
--; i
>= 0; i
--)
899 Lisp_Object prop
, val
;
904 if (EQ (prop
, Qwidth
) && NUMBERP (val
))
905 width
= XFASTINT (val
);
906 else if (EQ (prop
, Qheight
) && NUMBERP (val
))
907 height
= XFASTINT (val
);
908 else if (EQ (prop
, Qtop
))
910 else if (EQ (prop
, Qleft
))
912 else if (EQ (prop
, Qicon_top
))
914 else if (EQ (prop
, Qicon_left
))
916 else if (EQ (prop
, Qforeground_color
)
917 || EQ (prop
, Qbackground_color
)
919 || EQ (prop
, Qfullscreen
))
920 /* Processed above. */
924 register Lisp_Object param_index
, old_value
;
926 old_value
= get_frame_param (f
, prop
);
928 store_frame_param (f
, prop
, val
);
930 param_index
= Fget (prop
, Qx_frame_parameter
);
931 if (NATNUMP (param_index
)
932 && (XFASTINT (param_index
)
933 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
934 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
938 /* Don't die if just one of these was set. */
939 if (EQ (left
, Qunbound
))
942 if (f
->output_data
.w32
->left_pos
< 0)
943 left
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->left_pos
), Qnil
));
945 XSETINT (left
, f
->output_data
.w32
->left_pos
);
947 if (EQ (top
, Qunbound
))
950 if (f
->output_data
.w32
->top_pos
< 0)
951 top
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->top_pos
), Qnil
));
953 XSETINT (top
, f
->output_data
.w32
->top_pos
);
956 /* If one of the icon positions was not set, preserve or default it. */
957 if (EQ (icon_left
, Qunbound
) || ! INTEGERP (icon_left
))
959 icon_left_no_change
= 1;
960 icon_left
= Fcdr (Fassq (Qicon_left
, f
->param_alist
));
961 if (NILP (icon_left
))
962 XSETINT (icon_left
, 0);
964 if (EQ (icon_top
, Qunbound
) || ! INTEGERP (icon_top
))
966 icon_top_no_change
= 1;
967 icon_top
= Fcdr (Fassq (Qicon_top
, f
->param_alist
));
969 XSETINT (icon_top
, 0);
972 if (FRAME_VISIBLE_P (f
) && fullscreen_is_being_set
)
974 /* If the frame is visible already and the fullscreen parameter is
975 being set, it is too late to set WM manager hints to specify
977 Here we first get the width, height and position that applies to
978 fullscreen. We then move the frame to the appropriate
979 position. Resize of the frame is taken care of in the code after
980 this if-statement. */
981 int new_left
, new_top
;
983 x_fullscreen_adjust (f
, &width
, &height
, &new_top
, &new_left
);
984 x_fullscreen_move (f
, new_top
, new_left
);
987 /* Don't set these parameters unless they've been explicitly
988 specified. The window might be mapped or resized while we're in
989 this function, and we don't want to override that unless the lisp
990 code has asked for it.
992 Don't set these parameters unless they actually differ from the
993 window's current parameters; the window may not actually exist
998 check_frame_size (f
, &height
, &width
);
1000 XSETFRAME (frame
, f
);
1002 if (width
!= FRAME_WIDTH (f
)
1003 || height
!= FRAME_HEIGHT (f
)
1004 || FRAME_NEW_HEIGHT (f
) || FRAME_NEW_WIDTH (f
))
1005 Fset_frame_size (frame
, make_number (width
), make_number (height
));
1007 if ((!NILP (left
) || !NILP (top
))
1008 && ! (left_no_change
&& top_no_change
)
1009 && ! (NUMBERP (left
) && XINT (left
) == f
->output_data
.w32
->left_pos
1010 && NUMBERP (top
) && XINT (top
) == f
->output_data
.w32
->top_pos
))
1015 /* Record the signs. */
1016 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
1017 if (EQ (left
, Qminus
))
1018 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
1019 else if (INTEGERP (left
))
1021 leftpos
= XINT (left
);
1023 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
1025 else if (CONSP (left
) && EQ (XCAR (left
), Qminus
)
1026 && CONSP (XCDR (left
))
1027 && INTEGERP (XCAR (XCDR (left
))))
1029 leftpos
= - XINT (XCAR (XCDR (left
)));
1030 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
1032 else if (CONSP (left
) && EQ (XCAR (left
), Qplus
)
1033 && CONSP (XCDR (left
))
1034 && INTEGERP (XCAR (XCDR (left
))))
1036 leftpos
= XINT (XCAR (XCDR (left
)));
1039 if (EQ (top
, Qminus
))
1040 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
1041 else if (INTEGERP (top
))
1043 toppos
= XINT (top
);
1045 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
1047 else if (CONSP (top
) && EQ (XCAR (top
), Qminus
)
1048 && CONSP (XCDR (top
))
1049 && INTEGERP (XCAR (XCDR (top
))))
1051 toppos
= - XINT (XCAR (XCDR (top
)));
1052 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
1054 else if (CONSP (top
) && EQ (XCAR (top
), Qplus
)
1055 && CONSP (XCDR (top
))
1056 && INTEGERP (XCAR (XCDR (top
))))
1058 toppos
= XINT (XCAR (XCDR (top
)));
1062 /* Store the numeric value of the position. */
1063 f
->output_data
.w32
->top_pos
= toppos
;
1064 f
->output_data
.w32
->left_pos
= leftpos
;
1066 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
1068 /* Actually set that position, and convert to absolute. */
1069 x_set_offset (f
, leftpos
, toppos
, -1);
1072 if ((!NILP (icon_left
) || !NILP (icon_top
))
1073 && ! (icon_left_no_change
&& icon_top_no_change
))
1074 x_wm_set_icon_position (f
, XINT (icon_left
), XINT (icon_top
));
1080 /* Store the screen positions of frame F into XPTR and YPTR.
1081 These are the positions of the containing window manager window,
1082 not Emacs's own window. */
1085 x_real_positions (f
, xptr
, yptr
)
1092 GetClientRect(FRAME_W32_WINDOW(f
), &rect
);
1093 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
, FRAME_EXTERNAL_MENU_BAR(f
));
1098 ClientToScreen (FRAME_W32_WINDOW(f
), &pt
);
1100 /* Remember x_pixels_diff and y_pixels_diff. */
1101 f
->output_data
.w32
->x_pixels_diff
= pt
.x
- rect
.left
;
1102 f
->output_data
.w32
->y_pixels_diff
= pt
.y
- rect
.top
;
1108 /* Insert a description of internally-recorded parameters of frame X
1109 into the parameter alist *ALISTPTR that is to be given to the user.
1110 Only parameters that are specific to W32
1111 and whose values are not correctly recorded in the frame's
1112 param_alist need to be considered here. */
1115 x_report_frame_params (f
, alistptr
)
1117 Lisp_Object
*alistptr
;
1122 /* Represent negative positions (off the top or left screen edge)
1123 in a way that Fmodify_frame_parameters will understand correctly. */
1124 XSETINT (tem
, f
->output_data
.w32
->left_pos
);
1125 if (f
->output_data
.w32
->left_pos
>= 0)
1126 store_in_alist (alistptr
, Qleft
, tem
);
1128 store_in_alist (alistptr
, Qleft
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1130 XSETINT (tem
, f
->output_data
.w32
->top_pos
);
1131 if (f
->output_data
.w32
->top_pos
>= 0)
1132 store_in_alist (alistptr
, Qtop
, tem
);
1134 store_in_alist (alistptr
, Qtop
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1136 store_in_alist (alistptr
, Qborder_width
,
1137 make_number (f
->output_data
.w32
->border_width
));
1138 store_in_alist (alistptr
, Qinternal_border_width
,
1139 make_number (f
->output_data
.w32
->internal_border_width
));
1140 store_in_alist (alistptr
, Qleft_fringe
,
1141 make_number (f
->output_data
.w32
->left_fringe_width
));
1142 store_in_alist (alistptr
, Qright_fringe
,
1143 make_number (f
->output_data
.w32
->right_fringe_width
));
1144 store_in_alist (alistptr
, Qscroll_bar_width
,
1145 make_number (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
1146 ? FRAME_SCROLL_BAR_PIXEL_WIDTH(f
)
1148 sprintf (buf
, "%ld", (long) FRAME_W32_WINDOW (f
));
1149 store_in_alist (alistptr
, Qwindow_id
,
1150 build_string (buf
));
1151 store_in_alist (alistptr
, Qicon_name
, f
->icon_name
);
1152 FRAME_SAMPLE_VISIBILITY (f
);
1153 store_in_alist (alistptr
, Qvisibility
,
1154 (FRAME_VISIBLE_P (f
) ? Qt
1155 : FRAME_ICONIFIED_P (f
) ? Qicon
: Qnil
));
1156 store_in_alist (alistptr
, Qdisplay
,
1157 XCAR (FRAME_W32_DISPLAY_INFO (f
)->name_list_element
));
1161 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
,
1162 Sw32_define_rgb_color
, 4, 4, 0,
1163 doc
: /* Convert RGB numbers to a windows color reference and associate with NAME.
1164 This adds or updates a named color to w32-color-map, making it
1165 available for use. The original entry's RGB ref is returned, or nil
1166 if the entry is new. */)
1167 (red
, green
, blue
, name
)
1168 Lisp_Object red
, green
, blue
, name
;
1171 Lisp_Object oldrgb
= Qnil
;
1175 CHECK_NUMBER (green
);
1176 CHECK_NUMBER (blue
);
1177 CHECK_STRING (name
);
1179 XSET (rgb
, Lisp_Int
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
1183 /* replace existing entry in w32-color-map or add new entry. */
1184 entry
= Fassoc (name
, Vw32_color_map
);
1187 entry
= Fcons (name
, rgb
);
1188 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
1192 oldrgb
= Fcdr (entry
);
1193 Fsetcdr (entry
, rgb
);
1201 DEFUN ("w32-load-color-file", Fw32_load_color_file
,
1202 Sw32_load_color_file
, 1, 1, 0,
1203 doc
: /* Create an alist of color entries from an external file.
1204 Assign this value to w32-color-map to replace the existing color map.
1206 The file should define one named RGB color per line like so:
1208 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
1210 Lisp_Object filename
;
1213 Lisp_Object cmap
= Qnil
;
1214 Lisp_Object abspath
;
1216 CHECK_STRING (filename
);
1217 abspath
= Fexpand_file_name (filename
, Qnil
);
1219 fp
= fopen (XSTRING (filename
)->data
, "rt");
1223 int red
, green
, blue
;
1228 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
1229 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
1231 char *name
= buf
+ num
;
1232 num
= strlen (name
) - 1;
1233 if (name
[num
] == '\n')
1235 cmap
= Fcons (Fcons (build_string (name
),
1236 make_number (RGB (red
, green
, blue
))),
1248 /* The default colors for the w32 color map */
1249 typedef struct colormap_t
1255 colormap_t w32_color_map
[] =
1257 {"snow" , PALETTERGB (255,250,250)},
1258 {"ghost white" , PALETTERGB (248,248,255)},
1259 {"GhostWhite" , PALETTERGB (248,248,255)},
1260 {"white smoke" , PALETTERGB (245,245,245)},
1261 {"WhiteSmoke" , PALETTERGB (245,245,245)},
1262 {"gainsboro" , PALETTERGB (220,220,220)},
1263 {"floral white" , PALETTERGB (255,250,240)},
1264 {"FloralWhite" , PALETTERGB (255,250,240)},
1265 {"old lace" , PALETTERGB (253,245,230)},
1266 {"OldLace" , PALETTERGB (253,245,230)},
1267 {"linen" , PALETTERGB (250,240,230)},
1268 {"antique white" , PALETTERGB (250,235,215)},
1269 {"AntiqueWhite" , PALETTERGB (250,235,215)},
1270 {"papaya whip" , PALETTERGB (255,239,213)},
1271 {"PapayaWhip" , PALETTERGB (255,239,213)},
1272 {"blanched almond" , PALETTERGB (255,235,205)},
1273 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
1274 {"bisque" , PALETTERGB (255,228,196)},
1275 {"peach puff" , PALETTERGB (255,218,185)},
1276 {"PeachPuff" , PALETTERGB (255,218,185)},
1277 {"navajo white" , PALETTERGB (255,222,173)},
1278 {"NavajoWhite" , PALETTERGB (255,222,173)},
1279 {"moccasin" , PALETTERGB (255,228,181)},
1280 {"cornsilk" , PALETTERGB (255,248,220)},
1281 {"ivory" , PALETTERGB (255,255,240)},
1282 {"lemon chiffon" , PALETTERGB (255,250,205)},
1283 {"LemonChiffon" , PALETTERGB (255,250,205)},
1284 {"seashell" , PALETTERGB (255,245,238)},
1285 {"honeydew" , PALETTERGB (240,255,240)},
1286 {"mint cream" , PALETTERGB (245,255,250)},
1287 {"MintCream" , PALETTERGB (245,255,250)},
1288 {"azure" , PALETTERGB (240,255,255)},
1289 {"alice blue" , PALETTERGB (240,248,255)},
1290 {"AliceBlue" , PALETTERGB (240,248,255)},
1291 {"lavender" , PALETTERGB (230,230,250)},
1292 {"lavender blush" , PALETTERGB (255,240,245)},
1293 {"LavenderBlush" , PALETTERGB (255,240,245)},
1294 {"misty rose" , PALETTERGB (255,228,225)},
1295 {"MistyRose" , PALETTERGB (255,228,225)},
1296 {"white" , PALETTERGB (255,255,255)},
1297 {"black" , PALETTERGB ( 0, 0, 0)},
1298 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
1299 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
1300 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
1301 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
1302 {"dim gray" , PALETTERGB (105,105,105)},
1303 {"DimGray" , PALETTERGB (105,105,105)},
1304 {"dim grey" , PALETTERGB (105,105,105)},
1305 {"DimGrey" , PALETTERGB (105,105,105)},
1306 {"slate gray" , PALETTERGB (112,128,144)},
1307 {"SlateGray" , PALETTERGB (112,128,144)},
1308 {"slate grey" , PALETTERGB (112,128,144)},
1309 {"SlateGrey" , PALETTERGB (112,128,144)},
1310 {"light slate gray" , PALETTERGB (119,136,153)},
1311 {"LightSlateGray" , PALETTERGB (119,136,153)},
1312 {"light slate grey" , PALETTERGB (119,136,153)},
1313 {"LightSlateGrey" , PALETTERGB (119,136,153)},
1314 {"gray" , PALETTERGB (190,190,190)},
1315 {"grey" , PALETTERGB (190,190,190)},
1316 {"light grey" , PALETTERGB (211,211,211)},
1317 {"LightGrey" , PALETTERGB (211,211,211)},
1318 {"light gray" , PALETTERGB (211,211,211)},
1319 {"LightGray" , PALETTERGB (211,211,211)},
1320 {"midnight blue" , PALETTERGB ( 25, 25,112)},
1321 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
1322 {"navy" , PALETTERGB ( 0, 0,128)},
1323 {"navy blue" , PALETTERGB ( 0, 0,128)},
1324 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
1325 {"cornflower blue" , PALETTERGB (100,149,237)},
1326 {"CornflowerBlue" , PALETTERGB (100,149,237)},
1327 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
1328 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
1329 {"slate blue" , PALETTERGB (106, 90,205)},
1330 {"SlateBlue" , PALETTERGB (106, 90,205)},
1331 {"medium slate blue" , PALETTERGB (123,104,238)},
1332 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
1333 {"light slate blue" , PALETTERGB (132,112,255)},
1334 {"LightSlateBlue" , PALETTERGB (132,112,255)},
1335 {"medium blue" , PALETTERGB ( 0, 0,205)},
1336 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
1337 {"royal blue" , PALETTERGB ( 65,105,225)},
1338 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
1339 {"blue" , PALETTERGB ( 0, 0,255)},
1340 {"dodger blue" , PALETTERGB ( 30,144,255)},
1341 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
1342 {"deep sky blue" , PALETTERGB ( 0,191,255)},
1343 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
1344 {"sky blue" , PALETTERGB (135,206,235)},
1345 {"SkyBlue" , PALETTERGB (135,206,235)},
1346 {"light sky blue" , PALETTERGB (135,206,250)},
1347 {"LightSkyBlue" , PALETTERGB (135,206,250)},
1348 {"steel blue" , PALETTERGB ( 70,130,180)},
1349 {"SteelBlue" , PALETTERGB ( 70,130,180)},
1350 {"light steel blue" , PALETTERGB (176,196,222)},
1351 {"LightSteelBlue" , PALETTERGB (176,196,222)},
1352 {"light blue" , PALETTERGB (173,216,230)},
1353 {"LightBlue" , PALETTERGB (173,216,230)},
1354 {"powder blue" , PALETTERGB (176,224,230)},
1355 {"PowderBlue" , PALETTERGB (176,224,230)},
1356 {"pale turquoise" , PALETTERGB (175,238,238)},
1357 {"PaleTurquoise" , PALETTERGB (175,238,238)},
1358 {"dark turquoise" , PALETTERGB ( 0,206,209)},
1359 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
1360 {"medium turquoise" , PALETTERGB ( 72,209,204)},
1361 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
1362 {"turquoise" , PALETTERGB ( 64,224,208)},
1363 {"cyan" , PALETTERGB ( 0,255,255)},
1364 {"light cyan" , PALETTERGB (224,255,255)},
1365 {"LightCyan" , PALETTERGB (224,255,255)},
1366 {"cadet blue" , PALETTERGB ( 95,158,160)},
1367 {"CadetBlue" , PALETTERGB ( 95,158,160)},
1368 {"medium aquamarine" , PALETTERGB (102,205,170)},
1369 {"MediumAquamarine" , PALETTERGB (102,205,170)},
1370 {"aquamarine" , PALETTERGB (127,255,212)},
1371 {"dark green" , PALETTERGB ( 0,100, 0)},
1372 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
1373 {"dark olive green" , PALETTERGB ( 85,107, 47)},
1374 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
1375 {"dark sea green" , PALETTERGB (143,188,143)},
1376 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
1377 {"sea green" , PALETTERGB ( 46,139, 87)},
1378 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
1379 {"medium sea green" , PALETTERGB ( 60,179,113)},
1380 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
1381 {"light sea green" , PALETTERGB ( 32,178,170)},
1382 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
1383 {"pale green" , PALETTERGB (152,251,152)},
1384 {"PaleGreen" , PALETTERGB (152,251,152)},
1385 {"spring green" , PALETTERGB ( 0,255,127)},
1386 {"SpringGreen" , PALETTERGB ( 0,255,127)},
1387 {"lawn green" , PALETTERGB (124,252, 0)},
1388 {"LawnGreen" , PALETTERGB (124,252, 0)},
1389 {"green" , PALETTERGB ( 0,255, 0)},
1390 {"chartreuse" , PALETTERGB (127,255, 0)},
1391 {"medium spring green" , PALETTERGB ( 0,250,154)},
1392 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
1393 {"green yellow" , PALETTERGB (173,255, 47)},
1394 {"GreenYellow" , PALETTERGB (173,255, 47)},
1395 {"lime green" , PALETTERGB ( 50,205, 50)},
1396 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
1397 {"yellow green" , PALETTERGB (154,205, 50)},
1398 {"YellowGreen" , PALETTERGB (154,205, 50)},
1399 {"forest green" , PALETTERGB ( 34,139, 34)},
1400 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
1401 {"olive drab" , PALETTERGB (107,142, 35)},
1402 {"OliveDrab" , PALETTERGB (107,142, 35)},
1403 {"dark khaki" , PALETTERGB (189,183,107)},
1404 {"DarkKhaki" , PALETTERGB (189,183,107)},
1405 {"khaki" , PALETTERGB (240,230,140)},
1406 {"pale goldenrod" , PALETTERGB (238,232,170)},
1407 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
1408 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
1409 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
1410 {"light yellow" , PALETTERGB (255,255,224)},
1411 {"LightYellow" , PALETTERGB (255,255,224)},
1412 {"yellow" , PALETTERGB (255,255, 0)},
1413 {"gold" , PALETTERGB (255,215, 0)},
1414 {"light goldenrod" , PALETTERGB (238,221,130)},
1415 {"LightGoldenrod" , PALETTERGB (238,221,130)},
1416 {"goldenrod" , PALETTERGB (218,165, 32)},
1417 {"dark goldenrod" , PALETTERGB (184,134, 11)},
1418 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
1419 {"rosy brown" , PALETTERGB (188,143,143)},
1420 {"RosyBrown" , PALETTERGB (188,143,143)},
1421 {"indian red" , PALETTERGB (205, 92, 92)},
1422 {"IndianRed" , PALETTERGB (205, 92, 92)},
1423 {"saddle brown" , PALETTERGB (139, 69, 19)},
1424 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
1425 {"sienna" , PALETTERGB (160, 82, 45)},
1426 {"peru" , PALETTERGB (205,133, 63)},
1427 {"burlywood" , PALETTERGB (222,184,135)},
1428 {"beige" , PALETTERGB (245,245,220)},
1429 {"wheat" , PALETTERGB (245,222,179)},
1430 {"sandy brown" , PALETTERGB (244,164, 96)},
1431 {"SandyBrown" , PALETTERGB (244,164, 96)},
1432 {"tan" , PALETTERGB (210,180,140)},
1433 {"chocolate" , PALETTERGB (210,105, 30)},
1434 {"firebrick" , PALETTERGB (178,34, 34)},
1435 {"brown" , PALETTERGB (165,42, 42)},
1436 {"dark salmon" , PALETTERGB (233,150,122)},
1437 {"DarkSalmon" , PALETTERGB (233,150,122)},
1438 {"salmon" , PALETTERGB (250,128,114)},
1439 {"light salmon" , PALETTERGB (255,160,122)},
1440 {"LightSalmon" , PALETTERGB (255,160,122)},
1441 {"orange" , PALETTERGB (255,165, 0)},
1442 {"dark orange" , PALETTERGB (255,140, 0)},
1443 {"DarkOrange" , PALETTERGB (255,140, 0)},
1444 {"coral" , PALETTERGB (255,127, 80)},
1445 {"light coral" , PALETTERGB (240,128,128)},
1446 {"LightCoral" , PALETTERGB (240,128,128)},
1447 {"tomato" , PALETTERGB (255, 99, 71)},
1448 {"orange red" , PALETTERGB (255, 69, 0)},
1449 {"OrangeRed" , PALETTERGB (255, 69, 0)},
1450 {"red" , PALETTERGB (255, 0, 0)},
1451 {"hot pink" , PALETTERGB (255,105,180)},
1452 {"HotPink" , PALETTERGB (255,105,180)},
1453 {"deep pink" , PALETTERGB (255, 20,147)},
1454 {"DeepPink" , PALETTERGB (255, 20,147)},
1455 {"pink" , PALETTERGB (255,192,203)},
1456 {"light pink" , PALETTERGB (255,182,193)},
1457 {"LightPink" , PALETTERGB (255,182,193)},
1458 {"pale violet red" , PALETTERGB (219,112,147)},
1459 {"PaleVioletRed" , PALETTERGB (219,112,147)},
1460 {"maroon" , PALETTERGB (176, 48, 96)},
1461 {"medium violet red" , PALETTERGB (199, 21,133)},
1462 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
1463 {"violet red" , PALETTERGB (208, 32,144)},
1464 {"VioletRed" , PALETTERGB (208, 32,144)},
1465 {"magenta" , PALETTERGB (255, 0,255)},
1466 {"violet" , PALETTERGB (238,130,238)},
1467 {"plum" , PALETTERGB (221,160,221)},
1468 {"orchid" , PALETTERGB (218,112,214)},
1469 {"medium orchid" , PALETTERGB (186, 85,211)},
1470 {"MediumOrchid" , PALETTERGB (186, 85,211)},
1471 {"dark orchid" , PALETTERGB (153, 50,204)},
1472 {"DarkOrchid" , PALETTERGB (153, 50,204)},
1473 {"dark violet" , PALETTERGB (148, 0,211)},
1474 {"DarkViolet" , PALETTERGB (148, 0,211)},
1475 {"blue violet" , PALETTERGB (138, 43,226)},
1476 {"BlueViolet" , PALETTERGB (138, 43,226)},
1477 {"purple" , PALETTERGB (160, 32,240)},
1478 {"medium purple" , PALETTERGB (147,112,219)},
1479 {"MediumPurple" , PALETTERGB (147,112,219)},
1480 {"thistle" , PALETTERGB (216,191,216)},
1481 {"gray0" , PALETTERGB ( 0, 0, 0)},
1482 {"grey0" , PALETTERGB ( 0, 0, 0)},
1483 {"dark grey" , PALETTERGB (169,169,169)},
1484 {"DarkGrey" , PALETTERGB (169,169,169)},
1485 {"dark gray" , PALETTERGB (169,169,169)},
1486 {"DarkGray" , PALETTERGB (169,169,169)},
1487 {"dark blue" , PALETTERGB ( 0, 0,139)},
1488 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
1489 {"dark cyan" , PALETTERGB ( 0,139,139)},
1490 {"DarkCyan" , PALETTERGB ( 0,139,139)},
1491 {"dark magenta" , PALETTERGB (139, 0,139)},
1492 {"DarkMagenta" , PALETTERGB (139, 0,139)},
1493 {"dark red" , PALETTERGB (139, 0, 0)},
1494 {"DarkRed" , PALETTERGB (139, 0, 0)},
1495 {"light green" , PALETTERGB (144,238,144)},
1496 {"LightGreen" , PALETTERGB (144,238,144)},
1499 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
1500 0, 0, 0, doc
: /* Return the default color map. */)
1504 colormap_t
*pc
= w32_color_map
;
1511 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
1513 cmap
= Fcons (Fcons (build_string (pc
->name
),
1514 make_number (pc
->colorref
)),
1523 w32_to_x_color (rgb
)
1532 color
= Frassq (rgb
, Vw32_color_map
);
1537 return (Fcar (color
));
1543 w32_color_map_lookup (colorname
)
1546 Lisp_Object tail
, ret
= Qnil
;
1550 for (tail
= Vw32_color_map
; !NILP (tail
); tail
= Fcdr (tail
))
1552 register Lisp_Object elt
, tem
;
1555 if (!CONSP (elt
)) continue;
1559 if (lstrcmpi (XSTRING (tem
)->data
, colorname
) == 0)
1561 ret
= XUINT (Fcdr (elt
));
1575 x_to_w32_color (colorname
)
1578 register Lisp_Object ret
= Qnil
;
1582 if (colorname
[0] == '#')
1584 /* Could be an old-style RGB Device specification. */
1587 color
= colorname
+ 1;
1589 size
= strlen(color
);
1590 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
1598 for (i
= 0; i
< 3; i
++)
1602 unsigned long value
;
1604 /* The check for 'x' in the following conditional takes into
1605 account the fact that strtol allows a "0x" in front of
1606 our numbers, and we don't. */
1607 if (!isxdigit(color
[0]) || color
[1] == 'x')
1611 value
= strtoul(color
, &end
, 16);
1613 if (errno
== ERANGE
|| end
- color
!= size
)
1618 value
= value
* 0x10;
1629 colorval
|= (value
<< pos
);
1640 else if (strnicmp(colorname
, "rgb:", 4) == 0)
1648 color
= colorname
+ 4;
1649 for (i
= 0; i
< 3; i
++)
1652 unsigned long value
;
1654 /* The check for 'x' in the following conditional takes into
1655 account the fact that strtol allows a "0x" in front of
1656 our numbers, and we don't. */
1657 if (!isxdigit(color
[0]) || color
[1] == 'x')
1659 value
= strtoul(color
, &end
, 16);
1660 if (errno
== ERANGE
)
1662 switch (end
- color
)
1665 value
= value
* 0x10 + value
;
1678 if (value
== ULONG_MAX
)
1680 colorval
|= (value
<< pos
);
1694 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1696 /* This is an RGB Intensity specification. */
1703 color
= colorname
+ 5;
1704 for (i
= 0; i
< 3; i
++)
1710 value
= strtod(color
, &end
);
1711 if (errno
== ERANGE
)
1713 if (value
< 0.0 || value
> 1.0)
1715 val
= (UINT
)(0x100 * value
);
1716 /* We used 0x100 instead of 0xFF to give an continuous
1717 range between 0.0 and 1.0 inclusive. The next statement
1718 fixes the 1.0 case. */
1721 colorval
|= (val
<< pos
);
1735 /* I am not going to attempt to handle any of the CIE color schemes
1736 or TekHVC, since I don't know the algorithms for conversion to
1739 /* If we fail to lookup the color name in w32_color_map, then check the
1740 colorname to see if it can be crudely approximated: If the X color
1741 ends in a number (e.g., "darkseagreen2"), strip the number and
1742 return the result of looking up the base color name. */
1743 ret
= w32_color_map_lookup (colorname
);
1746 int len
= strlen (colorname
);
1748 if (isdigit (colorname
[len
- 1]))
1750 char *ptr
, *approx
= alloca (len
+ 1);
1752 strcpy (approx
, colorname
);
1753 ptr
= &approx
[len
- 1];
1754 while (ptr
> approx
&& isdigit (*ptr
))
1757 ret
= w32_color_map_lookup (approx
);
1767 w32_regenerate_palette (FRAME_PTR f
)
1769 struct w32_palette_entry
* list
;
1770 LOGPALETTE
* log_palette
;
1771 HPALETTE new_palette
;
1774 /* don't bother trying to create palette if not supported */
1775 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1778 log_palette
= (LOGPALETTE
*)
1779 alloca (sizeof (LOGPALETTE
) +
1780 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1781 log_palette
->palVersion
= 0x300;
1782 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1784 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1786 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1787 i
++, list
= list
->next
)
1788 log_palette
->palPalEntry
[i
] = list
->entry
;
1790 new_palette
= CreatePalette (log_palette
);
1794 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1795 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1796 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1798 /* Realize display palette and garbage all frames. */
1799 release_frame_dc (f
, get_frame_dc (f
));
1804 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1805 #define SET_W32_COLOR(pe, color) \
1808 pe.peRed = GetRValue (color); \
1809 pe.peGreen = GetGValue (color); \
1810 pe.peBlue = GetBValue (color); \
1815 /* Keep these around in case we ever want to track color usage. */
1817 w32_map_color (FRAME_PTR f
, COLORREF color
)
1819 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1821 if (NILP (Vw32_enable_palette
))
1824 /* check if color is already mapped */
1827 if (W32_COLOR (list
->entry
) == color
)
1835 /* not already mapped, so add to list and recreate Windows palette */
1836 list
= (struct w32_palette_entry
*)
1837 xmalloc (sizeof (struct w32_palette_entry
));
1838 SET_W32_COLOR (list
->entry
, color
);
1840 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1841 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1842 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1844 /* set flag that palette must be regenerated */
1845 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1849 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1851 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1852 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1854 if (NILP (Vw32_enable_palette
))
1857 /* check if color is already mapped */
1860 if (W32_COLOR (list
->entry
) == color
)
1862 if (--list
->refcount
== 0)
1866 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1876 /* set flag that palette must be regenerated */
1877 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1882 /* Gamma-correct COLOR on frame F. */
1885 gamma_correct (f
, color
)
1891 *color
= PALETTERGB (
1892 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1893 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1894 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1899 /* Decide if color named COLOR is valid for the display associated with
1900 the selected frame; if so, return the rgb values in COLOR_DEF.
1901 If ALLOC is nonzero, allocate a new colormap cell. */
1904 w32_defined_color (f
, color
, color_def
, alloc
)
1910 register Lisp_Object tem
;
1911 COLORREF w32_color_ref
;
1913 tem
= x_to_w32_color (color
);
1919 /* Apply gamma correction. */
1920 w32_color_ref
= XUINT (tem
);
1921 gamma_correct (f
, &w32_color_ref
);
1922 XSETINT (tem
, w32_color_ref
);
1925 /* Map this color to the palette if it is enabled. */
1926 if (!NILP (Vw32_enable_palette
))
1928 struct w32_palette_entry
* entry
=
1929 one_w32_display_info
.color_list
;
1930 struct w32_palette_entry
** prev
=
1931 &one_w32_display_info
.color_list
;
1933 /* check if color is already mapped */
1936 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1938 prev
= &entry
->next
;
1939 entry
= entry
->next
;
1942 if (entry
== NULL
&& alloc
)
1944 /* not already mapped, so add to list */
1945 entry
= (struct w32_palette_entry
*)
1946 xmalloc (sizeof (struct w32_palette_entry
));
1947 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1950 one_w32_display_info
.num_colors
++;
1952 /* set flag that palette must be regenerated */
1953 one_w32_display_info
.regen_palette
= TRUE
;
1956 /* Ensure COLORREF value is snapped to nearest color in (default)
1957 palette by simulating the PALETTERGB macro. This works whether
1958 or not the display device has a palette. */
1959 w32_color_ref
= XUINT (tem
) | 0x2000000;
1961 color_def
->pixel
= w32_color_ref
;
1962 color_def
->red
= GetRValue (w32_color_ref
);
1963 color_def
->green
= GetGValue (w32_color_ref
);
1964 color_def
->blue
= GetBValue (w32_color_ref
);
1974 /* Given a string ARG naming a color, compute a pixel value from it
1975 suitable for screen F.
1976 If F is not a color screen, return DEF (default) regardless of what
1980 x_decode_color (f
, arg
, def
)
1989 if (strcmp (XSTRING (arg
)->data
, "black") == 0)
1990 return BLACK_PIX_DEFAULT (f
);
1991 else if (strcmp (XSTRING (arg
)->data
, "white") == 0)
1992 return WHITE_PIX_DEFAULT (f
);
1994 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1997 /* w32_defined_color is responsible for coping with failures
1998 by looking for a near-miss. */
1999 if (w32_defined_color (f
, XSTRING (arg
)->data
, &cdef
, 1))
2002 /* defined_color failed; return an ultimate default. */
2006 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
2007 the previous value of that parameter, NEW_VALUE is the new value. */
2010 x_set_line_spacing (f
, new_value
, old_value
)
2012 Lisp_Object new_value
, old_value
;
2014 if (NILP (new_value
))
2015 f
->extra_line_spacing
= 0;
2016 else if (NATNUMP (new_value
))
2017 f
->extra_line_spacing
= XFASTINT (new_value
);
2019 Fsignal (Qerror
, Fcons (build_string ("Invalid line-spacing"),
2020 Fcons (new_value
, Qnil
)));
2021 if (FRAME_VISIBLE_P (f
))
2026 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
2027 the previous value of that parameter, NEW_VALUE is the new value. */
2030 x_set_fullscreen (f
, new_value
, old_value
)
2032 Lisp_Object new_value
, old_value
;
2034 if (NILP (new_value
))
2035 f
->output_data
.w32
->want_fullscreen
= FULLSCREEN_NONE
;
2036 else if (EQ (new_value
, Qfullboth
))
2037 f
->output_data
.w32
->want_fullscreen
= FULLSCREEN_BOTH
;
2038 else if (EQ (new_value
, Qfullwidth
))
2039 f
->output_data
.w32
->want_fullscreen
= FULLSCREEN_WIDTH
;
2040 else if (EQ (new_value
, Qfullheight
))
2041 f
->output_data
.w32
->want_fullscreen
= FULLSCREEN_HEIGHT
;
2045 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
2046 the previous value of that parameter, NEW_VALUE is the new value. */
2049 x_set_screen_gamma (f
, new_value
, old_value
)
2051 Lisp_Object new_value
, old_value
;
2053 if (NILP (new_value
))
2055 else if (NUMBERP (new_value
) && XFLOATINT (new_value
) > 0)
2056 /* The value 0.4545 is the normal viewing gamma. */
2057 f
->gamma
= 1.0 / (0.4545 * XFLOATINT (new_value
));
2059 Fsignal (Qerror
, Fcons (build_string ("Invalid screen-gamma"),
2060 Fcons (new_value
, Qnil
)));
2062 clear_face_cache (0);
2066 /* Functions called only from `x_set_frame_param'
2067 to set individual parameters.
2069 If FRAME_W32_WINDOW (f) is 0,
2070 the frame is being created and its window does not exist yet.
2071 In that case, just record the parameter's new value
2072 in the standard place; do not attempt to change the window. */
2075 x_set_foreground_color (f
, arg
, oldval
)
2077 Lisp_Object arg
, oldval
;
2079 struct w32_output
*x
= f
->output_data
.w32
;
2080 PIX_TYPE fg
, old_fg
;
2082 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2083 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
2084 FRAME_FOREGROUND_PIXEL (f
) = fg
;
2086 if (FRAME_W32_WINDOW (f
) != 0)
2088 if (x
->cursor_pixel
== old_fg
)
2089 x
->cursor_pixel
= fg
;
2091 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
2092 if (FRAME_VISIBLE_P (f
))
2098 x_set_background_color (f
, arg
, oldval
)
2100 Lisp_Object arg
, oldval
;
2102 FRAME_BACKGROUND_PIXEL (f
)
2103 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
2105 if (FRAME_W32_WINDOW (f
) != 0)
2107 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
2108 FRAME_BACKGROUND_PIXEL (f
));
2110 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
2112 if (FRAME_VISIBLE_P (f
))
2118 x_set_mouse_color (f
, arg
, oldval
)
2120 Lisp_Object arg
, oldval
;
2122 Cursor cursor
, nontext_cursor
, mode_cursor
, cross_cursor
;
2126 if (!EQ (Qnil
, arg
))
2127 f
->output_data
.w32
->mouse_pixel
2128 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2129 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
2131 /* Don't let pointers be invisible. */
2132 if (mask_color
== f
->output_data
.w32
->mouse_pixel
2133 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
2134 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
2136 #if 0 /* TODO : cursor changes */
2139 /* It's not okay to crash if the user selects a screwy cursor. */
2140 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
2142 if (!EQ (Qnil
, Vx_pointer_shape
))
2144 CHECK_NUMBER (Vx_pointer_shape
);
2145 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
2148 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2149 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
2151 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
2153 CHECK_NUMBER (Vx_nontext_pointer_shape
);
2154 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2155 XINT (Vx_nontext_pointer_shape
));
2158 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
2159 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2161 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
2163 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
2164 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2165 XINT (Vx_hourglass_pointer_shape
));
2168 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
2169 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
2171 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2172 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
2174 CHECK_NUMBER (Vx_mode_pointer_shape
);
2175 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2176 XINT (Vx_mode_pointer_shape
));
2179 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2180 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
2182 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
2184 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
2186 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2187 XINT (Vx_sensitive_text_pointer_shape
));
2190 cross_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
2192 if (!NILP (Vx_window_horizontal_drag_shape
))
2194 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
2195 horizontal_drag_cursor
2196 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
2197 XINT (Vx_window_horizontal_drag_shape
));
2200 horizontal_drag_cursor
2201 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
2203 /* Check and report errors with the above calls. */
2204 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
2205 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
2208 XColor fore_color
, back_color
;
2210 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
2211 back_color
.pixel
= mask_color
;
2212 XQueryColor (FRAME_W32_DISPLAY (f
),
2213 DefaultColormap (FRAME_W32_DISPLAY (f
),
2214 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2216 XQueryColor (FRAME_W32_DISPLAY (f
),
2217 DefaultColormap (FRAME_W32_DISPLAY (f
),
2218 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2220 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
2221 &fore_color
, &back_color
);
2222 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
2223 &fore_color
, &back_color
);
2224 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
2225 &fore_color
, &back_color
);
2226 XRecolorCursor (FRAME_W32_DISPLAY (f
), cross_cursor
,
2227 &fore_color
, &back_color
);
2228 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
2229 &fore_color
, &back_color
);
2232 if (FRAME_W32_WINDOW (f
) != 0)
2233 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
2235 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
2236 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
2237 f
->output_data
.w32
->text_cursor
= cursor
;
2239 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
2240 && f
->output_data
.w32
->nontext_cursor
!= 0)
2241 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
2242 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
2244 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
2245 && f
->output_data
.w32
->hourglass_cursor
!= 0)
2246 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
2247 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
2249 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
2250 && f
->output_data
.w32
->modeline_cursor
!= 0)
2251 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
2252 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
2254 if (cross_cursor
!= f
->output_data
.w32
->cross_cursor
2255 && f
->output_data
.w32
->cross_cursor
!= 0)
2256 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->cross_cursor
);
2257 f
->output_data
.w32
->cross_cursor
= cross_cursor
;
2259 XFlush (FRAME_W32_DISPLAY (f
));
2262 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
2266 /* Defined in w32term.c. */
2267 void x_update_cursor (struct frame
*f
, int on_p
);
2270 x_set_cursor_color (f
, arg
, oldval
)
2272 Lisp_Object arg
, oldval
;
2274 unsigned long fore_pixel
, pixel
;
2276 if (!NILP (Vx_cursor_fore_pixel
))
2277 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
2278 WHITE_PIX_DEFAULT (f
));
2280 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2282 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2284 /* Make sure that the cursor color differs from the background color. */
2285 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
2287 pixel
= f
->output_data
.w32
->mouse_pixel
;
2288 if (pixel
== fore_pixel
)
2289 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2292 f
->output_data
.w32
->cursor_foreground_pixel
= fore_pixel
;
2293 f
->output_data
.w32
->cursor_pixel
= pixel
;
2295 if (FRAME_W32_WINDOW (f
) != 0)
2298 /* Update frame's cursor_gc. */
2299 f
->output_data
.w32
->cursor_gc
->foreground
= fore_pixel
;
2300 f
->output_data
.w32
->cursor_gc
->background
= pixel
;
2304 if (FRAME_VISIBLE_P (f
))
2306 x_update_cursor (f
, 0);
2307 x_update_cursor (f
, 1);
2311 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
2314 /* Set the border-color of frame F to pixel value PIX.
2315 Note that this does not fully take effect if done before
2318 x_set_border_pixel (f
, pix
)
2322 f
->output_data
.w32
->border_pixel
= pix
;
2324 if (FRAME_W32_WINDOW (f
) != 0 && f
->output_data
.w32
->border_width
> 0)
2326 if (FRAME_VISIBLE_P (f
))
2331 /* Set the border-color of frame F to value described by ARG.
2332 ARG can be a string naming a color.
2333 The border-color is used for the border that is drawn by the server.
2334 Note that this does not fully take effect if done before
2335 F has a window; it must be redone when the window is created. */
2338 x_set_border_color (f
, arg
, oldval
)
2340 Lisp_Object arg
, oldval
;
2345 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2346 x_set_border_pixel (f
, pix
);
2347 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
2350 /* Value is the internal representation of the specified cursor type
2351 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
2352 of the bar cursor. */
2354 enum text_cursor_kinds
2355 x_specified_cursor_type (arg
, width
)
2359 enum text_cursor_kinds type
;
2366 else if (CONSP (arg
)
2367 && EQ (XCAR (arg
), Qbar
)
2368 && INTEGERP (XCDR (arg
))
2369 && XINT (XCDR (arg
)) >= 0)
2372 *width
= XINT (XCDR (arg
));
2374 else if (EQ (arg
, Qhbar
))
2379 else if (CONSP (arg
)
2380 && EQ (XCAR (arg
), Qhbar
)
2381 && INTEGERP (XCDR (arg
))
2382 && XINT (XCDR (arg
)) >= 0)
2385 *width
= XINT (XCDR (arg
));
2387 else if (NILP (arg
))
2390 /* Treat anything unknown as "box cursor".
2391 It was bad to signal an error; people have trouble fixing
2392 .Xdefaults with Emacs, when it has something bad in it. */
2393 type
= FILLED_BOX_CURSOR
;
2399 x_set_cursor_type (f
, arg
, oldval
)
2401 Lisp_Object arg
, oldval
;
2405 FRAME_DESIRED_CURSOR (f
) = x_specified_cursor_type (arg
, &width
);
2406 f
->output_data
.w32
->cursor_width
= width
;
2408 /* Make sure the cursor gets redrawn. This is overkill, but how
2409 often do people change cursor types? */
2410 update_mode_lines
++;
2414 x_set_icon_type (f
, arg
, oldval
)
2416 Lisp_Object arg
, oldval
;
2420 if (NILP (arg
) && NILP (oldval
))
2423 if (STRINGP (arg
) && STRINGP (oldval
)
2424 && EQ (Fstring_equal (oldval
, arg
), Qt
))
2427 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
2432 result
= x_bitmap_icon (f
, arg
);
2436 error ("No icon window available");
2442 /* Return non-nil if frame F wants a bitmap icon. */
2450 tem
= assq_no_quit (Qicon_type
, f
->param_alist
);
2458 x_set_icon_name (f
, arg
, oldval
)
2460 Lisp_Object arg
, oldval
;
2464 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
2467 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
2473 if (f
->output_data
.w32
->icon_bitmap
!= 0)
2478 result
= x_text_icon (f
,
2479 (char *) XSTRING ((!NILP (f
->icon_name
)
2488 error ("No icon window available");
2491 /* If the window was unmapped (and its icon was mapped),
2492 the new icon is not mapped, so map the window in its stead. */
2493 if (FRAME_VISIBLE_P (f
))
2495 #ifdef USE_X_TOOLKIT
2496 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
2498 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
2501 XFlush (FRAME_W32_DISPLAY (f
));
2506 extern Lisp_Object
x_new_font ();
2507 extern Lisp_Object
x_new_fontset();
2510 x_set_font (f
, arg
, oldval
)
2512 Lisp_Object arg
, oldval
;
2515 Lisp_Object fontset_name
;
2517 int old_fontset
= FRAME_FONTSET(f
);
2521 fontset_name
= Fquery_fontset (arg
, Qnil
);
2524 result
= (STRINGP (fontset_name
)
2525 ? x_new_fontset (f
, XSTRING (fontset_name
)->data
)
2526 : x_new_font (f
, XSTRING (arg
)->data
));
2529 if (EQ (result
, Qnil
))
2530 error ("Font `%s' is not defined", XSTRING (arg
)->data
);
2531 else if (EQ (result
, Qt
))
2532 error ("The characters of the given font have varying widths");
2533 else if (STRINGP (result
))
2535 if (STRINGP (fontset_name
))
2537 /* Fontset names are built from ASCII font names, so the
2538 names may be equal despite there was a change. */
2539 if (old_fontset
== FRAME_FONTSET (f
))
2542 else if (!NILP (Fequal (result
, oldval
)))
2545 store_frame_param (f
, Qfont
, result
);
2546 recompute_basic_faces (f
);
2551 do_pending_window_change (0);
2553 /* Don't call `face-set-after-frame-default' when faces haven't been
2554 initialized yet. This is the case when called from
2555 Fx_create_frame. In that case, the X widget or window doesn't
2556 exist either, and we can end up in x_report_frame_params with a
2557 null widget which gives a segfault. */
2558 if (FRAME_FACE_CACHE (f
))
2560 XSETFRAME (frame
, f
);
2561 call1 (Qface_set_after_frame_default
, frame
);
2566 x_set_fringe_width (f
, new_value
, old_value
)
2568 Lisp_Object new_value
, old_value
;
2570 x_compute_fringe_widths (f
, 1);
2574 x_set_border_width (f
, arg
, oldval
)
2576 Lisp_Object arg
, oldval
;
2580 if (XINT (arg
) == f
->output_data
.w32
->border_width
)
2583 if (FRAME_W32_WINDOW (f
) != 0)
2584 error ("Cannot change the border width of a window");
2586 f
->output_data
.w32
->border_width
= XINT (arg
);
2590 x_set_internal_border_width (f
, arg
, oldval
)
2592 Lisp_Object arg
, oldval
;
2594 int old
= f
->output_data
.w32
->internal_border_width
;
2597 f
->output_data
.w32
->internal_border_width
= XINT (arg
);
2598 if (f
->output_data
.w32
->internal_border_width
< 0)
2599 f
->output_data
.w32
->internal_border_width
= 0;
2601 if (f
->output_data
.w32
->internal_border_width
== old
)
2604 if (FRAME_W32_WINDOW (f
) != 0)
2606 x_set_window_size (f
, 0, f
->width
, f
->height
);
2607 SET_FRAME_GARBAGED (f
);
2608 do_pending_window_change (0);
2611 SET_FRAME_GARBAGED (f
);
2615 x_set_visibility (f
, value
, oldval
)
2617 Lisp_Object value
, oldval
;
2620 XSETFRAME (frame
, f
);
2623 Fmake_frame_invisible (frame
, Qt
);
2624 else if (EQ (value
, Qicon
))
2625 Ficonify_frame (frame
);
2627 Fmake_frame_visible (frame
);
2631 /* Change window heights in windows rooted in WINDOW by N lines. */
2634 x_change_window_heights (window
, n
)
2638 struct window
*w
= XWINDOW (window
);
2640 XSETFASTINT (w
->top
, XFASTINT (w
->top
) + n
);
2641 XSETFASTINT (w
->height
, XFASTINT (w
->height
) - n
);
2643 if (INTEGERP (w
->orig_top
))
2644 XSETFASTINT (w
->orig_top
, XFASTINT (w
->orig_top
) + n
);
2645 if (INTEGERP (w
->orig_height
))
2646 XSETFASTINT (w
->orig_height
, XFASTINT (w
->orig_height
) - n
);
2648 /* Handle just the top child in a vertical split. */
2649 if (!NILP (w
->vchild
))
2650 x_change_window_heights (w
->vchild
, n
);
2652 /* Adjust all children in a horizontal split. */
2653 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
2655 w
= XWINDOW (window
);
2656 x_change_window_heights (window
, n
);
2661 x_set_menu_bar_lines (f
, value
, oldval
)
2663 Lisp_Object value
, oldval
;
2666 int olines
= FRAME_MENU_BAR_LINES (f
);
2668 /* Right now, menu bars don't work properly in minibuf-only frames;
2669 most of the commands try to apply themselves to the minibuffer
2670 frame itself, and get an error because you can't switch buffers
2671 in or split the minibuffer window. */
2672 if (FRAME_MINIBUF_ONLY_P (f
))
2675 if (INTEGERP (value
))
2676 nlines
= XINT (value
);
2680 FRAME_MENU_BAR_LINES (f
) = 0;
2682 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
2685 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
2686 free_frame_menubar (f
);
2687 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
2689 /* Adjust the frame size so that the client (text) dimensions
2690 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
2692 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2693 do_pending_window_change (0);
2699 /* Set the number of lines used for the tool bar of frame F to VALUE.
2700 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
2701 is the old number of tool bar lines. This function changes the
2702 height of all windows on frame F to match the new tool bar height.
2703 The frame's height doesn't change. */
2706 x_set_tool_bar_lines (f
, value
, oldval
)
2708 Lisp_Object value
, oldval
;
2710 int delta
, nlines
, root_height
;
2711 Lisp_Object root_window
;
2713 /* Treat tool bars like menu bars. */
2714 if (FRAME_MINIBUF_ONLY_P (f
))
2717 /* Use VALUE only if an integer >= 0. */
2718 if (INTEGERP (value
) && XINT (value
) >= 0)
2719 nlines
= XFASTINT (value
);
2723 /* Make sure we redisplay all windows in this frame. */
2724 ++windows_or_buffers_changed
;
2726 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
2728 /* Don't resize the tool-bar to more than we have room for. */
2729 root_window
= FRAME_ROOT_WINDOW (f
);
2730 root_height
= XINT (XWINDOW (root_window
)->height
);
2731 if (root_height
- delta
< 1)
2733 delta
= root_height
- 1;
2734 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
2737 FRAME_TOOL_BAR_LINES (f
) = nlines
;
2738 x_change_window_heights (root_window
, delta
);
2741 /* We also have to make sure that the internal border at the top of
2742 the frame, below the menu bar or tool bar, is redrawn when the
2743 tool bar disappears. This is so because the internal border is
2744 below the tool bar if one is displayed, but is below the menu bar
2745 if there isn't a tool bar. The tool bar draws into the area
2746 below the menu bar. */
2747 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
2751 clear_current_matrices (f
);
2752 updating_frame
= NULL
;
2755 /* If the tool bar gets smaller, the internal border below it
2756 has to be cleared. It was formerly part of the display
2757 of the larger tool bar, and updating windows won't clear it. */
2760 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2761 int width
= PIXEL_WIDTH (f
);
2762 int y
= nlines
* CANON_Y_UNIT (f
);
2766 HDC hdc
= get_frame_dc (f
);
2767 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
2768 release_frame_dc (f
, hdc
);
2772 if (WINDOWP (f
->tool_bar_window
))
2773 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
2778 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
2781 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2782 name; if NAME is a string, set F's name to NAME and set
2783 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2785 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2786 suggesting a new name, which lisp code should override; if
2787 F->explicit_name is set, ignore the new name; otherwise, set it. */
2790 x_set_name (f
, name
, explicit)
2795 /* Make sure that requests from lisp code override requests from
2796 Emacs redisplay code. */
2799 /* If we're switching from explicit to implicit, we had better
2800 update the mode lines and thereby update the title. */
2801 if (f
->explicit_name
&& NILP (name
))
2802 update_mode_lines
= 1;
2804 f
->explicit_name
= ! NILP (name
);
2806 else if (f
->explicit_name
)
2809 /* If NAME is nil, set the name to the w32_id_name. */
2812 /* Check for no change needed in this very common case
2813 before we do any consing. */
2814 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
2815 XSTRING (f
->name
)->data
))
2817 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
2820 CHECK_STRING (name
);
2822 /* Don't change the name if it's already NAME. */
2823 if (! NILP (Fstring_equal (name
, f
->name
)))
2828 /* For setting the frame title, the title parameter should override
2829 the name parameter. */
2830 if (! NILP (f
->title
))
2833 if (FRAME_W32_WINDOW (f
))
2835 if (STRING_MULTIBYTE (name
))
2836 name
= ENCODE_SYSTEM (name
);
2839 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2844 /* This function should be called when the user's lisp code has
2845 specified a name for the frame; the name will override any set by the
2848 x_explicitly_set_name (f
, arg
, oldval
)
2850 Lisp_Object arg
, oldval
;
2852 x_set_name (f
, arg
, 1);
2855 /* This function should be called by Emacs redisplay code to set the
2856 name; names set this way will never override names set by the user's
2859 x_implicitly_set_name (f
, arg
, oldval
)
2861 Lisp_Object arg
, oldval
;
2863 x_set_name (f
, arg
, 0);
2866 /* Change the title of frame F to NAME.
2867 If NAME is nil, use the frame name as the title.
2869 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2870 name; if NAME is a string, set F's name to NAME and set
2871 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2873 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2874 suggesting a new name, which lisp code should override; if
2875 F->explicit_name is set, ignore the new name; otherwise, set it. */
2878 x_set_title (f
, name
, old_name
)
2880 Lisp_Object name
, old_name
;
2882 /* Don't change the title if it's already NAME. */
2883 if (EQ (name
, f
->title
))
2886 update_mode_lines
= 1;
2893 if (FRAME_W32_WINDOW (f
))
2895 if (STRING_MULTIBYTE (name
))
2896 name
= ENCODE_SYSTEM (name
);
2899 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2905 x_set_autoraise (f
, arg
, oldval
)
2907 Lisp_Object arg
, oldval
;
2909 f
->auto_raise
= !EQ (Qnil
, arg
);
2913 x_set_autolower (f
, arg
, oldval
)
2915 Lisp_Object arg
, oldval
;
2917 f
->auto_lower
= !EQ (Qnil
, arg
);
2921 x_set_unsplittable (f
, arg
, oldval
)
2923 Lisp_Object arg
, oldval
;
2925 f
->no_split
= !NILP (arg
);
2929 x_set_vertical_scroll_bars (f
, arg
, oldval
)
2931 Lisp_Object arg
, oldval
;
2933 if ((EQ (arg
, Qleft
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
2934 || (EQ (arg
, Qright
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
2935 || (NILP (arg
) && FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2936 || (!NILP (arg
) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)))
2938 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = NILP (arg
) ?
2939 vertical_scroll_bar_none
:
2940 /* Put scroll bars on the right by default, as is conventional
2943 ? vertical_scroll_bar_left
2944 : vertical_scroll_bar_right
;
2946 /* We set this parameter before creating the window for the
2947 frame, so we can get the geometry right from the start.
2948 However, if the window hasn't been created yet, we shouldn't
2949 call x_set_window_size. */
2950 if (FRAME_W32_WINDOW (f
))
2951 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2952 do_pending_window_change (0);
2957 x_set_scroll_bar_width (f
, arg
, oldval
)
2959 Lisp_Object arg
, oldval
;
2961 int wid
= FONT_WIDTH (f
->output_data
.w32
->font
);
2965 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
2966 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) +
2968 if (FRAME_W32_WINDOW (f
))
2969 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2970 do_pending_window_change (0);
2972 else if (INTEGERP (arg
) && XINT (arg
) > 0
2973 && XFASTINT (arg
) != FRAME_SCROLL_BAR_PIXEL_WIDTH (f
))
2975 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = XFASTINT (arg
);
2976 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
2978 if (FRAME_W32_WINDOW (f
))
2979 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2980 do_pending_window_change (0);
2982 change_frame_size (f
, 0, FRAME_WIDTH (f
), 0, 0, 0);
2983 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.hpos
= 0;
2984 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.x
= 0;
2987 /* Subroutines of creating an frame. */
2989 /* Make sure that Vx_resource_name is set to a reasonable value.
2990 Fix it up, or set it to `emacs' if it is too hopeless. */
2993 validate_x_resource_name ()
2996 /* Number of valid characters in the resource name. */
2998 /* Number of invalid characters in the resource name. */
3003 if (STRINGP (Vx_resource_name
))
3005 unsigned char *p
= XSTRING (Vx_resource_name
)->data
;
3008 len
= STRING_BYTES (XSTRING (Vx_resource_name
));
3010 /* Only letters, digits, - and _ are valid in resource names.
3011 Count the valid characters and count the invalid ones. */
3012 for (i
= 0; i
< len
; i
++)
3015 if (! ((c
>= 'a' && c
<= 'z')
3016 || (c
>= 'A' && c
<= 'Z')
3017 || (c
>= '0' && c
<= '9')
3018 || c
== '-' || c
== '_'))
3025 /* Not a string => completely invalid. */
3026 bad_count
= 5, good_count
= 0;
3028 /* If name is valid already, return. */
3032 /* If name is entirely invalid, or nearly so, use `emacs'. */
3034 || (good_count
== 1 && bad_count
> 0))
3036 Vx_resource_name
= build_string ("emacs");
3040 /* Name is partly valid. Copy it and replace the invalid characters
3041 with underscores. */
3043 Vx_resource_name
= new = Fcopy_sequence (Vx_resource_name
);
3045 for (i
= 0; i
< len
; i
++)
3047 int c
= XSTRING (new)->data
[i
];
3048 if (! ((c
>= 'a' && c
<= 'z')
3049 || (c
>= 'A' && c
<= 'Z')
3050 || (c
>= '0' && c
<= '9')
3051 || c
== '-' || c
== '_'))
3052 XSTRING (new)->data
[i
] = '_';
3057 extern char *x_get_string_resource ();
3059 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
3060 doc
: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3061 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3062 class, where INSTANCE is the name under which Emacs was invoked, or
3063 the name specified by the `-name' or `-rn' command-line arguments.
3065 The optional arguments COMPONENT and SUBCLASS add to the key and the
3066 class, respectively. You must specify both of them or neither.
3067 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3068 and the class is `Emacs.CLASS.SUBCLASS'. */)
3069 (attribute
, class, component
, subclass
)
3070 Lisp_Object attribute
, class, component
, subclass
;
3072 register char *value
;
3076 CHECK_STRING (attribute
);
3077 CHECK_STRING (class);
3079 if (!NILP (component
))
3080 CHECK_STRING (component
);
3081 if (!NILP (subclass
))
3082 CHECK_STRING (subclass
);
3083 if (NILP (component
) != NILP (subclass
))
3084 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3086 validate_x_resource_name ();
3088 /* Allocate space for the components, the dots which separate them,
3089 and the final '\0'. Make them big enough for the worst case. */
3090 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vx_resource_name
))
3091 + (STRINGP (component
)
3092 ? STRING_BYTES (XSTRING (component
)) : 0)
3093 + STRING_BYTES (XSTRING (attribute
))
3096 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
3097 + STRING_BYTES (XSTRING (class))
3098 + (STRINGP (subclass
)
3099 ? STRING_BYTES (XSTRING (subclass
)) : 0)
3102 /* Start with emacs.FRAMENAME for the name (the specific one)
3103 and with `Emacs' for the class key (the general one). */
3104 strcpy (name_key
, XSTRING (Vx_resource_name
)->data
);
3105 strcpy (class_key
, EMACS_CLASS
);
3107 strcat (class_key
, ".");
3108 strcat (class_key
, XSTRING (class)->data
);
3110 if (!NILP (component
))
3112 strcat (class_key
, ".");
3113 strcat (class_key
, XSTRING (subclass
)->data
);
3115 strcat (name_key
, ".");
3116 strcat (name_key
, XSTRING (component
)->data
);
3119 strcat (name_key
, ".");
3120 strcat (name_key
, XSTRING (attribute
)->data
);
3122 value
= x_get_string_resource (Qnil
,
3123 name_key
, class_key
);
3125 if (value
!= (char *) 0)
3126 return build_string (value
);
3131 /* Used when C code wants a resource value. */
3134 x_get_resource_string (attribute
, class)
3135 char *attribute
, *class;
3139 struct frame
*sf
= SELECTED_FRAME ();
3141 /* Allocate space for the components, the dots which separate them,
3142 and the final '\0'. */
3143 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vinvocation_name
))
3144 + strlen (attribute
) + 2);
3145 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
3146 + strlen (class) + 2);
3148 sprintf (name_key
, "%s.%s",
3149 XSTRING (Vinvocation_name
)->data
,
3151 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
3153 return x_get_string_resource (sf
, name_key
, class_key
);
3156 /* Types we might convert a resource string into. */
3166 /* Return the value of parameter PARAM.
3168 First search ALIST, then Vdefault_frame_alist, then the X defaults
3169 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3171 Convert the resource to the type specified by desired_type.
3173 If no default is specified, return Qunbound. If you call
3174 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
3175 and don't let it get stored in any Lisp-visible variables! */
3178 w32_get_arg (alist
, param
, attribute
, class, type
)
3179 Lisp_Object alist
, param
;
3182 enum resource_types type
;
3184 register Lisp_Object tem
;
3186 tem
= Fassq (param
, alist
);
3188 tem
= Fassq (param
, Vdefault_frame_alist
);
3194 tem
= Fx_get_resource (build_string (attribute
),
3195 build_string (class),
3203 case RES_TYPE_NUMBER
:
3204 return make_number (atoi (XSTRING (tem
)->data
));
3206 case RES_TYPE_FLOAT
:
3207 return make_float (atof (XSTRING (tem
)->data
));
3209 case RES_TYPE_BOOLEAN
:
3210 tem
= Fdowncase (tem
);
3211 if (!strcmp (XSTRING (tem
)->data
, "on")
3212 || !strcmp (XSTRING (tem
)->data
, "true"))
3217 case RES_TYPE_STRING
:
3220 case RES_TYPE_SYMBOL
:
3221 /* As a special case, we map the values `true' and `on'
3222 to Qt, and `false' and `off' to Qnil. */
3225 lower
= Fdowncase (tem
);
3226 if (!strcmp (XSTRING (lower
)->data
, "on")
3227 || !strcmp (XSTRING (lower
)->data
, "true"))
3229 else if (!strcmp (XSTRING (lower
)->data
, "off")
3230 || !strcmp (XSTRING (lower
)->data
, "false"))
3233 return Fintern (tem
, Qnil
);
3246 /* Record in frame F the specified or default value according to ALIST
3247 of the parameter named PROP (a Lisp symbol).
3248 If no value is specified for PROP, look for an X default for XPROP
3249 on the frame named NAME.
3250 If that is not found either, use the value DEFLT. */
3253 x_default_parameter (f
, alist
, prop
, deflt
, xprop
, xclass
, type
)
3260 enum resource_types type
;
3264 tem
= w32_get_arg (alist
, prop
, xprop
, xclass
, type
);
3265 if (EQ (tem
, Qunbound
))
3267 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
3271 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
3272 doc
: /* Parse an X-style geometry string STRING.
3273 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3274 The properties returned may include `top', `left', `height', and `width'.
3275 The value of `left' or `top' may be an integer,
3276 or a list (+ N) meaning N pixels relative to top/left corner,
3277 or a list (- N) meaning -N pixels relative to bottom/right corner. */)
3282 unsigned int width
, height
;
3285 CHECK_STRING (string
);
3287 geometry
= XParseGeometry ((char *) XSTRING (string
)->data
,
3288 &x
, &y
, &width
, &height
);
3291 if (geometry
& XValue
)
3293 Lisp_Object element
;
3295 if (x
>= 0 && (geometry
& XNegative
))
3296 element
= Fcons (Qleft
, Fcons (Qminus
, Fcons (make_number (-x
), Qnil
)));
3297 else if (x
< 0 && ! (geometry
& XNegative
))
3298 element
= Fcons (Qleft
, Fcons (Qplus
, Fcons (make_number (x
), Qnil
)));
3300 element
= Fcons (Qleft
, make_number (x
));
3301 result
= Fcons (element
, result
);
3304 if (geometry
& YValue
)
3306 Lisp_Object element
;
3308 if (y
>= 0 && (geometry
& YNegative
))
3309 element
= Fcons (Qtop
, Fcons (Qminus
, Fcons (make_number (-y
), Qnil
)));
3310 else if (y
< 0 && ! (geometry
& YNegative
))
3311 element
= Fcons (Qtop
, Fcons (Qplus
, Fcons (make_number (y
), Qnil
)));
3313 element
= Fcons (Qtop
, make_number (y
));
3314 result
= Fcons (element
, result
);
3317 if (geometry
& WidthValue
)
3318 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
3319 if (geometry
& HeightValue
)
3320 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
3325 /* Calculate the desired size and position of this window,
3326 and return the flags saying which aspects were specified.
3328 This function does not make the coordinates positive. */
3330 #define DEFAULT_ROWS 40
3331 #define DEFAULT_COLS 80
3334 x_figure_window_size (f
, parms
)
3338 register Lisp_Object tem0
, tem1
, tem2
;
3339 long window_prompting
= 0;
3341 /* Default values if we fall through.
3342 Actually, if that happens we should get
3343 window manager prompting. */
3344 SET_FRAME_WIDTH (f
, DEFAULT_COLS
);
3345 f
->height
= DEFAULT_ROWS
;
3346 /* Window managers expect that if program-specified
3347 positions are not (0,0), they're intentional, not defaults. */
3348 f
->output_data
.w32
->top_pos
= 0;
3349 f
->output_data
.w32
->left_pos
= 0;
3351 /* Ensure that old new_width and new_height will not override the
3353 FRAME_NEW_WIDTH (f
) = 0;
3354 FRAME_NEW_HEIGHT (f
) = 0;
3356 tem0
= w32_get_arg (parms
, Qheight
, 0, 0, RES_TYPE_NUMBER
);
3357 tem1
= w32_get_arg (parms
, Qwidth
, 0, 0, RES_TYPE_NUMBER
);
3358 tem2
= w32_get_arg (parms
, Quser_size
, 0, 0, RES_TYPE_NUMBER
);
3359 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3361 if (!EQ (tem0
, Qunbound
))
3363 CHECK_NUMBER (tem0
);
3364 f
->height
= XINT (tem0
);
3366 if (!EQ (tem1
, Qunbound
))
3368 CHECK_NUMBER (tem1
);
3369 SET_FRAME_WIDTH (f
, XINT (tem1
));
3371 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
3372 window_prompting
|= USSize
;
3374 window_prompting
|= PSize
;
3377 f
->output_data
.w32
->vertical_scroll_bar_extra
3378 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
3380 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
3381 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
3382 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.w32
->font
)));
3384 x_compute_fringe_widths (f
, 0);
3386 f
->output_data
.w32
->pixel_width
= CHAR_TO_PIXEL_WIDTH (f
, f
->width
);
3387 f
->output_data
.w32
->pixel_height
= CHAR_TO_PIXEL_HEIGHT (f
, f
->height
);
3389 tem0
= w32_get_arg (parms
, Qtop
, 0, 0, RES_TYPE_NUMBER
);
3390 tem1
= w32_get_arg (parms
, Qleft
, 0, 0, RES_TYPE_NUMBER
);
3391 tem2
= w32_get_arg (parms
, Quser_position
, 0, 0, RES_TYPE_NUMBER
);
3392 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3394 if (EQ (tem0
, Qminus
))
3396 f
->output_data
.w32
->top_pos
= 0;
3397 window_prompting
|= YNegative
;
3399 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qminus
)
3400 && CONSP (XCDR (tem0
))
3401 && INTEGERP (XCAR (XCDR (tem0
))))
3403 f
->output_data
.w32
->top_pos
= - XINT (XCAR (XCDR (tem0
)));
3404 window_prompting
|= YNegative
;
3406 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qplus
)
3407 && CONSP (XCDR (tem0
))
3408 && INTEGERP (XCAR (XCDR (tem0
))))
3410 f
->output_data
.w32
->top_pos
= XINT (XCAR (XCDR (tem0
)));
3412 else if (EQ (tem0
, Qunbound
))
3413 f
->output_data
.w32
->top_pos
= 0;
3416 CHECK_NUMBER (tem0
);
3417 f
->output_data
.w32
->top_pos
= XINT (tem0
);
3418 if (f
->output_data
.w32
->top_pos
< 0)
3419 window_prompting
|= YNegative
;
3422 if (EQ (tem1
, Qminus
))
3424 f
->output_data
.w32
->left_pos
= 0;
3425 window_prompting
|= XNegative
;
3427 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qminus
)
3428 && CONSP (XCDR (tem1
))
3429 && INTEGERP (XCAR (XCDR (tem1
))))
3431 f
->output_data
.w32
->left_pos
= - XINT (XCAR (XCDR (tem1
)));
3432 window_prompting
|= XNegative
;
3434 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qplus
)
3435 && CONSP (XCDR (tem1
))
3436 && INTEGERP (XCAR (XCDR (tem1
))))
3438 f
->output_data
.w32
->left_pos
= XINT (XCAR (XCDR (tem1
)));
3440 else if (EQ (tem1
, Qunbound
))
3441 f
->output_data
.w32
->left_pos
= 0;
3444 CHECK_NUMBER (tem1
);
3445 f
->output_data
.w32
->left_pos
= XINT (tem1
);
3446 if (f
->output_data
.w32
->left_pos
< 0)
3447 window_prompting
|= XNegative
;
3450 if (!NILP (tem2
) && ! EQ (tem2
, Qunbound
))
3451 window_prompting
|= USPosition
;
3453 window_prompting
|= PPosition
;
3456 if (f
->output_data
.w32
->want_fullscreen
!= FULLSCREEN_NONE
)
3461 /* It takes both for some WM:s to place it where we want */
3462 window_prompting
= USPosition
| PPosition
;
3463 x_fullscreen_adjust (f
, &width
, &height
, &top
, &left
);
3466 f
->output_data
.w32
->pixel_width
= CHAR_TO_PIXEL_WIDTH (f
, f
->width
);
3467 f
->output_data
.w32
->pixel_height
= CHAR_TO_PIXEL_HEIGHT (f
, f
->height
);
3468 f
->output_data
.w32
->left_pos
= left
;
3469 f
->output_data
.w32
->top_pos
= top
;
3472 return window_prompting
;
3477 extern LRESULT CALLBACK
w32_wnd_proc ();
3480 w32_init_class (hinst
)
3485 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
3486 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
3488 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
3489 wc
.hInstance
= hinst
;
3490 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
3491 wc
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
3492 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
3493 wc
.lpszMenuName
= NULL
;
3494 wc
.lpszClassName
= EMACS_CLASS
;
3496 return (RegisterClass (&wc
));
3500 w32_createscrollbar (f
, bar
)
3502 struct scroll_bar
* bar
;
3504 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
3505 /* Position and size of scroll bar. */
3506 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
3508 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
3510 FRAME_W32_WINDOW (f
),
3517 w32_createwindow (f
)
3523 rect
.left
= rect
.top
= 0;
3524 rect
.right
= PIXEL_WIDTH (f
);
3525 rect
.bottom
= PIXEL_HEIGHT (f
);
3527 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3528 FRAME_EXTERNAL_MENU_BAR (f
));
3530 /* Do first time app init */
3534 w32_init_class (hinst
);
3537 FRAME_W32_WINDOW (f
) = hwnd
3538 = CreateWindow (EMACS_CLASS
,
3540 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
3541 f
->output_data
.w32
->left_pos
,
3542 f
->output_data
.w32
->top_pos
,
3543 rect
.right
- rect
.left
,
3544 rect
.bottom
- rect
.top
,
3552 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
3553 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
3554 SetWindowLong (hwnd
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
3555 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->output_data
.w32
->vertical_scroll_bar_extra
);
3556 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3558 /* Enable drag-n-drop. */
3559 DragAcceptFiles (hwnd
, TRUE
);
3561 /* Do this to discard the default setting specified by our parent. */
3562 ShowWindow (hwnd
, SW_HIDE
);
3567 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
3574 wmsg
->msg
.hwnd
= hwnd
;
3575 wmsg
->msg
.message
= msg
;
3576 wmsg
->msg
.wParam
= wParam
;
3577 wmsg
->msg
.lParam
= lParam
;
3578 wmsg
->msg
.time
= GetMessageTime ();
3583 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
3584 between left and right keys as advertised. We test for this
3585 support dynamically, and set a flag when the support is absent. If
3586 absent, we keep track of the left and right control and alt keys
3587 ourselves. This is particularly necessary on keyboards that rely
3588 upon the AltGr key, which is represented as having the left control
3589 and right alt keys pressed. For these keyboards, we need to know
3590 when the left alt key has been pressed in addition to the AltGr key
3591 so that we can properly support M-AltGr-key sequences (such as M-@
3592 on Swedish keyboards). */
3594 #define EMACS_LCONTROL 0
3595 #define EMACS_RCONTROL 1
3596 #define EMACS_LMENU 2
3597 #define EMACS_RMENU 3
3599 static int modifiers
[4];
3600 static int modifiers_recorded
;
3601 static int modifier_key_support_tested
;
3604 test_modifier_support (unsigned int wparam
)
3608 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
3610 if (wparam
== VK_CONTROL
)
3620 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
3621 modifiers_recorded
= 1;
3623 modifiers_recorded
= 0;
3624 modifier_key_support_tested
= 1;
3628 record_keydown (unsigned int wparam
, unsigned int lparam
)
3632 if (!modifier_key_support_tested
)
3633 test_modifier_support (wparam
);
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
;
3647 record_keyup (unsigned int wparam
, unsigned int lparam
)
3651 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3654 if (wparam
== VK_CONTROL
)
3655 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3657 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3662 /* Emacs can lose focus while a modifier key has been pressed. When
3663 it regains focus, be conservative and clear all modifiers since
3664 we cannot reconstruct the left and right modifier state. */
3670 if (GetFocus () == NULL
)
3671 /* Emacs doesn't have keyboard focus. Do nothing. */
3674 ctrl
= GetAsyncKeyState (VK_CONTROL
);
3675 alt
= GetAsyncKeyState (VK_MENU
);
3677 if (!(ctrl
& 0x08000))
3678 /* Clear any recorded control modifier state. */
3679 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3681 if (!(alt
& 0x08000))
3682 /* Clear any recorded alt modifier state. */
3683 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3685 /* Update the state of all modifier keys, because modifiers used in
3686 hot-key combinations can get stuck on if Emacs loses focus as a
3687 result of a hot-key being pressed. */
3691 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
3693 GetKeyboardState (keystate
);
3694 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
3695 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
3696 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
3697 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
3698 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
3699 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
3700 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
3701 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
3702 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
3703 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
3704 SetKeyboardState (keystate
);
3708 /* Synchronize modifier state with what is reported with the current
3709 keystroke. Even if we cannot distinguish between left and right
3710 modifier keys, we know that, if no modifiers are set, then neither
3711 the left or right modifier should be set. */
3715 if (!modifiers_recorded
)
3718 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
3719 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3721 if (!(GetKeyState (VK_MENU
) & 0x8000))
3722 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3726 modifier_set (int vkey
)
3728 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
3729 return (GetKeyState (vkey
) & 0x1);
3730 if (!modifiers_recorded
)
3731 return (GetKeyState (vkey
) & 0x8000);
3736 return modifiers
[EMACS_LCONTROL
];
3738 return modifiers
[EMACS_RCONTROL
];
3740 return modifiers
[EMACS_LMENU
];
3742 return modifiers
[EMACS_RMENU
];
3744 return (GetKeyState (vkey
) & 0x8000);
3747 /* Convert between the modifier bits W32 uses and the modifier bits
3751 w32_key_to_modifier (int key
)
3753 Lisp_Object key_mapping
;
3758 key_mapping
= Vw32_lwindow_modifier
;
3761 key_mapping
= Vw32_rwindow_modifier
;
3764 key_mapping
= Vw32_apps_modifier
;
3767 key_mapping
= Vw32_scroll_lock_modifier
;
3773 /* NB. This code runs in the input thread, asychronously to the lisp
3774 thread, so we must be careful to ensure access to lisp data is
3775 thread-safe. The following code is safe because the modifier
3776 variable values are updated atomically from lisp and symbols are
3777 not relocated by GC. Also, we don't have to worry about seeing GC
3779 if (EQ (key_mapping
, Qhyper
))
3780 return hyper_modifier
;
3781 if (EQ (key_mapping
, Qsuper
))
3782 return super_modifier
;
3783 if (EQ (key_mapping
, Qmeta
))
3784 return meta_modifier
;
3785 if (EQ (key_mapping
, Qalt
))
3786 return alt_modifier
;
3787 if (EQ (key_mapping
, Qctrl
))
3788 return ctrl_modifier
;
3789 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
3790 return ctrl_modifier
;
3791 if (EQ (key_mapping
, Qshift
))
3792 return shift_modifier
;
3794 /* Don't generate any modifier if not explicitly requested. */
3799 w32_get_modifiers ()
3801 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
3802 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
3803 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
3804 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
3805 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
3806 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
3807 (modifier_set (VK_MENU
) ?
3808 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
3811 /* We map the VK_* modifiers into console modifier constants
3812 so that we can use the same routines to handle both console
3813 and window input. */
3816 construct_console_modifiers ()
3821 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
3822 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
3823 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
3824 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
3825 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
3826 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
3827 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
3828 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
3829 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
3830 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
3831 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
3837 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
3841 /* Convert to emacs modifiers. */
3842 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
3848 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
3850 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
3853 if (virt_key
== VK_RETURN
)
3854 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
3856 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
3857 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
3859 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
3860 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
3862 if (virt_key
== VK_CLEAR
)
3863 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
3868 /* List of special key combinations which w32 would normally capture,
3869 but emacs should grab instead. Not directly visible to lisp, to
3870 simplify synchronization. Each item is an integer encoding a virtual
3871 key code and modifier combination to capture. */
3872 Lisp_Object w32_grabbed_keys
;
3874 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
3875 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
3876 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
3877 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
3879 /* Register hot-keys for reserved key combinations when Emacs has
3880 keyboard focus, since this is the only way Emacs can receive key
3881 combinations like Alt-Tab which are used by the system. */
3884 register_hot_keys (hwnd
)
3887 Lisp_Object keylist
;
3889 /* Use GC_CONSP, since we are called asynchronously. */
3890 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3892 Lisp_Object key
= XCAR (keylist
);
3894 /* Deleted entries get set to nil. */
3895 if (!INTEGERP (key
))
3898 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
3899 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
3904 unregister_hot_keys (hwnd
)
3907 Lisp_Object keylist
;
3909 /* Use GC_CONSP, since we are called asynchronously. */
3910 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3912 Lisp_Object key
= XCAR (keylist
);
3914 if (!INTEGERP (key
))
3917 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
3921 /* Main message dispatch loop. */
3924 w32_msg_pump (deferred_msg
* msg_buf
)
3930 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
3932 while (GetMessage (&msg
, NULL
, 0, 0))
3934 if (msg
.hwnd
== NULL
)
3936 switch (msg
.message
)
3939 /* Produced by complete_deferred_msg; just ignore. */
3941 case WM_EMACS_CREATEWINDOW
:
3942 w32_createwindow ((struct frame
*) msg
.wParam
);
3943 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3946 case WM_EMACS_SETLOCALE
:
3947 SetThreadLocale (msg
.wParam
);
3948 /* Reply is not expected. */
3950 case WM_EMACS_SETKEYBOARDLAYOUT
:
3951 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
3952 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3956 case WM_EMACS_REGISTER_HOT_KEY
:
3957 focus_window
= GetFocus ();
3958 if (focus_window
!= NULL
)
3959 RegisterHotKey (focus_window
,
3960 HOTKEY_ID (msg
.wParam
),
3961 HOTKEY_MODIFIERS (msg
.wParam
),
3962 HOTKEY_VK_CODE (msg
.wParam
));
3963 /* Reply is not expected. */
3965 case WM_EMACS_UNREGISTER_HOT_KEY
:
3966 focus_window
= GetFocus ();
3967 if (focus_window
!= NULL
)
3968 UnregisterHotKey (focus_window
, HOTKEY_ID (msg
.wParam
));
3969 /* Mark item as erased. NB: this code must be
3970 thread-safe. The next line is okay because the cons
3971 cell is never made into garbage and is not relocated by
3973 XSETCAR ((Lisp_Object
) msg
.lParam
, Qnil
);
3974 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3977 case WM_EMACS_TOGGLE_LOCK_KEY
:
3979 int vk_code
= (int) msg
.wParam
;
3980 int cur_state
= (GetKeyState (vk_code
) & 1);
3981 Lisp_Object new_state
= (Lisp_Object
) msg
.lParam
;
3983 /* NB: This code must be thread-safe. It is safe to
3984 call NILP because symbols are not relocated by GC,
3985 and pointer here is not touched by GC (so the markbit
3986 can't be set). Numbers are safe because they are
3987 immediate values. */
3988 if (NILP (new_state
)
3989 || (NUMBERP (new_state
)
3990 && ((XUINT (new_state
)) & 1) != cur_state
))
3992 one_w32_display_info
.faked_key
= vk_code
;
3994 keybd_event ((BYTE
) vk_code
,
3995 (BYTE
) MapVirtualKey (vk_code
, 0),
3996 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3997 keybd_event ((BYTE
) vk_code
,
3998 (BYTE
) MapVirtualKey (vk_code
, 0),
3999 KEYEVENTF_EXTENDEDKEY
| 0, 0);
4000 keybd_event ((BYTE
) vk_code
,
4001 (BYTE
) MapVirtualKey (vk_code
, 0),
4002 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4003 cur_state
= !cur_state
;
4005 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
4011 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
4016 DispatchMessage (&msg
);
4019 /* Exit nested loop when our deferred message has completed. */
4020 if (msg_buf
->completed
)
4025 deferred_msg
* deferred_msg_head
;
4027 static deferred_msg
*
4028 find_deferred_msg (HWND hwnd
, UINT msg
)
4030 deferred_msg
* item
;
4032 /* Don't actually need synchronization for read access, since
4033 modification of single pointer is always atomic. */
4034 /* enter_crit (); */
4036 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
4037 if (item
->w32msg
.msg
.hwnd
== hwnd
4038 && item
->w32msg
.msg
.message
== msg
)
4041 /* leave_crit (); */
4047 send_deferred_msg (deferred_msg
* msg_buf
,
4053 /* Only input thread can send deferred messages. */
4054 if (GetCurrentThreadId () != dwWindowsThreadId
)
4057 /* It is an error to send a message that is already deferred. */
4058 if (find_deferred_msg (hwnd
, msg
) != NULL
)
4061 /* Enforced synchronization is not needed because this is the only
4062 function that alters deferred_msg_head, and the following critical
4063 section is guaranteed to only be serially reentered (since only the
4064 input thread can call us). */
4066 /* enter_crit (); */
4068 msg_buf
->completed
= 0;
4069 msg_buf
->next
= deferred_msg_head
;
4070 deferred_msg_head
= msg_buf
;
4071 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
4073 /* leave_crit (); */
4075 /* Start a new nested message loop to process other messages until
4076 this one is completed. */
4077 w32_msg_pump (msg_buf
);
4079 deferred_msg_head
= msg_buf
->next
;
4081 return msg_buf
->result
;
4085 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
4087 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
4089 if (msg_buf
== NULL
)
4090 /* Message may have been cancelled, so don't abort(). */
4093 msg_buf
->result
= result
;
4094 msg_buf
->completed
= 1;
4096 /* Ensure input thread is woken so it notices the completion. */
4097 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
4101 cancel_all_deferred_msgs ()
4103 deferred_msg
* item
;
4105 /* Don't actually need synchronization for read access, since
4106 modification of single pointer is always atomic. */
4107 /* enter_crit (); */
4109 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
4112 item
->completed
= 1;
4115 /* leave_crit (); */
4117 /* Ensure input thread is woken so it notices the completion. */
4118 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
4126 deferred_msg dummy_buf
;
4128 /* Ensure our message queue is created */
4130 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
4132 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
4135 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
4136 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
4137 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
4139 /* This is the inital message loop which should only exit when the
4140 application quits. */
4141 w32_msg_pump (&dummy_buf
);
4147 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
4157 wmsg
.dwModifiers
= modifiers
;
4159 /* Detect quit_char and set quit-flag directly. Note that we
4160 still need to post a message to ensure the main thread will be
4161 woken up if blocked in sys_select(), but we do NOT want to post
4162 the quit_char message itself (because it will usually be as if
4163 the user had typed quit_char twice). Instead, we post a dummy
4164 message that has no particular effect. */
4167 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
4168 c
= make_ctrl_char (c
) & 0377;
4170 || (wmsg
.dwModifiers
== 0 &&
4171 XFASTINT (Vw32_quit_key
) && wParam
== XFASTINT (Vw32_quit_key
)))
4175 /* The choice of message is somewhat arbitrary, as long as
4176 the main thread handler just ignores it. */
4179 /* Interrupt any blocking system calls. */
4182 /* As a safety precaution, forcibly complete any deferred
4183 messages. This is a kludge, but I don't see any particularly
4184 clean way to handle the situation where a deferred message is
4185 "dropped" in the lisp thread, and will thus never be
4186 completed, eg. by the user trying to activate the menubar
4187 when the lisp thread is busy, and then typing C-g when the
4188 menubar doesn't open promptly (with the result that the
4189 menubar never responds at all because the deferred
4190 WM_INITMENU message is never completed). Another problem
4191 situation is when the lisp thread calls SendMessage (to send
4192 a window manager command) when a message has been deferred;
4193 the lisp thread gets blocked indefinitely waiting for the
4194 deferred message to be completed, which itself is waiting for
4195 the lisp thread to respond.
4197 Note that we don't want to block the input thread waiting for
4198 a reponse from the lisp thread (although that would at least
4199 solve the deadlock problem above), because we want to be able
4200 to receive C-g to interrupt the lisp thread. */
4201 cancel_all_deferred_msgs ();
4205 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4208 /* Main window procedure */
4211 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
4218 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4220 int windows_translate
;
4223 /* Note that it is okay to call x_window_to_frame, even though we are
4224 not running in the main lisp thread, because frame deletion
4225 requires the lisp thread to synchronize with this thread. Thus, if
4226 a frame struct is returned, it can be used without concern that the
4227 lisp thread might make it disappear while we are using it.
4229 NB. Walking the frame list in this thread is safe (as long as
4230 writes of Lisp_Object slots are atomic, which they are on Windows).
4231 Although delete-frame can destructively modify the frame list while
4232 we are walking it, a garbage collection cannot occur until after
4233 delete-frame has synchronized with this thread.
4235 It is also safe to use functions that make GDI calls, such as
4236 w32_clear_rect, because these functions must obtain a DC handle
4237 from the frame struct using get_frame_dc which is thread-aware. */
4242 f
= x_window_to_frame (dpyinfo
, hwnd
);
4245 HDC hdc
= get_frame_dc (f
);
4246 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
4247 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
4248 release_frame_dc (f
, hdc
);
4250 #if defined (W32_DEBUG_DISPLAY)
4251 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
4253 wmsg
.rect
.left
, wmsg
.rect
.top
,
4254 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
4255 #endif /* W32_DEBUG_DISPLAY */
4258 case WM_PALETTECHANGED
:
4259 /* ignore our own changes */
4260 if ((HWND
)wParam
!= hwnd
)
4262 f
= x_window_to_frame (dpyinfo
, hwnd
);
4264 /* get_frame_dc will realize our palette and force all
4265 frames to be redrawn if needed. */
4266 release_frame_dc (f
, get_frame_dc (f
));
4271 PAINTSTRUCT paintStruct
;
4273 bzero (&update_rect
, sizeof (update_rect
));
4275 f
= x_window_to_frame (dpyinfo
, hwnd
);
4278 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
4282 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
4283 fails. Apparently this can happen under some
4285 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
4288 BeginPaint (hwnd
, &paintStruct
);
4290 /* The rectangles returned by GetUpdateRect and BeginPaint
4291 do not always match. Play it safe by assuming both areas
4293 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
4295 #if defined (W32_DEBUG_DISPLAY)
4296 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
4298 wmsg
.rect
.left
, wmsg
.rect
.top
,
4299 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
4300 DebPrint ((" [update region is %d,%d-%d,%d]\n",
4301 update_rect
.left
, update_rect
.top
,
4302 update_rect
.right
, update_rect
.bottom
));
4304 EndPaint (hwnd
, &paintStruct
);
4307 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4312 /* If GetUpdateRect returns 0 (meaning there is no update
4313 region), assume the whole window needs to be repainted. */
4314 GetClientRect(hwnd
, &wmsg
.rect
);
4315 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4319 case WM_INPUTLANGCHANGE
:
4320 /* Inform lisp thread of keyboard layout changes. */
4321 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4323 /* Clear dead keys in the keyboard state; for simplicity only
4324 preserve modifier key states. */
4329 GetKeyboardState (keystate
);
4330 for (i
= 0; i
< 256; i
++)
4347 SetKeyboardState (keystate
);
4352 /* Synchronize hot keys with normal input. */
4353 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
4358 record_keyup (wParam
, lParam
);
4363 /* Ignore keystrokes we fake ourself; see below. */
4364 if (dpyinfo
->faked_key
== wParam
)
4366 dpyinfo
->faked_key
= 0;
4367 /* Make sure TranslateMessage sees them though (as long as
4368 they don't produce WM_CHAR messages). This ensures that
4369 indicator lights are toggled promptly on Windows 9x, for
4371 if (lispy_function_keys
[wParam
] != 0)
4373 windows_translate
= 1;
4379 /* Synchronize modifiers with current keystroke. */
4381 record_keydown (wParam
, lParam
);
4382 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
4384 windows_translate
= 0;
4389 if (NILP (Vw32_pass_lwindow_to_system
))
4391 /* Prevent system from acting on keyup (which opens the
4392 Start menu if no other key was pressed) by simulating a
4393 press of Space which we will ignore. */
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_lwindow_modifier
))
4408 if (NILP (Vw32_pass_rwindow_to_system
))
4410 if (GetAsyncKeyState (wParam
) & 1)
4412 if (NUMBERP (Vw32_phantom_key_code
))
4413 key
= XUINT (Vw32_phantom_key_code
) & 255;
4416 dpyinfo
->faked_key
= key
;
4417 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4420 if (!NILP (Vw32_rwindow_modifier
))
4424 if (!NILP (Vw32_apps_modifier
))
4428 if (NILP (Vw32_pass_alt_to_system
))
4429 /* Prevent DefWindowProc from activating the menu bar if an
4430 Alt key is pressed and released by itself. */
4432 windows_translate
= 1;
4435 /* Decide whether to treat as modifier or function key. */
4436 if (NILP (Vw32_enable_caps_lock
))
4437 goto disable_lock_key
;
4438 windows_translate
= 1;
4441 /* Decide whether to treat as modifier or function key. */
4442 if (NILP (Vw32_enable_num_lock
))
4443 goto disable_lock_key
;
4444 windows_translate
= 1;
4447 /* Decide whether to treat as modifier or function key. */
4448 if (NILP (Vw32_scroll_lock_modifier
))
4449 goto disable_lock_key
;
4450 windows_translate
= 1;
4453 /* Ensure the appropriate lock key state (and indicator light)
4454 remains in the same state. We do this by faking another
4455 press of the relevant key. Apparently, this really is the
4456 only way to toggle the state of the indicator lights. */
4457 dpyinfo
->faked_key
= wParam
;
4458 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4459 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4460 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4461 KEYEVENTF_EXTENDEDKEY
| 0, 0);
4462 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4463 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4464 /* Ensure indicator lights are updated promptly on Windows 9x
4465 (TranslateMessage apparently does this), after forwarding
4467 post_character_message (hwnd
, msg
, wParam
, lParam
,
4468 w32_get_key_modifiers (wParam
, lParam
));
4469 windows_translate
= 1;
4473 case VK_PROCESSKEY
: /* Generated by IME. */
4474 windows_translate
= 1;
4477 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
4478 which is confusing for purposes of key binding; convert
4479 VK_CANCEL events into VK_PAUSE events. */
4483 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
4484 for purposes of key binding; convert these back into
4485 VK_NUMLOCK events, at least when we want to see NumLock key
4486 presses. (Note that there is never any possibility that
4487 VK_PAUSE with Ctrl really is C-Pause as per above.) */
4488 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
4489 wParam
= VK_NUMLOCK
;
4492 /* If not defined as a function key, change it to a WM_CHAR message. */
4493 if (lispy_function_keys
[wParam
] == 0)
4495 DWORD modifiers
= construct_console_modifiers ();
4497 if (!NILP (Vw32_recognize_altgr
)
4498 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
4500 /* Always let TranslateMessage handle AltGr key chords;
4501 for some reason, ToAscii doesn't always process AltGr
4502 chords correctly. */
4503 windows_translate
= 1;
4505 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
4507 /* Handle key chords including any modifiers other
4508 than shift directly, in order to preserve as much
4509 modifier information as possible. */
4510 if ('A' <= wParam
&& wParam
<= 'Z')
4512 /* Don't translate modified alphabetic keystrokes,
4513 so the user doesn't need to constantly switch
4514 layout to type control or meta keystrokes when
4515 the normal layout translates alphabetic
4516 characters to non-ascii characters. */
4517 if (!modifier_set (VK_SHIFT
))
4518 wParam
+= ('a' - 'A');
4523 /* Try to handle other keystrokes by determining the
4524 base character (ie. translating the base key plus
4528 KEY_EVENT_RECORD key
;
4530 key
.bKeyDown
= TRUE
;
4531 key
.wRepeatCount
= 1;
4532 key
.wVirtualKeyCode
= wParam
;
4533 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
4534 key
.uChar
.AsciiChar
= 0;
4535 key
.dwControlKeyState
= modifiers
;
4537 add
= w32_kbd_patch_key (&key
);
4538 /* 0 means an unrecognised keycode, negative means
4539 dead key. Ignore both. */
4542 /* Forward asciified character sequence. */
4543 post_character_message
4544 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
4545 w32_get_key_modifiers (wParam
, lParam
));
4546 w32_kbd_patch_key (&key
);
4553 /* Let TranslateMessage handle everything else. */
4554 windows_translate
= 1;
4560 if (windows_translate
)
4562 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
4564 windows_msg
.time
= GetMessageTime ();
4565 TranslateMessage (&windows_msg
);
4573 post_character_message (hwnd
, msg
, wParam
, lParam
,
4574 w32_get_key_modifiers (wParam
, lParam
));
4577 /* Simulate middle mouse button events when left and right buttons
4578 are used together, but only if user has two button mouse. */
4579 case WM_LBUTTONDOWN
:
4580 case WM_RBUTTONDOWN
:
4581 if (XINT (Vw32_num_mouse_buttons
) > 2)
4582 goto handle_plain_button
;
4585 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
4586 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
4588 if (button_state
& this)
4591 if (button_state
== 0)
4594 button_state
|= this;
4596 if (button_state
& other
)
4598 if (mouse_button_timer
)
4600 KillTimer (hwnd
, mouse_button_timer
);
4601 mouse_button_timer
= 0;
4603 /* Generate middle mouse event instead. */
4604 msg
= WM_MBUTTONDOWN
;
4605 button_state
|= MMOUSE
;
4607 else if (button_state
& MMOUSE
)
4609 /* Ignore button event if we've already generated a
4610 middle mouse down event. This happens if the
4611 user releases and press one of the two buttons
4612 after we've faked a middle mouse event. */
4617 /* Flush out saved message. */
4618 post_msg (&saved_mouse_button_msg
);
4620 wmsg
.dwModifiers
= w32_get_modifiers ();
4621 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4623 /* Clear message buffer. */
4624 saved_mouse_button_msg
.msg
.hwnd
= 0;
4628 /* Hold onto message for now. */
4629 mouse_button_timer
=
4630 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
4631 XINT (Vw32_mouse_button_tolerance
), NULL
);
4632 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
4633 saved_mouse_button_msg
.msg
.message
= msg
;
4634 saved_mouse_button_msg
.msg
.wParam
= wParam
;
4635 saved_mouse_button_msg
.msg
.lParam
= lParam
;
4636 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
4637 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
4644 if (XINT (Vw32_num_mouse_buttons
) > 2)
4645 goto handle_plain_button
;
4648 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
4649 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
4651 if ((button_state
& this) == 0)
4654 button_state
&= ~this;
4656 if (button_state
& MMOUSE
)
4658 /* Only generate event when second button is released. */
4659 if ((button_state
& other
) == 0)
4662 button_state
&= ~MMOUSE
;
4664 if (button_state
) abort ();
4671 /* Flush out saved message if necessary. */
4672 if (saved_mouse_button_msg
.msg
.hwnd
)
4674 post_msg (&saved_mouse_button_msg
);
4677 wmsg
.dwModifiers
= w32_get_modifiers ();
4678 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4680 /* Always clear message buffer and cancel timer. */
4681 saved_mouse_button_msg
.msg
.hwnd
= 0;
4682 KillTimer (hwnd
, mouse_button_timer
);
4683 mouse_button_timer
= 0;
4685 if (button_state
== 0)
4690 case WM_XBUTTONDOWN
:
4692 if (w32_pass_extra_mouse_buttons_to_system
)
4694 /* else fall through and process them. */
4695 case WM_MBUTTONDOWN
:
4697 handle_plain_button
:
4702 if (parse_button (msg
, HIWORD (wParam
), &button
, &up
))
4704 if (up
) ReleaseCapture ();
4705 else SetCapture (hwnd
);
4706 button
= (button
== 0) ? LMOUSE
:
4707 ((button
== 1) ? MMOUSE
: RMOUSE
);
4709 button_state
&= ~button
;
4711 button_state
|= button
;
4715 wmsg
.dwModifiers
= w32_get_modifiers ();
4716 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4718 /* Need to return true for XBUTTON messages, false for others,
4719 to indicate that we processed the message. */
4720 return (msg
== WM_XBUTTONDOWN
|| msg
== WM_XBUTTONUP
);
4723 /* If the mouse has just moved into the frame, start tracking
4724 it, so we will be notified when it leaves the frame. Mouse
4725 tracking only works under W98 and NT4 and later. On earlier
4726 versions, there is no way of telling when the mouse leaves the
4727 frame, so we just have to put up with help-echo and mouse
4728 highlighting remaining while the frame is not active. */
4729 if (track_mouse_event_fn
&& !track_mouse_window
)
4731 TRACKMOUSEEVENT tme
;
4732 tme
.cbSize
= sizeof (tme
);
4733 tme
.dwFlags
= TME_LEAVE
;
4734 tme
.hwndTrack
= hwnd
;
4736 track_mouse_event_fn (&tme
);
4737 track_mouse_window
= hwnd
;
4740 if (XINT (Vw32_mouse_move_interval
) <= 0
4741 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
4743 wmsg
.dwModifiers
= w32_get_modifiers ();
4744 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4748 /* Hang onto mouse move and scroll messages for a bit, to avoid
4749 sending such events to Emacs faster than it can process them.
4750 If we get more events before the timer from the first message
4751 expires, we just replace the first message. */
4753 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
4755 SetTimer (hwnd
, MOUSE_MOVE_ID
,
4756 XINT (Vw32_mouse_move_interval
), NULL
);
4758 /* Hold onto message for now. */
4759 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
4760 saved_mouse_move_msg
.msg
.message
= msg
;
4761 saved_mouse_move_msg
.msg
.wParam
= wParam
;
4762 saved_mouse_move_msg
.msg
.lParam
= lParam
;
4763 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
4764 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
4769 wmsg
.dwModifiers
= w32_get_modifiers ();
4770 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4774 wmsg
.dwModifiers
= w32_get_modifiers ();
4775 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4779 /* Flush out saved messages if necessary. */
4780 if (wParam
== mouse_button_timer
)
4782 if (saved_mouse_button_msg
.msg
.hwnd
)
4784 post_msg (&saved_mouse_button_msg
);
4785 saved_mouse_button_msg
.msg
.hwnd
= 0;
4787 KillTimer (hwnd
, mouse_button_timer
);
4788 mouse_button_timer
= 0;
4790 else if (wParam
== mouse_move_timer
)
4792 if (saved_mouse_move_msg
.msg
.hwnd
)
4794 post_msg (&saved_mouse_move_msg
);
4795 saved_mouse_move_msg
.msg
.hwnd
= 0;
4797 KillTimer (hwnd
, mouse_move_timer
);
4798 mouse_move_timer
= 0;
4800 else if (wParam
== menu_free_timer
)
4802 KillTimer (hwnd
, menu_free_timer
);
4803 menu_free_timer
= 0;
4804 f
= x_window_to_frame (dpyinfo
, hwnd
);
4805 if (!f
->output_data
.w32
->menu_command_in_progress
)
4807 /* Free memory used by owner-drawn and help-echo strings. */
4808 w32_free_menu_strings (hwnd
);
4809 f
->output_data
.w32
->menubar_active
= 0;
4815 /* Windows doesn't send us focus messages when putting up and
4816 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
4817 The only indication we get that something happened is receiving
4818 this message afterwards. So this is a good time to reset our
4819 keyboard modifiers' state. */
4826 /* We must ensure menu bar is fully constructed and up to date
4827 before allowing user interaction with it. To achieve this
4828 we send this message to the lisp thread and wait for a
4829 reply (whose value is not actually needed) to indicate that
4830 the menu bar is now ready for use, so we can now return.
4832 To remain responsive in the meantime, we enter a nested message
4833 loop that can process all other messages.
4835 However, we skip all this if the message results from calling
4836 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
4837 thread a message because it is blocked on us at this point. We
4838 set menubar_active before calling TrackPopupMenu to indicate
4839 this (there is no possibility of confusion with real menubar
4842 f
= x_window_to_frame (dpyinfo
, hwnd
);
4844 && (f
->output_data
.w32
->menubar_active
4845 /* We can receive this message even in the absence of a
4846 menubar (ie. when the system menu is activated) - in this
4847 case we do NOT want to forward the message, otherwise it
4848 will cause the menubar to suddenly appear when the user
4849 had requested it to be turned off! */
4850 || f
->output_data
.w32
->menubar_widget
== NULL
))
4854 deferred_msg msg_buf
;
4856 /* Detect if message has already been deferred; in this case
4857 we cannot return any sensible value to ignore this. */
4858 if (find_deferred_msg (hwnd
, msg
) != NULL
)
4861 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
4864 case WM_EXITMENULOOP
:
4865 f
= x_window_to_frame (dpyinfo
, hwnd
);
4867 /* If a menu command is not already in progress, check again
4868 after a short delay, since Windows often (always?) sends the
4869 WM_EXITMENULOOP before the corresponding WM_COMMAND message. */
4870 if (f
&& !f
->output_data
.w32
->menu_command_in_progress
)
4871 menu_free_timer
= SetTimer (hwnd
, MENU_FREE_ID
, MENU_FREE_DELAY
, NULL
);
4875 /* Direct handling of help_echo in menus. Should be safe now
4876 that we generate the help_echo by placing a help event in the
4879 HMENU menu
= (HMENU
) lParam
;
4880 UINT menu_item
= (UINT
) LOWORD (wParam
);
4881 UINT flags
= (UINT
) HIWORD (wParam
);
4883 w32_menu_display_help (hwnd
, menu
, menu_item
, flags
);
4887 case WM_MEASUREITEM
:
4888 f
= x_window_to_frame (dpyinfo
, hwnd
);
4891 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
4893 if (pMis
->CtlType
== ODT_MENU
)
4895 /* Work out dimensions for popup menu titles. */
4896 char * title
= (char *) pMis
->itemData
;
4897 HDC hdc
= GetDC (hwnd
);
4898 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4899 LOGFONT menu_logfont
;
4903 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4904 menu_logfont
.lfWeight
= FW_BOLD
;
4905 menu_font
= CreateFontIndirect (&menu_logfont
);
4906 old_font
= SelectObject (hdc
, menu_font
);
4908 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
4911 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
4912 pMis
->itemWidth
= size
.cx
;
4913 if (pMis
->itemHeight
< size
.cy
)
4914 pMis
->itemHeight
= size
.cy
;
4917 pMis
->itemWidth
= 0;
4919 SelectObject (hdc
, old_font
);
4920 DeleteObject (menu_font
);
4921 ReleaseDC (hwnd
, hdc
);
4928 f
= x_window_to_frame (dpyinfo
, hwnd
);
4931 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
4933 if (pDis
->CtlType
== ODT_MENU
)
4935 /* Draw popup menu title. */
4936 char * title
= (char *) pDis
->itemData
;
4939 HDC hdc
= pDis
->hDC
;
4940 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4941 LOGFONT menu_logfont
;
4944 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4945 menu_logfont
.lfWeight
= FW_BOLD
;
4946 menu_font
= CreateFontIndirect (&menu_logfont
);
4947 old_font
= SelectObject (hdc
, menu_font
);
4949 /* Always draw title as if not selected. */
4952 + GetSystemMetrics (SM_CXMENUCHECK
),
4954 ETO_OPAQUE
, &pDis
->rcItem
,
4955 title
, strlen (title
), NULL
);
4957 SelectObject (hdc
, old_font
);
4958 DeleteObject (menu_font
);
4966 /* Still not right - can't distinguish between clicks in the
4967 client area of the frame from clicks forwarded from the scroll
4968 bars - may have to hook WM_NCHITTEST to remember the mouse
4969 position and then check if it is in the client area ourselves. */
4970 case WM_MOUSEACTIVATE
:
4971 /* Discard the mouse click that activates a frame, allowing the
4972 user to click anywhere without changing point (or worse!).
4973 Don't eat mouse clicks on scrollbars though!! */
4974 if (LOWORD (lParam
) == HTCLIENT
)
4975 return MA_ACTIVATEANDEAT
;
4980 /* No longer tracking mouse. */
4981 track_mouse_window
= NULL
;
4983 case WM_ACTIVATEAPP
:
4985 case WM_WINDOWPOSCHANGED
:
4987 /* Inform lisp thread that a frame might have just been obscured
4988 or exposed, so should recheck visibility of all frames. */
4989 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4993 dpyinfo
->faked_key
= 0;
4995 register_hot_keys (hwnd
);
4998 unregister_hot_keys (hwnd
);
5001 /* Relinquish the system caret. */
5002 if (w32_system_caret_hwnd
)
5004 w32_visible_system_caret_hwnd
= NULL
;
5005 w32_system_caret_hwnd
= NULL
;
5010 f
= x_window_to_frame (dpyinfo
, hwnd
);
5011 if (f
&& HIWORD (wParam
) == 0)
5013 f
->output_data
.w32
->menu_command_in_progress
= 1;
5014 if (menu_free_timer
)
5016 KillTimer (hwnd
, menu_free_timer
);
5017 menu_free_timer
= 0;
5023 wmsg
.dwModifiers
= w32_get_modifiers ();
5024 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
5028 wmsg
.dwModifiers
= w32_get_modifiers ();
5029 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
5032 case WM_WINDOWPOSCHANGING
:
5033 /* Don't restrict the sizing of tip frames. */
5034 if (hwnd
== tip_window
)
5038 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
5040 wp
.length
= sizeof (WINDOWPLACEMENT
);
5041 GetWindowPlacement (hwnd
, &wp
);
5043 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
5050 DWORD internal_border
;
5051 DWORD scrollbar_extra
;
5054 wp
.length
= sizeof(wp
);
5055 GetWindowRect (hwnd
, &wr
);
5059 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
5060 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
5061 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
5062 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
5066 memset (&rect
, 0, sizeof (rect
));
5067 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
5068 GetMenu (hwnd
) != NULL
);
5070 /* Force width and height of client area to be exact
5071 multiples of the character cell dimensions. */
5072 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
5073 - 2 * internal_border
- scrollbar_extra
)
5075 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
5076 - 2 * internal_border
)
5081 /* For right/bottom sizing we can just fix the sizes.
5082 However for top/left sizing we will need to fix the X
5083 and Y positions as well. */
5088 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
5089 && (lppos
->flags
& SWP_NOMOVE
) == 0)
5091 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
5098 lppos
->flags
|= SWP_NOMOVE
;
5109 case WM_GETMINMAXINFO
:
5110 /* Hack to correct bug that allows Emacs frames to be resized
5111 below the Minimum Tracking Size. */
5112 ((LPMINMAXINFO
) lParam
)->ptMinTrackSize
.y
++;
5113 /* Hack to allow resizing the Emacs frame above the screen size.
5114 Note that Windows 9x limits coordinates to 16-bits. */
5115 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
5116 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
5119 case WM_EMACS_CREATESCROLLBAR
:
5120 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
5121 (struct scroll_bar
*) lParam
);
5123 case WM_EMACS_SHOWWINDOW
:
5124 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
5126 case WM_EMACS_SETFOREGROUND
:
5128 HWND foreground_window
;
5129 DWORD foreground_thread
, retval
;
5131 /* On NT 5.0, and apparently Windows 98, it is necessary to
5132 attach to the thread that currently has focus in order to
5133 pull the focus away from it. */
5134 foreground_window
= GetForegroundWindow ();
5135 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
5136 if (!foreground_window
5137 || foreground_thread
== GetCurrentThreadId ()
5138 || !AttachThreadInput (GetCurrentThreadId (),
5139 foreground_thread
, TRUE
))
5140 foreground_thread
= 0;
5142 retval
= SetForegroundWindow ((HWND
) wParam
);
5144 /* Detach from the previous foreground thread. */
5145 if (foreground_thread
)
5146 AttachThreadInput (GetCurrentThreadId (),
5147 foreground_thread
, FALSE
);
5152 case WM_EMACS_SETWINDOWPOS
:
5154 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
5155 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
5156 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
5159 case WM_EMACS_DESTROYWINDOW
:
5160 DragAcceptFiles ((HWND
) wParam
, FALSE
);
5161 return DestroyWindow ((HWND
) wParam
);
5163 case WM_EMACS_HIDE_CARET
:
5164 return HideCaret (hwnd
);
5166 case WM_EMACS_SHOW_CARET
:
5167 return ShowCaret (hwnd
);
5169 case WM_EMACS_DESTROY_CARET
:
5170 w32_system_caret_hwnd
= NULL
;
5171 w32_visible_system_caret_hwnd
= NULL
;
5172 return DestroyCaret ();
5174 case WM_EMACS_TRACK_CARET
:
5175 /* If there is currently no system caret, create one. */
5176 if (w32_system_caret_hwnd
== NULL
)
5178 /* Use the default caret width, and avoid changing it
5179 unneccesarily, as it confuses screen reader software. */
5180 w32_system_caret_hwnd
= hwnd
;
5181 CreateCaret (hwnd
, NULL
, 0,
5182 w32_system_caret_height
);
5185 if (!SetCaretPos (w32_system_caret_x
, w32_system_caret_y
))
5187 /* Ensure visible caret gets turned on when requested. */
5188 else if (w32_use_visible_system_caret
5189 && w32_visible_system_caret_hwnd
!= hwnd
)
5191 w32_visible_system_caret_hwnd
= hwnd
;
5192 return ShowCaret (hwnd
);
5194 /* Ensure visible caret gets turned off when requested. */
5195 else if (!w32_use_visible_system_caret
5196 && w32_visible_system_caret_hwnd
)
5198 w32_visible_system_caret_hwnd
= NULL
;
5199 return HideCaret (hwnd
);
5204 case WM_EMACS_TRACKPOPUPMENU
:
5209 pos
= (POINT
*)lParam
;
5210 flags
= TPM_CENTERALIGN
;
5211 if (button_state
& LMOUSE
)
5212 flags
|= TPM_LEFTBUTTON
;
5213 else if (button_state
& RMOUSE
)
5214 flags
|= TPM_RIGHTBUTTON
;
5216 /* Remember we did a SetCapture on the initial mouse down event,
5217 so for safety, we make sure the capture is cancelled now. */
5221 /* Use menubar_active to indicate that WM_INITMENU is from
5222 TrackPopupMenu below, and should be ignored. */
5223 f
= x_window_to_frame (dpyinfo
, hwnd
);
5225 f
->output_data
.w32
->menubar_active
= 1;
5227 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
5231 /* Eat any mouse messages during popupmenu */
5232 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
5234 /* Get the menu selection, if any */
5235 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
5237 retval
= LOWORD (amsg
.wParam
);
5253 /* Check for messages registered at runtime. */
5254 if (msg
== msh_mousewheel
)
5256 wmsg
.dwModifiers
= w32_get_modifiers ();
5257 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
5262 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
5266 /* The most common default return code for handled messages is 0. */
5271 my_create_window (f
)
5276 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
5278 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
5282 /* Create a tooltip window. Unlike my_create_window, we do not do this
5283 indirectly via the Window thread, as we do not need to process Window
5284 messages for the tooltip. Creating tooltips indirectly also creates
5285 deadlocks when tooltips are created for menu items. */
5287 my_create_tip_window (f
)
5292 rect
.left
= rect
.top
= 0;
5293 rect
.right
= PIXEL_WIDTH (f
);
5294 rect
.bottom
= PIXEL_HEIGHT (f
);
5296 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
5297 FRAME_EXTERNAL_MENU_BAR (f
));
5299 tip_window
= FRAME_W32_WINDOW (f
)
5300 = CreateWindow (EMACS_CLASS
,
5302 f
->output_data
.w32
->dwStyle
,
5303 f
->output_data
.w32
->left_pos
,
5304 f
->output_data
.w32
->top_pos
,
5305 rect
.right
- rect
.left
,
5306 rect
.bottom
- rect
.top
,
5307 FRAME_W32_WINDOW (SELECTED_FRAME ()), /* owner */
5314 SetWindowLong (tip_window
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
5315 SetWindowLong (tip_window
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
5316 SetWindowLong (tip_window
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
5317 SetWindowLong (tip_window
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
5319 /* Tip frames have no scrollbars. */
5320 SetWindowLong (tip_window
, WND_SCROLLBAR_INDEX
, 0);
5322 /* Do this to discard the default setting specified by our parent. */
5323 ShowWindow (tip_window
, SW_HIDE
);
5328 /* Create and set up the w32 window for frame F. */
5331 w32_window (f
, window_prompting
, minibuffer_only
)
5333 long window_prompting
;
5334 int minibuffer_only
;
5338 /* Use the resource name as the top-level window name
5339 for looking up resources. Make a non-Lisp copy
5340 for the window manager, so GC relocation won't bother it.
5342 Elsewhere we specify the window name for the window manager. */
5345 char *str
= (char *) XSTRING (Vx_resource_name
)->data
;
5346 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
5347 strcpy (f
->namebuf
, str
);
5350 my_create_window (f
);
5352 validate_x_resource_name ();
5354 /* x_set_name normally ignores requests to set the name if the
5355 requested name is the same as the current name. This is the one
5356 place where that assumption isn't correct; f->name is set, but
5357 the server hasn't been told. */
5360 int explicit = f
->explicit_name
;
5362 f
->explicit_name
= 0;
5365 x_set_name (f
, name
, explicit);
5370 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
5371 initialize_frame_menubar (f
);
5373 if (FRAME_W32_WINDOW (f
) == 0)
5374 error ("Unable to create window");
5377 /* Handle the icon stuff for this window. Perhaps later we might
5378 want an x_set_icon_position which can be called interactively as
5386 Lisp_Object icon_x
, icon_y
;
5388 /* Set the position of the icon. Note that Windows 95 groups all
5389 icons in the tray. */
5390 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
5391 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
5392 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
5394 CHECK_NUMBER (icon_x
);
5395 CHECK_NUMBER (icon_y
);
5397 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
5398 error ("Both left and top icon corners of icon must be specified");
5402 if (! EQ (icon_x
, Qunbound
))
5403 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
5406 /* Start up iconic or window? */
5407 x_wm_set_window_state
5408 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
5412 x_text_icon (f
, (char *) XSTRING ((!NILP (f
->icon_name
)
5425 XGCValues gc_values
;
5429 /* Create the GC's of this frame.
5430 Note that many default values are used. */
5433 gc_values
.font
= f
->output_data
.w32
->font
;
5435 /* Cursor has cursor-color background, background-color foreground. */
5436 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
5437 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
5438 f
->output_data
.w32
->cursor_gc
5439 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
5440 (GCFont
| GCForeground
| GCBackground
),
5444 f
->output_data
.w32
->white_relief
.gc
= 0;
5445 f
->output_data
.w32
->black_relief
.gc
= 0;
5451 /* Handler for signals raised during x_create_frame and
5452 x_create_top_frame. FRAME is the frame which is partially
5456 unwind_create_frame (frame
)
5459 struct frame
*f
= XFRAME (frame
);
5461 /* If frame is ``official'', nothing to do. */
5462 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
5465 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5468 x_free_frame_resources (f
);
5470 /* Check that reference counts are indeed correct. */
5471 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
5472 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
5481 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
5483 doc
: /* Make a new window, which is called a \"frame\" in Emacs terms.
5484 Returns an Emacs frame object.
5485 ALIST is an alist of frame parameters.
5486 If the parameters specify that the frame should not have a minibuffer,
5487 and do not specify a specific minibuffer window to use,
5488 then `default-minibuffer-frame' must be a frame whose minibuffer can
5489 be shared by the new frame.
5491 This function is an internal primitive--use `make-frame' instead. */)
5496 Lisp_Object frame
, tem
;
5498 int minibuffer_only
= 0;
5499 long window_prompting
= 0;
5501 int count
= BINDING_STACK_SIZE ();
5502 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5503 Lisp_Object display
;
5504 struct w32_display_info
*dpyinfo
= NULL
;
5510 /* Use this general default value to start with
5511 until we know if this frame has a specified name. */
5512 Vx_resource_name
= Vinvocation_name
;
5514 display
= w32_get_arg (parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
5515 if (EQ (display
, Qunbound
))
5517 dpyinfo
= check_x_display_info (display
);
5519 kb
= dpyinfo
->kboard
;
5521 kb
= &the_only_kboard
;
5524 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5526 && ! EQ (name
, Qunbound
)
5528 error ("Invalid frame name--not a string or nil");
5531 Vx_resource_name
= name
;
5533 /* See if parent window is specified. */
5534 parent
= w32_get_arg (parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
5535 if (EQ (parent
, Qunbound
))
5537 if (! NILP (parent
))
5538 CHECK_NUMBER (parent
);
5540 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
5541 /* No need to protect DISPLAY because that's not used after passing
5542 it to make_frame_without_minibuffer. */
5544 GCPRO4 (parms
, parent
, name
, frame
);
5545 tem
= w32_get_arg (parms
, Qminibuffer
, "minibuffer", "Minibuffer",
5547 if (EQ (tem
, Qnone
) || NILP (tem
))
5548 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
5549 else if (EQ (tem
, Qonly
))
5551 f
= make_minibuffer_frame ();
5552 minibuffer_only
= 1;
5554 else if (WINDOWP (tem
))
5555 f
= make_frame_without_minibuffer (tem
, kb
, display
);
5559 XSETFRAME (frame
, f
);
5561 /* Note that Windows does support scroll bars. */
5562 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
5563 /* By default, make scrollbars the system standard width. */
5564 f
->scroll_bar_pixel_width
= GetSystemMetrics (SM_CXVSCROLL
);
5566 f
->output_method
= output_w32
;
5567 f
->output_data
.w32
=
5568 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
5569 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
5570 FRAME_FONTSET (f
) = -1;
5571 record_unwind_protect (unwind_create_frame
, frame
);
5574 = w32_get_arg (parms
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
5575 if (! STRINGP (f
->icon_name
))
5576 f
->icon_name
= Qnil
;
5578 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
5580 FRAME_KBOARD (f
) = kb
;
5583 /* Specify the parent under which to make this window. */
5587 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
5588 f
->output_data
.w32
->explicit_parent
= 1;
5592 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5593 f
->output_data
.w32
->explicit_parent
= 0;
5596 /* Set the name; the functions to which we pass f expect the name to
5598 if (EQ (name
, Qunbound
) || NILP (name
))
5600 f
->name
= build_string (dpyinfo
->w32_id_name
);
5601 f
->explicit_name
= 0;
5606 f
->explicit_name
= 1;
5607 /* use the frame's title when getting resources for this frame. */
5608 specbind (Qx_resource_name
, name
);
5611 /* Extract the window parameters from the supplied values
5612 that are needed to determine window geometry. */
5616 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
5619 /* First, try whatever font the caller has specified. */
5622 tem
= Fquery_fontset (font
, Qnil
);
5624 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
5626 font
= x_new_font (f
, XSTRING (font
)->data
);
5628 /* Try out a font which we hope has bold and italic variations. */
5629 if (!STRINGP (font
))
5630 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
5631 if (! STRINGP (font
))
5632 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
5633 /* If those didn't work, look for something which will at least work. */
5634 if (! STRINGP (font
))
5635 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
5637 if (! STRINGP (font
))
5638 font
= build_string ("Fixedsys");
5640 x_default_parameter (f
, parms
, Qfont
, font
,
5641 "font", "Font", RES_TYPE_STRING
);
5644 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5645 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5646 /* This defaults to 2 in order to match xterm. We recognize either
5647 internalBorderWidth or internalBorder (which is what xterm calls
5649 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5653 value
= w32_get_arg (parms
, Qinternal_border_width
,
5654 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
5655 if (! EQ (value
, Qunbound
))
5656 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5659 /* Default internalBorderWidth to 0 on Windows to match other programs. */
5660 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (0),
5661 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
5662 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qright
,
5663 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
5665 /* Also do the stuff which must be set before the window exists. */
5666 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5667 "foreground", "Foreground", RES_TYPE_STRING
);
5668 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5669 "background", "Background", RES_TYPE_STRING
);
5670 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5671 "pointerColor", "Foreground", RES_TYPE_STRING
);
5672 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5673 "cursorColor", "Foreground", RES_TYPE_STRING
);
5674 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5675 "borderColor", "BorderColor", RES_TYPE_STRING
);
5676 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
5677 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
5678 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
5679 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
5680 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
5681 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
5682 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
5683 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
5686 /* Init faces before x_default_parameter is called for scroll-bar
5687 parameters because that function calls x_set_scroll_bar_width,
5688 which calls change_frame_size, which calls Fset_window_buffer,
5689 which runs hooks, which call Fvertical_motion. At the end, we
5690 end up in init_iterator with a null face cache, which should not
5692 init_frame_faces (f
);
5694 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
5695 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
5696 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (1),
5697 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
5699 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
5700 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
5701 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
5702 "title", "Title", RES_TYPE_STRING
);
5703 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
5704 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
5706 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
5707 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5709 /* Add the tool-bar height to the initial frame height so that the
5710 user gets a text display area of the size he specified with -g or
5711 via .Xdefaults. Later changes of the tool-bar height don't
5712 change the frame size. This is done so that users can create
5713 tall Emacs frames without having to guess how tall the tool-bar
5715 if (FRAME_TOOL_BAR_LINES (f
))
5717 int margin
, relief
, bar_height
;
5719 relief
= (tool_bar_button_relief
>= 0
5720 ? tool_bar_button_relief
5721 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
5723 if (INTEGERP (Vtool_bar_button_margin
)
5724 && XINT (Vtool_bar_button_margin
) > 0)
5725 margin
= XFASTINT (Vtool_bar_button_margin
);
5726 else if (CONSP (Vtool_bar_button_margin
)
5727 && INTEGERP (XCDR (Vtool_bar_button_margin
))
5728 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
5729 margin
= XFASTINT (XCDR (Vtool_bar_button_margin
));
5733 bar_height
= DEFAULT_TOOL_BAR_IMAGE_HEIGHT
+ 2 * margin
+ 2 * relief
;
5734 f
->height
+= (bar_height
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
5737 window_prompting
= x_figure_window_size (f
, parms
);
5739 if (window_prompting
& XNegative
)
5741 if (window_prompting
& YNegative
)
5742 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
5744 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
5748 if (window_prompting
& YNegative
)
5749 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
5751 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
5754 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
5756 tem
= w32_get_arg (parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
5757 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
5759 w32_window (f
, window_prompting
, minibuffer_only
);
5764 /* Now consider the frame official. */
5765 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5766 Vframe_list
= Fcons (frame
, Vframe_list
);
5768 /* We need to do this after creating the window, so that the
5769 icon-creation functions can say whose icon they're describing. */
5770 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
5771 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
5773 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5774 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5775 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5776 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5777 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5778 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5779 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
5780 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
5782 /* Dimensions, especially f->height, must be done via change_frame_size.
5783 Change will not be effected unless different from the current
5789 SET_FRAME_WIDTH (f
, 0);
5790 change_frame_size (f
, height
, width
, 1, 0, 0);
5792 /* Tell the server what size and position, etc, we want, and how
5793 badly we want them. This should be done after we have the menu
5794 bar so that its size can be taken into account. */
5796 x_wm_set_size_hint (f
, window_prompting
, 0);
5799 /* Avoid a bug that causes the new frame to never become visible if
5800 an echo area message is displayed during the following call1. */
5801 specbind(Qredisplay_dont_pause
, Qt
);
5803 /* Set up faces after all frame parameters are known. This call
5804 also merges in face attributes specified for new frames. If we
5805 don't do this, the `menu' face for instance won't have the right
5806 colors, and the menu bar won't appear in the specified colors for
5808 call1 (Qface_set_after_frame_default
, frame
);
5810 /* Make the window appear on the frame and enable display, unless
5811 the caller says not to. However, with explicit parent, Emacs
5812 cannot control visibility, so don't try. */
5813 if (! f
->output_data
.w32
->explicit_parent
)
5815 Lisp_Object visibility
;
5817 visibility
= w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
5818 if (EQ (visibility
, Qunbound
))
5821 if (EQ (visibility
, Qicon
))
5822 x_iconify_frame (f
);
5823 else if (! NILP (visibility
))
5824 x_make_frame_visible (f
);
5826 /* Must have been Qnil. */
5831 /* Make sure windows on this frame appear in calls to next-window
5832 and similar functions. */
5833 Vwindow_list
= Qnil
;
5835 return unbind_to (count
, frame
);
5838 /* FRAME is used only to get a handle on the X display. We don't pass the
5839 display info directly because we're called from frame.c, which doesn't
5840 know about that structure. */
5842 x_get_focus_frame (frame
)
5843 struct frame
*frame
;
5845 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
5847 if (! dpyinfo
->w32_focus_frame
)
5850 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
5854 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
5855 doc
: /* Give FRAME input focus, raising to foreground if necessary. */)
5859 x_focus_on_frame (check_x_frame (frame
));
5864 /* Return the charset portion of a font name. */
5865 char * xlfd_charset_of_font (char * fontname
)
5867 char *charset
, *encoding
;
5869 encoding
= strrchr(fontname
, '-');
5870 if (!encoding
|| encoding
== fontname
)
5873 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
5874 if (*charset
== '-')
5877 if (charset
== fontname
|| strcmp(charset
, "-*-*") == 0)
5883 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
5884 int size
, char* filename
);
5885 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
5886 static BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
,
5888 static BOOL
x_to_w32_font (char *lpxstr
, LOGFONT
*lplogfont
);
5890 static struct font_info
*
5891 w32_load_system_font (f
,fontname
,size
)
5896 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5897 Lisp_Object font_names
;
5899 /* Get a list of all the fonts that match this name. Once we
5900 have a list of matching fonts, we compare them against the fonts
5901 we already have loaded by comparing names. */
5902 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
5904 if (!NILP (font_names
))
5909 /* First check if any are already loaded, as that is cheaper
5910 than loading another one. */
5911 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
5912 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
5913 if (dpyinfo
->font_table
[i
].name
5914 && (!strcmp (dpyinfo
->font_table
[i
].name
,
5915 XSTRING (XCAR (tail
))->data
)
5916 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
5917 XSTRING (XCAR (tail
))->data
)))
5918 return (dpyinfo
->font_table
+ i
);
5920 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
5922 else if (w32_strict_fontnames
)
5924 /* If EnumFontFamiliesEx was available, we got a full list of
5925 fonts back so stop now to avoid the possibility of loading a
5926 random font. If we had to fall back to EnumFontFamilies, the
5927 list is incomplete, so continue whether the font we want was
5929 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5930 FARPROC enum_font_families_ex
5931 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
5932 if (enum_font_families_ex
)
5936 /* Load the font and add it to the table. */
5938 char *full_name
, *encoding
, *charset
;
5940 struct font_info
*fontp
;
5946 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
5949 if (!*lf
.lfFaceName
)
5950 /* If no name was specified for the font, we get a random font
5951 from CreateFontIndirect - this is not particularly
5952 desirable, especially since CreateFontIndirect does not
5953 fill out the missing name in lf, so we never know what we
5957 /* Specify anti-aliasing to prevent Cleartype fonts being used,
5958 since those fonts leave garbage behind. */
5959 lf
.lfQuality
= ANTIALIASED_QUALITY
;
5961 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
5962 bzero (font
, sizeof (*font
));
5964 /* Set bdf to NULL to indicate that this is a Windows font. */
5969 font
->hfont
= CreateFontIndirect (&lf
);
5971 if (font
->hfont
== NULL
)
5980 codepage
= w32_codepage_for_font (fontname
);
5982 hdc
= GetDC (dpyinfo
->root_window
);
5983 oldobj
= SelectObject (hdc
, font
->hfont
);
5985 ok
= GetTextMetrics (hdc
, &font
->tm
);
5986 if (codepage
== CP_UNICODE
)
5987 font
->double_byte_p
= 1;
5990 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
5991 don't report themselves as double byte fonts, when
5992 patently they are. So instead of trusting
5993 GetFontLanguageInfo, we check the properties of the
5994 codepage directly, since that is ultimately what we are
5995 working from anyway. */
5996 /* font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS; */
5998 GetCPInfo (codepage
, &cpi
);
5999 font
->double_byte_p
= cpi
.MaxCharSize
> 1;
6002 SelectObject (hdc
, oldobj
);
6003 ReleaseDC (dpyinfo
->root_window
, hdc
);
6004 /* Fill out details in lf according to the font that was
6006 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
6007 lf
.lfWidth
= font
->tm
.tmAveCharWidth
;
6008 lf
.lfWeight
= font
->tm
.tmWeight
;
6009 lf
.lfItalic
= font
->tm
.tmItalic
;
6010 lf
.lfCharSet
= font
->tm
.tmCharSet
;
6011 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
6012 ? VARIABLE_PITCH
: FIXED_PITCH
);
6013 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
6014 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
6016 w32_cache_char_metrics (font
);
6023 w32_unload_font (dpyinfo
, font
);
6027 /* Find a free slot in the font table. */
6028 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
6029 if (dpyinfo
->font_table
[i
].name
== NULL
)
6032 /* If no free slot found, maybe enlarge the font table. */
6033 if (i
== dpyinfo
->n_fonts
6034 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
6037 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
6038 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
6040 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
6043 fontp
= dpyinfo
->font_table
+ i
;
6044 if (i
== dpyinfo
->n_fonts
)
6047 /* Now fill in the slots of *FONTP. */
6050 fontp
->font_idx
= i
;
6051 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
6052 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
6054 charset
= xlfd_charset_of_font (fontname
);
6056 /* Cache the W32 codepage for a font. This makes w32_encode_char
6057 (called for every glyph during redisplay) much faster. */
6058 fontp
->codepage
= codepage
;
6060 /* Work out the font's full name. */
6061 full_name
= (char *)xmalloc (100);
6062 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
6063 fontp
->full_name
= full_name
;
6066 /* If all else fails - just use the name we used to load it. */
6068 fontp
->full_name
= fontp
->name
;
6071 fontp
->size
= FONT_WIDTH (font
);
6072 fontp
->height
= FONT_HEIGHT (font
);
6074 /* The slot `encoding' specifies how to map a character
6075 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
6076 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
6077 (0:0x20..0x7F, 1:0xA0..0xFF,
6078 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
6079 2:0xA020..0xFF7F). For the moment, we don't know which charset
6080 uses this font. So, we set information in fontp->encoding[1]
6081 which is never used by any charset. If mapping can't be
6082 decided, set FONT_ENCODING_NOT_DECIDED. */
6084 /* SJIS fonts need to be set to type 4, all others seem to work as
6085 type FONT_ENCODING_NOT_DECIDED. */
6086 encoding
= strrchr (fontp
->name
, '-');
6087 if (encoding
&& strnicmp (encoding
+1, "sjis", 4) == 0)
6088 fontp
->encoding
[1] = 4;
6090 fontp
->encoding
[1] = FONT_ENCODING_NOT_DECIDED
;
6092 /* The following three values are set to 0 under W32, which is
6093 what they get set to if XGetFontProperty fails under X. */
6094 fontp
->baseline_offset
= 0;
6095 fontp
->relative_compose
= 0;
6096 fontp
->default_ascent
= 0;
6098 /* Set global flag fonts_changed_p to non-zero if the font loaded
6099 has a character with a smaller width than any other character
6100 before, or if the font loaded has a smaller height than any
6101 other font loaded before. If this happens, it will make a
6102 glyph matrix reallocation necessary. */
6103 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
6109 /* Load font named FONTNAME of size SIZE for frame F, and return a
6110 pointer to the structure font_info while allocating it dynamically.
6111 If loading fails, return NULL. */
6113 w32_load_font (f
,fontname
,size
)
6118 Lisp_Object bdf_fonts
;
6119 struct font_info
*retval
= NULL
;
6121 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
6123 while (!retval
&& CONSP (bdf_fonts
))
6125 char *bdf_name
, *bdf_file
;
6126 Lisp_Object bdf_pair
;
6128 bdf_name
= XSTRING (XCAR (bdf_fonts
))->data
;
6129 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
6130 bdf_file
= XSTRING (XCDR (bdf_pair
))->data
;
6132 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
6134 bdf_fonts
= XCDR (bdf_fonts
);
6140 return w32_load_system_font(f
, fontname
, size
);
6145 w32_unload_font (dpyinfo
, font
)
6146 struct w32_display_info
*dpyinfo
;
6151 if (font
->per_char
) xfree (font
->per_char
);
6152 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
6154 if (font
->hfont
) DeleteObject(font
->hfont
);
6159 /* The font conversion stuff between x and w32 */
6161 /* X font string is as follows (from faces.el)
6165 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
6166 * (weight\? "\\([^-]*\\)") ; 1
6167 * (slant "\\([ior]\\)") ; 2
6168 * (slant\? "\\([^-]?\\)") ; 2
6169 * (swidth "\\([^-]*\\)") ; 3
6170 * (adstyle "[^-]*") ; 4
6171 * (pixelsize "[0-9]+")
6172 * (pointsize "[0-9][0-9]+")
6173 * (resx "[0-9][0-9]+")
6174 * (resy "[0-9][0-9]+")
6175 * (spacing "[cmp?*]")
6176 * (avgwidth "[0-9]+")
6177 * (registry "[^-]+")
6178 * (encoding "[^-]+")
6183 x_to_w32_weight (lpw
)
6186 if (!lpw
) return (FW_DONTCARE
);
6188 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
6189 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
6190 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
6191 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
6192 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
6193 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
6194 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
6195 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
6196 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
6197 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
6204 w32_to_x_weight (fnweight
)
6207 if (fnweight
>= FW_HEAVY
) return "heavy";
6208 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
6209 if (fnweight
>= FW_BOLD
) return "bold";
6210 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
6211 if (fnweight
>= FW_MEDIUM
) return "medium";
6212 if (fnweight
>= FW_NORMAL
) return "normal";
6213 if (fnweight
>= FW_LIGHT
) return "light";
6214 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
6215 if (fnweight
>= FW_THIN
) return "thin";
6221 x_to_w32_charset (lpcs
)
6224 Lisp_Object this_entry
, w32_charset
;
6226 int len
= strlen (lpcs
);
6228 /* Support "*-#nnn" format for unknown charsets. */
6229 if (strncmp (lpcs
, "*-#", 3) == 0)
6230 return atoi (lpcs
+ 3);
6232 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
6233 charset
= alloca (len
+ 1);
6234 strcpy (charset
, lpcs
);
6235 lpcs
= strchr (charset
, '*');
6239 /* Look through w32-charset-info-alist for the character set.
6240 Format of each entry is
6241 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
6243 this_entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
6245 if (NILP(this_entry
))
6247 /* At startup, we want iso8859-1 fonts to come up properly. */
6248 if (stricmp(charset
, "iso8859-1") == 0)
6249 return ANSI_CHARSET
;
6251 return DEFAULT_CHARSET
;
6254 w32_charset
= Fcar (Fcdr (this_entry
));
6256 /* Translate Lisp symbol to number. */
6257 if (w32_charset
== Qw32_charset_ansi
)
6258 return ANSI_CHARSET
;
6259 if (w32_charset
== Qw32_charset_symbol
)
6260 return SYMBOL_CHARSET
;
6261 if (w32_charset
== Qw32_charset_shiftjis
)
6262 return SHIFTJIS_CHARSET
;
6263 if (w32_charset
== Qw32_charset_hangeul
)
6264 return HANGEUL_CHARSET
;
6265 if (w32_charset
== Qw32_charset_chinesebig5
)
6266 return CHINESEBIG5_CHARSET
;
6267 if (w32_charset
== Qw32_charset_gb2312
)
6268 return GB2312_CHARSET
;
6269 if (w32_charset
== Qw32_charset_oem
)
6271 #ifdef JOHAB_CHARSET
6272 if (w32_charset
== Qw32_charset_johab
)
6273 return JOHAB_CHARSET
;
6274 if (w32_charset
== Qw32_charset_easteurope
)
6275 return EASTEUROPE_CHARSET
;
6276 if (w32_charset
== Qw32_charset_turkish
)
6277 return TURKISH_CHARSET
;
6278 if (w32_charset
== Qw32_charset_baltic
)
6279 return BALTIC_CHARSET
;
6280 if (w32_charset
== Qw32_charset_russian
)
6281 return RUSSIAN_CHARSET
;
6282 if (w32_charset
== Qw32_charset_arabic
)
6283 return ARABIC_CHARSET
;
6284 if (w32_charset
== Qw32_charset_greek
)
6285 return GREEK_CHARSET
;
6286 if (w32_charset
== Qw32_charset_hebrew
)
6287 return HEBREW_CHARSET
;
6288 if (w32_charset
== Qw32_charset_vietnamese
)
6289 return VIETNAMESE_CHARSET
;
6290 if (w32_charset
== Qw32_charset_thai
)
6291 return THAI_CHARSET
;
6292 if (w32_charset
== Qw32_charset_mac
)
6294 #endif /* JOHAB_CHARSET */
6295 #ifdef UNICODE_CHARSET
6296 if (w32_charset
== Qw32_charset_unicode
)
6297 return UNICODE_CHARSET
;
6300 return DEFAULT_CHARSET
;
6305 w32_to_x_charset (fncharset
)
6308 static char buf
[32];
6309 Lisp_Object charset_type
;
6314 /* Handle startup case of w32-charset-info-alist not
6315 being set up yet. */
6316 if (NILP(Vw32_charset_info_alist
))
6318 charset_type
= Qw32_charset_ansi
;
6320 case DEFAULT_CHARSET
:
6321 charset_type
= Qw32_charset_default
;
6323 case SYMBOL_CHARSET
:
6324 charset_type
= Qw32_charset_symbol
;
6326 case SHIFTJIS_CHARSET
:
6327 charset_type
= Qw32_charset_shiftjis
;
6329 case HANGEUL_CHARSET
:
6330 charset_type
= Qw32_charset_hangeul
;
6332 case GB2312_CHARSET
:
6333 charset_type
= Qw32_charset_gb2312
;
6335 case CHINESEBIG5_CHARSET
:
6336 charset_type
= Qw32_charset_chinesebig5
;
6339 charset_type
= Qw32_charset_oem
;
6342 /* More recent versions of Windows (95 and NT4.0) define more
6344 #ifdef EASTEUROPE_CHARSET
6345 case EASTEUROPE_CHARSET
:
6346 charset_type
= Qw32_charset_easteurope
;
6348 case TURKISH_CHARSET
:
6349 charset_type
= Qw32_charset_turkish
;
6351 case BALTIC_CHARSET
:
6352 charset_type
= Qw32_charset_baltic
;
6354 case RUSSIAN_CHARSET
:
6355 charset_type
= Qw32_charset_russian
;
6357 case ARABIC_CHARSET
:
6358 charset_type
= Qw32_charset_arabic
;
6361 charset_type
= Qw32_charset_greek
;
6363 case HEBREW_CHARSET
:
6364 charset_type
= Qw32_charset_hebrew
;
6366 case VIETNAMESE_CHARSET
:
6367 charset_type
= Qw32_charset_vietnamese
;
6370 charset_type
= Qw32_charset_thai
;
6373 charset_type
= Qw32_charset_mac
;
6376 charset_type
= Qw32_charset_johab
;
6380 #ifdef UNICODE_CHARSET
6381 case UNICODE_CHARSET
:
6382 charset_type
= Qw32_charset_unicode
;
6386 /* Encode numerical value of unknown charset. */
6387 sprintf (buf
, "*-#%u", fncharset
);
6393 char * best_match
= NULL
;
6395 /* Look through w32-charset-info-alist for the character set.
6396 Prefer ISO codepages, and prefer lower numbers in the ISO
6397 range. Only return charsets for codepages which are installed.
6399 Format of each entry is
6400 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
6402 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
6405 Lisp_Object w32_charset
;
6406 Lisp_Object codepage
;
6408 Lisp_Object this_entry
= XCAR (rest
);
6410 /* Skip invalid entries in alist. */
6411 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
6412 || !CONSP (XCDR (this_entry
))
6413 || !SYMBOLP (XCAR (XCDR (this_entry
))))
6416 x_charset
= XSTRING (XCAR (this_entry
))->data
;
6417 w32_charset
= XCAR (XCDR (this_entry
));
6418 codepage
= XCDR (XCDR (this_entry
));
6420 /* Look for Same charset and a valid codepage (or non-int
6421 which means ignore). */
6422 if (w32_charset
== charset_type
6423 && (!INTEGERP (codepage
) || codepage
== CP_DEFAULT
6424 || IsValidCodePage (XINT (codepage
))))
6426 /* If we don't have a match already, then this is the
6429 best_match
= x_charset
;
6430 /* If this is an ISO codepage, and the best so far isn't,
6431 then this is better. */
6432 else if (strnicmp (best_match
, "iso", 3) != 0
6433 && strnicmp (x_charset
, "iso", 3) == 0)
6434 best_match
= x_charset
;
6435 /* If both are ISO8859 codepages, choose the one with the
6436 lowest number in the encoding field. */
6437 else if (strnicmp (best_match
, "iso8859-", 8) == 0
6438 && strnicmp (x_charset
, "iso8859-", 8) == 0)
6440 int best_enc
= atoi (best_match
+ 8);
6441 int this_enc
= atoi (x_charset
+ 8);
6442 if (this_enc
> 0 && this_enc
< best_enc
)
6443 best_match
= x_charset
;
6448 /* If no match, encode the numeric value. */
6451 sprintf (buf
, "*-#%u", fncharset
);
6455 strncpy(buf
, best_match
, 31);
6462 /* Return all the X charsets that map to a font. */
6464 w32_to_all_x_charsets (fncharset
)
6467 static char buf
[32];
6468 Lisp_Object charset_type
;
6469 Lisp_Object retval
= Qnil
;
6474 /* Handle startup case of w32-charset-info-alist not
6475 being set up yet. */
6476 if (NILP(Vw32_charset_info_alist
))
6477 return Fcons (build_string ("iso8859-1"), Qnil
);
6479 charset_type
= Qw32_charset_ansi
;
6481 case DEFAULT_CHARSET
:
6482 charset_type
= Qw32_charset_default
;
6484 case SYMBOL_CHARSET
:
6485 charset_type
= Qw32_charset_symbol
;
6487 case SHIFTJIS_CHARSET
:
6488 charset_type
= Qw32_charset_shiftjis
;
6490 case HANGEUL_CHARSET
:
6491 charset_type
= Qw32_charset_hangeul
;
6493 case GB2312_CHARSET
:
6494 charset_type
= Qw32_charset_gb2312
;
6496 case CHINESEBIG5_CHARSET
:
6497 charset_type
= Qw32_charset_chinesebig5
;
6500 charset_type
= Qw32_charset_oem
;
6503 /* More recent versions of Windows (95 and NT4.0) define more
6505 #ifdef EASTEUROPE_CHARSET
6506 case EASTEUROPE_CHARSET
:
6507 charset_type
= Qw32_charset_easteurope
;
6509 case TURKISH_CHARSET
:
6510 charset_type
= Qw32_charset_turkish
;
6512 case BALTIC_CHARSET
:
6513 charset_type
= Qw32_charset_baltic
;
6515 case RUSSIAN_CHARSET
:
6516 charset_type
= Qw32_charset_russian
;
6518 case ARABIC_CHARSET
:
6519 charset_type
= Qw32_charset_arabic
;
6522 charset_type
= Qw32_charset_greek
;
6524 case HEBREW_CHARSET
:
6525 charset_type
= Qw32_charset_hebrew
;
6527 case VIETNAMESE_CHARSET
:
6528 charset_type
= Qw32_charset_vietnamese
;
6531 charset_type
= Qw32_charset_thai
;
6534 charset_type
= Qw32_charset_mac
;
6537 charset_type
= Qw32_charset_johab
;
6541 #ifdef UNICODE_CHARSET
6542 case UNICODE_CHARSET
:
6543 charset_type
= Qw32_charset_unicode
;
6547 /* Encode numerical value of unknown charset. */
6548 sprintf (buf
, "*-#%u", fncharset
);
6549 return Fcons (build_string (buf
), Qnil
);
6554 /* Look through w32-charset-info-alist for the character set.
6555 Only return charsets for codepages which are installed.
6557 Format of each entry in Vw32_charset_info_alist is
6558 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
6560 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
6562 Lisp_Object x_charset
;
6563 Lisp_Object w32_charset
;
6564 Lisp_Object codepage
;
6566 Lisp_Object this_entry
= XCAR (rest
);
6568 /* Skip invalid entries in alist. */
6569 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
6570 || !CONSP (XCDR (this_entry
))
6571 || !SYMBOLP (XCAR (XCDR (this_entry
))))
6574 x_charset
= XCAR (this_entry
);
6575 w32_charset
= XCAR (XCDR (this_entry
));
6576 codepage
= XCDR (XCDR (this_entry
));
6578 /* Look for Same charset and a valid codepage (or non-int
6579 which means ignore). */
6580 if (w32_charset
== charset_type
6581 && (!INTEGERP (codepage
) || codepage
== CP_DEFAULT
6582 || IsValidCodePage (XINT (codepage
))))
6584 retval
= Fcons (x_charset
, retval
);
6588 /* If no match, encode the numeric value. */
6591 sprintf (buf
, "*-#%u", fncharset
);
6592 return Fcons (build_string (buf
), Qnil
);
6599 /* Get the Windows codepage corresponding to the specified font. The
6600 charset info in the font name is used to look up
6601 w32-charset-to-codepage-alist. */
6603 w32_codepage_for_font (char *fontname
)
6605 Lisp_Object codepage
, entry
;
6606 char *charset_str
, *charset
, *end
;
6608 if (NILP (Vw32_charset_info_alist
))
6611 /* Extract charset part of font string. */
6612 charset
= xlfd_charset_of_font (fontname
);
6617 charset_str
= (char *) alloca (strlen (charset
) + 1);
6618 strcpy (charset_str
, charset
);
6621 /* Remove leading "*-". */
6622 if (strncmp ("*-", charset_str
, 2) == 0)
6623 charset
= charset_str
+ 2;
6626 charset
= charset_str
;
6628 /* Stop match at wildcard (including preceding '-'). */
6629 if (end
= strchr (charset
, '*'))
6631 if (end
> charset
&& *(end
-1) == '-')
6636 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
6640 codepage
= Fcdr (Fcdr (entry
));
6642 if (NILP (codepage
))
6644 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
6646 else if (INTEGERP (codepage
))
6647 return XINT (codepage
);
6654 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
6655 LOGFONT
* lplogfont
;
6658 char * specific_charset
;
6662 char height_pixels
[8];
6664 char width_pixels
[8];
6665 char *fontname_dash
;
6666 int display_resy
= (int) one_w32_display_info
.resy
;
6667 int display_resx
= (int) one_w32_display_info
.resx
;
6669 struct coding_system coding
;
6671 if (!lpxstr
) abort ();
6676 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
6677 fonttype
= "raster";
6678 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
6679 fonttype
= "outline";
6681 fonttype
= "unknown";
6683 setup_coding_system (Fcheck_coding_system (Vlocale_coding_system
),
6685 coding
.src_multibyte
= 0;
6686 coding
.dst_multibyte
= 1;
6687 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6688 bufsz
= decoding_buffer_size (&coding
, LF_FACESIZE
);
6690 fontname
= alloca(sizeof(*fontname
) * bufsz
);
6691 decode_coding (&coding
, lplogfont
->lfFaceName
, fontname
,
6692 strlen(lplogfont
->lfFaceName
), bufsz
- 1);
6693 *(fontname
+ coding
.produced
) = '\0';
6695 /* Replace dashes with underscores so the dashes are not
6697 fontname_dash
= fontname
;
6698 while (fontname_dash
= strchr (fontname_dash
, '-'))
6699 *fontname_dash
= '_';
6701 if (lplogfont
->lfHeight
)
6703 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
6704 sprintf (height_dpi
, "%u",
6705 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
6709 strcpy (height_pixels
, "*");
6710 strcpy (height_dpi
, "*");
6712 if (lplogfont
->lfWidth
)
6713 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
6715 strcpy (width_pixels
, "*");
6717 _snprintf (lpxstr
, len
- 1,
6718 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
6719 fonttype
, /* foundry */
6720 fontname
, /* family */
6721 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
6722 lplogfont
->lfItalic
?'i':'r', /* slant */
6724 /* add style name */
6725 height_pixels
, /* pixel size */
6726 height_dpi
, /* point size */
6727 display_resx
, /* resx */
6728 display_resy
, /* resy */
6729 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
6730 ? 'p' : 'c', /* spacing */
6731 width_pixels
, /* avg width */
6732 specific_charset
? specific_charset
6733 : w32_to_x_charset (lplogfont
->lfCharSet
)
6734 /* charset registry and encoding */
6737 lpxstr
[len
- 1] = 0; /* just to be sure */
6742 x_to_w32_font (lpxstr
, lplogfont
)
6744 LOGFONT
* lplogfont
;
6746 struct coding_system coding
;
6748 if (!lplogfont
) return (FALSE
);
6750 memset (lplogfont
, 0, sizeof (*lplogfont
));
6752 /* Set default value for each field. */
6754 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
6755 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
6756 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
6758 /* go for maximum quality */
6759 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
6760 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
6761 lplogfont
->lfQuality
= PROOF_QUALITY
;
6764 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
6765 lplogfont
->lfWeight
= FW_DONTCARE
;
6766 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
6771 /* Provide a simple escape mechanism for specifying Windows font names
6772 * directly -- if font spec does not beginning with '-', assume this
6774 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
6780 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
6781 width
[10], resy
[10], remainder
[50];
6783 int dpi
= (int) one_w32_display_info
.resy
;
6785 fields
= sscanf (lpxstr
,
6786 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
6787 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
6791 /* In the general case when wildcards cover more than one field,
6792 we don't know which field is which, so don't fill any in.
6793 However, we need to cope with this particular form, which is
6794 generated by font_list_1 (invoked by try_font_list):
6795 "-raster-6x10-*-gb2312*-*"
6796 and make sure to correctly parse the charset field. */
6799 fields
= sscanf (lpxstr
,
6800 "-%*[^-]-%49[^-]-*-%49s",
6803 else if (fields
< 9)
6809 if (fields
> 0 && name
[0] != '*')
6815 (Fcheck_coding_system (Vlocale_coding_system
), &coding
);
6816 coding
.src_multibyte
= 1;
6817 coding
.dst_multibyte
= 1;
6818 bufsize
= encoding_buffer_size (&coding
, strlen (name
));
6819 buf
= (unsigned char *) alloca (bufsize
);
6820 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6821 encode_coding (&coding
, name
, buf
, strlen (name
), bufsize
);
6822 if (coding
.produced
>= LF_FACESIZE
)
6823 coding
.produced
= LF_FACESIZE
- 1;
6824 buf
[coding
.produced
] = 0;
6825 strcpy (lplogfont
->lfFaceName
, buf
);
6829 lplogfont
->lfFaceName
[0] = '\0';
6834 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6838 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
6842 if (fields
> 0 && pixels
[0] != '*')
6843 lplogfont
->lfHeight
= atoi (pixels
);
6847 if (fields
> 0 && resy
[0] != '*')
6850 if (tem
> 0) dpi
= tem
;
6853 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
6854 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
6857 lplogfont
->lfPitchAndFamily
=
6858 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
6862 if (fields
> 0 && width
[0] != '*')
6863 lplogfont
->lfWidth
= atoi (width
) / 10;
6867 /* Strip the trailing '-' if present. (it shouldn't be, as it
6868 fails the test against xlfd-tight-regexp in fontset.el). */
6870 int len
= strlen (remainder
);
6871 if (len
> 0 && remainder
[len
-1] == '-')
6872 remainder
[len
-1] = 0;
6874 encoding
= remainder
;
6876 if (strncmp (encoding
, "*-", 2) == 0)
6879 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
6884 char name
[100], height
[10], width
[10], weight
[20];
6886 fields
= sscanf (lpxstr
,
6887 "%99[^:]:%9[^:]:%9[^:]:%19s",
6888 name
, height
, width
, weight
);
6890 if (fields
== EOF
) return (FALSE
);
6894 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
6895 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
6899 lplogfont
->lfFaceName
[0] = 0;
6905 lplogfont
->lfHeight
= atoi (height
);
6910 lplogfont
->lfWidth
= atoi (width
);
6914 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6917 /* This makes TrueType fonts work better. */
6918 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
6923 /* Strip the pixel height and point height from the given xlfd, and
6924 return the pixel height. If no pixel height is specified, calculate
6925 one from the point height, or if that isn't defined either, return
6926 0 (which usually signifies a scalable font).
6929 xlfd_strip_height (char *fontname
)
6931 int pixel_height
, field_number
;
6932 char *read_from
, *write_to
;
6936 pixel_height
= field_number
= 0;
6939 /* Look for height fields. */
6940 for (read_from
= fontname
; *read_from
; read_from
++)
6942 if (*read_from
== '-')
6945 if (field_number
== 7) /* Pixel height. */
6948 write_to
= read_from
;
6950 /* Find end of field. */
6951 for (;*read_from
&& *read_from
!= '-'; read_from
++)
6954 /* Split the fontname at end of field. */
6960 pixel_height
= atoi (write_to
);
6961 /* Blank out field. */
6962 if (read_from
> write_to
)
6967 /* If the pixel height field is at the end (partial xlfd),
6970 return pixel_height
;
6972 /* If we got a pixel height, the point height can be
6973 ignored. Just blank it out and break now. */
6976 /* Find end of point size field. */
6977 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6983 /* Blank out the point size field. */
6984 if (read_from
> write_to
)
6990 return pixel_height
;
6994 /* If the point height is already blank, break now. */
6995 if (*read_from
== '-')
7001 else if (field_number
== 8)
7003 /* If we didn't get a pixel height, try to get the point
7004 height and convert that. */
7006 char *point_size_start
= read_from
++;
7008 /* Find end of field. */
7009 for (; *read_from
&& *read_from
!= '-'; read_from
++)
7018 point_size
= atoi (point_size_start
);
7020 /* Convert to pixel height. */
7021 pixel_height
= point_size
7022 * one_w32_display_info
.height_in
/ 720;
7024 /* Blank out this field and break. */
7032 /* Shift the rest of the font spec into place. */
7033 if (write_to
&& read_from
> write_to
)
7035 for (; *read_from
; read_from
++, write_to
++)
7036 *write_to
= *read_from
;
7040 return pixel_height
;
7043 /* Assume parameter 1 is fully qualified, no wildcards. */
7045 w32_font_match (fontname
, pattern
)
7049 char *regex
= alloca (strlen (pattern
) * 2 + 3);
7050 char *font_name_copy
= alloca (strlen (fontname
) + 1);
7053 /* Copy fontname so we can modify it during comparison. */
7054 strcpy (font_name_copy
, fontname
);
7059 /* Turn pattern into a regexp and do a regexp match. */
7060 for (; *pattern
; pattern
++)
7062 if (*pattern
== '?')
7064 else if (*pattern
== '*')
7075 /* Strip out font heights and compare them seperately, since
7076 rounding error can cause mismatches. This also allows a
7077 comparison between a font that declares only a pixel height and a
7078 pattern that declares the point height.
7081 int font_height
, pattern_height
;
7083 font_height
= xlfd_strip_height (font_name_copy
);
7084 pattern_height
= xlfd_strip_height (regex
);
7086 /* Compare now, and don't bother doing expensive regexp matching
7087 if the heights differ. */
7088 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
7092 return (fast_c_string_match_ignore_case (build_string (regex
),
7093 font_name_copy
) >= 0);
7096 /* Callback functions, and a structure holding info they need, for
7097 listing system fonts on W32. We need one set of functions to do the
7098 job properly, but these don't work on NT 3.51 and earlier, so we
7099 have a second set which don't handle character sets properly to
7102 In both cases, there are two passes made. The first pass gets one
7103 font from each family, the second pass lists all the fonts from
7106 typedef struct enumfont_t
7111 XFontStruct
*size_ref
;
7112 Lisp_Object pattern
;
7118 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
7122 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
7124 NEWTEXTMETRIC
* lptm
;
7128 /* Ignore struck out and underlined versions of fonts. */
7129 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
7132 /* Only return fonts with names starting with @ if they were
7133 explicitly specified, since Microsoft uses an initial @ to
7134 denote fonts for vertical writing, without providing a more
7135 convenient way of identifying them. */
7136 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
7137 && lpef
->logfont
.lfFaceName
[0] != '@')
7140 /* Check that the character set matches if it was specified */
7141 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
7142 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
7145 if (FontType
== RASTER_FONTTYPE
)
7147 /* DBCS raster fonts have problems displaying, so skip them. */
7148 int charset
= lplf
->elfLogFont
.lfCharSet
;
7149 if (charset
== SHIFTJIS_CHARSET
7150 || charset
== HANGEUL_CHARSET
7151 || charset
== CHINESEBIG5_CHARSET
7152 || charset
== GB2312_CHARSET
7153 #ifdef JOHAB_CHARSET
7154 || charset
== JOHAB_CHARSET
7162 Lisp_Object width
= Qnil
;
7163 Lisp_Object charset_list
= Qnil
;
7164 char *charset
= NULL
;
7166 /* Truetype fonts do not report their true metrics until loaded */
7167 if (FontType
!= RASTER_FONTTYPE
)
7169 if (!NILP (lpef
->pattern
))
7171 /* Scalable fonts are as big as you want them to be. */
7172 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
7173 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
7174 width
= make_number (lpef
->logfont
.lfWidth
);
7178 lplf
->elfLogFont
.lfHeight
= 0;
7179 lplf
->elfLogFont
.lfWidth
= 0;
7183 /* Make sure the height used here is the same as everywhere
7184 else (ie character height, not cell height). */
7185 if (lplf
->elfLogFont
.lfHeight
> 0)
7187 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
7188 if (FontType
== RASTER_FONTTYPE
)
7189 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
7191 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
7194 if (!NILP (lpef
->pattern
))
7196 charset
= xlfd_charset_of_font (XSTRING(lpef
->pattern
)->data
);
7198 /* We already checked charsets above, but DEFAULT_CHARSET
7199 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
7201 && strncmp (charset
, "*-*", 3) != 0
7202 && lpef
->logfont
.lfCharSet
== DEFAULT_CHARSET
7203 && strcmp (charset
, w32_to_x_charset (DEFAULT_CHARSET
)) != 0)
7208 charset_list
= Fcons (build_string (charset
), Qnil
);
7210 charset_list
= w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
);
7212 /* Loop through the charsets. */
7213 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
7215 Lisp_Object this_charset
= Fcar (charset_list
);
7216 charset
= XSTRING (this_charset
)->data
;
7218 /* List bold and italic variations if w32-enable-synthesized-fonts
7219 is non-nil and this is a plain font. */
7220 if (w32_enable_synthesized_fonts
7221 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
7222 && lplf
->elfLogFont
.lfItalic
== FALSE
)
7224 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
7227 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
7228 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
7231 lplf
->elfLogFont
.lfItalic
= TRUE
;
7232 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
7235 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
7236 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
7240 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
7249 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
7252 char * match_charset
;
7257 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
7260 if (NILP (lpef
->pattern
)
7261 || w32_font_match (buf
, XSTRING (lpef
->pattern
)->data
))
7263 /* Check if we already listed this font. This may happen if
7264 w32_enable_synthesized_fonts is non-nil, and there are real
7265 bold and italic versions of the font. */
7266 Lisp_Object font_name
= build_string (buf
);
7267 if (NILP (Fmember (font_name
, lpef
->list
)))
7269 Lisp_Object entry
= Fcons (font_name
, width
);
7270 lpef
->list
= Fcons (entry
, lpef
->list
);
7278 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
7280 NEWTEXTMETRIC
* lptm
;
7284 return EnumFontFamilies (lpef
->hdc
,
7285 lplf
->elfLogFont
.lfFaceName
,
7286 (FONTENUMPROC
) enum_font_cb2
,
7292 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
7293 ENUMLOGFONTEX
* lplf
;
7294 NEWTEXTMETRICEX
* lptm
;
7298 /* We are not interested in the extra info we get back from the 'Ex
7299 version - only the fact that we get character set variations
7300 enumerated seperately. */
7301 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
7306 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
7307 ENUMLOGFONTEX
* lplf
;
7308 NEWTEXTMETRICEX
* lptm
;
7312 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
7313 FARPROC enum_font_families_ex
7314 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
7315 /* We don't really expect EnumFontFamiliesEx to disappear once we
7316 get here, so don't bother handling it gracefully. */
7317 if (enum_font_families_ex
== NULL
)
7318 error ("gdi32.dll has disappeared!");
7319 return enum_font_families_ex (lpef
->hdc
,
7321 (FONTENUMPROC
) enum_fontex_cb2
,
7325 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
7326 and xterm.c in Emacs 20.3) */
7328 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
7330 char *fontname
, *ptnstr
;
7331 Lisp_Object list
, tem
, newlist
= Qnil
;
7334 list
= Vw32_bdf_filename_alist
;
7335 ptnstr
= XSTRING (pattern
)->data
;
7337 for ( ; CONSP (list
); list
= XCDR (list
))
7341 fontname
= XSTRING (XCAR (tem
))->data
;
7342 else if (STRINGP (tem
))
7343 fontname
= XSTRING (tem
)->data
;
7347 if (w32_font_match (fontname
, ptnstr
))
7349 newlist
= Fcons (XCAR (tem
), newlist
);
7351 if (n_fonts
>= max_names
)
7360 /* Return a list of names of available fonts matching PATTERN on frame
7361 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
7362 to be listed. Frame F NULL means we have not yet created any
7363 frame, which means we can't get proper size info, as we don't have
7364 a device context to use for GetTextMetrics.
7365 MAXNAMES sets a limit on how many fonts to match. */
7368 w32_list_fonts (f
, pattern
, size
, maxnames
)
7370 Lisp_Object pattern
;
7374 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
7375 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
7376 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
7379 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
7380 if (NILP (patterns
))
7381 patterns
= Fcons (pattern
, Qnil
);
7383 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
7388 tpat
= XCAR (patterns
);
7390 if (!STRINGP (tpat
))
7393 /* Avoid expensive EnumFontFamilies functions if we are not
7394 going to be able to output one of these anyway. */
7395 codepage
= w32_codepage_for_font (XSTRING (tpat
)->data
);
7396 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
7397 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
7398 && !IsValidCodePage(codepage
))
7401 /* See if we cached the result for this particular query.
7402 The cache is an alist of the form:
7403 ((PATTERN (FONTNAME . WIDTH) ...) ...)
7405 if (tem
= XCDR (dpyinfo
->name_list_element
),
7406 !NILP (list
= Fassoc (tpat
, tem
)))
7408 list
= Fcdr_safe (list
);
7409 /* We have a cached list. Don't have to get the list again. */
7414 /* At first, put PATTERN in the cache. */
7419 /* Use EnumFontFamiliesEx where it is available, as it knows
7420 about character sets. Fall back to EnumFontFamilies for
7421 older versions of NT that don't support the 'Ex function. */
7422 x_to_w32_font (XSTRING (tpat
)->data
, &ef
.logfont
);
7424 LOGFONT font_match_pattern
;
7425 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
7426 FARPROC enum_font_families_ex
7427 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
7429 /* We do our own pattern matching so we can handle wildcards. */
7430 font_match_pattern
.lfFaceName
[0] = 0;
7431 font_match_pattern
.lfPitchAndFamily
= 0;
7432 /* We can use the charset, because if it is a wildcard it will
7433 be DEFAULT_CHARSET anyway. */
7434 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
7436 ef
.hdc
= GetDC (dpyinfo
->root_window
);
7438 if (enum_font_families_ex
)
7439 enum_font_families_ex (ef
.hdc
,
7440 &font_match_pattern
,
7441 (FONTENUMPROC
) enum_fontex_cb1
,
7444 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
7447 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
7453 /* Make a list of the fonts we got back.
7454 Store that in the font cache for the display. */
7455 XSETCDR (dpyinfo
->name_list_element
,
7456 Fcons (Fcons (tpat
, list
),
7457 XCDR (dpyinfo
->name_list_element
)));
7460 if (NILP (list
)) continue; /* Try the remaining alternatives. */
7462 newlist
= second_best
= Qnil
;
7464 /* Make a list of the fonts that have the right width. */
7465 for (; CONSP (list
); list
= XCDR (list
))
7472 if (NILP (XCAR (tem
)))
7476 newlist
= Fcons (XCAR (tem
), newlist
);
7478 if (n_fonts
>= maxnames
)
7483 if (!INTEGERP (XCDR (tem
)))
7485 /* Since we don't yet know the size of the font, we must
7486 load it and try GetTextMetrics. */
7487 W32FontStruct thisinfo
;
7492 if (!x_to_w32_font (XSTRING (XCAR (tem
))->data
, &lf
))
7496 thisinfo
.bdf
= NULL
;
7497 thisinfo
.hfont
= CreateFontIndirect (&lf
);
7498 if (thisinfo
.hfont
== NULL
)
7501 hdc
= GetDC (dpyinfo
->root_window
);
7502 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
7503 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
7504 XSETCDR (tem
, make_number (FONT_WIDTH (&thisinfo
)));
7506 XSETCDR (tem
, make_number (0));
7507 SelectObject (hdc
, oldobj
);
7508 ReleaseDC (dpyinfo
->root_window
, hdc
);
7509 DeleteObject(thisinfo
.hfont
);
7512 found_size
= XINT (XCDR (tem
));
7513 if (found_size
== size
)
7515 newlist
= Fcons (XCAR (tem
), newlist
);
7517 if (n_fonts
>= maxnames
)
7520 /* keep track of the closest matching size in case
7521 no exact match is found. */
7522 else if (found_size
> 0)
7524 if (NILP (second_best
))
7527 else if (found_size
< size
)
7529 if (XINT (XCDR (second_best
)) > size
7530 || XINT (XCDR (second_best
)) < found_size
)
7535 if (XINT (XCDR (second_best
)) > size
7536 && XINT (XCDR (second_best
)) >
7543 if (!NILP (newlist
))
7545 else if (!NILP (second_best
))
7547 newlist
= Fcons (XCAR (second_best
), Qnil
);
7552 /* Include any bdf fonts. */
7553 if (n_fonts
< maxnames
)
7555 Lisp_Object combined
[2];
7556 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
7557 combined
[1] = newlist
;
7558 newlist
= Fnconc(2, combined
);
7565 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
7567 w32_get_font_info (f
, font_idx
)
7571 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
7576 w32_query_font (struct frame
*f
, char *fontname
)
7579 struct font_info
*pfi
;
7581 pfi
= FRAME_W32_FONT_TABLE (f
);
7583 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
7585 if (strcmp(pfi
->name
, fontname
) == 0) return pfi
;
7591 /* Find a CCL program for a font specified by FONTP, and set the member
7592 `encoder' of the structure. */
7595 w32_find_ccl_program (fontp
)
7596 struct font_info
*fontp
;
7598 Lisp_Object list
, elt
;
7600 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
7604 && STRINGP (XCAR (elt
))
7605 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
7611 struct ccl_program
*ccl
7612 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
7614 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
7617 fontp
->font_encoder
= ccl
;
7622 /* Find BDF files in a specified directory. (use GCPRO when calling,
7623 as this calls lisp to get a directory listing). */
7625 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
7627 Lisp_Object filelist
, list
= Qnil
;
7630 if (!STRINGP(directory
))
7633 filelist
= Fdirectory_files (directory
, Qt
,
7634 build_string (".*\\.[bB][dD][fF]"), Qt
);
7636 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
7638 Lisp_Object filename
= XCAR (filelist
);
7639 if (w32_BDF_to_x_font (XSTRING (filename
)->data
, fontname
, 100))
7640 store_in_alist (&list
, build_string (fontname
), filename
);
7645 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
7647 doc
: /* Return a list of BDF fonts in DIR.
7648 The list is suitable for appending to w32-bdf-filename-alist. Fonts
7649 which do not contain an xlfd description will not be included in the
7650 list. DIR may be a list of directories. */)
7652 Lisp_Object directory
;
7654 Lisp_Object list
= Qnil
;
7655 struct gcpro gcpro1
, gcpro2
;
7657 if (!CONSP (directory
))
7658 return w32_find_bdf_fonts_in_dir (directory
);
7660 for ( ; CONSP (directory
); directory
= XCDR (directory
))
7662 Lisp_Object pair
[2];
7665 GCPRO2 (directory
, list
);
7666 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
7667 list
= Fnconc( 2, pair
);
7674 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
7675 doc
: /* Internal function called by `color-defined-p', which see. */)
7677 Lisp_Object color
, frame
;
7680 FRAME_PTR f
= check_x_frame (frame
);
7682 CHECK_STRING (color
);
7684 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7690 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
7691 doc
: /* Internal function called by `color-values', which see. */)
7693 Lisp_Object color
, frame
;
7696 FRAME_PTR f
= check_x_frame (frame
);
7698 CHECK_STRING (color
);
7700 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7704 rgb
[0] = make_number ((GetRValue (foo
.pixel
) << 8)
7705 | GetRValue (foo
.pixel
));
7706 rgb
[1] = make_number ((GetGValue (foo
.pixel
) << 8)
7707 | GetGValue (foo
.pixel
));
7708 rgb
[2] = make_number ((GetBValue (foo
.pixel
) << 8)
7709 | GetBValue (foo
.pixel
));
7710 return Flist (3, rgb
);
7716 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
7717 doc
: /* Internal function called by `display-color-p', which see. */)
7719 Lisp_Object display
;
7721 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7723 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
7729 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
,
7730 Sx_display_grayscale_p
, 0, 1, 0,
7731 doc
: /* Return t if the X display supports shades of gray.
7732 Note that color displays do support shades of gray.
7733 The optional argument DISPLAY specifies which display to ask about.
7734 DISPLAY should be either a frame or a display name (a string).
7735 If omitted or nil, that stands for the selected frame's display. */)
7737 Lisp_Object display
;
7739 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7741 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
7747 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
,
7748 Sx_display_pixel_width
, 0, 1, 0,
7749 doc
: /* Returns the width in pixels of DISPLAY.
7750 The optional argument DISPLAY specifies which display to ask about.
7751 DISPLAY should be either a frame or a display name (a string).
7752 If omitted or nil, that stands for the selected frame's display. */)
7754 Lisp_Object display
;
7756 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7758 return make_number (dpyinfo
->width
);
7761 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
7762 Sx_display_pixel_height
, 0, 1, 0,
7763 doc
: /* Returns the height in pixels of DISPLAY.
7764 The optional argument DISPLAY specifies which display to ask about.
7765 DISPLAY should be either a frame or a display name (a string).
7766 If omitted or nil, that stands for the selected frame's display. */)
7768 Lisp_Object display
;
7770 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7772 return make_number (dpyinfo
->height
);
7775 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
7777 doc
: /* Returns the number of bitplanes of DISPLAY.
7778 The optional argument DISPLAY specifies which display to ask about.
7779 DISPLAY should be either a frame or a display name (a string).
7780 If omitted or nil, that stands for the selected frame's display. */)
7782 Lisp_Object display
;
7784 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7786 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
7789 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
7791 doc
: /* Returns the number of color cells of DISPLAY.
7792 The optional argument DISPLAY specifies which display to ask about.
7793 DISPLAY should be either a frame or a display name (a string).
7794 If omitted or nil, that stands for the selected frame's display. */)
7796 Lisp_Object display
;
7798 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7802 hdc
= GetDC (dpyinfo
->root_window
);
7803 if (dpyinfo
->has_palette
)
7804 cap
= GetDeviceCaps (hdc
,SIZEPALETTE
);
7806 cap
= GetDeviceCaps (hdc
,NUMCOLORS
);
7808 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
7809 and because probably is more meaningful on Windows anyway */
7811 cap
= 1 << min(dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
7813 ReleaseDC (dpyinfo
->root_window
, hdc
);
7815 return make_number (cap
);
7818 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
7819 Sx_server_max_request_size
,
7821 doc
: /* Returns the maximum request size of the server of DISPLAY.
7822 The optional argument DISPLAY specifies which display to ask about.
7823 DISPLAY should be either a frame or a display name (a string).
7824 If omitted or nil, that stands for the selected frame's display. */)
7826 Lisp_Object display
;
7828 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7830 return make_number (1);
7833 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
7834 doc
: /* Returns the vendor ID string of the W32 system (Microsoft).
7835 The optional argument DISPLAY specifies which display to ask about.
7836 DISPLAY should be either a frame or a display name (a string).
7837 If omitted or nil, that stands for the selected frame's display. */)
7839 Lisp_Object display
;
7841 return build_string ("Microsoft Corp.");
7844 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
7845 doc
: /* Returns the version numbers of the server of DISPLAY.
7846 The value is a list of three integers: the major and minor
7847 version numbers, and the vendor-specific release
7848 number. See also the function `x-server-vendor'.
7850 The optional argument DISPLAY specifies which display to ask about.
7851 DISPLAY should be either a frame or a display name (a string).
7852 If omitted or nil, that stands for the selected frame's display. */)
7854 Lisp_Object display
;
7856 return Fcons (make_number (w32_major_version
),
7857 Fcons (make_number (w32_minor_version
),
7858 Fcons (make_number (w32_build_number
), Qnil
)));
7861 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
7862 doc
: /* Returns the number of screens on the server of DISPLAY.
7863 The optional argument DISPLAY specifies which display to ask about.
7864 DISPLAY should be either a frame or a display name (a string).
7865 If omitted or nil, that stands for the selected frame's display. */)
7867 Lisp_Object display
;
7869 return make_number (1);
7872 DEFUN ("x-display-mm-height", Fx_display_mm_height
,
7873 Sx_display_mm_height
, 0, 1, 0,
7874 doc
: /* Returns the height in millimeters of DISPLAY.
7875 The optional argument DISPLAY specifies which display to ask about.
7876 DISPLAY should be either a frame or a display name (a string).
7877 If omitted or nil, that stands for the selected frame's display. */)
7879 Lisp_Object display
;
7881 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7885 hdc
= GetDC (dpyinfo
->root_window
);
7887 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
7889 ReleaseDC (dpyinfo
->root_window
, hdc
);
7891 return make_number (cap
);
7894 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
7895 doc
: /* Returns the width in millimeters of DISPLAY.
7896 The optional argument DISPLAY specifies which display to ask about.
7897 DISPLAY should be either a frame or a display name (a string).
7898 If omitted or nil, that stands for the selected frame's display. */)
7900 Lisp_Object display
;
7902 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7907 hdc
= GetDC (dpyinfo
->root_window
);
7909 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
7911 ReleaseDC (dpyinfo
->root_window
, hdc
);
7913 return make_number (cap
);
7916 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
7917 Sx_display_backing_store
, 0, 1, 0,
7918 doc
: /* Returns an indication of whether DISPLAY does backing store.
7919 The value may be `always', `when-mapped', or `not-useful'.
7920 The optional argument DISPLAY specifies which display to ask about.
7921 DISPLAY should be either a frame or a display name (a string).
7922 If omitted or nil, that stands for the selected frame's display. */)
7924 Lisp_Object display
;
7926 return intern ("not-useful");
7929 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
7930 Sx_display_visual_class
, 0, 1, 0,
7931 doc
: /* Returns the visual class of DISPLAY.
7932 The value is one of the symbols `static-gray', `gray-scale',
7933 `static-color', `pseudo-color', `true-color', or `direct-color'.
7935 The optional argument DISPLAY specifies which display to ask about.
7936 DISPLAY should be either a frame or a display name (a string).
7937 If omitted or nil, that stands for the selected frame's display. */)
7939 Lisp_Object display
;
7941 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7942 Lisp_Object result
= Qnil
;
7944 if (dpyinfo
->has_palette
)
7945 result
= intern ("pseudo-color");
7946 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
7947 result
= intern ("static-grey");
7948 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
7949 result
= intern ("static-color");
7950 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
7951 result
= intern ("true-color");
7956 DEFUN ("x-display-save-under", Fx_display_save_under
,
7957 Sx_display_save_under
, 0, 1, 0,
7958 doc
: /* Returns t if DISPLAY supports the save-under feature.
7959 The optional argument DISPLAY specifies which display to ask about.
7960 DISPLAY should be either a frame or a display name (a string).
7961 If omitted or nil, that stands for the selected frame's display. */)
7963 Lisp_Object display
;
7970 register struct frame
*f
;
7972 return PIXEL_WIDTH (f
);
7977 register struct frame
*f
;
7979 return PIXEL_HEIGHT (f
);
7984 register struct frame
*f
;
7986 return FONT_WIDTH (f
->output_data
.w32
->font
);
7991 register struct frame
*f
;
7993 return f
->output_data
.w32
->line_height
;
7998 register struct frame
*f
;
8000 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
8003 /* Return the display structure for the display named NAME.
8004 Open a new connection if necessary. */
8006 struct w32_display_info
*
8007 x_display_info_for_name (name
)
8011 struct w32_display_info
*dpyinfo
;
8013 CHECK_STRING (name
);
8015 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
8017 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
8020 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
8025 /* Use this general default value to start with. */
8026 Vx_resource_name
= Vinvocation_name
;
8028 validate_x_resource_name ();
8030 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
8031 (char *) XSTRING (Vx_resource_name
)->data
);
8034 error ("Cannot connect to server %s", XSTRING (name
)->data
);
8037 XSETFASTINT (Vwindow_system_version
, 3);
8042 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
8043 1, 3, 0, doc
: /* Open a connection to a server.
8044 DISPLAY is the name of the display to connect to.
8045 Optional second arg XRM-STRING is a string of resources in xrdb format.
8046 If the optional third arg MUST-SUCCEED is non-nil,
8047 terminate Emacs if we can't open the connection. */)
8048 (display
, xrm_string
, must_succeed
)
8049 Lisp_Object display
, xrm_string
, must_succeed
;
8051 unsigned char *xrm_option
;
8052 struct w32_display_info
*dpyinfo
;
8054 /* If initialization has already been done, return now to avoid
8055 overwriting critical parts of one_w32_display_info. */
8059 CHECK_STRING (display
);
8060 if (! NILP (xrm_string
))
8061 CHECK_STRING (xrm_string
);
8063 if (! EQ (Vwindow_system
, intern ("w32")))
8064 error ("Not using Microsoft Windows");
8066 /* Allow color mapping to be defined externally; first look in user's
8067 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
8069 Lisp_Object color_file
;
8070 struct gcpro gcpro1
;
8072 color_file
= build_string("~/rgb.txt");
8074 GCPRO1 (color_file
);
8076 if (NILP (Ffile_readable_p (color_file
)))
8078 Fexpand_file_name (build_string ("rgb.txt"),
8079 Fsymbol_value (intern ("data-directory")));
8081 Vw32_color_map
= Fw32_load_color_file (color_file
);
8085 if (NILP (Vw32_color_map
))
8086 Vw32_color_map
= Fw32_default_color_map ();
8088 if (! NILP (xrm_string
))
8089 xrm_option
= (unsigned char *) XSTRING (xrm_string
)->data
;
8091 xrm_option
= (unsigned char *) 0;
8093 /* Use this general default value to start with. */
8094 /* First remove .exe suffix from invocation-name - it looks ugly. */
8096 char basename
[ MAX_PATH
], *str
;
8098 strcpy (basename
, XSTRING (Vinvocation_name
)->data
);
8099 str
= strrchr (basename
, '.');
8101 Vinvocation_name
= build_string (basename
);
8103 Vx_resource_name
= Vinvocation_name
;
8105 validate_x_resource_name ();
8107 /* This is what opens the connection and sets x_current_display.
8108 This also initializes many symbols, such as those used for input. */
8109 dpyinfo
= w32_term_init (display
, xrm_option
,
8110 (char *) XSTRING (Vx_resource_name
)->data
);
8114 if (!NILP (must_succeed
))
8115 fatal ("Cannot connect to server %s.\n",
8116 XSTRING (display
)->data
);
8118 error ("Cannot connect to server %s", XSTRING (display
)->data
);
8123 XSETFASTINT (Vwindow_system_version
, 3);
8127 DEFUN ("x-close-connection", Fx_close_connection
,
8128 Sx_close_connection
, 1, 1, 0,
8129 doc
: /* Close the connection to DISPLAY's server.
8130 For DISPLAY, specify either a frame or a display name (a string).
8131 If DISPLAY is nil, that stands for the selected frame's display. */)
8133 Lisp_Object display
;
8135 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
8138 if (dpyinfo
->reference_count
> 0)
8139 error ("Display still has frames on it");
8142 /* Free the fonts in the font table. */
8143 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
8144 if (dpyinfo
->font_table
[i
].name
)
8146 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
8147 xfree (dpyinfo
->font_table
[i
].full_name
);
8148 xfree (dpyinfo
->font_table
[i
].name
);
8149 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
8151 x_destroy_all_bitmaps (dpyinfo
);
8153 x_delete_display (dpyinfo
);
8159 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
8160 doc
: /* Return the list of display names that Emacs has connections to. */)
8163 Lisp_Object tail
, result
;
8166 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
8167 result
= Fcons (XCAR (XCAR (tail
)), result
);
8172 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
8173 doc
: /* This is a noop on W32 systems. */)
8175 Lisp_Object display
, on
;
8181 /***********************************************************************
8183 ***********************************************************************/
8185 /* Value is the number of elements of vector VECTOR. */
8187 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
8189 /* List of supported image types. Use define_image_type to add new
8190 types. Use lookup_image_type to find a type for a given symbol. */
8192 static struct image_type
*image_types
;
8194 /* The symbol `image' which is the car of the lists used to represent
8197 extern Lisp_Object Qimage
;
8199 /* The symbol `xbm' which is used as the type symbol for XBM images. */
8205 extern Lisp_Object QCwidth
, QCheight
, QCforeground
, QCbackground
, QCfile
;
8206 extern Lisp_Object QCdata
, QCtype
;
8207 Lisp_Object QCascent
, QCmargin
, QCrelief
;
8208 Lisp_Object QCconversion
, QCcolor_symbols
, QCheuristic_mask
;
8209 Lisp_Object QCindex
, QCmatrix
, QCcolor_adjustment
, QCmask
;
8211 /* Other symbols. */
8213 Lisp_Object Qlaplace
, Qemboss
, Qedge_detection
, Qheuristic
;
8215 /* Time in seconds after which images should be removed from the cache
8216 if not displayed. */
8218 Lisp_Object Vimage_cache_eviction_delay
;
8220 /* Function prototypes. */
8222 static void define_image_type
P_ ((struct image_type
*type
));
8223 static struct image_type
*lookup_image_type
P_ ((Lisp_Object symbol
));
8224 static void image_error
P_ ((char *format
, Lisp_Object
, Lisp_Object
));
8225 static void x_laplace
P_ ((struct frame
*, struct image
*));
8226 static void x_emboss
P_ ((struct frame
*, struct image
*));
8227 static int x_build_heuristic_mask
P_ ((struct frame
*, struct image
*,
8231 /* Define a new image type from TYPE. This adds a copy of TYPE to
8232 image_types and adds the symbol *TYPE->type to Vimage_types. */
8235 define_image_type (type
)
8236 struct image_type
*type
;
8238 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
8239 The initialized data segment is read-only. */
8240 struct image_type
*p
= (struct image_type
*) xmalloc (sizeof *p
);
8241 bcopy (type
, p
, sizeof *p
);
8242 p
->next
= image_types
;
8244 Vimage_types
= Fcons (*p
->type
, Vimage_types
);
8248 /* Look up image type SYMBOL, and return a pointer to its image_type
8249 structure. Value is null if SYMBOL is not a known image type. */
8251 static INLINE
struct image_type
*
8252 lookup_image_type (symbol
)
8255 struct image_type
*type
;
8257 for (type
= image_types
; type
; type
= type
->next
)
8258 if (EQ (symbol
, *type
->type
))
8265 /* Value is non-zero if OBJECT is a valid Lisp image specification. A
8266 valid image specification is a list whose car is the symbol
8267 `image', and whose rest is a property list. The property list must
8268 contain a value for key `:type'. That value must be the name of a
8269 supported image type. The rest of the property list depends on the
8273 valid_image_p (object
)
8278 if (CONSP (object
) && EQ (XCAR (object
), Qimage
))
8282 for (tem
= XCDR (object
); CONSP (tem
); tem
= XCDR (tem
))
8283 if (EQ (XCAR (tem
), QCtype
))
8286 if (CONSP (tem
) && SYMBOLP (XCAR (tem
)))
8288 struct image_type
*type
;
8289 type
= lookup_image_type (XCAR (tem
));
8291 valid_p
= type
->valid_p (object
);
8302 /* Log error message with format string FORMAT and argument ARG.
8303 Signaling an error, e.g. when an image cannot be loaded, is not a
8304 good idea because this would interrupt redisplay, and the error
8305 message display would lead to another redisplay. This function
8306 therefore simply displays a message. */
8309 image_error (format
, arg1
, arg2
)
8311 Lisp_Object arg1
, arg2
;
8313 add_to_log (format
, arg1
, arg2
);
8318 /***********************************************************************
8319 Image specifications
8320 ***********************************************************************/
8322 enum image_value_type
8324 IMAGE_DONT_CHECK_VALUE_TYPE
,
8326 IMAGE_STRING_OR_NIL_VALUE
,
8328 IMAGE_POSITIVE_INTEGER_VALUE
,
8329 IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
,
8330 IMAGE_NON_NEGATIVE_INTEGER_VALUE
,
8332 IMAGE_INTEGER_VALUE
,
8333 IMAGE_FUNCTION_VALUE
,
8338 /* Structure used when parsing image specifications. */
8340 struct image_keyword
8342 /* Name of keyword. */
8345 /* The type of value allowed. */
8346 enum image_value_type type
;
8348 /* Non-zero means key must be present. */
8351 /* Used to recognize duplicate keywords in a property list. */
8354 /* The value that was found. */
8359 static int parse_image_spec
P_ ((Lisp_Object
, struct image_keyword
*,
8361 static Lisp_Object image_spec_value
P_ ((Lisp_Object
, Lisp_Object
, int *));
8364 /* Parse image spec SPEC according to KEYWORDS. A valid image spec
8365 has the format (image KEYWORD VALUE ...). One of the keyword/
8366 value pairs must be `:type TYPE'. KEYWORDS is a vector of
8367 image_keywords structures of size NKEYWORDS describing other
8368 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */
8371 parse_image_spec (spec
, keywords
, nkeywords
, type
)
8373 struct image_keyword
*keywords
;
8380 if (!CONSP (spec
) || !EQ (XCAR (spec
), Qimage
))
8383 plist
= XCDR (spec
);
8384 while (CONSP (plist
))
8386 Lisp_Object key
, value
;
8388 /* First element of a pair must be a symbol. */
8390 plist
= XCDR (plist
);
8394 /* There must follow a value. */
8397 value
= XCAR (plist
);
8398 plist
= XCDR (plist
);
8400 /* Find key in KEYWORDS. Error if not found. */
8401 for (i
= 0; i
< nkeywords
; ++i
)
8402 if (strcmp (keywords
[i
].name
, XSTRING (SYMBOL_NAME (key
))->data
) == 0)
8408 /* Record that we recognized the keyword. If a keywords
8409 was found more than once, it's an error. */
8410 keywords
[i
].value
= value
;
8411 ++keywords
[i
].count
;
8413 if (keywords
[i
].count
> 1)
8416 /* Check type of value against allowed type. */
8417 switch (keywords
[i
].type
)
8419 case IMAGE_STRING_VALUE
:
8420 if (!STRINGP (value
))
8424 case IMAGE_STRING_OR_NIL_VALUE
:
8425 if (!STRINGP (value
) && !NILP (value
))
8429 case IMAGE_SYMBOL_VALUE
:
8430 if (!SYMBOLP (value
))
8434 case IMAGE_POSITIVE_INTEGER_VALUE
:
8435 if (!INTEGERP (value
) || XINT (value
) <= 0)
8439 case IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
:
8440 if (INTEGERP (value
) && XINT (value
) >= 0)
8443 && INTEGERP (XCAR (value
)) && INTEGERP (XCDR (value
))
8444 && XINT (XCAR (value
)) >= 0 && XINT (XCDR (value
)) >= 0)
8448 case IMAGE_ASCENT_VALUE
:
8449 if (SYMBOLP (value
) && EQ (value
, Qcenter
))
8451 else if (INTEGERP (value
)
8452 && XINT (value
) >= 0
8453 && XINT (value
) <= 100)
8457 case IMAGE_NON_NEGATIVE_INTEGER_VALUE
:
8458 if (!INTEGERP (value
) || XINT (value
) < 0)
8462 case IMAGE_DONT_CHECK_VALUE_TYPE
:
8465 case IMAGE_FUNCTION_VALUE
:
8466 value
= indirect_function (value
);
8468 || COMPILEDP (value
)
8469 || (CONSP (value
) && EQ (XCAR (value
), Qlambda
)))
8473 case IMAGE_NUMBER_VALUE
:
8474 if (!INTEGERP (value
) && !FLOATP (value
))
8478 case IMAGE_INTEGER_VALUE
:
8479 if (!INTEGERP (value
))
8483 case IMAGE_BOOL_VALUE
:
8484 if (!NILP (value
) && !EQ (value
, Qt
))
8493 if (EQ (key
, QCtype
) && !EQ (type
, value
))
8497 /* Check that all mandatory fields are present. */
8498 for (i
= 0; i
< nkeywords
; ++i
)
8499 if (keywords
[i
].mandatory_p
&& keywords
[i
].count
== 0)
8502 return NILP (plist
);
8506 /* Return the value of KEY in image specification SPEC. Value is nil
8507 if KEY is not present in SPEC. if FOUND is not null, set *FOUND
8508 to 1 if KEY was found in SPEC, set it to 0 otherwise. */
8511 image_spec_value (spec
, key
, found
)
8512 Lisp_Object spec
, key
;
8517 xassert (valid_image_p (spec
));
8519 for (tail
= XCDR (spec
);
8520 CONSP (tail
) && CONSP (XCDR (tail
));
8521 tail
= XCDR (XCDR (tail
)))
8523 if (EQ (XCAR (tail
), key
))
8527 return XCAR (XCDR (tail
));
8537 DEFUN ("image-size", Fimage_size
, Simage_size
, 1, 3, 0,
8538 doc
: /* Return the size of image SPEC as pair (WIDTH . HEIGHT).
8539 PIXELS non-nil means return the size in pixels, otherwise return the
8540 size in canonical character units.
8541 FRAME is the frame on which the image will be displayed. FRAME nil
8542 or omitted means use the selected frame. */)
8543 (spec
, pixels
, frame
)
8544 Lisp_Object spec
, pixels
, frame
;
8549 if (valid_image_p (spec
))
8551 struct frame
*f
= check_x_frame (frame
);
8552 int id
= lookup_image (f
, spec
);
8553 struct image
*img
= IMAGE_FROM_ID (f
, id
);
8554 int width
= img
->width
+ 2 * img
->hmargin
;
8555 int height
= img
->height
+ 2 * img
->vmargin
;
8558 size
= Fcons (make_float ((double) width
/ CANON_X_UNIT (f
)),
8559 make_float ((double) height
/ CANON_Y_UNIT (f
)));
8561 size
= Fcons (make_number (width
), make_number (height
));
8564 error ("Invalid image specification");
8570 DEFUN ("image-mask-p", Fimage_mask_p
, Simage_mask_p
, 1, 2, 0,
8571 doc
: /* Return t if image SPEC has a mask bitmap.
8572 FRAME is the frame on which the image will be displayed. FRAME nil
8573 or omitted means use the selected frame. */)
8575 Lisp_Object spec
, frame
;
8580 if (valid_image_p (spec
))
8582 struct frame
*f
= check_x_frame (frame
);
8583 int id
= lookup_image (f
, spec
);
8584 struct image
*img
= IMAGE_FROM_ID (f
, id
);
8589 error ("Invalid image specification");
8595 /***********************************************************************
8596 Image type independent image structures
8597 ***********************************************************************/
8599 static struct image
*make_image
P_ ((Lisp_Object spec
, unsigned hash
));
8600 static void free_image
P_ ((struct frame
*f
, struct image
*img
));
8603 /* Allocate and return a new image structure for image specification
8604 SPEC. SPEC has a hash value of HASH. */
8606 static struct image
*
8607 make_image (spec
, hash
)
8611 struct image
*img
= (struct image
*) xmalloc (sizeof *img
);
8613 xassert (valid_image_p (spec
));
8614 bzero (img
, sizeof *img
);
8615 img
->type
= lookup_image_type (image_spec_value (spec
, QCtype
, NULL
));
8616 xassert (img
->type
!= NULL
);
8618 img
->data
.lisp_val
= Qnil
;
8619 img
->ascent
= DEFAULT_IMAGE_ASCENT
;
8625 /* Free image IMG which was used on frame F, including its resources. */
8634 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8636 /* Remove IMG from the hash table of its cache. */
8638 img
->prev
->next
= img
->next
;
8640 c
->buckets
[img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
] = img
->next
;
8643 img
->next
->prev
= img
->prev
;
8645 c
->images
[img
->id
] = NULL
;
8647 /* Free resources, then free IMG. */
8648 img
->type
->free (f
, img
);
8654 /* Prepare image IMG for display on frame F. Must be called before
8655 drawing an image. */
8658 prepare_image_for_display (f
, img
)
8664 /* We're about to display IMG, so set its timestamp to `now'. */
8666 img
->timestamp
= EMACS_SECS (t
);
8668 /* If IMG doesn't have a pixmap yet, load it now, using the image
8669 type dependent loader function. */
8670 if (img
->pixmap
== 0 && !img
->load_failed_p
)
8671 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
8675 /* Value is the number of pixels for the ascent of image IMG when
8676 drawn in face FACE. */
8679 image_ascent (img
, face
)
8683 int height
= img
->height
+ img
->vmargin
;
8686 if (img
->ascent
== CENTERED_IMAGE_ASCENT
)
8689 ascent
= height
/ 2 - (FONT_DESCENT(face
->font
)
8690 - FONT_BASE(face
->font
)) / 2;
8692 ascent
= height
/ 2;
8695 ascent
= (int) (height
* img
->ascent
/ 100.0);
8702 /* Image background colors. */
8704 /* Find the "best" corner color of a bitmap. XIMG is assumed to a device
8705 context with the bitmap selected. */
8707 four_corners_best (ximg
, width
, height
)
8709 unsigned long width
, height
;
8711 COLORREF corners
[4], best
;
8714 /* Get the colors at the corners of ximg. */
8715 corners
[0] = GetPixel (ximg
, 0, 0);
8716 corners
[1] = GetPixel (ximg
, width
- 1, 0);
8717 corners
[2] = GetPixel (ximg
, width
- 1, height
- 1);
8718 corners
[3] = GetPixel (ximg
, 0, height
- 1);
8720 /* Choose the most frequently found color as background. */
8721 for (i
= best_count
= 0; i
< 4; ++i
)
8725 for (j
= n
= 0; j
< 4; ++j
)
8726 if (corners
[i
] == corners
[j
])
8730 best
= corners
[i
], best_count
= n
;
8736 /* Return the `background' field of IMG. If IMG doesn't have one yet,
8737 it is guessed heuristically. If non-zero, XIMG is an existing XImage
8738 object to use for the heuristic. */
8741 image_background (img
, f
, ximg
)
8746 if (! img
->background_valid
)
8747 /* IMG doesn't have a background yet, try to guess a reasonable value. */
8749 #if 0 /* TODO: Image support. */
8750 int free_ximg
= !ximg
;
8753 ximg
= XGetImage (FRAME_X_DISPLAY (f
), img
->pixmap
,
8754 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
8756 img
->background
= four_corners_best (ximg
, img
->width
, img
->height
);
8759 XDestroyImage (ximg
);
8761 img
->background_valid
= 1;
8765 return img
->background
;
8768 /* Return the `background_transparent' field of IMG. If IMG doesn't
8769 have one yet, it is guessed heuristically. If non-zero, MASK is an
8770 existing XImage object to use for the heuristic. */
8773 image_background_transparent (img
, f
, mask
)
8778 if (! img
->background_transparent_valid
)
8779 /* IMG doesn't have a background yet, try to guess a reasonable value. */
8781 #if 0 /* TODO: Image support. */
8784 int free_mask
= !mask
;
8787 mask
= XGetImage (FRAME_X_DISPLAY (f
), img
->mask
,
8788 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
8790 img
->background_transparent
8791 = !four_corners_best (mask
, img
->width
, img
->height
);
8794 XDestroyImage (mask
);
8798 img
->background_transparent
= 0;
8800 img
->background_transparent_valid
= 1;
8803 return img
->background_transparent
;
8807 /***********************************************************************
8808 Helper functions for X image types
8809 ***********************************************************************/
8811 static void x_clear_image_1
P_ ((struct frame
*, struct image
*, int,
8813 static void x_clear_image
P_ ((struct frame
*f
, struct image
*img
));
8814 static unsigned long x_alloc_image_color
P_ ((struct frame
*f
,
8816 Lisp_Object color_name
,
8817 unsigned long dflt
));
8820 /* Clear X resources of image IMG on frame F. PIXMAP_P non-zero means
8821 free the pixmap if any. MASK_P non-zero means clear the mask
8822 pixmap if any. COLORS_P non-zero means free colors allocated for
8823 the image, if any. */
8826 x_clear_image_1 (f
, img
, pixmap_p
, mask_p
, colors_p
)
8829 int pixmap_p
, mask_p
, colors_p
;
8831 if (pixmap_p
&& img
->pixmap
)
8833 DeleteObject (img
->pixmap
);
8835 img
->background_valid
= 0;
8838 if (mask_p
&& img
->mask
)
8840 DeleteObject (img
->mask
);
8842 img
->background_transparent_valid
= 0;
8845 if (colors_p
&& img
->ncolors
)
8847 #if 0 /* TODO: color table support. */
8848 x_free_colors (f
, img
->colors
, img
->ncolors
);
8850 xfree (img
->colors
);
8856 /* Free X resources of image IMG which is used on frame F. */
8859 x_clear_image (f
, img
)
8866 DeleteObject (img
->pixmap
);
8873 #if 0 /* TODO: color table support */
8875 int class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
8877 /* If display has an immutable color map, freeing colors is not
8878 necessary and some servers don't allow it. So don't do it. */
8879 if (class != StaticColor
8880 && class != StaticGray
8881 && class != TrueColor
)
8885 cmap
= DefaultColormapOfScreen (FRAME_W32_DISPLAY_INFO (f
)->screen
);
8886 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
, img
->colors
,
8892 xfree (img
->colors
);
8899 /* Allocate color COLOR_NAME for image IMG on frame F. If color
8900 cannot be allocated, use DFLT. Add a newly allocated color to
8901 IMG->colors, so that it can be freed again. Value is the pixel
8904 static unsigned long
8905 x_alloc_image_color (f
, img
, color_name
, dflt
)
8908 Lisp_Object color_name
;
8912 unsigned long result
;
8914 xassert (STRINGP (color_name
));
8916 if (w32_defined_color (f
, XSTRING (color_name
)->data
, &color
, 1))
8918 /* This isn't called frequently so we get away with simply
8919 reallocating the color vector to the needed size, here. */
8922 (unsigned long *) xrealloc (img
->colors
,
8923 img
->ncolors
* sizeof *img
->colors
);
8924 img
->colors
[img
->ncolors
- 1] = color
.pixel
;
8925 result
= color
.pixel
;
8934 /***********************************************************************
8936 ***********************************************************************/
8938 static void cache_image
P_ ((struct frame
*f
, struct image
*img
));
8939 static void postprocess_image
P_ ((struct frame
*, struct image
*));
8942 /* Return a new, initialized image cache that is allocated from the
8943 heap. Call free_image_cache to free an image cache. */
8945 struct image_cache
*
8948 struct image_cache
*c
= (struct image_cache
*) xmalloc (sizeof *c
);
8951 bzero (c
, sizeof *c
);
8953 c
->images
= (struct image
**) xmalloc (c
->size
* sizeof *c
->images
);
8954 size
= IMAGE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
8955 c
->buckets
= (struct image
**) xmalloc (size
);
8956 bzero (c
->buckets
, size
);
8961 /* Free image cache of frame F. Be aware that X frames share images
8965 free_image_cache (f
)
8968 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8973 /* Cache should not be referenced by any frame when freed. */
8974 xassert (c
->refcount
== 0);
8976 for (i
= 0; i
< c
->used
; ++i
)
8977 free_image (f
, c
->images
[i
]);
8981 FRAME_X_IMAGE_CACHE (f
) = NULL
;
8986 /* Clear image cache of frame F. FORCE_P non-zero means free all
8987 images. FORCE_P zero means clear only images that haven't been
8988 displayed for some time. Should be called from time to time to
8989 reduce the number of loaded images. If image-eviction-seconds is
8990 non-nil, this frees images in the cache which weren't displayed for
8991 at least that many seconds. */
8994 clear_image_cache (f
, force_p
)
8998 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
9000 if (c
&& INTEGERP (Vimage_cache_eviction_delay
))
9007 old
= EMACS_SECS (t
) - XFASTINT (Vimage_cache_eviction_delay
);
9009 /* Block input so that we won't be interrupted by a SIGIO
9010 while being in an inconsistent state. */
9013 for (i
= nfreed
= 0; i
< c
->used
; ++i
)
9015 struct image
*img
= c
->images
[i
];
9017 && (force_p
|| (img
->timestamp
< old
)))
9019 free_image (f
, img
);
9024 /* We may be clearing the image cache because, for example,
9025 Emacs was iconified for a longer period of time. In that
9026 case, current matrices may still contain references to
9027 images freed above. So, clear these matrices. */
9030 Lisp_Object tail
, frame
;
9032 FOR_EACH_FRAME (tail
, frame
)
9034 struct frame
*f
= XFRAME (frame
);
9036 && FRAME_X_IMAGE_CACHE (f
) == c
)
9037 clear_current_matrices (f
);
9040 ++windows_or_buffers_changed
;
9048 DEFUN ("clear-image-cache", Fclear_image_cache
, Sclear_image_cache
,
9050 doc
: /* Clear the image cache of FRAME.
9051 FRAME nil or omitted means use the selected frame.
9052 FRAME t means clear the image caches of all frames. */)
9060 FOR_EACH_FRAME (tail
, frame
)
9061 if (FRAME_W32_P (XFRAME (frame
)))
9062 clear_image_cache (XFRAME (frame
), 1);
9065 clear_image_cache (check_x_frame (frame
), 1);
9071 /* Compute masks and transform image IMG on frame F, as specified
9072 by the image's specification, */
9075 postprocess_image (f
, img
)
9079 #if 0 /* TODO: image support. */
9080 /* Manipulation of the image's mask. */
9083 Lisp_Object conversion
, spec
;
9088 /* `:heuristic-mask t'
9090 means build a mask heuristically.
9091 `:heuristic-mask (R G B)'
9092 `:mask (heuristic (R G B))'
9093 means build a mask from color (R G B) in the
9096 means remove a mask, if any. */
9098 mask
= image_spec_value (spec
, QCheuristic_mask
, NULL
);
9100 x_build_heuristic_mask (f
, img
, mask
);
9105 mask
= image_spec_value (spec
, QCmask
, &found_p
);
9107 if (EQ (mask
, Qheuristic
))
9108 x_build_heuristic_mask (f
, img
, Qt
);
9109 else if (CONSP (mask
)
9110 && EQ (XCAR (mask
), Qheuristic
))
9112 if (CONSP (XCDR (mask
)))
9113 x_build_heuristic_mask (f
, img
, XCAR (XCDR (mask
)));
9115 x_build_heuristic_mask (f
, img
, XCDR (mask
));
9117 else if (NILP (mask
) && found_p
&& img
->mask
)
9119 DeleteObject (img
->mask
);
9125 /* Should we apply an image transformation algorithm? */
9126 conversion
= image_spec_value (spec
, QCconversion
, NULL
);
9127 if (EQ (conversion
, Qdisabled
))
9128 x_disable_image (f
, img
);
9129 else if (EQ (conversion
, Qlaplace
))
9131 else if (EQ (conversion
, Qemboss
))
9133 else if (CONSP (conversion
)
9134 && EQ (XCAR (conversion
), Qedge_detection
))
9137 tem
= XCDR (conversion
);
9139 x_edge_detection (f
, img
,
9140 Fplist_get (tem
, QCmatrix
),
9141 Fplist_get (tem
, QCcolor_adjustment
));
9148 /* Return the id of image with Lisp specification SPEC on frame F.
9149 SPEC must be a valid Lisp image specification (see valid_image_p). */
9152 lookup_image (f
, spec
)
9156 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
9160 struct gcpro gcpro1
;
9163 /* F must be a window-system frame, and SPEC must be a valid image
9165 xassert (FRAME_WINDOW_P (f
));
9166 xassert (valid_image_p (spec
));
9170 /* Look up SPEC in the hash table of the image cache. */
9171 hash
= sxhash (spec
, 0);
9172 i
= hash
% IMAGE_CACHE_BUCKETS_SIZE
;
9174 for (img
= c
->buckets
[i
]; img
; img
= img
->next
)
9175 if (img
->hash
== hash
&& !NILP (Fequal (img
->spec
, spec
)))
9178 /* If not found, create a new image and cache it. */
9181 extern Lisp_Object Qpostscript
;
9184 img
= make_image (spec
, hash
);
9185 cache_image (f
, img
);
9186 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
9188 /* If we can't load the image, and we don't have a width and
9189 height, use some arbitrary width and height so that we can
9190 draw a rectangle for it. */
9191 if (img
->load_failed_p
)
9195 value
= image_spec_value (spec
, QCwidth
, NULL
);
9196 img
->width
= (INTEGERP (value
)
9197 ? XFASTINT (value
) : DEFAULT_IMAGE_WIDTH
);
9198 value
= image_spec_value (spec
, QCheight
, NULL
);
9199 img
->height
= (INTEGERP (value
)
9200 ? XFASTINT (value
) : DEFAULT_IMAGE_HEIGHT
);
9204 /* Handle image type independent image attributes
9205 `:ascent PERCENT', `:margin MARGIN', `:relief RELIEF',
9206 `:background COLOR'. */
9207 Lisp_Object ascent
, margin
, relief
, bg
;
9209 ascent
= image_spec_value (spec
, QCascent
, NULL
);
9210 if (INTEGERP (ascent
))
9211 img
->ascent
= XFASTINT (ascent
);
9212 else if (EQ (ascent
, Qcenter
))
9213 img
->ascent
= CENTERED_IMAGE_ASCENT
;
9215 margin
= image_spec_value (spec
, QCmargin
, NULL
);
9216 if (INTEGERP (margin
) && XINT (margin
) >= 0)
9217 img
->vmargin
= img
->hmargin
= XFASTINT (margin
);
9218 else if (CONSP (margin
) && INTEGERP (XCAR (margin
))
9219 && INTEGERP (XCDR (margin
)))
9221 if (XINT (XCAR (margin
)) > 0)
9222 img
->hmargin
= XFASTINT (XCAR (margin
));
9223 if (XINT (XCDR (margin
)) > 0)
9224 img
->vmargin
= XFASTINT (XCDR (margin
));
9227 relief
= image_spec_value (spec
, QCrelief
, NULL
);
9228 if (INTEGERP (relief
))
9230 img
->relief
= XINT (relief
);
9231 img
->hmargin
+= abs (img
->relief
);
9232 img
->vmargin
+= abs (img
->relief
);
9235 if (! img
->background_valid
)
9237 bg
= image_spec_value (img
->spec
, QCbackground
, NULL
);
9241 = x_alloc_image_color (f
, img
, bg
,
9242 FRAME_BACKGROUND_PIXEL (f
));
9243 img
->background_valid
= 1;
9247 /* Do image transformations and compute masks, unless we
9248 don't have the image yet. */
9249 if (!EQ (*img
->type
->type
, Qpostscript
))
9250 postprocess_image (f
, img
);
9254 xassert (!interrupt_input_blocked
);
9257 /* We're using IMG, so set its timestamp to `now'. */
9258 EMACS_GET_TIME (now
);
9259 img
->timestamp
= EMACS_SECS (now
);
9263 /* Value is the image id. */
9268 /* Cache image IMG in the image cache of frame F. */
9271 cache_image (f
, img
)
9275 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
9278 /* Find a free slot in c->images. */
9279 for (i
= 0; i
< c
->used
; ++i
)
9280 if (c
->images
[i
] == NULL
)
9283 /* If no free slot found, maybe enlarge c->images. */
9284 if (i
== c
->used
&& c
->used
== c
->size
)
9287 c
->images
= (struct image
**) xrealloc (c
->images
,
9288 c
->size
* sizeof *c
->images
);
9291 /* Add IMG to c->images, and assign IMG an id. */
9297 /* Add IMG to the cache's hash table. */
9298 i
= img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
;
9299 img
->next
= c
->buckets
[i
];
9301 img
->next
->prev
= img
;
9303 c
->buckets
[i
] = img
;
9307 /* Call FN on every image in the image cache of frame F. Used to mark
9308 Lisp Objects in the image cache. */
9311 forall_images_in_image_cache (f
, fn
)
9313 void (*fn
) P_ ((struct image
*img
));
9315 if (FRAME_LIVE_P (f
) && FRAME_W32_P (f
))
9317 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
9321 for (i
= 0; i
< c
->used
; ++i
)
9330 /***********************************************************************
9332 ***********************************************************************/
9334 static int x_create_x_image_and_pixmap
P_ ((struct frame
*, int, int, int,
9335 XImage
**, Pixmap
*));
9336 static void x_destroy_x_image
P_ ((XImage
*));
9337 static void x_put_x_image
P_ ((struct frame
*, XImage
*, Pixmap
, int, int));
9340 /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on
9341 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
9342 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
9343 via xmalloc. DEPTH of zero signifies a 24 bit image, otherwise
9344 DEPTH should indicate the bit depth of the image. Print error
9345 messages via image_error if an error occurs. Value is non-zero if
9349 x_create_x_image_and_pixmap (f
, width
, height
, depth
, ximg
, pixmap
)
9351 int width
, height
, depth
;
9355 BITMAPINFOHEADER
*header
;
9357 int scanline_width_bits
;
9359 int palette_colors
= 0;
9364 if (depth
!= 1 && depth
!= 4 && depth
!= 8
9365 && depth
!= 16 && depth
!= 24 && depth
!= 32)
9367 image_error ("Invalid image bit depth specified", Qnil
, Qnil
);
9371 scanline_width_bits
= width
* depth
;
9372 remainder
= scanline_width_bits
% 32;
9375 scanline_width_bits
+= 32 - remainder
;
9377 /* Bitmaps with a depth less than 16 need a palette. */
9378 /* BITMAPINFO structure already contains the first RGBQUAD. */
9380 palette_colors
= 1 << depth
- 1;
9382 *ximg
= xmalloc (sizeof (XImage
) + palette_colors
* sizeof (RGBQUAD
));
9385 image_error ("Unable to allocate memory for XImage", Qnil
, Qnil
);
9389 header
= &((*ximg
)->info
.bmiHeader
);
9390 bzero (&((*ximg
)->info
), sizeof (BITMAPINFO
));
9391 header
->biSize
= sizeof (*header
);
9392 header
->biWidth
= width
;
9393 header
->biHeight
= -height
; /* negative indicates a top-down bitmap. */
9394 header
->biPlanes
= 1;
9395 header
->biBitCount
= depth
;
9396 header
->biCompression
= BI_RGB
;
9397 header
->biClrUsed
= palette_colors
;
9399 hdc
= get_frame_dc (f
);
9401 /* Create a DIBSection and raster array for the bitmap,
9402 and store its handle in *pixmap. */
9403 *pixmap
= CreateDIBSection (hdc
, &((*ximg
)->info
), DIB_RGB_COLORS
,
9404 &((*ximg
)->data
), NULL
, 0);
9406 /* Realize display palette and garbage all frames. */
9407 release_frame_dc (f
, hdc
);
9409 if (*pixmap
== NULL
)
9411 DWORD err
= GetLastError();
9412 Lisp_Object errcode
;
9413 /* All system errors are < 10000, so the following is safe. */
9414 XSETINT (errcode
, (int) err
);
9415 image_error ("Unable to create bitmap, error code %d", errcode
, Qnil
);
9416 x_destroy_x_image (*ximg
);
9424 /* Destroy XImage XIMG. Free XIMG->data. */
9427 x_destroy_x_image (ximg
)
9430 xassert (interrupt_input_blocked
);
9433 /* Data will be freed by DestroyObject. */
9440 /* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT
9441 are width and height of both the image and pixmap. */
9444 x_put_x_image (f
, ximg
, pixmap
, width
, height
)
9450 #if TODO /* W32 specific image code. */
9453 xassert (interrupt_input_blocked
);
9454 gc
= XCreateGC (NULL
, pixmap
, 0, NULL
);
9455 XPutImage (NULL
, pixmap
, gc
, ximg
, 0, 0, 0, 0, width
, height
);
9461 /***********************************************************************
9463 ***********************************************************************/
9465 static Lisp_Object x_find_image_file
P_ ((Lisp_Object
));
9466 static char *slurp_file
P_ ((char *, int *));
9469 /* Find image file FILE. Look in data-directory, then
9470 x-bitmap-file-path. Value is the full name of the file found, or
9471 nil if not found. */
9474 x_find_image_file (file
)
9477 Lisp_Object file_found
, search_path
;
9478 struct gcpro gcpro1
, gcpro2
;
9482 search_path
= Fcons (Vdata_directory
, Vx_bitmap_file_path
);
9483 GCPRO2 (file_found
, search_path
);
9485 /* Try to find FILE in data-directory, then x-bitmap-file-path. */
9486 fd
= openp (search_path
, file
, Qnil
, &file_found
, Qnil
);
9498 /* Read FILE into memory. Value is a pointer to a buffer allocated
9499 with xmalloc holding FILE's contents. Value is null if an error
9500 occurred. *SIZE is set to the size of the file. */
9503 slurp_file (file
, size
)
9511 if (stat (file
, &st
) == 0
9512 && (fp
= fopen (file
, "r")) != NULL
9513 && (buf
= (char *) xmalloc (st
.st_size
),
9514 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
9535 /***********************************************************************
9537 ***********************************************************************/
9539 static int xbm_scan
P_ ((char **, char *, char *, int *));
9540 static int xbm_load
P_ ((struct frame
*f
, struct image
*img
));
9541 static int xbm_load_image
P_ ((struct frame
*f
, struct image
*img
,
9543 static int xbm_image_p
P_ ((Lisp_Object object
));
9544 static int xbm_read_bitmap_data
P_ ((char *, char *, int *, int *,
9546 static int xbm_file_p
P_ ((Lisp_Object
));
9549 /* Indices of image specification fields in xbm_format, below. */
9551 enum xbm_keyword_index
9569 /* Vector of image_keyword structures describing the format
9570 of valid XBM image specifications. */
9572 static struct image_keyword xbm_format
[XBM_LAST
] =
9574 {":type", IMAGE_SYMBOL_VALUE
, 1},
9575 {":file", IMAGE_STRING_VALUE
, 0},
9576 {":width", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9577 {":height", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
9578 {":data", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9579 {":foreground", IMAGE_STRING_OR_NIL_VALUE
, 0},
9580 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0},
9581 {":ascent", IMAGE_ASCENT_VALUE
, 0},
9582 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
9583 {":relief", IMAGE_INTEGER_VALUE
, 0},
9584 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9585 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9586 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9589 /* Structure describing the image type XBM. */
9591 static struct image_type xbm_type
=
9600 /* Tokens returned from xbm_scan. */
9609 /* Return non-zero if OBJECT is a valid XBM-type image specification.
9610 A valid specification is a list starting with the symbol `image'
9611 The rest of the list is a property list which must contain an
9614 If the specification specifies a file to load, it must contain
9615 an entry `:file FILENAME' where FILENAME is a string.
9617 If the specification is for a bitmap loaded from memory it must
9618 contain `:width WIDTH', `:height HEIGHT', and `:data DATA', where
9619 WIDTH and HEIGHT are integers > 0. DATA may be:
9621 1. a string large enough to hold the bitmap data, i.e. it must
9622 have a size >= (WIDTH + 7) / 8 * HEIGHT
9624 2. a bool-vector of size >= WIDTH * HEIGHT
9626 3. a vector of strings or bool-vectors, one for each line of the
9629 4. A string containing an in-memory XBM file. WIDTH and HEIGHT
9630 may not be specified in this case because they are defined in the
9633 Both the file and data forms may contain the additional entries
9634 `:background COLOR' and `:foreground COLOR'. If not present,
9635 foreground and background of the frame on which the image is
9636 displayed is used. */
9639 xbm_image_p (object
)
9642 struct image_keyword kw
[XBM_LAST
];
9644 bcopy (xbm_format
, kw
, sizeof kw
);
9645 if (!parse_image_spec (object
, kw
, XBM_LAST
, Qxbm
))
9648 xassert (EQ (kw
[XBM_TYPE
].value
, Qxbm
));
9650 if (kw
[XBM_FILE
].count
)
9652 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_DATA
].count
)
9655 else if (kw
[XBM_DATA
].count
&& xbm_file_p (kw
[XBM_DATA
].value
))
9657 /* In-memory XBM file. */
9658 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_FILE
].count
)
9666 /* Entries for `:width', `:height' and `:data' must be present. */
9667 if (!kw
[XBM_WIDTH
].count
9668 || !kw
[XBM_HEIGHT
].count
9669 || !kw
[XBM_DATA
].count
)
9672 data
= kw
[XBM_DATA
].value
;
9673 width
= XFASTINT (kw
[XBM_WIDTH
].value
);
9674 height
= XFASTINT (kw
[XBM_HEIGHT
].value
);
9676 /* Check type of data, and width and height against contents of
9682 /* Number of elements of the vector must be >= height. */
9683 if (XVECTOR (data
)->size
< height
)
9686 /* Each string or bool-vector in data must be large enough
9687 for one line of the image. */
9688 for (i
= 0; i
< height
; ++i
)
9690 Lisp_Object elt
= XVECTOR (data
)->contents
[i
];
9694 if (XSTRING (elt
)->size
9695 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
)
9698 else if (BOOL_VECTOR_P (elt
))
9700 if (XBOOL_VECTOR (elt
)->size
< width
)
9707 else if (STRINGP (data
))
9709 if (XSTRING (data
)->size
9710 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
* height
)
9713 else if (BOOL_VECTOR_P (data
))
9715 if (XBOOL_VECTOR (data
)->size
< width
* height
)
9726 /* Scan a bitmap file. FP is the stream to read from. Value is
9727 either an enumerator from enum xbm_token, or a character for a
9728 single-character token, or 0 at end of file. If scanning an
9729 identifier, store the lexeme of the identifier in SVAL. If
9730 scanning a number, store its value in *IVAL. */
9733 xbm_scan (s
, end
, sval
, ival
)
9742 /* Skip white space. */
9743 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
9748 else if (isdigit (c
))
9750 int value
= 0, digit
;
9752 if (c
== '0' && *s
< end
)
9755 if (c
== 'x' || c
== 'X')
9762 else if (c
>= 'a' && c
<= 'f')
9763 digit
= c
- 'a' + 10;
9764 else if (c
>= 'A' && c
<= 'F')
9765 digit
= c
- 'A' + 10;
9768 value
= 16 * value
+ digit
;
9771 else if (isdigit (c
))
9775 && (c
= *(*s
)++, isdigit (c
)))
9776 value
= 8 * value
+ c
- '0';
9783 && (c
= *(*s
)++, isdigit (c
)))
9784 value
= 10 * value
+ c
- '0';
9792 else if (isalpha (c
) || c
== '_')
9796 && (c
= *(*s
)++, (isalnum (c
) || c
== '_')))
9803 else if (c
== '/' && **s
== '*')
9805 /* C-style comment. */
9807 while (**s
&& (**s
!= '*' || *(*s
+ 1) != '/'))
9820 /* XBM bits seem to be backward within bytes compared with how
9821 Windows does things. */
9822 static unsigned char reflect_byte (unsigned char orig
)
9825 unsigned char reflected
= 0x00;
9826 for (i
= 0; i
< 8; i
++)
9828 if (orig
& (0x01 << i
))
9829 reflected
|= 0x80 >> i
;
9835 /* Create a Windows bitmap from X bitmap data. */
9837 w32_create_pixmap_from_bitmap_data (int width
, int height
, char *data
)
9843 w1
= (width
+ 7) / 8; /* nb of 8bits elt in X bitmap */
9844 w2
= ((width
+ 15) / 16) * 2; /* nb of 16bits elt in W32 bitmap */
9845 bits
= (char *) xmalloc (height
* w2
);
9846 bzero (bits
, height
* w2
);
9847 for (i
= 0; i
< height
; i
++)
9850 for (j
= 0; j
< w1
; j
++)
9851 *p
++ = reflect_byte(*data
++);
9853 bmp
= CreateBitmap (width
, height
, 1, 1, bits
);
9860 /* Replacement for XReadBitmapFileData which isn't available under old
9861 X versions. CONTENTS is a pointer to a buffer to parse; END is the
9862 buffer's end. Set *WIDTH and *HEIGHT to the width and height of
9863 the image. Return in *DATA the bitmap data allocated with xmalloc.
9864 Value is non-zero if successful. DATA null means just test if
9865 CONTENTS looks like an in-memory XBM file. */
9868 xbm_read_bitmap_data (contents
, end
, width
, height
, data
)
9869 char *contents
, *end
;
9870 int *width
, *height
;
9871 unsigned char **data
;
9874 char buffer
[BUFSIZ
];
9877 int bytes_per_line
, i
, nbytes
;
9883 LA1 = xbm_scan (&s, end, buffer, &value)
9885 #define expect(TOKEN) \
9886 if (LA1 != (TOKEN)) \
9891 #define expect_ident(IDENT) \
9892 if (LA1 == XBM_TK_IDENT && strcmp (buffer, (IDENT)) == 0) \
9897 *width
= *height
= -1;
9900 LA1
= xbm_scan (&s
, end
, buffer
, &value
);
9902 /* Parse defines for width, height and hot-spots. */
9906 expect_ident ("define");
9907 expect (XBM_TK_IDENT
);
9909 if (LA1
== XBM_TK_NUMBER
);
9911 char *p
= strrchr (buffer
, '_');
9912 p
= p
? p
+ 1 : buffer
;
9913 if (strcmp (p
, "width") == 0)
9915 else if (strcmp (p
, "height") == 0)
9918 expect (XBM_TK_NUMBER
);
9921 if (*width
< 0 || *height
< 0)
9923 else if (data
== NULL
)
9926 /* Parse bits. Must start with `static'. */
9927 expect_ident ("static");
9928 if (LA1
== XBM_TK_IDENT
)
9930 if (strcmp (buffer
, "unsigned") == 0)
9933 expect_ident ("char");
9935 else if (strcmp (buffer
, "short") == 0)
9939 if (*width
% 16 && *width
% 16 < 9)
9942 else if (strcmp (buffer
, "char") == 0)
9950 expect (XBM_TK_IDENT
);
9956 bytes_per_line
= (*width
+ 7) / 8 + padding_p
;
9957 nbytes
= bytes_per_line
* *height
;
9958 p
= *data
= (char *) xmalloc (nbytes
);
9962 for (i
= 0; i
< nbytes
; i
+= 2)
9965 expect (XBM_TK_NUMBER
);
9968 if (!padding_p
|| ((i
+ 2) % bytes_per_line
))
9971 if (LA1
== ',' || LA1
== '}')
9979 for (i
= 0; i
< nbytes
; ++i
)
9982 expect (XBM_TK_NUMBER
);
9986 if (LA1
== ',' || LA1
== '}')
10007 #undef expect_ident
10011 /* Load XBM image IMG which will be displayed on frame F from buffer
10012 CONTENTS. END is the end of the buffer. Value is non-zero if
10016 xbm_load_image (f
, img
, contents
, end
)
10019 char *contents
, *end
;
10022 unsigned char *data
;
10025 rc
= xbm_read_bitmap_data (contents
, end
, &img
->width
, &img
->height
, &data
);
10028 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
10029 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
10032 xassert (img
->width
> 0 && img
->height
> 0);
10034 /* Get foreground and background colors, maybe allocate colors. */
10035 value
= image_spec_value (img
->spec
, QCforeground
, NULL
);
10037 foreground
= x_alloc_image_color (f
, img
, value
, foreground
);
10038 value
= image_spec_value (img
->spec
, QCbackground
, NULL
);
10041 background
= x_alloc_image_color (f
, img
, value
, background
);
10042 img
->background
= background
;
10043 img
->background_valid
= 1;
10046 = w32_create_pixmap_from_bitmap_data (img
->width
, img
->height
, data
);
10050 if (img
->pixmap
== 0)
10052 x_clear_image (f
, img
);
10053 image_error ("Unable to create X pixmap for `%s'", img
->spec
, Qnil
);
10059 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
10065 /* Value is non-zero if DATA looks like an in-memory XBM file. */
10072 return (STRINGP (data
)
10073 && xbm_read_bitmap_data (XSTRING (data
)->data
,
10074 (XSTRING (data
)->data
10075 + STRING_BYTES (XSTRING (data
))),
10080 /* Fill image IMG which is used on frame F with pixmap data. Value is
10081 non-zero if successful. */
10089 Lisp_Object file_name
;
10091 xassert (xbm_image_p (img
->spec
));
10093 /* If IMG->spec specifies a file name, create a non-file spec from it. */
10094 file_name
= image_spec_value (img
->spec
, QCfile
, NULL
);
10095 if (STRINGP (file_name
))
10100 struct gcpro gcpro1
;
10102 file
= x_find_image_file (file_name
);
10104 if (!STRINGP (file
))
10106 image_error ("Cannot find image file `%s'", file_name
, Qnil
);
10111 contents
= slurp_file (XSTRING (file
)->data
, &size
);
10112 if (contents
== NULL
)
10114 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
10119 success_p
= xbm_load_image (f
, img
, contents
, contents
+ size
);
10124 struct image_keyword fmt
[XBM_LAST
];
10127 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
10128 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
10131 int in_memory_file_p
= 0;
10133 /* See if data looks like an in-memory XBM file. */
10134 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10135 in_memory_file_p
= xbm_file_p (data
);
10137 /* Parse the image specification. */
10138 bcopy (xbm_format
, fmt
, sizeof fmt
);
10139 parsed_p
= parse_image_spec (img
->spec
, fmt
, XBM_LAST
, Qxbm
);
10140 xassert (parsed_p
);
10142 /* Get specified width, and height. */
10143 if (!in_memory_file_p
)
10145 img
->width
= XFASTINT (fmt
[XBM_WIDTH
].value
);
10146 img
->height
= XFASTINT (fmt
[XBM_HEIGHT
].value
);
10147 xassert (img
->width
> 0 && img
->height
> 0);
10150 /* Get foreground and background colors, maybe allocate colors. */
10151 if (fmt
[XBM_FOREGROUND
].count
10152 && STRINGP (fmt
[XBM_FOREGROUND
].value
))
10153 foreground
= x_alloc_image_color (f
, img
, fmt
[XBM_FOREGROUND
].value
,
10155 if (fmt
[XBM_BACKGROUND
].count
10156 && STRINGP (fmt
[XBM_BACKGROUND
].value
))
10157 background
= x_alloc_image_color (f
, img
, fmt
[XBM_BACKGROUND
].value
,
10160 if (in_memory_file_p
)
10161 success_p
= xbm_load_image (f
, img
, XSTRING (data
)->data
,
10162 (XSTRING (data
)->data
10163 + STRING_BYTES (XSTRING (data
))));
10166 if (VECTORP (data
))
10170 int nbytes
= (img
->width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
;
10172 p
= bits
= (char *) alloca (nbytes
* img
->height
);
10173 for (i
= 0; i
< img
->height
; ++i
, p
+= nbytes
)
10175 Lisp_Object line
= XVECTOR (data
)->contents
[i
];
10176 if (STRINGP (line
))
10177 bcopy (XSTRING (line
)->data
, p
, nbytes
);
10179 bcopy (XBOOL_VECTOR (line
)->data
, p
, nbytes
);
10182 else if (STRINGP (data
))
10183 bits
= XSTRING (data
)->data
;
10185 bits
= XBOOL_VECTOR (data
)->data
;
10187 /* Create the pixmap. */
10188 depth
= one_w32_display_info
.n_cbits
;
10190 = w32_create_pixmap_from_bitmap_data (img
->width
, img
->height
,
10197 image_error ("Unable to create pixmap for XBM image `%s'",
10199 x_clear_image (f
, img
);
10209 /***********************************************************************
10211 ***********************************************************************/
10215 static int xpm_image_p
P_ ((Lisp_Object object
));
10216 static int xpm_load
P_ ((struct frame
*f
, struct image
*img
));
10217 static int xpm_valid_color_symbols_p
P_ ((Lisp_Object
));
10219 #include "X11/xpm.h"
10221 /* The symbol `xpm' identifying XPM-format images. */
10225 /* Indices of image specification fields in xpm_format, below. */
10227 enum xpm_keyword_index
10236 XPM_HEURISTIC_MASK
,
10243 /* Vector of image_keyword structures describing the format
10244 of valid XPM image specifications. */
10246 static struct image_keyword xpm_format
[XPM_LAST
] =
10248 {":type", IMAGE_SYMBOL_VALUE
, 1},
10249 {":file", IMAGE_STRING_VALUE
, 0},
10250 {":data", IMAGE_STRING_VALUE
, 0},
10251 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10252 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
10253 {":relief", IMAGE_INTEGER_VALUE
, 0},
10254 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10255 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10256 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10257 {":color-symbols", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10258 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
10261 /* Structure describing the image type XBM. */
10263 static struct image_type xpm_type
=
10273 /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
10274 for XPM images. Such a list must consist of conses whose car and
10275 cdr are strings. */
10278 xpm_valid_color_symbols_p (color_symbols
)
10279 Lisp_Object color_symbols
;
10281 while (CONSP (color_symbols
))
10283 Lisp_Object sym
= XCAR (color_symbols
);
10285 || !STRINGP (XCAR (sym
))
10286 || !STRINGP (XCDR (sym
)))
10288 color_symbols
= XCDR (color_symbols
);
10291 return NILP (color_symbols
);
10295 /* Value is non-zero if OBJECT is a valid XPM image specification. */
10298 xpm_image_p (object
)
10299 Lisp_Object object
;
10301 struct image_keyword fmt
[XPM_LAST
];
10302 bcopy (xpm_format
, fmt
, sizeof fmt
);
10303 return (parse_image_spec (object
, fmt
, XPM_LAST
, Qxpm
)
10304 /* Either `:file' or `:data' must be present. */
10305 && fmt
[XPM_FILE
].count
+ fmt
[XPM_DATA
].count
== 1
10306 /* Either no `:color-symbols' or it's a list of conses
10307 whose car and cdr are strings. */
10308 && (fmt
[XPM_COLOR_SYMBOLS
].count
== 0
10309 || xpm_valid_color_symbols_p (fmt
[XPM_COLOR_SYMBOLS
].value
))
10310 && (fmt
[XPM_ASCENT
].count
== 0
10311 || XFASTINT (fmt
[XPM_ASCENT
].value
) < 100));
10315 /* Load image IMG which will be displayed on frame F. Value is
10316 non-zero if successful. */
10324 XpmAttributes attrs
;
10325 Lisp_Object specified_file
, color_symbols
;
10327 /* Configure the XPM lib. Use the visual of frame F. Allocate
10328 close colors. Return colors allocated. */
10329 bzero (&attrs
, sizeof attrs
);
10330 attrs
.visual
= FRAME_X_VISUAL (f
);
10331 attrs
.colormap
= FRAME_X_COLORMAP (f
);
10332 attrs
.valuemask
|= XpmVisual
;
10333 attrs
.valuemask
|= XpmColormap
;
10334 attrs
.valuemask
|= XpmReturnAllocPixels
;
10335 #ifdef XpmAllocCloseColors
10336 attrs
.alloc_close_colors
= 1;
10337 attrs
.valuemask
|= XpmAllocCloseColors
;
10339 attrs
.closeness
= 600;
10340 attrs
.valuemask
|= XpmCloseness
;
10343 /* If image specification contains symbolic color definitions, add
10344 these to `attrs'. */
10345 color_symbols
= image_spec_value (img
->spec
, QCcolor_symbols
, NULL
);
10346 if (CONSP (color_symbols
))
10349 XpmColorSymbol
*xpm_syms
;
10352 attrs
.valuemask
|= XpmColorSymbols
;
10354 /* Count number of symbols. */
10355 attrs
.numsymbols
= 0;
10356 for (tail
= color_symbols
; CONSP (tail
); tail
= XCDR (tail
))
10357 ++attrs
.numsymbols
;
10359 /* Allocate an XpmColorSymbol array. */
10360 size
= attrs
.numsymbols
* sizeof *xpm_syms
;
10361 xpm_syms
= (XpmColorSymbol
*) alloca (size
);
10362 bzero (xpm_syms
, size
);
10363 attrs
.colorsymbols
= xpm_syms
;
10365 /* Fill the color symbol array. */
10366 for (tail
= color_symbols
, i
= 0;
10368 ++i
, tail
= XCDR (tail
))
10370 Lisp_Object name
= XCAR (XCAR (tail
));
10371 Lisp_Object color
= XCDR (XCAR (tail
));
10372 xpm_syms
[i
].name
= (char *) alloca (XSTRING (name
)->size
+ 1);
10373 strcpy (xpm_syms
[i
].name
, XSTRING (name
)->data
);
10374 xpm_syms
[i
].value
= (char *) alloca (XSTRING (color
)->size
+ 1);
10375 strcpy (xpm_syms
[i
].value
, XSTRING (color
)->data
);
10379 /* Create a pixmap for the image, either from a file, or from a
10380 string buffer containing data in the same format as an XPM file. */
10382 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10383 if (STRINGP (specified_file
))
10385 Lisp_Object file
= x_find_image_file (specified_file
);
10386 if (!STRINGP (file
))
10388 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10393 rc
= XpmReadFileToPixmap (NULL
, FRAME_W32_WINDOW (f
),
10394 XSTRING (file
)->data
, &img
->pixmap
, &img
->mask
,
10399 Lisp_Object buffer
= image_spec_value (img
->spec
, QCdata
, NULL
);
10400 rc
= XpmCreatePixmapFromBuffer (NULL
, FRAME_W32_WINDOW (f
),
10401 XSTRING (buffer
)->data
,
10402 &img
->pixmap
, &img
->mask
,
10407 if (rc
== XpmSuccess
)
10409 /* Remember allocated colors. */
10410 img
->ncolors
= attrs
.nalloc_pixels
;
10411 img
->colors
= (unsigned long *) xmalloc (img
->ncolors
10412 * sizeof *img
->colors
);
10413 for (i
= 0; i
< attrs
.nalloc_pixels
; ++i
)
10414 img
->colors
[i
] = attrs
.alloc_pixels
[i
];
10416 img
->width
= attrs
.width
;
10417 img
->height
= attrs
.height
;
10418 xassert (img
->width
> 0 && img
->height
> 0);
10420 /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */
10422 XpmFreeAttributes (&attrs
);
10429 case XpmOpenFailed
:
10430 image_error ("Error opening XPM file (%s)", img
->spec
, Qnil
);
10433 case XpmFileInvalid
:
10434 image_error ("Invalid XPM file (%s)", img
->spec
, Qnil
);
10438 image_error ("Out of memory (%s)", img
->spec
, Qnil
);
10441 case XpmColorFailed
:
10442 image_error ("Color allocation error (%s)", img
->spec
, Qnil
);
10446 image_error ("Unknown error (%s)", img
->spec
, Qnil
);
10451 return rc
== XpmSuccess
;
10454 #endif /* HAVE_XPM != 0 */
10457 #if 0 /* TODO : Color tables on W32. */
10458 /***********************************************************************
10460 ***********************************************************************/
10462 /* An entry in the color table mapping an RGB color to a pixel color. */
10467 unsigned long pixel
;
10469 /* Next in color table collision list. */
10470 struct ct_color
*next
;
10473 /* The bucket vector size to use. Must be prime. */
10475 #define CT_SIZE 101
10477 /* Value is a hash of the RGB color given by R, G, and B. */
10479 #define CT_HASH_RGB(R, G, B) (((R) << 16) ^ ((G) << 8) ^ (B))
10481 /* The color hash table. */
10483 struct ct_color
**ct_table
;
10485 /* Number of entries in the color table. */
10487 int ct_colors_allocated
;
10489 /* Function prototypes. */
10491 static void init_color_table
P_ ((void));
10492 static void free_color_table
P_ ((void));
10493 static unsigned long *colors_in_color_table
P_ ((int *n
));
10494 static unsigned long lookup_rgb_color
P_ ((struct frame
*f
, int r
, int g
, int b
));
10495 static unsigned long lookup_pixel_color
P_ ((struct frame
*f
, unsigned long p
));
10498 /* Initialize the color table. */
10501 init_color_table ()
10503 int size
= CT_SIZE
* sizeof (*ct_table
);
10504 ct_table
= (struct ct_color
**) xmalloc (size
);
10505 bzero (ct_table
, size
);
10506 ct_colors_allocated
= 0;
10510 /* Free memory associated with the color table. */
10513 free_color_table ()
10516 struct ct_color
*p
, *next
;
10518 for (i
= 0; i
< CT_SIZE
; ++i
)
10519 for (p
= ct_table
[i
]; p
; p
= next
)
10530 /* Value is a pixel color for RGB color R, G, B on frame F. If an
10531 entry for that color already is in the color table, return the
10532 pixel color of that entry. Otherwise, allocate a new color for R,
10533 G, B, and make an entry in the color table. */
10535 static unsigned long
10536 lookup_rgb_color (f
, r
, g
, b
)
10540 unsigned hash
= CT_HASH_RGB (r
, g
, b
);
10541 int i
= hash
% CT_SIZE
;
10542 struct ct_color
*p
;
10544 for (p
= ct_table
[i
]; p
; p
= p
->next
)
10545 if (p
->r
== r
&& p
->g
== g
&& p
->b
== b
)
10554 color
= PALETTERGB (r
, g
, b
);
10556 ++ct_colors_allocated
;
10558 p
= (struct ct_color
*) xmalloc (sizeof *p
);
10563 p
->next
= ct_table
[i
];
10571 /* Look up pixel color PIXEL which is used on frame F in the color
10572 table. If not already present, allocate it. Value is PIXEL. */
10574 static unsigned long
10575 lookup_pixel_color (f
, pixel
)
10577 unsigned long pixel
;
10579 int i
= pixel
% CT_SIZE
;
10580 struct ct_color
*p
;
10582 for (p
= ct_table
[i
]; p
; p
= p
->next
)
10583 if (p
->pixel
== pixel
)
10594 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
10595 color
.pixel
= pixel
;
10596 XQueryColor (NULL
, cmap
, &color
);
10597 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
10602 ++ct_colors_allocated
;
10604 p
= (struct ct_color
*) xmalloc (sizeof *p
);
10606 p
->g
= color
.green
;
10609 p
->next
= ct_table
[i
];
10613 return FRAME_FOREGROUND_PIXEL (f
);
10619 /* Value is a vector of all pixel colors contained in the color table,
10620 allocated via xmalloc. Set *N to the number of colors. */
10622 static unsigned long *
10623 colors_in_color_table (n
)
10627 struct ct_color
*p
;
10628 unsigned long *colors
;
10630 if (ct_colors_allocated
== 0)
10637 colors
= (unsigned long *) xmalloc (ct_colors_allocated
10639 *n
= ct_colors_allocated
;
10641 for (i
= j
= 0; i
< CT_SIZE
; ++i
)
10642 for (p
= ct_table
[i
]; p
; p
= p
->next
)
10643 colors
[j
++] = p
->pixel
;
10652 /***********************************************************************
10654 ***********************************************************************/
10655 static XColor
*x_to_xcolors
P_ ((struct frame
*, struct image
*, int));
10656 static void x_from_xcolors
P_ ((struct frame
*, struct image
*, XColor
*));
10657 static void x_detect_edges
P_ ((struct frame
*, struct image
*, int[9], int));
10658 static void XPutPixel (XImage
*, int, int, COLORREF
);
10660 /* Non-zero means draw a cross on images having `:conversion
10663 int cross_disabled_images
;
10665 /* Edge detection matrices for different edge-detection
10668 static int emboss_matrix
[9] = {
10669 /* x - 1 x x + 1 */
10670 2, -1, 0, /* y - 1 */
10672 0, 1, -2 /* y + 1 */
10675 static int laplace_matrix
[9] = {
10676 /* x - 1 x x + 1 */
10677 1, 0, 0, /* y - 1 */
10679 0, 0, -1 /* y + 1 */
10682 /* Value is the intensity of the color whose red/green/blue values
10683 are R, G, and B. */
10685 #define COLOR_INTENSITY(R, G, B) ((2 * (R) + 3 * (G) + (B)) / 6)
10688 /* On frame F, return an array of XColor structures describing image
10689 IMG->pixmap. Each XColor structure has its pixel color set. RGB_P
10690 non-zero means also fill the red/green/blue members of the XColor
10691 structures. Value is a pointer to the array of XColors structures,
10692 allocated with xmalloc; it must be freed by the caller. */
10695 x_to_xcolors (f
, img
, rgb_p
)
10701 XColor
*colors
, *p
;
10704 colors
= (XColor
*) xmalloc (img
->width
* img
->height
* sizeof *colors
);
10705 #if 0 /* TODO: implement image colors. */
10706 /* Get the X image IMG->pixmap. */
10707 ximg
= XGetImage (FRAME_X_DISPLAY (f
), img
->pixmap
,
10708 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
10710 /* Fill the `pixel' members of the XColor array. I wished there
10711 were an easy and portable way to circumvent XGetPixel. */
10713 for (y
= 0; y
< img
->height
; ++y
)
10717 for (x
= 0; x
< img
->width
; ++x
, ++p
)
10718 p
->pixel
= XGetPixel (ximg
, x
, y
);
10721 x_query_colors (f
, row
, img
->width
);
10724 XDestroyImage (ximg
);
10729 /* Put a pixel of COLOR at position X, Y in XIMG. XIMG must have been
10730 created with CreateDIBSection, with the pointer to the bit values
10731 stored in ximg->data. */
10733 static void XPutPixel (ximg
, x
, y
, color
)
10738 int width
= ximg
->info
.bmiHeader
.biWidth
;
10739 int height
= ximg
->info
.bmiHeader
.biHeight
;
10740 int rowbytes
= width
* 3;
10741 unsigned char * pixel
;
10743 /* Don't support putting pixels in images with palettes. */
10744 xassert (ximg
->info
.bmiHeader
.biBitCount
== 24);
10746 /* Ensure scanlines are aligned on 4 byte boundaries. */
10748 rowbytes
+= 4 - (rowbytes
% 4);
10750 pixel
= ximg
->data
+ y
* rowbytes
+ x
* 3;
10751 *pixel
= 255 - GetRValue (color
);
10752 *(pixel
+ 1) = 255 - GetGValue (color
);
10753 *(pixel
+ 2) = 255 - GetBValue (color
);
10757 /* Create IMG->pixmap from an array COLORS of XColor structures, whose
10758 RGB members are set. F is the frame on which this all happens.
10759 COLORS will be freed; an existing IMG->pixmap will be freed, too. */
10762 x_from_xcolors (f
, img
, colors
)
10771 #if 0 /* TODO: color tables. */
10772 init_color_table ();
10774 x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 0,
10777 for (y
= 0; y
< img
->height
; ++y
)
10778 for (x
= 0; x
< img
->width
; ++x
, ++p
)
10780 unsigned long pixel
;
10781 #if 0 /* TODO: color tables. */
10782 pixel
= lookup_rgb_color (f
, p
->red
, p
->green
, p
->blue
);
10784 pixel
= PALETTERGB (p
->red
, p
->green
, p
->blue
);
10786 XPutPixel (oimg
, x
, y
, pixel
);
10790 x_clear_image_1 (f
, img
, 1, 0, 1);
10792 x_put_x_image (f
, oimg
, pixmap
, img
->width
, img
->height
);
10793 x_destroy_x_image (oimg
);
10794 img
->pixmap
= pixmap
;
10795 #if 0 /* TODO: color tables. */
10796 img
->colors
= colors_in_color_table (&img
->ncolors
);
10797 free_color_table ();
10802 /* On frame F, perform edge-detection on image IMG.
10804 MATRIX is a nine-element array specifying the transformation
10805 matrix. See emboss_matrix for an example.
10807 COLOR_ADJUST is a color adjustment added to each pixel of the
10811 x_detect_edges (f
, img
, matrix
, color_adjust
)
10814 int matrix
[9], color_adjust
;
10816 XColor
*colors
= x_to_xcolors (f
, img
, 1);
10820 for (i
= sum
= 0; i
< 9; ++i
)
10821 sum
+= abs (matrix
[i
]);
10823 #define COLOR(A, X, Y) ((A) + (Y) * img->width + (X))
10825 new = (XColor
*) xmalloc (img
->width
* img
->height
* sizeof *new);
10827 for (y
= 0; y
< img
->height
; ++y
)
10829 p
= COLOR (new, 0, y
);
10830 p
->red
= p
->green
= p
->blue
= 0xffff/2;
10831 p
= COLOR (new, img
->width
- 1, y
);
10832 p
->red
= p
->green
= p
->blue
= 0xffff/2;
10835 for (x
= 1; x
< img
->width
- 1; ++x
)
10837 p
= COLOR (new, x
, 0);
10838 p
->red
= p
->green
= p
->blue
= 0xffff/2;
10839 p
= COLOR (new, x
, img
->height
- 1);
10840 p
->red
= p
->green
= p
->blue
= 0xffff/2;
10843 for (y
= 1; y
< img
->height
- 1; ++y
)
10845 p
= COLOR (new, 1, y
);
10847 for (x
= 1; x
< img
->width
- 1; ++x
, ++p
)
10849 int r
, g
, b
, y1
, x1
;
10852 for (y1
= y
- 1; y1
< y
+ 2; ++y1
)
10853 for (x1
= x
- 1; x1
< x
+ 2; ++x1
, ++i
)
10856 XColor
*t
= COLOR (colors
, x1
, y1
);
10857 r
+= matrix
[i
] * t
->red
;
10858 g
+= matrix
[i
] * t
->green
;
10859 b
+= matrix
[i
] * t
->blue
;
10862 r
= (r
/ sum
+ color_adjust
) & 0xffff;
10863 g
= (g
/ sum
+ color_adjust
) & 0xffff;
10864 b
= (b
/ sum
+ color_adjust
) & 0xffff;
10865 p
->red
= p
->green
= p
->blue
= COLOR_INTENSITY (r
, g
, b
);
10870 x_from_xcolors (f
, img
, new);
10876 /* Perform the pre-defined `emboss' edge-detection on image IMG
10884 x_detect_edges (f
, img
, emboss_matrix
, 0xffff / 2);
10888 /* Transform image IMG which is used on frame F with a Laplace
10889 edge-detection algorithm. The result is an image that can be used
10890 to draw disabled buttons, for example. */
10897 x_detect_edges (f
, img
, laplace_matrix
, 45000);
10901 /* Perform edge-detection on image IMG on frame F, with specified
10902 transformation matrix MATRIX and color-adjustment COLOR_ADJUST.
10904 MATRIX must be either
10906 - a list of at least 9 numbers in row-major form
10907 - a vector of at least 9 numbers
10909 COLOR_ADJUST nil means use a default; otherwise it must be a
10913 x_edge_detection (f
, img
, matrix
, color_adjust
)
10916 Lisp_Object matrix
, color_adjust
;
10921 if (CONSP (matrix
))
10924 i
< 9 && CONSP (matrix
) && NUMBERP (XCAR (matrix
));
10925 ++i
, matrix
= XCDR (matrix
))
10926 trans
[i
] = XFLOATINT (XCAR (matrix
));
10928 else if (VECTORP (matrix
) && ASIZE (matrix
) >= 9)
10930 for (i
= 0; i
< 9 && NUMBERP (AREF (matrix
, i
)); ++i
)
10931 trans
[i
] = XFLOATINT (AREF (matrix
, i
));
10934 if (NILP (color_adjust
))
10935 color_adjust
= make_number (0xffff / 2);
10937 if (i
== 9 && NUMBERP (color_adjust
))
10938 x_detect_edges (f
, img
, trans
, (int) XFLOATINT (color_adjust
));
10942 /* Transform image IMG on frame F so that it looks disabled. */
10945 x_disable_image (f
, img
)
10949 struct w32_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10951 if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
>= 2)
10953 /* Color (or grayscale). Convert to gray, and equalize. Just
10954 drawing such images with a stipple can look very odd, so
10955 we're using this method instead. */
10956 XColor
*colors
= x_to_xcolors (f
, img
, 1);
10958 const int h
= 15000;
10959 const int l
= 30000;
10961 for (p
= colors
, end
= colors
+ img
->width
* img
->height
;
10965 int i
= COLOR_INTENSITY (p
->red
, p
->green
, p
->blue
);
10966 int i2
= (0xffff - h
- l
) * i
/ 0xffff + l
;
10967 p
->red
= p
->green
= p
->blue
= i2
;
10970 x_from_xcolors (f
, img
, colors
);
10973 /* Draw a cross over the disabled image, if we must or if we
10975 if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
< 2 || cross_disabled_images
)
10977 #if 0 /* TODO: full image support */
10978 Display
*dpy
= FRAME_X_DISPLAY (f
);
10981 gc
= XCreateGC (dpy
, img
->pixmap
, 0, NULL
);
10982 XSetForeground (dpy
, gc
, BLACK_PIX_DEFAULT (f
));
10983 XDrawLine (dpy
, img
->pixmap
, gc
, 0, 0,
10984 img
->width
- 1, img
->height
- 1);
10985 XDrawLine (dpy
, img
->pixmap
, gc
, 0, img
->height
- 1,
10986 img
->width
- 1, 0);
10991 gc
= XCreateGC (dpy
, img
->mask
, 0, NULL
);
10992 XSetForeground (dpy
, gc
, WHITE_PIX_DEFAULT (f
));
10993 XDrawLine (dpy
, img
->mask
, gc
, 0, 0,
10994 img
->width
- 1, img
->height
- 1);
10995 XDrawLine (dpy
, img
->mask
, gc
, 0, img
->height
- 1,
10996 img
->width
- 1, 0);
11004 /* Build a mask for image IMG which is used on frame F. FILE is the
11005 name of an image file, for error messages. HOW determines how to
11006 determine the background color of IMG. If it is a list '(R G B)',
11007 with R, G, and B being integers >= 0, take that as the color of the
11008 background. Otherwise, determine the background color of IMG
11009 heuristically. Value is non-zero if successful. */
11012 x_build_heuristic_mask (f
, img
, how
)
11017 #if 0 /* TODO: full image support. */
11018 Display
*dpy
= FRAME_W32_DISPLAY (f
);
11019 XImage
*ximg
, *mask_img
;
11020 int x
, y
, rc
, use_img_background
;
11021 unsigned long bg
= 0;
11025 XFreePixmap (FRAME_X_DISPLAY (f
), img
->mask
);
11027 img
->background_transparent_valid
= 0;
11030 /* Create an image and pixmap serving as mask. */
11031 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 1,
11032 &mask_img
, &img
->mask
);
11036 /* Get the X image of IMG->pixmap. */
11037 ximg
= XGetImage (dpy
, img
->pixmap
, 0, 0, img
->width
, img
->height
,
11040 /* Determine the background color of ximg. If HOW is `(R G B)'
11041 take that as color. Otherwise, use the image's background color. */
11042 use_img_background
= 1;
11048 for (i
= 0; i
< 3 && CONSP (how
) && NATNUMP (XCAR (how
)); ++i
)
11050 rgb
[i
] = XFASTINT (XCAR (how
)) & 0xffff;
11054 if (i
== 3 && NILP (how
))
11056 char color_name
[30];
11057 sprintf (color_name
, "#%04x%04x%04x", rgb
[0], rgb
[1], rgb
[2]);
11058 bg
= x_alloc_image_color (f
, img
, build_string (color_name
), 0);
11059 use_img_background
= 0;
11063 if (use_img_background
)
11064 bg
= four_corners_best (ximg
, img
->width
, img
->height
);
11066 /* Set all bits in mask_img to 1 whose color in ximg is different
11067 from the background color bg. */
11068 for (y
= 0; y
< img
->height
; ++y
)
11069 for (x
= 0; x
< img
->width
; ++x
)
11070 XPutPixel (mask_img
, x
, y
, XGetPixel (ximg
, x
, y
) != bg
);
11072 /* Fill in the background_transparent field while we have the mask handy. */
11073 image_background_transparent (img
, f
, mask_img
);
11075 /* Put mask_img into img->mask. */
11076 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
11077 x_destroy_x_image (mask_img
);
11078 XDestroyImage (ximg
);
11087 /***********************************************************************
11088 PBM (mono, gray, color)
11089 ***********************************************************************/
11091 static int pbm_image_p
P_ ((Lisp_Object object
));
11092 static int pbm_load
P_ ((struct frame
*f
, struct image
*img
));
11093 static int pbm_scan_number
P_ ((unsigned char **, unsigned char *));
11095 /* The symbol `pbm' identifying images of this type. */
11099 /* Indices of image specification fields in gs_format, below. */
11101 enum pbm_keyword_index
11110 PBM_HEURISTIC_MASK
,
11117 /* Vector of image_keyword structures describing the format
11118 of valid user-defined image specifications. */
11120 static struct image_keyword pbm_format
[PBM_LAST
] =
11122 {":type", IMAGE_SYMBOL_VALUE
, 1},
11123 {":file", IMAGE_STRING_VALUE
, 0},
11124 {":data", IMAGE_STRING_VALUE
, 0},
11125 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11126 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
11127 {":relief", IMAGE_INTEGER_VALUE
, 0},
11128 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11129 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11130 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11131 {":foreground", IMAGE_STRING_OR_NIL_VALUE
, 0},
11132 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
11135 /* Structure describing the image type `pbm'. */
11137 static struct image_type pbm_type
=
11147 /* Return non-zero if OBJECT is a valid PBM image specification. */
11150 pbm_image_p (object
)
11151 Lisp_Object object
;
11153 struct image_keyword fmt
[PBM_LAST
];
11155 bcopy (pbm_format
, fmt
, sizeof fmt
);
11157 if (!parse_image_spec (object
, fmt
, PBM_LAST
, Qpbm
)
11158 || (fmt
[PBM_ASCENT
].count
11159 && XFASTINT (fmt
[PBM_ASCENT
].value
) > 100))
11162 /* Must specify either :data or :file. */
11163 return fmt
[PBM_DATA
].count
+ fmt
[PBM_FILE
].count
== 1;
11167 /* Scan a decimal number from *S and return it. Advance *S while
11168 reading the number. END is the end of the string. Value is -1 at
11172 pbm_scan_number (s
, end
)
11173 unsigned char **s
, *end
;
11179 /* Skip white-space. */
11180 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
11185 /* Skip comment to end of line. */
11186 while (*s
< end
&& (c
= *(*s
)++, c
!= '\n'))
11189 else if (isdigit (c
))
11191 /* Read decimal number. */
11193 while (*s
< end
&& (c
= *(*s
)++, isdigit (c
)))
11194 val
= 10 * val
+ c
- '0';
11205 /* Read FILE into memory. Value is a pointer to a buffer allocated
11206 with xmalloc holding FILE's contents. Value is null if an error
11207 occured. *SIZE is set to the size of the file. */
11210 pbm_read_file (file
, size
)
11218 if (stat (XSTRING (file
)->data
, &st
) == 0
11219 && (fp
= fopen (XSTRING (file
)->data
, "r")) != NULL
11220 && (buf
= (char *) xmalloc (st
.st_size
),
11221 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
11223 *size
= st
.st_size
;
11241 /* Load PBM image IMG for use on frame F. */
11249 int width
, height
, max_color_idx
= 0;
11251 Lisp_Object file
, specified_file
;
11252 enum {PBM_MONO
, PBM_GRAY
, PBM_COLOR
} type
;
11253 struct gcpro gcpro1
;
11254 unsigned char *contents
= NULL
;
11255 unsigned char *end
, *p
;
11258 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11262 if (STRINGP (specified_file
))
11264 file
= x_find_image_file (specified_file
);
11265 if (!STRINGP (file
))
11267 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
11272 contents
= slurp_file (XSTRING (file
)->data
, &size
);
11273 if (contents
== NULL
)
11275 image_error ("Error reading `%s'", file
, Qnil
);
11281 end
= contents
+ size
;
11286 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11287 p
= XSTRING (data
)->data
;
11288 end
= p
+ STRING_BYTES (XSTRING (data
));
11291 /* Check magic number. */
11292 if (end
- p
< 2 || *p
++ != 'P')
11294 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
11304 raw_p
= 0, type
= PBM_MONO
;
11308 raw_p
= 0, type
= PBM_GRAY
;
11312 raw_p
= 0, type
= PBM_COLOR
;
11316 raw_p
= 1, type
= PBM_MONO
;
11320 raw_p
= 1, type
= PBM_GRAY
;
11324 raw_p
= 1, type
= PBM_COLOR
;
11328 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
11332 /* Read width, height, maximum color-component. Characters
11333 starting with `#' up to the end of a line are ignored. */
11334 width
= pbm_scan_number (&p
, end
);
11335 height
= pbm_scan_number (&p
, end
);
11337 if (type
!= PBM_MONO
)
11339 max_color_idx
= pbm_scan_number (&p
, end
);
11340 if (raw_p
&& max_color_idx
> 255)
11341 max_color_idx
= 255;
11346 || (type
!= PBM_MONO
&& max_color_idx
< 0))
11349 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11352 #if 0 /* TODO: color tables. */
11353 /* Initialize the color hash table. */
11354 init_color_table ();
11357 if (type
== PBM_MONO
)
11360 struct image_keyword fmt
[PBM_LAST
];
11361 unsigned long fg
= FRAME_FOREGROUND_PIXEL (f
);
11362 unsigned long bg
= FRAME_BACKGROUND_PIXEL (f
);
11364 /* Parse the image specification. */
11365 bcopy (pbm_format
, fmt
, sizeof fmt
);
11366 parse_image_spec (img
->spec
, fmt
, PBM_LAST
, Qpbm
);
11368 /* Get foreground and background colors, maybe allocate colors. */
11369 if (fmt
[PBM_FOREGROUND
].count
11370 && STRINGP (fmt
[PBM_FOREGROUND
].value
))
11371 fg
= x_alloc_image_color (f
, img
, fmt
[PBM_FOREGROUND
].value
, fg
);
11372 if (fmt
[PBM_BACKGROUND
].count
11373 && STRINGP (fmt
[PBM_BACKGROUND
].value
))
11375 bg
= x_alloc_image_color (f
, img
, fmt
[PBM_BACKGROUND
].value
, bg
);
11376 img
->background
= bg
;
11377 img
->background_valid
= 1;
11380 for (y
= 0; y
< height
; ++y
)
11381 for (x
= 0; x
< width
; ++x
)
11391 g
= pbm_scan_number (&p
, end
);
11393 XPutPixel (ximg
, x
, y
, g
? fg
: bg
);
11398 for (y
= 0; y
< height
; ++y
)
11399 for (x
= 0; x
< width
; ++x
)
11403 if (type
== PBM_GRAY
)
11404 r
= g
= b
= raw_p
? *p
++ : pbm_scan_number (&p
, end
);
11413 r
= pbm_scan_number (&p
, end
);
11414 g
= pbm_scan_number (&p
, end
);
11415 b
= pbm_scan_number (&p
, end
);
11418 if (r
< 0 || g
< 0 || b
< 0)
11420 x_destroy_x_image (ximg
);
11421 image_error ("Invalid pixel value in image `%s'",
11426 /* RGB values are now in the range 0..max_color_idx.
11427 Scale this to the range 0..0xff supported by W32. */
11428 r
= (int) ((double) r
* 255 / max_color_idx
);
11429 g
= (int) ((double) g
* 255 / max_color_idx
);
11430 b
= (int) ((double) b
* 255 / max_color_idx
);
11431 XPutPixel (ximg
, x
, y
,
11432 #if 0 /* TODO: color tables. */
11433 lookup_rgb_color (f
, r
, g
, b
));
11435 PALETTERGB (r
, g
, b
));
11440 #if 0 /* TODO: color tables. */
11441 /* Store in IMG->colors the colors allocated for the image, and
11442 free the color table. */
11443 img
->colors
= colors_in_color_table (&img
->ncolors
);
11444 free_color_table ();
11446 /* Maybe fill in the background field while we have ximg handy. */
11447 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
11448 IMAGE_BACKGROUND (img
, f
, ximg
);
11450 /* Put the image into a pixmap. */
11451 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11452 x_destroy_x_image (ximg
);
11454 img
->width
= width
;
11455 img
->height
= height
;
11463 /***********************************************************************
11465 ***********************************************************************/
11471 /* Function prototypes. */
11473 static int png_image_p
P_ ((Lisp_Object object
));
11474 static int png_load
P_ ((struct frame
*f
, struct image
*img
));
11476 /* The symbol `png' identifying images of this type. */
11480 /* Indices of image specification fields in png_format, below. */
11482 enum png_keyword_index
11491 PNG_HEURISTIC_MASK
,
11497 /* Vector of image_keyword structures describing the format
11498 of valid user-defined image specifications. */
11500 static struct image_keyword png_format
[PNG_LAST
] =
11502 {":type", IMAGE_SYMBOL_VALUE
, 1},
11503 {":data", IMAGE_STRING_VALUE
, 0},
11504 {":file", IMAGE_STRING_VALUE
, 0},
11505 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11506 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
11507 {":relief", IMAGE_INTEGER_VALUE
, 0},
11508 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11509 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11510 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11511 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
11514 /* Structure describing the image type `png'. */
11516 static struct image_type png_type
=
11526 /* Return non-zero if OBJECT is a valid PNG image specification. */
11529 png_image_p (object
)
11530 Lisp_Object object
;
11532 struct image_keyword fmt
[PNG_LAST
];
11533 bcopy (png_format
, fmt
, sizeof fmt
);
11535 if (!parse_image_spec (object
, fmt
, PNG_LAST
, Qpng
)
11536 || (fmt
[PNG_ASCENT
].count
11537 && XFASTINT (fmt
[PNG_ASCENT
].value
) > 100))
11540 /* Must specify either the :data or :file keyword. */
11541 return fmt
[PNG_FILE
].count
+ fmt
[PNG_DATA
].count
== 1;
11545 /* Error and warning handlers installed when the PNG library
11549 my_png_error (png_ptr
, msg
)
11550 png_struct
*png_ptr
;
11553 xassert (png_ptr
!= NULL
);
11554 image_error ("PNG error: %s", build_string (msg
), Qnil
);
11555 longjmp (png_ptr
->jmpbuf
, 1);
11560 my_png_warning (png_ptr
, msg
)
11561 png_struct
*png_ptr
;
11564 xassert (png_ptr
!= NULL
);
11565 image_error ("PNG warning: %s", build_string (msg
), Qnil
);
11568 /* Memory source for PNG decoding. */
11570 struct png_memory_storage
11572 unsigned char *bytes
; /* The data */
11573 size_t len
; /* How big is it? */
11574 int index
; /* Where are we? */
11578 /* Function set as reader function when reading PNG image from memory.
11579 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH
11580 bytes from the input to DATA. */
11583 png_read_from_memory (png_ptr
, data
, length
)
11584 png_structp png_ptr
;
11588 struct png_memory_storage
*tbr
11589 = (struct png_memory_storage
*) png_get_io_ptr (png_ptr
);
11591 if (length
> tbr
->len
- tbr
->index
)
11592 png_error (png_ptr
, "Read error");
11594 bcopy (tbr
->bytes
+ tbr
->index
, data
, length
);
11595 tbr
->index
= tbr
->index
+ length
;
11598 /* Load PNG image IMG for use on frame F. Value is non-zero if
11606 Lisp_Object file
, specified_file
;
11607 Lisp_Object specified_data
;
11609 XImage
*ximg
, *mask_img
= NULL
;
11610 struct gcpro gcpro1
;
11611 png_struct
*png_ptr
= NULL
;
11612 png_info
*info_ptr
= NULL
, *end_info
= NULL
;
11613 FILE *volatile fp
= NULL
;
11615 png_byte
*volatile pixels
= NULL
;
11616 png_byte
**volatile rows
= NULL
;
11617 png_uint_32 width
, height
;
11618 int bit_depth
, color_type
, interlace_type
;
11620 png_uint_32 row_bytes
;
11623 double screen_gamma
, image_gamma
;
11625 struct png_memory_storage tbr
; /* Data to be read */
11627 /* Find out what file to load. */
11628 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11629 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11633 if (NILP (specified_data
))
11635 file
= x_find_image_file (specified_file
);
11636 if (!STRINGP (file
))
11638 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
11643 /* Open the image file. */
11644 fp
= fopen (XSTRING (file
)->data
, "rb");
11647 image_error ("Cannot open image file `%s'", file
, Qnil
);
11653 /* Check PNG signature. */
11654 if (fread (sig
, 1, sizeof sig
, fp
) != sizeof sig
11655 || !png_check_sig (sig
, sizeof sig
))
11657 image_error ("Not a PNG file:` %s'", file
, Qnil
);
11665 /* Read from memory. */
11666 tbr
.bytes
= XSTRING (specified_data
)->data
;
11667 tbr
.len
= STRING_BYTES (XSTRING (specified_data
));
11670 /* Check PNG signature. */
11671 if (tbr
.len
< sizeof sig
11672 || !png_check_sig (tbr
.bytes
, sizeof sig
))
11674 image_error ("Not a PNG image: `%s'", img
->spec
, Qnil
);
11679 /* Need to skip past the signature. */
11680 tbr
.bytes
+= sizeof (sig
);
11683 /* Initialize read and info structs for PNG lib. */
11684 png_ptr
= png_create_read_struct (PNG_LIBPNG_VER_STRING
, NULL
,
11685 my_png_error
, my_png_warning
);
11688 if (fp
) fclose (fp
);
11693 info_ptr
= png_create_info_struct (png_ptr
);
11696 png_destroy_read_struct (&png_ptr
, NULL
, NULL
);
11697 if (fp
) fclose (fp
);
11702 end_info
= png_create_info_struct (png_ptr
);
11705 png_destroy_read_struct (&png_ptr
, &info_ptr
, NULL
);
11706 if (fp
) fclose (fp
);
11711 /* Set error jump-back. We come back here when the PNG library
11712 detects an error. */
11713 if (setjmp (png_ptr
->jmpbuf
))
11717 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
11720 if (fp
) fclose (fp
);
11725 /* Read image info. */
11726 if (!NILP (specified_data
))
11727 png_set_read_fn (png_ptr
, (void *) &tbr
, png_read_from_memory
);
11729 png_init_io (png_ptr
, fp
);
11731 png_set_sig_bytes (png_ptr
, sizeof sig
);
11732 png_read_info (png_ptr
, info_ptr
);
11733 png_get_IHDR (png_ptr
, info_ptr
, &width
, &height
, &bit_depth
, &color_type
,
11734 &interlace_type
, NULL
, NULL
);
11736 /* If image contains simply transparency data, we prefer to
11737 construct a clipping mask. */
11738 if (png_get_valid (png_ptr
, info_ptr
, PNG_INFO_tRNS
))
11743 /* This function is easier to write if we only have to handle
11744 one data format: RGB or RGBA with 8 bits per channel. Let's
11745 transform other formats into that format. */
11747 /* Strip more than 8 bits per channel. */
11748 if (bit_depth
== 16)
11749 png_set_strip_16 (png_ptr
);
11751 /* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha channel
11753 png_set_expand (png_ptr
);
11755 /* Convert grayscale images to RGB. */
11756 if (color_type
== PNG_COLOR_TYPE_GRAY
11757 || color_type
== PNG_COLOR_TYPE_GRAY_ALPHA
)
11758 png_set_gray_to_rgb (png_ptr
);
11760 /* The value 2.2 is a guess for PC monitors from PNG example.c. */
11761 gamma_str
= getenv ("SCREEN_GAMMA");
11762 screen_gamma
= gamma_str
? atof (gamma_str
) : 2.2;
11764 /* Tell the PNG lib to handle gamma correction for us. */
11766 #if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
11767 if (png_get_sRGB (png_ptr
, info_ptr
, &intent
))
11768 /* There is a special chunk in the image specifying the gamma. */
11769 png_set_sRGB (png_ptr
, info_ptr
, intent
);
11772 if (png_get_gAMA (png_ptr
, info_ptr
, &image_gamma
))
11773 /* Image contains gamma information. */
11774 png_set_gamma (png_ptr
, screen_gamma
, image_gamma
);
11776 /* Use a default of 0.5 for the image gamma. */
11777 png_set_gamma (png_ptr
, screen_gamma
, 0.5);
11779 /* Handle alpha channel by combining the image with a background
11780 color. Do this only if a real alpha channel is supplied. For
11781 simple transparency, we prefer a clipping mask. */
11782 if (!transparent_p
)
11784 png_color_16
*image_background
;
11785 Lisp_Object specified_bg
11786 = image_spec_value (img
->spec
, QCbackground
, NULL
);
11789 if (STRINGP (specified_bg
))
11790 /* The user specified `:background', use that. */
11793 if (w32_defined_color (f
, XSTRING (specified_bg
)->data
, &color
, 0))
11795 png_color_16 user_bg
;
11797 bzero (&user_bg
, sizeof user_bg
);
11798 user_bg
.red
= color
.red
;
11799 user_bg
.green
= color
.green
;
11800 user_bg
.blue
= color
.blue
;
11802 png_set_background (png_ptr
, &user_bg
,
11803 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
11806 else if (png_get_bKGD (png_ptr
, info_ptr
, &image_background
))
11807 /* Image contains a background color with which to
11808 combine the image. */
11809 png_set_background (png_ptr
, image_background
,
11810 PNG_BACKGROUND_GAMMA_FILE
, 1, 1.0);
11813 /* Image does not contain a background color with which
11814 to combine the image data via an alpha channel. Use
11815 the frame's background instead. */
11818 png_color_16 frame_background
;
11820 cmap
= FRAME_X_COLORMAP (f
);
11821 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
11822 x_query_color (f
, &color
);
11824 bzero (&frame_background
, sizeof frame_background
);
11825 frame_background
.red
= color
.red
;
11826 frame_background
.green
= color
.green
;
11827 frame_background
.blue
= color
.blue
;
11829 png_set_background (png_ptr
, &frame_background
,
11830 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
11834 /* Update info structure. */
11835 png_read_update_info (png_ptr
, info_ptr
);
11837 /* Get number of channels. Valid values are 1 for grayscale images
11838 and images with a palette, 2 for grayscale images with transparency
11839 information (alpha channel), 3 for RGB images, and 4 for RGB
11840 images with alpha channel, i.e. RGBA. If conversions above were
11841 sufficient we should only have 3 or 4 channels here. */
11842 channels
= png_get_channels (png_ptr
, info_ptr
);
11843 xassert (channels
== 3 || channels
== 4);
11845 /* Number of bytes needed for one row of the image. */
11846 row_bytes
= png_get_rowbytes (png_ptr
, info_ptr
);
11848 /* Allocate memory for the image. */
11849 pixels
= (png_byte
*) xmalloc (row_bytes
* height
* sizeof *pixels
);
11850 rows
= (png_byte
**) xmalloc (height
* sizeof *rows
);
11851 for (i
= 0; i
< height
; ++i
)
11852 rows
[i
] = pixels
+ i
* row_bytes
;
11854 /* Read the entire image. */
11855 png_read_image (png_ptr
, rows
);
11856 png_read_end (png_ptr
, info_ptr
);
11863 /* Create the X image and pixmap. */
11864 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
11868 /* Create an image and pixmap serving as mask if the PNG image
11869 contains an alpha channel. */
11872 && !x_create_x_image_and_pixmap (f
, width
, height
, 1,
11873 &mask_img
, &img
->mask
))
11875 x_destroy_x_image (ximg
);
11876 XFreePixmap (FRAME_W32_DISPLAY (f
), img
->pixmap
);
11881 /* Fill the X image and mask from PNG data. */
11882 init_color_table ();
11884 for (y
= 0; y
< height
; ++y
)
11886 png_byte
*p
= rows
[y
];
11888 for (x
= 0; x
< width
; ++x
)
11895 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
11897 /* An alpha channel, aka mask channel, associates variable
11898 transparency with an image. Where other image formats
11899 support binary transparency---fully transparent or fully
11900 opaque---PNG allows up to 254 levels of partial transparency.
11901 The PNG library implements partial transparency by combining
11902 the image with a specified background color.
11904 I'm not sure how to handle this here nicely: because the
11905 background on which the image is displayed may change, for
11906 real alpha channel support, it would be necessary to create
11907 a new image for each possible background.
11909 What I'm doing now is that a mask is created if we have
11910 boolean transparency information. Otherwise I'm using
11911 the frame's background color to combine the image with. */
11916 XPutPixel (mask_img
, x
, y
, *p
> 0);
11922 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
11923 /* Set IMG's background color from the PNG image, unless the user
11927 if (png_get_bKGD (png_ptr
, info_ptr
, &bg
))
11929 img
->background
= lookup_rgb_color (f
, bg
->red
, bg
->green
, bg
->blue
);
11930 img
->background_valid
= 1;
11934 /* Remember colors allocated for this image. */
11935 img
->colors
= colors_in_color_table (&img
->ncolors
);
11936 free_color_table ();
11939 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
11943 img
->width
= width
;
11944 img
->height
= height
;
11946 /* Maybe fill in the background field while we have ximg handy. */
11947 IMAGE_BACKGROUND (img
, f
, ximg
);
11949 /* Put the image into the pixmap, then free the X image and its buffer. */
11950 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11951 x_destroy_x_image (ximg
);
11953 /* Same for the mask. */
11956 /* Fill in the background_transparent field while we have the mask
11958 image_background_transparent (img
, f
, mask_img
);
11960 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
11961 x_destroy_x_image (mask_img
);
11968 #endif /* HAVE_PNG != 0 */
11972 /***********************************************************************
11974 ***********************************************************************/
11978 /* Work around a warning about HAVE_STDLIB_H being redefined in
11980 #ifdef HAVE_STDLIB_H
11981 #define HAVE_STDLIB_H_1
11982 #undef HAVE_STDLIB_H
11983 #endif /* HAVE_STLIB_H */
11985 #include <jpeglib.h>
11986 #include <jerror.h>
11987 #include <setjmp.h>
11989 #ifdef HAVE_STLIB_H_1
11990 #define HAVE_STDLIB_H 1
11993 static int jpeg_image_p
P_ ((Lisp_Object object
));
11994 static int jpeg_load
P_ ((struct frame
*f
, struct image
*img
));
11996 /* The symbol `jpeg' identifying images of this type. */
12000 /* Indices of image specification fields in gs_format, below. */
12002 enum jpeg_keyword_index
12011 JPEG_HEURISTIC_MASK
,
12017 /* Vector of image_keyword structures describing the format
12018 of valid user-defined image specifications. */
12020 static struct image_keyword jpeg_format
[JPEG_LAST
] =
12022 {":type", IMAGE_SYMBOL_VALUE
, 1},
12023 {":data", IMAGE_STRING_VALUE
, 0},
12024 {":file", IMAGE_STRING_VALUE
, 0},
12025 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
12026 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
12027 {":relief", IMAGE_INTEGER_VALUE
, 0},
12028 {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12029 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12030 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12031 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
12034 /* Structure describing the image type `jpeg'. */
12036 static struct image_type jpeg_type
=
12046 /* Return non-zero if OBJECT is a valid JPEG image specification. */
12049 jpeg_image_p (object
)
12050 Lisp_Object object
;
12052 struct image_keyword fmt
[JPEG_LAST
];
12054 bcopy (jpeg_format
, fmt
, sizeof fmt
);
12056 if (!parse_image_spec (object
, fmt
, JPEG_LAST
, Qjpeg
)
12057 || (fmt
[JPEG_ASCENT
].count
12058 && XFASTINT (fmt
[JPEG_ASCENT
].value
) > 100))
12061 /* Must specify either the :data or :file keyword. */
12062 return fmt
[JPEG_FILE
].count
+ fmt
[JPEG_DATA
].count
== 1;
12066 struct my_jpeg_error_mgr
12068 struct jpeg_error_mgr pub
;
12069 jmp_buf setjmp_buffer
;
12073 my_error_exit (cinfo
)
12074 j_common_ptr cinfo
;
12076 struct my_jpeg_error_mgr
*mgr
= (struct my_jpeg_error_mgr
*) cinfo
->err
;
12077 longjmp (mgr
->setjmp_buffer
, 1);
12080 /* Init source method for JPEG data source manager. Called by
12081 jpeg_read_header() before any data is actually read. See
12082 libjpeg.doc from the JPEG lib distribution. */
12085 our_init_source (cinfo
)
12086 j_decompress_ptr cinfo
;
12091 /* Fill input buffer method for JPEG data source manager. Called
12092 whenever more data is needed. We read the whole image in one step,
12093 so this only adds a fake end of input marker at the end. */
12096 our_fill_input_buffer (cinfo
)
12097 j_decompress_ptr cinfo
;
12099 /* Insert a fake EOI marker. */
12100 struct jpeg_source_mgr
*src
= cinfo
->src
;
12101 static JOCTET buffer
[2];
12103 buffer
[0] = (JOCTET
) 0xFF;
12104 buffer
[1] = (JOCTET
) JPEG_EOI
;
12106 src
->next_input_byte
= buffer
;
12107 src
->bytes_in_buffer
= 2;
12112 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src
12113 is the JPEG data source manager. */
12116 our_skip_input_data (cinfo
, num_bytes
)
12117 j_decompress_ptr cinfo
;
12120 struct jpeg_source_mgr
*src
= (struct jpeg_source_mgr
*) cinfo
->src
;
12124 if (num_bytes
> src
->bytes_in_buffer
)
12125 ERREXIT (cinfo
, JERR_INPUT_EOF
);
12127 src
->bytes_in_buffer
-= num_bytes
;
12128 src
->next_input_byte
+= num_bytes
;
12133 /* Method to terminate data source. Called by
12134 jpeg_finish_decompress() after all data has been processed. */
12137 our_term_source (cinfo
)
12138 j_decompress_ptr cinfo
;
12143 /* Set up the JPEG lib for reading an image from DATA which contains
12144 LEN bytes. CINFO is the decompression info structure created for
12145 reading the image. */
12148 jpeg_memory_src (cinfo
, data
, len
)
12149 j_decompress_ptr cinfo
;
12153 struct jpeg_source_mgr
*src
;
12155 if (cinfo
->src
== NULL
)
12157 /* First time for this JPEG object? */
12158 cinfo
->src
= (struct jpeg_source_mgr
*)
12159 (*cinfo
->mem
->alloc_small
) ((j_common_ptr
) cinfo
, JPOOL_PERMANENT
,
12160 sizeof (struct jpeg_source_mgr
));
12161 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
12162 src
->next_input_byte
= data
;
12165 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
12166 src
->init_source
= our_init_source
;
12167 src
->fill_input_buffer
= our_fill_input_buffer
;
12168 src
->skip_input_data
= our_skip_input_data
;
12169 src
->resync_to_restart
= jpeg_resync_to_restart
; /* Use default method. */
12170 src
->term_source
= our_term_source
;
12171 src
->bytes_in_buffer
= len
;
12172 src
->next_input_byte
= data
;
12176 /* Load image IMG for use on frame F. Patterned after example.c
12177 from the JPEG lib. */
12184 struct jpeg_decompress_struct cinfo
;
12185 struct my_jpeg_error_mgr mgr
;
12186 Lisp_Object file
, specified_file
;
12187 Lisp_Object specified_data
;
12188 FILE * volatile fp
= NULL
;
12190 int row_stride
, x
, y
;
12191 XImage
*ximg
= NULL
;
12193 unsigned long *colors
;
12195 struct gcpro gcpro1
;
12197 /* Open the JPEG file. */
12198 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
12199 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
12203 if (NILP (specified_data
))
12205 file
= x_find_image_file (specified_file
);
12206 if (!STRINGP (file
))
12208 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
12213 fp
= fopen (XSTRING (file
)->data
, "r");
12216 image_error ("Cannot open `%s'", file
, Qnil
);
12222 /* Customize libjpeg's error handling to call my_error_exit when an
12223 error is detected. This function will perform a longjmp. */
12224 cinfo
.err
= jpeg_std_error (&mgr
.pub
);
12225 mgr
.pub
.error_exit
= my_error_exit
;
12227 if ((rc
= setjmp (mgr
.setjmp_buffer
)) != 0)
12231 /* Called from my_error_exit. Display a JPEG error. */
12232 char buffer
[JMSG_LENGTH_MAX
];
12233 cinfo
.err
->format_message ((j_common_ptr
) &cinfo
, buffer
);
12234 image_error ("Error reading JPEG image `%s': %s", img
->spec
,
12235 build_string (buffer
));
12238 /* Close the input file and destroy the JPEG object. */
12241 jpeg_destroy_decompress (&cinfo
);
12243 /* If we already have an XImage, free that. */
12244 x_destroy_x_image (ximg
);
12246 /* Free pixmap and colors. */
12247 x_clear_image (f
, img
);
12253 /* Create the JPEG decompression object. Let it read from fp.
12254 Read the JPEG image header. */
12255 jpeg_create_decompress (&cinfo
);
12257 if (NILP (specified_data
))
12258 jpeg_stdio_src (&cinfo
, fp
);
12260 jpeg_memory_src (&cinfo
, XSTRING (specified_data
)->data
,
12261 STRING_BYTES (XSTRING (specified_data
)));
12263 jpeg_read_header (&cinfo
, TRUE
);
12265 /* Customize decompression so that color quantization will be used.
12266 Start decompression. */
12267 cinfo
.quantize_colors
= TRUE
;
12268 jpeg_start_decompress (&cinfo
);
12269 width
= img
->width
= cinfo
.output_width
;
12270 height
= img
->height
= cinfo
.output_height
;
12272 /* Create X image and pixmap. */
12273 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
12275 longjmp (mgr
.setjmp_buffer
, 2);
12277 /* Allocate colors. When color quantization is used,
12278 cinfo.actual_number_of_colors has been set with the number of
12279 colors generated, and cinfo.colormap is a two-dimensional array
12280 of color indices in the range 0..cinfo.actual_number_of_colors.
12281 No more than 255 colors will be generated. */
12285 if (cinfo
.out_color_components
> 2)
12286 ir
= 0, ig
= 1, ib
= 2;
12287 else if (cinfo
.out_color_components
> 1)
12288 ir
= 0, ig
= 1, ib
= 0;
12290 ir
= 0, ig
= 0, ib
= 0;
12292 /* Use the color table mechanism because it handles colors that
12293 cannot be allocated nicely. Such colors will be replaced with
12294 a default color, and we don't have to care about which colors
12295 can be freed safely, and which can't. */
12296 init_color_table ();
12297 colors
= (unsigned long *) alloca (cinfo
.actual_number_of_colors
12300 for (i
= 0; i
< cinfo
.actual_number_of_colors
; ++i
)
12302 /* Multiply RGB values with 255 because X expects RGB values
12303 in the range 0..0xffff. */
12304 int r
= cinfo
.colormap
[ir
][i
] << 8;
12305 int g
= cinfo
.colormap
[ig
][i
] << 8;
12306 int b
= cinfo
.colormap
[ib
][i
] << 8;
12307 colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
12310 /* Remember those colors actually allocated. */
12311 img
->colors
= colors_in_color_table (&img
->ncolors
);
12312 free_color_table ();
12316 row_stride
= width
* cinfo
.output_components
;
12317 buffer
= cinfo
.mem
->alloc_sarray ((j_common_ptr
) &cinfo
, JPOOL_IMAGE
,
12319 for (y
= 0; y
< height
; ++y
)
12321 jpeg_read_scanlines (&cinfo
, buffer
, 1);
12322 for (x
= 0; x
< cinfo
.output_width
; ++x
)
12323 XPutPixel (ximg
, x
, y
, colors
[buffer
[0][x
]]);
12327 jpeg_finish_decompress (&cinfo
);
12328 jpeg_destroy_decompress (&cinfo
);
12332 /* Maybe fill in the background field while we have ximg handy. */
12333 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
12334 IMAGE_BACKGROUND (img
, f
, ximg
);
12336 /* Put the image into the pixmap. */
12337 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
12338 x_destroy_x_image (ximg
);
12344 #endif /* HAVE_JPEG */
12348 /***********************************************************************
12350 ***********************************************************************/
12354 #include <tiffio.h>
12356 static int tiff_image_p
P_ ((Lisp_Object object
));
12357 static int tiff_load
P_ ((struct frame
*f
, struct image
*img
));
12359 /* The symbol `tiff' identifying images of this type. */
12363 /* Indices of image specification fields in tiff_format, below. */
12365 enum tiff_keyword_index
12374 TIFF_HEURISTIC_MASK
,
12380 /* Vector of image_keyword structures describing the format
12381 of valid user-defined image specifications. */
12383 static struct image_keyword tiff_format
[TIFF_LAST
] =
12385 {":type", IMAGE_SYMBOL_VALUE
, 1},
12386 {":data", IMAGE_STRING_VALUE
, 0},
12387 {":file", IMAGE_STRING_VALUE
, 0},
12388 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
12389 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
12390 {":relief", IMAGE_INTEGER_VALUE
, 0},
12391 {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12392 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12393 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12394 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
12397 /* Structure describing the image type `tiff'. */
12399 static struct image_type tiff_type
=
12409 /* Return non-zero if OBJECT is a valid TIFF image specification. */
12412 tiff_image_p (object
)
12413 Lisp_Object object
;
12415 struct image_keyword fmt
[TIFF_LAST
];
12416 bcopy (tiff_format
, fmt
, sizeof fmt
);
12418 if (!parse_image_spec (object
, fmt
, TIFF_LAST
, Qtiff
)
12419 || (fmt
[TIFF_ASCENT
].count
12420 && XFASTINT (fmt
[TIFF_ASCENT
].value
) > 100))
12423 /* Must specify either the :data or :file keyword. */
12424 return fmt
[TIFF_FILE
].count
+ fmt
[TIFF_DATA
].count
== 1;
12428 /* Reading from a memory buffer for TIFF images Based on the PNG
12429 memory source, but we have to provide a lot of extra functions.
12432 We really only need to implement read and seek, but I am not
12433 convinced that the TIFF library is smart enough not to destroy
12434 itself if we only hand it the function pointers we need to
12439 unsigned char *bytes
;
12443 tiff_memory_source
;
12446 tiff_read_from_memory (data
, buf
, size
)
12451 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
12453 if (size
> src
->len
- src
->index
)
12454 return (size_t) -1;
12455 bcopy (src
->bytes
+ src
->index
, buf
, size
);
12456 src
->index
+= size
;
12461 tiff_write_from_memory (data
, buf
, size
)
12466 return (size_t) -1;
12470 tiff_seek_in_memory (data
, off
, whence
)
12475 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
12480 case SEEK_SET
: /* Go from beginning of source. */
12484 case SEEK_END
: /* Go from end of source. */
12485 idx
= src
->len
+ off
;
12488 case SEEK_CUR
: /* Go from current position. */
12489 idx
= src
->index
+ off
;
12492 default: /* Invalid `whence'. */
12496 if (idx
> src
->len
|| idx
< 0)
12504 tiff_close_memory (data
)
12512 tiff_mmap_memory (data
, pbase
, psize
)
12517 /* It is already _IN_ memory. */
12522 tiff_unmap_memory (data
, base
, size
)
12527 /* We don't need to do this. */
12531 tiff_size_of_memory (data
)
12534 return ((tiff_memory_source
*) data
)->len
;
12539 tiff_error_handler (title
, format
, ap
)
12540 const char *title
, *format
;
12546 len
= sprintf (buf
, "TIFF error: %s ", title
);
12547 vsprintf (buf
+ len
, format
, ap
);
12548 add_to_log (buf
, Qnil
, Qnil
);
12553 tiff_warning_handler (title
, format
, ap
)
12554 const char *title
, *format
;
12560 len
= sprintf (buf
, "TIFF warning: %s ", title
);
12561 vsprintf (buf
+ len
, format
, ap
);
12562 add_to_log (buf
, Qnil
, Qnil
);
12566 /* Load TIFF image IMG for use on frame F. Value is non-zero if
12574 Lisp_Object file
, specified_file
;
12575 Lisp_Object specified_data
;
12577 int width
, height
, x
, y
;
12581 struct gcpro gcpro1
;
12582 tiff_memory_source memsrc
;
12584 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
12585 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
12589 TIFFSetErrorHandler (tiff_error_handler
);
12590 TIFFSetWarningHandler (tiff_warning_handler
);
12592 if (NILP (specified_data
))
12594 /* Read from a file */
12595 file
= x_find_image_file (specified_file
);
12596 if (!STRINGP (file
))
12598 image_error ("Cannot find image file `%s'", file
, Qnil
);
12603 /* Try to open the image file. */
12604 tiff
= TIFFOpen (XSTRING (file
)->data
, "r");
12607 image_error ("Cannot open `%s'", file
, Qnil
);
12614 /* Memory source! */
12615 memsrc
.bytes
= XSTRING (specified_data
)->data
;
12616 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
12619 tiff
= TIFFClientOpen ("memory_source", "r", &memsrc
,
12620 (TIFFReadWriteProc
) tiff_read_from_memory
,
12621 (TIFFReadWriteProc
) tiff_write_from_memory
,
12622 tiff_seek_in_memory
,
12624 tiff_size_of_memory
,
12626 tiff_unmap_memory
);
12630 image_error ("Cannot open memory source for `%s'", img
->spec
, Qnil
);
12636 /* Get width and height of the image, and allocate a raster buffer
12637 of width x height 32-bit values. */
12638 TIFFGetField (tiff
, TIFFTAG_IMAGEWIDTH
, &width
);
12639 TIFFGetField (tiff
, TIFFTAG_IMAGELENGTH
, &height
);
12640 buf
= (uint32
*) xmalloc (width
* height
* sizeof *buf
);
12642 rc
= TIFFReadRGBAImage (tiff
, width
, height
, buf
, 0);
12646 image_error ("Error reading TIFF image `%s'", img
->spec
, Qnil
);
12652 /* Create the X image and pixmap. */
12653 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
12660 /* Initialize the color table. */
12661 init_color_table ();
12663 /* Process the pixel raster. Origin is in the lower-left corner. */
12664 for (y
= 0; y
< height
; ++y
)
12666 uint32
*row
= buf
+ y
* width
;
12668 for (x
= 0; x
< width
; ++x
)
12670 uint32 abgr
= row
[x
];
12671 int r
= TIFFGetR (abgr
) << 8;
12672 int g
= TIFFGetG (abgr
) << 8;
12673 int b
= TIFFGetB (abgr
) << 8;
12674 XPutPixel (ximg
, x
, height
- 1 - y
, lookup_rgb_color (f
, r
, g
, b
));
12678 /* Remember the colors allocated for the image. Free the color table. */
12679 img
->colors
= colors_in_color_table (&img
->ncolors
);
12680 free_color_table ();
12682 img
->width
= width
;
12683 img
->height
= height
;
12685 /* Maybe fill in the background field while we have ximg handy. */
12686 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
12687 IMAGE_BACKGROUND (img
, f
, ximg
);
12689 /* Put the image into the pixmap, then free the X image and its buffer. */
12690 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
12691 x_destroy_x_image (ximg
);
12698 #endif /* HAVE_TIFF != 0 */
12702 /***********************************************************************
12704 ***********************************************************************/
12708 #include <gif_lib.h>
12710 static int gif_image_p
P_ ((Lisp_Object object
));
12711 static int gif_load
P_ ((struct frame
*f
, struct image
*img
));
12713 /* The symbol `gif' identifying images of this type. */
12717 /* Indices of image specification fields in gif_format, below. */
12719 enum gif_keyword_index
12728 GIF_HEURISTIC_MASK
,
12735 /* Vector of image_keyword structures describing the format
12736 of valid user-defined image specifications. */
12738 static struct image_keyword gif_format
[GIF_LAST
] =
12740 {":type", IMAGE_SYMBOL_VALUE
, 1},
12741 {":data", IMAGE_STRING_VALUE
, 0},
12742 {":file", IMAGE_STRING_VALUE
, 0},
12743 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
12744 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
12745 {":relief", IMAGE_INTEGER_VALUE
, 0},
12746 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12747 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12748 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12749 {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
12750 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
12753 /* Structure describing the image type `gif'. */
12755 static struct image_type gif_type
=
12764 /* Return non-zero if OBJECT is a valid GIF image specification. */
12767 gif_image_p (object
)
12768 Lisp_Object object
;
12770 struct image_keyword fmt
[GIF_LAST
];
12771 bcopy (gif_format
, fmt
, sizeof fmt
);
12773 if (!parse_image_spec (object
, fmt
, GIF_LAST
, Qgif
)
12774 || (fmt
[GIF_ASCENT
].count
12775 && XFASTINT (fmt
[GIF_ASCENT
].value
) > 100))
12778 /* Must specify either the :data or :file keyword. */
12779 return fmt
[GIF_FILE
].count
+ fmt
[GIF_DATA
].count
== 1;
12782 /* Reading a GIF image from memory
12783 Based on the PNG memory stuff to a certain extent. */
12787 unsigned char *bytes
;
12793 /* Make the current memory source available to gif_read_from_memory.
12794 It's done this way because not all versions of libungif support
12795 a UserData field in the GifFileType structure. */
12796 static gif_memory_source
*current_gif_memory_src
;
12799 gif_read_from_memory (file
, buf
, len
)
12804 gif_memory_source
*src
= current_gif_memory_src
;
12806 if (len
> src
->len
- src
->index
)
12809 bcopy (src
->bytes
+ src
->index
, buf
, len
);
12815 /* Load GIF image IMG for use on frame F. Value is non-zero if
12823 Lisp_Object file
, specified_file
;
12824 Lisp_Object specified_data
;
12825 int rc
, width
, height
, x
, y
, i
;
12827 ColorMapObject
*gif_color_map
;
12828 unsigned long pixel_colors
[256];
12830 struct gcpro gcpro1
;
12832 int ino
, image_left
, image_top
, image_width
, image_height
;
12833 gif_memory_source memsrc
;
12834 unsigned char *raster
;
12836 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
12837 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
12841 if (NILP (specified_data
))
12843 file
= x_find_image_file (specified_file
);
12844 if (!STRINGP (file
))
12846 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
12851 /* Open the GIF file. */
12852 gif
= DGifOpenFileName (XSTRING (file
)->data
);
12855 image_error ("Cannot open `%s'", file
, Qnil
);
12862 /* Read from memory! */
12863 current_gif_memory_src
= &memsrc
;
12864 memsrc
.bytes
= XSTRING (specified_data
)->data
;
12865 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
12868 gif
= DGifOpen(&memsrc
, gif_read_from_memory
);
12871 image_error ("Cannot open memory source `%s'", img
->spec
, Qnil
);
12877 /* Read entire contents. */
12878 rc
= DGifSlurp (gif
);
12879 if (rc
== GIF_ERROR
)
12881 image_error ("Error reading `%s'", img
->spec
, Qnil
);
12882 DGifCloseFile (gif
);
12887 image
= image_spec_value (img
->spec
, QCindex
, NULL
);
12888 ino
= INTEGERP (image
) ? XFASTINT (image
) : 0;
12889 if (ino
>= gif
->ImageCount
)
12891 image_error ("Invalid image number `%s' in image `%s'",
12893 DGifCloseFile (gif
);
12898 width
= img
->width
= gif
->SWidth
;
12899 height
= img
->height
= gif
->SHeight
;
12901 /* Create the X image and pixmap. */
12902 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
12904 DGifCloseFile (gif
);
12909 /* Allocate colors. */
12910 gif_color_map
= gif
->SavedImages
[ino
].ImageDesc
.ColorMap
;
12911 if (!gif_color_map
)
12912 gif_color_map
= gif
->SColorMap
;
12913 init_color_table ();
12914 bzero (pixel_colors
, sizeof pixel_colors
);
12916 for (i
= 0; i
< gif_color_map
->ColorCount
; ++i
)
12918 int r
= gif_color_map
->Colors
[i
].Red
<< 8;
12919 int g
= gif_color_map
->Colors
[i
].Green
<< 8;
12920 int b
= gif_color_map
->Colors
[i
].Blue
<< 8;
12921 pixel_colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
12924 img
->colors
= colors_in_color_table (&img
->ncolors
);
12925 free_color_table ();
12927 /* Clear the part of the screen image that are not covered by
12928 the image from the GIF file. Full animated GIF support
12929 requires more than can be done here (see the gif89 spec,
12930 disposal methods). Let's simply assume that the part
12931 not covered by a sub-image is in the frame's background color. */
12932 image_top
= gif
->SavedImages
[ino
].ImageDesc
.Top
;
12933 image_left
= gif
->SavedImages
[ino
].ImageDesc
.Left
;
12934 image_width
= gif
->SavedImages
[ino
].ImageDesc
.Width
;
12935 image_height
= gif
->SavedImages
[ino
].ImageDesc
.Height
;
12937 for (y
= 0; y
< image_top
; ++y
)
12938 for (x
= 0; x
< width
; ++x
)
12939 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
12941 for (y
= image_top
+ image_height
; y
< height
; ++y
)
12942 for (x
= 0; x
< width
; ++x
)
12943 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
12945 for (y
= image_top
; y
< image_top
+ image_height
; ++y
)
12947 for (x
= 0; x
< image_left
; ++x
)
12948 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
12949 for (x
= image_left
+ image_width
; x
< width
; ++x
)
12950 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
12953 /* Read the GIF image into the X image. We use a local variable
12954 `raster' here because RasterBits below is a char *, and invites
12955 problems with bytes >= 0x80. */
12956 raster
= (unsigned char *) gif
->SavedImages
[ino
].RasterBits
;
12958 if (gif
->SavedImages
[ino
].ImageDesc
.Interlace
)
12960 static int interlace_start
[] = {0, 4, 2, 1};
12961 static int interlace_increment
[] = {8, 8, 4, 2};
12963 int row
= interlace_start
[0];
12967 for (y
= 0; y
< image_height
; y
++)
12969 if (row
>= image_height
)
12971 row
= interlace_start
[++pass
];
12972 while (row
>= image_height
)
12973 row
= interlace_start
[++pass
];
12976 for (x
= 0; x
< image_width
; x
++)
12978 int i
= raster
[(y
* image_width
) + x
];
12979 XPutPixel (ximg
, x
+ image_left
, row
+ image_top
,
12983 row
+= interlace_increment
[pass
];
12988 for (y
= 0; y
< image_height
; ++y
)
12989 for (x
= 0; x
< image_width
; ++x
)
12991 int i
= raster
[y
* image_width
+ x
];
12992 XPutPixel (ximg
, x
+ image_left
, y
+ image_top
, pixel_colors
[i
]);
12996 DGifCloseFile (gif
);
12998 /* Maybe fill in the background field while we have ximg handy. */
12999 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
13000 IMAGE_BACKGROUND (img
, f
, ximg
);
13002 /* Put the image into the pixmap, then free the X image and its buffer. */
13003 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
13004 x_destroy_x_image (ximg
);
13010 #endif /* HAVE_GIF != 0 */
13014 /***********************************************************************
13016 ***********************************************************************/
13018 Lisp_Object Qpostscript
;
13020 #ifdef HAVE_GHOSTSCRIPT
13021 static int gs_image_p
P_ ((Lisp_Object object
));
13022 static int gs_load
P_ ((struct frame
*f
, struct image
*img
));
13023 static void gs_clear_image
P_ ((struct frame
*f
, struct image
*img
));
13025 /* The symbol `postscript' identifying images of this type. */
13027 /* Keyword symbols. */
13029 Lisp_Object QCloader
, QCbounding_box
, QCpt_width
, QCpt_height
;
13031 /* Indices of image specification fields in gs_format, below. */
13033 enum gs_keyword_index
13051 /* Vector of image_keyword structures describing the format
13052 of valid user-defined image specifications. */
13054 static struct image_keyword gs_format
[GS_LAST
] =
13056 {":type", IMAGE_SYMBOL_VALUE
, 1},
13057 {":pt-width", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
13058 {":pt-height", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
13059 {":file", IMAGE_STRING_VALUE
, 1},
13060 {":loader", IMAGE_FUNCTION_VALUE
, 0},
13061 {":bounding-box", IMAGE_DONT_CHECK_VALUE_TYPE
, 1},
13062 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
13063 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
13064 {":relief", IMAGE_INTEGER_VALUE
, 0},
13065 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
13066 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
13067 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
13068 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
13071 /* Structure describing the image type `ghostscript'. */
13073 static struct image_type gs_type
=
13083 /* Free X resources of Ghostscript image IMG which is used on frame F. */
13086 gs_clear_image (f
, img
)
13090 /* IMG->data.ptr_val may contain a recorded colormap. */
13091 xfree (img
->data
.ptr_val
);
13092 x_clear_image (f
, img
);
13096 /* Return non-zero if OBJECT is a valid Ghostscript image
13100 gs_image_p (object
)
13101 Lisp_Object object
;
13103 struct image_keyword fmt
[GS_LAST
];
13107 bcopy (gs_format
, fmt
, sizeof fmt
);
13109 if (!parse_image_spec (object
, fmt
, GS_LAST
, Qpostscript
)
13110 || (fmt
[GS_ASCENT
].count
13111 && XFASTINT (fmt
[GS_ASCENT
].value
) > 100))
13114 /* Bounding box must be a list or vector containing 4 integers. */
13115 tem
= fmt
[GS_BOUNDING_BOX
].value
;
13118 for (i
= 0; i
< 4; ++i
, tem
= XCDR (tem
))
13119 if (!CONSP (tem
) || !INTEGERP (XCAR (tem
)))
13124 else if (VECTORP (tem
))
13126 if (XVECTOR (tem
)->size
!= 4)
13128 for (i
= 0; i
< 4; ++i
)
13129 if (!INTEGERP (XVECTOR (tem
)->contents
[i
]))
13139 /* Load Ghostscript image IMG for use on frame F. Value is non-zero
13148 Lisp_Object window_and_pixmap_id
= Qnil
, loader
, pt_height
, pt_width
;
13149 struct gcpro gcpro1
, gcpro2
;
13151 double in_width
, in_height
;
13152 Lisp_Object pixel_colors
= Qnil
;
13154 /* Compute pixel size of pixmap needed from the given size in the
13155 image specification. Sizes in the specification are in pt. 1 pt
13156 = 1/72 in, xdpi and ydpi are stored in the frame's X display
13158 pt_width
= image_spec_value (img
->spec
, QCpt_width
, NULL
);
13159 in_width
= XFASTINT (pt_width
) / 72.0;
13160 img
->width
= in_width
* FRAME_W32_DISPLAY_INFO (f
)->resx
;
13161 pt_height
= image_spec_value (img
->spec
, QCpt_height
, NULL
);
13162 in_height
= XFASTINT (pt_height
) / 72.0;
13163 img
->height
= in_height
* FRAME_W32_DISPLAY_INFO (f
)->resy
;
13165 /* Create the pixmap. */
13167 xassert (img
->pixmap
== 0);
13168 img
->pixmap
= XCreatePixmap (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
13169 img
->width
, img
->height
,
13170 one_w32_display_info
.n_cbits
);
13175 image_error ("Unable to create pixmap for `%s'", img
->spec
, Qnil
);
13179 /* Call the loader to fill the pixmap. It returns a process object
13180 if successful. We do not record_unwind_protect here because
13181 other places in redisplay like calling window scroll functions
13182 don't either. Let the Lisp loader use `unwind-protect' instead. */
13183 GCPRO2 (window_and_pixmap_id
, pixel_colors
);
13185 sprintf (buffer
, "%lu %lu",
13186 (unsigned long) FRAME_W32_WINDOW (f
),
13187 (unsigned long) img
->pixmap
);
13188 window_and_pixmap_id
= build_string (buffer
);
13190 sprintf (buffer
, "%lu %lu",
13191 FRAME_FOREGROUND_PIXEL (f
),
13192 FRAME_BACKGROUND_PIXEL (f
));
13193 pixel_colors
= build_string (buffer
);
13195 XSETFRAME (frame
, f
);
13196 loader
= image_spec_value (img
->spec
, QCloader
, NULL
);
13198 loader
= intern ("gs-load-image");
13200 img
->data
.lisp_val
= call6 (loader
, frame
, img
->spec
,
13201 make_number (img
->width
),
13202 make_number (img
->height
),
13203 window_and_pixmap_id
,
13206 return PROCESSP (img
->data
.lisp_val
);
13210 /* Kill the Ghostscript process that was started to fill PIXMAP on
13211 frame F. Called from XTread_socket when receiving an event
13212 telling Emacs that Ghostscript has finished drawing. */
13215 x_kill_gs_process (pixmap
, f
)
13219 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
13223 /* Find the image containing PIXMAP. */
13224 for (i
= 0; i
< c
->used
; ++i
)
13225 if (c
->images
[i
]->pixmap
== pixmap
)
13228 /* Should someone in between have cleared the image cache, for
13229 instance, give up. */
13233 /* Kill the GS process. We should have found PIXMAP in the image
13234 cache and its image should contain a process object. */
13235 img
= c
->images
[i
];
13236 xassert (PROCESSP (img
->data
.lisp_val
));
13237 Fkill_process (img
->data
.lisp_val
, Qnil
);
13238 img
->data
.lisp_val
= Qnil
;
13240 /* On displays with a mutable colormap, figure out the colors
13241 allocated for the image by looking at the pixels of an XImage for
13243 class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
13244 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
13250 /* Try to get an XImage for img->pixmep. */
13251 ximg
= XGetImage (FRAME_W32_DISPLAY (f
), img
->pixmap
,
13252 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
13257 /* Initialize the color table. */
13258 init_color_table ();
13260 /* For each pixel of the image, look its color up in the
13261 color table. After having done so, the color table will
13262 contain an entry for each color used by the image. */
13263 for (y
= 0; y
< img
->height
; ++y
)
13264 for (x
= 0; x
< img
->width
; ++x
)
13266 unsigned long pixel
= XGetPixel (ximg
, x
, y
);
13267 lookup_pixel_color (f
, pixel
);
13270 /* Record colors in the image. Free color table and XImage. */
13271 img
->colors
= colors_in_color_table (&img
->ncolors
);
13272 free_color_table ();
13273 XDestroyImage (ximg
);
13275 #if 0 /* This doesn't seem to be the case. If we free the colors
13276 here, we get a BadAccess later in x_clear_image when
13277 freeing the colors. */
13278 /* We have allocated colors once, but Ghostscript has also
13279 allocated colors on behalf of us. So, to get the
13280 reference counts right, free them once. */
13282 x_free_colors (FRAME_W32_DISPLAY (f
), cmap
,
13283 img
->colors
, img
->ncolors
, 0);
13287 image_error ("Cannot get X image of `%s'; colors will not be freed",
13293 /* Now that we have the pixmap, compute mask and transform the
13294 image if requested. */
13296 postprocess_image (f
, img
);
13300 #endif /* HAVE_GHOSTSCRIPT */
13303 /***********************************************************************
13305 ***********************************************************************/
13307 DEFUN ("x-change-window-property", Fx_change_window_property
,
13308 Sx_change_window_property
, 2, 3, 0,
13309 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
13310 PROP and VALUE must be strings. FRAME nil or omitted means use the
13311 selected frame. Value is VALUE. */)
13312 (prop
, value
, frame
)
13313 Lisp_Object frame
, prop
, value
;
13315 #if 0 /* TODO : port window properties to W32 */
13316 struct frame
*f
= check_x_frame (frame
);
13319 CHECK_STRING (prop
);
13320 CHECK_STRING (value
);
13323 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
13324 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
13325 prop_atom
, XA_STRING
, 8, PropModeReplace
,
13326 XSTRING (value
)->data
, XSTRING (value
)->size
);
13328 /* Make sure the property is set when we return. */
13329 XFlush (FRAME_W32_DISPLAY (f
));
13338 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
13339 Sx_delete_window_property
, 1, 2, 0,
13340 doc
: /* Remove window property PROP from X window of FRAME.
13341 FRAME nil or omitted means use the selected frame. Value is PROP. */)
13343 Lisp_Object prop
, frame
;
13345 #if 0 /* TODO : port window properties to W32 */
13347 struct frame
*f
= check_x_frame (frame
);
13350 CHECK_STRING (prop
);
13352 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
13353 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
13355 /* Make sure the property is removed when we return. */
13356 XFlush (FRAME_W32_DISPLAY (f
));
13364 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
13366 doc
: /* Value is the value of window property PROP on FRAME.
13367 If FRAME is nil or omitted, use the selected frame. Value is nil
13368 if FRAME hasn't a property with name PROP or if PROP has no string
13371 Lisp_Object prop
, frame
;
13373 #if 0 /* TODO : port window properties to W32 */
13375 struct frame
*f
= check_x_frame (frame
);
13378 Lisp_Object prop_value
= Qnil
;
13379 char *tmp_data
= NULL
;
13382 unsigned long actual_size
, bytes_remaining
;
13384 CHECK_STRING (prop
);
13386 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
13387 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
13388 prop_atom
, 0, 0, False
, XA_STRING
,
13389 &actual_type
, &actual_format
, &actual_size
,
13390 &bytes_remaining
, (unsigned char **) &tmp_data
);
13393 int size
= bytes_remaining
;
13398 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
13399 prop_atom
, 0, bytes_remaining
,
13401 &actual_type
, &actual_format
,
13402 &actual_size
, &bytes_remaining
,
13403 (unsigned char **) &tmp_data
);
13405 prop_value
= make_string (tmp_data
, size
);
13420 /***********************************************************************
13422 ***********************************************************************/
13424 /* If non-null, an asynchronous timer that, when it expires, displays
13425 an hourglass cursor on all frames. */
13427 static struct atimer
*hourglass_atimer
;
13429 /* Non-zero means an hourglass cursor is currently shown. */
13431 static int hourglass_shown_p
;
13433 /* Number of seconds to wait before displaying an hourglass cursor. */
13435 static Lisp_Object Vhourglass_delay
;
13437 /* Default number of seconds to wait before displaying an hourglass
13440 #define DEFAULT_HOURGLASS_DELAY 1
13442 /* Function prototypes. */
13444 static void show_hourglass
P_ ((struct atimer
*));
13445 static void hide_hourglass
P_ ((void));
13448 /* Cancel a currently active hourglass timer, and start a new one. */
13453 #if 0 /* TODO: cursor shape changes. */
13455 int secs
, usecs
= 0;
13457 cancel_hourglass ();
13459 if (INTEGERP (Vhourglass_delay
)
13460 && XINT (Vhourglass_delay
) > 0)
13461 secs
= XFASTINT (Vhourglass_delay
);
13462 else if (FLOATP (Vhourglass_delay
)
13463 && XFLOAT_DATA (Vhourglass_delay
) > 0)
13466 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
13467 secs
= XFASTINT (tem
);
13468 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
13471 secs
= DEFAULT_HOURGLASS_DELAY
;
13473 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
13474 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
13475 show_hourglass
, NULL
);
13480 /* Cancel the hourglass cursor timer if active, hide an hourglass
13481 cursor if shown. */
13484 cancel_hourglass ()
13486 if (hourglass_atimer
)
13488 cancel_atimer (hourglass_atimer
);
13489 hourglass_atimer
= NULL
;
13492 if (hourglass_shown_p
)
13497 /* Timer function of hourglass_atimer. TIMER is equal to
13500 Display an hourglass cursor on all frames by mapping the frames'
13501 hourglass_window. Set the hourglass_p flag in the frames'
13502 output_data.x structure to indicate that an hourglass cursor is
13503 shown on the frames. */
13506 show_hourglass (timer
)
13507 struct atimer
*timer
;
13509 #if 0 /* TODO: cursor shape changes. */
13510 /* The timer implementation will cancel this timer automatically
13511 after this function has run. Set hourglass_atimer to null
13512 so that we know the timer doesn't have to be canceled. */
13513 hourglass_atimer
= NULL
;
13515 if (!hourglass_shown_p
)
13517 Lisp_Object rest
, frame
;
13521 FOR_EACH_FRAME (rest
, frame
)
13522 if (FRAME_W32_P (XFRAME (frame
)))
13524 struct frame
*f
= XFRAME (frame
);
13526 f
->output_data
.w32
->hourglass_p
= 1;
13528 if (!f
->output_data
.w32
->hourglass_window
)
13530 unsigned long mask
= CWCursor
;
13531 XSetWindowAttributes attrs
;
13533 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
13535 f
->output_data
.w32
->hourglass_window
13536 = XCreateWindow (FRAME_X_DISPLAY (f
),
13537 FRAME_OUTER_WINDOW (f
),
13538 0, 0, 32000, 32000, 0, 0,
13544 XMapRaised (FRAME_X_DISPLAY (f
),
13545 f
->output_data
.w32
->hourglass_window
);
13546 XFlush (FRAME_X_DISPLAY (f
));
13549 hourglass_shown_p
= 1;
13556 /* Hide the hourglass cursor on all frames, if it is currently shown. */
13561 #if 0 /* TODO: cursor shape changes. */
13562 if (hourglass_shown_p
)
13564 Lisp_Object rest
, frame
;
13567 FOR_EACH_FRAME (rest
, frame
)
13569 struct frame
*f
= XFRAME (frame
);
13571 if (FRAME_W32_P (f
)
13572 /* Watch out for newly created frames. */
13573 && f
->output_data
.x
->hourglass_window
)
13575 XUnmapWindow (FRAME_X_DISPLAY (f
),
13576 f
->output_data
.x
->hourglass_window
);
13577 /* Sync here because XTread_socket looks at the
13578 hourglass_p flag that is reset to zero below. */
13579 XSync (FRAME_X_DISPLAY (f
), False
);
13580 f
->output_data
.x
->hourglass_p
= 0;
13584 hourglass_shown_p
= 0;
13592 /***********************************************************************
13594 ***********************************************************************/
13596 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
13597 Lisp_Object
, Lisp_Object
));
13598 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
13599 Lisp_Object
, int, int, int *, int *));
13601 /* The frame of a currently visible tooltip. */
13603 Lisp_Object tip_frame
;
13605 /* If non-nil, a timer started that hides the last tooltip when it
13608 Lisp_Object tip_timer
;
13611 /* If non-nil, a vector of 3 elements containing the last args
13612 with which x-show-tip was called. See there. */
13614 Lisp_Object last_show_tip_args
;
13616 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
13618 Lisp_Object Vx_max_tooltip_size
;
13622 unwind_create_tip_frame (frame
)
13625 Lisp_Object deleted
;
13627 deleted
= unwind_create_frame (frame
);
13628 if (EQ (deleted
, Qt
))
13638 /* Create a frame for a tooltip on the display described by DPYINFO.
13639 PARMS is a list of frame parameters. TEXT is the string to
13640 display in the tip frame. Value is the frame.
13642 Note that functions called here, esp. x_default_parameter can
13643 signal errors, for instance when a specified color name is
13644 undefined. We have to make sure that we're in a consistent state
13645 when this happens. */
13648 x_create_tip_frame (dpyinfo
, parms
, text
)
13649 struct w32_display_info
*dpyinfo
;
13650 Lisp_Object parms
, text
;
13653 Lisp_Object frame
, tem
;
13655 long window_prompting
= 0;
13657 int count
= BINDING_STACK_SIZE ();
13658 struct gcpro gcpro1
, gcpro2
, gcpro3
;
13660 int face_change_count_before
= face_change_count
;
13661 Lisp_Object buffer
;
13662 struct buffer
*old_buffer
;
13666 /* Use this general default value to start with until we know if
13667 this frame has a specified name. */
13668 Vx_resource_name
= Vinvocation_name
;
13670 #ifdef MULTI_KBOARD
13671 kb
= dpyinfo
->kboard
;
13673 kb
= &the_only_kboard
;
13676 /* Get the name of the frame to use for resource lookup. */
13677 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
13678 if (!STRINGP (name
)
13679 && !EQ (name
, Qunbound
)
13681 error ("Invalid frame name--not a string or nil");
13682 Vx_resource_name
= name
;
13685 GCPRO3 (parms
, name
, frame
);
13686 /* Make a frame without minibuffer nor mode-line. */
13687 f
= make_frame (0);
13688 f
->wants_modeline
= 0;
13689 XSETFRAME (frame
, f
);
13691 buffer
= Fget_buffer_create (build_string (" *tip*"));
13692 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
);
13693 old_buffer
= current_buffer
;
13694 set_buffer_internal_1 (XBUFFER (buffer
));
13695 current_buffer
->truncate_lines
= Qnil
;
13697 Finsert (1, &text
);
13698 set_buffer_internal_1 (old_buffer
);
13700 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
13701 record_unwind_protect (unwind_create_tip_frame
, frame
);
13703 /* By setting the output method, we're essentially saying that
13704 the frame is live, as per FRAME_LIVE_P. If we get a signal
13705 from this point on, x_destroy_window might screw up reference
13707 f
->output_method
= output_w32
;
13708 f
->output_data
.w32
=
13709 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
13710 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
13712 FRAME_FONTSET (f
) = -1;
13713 f
->icon_name
= Qnil
;
13715 #if 0 /* GLYPH_DEBUG TODO: image support. */
13716 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
13717 dpyinfo_refcount
= dpyinfo
->reference_count
;
13718 #endif /* GLYPH_DEBUG */
13719 #ifdef MULTI_KBOARD
13720 FRAME_KBOARD (f
) = kb
;
13722 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
13723 f
->output_data
.w32
->explicit_parent
= 0;
13725 /* Set the name; the functions to which we pass f expect the name to
13727 if (EQ (name
, Qunbound
) || NILP (name
))
13729 f
->name
= build_string (dpyinfo
->w32_id_name
);
13730 f
->explicit_name
= 0;
13735 f
->explicit_name
= 1;
13736 /* use the frame's title when getting resources for this frame. */
13737 specbind (Qx_resource_name
, name
);
13740 /* Extract the window parameters from the supplied values
13741 that are needed to determine window geometry. */
13745 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
13748 /* First, try whatever font the caller has specified. */
13749 if (STRINGP (font
))
13751 tem
= Fquery_fontset (font
, Qnil
);
13753 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
13755 font
= x_new_font (f
, XSTRING (font
)->data
);
13758 /* Try out a font which we hope has bold and italic variations. */
13759 if (!STRINGP (font
))
13760 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
13761 if (! STRINGP (font
))
13762 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
13763 /* If those didn't work, look for something which will at least work. */
13764 if (! STRINGP (font
))
13765 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
13767 if (! STRINGP (font
))
13768 font
= build_string ("Fixedsys");
13770 x_default_parameter (f
, parms
, Qfont
, font
,
13771 "font", "Font", RES_TYPE_STRING
);
13774 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
13775 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
13776 /* This defaults to 2 in order to match xterm. We recognize either
13777 internalBorderWidth or internalBorder (which is what xterm calls
13779 if (NILP (Fassq (Qinternal_border_width
, parms
)))
13783 value
= w32_get_arg (parms
, Qinternal_border_width
,
13784 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
13785 if (! EQ (value
, Qunbound
))
13786 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
13789 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
13790 "internalBorderWidth", "internalBorderWidth",
13793 /* Also do the stuff which must be set before the window exists. */
13794 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
13795 "foreground", "Foreground", RES_TYPE_STRING
);
13796 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
13797 "background", "Background", RES_TYPE_STRING
);
13798 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
13799 "pointerColor", "Foreground", RES_TYPE_STRING
);
13800 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
13801 "cursorColor", "Foreground", RES_TYPE_STRING
);
13802 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
13803 "borderColor", "BorderColor", RES_TYPE_STRING
);
13805 /* Init faces before x_default_parameter is called for scroll-bar
13806 parameters because that function calls x_set_scroll_bar_width,
13807 which calls change_frame_size, which calls Fset_window_buffer,
13808 which runs hooks, which call Fvertical_motion. At the end, we
13809 end up in init_iterator with a null face cache, which should not
13811 init_frame_faces (f
);
13813 f
->output_data
.w32
->dwStyle
= WS_BORDER
| WS_POPUP
| WS_DISABLED
;
13814 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
13816 window_prompting
= x_figure_window_size (f
, parms
);
13818 /* No fringes on tip frame. */
13819 f
->output_data
.w32
->fringes_extra
= 0;
13820 f
->output_data
.w32
->fringe_cols
= 0;
13821 f
->output_data
.w32
->left_fringe_width
= 0;
13822 f
->output_data
.w32
->right_fringe_width
= 0;
13824 if (window_prompting
& XNegative
)
13826 if (window_prompting
& YNegative
)
13827 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
13829 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
13833 if (window_prompting
& YNegative
)
13834 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
13836 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
13839 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
13842 my_create_tip_window (f
);
13847 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
13848 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
13849 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
13850 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
13851 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
13852 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
13854 /* Dimensions, especially f->height, must be done via change_frame_size.
13855 Change will not be effected unless different from the current
13858 height
= f
->height
;
13860 SET_FRAME_WIDTH (f
, 0);
13861 change_frame_size (f
, height
, width
, 1, 0, 0);
13863 /* Set up faces after all frame parameters are known. This call
13864 also merges in face attributes specified for new frames.
13866 Frame parameters may be changed if .Xdefaults contains
13867 specifications for the default font. For example, if there is an
13868 `Emacs.default.attributeBackground: pink', the `background-color'
13869 attribute of the frame get's set, which let's the internal border
13870 of the tooltip frame appear in pink. Prevent this. */
13872 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
13874 /* Set tip_frame here, so that */
13876 call1 (Qface_set_after_frame_default
, frame
);
13878 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
13879 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
13887 /* It is now ok to make the frame official even if we get an error
13888 below. And the frame needs to be on Vframe_list or making it
13889 visible won't work. */
13890 Vframe_list
= Fcons (frame
, Vframe_list
);
13892 /* Now that the frame is official, it counts as a reference to
13894 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
13896 /* Setting attributes of faces of the tooltip frame from resources
13897 and similar will increment face_change_count, which leads to the
13898 clearing of all current matrices. Since this isn't necessary
13899 here, avoid it by resetting face_change_count to the value it
13900 had before we created the tip frame. */
13901 face_change_count
= face_change_count_before
;
13903 /* Discard the unwind_protect. */
13904 return unbind_to (count
, frame
);
13908 /* Compute where to display tip frame F. PARMS is the list of frame
13909 parameters for F. DX and DY are specified offsets from the current
13910 location of the mouse. WIDTH and HEIGHT are the width and height
13911 of the tooltip. Return coordinates relative to the root window of
13912 the display in *ROOT_X, and *ROOT_Y. */
13915 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
13917 Lisp_Object parms
, dx
, dy
;
13919 int *root_x
, *root_y
;
13921 Lisp_Object left
, top
;
13923 /* User-specified position? */
13924 left
= Fcdr (Fassq (Qleft
, parms
));
13925 top
= Fcdr (Fassq (Qtop
, parms
));
13927 /* Move the tooltip window where the mouse pointer is. Resize and
13929 if (!INTEGERP (left
) || !INTEGERP (top
))
13934 GetCursorPos (&pt
);
13940 if (INTEGERP (top
))
13941 *root_y
= XINT (top
);
13942 else if (*root_y
+ XINT (dy
) - height
< 0)
13943 *root_y
-= XINT (dy
);
13947 *root_y
+= XINT (dy
);
13950 if (INTEGERP (left
))
13951 *root_x
= XINT (left
);
13952 else if (*root_x
+ XINT (dx
) + width
<= FRAME_W32_DISPLAY_INFO (f
)->width
)
13953 /* It fits to the right of the pointer. */
13954 *root_x
+= XINT (dx
);
13955 else if (width
+ XINT (dx
) <= *root_x
)
13956 /* It fits to the left of the pointer. */
13957 *root_x
-= width
+ XINT (dx
);
13959 /* Put it left justified on the screen -- it ought to fit that way. */
13964 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
13965 doc
: /* Show STRING in a \"tooltip\" window on frame FRAME.
13966 A tooltip window is a small window displaying a string.
13968 FRAME nil or omitted means use the selected frame.
13970 PARMS is an optional list of frame parameters which can be
13971 used to change the tooltip's appearance.
13973 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
13974 means use the default timeout of 5 seconds.
13976 If the list of frame parameters PARAMS contains a `left' parameter,
13977 the tooltip is displayed at that x-position. Otherwise it is
13978 displayed at the mouse position, with offset DX added (default is 5 if
13979 DX isn't specified). Likewise for the y-position; if a `top' frame
13980 parameter is specified, it determines the y-position of the tooltip
13981 window, otherwise it is displayed at the mouse position, with offset
13982 DY added (default is -10).
13984 A tooltip's maximum size is specified by `x-max-tooltip-size'.
13985 Text larger than the specified size is clipped. */)
13986 (string
, frame
, parms
, timeout
, dx
, dy
)
13987 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
13991 int root_x
, root_y
;
13992 struct buffer
*old_buffer
;
13993 struct text_pos pos
;
13994 int i
, width
, height
;
13995 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
13996 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
13997 int count
= BINDING_STACK_SIZE ();
13999 specbind (Qinhibit_redisplay
, Qt
);
14001 GCPRO4 (string
, parms
, frame
, timeout
);
14003 CHECK_STRING (string
);
14004 f
= check_x_frame (frame
);
14005 if (NILP (timeout
))
14006 timeout
= make_number (5);
14008 CHECK_NATNUM (timeout
);
14011 dx
= make_number (5);
14016 dy
= make_number (-10);
14020 if (NILP (last_show_tip_args
))
14021 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
14023 if (!NILP (tip_frame
))
14025 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
14026 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
14027 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
14029 if (EQ (frame
, last_frame
)
14030 && !NILP (Fequal (last_string
, string
))
14031 && !NILP (Fequal (last_parms
, parms
)))
14033 struct frame
*f
= XFRAME (tip_frame
);
14035 /* Only DX and DY have changed. */
14036 if (!NILP (tip_timer
))
14038 Lisp_Object timer
= tip_timer
;
14040 call1 (Qcancel_timer
, timer
);
14044 compute_tip_xy (f
, parms
, dx
, dy
, PIXEL_WIDTH (f
),
14045 PIXEL_HEIGHT (f
), &root_x
, &root_y
);
14047 /* Put tooltip in topmost group and in position. */
14048 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
14049 root_x
, root_y
, 0, 0,
14050 SWP_NOSIZE
| SWP_NOACTIVATE
);
14052 /* Ensure tooltip is on top of other topmost windows (eg menus). */
14053 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
14055 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
14062 /* Hide a previous tip, if any. */
14065 ASET (last_show_tip_args
, 0, string
);
14066 ASET (last_show_tip_args
, 1, frame
);
14067 ASET (last_show_tip_args
, 2, parms
);
14069 /* Add default values to frame parameters. */
14070 if (NILP (Fassq (Qname
, parms
)))
14071 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
14072 if (NILP (Fassq (Qinternal_border_width
, parms
)))
14073 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
14074 if (NILP (Fassq (Qborder_width
, parms
)))
14075 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
14076 if (NILP (Fassq (Qborder_color
, parms
)))
14077 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
14078 if (NILP (Fassq (Qbackground_color
, parms
)))
14079 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
14082 /* Block input until the tip has been fully drawn, to avoid crashes
14083 when drawing tips in menus. */
14086 /* Create a frame for the tooltip, and record it in the global
14087 variable tip_frame. */
14088 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
, string
);
14089 f
= XFRAME (frame
);
14091 /* Set up the frame's root window. */
14092 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
14093 w
->left
= w
->top
= make_number (0);
14095 if (CONSP (Vx_max_tooltip_size
)
14096 && INTEGERP (XCAR (Vx_max_tooltip_size
))
14097 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
14098 && INTEGERP (XCDR (Vx_max_tooltip_size
))
14099 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
14101 w
->width
= XCAR (Vx_max_tooltip_size
);
14102 w
->height
= XCDR (Vx_max_tooltip_size
);
14106 w
->width
= make_number (80);
14107 w
->height
= make_number (40);
14110 f
->window_width
= XINT (w
->width
);
14112 w
->pseudo_window_p
= 1;
14114 /* Display the tooltip text in a temporary buffer. */
14115 old_buffer
= current_buffer
;
14116 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
14117 current_buffer
->truncate_lines
= Qnil
;
14118 clear_glyph_matrix (w
->desired_matrix
);
14119 clear_glyph_matrix (w
->current_matrix
);
14120 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
14121 try_window (FRAME_ROOT_WINDOW (f
), pos
);
14123 /* Compute width and height of the tooltip. */
14124 width
= height
= 0;
14125 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
14127 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
14128 struct glyph
*last
;
14131 /* Stop at the first empty row at the end. */
14132 if (!row
->enabled_p
|| !row
->displays_text_p
)
14135 /* Let the row go over the full width of the frame. */
14136 row
->full_width_p
= 1;
14138 #ifdef TODO /* Investigate why some fonts need more width than is
14139 calculated for some tooltips. */
14140 /* There's a glyph at the end of rows that is use to place
14141 the cursor there. Don't include the width of this glyph. */
14142 if (row
->used
[TEXT_AREA
])
14144 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
14145 row_width
= row
->pixel_width
- last
->pixel_width
;
14149 row_width
= row
->pixel_width
;
14151 /* TODO: find why tips do not draw along baseline as instructed. */
14152 height
+= row
->height
;
14153 width
= max (width
, row_width
);
14156 /* Add the frame's internal border to the width and height the X
14157 window should have. */
14158 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
14159 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
14161 /* Move the tooltip window where the mouse pointer is. Resize and
14163 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
14166 /* Adjust Window size to take border into account. */
14168 rect
.left
= rect
.top
= 0;
14169 rect
.right
= width
;
14170 rect
.bottom
= height
;
14171 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
14172 FRAME_EXTERNAL_MENU_BAR (f
));
14174 /* Position and size tooltip, and put it in the topmost group. */
14175 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOPMOST
,
14176 root_x
, root_y
, rect
.right
- rect
.left
,
14177 rect
.bottom
- rect
.top
, SWP_NOACTIVATE
);
14179 /* Ensure tooltip is on top of other topmost windows (eg menus). */
14180 SetWindowPos (FRAME_W32_WINDOW (f
), HWND_TOP
,
14182 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
14184 /* Let redisplay know that we have made the frame visible already. */
14185 f
->async_visible
= 1;
14187 ShowWindow (FRAME_W32_WINDOW (f
), SW_SHOWNOACTIVATE
);
14190 /* Draw into the window. */
14191 w
->must_be_updated_p
= 1;
14192 update_single_window (w
, 1);
14196 /* Restore original current buffer. */
14197 set_buffer_internal_1 (old_buffer
);
14198 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
14201 /* Let the tip disappear after timeout seconds. */
14202 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
14203 intern ("x-hide-tip"));
14206 return unbind_to (count
, Qnil
);
14210 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
14211 doc
: /* Hide the current tooltip window, if there is any.
14212 Value is t if tooltip was open, nil otherwise. */)
14216 Lisp_Object deleted
, frame
, timer
;
14217 struct gcpro gcpro1
, gcpro2
;
14219 /* Return quickly if nothing to do. */
14220 if (NILP (tip_timer
) && NILP (tip_frame
))
14225 GCPRO2 (frame
, timer
);
14226 tip_frame
= tip_timer
= deleted
= Qnil
;
14228 count
= BINDING_STACK_SIZE ();
14229 specbind (Qinhibit_redisplay
, Qt
);
14230 specbind (Qinhibit_quit
, Qt
);
14233 call1 (Qcancel_timer
, timer
);
14235 if (FRAMEP (frame
))
14237 Fdelete_frame (frame
, Qnil
);
14242 return unbind_to (count
, deleted
);
14247 /***********************************************************************
14248 File selection dialog
14249 ***********************************************************************/
14250 extern Lisp_Object Qfile_name_history
;
14252 /* Callback for altering the behaviour of the Open File dialog.
14253 Makes the Filename text field contain "Current Directory" and be
14254 read-only when "Directories" is selected in the filter. This
14255 allows us to work around the fact that the standard Open File
14256 dialog does not support directories. */
14258 file_dialog_callback (hwnd
, msg
, wParam
, lParam
)
14264 if (msg
== WM_NOTIFY
)
14266 OFNOTIFY
* notify
= (OFNOTIFY
*)lParam
;
14267 /* Detect when the Filter dropdown is changed. */
14268 if (notify
->hdr
.code
== CDN_TYPECHANGE
)
14270 HWND dialog
= GetParent (hwnd
);
14271 HWND edit_control
= GetDlgItem (dialog
, FILE_NAME_TEXT_FIELD
);
14273 /* Directories is in index 2. */
14274 if (notify
->lpOFN
->nFilterIndex
== 2)
14276 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
14277 "Current Directory");
14278 EnableWindow (edit_control
, FALSE
);
14282 CommDlg_OpenSave_SetControlText (dialog
, FILE_NAME_TEXT_FIELD
,
14284 EnableWindow (edit_control
, TRUE
);
14291 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
14292 doc
: /* Read file name, prompting with PROMPT in directory DIR.
14293 Use a file selection dialog.
14294 Select DEFAULT-FILENAME in the dialog's file selection box, if
14295 specified. Ensure that file exists if MUSTMATCH is non-nil. */)
14296 (prompt
, dir
, default_filename
, mustmatch
)
14297 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
14299 struct frame
*f
= SELECTED_FRAME ();
14300 Lisp_Object file
= Qnil
;
14301 int count
= specpdl_ptr
- specpdl
;
14302 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
14303 char filename
[MAX_PATH
+ 1];
14304 char init_dir
[MAX_PATH
+ 1];
14306 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
14307 CHECK_STRING (prompt
);
14308 CHECK_STRING (dir
);
14310 /* Create the dialog with PROMPT as title, using DIR as initial
14311 directory and using "*" as pattern. */
14312 dir
= Fexpand_file_name (dir
, Qnil
);
14313 strncpy (init_dir
, XSTRING (dir
)->data
, MAX_PATH
);
14314 init_dir
[MAX_PATH
] = '\0';
14315 unixtodos_filename (init_dir
);
14317 if (STRINGP (default_filename
))
14319 char *file_name_only
;
14320 char *full_path_name
= XSTRING (default_filename
)->data
;
14322 unixtodos_filename (full_path_name
);
14324 file_name_only
= strrchr (full_path_name
, '\\');
14325 if (!file_name_only
)
14326 file_name_only
= full_path_name
;
14332 strncpy (filename
, file_name_only
, MAX_PATH
);
14333 filename
[MAX_PATH
] = '\0';
14336 filename
[0] = '\0';
14339 OPENFILENAME file_details
;
14341 /* Prevent redisplay. */
14342 specbind (Qinhibit_redisplay
, Qt
);
14345 bzero (&file_details
, sizeof (file_details
));
14346 file_details
.lStructSize
= sizeof (file_details
);
14347 file_details
.hwndOwner
= FRAME_W32_WINDOW (f
);
14348 /* Undocumented Bug in Common File Dialog:
14349 If a filter is not specified, shell links are not resolved. */
14350 file_details
.lpstrFilter
= "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
14351 file_details
.lpstrFile
= filename
;
14352 file_details
.nMaxFile
= sizeof (filename
);
14353 file_details
.lpstrInitialDir
= init_dir
;
14354 file_details
.lpstrTitle
= XSTRING (prompt
)->data
;
14355 file_details
.Flags
= (OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
14356 | OFN_EXPLORER
| OFN_ENABLEHOOK
);
14357 if (!NILP (mustmatch
))
14358 file_details
.Flags
|= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
14360 file_details
.lpfnHook
= (LPOFNHOOKPROC
) file_dialog_callback
;
14362 if (GetOpenFileName (&file_details
))
14364 dostounix_filename (filename
);
14365 if (file_details
.nFilterIndex
== 2)
14367 /* "Folder Only" selected - strip dummy file name. */
14368 char * last
= strrchr (filename
, '/');
14372 file
= DECODE_FILE(build_string (filename
));
14374 /* User cancelled the dialog without making a selection. */
14375 else if (!CommDlgExtendedError ())
14377 /* An error occurred, fallback on reading from the mini-buffer. */
14379 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
14380 dir
, mustmatch
, dir
, Qfile_name_history
,
14381 default_filename
, Qnil
);
14384 file
= unbind_to (count
, file
);
14389 /* Make "Cancel" equivalent to C-g. */
14391 Fsignal (Qquit
, Qnil
);
14393 return unbind_to (count
, file
);
14398 /***********************************************************************
14399 w32 specialized functions
14400 ***********************************************************************/
14402 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 2, 0,
14403 doc
: /* Select a font using the W32 font dialog.
14404 Returns an X font string corresponding to the selection. */)
14405 (frame
, include_proportional
)
14406 Lisp_Object frame
, include_proportional
;
14408 FRAME_PTR f
= check_x_frame (frame
);
14416 bzero (&cf
, sizeof (cf
));
14417 bzero (&lf
, sizeof (lf
));
14419 cf
.lStructSize
= sizeof (cf
);
14420 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
14421 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
14423 /* Unless include_proportional is non-nil, limit the selection to
14424 monospaced fonts. */
14425 if (NILP (include_proportional
))
14426 cf
.Flags
|= CF_FIXEDPITCHONLY
;
14428 cf
.lpLogFont
= &lf
;
14430 /* Initialize as much of the font details as we can from the current
14432 hdc
= GetDC (FRAME_W32_WINDOW (f
));
14433 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
14434 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
14435 if (GetTextMetrics (hdc
, &tm
))
14437 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
14438 lf
.lfWeight
= tm
.tmWeight
;
14439 lf
.lfItalic
= tm
.tmItalic
;
14440 lf
.lfUnderline
= tm
.tmUnderlined
;
14441 lf
.lfStrikeOut
= tm
.tmStruckOut
;
14442 lf
.lfCharSet
= tm
.tmCharSet
;
14443 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
14445 SelectObject (hdc
, oldobj
);
14446 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
14448 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
14451 return build_string (buf
);
14454 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
,
14455 Sw32_send_sys_command
, 1, 2, 0,
14456 doc
: /* Send frame a Windows WM_SYSCOMMAND message of type COMMAND.
14457 Some useful values for command are #xf030 to maximise frame (#xf020
14458 to minimize), #xf120 to restore frame to original size, and #xf100
14459 to activate the menubar for keyboard access. #xf140 activates the
14460 screen saver if defined.
14462 If optional parameter FRAME is not specified, use selected frame. */)
14464 Lisp_Object command
, frame
;
14466 FRAME_PTR f
= check_x_frame (frame
);
14468 CHECK_NUMBER (command
);
14470 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
14475 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
14476 doc
: /* Get Windows to perform OPERATION on DOCUMENT.
14477 This is a wrapper around the ShellExecute system function, which
14478 invokes the application registered to handle OPERATION for DOCUMENT.
14479 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be
14480 nil for the default action), and DOCUMENT is typically the name of a
14481 document file or URL, but can also be a program executable to run or
14482 a directory to open in the Windows Explorer.
14484 If DOCUMENT is a program executable, PARAMETERS can be a string
14485 containing command line parameters, but otherwise should be nil.
14487 SHOW-FLAG can be used to control whether the invoked application is hidden
14488 or minimized. If SHOW-FLAG is nil, the application is displayed normally,
14489 otherwise it is an integer representing a ShowWindow flag:
14493 3 - start maximized
14494 6 - start minimized */)
14495 (operation
, document
, parameters
, show_flag
)
14496 Lisp_Object operation
, document
, parameters
, show_flag
;
14498 Lisp_Object current_dir
;
14500 CHECK_STRING (document
);
14502 /* Encode filename and current directory. */
14503 current_dir
= ENCODE_FILE (current_buffer
->directory
);
14504 document
= ENCODE_FILE (document
);
14505 if ((int) ShellExecute (NULL
,
14506 (STRINGP (operation
) ?
14507 XSTRING (operation
)->data
: NULL
),
14508 XSTRING (document
)->data
,
14509 (STRINGP (parameters
) ?
14510 XSTRING (parameters
)->data
: NULL
),
14511 XSTRING (current_dir
)->data
,
14512 (INTEGERP (show_flag
) ?
14513 XINT (show_flag
) : SW_SHOWDEFAULT
))
14516 error ("ShellExecute failed: %s", w32_strerror (0));
14519 /* Lookup virtual keycode from string representing the name of a
14520 non-ascii keystroke into the corresponding virtual key, using
14521 lispy_function_keys. */
14523 lookup_vk_code (char *key
)
14527 for (i
= 0; i
< 256; i
++)
14528 if (lispy_function_keys
[i
] != 0
14529 && strcmp (lispy_function_keys
[i
], key
) == 0)
14535 /* Convert a one-element vector style key sequence to a hot key
14538 w32_parse_hot_key (key
)
14541 /* Copied from Fdefine_key and store_in_keymap. */
14542 register Lisp_Object c
;
14544 int lisp_modifiers
;
14546 struct gcpro gcpro1
;
14548 CHECK_VECTOR (key
);
14550 if (XFASTINT (Flength (key
)) != 1)
14555 c
= Faref (key
, make_number (0));
14557 if (CONSP (c
) && lucid_event_type_list_p (c
))
14558 c
= Fevent_convert_list (c
);
14562 if (! INTEGERP (c
) && ! SYMBOLP (c
))
14563 error ("Key definition is invalid");
14565 /* Work out the base key and the modifiers. */
14568 c
= parse_modifiers (c
);
14569 lisp_modifiers
= Fcar (Fcdr (c
));
14573 vk_code
= lookup_vk_code (XSTRING (SYMBOL_NAME (c
))->data
);
14575 else if (INTEGERP (c
))
14577 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
14578 /* Many ascii characters are their own virtual key code. */
14579 vk_code
= XINT (c
) & CHARACTERBITS
;
14582 if (vk_code
< 0 || vk_code
> 255)
14585 if ((lisp_modifiers
& meta_modifier
) != 0
14586 && !NILP (Vw32_alt_is_meta
))
14587 lisp_modifiers
|= alt_modifier
;
14589 /* Supply defs missing from mingw32. */
14591 #define MOD_ALT 0x0001
14592 #define MOD_CONTROL 0x0002
14593 #define MOD_SHIFT 0x0004
14594 #define MOD_WIN 0x0008
14597 /* Convert lisp modifiers to Windows hot-key form. */
14598 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
14599 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
14600 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
14601 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
14603 return HOTKEY (vk_code
, w32_modifiers
);
14606 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
,
14607 Sw32_register_hot_key
, 1, 1, 0,
14608 doc
: /* Register KEY as a hot-key combination.
14609 Certain key combinations like Alt-Tab are reserved for system use on
14610 Windows, and therefore are normally intercepted by the system. However,
14611 most of these key combinations can be received by registering them as
14612 hot-keys, overriding their special meaning.
14614 KEY must be a one element key definition in vector form that would be
14615 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta
14616 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper
14617 is always interpreted as the Windows modifier keys.
14619 The return value is the hotkey-id if registered, otherwise nil. */)
14623 key
= w32_parse_hot_key (key
);
14625 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
14627 /* Reuse an empty slot if possible. */
14628 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
14630 /* Safe to add new key to list, even if we have focus. */
14632 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
14634 XSETCAR (item
, key
);
14636 /* Notify input thread about new hot-key definition, so that it
14637 takes effect without needing to switch focus. */
14638 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
14645 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
,
14646 Sw32_unregister_hot_key
, 1, 1, 0,
14647 doc
: /* Unregister HOTKEY as a hot-key combination. */)
14653 if (!INTEGERP (key
))
14654 key
= w32_parse_hot_key (key
);
14656 item
= Fmemq (key
, w32_grabbed_keys
);
14660 /* Notify input thread about hot-key definition being removed, so
14661 that it takes effect without needing focus switch. */
14662 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
14663 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
14666 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
14673 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
,
14674 Sw32_registered_hot_keys
, 0, 0, 0,
14675 doc
: /* Return list of registered hot-key IDs. */)
14678 return Fcopy_sequence (w32_grabbed_keys
);
14681 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
,
14682 Sw32_reconstruct_hot_key
, 1, 1, 0,
14683 doc
: /* Convert hot-key ID to a lisp key combination. */)
14685 Lisp_Object hotkeyid
;
14687 int vk_code
, w32_modifiers
;
14690 CHECK_NUMBER (hotkeyid
);
14692 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
14693 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
14695 if (lispy_function_keys
[vk_code
])
14696 key
= intern (lispy_function_keys
[vk_code
]);
14698 key
= make_number (vk_code
);
14700 key
= Fcons (key
, Qnil
);
14701 if (w32_modifiers
& MOD_SHIFT
)
14702 key
= Fcons (Qshift
, key
);
14703 if (w32_modifiers
& MOD_CONTROL
)
14704 key
= Fcons (Qctrl
, key
);
14705 if (w32_modifiers
& MOD_ALT
)
14706 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
14707 if (w32_modifiers
& MOD_WIN
)
14708 key
= Fcons (Qhyper
, key
);
14713 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
,
14714 Sw32_toggle_lock_key
, 1, 2, 0,
14715 doc
: /* Toggle the state of the lock key KEY.
14716 KEY can be `capslock', `kp-numlock', or `scroll'.
14717 If the optional parameter NEW-STATE is a number, then the state of KEY
14718 is set to off if the low bit of NEW-STATE is zero, otherwise on. */)
14720 Lisp_Object key
, new_state
;
14724 if (EQ (key
, intern ("capslock")))
14725 vk_code
= VK_CAPITAL
;
14726 else if (EQ (key
, intern ("kp-numlock")))
14727 vk_code
= VK_NUMLOCK
;
14728 else if (EQ (key
, intern ("scroll")))
14729 vk_code
= VK_SCROLL
;
14733 if (!dwWindowsThreadId
)
14734 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
14736 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
14737 (WPARAM
) vk_code
, (LPARAM
) new_state
))
14740 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
14741 return make_number (msg
.wParam
);
14746 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
14747 doc
: /* Return storage information about the file system FILENAME is on.
14748 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
14749 storage of the file system, FREE is the free storage, and AVAIL is the
14750 storage available to a non-superuser. All 3 numbers are in bytes.
14751 If the underlying system call fails, value is nil. */)
14753 Lisp_Object filename
;
14755 Lisp_Object encoded
, value
;
14757 CHECK_STRING (filename
);
14758 filename
= Fexpand_file_name (filename
, Qnil
);
14759 encoded
= ENCODE_FILE (filename
);
14763 /* Determining the required information on Windows turns out, sadly,
14764 to be more involved than one would hope. The original Win32 api
14765 call for this will return bogus information on some systems, but we
14766 must dynamically probe for the replacement api, since that was
14767 added rather late on. */
14769 HMODULE hKernel
= GetModuleHandle ("kernel32");
14770 BOOL (*pfn_GetDiskFreeSpaceEx
)
14771 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
14772 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
14774 /* On Windows, we may need to specify the root directory of the
14775 volume holding FILENAME. */
14776 char rootname
[MAX_PATH
];
14777 char *name
= XSTRING (encoded
)->data
;
14779 /* find the root name of the volume if given */
14780 if (isalpha (name
[0]) && name
[1] == ':')
14782 rootname
[0] = name
[0];
14783 rootname
[1] = name
[1];
14784 rootname
[2] = '\\';
14787 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
14789 char *str
= rootname
;
14793 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
14803 if (pfn_GetDiskFreeSpaceEx
)
14805 /* Unsigned large integers cannot be cast to double, so
14806 use signed ones instead. */
14807 LARGE_INTEGER availbytes
;
14808 LARGE_INTEGER freebytes
;
14809 LARGE_INTEGER totalbytes
;
14811 if (pfn_GetDiskFreeSpaceEx(rootname
,
14812 (ULARGE_INTEGER
*)&availbytes
,
14813 (ULARGE_INTEGER
*)&totalbytes
,
14814 (ULARGE_INTEGER
*)&freebytes
))
14815 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
14816 make_float ((double) freebytes
.QuadPart
),
14817 make_float ((double) availbytes
.QuadPart
));
14821 DWORD sectors_per_cluster
;
14822 DWORD bytes_per_sector
;
14823 DWORD free_clusters
;
14824 DWORD total_clusters
;
14826 if (GetDiskFreeSpace(rootname
,
14827 §ors_per_cluster
,
14831 value
= list3 (make_float ((double) total_clusters
14832 * sectors_per_cluster
* bytes_per_sector
),
14833 make_float ((double) free_clusters
14834 * sectors_per_cluster
* bytes_per_sector
),
14835 make_float ((double) free_clusters
14836 * sectors_per_cluster
* bytes_per_sector
));
14843 /***********************************************************************
14845 ***********************************************************************/
14850 HMODULE user32_lib
= GetModuleHandle ("user32.dll");
14852 /* This is zero if not using MS-Windows. */
14855 /* TrackMouseEvent not available in all versions of Windows, so must load
14856 it dynamically. Do it once, here, instead of every time it is used. */
14857 track_mouse_event_fn
= GetProcAddress (user32_lib
, "TrackMouseEvent");
14858 track_mouse_window
= NULL
;
14860 w32_visible_system_caret_hwnd
= NULL
;
14862 Qauto_raise
= intern ("auto-raise");
14863 staticpro (&Qauto_raise
);
14864 Qauto_lower
= intern ("auto-lower");
14865 staticpro (&Qauto_lower
);
14866 Qbar
= intern ("bar");
14868 Qhbar
= intern ("hbar");
14869 staticpro (&Qhbar
);
14870 Qborder_color
= intern ("border-color");
14871 staticpro (&Qborder_color
);
14872 Qborder_width
= intern ("border-width");
14873 staticpro (&Qborder_width
);
14874 Qbox
= intern ("box");
14876 Qcursor_color
= intern ("cursor-color");
14877 staticpro (&Qcursor_color
);
14878 Qcursor_type
= intern ("cursor-type");
14879 staticpro (&Qcursor_type
);
14880 Qgeometry
= intern ("geometry");
14881 staticpro (&Qgeometry
);
14882 Qicon_left
= intern ("icon-left");
14883 staticpro (&Qicon_left
);
14884 Qicon_top
= intern ("icon-top");
14885 staticpro (&Qicon_top
);
14886 Qicon_type
= intern ("icon-type");
14887 staticpro (&Qicon_type
);
14888 Qicon_name
= intern ("icon-name");
14889 staticpro (&Qicon_name
);
14890 Qinternal_border_width
= intern ("internal-border-width");
14891 staticpro (&Qinternal_border_width
);
14892 Qleft
= intern ("left");
14893 staticpro (&Qleft
);
14894 Qright
= intern ("right");
14895 staticpro (&Qright
);
14896 Qmouse_color
= intern ("mouse-color");
14897 staticpro (&Qmouse_color
);
14898 Qnone
= intern ("none");
14899 staticpro (&Qnone
);
14900 Qparent_id
= intern ("parent-id");
14901 staticpro (&Qparent_id
);
14902 Qscroll_bar_width
= intern ("scroll-bar-width");
14903 staticpro (&Qscroll_bar_width
);
14904 Qsuppress_icon
= intern ("suppress-icon");
14905 staticpro (&Qsuppress_icon
);
14906 Qundefined_color
= intern ("undefined-color");
14907 staticpro (&Qundefined_color
);
14908 Qvertical_scroll_bars
= intern ("vertical-scroll-bars");
14909 staticpro (&Qvertical_scroll_bars
);
14910 Qvisibility
= intern ("visibility");
14911 staticpro (&Qvisibility
);
14912 Qwindow_id
= intern ("window-id");
14913 staticpro (&Qwindow_id
);
14914 Qx_frame_parameter
= intern ("x-frame-parameter");
14915 staticpro (&Qx_frame_parameter
);
14916 Qx_resource_name
= intern ("x-resource-name");
14917 staticpro (&Qx_resource_name
);
14918 Quser_position
= intern ("user-position");
14919 staticpro (&Quser_position
);
14920 Quser_size
= intern ("user-size");
14921 staticpro (&Quser_size
);
14922 Qscreen_gamma
= intern ("screen-gamma");
14923 staticpro (&Qscreen_gamma
);
14924 Qline_spacing
= intern ("line-spacing");
14925 staticpro (&Qline_spacing
);
14926 Qcenter
= intern ("center");
14927 staticpro (&Qcenter
);
14928 Qcancel_timer
= intern ("cancel-timer");
14929 staticpro (&Qcancel_timer
);
14930 Qfullscreen
= intern ("fullscreen");
14931 staticpro (&Qfullscreen
);
14932 Qfullwidth
= intern ("fullwidth");
14933 staticpro (&Qfullwidth
);
14934 Qfullheight
= intern ("fullheight");
14935 staticpro (&Qfullheight
);
14936 Qfullboth
= intern ("fullboth");
14937 staticpro (&Qfullboth
);
14939 Qhyper
= intern ("hyper");
14940 staticpro (&Qhyper
);
14941 Qsuper
= intern ("super");
14942 staticpro (&Qsuper
);
14943 Qmeta
= intern ("meta");
14944 staticpro (&Qmeta
);
14945 Qalt
= intern ("alt");
14947 Qctrl
= intern ("ctrl");
14948 staticpro (&Qctrl
);
14949 Qcontrol
= intern ("control");
14950 staticpro (&Qcontrol
);
14951 Qshift
= intern ("shift");
14952 staticpro (&Qshift
);
14953 /* This is the end of symbol initialization. */
14955 /* Text property `display' should be nonsticky by default. */
14956 Vtext_property_default_nonsticky
14957 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
14960 Qlaplace
= intern ("laplace");
14961 staticpro (&Qlaplace
);
14962 Qemboss
= intern ("emboss");
14963 staticpro (&Qemboss
);
14964 Qedge_detection
= intern ("edge-detection");
14965 staticpro (&Qedge_detection
);
14966 Qheuristic
= intern ("heuristic");
14967 staticpro (&Qheuristic
);
14968 QCmatrix
= intern (":matrix");
14969 staticpro (&QCmatrix
);
14970 QCcolor_adjustment
= intern (":color-adjustment");
14971 staticpro (&QCcolor_adjustment
);
14972 QCmask
= intern (":mask");
14973 staticpro (&QCmask
);
14975 Qface_set_after_frame_default
= intern ("face-set-after-frame-default");
14976 staticpro (&Qface_set_after_frame_default
);
14978 Fput (Qundefined_color
, Qerror_conditions
,
14979 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
14980 Fput (Qundefined_color
, Qerror_message
,
14981 build_string ("Undefined color"));
14983 staticpro (&w32_grabbed_keys
);
14984 w32_grabbed_keys
= Qnil
;
14986 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
14987 doc
: /* An array of color name mappings for windows. */);
14988 Vw32_color_map
= Qnil
;
14990 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
14991 doc
: /* Non-nil if alt key presses are passed on to Windows.
14992 When non-nil, for example, alt pressed and released and then space will
14993 open the System menu. When nil, Emacs silently swallows alt key events. */);
14994 Vw32_pass_alt_to_system
= Qnil
;
14996 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
14997 doc
: /* Non-nil if the alt key is to be considered the same as the meta key.
14998 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta. */);
14999 Vw32_alt_is_meta
= Qt
;
15001 DEFVAR_INT ("w32-quit-key", &Vw32_quit_key
,
15002 doc
: /* If non-zero, the virtual key code for an alternative quit key. */);
15003 XSETINT (Vw32_quit_key
, 0);
15005 DEFVAR_LISP ("w32-pass-lwindow-to-system",
15006 &Vw32_pass_lwindow_to_system
,
15007 doc
: /* Non-nil if the left \"Windows\" key is passed on to Windows.
15008 When non-nil, the Start menu is opened by tapping the key. */);
15009 Vw32_pass_lwindow_to_system
= Qt
;
15011 DEFVAR_LISP ("w32-pass-rwindow-to-system",
15012 &Vw32_pass_rwindow_to_system
,
15013 doc
: /* Non-nil if the right \"Windows\" key is passed on to Windows.
15014 When non-nil, the Start menu is opened by tapping the key. */);
15015 Vw32_pass_rwindow_to_system
= Qt
;
15017 DEFVAR_INT ("w32-phantom-key-code",
15018 &Vw32_phantom_key_code
,
15019 doc
: /* Virtual key code used to generate \"phantom\" key presses.
15020 Value is a number between 0 and 255.
15022 Phantom key presses are generated in order to stop the system from
15023 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or
15024 `w32-pass-rwindow-to-system' is nil. */);
15025 /* Although 255 is technically not a valid key code, it works and
15026 means that this hack won't interfere with any real key code. */
15027 Vw32_phantom_key_code
= 255;
15029 DEFVAR_LISP ("w32-enable-num-lock",
15030 &Vw32_enable_num_lock
,
15031 doc
: /* Non-nil if Num Lock should act normally.
15032 Set to nil to see Num Lock as the key `kp-numlock'. */);
15033 Vw32_enable_num_lock
= Qt
;
15035 DEFVAR_LISP ("w32-enable-caps-lock",
15036 &Vw32_enable_caps_lock
,
15037 doc
: /* Non-nil if Caps Lock should act normally.
15038 Set to nil to see Caps Lock as the key `capslock'. */);
15039 Vw32_enable_caps_lock
= Qt
;
15041 DEFVAR_LISP ("w32-scroll-lock-modifier",
15042 &Vw32_scroll_lock_modifier
,
15043 doc
: /* Modifier to use for the Scroll Lock on state.
15044 The value can be hyper, super, meta, alt, control or shift for the
15045 respective modifier, or nil to see Scroll Lock as the key `scroll'.
15046 Any other value will cause the key to be ignored. */);
15047 Vw32_scroll_lock_modifier
= Qt
;
15049 DEFVAR_LISP ("w32-lwindow-modifier",
15050 &Vw32_lwindow_modifier
,
15051 doc
: /* Modifier to use for the left \"Windows\" key.
15052 The value can be hyper, super, meta, alt, control or shift for the
15053 respective modifier, or nil to appear as the key `lwindow'.
15054 Any other value will cause the key to be ignored. */);
15055 Vw32_lwindow_modifier
= Qnil
;
15057 DEFVAR_LISP ("w32-rwindow-modifier",
15058 &Vw32_rwindow_modifier
,
15059 doc
: /* Modifier to use for the right \"Windows\" key.
15060 The value can be hyper, super, meta, alt, control or shift for the
15061 respective modifier, or nil to appear as the key `rwindow'.
15062 Any other value will cause the key to be ignored. */);
15063 Vw32_rwindow_modifier
= Qnil
;
15065 DEFVAR_LISP ("w32-apps-modifier",
15066 &Vw32_apps_modifier
,
15067 doc
: /* Modifier to use for the \"Apps\" key.
15068 The value can be hyper, super, meta, alt, control or shift for the
15069 respective modifier, or nil to appear as the key `apps'.
15070 Any other value will cause the key to be ignored. */);
15071 Vw32_apps_modifier
= Qnil
;
15073 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
15074 doc
: /* Non-nil enables selection of artificially italicized and bold fonts. */);
15075 w32_enable_synthesized_fonts
= 0;
15077 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
15078 doc
: /* Non-nil enables Windows palette management to map colors exactly. */);
15079 Vw32_enable_palette
= Qt
;
15081 DEFVAR_INT ("w32-mouse-button-tolerance",
15082 &Vw32_mouse_button_tolerance
,
15083 doc
: /* Analogue of double click interval for faking middle mouse events.
15084 The value is the minimum time in milliseconds that must elapse between
15085 left/right button down events before they are considered distinct events.
15086 If both mouse buttons are depressed within this interval, a middle mouse
15087 button down event is generated instead. */);
15088 XSETINT (Vw32_mouse_button_tolerance
, GetDoubleClickTime () / 2);
15090 DEFVAR_INT ("w32-mouse-move-interval",
15091 &Vw32_mouse_move_interval
,
15092 doc
: /* Minimum interval between mouse move events.
15093 The value is the minimum time in milliseconds that must elapse between
15094 successive mouse move (or scroll bar drag) events before they are
15095 reported as lisp events. */);
15096 XSETINT (Vw32_mouse_move_interval
, 0);
15098 DEFVAR_BOOL ("w32-pass-extra-mouse-buttons-to-system",
15099 &w32_pass_extra_mouse_buttons_to_system
,
15100 doc
: /* Non-nil if the fourth and fifth mouse buttons are passed to Windows.
15101 Recent versions of Windows support mice with up to five buttons.
15102 Since most applications don't support these extra buttons, most mouse
15103 drivers will allow you to map them to functions at the system level.
15104 If this variable is non-nil, Emacs will pass them on, allowing the
15105 system to handle them. */);
15106 w32_pass_extra_mouse_buttons_to_system
= 0;
15108 init_x_parm_symbols ();
15110 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
15111 doc
: /* List of directories to search for bitmap files for w32. */);
15112 Vx_bitmap_file_path
= decode_env_path ((char *) 0, "PATH");
15114 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
15115 doc
: /* The shape of the pointer when over text.
15116 Changing the value does not affect existing frames
15117 unless you set the mouse color. */);
15118 Vx_pointer_shape
= Qnil
;
15120 DEFVAR_LISP ("x-resource-name", &Vx_resource_name
,
15121 doc
: /* The name Emacs uses to look up resources; for internal use only.
15122 `x-get-resource' uses this as the first component of the instance name
15123 when requesting resource values.
15124 Emacs initially sets `x-resource-name' to the name under which Emacs
15125 was invoked, or to the value specified with the `-name' or `-rn'
15126 switches, if present. */);
15127 Vx_resource_name
= Qnil
;
15129 Vx_nontext_pointer_shape
= Qnil
;
15131 Vx_mode_pointer_shape
= Qnil
;
15133 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
15134 doc
: /* The shape of the pointer when Emacs is busy.
15135 This variable takes effect when you create a new frame
15136 or when you set the mouse color. */);
15137 Vx_hourglass_pointer_shape
= Qnil
;
15139 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
15140 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
15141 display_hourglass_p
= 1;
15143 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
15144 doc
: /* *Seconds to wait before displaying an hourglass pointer.
15145 Value must be an integer or float. */);
15146 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
15148 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
15149 &Vx_sensitive_text_pointer_shape
,
15150 doc
: /* The shape of the pointer when over mouse-sensitive text.
15151 This variable takes effect when you create a new frame
15152 or when you set the mouse color. */);
15153 Vx_sensitive_text_pointer_shape
= Qnil
;
15155 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
15156 &Vx_window_horizontal_drag_shape
,
15157 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
15158 This variable takes effect when you create a new frame
15159 or when you set the mouse color. */);
15160 Vx_window_horizontal_drag_shape
= Qnil
;
15162 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
15163 doc
: /* A string indicating the foreground color of the cursor box. */);
15164 Vx_cursor_fore_pixel
= Qnil
;
15166 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
15167 doc
: /* Maximum size for tooltips.
15168 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
15169 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
15171 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
15172 doc
: /* Non-nil if no window manager is in use.
15173 Emacs doesn't try to figure this out; this is always nil
15174 unless you set it to something else. */);
15175 /* We don't have any way to find this out, so set it to nil
15176 and maybe the user would like to set it to t. */
15177 Vx_no_window_manager
= Qnil
;
15179 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
15180 &Vx_pixel_size_width_font_regexp
,
15181 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
15183 Since Emacs gets width of a font matching with this regexp from
15184 PIXEL_SIZE field of the name, font finding mechanism gets faster for
15185 such a font. This is especially effective for such large fonts as
15186 Chinese, Japanese, and Korean. */);
15187 Vx_pixel_size_width_font_regexp
= Qnil
;
15189 DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay
,
15190 doc
: /* Time after which cached images are removed from the cache.
15191 When an image has not been displayed this many seconds, remove it
15192 from the image cache. Value must be an integer or nil with nil
15193 meaning don't clear the cache. */);
15194 Vimage_cache_eviction_delay
= make_number (30 * 60);
15196 DEFVAR_LISP ("w32-bdf-filename-alist",
15197 &Vw32_bdf_filename_alist
,
15198 doc
: /* List of bdf fonts and their corresponding filenames. */);
15199 Vw32_bdf_filename_alist
= Qnil
;
15201 DEFVAR_BOOL ("w32-strict-fontnames",
15202 &w32_strict_fontnames
,
15203 doc
: /* Non-nil means only use fonts that are exact matches for those requested.
15204 Default is nil, which allows old fontnames that are not XLFD compliant,
15205 and allows third-party CJK display to work by specifying false charset
15206 fields to trick Emacs into translating to Big5, SJIS etc.
15207 Setting this to t will prevent wrong fonts being selected when
15208 fontsets are automatically created. */);
15209 w32_strict_fontnames
= 0;
15211 DEFVAR_BOOL ("w32-strict-painting",
15212 &w32_strict_painting
,
15213 doc
: /* Non-nil means use strict rules for repainting frames.
15214 Set this to nil to get the old behaviour for repainting; this should
15215 only be necessary if the default setting causes problems. */);
15216 w32_strict_painting
= 1;
15218 DEFVAR_LISP ("w32-charset-info-alist",
15219 &Vw32_charset_info_alist
,
15220 doc
: /* Alist linking Emacs character sets to Windows fonts and codepages.
15221 Each entry should be of the form:
15223 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))
15225 where CHARSET_NAME is a string used in font names to identify the charset,
15226 WINDOWS_CHARSET is a symbol that can be one of:
15227 w32-charset-ansi, w32-charset-default, w32-charset-symbol,
15228 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,
15229 w32-charset-chinesebig5,
15230 #ifdef JOHAB_CHARSET
15231 w32-charset-johab, w32-charset-hebrew,
15232 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,
15233 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,
15234 w32-charset-russian, w32-charset-mac, w32-charset-baltic,
15236 #ifdef UNICODE_CHARSET
15237 w32-charset-unicode,
15239 or w32-charset-oem.
15240 CODEPAGE should be an integer specifying the codepage that should be used
15241 to display the character set, t to do no translation and output as Unicode,
15242 or nil to do no translation and output as 8 bit (or multibyte on far-east
15243 versions of Windows) characters. */);
15244 Vw32_charset_info_alist
= Qnil
;
15246 staticpro (&Qw32_charset_ansi
);
15247 Qw32_charset_ansi
= intern ("w32-charset-ansi");
15248 staticpro (&Qw32_charset_symbol
);
15249 Qw32_charset_symbol
= intern ("w32-charset-symbol");
15250 staticpro (&Qw32_charset_shiftjis
);
15251 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
15252 staticpro (&Qw32_charset_hangeul
);
15253 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
15254 staticpro (&Qw32_charset_chinesebig5
);
15255 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
15256 staticpro (&Qw32_charset_gb2312
);
15257 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
15258 staticpro (&Qw32_charset_oem
);
15259 Qw32_charset_oem
= intern ("w32-charset-oem");
15261 #ifdef JOHAB_CHARSET
15263 static int w32_extra_charsets_defined
= 1;
15264 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
,
15265 doc
: /* Internal variable. */);
15267 staticpro (&Qw32_charset_johab
);
15268 Qw32_charset_johab
= intern ("w32-charset-johab");
15269 staticpro (&Qw32_charset_easteurope
);
15270 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
15271 staticpro (&Qw32_charset_turkish
);
15272 Qw32_charset_turkish
= intern ("w32-charset-turkish");
15273 staticpro (&Qw32_charset_baltic
);
15274 Qw32_charset_baltic
= intern ("w32-charset-baltic");
15275 staticpro (&Qw32_charset_russian
);
15276 Qw32_charset_russian
= intern ("w32-charset-russian");
15277 staticpro (&Qw32_charset_arabic
);
15278 Qw32_charset_arabic
= intern ("w32-charset-arabic");
15279 staticpro (&Qw32_charset_greek
);
15280 Qw32_charset_greek
= intern ("w32-charset-greek");
15281 staticpro (&Qw32_charset_hebrew
);
15282 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
15283 staticpro (&Qw32_charset_vietnamese
);
15284 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
15285 staticpro (&Qw32_charset_thai
);
15286 Qw32_charset_thai
= intern ("w32-charset-thai");
15287 staticpro (&Qw32_charset_mac
);
15288 Qw32_charset_mac
= intern ("w32-charset-mac");
15292 #ifdef UNICODE_CHARSET
15294 static int w32_unicode_charset_defined
= 1;
15295 DEFVAR_BOOL ("w32-unicode-charset-defined",
15296 &w32_unicode_charset_defined
,
15297 doc
: /* Internal variable. */);
15299 staticpro (&Qw32_charset_unicode
);
15300 Qw32_charset_unicode
= intern ("w32-charset-unicode");
15303 defsubr (&Sx_get_resource
);
15304 #if 0 /* TODO: Port to W32 */
15305 defsubr (&Sx_change_window_property
);
15306 defsubr (&Sx_delete_window_property
);
15307 defsubr (&Sx_window_property
);
15309 defsubr (&Sxw_display_color_p
);
15310 defsubr (&Sx_display_grayscale_p
);
15311 defsubr (&Sxw_color_defined_p
);
15312 defsubr (&Sxw_color_values
);
15313 defsubr (&Sx_server_max_request_size
);
15314 defsubr (&Sx_server_vendor
);
15315 defsubr (&Sx_server_version
);
15316 defsubr (&Sx_display_pixel_width
);
15317 defsubr (&Sx_display_pixel_height
);
15318 defsubr (&Sx_display_mm_width
);
15319 defsubr (&Sx_display_mm_height
);
15320 defsubr (&Sx_display_screens
);
15321 defsubr (&Sx_display_planes
);
15322 defsubr (&Sx_display_color_cells
);
15323 defsubr (&Sx_display_visual_class
);
15324 defsubr (&Sx_display_backing_store
);
15325 defsubr (&Sx_display_save_under
);
15326 defsubr (&Sx_parse_geometry
);
15327 defsubr (&Sx_create_frame
);
15328 defsubr (&Sx_open_connection
);
15329 defsubr (&Sx_close_connection
);
15330 defsubr (&Sx_display_list
);
15331 defsubr (&Sx_synchronize
);
15333 /* W32 specific functions */
15335 defsubr (&Sw32_focus_frame
);
15336 defsubr (&Sw32_select_font
);
15337 defsubr (&Sw32_define_rgb_color
);
15338 defsubr (&Sw32_default_color_map
);
15339 defsubr (&Sw32_load_color_file
);
15340 defsubr (&Sw32_send_sys_command
);
15341 defsubr (&Sw32_shell_execute
);
15342 defsubr (&Sw32_register_hot_key
);
15343 defsubr (&Sw32_unregister_hot_key
);
15344 defsubr (&Sw32_registered_hot_keys
);
15345 defsubr (&Sw32_reconstruct_hot_key
);
15346 defsubr (&Sw32_toggle_lock_key
);
15347 defsubr (&Sw32_find_bdf_fonts
);
15349 defsubr (&Sfile_system_info
);
15351 /* Setting callback functions for fontset handler. */
15352 get_font_info_func
= w32_get_font_info
;
15354 #if 0 /* This function pointer doesn't seem to be used anywhere.
15355 And the pointer assigned has the wrong type, anyway. */
15356 list_fonts_func
= w32_list_fonts
;
15359 load_font_func
= w32_load_font
;
15360 find_ccl_program_func
= w32_find_ccl_program
;
15361 query_font_func
= w32_query_font
;
15362 set_frame_fontset_func
= x_set_font
;
15363 check_window_system_func
= check_w32
;
15366 Qxbm
= intern ("xbm");
15368 QCconversion
= intern (":conversion");
15369 staticpro (&QCconversion
);
15370 QCheuristic_mask
= intern (":heuristic-mask");
15371 staticpro (&QCheuristic_mask
);
15372 QCcolor_symbols
= intern (":color-symbols");
15373 staticpro (&QCcolor_symbols
);
15374 QCascent
= intern (":ascent");
15375 staticpro (&QCascent
);
15376 QCmargin
= intern (":margin");
15377 staticpro (&QCmargin
);
15378 QCrelief
= intern (":relief");
15379 staticpro (&QCrelief
);
15380 Qpostscript
= intern ("postscript");
15381 staticpro (&Qpostscript
);
15382 #if 0 /* TODO: These need entries at top of file. */
15383 QCloader
= intern (":loader");
15384 staticpro (&QCloader
);
15385 QCbounding_box
= intern (":bounding-box");
15386 staticpro (&QCbounding_box
);
15387 QCpt_width
= intern (":pt-width");
15388 staticpro (&QCpt_width
);
15389 QCpt_height
= intern (":pt-height");
15390 staticpro (&QCpt_height
);
15392 QCindex
= intern (":index");
15393 staticpro (&QCindex
);
15394 Qpbm
= intern ("pbm");
15398 Qxpm
= intern ("xpm");
15403 Qjpeg
= intern ("jpeg");
15404 staticpro (&Qjpeg
);
15408 Qtiff
= intern ("tiff");
15409 staticpro (&Qtiff
);
15413 Qgif
= intern ("gif");
15418 Qpng
= intern ("png");
15422 defsubr (&Sclear_image_cache
);
15423 defsubr (&Simage_size
);
15424 defsubr (&Simage_mask_p
);
15427 defsubr (&Simagep
);
15428 defsubr (&Slookup_image
);
15431 hourglass_atimer
= NULL
;
15432 hourglass_shown_p
= 0;
15433 defsubr (&Sx_show_tip
);
15434 defsubr (&Sx_hide_tip
);
15436 staticpro (&tip_timer
);
15438 staticpro (&tip_frame
);
15440 last_show_tip_args
= Qnil
;
15441 staticpro (&last_show_tip_args
);
15443 defsubr (&Sx_file_dialog
);
15450 image_types
= NULL
;
15451 Vimage_types
= Qnil
;
15453 define_image_type (&pbm_type
);
15454 define_image_type (&xbm_type
);
15455 #if 0 /* TODO : Image support for W32 */
15456 define_image_type (&gs_type
);
15460 define_image_type (&xpm_type
);
15464 define_image_type (&jpeg_type
);
15468 define_image_type (&tiff_type
);
15472 define_image_type (&gif_type
);
15476 define_image_type (&png_type
);
15486 button
= MessageBox (NULL
,
15487 "A fatal error has occurred!\n\n"
15488 "Select Abort to exit, Retry to debug, Ignore to continue",
15489 "Emacs Abort Dialog",
15490 MB_ICONEXCLAMATION
| MB_TASKMODAL
15491 | MB_SETFOREGROUND
| MB_ABORTRETRYIGNORE
);
15506 /* For convenience when debugging. */
15510 return GetLastError ();