1 /* Graphical user interface functions for the Microsoft W32 API.
2 Copyright (C) 1989, 92, 93, 94, 95, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Added by Kevin Gallo */
33 #include "dispextern.h"
40 #include "intervals.h"
41 #include "blockinput.h"
44 #include "termhooks.h"
49 #include "bitmaps/gray.xbm"
55 #define min(a, b) ((a) < (b) ? (a) : (b))
56 #define max(a, b) ((a) > (b) ? (a) : (b))
58 extern void free_frame_menubar ();
59 extern double atof ();
60 extern int w32_console_toggle_lock_key (int vk_code
, Lisp_Object new_state
);
63 /* A definition of XColor for non-X frames. */
64 #ifndef HAVE_X_WINDOWS
67 unsigned short red
, green
, blue
;
73 extern char *lispy_function_keys
[];
75 /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses
76 it, and including `bitmaps/gray' more than once is a problem when
77 config.h defines `static' as an empty replacement string. */
79 int gray_bitmap_width
= gray_width
;
80 int gray_bitmap_height
= gray_height
;
81 unsigned char *gray_bitmap_bits
= gray_bits
;
83 /* The colormap for converting color names to RGB values */
84 Lisp_Object Vw32_color_map
;
86 /* Non nil if alt key presses are passed on to Windows. */
87 Lisp_Object Vw32_pass_alt_to_system
;
89 /* Non nil if alt key is translated to meta_modifier, nil if it is translated
91 Lisp_Object Vw32_alt_is_meta
;
93 /* If non-zero, the windows virtual key code for an alternative quit key. */
94 Lisp_Object Vw32_quit_key
;
96 /* Non nil if left window key events are passed on to Windows (this only
97 affects whether "tapping" the key opens the Start menu). */
98 Lisp_Object Vw32_pass_lwindow_to_system
;
100 /* Non nil if right window key events are passed on to Windows (this
101 only affects whether "tapping" the key opens the Start menu). */
102 Lisp_Object Vw32_pass_rwindow_to_system
;
104 /* Virtual key code used to generate "phantom" key presses in order
105 to stop system from acting on Windows key events. */
106 Lisp_Object Vw32_phantom_key_code
;
108 /* Modifier associated with the left "Windows" key, or nil to act as a
110 Lisp_Object Vw32_lwindow_modifier
;
112 /* Modifier associated with the right "Windows" key, or nil to act as a
114 Lisp_Object Vw32_rwindow_modifier
;
116 /* Modifier associated with the "Apps" key, or nil to act as a normal
118 Lisp_Object Vw32_apps_modifier
;
120 /* Value is nil if Num Lock acts as a function key. */
121 Lisp_Object Vw32_enable_num_lock
;
123 /* Value is nil if Caps Lock acts as a function key. */
124 Lisp_Object Vw32_enable_caps_lock
;
126 /* Modifier associated with Scroll Lock, or nil to act as a normal key. */
127 Lisp_Object Vw32_scroll_lock_modifier
;
129 /* Switch to control whether we inhibit requests for synthesized bold
130 and italic versions of fonts. */
131 int w32_enable_synthesized_fonts
;
133 /* Enable palette management. */
134 Lisp_Object Vw32_enable_palette
;
136 /* Control how close left/right button down events must be to
137 be converted to a middle button down event. */
138 Lisp_Object Vw32_mouse_button_tolerance
;
140 /* Minimum interval between mouse movement (and scroll bar drag)
141 events that are passed on to the event loop. */
142 Lisp_Object Vw32_mouse_move_interval
;
144 /* The name we're using in resource queries. */
145 Lisp_Object Vx_resource_name
;
147 /* Non nil if no window manager is in use. */
148 Lisp_Object Vx_no_window_manager
;
150 /* Non-zero means we're allowed to display a hourglass pointer. */
152 int display_hourglass_p
;
154 /* The background and shape of the mouse pointer, and shape when not
155 over text or in the modeline. */
157 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
158 Lisp_Object Vx_hourglass_pointer_shape
, Vx_window_horizontal_drag_shape
;
160 /* The shape when over mouse-sensitive text. */
162 Lisp_Object Vx_sensitive_text_pointer_shape
;
164 /* Color of chars displayed in cursor box. */
166 Lisp_Object Vx_cursor_fore_pixel
;
168 /* Nonzero if using Windows. */
170 static int w32_in_use
;
172 /* Search path for bitmap files. */
174 Lisp_Object Vx_bitmap_file_path
;
176 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
178 Lisp_Object Vx_pixel_size_width_font_regexp
;
180 /* Alist of bdf fonts and the files that define them. */
181 Lisp_Object Vw32_bdf_filename_alist
;
183 Lisp_Object Vw32_system_coding_system
;
185 /* A flag to control whether fonts are matched strictly or not. */
186 int w32_strict_fontnames
;
188 /* A flag to control whether we should only repaint if GetUpdateRect
189 indicates there is an update region. */
190 int w32_strict_painting
;
192 /* Associative list linking character set strings to Windows codepages. */
193 Lisp_Object Vw32_charset_info_alist
;
195 /* VIETNAMESE_CHARSET is not defined in some versions of MSVC. */
196 #ifndef VIETNAMESE_CHARSET
197 #define VIETNAMESE_CHARSET 163
200 Lisp_Object Qauto_raise
;
201 Lisp_Object Qauto_lower
;
203 Lisp_Object Qborder_color
;
204 Lisp_Object Qborder_width
;
206 Lisp_Object Qcursor_color
;
207 Lisp_Object Qcursor_type
;
208 Lisp_Object Qgeometry
;
209 Lisp_Object Qicon_left
;
210 Lisp_Object Qicon_top
;
211 Lisp_Object Qicon_type
;
212 Lisp_Object Qicon_name
;
213 Lisp_Object Qinternal_border_width
;
216 Lisp_Object Qmouse_color
;
218 Lisp_Object Qparent_id
;
219 Lisp_Object Qscroll_bar_width
;
220 Lisp_Object Qsuppress_icon
;
221 Lisp_Object Qundefined_color
;
222 Lisp_Object Qvertical_scroll_bars
;
223 Lisp_Object Qvisibility
;
224 Lisp_Object Qwindow_id
;
225 Lisp_Object Qx_frame_parameter
;
226 Lisp_Object Qx_resource_name
;
227 Lisp_Object Quser_position
;
228 Lisp_Object Quser_size
;
229 Lisp_Object Qscreen_gamma
;
230 Lisp_Object Qline_spacing
;
232 Lisp_Object Qcancel_timer
;
238 Lisp_Object Qcontrol
;
241 Lisp_Object Qw32_charset_ansi
;
242 Lisp_Object Qw32_charset_default
;
243 Lisp_Object Qw32_charset_symbol
;
244 Lisp_Object Qw32_charset_shiftjis
;
245 Lisp_Object Qw32_charset_hangeul
;
246 Lisp_Object Qw32_charset_gb2312
;
247 Lisp_Object Qw32_charset_chinesebig5
;
248 Lisp_Object Qw32_charset_oem
;
250 #ifndef JOHAB_CHARSET
251 #define JOHAB_CHARSET 130
254 Lisp_Object Qw32_charset_easteurope
;
255 Lisp_Object Qw32_charset_turkish
;
256 Lisp_Object Qw32_charset_baltic
;
257 Lisp_Object Qw32_charset_russian
;
258 Lisp_Object Qw32_charset_arabic
;
259 Lisp_Object Qw32_charset_greek
;
260 Lisp_Object Qw32_charset_hebrew
;
261 Lisp_Object Qw32_charset_vietnamese
;
262 Lisp_Object Qw32_charset_thai
;
263 Lisp_Object Qw32_charset_johab
;
264 Lisp_Object Qw32_charset_mac
;
267 #ifdef UNICODE_CHARSET
268 Lisp_Object Qw32_charset_unicode
;
271 extern Lisp_Object Qtop
;
272 extern Lisp_Object Qdisplay
;
273 extern Lisp_Object Qtool_bar_lines
;
275 /* State variables for emulating a three button mouse. */
280 static int button_state
= 0;
281 static W32Msg saved_mouse_button_msg
;
282 static unsigned mouse_button_timer
; /* non-zero when timer is active */
283 static W32Msg saved_mouse_move_msg
;
284 static unsigned mouse_move_timer
;
286 /* W95 mousewheel handler */
287 unsigned int msh_mousewheel
= 0;
289 #define MOUSE_BUTTON_ID 1
290 #define MOUSE_MOVE_ID 2
292 /* The below are defined in frame.c. */
294 extern Lisp_Object Qheight
, Qminibuffer
, Qname
, Qonly
, Qwidth
;
295 extern Lisp_Object Qunsplittable
, Qmenu_bar_lines
, Qbuffer_predicate
, Qtitle
;
296 extern Lisp_Object Qtool_bar_lines
;
298 extern Lisp_Object Vwindow_system_version
;
300 Lisp_Object Qface_set_after_frame_default
;
303 int image_cache_refcount
, dpyinfo_refcount
;
307 /* From w32term.c. */
308 extern Lisp_Object Vw32_num_mouse_buttons
;
309 extern Lisp_Object Vw32_recognize_altgr
;
312 /* Error if we are not connected to MS-Windows. */
317 error ("MS-Windows not in use or not initialized");
320 /* Nonzero if we can use mouse menus.
321 You should not call this unless HAVE_MENUS is defined. */
329 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
330 and checking validity for W32. */
333 check_x_frame (frame
)
339 frame
= selected_frame
;
340 CHECK_LIVE_FRAME (frame
, 0);
342 if (! FRAME_W32_P (f
))
343 error ("non-w32 frame used");
347 /* Let the user specify an display with a frame.
348 nil stands for the selected frame--or, if that is not a w32 frame,
349 the first display on the list. */
351 static struct w32_display_info
*
352 check_x_display_info (frame
)
357 struct frame
*sf
= XFRAME (selected_frame
);
359 if (FRAME_W32_P (sf
) && FRAME_LIVE_P (sf
))
360 return FRAME_W32_DISPLAY_INFO (sf
);
362 return &one_w32_display_info
;
364 else if (STRINGP (frame
))
365 return x_display_info_for_name (frame
);
370 CHECK_LIVE_FRAME (frame
, 0);
372 if (! FRAME_W32_P (f
))
373 error ("non-w32 frame used");
374 return FRAME_W32_DISPLAY_INFO (f
);
378 /* Return the Emacs frame-object corresponding to an w32 window.
379 It could be the frame's main window or an icon window. */
381 /* This function can be called during GC, so use GC_xxx type test macros. */
384 x_window_to_frame (dpyinfo
, wdesc
)
385 struct w32_display_info
*dpyinfo
;
388 Lisp_Object tail
, frame
;
391 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
394 if (!GC_FRAMEP (frame
))
397 if (!FRAME_W32_P (f
) || FRAME_W32_DISPLAY_INFO (f
) != dpyinfo
)
399 if (f
->output_data
.w32
->hourglass_window
== wdesc
)
402 /* TODO: Check tooltips when supported. */
403 if (FRAME_W32_WINDOW (f
) == wdesc
)
411 /* Code to deal with bitmaps. Bitmaps are referenced by their bitmap
412 id, which is just an int that this section returns. Bitmaps are
413 reference counted so they can be shared among frames.
415 Bitmap indices are guaranteed to be > 0, so a negative number can
416 be used to indicate no bitmap.
418 If you use x_create_bitmap_from_data, then you must keep track of
419 the bitmaps yourself. That is, creating a bitmap from the same
420 data more than once will not be caught. */
423 /* Functions to access the contents of a bitmap, given an id. */
426 x_bitmap_height (f
, id
)
430 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].height
;
434 x_bitmap_width (f
, id
)
438 return FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].width
;
442 x_bitmap_pixmap (f
, id
)
446 return (int) FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].pixmap
;
450 /* Allocate a new bitmap record. Returns index of new record. */
453 x_allocate_bitmap_record (f
)
456 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
459 if (dpyinfo
->bitmaps
== NULL
)
461 dpyinfo
->bitmaps_size
= 10;
463 = (struct w32_bitmap_record
*) xmalloc (dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
464 dpyinfo
->bitmaps_last
= 1;
468 if (dpyinfo
->bitmaps_last
< dpyinfo
->bitmaps_size
)
469 return ++dpyinfo
->bitmaps_last
;
471 for (i
= 0; i
< dpyinfo
->bitmaps_size
; ++i
)
472 if (dpyinfo
->bitmaps
[i
].refcount
== 0)
475 dpyinfo
->bitmaps_size
*= 2;
477 = (struct w32_bitmap_record
*) xrealloc (dpyinfo
->bitmaps
,
478 dpyinfo
->bitmaps_size
* sizeof (struct w32_bitmap_record
));
479 return ++dpyinfo
->bitmaps_last
;
482 /* Add one reference to the reference count of the bitmap with id ID. */
485 x_reference_bitmap (f
, id
)
489 ++FRAME_W32_DISPLAY_INFO (f
)->bitmaps
[id
- 1].refcount
;
492 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
495 x_create_bitmap_from_data (f
, bits
, width
, height
)
498 unsigned int width
, height
;
500 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
504 bitmap
= CreateBitmap (width
, height
,
505 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_planes
,
506 FRAME_W32_DISPLAY_INFO (XFRAME (frame
))->n_cbits
,
512 id
= x_allocate_bitmap_record (f
);
513 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
514 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
515 dpyinfo
->bitmaps
[id
- 1].hinst
= NULL
;
516 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
517 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
518 dpyinfo
->bitmaps
[id
- 1].height
= height
;
519 dpyinfo
->bitmaps
[id
- 1].width
= width
;
524 /* Create bitmap from file FILE for frame F. */
527 x_create_bitmap_from_file (f
, file
)
532 #if 0 /* TODO : bitmap support */
533 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
534 unsigned int width
, height
;
536 int xhot
, yhot
, result
, id
;
542 /* Look for an existing bitmap with the same name. */
543 for (id
= 0; id
< dpyinfo
->bitmaps_last
; ++id
)
545 if (dpyinfo
->bitmaps
[id
].refcount
546 && dpyinfo
->bitmaps
[id
].file
547 && !strcmp (dpyinfo
->bitmaps
[id
].file
, (char *) XSTRING (file
)->data
))
549 ++dpyinfo
->bitmaps
[id
].refcount
;
554 /* Search bitmap-file-path for the file, if appropriate. */
555 fd
= openp (Vx_bitmap_file_path
, file
, "", &found
, 0);
560 filename
= (char *) XSTRING (found
)->data
;
562 hinst
= LoadLibraryEx (filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
568 result
= XReadBitmapFile (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
569 filename
, &width
, &height
, &bitmap
, &xhot
, &yhot
);
570 if (result
!= BitmapSuccess
)
573 id
= x_allocate_bitmap_record (f
);
574 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
575 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
576 dpyinfo
->bitmaps
[id
- 1].file
= (char *) xmalloc (XSTRING (file
)->size
+ 1);
577 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
578 dpyinfo
->bitmaps
[id
- 1].height
= height
;
579 dpyinfo
->bitmaps
[id
- 1].width
= width
;
580 strcpy (dpyinfo
->bitmaps
[id
- 1].file
, XSTRING (file
)->data
);
586 /* Remove reference to bitmap with id number ID. */
589 x_destroy_bitmap (f
, id
)
593 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
597 --dpyinfo
->bitmaps
[id
- 1].refcount
;
598 if (dpyinfo
->bitmaps
[id
- 1].refcount
== 0)
601 DeleteObject (dpyinfo
->bitmaps
[id
- 1].pixmap
);
602 if (dpyinfo
->bitmaps
[id
- 1].file
)
604 xfree (dpyinfo
->bitmaps
[id
- 1].file
);
605 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
612 /* Free all the bitmaps for the display specified by DPYINFO. */
615 x_destroy_all_bitmaps (dpyinfo
)
616 struct w32_display_info
*dpyinfo
;
619 for (i
= 0; i
< dpyinfo
->bitmaps_last
; i
++)
620 if (dpyinfo
->bitmaps
[i
].refcount
> 0)
622 DeleteObject (dpyinfo
->bitmaps
[i
].pixmap
);
623 if (dpyinfo
->bitmaps
[i
].file
)
624 xfree (dpyinfo
->bitmaps
[i
].file
);
626 dpyinfo
->bitmaps_last
= 0;
629 /* Connect the frame-parameter names for W32 frames
630 to the ways of passing the parameter values to the window system.
632 The name of a parameter, as a Lisp symbol,
633 has an `x-frame-parameter' property which is an integer in Lisp
634 but can be interpreted as an `enum x_frame_parm' in C. */
638 X_PARM_FOREGROUND_COLOR
,
639 X_PARM_BACKGROUND_COLOR
,
646 X_PARM_INTERNAL_BORDER_WIDTH
,
650 X_PARM_VERT_SCROLL_BAR
,
652 X_PARM_MENU_BAR_LINES
656 struct x_frame_parm_table
659 void (*setter
) P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
662 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
663 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
664 static void x_change_window_heights
P_ ((Lisp_Object
, int));
665 /* TODO: Native Input Method support; see x_create_im. */
666 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
667 static void x_set_line_spacing
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
668 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
669 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
670 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
671 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
672 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
673 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
674 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
675 void x_set_font
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
676 void x_set_border_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
677 void x_set_internal_border_width
P_ ((struct frame
*, Lisp_Object
,
679 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
680 void x_set_autoraise
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
681 void x_set_autolower
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
682 void x_set_vertical_scroll_bars
P_ ((struct frame
*, Lisp_Object
,
684 void x_set_visibility
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
685 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
686 void x_set_scroll_bar_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
687 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
688 void x_set_unsplittable
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
689 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
690 static void x_set_screen_gamma
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
692 static struct x_frame_parm_table x_frame_parms
[] =
694 "auto-raise", x_set_autoraise
,
695 "auto-lower", x_set_autolower
,
696 "background-color", x_set_background_color
,
697 "border-color", x_set_border_color
,
698 "border-width", x_set_border_width
,
699 "cursor-color", x_set_cursor_color
,
700 "cursor-type", x_set_cursor_type
,
702 "foreground-color", x_set_foreground_color
,
703 "icon-name", x_set_icon_name
,
704 "icon-type", x_set_icon_type
,
705 "internal-border-width", x_set_internal_border_width
,
706 "menu-bar-lines", x_set_menu_bar_lines
,
707 "mouse-color", x_set_mouse_color
,
708 "name", x_explicitly_set_name
,
709 "scroll-bar-width", x_set_scroll_bar_width
,
710 "title", x_set_title
,
711 "unsplittable", x_set_unsplittable
,
712 "vertical-scroll-bars", x_set_vertical_scroll_bars
,
713 "visibility", x_set_visibility
,
714 "tool-bar-lines", x_set_tool_bar_lines
,
715 "screen-gamma", x_set_screen_gamma
,
716 "line-spacing", x_set_line_spacing
719 /* Attach the `x-frame-parameter' properties to
720 the Lisp symbol names of parameters relevant to W32. */
723 init_x_parm_symbols ()
727 for (i
= 0; i
< sizeof (x_frame_parms
) / sizeof (x_frame_parms
[0]); i
++)
728 Fput (intern (x_frame_parms
[i
].name
), Qx_frame_parameter
,
732 /* Change the parameters of frame F as specified by ALIST.
733 If a parameter is not specially recognized, do nothing;
734 otherwise call the `x_set_...' function for that parameter. */
737 x_set_frame_parameters (f
, alist
)
743 /* If both of these parameters are present, it's more efficient to
744 set them both at once. So we wait until we've looked at the
745 entire list before we set them. */
749 Lisp_Object left
, top
;
751 /* Same with these. */
752 Lisp_Object icon_left
, icon_top
;
754 /* Record in these vectors all the parms specified. */
758 int left_no_change
= 0, top_no_change
= 0;
759 int icon_left_no_change
= 0, icon_top_no_change
= 0;
761 struct gcpro gcpro1
, gcpro2
;
764 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
767 parms
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
768 values
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
770 /* Extract parm names and values into those vectors. */
773 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
778 parms
[i
] = Fcar (elt
);
779 values
[i
] = Fcdr (elt
);
782 /* TAIL and ALIST are not used again below here. */
785 GCPRO2 (*parms
, *values
);
789 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
790 because their values appear in VALUES and strings are not valid. */
791 top
= left
= Qunbound
;
792 icon_left
= icon_top
= Qunbound
;
794 /* Provide default values for HEIGHT and WIDTH. */
795 if (FRAME_NEW_WIDTH (f
))
796 width
= FRAME_NEW_WIDTH (f
);
798 width
= FRAME_WIDTH (f
);
800 if (FRAME_NEW_HEIGHT (f
))
801 height
= FRAME_NEW_HEIGHT (f
);
803 height
= FRAME_HEIGHT (f
);
805 /* Process foreground_color and background_color before anything else.
806 They are independent of other properties, but other properties (e.g.,
807 cursor_color) are dependent upon them. */
808 for (p
= 0; p
< i
; p
++)
810 Lisp_Object prop
, val
;
814 if (EQ (prop
, Qforeground_color
) || EQ (prop
, Qbackground_color
))
816 register Lisp_Object param_index
, old_value
;
818 param_index
= Fget (prop
, Qx_frame_parameter
);
819 old_value
= get_frame_param (f
, prop
);
820 store_frame_param (f
, prop
, val
);
821 if (NATNUMP (param_index
)
822 && (XFASTINT (param_index
)
823 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
824 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
828 /* Now process them in reverse of specified order. */
829 for (i
--; i
>= 0; i
--)
831 Lisp_Object prop
, val
;
836 if (EQ (prop
, Qwidth
) && NUMBERP (val
))
837 width
= XFASTINT (val
);
838 else if (EQ (prop
, Qheight
) && NUMBERP (val
))
839 height
= XFASTINT (val
);
840 else if (EQ (prop
, Qtop
))
842 else if (EQ (prop
, Qleft
))
844 else if (EQ (prop
, Qicon_top
))
846 else if (EQ (prop
, Qicon_left
))
848 else if (EQ (prop
, Qforeground_color
) || EQ (prop
, Qbackground_color
))
849 /* Processed above. */
853 register Lisp_Object param_index
, old_value
;
855 param_index
= Fget (prop
, Qx_frame_parameter
);
856 old_value
= get_frame_param (f
, prop
);
857 store_frame_param (f
, prop
, val
);
858 if (NATNUMP (param_index
)
859 && (XFASTINT (param_index
)
860 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
861 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
865 /* Don't die if just one of these was set. */
866 if (EQ (left
, Qunbound
))
869 if (f
->output_data
.w32
->left_pos
< 0)
870 left
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->left_pos
), Qnil
));
872 XSETINT (left
, f
->output_data
.w32
->left_pos
);
874 if (EQ (top
, Qunbound
))
877 if (f
->output_data
.w32
->top_pos
< 0)
878 top
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.w32
->top_pos
), Qnil
));
880 XSETINT (top
, f
->output_data
.w32
->top_pos
);
883 /* If one of the icon positions was not set, preserve or default it. */
884 if (EQ (icon_left
, Qunbound
) || ! INTEGERP (icon_left
))
886 icon_left_no_change
= 1;
887 icon_left
= Fcdr (Fassq (Qicon_left
, f
->param_alist
));
888 if (NILP (icon_left
))
889 XSETINT (icon_left
, 0);
891 if (EQ (icon_top
, Qunbound
) || ! INTEGERP (icon_top
))
893 icon_top_no_change
= 1;
894 icon_top
= Fcdr (Fassq (Qicon_top
, f
->param_alist
));
896 XSETINT (icon_top
, 0);
899 /* Don't set these parameters unless they've been explicitly
900 specified. The window might be mapped or resized while we're in
901 this function, and we don't want to override that unless the lisp
902 code has asked for it.
904 Don't set these parameters unless they actually differ from the
905 window's current parameters; the window may not actually exist
910 check_frame_size (f
, &height
, &width
);
912 XSETFRAME (frame
, f
);
914 if (width
!= FRAME_WIDTH (f
)
915 || height
!= FRAME_HEIGHT (f
)
916 || FRAME_NEW_HEIGHT (f
) || FRAME_NEW_WIDTH (f
))
917 Fset_frame_size (frame
, make_number (width
), make_number (height
));
919 if ((!NILP (left
) || !NILP (top
))
920 && ! (left_no_change
&& top_no_change
)
921 && ! (NUMBERP (left
) && XINT (left
) == f
->output_data
.w32
->left_pos
922 && NUMBERP (top
) && XINT (top
) == f
->output_data
.w32
->top_pos
))
927 /* Record the signs. */
928 f
->output_data
.w32
->size_hint_flags
&= ~ (XNegative
| YNegative
);
929 if (EQ (left
, Qminus
))
930 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
931 else if (INTEGERP (left
))
933 leftpos
= XINT (left
);
935 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
937 else if (CONSP (left
) && EQ (XCAR (left
), Qminus
)
938 && CONSP (XCDR (left
))
939 && INTEGERP (XCAR (XCDR (left
))))
941 leftpos
= - XINT (XCAR (XCDR (left
)));
942 f
->output_data
.w32
->size_hint_flags
|= XNegative
;
944 else if (CONSP (left
) && EQ (XCAR (left
), Qplus
)
945 && CONSP (XCDR (left
))
946 && INTEGERP (XCAR (XCDR (left
))))
948 leftpos
= XINT (XCAR (XCDR (left
)));
951 if (EQ (top
, Qminus
))
952 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
953 else if (INTEGERP (top
))
957 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
959 else if (CONSP (top
) && EQ (XCAR (top
), Qminus
)
960 && CONSP (XCDR (top
))
961 && INTEGERP (XCAR (XCDR (top
))))
963 toppos
= - XINT (XCAR (XCDR (top
)));
964 f
->output_data
.w32
->size_hint_flags
|= YNegative
;
966 else if (CONSP (top
) && EQ (XCAR (top
), Qplus
)
967 && CONSP (XCDR (top
))
968 && INTEGERP (XCAR (XCDR (top
))))
970 toppos
= XINT (XCAR (XCDR (top
)));
974 /* Store the numeric value of the position. */
975 f
->output_data
.w32
->top_pos
= toppos
;
976 f
->output_data
.w32
->left_pos
= leftpos
;
978 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
980 /* Actually set that position, and convert to absolute. */
981 x_set_offset (f
, leftpos
, toppos
, -1);
984 if ((!NILP (icon_left
) || !NILP (icon_top
))
985 && ! (icon_left_no_change
&& icon_top_no_change
))
986 x_wm_set_icon_position (f
, XINT (icon_left
), XINT (icon_top
));
992 /* Store the screen positions of frame F into XPTR and YPTR.
993 These are the positions of the containing window manager window,
994 not Emacs's own window. */
997 x_real_positions (f
, xptr
, yptr
)
1006 GetClientRect(FRAME_W32_WINDOW(f
), &rect
);
1007 AdjustWindowRect(&rect
, f
->output_data
.w32
->dwStyle
, FRAME_EXTERNAL_MENU_BAR(f
));
1013 ClientToScreen (FRAME_W32_WINDOW(f
), &pt
);
1019 /* Insert a description of internally-recorded parameters of frame X
1020 into the parameter alist *ALISTPTR that is to be given to the user.
1021 Only parameters that are specific to W32
1022 and whose values are not correctly recorded in the frame's
1023 param_alist need to be considered here. */
1026 x_report_frame_params (f
, alistptr
)
1028 Lisp_Object
*alistptr
;
1033 /* Represent negative positions (off the top or left screen edge)
1034 in a way that Fmodify_frame_parameters will understand correctly. */
1035 XSETINT (tem
, f
->output_data
.w32
->left_pos
);
1036 if (f
->output_data
.w32
->left_pos
>= 0)
1037 store_in_alist (alistptr
, Qleft
, tem
);
1039 store_in_alist (alistptr
, Qleft
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1041 XSETINT (tem
, f
->output_data
.w32
->top_pos
);
1042 if (f
->output_data
.w32
->top_pos
>= 0)
1043 store_in_alist (alistptr
, Qtop
, tem
);
1045 store_in_alist (alistptr
, Qtop
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1047 store_in_alist (alistptr
, Qborder_width
,
1048 make_number (f
->output_data
.w32
->border_width
));
1049 store_in_alist (alistptr
, Qinternal_border_width
,
1050 make_number (f
->output_data
.w32
->internal_border_width
));
1051 sprintf (buf
, "%ld", (long) FRAME_W32_WINDOW (f
));
1052 store_in_alist (alistptr
, Qwindow_id
,
1053 build_string (buf
));
1054 store_in_alist (alistptr
, Qicon_name
, f
->icon_name
);
1055 FRAME_SAMPLE_VISIBILITY (f
);
1056 store_in_alist (alistptr
, Qvisibility
,
1057 (FRAME_VISIBLE_P (f
) ? Qt
1058 : FRAME_ICONIFIED_P (f
) ? Qicon
: Qnil
));
1059 store_in_alist (alistptr
, Qdisplay
,
1060 XCAR (FRAME_W32_DISPLAY_INFO (f
)->name_list_element
));
1064 DEFUN ("w32-define-rgb-color", Fw32_define_rgb_color
, Sw32_define_rgb_color
, 4, 4, 0,
1065 "Convert RGB numbers to a windows color reference and associate with NAME (a string).\n\
1066 This adds or updates a named color to w32-color-map, making it available for use.\n\
1067 The original entry's RGB ref is returned, or nil if the entry is new.")
1068 (red
, green
, blue
, name
)
1069 Lisp_Object red
, green
, blue
, name
;
1072 Lisp_Object oldrgb
= Qnil
;
1075 CHECK_NUMBER (red
, 0);
1076 CHECK_NUMBER (green
, 0);
1077 CHECK_NUMBER (blue
, 0);
1078 CHECK_STRING (name
, 0);
1080 XSET (rgb
, Lisp_Int
, RGB(XUINT (red
), XUINT (green
), XUINT (blue
)));
1084 /* replace existing entry in w32-color-map or add new entry. */
1085 entry
= Fassoc (name
, Vw32_color_map
);
1088 entry
= Fcons (name
, rgb
);
1089 Vw32_color_map
= Fcons (entry
, Vw32_color_map
);
1093 oldrgb
= Fcdr (entry
);
1094 Fsetcdr (entry
, rgb
);
1102 DEFUN ("w32-load-color-file", Fw32_load_color_file
, Sw32_load_color_file
, 1, 1, 0,
1103 "Create an alist of color entries from an external file (ie. rgb.txt).\n\
1104 Assign this value to w32-color-map to replace the existing color map.\n\
1106 The file should define one named RGB color per line like so:\
1108 where R,G,B are numbers between 0 and 255 and name is an arbitrary string.")
1110 Lisp_Object filename
;
1113 Lisp_Object cmap
= Qnil
;
1114 Lisp_Object abspath
;
1116 CHECK_STRING (filename
, 0);
1117 abspath
= Fexpand_file_name (filename
, Qnil
);
1119 fp
= fopen (XSTRING (filename
)->data
, "rt");
1123 int red
, green
, blue
;
1128 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
1129 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
1131 char *name
= buf
+ num
;
1132 num
= strlen (name
) - 1;
1133 if (name
[num
] == '\n')
1135 cmap
= Fcons (Fcons (build_string (name
),
1136 make_number (RGB (red
, green
, blue
))),
1148 /* The default colors for the w32 color map */
1149 typedef struct colormap_t
1155 colormap_t w32_color_map
[] =
1157 {"snow" , PALETTERGB (255,250,250)},
1158 {"ghost white" , PALETTERGB (248,248,255)},
1159 {"GhostWhite" , PALETTERGB (248,248,255)},
1160 {"white smoke" , PALETTERGB (245,245,245)},
1161 {"WhiteSmoke" , PALETTERGB (245,245,245)},
1162 {"gainsboro" , PALETTERGB (220,220,220)},
1163 {"floral white" , PALETTERGB (255,250,240)},
1164 {"FloralWhite" , PALETTERGB (255,250,240)},
1165 {"old lace" , PALETTERGB (253,245,230)},
1166 {"OldLace" , PALETTERGB (253,245,230)},
1167 {"linen" , PALETTERGB (250,240,230)},
1168 {"antique white" , PALETTERGB (250,235,215)},
1169 {"AntiqueWhite" , PALETTERGB (250,235,215)},
1170 {"papaya whip" , PALETTERGB (255,239,213)},
1171 {"PapayaWhip" , PALETTERGB (255,239,213)},
1172 {"blanched almond" , PALETTERGB (255,235,205)},
1173 {"BlanchedAlmond" , PALETTERGB (255,235,205)},
1174 {"bisque" , PALETTERGB (255,228,196)},
1175 {"peach puff" , PALETTERGB (255,218,185)},
1176 {"PeachPuff" , PALETTERGB (255,218,185)},
1177 {"navajo white" , PALETTERGB (255,222,173)},
1178 {"NavajoWhite" , PALETTERGB (255,222,173)},
1179 {"moccasin" , PALETTERGB (255,228,181)},
1180 {"cornsilk" , PALETTERGB (255,248,220)},
1181 {"ivory" , PALETTERGB (255,255,240)},
1182 {"lemon chiffon" , PALETTERGB (255,250,205)},
1183 {"LemonChiffon" , PALETTERGB (255,250,205)},
1184 {"seashell" , PALETTERGB (255,245,238)},
1185 {"honeydew" , PALETTERGB (240,255,240)},
1186 {"mint cream" , PALETTERGB (245,255,250)},
1187 {"MintCream" , PALETTERGB (245,255,250)},
1188 {"azure" , PALETTERGB (240,255,255)},
1189 {"alice blue" , PALETTERGB (240,248,255)},
1190 {"AliceBlue" , PALETTERGB (240,248,255)},
1191 {"lavender" , PALETTERGB (230,230,250)},
1192 {"lavender blush" , PALETTERGB (255,240,245)},
1193 {"LavenderBlush" , PALETTERGB (255,240,245)},
1194 {"misty rose" , PALETTERGB (255,228,225)},
1195 {"MistyRose" , PALETTERGB (255,228,225)},
1196 {"white" , PALETTERGB (255,255,255)},
1197 {"black" , PALETTERGB ( 0, 0, 0)},
1198 {"dark slate gray" , PALETTERGB ( 47, 79, 79)},
1199 {"DarkSlateGray" , PALETTERGB ( 47, 79, 79)},
1200 {"dark slate grey" , PALETTERGB ( 47, 79, 79)},
1201 {"DarkSlateGrey" , PALETTERGB ( 47, 79, 79)},
1202 {"dim gray" , PALETTERGB (105,105,105)},
1203 {"DimGray" , PALETTERGB (105,105,105)},
1204 {"dim grey" , PALETTERGB (105,105,105)},
1205 {"DimGrey" , PALETTERGB (105,105,105)},
1206 {"slate gray" , PALETTERGB (112,128,144)},
1207 {"SlateGray" , PALETTERGB (112,128,144)},
1208 {"slate grey" , PALETTERGB (112,128,144)},
1209 {"SlateGrey" , PALETTERGB (112,128,144)},
1210 {"light slate gray" , PALETTERGB (119,136,153)},
1211 {"LightSlateGray" , PALETTERGB (119,136,153)},
1212 {"light slate grey" , PALETTERGB (119,136,153)},
1213 {"LightSlateGrey" , PALETTERGB (119,136,153)},
1214 {"gray" , PALETTERGB (190,190,190)},
1215 {"grey" , PALETTERGB (190,190,190)},
1216 {"light grey" , PALETTERGB (211,211,211)},
1217 {"LightGrey" , PALETTERGB (211,211,211)},
1218 {"light gray" , PALETTERGB (211,211,211)},
1219 {"LightGray" , PALETTERGB (211,211,211)},
1220 {"midnight blue" , PALETTERGB ( 25, 25,112)},
1221 {"MidnightBlue" , PALETTERGB ( 25, 25,112)},
1222 {"navy" , PALETTERGB ( 0, 0,128)},
1223 {"navy blue" , PALETTERGB ( 0, 0,128)},
1224 {"NavyBlue" , PALETTERGB ( 0, 0,128)},
1225 {"cornflower blue" , PALETTERGB (100,149,237)},
1226 {"CornflowerBlue" , PALETTERGB (100,149,237)},
1227 {"dark slate blue" , PALETTERGB ( 72, 61,139)},
1228 {"DarkSlateBlue" , PALETTERGB ( 72, 61,139)},
1229 {"slate blue" , PALETTERGB (106, 90,205)},
1230 {"SlateBlue" , PALETTERGB (106, 90,205)},
1231 {"medium slate blue" , PALETTERGB (123,104,238)},
1232 {"MediumSlateBlue" , PALETTERGB (123,104,238)},
1233 {"light slate blue" , PALETTERGB (132,112,255)},
1234 {"LightSlateBlue" , PALETTERGB (132,112,255)},
1235 {"medium blue" , PALETTERGB ( 0, 0,205)},
1236 {"MediumBlue" , PALETTERGB ( 0, 0,205)},
1237 {"royal blue" , PALETTERGB ( 65,105,225)},
1238 {"RoyalBlue" , PALETTERGB ( 65,105,225)},
1239 {"blue" , PALETTERGB ( 0, 0,255)},
1240 {"dodger blue" , PALETTERGB ( 30,144,255)},
1241 {"DodgerBlue" , PALETTERGB ( 30,144,255)},
1242 {"deep sky blue" , PALETTERGB ( 0,191,255)},
1243 {"DeepSkyBlue" , PALETTERGB ( 0,191,255)},
1244 {"sky blue" , PALETTERGB (135,206,235)},
1245 {"SkyBlue" , PALETTERGB (135,206,235)},
1246 {"light sky blue" , PALETTERGB (135,206,250)},
1247 {"LightSkyBlue" , PALETTERGB (135,206,250)},
1248 {"steel blue" , PALETTERGB ( 70,130,180)},
1249 {"SteelBlue" , PALETTERGB ( 70,130,180)},
1250 {"light steel blue" , PALETTERGB (176,196,222)},
1251 {"LightSteelBlue" , PALETTERGB (176,196,222)},
1252 {"light blue" , PALETTERGB (173,216,230)},
1253 {"LightBlue" , PALETTERGB (173,216,230)},
1254 {"powder blue" , PALETTERGB (176,224,230)},
1255 {"PowderBlue" , PALETTERGB (176,224,230)},
1256 {"pale turquoise" , PALETTERGB (175,238,238)},
1257 {"PaleTurquoise" , PALETTERGB (175,238,238)},
1258 {"dark turquoise" , PALETTERGB ( 0,206,209)},
1259 {"DarkTurquoise" , PALETTERGB ( 0,206,209)},
1260 {"medium turquoise" , PALETTERGB ( 72,209,204)},
1261 {"MediumTurquoise" , PALETTERGB ( 72,209,204)},
1262 {"turquoise" , PALETTERGB ( 64,224,208)},
1263 {"cyan" , PALETTERGB ( 0,255,255)},
1264 {"light cyan" , PALETTERGB (224,255,255)},
1265 {"LightCyan" , PALETTERGB (224,255,255)},
1266 {"cadet blue" , PALETTERGB ( 95,158,160)},
1267 {"CadetBlue" , PALETTERGB ( 95,158,160)},
1268 {"medium aquamarine" , PALETTERGB (102,205,170)},
1269 {"MediumAquamarine" , PALETTERGB (102,205,170)},
1270 {"aquamarine" , PALETTERGB (127,255,212)},
1271 {"dark green" , PALETTERGB ( 0,100, 0)},
1272 {"DarkGreen" , PALETTERGB ( 0,100, 0)},
1273 {"dark olive green" , PALETTERGB ( 85,107, 47)},
1274 {"DarkOliveGreen" , PALETTERGB ( 85,107, 47)},
1275 {"dark sea green" , PALETTERGB (143,188,143)},
1276 {"DarkSeaGreen" , PALETTERGB (143,188,143)},
1277 {"sea green" , PALETTERGB ( 46,139, 87)},
1278 {"SeaGreen" , PALETTERGB ( 46,139, 87)},
1279 {"medium sea green" , PALETTERGB ( 60,179,113)},
1280 {"MediumSeaGreen" , PALETTERGB ( 60,179,113)},
1281 {"light sea green" , PALETTERGB ( 32,178,170)},
1282 {"LightSeaGreen" , PALETTERGB ( 32,178,170)},
1283 {"pale green" , PALETTERGB (152,251,152)},
1284 {"PaleGreen" , PALETTERGB (152,251,152)},
1285 {"spring green" , PALETTERGB ( 0,255,127)},
1286 {"SpringGreen" , PALETTERGB ( 0,255,127)},
1287 {"lawn green" , PALETTERGB (124,252, 0)},
1288 {"LawnGreen" , PALETTERGB (124,252, 0)},
1289 {"green" , PALETTERGB ( 0,255, 0)},
1290 {"chartreuse" , PALETTERGB (127,255, 0)},
1291 {"medium spring green" , PALETTERGB ( 0,250,154)},
1292 {"MediumSpringGreen" , PALETTERGB ( 0,250,154)},
1293 {"green yellow" , PALETTERGB (173,255, 47)},
1294 {"GreenYellow" , PALETTERGB (173,255, 47)},
1295 {"lime green" , PALETTERGB ( 50,205, 50)},
1296 {"LimeGreen" , PALETTERGB ( 50,205, 50)},
1297 {"yellow green" , PALETTERGB (154,205, 50)},
1298 {"YellowGreen" , PALETTERGB (154,205, 50)},
1299 {"forest green" , PALETTERGB ( 34,139, 34)},
1300 {"ForestGreen" , PALETTERGB ( 34,139, 34)},
1301 {"olive drab" , PALETTERGB (107,142, 35)},
1302 {"OliveDrab" , PALETTERGB (107,142, 35)},
1303 {"dark khaki" , PALETTERGB (189,183,107)},
1304 {"DarkKhaki" , PALETTERGB (189,183,107)},
1305 {"khaki" , PALETTERGB (240,230,140)},
1306 {"pale goldenrod" , PALETTERGB (238,232,170)},
1307 {"PaleGoldenrod" , PALETTERGB (238,232,170)},
1308 {"light goldenrod yellow" , PALETTERGB (250,250,210)},
1309 {"LightGoldenrodYellow" , PALETTERGB (250,250,210)},
1310 {"light yellow" , PALETTERGB (255,255,224)},
1311 {"LightYellow" , PALETTERGB (255,255,224)},
1312 {"yellow" , PALETTERGB (255,255, 0)},
1313 {"gold" , PALETTERGB (255,215, 0)},
1314 {"light goldenrod" , PALETTERGB (238,221,130)},
1315 {"LightGoldenrod" , PALETTERGB (238,221,130)},
1316 {"goldenrod" , PALETTERGB (218,165, 32)},
1317 {"dark goldenrod" , PALETTERGB (184,134, 11)},
1318 {"DarkGoldenrod" , PALETTERGB (184,134, 11)},
1319 {"rosy brown" , PALETTERGB (188,143,143)},
1320 {"RosyBrown" , PALETTERGB (188,143,143)},
1321 {"indian red" , PALETTERGB (205, 92, 92)},
1322 {"IndianRed" , PALETTERGB (205, 92, 92)},
1323 {"saddle brown" , PALETTERGB (139, 69, 19)},
1324 {"SaddleBrown" , PALETTERGB (139, 69, 19)},
1325 {"sienna" , PALETTERGB (160, 82, 45)},
1326 {"peru" , PALETTERGB (205,133, 63)},
1327 {"burlywood" , PALETTERGB (222,184,135)},
1328 {"beige" , PALETTERGB (245,245,220)},
1329 {"wheat" , PALETTERGB (245,222,179)},
1330 {"sandy brown" , PALETTERGB (244,164, 96)},
1331 {"SandyBrown" , PALETTERGB (244,164, 96)},
1332 {"tan" , PALETTERGB (210,180,140)},
1333 {"chocolate" , PALETTERGB (210,105, 30)},
1334 {"firebrick" , PALETTERGB (178,34, 34)},
1335 {"brown" , PALETTERGB (165,42, 42)},
1336 {"dark salmon" , PALETTERGB (233,150,122)},
1337 {"DarkSalmon" , PALETTERGB (233,150,122)},
1338 {"salmon" , PALETTERGB (250,128,114)},
1339 {"light salmon" , PALETTERGB (255,160,122)},
1340 {"LightSalmon" , PALETTERGB (255,160,122)},
1341 {"orange" , PALETTERGB (255,165, 0)},
1342 {"dark orange" , PALETTERGB (255,140, 0)},
1343 {"DarkOrange" , PALETTERGB (255,140, 0)},
1344 {"coral" , PALETTERGB (255,127, 80)},
1345 {"light coral" , PALETTERGB (240,128,128)},
1346 {"LightCoral" , PALETTERGB (240,128,128)},
1347 {"tomato" , PALETTERGB (255, 99, 71)},
1348 {"orange red" , PALETTERGB (255, 69, 0)},
1349 {"OrangeRed" , PALETTERGB (255, 69, 0)},
1350 {"red" , PALETTERGB (255, 0, 0)},
1351 {"hot pink" , PALETTERGB (255,105,180)},
1352 {"HotPink" , PALETTERGB (255,105,180)},
1353 {"deep pink" , PALETTERGB (255, 20,147)},
1354 {"DeepPink" , PALETTERGB (255, 20,147)},
1355 {"pink" , PALETTERGB (255,192,203)},
1356 {"light pink" , PALETTERGB (255,182,193)},
1357 {"LightPink" , PALETTERGB (255,182,193)},
1358 {"pale violet red" , PALETTERGB (219,112,147)},
1359 {"PaleVioletRed" , PALETTERGB (219,112,147)},
1360 {"maroon" , PALETTERGB (176, 48, 96)},
1361 {"medium violet red" , PALETTERGB (199, 21,133)},
1362 {"MediumVioletRed" , PALETTERGB (199, 21,133)},
1363 {"violet red" , PALETTERGB (208, 32,144)},
1364 {"VioletRed" , PALETTERGB (208, 32,144)},
1365 {"magenta" , PALETTERGB (255, 0,255)},
1366 {"violet" , PALETTERGB (238,130,238)},
1367 {"plum" , PALETTERGB (221,160,221)},
1368 {"orchid" , PALETTERGB (218,112,214)},
1369 {"medium orchid" , PALETTERGB (186, 85,211)},
1370 {"MediumOrchid" , PALETTERGB (186, 85,211)},
1371 {"dark orchid" , PALETTERGB (153, 50,204)},
1372 {"DarkOrchid" , PALETTERGB (153, 50,204)},
1373 {"dark violet" , PALETTERGB (148, 0,211)},
1374 {"DarkViolet" , PALETTERGB (148, 0,211)},
1375 {"blue violet" , PALETTERGB (138, 43,226)},
1376 {"BlueViolet" , PALETTERGB (138, 43,226)},
1377 {"purple" , PALETTERGB (160, 32,240)},
1378 {"medium purple" , PALETTERGB (147,112,219)},
1379 {"MediumPurple" , PALETTERGB (147,112,219)},
1380 {"thistle" , PALETTERGB (216,191,216)},
1381 {"gray0" , PALETTERGB ( 0, 0, 0)},
1382 {"grey0" , PALETTERGB ( 0, 0, 0)},
1383 {"dark grey" , PALETTERGB (169,169,169)},
1384 {"DarkGrey" , PALETTERGB (169,169,169)},
1385 {"dark gray" , PALETTERGB (169,169,169)},
1386 {"DarkGray" , PALETTERGB (169,169,169)},
1387 {"dark blue" , PALETTERGB ( 0, 0,139)},
1388 {"DarkBlue" , PALETTERGB ( 0, 0,139)},
1389 {"dark cyan" , PALETTERGB ( 0,139,139)},
1390 {"DarkCyan" , PALETTERGB ( 0,139,139)},
1391 {"dark magenta" , PALETTERGB (139, 0,139)},
1392 {"DarkMagenta" , PALETTERGB (139, 0,139)},
1393 {"dark red" , PALETTERGB (139, 0, 0)},
1394 {"DarkRed" , PALETTERGB (139, 0, 0)},
1395 {"light green" , PALETTERGB (144,238,144)},
1396 {"LightGreen" , PALETTERGB (144,238,144)},
1399 DEFUN ("w32-default-color-map", Fw32_default_color_map
, Sw32_default_color_map
,
1400 0, 0, 0, "Return the default color map.")
1404 colormap_t
*pc
= w32_color_map
;
1411 for (i
= 0; i
< sizeof (w32_color_map
) / sizeof (w32_color_map
[0]);
1413 cmap
= Fcons (Fcons (build_string (pc
->name
),
1414 make_number (pc
->colorref
)),
1423 w32_to_x_color (rgb
)
1428 CHECK_NUMBER (rgb
, 0);
1432 color
= Frassq (rgb
, Vw32_color_map
);
1437 return (Fcar (color
));
1443 w32_color_map_lookup (colorname
)
1446 Lisp_Object tail
, ret
= Qnil
;
1450 for (tail
= Vw32_color_map
; !NILP (tail
); tail
= Fcdr (tail
))
1452 register Lisp_Object elt
, tem
;
1455 if (!CONSP (elt
)) continue;
1459 if (lstrcmpi (XSTRING (tem
)->data
, colorname
) == 0)
1461 ret
= XUINT (Fcdr (elt
));
1475 x_to_w32_color (colorname
)
1478 register Lisp_Object ret
= Qnil
;
1482 if (colorname
[0] == '#')
1484 /* Could be an old-style RGB Device specification. */
1487 color
= colorname
+ 1;
1489 size
= strlen(color
);
1490 if (size
== 3 || size
== 6 || size
== 9 || size
== 12)
1498 for (i
= 0; i
< 3; i
++)
1502 unsigned long value
;
1504 /* The check for 'x' in the following conditional takes into
1505 account the fact that strtol allows a "0x" in front of
1506 our numbers, and we don't. */
1507 if (!isxdigit(color
[0]) || color
[1] == 'x')
1511 value
= strtoul(color
, &end
, 16);
1513 if (errno
== ERANGE
|| end
- color
!= size
)
1518 value
= value
* 0x10;
1529 colorval
|= (value
<< pos
);
1540 else if (strnicmp(colorname
, "rgb:", 4) == 0)
1548 color
= colorname
+ 4;
1549 for (i
= 0; i
< 3; i
++)
1552 unsigned long value
;
1554 /* The check for 'x' in the following conditional takes into
1555 account the fact that strtol allows a "0x" in front of
1556 our numbers, and we don't. */
1557 if (!isxdigit(color
[0]) || color
[1] == 'x')
1559 value
= strtoul(color
, &end
, 16);
1560 if (errno
== ERANGE
)
1562 switch (end
- color
)
1565 value
= value
* 0x10 + value
;
1578 if (value
== ULONG_MAX
)
1580 colorval
|= (value
<< pos
);
1594 else if (strnicmp(colorname
, "rgbi:", 5) == 0)
1596 /* This is an RGB Intensity specification. */
1603 color
= colorname
+ 5;
1604 for (i
= 0; i
< 3; i
++)
1610 value
= strtod(color
, &end
);
1611 if (errno
== ERANGE
)
1613 if (value
< 0.0 || value
> 1.0)
1615 val
= (UINT
)(0x100 * value
);
1616 /* We used 0x100 instead of 0xFF to give an continuous
1617 range between 0.0 and 1.0 inclusive. The next statement
1618 fixes the 1.0 case. */
1621 colorval
|= (val
<< pos
);
1635 /* I am not going to attempt to handle any of the CIE color schemes
1636 or TekHVC, since I don't know the algorithms for conversion to
1639 /* If we fail to lookup the color name in w32_color_map, then check the
1640 colorname to see if it can be crudely approximated: If the X color
1641 ends in a number (e.g., "darkseagreen2"), strip the number and
1642 return the result of looking up the base color name. */
1643 ret
= w32_color_map_lookup (colorname
);
1646 int len
= strlen (colorname
);
1648 if (isdigit (colorname
[len
- 1]))
1650 char *ptr
, *approx
= alloca (len
+ 1);
1652 strcpy (approx
, colorname
);
1653 ptr
= &approx
[len
- 1];
1654 while (ptr
> approx
&& isdigit (*ptr
))
1657 ret
= w32_color_map_lookup (approx
);
1667 w32_regenerate_palette (FRAME_PTR f
)
1669 struct w32_palette_entry
* list
;
1670 LOGPALETTE
* log_palette
;
1671 HPALETTE new_palette
;
1674 /* don't bother trying to create palette if not supported */
1675 if (! FRAME_W32_DISPLAY_INFO (f
)->has_palette
)
1678 log_palette
= (LOGPALETTE
*)
1679 alloca (sizeof (LOGPALETTE
) +
1680 FRAME_W32_DISPLAY_INFO (f
)->num_colors
* sizeof (PALETTEENTRY
));
1681 log_palette
->palVersion
= 0x300;
1682 log_palette
->palNumEntries
= FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1684 list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1686 i
< FRAME_W32_DISPLAY_INFO (f
)->num_colors
;
1687 i
++, list
= list
->next
)
1688 log_palette
->palPalEntry
[i
] = list
->entry
;
1690 new_palette
= CreatePalette (log_palette
);
1694 if (FRAME_W32_DISPLAY_INFO (f
)->palette
)
1695 DeleteObject (FRAME_W32_DISPLAY_INFO (f
)->palette
);
1696 FRAME_W32_DISPLAY_INFO (f
)->palette
= new_palette
;
1698 /* Realize display palette and garbage all frames. */
1699 release_frame_dc (f
, get_frame_dc (f
));
1704 #define W32_COLOR(pe) RGB (pe.peRed, pe.peGreen, pe.peBlue)
1705 #define SET_W32_COLOR(pe, color) \
1708 pe.peRed = GetRValue (color); \
1709 pe.peGreen = GetGValue (color); \
1710 pe.peBlue = GetBValue (color); \
1715 /* Keep these around in case we ever want to track color usage. */
1717 w32_map_color (FRAME_PTR f
, COLORREF color
)
1719 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1721 if (NILP (Vw32_enable_palette
))
1724 /* check if color is already mapped */
1727 if (W32_COLOR (list
->entry
) == color
)
1735 /* not already mapped, so add to list and recreate Windows palette */
1736 list
= (struct w32_palette_entry
*)
1737 xmalloc (sizeof (struct w32_palette_entry
));
1738 SET_W32_COLOR (list
->entry
, color
);
1740 list
->next
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1741 FRAME_W32_DISPLAY_INFO (f
)->color_list
= list
;
1742 FRAME_W32_DISPLAY_INFO (f
)->num_colors
++;
1744 /* set flag that palette must be regenerated */
1745 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1749 w32_unmap_color (FRAME_PTR f
, COLORREF color
)
1751 struct w32_palette_entry
* list
= FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1752 struct w32_palette_entry
**prev
= &FRAME_W32_DISPLAY_INFO (f
)->color_list
;
1754 if (NILP (Vw32_enable_palette
))
1757 /* check if color is already mapped */
1760 if (W32_COLOR (list
->entry
) == color
)
1762 if (--list
->refcount
== 0)
1766 FRAME_W32_DISPLAY_INFO (f
)->num_colors
--;
1776 /* set flag that palette must be regenerated */
1777 FRAME_W32_DISPLAY_INFO (f
)->regen_palette
= TRUE
;
1782 /* Gamma-correct COLOR on frame F. */
1785 gamma_correct (f
, color
)
1791 *color
= PALETTERGB (
1792 pow (GetRValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1793 pow (GetGValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5,
1794 pow (GetBValue (*color
) / 255.0, f
->gamma
) * 255.0 + 0.5);
1799 /* Decide if color named COLOR is valid for the display associated with
1800 the selected frame; if so, return the rgb values in COLOR_DEF.
1801 If ALLOC is nonzero, allocate a new colormap cell. */
1804 w32_defined_color (f
, color
, color_def
, alloc
)
1810 register Lisp_Object tem
;
1811 COLORREF w32_color_ref
;
1813 tem
= x_to_w32_color (color
);
1819 /* Apply gamma correction. */
1820 w32_color_ref
= XUINT (tem
);
1821 gamma_correct (f
, &w32_color_ref
);
1822 XSETINT (tem
, w32_color_ref
);
1825 /* Map this color to the palette if it is enabled. */
1826 if (!NILP (Vw32_enable_palette
))
1828 struct w32_palette_entry
* entry
=
1829 one_w32_display_info
.color_list
;
1830 struct w32_palette_entry
** prev
=
1831 &one_w32_display_info
.color_list
;
1833 /* check if color is already mapped */
1836 if (W32_COLOR (entry
->entry
) == XUINT (tem
))
1838 prev
= &entry
->next
;
1839 entry
= entry
->next
;
1842 if (entry
== NULL
&& alloc
)
1844 /* not already mapped, so add to list */
1845 entry
= (struct w32_palette_entry
*)
1846 xmalloc (sizeof (struct w32_palette_entry
));
1847 SET_W32_COLOR (entry
->entry
, XUINT (tem
));
1850 one_w32_display_info
.num_colors
++;
1852 /* set flag that palette must be regenerated */
1853 one_w32_display_info
.regen_palette
= TRUE
;
1856 /* Ensure COLORREF value is snapped to nearest color in (default)
1857 palette by simulating the PALETTERGB macro. This works whether
1858 or not the display device has a palette. */
1859 w32_color_ref
= XUINT (tem
) | 0x2000000;
1861 color_def
->pixel
= w32_color_ref
;
1862 color_def
->red
= GetRValue (w32_color_ref
);
1863 color_def
->green
= GetGValue (w32_color_ref
);
1864 color_def
->blue
= GetBValue (w32_color_ref
);
1874 /* Given a string ARG naming a color, compute a pixel value from it
1875 suitable for screen F.
1876 If F is not a color screen, return DEF (default) regardless of what
1880 x_decode_color (f
, arg
, def
)
1887 CHECK_STRING (arg
, 0);
1889 if (strcmp (XSTRING (arg
)->data
, "black") == 0)
1890 return BLACK_PIX_DEFAULT (f
);
1891 else if (strcmp (XSTRING (arg
)->data
, "white") == 0)
1892 return WHITE_PIX_DEFAULT (f
);
1894 if ((FRAME_W32_DISPLAY_INFO (f
)->n_planes
* FRAME_W32_DISPLAY_INFO (f
)->n_cbits
) == 1)
1897 /* w32_defined_color is responsible for coping with failures
1898 by looking for a near-miss. */
1899 if (w32_defined_color (f
, XSTRING (arg
)->data
, &cdef
, 1))
1902 /* defined_color failed; return an ultimate default. */
1906 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
1907 the previous value of that parameter, NEW_VALUE is the new value. */
1910 x_set_line_spacing (f
, new_value
, old_value
)
1912 Lisp_Object new_value
, old_value
;
1914 if (NILP (new_value
))
1915 f
->extra_line_spacing
= 0;
1916 else if (NATNUMP (new_value
))
1917 f
->extra_line_spacing
= XFASTINT (new_value
);
1919 Fsignal (Qerror
, Fcons (build_string ("Invalid line-spacing"),
1920 Fcons (new_value
, Qnil
)));
1921 if (FRAME_VISIBLE_P (f
))
1926 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
1927 the previous value of that parameter, NEW_VALUE is the new value. */
1930 x_set_screen_gamma (f
, new_value
, old_value
)
1932 Lisp_Object new_value
, old_value
;
1934 if (NILP (new_value
))
1936 else if (NUMBERP (new_value
) && XFLOATINT (new_value
) > 0)
1937 /* The value 0.4545 is the normal viewing gamma. */
1938 f
->gamma
= 1.0 / (0.4545 * XFLOATINT (new_value
));
1940 Fsignal (Qerror
, Fcons (build_string ("Invalid screen-gamma"),
1941 Fcons (new_value
, Qnil
)));
1943 clear_face_cache (0);
1947 /* Functions called only from `x_set_frame_param'
1948 to set individual parameters.
1950 If FRAME_W32_WINDOW (f) is 0,
1951 the frame is being created and its window does not exist yet.
1952 In that case, just record the parameter's new value
1953 in the standard place; do not attempt to change the window. */
1956 x_set_foreground_color (f
, arg
, oldval
)
1958 Lisp_Object arg
, oldval
;
1960 struct w32_output
*x
= f
->output_data
.w32
;
1961 PIX_TYPE fg
, old_fg
;
1963 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1964 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
1965 FRAME_FOREGROUND_PIXEL (f
) = fg
;
1967 if (FRAME_W32_WINDOW (f
) != 0)
1969 if (x
->cursor_pixel
== old_fg
)
1970 x
->cursor_pixel
= fg
;
1972 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1973 if (FRAME_VISIBLE_P (f
))
1979 x_set_background_color (f
, arg
, oldval
)
1981 Lisp_Object arg
, oldval
;
1983 FRAME_BACKGROUND_PIXEL (f
)
1984 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1986 if (FRAME_W32_WINDOW (f
) != 0)
1988 SetWindowLong (FRAME_W32_WINDOW (f
), WND_BACKGROUND_INDEX
,
1989 FRAME_BACKGROUND_PIXEL (f
));
1991 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1993 if (FRAME_VISIBLE_P (f
))
1999 x_set_mouse_color (f
, arg
, oldval
)
2001 Lisp_Object arg
, oldval
;
2003 Cursor cursor
, nontext_cursor
, mode_cursor
, cross_cursor
;
2007 if (!EQ (Qnil
, arg
))
2008 f
->output_data
.w32
->mouse_pixel
2009 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2010 mask_color
= FRAME_BACKGROUND_PIXEL (f
);
2012 /* Don't let pointers be invisible. */
2013 if (mask_color
== f
->output_data
.w32
->mouse_pixel
2014 && mask_color
== FRAME_BACKGROUND_PIXEL (f
))
2015 f
->output_data
.w32
->mouse_pixel
= FRAME_FOREGROUND_PIXEL (f
);
2017 #if 0 /* TODO : cursor changes */
2020 /* It's not okay to crash if the user selects a screwy cursor. */
2021 count
= x_catch_errors (FRAME_W32_DISPLAY (f
));
2023 if (!EQ (Qnil
, Vx_pointer_shape
))
2025 CHECK_NUMBER (Vx_pointer_shape
, 0);
2026 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XINT (Vx_pointer_shape
));
2029 cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2030 x_check_errors (FRAME_W32_DISPLAY (f
), "bad text pointer cursor: %s");
2032 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
2034 CHECK_NUMBER (Vx_nontext_pointer_shape
, 0);
2035 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2036 XINT (Vx_nontext_pointer_shape
));
2039 nontext_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_left_ptr
);
2040 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2042 if (!EQ (Qnil
, Vx_hourglass_pointer_shape
))
2044 CHECK_NUMBER (Vx_hourglass_pointer_shape
, 0);
2045 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2046 XINT (Vx_hourglass_pointer_shape
));
2049 hourglass_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_watch
);
2050 x_check_errors (FRAME_W32_DISPLAY (f
), "bad busy pointer cursor: %s");
2052 x_check_errors (FRAME_W32_DISPLAY (f
), "bad nontext pointer cursor: %s");
2053 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
2055 CHECK_NUMBER (Vx_mode_pointer_shape
, 0);
2056 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2057 XINT (Vx_mode_pointer_shape
));
2060 mode_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_xterm
);
2061 x_check_errors (FRAME_W32_DISPLAY (f
), "bad modeline pointer cursor: %s");
2063 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
2065 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
, 0);
2067 = XCreateFontCursor (FRAME_W32_DISPLAY (f
),
2068 XINT (Vx_sensitive_text_pointer_shape
));
2071 cross_cursor
= XCreateFontCursor (FRAME_W32_DISPLAY (f
), XC_crosshair
);
2073 if (!NILP (Vx_window_horizontal_drag_shape
))
2075 CHECK_NUMBER (Vx_window_horizontal_drag_shape
, 0);
2076 horizontal_drag_cursor
2077 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
2078 XINT (Vx_window_horizontal_drag_shape
));
2081 horizontal_drag_cursor
2082 = XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_sb_h_double_arrow
);
2084 /* Check and report errors with the above calls. */
2085 x_check_errors (FRAME_W32_DISPLAY (f
), "can't set cursor shape: %s");
2086 x_uncatch_errors (FRAME_W32_DISPLAY (f
), count
);
2089 XColor fore_color
, back_color
;
2091 fore_color
.pixel
= f
->output_data
.w32
->mouse_pixel
;
2092 back_color
.pixel
= mask_color
;
2093 XQueryColor (FRAME_W32_DISPLAY (f
),
2094 DefaultColormap (FRAME_W32_DISPLAY (f
),
2095 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2097 XQueryColor (FRAME_W32_DISPLAY (f
),
2098 DefaultColormap (FRAME_W32_DISPLAY (f
),
2099 DefaultScreen (FRAME_W32_DISPLAY (f
))),
2101 XRecolorCursor (FRAME_W32_DISPLAY (f
), cursor
,
2102 &fore_color
, &back_color
);
2103 XRecolorCursor (FRAME_W32_DISPLAY (f
), nontext_cursor
,
2104 &fore_color
, &back_color
);
2105 XRecolorCursor (FRAME_W32_DISPLAY (f
), mode_cursor
,
2106 &fore_color
, &back_color
);
2107 XRecolorCursor (FRAME_W32_DISPLAY (f
), cross_cursor
,
2108 &fore_color
, &back_color
);
2109 XRecolorCursor (FRAME_W32_DISPLAY (f
), hourglass_cursor
,
2110 &fore_color
, &back_color
);
2113 if (FRAME_W32_WINDOW (f
) != 0)
2114 XDefineCursor (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), cursor
);
2116 if (cursor
!= f
->output_data
.w32
->text_cursor
&& f
->output_data
.w32
->text_cursor
!= 0)
2117 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->text_cursor
);
2118 f
->output_data
.w32
->text_cursor
= cursor
;
2120 if (nontext_cursor
!= f
->output_data
.w32
->nontext_cursor
2121 && f
->output_data
.w32
->nontext_cursor
!= 0)
2122 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->nontext_cursor
);
2123 f
->output_data
.w32
->nontext_cursor
= nontext_cursor
;
2125 if (hourglass_cursor
!= f
->output_data
.w32
->hourglass_cursor
2126 && f
->output_data
.w32
->hourglass_cursor
!= 0)
2127 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->hourglass_cursor
);
2128 f
->output_data
.w32
->hourglass_cursor
= hourglass_cursor
;
2130 if (mode_cursor
!= f
->output_data
.w32
->modeline_cursor
2131 && f
->output_data
.w32
->modeline_cursor
!= 0)
2132 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->modeline_cursor
);
2133 f
->output_data
.w32
->modeline_cursor
= mode_cursor
;
2135 if (cross_cursor
!= f
->output_data
.w32
->cross_cursor
2136 && f
->output_data
.w32
->cross_cursor
!= 0)
2137 XFreeCursor (FRAME_W32_DISPLAY (f
), f
->output_data
.w32
->cross_cursor
);
2138 f
->output_data
.w32
->cross_cursor
= cross_cursor
;
2140 XFlush (FRAME_W32_DISPLAY (f
));
2143 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
2147 /* Defined in w32term.c. */
2148 void x_update_cursor (struct frame
*f
, int on_p
);
2151 x_set_cursor_color (f
, arg
, oldval
)
2153 Lisp_Object arg
, oldval
;
2155 unsigned long fore_pixel
, pixel
;
2157 if (!NILP (Vx_cursor_fore_pixel
))
2158 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
2159 WHITE_PIX_DEFAULT (f
));
2161 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2163 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2165 /* Make sure that the cursor color differs from the background color. */
2166 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
2168 pixel
= f
->output_data
.w32
->mouse_pixel
;
2169 if (pixel
== fore_pixel
)
2170 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2173 FRAME_FOREGROUND_PIXEL (f
) = fore_pixel
;
2174 f
->output_data
.w32
->cursor_pixel
= pixel
;
2176 if (FRAME_W32_WINDOW (f
) != 0)
2178 if (FRAME_VISIBLE_P (f
))
2180 x_update_cursor (f
, 0);
2181 x_update_cursor (f
, 1);
2185 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
2188 /* Set the border-color of frame F to pixel value PIX.
2189 Note that this does not fully take effect if done before
2192 x_set_border_pixel (f
, pix
)
2196 f
->output_data
.w32
->border_pixel
= pix
;
2198 if (FRAME_W32_WINDOW (f
) != 0 && f
->output_data
.w32
->border_width
> 0)
2200 if (FRAME_VISIBLE_P (f
))
2205 /* Set the border-color of frame F to value described by ARG.
2206 ARG can be a string naming a color.
2207 The border-color is used for the border that is drawn by the server.
2208 Note that this does not fully take effect if done before
2209 F has a window; it must be redone when the window is created. */
2212 x_set_border_color (f
, arg
, oldval
)
2214 Lisp_Object arg
, oldval
;
2218 CHECK_STRING (arg
, 0);
2219 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
2220 x_set_border_pixel (f
, pix
);
2221 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
2224 /* Value is the internal representation of the specified cursor type
2225 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
2226 of the bar cursor. */
2228 enum text_cursor_kinds
2229 x_specified_cursor_type (arg
, width
)
2233 enum text_cursor_kinds type
;
2240 else if (CONSP (arg
)
2241 && EQ (XCAR (arg
), Qbar
)
2242 && INTEGERP (XCDR (arg
))
2243 && XINT (XCDR (arg
)) >= 0)
2246 *width
= XINT (XCDR (arg
));
2248 else if (NILP (arg
))
2251 /* Treat anything unknown as "box cursor".
2252 It was bad to signal an error; people have trouble fixing
2253 .Xdefaults with Emacs, when it has something bad in it. */
2254 type
= FILLED_BOX_CURSOR
;
2260 x_set_cursor_type (f
, arg
, oldval
)
2262 Lisp_Object arg
, oldval
;
2266 FRAME_DESIRED_CURSOR (f
) = x_specified_cursor_type (arg
, &width
);
2267 f
->output_data
.w32
->cursor_width
= width
;
2269 /* Make sure the cursor gets redrawn. This is overkill, but how
2270 often do people change cursor types? */
2271 update_mode_lines
++;
2275 x_set_icon_type (f
, arg
, oldval
)
2277 Lisp_Object arg
, oldval
;
2281 if (NILP (arg
) && NILP (oldval
))
2284 if (STRINGP (arg
) && STRINGP (oldval
)
2285 && EQ (Fstring_equal (oldval
, arg
), Qt
))
2288 if (SYMBOLP (arg
) && SYMBOLP (oldval
) && EQ (arg
, oldval
))
2293 result
= x_bitmap_icon (f
, arg
);
2297 error ("No icon window available");
2303 /* Return non-nil if frame F wants a bitmap icon. */
2311 tem
= assq_no_quit (Qicon_type
, f
->param_alist
);
2319 x_set_icon_name (f
, arg
, oldval
)
2321 Lisp_Object arg
, oldval
;
2325 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
2328 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
2334 if (f
->output_data
.w32
->icon_bitmap
!= 0)
2339 result
= x_text_icon (f
,
2340 (char *) XSTRING ((!NILP (f
->icon_name
)
2349 error ("No icon window available");
2352 /* If the window was unmapped (and its icon was mapped),
2353 the new icon is not mapped, so map the window in its stead. */
2354 if (FRAME_VISIBLE_P (f
))
2356 #ifdef USE_X_TOOLKIT
2357 XtPopup (f
->output_data
.w32
->widget
, XtGrabNone
);
2359 XMapWindow (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
));
2362 XFlush (FRAME_W32_DISPLAY (f
));
2367 extern Lisp_Object
x_new_font ();
2368 extern Lisp_Object
x_new_fontset();
2371 x_set_font (f
, arg
, oldval
)
2373 Lisp_Object arg
, oldval
;
2376 Lisp_Object fontset_name
;
2378 int old_fontset
= FRAME_FONTSET (f
);
2380 CHECK_STRING (arg
, 1);
2382 fontset_name
= Fquery_fontset (arg
, Qnil
);
2385 result
= (STRINGP (fontset_name
)
2386 ? x_new_fontset (f
, XSTRING (fontset_name
)->data
)
2387 : x_new_font (f
, XSTRING (arg
)->data
));
2390 if (EQ (result
, Qnil
))
2391 error ("Font `%s' is not defined", XSTRING (arg
)->data
);
2392 else if (EQ (result
, Qt
))
2393 error ("The characters of the given font have varying widths");
2394 else if (STRINGP (result
))
2396 if (STRINGP (fontset_name
))
2398 /* Fontset names are built from ASCII font names, so the
2399 names may be equal despite there was a change. */
2400 if (old_fontset
== FRAME_FONTSET (f
))
2403 else if (!NILP (Fequal (result
, oldval
)))
2405 store_frame_param (f
, Qfont
, result
);
2406 recompute_basic_faces (f
);
2411 do_pending_window_change (0);
2413 /* Don't call `face-set-after-frame-default' when faces haven't been
2414 initialized yet. This is the case when called from
2415 Fx_create_frame. In that case, the X widget or window doesn't
2416 exist either, and we can end up in x_report_frame_params with a
2417 null widget which gives a segfault. */
2418 if (FRAME_FACE_CACHE (f
))
2420 XSETFRAME (frame
, f
);
2421 call1 (Qface_set_after_frame_default
, frame
);
2426 x_set_border_width (f
, arg
, oldval
)
2428 Lisp_Object arg
, oldval
;
2430 CHECK_NUMBER (arg
, 0);
2432 if (XINT (arg
) == f
->output_data
.w32
->border_width
)
2435 if (FRAME_W32_WINDOW (f
) != 0)
2436 error ("Cannot change the border width of a window");
2438 f
->output_data
.w32
->border_width
= XINT (arg
);
2442 x_set_internal_border_width (f
, arg
, oldval
)
2444 Lisp_Object arg
, oldval
;
2446 int old
= f
->output_data
.w32
->internal_border_width
;
2448 CHECK_NUMBER (arg
, 0);
2449 f
->output_data
.w32
->internal_border_width
= XINT (arg
);
2450 if (f
->output_data
.w32
->internal_border_width
< 0)
2451 f
->output_data
.w32
->internal_border_width
= 0;
2453 if (f
->output_data
.w32
->internal_border_width
== old
)
2456 if (FRAME_W32_WINDOW (f
) != 0)
2458 x_set_window_size (f
, 0, f
->width
, f
->height
);
2459 SET_FRAME_GARBAGED (f
);
2460 do_pending_window_change (0);
2463 SET_FRAME_GARBAGED (f
);
2467 x_set_visibility (f
, value
, oldval
)
2469 Lisp_Object value
, oldval
;
2472 XSETFRAME (frame
, f
);
2475 Fmake_frame_invisible (frame
, Qt
);
2476 else if (EQ (value
, Qicon
))
2477 Ficonify_frame (frame
);
2479 Fmake_frame_visible (frame
);
2483 /* Change window heights in windows rooted in WINDOW by N lines. */
2486 x_change_window_heights (window
, n
)
2490 struct window
*w
= XWINDOW (window
);
2492 XSETFASTINT (w
->top
, XFASTINT (w
->top
) + n
);
2493 XSETFASTINT (w
->height
, XFASTINT (w
->height
) - n
);
2495 if (INTEGERP (w
->orig_top
))
2496 XSETFASTINT (w
->orig_top
, XFASTINT (w
->orig_top
) + n
);
2497 if (INTEGERP (w
->orig_height
))
2498 XSETFASTINT (w
->orig_height
, XFASTINT (w
->orig_height
) - n
);
2500 /* Handle just the top child in a vertical split. */
2501 if (!NILP (w
->vchild
))
2502 x_change_window_heights (w
->vchild
, n
);
2504 /* Adjust all children in a horizontal split. */
2505 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
2507 w
= XWINDOW (window
);
2508 x_change_window_heights (window
, n
);
2513 x_set_menu_bar_lines (f
, value
, oldval
)
2515 Lisp_Object value
, oldval
;
2518 int olines
= FRAME_MENU_BAR_LINES (f
);
2520 /* Right now, menu bars don't work properly in minibuf-only frames;
2521 most of the commands try to apply themselves to the minibuffer
2522 frame itself, and get an error because you can't switch buffers
2523 in or split the minibuffer window. */
2524 if (FRAME_MINIBUF_ONLY_P (f
))
2527 if (INTEGERP (value
))
2528 nlines
= XINT (value
);
2532 FRAME_MENU_BAR_LINES (f
) = 0;
2534 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
2537 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
2538 free_frame_menubar (f
);
2539 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
2541 /* Adjust the frame size so that the client (text) dimensions
2542 remain the same. This depends on FRAME_EXTERNAL_MENU_BAR being
2544 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2545 do_pending_window_change (0);
2551 /* Set the number of lines used for the tool bar of frame F to VALUE.
2552 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
2553 is the old number of tool bar lines. This function changes the
2554 height of all windows on frame F to match the new tool bar height.
2555 The frame's height doesn't change. */
2558 x_set_tool_bar_lines (f
, value
, oldval
)
2560 Lisp_Object value
, oldval
;
2562 int delta
, nlines
, root_height
;
2563 Lisp_Object root_window
;
2565 /* Treat tool bars like menu bars. */
2566 if (FRAME_MINIBUF_ONLY_P (f
))
2569 /* Use VALUE only if an integer >= 0. */
2570 if (INTEGERP (value
) && XINT (value
) >= 0)
2571 nlines
= XFASTINT (value
);
2575 /* Make sure we redisplay all windows in this frame. */
2576 ++windows_or_buffers_changed
;
2578 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
2580 /* Don't resize the tool-bar to more than we have room for. */
2581 root_window
= FRAME_ROOT_WINDOW (f
);
2582 root_height
= XINT (XWINDOW (root_window
)->height
);
2583 if (root_height
- delta
< 1)
2585 delta
= root_height
- 1;
2586 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
2589 FRAME_TOOL_BAR_LINES (f
) = nlines
;
2590 x_change_window_heights (root_window
, delta
);
2593 /* We also have to make sure that the internal border at the top of
2594 the frame, below the menu bar or tool bar, is redrawn when the
2595 tool bar disappears. This is so because the internal border is
2596 below the tool bar if one is displayed, but is below the menu bar
2597 if there isn't a tool bar. The tool bar draws into the area
2598 below the menu bar. */
2599 if (FRAME_W32_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
2603 clear_current_matrices (f
);
2604 updating_frame
= NULL
;
2607 /* If the tool bar gets smaller, the internal border below it
2608 has to be cleared. It was formerly part of the display
2609 of the larger tool bar, and updating windows won't clear it. */
2612 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2613 int width
= PIXEL_WIDTH (f
);
2614 int y
= nlines
* CANON_Y_UNIT (f
);
2618 HDC hdc
= get_frame_dc (f
);
2619 w32_clear_area (f
, hdc
, 0, y
, width
, height
);
2620 release_frame_dc (f
, hdc
);
2627 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
2630 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2631 name; if NAME is a string, set F's name to NAME and set
2632 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2634 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2635 suggesting a new name, which lisp code should override; if
2636 F->explicit_name is set, ignore the new name; otherwise, set it. */
2639 x_set_name (f
, name
, explicit)
2644 /* Make sure that requests from lisp code override requests from
2645 Emacs redisplay code. */
2648 /* If we're switching from explicit to implicit, we had better
2649 update the mode lines and thereby update the title. */
2650 if (f
->explicit_name
&& NILP (name
))
2651 update_mode_lines
= 1;
2653 f
->explicit_name
= ! NILP (name
);
2655 else if (f
->explicit_name
)
2658 /* If NAME is nil, set the name to the w32_id_name. */
2661 /* Check for no change needed in this very common case
2662 before we do any consing. */
2663 if (!strcmp (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
,
2664 XSTRING (f
->name
)->data
))
2666 name
= build_string (FRAME_W32_DISPLAY_INFO (f
)->w32_id_name
);
2669 CHECK_STRING (name
, 0);
2671 /* Don't change the name if it's already NAME. */
2672 if (! NILP (Fstring_equal (name
, f
->name
)))
2677 /* For setting the frame title, the title parameter should override
2678 the name parameter. */
2679 if (! NILP (f
->title
))
2682 if (FRAME_W32_WINDOW (f
))
2684 if (STRING_MULTIBYTE (name
))
2685 name
= ENCODE_SYSTEM (name
);
2688 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2693 /* This function should be called when the user's lisp code has
2694 specified a name for the frame; the name will override any set by the
2697 x_explicitly_set_name (f
, arg
, oldval
)
2699 Lisp_Object arg
, oldval
;
2701 x_set_name (f
, arg
, 1);
2704 /* This function should be called by Emacs redisplay code to set the
2705 name; names set this way will never override names set by the user's
2708 x_implicitly_set_name (f
, arg
, oldval
)
2710 Lisp_Object arg
, oldval
;
2712 x_set_name (f
, arg
, 0);
2715 /* Change the title of frame F to NAME.
2716 If NAME is nil, use the frame name as the title.
2718 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2719 name; if NAME is a string, set F's name to NAME and set
2720 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2722 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2723 suggesting a new name, which lisp code should override; if
2724 F->explicit_name is set, ignore the new name; otherwise, set it. */
2727 x_set_title (f
, name
, old_name
)
2729 Lisp_Object name
, old_name
;
2731 /* Don't change the title if it's already NAME. */
2732 if (EQ (name
, f
->title
))
2735 update_mode_lines
= 1;
2742 if (FRAME_W32_WINDOW (f
))
2744 if (STRING_MULTIBYTE (name
))
2745 name
= ENCODE_SYSTEM (name
);
2748 SetWindowText(FRAME_W32_WINDOW (f
), XSTRING (name
)->data
);
2754 x_set_autoraise (f
, arg
, oldval
)
2756 Lisp_Object arg
, oldval
;
2758 f
->auto_raise
= !EQ (Qnil
, arg
);
2762 x_set_autolower (f
, arg
, oldval
)
2764 Lisp_Object arg
, oldval
;
2766 f
->auto_lower
= !EQ (Qnil
, arg
);
2770 x_set_unsplittable (f
, arg
, oldval
)
2772 Lisp_Object arg
, oldval
;
2774 f
->no_split
= !NILP (arg
);
2778 x_set_vertical_scroll_bars (f
, arg
, oldval
)
2780 Lisp_Object arg
, oldval
;
2782 if ((EQ (arg
, Qleft
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
2783 || (EQ (arg
, Qright
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
2784 || (NILP (arg
) && FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2785 || (!NILP (arg
) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)))
2787 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = NILP (arg
) ?
2788 vertical_scroll_bar_none
:
2789 /* Put scroll bars on the right by default, as is conventional
2792 ? vertical_scroll_bar_left
2793 : vertical_scroll_bar_right
;
2795 /* We set this parameter before creating the window for the
2796 frame, so we can get the geometry right from the start.
2797 However, if the window hasn't been created yet, we shouldn't
2798 call x_set_window_size. */
2799 if (FRAME_W32_WINDOW (f
))
2800 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2801 do_pending_window_change (0);
2806 x_set_scroll_bar_width (f
, arg
, oldval
)
2808 Lisp_Object arg
, oldval
;
2810 int wid
= FONT_WIDTH (f
->output_data
.w32
->font
);
2814 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = GetSystemMetrics (SM_CXVSCROLL
);
2815 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) +
2817 if (FRAME_W32_WINDOW (f
))
2818 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2819 do_pending_window_change (0);
2821 else if (INTEGERP (arg
) && XINT (arg
) > 0
2822 && XFASTINT (arg
) != FRAME_SCROLL_BAR_PIXEL_WIDTH (f
))
2824 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = XFASTINT (arg
);
2825 FRAME_SCROLL_BAR_COLS (f
) = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
2827 if (FRAME_W32_WINDOW (f
))
2828 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2829 do_pending_window_change (0);
2831 change_frame_size (f
, 0, FRAME_WIDTH (f
), 0, 0, 0);
2832 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.hpos
= 0;
2833 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.x
= 0;
2836 /* Subroutines of creating an frame. */
2838 /* Make sure that Vx_resource_name is set to a reasonable value.
2839 Fix it up, or set it to `emacs' if it is too hopeless. */
2842 validate_x_resource_name ()
2845 /* Number of valid characters in the resource name. */
2847 /* Number of invalid characters in the resource name. */
2852 if (STRINGP (Vx_resource_name
))
2854 unsigned char *p
= XSTRING (Vx_resource_name
)->data
;
2857 len
= STRING_BYTES (XSTRING (Vx_resource_name
));
2859 /* Only letters, digits, - and _ are valid in resource names.
2860 Count the valid characters and count the invalid ones. */
2861 for (i
= 0; i
< len
; i
++)
2864 if (! ((c
>= 'a' && c
<= 'z')
2865 || (c
>= 'A' && c
<= 'Z')
2866 || (c
>= '0' && c
<= '9')
2867 || c
== '-' || c
== '_'))
2874 /* Not a string => completely invalid. */
2875 bad_count
= 5, good_count
= 0;
2877 /* If name is valid already, return. */
2881 /* If name is entirely invalid, or nearly so, use `emacs'. */
2883 || (good_count
== 1 && bad_count
> 0))
2885 Vx_resource_name
= build_string ("emacs");
2889 /* Name is partly valid. Copy it and replace the invalid characters
2890 with underscores. */
2892 Vx_resource_name
= new = Fcopy_sequence (Vx_resource_name
);
2894 for (i
= 0; i
< len
; i
++)
2896 int c
= XSTRING (new)->data
[i
];
2897 if (! ((c
>= 'a' && c
<= 'z')
2898 || (c
>= 'A' && c
<= 'Z')
2899 || (c
>= '0' && c
<= '9')
2900 || c
== '-' || c
== '_'))
2901 XSTRING (new)->data
[i
] = '_';
2906 extern char *x_get_string_resource ();
2908 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
2909 "Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.\n\
2910 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the\n\
2911 class, where INSTANCE is the name under which Emacs was invoked, or\n\
2912 the name specified by the `-name' or `-rn' command-line arguments.\n\
2914 The optional arguments COMPONENT and SUBCLASS add to the key and the\n\
2915 class, respectively. You must specify both of them or neither.\n\
2916 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'\n\
2917 and the class is `Emacs.CLASS.SUBCLASS'.")
2918 (attribute
, class, component
, subclass
)
2919 Lisp_Object attribute
, class, component
, subclass
;
2921 register char *value
;
2925 CHECK_STRING (attribute
, 0);
2926 CHECK_STRING (class, 0);
2928 if (!NILP (component
))
2929 CHECK_STRING (component
, 1);
2930 if (!NILP (subclass
))
2931 CHECK_STRING (subclass
, 2);
2932 if (NILP (component
) != NILP (subclass
))
2933 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
2935 validate_x_resource_name ();
2937 /* Allocate space for the components, the dots which separate them,
2938 and the final '\0'. Make them big enough for the worst case. */
2939 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vx_resource_name
))
2940 + (STRINGP (component
)
2941 ? STRING_BYTES (XSTRING (component
)) : 0)
2942 + STRING_BYTES (XSTRING (attribute
))
2945 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
2946 + STRING_BYTES (XSTRING (class))
2947 + (STRINGP (subclass
)
2948 ? STRING_BYTES (XSTRING (subclass
)) : 0)
2951 /* Start with emacs.FRAMENAME for the name (the specific one)
2952 and with `Emacs' for the class key (the general one). */
2953 strcpy (name_key
, XSTRING (Vx_resource_name
)->data
);
2954 strcpy (class_key
, EMACS_CLASS
);
2956 strcat (class_key
, ".");
2957 strcat (class_key
, XSTRING (class)->data
);
2959 if (!NILP (component
))
2961 strcat (class_key
, ".");
2962 strcat (class_key
, XSTRING (subclass
)->data
);
2964 strcat (name_key
, ".");
2965 strcat (name_key
, XSTRING (component
)->data
);
2968 strcat (name_key
, ".");
2969 strcat (name_key
, XSTRING (attribute
)->data
);
2971 value
= x_get_string_resource (Qnil
,
2972 name_key
, class_key
);
2974 if (value
!= (char *) 0)
2975 return build_string (value
);
2980 /* Used when C code wants a resource value. */
2983 x_get_resource_string (attribute
, class)
2984 char *attribute
, *class;
2988 struct frame
*sf
= SELECTED_FRAME ();
2990 /* Allocate space for the components, the dots which separate them,
2991 and the final '\0'. */
2992 name_key
= (char *) alloca (STRING_BYTES (XSTRING (Vinvocation_name
))
2993 + strlen (attribute
) + 2);
2994 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
2995 + strlen (class) + 2);
2997 sprintf (name_key
, "%s.%s",
2998 XSTRING (Vinvocation_name
)->data
,
3000 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
3002 return x_get_string_resource (sf
, name_key
, class_key
);
3005 /* Types we might convert a resource string into. */
3015 /* Return the value of parameter PARAM.
3017 First search ALIST, then Vdefault_frame_alist, then the X defaults
3018 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3020 Convert the resource to the type specified by desired_type.
3022 If no default is specified, return Qunbound. If you call
3023 w32_get_arg, make sure you deal with Qunbound in a reasonable way,
3024 and don't let it get stored in any Lisp-visible variables! */
3027 w32_get_arg (alist
, param
, attribute
, class, type
)
3028 Lisp_Object alist
, param
;
3031 enum resource_types type
;
3033 register Lisp_Object tem
;
3035 tem
= Fassq (param
, alist
);
3037 tem
= Fassq (param
, Vdefault_frame_alist
);
3043 tem
= Fx_get_resource (build_string (attribute
),
3044 build_string (class),
3052 case RES_TYPE_NUMBER
:
3053 return make_number (atoi (XSTRING (tem
)->data
));
3055 case RES_TYPE_FLOAT
:
3056 return make_float (atof (XSTRING (tem
)->data
));
3058 case RES_TYPE_BOOLEAN
:
3059 tem
= Fdowncase (tem
);
3060 if (!strcmp (XSTRING (tem
)->data
, "on")
3061 || !strcmp (XSTRING (tem
)->data
, "true"))
3066 case RES_TYPE_STRING
:
3069 case RES_TYPE_SYMBOL
:
3070 /* As a special case, we map the values `true' and `on'
3071 to Qt, and `false' and `off' to Qnil. */
3074 lower
= Fdowncase (tem
);
3075 if (!strcmp (XSTRING (lower
)->data
, "on")
3076 || !strcmp (XSTRING (lower
)->data
, "true"))
3078 else if (!strcmp (XSTRING (lower
)->data
, "off")
3079 || !strcmp (XSTRING (lower
)->data
, "false"))
3082 return Fintern (tem
, Qnil
);
3095 /* Record in frame F the specified or default value according to ALIST
3096 of the parameter named PROP (a Lisp symbol).
3097 If no value is specified for PROP, look for an X default for XPROP
3098 on the frame named NAME.
3099 If that is not found either, use the value DEFLT. */
3102 x_default_parameter (f
, alist
, prop
, deflt
, xprop
, xclass
, type
)
3109 enum resource_types type
;
3113 tem
= w32_get_arg (alist
, prop
, xprop
, xclass
, type
);
3114 if (EQ (tem
, Qunbound
))
3116 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
3120 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
3121 "Parse an X-style geometry string STRING.\n\
3122 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).\n\
3123 The properties returned may include `top', `left', `height', and `width'.\n\
3124 The value of `left' or `top' may be an integer,\n\
3125 or a list (+ N) meaning N pixels relative to top/left corner,\n\
3126 or a list (- N) meaning -N pixels relative to bottom/right corner.")
3131 unsigned int width
, height
;
3134 CHECK_STRING (string
, 0);
3136 geometry
= XParseGeometry ((char *) XSTRING (string
)->data
,
3137 &x
, &y
, &width
, &height
);
3140 if (geometry
& XValue
)
3142 Lisp_Object element
;
3144 if (x
>= 0 && (geometry
& XNegative
))
3145 element
= Fcons (Qleft
, Fcons (Qminus
, Fcons (make_number (-x
), Qnil
)));
3146 else if (x
< 0 && ! (geometry
& XNegative
))
3147 element
= Fcons (Qleft
, Fcons (Qplus
, Fcons (make_number (x
), Qnil
)));
3149 element
= Fcons (Qleft
, make_number (x
));
3150 result
= Fcons (element
, result
);
3153 if (geometry
& YValue
)
3155 Lisp_Object element
;
3157 if (y
>= 0 && (geometry
& YNegative
))
3158 element
= Fcons (Qtop
, Fcons (Qminus
, Fcons (make_number (-y
), Qnil
)));
3159 else if (y
< 0 && ! (geometry
& YNegative
))
3160 element
= Fcons (Qtop
, Fcons (Qplus
, Fcons (make_number (y
), Qnil
)));
3162 element
= Fcons (Qtop
, make_number (y
));
3163 result
= Fcons (element
, result
);
3166 if (geometry
& WidthValue
)
3167 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
3168 if (geometry
& HeightValue
)
3169 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
3174 /* Calculate the desired size and position of this window,
3175 and return the flags saying which aspects were specified.
3177 This function does not make the coordinates positive. */
3179 #define DEFAULT_ROWS 40
3180 #define DEFAULT_COLS 80
3183 x_figure_window_size (f
, parms
)
3187 register Lisp_Object tem0
, tem1
, tem2
;
3188 long window_prompting
= 0;
3190 /* Default values if we fall through.
3191 Actually, if that happens we should get
3192 window manager prompting. */
3193 SET_FRAME_WIDTH (f
, DEFAULT_COLS
);
3194 f
->height
= DEFAULT_ROWS
;
3195 /* Window managers expect that if program-specified
3196 positions are not (0,0), they're intentional, not defaults. */
3197 f
->output_data
.w32
->top_pos
= 0;
3198 f
->output_data
.w32
->left_pos
= 0;
3200 /* Ensure that old new_width and new_height will not override the
3202 FRAME_NEW_WIDTH (f
) = 0;
3203 FRAME_NEW_HEIGHT (f
) = 0;
3205 tem0
= w32_get_arg (parms
, Qheight
, 0, 0, RES_TYPE_NUMBER
);
3206 tem1
= w32_get_arg (parms
, Qwidth
, 0, 0, RES_TYPE_NUMBER
);
3207 tem2
= w32_get_arg (parms
, Quser_size
, 0, 0, RES_TYPE_NUMBER
);
3208 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3210 if (!EQ (tem0
, Qunbound
))
3212 CHECK_NUMBER (tem0
, 0);
3213 f
->height
= XINT (tem0
);
3215 if (!EQ (tem1
, Qunbound
))
3217 CHECK_NUMBER (tem1
, 0);
3218 SET_FRAME_WIDTH (f
, XINT (tem1
));
3220 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
3221 window_prompting
|= USSize
;
3223 window_prompting
|= PSize
;
3226 f
->output_data
.w32
->vertical_scroll_bar_extra
3227 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
3229 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
3230 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
3231 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.w32
->font
)));
3232 f
->output_data
.w32
->flags_areas_extra
3233 = FRAME_FLAGS_AREA_WIDTH (f
);
3234 f
->output_data
.w32
->pixel_width
= CHAR_TO_PIXEL_WIDTH (f
, f
->width
);
3235 f
->output_data
.w32
->pixel_height
= CHAR_TO_PIXEL_HEIGHT (f
, f
->height
);
3237 tem0
= w32_get_arg (parms
, Qtop
, 0, 0, RES_TYPE_NUMBER
);
3238 tem1
= w32_get_arg (parms
, Qleft
, 0, 0, RES_TYPE_NUMBER
);
3239 tem2
= w32_get_arg (parms
, Quser_position
, 0, 0, RES_TYPE_NUMBER
);
3240 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3242 if (EQ (tem0
, Qminus
))
3244 f
->output_data
.w32
->top_pos
= 0;
3245 window_prompting
|= YNegative
;
3247 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qminus
)
3248 && CONSP (XCDR (tem0
))
3249 && INTEGERP (XCAR (XCDR (tem0
))))
3251 f
->output_data
.w32
->top_pos
= - XINT (XCAR (XCDR (tem0
)));
3252 window_prompting
|= YNegative
;
3254 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qplus
)
3255 && CONSP (XCDR (tem0
))
3256 && INTEGERP (XCAR (XCDR (tem0
))))
3258 f
->output_data
.w32
->top_pos
= XINT (XCAR (XCDR (tem0
)));
3260 else if (EQ (tem0
, Qunbound
))
3261 f
->output_data
.w32
->top_pos
= 0;
3264 CHECK_NUMBER (tem0
, 0);
3265 f
->output_data
.w32
->top_pos
= XINT (tem0
);
3266 if (f
->output_data
.w32
->top_pos
< 0)
3267 window_prompting
|= YNegative
;
3270 if (EQ (tem1
, Qminus
))
3272 f
->output_data
.w32
->left_pos
= 0;
3273 window_prompting
|= XNegative
;
3275 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qminus
)
3276 && CONSP (XCDR (tem1
))
3277 && INTEGERP (XCAR (XCDR (tem1
))))
3279 f
->output_data
.w32
->left_pos
= - XINT (XCAR (XCDR (tem1
)));
3280 window_prompting
|= XNegative
;
3282 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qplus
)
3283 && CONSP (XCDR (tem1
))
3284 && INTEGERP (XCAR (XCDR (tem1
))))
3286 f
->output_data
.w32
->left_pos
= XINT (XCAR (XCDR (tem1
)));
3288 else if (EQ (tem1
, Qunbound
))
3289 f
->output_data
.w32
->left_pos
= 0;
3292 CHECK_NUMBER (tem1
, 0);
3293 f
->output_data
.w32
->left_pos
= XINT (tem1
);
3294 if (f
->output_data
.w32
->left_pos
< 0)
3295 window_prompting
|= XNegative
;
3298 if (!NILP (tem2
) && ! EQ (tem2
, Qunbound
))
3299 window_prompting
|= USPosition
;
3301 window_prompting
|= PPosition
;
3304 return window_prompting
;
3309 extern LRESULT CALLBACK
w32_wnd_proc ();
3312 w32_init_class (hinst
)
3317 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
3318 wc
.lpfnWndProc
= (WNDPROC
) w32_wnd_proc
;
3320 wc
.cbWndExtra
= WND_EXTRA_BYTES
;
3321 wc
.hInstance
= hinst
;
3322 wc
.hIcon
= LoadIcon (hinst
, EMACS_CLASS
);
3323 wc
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
3324 wc
.hbrBackground
= NULL
; /* GetStockObject (WHITE_BRUSH); */
3325 wc
.lpszMenuName
= NULL
;
3326 wc
.lpszClassName
= EMACS_CLASS
;
3328 return (RegisterClass (&wc
));
3332 w32_createscrollbar (f
, bar
)
3334 struct scroll_bar
* bar
;
3336 return (CreateWindow ("SCROLLBAR", "", SBS_VERT
| WS_CHILD
| WS_VISIBLE
,
3337 /* Position and size of scroll bar. */
3338 XINT(bar
->left
) + VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
3340 XINT(bar
->width
) - VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
3342 FRAME_W32_WINDOW (f
),
3349 w32_createwindow (f
)
3355 rect
.left
= rect
.top
= 0;
3356 rect
.right
= PIXEL_WIDTH (f
);
3357 rect
.bottom
= PIXEL_HEIGHT (f
);
3359 AdjustWindowRect (&rect
, f
->output_data
.w32
->dwStyle
,
3360 FRAME_EXTERNAL_MENU_BAR (f
));
3362 /* Do first time app init */
3366 w32_init_class (hinst
);
3369 FRAME_W32_WINDOW (f
) = hwnd
3370 = CreateWindow (EMACS_CLASS
,
3372 f
->output_data
.w32
->dwStyle
| WS_CLIPCHILDREN
,
3373 f
->output_data
.w32
->left_pos
,
3374 f
->output_data
.w32
->top_pos
,
3375 rect
.right
- rect
.left
,
3376 rect
.bottom
- rect
.top
,
3384 SetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
, FONT_WIDTH (f
->output_data
.w32
->font
));
3385 SetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
, f
->output_data
.w32
->line_height
);
3386 SetWindowLong (hwnd
, WND_BORDER_INDEX
, f
->output_data
.w32
->internal_border_width
);
3387 SetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
, f
->output_data
.w32
->vertical_scroll_bar_extra
);
3388 SetWindowLong (hwnd
, WND_BACKGROUND_INDEX
, FRAME_BACKGROUND_PIXEL (f
));
3390 /* Enable drag-n-drop. */
3391 DragAcceptFiles (hwnd
, TRUE
);
3393 /* Do this to discard the default setting specified by our parent. */
3394 ShowWindow (hwnd
, SW_HIDE
);
3399 my_post_msg (wmsg
, hwnd
, msg
, wParam
, lParam
)
3406 wmsg
->msg
.hwnd
= hwnd
;
3407 wmsg
->msg
.message
= msg
;
3408 wmsg
->msg
.wParam
= wParam
;
3409 wmsg
->msg
.lParam
= lParam
;
3410 wmsg
->msg
.time
= GetMessageTime ();
3415 /* GetKeyState and MapVirtualKey on Windows 95 do not actually distinguish
3416 between left and right keys as advertised. We test for this
3417 support dynamically, and set a flag when the support is absent. If
3418 absent, we keep track of the left and right control and alt keys
3419 ourselves. This is particularly necessary on keyboards that rely
3420 upon the AltGr key, which is represented as having the left control
3421 and right alt keys pressed. For these keyboards, we need to know
3422 when the left alt key has been pressed in addition to the AltGr key
3423 so that we can properly support M-AltGr-key sequences (such as M-@
3424 on Swedish keyboards). */
3426 #define EMACS_LCONTROL 0
3427 #define EMACS_RCONTROL 1
3428 #define EMACS_LMENU 2
3429 #define EMACS_RMENU 3
3431 static int modifiers
[4];
3432 static int modifiers_recorded
;
3433 static int modifier_key_support_tested
;
3436 test_modifier_support (unsigned int wparam
)
3440 if (wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
)
3442 if (wparam
== VK_CONTROL
)
3452 if (!(GetKeyState (l
) & 0x8000) && !(GetKeyState (r
) & 0x8000))
3453 modifiers_recorded
= 1;
3455 modifiers_recorded
= 0;
3456 modifier_key_support_tested
= 1;
3460 record_keydown (unsigned int wparam
, unsigned int lparam
)
3464 if (!modifier_key_support_tested
)
3465 test_modifier_support (wparam
);
3467 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3470 if (wparam
== VK_CONTROL
)
3471 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3473 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3479 record_keyup (unsigned int wparam
, unsigned int lparam
)
3483 if ((wparam
!= VK_CONTROL
&& wparam
!= VK_MENU
) || !modifiers_recorded
)
3486 if (wparam
== VK_CONTROL
)
3487 i
= (lparam
& 0x1000000) ? EMACS_RCONTROL
: EMACS_LCONTROL
;
3489 i
= (lparam
& 0x1000000) ? EMACS_RMENU
: EMACS_LMENU
;
3494 /* Emacs can lose focus while a modifier key has been pressed. When
3495 it regains focus, be conservative and clear all modifiers since
3496 we cannot reconstruct the left and right modifier state. */
3502 if (GetFocus () == NULL
)
3503 /* Emacs doesn't have keyboard focus. Do nothing. */
3506 ctrl
= GetAsyncKeyState (VK_CONTROL
);
3507 alt
= GetAsyncKeyState (VK_MENU
);
3509 if (!(ctrl
& 0x08000))
3510 /* Clear any recorded control modifier state. */
3511 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3513 if (!(alt
& 0x08000))
3514 /* Clear any recorded alt modifier state. */
3515 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3517 /* Update the state of all modifier keys, because modifiers used in
3518 hot-key combinations can get stuck on if Emacs loses focus as a
3519 result of a hot-key being pressed. */
3523 #define CURRENT_STATE(key) ((GetAsyncKeyState (key) & 0x8000) >> 8)
3525 GetKeyboardState (keystate
);
3526 keystate
[VK_SHIFT
] = CURRENT_STATE (VK_SHIFT
);
3527 keystate
[VK_CONTROL
] = CURRENT_STATE (VK_CONTROL
);
3528 keystate
[VK_LCONTROL
] = CURRENT_STATE (VK_LCONTROL
);
3529 keystate
[VK_RCONTROL
] = CURRENT_STATE (VK_RCONTROL
);
3530 keystate
[VK_MENU
] = CURRENT_STATE (VK_MENU
);
3531 keystate
[VK_LMENU
] = CURRENT_STATE (VK_LMENU
);
3532 keystate
[VK_RMENU
] = CURRENT_STATE (VK_RMENU
);
3533 keystate
[VK_LWIN
] = CURRENT_STATE (VK_LWIN
);
3534 keystate
[VK_RWIN
] = CURRENT_STATE (VK_RWIN
);
3535 keystate
[VK_APPS
] = CURRENT_STATE (VK_APPS
);
3536 SetKeyboardState (keystate
);
3540 /* Synchronize modifier state with what is reported with the current
3541 keystroke. Even if we cannot distinguish between left and right
3542 modifier keys, we know that, if no modifiers are set, then neither
3543 the left or right modifier should be set. */
3547 if (!modifiers_recorded
)
3550 if (!(GetKeyState (VK_CONTROL
) & 0x8000))
3551 modifiers
[EMACS_RCONTROL
] = modifiers
[EMACS_LCONTROL
] = 0;
3553 if (!(GetKeyState (VK_MENU
) & 0x8000))
3554 modifiers
[EMACS_RMENU
] = modifiers
[EMACS_LMENU
] = 0;
3558 modifier_set (int vkey
)
3560 if (vkey
== VK_CAPITAL
|| vkey
== VK_SCROLL
)
3561 return (GetKeyState (vkey
) & 0x1);
3562 if (!modifiers_recorded
)
3563 return (GetKeyState (vkey
) & 0x8000);
3568 return modifiers
[EMACS_LCONTROL
];
3570 return modifiers
[EMACS_RCONTROL
];
3572 return modifiers
[EMACS_LMENU
];
3574 return modifiers
[EMACS_RMENU
];
3576 return (GetKeyState (vkey
) & 0x8000);
3579 /* Convert between the modifier bits W32 uses and the modifier bits
3583 w32_key_to_modifier (int key
)
3585 Lisp_Object key_mapping
;
3590 key_mapping
= Vw32_lwindow_modifier
;
3593 key_mapping
= Vw32_rwindow_modifier
;
3596 key_mapping
= Vw32_apps_modifier
;
3599 key_mapping
= Vw32_scroll_lock_modifier
;
3605 /* NB. This code runs in the input thread, asychronously to the lisp
3606 thread, so we must be careful to ensure access to lisp data is
3607 thread-safe. The following code is safe because the modifier
3608 variable values are updated atomically from lisp and symbols are
3609 not relocated by GC. Also, we don't have to worry about seeing GC
3611 if (EQ (key_mapping
, Qhyper
))
3612 return hyper_modifier
;
3613 if (EQ (key_mapping
, Qsuper
))
3614 return super_modifier
;
3615 if (EQ (key_mapping
, Qmeta
))
3616 return meta_modifier
;
3617 if (EQ (key_mapping
, Qalt
))
3618 return alt_modifier
;
3619 if (EQ (key_mapping
, Qctrl
))
3620 return ctrl_modifier
;
3621 if (EQ (key_mapping
, Qcontrol
)) /* synonym for ctrl */
3622 return ctrl_modifier
;
3623 if (EQ (key_mapping
, Qshift
))
3624 return shift_modifier
;
3626 /* Don't generate any modifier if not explicitly requested. */
3631 w32_get_modifiers ()
3633 return ((modifier_set (VK_SHIFT
) ? shift_modifier
: 0) |
3634 (modifier_set (VK_CONTROL
) ? ctrl_modifier
: 0) |
3635 (modifier_set (VK_LWIN
) ? w32_key_to_modifier (VK_LWIN
) : 0) |
3636 (modifier_set (VK_RWIN
) ? w32_key_to_modifier (VK_RWIN
) : 0) |
3637 (modifier_set (VK_APPS
) ? w32_key_to_modifier (VK_APPS
) : 0) |
3638 (modifier_set (VK_SCROLL
) ? w32_key_to_modifier (VK_SCROLL
) : 0) |
3639 (modifier_set (VK_MENU
) ?
3640 ((NILP (Vw32_alt_is_meta
)) ? alt_modifier
: meta_modifier
) : 0));
3643 /* We map the VK_* modifiers into console modifier constants
3644 so that we can use the same routines to handle both console
3645 and window input. */
3648 construct_console_modifiers ()
3653 mods
|= (modifier_set (VK_SHIFT
)) ? SHIFT_PRESSED
: 0;
3654 mods
|= (modifier_set (VK_CAPITAL
)) ? CAPSLOCK_ON
: 0;
3655 mods
|= (modifier_set (VK_SCROLL
)) ? SCROLLLOCK_ON
: 0;
3656 mods
|= (modifier_set (VK_NUMLOCK
)) ? NUMLOCK_ON
: 0;
3657 mods
|= (modifier_set (VK_LCONTROL
)) ? LEFT_CTRL_PRESSED
: 0;
3658 mods
|= (modifier_set (VK_RCONTROL
)) ? RIGHT_CTRL_PRESSED
: 0;
3659 mods
|= (modifier_set (VK_LMENU
)) ? LEFT_ALT_PRESSED
: 0;
3660 mods
|= (modifier_set (VK_RMENU
)) ? RIGHT_ALT_PRESSED
: 0;
3661 mods
|= (modifier_set (VK_LWIN
)) ? LEFT_WIN_PRESSED
: 0;
3662 mods
|= (modifier_set (VK_RWIN
)) ? RIGHT_WIN_PRESSED
: 0;
3663 mods
|= (modifier_set (VK_APPS
)) ? APPS_PRESSED
: 0;
3669 w32_get_key_modifiers (unsigned int wparam
, unsigned int lparam
)
3673 /* Convert to emacs modifiers. */
3674 mods
= w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam
);
3680 map_keypad_keys (unsigned int virt_key
, unsigned int extended
)
3682 if (virt_key
< VK_CLEAR
|| virt_key
> VK_DELETE
)
3685 if (virt_key
== VK_RETURN
)
3686 return (extended
? VK_NUMPAD_ENTER
: VK_RETURN
);
3688 if (virt_key
>= VK_PRIOR
&& virt_key
<= VK_DOWN
)
3689 return (!extended
? (VK_NUMPAD_PRIOR
+ (virt_key
- VK_PRIOR
)) : virt_key
);
3691 if (virt_key
== VK_INSERT
|| virt_key
== VK_DELETE
)
3692 return (!extended
? (VK_NUMPAD_INSERT
+ (virt_key
- VK_INSERT
)) : virt_key
);
3694 if (virt_key
== VK_CLEAR
)
3695 return (!extended
? VK_NUMPAD_CLEAR
: virt_key
);
3700 /* List of special key combinations which w32 would normally capture,
3701 but emacs should grab instead. Not directly visible to lisp, to
3702 simplify synchronization. Each item is an integer encoding a virtual
3703 key code and modifier combination to capture. */
3704 Lisp_Object w32_grabbed_keys
;
3706 #define HOTKEY(vk,mods) make_number (((vk) & 255) | ((mods) << 8))
3707 #define HOTKEY_ID(k) (XFASTINT (k) & 0xbfff)
3708 #define HOTKEY_VK_CODE(k) (XFASTINT (k) & 255)
3709 #define HOTKEY_MODIFIERS(k) (XFASTINT (k) >> 8)
3711 /* Register hot-keys for reserved key combinations when Emacs has
3712 keyboard focus, since this is the only way Emacs can receive key
3713 combinations like Alt-Tab which are used by the system. */
3716 register_hot_keys (hwnd
)
3719 Lisp_Object keylist
;
3721 /* Use GC_CONSP, since we are called asynchronously. */
3722 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3724 Lisp_Object key
= XCAR (keylist
);
3726 /* Deleted entries get set to nil. */
3727 if (!INTEGERP (key
))
3730 RegisterHotKey (hwnd
, HOTKEY_ID (key
),
3731 HOTKEY_MODIFIERS (key
), HOTKEY_VK_CODE (key
));
3736 unregister_hot_keys (hwnd
)
3739 Lisp_Object keylist
;
3741 /* Use GC_CONSP, since we are called asynchronously. */
3742 for (keylist
= w32_grabbed_keys
; GC_CONSP (keylist
); keylist
= XCDR (keylist
))
3744 Lisp_Object key
= XCAR (keylist
);
3746 if (!INTEGERP (key
))
3749 UnregisterHotKey (hwnd
, HOTKEY_ID (key
));
3753 /* Main message dispatch loop. */
3756 w32_msg_pump (deferred_msg
* msg_buf
)
3762 msh_mousewheel
= RegisterWindowMessage (MSH_MOUSEWHEEL
);
3764 while (GetMessage (&msg
, NULL
, 0, 0))
3766 if (msg
.hwnd
== NULL
)
3768 switch (msg
.message
)
3771 /* Produced by complete_deferred_msg; just ignore. */
3773 case WM_EMACS_CREATEWINDOW
:
3774 w32_createwindow ((struct frame
*) msg
.wParam
);
3775 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3778 case WM_EMACS_SETLOCALE
:
3779 SetThreadLocale (msg
.wParam
);
3780 /* Reply is not expected. */
3782 case WM_EMACS_SETKEYBOARDLAYOUT
:
3783 result
= (int) ActivateKeyboardLayout ((HKL
) msg
.wParam
, 0);
3784 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3788 case WM_EMACS_REGISTER_HOT_KEY
:
3789 focus_window
= GetFocus ();
3790 if (focus_window
!= NULL
)
3791 RegisterHotKey (focus_window
,
3792 HOTKEY_ID (msg
.wParam
),
3793 HOTKEY_MODIFIERS (msg
.wParam
),
3794 HOTKEY_VK_CODE (msg
.wParam
));
3795 /* Reply is not expected. */
3797 case WM_EMACS_UNREGISTER_HOT_KEY
:
3798 focus_window
= GetFocus ();
3799 if (focus_window
!= NULL
)
3800 UnregisterHotKey (focus_window
, HOTKEY_ID (msg
.wParam
));
3801 /* Mark item as erased. NB: this code must be
3802 thread-safe. The next line is okay because the cons
3803 cell is never made into garbage and is not relocated by
3805 XCAR ((Lisp_Object
) msg
.lParam
) = Qnil
;
3806 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3809 case WM_EMACS_TOGGLE_LOCK_KEY
:
3811 int vk_code
= (int) msg
.wParam
;
3812 int cur_state
= (GetKeyState (vk_code
) & 1);
3813 Lisp_Object new_state
= (Lisp_Object
) msg
.lParam
;
3815 /* NB: This code must be thread-safe. It is safe to
3816 call NILP because symbols are not relocated by GC,
3817 and pointer here is not touched by GC (so the markbit
3818 can't be set). Numbers are safe because they are
3819 immediate values. */
3820 if (NILP (new_state
)
3821 || (NUMBERP (new_state
)
3822 && ((XUINT (new_state
)) & 1) != cur_state
))
3824 one_w32_display_info
.faked_key
= vk_code
;
3826 keybd_event ((BYTE
) vk_code
,
3827 (BYTE
) MapVirtualKey (vk_code
, 0),
3828 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3829 keybd_event ((BYTE
) vk_code
,
3830 (BYTE
) MapVirtualKey (vk_code
, 0),
3831 KEYEVENTF_EXTENDEDKEY
| 0, 0);
3832 keybd_event ((BYTE
) vk_code
,
3833 (BYTE
) MapVirtualKey (vk_code
, 0),
3834 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
3835 cur_state
= !cur_state
;
3837 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
,
3843 DebPrint (("msg %x not expected by w32_msg_pump\n", msg
.message
));
3848 DispatchMessage (&msg
);
3851 /* Exit nested loop when our deferred message has completed. */
3852 if (msg_buf
->completed
)
3857 deferred_msg
* deferred_msg_head
;
3859 static deferred_msg
*
3860 find_deferred_msg (HWND hwnd
, UINT msg
)
3862 deferred_msg
* item
;
3864 /* Don't actually need synchronization for read access, since
3865 modification of single pointer is always atomic. */
3866 /* enter_crit (); */
3868 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3869 if (item
->w32msg
.msg
.hwnd
== hwnd
3870 && item
->w32msg
.msg
.message
== msg
)
3873 /* leave_crit (); */
3879 send_deferred_msg (deferred_msg
* msg_buf
,
3885 /* Only input thread can send deferred messages. */
3886 if (GetCurrentThreadId () != dwWindowsThreadId
)
3889 /* It is an error to send a message that is already deferred. */
3890 if (find_deferred_msg (hwnd
, msg
) != NULL
)
3893 /* Enforced synchronization is not needed because this is the only
3894 function that alters deferred_msg_head, and the following critical
3895 section is guaranteed to only be serially reentered (since only the
3896 input thread can call us). */
3898 /* enter_crit (); */
3900 msg_buf
->completed
= 0;
3901 msg_buf
->next
= deferred_msg_head
;
3902 deferred_msg_head
= msg_buf
;
3903 my_post_msg (&msg_buf
->w32msg
, hwnd
, msg
, wParam
, lParam
);
3905 /* leave_crit (); */
3907 /* Start a new nested message loop to process other messages until
3908 this one is completed. */
3909 w32_msg_pump (msg_buf
);
3911 deferred_msg_head
= msg_buf
->next
;
3913 return msg_buf
->result
;
3917 complete_deferred_msg (HWND hwnd
, UINT msg
, LRESULT result
)
3919 deferred_msg
* msg_buf
= find_deferred_msg (hwnd
, msg
);
3921 if (msg_buf
== NULL
)
3922 /* Message may have been cancelled, so don't abort(). */
3925 msg_buf
->result
= result
;
3926 msg_buf
->completed
= 1;
3928 /* Ensure input thread is woken so it notices the completion. */
3929 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
3933 cancel_all_deferred_msgs ()
3935 deferred_msg
* item
;
3937 /* Don't actually need synchronization for read access, since
3938 modification of single pointer is always atomic. */
3939 /* enter_crit (); */
3941 for (item
= deferred_msg_head
; item
!= NULL
; item
= item
->next
)
3944 item
->completed
= 1;
3947 /* leave_crit (); */
3949 /* Ensure input thread is woken so it notices the completion. */
3950 PostThreadMessage (dwWindowsThreadId
, WM_NULL
, 0, 0);
3958 deferred_msg dummy_buf
;
3960 /* Ensure our message queue is created */
3962 PeekMessage (&msg
, NULL
, 0, 0, PM_NOREMOVE
);
3964 if (!PostThreadMessage (dwMainThreadId
, WM_EMACS_DONE
, 0, 0))
3967 memset (&dummy_buf
, 0, sizeof (dummy_buf
));
3968 dummy_buf
.w32msg
.msg
.hwnd
= NULL
;
3969 dummy_buf
.w32msg
.msg
.message
= WM_NULL
;
3971 /* This is the inital message loop which should only exit when the
3972 application quits. */
3973 w32_msg_pump (&dummy_buf
);
3979 post_character_message (hwnd
, msg
, wParam
, lParam
, modifiers
)
3989 wmsg
.dwModifiers
= modifiers
;
3991 /* Detect quit_char and set quit-flag directly. Note that we
3992 still need to post a message to ensure the main thread will be
3993 woken up if blocked in sys_select(), but we do NOT want to post
3994 the quit_char message itself (because it will usually be as if
3995 the user had typed quit_char twice). Instead, we post a dummy
3996 message that has no particular effect. */
3999 if (isalpha (c
) && wmsg
.dwModifiers
== ctrl_modifier
)
4000 c
= make_ctrl_char (c
) & 0377;
4002 || (wmsg
.dwModifiers
== 0 &&
4003 XFASTINT (Vw32_quit_key
) && wParam
== XFASTINT (Vw32_quit_key
)))
4007 /* The choice of message is somewhat arbitrary, as long as
4008 the main thread handler just ignores it. */
4011 /* Interrupt any blocking system calls. */
4014 /* As a safety precaution, forcibly complete any deferred
4015 messages. This is a kludge, but I don't see any particularly
4016 clean way to handle the situation where a deferred message is
4017 "dropped" in the lisp thread, and will thus never be
4018 completed, eg. by the user trying to activate the menubar
4019 when the lisp thread is busy, and then typing C-g when the
4020 menubar doesn't open promptly (with the result that the
4021 menubar never responds at all because the deferred
4022 WM_INITMENU message is never completed). Another problem
4023 situation is when the lisp thread calls SendMessage (to send
4024 a window manager command) when a message has been deferred;
4025 the lisp thread gets blocked indefinitely waiting for the
4026 deferred message to be completed, which itself is waiting for
4027 the lisp thread to respond.
4029 Note that we don't want to block the input thread waiting for
4030 a reponse from the lisp thread (although that would at least
4031 solve the deadlock problem above), because we want to be able
4032 to receive C-g to interrupt the lisp thread. */
4033 cancel_all_deferred_msgs ();
4037 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4040 /* Main window procedure */
4043 w32_wnd_proc (hwnd
, msg
, wParam
, lParam
)
4050 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
4052 int windows_translate
;
4055 /* Note that it is okay to call x_window_to_frame, even though we are
4056 not running in the main lisp thread, because frame deletion
4057 requires the lisp thread to synchronize with this thread. Thus, if
4058 a frame struct is returned, it can be used without concern that the
4059 lisp thread might make it disappear while we are using it.
4061 NB. Walking the frame list in this thread is safe (as long as
4062 writes of Lisp_Object slots are atomic, which they are on Windows).
4063 Although delete-frame can destructively modify the frame list while
4064 we are walking it, a garbage collection cannot occur until after
4065 delete-frame has synchronized with this thread.
4067 It is also safe to use functions that make GDI calls, such as
4068 w32_clear_rect, because these functions must obtain a DC handle
4069 from the frame struct using get_frame_dc which is thread-aware. */
4074 f
= x_window_to_frame (dpyinfo
, hwnd
);
4077 HDC hdc
= get_frame_dc (f
);
4078 GetUpdateRect (hwnd
, &wmsg
.rect
, FALSE
);
4079 w32_clear_rect (f
, hdc
, &wmsg
.rect
);
4080 release_frame_dc (f
, hdc
);
4082 #if defined (W32_DEBUG_DISPLAY)
4083 DebPrint (("WM_ERASEBKGND (frame %p): erasing %d,%d-%d,%d\n",
4085 wmsg
.rect
.left
, wmsg
.rect
.top
,
4086 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
4087 #endif /* W32_DEBUG_DISPLAY */
4090 case WM_PALETTECHANGED
:
4091 /* ignore our own changes */
4092 if ((HWND
)wParam
!= hwnd
)
4094 f
= x_window_to_frame (dpyinfo
, hwnd
);
4096 /* get_frame_dc will realize our palette and force all
4097 frames to be redrawn if needed. */
4098 release_frame_dc (f
, get_frame_dc (f
));
4103 PAINTSTRUCT paintStruct
;
4105 bzero (&update_rect
, sizeof (update_rect
));
4107 f
= x_window_to_frame (dpyinfo
, hwnd
);
4110 DebPrint (("WM_PAINT received for unknown window %p\n", hwnd
));
4114 /* MSDN Docs say not to call BeginPaint if GetUpdateRect
4115 fails. Apparently this can happen under some
4117 if (GetUpdateRect (hwnd
, &update_rect
, FALSE
) || !w32_strict_painting
)
4120 BeginPaint (hwnd
, &paintStruct
);
4122 /* The rectangles returned by GetUpdateRect and BeginPaint
4123 do not always match. Play it safe by assuming both areas
4125 UnionRect (&(wmsg
.rect
), &update_rect
, &(paintStruct
.rcPaint
));
4127 #if defined (W32_DEBUG_DISPLAY)
4128 DebPrint (("WM_PAINT (frame %p): painting %d,%d-%d,%d\n",
4130 wmsg
.rect
.left
, wmsg
.rect
.top
,
4131 wmsg
.rect
.right
, wmsg
.rect
.bottom
));
4132 DebPrint ((" [update region is %d,%d-%d,%d]\n",
4133 update_rect
.left
, update_rect
.top
,
4134 update_rect
.right
, update_rect
.bottom
));
4136 EndPaint (hwnd
, &paintStruct
);
4139 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4144 /* If GetUpdateRect returns 0 (meaning there is no update
4145 region), assume the whole window needs to be repainted. */
4146 GetClientRect(hwnd
, &wmsg
.rect
);
4147 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4151 case WM_INPUTLANGCHANGE
:
4152 /* Inform lisp thread of keyboard layout changes. */
4153 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4155 /* Clear dead keys in the keyboard state; for simplicity only
4156 preserve modifier key states. */
4161 GetKeyboardState (keystate
);
4162 for (i
= 0; i
< 256; i
++)
4179 SetKeyboardState (keystate
);
4184 /* Synchronize hot keys with normal input. */
4185 PostMessage (hwnd
, WM_KEYDOWN
, HIWORD (lParam
), 0);
4190 record_keyup (wParam
, lParam
);
4195 /* Ignore keystrokes we fake ourself; see below. */
4196 if (dpyinfo
->faked_key
== wParam
)
4198 dpyinfo
->faked_key
= 0;
4199 /* Make sure TranslateMessage sees them though (as long as
4200 they don't produce WM_CHAR messages). This ensures that
4201 indicator lights are toggled promptly on Windows 9x, for
4203 if (lispy_function_keys
[wParam
] != 0)
4205 windows_translate
= 1;
4211 /* Synchronize modifiers with current keystroke. */
4213 record_keydown (wParam
, lParam
);
4214 wParam
= map_keypad_keys (wParam
, (lParam
& 0x1000000L
) != 0);
4216 windows_translate
= 0;
4221 if (NILP (Vw32_pass_lwindow_to_system
))
4223 /* Prevent system from acting on keyup (which opens the
4224 Start menu if no other key was pressed) by simulating a
4225 press of Space which we will ignore. */
4226 if (GetAsyncKeyState (wParam
) & 1)
4228 if (NUMBERP (Vw32_phantom_key_code
))
4229 key
= XUINT (Vw32_phantom_key_code
) & 255;
4232 dpyinfo
->faked_key
= key
;
4233 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4236 if (!NILP (Vw32_lwindow_modifier
))
4240 if (NILP (Vw32_pass_rwindow_to_system
))
4242 if (GetAsyncKeyState (wParam
) & 1)
4244 if (NUMBERP (Vw32_phantom_key_code
))
4245 key
= XUINT (Vw32_phantom_key_code
) & 255;
4248 dpyinfo
->faked_key
= key
;
4249 keybd_event (key
, (BYTE
) MapVirtualKey (key
, 0), 0, 0);
4252 if (!NILP (Vw32_rwindow_modifier
))
4256 if (!NILP (Vw32_apps_modifier
))
4260 if (NILP (Vw32_pass_alt_to_system
))
4261 /* Prevent DefWindowProc from activating the menu bar if an
4262 Alt key is pressed and released by itself. */
4264 windows_translate
= 1;
4267 /* Decide whether to treat as modifier or function key. */
4268 if (NILP (Vw32_enable_caps_lock
))
4269 goto disable_lock_key
;
4270 windows_translate
= 1;
4273 /* Decide whether to treat as modifier or function key. */
4274 if (NILP (Vw32_enable_num_lock
))
4275 goto disable_lock_key
;
4276 windows_translate
= 1;
4279 /* Decide whether to treat as modifier or function key. */
4280 if (NILP (Vw32_scroll_lock_modifier
))
4281 goto disable_lock_key
;
4282 windows_translate
= 1;
4285 /* Ensure the appropriate lock key state (and indicator light)
4286 remains in the same state. We do this by faking another
4287 press of the relevant key. Apparently, this really is the
4288 only way to toggle the state of the indicator lights. */
4289 dpyinfo
->faked_key
= wParam
;
4290 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4291 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4292 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4293 KEYEVENTF_EXTENDEDKEY
| 0, 0);
4294 keybd_event ((BYTE
) wParam
, (BYTE
) MapVirtualKey (wParam
, 0),
4295 KEYEVENTF_EXTENDEDKEY
| KEYEVENTF_KEYUP
, 0);
4296 /* Ensure indicator lights are updated promptly on Windows 9x
4297 (TranslateMessage apparently does this), after forwarding
4299 post_character_message (hwnd
, msg
, wParam
, lParam
,
4300 w32_get_key_modifiers (wParam
, lParam
));
4301 windows_translate
= 1;
4305 case VK_PROCESSKEY
: /* Generated by IME. */
4306 windows_translate
= 1;
4309 /* Windows maps Ctrl-Pause (aka Ctrl-Break) into VK_CANCEL,
4310 which is confusing for purposes of key binding; convert
4311 VK_CANCEL events into VK_PAUSE events. */
4315 /* Windows maps Ctrl-NumLock into VK_PAUSE, which is confusing
4316 for purposes of key binding; convert these back into
4317 VK_NUMLOCK events, at least when we want to see NumLock key
4318 presses. (Note that there is never any possibility that
4319 VK_PAUSE with Ctrl really is C-Pause as per above.) */
4320 if (NILP (Vw32_enable_num_lock
) && modifier_set (VK_CONTROL
))
4321 wParam
= VK_NUMLOCK
;
4324 /* If not defined as a function key, change it to a WM_CHAR message. */
4325 if (lispy_function_keys
[wParam
] == 0)
4327 DWORD modifiers
= construct_console_modifiers ();
4329 if (!NILP (Vw32_recognize_altgr
)
4330 && modifier_set (VK_LCONTROL
) && modifier_set (VK_RMENU
))
4332 /* Always let TranslateMessage handle AltGr key chords;
4333 for some reason, ToAscii doesn't always process AltGr
4334 chords correctly. */
4335 windows_translate
= 1;
4337 else if ((modifiers
& (~SHIFT_PRESSED
& ~CAPSLOCK_ON
)) != 0)
4339 /* Handle key chords including any modifiers other
4340 than shift directly, in order to preserve as much
4341 modifier information as possible. */
4342 if ('A' <= wParam
&& wParam
<= 'Z')
4344 /* Don't translate modified alphabetic keystrokes,
4345 so the user doesn't need to constantly switch
4346 layout to type control or meta keystrokes when
4347 the normal layout translates alphabetic
4348 characters to non-ascii characters. */
4349 if (!modifier_set (VK_SHIFT
))
4350 wParam
+= ('a' - 'A');
4355 /* Try to handle other keystrokes by determining the
4356 base character (ie. translating the base key plus
4360 KEY_EVENT_RECORD key
;
4362 key
.bKeyDown
= TRUE
;
4363 key
.wRepeatCount
= 1;
4364 key
.wVirtualKeyCode
= wParam
;
4365 key
.wVirtualScanCode
= (lParam
& 0xFF0000) >> 16;
4366 key
.uChar
.AsciiChar
= 0;
4367 key
.dwControlKeyState
= modifiers
;
4369 add
= w32_kbd_patch_key (&key
);
4370 /* 0 means an unrecognised keycode, negative means
4371 dead key. Ignore both. */
4374 /* Forward asciified character sequence. */
4375 post_character_message
4376 (hwnd
, WM_CHAR
, key
.uChar
.AsciiChar
, lParam
,
4377 w32_get_key_modifiers (wParam
, lParam
));
4378 w32_kbd_patch_key (&key
);
4385 /* Let TranslateMessage handle everything else. */
4386 windows_translate
= 1;
4392 if (windows_translate
)
4394 MSG windows_msg
= { hwnd
, msg
, wParam
, lParam
, 0, {0,0} };
4396 windows_msg
.time
= GetMessageTime ();
4397 TranslateMessage (&windows_msg
);
4405 post_character_message (hwnd
, msg
, wParam
, lParam
,
4406 w32_get_key_modifiers (wParam
, lParam
));
4409 /* Simulate middle mouse button events when left and right buttons
4410 are used together, but only if user has two button mouse. */
4411 case WM_LBUTTONDOWN
:
4412 case WM_RBUTTONDOWN
:
4413 if (XINT (Vw32_num_mouse_buttons
) > 2)
4414 goto handle_plain_button
;
4417 int this = (msg
== WM_LBUTTONDOWN
) ? LMOUSE
: RMOUSE
;
4418 int other
= (msg
== WM_LBUTTONDOWN
) ? RMOUSE
: LMOUSE
;
4420 if (button_state
& this)
4423 if (button_state
== 0)
4426 button_state
|= this;
4428 if (button_state
& other
)
4430 if (mouse_button_timer
)
4432 KillTimer (hwnd
, mouse_button_timer
);
4433 mouse_button_timer
= 0;
4435 /* Generate middle mouse event instead. */
4436 msg
= WM_MBUTTONDOWN
;
4437 button_state
|= MMOUSE
;
4439 else if (button_state
& MMOUSE
)
4441 /* Ignore button event if we've already generated a
4442 middle mouse down event. This happens if the
4443 user releases and press one of the two buttons
4444 after we've faked a middle mouse event. */
4449 /* Flush out saved message. */
4450 post_msg (&saved_mouse_button_msg
);
4452 wmsg
.dwModifiers
= w32_get_modifiers ();
4453 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4455 /* Clear message buffer. */
4456 saved_mouse_button_msg
.msg
.hwnd
= 0;
4460 /* Hold onto message for now. */
4461 mouse_button_timer
=
4462 SetTimer (hwnd
, MOUSE_BUTTON_ID
,
4463 XINT (Vw32_mouse_button_tolerance
), NULL
);
4464 saved_mouse_button_msg
.msg
.hwnd
= hwnd
;
4465 saved_mouse_button_msg
.msg
.message
= msg
;
4466 saved_mouse_button_msg
.msg
.wParam
= wParam
;
4467 saved_mouse_button_msg
.msg
.lParam
= lParam
;
4468 saved_mouse_button_msg
.msg
.time
= GetMessageTime ();
4469 saved_mouse_button_msg
.dwModifiers
= w32_get_modifiers ();
4476 if (XINT (Vw32_num_mouse_buttons
) > 2)
4477 goto handle_plain_button
;
4480 int this = (msg
== WM_LBUTTONUP
) ? LMOUSE
: RMOUSE
;
4481 int other
= (msg
== WM_LBUTTONUP
) ? RMOUSE
: LMOUSE
;
4483 if ((button_state
& this) == 0)
4486 button_state
&= ~this;
4488 if (button_state
& MMOUSE
)
4490 /* Only generate event when second button is released. */
4491 if ((button_state
& other
) == 0)
4494 button_state
&= ~MMOUSE
;
4496 if (button_state
) abort ();
4503 /* Flush out saved message if necessary. */
4504 if (saved_mouse_button_msg
.msg
.hwnd
)
4506 post_msg (&saved_mouse_button_msg
);
4509 wmsg
.dwModifiers
= w32_get_modifiers ();
4510 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4512 /* Always clear message buffer and cancel timer. */
4513 saved_mouse_button_msg
.msg
.hwnd
= 0;
4514 KillTimer (hwnd
, mouse_button_timer
);
4515 mouse_button_timer
= 0;
4517 if (button_state
== 0)
4522 case WM_MBUTTONDOWN
:
4524 handle_plain_button
:
4529 if (parse_button (msg
, &button
, &up
))
4531 if (up
) ReleaseCapture ();
4532 else SetCapture (hwnd
);
4533 button
= (button
== 0) ? LMOUSE
:
4534 ((button
== 1) ? MMOUSE
: RMOUSE
);
4536 button_state
&= ~button
;
4538 button_state
|= button
;
4542 wmsg
.dwModifiers
= w32_get_modifiers ();
4543 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4548 if (XINT (Vw32_mouse_move_interval
) <= 0
4549 || (msg
== WM_MOUSEMOVE
&& button_state
== 0))
4551 wmsg
.dwModifiers
= w32_get_modifiers ();
4552 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4556 /* Hang onto mouse move and scroll messages for a bit, to avoid
4557 sending such events to Emacs faster than it can process them.
4558 If we get more events before the timer from the first message
4559 expires, we just replace the first message. */
4561 if (saved_mouse_move_msg
.msg
.hwnd
== 0)
4563 SetTimer (hwnd
, MOUSE_MOVE_ID
,
4564 XINT (Vw32_mouse_move_interval
), NULL
);
4566 /* Hold onto message for now. */
4567 saved_mouse_move_msg
.msg
.hwnd
= hwnd
;
4568 saved_mouse_move_msg
.msg
.message
= msg
;
4569 saved_mouse_move_msg
.msg
.wParam
= wParam
;
4570 saved_mouse_move_msg
.msg
.lParam
= lParam
;
4571 saved_mouse_move_msg
.msg
.time
= GetMessageTime ();
4572 saved_mouse_move_msg
.dwModifiers
= w32_get_modifiers ();
4577 wmsg
.dwModifiers
= w32_get_modifiers ();
4578 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4582 wmsg
.dwModifiers
= w32_get_modifiers ();
4583 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4587 /* Flush out saved messages if necessary. */
4588 if (wParam
== mouse_button_timer
)
4590 if (saved_mouse_button_msg
.msg
.hwnd
)
4592 post_msg (&saved_mouse_button_msg
);
4593 saved_mouse_button_msg
.msg
.hwnd
= 0;
4595 KillTimer (hwnd
, mouse_button_timer
);
4596 mouse_button_timer
= 0;
4598 else if (wParam
== mouse_move_timer
)
4600 if (saved_mouse_move_msg
.msg
.hwnd
)
4602 post_msg (&saved_mouse_move_msg
);
4603 saved_mouse_move_msg
.msg
.hwnd
= 0;
4605 KillTimer (hwnd
, mouse_move_timer
);
4606 mouse_move_timer
= 0;
4611 /* Windows doesn't send us focus messages when putting up and
4612 taking down a system popup dialog as for Ctrl-Alt-Del on Windows 95.
4613 The only indication we get that something happened is receiving
4614 this message afterwards. So this is a good time to reset our
4615 keyboard modifiers' state. */
4622 /* We must ensure menu bar is fully constructed and up to date
4623 before allowing user interaction with it. To achieve this
4624 we send this message to the lisp thread and wait for a
4625 reply (whose value is not actually needed) to indicate that
4626 the menu bar is now ready for use, so we can now return.
4628 To remain responsive in the meantime, we enter a nested message
4629 loop that can process all other messages.
4631 However, we skip all this if the message results from calling
4632 TrackPopupMenu - in fact, we must NOT attempt to send the lisp
4633 thread a message because it is blocked on us at this point. We
4634 set menubar_active before calling TrackPopupMenu to indicate
4635 this (there is no possibility of confusion with real menubar
4638 f
= x_window_to_frame (dpyinfo
, hwnd
);
4640 && (f
->output_data
.w32
->menubar_active
4641 /* We can receive this message even in the absence of a
4642 menubar (ie. when the system menu is activated) - in this
4643 case we do NOT want to forward the message, otherwise it
4644 will cause the menubar to suddenly appear when the user
4645 had requested it to be turned off! */
4646 || f
->output_data
.w32
->menubar_widget
== NULL
))
4650 deferred_msg msg_buf
;
4652 /* Detect if message has already been deferred; in this case
4653 we cannot return any sensible value to ignore this. */
4654 if (find_deferred_msg (hwnd
, msg
) != NULL
)
4657 return send_deferred_msg (&msg_buf
, hwnd
, msg
, wParam
, lParam
);
4660 case WM_EXITMENULOOP
:
4661 f
= x_window_to_frame (dpyinfo
, hwnd
);
4663 /* Indicate that menubar can be modified again. */
4665 f
->output_data
.w32
->menubar_active
= 0;
4669 wmsg
.dwModifiers
= w32_get_modifiers ();
4670 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4673 case WM_MEASUREITEM
:
4674 f
= x_window_to_frame (dpyinfo
, hwnd
);
4677 MEASUREITEMSTRUCT
* pMis
= (MEASUREITEMSTRUCT
*) lParam
;
4679 if (pMis
->CtlType
== ODT_MENU
)
4681 /* Work out dimensions for popup menu titles. */
4682 char * title
= (char *) pMis
->itemData
;
4683 HDC hdc
= GetDC (hwnd
);
4684 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4685 LOGFONT menu_logfont
;
4689 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4690 menu_logfont
.lfWeight
= FW_BOLD
;
4691 menu_font
= CreateFontIndirect (&menu_logfont
);
4692 old_font
= SelectObject (hdc
, menu_font
);
4694 pMis
->itemHeight
= GetSystemMetrics (SM_CYMENUSIZE
);
4697 GetTextExtentPoint32 (hdc
, title
, strlen (title
), &size
);
4698 pMis
->itemWidth
= size
.cx
;
4699 if (pMis
->itemHeight
< size
.cy
)
4700 pMis
->itemHeight
= size
.cy
;
4703 pMis
->itemWidth
= 0;
4705 SelectObject (hdc
, old_font
);
4706 DeleteObject (menu_font
);
4707 ReleaseDC (hwnd
, hdc
);
4714 f
= x_window_to_frame (dpyinfo
, hwnd
);
4717 DRAWITEMSTRUCT
* pDis
= (DRAWITEMSTRUCT
*) lParam
;
4719 if (pDis
->CtlType
== ODT_MENU
)
4721 /* Draw popup menu title. */
4722 char * title
= (char *) pDis
->itemData
;
4725 HDC hdc
= pDis
->hDC
;
4726 HFONT menu_font
= GetCurrentObject (hdc
, OBJ_FONT
);
4727 LOGFONT menu_logfont
;
4730 GetObject (menu_font
, sizeof (menu_logfont
), &menu_logfont
);
4731 menu_logfont
.lfWeight
= FW_BOLD
;
4732 menu_font
= CreateFontIndirect (&menu_logfont
);
4733 old_font
= SelectObject (hdc
, menu_font
);
4735 /* Always draw title as if not selected. */
4738 + GetSystemMetrics (SM_CXMENUCHECK
),
4740 ETO_OPAQUE
, &pDis
->rcItem
,
4741 title
, strlen (title
), NULL
);
4743 SelectObject (hdc
, old_font
);
4744 DeleteObject (menu_font
);
4752 /* Still not right - can't distinguish between clicks in the
4753 client area of the frame from clicks forwarded from the scroll
4754 bars - may have to hook WM_NCHITTEST to remember the mouse
4755 position and then check if it is in the client area ourselves. */
4756 case WM_MOUSEACTIVATE
:
4757 /* Discard the mouse click that activates a frame, allowing the
4758 user to click anywhere without changing point (or worse!).
4759 Don't eat mouse clicks on scrollbars though!! */
4760 if (LOWORD (lParam
) == HTCLIENT
)
4761 return MA_ACTIVATEANDEAT
;
4765 case WM_ACTIVATEAPP
:
4767 case WM_WINDOWPOSCHANGED
:
4769 /* Inform lisp thread that a frame might have just been obscured
4770 or exposed, so should recheck visibility of all frames. */
4771 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4775 dpyinfo
->faked_key
= 0;
4777 register_hot_keys (hwnd
);
4780 unregister_hot_keys (hwnd
);
4787 wmsg
.dwModifiers
= w32_get_modifiers ();
4788 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4792 wmsg
.dwModifiers
= w32_get_modifiers ();
4793 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4796 case WM_WINDOWPOSCHANGING
:
4799 LPWINDOWPOS lppos
= (WINDOWPOS
*) lParam
;
4801 wp
.length
= sizeof (WINDOWPLACEMENT
);
4802 GetWindowPlacement (hwnd
, &wp
);
4804 if (wp
.showCmd
!= SW_SHOWMINIMIZED
&& (lppos
->flags
& SWP_NOSIZE
) == 0)
4811 DWORD internal_border
;
4812 DWORD scrollbar_extra
;
4815 wp
.length
= sizeof(wp
);
4816 GetWindowRect (hwnd
, &wr
);
4820 font_width
= GetWindowLong (hwnd
, WND_FONTWIDTH_INDEX
);
4821 line_height
= GetWindowLong (hwnd
, WND_LINEHEIGHT_INDEX
);
4822 internal_border
= GetWindowLong (hwnd
, WND_BORDER_INDEX
);
4823 scrollbar_extra
= GetWindowLong (hwnd
, WND_SCROLLBAR_INDEX
);
4827 memset (&rect
, 0, sizeof (rect
));
4828 AdjustWindowRect (&rect
, GetWindowLong (hwnd
, GWL_STYLE
),
4829 GetMenu (hwnd
) != NULL
);
4831 /* Force width and height of client area to be exact
4832 multiples of the character cell dimensions. */
4833 wdiff
= (lppos
->cx
- (rect
.right
- rect
.left
)
4834 - 2 * internal_border
- scrollbar_extra
)
4836 hdiff
= (lppos
->cy
- (rect
.bottom
- rect
.top
)
4837 - 2 * internal_border
)
4842 /* For right/bottom sizing we can just fix the sizes.
4843 However for top/left sizing we will need to fix the X
4844 and Y positions as well. */
4849 if (wp
.showCmd
!= SW_SHOWMAXIMIZED
4850 && (lppos
->flags
& SWP_NOMOVE
) == 0)
4852 if (lppos
->x
!= wr
.left
|| lppos
->y
!= wr
.top
)
4859 lppos
->flags
|= SWP_NOMOVE
;
4870 case WM_GETMINMAXINFO
:
4871 /* Hack to correct bug that allows Emacs frames to be resized
4872 below the Minimum Tracking Size. */
4873 ((LPMINMAXINFO
) lParam
)->ptMinTrackSize
.y
++;
4874 /* Hack to allow resizing the Emacs frame above the screen size.
4875 Note that Windows 9x limits coordinates to 16-bits. */
4876 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.x
= 32767;
4877 ((LPMINMAXINFO
) lParam
)->ptMaxTrackSize
.y
= 32767;
4880 case WM_EMACS_CREATESCROLLBAR
:
4881 return (LRESULT
) w32_createscrollbar ((struct frame
*) wParam
,
4882 (struct scroll_bar
*) lParam
);
4884 case WM_EMACS_SHOWWINDOW
:
4885 return ShowWindow ((HWND
) wParam
, (WPARAM
) lParam
);
4887 case WM_EMACS_SETFOREGROUND
:
4889 HWND foreground_window
;
4890 DWORD foreground_thread
, retval
;
4892 /* On NT 5.0, and apparently Windows 98, it is necessary to
4893 attach to the thread that currently has focus in order to
4894 pull the focus away from it. */
4895 foreground_window
= GetForegroundWindow ();
4896 foreground_thread
= GetWindowThreadProcessId (foreground_window
, NULL
);
4897 if (!foreground_window
4898 || foreground_thread
== GetCurrentThreadId ()
4899 || !AttachThreadInput (GetCurrentThreadId (),
4900 foreground_thread
, TRUE
))
4901 foreground_thread
= 0;
4903 retval
= SetForegroundWindow ((HWND
) wParam
);
4905 /* Detach from the previous foreground thread. */
4906 if (foreground_thread
)
4907 AttachThreadInput (GetCurrentThreadId (),
4908 foreground_thread
, FALSE
);
4913 case WM_EMACS_SETWINDOWPOS
:
4915 WINDOWPOS
* pos
= (WINDOWPOS
*) wParam
;
4916 return SetWindowPos (hwnd
, pos
->hwndInsertAfter
,
4917 pos
->x
, pos
->y
, pos
->cx
, pos
->cy
, pos
->flags
);
4920 case WM_EMACS_DESTROYWINDOW
:
4921 DragAcceptFiles ((HWND
) wParam
, FALSE
);
4922 return DestroyWindow ((HWND
) wParam
);
4924 case WM_EMACS_TRACKPOPUPMENU
:
4929 pos
= (POINT
*)lParam
;
4930 flags
= TPM_CENTERALIGN
;
4931 if (button_state
& LMOUSE
)
4932 flags
|= TPM_LEFTBUTTON
;
4933 else if (button_state
& RMOUSE
)
4934 flags
|= TPM_RIGHTBUTTON
;
4936 /* Remember we did a SetCapture on the initial mouse down event,
4937 so for safety, we make sure the capture is cancelled now. */
4941 /* Use menubar_active to indicate that WM_INITMENU is from
4942 TrackPopupMenu below, and should be ignored. */
4943 f
= x_window_to_frame (dpyinfo
, hwnd
);
4945 f
->output_data
.w32
->menubar_active
= 1;
4947 if (TrackPopupMenu ((HMENU
)wParam
, flags
, pos
->x
, pos
->y
,
4951 /* Eat any mouse messages during popupmenu */
4952 while (PeekMessage (&amsg
, hwnd
, WM_MOUSEFIRST
, WM_MOUSELAST
,
4954 /* Get the menu selection, if any */
4955 if (PeekMessage (&amsg
, hwnd
, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
))
4957 retval
= LOWORD (amsg
.wParam
);
4973 /* Check for messages registered at runtime. */
4974 if (msg
== msh_mousewheel
)
4976 wmsg
.dwModifiers
= w32_get_modifiers ();
4977 my_post_msg (&wmsg
, hwnd
, msg
, wParam
, lParam
);
4982 return DefWindowProc (hwnd
, msg
, wParam
, lParam
);
4986 /* The most common default return code for handled messages is 0. */
4991 my_create_window (f
)
4996 if (!PostThreadMessage (dwWindowsThreadId
, WM_EMACS_CREATEWINDOW
, (WPARAM
)f
, 0))
4998 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
5001 /* Create and set up the w32 window for frame F. */
5004 w32_window (f
, window_prompting
, minibuffer_only
)
5006 long window_prompting
;
5007 int minibuffer_only
;
5011 /* Use the resource name as the top-level window name
5012 for looking up resources. Make a non-Lisp copy
5013 for the window manager, so GC relocation won't bother it.
5015 Elsewhere we specify the window name for the window manager. */
5018 char *str
= (char *) XSTRING (Vx_resource_name
)->data
;
5019 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
5020 strcpy (f
->namebuf
, str
);
5023 my_create_window (f
);
5025 validate_x_resource_name ();
5027 /* x_set_name normally ignores requests to set the name if the
5028 requested name is the same as the current name. This is the one
5029 place where that assumption isn't correct; f->name is set, but
5030 the server hasn't been told. */
5033 int explicit = f
->explicit_name
;
5035 f
->explicit_name
= 0;
5038 x_set_name (f
, name
, explicit);
5043 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
5044 initialize_frame_menubar (f
);
5046 if (FRAME_W32_WINDOW (f
) == 0)
5047 error ("Unable to create window");
5050 /* Handle the icon stuff for this window. Perhaps later we might
5051 want an x_set_icon_position which can be called interactively as
5059 Lisp_Object icon_x
, icon_y
;
5061 /* Set the position of the icon. Note that Windows 95 groups all
5062 icons in the tray. */
5063 icon_x
= w32_get_arg (parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
5064 icon_y
= w32_get_arg (parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
5065 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
5067 CHECK_NUMBER (icon_x
, 0);
5068 CHECK_NUMBER (icon_y
, 0);
5070 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
5071 error ("Both left and top icon corners of icon must be specified");
5075 if (! EQ (icon_x
, Qunbound
))
5076 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
5079 /* Start up iconic or window? */
5080 x_wm_set_window_state
5081 (f
, (EQ (w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
), Qicon
)
5085 x_text_icon (f
, (char *) XSTRING ((!NILP (f
->icon_name
)
5098 XGCValues gc_values
;
5102 /* Create the GC's of this frame.
5103 Note that many default values are used. */
5106 gc_values
.font
= f
->output_data
.w32
->font
;
5108 /* Cursor has cursor-color background, background-color foreground. */
5109 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
5110 gc_values
.background
= f
->output_data
.w32
->cursor_pixel
;
5111 f
->output_data
.w32
->cursor_gc
5112 = XCreateGC (NULL
, FRAME_W32_WINDOW (f
),
5113 (GCFont
| GCForeground
| GCBackground
),
5117 f
->output_data
.w32
->white_relief
.gc
= 0;
5118 f
->output_data
.w32
->black_relief
.gc
= 0;
5124 /* Handler for signals raised during x_create_frame and
5125 x_create_top_frame. FRAME is the frame which is partially
5129 unwind_create_frame (frame
)
5132 struct frame
*f
= XFRAME (frame
);
5134 /* If frame is ``official'', nothing to do. */
5135 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
5138 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5141 x_free_frame_resources (f
);
5143 /* Check that reference counts are indeed correct. */
5144 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
5145 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
5154 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
5156 "Make a new window, which is called a \"frame\" in Emacs terms.\n\
5157 Returns an Emacs frame object.\n\
5158 ALIST is an alist of frame parameters.\n\
5159 If the parameters specify that the frame should not have a minibuffer,\n\
5160 and do not specify a specific minibuffer window to use,\n\
5161 then `default-minibuffer-frame' must be a frame whose minibuffer can\n\
5162 be shared by the new frame.\n\
5164 This function is an internal primitive--use `make-frame' instead.")
5169 Lisp_Object frame
, tem
;
5171 int minibuffer_only
= 0;
5172 long window_prompting
= 0;
5174 int count
= BINDING_STACK_SIZE ();
5175 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5176 Lisp_Object display
;
5177 struct w32_display_info
*dpyinfo
= NULL
;
5183 /* Use this general default value to start with
5184 until we know if this frame has a specified name. */
5185 Vx_resource_name
= Vinvocation_name
;
5187 display
= w32_get_arg (parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
5188 if (EQ (display
, Qunbound
))
5190 dpyinfo
= check_x_display_info (display
);
5192 kb
= dpyinfo
->kboard
;
5194 kb
= &the_only_kboard
;
5197 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5199 && ! EQ (name
, Qunbound
)
5201 error ("Invalid frame name--not a string or nil");
5204 Vx_resource_name
= name
;
5206 /* See if parent window is specified. */
5207 parent
= w32_get_arg (parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
5208 if (EQ (parent
, Qunbound
))
5210 if (! NILP (parent
))
5211 CHECK_NUMBER (parent
, 0);
5213 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
5214 /* No need to protect DISPLAY because that's not used after passing
5215 it to make_frame_without_minibuffer. */
5217 GCPRO4 (parms
, parent
, name
, frame
);
5218 tem
= w32_get_arg (parms
, Qminibuffer
, "minibuffer", "Minibuffer",
5220 if (EQ (tem
, Qnone
) || NILP (tem
))
5221 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
5222 else if (EQ (tem
, Qonly
))
5224 f
= make_minibuffer_frame ();
5225 minibuffer_only
= 1;
5227 else if (WINDOWP (tem
))
5228 f
= make_frame_without_minibuffer (tem
, kb
, display
);
5232 XSETFRAME (frame
, f
);
5234 /* Note that Windows does support scroll bars. */
5235 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
5236 /* By default, make scrollbars the system standard width. */
5237 f
->scroll_bar_pixel_width
= GetSystemMetrics (SM_CXVSCROLL
);
5239 f
->output_method
= output_w32
;
5240 f
->output_data
.w32
=
5241 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
5242 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
5243 FRAME_FONTSET (f
) = -1;
5244 record_unwind_protect (unwind_create_frame
, frame
);
5247 = w32_get_arg (parms
, Qicon_name
, "iconName", "Title", RES_TYPE_STRING
);
5248 if (! STRINGP (f
->icon_name
))
5249 f
->icon_name
= Qnil
;
5251 /* FRAME_W32_DISPLAY_INFO (f) = dpyinfo; */
5253 FRAME_KBOARD (f
) = kb
;
5256 /* Specify the parent under which to make this window. */
5260 f
->output_data
.w32
->parent_desc
= (Window
) XFASTINT (parent
);
5261 f
->output_data
.w32
->explicit_parent
= 1;
5265 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5266 f
->output_data
.w32
->explicit_parent
= 0;
5269 /* Set the name; the functions to which we pass f expect the name to
5271 if (EQ (name
, Qunbound
) || NILP (name
))
5273 f
->name
= build_string (dpyinfo
->w32_id_name
);
5274 f
->explicit_name
= 0;
5279 f
->explicit_name
= 1;
5280 /* use the frame's title when getting resources for this frame. */
5281 specbind (Qx_resource_name
, name
);
5284 /* Extract the window parameters from the supplied values
5285 that are needed to determine window geometry. */
5289 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
5292 /* First, try whatever font the caller has specified. */
5295 tem
= Fquery_fontset (font
, Qnil
);
5297 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
5299 font
= x_new_font (f
, XSTRING (font
)->data
);
5301 /* Try out a font which we hope has bold and italic variations. */
5302 if (!STRINGP (font
))
5303 font
= x_new_font (f
, "-*-Courier New-normal-r-*-*-*-100-*-*-c-*-iso8859-1");
5304 if (! STRINGP (font
))
5305 font
= x_new_font (f
, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1");
5306 /* If those didn't work, look for something which will at least work. */
5307 if (! STRINGP (font
))
5308 font
= x_new_font (f
, "-*-Fixedsys-normal-r-*-*-12-*-*-*-c-*-iso8859-1");
5310 if (! STRINGP (font
))
5311 font
= build_string ("Fixedsys");
5313 x_default_parameter (f
, parms
, Qfont
, font
,
5314 "font", "Font", RES_TYPE_STRING
);
5317 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
5318 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5319 /* This defaults to 2 in order to match xterm. We recognize either
5320 internalBorderWidth or internalBorder (which is what xterm calls
5322 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5326 value
= w32_get_arg (parms
, Qinternal_border_width
,
5327 "internalBorder", "InternalBorder", RES_TYPE_NUMBER
);
5328 if (! EQ (value
, Qunbound
))
5329 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5332 /* Default internalBorderWidth to 0 on Windows to match other programs. */
5333 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (0),
5334 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER
);
5335 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qright
,
5336 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL
);
5338 /* Also do the stuff which must be set before the window exists. */
5339 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5340 "foreground", "Foreground", RES_TYPE_STRING
);
5341 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5342 "background", "Background", RES_TYPE_STRING
);
5343 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5344 "pointerColor", "Foreground", RES_TYPE_STRING
);
5345 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5346 "cursorColor", "Foreground", RES_TYPE_STRING
);
5347 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5348 "borderColor", "BorderColor", RES_TYPE_STRING
);
5349 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
5350 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
5351 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
5352 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
5355 /* Init faces before x_default_parameter is called for scroll-bar
5356 parameters because that function calls x_set_scroll_bar_width,
5357 which calls change_frame_size, which calls Fset_window_buffer,
5358 which runs hooks, which call Fvertical_motion. At the end, we
5359 end up in init_iterator with a null face cache, which should not
5361 init_frame_faces (f
);
5363 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
5364 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
5365 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (0),
5366 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
5367 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
5368 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL
);
5369 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
5370 "title", "Title", RES_TYPE_STRING
);
5372 f
->output_data
.w32
->dwStyle
= WS_OVERLAPPEDWINDOW
;
5373 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
5374 window_prompting
= x_figure_window_size (f
, parms
);
5376 if (window_prompting
& XNegative
)
5378 if (window_prompting
& YNegative
)
5379 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
5381 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
5385 if (window_prompting
& YNegative
)
5386 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
5388 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
5391 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
5393 tem
= w32_get_arg (parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
5394 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
5396 w32_window (f
, window_prompting
, minibuffer_only
);
5401 /* Now consider the frame official. */
5402 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
5403 Vframe_list
= Fcons (frame
, Vframe_list
);
5405 /* We need to do this after creating the window, so that the
5406 icon-creation functions can say whose icon they're describing. */
5407 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
5408 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
5410 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5411 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5412 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5413 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5414 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5415 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5416 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
5417 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER
);
5419 /* Dimensions, especially f->height, must be done via change_frame_size.
5420 Change will not be effected unless different from the current
5425 /* Add the tool-bar height to the initial frame height so that the
5426 user gets a text display area of the size he specified with -g or
5427 via .Xdefaults. Later changes of the tool-bar height don't
5428 change the frame size. This is done so that users can create
5429 tall Emacs frames without having to guess how tall the tool-bar
5431 if (FRAME_TOOL_BAR_LINES (f
))
5433 int margin
, relief
, bar_height
;
5435 relief
= (tool_bar_button_relief
> 0
5436 ? tool_bar_button_relief
5437 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
5439 if (INTEGERP (Vtool_bar_button_margin
)
5440 && XINT (Vtool_bar_button_margin
) > 0)
5441 margin
= XFASTINT (Vtool_bar_button_margin
);
5442 else if (CONSP (Vtool_bar_button_margin
)
5443 && INTEGERP (XCDR (Vtool_bar_button_margin
))
5444 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
5445 margin
= XFASTINT (XCDR (Vtool_bar_button_margin
));
5449 bar_height
= DEFAULT_TOOL_BAR_IMAGE_HEIGHT
+ 2 * margin
+ 2 * relief
;
5450 height
+= (bar_height
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
5454 SET_FRAME_WIDTH (f
, 0);
5455 change_frame_size (f
, height
, width
, 1, 0, 0);
5457 /* Tell the server what size and position, etc, we want, and how
5458 badly we want them. This should be done after we have the menu
5459 bar so that its size can be taken into account. */
5461 x_wm_set_size_hint (f
, window_prompting
, 0);
5464 /* Avoid a bug that causes the new frame to never become visible if
5465 an echo area message is displayed during the following call1. */
5466 specbind(Qredisplay_dont_pause
, Qt
);
5468 /* Set up faces after all frame parameters are known. This call
5469 also merges in face attributes specified for new frames. If we
5470 don't do this, the `menu' face for instance won't have the right
5471 colors, and the menu bar won't appear in the specified colors for
5473 call1 (Qface_set_after_frame_default
, frame
);
5475 /* Make the window appear on the frame and enable display, unless
5476 the caller says not to. However, with explicit parent, Emacs
5477 cannot control visibility, so don't try. */
5478 if (! f
->output_data
.w32
->explicit_parent
)
5480 Lisp_Object visibility
;
5482 visibility
= w32_get_arg (parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
);
5483 if (EQ (visibility
, Qunbound
))
5486 if (EQ (visibility
, Qicon
))
5487 x_iconify_frame (f
);
5488 else if (! NILP (visibility
))
5489 x_make_frame_visible (f
);
5491 /* Must have been Qnil. */
5496 /* Make sure windows on this frame appear in calls to next-window
5497 and similar functions. */
5498 Vwindow_list
= Qnil
;
5500 return unbind_to (count
, frame
);
5503 /* FRAME is used only to get a handle on the X display. We don't pass the
5504 display info directly because we're called from frame.c, which doesn't
5505 know about that structure. */
5507 x_get_focus_frame (frame
)
5508 struct frame
*frame
;
5510 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (frame
);
5512 if (! dpyinfo
->w32_focus_frame
)
5515 XSETFRAME (xfocus
, dpyinfo
->w32_focus_frame
);
5519 DEFUN ("w32-focus-frame", Fw32_focus_frame
, Sw32_focus_frame
, 1, 1, 0,
5520 "Give FRAME input focus, raising to foreground if necessary.")
5524 x_focus_on_frame (check_x_frame (frame
));
5529 /* Return the charset portion of a font name. */
5530 char * xlfd_charset_of_font (char * fontname
)
5532 char *charset
, *encoding
;
5534 encoding
= strrchr(fontname
, '-');
5535 if (!encoding
|| encoding
== fontname
)
5538 for (charset
= encoding
- 1; charset
>= fontname
; charset
--)
5539 if (*charset
== '-')
5542 if (charset
== fontname
|| strcmp(charset
, "-*-*") == 0)
5548 struct font_info
*w32_load_bdf_font (struct frame
*f
, char *fontname
,
5549 int size
, char* filename
);
5550 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
);
5551 static BOOL
w32_to_x_font (LOGFONT
* lplf
, char * lpxstr
, int len
,
5553 static BOOL
x_to_w32_font (char *lpxstr
, LOGFONT
*lplogfont
);
5555 static struct font_info
*
5556 w32_load_system_font (f
,fontname
,size
)
5561 struct w32_display_info
*dpyinfo
= FRAME_W32_DISPLAY_INFO (f
);
5562 Lisp_Object font_names
;
5564 /* Get a list of all the fonts that match this name. Once we
5565 have a list of matching fonts, we compare them against the fonts
5566 we already have loaded by comparing names. */
5567 font_names
= w32_list_fonts (f
, build_string (fontname
), size
, 100);
5569 if (!NILP (font_names
))
5574 /* First check if any are already loaded, as that is cheaper
5575 than loading another one. */
5576 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
5577 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
5578 if (dpyinfo
->font_table
[i
].name
5579 && (!strcmp (dpyinfo
->font_table
[i
].name
,
5580 XSTRING (XCAR (tail
))->data
)
5581 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
5582 XSTRING (XCAR (tail
))->data
)))
5583 return (dpyinfo
->font_table
+ i
);
5585 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
5587 else if (w32_strict_fontnames
)
5589 /* If EnumFontFamiliesEx was available, we got a full list of
5590 fonts back so stop now to avoid the possibility of loading a
5591 random font. If we had to fall back to EnumFontFamilies, the
5592 list is incomplete, so continue whether the font we want was
5594 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
5595 FARPROC enum_font_families_ex
5596 = GetProcAddress (gdi32
, "EnumFontFamiliesExA");
5597 if (enum_font_families_ex
)
5601 /* Load the font and add it to the table. */
5603 char *full_name
, *encoding
, *charset
;
5605 struct font_info
*fontp
;
5611 if (!fontname
|| !x_to_w32_font (fontname
, &lf
))
5614 if (!*lf
.lfFaceName
)
5615 /* If no name was specified for the font, we get a random font
5616 from CreateFontIndirect - this is not particularly
5617 desirable, especially since CreateFontIndirect does not
5618 fill out the missing name in lf, so we never know what we
5622 /* Specify anti-aliasing to prevent Cleartype fonts being used,
5623 since those fonts leave garbage behind. */
5624 lf
.lfQuality
= ANTIALIASED_QUALITY
;
5626 font
= (XFontStruct
*) xmalloc (sizeof (XFontStruct
));
5627 bzero (font
, sizeof (*font
));
5629 /* Set bdf to NULL to indicate that this is a Windows font. */
5634 font
->hfont
= CreateFontIndirect (&lf
);
5636 if (font
->hfont
== NULL
)
5645 codepage
= w32_codepage_for_font (fontname
);
5647 hdc
= GetDC (dpyinfo
->root_window
);
5648 oldobj
= SelectObject (hdc
, font
->hfont
);
5650 ok
= GetTextMetrics (hdc
, &font
->tm
);
5651 if (codepage
== CP_UNICODE
)
5652 font
->double_byte_p
= 1;
5655 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
5656 don't report themselves as double byte fonts, when
5657 patently they are. So instead of trusting
5658 GetFontLanguageInfo, we check the properties of the
5659 codepage directly, since that is ultimately what we are
5660 working from anyway. */
5661 /* font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS; */
5663 GetCPInfo (codepage
, &cpi
);
5664 font
->double_byte_p
= cpi
.MaxCharSize
> 1;
5667 SelectObject (hdc
, oldobj
);
5668 ReleaseDC (dpyinfo
->root_window
, hdc
);
5669 /* Fill out details in lf according to the font that was
5671 lf
.lfHeight
= font
->tm
.tmInternalLeading
- font
->tm
.tmHeight
;
5672 lf
.lfWidth
= font
->tm
.tmAveCharWidth
;
5673 lf
.lfWeight
= font
->tm
.tmWeight
;
5674 lf
.lfItalic
= font
->tm
.tmItalic
;
5675 lf
.lfCharSet
= font
->tm
.tmCharSet
;
5676 lf
.lfPitchAndFamily
= ((font
->tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
5677 ? VARIABLE_PITCH
: FIXED_PITCH
);
5678 lf
.lfOutPrecision
= ((font
->tm
.tmPitchAndFamily
& TMPF_VECTOR
)
5679 ? OUT_STROKE_PRECIS
: OUT_STRING_PRECIS
);
5681 w32_cache_char_metrics (font
);
5688 w32_unload_font (dpyinfo
, font
);
5692 /* Find a free slot in the font table. */
5693 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
5694 if (dpyinfo
->font_table
[i
].name
== NULL
)
5697 /* If no free slot found, maybe enlarge the font table. */
5698 if (i
== dpyinfo
->n_fonts
5699 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
5702 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
5703 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
5705 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
5708 fontp
= dpyinfo
->font_table
+ i
;
5709 if (i
== dpyinfo
->n_fonts
)
5712 /* Now fill in the slots of *FONTP. */
5715 fontp
->font_idx
= i
;
5716 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
5717 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
5719 charset
= xlfd_charset_of_font (fontname
);
5721 /* Cache the W32 codepage for a font. This makes w32_encode_char
5722 (called for every glyph during redisplay) much faster. */
5723 fontp
->codepage
= codepage
;
5725 /* Work out the font's full name. */
5726 full_name
= (char *)xmalloc (100);
5727 if (full_name
&& w32_to_x_font (&lf
, full_name
, 100, charset
))
5728 fontp
->full_name
= full_name
;
5731 /* If all else fails - just use the name we used to load it. */
5733 fontp
->full_name
= fontp
->name
;
5736 fontp
->size
= FONT_WIDTH (font
);
5737 fontp
->height
= FONT_HEIGHT (font
);
5739 /* The slot `encoding' specifies how to map a character
5740 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
5741 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
5742 (0:0x20..0x7F, 1:0xA0..0xFF,
5743 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
5744 2:0xA020..0xFF7F). For the moment, we don't know which charset
5745 uses this font. So, we set information in fontp->encoding[1]
5746 which is never used by any charset. If mapping can't be
5747 decided, set FONT_ENCODING_NOT_DECIDED. */
5749 /* SJIS fonts need to be set to type 4, all others seem to work as
5750 type FONT_ENCODING_NOT_DECIDED. */
5751 encoding
= strrchr (fontp
->name
, '-');
5752 if (encoding
&& strnicmp (encoding
+1, "sjis", 4) == 0)
5753 fontp
->encoding
[1] = 4;
5755 fontp
->encoding
[1] = FONT_ENCODING_NOT_DECIDED
;
5757 /* The following three values are set to 0 under W32, which is
5758 what they get set to if XGetFontProperty fails under X. */
5759 fontp
->baseline_offset
= 0;
5760 fontp
->relative_compose
= 0;
5761 fontp
->default_ascent
= 0;
5763 /* Set global flag fonts_changed_p to non-zero if the font loaded
5764 has a character with a smaller width than any other character
5765 before, or if the font loaded has a smalle>r height than any
5766 other font loaded before. If this happens, it will make a
5767 glyph matrix reallocation necessary. */
5768 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
5774 /* Load font named FONTNAME of size SIZE for frame F, and return a
5775 pointer to the structure font_info while allocating it dynamically.
5776 If loading fails, return NULL. */
5778 w32_load_font (f
,fontname
,size
)
5783 Lisp_Object bdf_fonts
;
5784 struct font_info
*retval
= NULL
;
5786 bdf_fonts
= w32_list_bdf_fonts (build_string (fontname
), 1);
5788 while (!retval
&& CONSP (bdf_fonts
))
5790 char *bdf_name
, *bdf_file
;
5791 Lisp_Object bdf_pair
;
5793 bdf_name
= XSTRING (XCAR (bdf_fonts
))->data
;
5794 bdf_pair
= Fassoc (XCAR (bdf_fonts
), Vw32_bdf_filename_alist
);
5795 bdf_file
= XSTRING (XCDR (bdf_pair
))->data
;
5797 retval
= w32_load_bdf_font (f
, bdf_name
, size
, bdf_file
);
5799 bdf_fonts
= XCDR (bdf_fonts
);
5805 return w32_load_system_font(f
, fontname
, size
);
5810 w32_unload_font (dpyinfo
, font
)
5811 struct w32_display_info
*dpyinfo
;
5816 if (font
->per_char
) xfree (font
->per_char
);
5817 if (font
->bdf
) w32_free_bdf_font (font
->bdf
);
5819 if (font
->hfont
) DeleteObject(font
->hfont
);
5824 /* The font conversion stuff between x and w32 */
5826 /* X font string is as follows (from faces.el)
5830 * (weight "\\(bold\\|demibold\\|medium\\)") ; 1
5831 * (weight\? "\\([^-]*\\)") ; 1
5832 * (slant "\\([ior]\\)") ; 2
5833 * (slant\? "\\([^-]?\\)") ; 2
5834 * (swidth "\\([^-]*\\)") ; 3
5835 * (adstyle "[^-]*") ; 4
5836 * (pixelsize "[0-9]+")
5837 * (pointsize "[0-9][0-9]+")
5838 * (resx "[0-9][0-9]+")
5839 * (resy "[0-9][0-9]+")
5840 * (spacing "[cmp?*]")
5841 * (avgwidth "[0-9]+")
5842 * (registry "[^-]+")
5843 * (encoding "[^-]+")
5848 x_to_w32_weight (lpw
)
5851 if (!lpw
) return (FW_DONTCARE
);
5853 if (stricmp (lpw
,"heavy") == 0) return FW_HEAVY
;
5854 else if (stricmp (lpw
,"extrabold") == 0) return FW_EXTRABOLD
;
5855 else if (stricmp (lpw
,"bold") == 0) return FW_BOLD
;
5856 else if (stricmp (lpw
,"demibold") == 0) return FW_SEMIBOLD
;
5857 else if (stricmp (lpw
,"semibold") == 0) return FW_SEMIBOLD
;
5858 else if (stricmp (lpw
,"medium") == 0) return FW_MEDIUM
;
5859 else if (stricmp (lpw
,"normal") == 0) return FW_NORMAL
;
5860 else if (stricmp (lpw
,"light") == 0) return FW_LIGHT
;
5861 else if (stricmp (lpw
,"extralight") == 0) return FW_EXTRALIGHT
;
5862 else if (stricmp (lpw
,"thin") == 0) return FW_THIN
;
5869 w32_to_x_weight (fnweight
)
5872 if (fnweight
>= FW_HEAVY
) return "heavy";
5873 if (fnweight
>= FW_EXTRABOLD
) return "extrabold";
5874 if (fnweight
>= FW_BOLD
) return "bold";
5875 if (fnweight
>= FW_SEMIBOLD
) return "demibold";
5876 if (fnweight
>= FW_MEDIUM
) return "medium";
5877 if (fnweight
>= FW_NORMAL
) return "normal";
5878 if (fnweight
>= FW_LIGHT
) return "light";
5879 if (fnweight
>= FW_EXTRALIGHT
) return "extralight";
5880 if (fnweight
>= FW_THIN
) return "thin";
5886 x_to_w32_charset (lpcs
)
5889 Lisp_Object this_entry
, w32_charset
;
5891 int len
= strlen (lpcs
);
5893 /* Support "*-#nnn" format for unknown charsets. */
5894 if (strncmp (lpcs
, "*-#", 3) == 0)
5895 return atoi (lpcs
+ 3);
5897 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
5898 charset
= alloca (len
+ 1);
5899 strcpy (charset
, lpcs
);
5900 lpcs
= strchr (charset
, '*');
5904 /* Look through w32-charset-info-alist for the character set.
5905 Format of each entry is
5906 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5908 this_entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
5910 if (NILP(this_entry
))
5912 /* At startup, we want iso8859-1 fonts to come up properly. */
5913 if (stricmp(charset
, "iso8859-1") == 0)
5914 return ANSI_CHARSET
;
5916 return DEFAULT_CHARSET
;
5919 w32_charset
= Fcar (Fcdr (this_entry
));
5921 /* Translate Lisp symbol to number. */
5922 if (w32_charset
== Qw32_charset_ansi
)
5923 return ANSI_CHARSET
;
5924 if (w32_charset
== Qw32_charset_symbol
)
5925 return SYMBOL_CHARSET
;
5926 if (w32_charset
== Qw32_charset_shiftjis
)
5927 return SHIFTJIS_CHARSET
;
5928 if (w32_charset
== Qw32_charset_hangeul
)
5929 return HANGEUL_CHARSET
;
5930 if (w32_charset
== Qw32_charset_chinesebig5
)
5931 return CHINESEBIG5_CHARSET
;
5932 if (w32_charset
== Qw32_charset_gb2312
)
5933 return GB2312_CHARSET
;
5934 if (w32_charset
== Qw32_charset_oem
)
5936 #ifdef JOHAB_CHARSET
5937 if (w32_charset
== Qw32_charset_johab
)
5938 return JOHAB_CHARSET
;
5939 if (w32_charset
== Qw32_charset_easteurope
)
5940 return EASTEUROPE_CHARSET
;
5941 if (w32_charset
== Qw32_charset_turkish
)
5942 return TURKISH_CHARSET
;
5943 if (w32_charset
== Qw32_charset_baltic
)
5944 return BALTIC_CHARSET
;
5945 if (w32_charset
== Qw32_charset_russian
)
5946 return RUSSIAN_CHARSET
;
5947 if (w32_charset
== Qw32_charset_arabic
)
5948 return ARABIC_CHARSET
;
5949 if (w32_charset
== Qw32_charset_greek
)
5950 return GREEK_CHARSET
;
5951 if (w32_charset
== Qw32_charset_hebrew
)
5952 return HEBREW_CHARSET
;
5953 if (w32_charset
== Qw32_charset_vietnamese
)
5954 return VIETNAMESE_CHARSET
;
5955 if (w32_charset
== Qw32_charset_thai
)
5956 return THAI_CHARSET
;
5957 if (w32_charset
== Qw32_charset_mac
)
5959 #endif /* JOHAB_CHARSET */
5960 #ifdef UNICODE_CHARSET
5961 if (w32_charset
== Qw32_charset_unicode
)
5962 return UNICODE_CHARSET
;
5965 return DEFAULT_CHARSET
;
5970 w32_to_x_charset (fncharset
)
5973 static char buf
[32];
5974 Lisp_Object charset_type
;
5979 /* Handle startup case of w32-charset-info-alist not
5980 being set up yet. */
5981 if (NILP(Vw32_charset_info_alist
))
5983 charset_type
= Qw32_charset_ansi
;
5985 case DEFAULT_CHARSET
:
5986 charset_type
= Qw32_charset_default
;
5988 case SYMBOL_CHARSET
:
5989 charset_type
= Qw32_charset_symbol
;
5991 case SHIFTJIS_CHARSET
:
5992 charset_type
= Qw32_charset_shiftjis
;
5994 case HANGEUL_CHARSET
:
5995 charset_type
= Qw32_charset_hangeul
;
5997 case GB2312_CHARSET
:
5998 charset_type
= Qw32_charset_gb2312
;
6000 case CHINESEBIG5_CHARSET
:
6001 charset_type
= Qw32_charset_chinesebig5
;
6004 charset_type
= Qw32_charset_oem
;
6007 /* More recent versions of Windows (95 and NT4.0) define more
6009 #ifdef EASTEUROPE_CHARSET
6010 case EASTEUROPE_CHARSET
:
6011 charset_type
= Qw32_charset_easteurope
;
6013 case TURKISH_CHARSET
:
6014 charset_type
= Qw32_charset_turkish
;
6016 case BALTIC_CHARSET
:
6017 charset_type
= Qw32_charset_baltic
;
6019 case RUSSIAN_CHARSET
:
6020 charset_type
= Qw32_charset_russian
;
6022 case ARABIC_CHARSET
:
6023 charset_type
= Qw32_charset_arabic
;
6026 charset_type
= Qw32_charset_greek
;
6028 case HEBREW_CHARSET
:
6029 charset_type
= Qw32_charset_hebrew
;
6031 case VIETNAMESE_CHARSET
:
6032 charset_type
= Qw32_charset_vietnamese
;
6035 charset_type
= Qw32_charset_thai
;
6038 charset_type
= Qw32_charset_mac
;
6041 charset_type
= Qw32_charset_johab
;
6045 #ifdef UNICODE_CHARSET
6046 case UNICODE_CHARSET
:
6047 charset_type
= Qw32_charset_unicode
;
6051 /* Encode numerical value of unknown charset. */
6052 sprintf (buf
, "*-#%u", fncharset
);
6058 char * best_match
= NULL
;
6060 /* Look through w32-charset-info-alist for the character set.
6061 Prefer ISO codepages, and prefer lower numbers in the ISO
6062 range. Only return charsets for codepages which are installed.
6064 Format of each entry is
6065 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
6067 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
6070 Lisp_Object w32_charset
;
6071 Lisp_Object codepage
;
6073 Lisp_Object this_entry
= XCAR (rest
);
6075 /* Skip invalid entries in alist. */
6076 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
6077 || !CONSP (XCDR (this_entry
))
6078 || !SYMBOLP (XCAR (XCDR (this_entry
))))
6081 x_charset
= XSTRING (XCAR (this_entry
))->data
;
6082 w32_charset
= XCAR (XCDR (this_entry
));
6083 codepage
= XCDR (XCDR (this_entry
));
6085 /* Look for Same charset and a valid codepage (or non-int
6086 which means ignore). */
6087 if (w32_charset
== charset_type
6088 && (!INTEGERP (codepage
) || codepage
== CP_DEFAULT
6089 || IsValidCodePage (XINT (codepage
))))
6091 /* If we don't have a match already, then this is the
6094 best_match
= x_charset
;
6095 /* If this is an ISO codepage, and the best so far isn't,
6096 then this is better. */
6097 else if (strnicmp (best_match
, "iso", 3) != 0
6098 && strnicmp (x_charset
, "iso", 3) == 0)
6099 best_match
= x_charset
;
6100 /* If both are ISO8859 codepages, choose the one with the
6101 lowest number in the encoding field. */
6102 else if (strnicmp (best_match
, "iso8859-", 8) == 0
6103 && strnicmp (x_charset
, "iso8859-", 8) == 0)
6105 int best_enc
= atoi (best_match
+ 8);
6106 int this_enc
= atoi (x_charset
+ 8);
6107 if (this_enc
> 0 && this_enc
< best_enc
)
6108 best_match
= x_charset
;
6113 /* If no match, encode the numeric value. */
6116 sprintf (buf
, "*-#%u", fncharset
);
6120 strncpy(buf
, best_match
, 31);
6127 /* Return all the X charsets that map to a font. */
6129 w32_to_all_x_charsets (fncharset
)
6132 static char buf
[32];
6133 Lisp_Object charset_type
;
6134 Lisp_Object retval
= Qnil
;
6139 /* Handle startup case of w32-charset-info-alist not
6140 being set up yet. */
6141 if (NILP(Vw32_charset_info_alist
))
6143 charset_type
= Qw32_charset_ansi
;
6145 case DEFAULT_CHARSET
:
6146 charset_type
= Qw32_charset_default
;
6148 case SYMBOL_CHARSET
:
6149 charset_type
= Qw32_charset_symbol
;
6151 case SHIFTJIS_CHARSET
:
6152 charset_type
= Qw32_charset_shiftjis
;
6154 case HANGEUL_CHARSET
:
6155 charset_type
= Qw32_charset_hangeul
;
6157 case GB2312_CHARSET
:
6158 charset_type
= Qw32_charset_gb2312
;
6160 case CHINESEBIG5_CHARSET
:
6161 charset_type
= Qw32_charset_chinesebig5
;
6164 charset_type
= Qw32_charset_oem
;
6167 /* More recent versions of Windows (95 and NT4.0) define more
6169 #ifdef EASTEUROPE_CHARSET
6170 case EASTEUROPE_CHARSET
:
6171 charset_type
= Qw32_charset_easteurope
;
6173 case TURKISH_CHARSET
:
6174 charset_type
= Qw32_charset_turkish
;
6176 case BALTIC_CHARSET
:
6177 charset_type
= Qw32_charset_baltic
;
6179 case RUSSIAN_CHARSET
:
6180 charset_type
= Qw32_charset_russian
;
6182 case ARABIC_CHARSET
:
6183 charset_type
= Qw32_charset_arabic
;
6186 charset_type
= Qw32_charset_greek
;
6188 case HEBREW_CHARSET
:
6189 charset_type
= Qw32_charset_hebrew
;
6191 case VIETNAMESE_CHARSET
:
6192 charset_type
= Qw32_charset_vietnamese
;
6195 charset_type
= Qw32_charset_thai
;
6198 charset_type
= Qw32_charset_mac
;
6201 charset_type
= Qw32_charset_johab
;
6205 #ifdef UNICODE_CHARSET
6206 case UNICODE_CHARSET
:
6207 charset_type
= Qw32_charset_unicode
;
6211 /* Encode numerical value of unknown charset. */
6212 sprintf (buf
, "*-#%u", fncharset
);
6213 return Fcons (build_string (buf
), Qnil
);
6218 /* Look through w32-charset-info-alist for the character set.
6219 Only return charsets for codepages which are installed.
6221 Format of each entry in Vw32_charset_info_alist is
6222 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
6224 for (rest
= Vw32_charset_info_alist
; CONSP (rest
); rest
= XCDR (rest
))
6226 Lisp_Object x_charset
;
6227 Lisp_Object w32_charset
;
6228 Lisp_Object codepage
;
6230 Lisp_Object this_entry
= XCAR (rest
);
6232 /* Skip invalid entries in alist. */
6233 if (!CONSP (this_entry
) || !STRINGP (XCAR (this_entry
))
6234 || !CONSP (XCDR (this_entry
))
6235 || !SYMBOLP (XCAR (XCDR (this_entry
))))
6238 x_charset
= XCAR (this_entry
);
6239 w32_charset
= XCAR (XCDR (this_entry
));
6240 codepage
= XCDR (XCDR (this_entry
));
6242 /* Look for Same charset and a valid codepage (or non-int
6243 which means ignore). */
6244 if (w32_charset
== charset_type
6245 && (!INTEGERP (codepage
) || codepage
== CP_DEFAULT
6246 || IsValidCodePage (XINT (codepage
))))
6248 retval
= Fcons (x_charset
, retval
);
6252 /* If no match, encode the numeric value. */
6255 sprintf (buf
, "*-#%u", fncharset
);
6256 return Fcons (build_string (buf
), Qnil
);
6263 /* Get the Windows codepage corresponding to the specified font. The
6264 charset info in the font name is used to look up
6265 w32-charset-to-codepage-alist. */
6267 w32_codepage_for_font (char *fontname
)
6269 Lisp_Object codepage
, entry
;
6270 char *charset_str
, *charset
, *end
;
6272 if (NILP (Vw32_charset_info_alist
))
6275 /* Extract charset part of font string. */
6276 charset
= xlfd_charset_of_font (fontname
);
6281 charset_str
= (char *) alloca (strlen (charset
) + 1);
6282 strcpy (charset_str
, charset
);
6285 /* Remove leading "*-". */
6286 if (strncmp ("*-", charset_str
, 2) == 0)
6287 charset
= charset_str
+ 2;
6290 charset
= charset_str
;
6292 /* Stop match at wildcard (including preceding '-'). */
6293 if (end
= strchr (charset
, '*'))
6295 if (end
> charset
&& *(end
-1) == '-')
6300 entry
= Fassoc (build_string(charset
), Vw32_charset_info_alist
);
6304 codepage
= Fcdr (Fcdr (entry
));
6306 if (NILP (codepage
))
6308 else if (XFASTINT (codepage
) == XFASTINT (Qt
))
6310 else if (INTEGERP (codepage
))
6311 return XINT (codepage
);
6318 w32_to_x_font (lplogfont
, lpxstr
, len
, specific_charset
)
6319 LOGFONT
* lplogfont
;
6322 char * specific_charset
;
6326 char height_pixels
[8];
6328 char width_pixels
[8];
6329 char *fontname_dash
;
6330 int display_resy
= one_w32_display_info
.resy
;
6331 int display_resx
= one_w32_display_info
.resx
;
6333 struct coding_system coding
;
6335 if (!lpxstr
) abort ();
6340 if (lplogfont
->lfOutPrecision
== OUT_STRING_PRECIS
)
6341 fonttype
= "raster";
6342 else if (lplogfont
->lfOutPrecision
== OUT_STROKE_PRECIS
)
6343 fonttype
= "outline";
6345 fonttype
= "unknown";
6347 setup_coding_system (Fcheck_coding_system (Vw32_system_coding_system
),
6349 coding
.src_multibyte
= 0;
6350 coding
.dst_multibyte
= 1;
6351 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6352 bufsz
= decoding_buffer_size (&coding
, LF_FACESIZE
);
6354 fontname
= alloca(sizeof(*fontname
) * bufsz
);
6355 decode_coding (&coding
, lplogfont
->lfFaceName
, fontname
,
6356 strlen(lplogfont
->lfFaceName
), bufsz
- 1);
6357 *(fontname
+ coding
.produced
) = '\0';
6359 /* Replace dashes with underscores so the dashes are not
6361 fontname_dash
= fontname
;
6362 while (fontname_dash
= strchr (fontname_dash
, '-'))
6363 *fontname_dash
= '_';
6365 if (lplogfont
->lfHeight
)
6367 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
6368 sprintf (height_dpi
, "%u",
6369 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
6373 strcpy (height_pixels
, "*");
6374 strcpy (height_dpi
, "*");
6376 if (lplogfont
->lfWidth
)
6377 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
6379 strcpy (width_pixels
, "*");
6381 _snprintf (lpxstr
, len
- 1,
6382 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
6383 fonttype
, /* foundry */
6384 fontname
, /* family */
6385 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
6386 lplogfont
->lfItalic
?'i':'r', /* slant */
6388 /* add style name */
6389 height_pixels
, /* pixel size */
6390 height_dpi
, /* point size */
6391 display_resx
, /* resx */
6392 display_resy
, /* resy */
6393 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
6394 ? 'p' : 'c', /* spacing */
6395 width_pixels
, /* avg width */
6396 specific_charset
? specific_charset
6397 : w32_to_x_charset (lplogfont
->lfCharSet
)
6398 /* charset registry and encoding */
6401 lpxstr
[len
- 1] = 0; /* just to be sure */
6406 x_to_w32_font (lpxstr
, lplogfont
)
6408 LOGFONT
* lplogfont
;
6410 struct coding_system coding
;
6412 if (!lplogfont
) return (FALSE
);
6414 memset (lplogfont
, 0, sizeof (*lplogfont
));
6416 /* Set default value for each field. */
6418 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
6419 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
6420 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
6422 /* go for maximum quality */
6423 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
6424 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
6425 lplogfont
->lfQuality
= PROOF_QUALITY
;
6428 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
6429 lplogfont
->lfWeight
= FW_DONTCARE
;
6430 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
6435 /* Provide a simple escape mechanism for specifying Windows font names
6436 * directly -- if font spec does not beginning with '-', assume this
6438 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
6444 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
6445 width
[10], resy
[10], remainder
[50];
6447 int dpi
= one_w32_display_info
.resy
;
6449 fields
= sscanf (lpxstr
,
6450 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
6451 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
6455 /* In the general case when wildcards cover more than one field,
6456 we don't know which field is which, so don't fill any in.
6457 However, we need to cope with this particular form, which is
6458 generated by font_list_1 (invoked by try_font_list):
6459 "-raster-6x10-*-gb2312*-*"
6460 and make sure to correctly parse the charset field. */
6463 fields
= sscanf (lpxstr
,
6464 "-%*[^-]-%49[^-]-*-%49s",
6467 else if (fields
< 9)
6473 if (fields
> 0 && name
[0] != '*')
6479 (Fcheck_coding_system (Vw32_system_coding_system
), &coding
);
6480 coding
.src_multibyte
= 1;
6481 coding
.dst_multibyte
= 1;
6482 bufsize
= encoding_buffer_size (&coding
, strlen (name
));
6483 buf
= (unsigned char *) alloca (bufsize
);
6484 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6485 encode_coding (&coding
, name
, buf
, strlen (name
), bufsize
);
6486 if (coding
.produced
>= LF_FACESIZE
)
6487 coding
.produced
= LF_FACESIZE
- 1;
6488 buf
[coding
.produced
] = 0;
6489 strcpy (lplogfont
->lfFaceName
, buf
);
6493 lplogfont
->lfFaceName
[0] = '\0';
6498 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6502 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
6506 if (fields
> 0 && pixels
[0] != '*')
6507 lplogfont
->lfHeight
= atoi (pixels
);
6511 if (fields
> 0 && resy
[0] != '*')
6514 if (tem
> 0) dpi
= tem
;
6517 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
6518 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
6521 lplogfont
->lfPitchAndFamily
=
6522 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
6526 if (fields
> 0 && width
[0] != '*')
6527 lplogfont
->lfWidth
= atoi (width
) / 10;
6531 /* Strip the trailing '-' if present. (it shouldn't be, as it
6532 fails the test against xlfd-tight-regexp in fontset.el). */
6534 int len
= strlen (remainder
);
6535 if (len
> 0 && remainder
[len
-1] == '-')
6536 remainder
[len
-1] = 0;
6538 encoding
= remainder
;
6540 if (strncmp (encoding
, "*-", 2) == 0)
6543 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
6548 char name
[100], height
[10], width
[10], weight
[20];
6550 fields
= sscanf (lpxstr
,
6551 "%99[^:]:%9[^:]:%9[^:]:%19s",
6552 name
, height
, width
, weight
);
6554 if (fields
== EOF
) return (FALSE
);
6558 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
6559 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
6563 lplogfont
->lfFaceName
[0] = 0;
6569 lplogfont
->lfHeight
= atoi (height
);
6574 lplogfont
->lfWidth
= atoi (width
);
6578 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6581 /* This makes TrueType fonts work better. */
6582 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
6587 /* Strip the pixel height and point height from the given xlfd, and
6588 return the pixel height. If no pixel height is specified, calculate
6589 one from the point height, or if that isn't defined either, return
6590 0 (which usually signifies a scalable font).
6593 xlfd_strip_height (char *fontname
)
6595 int pixel_height
, field_number
;
6596 char *read_from
, *write_to
;
6600 pixel_height
= field_number
= 0;
6603 /* Look for height fields. */
6604 for (read_from
= fontname
; *read_from
; read_from
++)
6606 if (*read_from
== '-')
6609 if (field_number
== 7) /* Pixel height. */
6612 write_to
= read_from
;
6614 /* Find end of field. */
6615 for (;*read_from
&& *read_from
!= '-'; read_from
++)
6618 /* Split the fontname at end of field. */
6624 pixel_height
= atoi (write_to
);
6625 /* Blank out field. */
6626 if (read_from
> write_to
)
6631 /* If the pixel height field is at the end (partial xlfd),
6634 return pixel_height
;
6636 /* If we got a pixel height, the point height can be
6637 ignored. Just blank it out and break now. */
6640 /* Find end of point size field. */
6641 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6647 /* Blank out the point size field. */
6648 if (read_from
> write_to
)
6654 return pixel_height
;
6658 /* If the point height is already blank, break now. */
6659 if (*read_from
== '-')
6665 else if (field_number
== 8)
6667 /* If we didn't get a pixel height, try to get the point
6668 height and convert that. */
6670 char *point_size_start
= read_from
++;
6672 /* Find end of field. */
6673 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6682 point_size
= atoi (point_size_start
);
6684 /* Convert to pixel height. */
6685 pixel_height
= point_size
6686 * one_w32_display_info
.height_in
/ 720;
6688 /* Blank out this field and break. */
6696 /* Shift the rest of the font spec into place. */
6697 if (write_to
&& read_from
> write_to
)
6699 for (; *read_from
; read_from
++, write_to
++)
6700 *write_to
= *read_from
;
6704 return pixel_height
;
6707 /* Assume parameter 1 is fully qualified, no wildcards. */
6709 w32_font_match (fontname
, pattern
)
6713 char *regex
= alloca (strlen (pattern
) * 2 + 3);
6714 char *font_name_copy
= alloca (strlen (fontname
) + 1);
6717 /* Copy fontname so we can modify it during comparison. */
6718 strcpy (font_name_copy
, fontname
);
6723 /* Turn pattern into a regexp and do a regexp match. */
6724 for (; *pattern
; pattern
++)
6726 if (*pattern
== '?')
6728 else if (*pattern
== '*')
6739 /* Strip out font heights and compare them seperately, since
6740 rounding error can cause mismatches. This also allows a
6741 comparison between a font that declares only a pixel height and a
6742 pattern that declares the point height.
6745 int font_height
, pattern_height
;
6747 font_height
= xlfd_strip_height (font_name_copy
);
6748 pattern_height
= xlfd_strip_height (regex
);
6750 /* Compare now, and don't bother doing expensive regexp matching
6751 if the heights differ. */
6752 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
6756 return (fast_c_string_match_ignore_case (build_string (regex
),
6757 font_name_copy
) >= 0);
6760 /* Callback functions, and a structure holding info they need, for
6761 listing system fonts on W32. We need one set of functions to do the
6762 job properly, but these don't work on NT 3.51 and earlier, so we
6763 have a second set which don't handle character sets properly to
6766 In both cases, there are two passes made. The first pass gets one
6767 font from each family, the second pass lists all the fonts from
6770 typedef struct enumfont_t
6775 XFontStruct
*size_ref
;
6776 Lisp_Object
*pattern
;
6782 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
6785 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
6787 NEWTEXTMETRIC
* lptm
;
6791 /* Ignore underlined and struck out versions of fonts. */
6792 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
6795 /* Only return fonts with names starting with @ if they were
6796 explicitly specified, since Microsoft uses an initial @ to
6797 denote fonts for vertical writing, without providing a more
6798 convenient way of identifying them. */
6799 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
6800 && lpef
->logfont
.lfFaceName
[0] != '@')
6803 /* Check that the character set matches if it was specified */
6804 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
6805 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
6810 Lisp_Object width
= Qnil
;
6811 Lisp_Object charset_list
= Qnil
;
6812 char *charset
= NULL
;
6814 /* Truetype fonts do not report their true metrics until loaded */
6815 if (FontType
!= RASTER_FONTTYPE
)
6817 if (!NILP (*(lpef
->pattern
)))
6819 /* Scalable fonts are as big as you want them to be. */
6820 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
6821 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
6822 width
= make_number (lpef
->logfont
.lfWidth
);
6826 lplf
->elfLogFont
.lfHeight
= 0;
6827 lplf
->elfLogFont
.lfWidth
= 0;
6831 /* Make sure the height used here is the same as everywhere
6832 else (ie character height, not cell height). */
6833 if (lplf
->elfLogFont
.lfHeight
> 0)
6835 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
6836 if (FontType
== RASTER_FONTTYPE
)
6837 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
6839 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
6842 if (!NILP (*(lpef
->pattern
)))
6844 charset
= xlfd_charset_of_font (XSTRING(*(lpef
->pattern
))->data
);
6846 /* We already checked charsets above, but DEFAULT_CHARSET
6847 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
6849 && strncmp (charset
, "*-*", 3) != 0
6850 && lpef
->logfont
.lfCharSet
== DEFAULT_CHARSET
6851 && strcmp (charset
, w32_to_x_charset (DEFAULT_CHARSET
)) != 0)
6856 charset_list
= Fcons (build_string (charset
), Qnil
);
6858 charset_list
= w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
);
6860 /* Loop through the charsets. */
6861 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
6863 Lisp_Object this_charset
= Fcar (charset_list
);
6864 charset
= XSTRING (this_charset
)->data
;
6866 /* List bold and italic variations if w32-enable-synthesized-fonts
6867 is non-nil and this is a plain font. */
6868 if (w32_enable_synthesized_fonts
6869 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
6870 && lplf
->elfLogFont
.lfItalic
== FALSE
)
6872 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6875 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
6876 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6879 lplf
->elfLogFont
.lfItalic
= TRUE
;
6880 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6883 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
6884 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6888 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6897 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
6900 char * match_charset
;
6905 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
6908 if (NILP (*(lpef
->pattern
))
6909 || w32_font_match (buf
, XSTRING (*(lpef
->pattern
))->data
))
6911 /* Check if we already listed this font. This may happen if
6912 w32_enable_synthesized_fonts is non-nil, and there are real
6913 bold and italic versions of the font. */
6914 Lisp_Object font_name
= build_string (buf
);
6915 if (NILP (Fmember (font_name
, lpef
->list
)))
6917 *lpef
->tail
= Fcons (Fcons (build_string (buf
), width
), Qnil
);
6918 lpef
->tail
= &(XCDR (*lpef
->tail
));
6926 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
6928 NEWTEXTMETRIC
* lptm
;
6931 { return EnumFontFamilies (lpef
->hdc
,
6932 lplf
->elfLogFont
.lfFaceName
,
6933 (FONTENUMPROC
) enum_font_cb2
,
6939 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
6940 ENUMLOGFONTEX
* lplf
;
6941 NEWTEXTMETRICEX
* lptm
;
6945 /* We are not interested in the extra info we get back from the 'Ex
6946 version - only the fact that we get character set variations
6947 enumerated seperately. */
6948 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
6953 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
6954 ENUMLOGFONTEX
* lplf
;
6955 NEWTEXTMETRICEX
* lptm
;
6959 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6960 FARPROC enum_font_families_ex
6961 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6962 /* We don't really expect EnumFontFamiliesEx to disappear once we
6963 get here, so don't bother handling it gracefully. */
6964 if (enum_font_families_ex
== NULL
)
6965 error ("gdi32.dll has disappeared!");
6966 return enum_font_families_ex (lpef
->hdc
,
6968 (FONTENUMPROC
) enum_fontex_cb2
,
6972 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
6973 and xterm.c in Emacs 20.3) */
6975 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
6977 char *fontname
, *ptnstr
;
6978 Lisp_Object list
, tem
, newlist
= Qnil
;
6981 list
= Vw32_bdf_filename_alist
;
6982 ptnstr
= XSTRING (pattern
)->data
;
6984 for ( ; CONSP (list
); list
= XCDR (list
))
6988 fontname
= XSTRING (XCAR (tem
))->data
;
6989 else if (STRINGP (tem
))
6990 fontname
= XSTRING (tem
)->data
;
6994 if (w32_font_match (fontname
, ptnstr
))
6996 newlist
= Fcons (XCAR (tem
), newlist
);
6998 if (n_fonts
>= max_names
)
7006 /* Return a list of names of available fonts matching PATTERN on frame
7007 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
7008 to be listed. Frame F NULL means we have not yet created any
7009 frame, which means we can't get proper size info, as we don't have
7010 a device context to use for GetTextMetrics.
7011 MAXNAMES sets a limit on how many fonts to match. */
7014 w32_list_fonts (f
, pattern
, size
, maxnames
)
7016 Lisp_Object pattern
;
7020 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
7021 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
7022 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
7025 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
7026 if (NILP (patterns
))
7027 patterns
= Fcons (pattern
, Qnil
);
7029 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
7034 tpat
= XCAR (patterns
);
7036 if (!STRINGP (tpat
))
7039 /* Avoid expensive EnumFontFamilies functions if we are not
7040 going to be able to output one of these anyway. */
7041 codepage
= w32_codepage_for_font (XSTRING (tpat
)->data
);
7042 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
7043 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
7044 && !IsValidCodePage(codepage
))
7047 /* See if we cached the result for this particular query.
7048 The cache is an alist of the form:
7049 ((PATTERN (FONTNAME . WIDTH) ...) ...)
7051 if (tem
= XCDR (dpyinfo
->name_list_element
),
7052 !NILP (list
= Fassoc (tpat
, tem
)))
7054 list
= Fcdr_safe (list
);
7055 /* We have a cached list. Don't have to get the list again. */
7060 /* At first, put PATTERN in the cache. */
7067 /* Use EnumFontFamiliesEx where it is available, as it knows
7068 about character sets. Fall back to EnumFontFamilies for
7069 older versions of NT that don't support the 'Ex function. */
7070 x_to_w32_font (XSTRING (tpat
)->data
, &ef
.logfont
);
7072 LOGFONT font_match_pattern
;
7073 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
7074 FARPROC enum_font_families_ex
7075 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
7077 /* We do our own pattern matching so we can handle wildcards. */
7078 font_match_pattern
.lfFaceName
[0] = 0;
7079 font_match_pattern
.lfPitchAndFamily
= 0;
7080 /* We can use the charset, because if it has a wildcard it will
7081 translate to DEFAULT_CHARSET anyway. */
7082 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
7084 ef
.hdc
= GetDC (dpyinfo
->root_window
);
7086 if (enum_font_families_ex
)
7087 enum_font_families_ex (ef
.hdc
,
7088 &font_match_pattern
,
7089 (FONTENUMPROC
) enum_fontex_cb1
,
7092 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
7095 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
7100 /* Make a list of the fonts we got back.
7101 Store that in the font cache for the display. */
7102 XCDR (dpyinfo
->name_list_element
)
7103 = Fcons (Fcons (tpat
, list
),
7104 XCDR (dpyinfo
->name_list_element
));
7107 if (NILP (list
)) continue; /* Try the remaining alternatives. */
7109 newlist
= second_best
= Qnil
;
7111 /* Make a list of the fonts that have the right width. */
7112 for (; CONSP (list
); list
= XCDR (list
))
7119 if (NILP (XCAR (tem
)))
7123 newlist
= Fcons (XCAR (tem
), newlist
);
7125 if (n_fonts
>= maxnames
)
7130 if (!INTEGERP (XCDR (tem
)))
7132 /* Since we don't yet know the size of the font, we must
7133 load it and try GetTextMetrics. */
7134 W32FontStruct thisinfo
;
7139 if (!x_to_w32_font (XSTRING (XCAR (tem
))->data
, &lf
))
7143 thisinfo
.bdf
= NULL
;
7144 thisinfo
.hfont
= CreateFontIndirect (&lf
);
7145 if (thisinfo
.hfont
== NULL
)
7148 hdc
= GetDC (dpyinfo
->root_window
);
7149 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
7150 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
7151 XCDR (tem
) = make_number (FONT_WIDTH (&thisinfo
));
7153 XCDR (tem
) = make_number (0);
7154 SelectObject (hdc
, oldobj
);
7155 ReleaseDC (dpyinfo
->root_window
, hdc
);
7156 DeleteObject(thisinfo
.hfont
);
7159 found_size
= XINT (XCDR (tem
));
7160 if (found_size
== size
)
7162 newlist
= Fcons (XCAR (tem
), newlist
);
7164 if (n_fonts
>= maxnames
)
7167 /* keep track of the closest matching size in case
7168 no exact match is found. */
7169 else if (found_size
> 0)
7171 if (NILP (second_best
))
7174 else if (found_size
< size
)
7176 if (XINT (XCDR (second_best
)) > size
7177 || XINT (XCDR (second_best
)) < found_size
)
7182 if (XINT (XCDR (second_best
)) > size
7183 && XINT (XCDR (second_best
)) >
7190 if (!NILP (newlist
))
7192 else if (!NILP (second_best
))
7194 newlist
= Fcons (XCAR (second_best
), Qnil
);
7199 /* Include any bdf fonts. */
7200 if (n_fonts
< maxnames
)
7202 Lisp_Object combined
[2];
7203 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
7204 combined
[1] = newlist
;
7205 newlist
= Fnconc(2, combined
);
7212 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
7214 w32_get_font_info (f
, font_idx
)
7218 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
7223 w32_query_font (struct frame
*f
, char *fontname
)
7226 struct font_info
*pfi
;
7228 pfi
= FRAME_W32_FONT_TABLE (f
);
7230 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
7232 if (strcmp(pfi
->name
, fontname
) == 0) return pfi
;
7238 /* Find a CCL program for a font specified by FONTP, and set the member
7239 `encoder' of the structure. */
7242 w32_find_ccl_program (fontp
)
7243 struct font_info
*fontp
;
7245 Lisp_Object list
, elt
;
7247 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
7251 && STRINGP (XCAR (elt
))
7252 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
7258 struct ccl_program
*ccl
7259 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
7261 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
7264 fontp
->font_encoder
= ccl
;
7269 /* Find BDF files in a specified directory. (use GCPRO when calling,
7270 as this calls lisp to get a directory listing). */
7272 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
7274 Lisp_Object filelist
, list
= Qnil
;
7277 if (!STRINGP(directory
))
7280 filelist
= Fdirectory_files (directory
, Qt
,
7281 build_string (".*\\.[bB][dD][fF]"), Qt
);
7283 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
7285 Lisp_Object filename
= XCAR (filelist
);
7286 if (w32_BDF_to_x_font (XSTRING (filename
)->data
, fontname
, 100))
7287 store_in_alist (&list
, build_string (fontname
), filename
);
7292 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
7294 "Return a list of BDF fonts in DIR, suitable for appending to\n\
7295 w32-bdf-filename-alist. Fonts which do not contain an xlfd description\n\
7296 will not be included in the list. DIR may be a list of directories.")
7298 Lisp_Object directory
;
7300 Lisp_Object list
= Qnil
;
7301 struct gcpro gcpro1
, gcpro2
;
7303 if (!CONSP (directory
))
7304 return w32_find_bdf_fonts_in_dir (directory
);
7306 for ( ; CONSP (directory
); directory
= XCDR (directory
))
7308 Lisp_Object pair
[2];
7311 GCPRO2 (directory
, list
);
7312 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
7313 list
= Fnconc( 2, pair
);
7320 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
7321 "Internal function called by `color-defined-p', which see.")
7323 Lisp_Object color
, frame
;
7326 FRAME_PTR f
= check_x_frame (frame
);
7328 CHECK_STRING (color
, 1);
7330 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7336 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
7337 "Internal function called by `color-values', which see.")
7339 Lisp_Object color
, frame
;
7342 FRAME_PTR f
= check_x_frame (frame
);
7344 CHECK_STRING (color
, 1);
7346 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7350 rgb
[0] = make_number ((GetRValue (foo
.pixel
) << 8)
7351 | GetRValue (foo
.pixel
));
7352 rgb
[1] = make_number ((GetGValue (foo
.pixel
) << 8)
7353 | GetGValue (foo
.pixel
));
7354 rgb
[2] = make_number ((GetBValue (foo
.pixel
) << 8)
7355 | GetBValue (foo
.pixel
));
7356 return Flist (3, rgb
);
7362 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
7363 "Internal function called by `display-color-p', which see.")
7365 Lisp_Object display
;
7367 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7369 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
7375 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
7377 "Return t if the X display supports shades of gray.\n\
7378 Note that color displays do support shades of gray.\n\
7379 The optional argument DISPLAY specifies which display to ask about.\n\
7380 DISPLAY should be either a frame or a display name (a string).\n\
7381 If omitted or nil, that stands for the selected frame's display.")
7383 Lisp_Object display
;
7385 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7387 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
7393 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
7395 "Returns the width in pixels of the X display DISPLAY.\n\
7396 The optional argument DISPLAY specifies which display to ask about.\n\
7397 DISPLAY should be either a frame or a display name (a string).\n\
7398 If omitted or nil, that stands for the selected frame's display.")
7400 Lisp_Object display
;
7402 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7404 return make_number (dpyinfo
->width
);
7407 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
7408 Sx_display_pixel_height
, 0, 1, 0,
7409 "Returns the height in pixels of the X display DISPLAY.\n\
7410 The optional argument DISPLAY specifies which display to ask about.\n\
7411 DISPLAY should be either a frame or a display name (a string).\n\
7412 If omitted or nil, that stands for the selected frame's display.")
7414 Lisp_Object display
;
7416 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7418 return make_number (dpyinfo
->height
);
7421 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
7423 "Returns the number of bitplanes of the display DISPLAY.\n\
7424 The optional argument DISPLAY specifies which display to ask about.\n\
7425 DISPLAY should be either a frame or a display name (a string).\n\
7426 If omitted or nil, that stands for the selected frame's display.")
7428 Lisp_Object display
;
7430 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7432 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
7435 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
7437 "Returns the number of color cells of the display DISPLAY.\n\
7438 The optional argument DISPLAY specifies which display to ask about.\n\
7439 DISPLAY should be either a frame or a display name (a string).\n\
7440 If omitted or nil, that stands for the selected frame's display.")
7442 Lisp_Object display
;
7444 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7448 hdc
= GetDC (dpyinfo
->root_window
);
7449 if (dpyinfo
->has_palette
)
7450 cap
= GetDeviceCaps (hdc
,SIZEPALETTE
);
7452 cap
= GetDeviceCaps (hdc
,NUMCOLORS
);
7454 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
7455 and because probably is more meaningful on Windows anyway */
7457 cap
= 1 << min(dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
7459 ReleaseDC (dpyinfo
->root_window
, hdc
);
7461 return make_number (cap
);
7464 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
7465 Sx_server_max_request_size
,
7467 "Returns the maximum request size of the server of display DISPLAY.\n\
7468 The optional argument DISPLAY specifies which display to ask about.\n\
7469 DISPLAY should be either a frame or a display name (a string).\n\
7470 If omitted or nil, that stands for the selected frame's display.")
7472 Lisp_Object display
;
7474 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7476 return make_number (1);
7479 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
7480 "Returns the vendor ID string of the W32 system (Microsoft).\n\
7481 The optional argument DISPLAY specifies which display to ask about.\n\
7482 DISPLAY should be either a frame or a display name (a string).\n\
7483 If omitted or nil, that stands for the selected frame's display.")
7485 Lisp_Object display
;
7487 return build_string ("Microsoft Corp.");
7490 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
7491 "Returns the version numbers of the server of display DISPLAY.\n\
7492 The value is a list of three integers: the major and minor\n\
7493 version numbers, and the vendor-specific release\n\
7494 number. See also the function `x-server-vendor'.\n\n\
7495 The optional argument DISPLAY specifies which display to ask about.\n\
7496 DISPLAY should be either a frame or a display name (a string).\n\
7497 If omitted or nil, that stands for the selected frame's display.")
7499 Lisp_Object display
;
7501 return Fcons (make_number (w32_major_version
),
7502 Fcons (make_number (w32_minor_version
),
7503 Fcons (make_number (w32_build_number
), Qnil
)));
7506 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
7507 "Returns the number of screens on the server of display DISPLAY.\n\
7508 The optional argument DISPLAY specifies which display to ask about.\n\
7509 DISPLAY should be either a frame or a display name (a string).\n\
7510 If omitted or nil, that stands for the selected frame's display.")
7512 Lisp_Object display
;
7514 return make_number (1);
7517 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
7518 "Returns the height in millimeters of the X display DISPLAY.\n\
7519 The optional argument DISPLAY specifies which display to ask about.\n\
7520 DISPLAY should be either a frame or a display name (a string).\n\
7521 If omitted or nil, that stands for the selected frame's display.")
7523 Lisp_Object display
;
7525 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7529 hdc
= GetDC (dpyinfo
->root_window
);
7531 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
7533 ReleaseDC (dpyinfo
->root_window
, hdc
);
7535 return make_number (cap
);
7538 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
7539 "Returns the width in millimeters of the X display DISPLAY.\n\
7540 The optional argument DISPLAY specifies which display to ask about.\n\
7541 DISPLAY should be either a frame or a display name (a string).\n\
7542 If omitted or nil, that stands for the selected frame's display.")
7544 Lisp_Object display
;
7546 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7551 hdc
= GetDC (dpyinfo
->root_window
);
7553 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
7555 ReleaseDC (dpyinfo
->root_window
, hdc
);
7557 return make_number (cap
);
7560 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
7561 Sx_display_backing_store
, 0, 1, 0,
7562 "Returns an indication of whether display DISPLAY does backing store.\n\
7563 The value may be `always', `when-mapped', or `not-useful'.\n\
7564 The optional argument DISPLAY specifies which display to ask about.\n\
7565 DISPLAY should be either a frame or a display name (a string).\n\
7566 If omitted or nil, that stands for the selected frame's display.")
7568 Lisp_Object display
;
7570 return intern ("not-useful");
7573 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
7574 Sx_display_visual_class
, 0, 1, 0,
7575 "Returns the visual class of the display DISPLAY.\n\
7576 The value is one of the symbols `static-gray', `gray-scale',\n\
7577 `static-color', `pseudo-color', `true-color', or `direct-color'.\n\n\
7578 The optional argument DISPLAY specifies which display to ask about.\n\
7579 DISPLAY should be either a frame or a display name (a string).\n\
7580 If omitted or nil, that stands for the selected frame's display.")
7582 Lisp_Object display
;
7584 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7585 Lisp_Object result
= Qnil
;
7587 if (dpyinfo
->has_palette
)
7588 result
= intern ("pseudo-color");
7589 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
7590 result
= intern ("static-grey");
7591 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
7592 result
= intern ("static-color");
7593 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
7594 result
= intern ("true-color");
7599 DEFUN ("x-display-save-under", Fx_display_save_under
,
7600 Sx_display_save_under
, 0, 1, 0,
7601 "Returns t if the display DISPLAY supports the save-under feature.\n\
7602 The optional argument DISPLAY specifies which display to ask about.\n\
7603 DISPLAY should be either a frame or a display name (a string).\n\
7604 If omitted or nil, that stands for the selected frame's display.")
7606 Lisp_Object display
;
7613 register struct frame
*f
;
7615 return PIXEL_WIDTH (f
);
7620 register struct frame
*f
;
7622 return PIXEL_HEIGHT (f
);
7627 register struct frame
*f
;
7629 return FONT_WIDTH (f
->output_data
.w32
->font
);
7634 register struct frame
*f
;
7636 return f
->output_data
.w32
->line_height
;
7641 register struct frame
*f
;
7643 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
7646 /* Return the display structure for the display named NAME.
7647 Open a new connection if necessary. */
7649 struct w32_display_info
*
7650 x_display_info_for_name (name
)
7654 struct w32_display_info
*dpyinfo
;
7656 CHECK_STRING (name
, 0);
7658 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
7660 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
7663 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
7668 /* Use this general default value to start with. */
7669 Vx_resource_name
= Vinvocation_name
;
7671 validate_x_resource_name ();
7673 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
7674 (char *) XSTRING (Vx_resource_name
)->data
);
7677 error ("Cannot connect to server %s", XSTRING (name
)->data
);
7680 XSETFASTINT (Vwindow_system_version
, 3);
7685 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
7686 1, 3, 0, "Open a connection to a server.\n\
7687 DISPLAY is the name of the display to connect to.\n\
7688 Optional second arg XRM-STRING is a string of resources in xrdb format.\n\
7689 If the optional third arg MUST-SUCCEED is non-nil,\n\
7690 terminate Emacs if we can't open the connection.")
7691 (display
, xrm_string
, must_succeed
)
7692 Lisp_Object display
, xrm_string
, must_succeed
;
7694 unsigned char *xrm_option
;
7695 struct w32_display_info
*dpyinfo
;
7697 /* If initialization has already been done, return now to avoid
7698 overwriting critical parts of one_w32_display_info. */
7702 CHECK_STRING (display
, 0);
7703 if (! NILP (xrm_string
))
7704 CHECK_STRING (xrm_string
, 1);
7706 if (! EQ (Vwindow_system
, intern ("w32")))
7707 error ("Not using Microsoft Windows");
7709 /* Allow color mapping to be defined externally; first look in user's
7710 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
7712 Lisp_Object color_file
;
7713 struct gcpro gcpro1
;
7715 color_file
= build_string("~/rgb.txt");
7717 GCPRO1 (color_file
);
7719 if (NILP (Ffile_readable_p (color_file
)))
7721 Fexpand_file_name (build_string ("rgb.txt"),
7722 Fsymbol_value (intern ("data-directory")));
7724 Vw32_color_map
= Fw32_load_color_file (color_file
);
7728 if (NILP (Vw32_color_map
))
7729 Vw32_color_map
= Fw32_default_color_map ();
7731 if (! NILP (xrm_string
))
7732 xrm_option
= (unsigned char *) XSTRING (xrm_string
)->data
;
7734 xrm_option
= (unsigned char *) 0;
7736 /* Use this general default value to start with. */
7737 /* First remove .exe suffix from invocation-name - it looks ugly. */
7739 char basename
[ MAX_PATH
], *str
;
7741 strcpy (basename
, XSTRING (Vinvocation_name
)->data
);
7742 str
= strrchr (basename
, '.');
7744 Vinvocation_name
= build_string (basename
);
7746 Vx_resource_name
= Vinvocation_name
;
7748 validate_x_resource_name ();
7750 /* This is what opens the connection and sets x_current_display.
7751 This also initializes many symbols, such as those used for input. */
7752 dpyinfo
= w32_term_init (display
, xrm_option
,
7753 (char *) XSTRING (Vx_resource_name
)->data
);
7757 if (!NILP (must_succeed
))
7758 fatal ("Cannot connect to server %s.\n",
7759 XSTRING (display
)->data
);
7761 error ("Cannot connect to server %s", XSTRING (display
)->data
);
7766 XSETFASTINT (Vwindow_system_version
, 3);
7770 DEFUN ("x-close-connection", Fx_close_connection
,
7771 Sx_close_connection
, 1, 1, 0,
7772 "Close the connection to DISPLAY's server.\n\
7773 For DISPLAY, specify either a frame or a display name (a string).\n\
7774 If DISPLAY is nil, that stands for the selected frame's display.")
7776 Lisp_Object display
;
7778 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7781 if (dpyinfo
->reference_count
> 0)
7782 error ("Display still has frames on it");
7785 /* Free the fonts in the font table. */
7786 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7787 if (dpyinfo
->font_table
[i
].name
)
7789 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
7790 xfree (dpyinfo
->font_table
[i
].full_name
);
7791 xfree (dpyinfo
->font_table
[i
].name
);
7792 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
7794 x_destroy_all_bitmaps (dpyinfo
);
7796 x_delete_display (dpyinfo
);
7802 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
7803 "Return the list of display names that Emacs has connections to.")
7806 Lisp_Object tail
, result
;
7809 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
7810 result
= Fcons (XCAR (XCAR (tail
)), result
);
7815 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
7816 "If ON is non-nil, report errors as soon as the erring request is made.\n\
7817 If ON is nil, allow buffering of requests.\n\
7818 This is a noop on W32 systems.\n\
7819 The optional second argument DISPLAY specifies which display to act on.\n\
7820 DISPLAY should be either a frame or a display name (a string).\n\
7821 If DISPLAY is omitted or nil, that stands for the selected frame's display.")
7823 Lisp_Object display
, on
;
7830 /***********************************************************************
7832 ***********************************************************************/
7834 /* Value is the number of elements of vector VECTOR. */
7836 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
7838 /* List of supported image types. Use define_image_type to add new
7839 types. Use lookup_image_type to find a type for a given symbol. */
7841 static struct image_type
*image_types
;
7843 /* The symbol `image' which is the car of the lists used to represent
7846 extern Lisp_Object Qimage
;
7848 /* The symbol `xbm' which is used as the type symbol for XBM images. */
7854 extern Lisp_Object QCwidth
, QCheight
, QCforeground
, QCbackground
, QCfile
;
7855 extern Lisp_Object QCdata
;
7856 Lisp_Object QCtype
, QCascent
, QCmargin
, QCrelief
;
7857 Lisp_Object QCconversion
, QCcolor_symbols
, QCheuristic_mask
;
7858 Lisp_Object QCindex
;
7860 /* Other symbols. */
7862 Lisp_Object Qlaplace
;
7864 /* Time in seconds after which images should be removed from the cache
7865 if not displayed. */
7867 Lisp_Object Vimage_cache_eviction_delay
;
7869 /* Function prototypes. */
7871 static void define_image_type
P_ ((struct image_type
*type
));
7872 static struct image_type
*lookup_image_type
P_ ((Lisp_Object symbol
));
7873 static void image_error
P_ ((char *format
, Lisp_Object
, Lisp_Object
));
7874 static void x_laplace
P_ ((struct frame
*, struct image
*));
7875 static int x_build_heuristic_mask
P_ ((struct frame
*, struct image
*,
7879 /* Define a new image type from TYPE. This adds a copy of TYPE to
7880 image_types and adds the symbol *TYPE->type to Vimage_types. */
7883 define_image_type (type
)
7884 struct image_type
*type
;
7886 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
7887 The initialized data segment is read-only. */
7888 struct image_type
*p
= (struct image_type
*) xmalloc (sizeof *p
);
7889 bcopy (type
, p
, sizeof *p
);
7890 p
->next
= image_types
;
7892 Vimage_types
= Fcons (*p
->type
, Vimage_types
);
7896 /* Look up image type SYMBOL, and return a pointer to its image_type
7897 structure. Value is null if SYMBOL is not a known image type. */
7899 static INLINE
struct image_type
*
7900 lookup_image_type (symbol
)
7903 struct image_type
*type
;
7905 for (type
= image_types
; type
; type
= type
->next
)
7906 if (EQ (symbol
, *type
->type
))
7913 /* Value is non-zero if OBJECT is a valid Lisp image specification. A
7914 valid image specification is a list whose car is the symbol
7915 `image', and whose rest is a property list. The property list must
7916 contain a value for key `:type'. That value must be the name of a
7917 supported image type. The rest of the property list depends on the
7921 valid_image_p (object
)
7926 if (CONSP (object
) && EQ (XCAR (object
), Qimage
))
7928 Lisp_Object symbol
= Fplist_get (XCDR (object
), QCtype
);
7929 struct image_type
*type
= lookup_image_type (symbol
);
7932 valid_p
= type
->valid_p (object
);
7939 /* Log error message with format string FORMAT and argument ARG.
7940 Signaling an error, e.g. when an image cannot be loaded, is not a
7941 good idea because this would interrupt redisplay, and the error
7942 message display would lead to another redisplay. This function
7943 therefore simply displays a message. */
7946 image_error (format
, arg1
, arg2
)
7948 Lisp_Object arg1
, arg2
;
7950 add_to_log (format
, arg1
, arg2
);
7955 /***********************************************************************
7956 Image specifications
7957 ***********************************************************************/
7959 enum image_value_type
7961 IMAGE_DONT_CHECK_VALUE_TYPE
,
7964 IMAGE_POSITIVE_INTEGER_VALUE
,
7965 IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
,
7966 IMAGE_NON_NEGATIVE_INTEGER_VALUE
,
7968 IMAGE_INTEGER_VALUE
,
7969 IMAGE_FUNCTION_VALUE
,
7974 /* Structure used when parsing image specifications. */
7976 struct image_keyword
7978 /* Name of keyword. */
7981 /* The type of value allowed. */
7982 enum image_value_type type
;
7984 /* Non-zero means key must be present. */
7987 /* Used to recognize duplicate keywords in a property list. */
7990 /* The value that was found. */
7995 static int parse_image_spec
P_ ((Lisp_Object
, struct image_keyword
*,
7997 static Lisp_Object image_spec_value
P_ ((Lisp_Object
, Lisp_Object
, int *));
8000 /* Parse image spec SPEC according to KEYWORDS. A valid image spec
8001 has the format (image KEYWORD VALUE ...). One of the keyword/
8002 value pairs must be `:type TYPE'. KEYWORDS is a vector of
8003 image_keywords structures of size NKEYWORDS describing other
8004 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */
8007 parse_image_spec (spec
, keywords
, nkeywords
, type
)
8009 struct image_keyword
*keywords
;
8016 if (!CONSP (spec
) || !EQ (XCAR (spec
), Qimage
))
8019 plist
= XCDR (spec
);
8020 while (CONSP (plist
))
8022 Lisp_Object key
, value
;
8024 /* First element of a pair must be a symbol. */
8026 plist
= XCDR (plist
);
8030 /* There must follow a value. */
8033 value
= XCAR (plist
);
8034 plist
= XCDR (plist
);
8036 /* Find key in KEYWORDS. Error if not found. */
8037 for (i
= 0; i
< nkeywords
; ++i
)
8038 if (strcmp (keywords
[i
].name
, XSYMBOL (key
)->name
->data
) == 0)
8044 /* Record that we recognized the keyword. If a keywords
8045 was found more than once, it's an error. */
8046 keywords
[i
].value
= value
;
8047 ++keywords
[i
].count
;
8049 if (keywords
[i
].count
> 1)
8052 /* Check type of value against allowed type. */
8053 switch (keywords
[i
].type
)
8055 case IMAGE_STRING_VALUE
:
8056 if (!STRINGP (value
))
8060 case IMAGE_SYMBOL_VALUE
:
8061 if (!SYMBOLP (value
))
8065 case IMAGE_POSITIVE_INTEGER_VALUE
:
8066 if (!INTEGERP (value
) || XINT (value
) <= 0)
8070 case IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
:
8071 if (INTEGERP (value
) && XINT (value
) >= 0)
8074 && INTEGERP (XCAR (value
)) && INTEGERP (XCDR (value
))
8075 && XINT (XCAR (value
)) >= 0 && XINT (XCDR (value
)) >= 0)
8079 case IMAGE_ASCENT_VALUE
:
8080 if (SYMBOLP (value
) && EQ (value
, Qcenter
))
8082 else if (INTEGERP (value
)
8083 && XINT (value
) >= 0
8084 && XINT (value
) <= 100)
8088 case IMAGE_NON_NEGATIVE_INTEGER_VALUE
:
8089 if (!INTEGERP (value
) || XINT (value
) < 0)
8093 case IMAGE_DONT_CHECK_VALUE_TYPE
:
8096 case IMAGE_FUNCTION_VALUE
:
8097 value
= indirect_function (value
);
8099 || COMPILEDP (value
)
8100 || (CONSP (value
) && EQ (XCAR (value
), Qlambda
)))
8104 case IMAGE_NUMBER_VALUE
:
8105 if (!INTEGERP (value
) && !FLOATP (value
))
8109 case IMAGE_INTEGER_VALUE
:
8110 if (!INTEGERP (value
))
8114 case IMAGE_BOOL_VALUE
:
8115 if (!NILP (value
) && !EQ (value
, Qt
))
8124 if (EQ (key
, QCtype
) && !EQ (type
, value
))
8128 /* Check that all mandatory fields are present. */
8129 for (i
= 0; i
< nkeywords
; ++i
)
8130 if (keywords
[i
].mandatory_p
&& keywords
[i
].count
== 0)
8133 return NILP (plist
);
8137 /* Return the value of KEY in image specification SPEC. Value is nil
8138 if KEY is not present in SPEC. if FOUND is not null, set *FOUND
8139 to 1 if KEY was found in SPEC, set it to 0 otherwise. */
8142 image_spec_value (spec
, key
, found
)
8143 Lisp_Object spec
, key
;
8148 xassert (valid_image_p (spec
));
8150 for (tail
= XCDR (spec
);
8151 CONSP (tail
) && CONSP (XCDR (tail
));
8152 tail
= XCDR (XCDR (tail
)))
8154 if (EQ (XCAR (tail
), key
))
8158 return XCAR (XCDR (tail
));
8170 /***********************************************************************
8171 Image type independent image structures
8172 ***********************************************************************/
8174 static struct image
*make_image
P_ ((Lisp_Object spec
, unsigned hash
));
8175 static void free_image
P_ ((struct frame
*f
, struct image
*img
));
8178 /* Allocate and return a new image structure for image specification
8179 SPEC. SPEC has a hash value of HASH. */
8181 static struct image
*
8182 make_image (spec
, hash
)
8186 struct image
*img
= (struct image
*) xmalloc (sizeof *img
);
8188 xassert (valid_image_p (spec
));
8189 bzero (img
, sizeof *img
);
8190 img
->type
= lookup_image_type (image_spec_value (spec
, QCtype
, NULL
));
8191 xassert (img
->type
!= NULL
);
8193 img
->data
.lisp_val
= Qnil
;
8194 img
->ascent
= DEFAULT_IMAGE_ASCENT
;
8200 /* Free image IMG which was used on frame F, including its resources. */
8209 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8211 /* Remove IMG from the hash table of its cache. */
8213 img
->prev
->next
= img
->next
;
8215 c
->buckets
[img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
] = img
->next
;
8218 img
->next
->prev
= img
->prev
;
8220 c
->images
[img
->id
] = NULL
;
8222 /* Free resources, then free IMG. */
8223 img
->type
->free (f
, img
);
8229 /* Prepare image IMG for display on frame F. Must be called before
8230 drawing an image. */
8233 prepare_image_for_display (f
, img
)
8239 /* We're about to display IMG, so set its timestamp to `now'. */
8241 img
->timestamp
= EMACS_SECS (t
);
8243 /* If IMG doesn't have a pixmap yet, load it now, using the image
8244 type dependent loader function. */
8245 if (img
->pixmap
== 0 && !img
->load_failed_p
)
8246 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
8250 /* Value is the number of pixels for the ascent of image IMG when
8251 drawn in face FACE. */
8254 image_ascent (img
, face
)
8258 int height
= img
->height
+ img
->vmargin
;
8261 if (img
->ascent
== CENTERED_IMAGE_ASCENT
)
8264 ascent
= height
/ 2 - (FONT_DESCENT(face
->font
)
8265 - FONT_BASE(face
->font
)) / 2;
8267 ascent
= height
/ 2;
8270 ascent
= height
* img
->ascent
/ 100.0;
8277 /***********************************************************************
8278 Helper functions for X image types
8279 ***********************************************************************/
8281 static void x_clear_image
P_ ((struct frame
*f
, struct image
*img
));
8282 static unsigned long x_alloc_image_color
P_ ((struct frame
*f
,
8284 Lisp_Object color_name
,
8285 unsigned long dflt
));
8287 /* Free X resources of image IMG which is used on frame F. */
8290 x_clear_image (f
, img
)
8294 #if 0 /* TODO: W32 image support */
8299 XFreePixmap (NULL
, img
->pixmap
);
8306 int class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
8308 /* If display has an immutable color map, freeing colors is not
8309 necessary and some servers don't allow it. So don't do it. */
8310 if (class != StaticColor
8311 && class != StaticGray
8312 && class != TrueColor
)
8316 cmap
= DefaultColormapOfScreen (FRAME_W32_DISPLAY_INFO (f
)->screen
);
8317 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
, img
->colors
,
8322 xfree (img
->colors
);
8330 /* Allocate color COLOR_NAME for image IMG on frame F. If color
8331 cannot be allocated, use DFLT. Add a newly allocated color to
8332 IMG->colors, so that it can be freed again. Value is the pixel
8335 static unsigned long
8336 x_alloc_image_color (f
, img
, color_name
, dflt
)
8339 Lisp_Object color_name
;
8342 #if 0 /* TODO: allocing colors. */
8344 unsigned long result
;
8346 xassert (STRINGP (color_name
));
8348 if (w32_defined_color (f
, XSTRING (color_name
)->data
, &color
, 1))
8350 /* This isn't called frequently so we get away with simply
8351 reallocating the color vector to the needed size, here. */
8354 (unsigned long *) xrealloc (img
->colors
,
8355 img
->ncolors
* sizeof *img
->colors
);
8356 img
->colors
[img
->ncolors
- 1] = color
.pixel
;
8357 result
= color
.pixel
;
8368 /***********************************************************************
8370 ***********************************************************************/
8372 static void cache_image
P_ ((struct frame
*f
, struct image
*img
));
8375 /* Return a new, initialized image cache that is allocated from the
8376 heap. Call free_image_cache to free an image cache. */
8378 struct image_cache
*
8381 struct image_cache
*c
= (struct image_cache
*) xmalloc (sizeof *c
);
8384 bzero (c
, sizeof *c
);
8386 c
->images
= (struct image
**) xmalloc (c
->size
* sizeof *c
->images
);
8387 size
= IMAGE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
8388 c
->buckets
= (struct image
**) xmalloc (size
);
8389 bzero (c
->buckets
, size
);
8394 /* Free image cache of frame F. Be aware that X frames share images
8398 free_image_cache (f
)
8401 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8406 /* Cache should not be referenced by any frame when freed. */
8407 xassert (c
->refcount
== 0);
8409 for (i
= 0; i
< c
->used
; ++i
)
8410 free_image (f
, c
->images
[i
]);
8414 FRAME_X_IMAGE_CACHE (f
) = NULL
;
8419 /* Clear image cache of frame F. FORCE_P non-zero means free all
8420 images. FORCE_P zero means clear only images that haven't been
8421 displayed for some time. Should be called from time to time to
8422 reduce the number of loaded images. If image-eviction-seconds is
8423 non-nil, this frees images in the cache which weren't displayed for
8424 at least that many seconds. */
8427 clear_image_cache (f
, force_p
)
8431 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8433 if (c
&& INTEGERP (Vimage_cache_eviction_delay
))
8437 int i
, any_freed_p
= 0;
8440 old
= EMACS_SECS (t
) - XFASTINT (Vimage_cache_eviction_delay
);
8442 for (i
= 0; i
< c
->used
; ++i
)
8444 struct image
*img
= c
->images
[i
];
8447 || (img
->timestamp
> old
)))
8449 free_image (f
, img
);
8454 /* We may be clearing the image cache because, for example,
8455 Emacs was iconified for a longer period of time. In that
8456 case, current matrices may still contain references to
8457 images freed above. So, clear these matrices. */
8460 clear_current_matrices (f
);
8461 ++windows_or_buffers_changed
;
8467 DEFUN ("clear-image-cache", Fclear_image_cache
, Sclear_image_cache
,
8469 "Clear the image cache of FRAME.\n\
8470 FRAME nil or omitted means use the selected frame.\n\
8471 FRAME t means clear the image caches of all frames.")
8479 FOR_EACH_FRAME (tail
, frame
)
8480 if (FRAME_W32_P (XFRAME (frame
)))
8481 clear_image_cache (XFRAME (frame
), 1);
8484 clear_image_cache (check_x_frame (frame
), 1);
8490 /* Return the id of image with Lisp specification SPEC on frame F.
8491 SPEC must be a valid Lisp image specification (see valid_image_p). */
8494 lookup_image (f
, spec
)
8498 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8502 struct gcpro gcpro1
;
8505 /* F must be a window-system frame, and SPEC must be a valid image
8507 xassert (FRAME_WINDOW_P (f
));
8508 xassert (valid_image_p (spec
));
8512 /* Look up SPEC in the hash table of the image cache. */
8513 hash
= sxhash (spec
, 0);
8514 i
= hash
% IMAGE_CACHE_BUCKETS_SIZE
;
8516 for (img
= c
->buckets
[i
]; img
; img
= img
->next
)
8517 if (img
->hash
== hash
&& !NILP (Fequal (img
->spec
, spec
)))
8520 /* If not found, create a new image and cache it. */
8524 img
= make_image (spec
, hash
);
8525 cache_image (f
, img
);
8526 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
8528 /* If we can't load the image, and we don't have a width and
8529 height, use some arbitrary width and height so that we can
8530 draw a rectangle for it. */
8531 if (img
->load_failed_p
)
8535 value
= image_spec_value (spec
, QCwidth
, NULL
);
8536 img
->width
= (INTEGERP (value
)
8537 ? XFASTINT (value
) : DEFAULT_IMAGE_WIDTH
);
8538 value
= image_spec_value (spec
, QCheight
, NULL
);
8539 img
->height
= (INTEGERP (value
)
8540 ? XFASTINT (value
) : DEFAULT_IMAGE_HEIGHT
);
8544 /* Handle image type independent image attributes
8545 `:ascent PERCENT', `:margin MARGIN', `:relief RELIEF'. */
8546 Lisp_Object ascent
, margin
, relief
;
8548 ascent
= image_spec_value (spec
, QCascent
, NULL
);
8549 if (INTEGERP (ascent
))
8550 img
->ascent
= XFASTINT (ascent
);
8551 else if (EQ (ascent
, Qcenter
))
8552 img
->ascent
= CENTERED_IMAGE_ASCENT
;
8554 margin
= image_spec_value (spec
, QCmargin
, NULL
);
8555 if (INTEGERP (margin
) && XINT (margin
) >= 0)
8556 img
->vmargin
= img
->hmargin
= XFASTINT (margin
);
8557 else if (CONSP (margin
) && INTEGERP (XCAR (margin
))
8558 && INTEGERP (XCDR (margin
)))
8560 if (XINT (XCAR (margin
)) > 0)
8561 img
->hmargin
= XFASTINT (XCAR (margin
));
8562 if (XINT (XCDR (margin
)) > 0)
8563 img
->vmargin
= XFASTINT (XCDR (margin
));
8566 relief
= image_spec_value (spec
, QCrelief
, NULL
);
8567 if (INTEGERP (relief
))
8569 img
->relief
= XINT (relief
);
8570 img
->hmargin
+= abs (img
->relief
);
8571 img
->vmargin
+= abs (img
->relief
);
8574 #if 0 /* TODO: image mask and algorithm. */
8575 /* Manipulation of the image's mask. */
8578 /* `:heuristic-mask t'
8580 means build a mask heuristically.
8581 `:heuristic-mask (R G B)'
8582 `:mask (heuristic (R G B))'
8583 means build a mask from color (R G B) in the
8586 means remove a mask, if any. */
8590 mask
= image_spec_value (spec
, QCheuristic_mask
, NULL
);
8592 x_build_heuristic_mask (f
, img
, mask
);
8597 mask
= image_spec_value (spec
, QCmask
, &found_p
);
8599 if (EQ (mask
, Qheuristic
))
8600 x_build_heuristic_mask (f
, img
, Qt
);
8601 else if (CONSP (mask
)
8602 && EQ (XCAR (mask
), Qheuristic
))
8604 if (CONSP (XCDR (mask
)))
8605 x_build_heuristic_mask (f
, img
, XCAR (XCDR (mask
)));
8607 x_build_heuristic_mask (f
, img
, XCDR (mask
));
8609 else if (NILP (mask
) && found_p
&& img
->mask
)
8611 XFreePixmap (FRAME_X_DISPLAY (f
), img
->mask
);
8617 /* Should we apply an image transformation algorithm? */
8620 Lisp_Object conversion
;
8622 algorithm
= image_spec_value (spec
, QCconversion
, NULL
);
8623 if (EQ (conversion
, Qdisabled
))
8624 x_disable_image (f
, img
);
8625 else if (EQ (conversion
, Qlaplace
))
8627 else if (EQ (conversion
, Qemboss
))
8629 else if (CONSP (conversion
)
8630 && EQ (XCAR (conversion
), Qedge_detection
))
8633 tem
= XCDR (conversion
);
8635 x_edge_detection (f
, img
,
8636 Fplist_get (tem
, QCmatrix
),
8637 Fplist_get (tem
, QCcolor_adjustment
));
8643 xassert (!interrupt_input_blocked
);
8646 /* We're using IMG, so set its timestamp to `now'. */
8647 EMACS_GET_TIME (now
);
8648 img
->timestamp
= EMACS_SECS (now
);
8652 /* Value is the image id. */
8657 /* Cache image IMG in the image cache of frame F. */
8660 cache_image (f
, img
)
8664 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8667 /* Find a free slot in c->images. */
8668 for (i
= 0; i
< c
->used
; ++i
)
8669 if (c
->images
[i
] == NULL
)
8672 /* If no free slot found, maybe enlarge c->images. */
8673 if (i
== c
->used
&& c
->used
== c
->size
)
8676 c
->images
= (struct image
**) xrealloc (c
->images
,
8677 c
->size
* sizeof *c
->images
);
8680 /* Add IMG to c->images, and assign IMG an id. */
8686 /* Add IMG to the cache's hash table. */
8687 i
= img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
;
8688 img
->next
= c
->buckets
[i
];
8690 img
->next
->prev
= img
;
8692 c
->buckets
[i
] = img
;
8696 /* Call FN on every image in the image cache of frame F. Used to mark
8697 Lisp Objects in the image cache. */
8700 forall_images_in_image_cache (f
, fn
)
8702 void (*fn
) P_ ((struct image
*img
));
8704 if (FRAME_LIVE_P (f
) && FRAME_W32_P (f
))
8706 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8710 for (i
= 0; i
< c
->used
; ++i
)
8719 /***********************************************************************
8721 ***********************************************************************/
8723 #if 0 /* TODO: W32 specific image code. */
8725 static int x_create_x_image_and_pixmap
P_ ((struct frame
*, int, int, int,
8726 XImage
**, Pixmap
*));
8727 static void x_destroy_x_image
P_ ((XImage
*));
8728 static void x_put_x_image
P_ ((struct frame
*, XImage
*, Pixmap
, int, int));
8731 /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on
8732 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
8733 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
8734 via xmalloc. Print error messages via image_error if an error
8735 occurs. Value is non-zero if successful. */
8738 x_create_x_image_and_pixmap (f
, width
, height
, depth
, ximg
, pixmap
)
8740 int width
, height
, depth
;
8744 #if 0 /* TODO: Image support for W32 */
8745 Display
*display
= FRAME_W32_DISPLAY (f
);
8746 Screen
*screen
= FRAME_X_SCREEN (f
);
8747 Window window
= FRAME_W32_WINDOW (f
);
8749 xassert (interrupt_input_blocked
);
8752 depth
= DefaultDepthOfScreen (screen
);
8753 *ximg
= XCreateImage (display
, DefaultVisualOfScreen (screen
),
8754 depth
, ZPixmap
, 0, NULL
, width
, height
,
8755 depth
> 16 ? 32 : depth
> 8 ? 16 : 8, 0);
8758 image_error ("Unable to allocate X image", Qnil
, Qnil
);
8762 /* Allocate image raster. */
8763 (*ximg
)->data
= (char *) xmalloc ((*ximg
)->bytes_per_line
* height
);
8765 /* Allocate a pixmap of the same size. */
8766 *pixmap
= XCreatePixmap (display
, window
, width
, height
, depth
);
8769 x_destroy_x_image (*ximg
);
8771 image_error ("Unable to create X pixmap", Qnil
, Qnil
);
8779 /* Destroy XImage XIMG. Free XIMG->data. */
8782 x_destroy_x_image (ximg
)
8785 xassert (interrupt_input_blocked
);
8790 XDestroyImage (ximg
);
8795 /* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT
8796 are width and height of both the image and pixmap. */
8799 x_put_x_image (f
, ximg
, pixmap
, width
, height
)
8806 xassert (interrupt_input_blocked
);
8807 gc
= XCreateGC (NULL
, pixmap
, 0, NULL
);
8808 XPutImage (NULL
, pixmap
, gc
, ximg
, 0, 0, 0, 0, width
, height
);
8815 /***********************************************************************
8817 ***********************************************************************/
8819 static Lisp_Object x_find_image_file
P_ ((Lisp_Object
));
8821 /* Find image file FILE. Look in data-directory, then
8822 x-bitmap-file-path. Value is the full name of the file found, or
8823 nil if not found. */
8826 x_find_image_file (file
)
8829 Lisp_Object file_found
, search_path
;
8830 struct gcpro gcpro1
, gcpro2
;
8834 search_path
= Fcons (Vdata_directory
, Vx_bitmap_file_path
);
8835 GCPRO2 (file_found
, search_path
);
8837 /* Try to find FILE in data-directory, then x-bitmap-file-path. */
8838 fd
= openp (search_path
, file
, "", &file_found
, 0);
8851 /***********************************************************************
8853 ***********************************************************************/
8855 static int xbm_load
P_ ((struct frame
*f
, struct image
*img
));
8856 static int xbm_load_image_from_file
P_ ((struct frame
*f
, struct image
*img
,
8858 static int xbm_image_p
P_ ((Lisp_Object object
));
8859 static int xbm_read_bitmap_file_data
P_ ((char *, int *, int *,
8863 /* Indices of image specification fields in xbm_format, below. */
8865 enum xbm_keyword_index
8882 /* Vector of image_keyword structures describing the format
8883 of valid XBM image specifications. */
8885 static struct image_keyword xbm_format
[XBM_LAST
] =
8887 {":type", IMAGE_SYMBOL_VALUE
, 1},
8888 {":file", IMAGE_STRING_VALUE
, 0},
8889 {":width", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8890 {":height", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8891 {":data", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8892 {":foreground", IMAGE_STRING_VALUE
, 0},
8893 {":background", IMAGE_STRING_VALUE
, 0},
8894 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
8895 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
8896 {":relief", IMAGE_INTEGER_VALUE
, 0},
8897 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8898 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
8901 /* Structure describing the image type XBM. */
8903 static struct image_type xbm_type
=
8912 /* Tokens returned from xbm_scan. */
8921 /* Return non-zero if OBJECT is a valid XBM-type image specification.
8922 A valid specification is a list starting with the symbol `image'
8923 The rest of the list is a property list which must contain an
8926 If the specification specifies a file to load, it must contain
8927 an entry `:file FILENAME' where FILENAME is a string.
8929 If the specification is for a bitmap loaded from memory it must
8930 contain `:width WIDTH', `:height HEIGHT', and `:data DATA', where
8931 WIDTH and HEIGHT are integers > 0. DATA may be:
8933 1. a string large enough to hold the bitmap data, i.e. it must
8934 have a size >= (WIDTH + 7) / 8 * HEIGHT
8936 2. a bool-vector of size >= WIDTH * HEIGHT
8938 3. a vector of strings or bool-vectors, one for each line of the
8941 Both the file and data forms may contain the additional entries
8942 `:background COLOR' and `:foreground COLOR'. If not present,
8943 foreground and background of the frame on which the image is
8944 displayed, is used. */
8947 xbm_image_p (object
)
8950 struct image_keyword kw
[XBM_LAST
];
8952 bcopy (xbm_format
, kw
, sizeof kw
);
8953 if (!parse_image_spec (object
, kw
, XBM_LAST
, Qxbm
))
8956 xassert (EQ (kw
[XBM_TYPE
].value
, Qxbm
));
8958 if (kw
[XBM_FILE
].count
)
8960 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_DATA
].count
)
8968 /* Entries for `:width', `:height' and `:data' must be present. */
8969 if (!kw
[XBM_WIDTH
].count
8970 || !kw
[XBM_HEIGHT
].count
8971 || !kw
[XBM_DATA
].count
)
8974 data
= kw
[XBM_DATA
].value
;
8975 width
= XFASTINT (kw
[XBM_WIDTH
].value
);
8976 height
= XFASTINT (kw
[XBM_HEIGHT
].value
);
8978 /* Check type of data, and width and height against contents of
8984 /* Number of elements of the vector must be >= height. */
8985 if (XVECTOR (data
)->size
< height
)
8988 /* Each string or bool-vector in data must be large enough
8989 for one line of the image. */
8990 for (i
= 0; i
< height
; ++i
)
8992 Lisp_Object elt
= XVECTOR (data
)->contents
[i
];
8996 if (XSTRING (elt
)->size
8997 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
)
9000 else if (BOOL_VECTOR_P (elt
))
9002 if (XBOOL_VECTOR (elt
)->size
< width
)
9009 else if (STRINGP (data
))
9011 if (XSTRING (data
)->size
9012 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
* height
)
9015 else if (BOOL_VECTOR_P (data
))
9017 if (XBOOL_VECTOR (data
)->size
< width
* height
)
9024 /* Baseline must be a value between 0 and 100 (a percentage). */
9025 if (kw
[XBM_ASCENT
].count
9026 && XFASTINT (kw
[XBM_ASCENT
].value
) > 100)
9033 /* Scan a bitmap file. FP is the stream to read from. Value is
9034 either an enumerator from enum xbm_token, or a character for a
9035 single-character token, or 0 at end of file. If scanning an
9036 identifier, store the lexeme of the identifier in SVAL. If
9037 scanning a number, store its value in *IVAL. */
9040 xbm_scan (fp
, sval
, ival
)
9047 /* Skip white space. */
9048 while ((c
= fgetc (fp
)) != EOF
&& isspace (c
))
9053 else if (isdigit (c
))
9055 int value
= 0, digit
;
9060 if (c
== 'x' || c
== 'X')
9062 while ((c
= fgetc (fp
)) != EOF
)
9066 else if (c
>= 'a' && c
<= 'f')
9067 digit
= c
- 'a' + 10;
9068 else if (c
>= 'A' && c
<= 'F')
9069 digit
= c
- 'A' + 10;
9072 value
= 16 * value
+ digit
;
9075 else if (isdigit (c
))
9078 while ((c
= fgetc (fp
)) != EOF
9080 value
= 8 * value
+ c
- '0';
9086 while ((c
= fgetc (fp
)) != EOF
9088 value
= 10 * value
+ c
- '0';
9096 else if (isalpha (c
) || c
== '_')
9099 while ((c
= fgetc (fp
)) != EOF
9100 && (isalnum (c
) || c
== '_'))
9112 /* Replacement for XReadBitmapFileData which isn't available under old
9113 X versions. FILE is the name of the bitmap file to read. Set
9114 *WIDTH and *HEIGHT to the width and height of the image. Return in
9115 *DATA the bitmap data allocated with xmalloc. Value is non-zero if
9119 xbm_read_bitmap_file_data (file
, width
, height
, data
)
9121 int *width
, *height
;
9122 unsigned char **data
;
9125 char buffer
[BUFSIZ
];
9128 int bytes_per_line
, i
, nbytes
;
9134 LA1 = xbm_scan (fp, buffer, &value)
9136 #define expect(TOKEN) \
9137 if (LA1 != (TOKEN)) \
9142 #define expect_ident(IDENT) \
9143 if (LA1 == XBM_TK_IDENT && strcmp (buffer, (IDENT)) == 0) \
9148 fp
= fopen (file
, "r");
9152 *width
= *height
= -1;
9154 LA1
= xbm_scan (fp
, buffer
, &value
);
9156 /* Parse defines for width, height and hot-spots. */
9160 expect_ident ("define");
9161 expect (XBM_TK_IDENT
);
9163 if (LA1
== XBM_TK_NUMBER
);
9165 char *p
= strrchr (buffer
, '_');
9166 p
= p
? p
+ 1 : buffer
;
9167 if (strcmp (p
, "width") == 0)
9169 else if (strcmp (p
, "height") == 0)
9172 expect (XBM_TK_NUMBER
);
9175 if (*width
< 0 || *height
< 0)
9178 /* Parse bits. Must start with `static'. */
9179 expect_ident ("static");
9180 if (LA1
== XBM_TK_IDENT
)
9182 if (strcmp (buffer
, "unsigned") == 0)
9185 expect_ident ("char");
9187 else if (strcmp (buffer
, "short") == 0)
9191 if (*width
% 16 && *width
% 16 < 9)
9194 else if (strcmp (buffer
, "char") == 0)
9202 expect (XBM_TK_IDENT
);
9208 bytes_per_line
= (*width
+ 7) / 8 + padding_p
;
9209 nbytes
= bytes_per_line
* *height
;
9210 p
= *data
= (char *) xmalloc (nbytes
);
9215 for (i
= 0; i
< nbytes
; i
+= 2)
9218 expect (XBM_TK_NUMBER
);
9221 if (!padding_p
|| ((i
+ 2) % bytes_per_line
))
9224 if (LA1
== ',' || LA1
== '}')
9232 for (i
= 0; i
< nbytes
; ++i
)
9235 expect (XBM_TK_NUMBER
);
9239 if (LA1
== ',' || LA1
== '}')
9265 /* Load XBM image IMG which will be displayed on frame F from file
9266 SPECIFIED_FILE. Value is non-zero if successful. */
9269 xbm_load_image_from_file (f
, img
, specified_file
)
9272 Lisp_Object specified_file
;
9275 unsigned char *data
;
9278 struct gcpro gcpro1
;
9280 xassert (STRINGP (specified_file
));
9284 file
= x_find_image_file (specified_file
);
9285 if (!STRINGP (file
))
9287 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9292 rc
= xbm_read_bitmap_file_data (XSTRING (file
)->data
, &img
->width
,
9293 &img
->height
, &data
);
9296 int depth
= one_w32_display_info
.n_cbits
;
9297 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
9298 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
9301 xassert (img
->width
> 0 && img
->height
> 0);
9303 /* Get foreground and background colors, maybe allocate colors. */
9304 value
= image_spec_value (img
->spec
, QCforeground
, NULL
);
9306 foreground
= x_alloc_image_color (f
, img
, value
, foreground
);
9308 value
= image_spec_value (img
->spec
, QCbackground
, NULL
);
9310 background
= x_alloc_image_color (f
, img
, value
, background
);
9312 #if 0 /* TODO : Port image display to W32 */
9315 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
9316 FRAME_W32_WINDOW (f
),
9318 img
->width
, img
->height
,
9319 foreground
, background
,
9323 if (img
->pixmap
== 0)
9325 x_clear_image (f
, img
);
9326 image_error ("Unable to create X pixmap for `%s'", file
, Qnil
);
9335 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
9342 /* Fill image IMG which is used on frame F with pixmap data. Value is
9343 non-zero if successful. */
9351 Lisp_Object file_name
;
9353 xassert (xbm_image_p (img
->spec
));
9355 /* If IMG->spec specifies a file name, create a non-file spec from it. */
9356 file_name
= image_spec_value (img
->spec
, QCfile
, NULL
);
9357 if (STRINGP (file_name
))
9358 success_p
= xbm_load_image_from_file (f
, img
, file_name
);
9361 struct image_keyword fmt
[XBM_LAST
];
9364 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
9365 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
9369 /* Parse the list specification. */
9370 bcopy (xbm_format
, fmt
, sizeof fmt
);
9371 parsed_p
= parse_image_spec (img
->spec
, fmt
, XBM_LAST
, Qxbm
);
9374 /* Get specified width, and height. */
9375 img
->width
= XFASTINT (fmt
[XBM_WIDTH
].value
);
9376 img
->height
= XFASTINT (fmt
[XBM_HEIGHT
].value
);
9377 xassert (img
->width
> 0 && img
->height
> 0);
9381 if (fmt
[XBM_ASCENT
].count
)
9382 img
->ascent
= XFASTINT (fmt
[XBM_ASCENT
].value
);
9384 /* Get foreground and background colors, maybe allocate colors. */
9385 if (fmt
[XBM_FOREGROUND
].count
)
9386 foreground
= x_alloc_image_color (f
, img
, fmt
[XBM_FOREGROUND
].value
,
9388 if (fmt
[XBM_BACKGROUND
].count
)
9389 background
= x_alloc_image_color (f
, img
, fmt
[XBM_BACKGROUND
].value
,
9392 /* Set bits to the bitmap image data. */
9393 data
= fmt
[XBM_DATA
].value
;
9398 int nbytes
= (img
->width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
;
9400 p
= bits
= (char *) alloca (nbytes
* img
->height
);
9401 for (i
= 0; i
< img
->height
; ++i
, p
+= nbytes
)
9403 Lisp_Object line
= XVECTOR (data
)->contents
[i
];
9405 bcopy (XSTRING (line
)->data
, p
, nbytes
);
9407 bcopy (XBOOL_VECTOR (line
)->data
, p
, nbytes
);
9410 else if (STRINGP (data
))
9411 bits
= XSTRING (data
)->data
;
9413 bits
= XBOOL_VECTOR (data
)->data
;
9415 #if 0 /* TODO : W32 XPM code */
9416 /* Create the pixmap. */
9417 depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
9419 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
9420 FRAME_W32_WINDOW (f
),
9422 img
->width
, img
->height
,
9423 foreground
, background
,
9431 image_error ("Unable to create pixmap for XBM image `%s'",
9433 x_clear_image (f
, img
);
9444 /***********************************************************************
9446 ***********************************************************************/
9450 static int xpm_image_p
P_ ((Lisp_Object object
));
9451 static int xpm_load
P_ ((struct frame
*f
, struct image
*img
));
9452 static int xpm_valid_color_symbols_p
P_ ((Lisp_Object
));
9454 #include "X11/xpm.h"
9456 /* The symbol `xpm' identifying XPM-format images. */
9460 /* Indices of image specification fields in xpm_format, below. */
9462 enum xpm_keyword_index
9476 /* Vector of image_keyword structures describing the format
9477 of valid XPM image specifications. */
9479 static struct image_keyword xpm_format
[XPM_LAST
] =
9481 {":type", IMAGE_SYMBOL_VALUE
, 1},
9482 {":file", IMAGE_STRING_VALUE
, 0},
9483 {":data", IMAGE_STRING_VALUE
, 0},
9484 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9485 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
9486 {":relief", IMAGE_INTEGER_VALUE
, 0},
9487 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9488 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9489 {":color-symbols", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9492 /* Structure describing the image type XBM. */
9494 static struct image_type xpm_type
=
9504 /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
9505 for XPM images. Such a list must consist of conses whose car and
9509 xpm_valid_color_symbols_p (color_symbols
)
9510 Lisp_Object color_symbols
;
9512 while (CONSP (color_symbols
))
9514 Lisp_Object sym
= XCAR (color_symbols
);
9516 || !STRINGP (XCAR (sym
))
9517 || !STRINGP (XCDR (sym
)))
9519 color_symbols
= XCDR (color_symbols
);
9522 return NILP (color_symbols
);
9526 /* Value is non-zero if OBJECT is a valid XPM image specification. */
9529 xpm_image_p (object
)
9532 struct image_keyword fmt
[XPM_LAST
];
9533 bcopy (xpm_format
, fmt
, sizeof fmt
);
9534 return (parse_image_spec (object
, fmt
, XPM_LAST
, Qxpm
)
9535 /* Either `:file' or `:data' must be present. */
9536 && fmt
[XPM_FILE
].count
+ fmt
[XPM_DATA
].count
== 1
9537 /* Either no `:color-symbols' or it's a list of conses
9538 whose car and cdr are strings. */
9539 && (fmt
[XPM_COLOR_SYMBOLS
].count
== 0
9540 || xpm_valid_color_symbols_p (fmt
[XPM_COLOR_SYMBOLS
].value
))
9541 && (fmt
[XPM_ASCENT
].count
== 0
9542 || XFASTINT (fmt
[XPM_ASCENT
].value
) < 100));
9546 /* Load image IMG which will be displayed on frame F. Value is
9547 non-zero if successful. */
9555 XpmAttributes attrs
;
9556 Lisp_Object specified_file
, color_symbols
;
9558 /* Configure the XPM lib. Use the visual of frame F. Allocate
9559 close colors. Return colors allocated. */
9560 bzero (&attrs
, sizeof attrs
);
9561 attrs
.visual
= FRAME_X_VISUAL (f
);
9562 attrs
.colormap
= FRAME_X_COLORMAP (f
);
9563 attrs
.valuemask
|= XpmVisual
;
9564 attrs
.valuemask
|= XpmColormap
;
9565 attrs
.valuemask
|= XpmReturnAllocPixels
;
9566 #ifdef XpmAllocCloseColors
9567 attrs
.alloc_close_colors
= 1;
9568 attrs
.valuemask
|= XpmAllocCloseColors
;
9570 attrs
.closeness
= 600;
9571 attrs
.valuemask
|= XpmCloseness
;
9574 /* If image specification contains symbolic color definitions, add
9575 these to `attrs'. */
9576 color_symbols
= image_spec_value (img
->spec
, QCcolor_symbols
, NULL
);
9577 if (CONSP (color_symbols
))
9580 XpmColorSymbol
*xpm_syms
;
9583 attrs
.valuemask
|= XpmColorSymbols
;
9585 /* Count number of symbols. */
9586 attrs
.numsymbols
= 0;
9587 for (tail
= color_symbols
; CONSP (tail
); tail
= XCDR (tail
))
9590 /* Allocate an XpmColorSymbol array. */
9591 size
= attrs
.numsymbols
* sizeof *xpm_syms
;
9592 xpm_syms
= (XpmColorSymbol
*) alloca (size
);
9593 bzero (xpm_syms
, size
);
9594 attrs
.colorsymbols
= xpm_syms
;
9596 /* Fill the color symbol array. */
9597 for (tail
= color_symbols
, i
= 0;
9599 ++i
, tail
= XCDR (tail
))
9601 Lisp_Object name
= XCAR (XCAR (tail
));
9602 Lisp_Object color
= XCDR (XCAR (tail
));
9603 xpm_syms
[i
].name
= (char *) alloca (XSTRING (name
)->size
+ 1);
9604 strcpy (xpm_syms
[i
].name
, XSTRING (name
)->data
);
9605 xpm_syms
[i
].value
= (char *) alloca (XSTRING (color
)->size
+ 1);
9606 strcpy (xpm_syms
[i
].value
, XSTRING (color
)->data
);
9610 /* Create a pixmap for the image, either from a file, or from a
9611 string buffer containing data in the same format as an XPM file. */
9613 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9614 if (STRINGP (specified_file
))
9616 Lisp_Object file
= x_find_image_file (specified_file
);
9617 if (!STRINGP (file
))
9619 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9624 rc
= XpmReadFileToPixmap (NULL
, FRAME_W32_WINDOW (f
),
9625 XSTRING (file
)->data
, &img
->pixmap
, &img
->mask
,
9630 Lisp_Object buffer
= image_spec_value (img
->spec
, QCdata
, NULL
);
9631 rc
= XpmCreatePixmapFromBuffer (NULL
, FRAME_W32_WINDOW (f
),
9632 XSTRING (buffer
)->data
,
9633 &img
->pixmap
, &img
->mask
,
9638 if (rc
== XpmSuccess
)
9640 /* Remember allocated colors. */
9641 img
->ncolors
= attrs
.nalloc_pixels
;
9642 img
->colors
= (unsigned long *) xmalloc (img
->ncolors
9643 * sizeof *img
->colors
);
9644 for (i
= 0; i
< attrs
.nalloc_pixels
; ++i
)
9645 img
->colors
[i
] = attrs
.alloc_pixels
[i
];
9647 img
->width
= attrs
.width
;
9648 img
->height
= attrs
.height
;
9649 xassert (img
->width
> 0 && img
->height
> 0);
9651 /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */
9653 XpmFreeAttributes (&attrs
);
9661 image_error ("Error opening XPM file (%s)", img
->spec
, Qnil
);
9664 case XpmFileInvalid
:
9665 image_error ("Invalid XPM file (%s)", img
->spec
, Qnil
);
9669 image_error ("Out of memory (%s)", img
->spec
, Qnil
);
9672 case XpmColorFailed
:
9673 image_error ("Color allocation error (%s)", img
->spec
, Qnil
);
9677 image_error ("Unknown error (%s)", img
->spec
, Qnil
);
9682 return rc
== XpmSuccess
;
9685 #endif /* HAVE_XPM != 0 */
9688 #if 0 /* TODO : Color tables on W32. */
9689 /***********************************************************************
9691 ***********************************************************************/
9693 /* An entry in the color table mapping an RGB color to a pixel color. */
9698 unsigned long pixel
;
9700 /* Next in color table collision list. */
9701 struct ct_color
*next
;
9704 /* The bucket vector size to use. Must be prime. */
9708 /* Value is a hash of the RGB color given by R, G, and B. */
9710 #define CT_HASH_RGB(R, G, B) (((R) << 16) ^ ((G) << 8) ^ (B))
9712 /* The color hash table. */
9714 struct ct_color
**ct_table
;
9716 /* Number of entries in the color table. */
9718 int ct_colors_allocated
;
9720 /* Function prototypes. */
9722 static void init_color_table
P_ ((void));
9723 static void free_color_table
P_ ((void));
9724 static unsigned long *colors_in_color_table
P_ ((int *n
));
9725 static unsigned long lookup_rgb_color
P_ ((struct frame
*f
, int r
, int g
, int b
));
9726 static unsigned long lookup_pixel_color
P_ ((struct frame
*f
, unsigned long p
));
9729 /* Initialize the color table. */
9734 int size
= CT_SIZE
* sizeof (*ct_table
);
9735 ct_table
= (struct ct_color
**) xmalloc (size
);
9736 bzero (ct_table
, size
);
9737 ct_colors_allocated
= 0;
9741 /* Free memory associated with the color table. */
9747 struct ct_color
*p
, *next
;
9749 for (i
= 0; i
< CT_SIZE
; ++i
)
9750 for (p
= ct_table
[i
]; p
; p
= next
)
9761 /* Value is a pixel color for RGB color R, G, B on frame F. If an
9762 entry for that color already is in the color table, return the
9763 pixel color of that entry. Otherwise, allocate a new color for R,
9764 G, B, and make an entry in the color table. */
9766 static unsigned long
9767 lookup_rgb_color (f
, r
, g
, b
)
9771 unsigned hash
= CT_HASH_RGB (r
, g
, b
);
9772 int i
= hash
% CT_SIZE
;
9775 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9776 if (p
->r
== r
&& p
->g
== g
&& p
->b
== b
)
9785 color
= PALETTERGB (r
, g
, b
);
9787 ++ct_colors_allocated
;
9789 p
= (struct ct_color
*) xmalloc (sizeof *p
);
9794 p
->next
= ct_table
[i
];
9802 /* Look up pixel color PIXEL which is used on frame F in the color
9803 table. If not already present, allocate it. Value is PIXEL. */
9805 static unsigned long
9806 lookup_pixel_color (f
, pixel
)
9808 unsigned long pixel
;
9810 int i
= pixel
% CT_SIZE
;
9813 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9814 if (p
->pixel
== pixel
)
9825 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9826 color
.pixel
= pixel
;
9827 XQueryColor (NULL
, cmap
, &color
);
9828 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
9833 ++ct_colors_allocated
;
9835 p
= (struct ct_color
*) xmalloc (sizeof *p
);
9840 p
->next
= ct_table
[i
];
9844 return FRAME_FOREGROUND_PIXEL (f
);
9850 /* Value is a vector of all pixel colors contained in the color table,
9851 allocated via xmalloc. Set *N to the number of colors. */
9853 static unsigned long *
9854 colors_in_color_table (n
)
9859 unsigned long *colors
;
9861 if (ct_colors_allocated
== 0)
9868 colors
= (unsigned long *) xmalloc (ct_colors_allocated
9870 *n
= ct_colors_allocated
;
9872 for (i
= j
= 0; i
< CT_SIZE
; ++i
)
9873 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9874 colors
[j
++] = p
->pixel
;
9883 /***********************************************************************
9885 ***********************************************************************/
9887 #if 0 /* TODO : W32 versions of low level algorithms */
9888 static void x_laplace_write_row
P_ ((struct frame
*, long *,
9889 int, XImage
*, int));
9890 static void x_laplace_read_row
P_ ((struct frame
*, Colormap
,
9891 XColor
*, int, XImage
*, int));
9894 /* Fill COLORS with RGB colors from row Y of image XIMG. F is the
9895 frame we operate on, CMAP is the color-map in effect, and WIDTH is
9896 the width of one row in the image. */
9899 x_laplace_read_row (f
, cmap
, colors
, width
, ximg
, y
)
9909 for (x
= 0; x
< width
; ++x
)
9910 colors
[x
].pixel
= XGetPixel (ximg
, x
, y
);
9912 XQueryColors (NULL
, cmap
, colors
, width
);
9916 /* Write row Y of image XIMG. PIXELS is an array of WIDTH longs
9917 containing the pixel colors to write. F is the frame we are
9921 x_laplace_write_row (f
, pixels
, width
, ximg
, y
)
9930 for (x
= 0; x
< width
; ++x
)
9931 XPutPixel (ximg
, x
, y
, pixels
[x
]);
9935 /* Transform image IMG which is used on frame F with a Laplace
9936 edge-detection algorithm. The result is an image that can be used
9937 to draw disabled buttons, for example. */
9944 #if 0 /* TODO : W32 version */
9945 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9946 XImage
*ximg
, *oimg
;
9952 int in_y
, out_y
, rc
;
9957 /* Get the X image IMG->pixmap. */
9958 ximg
= XGetImage (NULL
, img
->pixmap
,
9959 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
9961 /* Allocate 3 input rows, and one output row of colors. */
9962 for (i
= 0; i
< 3; ++i
)
9963 in
[i
] = (XColor
*) alloca (img
->width
* sizeof (XColor
));
9964 out
= (long *) alloca (img
->width
* sizeof (long));
9966 /* Create an X image for output. */
9967 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 0,
9970 /* Fill first two rows. */
9971 x_laplace_read_row (f
, cmap
, in
[0], img
->width
, ximg
, 0);
9972 x_laplace_read_row (f
, cmap
, in
[1], img
->width
, ximg
, 1);
9975 /* Write first row, all zeros. */
9976 init_color_table ();
9977 pixel
= lookup_rgb_color (f
, 0, 0, 0);
9978 for (x
= 0; x
< img
->width
; ++x
)
9980 x_laplace_write_row (f
, out
, img
->width
, oimg
, 0);
9983 for (y
= 2; y
< img
->height
; ++y
)
9986 int rowb
= (y
+ 2) % 3;
9988 x_laplace_read_row (f
, cmap
, in
[rowa
], img
->width
, ximg
, in_y
++);
9990 for (x
= 0; x
< img
->width
- 2; ++x
)
9992 int r
= in
[rowa
][x
].red
+ mv2
- in
[rowb
][x
+ 2].red
;
9993 int g
= in
[rowa
][x
].green
+ mv2
- in
[rowb
][x
+ 2].green
;
9994 int b
= in
[rowa
][x
].blue
+ mv2
- in
[rowb
][x
+ 2].blue
;
9996 out
[x
+ 1] = lookup_rgb_color (f
, r
& 0xffff, g
& 0xffff,
10000 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
++);
10003 /* Write last line, all zeros. */
10004 for (x
= 0; x
< img
->width
; ++x
)
10006 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
);
10008 /* Free the input image, and free resources of IMG. */
10009 XDestroyImage (ximg
);
10010 x_clear_image (f
, img
);
10012 /* Put the output image into pixmap, and destroy it. */
10013 x_put_x_image (f
, oimg
, pixmap
, img
->width
, img
->height
);
10014 x_destroy_x_image (oimg
);
10016 /* Remember new pixmap and colors in IMG. */
10017 img
->pixmap
= pixmap
;
10018 img
->colors
= colors_in_color_table (&img
->ncolors
);
10019 free_color_table ();
10026 /* Build a mask for image IMG which is used on frame F. FILE is the
10027 name of an image file, for error messages. HOW determines how to
10028 determine the background color of IMG. If it is a list '(R G B)',
10029 with R, G, and B being integers >= 0, take that as the color of the
10030 background. Otherwise, determine the background color of IMG
10031 heuristically. Value is non-zero if successful. */
10034 x_build_heuristic_mask (f
, img
, how
)
10039 #if 0 /* TODO : W32 version */
10040 Display
*dpy
= FRAME_W32_DISPLAY (f
);
10041 XImage
*ximg
, *mask_img
;
10042 int x
, y
, rc
, look_at_corners_p
;
10047 /* Create an image and pixmap serving as mask. */
10048 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 1,
10049 &mask_img
, &img
->mask
);
10056 /* Get the X image of IMG->pixmap. */
10057 ximg
= XGetImage (dpy
, img
->pixmap
, 0, 0, img
->width
, img
->height
,
10060 /* Determine the background color of ximg. If HOW is `(R G B)'
10061 take that as color. Otherwise, try to determine the color
10063 look_at_corners_p
= 1;
10071 && NATNUMP (XCAR (how
)))
10073 rgb
[i
] = XFASTINT (XCAR (how
)) & 0xffff;
10077 if (i
== 3 && NILP (how
))
10079 char color_name
[30];
10080 XColor exact
, color
;
10083 sprintf (color_name
, "#%04x%04x%04x", rgb
[0], rgb
[1], rgb
[2]);
10085 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
10086 if (XLookupColor (dpy
, cmap
, color_name
, &exact
, &color
))
10089 look_at_corners_p
= 0;
10094 if (look_at_corners_p
)
10096 unsigned long corners
[4];
10099 /* Get the colors at the corners of ximg. */
10100 corners
[0] = XGetPixel (ximg
, 0, 0);
10101 corners
[1] = XGetPixel (ximg
, img
->width
- 1, 0);
10102 corners
[2] = XGetPixel (ximg
, img
->width
- 1, img
->height
- 1);
10103 corners
[3] = XGetPixel (ximg
, 0, img
->height
- 1);
10105 /* Choose the most frequently found color as background. */
10106 for (i
= best_count
= 0; i
< 4; ++i
)
10110 for (j
= n
= 0; j
< 4; ++j
)
10111 if (corners
[i
] == corners
[j
])
10114 if (n
> best_count
)
10115 bg
= corners
[i
], best_count
= n
;
10119 /* Set all bits in mask_img to 1 whose color in ximg is different
10120 from the background color bg. */
10121 for (y
= 0; y
< img
->height
; ++y
)
10122 for (x
= 0; x
< img
->width
; ++x
)
10123 XPutPixel (mask_img
, x
, y
, XGetPixel (ximg
, x
, y
) != bg
);
10125 /* Put mask_img into img->mask. */
10126 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
10127 x_destroy_x_image (mask_img
);
10128 XDestroyImage (ximg
);
10138 /***********************************************************************
10139 PBM (mono, gray, color)
10140 ***********************************************************************/
10143 static int pbm_image_p
P_ ((Lisp_Object object
));
10144 static int pbm_load
P_ ((struct frame
*f
, struct image
*img
));
10145 static int pbm_scan_number
P_ ((unsigned char **, unsigned char *));
10147 /* The symbol `pbm' identifying images of this type. */
10151 /* Indices of image specification fields in gs_format, below. */
10153 enum pbm_keyword_index
10162 PBM_HEURISTIC_MASK
,
10166 /* Vector of image_keyword structures describing the format
10167 of valid user-defined image specifications. */
10169 static struct image_keyword pbm_format
[PBM_LAST
] =
10171 {":type", IMAGE_SYMBOL_VALUE
, 1},
10172 {":file", IMAGE_STRING_VALUE
, 0},
10173 {":data", IMAGE_STRING_VALUE
, 0},
10174 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10175 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
10176 {":relief", IMAGE_INTEGER_VALUE
, 0},
10177 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10178 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10181 /* Structure describing the image type `pbm'. */
10183 static struct image_type pbm_type
=
10193 /* Return non-zero if OBJECT is a valid PBM image specification. */
10196 pbm_image_p (object
)
10197 Lisp_Object object
;
10199 struct image_keyword fmt
[PBM_LAST
];
10201 bcopy (pbm_format
, fmt
, sizeof fmt
);
10203 if (!parse_image_spec (object
, fmt
, PBM_LAST
, Qpbm
)
10204 || (fmt
[PBM_ASCENT
].count
10205 && XFASTINT (fmt
[PBM_ASCENT
].value
) > 100))
10208 /* Must specify either :data or :file. */
10209 return fmt
[PBM_DATA
].count
+ fmt
[PBM_FILE
].count
== 1;
10213 /* Scan a decimal number from *S and return it. Advance *S while
10214 reading the number. END is the end of the string. Value is -1 at
10218 pbm_scan_number (s
, end
)
10219 unsigned char **s
, *end
;
10225 /* Skip white-space. */
10226 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
10231 /* Skip comment to end of line. */
10232 while (*s
< end
&& (c
= *(*s
)++, c
!= '\n'))
10235 else if (isdigit (c
))
10237 /* Read decimal number. */
10239 while (*s
< end
&& (c
= *(*s
)++, isdigit (c
)))
10240 val
= 10 * val
+ c
- '0';
10251 /* Read FILE into memory. Value is a pointer to a buffer allocated
10252 with xmalloc holding FILE's contents. Value is null if an error
10253 occured. *SIZE is set to the size of the file. */
10256 pbm_read_file (file
, size
)
10264 if (stat (XSTRING (file
)->data
, &st
) == 0
10265 && (fp
= fopen (XSTRING (file
)->data
, "r")) != NULL
10266 && (buf
= (char *) xmalloc (st
.st_size
),
10267 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
10269 *size
= st
.st_size
;
10287 /* Load PBM image IMG for use on frame F. */
10295 int width
, height
, max_color_idx
= 0;
10297 Lisp_Object file
, specified_file
;
10298 enum {PBM_MONO
, PBM_GRAY
, PBM_COLOR
} type
;
10299 struct gcpro gcpro1
;
10300 unsigned char *contents
= NULL
;
10301 unsigned char *end
, *p
;
10304 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10308 if (STRINGP (specified_file
))
10310 file
= x_find_image_file (specified_file
);
10311 if (!STRINGP (file
))
10313 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10318 contents
= pbm_read_file (file
, &size
);
10319 if (contents
== NULL
)
10321 image_error ("Error reading `%s'", file
, Qnil
);
10327 end
= contents
+ size
;
10332 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10333 p
= XSTRING (data
)->data
;
10334 end
= p
+ STRING_BYTES (XSTRING (data
));
10337 /* Check magic number. */
10338 if (end
- p
< 2 || *p
++ != 'P')
10340 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
10350 raw_p
= 0, type
= PBM_MONO
;
10354 raw_p
= 0, type
= PBM_GRAY
;
10358 raw_p
= 0, type
= PBM_COLOR
;
10362 raw_p
= 1, type
= PBM_MONO
;
10366 raw_p
= 1, type
= PBM_GRAY
;
10370 raw_p
= 1, type
= PBM_COLOR
;
10374 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
10378 /* Read width, height, maximum color-component. Characters
10379 starting with `#' up to the end of a line are ignored. */
10380 width
= pbm_scan_number (&p
, end
);
10381 height
= pbm_scan_number (&p
, end
);
10383 if (type
!= PBM_MONO
)
10385 max_color_idx
= pbm_scan_number (&p
, end
);
10386 if (raw_p
&& max_color_idx
> 255)
10387 max_color_idx
= 255;
10392 || (type
!= PBM_MONO
&& max_color_idx
< 0))
10396 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0,
10397 &ximg
, &img
->pixmap
))
10403 /* Initialize the color hash table. */
10404 init_color_table ();
10406 if (type
== PBM_MONO
)
10410 for (y
= 0; y
< height
; ++y
)
10411 for (x
= 0; x
< width
; ++x
)
10421 g
= pbm_scan_number (&p
, end
);
10423 XPutPixel (ximg
, x
, y
, (g
10424 ? FRAME_FOREGROUND_PIXEL (f
)
10425 : FRAME_BACKGROUND_PIXEL (f
)));
10430 for (y
= 0; y
< height
; ++y
)
10431 for (x
= 0; x
< width
; ++x
)
10435 if (type
== PBM_GRAY
)
10436 r
= g
= b
= raw_p
? *p
++ : pbm_scan_number (&p
, end
);
10445 r
= pbm_scan_number (&p
, end
);
10446 g
= pbm_scan_number (&p
, end
);
10447 b
= pbm_scan_number (&p
, end
);
10450 if (r
< 0 || g
< 0 || b
< 0)
10452 xfree (ximg
->data
);
10454 XDestroyImage (ximg
);
10456 image_error ("Invalid pixel value in image `%s'",
10461 /* RGB values are now in the range 0..max_color_idx.
10462 Scale this to the range 0..0xffff supported by X. */
10463 r
= (double) r
* 65535 / max_color_idx
;
10464 g
= (double) g
* 65535 / max_color_idx
;
10465 b
= (double) b
* 65535 / max_color_idx
;
10466 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
10470 /* Store in IMG->colors the colors allocated for the image, and
10471 free the color table. */
10472 img
->colors
= colors_in_color_table (&img
->ncolors
);
10473 free_color_table ();
10475 /* Put the image into a pixmap. */
10476 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10477 x_destroy_x_image (ximg
);
10480 img
->width
= width
;
10481 img
->height
= height
;
10487 #endif /* HAVE_PBM */
10490 /***********************************************************************
10492 ***********************************************************************/
10498 /* Function prototypes. */
10500 static int png_image_p
P_ ((Lisp_Object object
));
10501 static int png_load
P_ ((struct frame
*f
, struct image
*img
));
10503 /* The symbol `png' identifying images of this type. */
10507 /* Indices of image specification fields in png_format, below. */
10509 enum png_keyword_index
10518 PNG_HEURISTIC_MASK
,
10522 /* Vector of image_keyword structures describing the format
10523 of valid user-defined image specifications. */
10525 static struct image_keyword png_format
[PNG_LAST
] =
10527 {":type", IMAGE_SYMBOL_VALUE
, 1},
10528 {":data", IMAGE_STRING_VALUE
, 0},
10529 {":file", IMAGE_STRING_VALUE
, 0},
10530 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10531 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
10532 {":relief", IMAGE_INTEGER_VALUE
, 0},
10533 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10534 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10537 /* Structure describing the image type `png'. */
10539 static struct image_type png_type
=
10549 /* Return non-zero if OBJECT is a valid PNG image specification. */
10552 png_image_p (object
)
10553 Lisp_Object object
;
10555 struct image_keyword fmt
[PNG_LAST
];
10556 bcopy (png_format
, fmt
, sizeof fmt
);
10558 if (!parse_image_spec (object
, fmt
, PNG_LAST
, Qpng
)
10559 || (fmt
[PNG_ASCENT
].count
10560 && XFASTINT (fmt
[PNG_ASCENT
].value
) > 100))
10563 /* Must specify either the :data or :file keyword. */
10564 return fmt
[PNG_FILE
].count
+ fmt
[PNG_DATA
].count
== 1;
10568 /* Error and warning handlers installed when the PNG library
10572 my_png_error (png_ptr
, msg
)
10573 png_struct
*png_ptr
;
10576 xassert (png_ptr
!= NULL
);
10577 image_error ("PNG error: %s", build_string (msg
), Qnil
);
10578 longjmp (png_ptr
->jmpbuf
, 1);
10583 my_png_warning (png_ptr
, msg
)
10584 png_struct
*png_ptr
;
10587 xassert (png_ptr
!= NULL
);
10588 image_error ("PNG warning: %s", build_string (msg
), Qnil
);
10591 /* Memory source for PNG decoding. */
10593 struct png_memory_storage
10595 unsigned char *bytes
; /* The data */
10596 size_t len
; /* How big is it? */
10597 int index
; /* Where are we? */
10601 /* Function set as reader function when reading PNG image from memory.
10602 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH
10603 bytes from the input to DATA. */
10606 png_read_from_memory (png_ptr
, data
, length
)
10607 png_structp png_ptr
;
10611 struct png_memory_storage
*tbr
10612 = (struct png_memory_storage
*) png_get_io_ptr (png_ptr
);
10614 if (length
> tbr
->len
- tbr
->index
)
10615 png_error (png_ptr
, "Read error");
10617 bcopy (tbr
->bytes
+ tbr
->index
, data
, length
);
10618 tbr
->index
= tbr
->index
+ length
;
10621 /* Load PNG image IMG for use on frame F. Value is non-zero if
10629 Lisp_Object file
, specified_file
;
10630 Lisp_Object specified_data
;
10632 XImage
*ximg
, *mask_img
= NULL
;
10633 struct gcpro gcpro1
;
10634 png_struct
*png_ptr
= NULL
;
10635 png_info
*info_ptr
= NULL
, *end_info
= NULL
;
10638 png_byte
*pixels
= NULL
;
10639 png_byte
**rows
= NULL
;
10640 png_uint_32 width
, height
;
10641 int bit_depth
, color_type
, interlace_type
;
10643 png_uint_32 row_bytes
;
10646 double screen_gamma
, image_gamma
;
10648 struct png_memory_storage tbr
; /* Data to be read */
10650 /* Find out what file to load. */
10651 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10652 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10656 if (NILP (specified_data
))
10658 file
= x_find_image_file (specified_file
);
10659 if (!STRINGP (file
))
10661 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10666 /* Open the image file. */
10667 fp
= fopen (XSTRING (file
)->data
, "rb");
10670 image_error ("Cannot open image file `%s'", file
, Qnil
);
10676 /* Check PNG signature. */
10677 if (fread (sig
, 1, sizeof sig
, fp
) != sizeof sig
10678 || !png_check_sig (sig
, sizeof sig
))
10680 image_error ("Not a PNG file:` %s'", file
, Qnil
);
10688 /* Read from memory. */
10689 tbr
.bytes
= XSTRING (specified_data
)->data
;
10690 tbr
.len
= STRING_BYTES (XSTRING (specified_data
));
10693 /* Check PNG signature. */
10694 if (tbr
.len
< sizeof sig
10695 || !png_check_sig (tbr
.bytes
, sizeof sig
))
10697 image_error ("Not a PNG image: `%s'", img
->spec
, Qnil
);
10702 /* Need to skip past the signature. */
10703 tbr
.bytes
+= sizeof (sig
);
10706 /* Initialize read and info structs for PNG lib. */
10707 png_ptr
= png_create_read_struct (PNG_LIBPNG_VER_STRING
, NULL
,
10708 my_png_error
, my_png_warning
);
10711 if (fp
) fclose (fp
);
10716 info_ptr
= png_create_info_struct (png_ptr
);
10719 png_destroy_read_struct (&png_ptr
, NULL
, NULL
);
10720 if (fp
) fclose (fp
);
10725 end_info
= png_create_info_struct (png_ptr
);
10728 png_destroy_read_struct (&png_ptr
, &info_ptr
, NULL
);
10729 if (fp
) fclose (fp
);
10734 /* Set error jump-back. We come back here when the PNG library
10735 detects an error. */
10736 if (setjmp (png_ptr
->jmpbuf
))
10740 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
10743 if (fp
) fclose (fp
);
10748 /* Read image info. */
10749 if (!NILP (specified_data
))
10750 png_set_read_fn (png_ptr
, (void *) &tbr
, png_read_from_memory
);
10752 png_init_io (png_ptr
, fp
);
10754 png_set_sig_bytes (png_ptr
, sizeof sig
);
10755 png_read_info (png_ptr
, info_ptr
);
10756 png_get_IHDR (png_ptr
, info_ptr
, &width
, &height
, &bit_depth
, &color_type
,
10757 &interlace_type
, NULL
, NULL
);
10759 /* If image contains simply transparency data, we prefer to
10760 construct a clipping mask. */
10761 if (png_get_valid (png_ptr
, info_ptr
, PNG_INFO_tRNS
))
10766 /* This function is easier to write if we only have to handle
10767 one data format: RGB or RGBA with 8 bits per channel. Let's
10768 transform other formats into that format. */
10770 /* Strip more than 8 bits per channel. */
10771 if (bit_depth
== 16)
10772 png_set_strip_16 (png_ptr
);
10774 /* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha channel
10776 png_set_expand (png_ptr
);
10778 /* Convert grayscale images to RGB. */
10779 if (color_type
== PNG_COLOR_TYPE_GRAY
10780 || color_type
== PNG_COLOR_TYPE_GRAY_ALPHA
)
10781 png_set_gray_to_rgb (png_ptr
);
10783 /* The value 2.2 is a guess for PC monitors from PNG example.c. */
10784 gamma_str
= getenv ("SCREEN_GAMMA");
10785 screen_gamma
= gamma_str
? atof (gamma_str
) : 2.2;
10787 /* Tell the PNG lib to handle gamma correction for us. */
10789 #if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
10790 if (png_get_sRGB (png_ptr
, info_ptr
, &intent
))
10791 /* There is a special chunk in the image specifying the gamma. */
10792 png_set_sRGB (png_ptr
, info_ptr
, intent
);
10795 if (png_get_gAMA (png_ptr
, info_ptr
, &image_gamma
))
10796 /* Image contains gamma information. */
10797 png_set_gamma (png_ptr
, screen_gamma
, image_gamma
);
10799 /* Use a default of 0.5 for the image gamma. */
10800 png_set_gamma (png_ptr
, screen_gamma
, 0.5);
10802 /* Handle alpha channel by combining the image with a background
10803 color. Do this only if a real alpha channel is supplied. For
10804 simple transparency, we prefer a clipping mask. */
10805 if (!transparent_p
)
10807 png_color_16
*image_background
;
10809 if (png_get_bKGD (png_ptr
, info_ptr
, &image_background
))
10810 /* Image contains a background color with which to
10811 combine the image. */
10812 png_set_background (png_ptr
, image_background
,
10813 PNG_BACKGROUND_GAMMA_FILE
, 1, 1.0);
10816 /* Image does not contain a background color with which
10817 to combine the image data via an alpha channel. Use
10818 the frame's background instead. */
10821 png_color_16 frame_background
;
10824 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
10825 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
10826 XQueryColor (FRAME_W32_DISPLAY (f
), cmap
, &color
);
10829 bzero (&frame_background
, sizeof frame_background
);
10830 frame_background
.red
= color
.red
;
10831 frame_background
.green
= color
.green
;
10832 frame_background
.blue
= color
.blue
;
10834 png_set_background (png_ptr
, &frame_background
,
10835 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
10839 /* Update info structure. */
10840 png_read_update_info (png_ptr
, info_ptr
);
10842 /* Get number of channels. Valid values are 1 for grayscale images
10843 and images with a palette, 2 for grayscale images with transparency
10844 information (alpha channel), 3 for RGB images, and 4 for RGB
10845 images with alpha channel, i.e. RGBA. If conversions above were
10846 sufficient we should only have 3 or 4 channels here. */
10847 channels
= png_get_channels (png_ptr
, info_ptr
);
10848 xassert (channels
== 3 || channels
== 4);
10850 /* Number of bytes needed for one row of the image. */
10851 row_bytes
= png_get_rowbytes (png_ptr
, info_ptr
);
10853 /* Allocate memory for the image. */
10854 pixels
= (png_byte
*) xmalloc (row_bytes
* height
* sizeof *pixels
);
10855 rows
= (png_byte
**) xmalloc (height
* sizeof *rows
);
10856 for (i
= 0; i
< height
; ++i
)
10857 rows
[i
] = pixels
+ i
* row_bytes
;
10859 /* Read the entire image. */
10860 png_read_image (png_ptr
, rows
);
10861 png_read_end (png_ptr
, info_ptr
);
10870 /* Create the X image and pixmap. */
10871 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
10878 /* Create an image and pixmap serving as mask if the PNG image
10879 contains an alpha channel. */
10882 && !x_create_x_image_and_pixmap (f
, width
, height
, 1,
10883 &mask_img
, &img
->mask
))
10885 x_destroy_x_image (ximg
);
10886 XFreePixmap (FRAME_W32_DISPLAY (f
), img
->pixmap
);
10892 /* Fill the X image and mask from PNG data. */
10893 init_color_table ();
10895 for (y
= 0; y
< height
; ++y
)
10897 png_byte
*p
= rows
[y
];
10899 for (x
= 0; x
< width
; ++x
)
10906 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
10908 /* An alpha channel, aka mask channel, associates variable
10909 transparency with an image. Where other image formats
10910 support binary transparency---fully transparent or fully
10911 opaque---PNG allows up to 254 levels of partial transparency.
10912 The PNG library implements partial transparency by combining
10913 the image with a specified background color.
10915 I'm not sure how to handle this here nicely: because the
10916 background on which the image is displayed may change, for
10917 real alpha channel support, it would be necessary to create
10918 a new image for each possible background.
10920 What I'm doing now is that a mask is created if we have
10921 boolean transparency information. Otherwise I'm using
10922 the frame's background color to combine the image with. */
10927 XPutPixel (mask_img
, x
, y
, *p
> 0);
10933 /* Remember colors allocated for this image. */
10934 img
->colors
= colors_in_color_table (&img
->ncolors
);
10935 free_color_table ();
10938 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
10942 img
->width
= width
;
10943 img
->height
= height
;
10945 /* Put the image into the pixmap, then free the X image and its buffer. */
10946 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10947 x_destroy_x_image (ximg
);
10949 /* Same for the mask. */
10952 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
10953 x_destroy_x_image (mask_img
);
10961 #endif /* HAVE_PNG != 0 */
10965 /***********************************************************************
10967 ***********************************************************************/
10971 /* Work around a warning about HAVE_STDLIB_H being redefined in
10973 #ifdef HAVE_STDLIB_H
10974 #define HAVE_STDLIB_H_1
10975 #undef HAVE_STDLIB_H
10976 #endif /* HAVE_STLIB_H */
10978 #include <jpeglib.h>
10979 #include <jerror.h>
10980 #include <setjmp.h>
10982 #ifdef HAVE_STLIB_H_1
10983 #define HAVE_STDLIB_H 1
10986 static int jpeg_image_p
P_ ((Lisp_Object object
));
10987 static int jpeg_load
P_ ((struct frame
*f
, struct image
*img
));
10989 /* The symbol `jpeg' identifying images of this type. */
10993 /* Indices of image specification fields in gs_format, below. */
10995 enum jpeg_keyword_index
11004 JPEG_HEURISTIC_MASK
,
11008 /* Vector of image_keyword structures describing the format
11009 of valid user-defined image specifications. */
11011 static struct image_keyword jpeg_format
[JPEG_LAST
] =
11013 {":type", IMAGE_SYMBOL_VALUE
, 1},
11014 {":data", IMAGE_STRING_VALUE
, 0},
11015 {":file", IMAGE_STRING_VALUE
, 0},
11016 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11017 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
11018 {":relief", IMAGE_INTEGER_VALUE
, 0},
11019 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11020 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
11023 /* Structure describing the image type `jpeg'. */
11025 static struct image_type jpeg_type
=
11035 /* Return non-zero if OBJECT is a valid JPEG image specification. */
11038 jpeg_image_p (object
)
11039 Lisp_Object object
;
11041 struct image_keyword fmt
[JPEG_LAST
];
11043 bcopy (jpeg_format
, fmt
, sizeof fmt
);
11045 if (!parse_image_spec (object
, fmt
, JPEG_LAST
, Qjpeg
)
11046 || (fmt
[JPEG_ASCENT
].count
11047 && XFASTINT (fmt
[JPEG_ASCENT
].value
) > 100))
11050 /* Must specify either the :data or :file keyword. */
11051 return fmt
[JPEG_FILE
].count
+ fmt
[JPEG_DATA
].count
== 1;
11055 struct my_jpeg_error_mgr
11057 struct jpeg_error_mgr pub
;
11058 jmp_buf setjmp_buffer
;
11062 my_error_exit (cinfo
)
11063 j_common_ptr cinfo
;
11065 struct my_jpeg_error_mgr
*mgr
= (struct my_jpeg_error_mgr
*) cinfo
->err
;
11066 longjmp (mgr
->setjmp_buffer
, 1);
11069 /* Init source method for JPEG data source manager. Called by
11070 jpeg_read_header() before any data is actually read. See
11071 libjpeg.doc from the JPEG lib distribution. */
11074 our_init_source (cinfo
)
11075 j_decompress_ptr cinfo
;
11080 /* Fill input buffer method for JPEG data source manager. Called
11081 whenever more data is needed. We read the whole image in one step,
11082 so this only adds a fake end of input marker at the end. */
11085 our_fill_input_buffer (cinfo
)
11086 j_decompress_ptr cinfo
;
11088 /* Insert a fake EOI marker. */
11089 struct jpeg_source_mgr
*src
= cinfo
->src
;
11090 static JOCTET buffer
[2];
11092 buffer
[0] = (JOCTET
) 0xFF;
11093 buffer
[1] = (JOCTET
) JPEG_EOI
;
11095 src
->next_input_byte
= buffer
;
11096 src
->bytes_in_buffer
= 2;
11101 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src
11102 is the JPEG data source manager. */
11105 our_skip_input_data (cinfo
, num_bytes
)
11106 j_decompress_ptr cinfo
;
11109 struct jpeg_source_mgr
*src
= (struct jpeg_source_mgr
*) cinfo
->src
;
11113 if (num_bytes
> src
->bytes_in_buffer
)
11114 ERREXIT (cinfo
, JERR_INPUT_EOF
);
11116 src
->bytes_in_buffer
-= num_bytes
;
11117 src
->next_input_byte
+= num_bytes
;
11122 /* Method to terminate data source. Called by
11123 jpeg_finish_decompress() after all data has been processed. */
11126 our_term_source (cinfo
)
11127 j_decompress_ptr cinfo
;
11132 /* Set up the JPEG lib for reading an image from DATA which contains
11133 LEN bytes. CINFO is the decompression info structure created for
11134 reading the image. */
11137 jpeg_memory_src (cinfo
, data
, len
)
11138 j_decompress_ptr cinfo
;
11142 struct jpeg_source_mgr
*src
;
11144 if (cinfo
->src
== NULL
)
11146 /* First time for this JPEG object? */
11147 cinfo
->src
= (struct jpeg_source_mgr
*)
11148 (*cinfo
->mem
->alloc_small
) ((j_common_ptr
) cinfo
, JPOOL_PERMANENT
,
11149 sizeof (struct jpeg_source_mgr
));
11150 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
11151 src
->next_input_byte
= data
;
11154 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
11155 src
->init_source
= our_init_source
;
11156 src
->fill_input_buffer
= our_fill_input_buffer
;
11157 src
->skip_input_data
= our_skip_input_data
;
11158 src
->resync_to_restart
= jpeg_resync_to_restart
; /* Use default method. */
11159 src
->term_source
= our_term_source
;
11160 src
->bytes_in_buffer
= len
;
11161 src
->next_input_byte
= data
;
11165 /* Load image IMG for use on frame F. Patterned after example.c
11166 from the JPEG lib. */
11173 struct jpeg_decompress_struct cinfo
;
11174 struct my_jpeg_error_mgr mgr
;
11175 Lisp_Object file
, specified_file
;
11176 Lisp_Object specified_data
;
11179 int row_stride
, x
, y
;
11180 XImage
*ximg
= NULL
;
11182 unsigned long *colors
;
11184 struct gcpro gcpro1
;
11186 /* Open the JPEG file. */
11187 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11188 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11192 if (NILP (specified_data
))
11194 file
= x_find_image_file (specified_file
);
11195 if (!STRINGP (file
))
11197 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
11202 fp
= fopen (XSTRING (file
)->data
, "r");
11205 image_error ("Cannot open `%s'", file
, Qnil
);
11211 /* Customize libjpeg's error handling to call my_error_exit when an
11212 error is detected. This function will perform a longjmp. */
11213 mgr
.pub
.error_exit
= my_error_exit
;
11214 cinfo
.err
= jpeg_std_error (&mgr
.pub
);
11216 if ((rc
= setjmp (mgr
.setjmp_buffer
)) != 0)
11220 /* Called from my_error_exit. Display a JPEG error. */
11221 char buffer
[JMSG_LENGTH_MAX
];
11222 cinfo
.err
->format_message ((j_common_ptr
) &cinfo
, buffer
);
11223 image_error ("Error reading JPEG image `%s': %s", img
->spec
,
11224 build_string (buffer
));
11227 /* Close the input file and destroy the JPEG object. */
11230 jpeg_destroy_decompress (&cinfo
);
11234 /* If we already have an XImage, free that. */
11235 x_destroy_x_image (ximg
);
11237 /* Free pixmap and colors. */
11238 x_clear_image (f
, img
);
11245 /* Create the JPEG decompression object. Let it read from fp.
11246 Read the JPEG image header. */
11247 jpeg_create_decompress (&cinfo
);
11249 if (NILP (specified_data
))
11250 jpeg_stdio_src (&cinfo
, fp
);
11252 jpeg_memory_src (&cinfo
, XSTRING (specified_data
)->data
,
11253 STRING_BYTES (XSTRING (specified_data
)));
11255 jpeg_read_header (&cinfo
, TRUE
);
11257 /* Customize decompression so that color quantization will be used.
11258 Start decompression. */
11259 cinfo
.quantize_colors
= TRUE
;
11260 jpeg_start_decompress (&cinfo
);
11261 width
= img
->width
= cinfo
.output_width
;
11262 height
= img
->height
= cinfo
.output_height
;
11266 /* Create X image and pixmap. */
11267 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
11271 longjmp (mgr
.setjmp_buffer
, 2);
11274 /* Allocate colors. When color quantization is used,
11275 cinfo.actual_number_of_colors has been set with the number of
11276 colors generated, and cinfo.colormap is a two-dimensional array
11277 of color indices in the range 0..cinfo.actual_number_of_colors.
11278 No more than 255 colors will be generated. */
11282 if (cinfo
.out_color_components
> 2)
11283 ir
= 0, ig
= 1, ib
= 2;
11284 else if (cinfo
.out_color_components
> 1)
11285 ir
= 0, ig
= 1, ib
= 0;
11287 ir
= 0, ig
= 0, ib
= 0;
11289 /* Use the color table mechanism because it handles colors that
11290 cannot be allocated nicely. Such colors will be replaced with
11291 a default color, and we don't have to care about which colors
11292 can be freed safely, and which can't. */
11293 init_color_table ();
11294 colors
= (unsigned long *) alloca (cinfo
.actual_number_of_colors
11297 for (i
= 0; i
< cinfo
.actual_number_of_colors
; ++i
)
11299 /* Multiply RGB values with 255 because X expects RGB values
11300 in the range 0..0xffff. */
11301 int r
= cinfo
.colormap
[ir
][i
] << 8;
11302 int g
= cinfo
.colormap
[ig
][i
] << 8;
11303 int b
= cinfo
.colormap
[ib
][i
] << 8;
11304 colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
11307 /* Remember those colors actually allocated. */
11308 img
->colors
= colors_in_color_table (&img
->ncolors
);
11309 free_color_table ();
11313 row_stride
= width
* cinfo
.output_components
;
11314 buffer
= cinfo
.mem
->alloc_sarray ((j_common_ptr
) &cinfo
, JPOOL_IMAGE
,
11316 for (y
= 0; y
< height
; ++y
)
11318 jpeg_read_scanlines (&cinfo
, buffer
, 1);
11319 for (x
= 0; x
< cinfo
.output_width
; ++x
)
11320 XPutPixel (ximg
, x
, y
, colors
[buffer
[0][x
]]);
11324 jpeg_finish_decompress (&cinfo
);
11325 jpeg_destroy_decompress (&cinfo
);
11329 /* Put the image into the pixmap. */
11330 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11331 x_destroy_x_image (ximg
);
11337 #endif /* HAVE_JPEG */
11341 /***********************************************************************
11343 ***********************************************************************/
11347 #include <tiffio.h>
11349 static int tiff_image_p
P_ ((Lisp_Object object
));
11350 static int tiff_load
P_ ((struct frame
*f
, struct image
*img
));
11352 /* The symbol `tiff' identifying images of this type. */
11356 /* Indices of image specification fields in tiff_format, below. */
11358 enum tiff_keyword_index
11367 TIFF_HEURISTIC_MASK
,
11371 /* Vector of image_keyword structures describing the format
11372 of valid user-defined image specifications. */
11374 static struct image_keyword tiff_format
[TIFF_LAST
] =
11376 {":type", IMAGE_SYMBOL_VALUE
, 1},
11377 {":data", IMAGE_STRING_VALUE
, 0},
11378 {":file", IMAGE_STRING_VALUE
, 0},
11379 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11380 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
11381 {":relief", IMAGE_INTEGER_VALUE
, 0},
11382 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11383 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
11386 /* Structure describing the image type `tiff'. */
11388 static struct image_type tiff_type
=
11398 /* Return non-zero if OBJECT is a valid TIFF image specification. */
11401 tiff_image_p (object
)
11402 Lisp_Object object
;
11404 struct image_keyword fmt
[TIFF_LAST
];
11405 bcopy (tiff_format
, fmt
, sizeof fmt
);
11407 if (!parse_image_spec (object
, fmt
, TIFF_LAST
, Qtiff
)
11408 || (fmt
[TIFF_ASCENT
].count
11409 && XFASTINT (fmt
[TIFF_ASCENT
].value
) > 100))
11412 /* Must specify either the :data or :file keyword. */
11413 return fmt
[TIFF_FILE
].count
+ fmt
[TIFF_DATA
].count
== 1;
11417 /* Reading from a memory buffer for TIFF images Based on the PNG
11418 memory source, but we have to provide a lot of extra functions.
11421 We really only need to implement read and seek, but I am not
11422 convinced that the TIFF library is smart enough not to destroy
11423 itself if we only hand it the function pointers we need to
11428 unsigned char *bytes
;
11432 tiff_memory_source
;
11435 tiff_read_from_memory (data
, buf
, size
)
11440 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
11442 if (size
> src
->len
- src
->index
)
11443 return (size_t) -1;
11444 bcopy (src
->bytes
+ src
->index
, buf
, size
);
11445 src
->index
+= size
;
11450 tiff_write_from_memory (data
, buf
, size
)
11455 return (size_t) -1;
11459 tiff_seek_in_memory (data
, off
, whence
)
11464 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
11469 case SEEK_SET
: /* Go from beginning of source. */
11473 case SEEK_END
: /* Go from end of source. */
11474 idx
= src
->len
+ off
;
11477 case SEEK_CUR
: /* Go from current position. */
11478 idx
= src
->index
+ off
;
11481 default: /* Invalid `whence'. */
11485 if (idx
> src
->len
|| idx
< 0)
11493 tiff_close_memory (data
)
11501 tiff_mmap_memory (data
, pbase
, psize
)
11506 /* It is already _IN_ memory. */
11511 tiff_unmap_memory (data
, base
, size
)
11516 /* We don't need to do this. */
11520 tiff_size_of_memory (data
)
11523 return ((tiff_memory_source
*) data
)->len
;
11526 /* Load TIFF image IMG for use on frame F. Value is non-zero if
11534 Lisp_Object file
, specified_file
;
11535 Lisp_Object specified_data
;
11537 int width
, height
, x
, y
;
11541 struct gcpro gcpro1
;
11542 tiff_memory_source memsrc
;
11544 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11545 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11549 if (NILP (specified_data
))
11551 /* Read from a file */
11552 file
= x_find_image_file (specified_file
);
11553 if (!STRINGP (file
))
11555 image_error ("Cannot find image file `%s'", file
, Qnil
);
11560 /* Try to open the image file. */
11561 tiff
= TIFFOpen (XSTRING (file
)->data
, "r");
11564 image_error ("Cannot open `%s'", file
, Qnil
);
11571 /* Memory source! */
11572 memsrc
.bytes
= XSTRING (specified_data
)->data
;
11573 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
11576 tiff
= TIFFClientOpen ("memory_source", "r", &memsrc
,
11577 (TIFFReadWriteProc
) tiff_read_from_memory
,
11578 (TIFFReadWriteProc
) tiff_write_from_memory
,
11579 tiff_seek_in_memory
,
11581 tiff_size_of_memory
,
11583 tiff_unmap_memory
);
11587 image_error ("Cannot open memory source for `%s'", img
->spec
, Qnil
);
11593 /* Get width and height of the image, and allocate a raster buffer
11594 of width x height 32-bit values. */
11595 TIFFGetField (tiff
, TIFFTAG_IMAGEWIDTH
, &width
);
11596 TIFFGetField (tiff
, TIFFTAG_IMAGELENGTH
, &height
);
11597 buf
= (uint32
*) xmalloc (width
* height
* sizeof *buf
);
11599 rc
= TIFFReadRGBAImage (tiff
, width
, height
, buf
, 0);
11603 image_error ("Error reading TIFF image `%s'", img
->spec
, Qnil
);
11611 /* Create the X image and pixmap. */
11612 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11620 /* Initialize the color table. */
11621 init_color_table ();
11623 /* Process the pixel raster. Origin is in the lower-left corner. */
11624 for (y
= 0; y
< height
; ++y
)
11626 uint32
*row
= buf
+ y
* width
;
11628 for (x
= 0; x
< width
; ++x
)
11630 uint32 abgr
= row
[x
];
11631 int r
= TIFFGetR (abgr
) << 8;
11632 int g
= TIFFGetG (abgr
) << 8;
11633 int b
= TIFFGetB (abgr
) << 8;
11634 XPutPixel (ximg
, x
, height
- 1 - y
, lookup_rgb_color (f
, r
, g
, b
));
11638 /* Remember the colors allocated for the image. Free the color table. */
11639 img
->colors
= colors_in_color_table (&img
->ncolors
);
11640 free_color_table ();
11642 /* Put the image into the pixmap, then free the X image and its buffer. */
11643 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11644 x_destroy_x_image (ximg
);
11648 img
->width
= width
;
11649 img
->height
= height
;
11655 #endif /* HAVE_TIFF != 0 */
11659 /***********************************************************************
11661 ***********************************************************************/
11665 #include <gif_lib.h>
11667 static int gif_image_p
P_ ((Lisp_Object object
));
11668 static int gif_load
P_ ((struct frame
*f
, struct image
*img
));
11670 /* The symbol `gif' identifying images of this type. */
11674 /* Indices of image specification fields in gif_format, below. */
11676 enum gif_keyword_index
11685 GIF_HEURISTIC_MASK
,
11690 /* Vector of image_keyword structures describing the format
11691 of valid user-defined image specifications. */
11693 static struct image_keyword gif_format
[GIF_LAST
] =
11695 {":type", IMAGE_SYMBOL_VALUE
, 1},
11696 {":data", IMAGE_STRING_VALUE
, 0},
11697 {":file", IMAGE_STRING_VALUE
, 0},
11698 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11699 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
11700 {":relief", IMAGE_INTEGER_VALUE
, 0},
11701 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11702 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11703 {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0}
11706 /* Structure describing the image type `gif'. */
11708 static struct image_type gif_type
=
11717 /* Return non-zero if OBJECT is a valid GIF image specification. */
11720 gif_image_p (object
)
11721 Lisp_Object object
;
11723 struct image_keyword fmt
[GIF_LAST
];
11724 bcopy (gif_format
, fmt
, sizeof fmt
);
11726 if (!parse_image_spec (object
, fmt
, GIF_LAST
, Qgif
)
11727 || (fmt
[GIF_ASCENT
].count
11728 && XFASTINT (fmt
[GIF_ASCENT
].value
) > 100))
11731 /* Must specify either the :data or :file keyword. */
11732 return fmt
[GIF_FILE
].count
+ fmt
[GIF_DATA
].count
== 1;
11735 /* Reading a GIF image from memory
11736 Based on the PNG memory stuff to a certain extent. */
11740 unsigned char *bytes
;
11746 /* Make the current memory source available to gif_read_from_memory.
11747 It's done this way because not all versions of libungif support
11748 a UserData field in the GifFileType structure. */
11749 static gif_memory_source
*current_gif_memory_src
;
11752 gif_read_from_memory (file
, buf
, len
)
11757 gif_memory_source
*src
= current_gif_memory_src
;
11759 if (len
> src
->len
- src
->index
)
11762 bcopy (src
->bytes
+ src
->index
, buf
, len
);
11768 /* Load GIF image IMG for use on frame F. Value is non-zero if
11776 Lisp_Object file
, specified_file
;
11777 Lisp_Object specified_data
;
11778 int rc
, width
, height
, x
, y
, i
;
11780 ColorMapObject
*gif_color_map
;
11781 unsigned long pixel_colors
[256];
11783 struct gcpro gcpro1
;
11785 int ino
, image_left
, image_top
, image_width
, image_height
;
11786 gif_memory_source memsrc
;
11787 unsigned char *raster
;
11789 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11790 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11794 if (NILP (specified_data
))
11796 file
= x_find_image_file (specified_file
);
11797 if (!STRINGP (file
))
11799 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
11804 /* Open the GIF file. */
11805 gif
= DGifOpenFileName (XSTRING (file
)->data
);
11808 image_error ("Cannot open `%s'", file
, Qnil
);
11815 /* Read from memory! */
11816 current_gif_memory_src
= &memsrc
;
11817 memsrc
.bytes
= XSTRING (specified_data
)->data
;
11818 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
11821 gif
= DGifOpen(&memsrc
, gif_read_from_memory
);
11824 image_error ("Cannot open memory source `%s'", img
->spec
, Qnil
);
11830 /* Read entire contents. */
11831 rc
= DGifSlurp (gif
);
11832 if (rc
== GIF_ERROR
)
11834 image_error ("Error reading `%s'", img
->spec
, Qnil
);
11835 DGifCloseFile (gif
);
11840 image
= image_spec_value (img
->spec
, QCindex
, NULL
);
11841 ino
= INTEGERP (image
) ? XFASTINT (image
) : 0;
11842 if (ino
>= gif
->ImageCount
)
11844 image_error ("Invalid image number `%s' in image `%s'",
11846 DGifCloseFile (gif
);
11851 width
= img
->width
= gif
->SWidth
;
11852 height
= img
->height
= gif
->SHeight
;
11856 /* Create the X image and pixmap. */
11857 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11860 DGifCloseFile (gif
);
11865 /* Allocate colors. */
11866 gif_color_map
= gif
->SavedImages
[ino
].ImageDesc
.ColorMap
;
11867 if (!gif_color_map
)
11868 gif_color_map
= gif
->SColorMap
;
11869 init_color_table ();
11870 bzero (pixel_colors
, sizeof pixel_colors
);
11872 for (i
= 0; i
< gif_color_map
->ColorCount
; ++i
)
11874 int r
= gif_color_map
->Colors
[i
].Red
<< 8;
11875 int g
= gif_color_map
->Colors
[i
].Green
<< 8;
11876 int b
= gif_color_map
->Colors
[i
].Blue
<< 8;
11877 pixel_colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
11880 img
->colors
= colors_in_color_table (&img
->ncolors
);
11881 free_color_table ();
11883 /* Clear the part of the screen image that are not covered by
11884 the image from the GIF file. Full animated GIF support
11885 requires more than can be done here (see the gif89 spec,
11886 disposal methods). Let's simply assume that the part
11887 not covered by a sub-image is in the frame's background color. */
11888 image_top
= gif
->SavedImages
[ino
].ImageDesc
.Top
;
11889 image_left
= gif
->SavedImages
[ino
].ImageDesc
.Left
;
11890 image_width
= gif
->SavedImages
[ino
].ImageDesc
.Width
;
11891 image_height
= gif
->SavedImages
[ino
].ImageDesc
.Height
;
11893 for (y
= 0; y
< image_top
; ++y
)
11894 for (x
= 0; x
< width
; ++x
)
11895 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11897 for (y
= image_top
+ image_height
; y
< height
; ++y
)
11898 for (x
= 0; x
< width
; ++x
)
11899 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11901 for (y
= image_top
; y
< image_top
+ image_height
; ++y
)
11903 for (x
= 0; x
< image_left
; ++x
)
11904 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11905 for (x
= image_left
+ image_width
; x
< width
; ++x
)
11906 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11909 /* Read the GIF image into the X image. We use a local variable
11910 `raster' here because RasterBits below is a char *, and invites
11911 problems with bytes >= 0x80. */
11912 raster
= (unsigned char *) gif
->SavedImages
[ino
].RasterBits
;
11914 if (gif
->SavedImages
[ino
].ImageDesc
.Interlace
)
11916 static int interlace_start
[] = {0, 4, 2, 1};
11917 static int interlace_increment
[] = {8, 8, 4, 2};
11919 int row
= interlace_start
[0];
11923 for (y
= 0; y
< image_height
; y
++)
11925 if (row
>= image_height
)
11927 row
= interlace_start
[++pass
];
11928 while (row
>= image_height
)
11929 row
= interlace_start
[++pass
];
11932 for (x
= 0; x
< image_width
; x
++)
11934 int i
= raster
[(y
* image_width
) + x
];
11935 XPutPixel (ximg
, x
+ image_left
, row
+ image_top
,
11939 row
+= interlace_increment
[pass
];
11944 for (y
= 0; y
< image_height
; ++y
)
11945 for (x
= 0; x
< image_width
; ++x
)
11947 int i
= raster
[y
* image_width
+ x
];
11948 XPutPixel (ximg
, x
+ image_left
, y
+ image_top
, pixel_colors
[i
]);
11952 DGifCloseFile (gif
);
11954 /* Put the image into the pixmap, then free the X image and its buffer. */
11955 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11956 x_destroy_x_image (ximg
);
11963 #endif /* HAVE_GIF != 0 */
11967 /***********************************************************************
11969 ***********************************************************************/
11971 #ifdef HAVE_GHOSTSCRIPT
11972 static int gs_image_p
P_ ((Lisp_Object object
));
11973 static int gs_load
P_ ((struct frame
*f
, struct image
*img
));
11974 static void gs_clear_image
P_ ((struct frame
*f
, struct image
*img
));
11976 /* The symbol `postscript' identifying images of this type. */
11978 Lisp_Object Qpostscript
;
11980 /* Keyword symbols. */
11982 Lisp_Object QCloader
, QCbounding_box
, QCpt_width
, QCpt_height
;
11984 /* Indices of image specification fields in gs_format, below. */
11986 enum gs_keyword_index
12002 /* Vector of image_keyword structures describing the format
12003 of valid user-defined image specifications. */
12005 static struct image_keyword gs_format
[GS_LAST
] =
12007 {":type", IMAGE_SYMBOL_VALUE
, 1},
12008 {":pt-width", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
12009 {":pt-height", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
12010 {":file", IMAGE_STRING_VALUE
, 1},
12011 {":loader", IMAGE_FUNCTION_VALUE
, 0},
12012 {":bounding-box", IMAGE_DONT_CHECK_VALUE_TYPE
, 1},
12013 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
12014 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
12015 {":relief", IMAGE_INTEGER_VALUE
, 0},
12016 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12017 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
12020 /* Structure describing the image type `ghostscript'. */
12022 static struct image_type gs_type
=
12032 /* Free X resources of Ghostscript image IMG which is used on frame F. */
12035 gs_clear_image (f
, img
)
12039 /* IMG->data.ptr_val may contain a recorded colormap. */
12040 xfree (img
->data
.ptr_val
);
12041 x_clear_image (f
, img
);
12045 /* Return non-zero if OBJECT is a valid Ghostscript image
12049 gs_image_p (object
)
12050 Lisp_Object object
;
12052 struct image_keyword fmt
[GS_LAST
];
12056 bcopy (gs_format
, fmt
, sizeof fmt
);
12058 if (!parse_image_spec (object
, fmt
, GS_LAST
, Qpostscript
)
12059 || (fmt
[GS_ASCENT
].count
12060 && XFASTINT (fmt
[GS_ASCENT
].value
) > 100))
12063 /* Bounding box must be a list or vector containing 4 integers. */
12064 tem
= fmt
[GS_BOUNDING_BOX
].value
;
12067 for (i
= 0; i
< 4; ++i
, tem
= XCDR (tem
))
12068 if (!CONSP (tem
) || !INTEGERP (XCAR (tem
)))
12073 else if (VECTORP (tem
))
12075 if (XVECTOR (tem
)->size
!= 4)
12077 for (i
= 0; i
< 4; ++i
)
12078 if (!INTEGERP (XVECTOR (tem
)->contents
[i
]))
12088 /* Load Ghostscript image IMG for use on frame F. Value is non-zero
12097 Lisp_Object window_and_pixmap_id
= Qnil
, loader
, pt_height
, pt_width
;
12098 struct gcpro gcpro1
, gcpro2
;
12100 double in_width
, in_height
;
12101 Lisp_Object pixel_colors
= Qnil
;
12103 /* Compute pixel size of pixmap needed from the given size in the
12104 image specification. Sizes in the specification are in pt. 1 pt
12105 = 1/72 in, xdpi and ydpi are stored in the frame's X display
12107 pt_width
= image_spec_value (img
->spec
, QCpt_width
, NULL
);
12108 in_width
= XFASTINT (pt_width
) / 72.0;
12109 img
->width
= in_width
* FRAME_W32_DISPLAY_INFO (f
)->resx
;
12110 pt_height
= image_spec_value (img
->spec
, QCpt_height
, NULL
);
12111 in_height
= XFASTINT (pt_height
) / 72.0;
12112 img
->height
= in_height
* FRAME_W32_DISPLAY_INFO (f
)->resy
;
12114 /* Create the pixmap. */
12116 xassert (img
->pixmap
== 0);
12117 img
->pixmap
= XCreatePixmap (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
12118 img
->width
, img
->height
,
12119 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)));
12124 image_error ("Unable to create pixmap for `%s'", img
->spec
, Qnil
);
12128 /* Call the loader to fill the pixmap. It returns a process object
12129 if successful. We do not record_unwind_protect here because
12130 other places in redisplay like calling window scroll functions
12131 don't either. Let the Lisp loader use `unwind-protect' instead. */
12132 GCPRO2 (window_and_pixmap_id
, pixel_colors
);
12134 sprintf (buffer
, "%lu %lu",
12135 (unsigned long) FRAME_W32_WINDOW (f
),
12136 (unsigned long) img
->pixmap
);
12137 window_and_pixmap_id
= build_string (buffer
);
12139 sprintf (buffer
, "%lu %lu",
12140 FRAME_FOREGROUND_PIXEL (f
),
12141 FRAME_BACKGROUND_PIXEL (f
));
12142 pixel_colors
= build_string (buffer
);
12144 XSETFRAME (frame
, f
);
12145 loader
= image_spec_value (img
->spec
, QCloader
, NULL
);
12147 loader
= intern ("gs-load-image");
12149 img
->data
.lisp_val
= call6 (loader
, frame
, img
->spec
,
12150 make_number (img
->width
),
12151 make_number (img
->height
),
12152 window_and_pixmap_id
,
12155 return PROCESSP (img
->data
.lisp_val
);
12159 /* Kill the Ghostscript process that was started to fill PIXMAP on
12160 frame F. Called from XTread_socket when receiving an event
12161 telling Emacs that Ghostscript has finished drawing. */
12164 x_kill_gs_process (pixmap
, f
)
12168 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
12172 /* Find the image containing PIXMAP. */
12173 for (i
= 0; i
< c
->used
; ++i
)
12174 if (c
->images
[i
]->pixmap
== pixmap
)
12177 /* Kill the GS process. We should have found PIXMAP in the image
12178 cache and its image should contain a process object. */
12179 xassert (i
< c
->used
);
12180 img
= c
->images
[i
];
12181 xassert (PROCESSP (img
->data
.lisp_val
));
12182 Fkill_process (img
->data
.lisp_val
, Qnil
);
12183 img
->data
.lisp_val
= Qnil
;
12185 /* On displays with a mutable colormap, figure out the colors
12186 allocated for the image by looking at the pixels of an XImage for
12188 class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
12189 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
12195 /* Try to get an XImage for img->pixmep. */
12196 ximg
= XGetImage (FRAME_W32_DISPLAY (f
), img
->pixmap
,
12197 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
12202 /* Initialize the color table. */
12203 init_color_table ();
12205 /* For each pixel of the image, look its color up in the
12206 color table. After having done so, the color table will
12207 contain an entry for each color used by the image. */
12208 for (y
= 0; y
< img
->height
; ++y
)
12209 for (x
= 0; x
< img
->width
; ++x
)
12211 unsigned long pixel
= XGetPixel (ximg
, x
, y
);
12212 lookup_pixel_color (f
, pixel
);
12215 /* Record colors in the image. Free color table and XImage. */
12216 img
->colors
= colors_in_color_table (&img
->ncolors
);
12217 free_color_table ();
12218 XDestroyImage (ximg
);
12220 #if 0 /* This doesn't seem to be the case. If we free the colors
12221 here, we get a BadAccess later in x_clear_image when
12222 freeing the colors. */
12223 /* We have allocated colors once, but Ghostscript has also
12224 allocated colors on behalf of us. So, to get the
12225 reference counts right, free them once. */
12228 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
12229 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
,
12230 img
->colors
, img
->ncolors
, 0);
12235 image_error ("Cannot get X image of `%s'; colors will not be freed",
12242 #endif /* HAVE_GHOSTSCRIPT */
12245 /***********************************************************************
12247 ***********************************************************************/
12249 DEFUN ("x-change-window-property", Fx_change_window_property
,
12250 Sx_change_window_property
, 2, 3, 0,
12251 "Change window property PROP to VALUE on the X window of FRAME.\n\
12252 PROP and VALUE must be strings. FRAME nil or omitted means use the\n\
12253 selected frame. Value is VALUE.")
12254 (prop
, value
, frame
)
12255 Lisp_Object frame
, prop
, value
;
12257 #if 0 /* TODO : port window properties to W32 */
12258 struct frame
*f
= check_x_frame (frame
);
12261 CHECK_STRING (prop
, 1);
12262 CHECK_STRING (value
, 2);
12265 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
12266 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
12267 prop_atom
, XA_STRING
, 8, PropModeReplace
,
12268 XSTRING (value
)->data
, XSTRING (value
)->size
);
12270 /* Make sure the property is set when we return. */
12271 XFlush (FRAME_W32_DISPLAY (f
));
12280 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
12281 Sx_delete_window_property
, 1, 2, 0,
12282 "Remove window property PROP from X window of FRAME.\n\
12283 FRAME nil or omitted means use the selected frame. Value is PROP.")
12285 Lisp_Object prop
, frame
;
12287 #if 0 /* TODO : port window properties to W32 */
12289 struct frame
*f
= check_x_frame (frame
);
12292 CHECK_STRING (prop
, 1);
12294 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
12295 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
12297 /* Make sure the property is removed when we return. */
12298 XFlush (FRAME_W32_DISPLAY (f
));
12306 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
12308 "Value is the value of window property PROP on FRAME.\n\
12309 If FRAME is nil or omitted, use the selected frame. Value is nil\n\
12310 if FRAME hasn't a property with name PROP or if PROP has no string\n\
12313 Lisp_Object prop
, frame
;
12315 #if 0 /* TODO : port window properties to W32 */
12317 struct frame
*f
= check_x_frame (frame
);
12320 Lisp_Object prop_value
= Qnil
;
12321 char *tmp_data
= NULL
;
12324 unsigned long actual_size
, bytes_remaining
;
12326 CHECK_STRING (prop
, 1);
12328 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
12329 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
12330 prop_atom
, 0, 0, False
, XA_STRING
,
12331 &actual_type
, &actual_format
, &actual_size
,
12332 &bytes_remaining
, (unsigned char **) &tmp_data
);
12335 int size
= bytes_remaining
;
12340 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
12341 prop_atom
, 0, bytes_remaining
,
12343 &actual_type
, &actual_format
,
12344 &actual_size
, &bytes_remaining
,
12345 (unsigned char **) &tmp_data
);
12347 prop_value
= make_string (tmp_data
, size
);
12362 /***********************************************************************
12364 ***********************************************************************/
12366 /* If non-null, an asynchronous timer that, when it expires, displays
12367 an hourglass cursor on all frames. */
12369 static struct atimer
*hourglass_atimer
;
12371 /* Non-zero means an hourglass cursor is currently shown. */
12373 static int hourglass_shown_p
;
12375 /* Number of seconds to wait before displaying an hourglass cursor. */
12377 static Lisp_Object Vhourglass_delay
;
12379 /* Default number of seconds to wait before displaying an hourglass
12382 #define DEFAULT_HOURGLASS_DELAY 1
12384 /* Function prototypes. */
12386 static void show_hourglass
P_ ((struct atimer
*));
12387 static void hide_hourglass
P_ ((void));
12390 /* Cancel a currently active hourglass timer, and start a new one. */
12395 #if 0 /* TODO: cursor shape changes. */
12397 int secs
, usecs
= 0;
12399 cancel_hourglass ();
12401 if (INTEGERP (Vhourglass_delay
)
12402 && XINT (Vhourglass_delay
) > 0)
12403 secs
= XFASTINT (Vhourglass_delay
);
12404 else if (FLOATP (Vhourglass_delay
)
12405 && XFLOAT_DATA (Vhourglass_delay
) > 0)
12408 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
12409 secs
= XFASTINT (tem
);
12410 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
12413 secs
= DEFAULT_HOURGLASS_DELAY
;
12415 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
12416 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
12417 show_hourglass
, NULL
);
12422 /* Cancel the hourglass cursor timer if active, hide an hourglass
12423 cursor if shown. */
12426 cancel_hourglass ()
12428 if (hourglass_atimer
)
12430 cancel_atimer (hourglass_atimer
);
12431 hourglass_atimer
= NULL
;
12434 if (hourglass_shown_p
)
12439 /* Timer function of hourglass_atimer. TIMER is equal to
12442 Display an hourglass cursor on all frames by mapping the frames'
12443 hourglass_window. Set the hourglass_p flag in the frames'
12444 output_data.x structure to indicate that an hourglass cursor is
12445 shown on the frames. */
12448 show_hourglass (timer
)
12449 struct atimer
*timer
;
12451 #if 0 /* TODO: cursor shape changes. */
12452 /* The timer implementation will cancel this timer automatically
12453 after this function has run. Set hourglass_atimer to null
12454 so that we know the timer doesn't have to be canceled. */
12455 hourglass_atimer
= NULL
;
12457 if (!hourglass_shown_p
)
12459 Lisp_Object rest
, frame
;
12463 FOR_EACH_FRAME (rest
, frame
)
12464 if (FRAME_W32_P (XFRAME (frame
)))
12466 struct frame
*f
= XFRAME (frame
);
12468 f
->output_data
.w32
->hourglass_p
= 1;
12470 if (!f
->output_data
.w32
->hourglass_window
)
12472 unsigned long mask
= CWCursor
;
12473 XSetWindowAttributes attrs
;
12475 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
12477 f
->output_data
.w32
->hourglass_window
12478 = XCreateWindow (FRAME_X_DISPLAY (f
),
12479 FRAME_OUTER_WINDOW (f
),
12480 0, 0, 32000, 32000, 0, 0,
12486 XMapRaised (FRAME_X_DISPLAY (f
),
12487 f
->output_data
.w32
->hourglass_window
);
12488 XFlush (FRAME_X_DISPLAY (f
));
12491 hourglass_shown_p
= 1;
12498 /* Hide the hourglass cursor on all frames, if it is currently shown. */
12503 #if 0 /* TODO: cursor shape changes. */
12504 if (hourglass_shown_p
)
12506 Lisp_Object rest
, frame
;
12509 FOR_EACH_FRAME (rest
, frame
)
12511 struct frame
*f
= XFRAME (frame
);
12513 if (FRAME_W32_P (f
)
12514 /* Watch out for newly created frames. */
12515 && f
->output_data
.x
->hourglass_window
)
12517 XUnmapWindow (FRAME_X_DISPLAY (f
),
12518 f
->output_data
.x
->hourglass_window
);
12519 /* Sync here because XTread_socket looks at the
12520 hourglass_p flag that is reset to zero below. */
12521 XSync (FRAME_X_DISPLAY (f
), False
);
12522 f
->output_data
.x
->hourglass_p
= 0;
12526 hourglass_shown_p
= 0;
12534 /***********************************************************************
12536 ***********************************************************************/
12538 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
12541 /* The frame of a currently visible tooltip, or null. */
12543 Lisp_Object tip_frame
;
12545 /* If non-nil, a timer started that hides the last tooltip when it
12548 Lisp_Object tip_timer
;
12552 unwind_create_tip_frame (frame
)
12555 Lisp_Object deleted
;
12557 deleted
= unwind_create_frame (frame
);
12558 if (EQ (deleted
, Qt
))
12568 /* Create a frame for a tooltip on the display described by DPYINFO.
12569 PARMS is a list of frame parameters. Value is the frame.
12571 Note that functions called here, esp. x_default_parameter can
12572 signal errors, for instance when a specified color name is
12573 undefined. We have to make sure that we're in a consistent state
12574 when this happens. */
12577 x_create_tip_frame (dpyinfo
, parms
)
12578 struct w32_display_info
*dpyinfo
;
12581 #if 0 /* TODO : w32 version */
12583 Lisp_Object frame
, tem
;
12585 long window_prompting
= 0;
12587 int count
= BINDING_STACK_SIZE ();
12588 struct gcpro gcpro1
, gcpro2
, gcpro3
;
12593 /* Use this general default value to start with until we know if
12594 this frame has a specified name. */
12595 Vx_resource_name
= Vinvocation_name
;
12597 #ifdef MULTI_KBOARD
12598 kb
= dpyinfo
->kboard
;
12600 kb
= &the_only_kboard
;
12603 /* Get the name of the frame to use for resource lookup. */
12604 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
12605 if (!STRINGP (name
)
12606 && !EQ (name
, Qunbound
)
12608 error ("Invalid frame name--not a string or nil");
12609 Vx_resource_name
= name
;
12612 GCPRO3 (parms
, name
, frame
);
12613 f
= make_frame (1);
12614 XSETFRAME (frame
, f
);
12615 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
12616 record_unwind_protect (unwind_create_tip_frame
, frame
);
12618 f
->output_method
= output_w32
;
12619 f
->output_data
.w32
=
12620 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
12621 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
12623 f
->output_data
.w32
->icon_bitmap
= -1;
12625 f
->output_data
.w32
->fontset
= -1;
12626 f
->icon_name
= Qnil
;
12629 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
12630 dpyinfo_refcount
= dpyinfo
->reference_count
;
12631 #endif /* GLYPH_DEBUG */
12632 #ifdef MULTI_KBOARD
12633 FRAME_KBOARD (f
) = kb
;
12635 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
12636 f
->output_data
.w32
->explicit_parent
= 0;
12638 /* Set the name; the functions to which we pass f expect the name to
12640 if (EQ (name
, Qunbound
) || NILP (name
))
12642 f
->name
= build_string (dpyinfo
->x_id_name
);
12643 f
->explicit_name
= 0;
12648 f
->explicit_name
= 1;
12649 /* use the frame's title when getting resources for this frame. */
12650 specbind (Qx_resource_name
, name
);
12653 /* Extract the window parameters from the supplied values
12654 that are needed to determine window geometry. */
12658 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
12661 /* First, try whatever font the caller has specified. */
12662 if (STRINGP (font
))
12664 tem
= Fquery_fontset (font
, Qnil
);
12666 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
12668 font
= x_new_font (f
, XSTRING (font
)->data
);
12671 /* Try out a font which we hope has bold and italic variations. */
12672 if (!STRINGP (font
))
12673 font
= x_new_font (f
, "-*-courier new-normal-r-*-*-*-100-*-*-*-*-iso8859-1");
12674 if (!STRINGP (font
))
12675 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
12676 if (! STRINGP (font
))
12677 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
12678 if (! STRINGP (font
))
12679 /* This was formerly the first thing tried, but it finds too many fonts
12680 and takes too long. */
12681 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
12682 /* If those didn't work, look for something which will at least work. */
12683 if (! STRINGP (font
))
12684 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
12686 if (! STRINGP (font
))
12687 font
= build_string ("fixed");
12689 x_default_parameter (f
, parms
, Qfont
, font
,
12690 "font", "Font", RES_TYPE_STRING
);
12693 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
12694 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
12696 /* This defaults to 2 in order to match xterm. We recognize either
12697 internalBorderWidth or internalBorder (which is what xterm calls
12699 if (NILP (Fassq (Qinternal_border_width
, parms
)))
12703 value
= w32_get_arg (parms
, Qinternal_border_width
,
12704 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
12705 if (! EQ (value
, Qunbound
))
12706 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
12710 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
12711 "internalBorderWidth", "internalBorderWidth",
12714 /* Also do the stuff which must be set before the window exists. */
12715 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
12716 "foreground", "Foreground", RES_TYPE_STRING
);
12717 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
12718 "background", "Background", RES_TYPE_STRING
);
12719 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
12720 "pointerColor", "Foreground", RES_TYPE_STRING
);
12721 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
12722 "cursorColor", "Foreground", RES_TYPE_STRING
);
12723 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
12724 "borderColor", "BorderColor", RES_TYPE_STRING
);
12726 /* Init faces before x_default_parameter is called for scroll-bar
12727 parameters because that function calls x_set_scroll_bar_width,
12728 which calls change_frame_size, which calls Fset_window_buffer,
12729 which runs hooks, which call Fvertical_motion. At the end, we
12730 end up in init_iterator with a null face cache, which should not
12732 init_frame_faces (f
);
12734 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
12735 window_prompting
= x_figure_window_size (f
, parms
);
12737 if (window_prompting
& XNegative
)
12739 if (window_prompting
& YNegative
)
12740 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
12742 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
12746 if (window_prompting
& YNegative
)
12747 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
12749 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
12752 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
12754 XSetWindowAttributes attrs
;
12755 unsigned long mask
;
12758 mask
= CWBackPixel
| CWOverrideRedirect
| CWSaveUnder
| CWEventMask
;
12759 /* Window managers looks at the override-redirect flag to
12760 determine whether or net to give windows a decoration (Xlib
12762 attrs
.override_redirect
= True
;
12763 attrs
.save_under
= True
;
12764 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
12765 /* Arrange for getting MapNotify and UnmapNotify events. */
12766 attrs
.event_mask
= StructureNotifyMask
;
12768 = FRAME_W32_WINDOW (f
)
12769 = XCreateWindow (FRAME_W32_DISPLAY (f
),
12770 FRAME_W32_DISPLAY_INFO (f
)->root_window
,
12771 /* x, y, width, height */
12775 CopyFromParent
, InputOutput
, CopyFromParent
,
12782 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
12783 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
12784 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
12785 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
12786 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
12787 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
12789 /* Dimensions, especially f->height, must be done via change_frame_size.
12790 Change will not be effected unless different from the current
12793 height
= f
->height
;
12795 SET_FRAME_WIDTH (f
, 0);
12796 change_frame_size (f
, height
, width
, 1, 0, 0);
12802 /* It is now ok to make the frame official even if we get an error
12803 below. And the frame needs to be on Vframe_list or making it
12804 visible won't work. */
12805 Vframe_list
= Fcons (frame
, Vframe_list
);
12808 /* Now that the frame is official, it counts as a reference to
12810 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
12812 return unbind_to (count
, frame
);
12817 #ifdef TODO /* Tooltip support not complete. */
12818 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
12819 "Show STRING in a \"tooltip\" window on frame FRAME.\n\
12820 A tooltip window is a small window displaying a string.\n\
12822 FRAME nil or omitted means use the selected frame.\n\
12824 PARMS is an optional list of frame parameters which can be\n\
12825 used to change the tooltip's appearance.\n\
12827 Automatically hide the tooltip after TIMEOUT seconds.\n\
12828 TIMEOUT nil means use the default timeout of 5 seconds.\n\
12830 If the list of frame parameters PARAMS contains a `left' parameters,\n\
12831 the tooltip is displayed at that x-position. Otherwise it is\n\
12832 displayed at the mouse position, with offset DX added (default is 5 if\n\
12833 DX isn't specified). Likewise for the y-position; if a `top' frame\n\
12834 parameter is specified, it determines the y-position of the tooltip\n\
12835 window, otherwise it is displayed at the mouse position, with offset\n\
12836 DY added (default is 10).")
12837 (string
, frame
, parms
, timeout
, dx
, dy
)
12838 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
12842 Window root
, child
;
12843 Lisp_Object buffer
, top
, left
;
12844 struct buffer
*old_buffer
;
12845 struct text_pos pos
;
12846 int i
, width
, height
;
12847 int root_x
, root_y
, win_x
, win_y
;
12849 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
12850 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
12851 int count
= specpdl_ptr
- specpdl
;
12853 specbind (Qinhibit_redisplay
, Qt
);
12855 GCPRO4 (string
, parms
, frame
, timeout
);
12857 CHECK_STRING (string
, 0);
12858 f
= check_x_frame (frame
);
12859 if (NILP (timeout
))
12860 timeout
= make_number (5);
12862 CHECK_NATNUM (timeout
, 2);
12865 dx
= make_number (5);
12867 CHECK_NUMBER (dx
, 5);
12870 dy
= make_number (-10);
12872 CHECK_NUMBER (dy
, 6);
12874 if (NILP (last_show_tip_args
))
12875 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
12877 if (!NILP (tip_frame
))
12879 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
12880 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
12881 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
12883 if (EQ (frame
, last_frame
)
12884 && !NILP (Fequal (last_string
, string
))
12885 && !NILP (Fequal (last_parms
, parms
)))
12887 struct frame
*f
= XFRAME (tip_frame
);
12889 /* Only DX and DY have changed. */
12890 if (!NILP (tip_timer
))
12892 Lisp_Object timer
= tip_timer
;
12894 call1 (Qcancel_timer
, timer
);
12898 compute_tip_xy (f
, parms
, dx
, dy
, &root_x
, &root_y
);
12899 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12900 root_x
, root_y
- PIXEL_HEIGHT (f
));
12906 /* Hide a previous tip, if any. */
12909 ASET (last_show_tip_args
, 0, string
);
12910 ASET (last_show_tip_args
, 1, frame
);
12911 ASET (last_show_tip_args
, 2, parms
);
12913 /* Add default values to frame parameters. */
12914 if (NILP (Fassq (Qname
, parms
)))
12915 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
12916 if (NILP (Fassq (Qinternal_border_width
, parms
)))
12917 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
12918 if (NILP (Fassq (Qborder_width
, parms
)))
12919 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
12920 if (NILP (Fassq (Qborder_color
, parms
)))
12921 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
12922 if (NILP (Fassq (Qbackground_color
, parms
)))
12923 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
12926 /* Create a frame for the tooltip, and record it in the global
12927 variable tip_frame. */
12928 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
);
12929 f
= XFRAME (frame
);
12931 /* Set up the frame's root window. Currently we use a size of 80
12932 columns x 40 lines. If someone wants to show a larger tip, he
12933 will loose. I don't think this is a realistic case. */
12934 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
12935 w
->left
= w
->top
= make_number (0);
12936 w
->width
= make_number (80);
12937 w
->height
= make_number (40);
12939 w
->pseudo_window_p
= 1;
12941 /* Display the tooltip text in a temporary buffer. */
12942 buffer
= Fget_buffer_create (build_string (" *tip*"));
12943 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
);
12944 old_buffer
= current_buffer
;
12945 set_buffer_internal_1 (XBUFFER (buffer
));
12947 Finsert (1, &string
);
12948 clear_glyph_matrix (w
->desired_matrix
);
12949 clear_glyph_matrix (w
->current_matrix
);
12950 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
12951 try_window (FRAME_ROOT_WINDOW (f
), pos
);
12953 /* Compute width and height of the tooltip. */
12954 width
= height
= 0;
12955 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
12957 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
12958 struct glyph
*last
;
12961 /* Stop at the first empty row at the end. */
12962 if (!row
->enabled_p
|| !row
->displays_text_p
)
12965 /* Let the row go over the full width of the frame. */
12966 row
->full_width_p
= 1;
12968 /* There's a glyph at the end of rows that is use to place
12969 the cursor there. Don't include the width of this glyph. */
12970 if (row
->used
[TEXT_AREA
])
12972 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
12973 row_width
= row
->pixel_width
- last
->pixel_width
;
12976 row_width
= row
->pixel_width
;
12978 height
+= row
->height
;
12979 width
= max (width
, row_width
);
12982 /* Add the frame's internal border to the width and height the X
12983 window should have. */
12984 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
12985 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
12987 /* Move the tooltip window where the mouse pointer is. Resize and
12989 compute_tip_xy (f
, parms
, dx
, dy
, &root_x
, &root_y
);
12991 #if 0 /* TODO : W32 specifics */
12993 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12994 root_x
, root_y
- height
, width
, height
);
12995 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12999 /* Draw into the window. */
13000 w
->must_be_updated_p
= 1;
13001 update_single_window (w
, 1);
13003 /* Restore original current buffer. */
13004 set_buffer_internal_1 (old_buffer
);
13005 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
13008 /* Let the tip disappear after timeout seconds. */
13009 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
13010 intern ("x-hide-tip"));
13013 return unbind_to (count
, Qnil
);
13017 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
13018 "Hide the current tooltip window, if there is any.\n\
13019 Value is t is tooltip was open, nil otherwise.")
13023 Lisp_Object deleted
, frame
, timer
;
13024 struct gcpro gcpro1
, gcpro2
;
13026 /* Return quickly if nothing to do. */
13027 if (NILP (tip_timer
) && NILP (tip_frame
))
13032 GCPRO2 (frame
, timer
);
13033 tip_frame
= tip_timer
= deleted
= Qnil
;
13035 count
= BINDING_STACK_SIZE ();
13036 specbind (Qinhibit_redisplay
, Qt
);
13037 specbind (Qinhibit_quit
, Qt
);
13040 call1 (Qcancel_timer
, timer
);
13042 if (FRAMEP (frame
))
13044 Fdelete_frame (frame
, Qnil
);
13049 return unbind_to (count
, deleted
);
13055 /***********************************************************************
13056 File selection dialog
13057 ***********************************************************************/
13059 extern Lisp_Object Qfile_name_history
;
13061 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
13062 "Read file name, prompting with PROMPT in directory DIR.\n\
13063 Use a file selection dialog.\n\
13064 Select DEFAULT-FILENAME in the dialog's file selection box, if\n\
13065 specified. Ensure that file exists if MUSTMATCH is non-nil.")
13066 (prompt
, dir
, default_filename
, mustmatch
)
13067 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
13069 struct frame
*f
= SELECTED_FRAME ();
13070 Lisp_Object file
= Qnil
;
13071 int count
= specpdl_ptr
- specpdl
;
13072 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
13073 char filename
[MAX_PATH
+ 1];
13074 char init_dir
[MAX_PATH
+ 1];
13075 int use_dialog_p
= 1;
13077 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
13078 CHECK_STRING (prompt
, 0);
13079 CHECK_STRING (dir
, 1);
13081 /* Create the dialog with PROMPT as title, using DIR as initial
13082 directory and using "*" as pattern. */
13083 dir
= Fexpand_file_name (dir
, Qnil
);
13084 strncpy (init_dir
, XSTRING (dir
)->data
, MAX_PATH
);
13085 init_dir
[MAX_PATH
] = '\0';
13086 unixtodos_filename (init_dir
);
13088 if (STRINGP (default_filename
))
13090 char *file_name_only
;
13091 char *full_path_name
= XSTRING (default_filename
)->data
;
13093 unixtodos_filename (full_path_name
);
13095 file_name_only
= strrchr (full_path_name
, '\\');
13096 if (!file_name_only
)
13097 file_name_only
= full_path_name
;
13102 /* If default_file_name is a directory, don't use the open
13103 file dialog, as it does not support selecting
13105 if (!(*file_name_only
))
13109 strncpy (filename
, file_name_only
, MAX_PATH
);
13110 filename
[MAX_PATH
] = '\0';
13113 filename
[0] = '\0';
13117 OPENFILENAME file_details
;
13119 /* Prevent redisplay. */
13120 specbind (Qinhibit_redisplay
, Qt
);
13123 bzero (&file_details
, sizeof (file_details
));
13124 file_details
.lStructSize
= sizeof (file_details
);
13125 file_details
.hwndOwner
= FRAME_W32_WINDOW (f
);
13126 /* Undocumented Bug in Common File Dialog:
13127 If a filter is not specified, shell links are not resolved. */
13128 file_details
.lpstrFilter
= "All Files (*.*)\0*.*\0\0";
13129 file_details
.lpstrFile
= filename
;
13130 file_details
.nMaxFile
= sizeof (filename
);
13131 file_details
.lpstrInitialDir
= init_dir
;
13132 file_details
.lpstrTitle
= XSTRING (prompt
)->data
;
13133 file_details
.Flags
= OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
;
13135 if (!NILP (mustmatch
))
13136 file_details
.Flags
|= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
13138 if (GetOpenFileName (&file_details
))
13140 dostounix_filename (filename
);
13141 file
= build_string (filename
);
13147 file
= unbind_to (count
, file
);
13149 /* Open File dialog will not allow folders to be selected, so resort
13150 to minibuffer completing reads for directories. */
13152 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
13153 dir
, mustmatch
, dir
, Qfile_name_history
,
13154 default_filename
, Qnil
);
13158 /* Make "Cancel" equivalent to C-g. */
13160 Fsignal (Qquit
, Qnil
);
13162 return unbind_to (count
, file
);
13167 /***********************************************************************
13169 ***********************************************************************/
13173 DEFUN ("imagep", Fimagep
, Simagep
, 1, 1, 0,
13174 "Value is non-nil if SPEC is a valid image specification.")
13178 return valid_image_p (spec
) ? Qt
: Qnil
;
13182 DEFUN ("lookup-image", Flookup_image
, Slookup_image
, 1, 1, 0, "")
13188 if (valid_image_p (spec
))
13189 id
= lookup_image (SELECTED_FRAME (), spec
);
13191 debug_print (spec
);
13192 return make_number (id
);
13195 #endif /* GLYPH_DEBUG != 0 */
13199 /***********************************************************************
13200 w32 specialized functions
13201 ***********************************************************************/
13203 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 1, 0,
13204 "This will display the W32 font dialog and return an X font string corresponding to the selection.")
13208 FRAME_PTR f
= check_x_frame (frame
);
13216 bzero (&cf
, sizeof (cf
));
13217 bzero (&lf
, sizeof (lf
));
13219 cf
.lStructSize
= sizeof (cf
);
13220 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
13221 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
13222 cf
.lpLogFont
= &lf
;
13224 /* Initialize as much of the font details as we can from the current
13226 hdc
= GetDC (FRAME_W32_WINDOW (f
));
13227 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
13228 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
13229 if (GetTextMetrics (hdc
, &tm
))
13231 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
13232 lf
.lfWeight
= tm
.tmWeight
;
13233 lf
.lfItalic
= tm
.tmItalic
;
13234 lf
.lfUnderline
= tm
.tmUnderlined
;
13235 lf
.lfStrikeOut
= tm
.tmStruckOut
;
13236 lf
.lfCharSet
= tm
.tmCharSet
;
13237 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
13239 SelectObject (hdc
, oldobj
);
13240 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
13242 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
13245 return build_string (buf
);
13248 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
, Sw32_send_sys_command
, 1, 2, 0,
13249 "Send frame a Windows WM_SYSCOMMAND message of type COMMAND.\n\
13250 Some useful values for command are #xf030 to maximise frame (#xf020\n\
13251 to minimize), #xf120 to restore frame to original size, and #xf100\n\
13252 to activate the menubar for keyboard access. #xf140 activates the\n\
13253 screen saver if defined.\n\
13255 If optional parameter FRAME is not specified, use selected frame.")
13257 Lisp_Object command
, frame
;
13259 FRAME_PTR f
= check_x_frame (frame
);
13261 CHECK_NUMBER (command
, 0);
13263 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
13268 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
13269 "Get Windows to perform OPERATION on DOCUMENT.\n\
13270 This is a wrapper around the ShellExecute system function, which\n\
13271 invokes the application registered to handle OPERATION for DOCUMENT.\n\
13272 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be\n\
13273 nil for the default action), and DOCUMENT is typically the name of a\n\
13274 document file or URL, but can also be a program executable to run or\n\
13275 a directory to open in the Windows Explorer.\n\
13277 If DOCUMENT is a program executable, PARAMETERS can be a string\n\
13278 containing command line parameters, but otherwise should be nil.\n\
13280 SHOW-FLAG can be used to control whether the invoked application is hidden\n\
13281 or minimized. If SHOW-FLAG is nil, the application is displayed normally,\n\
13282 otherwise it is an integer representing a ShowWindow flag:\n\
13284 0 - start hidden\n\
13285 1 - start normally\n\
13286 3 - start maximized\n\
13287 6 - start minimized")
13288 (operation
, document
, parameters
, show_flag
)
13289 Lisp_Object operation
, document
, parameters
, show_flag
;
13291 Lisp_Object current_dir
;
13293 CHECK_STRING (document
, 0);
13295 /* Encode filename and current directory. */
13296 current_dir
= ENCODE_FILE (current_buffer
->directory
);
13297 document
= ENCODE_FILE (document
);
13298 if ((int) ShellExecute (NULL
,
13299 (STRINGP (operation
) ?
13300 XSTRING (operation
)->data
: NULL
),
13301 XSTRING (document
)->data
,
13302 (STRINGP (parameters
) ?
13303 XSTRING (parameters
)->data
: NULL
),
13304 XSTRING (current_dir
)->data
,
13305 (INTEGERP (show_flag
) ?
13306 XINT (show_flag
) : SW_SHOWDEFAULT
))
13309 error ("ShellExecute failed: %s", w32_strerror (0));
13312 /* Lookup virtual keycode from string representing the name of a
13313 non-ascii keystroke into the corresponding virtual key, using
13314 lispy_function_keys. */
13316 lookup_vk_code (char *key
)
13320 for (i
= 0; i
< 256; i
++)
13321 if (lispy_function_keys
[i
] != 0
13322 && strcmp (lispy_function_keys
[i
], key
) == 0)
13328 /* Convert a one-element vector style key sequence to a hot key
13331 w32_parse_hot_key (key
)
13334 /* Copied from Fdefine_key and store_in_keymap. */
13335 register Lisp_Object c
;
13337 int lisp_modifiers
;
13339 struct gcpro gcpro1
;
13341 CHECK_VECTOR (key
, 0);
13343 if (XFASTINT (Flength (key
)) != 1)
13348 c
= Faref (key
, make_number (0));
13350 if (CONSP (c
) && lucid_event_type_list_p (c
))
13351 c
= Fevent_convert_list (c
);
13355 if (! INTEGERP (c
) && ! SYMBOLP (c
))
13356 error ("Key definition is invalid");
13358 /* Work out the base key and the modifiers. */
13361 c
= parse_modifiers (c
);
13362 lisp_modifiers
= Fcar (Fcdr (c
));
13366 vk_code
= lookup_vk_code (XSYMBOL (c
)->name
->data
);
13368 else if (INTEGERP (c
))
13370 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
13371 /* Many ascii characters are their own virtual key code. */
13372 vk_code
= XINT (c
) & CHARACTERBITS
;
13375 if (vk_code
< 0 || vk_code
> 255)
13378 if ((lisp_modifiers
& meta_modifier
) != 0
13379 && !NILP (Vw32_alt_is_meta
))
13380 lisp_modifiers
|= alt_modifier
;
13382 /* Supply defs missing from mingw32. */
13384 #define MOD_ALT 0x0001
13385 #define MOD_CONTROL 0x0002
13386 #define MOD_SHIFT 0x0004
13387 #define MOD_WIN 0x0008
13390 /* Convert lisp modifiers to Windows hot-key form. */
13391 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
13392 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
13393 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
13394 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
13396 return HOTKEY (vk_code
, w32_modifiers
);
13399 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
, Sw32_register_hot_key
, 1, 1, 0,
13400 "Register KEY as a hot-key combination.\n\
13401 Certain key combinations like Alt-Tab are reserved for system use on\n\
13402 Windows, and therefore are normally intercepted by the system. However,\n\
13403 most of these key combinations can be received by registering them as\n\
13404 hot-keys, overriding their special meaning.\n\
13406 KEY must be a one element key definition in vector form that would be\n\
13407 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta\n\
13408 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper\n\
13409 is always interpreted as the Windows modifier keys.\n\
13411 The return value is the hotkey-id if registered, otherwise nil.")
13415 key
= w32_parse_hot_key (key
);
13417 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
13419 /* Reuse an empty slot if possible. */
13420 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
13422 /* Safe to add new key to list, even if we have focus. */
13424 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
13428 /* Notify input thread about new hot-key definition, so that it
13429 takes effect without needing to switch focus. */
13430 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
13437 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
, Sw32_unregister_hot_key
, 1, 1, 0,
13438 "Unregister HOTKEY as a hot-key combination.")
13444 if (!INTEGERP (key
))
13445 key
= w32_parse_hot_key (key
);
13447 item
= Fmemq (key
, w32_grabbed_keys
);
13451 /* Notify input thread about hot-key definition being removed, so
13452 that it takes effect without needing focus switch. */
13453 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
13454 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
13457 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
13464 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
, Sw32_registered_hot_keys
, 0, 0, 0,
13465 "Return list of registered hot-key IDs.")
13468 return Fcopy_sequence (w32_grabbed_keys
);
13471 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
, Sw32_reconstruct_hot_key
, 1, 1, 0,
13472 "Convert hot-key ID to a lisp key combination.")
13474 Lisp_Object hotkeyid
;
13476 int vk_code
, w32_modifiers
;
13479 CHECK_NUMBER (hotkeyid
, 0);
13481 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
13482 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
13484 if (lispy_function_keys
[vk_code
])
13485 key
= intern (lispy_function_keys
[vk_code
]);
13487 key
= make_number (vk_code
);
13489 key
= Fcons (key
, Qnil
);
13490 if (w32_modifiers
& MOD_SHIFT
)
13491 key
= Fcons (Qshift
, key
);
13492 if (w32_modifiers
& MOD_CONTROL
)
13493 key
= Fcons (Qctrl
, key
);
13494 if (w32_modifiers
& MOD_ALT
)
13495 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
13496 if (w32_modifiers
& MOD_WIN
)
13497 key
= Fcons (Qhyper
, key
);
13502 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
, Sw32_toggle_lock_key
, 1, 2, 0,
13503 "Toggle the state of the lock key KEY.\n\
13504 KEY can be `capslock', `kp-numlock', or `scroll'.\n\
13505 If the optional parameter NEW-STATE is a number, then the state of KEY\n\
13506 is set to off if the low bit of NEW-STATE is zero, otherwise on.")
13508 Lisp_Object key
, new_state
;
13512 if (EQ (key
, intern ("capslock")))
13513 vk_code
= VK_CAPITAL
;
13514 else if (EQ (key
, intern ("kp-numlock")))
13515 vk_code
= VK_NUMLOCK
;
13516 else if (EQ (key
, intern ("scroll")))
13517 vk_code
= VK_SCROLL
;
13521 if (!dwWindowsThreadId
)
13522 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
13524 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
13525 (WPARAM
) vk_code
, (LPARAM
) new_state
))
13528 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
13529 return make_number (msg
.wParam
);
13534 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
13535 "Return storage information about the file system FILENAME is on.\n\
13536 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total\n\
13537 storage of the file system, FREE is the free storage, and AVAIL is the\n\
13538 storage available to a non-superuser. All 3 numbers are in bytes.\n\
13539 If the underlying system call fails, value is nil.")
13541 Lisp_Object filename
;
13543 Lisp_Object encoded
, value
;
13545 CHECK_STRING (filename
, 0);
13546 filename
= Fexpand_file_name (filename
, Qnil
);
13547 encoded
= ENCODE_FILE (filename
);
13551 /* Determining the required information on Windows turns out, sadly,
13552 to be more involved than one would hope. The original Win32 api
13553 call for this will return bogus information on some systems, but we
13554 must dynamically probe for the replacement api, since that was
13555 added rather late on. */
13557 HMODULE hKernel
= GetModuleHandle ("kernel32");
13558 BOOL (*pfn_GetDiskFreeSpaceEx
)
13559 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
13560 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
13562 /* On Windows, we may need to specify the root directory of the
13563 volume holding FILENAME. */
13564 char rootname
[MAX_PATH
];
13565 char *name
= XSTRING (encoded
)->data
;
13567 /* find the root name of the volume if given */
13568 if (isalpha (name
[0]) && name
[1] == ':')
13570 rootname
[0] = name
[0];
13571 rootname
[1] = name
[1];
13572 rootname
[2] = '\\';
13575 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
13577 char *str
= rootname
;
13581 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
13591 if (pfn_GetDiskFreeSpaceEx
)
13593 LARGE_INTEGER availbytes
;
13594 LARGE_INTEGER freebytes
;
13595 LARGE_INTEGER totalbytes
;
13597 if (pfn_GetDiskFreeSpaceEx(rootname
,
13601 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
13602 make_float ((double) freebytes
.QuadPart
),
13603 make_float ((double) availbytes
.QuadPart
));
13607 DWORD sectors_per_cluster
;
13608 DWORD bytes_per_sector
;
13609 DWORD free_clusters
;
13610 DWORD total_clusters
;
13612 if (GetDiskFreeSpace(rootname
,
13613 §ors_per_cluster
,
13617 value
= list3 (make_float ((double) total_clusters
13618 * sectors_per_cluster
* bytes_per_sector
),
13619 make_float ((double) free_clusters
13620 * sectors_per_cluster
* bytes_per_sector
),
13621 make_float ((double) free_clusters
13622 * sectors_per_cluster
* bytes_per_sector
));
13631 /* This is zero if not using MS-Windows. */
13634 /* The section below is built by the lisp expression at the top of the file,
13635 just above where these variables are declared. */
13636 /*&&& init symbols here &&&*/
13637 Qauto_raise
= intern ("auto-raise");
13638 staticpro (&Qauto_raise
);
13639 Qauto_lower
= intern ("auto-lower");
13640 staticpro (&Qauto_lower
);
13641 Qbar
= intern ("bar");
13643 Qborder_color
= intern ("border-color");
13644 staticpro (&Qborder_color
);
13645 Qborder_width
= intern ("border-width");
13646 staticpro (&Qborder_width
);
13647 Qbox
= intern ("box");
13649 Qcursor_color
= intern ("cursor-color");
13650 staticpro (&Qcursor_color
);
13651 Qcursor_type
= intern ("cursor-type");
13652 staticpro (&Qcursor_type
);
13653 Qgeometry
= intern ("geometry");
13654 staticpro (&Qgeometry
);
13655 Qicon_left
= intern ("icon-left");
13656 staticpro (&Qicon_left
);
13657 Qicon_top
= intern ("icon-top");
13658 staticpro (&Qicon_top
);
13659 Qicon_type
= intern ("icon-type");
13660 staticpro (&Qicon_type
);
13661 Qicon_name
= intern ("icon-name");
13662 staticpro (&Qicon_name
);
13663 Qinternal_border_width
= intern ("internal-border-width");
13664 staticpro (&Qinternal_border_width
);
13665 Qleft
= intern ("left");
13666 staticpro (&Qleft
);
13667 Qright
= intern ("right");
13668 staticpro (&Qright
);
13669 Qmouse_color
= intern ("mouse-color");
13670 staticpro (&Qmouse_color
);
13671 Qnone
= intern ("none");
13672 staticpro (&Qnone
);
13673 Qparent_id
= intern ("parent-id");
13674 staticpro (&Qparent_id
);
13675 Qscroll_bar_width
= intern ("scroll-bar-width");
13676 staticpro (&Qscroll_bar_width
);
13677 Qsuppress_icon
= intern ("suppress-icon");
13678 staticpro (&Qsuppress_icon
);
13679 Qundefined_color
= intern ("undefined-color");
13680 staticpro (&Qundefined_color
);
13681 Qvertical_scroll_bars
= intern ("vertical-scroll-bars");
13682 staticpro (&Qvertical_scroll_bars
);
13683 Qvisibility
= intern ("visibility");
13684 staticpro (&Qvisibility
);
13685 Qwindow_id
= intern ("window-id");
13686 staticpro (&Qwindow_id
);
13687 Qx_frame_parameter
= intern ("x-frame-parameter");
13688 staticpro (&Qx_frame_parameter
);
13689 Qx_resource_name
= intern ("x-resource-name");
13690 staticpro (&Qx_resource_name
);
13691 Quser_position
= intern ("user-position");
13692 staticpro (&Quser_position
);
13693 Quser_size
= intern ("user-size");
13694 staticpro (&Quser_size
);
13695 Qscreen_gamma
= intern ("screen-gamma");
13696 staticpro (&Qscreen_gamma
);
13697 Qline_spacing
= intern ("line-spacing");
13698 staticpro (&Qline_spacing
);
13699 Qcenter
= intern ("center");
13700 staticpro (&Qcenter
);
13701 Qcancel_timer
= intern ("cancel-timer");
13702 staticpro (&Qcancel_timer
);
13703 /* This is the end of symbol initialization. */
13705 Qhyper
= intern ("hyper");
13706 staticpro (&Qhyper
);
13707 Qsuper
= intern ("super");
13708 staticpro (&Qsuper
);
13709 Qmeta
= intern ("meta");
13710 staticpro (&Qmeta
);
13711 Qalt
= intern ("alt");
13713 Qctrl
= intern ("ctrl");
13714 staticpro (&Qctrl
);
13715 Qcontrol
= intern ("control");
13716 staticpro (&Qcontrol
);
13717 Qshift
= intern ("shift");
13718 staticpro (&Qshift
);
13720 /* Text property `display' should be nonsticky by default. */
13721 Vtext_property_default_nonsticky
13722 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
13725 Qlaplace
= intern ("laplace");
13726 staticpro (&Qlaplace
);
13728 Qface_set_after_frame_default
= intern ("face-set-after-frame-default");
13729 staticpro (&Qface_set_after_frame_default
);
13731 Fput (Qundefined_color
, Qerror_conditions
,
13732 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
13733 Fput (Qundefined_color
, Qerror_message
,
13734 build_string ("Undefined color"));
13736 staticpro (&w32_grabbed_keys
);
13737 w32_grabbed_keys
= Qnil
;
13739 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
13740 "An array of color name mappings for windows.");
13741 Vw32_color_map
= Qnil
;
13743 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
13744 "Non-nil if alt key presses are passed on to Windows.\n\
13745 When non-nil, for example, alt pressed and released and then space will\n\
13746 open the System menu. When nil, Emacs silently swallows alt key events.");
13747 Vw32_pass_alt_to_system
= Qnil
;
13749 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
13750 "Non-nil if the alt key is to be considered the same as the meta key.\n\
13751 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta.");
13752 Vw32_alt_is_meta
= Qt
;
13754 DEFVAR_INT ("w32-quit-key", &Vw32_quit_key
,
13755 "If non-zero, the virtual key code for an alternative quit key.");
13756 XSETINT (Vw32_quit_key
, 0);
13758 DEFVAR_LISP ("w32-pass-lwindow-to-system",
13759 &Vw32_pass_lwindow_to_system
,
13760 "Non-nil if the left \"Windows\" key is passed on to Windows.\n\
13761 When non-nil, the Start menu is opened by tapping the key.");
13762 Vw32_pass_lwindow_to_system
= Qt
;
13764 DEFVAR_LISP ("w32-pass-rwindow-to-system",
13765 &Vw32_pass_rwindow_to_system
,
13766 "Non-nil if the right \"Windows\" key is passed on to Windows.\n\
13767 When non-nil, the Start menu is opened by tapping the key.");
13768 Vw32_pass_rwindow_to_system
= Qt
;
13770 DEFVAR_INT ("w32-phantom-key-code",
13771 &Vw32_phantom_key_code
,
13772 "Virtual key code used to generate \"phantom\" key presses.\n\
13773 Value is a number between 0 and 255.\n\
13775 Phantom key presses are generated in order to stop the system from\n\
13776 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or\n\
13777 `w32-pass-rwindow-to-system' is nil.");
13778 /* Although 255 is technically not a valid key code, it works and
13779 means that this hack won't interfere with any real key code. */
13780 Vw32_phantom_key_code
= 255;
13782 DEFVAR_LISP ("w32-enable-num-lock",
13783 &Vw32_enable_num_lock
,
13784 "Non-nil if Num Lock should act normally.\n\
13785 Set to nil to see Num Lock as the key `kp-numlock'.");
13786 Vw32_enable_num_lock
= Qt
;
13788 DEFVAR_LISP ("w32-enable-caps-lock",
13789 &Vw32_enable_caps_lock
,
13790 "Non-nil if Caps Lock should act normally.\n\
13791 Set to nil to see Caps Lock as the key `capslock'.");
13792 Vw32_enable_caps_lock
= Qt
;
13794 DEFVAR_LISP ("w32-scroll-lock-modifier",
13795 &Vw32_scroll_lock_modifier
,
13796 "Modifier to use for the Scroll Lock on state.\n\
13797 The value can be hyper, super, meta, alt, control or shift for the\n\
13798 respective modifier, or nil to see Scroll Lock as the key `scroll'.\n\
13799 Any other value will cause the key to be ignored.");
13800 Vw32_scroll_lock_modifier
= Qt
;
13802 DEFVAR_LISP ("w32-lwindow-modifier",
13803 &Vw32_lwindow_modifier
,
13804 "Modifier to use for the left \"Windows\" key.\n\
13805 The value can be hyper, super, meta, alt, control or shift for the\n\
13806 respective modifier, or nil to appear as the key `lwindow'.\n\
13807 Any other value will cause the key to be ignored.");
13808 Vw32_lwindow_modifier
= Qnil
;
13810 DEFVAR_LISP ("w32-rwindow-modifier",
13811 &Vw32_rwindow_modifier
,
13812 "Modifier to use for the right \"Windows\" key.\n\
13813 The value can be hyper, super, meta, alt, control or shift for the\n\
13814 respective modifier, or nil to appear as the key `rwindow'.\n\
13815 Any other value will cause the key to be ignored.");
13816 Vw32_rwindow_modifier
= Qnil
;
13818 DEFVAR_LISP ("w32-apps-modifier",
13819 &Vw32_apps_modifier
,
13820 "Modifier to use for the \"Apps\" key.\n\
13821 The value can be hyper, super, meta, alt, control or shift for the\n\
13822 respective modifier, or nil to appear as the key `apps'.\n\
13823 Any other value will cause the key to be ignored.");
13824 Vw32_apps_modifier
= Qnil
;
13826 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
13827 "Non-nil enables selection of artificially italicized and bold fonts.");
13828 w32_enable_synthesized_fonts
= 0;
13830 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
13831 "Non-nil enables Windows palette management to map colors exactly.");
13832 Vw32_enable_palette
= Qt
;
13834 DEFVAR_INT ("w32-mouse-button-tolerance",
13835 &Vw32_mouse_button_tolerance
,
13836 "Analogue of double click interval for faking middle mouse events.\n\
13837 The value is the minimum time in milliseconds that must elapse between\n\
13838 left/right button down events before they are considered distinct events.\n\
13839 If both mouse buttons are depressed within this interval, a middle mouse\n\
13840 button down event is generated instead.");
13841 XSETINT (Vw32_mouse_button_tolerance
, GetDoubleClickTime () / 2);
13843 DEFVAR_INT ("w32-mouse-move-interval",
13844 &Vw32_mouse_move_interval
,
13845 "Minimum interval between mouse move events.\n\
13846 The value is the minimum time in milliseconds that must elapse between\n\
13847 successive mouse move (or scroll bar drag) events before they are\n\
13848 reported as lisp events.");
13849 XSETINT (Vw32_mouse_move_interval
, 0);
13851 init_x_parm_symbols ();
13853 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
13854 "List of directories to search for bitmap files for w32.");
13855 Vx_bitmap_file_path
= decode_env_path ((char *) 0, "PATH");
13857 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
13858 "The shape of the pointer when over text.\n\
13859 Changing the value does not affect existing frames\n\
13860 unless you set the mouse color.");
13861 Vx_pointer_shape
= Qnil
;
13863 DEFVAR_LISP ("x-resource-name", &Vx_resource_name
,
13864 "The name Emacs uses to look up resources; for internal use only.\n\
13865 `x-get-resource' uses this as the first component of the instance name\n\
13866 when requesting resource values.\n\
13867 Emacs initially sets `x-resource-name' to the name under which Emacs\n\
13868 was invoked, or to the value specified with the `-name' or `-rn'\n\
13869 switches, if present.");
13870 Vx_resource_name
= Qnil
;
13872 Vx_nontext_pointer_shape
= Qnil
;
13874 Vx_mode_pointer_shape
= Qnil
;
13876 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
13877 "The shape of the pointer when Emacs is busy.\n\
13878 This variable takes effect when you create a new frame\n\
13879 or when you set the mouse color.");
13880 Vx_hourglass_pointer_shape
= Qnil
;
13882 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
13883 "Non-zero means Emacs displays an hourglass pointer on window systems.");
13884 display_hourglass_p
= 1;
13886 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
13887 "*Seconds to wait before displaying an hourglass pointer.\n\
13888 Value must be an integer or float.");
13889 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
13891 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
13892 &Vx_sensitive_text_pointer_shape
,
13893 "The shape of the pointer when over mouse-sensitive text.\n\
13894 This variable takes effect when you create a new frame\n\
13895 or when you set the mouse color.");
13896 Vx_sensitive_text_pointer_shape
= Qnil
;
13898 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
13899 &Vx_window_horizontal_drag_shape
,
13900 "Pointer shape to use for indicating a window can be dragged horizontally.\n\
13901 This variable takes effect when you create a new frame\n\
13902 or when you set the mouse color.");
13903 Vx_window_horizontal_drag_shape
= Qnil
;
13905 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
13906 "A string indicating the foreground color of the cursor box.");
13907 Vx_cursor_fore_pixel
= Qnil
;
13909 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
13910 "Non-nil if no window manager is in use.\n\
13911 Emacs doesn't try to figure this out; this is always nil\n\
13912 unless you set it to something else.");
13913 /* We don't have any way to find this out, so set it to nil
13914 and maybe the user would like to set it to t. */
13915 Vx_no_window_manager
= Qnil
;
13917 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
13918 &Vx_pixel_size_width_font_regexp
,
13919 "Regexp matching a font name whose width is the same as `PIXEL_SIZE'.\n\
13921 Since Emacs gets width of a font matching with this regexp from\n\
13922 PIXEL_SIZE field of the name, font finding mechanism gets faster for\n\
13923 such a font. This is especially effective for such large fonts as\n\
13924 Chinese, Japanese, and Korean.");
13925 Vx_pixel_size_width_font_regexp
= Qnil
;
13927 DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay
,
13928 "Time after which cached images are removed from the cache.\n\
13929 When an image has not been displayed this many seconds, remove it\n\
13930 from the image cache. Value must be an integer or nil with nil\n\
13931 meaning don't clear the cache.");
13932 Vimage_cache_eviction_delay
= make_number (30 * 60);
13934 DEFVAR_LISP ("w32-bdf-filename-alist",
13935 &Vw32_bdf_filename_alist
,
13936 "List of bdf fonts and their corresponding filenames.");
13937 Vw32_bdf_filename_alist
= Qnil
;
13939 DEFVAR_BOOL ("w32-strict-fontnames",
13940 &w32_strict_fontnames
,
13941 "Non-nil means only use fonts that are exact matches for those requested.\n\
13942 Default is nil, which allows old fontnames that are not XLFD compliant,\n\
13943 and allows third-party CJK display to work by specifying false charset\n\
13944 fields to trick Emacs into translating to Big5, SJIS etc.\n\
13945 Setting this to t will prevent wrong fonts being selected when\n\
13946 fontsets are automatically created.");
13947 w32_strict_fontnames
= 0;
13949 DEFVAR_BOOL ("w32-strict-painting",
13950 &w32_strict_painting
,
13951 "Non-nil means use strict rules for repainting frames.\n\
13952 Set this to nil to get the old behaviour for repainting; this should\n\
13953 only be necessary if the default setting causes problems.");
13954 w32_strict_painting
= 1;
13956 DEFVAR_LISP ("w32-system-coding-system",
13957 &Vw32_system_coding_system
,
13958 "Coding system used by Windows system functions, such as for font names.");
13959 Vw32_system_coding_system
= Qnil
;
13961 DEFVAR_LISP ("w32-charset-info-alist",
13962 &Vw32_charset_info_alist
,
13963 "Alist linking Emacs character sets to Windows fonts\n\
13964 and codepages. Each entry should be of the form:\n\
13966 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE))\n\
13968 where CHARSET_NAME is a string used in font names to identify the charset,\n\
13969 WINDOWS_CHARSET is a symbol that can be one of:\n\
13970 w32-charset-ansi, w32-charset-default, w32-charset-symbol,\n\
13971 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,\n\
13972 w32-charset-chinesebig5, "
13973 #ifdef JOHAB_CHARSET
13974 "w32-charset-johab, w32-charset-hebrew,\n\
13975 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,\n\
13976 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,\n\
13977 w32-charset-russian, w32-charset-mac, w32-charset-baltic,\n"
13979 #ifdef UNICODE_CHARSET
13980 "w32-charset-unicode, "
13982 "or w32-charset-oem.\n\
13983 CODEPAGE should be an integer specifying the codepage that should be used\n\
13984 to display the character set, t to do no translation and output as Unicode,\n\
13985 or nil to do no translation and output as 8 bit (or multibyte on far-east\n\
13986 versions of Windows) characters.");
13987 Vw32_charset_info_alist
= Qnil
;
13989 staticpro (&Qw32_charset_ansi
);
13990 Qw32_charset_ansi
= intern ("w32-charset-ansi");
13991 staticpro (&Qw32_charset_symbol
);
13992 Qw32_charset_symbol
= intern ("w32-charset-symbol");
13993 staticpro (&Qw32_charset_shiftjis
);
13994 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
13995 staticpro (&Qw32_charset_hangeul
);
13996 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
13997 staticpro (&Qw32_charset_chinesebig5
);
13998 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
13999 staticpro (&Qw32_charset_gb2312
);
14000 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
14001 staticpro (&Qw32_charset_oem
);
14002 Qw32_charset_oem
= intern ("w32-charset-oem");
14004 #ifdef JOHAB_CHARSET
14006 static int w32_extra_charsets_defined
= 1;
14007 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
, "");
14009 staticpro (&Qw32_charset_johab
);
14010 Qw32_charset_johab
= intern ("w32-charset-johab");
14011 staticpro (&Qw32_charset_easteurope
);
14012 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
14013 staticpro (&Qw32_charset_turkish
);
14014 Qw32_charset_turkish
= intern ("w32-charset-turkish");
14015 staticpro (&Qw32_charset_baltic
);
14016 Qw32_charset_baltic
= intern ("w32-charset-baltic");
14017 staticpro (&Qw32_charset_russian
);
14018 Qw32_charset_russian
= intern ("w32-charset-russian");
14019 staticpro (&Qw32_charset_arabic
);
14020 Qw32_charset_arabic
= intern ("w32-charset-arabic");
14021 staticpro (&Qw32_charset_greek
);
14022 Qw32_charset_greek
= intern ("w32-charset-greek");
14023 staticpro (&Qw32_charset_hebrew
);
14024 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
14025 staticpro (&Qw32_charset_vietnamese
);
14026 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
14027 staticpro (&Qw32_charset_thai
);
14028 Qw32_charset_thai
= intern ("w32-charset-thai");
14029 staticpro (&Qw32_charset_mac
);
14030 Qw32_charset_mac
= intern ("w32-charset-mac");
14034 #ifdef UNICODE_CHARSET
14036 static int w32_unicode_charset_defined
= 1;
14037 DEFVAR_BOOL ("w32-unicode-charset-defined",
14038 &w32_unicode_charset_defined
, "");
14040 staticpro (&Qw32_charset_unicode
);
14041 Qw32_charset_unicode
= intern ("w32-charset-unicode");
14044 defsubr (&Sx_get_resource
);
14045 #if 0 /* TODO: Port to W32 */
14046 defsubr (&Sx_change_window_property
);
14047 defsubr (&Sx_delete_window_property
);
14048 defsubr (&Sx_window_property
);
14050 defsubr (&Sxw_display_color_p
);
14051 defsubr (&Sx_display_grayscale_p
);
14052 defsubr (&Sxw_color_defined_p
);
14053 defsubr (&Sxw_color_values
);
14054 defsubr (&Sx_server_max_request_size
);
14055 defsubr (&Sx_server_vendor
);
14056 defsubr (&Sx_server_version
);
14057 defsubr (&Sx_display_pixel_width
);
14058 defsubr (&Sx_display_pixel_height
);
14059 defsubr (&Sx_display_mm_width
);
14060 defsubr (&Sx_display_mm_height
);
14061 defsubr (&Sx_display_screens
);
14062 defsubr (&Sx_display_planes
);
14063 defsubr (&Sx_display_color_cells
);
14064 defsubr (&Sx_display_visual_class
);
14065 defsubr (&Sx_display_backing_store
);
14066 defsubr (&Sx_display_save_under
);
14067 defsubr (&Sx_parse_geometry
);
14068 defsubr (&Sx_create_frame
);
14069 defsubr (&Sx_open_connection
);
14070 defsubr (&Sx_close_connection
);
14071 defsubr (&Sx_display_list
);
14072 defsubr (&Sx_synchronize
);
14074 /* W32 specific functions */
14076 defsubr (&Sw32_focus_frame
);
14077 defsubr (&Sw32_select_font
);
14078 defsubr (&Sw32_define_rgb_color
);
14079 defsubr (&Sw32_default_color_map
);
14080 defsubr (&Sw32_load_color_file
);
14081 defsubr (&Sw32_send_sys_command
);
14082 defsubr (&Sw32_shell_execute
);
14083 defsubr (&Sw32_register_hot_key
);
14084 defsubr (&Sw32_unregister_hot_key
);
14085 defsubr (&Sw32_registered_hot_keys
);
14086 defsubr (&Sw32_reconstruct_hot_key
);
14087 defsubr (&Sw32_toggle_lock_key
);
14088 defsubr (&Sw32_find_bdf_fonts
);
14090 defsubr (&Sfile_system_info
);
14092 /* Setting callback functions for fontset handler. */
14093 get_font_info_func
= w32_get_font_info
;
14095 #if 0 /* This function pointer doesn't seem to be used anywhere.
14096 And the pointer assigned has the wrong type, anyway. */
14097 list_fonts_func
= w32_list_fonts
;
14100 load_font_func
= w32_load_font
;
14101 find_ccl_program_func
= w32_find_ccl_program
;
14102 query_font_func
= w32_query_font
;
14103 set_frame_fontset_func
= x_set_font
;
14104 check_window_system_func
= check_w32
;
14106 #if 0 /* TODO Image support for W32 */
14108 Qxbm
= intern ("xbm");
14110 QCtype
= intern (":type");
14111 staticpro (&QCtype
);
14112 QCconversion
= intern (":conversion");
14113 staticpro (&QCconversion
);
14114 QCheuristic_mask
= intern (":heuristic-mask");
14115 staticpro (&QCheuristic_mask
);
14116 QCcolor_symbols
= intern (":color-symbols");
14117 staticpro (&QCcolor_symbols
);
14118 QCascent
= intern (":ascent");
14119 staticpro (&QCascent
);
14120 QCmargin
= intern (":margin");
14121 staticpro (&QCmargin
);
14122 QCrelief
= intern (":relief");
14123 staticpro (&QCrelief
);
14124 Qpostscript
= intern ("postscript");
14125 staticpro (&Qpostscript
);
14126 QCloader
= intern (":loader");
14127 staticpro (&QCloader
);
14128 QCbounding_box
= intern (":bounding-box");
14129 staticpro (&QCbounding_box
);
14130 QCpt_width
= intern (":pt-width");
14131 staticpro (&QCpt_width
);
14132 QCpt_height
= intern (":pt-height");
14133 staticpro (&QCpt_height
);
14134 QCindex
= intern (":index");
14135 staticpro (&QCindex
);
14136 Qpbm
= intern ("pbm");
14140 Qxpm
= intern ("xpm");
14145 Qjpeg
= intern ("jpeg");
14146 staticpro (&Qjpeg
);
14150 Qtiff
= intern ("tiff");
14151 staticpro (&Qtiff
);
14155 Qgif
= intern ("gif");
14160 Qpng
= intern ("png");
14164 defsubr (&Sclear_image_cache
);
14167 defsubr (&Simagep
);
14168 defsubr (&Slookup_image
);
14172 hourglass_atimer
= NULL
;
14173 hourglass_shown_p
= 0;
14174 #ifdef TODO /* Tooltip support not complete. */
14175 defsubr (&Sx_show_tip
);
14176 defsubr (&Sx_hide_tip
);
14179 staticpro (&tip_timer
);
14181 staticpro (&tip_frame
);
14183 defsubr (&Sx_file_dialog
);
14190 image_types
= NULL
;
14191 Vimage_types
= Qnil
;
14193 #if 0 /* TODO : Image support for W32 */
14194 define_image_type (&xbm_type
);
14195 define_image_type (&gs_type
);
14196 define_image_type (&pbm_type
);
14199 define_image_type (&xpm_type
);
14203 define_image_type (&jpeg_type
);
14207 define_image_type (&tiff_type
);
14211 define_image_type (&gif_type
);
14215 define_image_type (&png_type
);
14226 button
= MessageBox (NULL
,
14227 "A fatal error has occurred!\n\n"
14228 "Select Abort to exit, Retry to debug, Ignore to continue",
14229 "Emacs Abort Dialog",
14230 MB_ICONEXCLAMATION
| MB_TASKMODAL
14231 | MB_SETFOREGROUND
| MB_ABORTRETRYIGNORE
);
14246 /* For convenience when debugging. */
14250 return GetLastError ();