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 /* We explicitely disable composition handling because selection
6353 data should not contain any composition sequence. */
6354 coding
.composing
= COMPOSITION_DISABLED
;
6355 bufsz
= decoding_buffer_size (&coding
, LF_FACESIZE
);
6357 fontname
= alloca(sizeof(*fontname
) * bufsz
);
6358 decode_coding (&coding
, lplogfont
->lfFaceName
, fontname
,
6359 strlen(lplogfont
->lfFaceName
), bufsz
- 1);
6360 *(fontname
+ coding
.produced
) = '\0';
6362 /* Replace dashes with underscores so the dashes are not
6364 fontname_dash
= fontname
;
6365 while (fontname_dash
= strchr (fontname_dash
, '-'))
6366 *fontname_dash
= '_';
6368 if (lplogfont
->lfHeight
)
6370 sprintf (height_pixels
, "%u", abs (lplogfont
->lfHeight
));
6371 sprintf (height_dpi
, "%u",
6372 abs (lplogfont
->lfHeight
) * 720 / display_resy
);
6376 strcpy (height_pixels
, "*");
6377 strcpy (height_dpi
, "*");
6379 if (lplogfont
->lfWidth
)
6380 sprintf (width_pixels
, "%u", lplogfont
->lfWidth
* 10);
6382 strcpy (width_pixels
, "*");
6384 _snprintf (lpxstr
, len
- 1,
6385 "-%s-%s-%s-%c-normal-normal-%s-%s-%d-%d-%c-%s-%s",
6386 fonttype
, /* foundry */
6387 fontname
, /* family */
6388 w32_to_x_weight (lplogfont
->lfWeight
), /* weight */
6389 lplogfont
->lfItalic
?'i':'r', /* slant */
6391 /* add style name */
6392 height_pixels
, /* pixel size */
6393 height_dpi
, /* point size */
6394 display_resx
, /* resx */
6395 display_resy
, /* resy */
6396 ((lplogfont
->lfPitchAndFamily
& 0x3) == VARIABLE_PITCH
)
6397 ? 'p' : 'c', /* spacing */
6398 width_pixels
, /* avg width */
6399 specific_charset
? specific_charset
6400 : w32_to_x_charset (lplogfont
->lfCharSet
)
6401 /* charset registry and encoding */
6404 lpxstr
[len
- 1] = 0; /* just to be sure */
6409 x_to_w32_font (lpxstr
, lplogfont
)
6411 LOGFONT
* lplogfont
;
6413 struct coding_system coding
;
6415 if (!lplogfont
) return (FALSE
);
6417 memset (lplogfont
, 0, sizeof (*lplogfont
));
6419 /* Set default value for each field. */
6421 lplogfont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
6422 lplogfont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
6423 lplogfont
->lfQuality
= DEFAULT_QUALITY
;
6425 /* go for maximum quality */
6426 lplogfont
->lfOutPrecision
= OUT_STROKE_PRECIS
;
6427 lplogfont
->lfClipPrecision
= CLIP_STROKE_PRECIS
;
6428 lplogfont
->lfQuality
= PROOF_QUALITY
;
6431 lplogfont
->lfCharSet
= DEFAULT_CHARSET
;
6432 lplogfont
->lfWeight
= FW_DONTCARE
;
6433 lplogfont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_DONTCARE
;
6438 /* Provide a simple escape mechanism for specifying Windows font names
6439 * directly -- if font spec does not beginning with '-', assume this
6441 * "<font name>[:height in pixels[:width in pixels[:weight]]]"
6447 char name
[50], weight
[20], slant
, pitch
, pixels
[10], height
[10],
6448 width
[10], resy
[10], remainder
[50];
6450 int dpi
= one_w32_display_info
.resy
;
6452 fields
= sscanf (lpxstr
,
6453 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
6454 name
, weight
, &slant
, pixels
, height
, resy
, &pitch
, width
, remainder
);
6458 /* In the general case when wildcards cover more than one field,
6459 we don't know which field is which, so don't fill any in.
6460 However, we need to cope with this particular form, which is
6461 generated by font_list_1 (invoked by try_font_list):
6462 "-raster-6x10-*-gb2312*-*"
6463 and make sure to correctly parse the charset field. */
6466 fields
= sscanf (lpxstr
,
6467 "-%*[^-]-%49[^-]-*-%49s",
6470 else if (fields
< 9)
6476 if (fields
> 0 && name
[0] != '*')
6482 (Fcheck_coding_system (Vw32_system_coding_system
), &coding
);
6483 coding
.src_multibyte
= 1;
6484 coding
.dst_multibyte
= 1;
6485 bufsize
= encoding_buffer_size (&coding
, strlen (name
));
6486 buf
= (unsigned char *) alloca (bufsize
);
6487 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6488 encode_coding (&coding
, name
, buf
, strlen (name
), bufsize
);
6489 if (coding
.produced
>= LF_FACESIZE
)
6490 coding
.produced
= LF_FACESIZE
- 1;
6491 buf
[coding
.produced
] = 0;
6492 strcpy (lplogfont
->lfFaceName
, buf
);
6496 lplogfont
->lfFaceName
[0] = '\0';
6501 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6505 lplogfont
->lfItalic
= (fields
> 0 && slant
== 'i');
6509 if (fields
> 0 && pixels
[0] != '*')
6510 lplogfont
->lfHeight
= atoi (pixels
);
6514 if (fields
> 0 && resy
[0] != '*')
6517 if (tem
> 0) dpi
= tem
;
6520 if (fields
> -1 && lplogfont
->lfHeight
== 0 && height
[0] != '*')
6521 lplogfont
->lfHeight
= atoi (height
) * dpi
/ 720;
6524 lplogfont
->lfPitchAndFamily
=
6525 (fields
> 0 && pitch
== 'p') ? VARIABLE_PITCH
: FIXED_PITCH
;
6529 if (fields
> 0 && width
[0] != '*')
6530 lplogfont
->lfWidth
= atoi (width
) / 10;
6534 /* Strip the trailing '-' if present. (it shouldn't be, as it
6535 fails the test against xlfd-tight-regexp in fontset.el). */
6537 int len
= strlen (remainder
);
6538 if (len
> 0 && remainder
[len
-1] == '-')
6539 remainder
[len
-1] = 0;
6541 encoding
= remainder
;
6543 if (strncmp (encoding
, "*-", 2) == 0)
6546 lplogfont
->lfCharSet
= x_to_w32_charset (encoding
);
6551 char name
[100], height
[10], width
[10], weight
[20];
6553 fields
= sscanf (lpxstr
,
6554 "%99[^:]:%9[^:]:%9[^:]:%19s",
6555 name
, height
, width
, weight
);
6557 if (fields
== EOF
) return (FALSE
);
6561 strncpy (lplogfont
->lfFaceName
,name
, LF_FACESIZE
);
6562 lplogfont
->lfFaceName
[LF_FACESIZE
-1] = 0;
6566 lplogfont
->lfFaceName
[0] = 0;
6572 lplogfont
->lfHeight
= atoi (height
);
6577 lplogfont
->lfWidth
= atoi (width
);
6581 lplogfont
->lfWeight
= x_to_w32_weight ((fields
> 0 ? weight
: ""));
6584 /* This makes TrueType fonts work better. */
6585 lplogfont
->lfHeight
= - abs (lplogfont
->lfHeight
);
6590 /* Strip the pixel height and point height from the given xlfd, and
6591 return the pixel height. If no pixel height is specified, calculate
6592 one from the point height, or if that isn't defined either, return
6593 0 (which usually signifies a scalable font).
6596 xlfd_strip_height (char *fontname
)
6598 int pixel_height
, field_number
;
6599 char *read_from
, *write_to
;
6603 pixel_height
= field_number
= 0;
6606 /* Look for height fields. */
6607 for (read_from
= fontname
; *read_from
; read_from
++)
6609 if (*read_from
== '-')
6612 if (field_number
== 7) /* Pixel height. */
6615 write_to
= read_from
;
6617 /* Find end of field. */
6618 for (;*read_from
&& *read_from
!= '-'; read_from
++)
6621 /* Split the fontname at end of field. */
6627 pixel_height
= atoi (write_to
);
6628 /* Blank out field. */
6629 if (read_from
> write_to
)
6634 /* If the pixel height field is at the end (partial xlfd),
6637 return pixel_height
;
6639 /* If we got a pixel height, the point height can be
6640 ignored. Just blank it out and break now. */
6643 /* Find end of point size field. */
6644 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6650 /* Blank out the point size field. */
6651 if (read_from
> write_to
)
6657 return pixel_height
;
6661 /* If the point height is already blank, break now. */
6662 if (*read_from
== '-')
6668 else if (field_number
== 8)
6670 /* If we didn't get a pixel height, try to get the point
6671 height and convert that. */
6673 char *point_size_start
= read_from
++;
6675 /* Find end of field. */
6676 for (; *read_from
&& *read_from
!= '-'; read_from
++)
6685 point_size
= atoi (point_size_start
);
6687 /* Convert to pixel height. */
6688 pixel_height
= point_size
6689 * one_w32_display_info
.height_in
/ 720;
6691 /* Blank out this field and break. */
6699 /* Shift the rest of the font spec into place. */
6700 if (write_to
&& read_from
> write_to
)
6702 for (; *read_from
; read_from
++, write_to
++)
6703 *write_to
= *read_from
;
6707 return pixel_height
;
6710 /* Assume parameter 1 is fully qualified, no wildcards. */
6712 w32_font_match (fontname
, pattern
)
6716 char *regex
= alloca (strlen (pattern
) * 2 + 3);
6717 char *font_name_copy
= alloca (strlen (fontname
) + 1);
6720 /* Copy fontname so we can modify it during comparison. */
6721 strcpy (font_name_copy
, fontname
);
6726 /* Turn pattern into a regexp and do a regexp match. */
6727 for (; *pattern
; pattern
++)
6729 if (*pattern
== '?')
6731 else if (*pattern
== '*')
6742 /* Strip out font heights and compare them seperately, since
6743 rounding error can cause mismatches. This also allows a
6744 comparison between a font that declares only a pixel height and a
6745 pattern that declares the point height.
6748 int font_height
, pattern_height
;
6750 font_height
= xlfd_strip_height (font_name_copy
);
6751 pattern_height
= xlfd_strip_height (regex
);
6753 /* Compare now, and don't bother doing expensive regexp matching
6754 if the heights differ. */
6755 if (font_height
&& pattern_height
&& (font_height
!= pattern_height
))
6759 return (fast_c_string_match_ignore_case (build_string (regex
),
6760 font_name_copy
) >= 0);
6763 /* Callback functions, and a structure holding info they need, for
6764 listing system fonts on W32. We need one set of functions to do the
6765 job properly, but these don't work on NT 3.51 and earlier, so we
6766 have a second set which don't handle character sets properly to
6769 In both cases, there are two passes made. The first pass gets one
6770 font from each family, the second pass lists all the fonts from
6773 typedef struct enumfont_t
6778 XFontStruct
*size_ref
;
6779 Lisp_Object
*pattern
;
6785 enum_font_maybe_add_to_list (enumfont_t
*, LOGFONT
*, char *, Lisp_Object
);
6788 enum_font_cb2 (lplf
, lptm
, FontType
, lpef
)
6790 NEWTEXTMETRIC
* lptm
;
6794 /* Ignore underlined and struck out versions of fonts. */
6795 if (lplf
->elfLogFont
.lfStrikeOut
|| lplf
->elfLogFont
.lfUnderline
)
6798 /* Only return fonts with names starting with @ if they were
6799 explicitly specified, since Microsoft uses an initial @ to
6800 denote fonts for vertical writing, without providing a more
6801 convenient way of identifying them. */
6802 if (lplf
->elfLogFont
.lfFaceName
[0] == '@'
6803 && lpef
->logfont
.lfFaceName
[0] != '@')
6806 /* Check that the character set matches if it was specified */
6807 if (lpef
->logfont
.lfCharSet
!= DEFAULT_CHARSET
&&
6808 lplf
->elfLogFont
.lfCharSet
!= lpef
->logfont
.lfCharSet
)
6812 if (FontType
== RASTER_FONTTYPE
)
6814 /* DBCS raster fonts have problems displaying, so skip them. */
6815 int charset
= lplf
->elfLogFont
.lfCharSet
;
6816 if (charset
== SHIFTJIS_CHARSET
6817 || charset
== HANGEUL_CHARSET
6818 || charset
== CHINESEBIG5_CHARSET
6819 || charset
== GB2312_CHARSET
6820 #ifdef JOHAB_CHARSET
6821 || charset
== JOHAB_CHARSET
6829 Lisp_Object width
= Qnil
;
6830 Lisp_Object charset_list
= Qnil
;
6831 char *charset
= NULL
;
6833 /* Truetype fonts do not report their true metrics until loaded */
6834 if (FontType
!= RASTER_FONTTYPE
)
6836 if (!NILP (*(lpef
->pattern
)))
6838 /* Scalable fonts are as big as you want them to be. */
6839 lplf
->elfLogFont
.lfHeight
= lpef
->logfont
.lfHeight
;
6840 lplf
->elfLogFont
.lfWidth
= lpef
->logfont
.lfWidth
;
6841 width
= make_number (lpef
->logfont
.lfWidth
);
6845 lplf
->elfLogFont
.lfHeight
= 0;
6846 lplf
->elfLogFont
.lfWidth
= 0;
6850 /* Make sure the height used here is the same as everywhere
6851 else (ie character height, not cell height). */
6852 if (lplf
->elfLogFont
.lfHeight
> 0)
6854 /* lptm can be trusted for RASTER fonts, but not scalable ones. */
6855 if (FontType
== RASTER_FONTTYPE
)
6856 lplf
->elfLogFont
.lfHeight
= lptm
->tmInternalLeading
- lptm
->tmHeight
;
6858 lplf
->elfLogFont
.lfHeight
= -lplf
->elfLogFont
.lfHeight
;
6861 if (!NILP (*(lpef
->pattern
)))
6863 charset
= xlfd_charset_of_font (XSTRING(*(lpef
->pattern
))->data
);
6865 /* We already checked charsets above, but DEFAULT_CHARSET
6866 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
6868 && strncmp (charset
, "*-*", 3) != 0
6869 && lpef
->logfont
.lfCharSet
== DEFAULT_CHARSET
6870 && strcmp (charset
, w32_to_x_charset (DEFAULT_CHARSET
)) != 0)
6875 charset_list
= Fcons (build_string (charset
), Qnil
);
6877 charset_list
= w32_to_all_x_charsets (lplf
->elfLogFont
.lfCharSet
);
6879 /* Loop through the charsets. */
6880 for ( ; CONSP (charset_list
); charset_list
= Fcdr (charset_list
))
6882 Lisp_Object this_charset
= Fcar (charset_list
);
6883 charset
= XSTRING (this_charset
)->data
;
6885 /* List bold and italic variations if w32-enable-synthesized-fonts
6886 is non-nil and this is a plain font. */
6887 if (w32_enable_synthesized_fonts
6888 && lplf
->elfLogFont
.lfWeight
== FW_NORMAL
6889 && lplf
->elfLogFont
.lfItalic
== FALSE
)
6891 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6894 lplf
->elfLogFont
.lfWeight
= FW_BOLD
;
6895 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6898 lplf
->elfLogFont
.lfItalic
= TRUE
;
6899 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6902 lplf
->elfLogFont
.lfWeight
= FW_NORMAL
;
6903 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6907 enum_font_maybe_add_to_list (lpef
, &(lplf
->elfLogFont
),
6916 enum_font_maybe_add_to_list (lpef
, logfont
, match_charset
, width
)
6919 char * match_charset
;
6924 if (!w32_to_x_font (logfont
, buf
, 100, match_charset
))
6927 if (NILP (*(lpef
->pattern
))
6928 || w32_font_match (buf
, XSTRING (*(lpef
->pattern
))->data
))
6930 /* Check if we already listed this font. This may happen if
6931 w32_enable_synthesized_fonts is non-nil, and there are real
6932 bold and italic versions of the font. */
6933 Lisp_Object font_name
= build_string (buf
);
6934 if (NILP (Fmember (font_name
, lpef
->list
)))
6936 *lpef
->tail
= Fcons (Fcons (build_string (buf
), width
), Qnil
);
6937 lpef
->tail
= &(XCDR (*lpef
->tail
));
6945 enum_font_cb1 (lplf
, lptm
, FontType
, lpef
)
6947 NEWTEXTMETRIC
* lptm
;
6950 { return EnumFontFamilies (lpef
->hdc
,
6951 lplf
->elfLogFont
.lfFaceName
,
6952 (FONTENUMPROC
) enum_font_cb2
,
6958 enum_fontex_cb2 (lplf
, lptm
, font_type
, lpef
)
6959 ENUMLOGFONTEX
* lplf
;
6960 NEWTEXTMETRICEX
* lptm
;
6964 /* We are not interested in the extra info we get back from the 'Ex
6965 version - only the fact that we get character set variations
6966 enumerated seperately. */
6967 return enum_font_cb2 ((ENUMLOGFONT
*) lplf
, (NEWTEXTMETRIC
*) lptm
,
6972 enum_fontex_cb1 (lplf
, lptm
, font_type
, lpef
)
6973 ENUMLOGFONTEX
* lplf
;
6974 NEWTEXTMETRICEX
* lptm
;
6978 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
6979 FARPROC enum_font_families_ex
6980 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
6981 /* We don't really expect EnumFontFamiliesEx to disappear once we
6982 get here, so don't bother handling it gracefully. */
6983 if (enum_font_families_ex
== NULL
)
6984 error ("gdi32.dll has disappeared!");
6985 return enum_font_families_ex (lpef
->hdc
,
6987 (FONTENUMPROC
) enum_fontex_cb2
,
6991 /* Interface to fontset handler. (adapted from mw32font.c in Meadow
6992 and xterm.c in Emacs 20.3) */
6994 static Lisp_Object
w32_list_bdf_fonts (Lisp_Object pattern
, int max_names
)
6996 char *fontname
, *ptnstr
;
6997 Lisp_Object list
, tem
, newlist
= Qnil
;
7000 list
= Vw32_bdf_filename_alist
;
7001 ptnstr
= XSTRING (pattern
)->data
;
7003 for ( ; CONSP (list
); list
= XCDR (list
))
7007 fontname
= XSTRING (XCAR (tem
))->data
;
7008 else if (STRINGP (tem
))
7009 fontname
= XSTRING (tem
)->data
;
7013 if (w32_font_match (fontname
, ptnstr
))
7015 newlist
= Fcons (XCAR (tem
), newlist
);
7017 if (n_fonts
>= max_names
)
7025 /* Return a list of names of available fonts matching PATTERN on frame
7026 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
7027 to be listed. Frame F NULL means we have not yet created any
7028 frame, which means we can't get proper size info, as we don't have
7029 a device context to use for GetTextMetrics.
7030 MAXNAMES sets a limit on how many fonts to match. */
7033 w32_list_fonts (f
, pattern
, size
, maxnames
)
7035 Lisp_Object pattern
;
7039 Lisp_Object patterns
, key
= Qnil
, tem
, tpat
;
7040 Lisp_Object list
= Qnil
, newlist
= Qnil
, second_best
= Qnil
;
7041 struct w32_display_info
*dpyinfo
= &one_w32_display_info
;
7044 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
7045 if (NILP (patterns
))
7046 patterns
= Fcons (pattern
, Qnil
);
7048 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
7053 tpat
= XCAR (patterns
);
7055 if (!STRINGP (tpat
))
7058 /* Avoid expensive EnumFontFamilies functions if we are not
7059 going to be able to output one of these anyway. */
7060 codepage
= w32_codepage_for_font (XSTRING (tpat
)->data
);
7061 if (codepage
!= CP_8BIT
&& codepage
!= CP_UNICODE
7062 && codepage
!= CP_DEFAULT
&& codepage
!= CP_UNKNOWN
7063 && !IsValidCodePage(codepage
))
7066 /* See if we cached the result for this particular query.
7067 The cache is an alist of the form:
7068 ((PATTERN (FONTNAME . WIDTH) ...) ...)
7070 if (tem
= XCDR (dpyinfo
->name_list_element
),
7071 !NILP (list
= Fassoc (tpat
, tem
)))
7073 list
= Fcdr_safe (list
);
7074 /* We have a cached list. Don't have to get the list again. */
7079 /* At first, put PATTERN in the cache. */
7086 /* Use EnumFontFamiliesEx where it is available, as it knows
7087 about character sets. Fall back to EnumFontFamilies for
7088 older versions of NT that don't support the 'Ex function. */
7089 x_to_w32_font (XSTRING (tpat
)->data
, &ef
.logfont
);
7091 LOGFONT font_match_pattern
;
7092 HMODULE gdi32
= GetModuleHandle ("gdi32.dll");
7093 FARPROC enum_font_families_ex
7094 = GetProcAddress ( gdi32
, "EnumFontFamiliesExA");
7096 /* We do our own pattern matching so we can handle wildcards. */
7097 font_match_pattern
.lfFaceName
[0] = 0;
7098 font_match_pattern
.lfPitchAndFamily
= 0;
7099 /* We can use the charset, because if it has a wildcard it will
7100 translate to DEFAULT_CHARSET anyway. */
7101 font_match_pattern
.lfCharSet
= ef
.logfont
.lfCharSet
;
7103 ef
.hdc
= GetDC (dpyinfo
->root_window
);
7105 if (enum_font_families_ex
)
7106 enum_font_families_ex (ef
.hdc
,
7107 &font_match_pattern
,
7108 (FONTENUMPROC
) enum_fontex_cb1
,
7111 EnumFontFamilies (ef
.hdc
, NULL
, (FONTENUMPROC
) enum_font_cb1
,
7114 ReleaseDC (dpyinfo
->root_window
, ef
.hdc
);
7119 /* Make a list of the fonts we got back.
7120 Store that in the font cache for the display. */
7121 XCDR (dpyinfo
->name_list_element
)
7122 = Fcons (Fcons (tpat
, list
),
7123 XCDR (dpyinfo
->name_list_element
));
7126 if (NILP (list
)) continue; /* Try the remaining alternatives. */
7128 newlist
= second_best
= Qnil
;
7130 /* Make a list of the fonts that have the right width. */
7131 for (; CONSP (list
); list
= XCDR (list
))
7138 if (NILP (XCAR (tem
)))
7142 newlist
= Fcons (XCAR (tem
), newlist
);
7144 if (n_fonts
>= maxnames
)
7149 if (!INTEGERP (XCDR (tem
)))
7151 /* Since we don't yet know the size of the font, we must
7152 load it and try GetTextMetrics. */
7153 W32FontStruct thisinfo
;
7158 if (!x_to_w32_font (XSTRING (XCAR (tem
))->data
, &lf
))
7162 thisinfo
.bdf
= NULL
;
7163 thisinfo
.hfont
= CreateFontIndirect (&lf
);
7164 if (thisinfo
.hfont
== NULL
)
7167 hdc
= GetDC (dpyinfo
->root_window
);
7168 oldobj
= SelectObject (hdc
, thisinfo
.hfont
);
7169 if (GetTextMetrics (hdc
, &thisinfo
.tm
))
7170 XCDR (tem
) = make_number (FONT_WIDTH (&thisinfo
));
7172 XCDR (tem
) = make_number (0);
7173 SelectObject (hdc
, oldobj
);
7174 ReleaseDC (dpyinfo
->root_window
, hdc
);
7175 DeleteObject(thisinfo
.hfont
);
7178 found_size
= XINT (XCDR (tem
));
7179 if (found_size
== size
)
7181 newlist
= Fcons (XCAR (tem
), newlist
);
7183 if (n_fonts
>= maxnames
)
7186 /* keep track of the closest matching size in case
7187 no exact match is found. */
7188 else if (found_size
> 0)
7190 if (NILP (second_best
))
7193 else if (found_size
< size
)
7195 if (XINT (XCDR (second_best
)) > size
7196 || XINT (XCDR (second_best
)) < found_size
)
7201 if (XINT (XCDR (second_best
)) > size
7202 && XINT (XCDR (second_best
)) >
7209 if (!NILP (newlist
))
7211 else if (!NILP (second_best
))
7213 newlist
= Fcons (XCAR (second_best
), Qnil
);
7218 /* Include any bdf fonts. */
7219 if (n_fonts
< maxnames
)
7221 Lisp_Object combined
[2];
7222 combined
[0] = w32_list_bdf_fonts (pattern
, maxnames
- n_fonts
);
7223 combined
[1] = newlist
;
7224 newlist
= Fnconc(2, combined
);
7231 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
7233 w32_get_font_info (f
, font_idx
)
7237 return (FRAME_W32_FONT_TABLE (f
) + font_idx
);
7242 w32_query_font (struct frame
*f
, char *fontname
)
7245 struct font_info
*pfi
;
7247 pfi
= FRAME_W32_FONT_TABLE (f
);
7249 for (i
= 0; i
< one_w32_display_info
.n_fonts
;i
++, pfi
++)
7251 if (strcmp(pfi
->name
, fontname
) == 0) return pfi
;
7257 /* Find a CCL program for a font specified by FONTP, and set the member
7258 `encoder' of the structure. */
7261 w32_find_ccl_program (fontp
)
7262 struct font_info
*fontp
;
7264 Lisp_Object list
, elt
;
7266 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
7270 && STRINGP (XCAR (elt
))
7271 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
7277 struct ccl_program
*ccl
7278 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
7280 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
7283 fontp
->font_encoder
= ccl
;
7288 /* Find BDF files in a specified directory. (use GCPRO when calling,
7289 as this calls lisp to get a directory listing). */
7291 w32_find_bdf_fonts_in_dir (Lisp_Object directory
)
7293 Lisp_Object filelist
, list
= Qnil
;
7296 if (!STRINGP(directory
))
7299 filelist
= Fdirectory_files (directory
, Qt
,
7300 build_string (".*\\.[bB][dD][fF]"), Qt
);
7302 for ( ; CONSP(filelist
); filelist
= XCDR (filelist
))
7304 Lisp_Object filename
= XCAR (filelist
);
7305 if (w32_BDF_to_x_font (XSTRING (filename
)->data
, fontname
, 100))
7306 store_in_alist (&list
, build_string (fontname
), filename
);
7311 DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts
, Sw32_find_bdf_fonts
,
7313 "Return a list of BDF fonts in DIR, suitable for appending to\n\
7314 w32-bdf-filename-alist. Fonts which do not contain an xlfd description\n\
7315 will not be included in the list. DIR may be a list of directories.")
7317 Lisp_Object directory
;
7319 Lisp_Object list
= Qnil
;
7320 struct gcpro gcpro1
, gcpro2
;
7322 if (!CONSP (directory
))
7323 return w32_find_bdf_fonts_in_dir (directory
);
7325 for ( ; CONSP (directory
); directory
= XCDR (directory
))
7327 Lisp_Object pair
[2];
7330 GCPRO2 (directory
, list
);
7331 pair
[1] = w32_find_bdf_fonts_in_dir( XCAR (directory
) );
7332 list
= Fnconc( 2, pair
);
7339 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
7340 "Internal function called by `color-defined-p', which see.")
7342 Lisp_Object color
, frame
;
7345 FRAME_PTR f
= check_x_frame (frame
);
7347 CHECK_STRING (color
, 1);
7349 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7355 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
7356 "Internal function called by `color-values', which see.")
7358 Lisp_Object color
, frame
;
7361 FRAME_PTR f
= check_x_frame (frame
);
7363 CHECK_STRING (color
, 1);
7365 if (w32_defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
7369 rgb
[0] = make_number ((GetRValue (foo
.pixel
) << 8)
7370 | GetRValue (foo
.pixel
));
7371 rgb
[1] = make_number ((GetGValue (foo
.pixel
) << 8)
7372 | GetGValue (foo
.pixel
));
7373 rgb
[2] = make_number ((GetBValue (foo
.pixel
) << 8)
7374 | GetBValue (foo
.pixel
));
7375 return Flist (3, rgb
);
7381 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
7382 "Internal function called by `display-color-p', which see.")
7384 Lisp_Object display
;
7386 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7388 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 2)
7394 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
7396 "Return t if the X display supports shades of gray.\n\
7397 Note that color displays do support shades of gray.\n\
7398 The optional argument DISPLAY specifies which display to ask about.\n\
7399 DISPLAY should be either a frame or a display name (a string).\n\
7400 If omitted or nil, that stands for the selected frame's display.")
7402 Lisp_Object display
;
7404 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7406 if ((dpyinfo
->n_planes
* dpyinfo
->n_cbits
) <= 1)
7412 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
7414 "Returns the width in pixels of the X display DISPLAY.\n\
7415 The optional argument DISPLAY specifies which display to ask about.\n\
7416 DISPLAY should be either a frame or a display name (a string).\n\
7417 If omitted or nil, that stands for the selected frame's display.")
7419 Lisp_Object display
;
7421 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7423 return make_number (dpyinfo
->width
);
7426 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
7427 Sx_display_pixel_height
, 0, 1, 0,
7428 "Returns the height in pixels of the X display DISPLAY.\n\
7429 The optional argument DISPLAY specifies which display to ask about.\n\
7430 DISPLAY should be either a frame or a display name (a string).\n\
7431 If omitted or nil, that stands for the selected frame's display.")
7433 Lisp_Object display
;
7435 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7437 return make_number (dpyinfo
->height
);
7440 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
7442 "Returns the number of bitplanes of the display DISPLAY.\n\
7443 The optional argument DISPLAY specifies which display to ask about.\n\
7444 DISPLAY should be either a frame or a display name (a string).\n\
7445 If omitted or nil, that stands for the selected frame's display.")
7447 Lisp_Object display
;
7449 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7451 return make_number (dpyinfo
->n_planes
* dpyinfo
->n_cbits
);
7454 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
7456 "Returns the number of color cells of the display DISPLAY.\n\
7457 The optional argument DISPLAY specifies which display to ask about.\n\
7458 DISPLAY should be either a frame or a display name (a string).\n\
7459 If omitted or nil, that stands for the selected frame's display.")
7461 Lisp_Object display
;
7463 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7467 hdc
= GetDC (dpyinfo
->root_window
);
7468 if (dpyinfo
->has_palette
)
7469 cap
= GetDeviceCaps (hdc
,SIZEPALETTE
);
7471 cap
= GetDeviceCaps (hdc
,NUMCOLORS
);
7473 /* We force 24+ bit depths to 24-bit, both to prevent an overflow
7474 and because probably is more meaningful on Windows anyway */
7476 cap
= 1 << min(dpyinfo
->n_planes
* dpyinfo
->n_cbits
, 24);
7478 ReleaseDC (dpyinfo
->root_window
, hdc
);
7480 return make_number (cap
);
7483 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
7484 Sx_server_max_request_size
,
7486 "Returns the maximum request size of the server of display DISPLAY.\n\
7487 The optional argument DISPLAY specifies which display to ask about.\n\
7488 DISPLAY should be either a frame or a display name (a string).\n\
7489 If omitted or nil, that stands for the selected frame's display.")
7491 Lisp_Object display
;
7493 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7495 return make_number (1);
7498 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
7499 "Returns the vendor ID string of the W32 system (Microsoft).\n\
7500 The optional argument DISPLAY specifies which display to ask about.\n\
7501 DISPLAY should be either a frame or a display name (a string).\n\
7502 If omitted or nil, that stands for the selected frame's display.")
7504 Lisp_Object display
;
7506 return build_string ("Microsoft Corp.");
7509 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
7510 "Returns the version numbers of the server of display DISPLAY.\n\
7511 The value is a list of three integers: the major and minor\n\
7512 version numbers, and the vendor-specific release\n\
7513 number. See also the function `x-server-vendor'.\n\n\
7514 The optional argument DISPLAY specifies which display to ask about.\n\
7515 DISPLAY should be either a frame or a display name (a string).\n\
7516 If omitted or nil, that stands for the selected frame's display.")
7518 Lisp_Object display
;
7520 return Fcons (make_number (w32_major_version
),
7521 Fcons (make_number (w32_minor_version
),
7522 Fcons (make_number (w32_build_number
), Qnil
)));
7525 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
7526 "Returns the number of screens on the server of display DISPLAY.\n\
7527 The optional argument DISPLAY specifies which display to ask about.\n\
7528 DISPLAY should be either a frame or a display name (a string).\n\
7529 If omitted or nil, that stands for the selected frame's display.")
7531 Lisp_Object display
;
7533 return make_number (1);
7536 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
7537 "Returns the height in millimeters of the X display DISPLAY.\n\
7538 The optional argument DISPLAY specifies which display to ask about.\n\
7539 DISPLAY should be either a frame or a display name (a string).\n\
7540 If omitted or nil, that stands for the selected frame's display.")
7542 Lisp_Object display
;
7544 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7548 hdc
= GetDC (dpyinfo
->root_window
);
7550 cap
= GetDeviceCaps (hdc
, VERTSIZE
);
7552 ReleaseDC (dpyinfo
->root_window
, hdc
);
7554 return make_number (cap
);
7557 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
7558 "Returns the width in millimeters of the X display DISPLAY.\n\
7559 The optional argument DISPLAY specifies which display to ask about.\n\
7560 DISPLAY should be either a frame or a display name (a string).\n\
7561 If omitted or nil, that stands for the selected frame's display.")
7563 Lisp_Object display
;
7565 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7570 hdc
= GetDC (dpyinfo
->root_window
);
7572 cap
= GetDeviceCaps (hdc
, HORZSIZE
);
7574 ReleaseDC (dpyinfo
->root_window
, hdc
);
7576 return make_number (cap
);
7579 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
7580 Sx_display_backing_store
, 0, 1, 0,
7581 "Returns an indication of whether display DISPLAY does backing store.\n\
7582 The value may be `always', `when-mapped', or `not-useful'.\n\
7583 The optional argument DISPLAY specifies which display to ask about.\n\
7584 DISPLAY should be either a frame or a display name (a string).\n\
7585 If omitted or nil, that stands for the selected frame's display.")
7587 Lisp_Object display
;
7589 return intern ("not-useful");
7592 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
7593 Sx_display_visual_class
, 0, 1, 0,
7594 "Returns the visual class of the display DISPLAY.\n\
7595 The value is one of the symbols `static-gray', `gray-scale',\n\
7596 `static-color', `pseudo-color', `true-color', or `direct-color'.\n\n\
7597 The optional argument DISPLAY specifies which display to ask about.\n\
7598 DISPLAY should be either a frame or a display name (a string).\n\
7599 If omitted or nil, that stands for the selected frame's display.")
7601 Lisp_Object display
;
7603 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7604 Lisp_Object result
= Qnil
;
7606 if (dpyinfo
->has_palette
)
7607 result
= intern ("pseudo-color");
7608 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 1)
7609 result
= intern ("static-grey");
7610 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
== 4)
7611 result
= intern ("static-color");
7612 else if (dpyinfo
->n_planes
* dpyinfo
->n_cbits
> 8)
7613 result
= intern ("true-color");
7618 DEFUN ("x-display-save-under", Fx_display_save_under
,
7619 Sx_display_save_under
, 0, 1, 0,
7620 "Returns t if the display DISPLAY supports the save-under feature.\n\
7621 The optional argument DISPLAY specifies which display to ask about.\n\
7622 DISPLAY should be either a frame or a display name (a string).\n\
7623 If omitted or nil, that stands for the selected frame's display.")
7625 Lisp_Object display
;
7632 register struct frame
*f
;
7634 return PIXEL_WIDTH (f
);
7639 register struct frame
*f
;
7641 return PIXEL_HEIGHT (f
);
7646 register struct frame
*f
;
7648 return FONT_WIDTH (f
->output_data
.w32
->font
);
7653 register struct frame
*f
;
7655 return f
->output_data
.w32
->line_height
;
7660 register struct frame
*f
;
7662 return FRAME_W32_DISPLAY_INFO (f
)->n_planes
;
7665 /* Return the display structure for the display named NAME.
7666 Open a new connection if necessary. */
7668 struct w32_display_info
*
7669 x_display_info_for_name (name
)
7673 struct w32_display_info
*dpyinfo
;
7675 CHECK_STRING (name
, 0);
7677 for (dpyinfo
= &one_w32_display_info
, names
= w32_display_name_list
;
7679 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
7682 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
7687 /* Use this general default value to start with. */
7688 Vx_resource_name
= Vinvocation_name
;
7690 validate_x_resource_name ();
7692 dpyinfo
= w32_term_init (name
, (unsigned char *)0,
7693 (char *) XSTRING (Vx_resource_name
)->data
);
7696 error ("Cannot connect to server %s", XSTRING (name
)->data
);
7699 XSETFASTINT (Vwindow_system_version
, 3);
7704 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
7705 1, 3, 0, "Open a connection to a server.\n\
7706 DISPLAY is the name of the display to connect to.\n\
7707 Optional second arg XRM-STRING is a string of resources in xrdb format.\n\
7708 If the optional third arg MUST-SUCCEED is non-nil,\n\
7709 terminate Emacs if we can't open the connection.")
7710 (display
, xrm_string
, must_succeed
)
7711 Lisp_Object display
, xrm_string
, must_succeed
;
7713 unsigned char *xrm_option
;
7714 struct w32_display_info
*dpyinfo
;
7716 /* If initialization has already been done, return now to avoid
7717 overwriting critical parts of one_w32_display_info. */
7721 CHECK_STRING (display
, 0);
7722 if (! NILP (xrm_string
))
7723 CHECK_STRING (xrm_string
, 1);
7725 if (! EQ (Vwindow_system
, intern ("w32")))
7726 error ("Not using Microsoft Windows");
7728 /* Allow color mapping to be defined externally; first look in user's
7729 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
7731 Lisp_Object color_file
;
7732 struct gcpro gcpro1
;
7734 color_file
= build_string("~/rgb.txt");
7736 GCPRO1 (color_file
);
7738 if (NILP (Ffile_readable_p (color_file
)))
7740 Fexpand_file_name (build_string ("rgb.txt"),
7741 Fsymbol_value (intern ("data-directory")));
7743 Vw32_color_map
= Fw32_load_color_file (color_file
);
7747 if (NILP (Vw32_color_map
))
7748 Vw32_color_map
= Fw32_default_color_map ();
7750 if (! NILP (xrm_string
))
7751 xrm_option
= (unsigned char *) XSTRING (xrm_string
)->data
;
7753 xrm_option
= (unsigned char *) 0;
7755 /* Use this general default value to start with. */
7756 /* First remove .exe suffix from invocation-name - it looks ugly. */
7758 char basename
[ MAX_PATH
], *str
;
7760 strcpy (basename
, XSTRING (Vinvocation_name
)->data
);
7761 str
= strrchr (basename
, '.');
7763 Vinvocation_name
= build_string (basename
);
7765 Vx_resource_name
= Vinvocation_name
;
7767 validate_x_resource_name ();
7769 /* This is what opens the connection and sets x_current_display.
7770 This also initializes many symbols, such as those used for input. */
7771 dpyinfo
= w32_term_init (display
, xrm_option
,
7772 (char *) XSTRING (Vx_resource_name
)->data
);
7776 if (!NILP (must_succeed
))
7777 fatal ("Cannot connect to server %s.\n",
7778 XSTRING (display
)->data
);
7780 error ("Cannot connect to server %s", XSTRING (display
)->data
);
7785 XSETFASTINT (Vwindow_system_version
, 3);
7789 DEFUN ("x-close-connection", Fx_close_connection
,
7790 Sx_close_connection
, 1, 1, 0,
7791 "Close the connection to DISPLAY's server.\n\
7792 For DISPLAY, specify either a frame or a display name (a string).\n\
7793 If DISPLAY is nil, that stands for the selected frame's display.")
7795 Lisp_Object display
;
7797 struct w32_display_info
*dpyinfo
= check_x_display_info (display
);
7800 if (dpyinfo
->reference_count
> 0)
7801 error ("Display still has frames on it");
7804 /* Free the fonts in the font table. */
7805 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
7806 if (dpyinfo
->font_table
[i
].name
)
7808 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
7809 xfree (dpyinfo
->font_table
[i
].full_name
);
7810 xfree (dpyinfo
->font_table
[i
].name
);
7811 w32_unload_font (dpyinfo
, dpyinfo
->font_table
[i
].font
);
7813 x_destroy_all_bitmaps (dpyinfo
);
7815 x_delete_display (dpyinfo
);
7821 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
7822 "Return the list of display names that Emacs has connections to.")
7825 Lisp_Object tail
, result
;
7828 for (tail
= w32_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
7829 result
= Fcons (XCAR (XCAR (tail
)), result
);
7834 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
7835 "If ON is non-nil, report errors as soon as the erring request is made.\n\
7836 If ON is nil, allow buffering of requests.\n\
7837 This is a noop on W32 systems.\n\
7838 The optional second argument DISPLAY specifies which display to act on.\n\
7839 DISPLAY should be either a frame or a display name (a string).\n\
7840 If DISPLAY is omitted or nil, that stands for the selected frame's display.")
7842 Lisp_Object display
, on
;
7849 /***********************************************************************
7851 ***********************************************************************/
7853 /* Value is the number of elements of vector VECTOR. */
7855 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
7857 /* List of supported image types. Use define_image_type to add new
7858 types. Use lookup_image_type to find a type for a given symbol. */
7860 static struct image_type
*image_types
;
7862 /* The symbol `image' which is the car of the lists used to represent
7865 extern Lisp_Object Qimage
;
7867 /* The symbol `xbm' which is used as the type symbol for XBM images. */
7873 extern Lisp_Object QCwidth
, QCheight
, QCforeground
, QCbackground
, QCfile
;
7874 extern Lisp_Object QCdata
;
7875 Lisp_Object QCtype
, QCascent
, QCmargin
, QCrelief
;
7876 Lisp_Object QCconversion
, QCcolor_symbols
, QCheuristic_mask
;
7877 Lisp_Object QCindex
;
7879 /* Other symbols. */
7881 Lisp_Object Qlaplace
;
7883 /* Time in seconds after which images should be removed from the cache
7884 if not displayed. */
7886 Lisp_Object Vimage_cache_eviction_delay
;
7888 /* Function prototypes. */
7890 static void define_image_type
P_ ((struct image_type
*type
));
7891 static struct image_type
*lookup_image_type
P_ ((Lisp_Object symbol
));
7892 static void image_error
P_ ((char *format
, Lisp_Object
, Lisp_Object
));
7893 static void x_laplace
P_ ((struct frame
*, struct image
*));
7894 static int x_build_heuristic_mask
P_ ((struct frame
*, struct image
*,
7898 /* Define a new image type from TYPE. This adds a copy of TYPE to
7899 image_types and adds the symbol *TYPE->type to Vimage_types. */
7902 define_image_type (type
)
7903 struct image_type
*type
;
7905 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
7906 The initialized data segment is read-only. */
7907 struct image_type
*p
= (struct image_type
*) xmalloc (sizeof *p
);
7908 bcopy (type
, p
, sizeof *p
);
7909 p
->next
= image_types
;
7911 Vimage_types
= Fcons (*p
->type
, Vimage_types
);
7915 /* Look up image type SYMBOL, and return a pointer to its image_type
7916 structure. Value is null if SYMBOL is not a known image type. */
7918 static INLINE
struct image_type
*
7919 lookup_image_type (symbol
)
7922 struct image_type
*type
;
7924 for (type
= image_types
; type
; type
= type
->next
)
7925 if (EQ (symbol
, *type
->type
))
7932 /* Value is non-zero if OBJECT is a valid Lisp image specification. A
7933 valid image specification is a list whose car is the symbol
7934 `image', and whose rest is a property list. The property list must
7935 contain a value for key `:type'. That value must be the name of a
7936 supported image type. The rest of the property list depends on the
7940 valid_image_p (object
)
7945 if (CONSP (object
) && EQ (XCAR (object
), Qimage
))
7947 Lisp_Object symbol
= Fplist_get (XCDR (object
), QCtype
);
7948 struct image_type
*type
= lookup_image_type (symbol
);
7951 valid_p
= type
->valid_p (object
);
7958 /* Log error message with format string FORMAT and argument ARG.
7959 Signaling an error, e.g. when an image cannot be loaded, is not a
7960 good idea because this would interrupt redisplay, and the error
7961 message display would lead to another redisplay. This function
7962 therefore simply displays a message. */
7965 image_error (format
, arg1
, arg2
)
7967 Lisp_Object arg1
, arg2
;
7969 add_to_log (format
, arg1
, arg2
);
7974 /***********************************************************************
7975 Image specifications
7976 ***********************************************************************/
7978 enum image_value_type
7980 IMAGE_DONT_CHECK_VALUE_TYPE
,
7983 IMAGE_POSITIVE_INTEGER_VALUE
,
7984 IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
,
7985 IMAGE_NON_NEGATIVE_INTEGER_VALUE
,
7987 IMAGE_INTEGER_VALUE
,
7988 IMAGE_FUNCTION_VALUE
,
7993 /* Structure used when parsing image specifications. */
7995 struct image_keyword
7997 /* Name of keyword. */
8000 /* The type of value allowed. */
8001 enum image_value_type type
;
8003 /* Non-zero means key must be present. */
8006 /* Used to recognize duplicate keywords in a property list. */
8009 /* The value that was found. */
8014 static int parse_image_spec
P_ ((Lisp_Object
, struct image_keyword
*,
8016 static Lisp_Object image_spec_value
P_ ((Lisp_Object
, Lisp_Object
, int *));
8019 /* Parse image spec SPEC according to KEYWORDS. A valid image spec
8020 has the format (image KEYWORD VALUE ...). One of the keyword/
8021 value pairs must be `:type TYPE'. KEYWORDS is a vector of
8022 image_keywords structures of size NKEYWORDS describing other
8023 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */
8026 parse_image_spec (spec
, keywords
, nkeywords
, type
)
8028 struct image_keyword
*keywords
;
8035 if (!CONSP (spec
) || !EQ (XCAR (spec
), Qimage
))
8038 plist
= XCDR (spec
);
8039 while (CONSP (plist
))
8041 Lisp_Object key
, value
;
8043 /* First element of a pair must be a symbol. */
8045 plist
= XCDR (plist
);
8049 /* There must follow a value. */
8052 value
= XCAR (plist
);
8053 plist
= XCDR (plist
);
8055 /* Find key in KEYWORDS. Error if not found. */
8056 for (i
= 0; i
< nkeywords
; ++i
)
8057 if (strcmp (keywords
[i
].name
, XSYMBOL (key
)->name
->data
) == 0)
8063 /* Record that we recognized the keyword. If a keywords
8064 was found more than once, it's an error. */
8065 keywords
[i
].value
= value
;
8066 ++keywords
[i
].count
;
8068 if (keywords
[i
].count
> 1)
8071 /* Check type of value against allowed type. */
8072 switch (keywords
[i
].type
)
8074 case IMAGE_STRING_VALUE
:
8075 if (!STRINGP (value
))
8079 case IMAGE_SYMBOL_VALUE
:
8080 if (!SYMBOLP (value
))
8084 case IMAGE_POSITIVE_INTEGER_VALUE
:
8085 if (!INTEGERP (value
) || XINT (value
) <= 0)
8089 case IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
:
8090 if (INTEGERP (value
) && XINT (value
) >= 0)
8093 && INTEGERP (XCAR (value
)) && INTEGERP (XCDR (value
))
8094 && XINT (XCAR (value
)) >= 0 && XINT (XCDR (value
)) >= 0)
8098 case IMAGE_ASCENT_VALUE
:
8099 if (SYMBOLP (value
) && EQ (value
, Qcenter
))
8101 else if (INTEGERP (value
)
8102 && XINT (value
) >= 0
8103 && XINT (value
) <= 100)
8107 case IMAGE_NON_NEGATIVE_INTEGER_VALUE
:
8108 if (!INTEGERP (value
) || XINT (value
) < 0)
8112 case IMAGE_DONT_CHECK_VALUE_TYPE
:
8115 case IMAGE_FUNCTION_VALUE
:
8116 value
= indirect_function (value
);
8118 || COMPILEDP (value
)
8119 || (CONSP (value
) && EQ (XCAR (value
), Qlambda
)))
8123 case IMAGE_NUMBER_VALUE
:
8124 if (!INTEGERP (value
) && !FLOATP (value
))
8128 case IMAGE_INTEGER_VALUE
:
8129 if (!INTEGERP (value
))
8133 case IMAGE_BOOL_VALUE
:
8134 if (!NILP (value
) && !EQ (value
, Qt
))
8143 if (EQ (key
, QCtype
) && !EQ (type
, value
))
8147 /* Check that all mandatory fields are present. */
8148 for (i
= 0; i
< nkeywords
; ++i
)
8149 if (keywords
[i
].mandatory_p
&& keywords
[i
].count
== 0)
8152 return NILP (plist
);
8156 /* Return the value of KEY in image specification SPEC. Value is nil
8157 if KEY is not present in SPEC. if FOUND is not null, set *FOUND
8158 to 1 if KEY was found in SPEC, set it to 0 otherwise. */
8161 image_spec_value (spec
, key
, found
)
8162 Lisp_Object spec
, key
;
8167 xassert (valid_image_p (spec
));
8169 for (tail
= XCDR (spec
);
8170 CONSP (tail
) && CONSP (XCDR (tail
));
8171 tail
= XCDR (XCDR (tail
)))
8173 if (EQ (XCAR (tail
), key
))
8177 return XCAR (XCDR (tail
));
8189 /***********************************************************************
8190 Image type independent image structures
8191 ***********************************************************************/
8193 static struct image
*make_image
P_ ((Lisp_Object spec
, unsigned hash
));
8194 static void free_image
P_ ((struct frame
*f
, struct image
*img
));
8197 /* Allocate and return a new image structure for image specification
8198 SPEC. SPEC has a hash value of HASH. */
8200 static struct image
*
8201 make_image (spec
, hash
)
8205 struct image
*img
= (struct image
*) xmalloc (sizeof *img
);
8207 xassert (valid_image_p (spec
));
8208 bzero (img
, sizeof *img
);
8209 img
->type
= lookup_image_type (image_spec_value (spec
, QCtype
, NULL
));
8210 xassert (img
->type
!= NULL
);
8212 img
->data
.lisp_val
= Qnil
;
8213 img
->ascent
= DEFAULT_IMAGE_ASCENT
;
8219 /* Free image IMG which was used on frame F, including its resources. */
8228 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8230 /* Remove IMG from the hash table of its cache. */
8232 img
->prev
->next
= img
->next
;
8234 c
->buckets
[img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
] = img
->next
;
8237 img
->next
->prev
= img
->prev
;
8239 c
->images
[img
->id
] = NULL
;
8241 /* Free resources, then free IMG. */
8242 img
->type
->free (f
, img
);
8248 /* Prepare image IMG for display on frame F. Must be called before
8249 drawing an image. */
8252 prepare_image_for_display (f
, img
)
8258 /* We're about to display IMG, so set its timestamp to `now'. */
8260 img
->timestamp
= EMACS_SECS (t
);
8262 /* If IMG doesn't have a pixmap yet, load it now, using the image
8263 type dependent loader function. */
8264 if (img
->pixmap
== 0 && !img
->load_failed_p
)
8265 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
8269 /* Value is the number of pixels for the ascent of image IMG when
8270 drawn in face FACE. */
8273 image_ascent (img
, face
)
8277 int height
= img
->height
+ img
->vmargin
;
8280 if (img
->ascent
== CENTERED_IMAGE_ASCENT
)
8283 ascent
= height
/ 2 - (FONT_DESCENT(face
->font
)
8284 - FONT_BASE(face
->font
)) / 2;
8286 ascent
= height
/ 2;
8289 ascent
= height
* img
->ascent
/ 100.0;
8296 /***********************************************************************
8297 Helper functions for X image types
8298 ***********************************************************************/
8300 static void x_clear_image
P_ ((struct frame
*f
, struct image
*img
));
8301 static unsigned long x_alloc_image_color
P_ ((struct frame
*f
,
8303 Lisp_Object color_name
,
8304 unsigned long dflt
));
8306 /* Free X resources of image IMG which is used on frame F. */
8309 x_clear_image (f
, img
)
8313 #if 0 /* TODO: W32 image support */
8318 XFreePixmap (NULL
, img
->pixmap
);
8325 int class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
8327 /* If display has an immutable color map, freeing colors is not
8328 necessary and some servers don't allow it. So don't do it. */
8329 if (class != StaticColor
8330 && class != StaticGray
8331 && class != TrueColor
)
8335 cmap
= DefaultColormapOfScreen (FRAME_W32_DISPLAY_INFO (f
)->screen
);
8336 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
, img
->colors
,
8341 xfree (img
->colors
);
8349 /* Allocate color COLOR_NAME for image IMG on frame F. If color
8350 cannot be allocated, use DFLT. Add a newly allocated color to
8351 IMG->colors, so that it can be freed again. Value is the pixel
8354 static unsigned long
8355 x_alloc_image_color (f
, img
, color_name
, dflt
)
8358 Lisp_Object color_name
;
8361 #if 0 /* TODO: allocing colors. */
8363 unsigned long result
;
8365 xassert (STRINGP (color_name
));
8367 if (w32_defined_color (f
, XSTRING (color_name
)->data
, &color
, 1))
8369 /* This isn't called frequently so we get away with simply
8370 reallocating the color vector to the needed size, here. */
8373 (unsigned long *) xrealloc (img
->colors
,
8374 img
->ncolors
* sizeof *img
->colors
);
8375 img
->colors
[img
->ncolors
- 1] = color
.pixel
;
8376 result
= color
.pixel
;
8387 /***********************************************************************
8389 ***********************************************************************/
8391 static void cache_image
P_ ((struct frame
*f
, struct image
*img
));
8394 /* Return a new, initialized image cache that is allocated from the
8395 heap. Call free_image_cache to free an image cache. */
8397 struct image_cache
*
8400 struct image_cache
*c
= (struct image_cache
*) xmalloc (sizeof *c
);
8403 bzero (c
, sizeof *c
);
8405 c
->images
= (struct image
**) xmalloc (c
->size
* sizeof *c
->images
);
8406 size
= IMAGE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
8407 c
->buckets
= (struct image
**) xmalloc (size
);
8408 bzero (c
->buckets
, size
);
8413 /* Free image cache of frame F. Be aware that X frames share images
8417 free_image_cache (f
)
8420 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8425 /* Cache should not be referenced by any frame when freed. */
8426 xassert (c
->refcount
== 0);
8428 for (i
= 0; i
< c
->used
; ++i
)
8429 free_image (f
, c
->images
[i
]);
8433 FRAME_X_IMAGE_CACHE (f
) = NULL
;
8438 /* Clear image cache of frame F. FORCE_P non-zero means free all
8439 images. FORCE_P zero means clear only images that haven't been
8440 displayed for some time. Should be called from time to time to
8441 reduce the number of loaded images. If image-eviction-seconds is
8442 non-nil, this frees images in the cache which weren't displayed for
8443 at least that many seconds. */
8446 clear_image_cache (f
, force_p
)
8450 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8452 if (c
&& INTEGERP (Vimage_cache_eviction_delay
))
8456 int i
, any_freed_p
= 0;
8459 old
= EMACS_SECS (t
) - XFASTINT (Vimage_cache_eviction_delay
);
8461 for (i
= 0; i
< c
->used
; ++i
)
8463 struct image
*img
= c
->images
[i
];
8466 || (img
->timestamp
> old
)))
8468 free_image (f
, img
);
8473 /* We may be clearing the image cache because, for example,
8474 Emacs was iconified for a longer period of time. In that
8475 case, current matrices may still contain references to
8476 images freed above. So, clear these matrices. */
8479 clear_current_matrices (f
);
8480 ++windows_or_buffers_changed
;
8486 DEFUN ("clear-image-cache", Fclear_image_cache
, Sclear_image_cache
,
8488 "Clear the image cache of FRAME.\n\
8489 FRAME nil or omitted means use the selected frame.\n\
8490 FRAME t means clear the image caches of all frames.")
8498 FOR_EACH_FRAME (tail
, frame
)
8499 if (FRAME_W32_P (XFRAME (frame
)))
8500 clear_image_cache (XFRAME (frame
), 1);
8503 clear_image_cache (check_x_frame (frame
), 1);
8509 /* Return the id of image with Lisp specification SPEC on frame F.
8510 SPEC must be a valid Lisp image specification (see valid_image_p). */
8513 lookup_image (f
, spec
)
8517 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8521 struct gcpro gcpro1
;
8524 /* F must be a window-system frame, and SPEC must be a valid image
8526 xassert (FRAME_WINDOW_P (f
));
8527 xassert (valid_image_p (spec
));
8531 /* Look up SPEC in the hash table of the image cache. */
8532 hash
= sxhash (spec
, 0);
8533 i
= hash
% IMAGE_CACHE_BUCKETS_SIZE
;
8535 for (img
= c
->buckets
[i
]; img
; img
= img
->next
)
8536 if (img
->hash
== hash
&& !NILP (Fequal (img
->spec
, spec
)))
8539 /* If not found, create a new image and cache it. */
8543 img
= make_image (spec
, hash
);
8544 cache_image (f
, img
);
8545 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
8547 /* If we can't load the image, and we don't have a width and
8548 height, use some arbitrary width and height so that we can
8549 draw a rectangle for it. */
8550 if (img
->load_failed_p
)
8554 value
= image_spec_value (spec
, QCwidth
, NULL
);
8555 img
->width
= (INTEGERP (value
)
8556 ? XFASTINT (value
) : DEFAULT_IMAGE_WIDTH
);
8557 value
= image_spec_value (spec
, QCheight
, NULL
);
8558 img
->height
= (INTEGERP (value
)
8559 ? XFASTINT (value
) : DEFAULT_IMAGE_HEIGHT
);
8563 /* Handle image type independent image attributes
8564 `:ascent PERCENT', `:margin MARGIN', `:relief RELIEF'. */
8565 Lisp_Object ascent
, margin
, relief
;
8567 ascent
= image_spec_value (spec
, QCascent
, NULL
);
8568 if (INTEGERP (ascent
))
8569 img
->ascent
= XFASTINT (ascent
);
8570 else if (EQ (ascent
, Qcenter
))
8571 img
->ascent
= CENTERED_IMAGE_ASCENT
;
8573 margin
= image_spec_value (spec
, QCmargin
, NULL
);
8574 if (INTEGERP (margin
) && XINT (margin
) >= 0)
8575 img
->vmargin
= img
->hmargin
= XFASTINT (margin
);
8576 else if (CONSP (margin
) && INTEGERP (XCAR (margin
))
8577 && INTEGERP (XCDR (margin
)))
8579 if (XINT (XCAR (margin
)) > 0)
8580 img
->hmargin
= XFASTINT (XCAR (margin
));
8581 if (XINT (XCDR (margin
)) > 0)
8582 img
->vmargin
= XFASTINT (XCDR (margin
));
8585 relief
= image_spec_value (spec
, QCrelief
, NULL
);
8586 if (INTEGERP (relief
))
8588 img
->relief
= XINT (relief
);
8589 img
->hmargin
+= abs (img
->relief
);
8590 img
->vmargin
+= abs (img
->relief
);
8593 #if 0 /* TODO: image mask and algorithm. */
8594 /* Manipulation of the image's mask. */
8597 /* `:heuristic-mask t'
8599 means build a mask heuristically.
8600 `:heuristic-mask (R G B)'
8601 `:mask (heuristic (R G B))'
8602 means build a mask from color (R G B) in the
8605 means remove a mask, if any. */
8609 mask
= image_spec_value (spec
, QCheuristic_mask
, NULL
);
8611 x_build_heuristic_mask (f
, img
, mask
);
8616 mask
= image_spec_value (spec
, QCmask
, &found_p
);
8618 if (EQ (mask
, Qheuristic
))
8619 x_build_heuristic_mask (f
, img
, Qt
);
8620 else if (CONSP (mask
)
8621 && EQ (XCAR (mask
), Qheuristic
))
8623 if (CONSP (XCDR (mask
)))
8624 x_build_heuristic_mask (f
, img
, XCAR (XCDR (mask
)));
8626 x_build_heuristic_mask (f
, img
, XCDR (mask
));
8628 else if (NILP (mask
) && found_p
&& img
->mask
)
8630 XFreePixmap (FRAME_X_DISPLAY (f
), img
->mask
);
8636 /* Should we apply an image transformation algorithm? */
8639 Lisp_Object conversion
;
8641 algorithm
= image_spec_value (spec
, QCconversion
, NULL
);
8642 if (EQ (conversion
, Qdisabled
))
8643 x_disable_image (f
, img
);
8644 else if (EQ (conversion
, Qlaplace
))
8646 else if (EQ (conversion
, Qemboss
))
8648 else if (CONSP (conversion
)
8649 && EQ (XCAR (conversion
), Qedge_detection
))
8652 tem
= XCDR (conversion
);
8654 x_edge_detection (f
, img
,
8655 Fplist_get (tem
, QCmatrix
),
8656 Fplist_get (tem
, QCcolor_adjustment
));
8662 xassert (!interrupt_input_blocked
);
8665 /* We're using IMG, so set its timestamp to `now'. */
8666 EMACS_GET_TIME (now
);
8667 img
->timestamp
= EMACS_SECS (now
);
8671 /* Value is the image id. */
8676 /* Cache image IMG in the image cache of frame F. */
8679 cache_image (f
, img
)
8683 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8686 /* Find a free slot in c->images. */
8687 for (i
= 0; i
< c
->used
; ++i
)
8688 if (c
->images
[i
] == NULL
)
8691 /* If no free slot found, maybe enlarge c->images. */
8692 if (i
== c
->used
&& c
->used
== c
->size
)
8695 c
->images
= (struct image
**) xrealloc (c
->images
,
8696 c
->size
* sizeof *c
->images
);
8699 /* Add IMG to c->images, and assign IMG an id. */
8705 /* Add IMG to the cache's hash table. */
8706 i
= img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
;
8707 img
->next
= c
->buckets
[i
];
8709 img
->next
->prev
= img
;
8711 c
->buckets
[i
] = img
;
8715 /* Call FN on every image in the image cache of frame F. Used to mark
8716 Lisp Objects in the image cache. */
8719 forall_images_in_image_cache (f
, fn
)
8721 void (*fn
) P_ ((struct image
*img
));
8723 if (FRAME_LIVE_P (f
) && FRAME_W32_P (f
))
8725 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
8729 for (i
= 0; i
< c
->used
; ++i
)
8738 /***********************************************************************
8740 ***********************************************************************/
8742 #if 0 /* TODO: W32 specific image code. */
8744 static int x_create_x_image_and_pixmap
P_ ((struct frame
*, int, int, int,
8745 XImage
**, Pixmap
*));
8746 static void x_destroy_x_image
P_ ((XImage
*));
8747 static void x_put_x_image
P_ ((struct frame
*, XImage
*, Pixmap
, int, int));
8750 /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on
8751 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
8752 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
8753 via xmalloc. Print error messages via image_error if an error
8754 occurs. Value is non-zero if successful. */
8757 x_create_x_image_and_pixmap (f
, width
, height
, depth
, ximg
, pixmap
)
8759 int width
, height
, depth
;
8763 #if 0 /* TODO: Image support for W32 */
8764 Display
*display
= FRAME_W32_DISPLAY (f
);
8765 Screen
*screen
= FRAME_X_SCREEN (f
);
8766 Window window
= FRAME_W32_WINDOW (f
);
8768 xassert (interrupt_input_blocked
);
8771 depth
= DefaultDepthOfScreen (screen
);
8772 *ximg
= XCreateImage (display
, DefaultVisualOfScreen (screen
),
8773 depth
, ZPixmap
, 0, NULL
, width
, height
,
8774 depth
> 16 ? 32 : depth
> 8 ? 16 : 8, 0);
8777 image_error ("Unable to allocate X image", Qnil
, Qnil
);
8781 /* Allocate image raster. */
8782 (*ximg
)->data
= (char *) xmalloc ((*ximg
)->bytes_per_line
* height
);
8784 /* Allocate a pixmap of the same size. */
8785 *pixmap
= XCreatePixmap (display
, window
, width
, height
, depth
);
8788 x_destroy_x_image (*ximg
);
8790 image_error ("Unable to create X pixmap", Qnil
, Qnil
);
8798 /* Destroy XImage XIMG. Free XIMG->data. */
8801 x_destroy_x_image (ximg
)
8804 xassert (interrupt_input_blocked
);
8809 XDestroyImage (ximg
);
8814 /* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT
8815 are width and height of both the image and pixmap. */
8818 x_put_x_image (f
, ximg
, pixmap
, width
, height
)
8825 xassert (interrupt_input_blocked
);
8826 gc
= XCreateGC (NULL
, pixmap
, 0, NULL
);
8827 XPutImage (NULL
, pixmap
, gc
, ximg
, 0, 0, 0, 0, width
, height
);
8834 /***********************************************************************
8836 ***********************************************************************/
8838 static Lisp_Object x_find_image_file
P_ ((Lisp_Object
));
8840 /* Find image file FILE. Look in data-directory, then
8841 x-bitmap-file-path. Value is the full name of the file found, or
8842 nil if not found. */
8845 x_find_image_file (file
)
8848 Lisp_Object file_found
, search_path
;
8849 struct gcpro gcpro1
, gcpro2
;
8853 search_path
= Fcons (Vdata_directory
, Vx_bitmap_file_path
);
8854 GCPRO2 (file_found
, search_path
);
8856 /* Try to find FILE in data-directory, then x-bitmap-file-path. */
8857 fd
= openp (search_path
, file
, "", &file_found
, 0);
8870 /***********************************************************************
8872 ***********************************************************************/
8874 static int xbm_load
P_ ((struct frame
*f
, struct image
*img
));
8875 static int xbm_load_image_from_file
P_ ((struct frame
*f
, struct image
*img
,
8877 static int xbm_image_p
P_ ((Lisp_Object object
));
8878 static int xbm_read_bitmap_file_data
P_ ((char *, int *, int *,
8882 /* Indices of image specification fields in xbm_format, below. */
8884 enum xbm_keyword_index
8901 /* Vector of image_keyword structures describing the format
8902 of valid XBM image specifications. */
8904 static struct image_keyword xbm_format
[XBM_LAST
] =
8906 {":type", IMAGE_SYMBOL_VALUE
, 1},
8907 {":file", IMAGE_STRING_VALUE
, 0},
8908 {":width", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8909 {":height", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
8910 {":data", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8911 {":foreground", IMAGE_STRING_VALUE
, 0},
8912 {":background", IMAGE_STRING_VALUE
, 0},
8913 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
8914 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
8915 {":relief", IMAGE_INTEGER_VALUE
, 0},
8916 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8917 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
8920 /* Structure describing the image type XBM. */
8922 static struct image_type xbm_type
=
8931 /* Tokens returned from xbm_scan. */
8940 /* Return non-zero if OBJECT is a valid XBM-type image specification.
8941 A valid specification is a list starting with the symbol `image'
8942 The rest of the list is a property list which must contain an
8945 If the specification specifies a file to load, it must contain
8946 an entry `:file FILENAME' where FILENAME is a string.
8948 If the specification is for a bitmap loaded from memory it must
8949 contain `:width WIDTH', `:height HEIGHT', and `:data DATA', where
8950 WIDTH and HEIGHT are integers > 0. DATA may be:
8952 1. a string large enough to hold the bitmap data, i.e. it must
8953 have a size >= (WIDTH + 7) / 8 * HEIGHT
8955 2. a bool-vector of size >= WIDTH * HEIGHT
8957 3. a vector of strings or bool-vectors, one for each line of the
8960 Both the file and data forms may contain the additional entries
8961 `:background COLOR' and `:foreground COLOR'. If not present,
8962 foreground and background of the frame on which the image is
8963 displayed, is used. */
8966 xbm_image_p (object
)
8969 struct image_keyword kw
[XBM_LAST
];
8971 bcopy (xbm_format
, kw
, sizeof kw
);
8972 if (!parse_image_spec (object
, kw
, XBM_LAST
, Qxbm
))
8975 xassert (EQ (kw
[XBM_TYPE
].value
, Qxbm
));
8977 if (kw
[XBM_FILE
].count
)
8979 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_DATA
].count
)
8987 /* Entries for `:width', `:height' and `:data' must be present. */
8988 if (!kw
[XBM_WIDTH
].count
8989 || !kw
[XBM_HEIGHT
].count
8990 || !kw
[XBM_DATA
].count
)
8993 data
= kw
[XBM_DATA
].value
;
8994 width
= XFASTINT (kw
[XBM_WIDTH
].value
);
8995 height
= XFASTINT (kw
[XBM_HEIGHT
].value
);
8997 /* Check type of data, and width and height against contents of
9003 /* Number of elements of the vector must be >= height. */
9004 if (XVECTOR (data
)->size
< height
)
9007 /* Each string or bool-vector in data must be large enough
9008 for one line of the image. */
9009 for (i
= 0; i
< height
; ++i
)
9011 Lisp_Object elt
= XVECTOR (data
)->contents
[i
];
9015 if (XSTRING (elt
)->size
9016 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
)
9019 else if (BOOL_VECTOR_P (elt
))
9021 if (XBOOL_VECTOR (elt
)->size
< width
)
9028 else if (STRINGP (data
))
9030 if (XSTRING (data
)->size
9031 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
* height
)
9034 else if (BOOL_VECTOR_P (data
))
9036 if (XBOOL_VECTOR (data
)->size
< width
* height
)
9043 /* Baseline must be a value between 0 and 100 (a percentage). */
9044 if (kw
[XBM_ASCENT
].count
9045 && XFASTINT (kw
[XBM_ASCENT
].value
) > 100)
9052 /* Scan a bitmap file. FP is the stream to read from. Value is
9053 either an enumerator from enum xbm_token, or a character for a
9054 single-character token, or 0 at end of file. If scanning an
9055 identifier, store the lexeme of the identifier in SVAL. If
9056 scanning a number, store its value in *IVAL. */
9059 xbm_scan (fp
, sval
, ival
)
9066 /* Skip white space. */
9067 while ((c
= fgetc (fp
)) != EOF
&& isspace (c
))
9072 else if (isdigit (c
))
9074 int value
= 0, digit
;
9079 if (c
== 'x' || c
== 'X')
9081 while ((c
= fgetc (fp
)) != EOF
)
9085 else if (c
>= 'a' && c
<= 'f')
9086 digit
= c
- 'a' + 10;
9087 else if (c
>= 'A' && c
<= 'F')
9088 digit
= c
- 'A' + 10;
9091 value
= 16 * value
+ digit
;
9094 else if (isdigit (c
))
9097 while ((c
= fgetc (fp
)) != EOF
9099 value
= 8 * value
+ c
- '0';
9105 while ((c
= fgetc (fp
)) != EOF
9107 value
= 10 * value
+ c
- '0';
9115 else if (isalpha (c
) || c
== '_')
9118 while ((c
= fgetc (fp
)) != EOF
9119 && (isalnum (c
) || c
== '_'))
9131 /* Replacement for XReadBitmapFileData which isn't available under old
9132 X versions. FILE is the name of the bitmap file to read. Set
9133 *WIDTH and *HEIGHT to the width and height of the image. Return in
9134 *DATA the bitmap data allocated with xmalloc. Value is non-zero if
9138 xbm_read_bitmap_file_data (file
, width
, height
, data
)
9140 int *width
, *height
;
9141 unsigned char **data
;
9144 char buffer
[BUFSIZ
];
9147 int bytes_per_line
, i
, nbytes
;
9153 LA1 = xbm_scan (fp, buffer, &value)
9155 #define expect(TOKEN) \
9156 if (LA1 != (TOKEN)) \
9161 #define expect_ident(IDENT) \
9162 if (LA1 == XBM_TK_IDENT && strcmp (buffer, (IDENT)) == 0) \
9167 fp
= fopen (file
, "r");
9171 *width
= *height
= -1;
9173 LA1
= xbm_scan (fp
, buffer
, &value
);
9175 /* Parse defines for width, height and hot-spots. */
9179 expect_ident ("define");
9180 expect (XBM_TK_IDENT
);
9182 if (LA1
== XBM_TK_NUMBER
);
9184 char *p
= strrchr (buffer
, '_');
9185 p
= p
? p
+ 1 : buffer
;
9186 if (strcmp (p
, "width") == 0)
9188 else if (strcmp (p
, "height") == 0)
9191 expect (XBM_TK_NUMBER
);
9194 if (*width
< 0 || *height
< 0)
9197 /* Parse bits. Must start with `static'. */
9198 expect_ident ("static");
9199 if (LA1
== XBM_TK_IDENT
)
9201 if (strcmp (buffer
, "unsigned") == 0)
9204 expect_ident ("char");
9206 else if (strcmp (buffer
, "short") == 0)
9210 if (*width
% 16 && *width
% 16 < 9)
9213 else if (strcmp (buffer
, "char") == 0)
9221 expect (XBM_TK_IDENT
);
9227 bytes_per_line
= (*width
+ 7) / 8 + padding_p
;
9228 nbytes
= bytes_per_line
* *height
;
9229 p
= *data
= (char *) xmalloc (nbytes
);
9234 for (i
= 0; i
< nbytes
; i
+= 2)
9237 expect (XBM_TK_NUMBER
);
9240 if (!padding_p
|| ((i
+ 2) % bytes_per_line
))
9243 if (LA1
== ',' || LA1
== '}')
9251 for (i
= 0; i
< nbytes
; ++i
)
9254 expect (XBM_TK_NUMBER
);
9258 if (LA1
== ',' || LA1
== '}')
9284 /* Load XBM image IMG which will be displayed on frame F from file
9285 SPECIFIED_FILE. Value is non-zero if successful. */
9288 xbm_load_image_from_file (f
, img
, specified_file
)
9291 Lisp_Object specified_file
;
9294 unsigned char *data
;
9297 struct gcpro gcpro1
;
9299 xassert (STRINGP (specified_file
));
9303 file
= x_find_image_file (specified_file
);
9304 if (!STRINGP (file
))
9306 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9311 rc
= xbm_read_bitmap_file_data (XSTRING (file
)->data
, &img
->width
,
9312 &img
->height
, &data
);
9315 int depth
= one_w32_display_info
.n_cbits
;
9316 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
9317 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
9320 xassert (img
->width
> 0 && img
->height
> 0);
9322 /* Get foreground and background colors, maybe allocate colors. */
9323 value
= image_spec_value (img
->spec
, QCforeground
, NULL
);
9325 foreground
= x_alloc_image_color (f
, img
, value
, foreground
);
9327 value
= image_spec_value (img
->spec
, QCbackground
, NULL
);
9329 background
= x_alloc_image_color (f
, img
, value
, background
);
9331 #if 0 /* TODO : Port image display to W32 */
9334 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
9335 FRAME_W32_WINDOW (f
),
9337 img
->width
, img
->height
,
9338 foreground
, background
,
9342 if (img
->pixmap
== 0)
9344 x_clear_image (f
, img
);
9345 image_error ("Unable to create X pixmap for `%s'", file
, Qnil
);
9354 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
9361 /* Fill image IMG which is used on frame F with pixmap data. Value is
9362 non-zero if successful. */
9370 Lisp_Object file_name
;
9372 xassert (xbm_image_p (img
->spec
));
9374 /* If IMG->spec specifies a file name, create a non-file spec from it. */
9375 file_name
= image_spec_value (img
->spec
, QCfile
, NULL
);
9376 if (STRINGP (file_name
))
9377 success_p
= xbm_load_image_from_file (f
, img
, file_name
);
9380 struct image_keyword fmt
[XBM_LAST
];
9383 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
9384 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
9388 /* Parse the list specification. */
9389 bcopy (xbm_format
, fmt
, sizeof fmt
);
9390 parsed_p
= parse_image_spec (img
->spec
, fmt
, XBM_LAST
, Qxbm
);
9393 /* Get specified width, and height. */
9394 img
->width
= XFASTINT (fmt
[XBM_WIDTH
].value
);
9395 img
->height
= XFASTINT (fmt
[XBM_HEIGHT
].value
);
9396 xassert (img
->width
> 0 && img
->height
> 0);
9400 if (fmt
[XBM_ASCENT
].count
)
9401 img
->ascent
= XFASTINT (fmt
[XBM_ASCENT
].value
);
9403 /* Get foreground and background colors, maybe allocate colors. */
9404 if (fmt
[XBM_FOREGROUND
].count
)
9405 foreground
= x_alloc_image_color (f
, img
, fmt
[XBM_FOREGROUND
].value
,
9407 if (fmt
[XBM_BACKGROUND
].count
)
9408 background
= x_alloc_image_color (f
, img
, fmt
[XBM_BACKGROUND
].value
,
9411 /* Set bits to the bitmap image data. */
9412 data
= fmt
[XBM_DATA
].value
;
9417 int nbytes
= (img
->width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
;
9419 p
= bits
= (char *) alloca (nbytes
* img
->height
);
9420 for (i
= 0; i
< img
->height
; ++i
, p
+= nbytes
)
9422 Lisp_Object line
= XVECTOR (data
)->contents
[i
];
9424 bcopy (XSTRING (line
)->data
, p
, nbytes
);
9426 bcopy (XBOOL_VECTOR (line
)->data
, p
, nbytes
);
9429 else if (STRINGP (data
))
9430 bits
= XSTRING (data
)->data
;
9432 bits
= XBOOL_VECTOR (data
)->data
;
9434 #if 0 /* TODO : W32 XPM code */
9435 /* Create the pixmap. */
9436 depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
9438 = XCreatePixmapFromBitmapData (FRAME_W32_DISPLAY (f
),
9439 FRAME_W32_WINDOW (f
),
9441 img
->width
, img
->height
,
9442 foreground
, background
,
9450 image_error ("Unable to create pixmap for XBM image `%s'",
9452 x_clear_image (f
, img
);
9463 /***********************************************************************
9465 ***********************************************************************/
9469 static int xpm_image_p
P_ ((Lisp_Object object
));
9470 static int xpm_load
P_ ((struct frame
*f
, struct image
*img
));
9471 static int xpm_valid_color_symbols_p
P_ ((Lisp_Object
));
9473 #include "X11/xpm.h"
9475 /* The symbol `xpm' identifying XPM-format images. */
9479 /* Indices of image specification fields in xpm_format, below. */
9481 enum xpm_keyword_index
9495 /* Vector of image_keyword structures describing the format
9496 of valid XPM image specifications. */
9498 static struct image_keyword xpm_format
[XPM_LAST
] =
9500 {":type", IMAGE_SYMBOL_VALUE
, 1},
9501 {":file", IMAGE_STRING_VALUE
, 0},
9502 {":data", IMAGE_STRING_VALUE
, 0},
9503 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9504 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
9505 {":relief", IMAGE_INTEGER_VALUE
, 0},
9506 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9507 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9508 {":color-symbols", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
9511 /* Structure describing the image type XBM. */
9513 static struct image_type xpm_type
=
9523 /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
9524 for XPM images. Such a list must consist of conses whose car and
9528 xpm_valid_color_symbols_p (color_symbols
)
9529 Lisp_Object color_symbols
;
9531 while (CONSP (color_symbols
))
9533 Lisp_Object sym
= XCAR (color_symbols
);
9535 || !STRINGP (XCAR (sym
))
9536 || !STRINGP (XCDR (sym
)))
9538 color_symbols
= XCDR (color_symbols
);
9541 return NILP (color_symbols
);
9545 /* Value is non-zero if OBJECT is a valid XPM image specification. */
9548 xpm_image_p (object
)
9551 struct image_keyword fmt
[XPM_LAST
];
9552 bcopy (xpm_format
, fmt
, sizeof fmt
);
9553 return (parse_image_spec (object
, fmt
, XPM_LAST
, Qxpm
)
9554 /* Either `:file' or `:data' must be present. */
9555 && fmt
[XPM_FILE
].count
+ fmt
[XPM_DATA
].count
== 1
9556 /* Either no `:color-symbols' or it's a list of conses
9557 whose car and cdr are strings. */
9558 && (fmt
[XPM_COLOR_SYMBOLS
].count
== 0
9559 || xpm_valid_color_symbols_p (fmt
[XPM_COLOR_SYMBOLS
].value
))
9560 && (fmt
[XPM_ASCENT
].count
== 0
9561 || XFASTINT (fmt
[XPM_ASCENT
].value
) < 100));
9565 /* Load image IMG which will be displayed on frame F. Value is
9566 non-zero if successful. */
9574 XpmAttributes attrs
;
9575 Lisp_Object specified_file
, color_symbols
;
9577 /* Configure the XPM lib. Use the visual of frame F. Allocate
9578 close colors. Return colors allocated. */
9579 bzero (&attrs
, sizeof attrs
);
9580 attrs
.visual
= FRAME_X_VISUAL (f
);
9581 attrs
.colormap
= FRAME_X_COLORMAP (f
);
9582 attrs
.valuemask
|= XpmVisual
;
9583 attrs
.valuemask
|= XpmColormap
;
9584 attrs
.valuemask
|= XpmReturnAllocPixels
;
9585 #ifdef XpmAllocCloseColors
9586 attrs
.alloc_close_colors
= 1;
9587 attrs
.valuemask
|= XpmAllocCloseColors
;
9589 attrs
.closeness
= 600;
9590 attrs
.valuemask
|= XpmCloseness
;
9593 /* If image specification contains symbolic color definitions, add
9594 these to `attrs'. */
9595 color_symbols
= image_spec_value (img
->spec
, QCcolor_symbols
, NULL
);
9596 if (CONSP (color_symbols
))
9599 XpmColorSymbol
*xpm_syms
;
9602 attrs
.valuemask
|= XpmColorSymbols
;
9604 /* Count number of symbols. */
9605 attrs
.numsymbols
= 0;
9606 for (tail
= color_symbols
; CONSP (tail
); tail
= XCDR (tail
))
9609 /* Allocate an XpmColorSymbol array. */
9610 size
= attrs
.numsymbols
* sizeof *xpm_syms
;
9611 xpm_syms
= (XpmColorSymbol
*) alloca (size
);
9612 bzero (xpm_syms
, size
);
9613 attrs
.colorsymbols
= xpm_syms
;
9615 /* Fill the color symbol array. */
9616 for (tail
= color_symbols
, i
= 0;
9618 ++i
, tail
= XCDR (tail
))
9620 Lisp_Object name
= XCAR (XCAR (tail
));
9621 Lisp_Object color
= XCDR (XCAR (tail
));
9622 xpm_syms
[i
].name
= (char *) alloca (XSTRING (name
)->size
+ 1);
9623 strcpy (xpm_syms
[i
].name
, XSTRING (name
)->data
);
9624 xpm_syms
[i
].value
= (char *) alloca (XSTRING (color
)->size
+ 1);
9625 strcpy (xpm_syms
[i
].value
, XSTRING (color
)->data
);
9629 /* Create a pixmap for the image, either from a file, or from a
9630 string buffer containing data in the same format as an XPM file. */
9632 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9633 if (STRINGP (specified_file
))
9635 Lisp_Object file
= x_find_image_file (specified_file
);
9636 if (!STRINGP (file
))
9638 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9643 rc
= XpmReadFileToPixmap (NULL
, FRAME_W32_WINDOW (f
),
9644 XSTRING (file
)->data
, &img
->pixmap
, &img
->mask
,
9649 Lisp_Object buffer
= image_spec_value (img
->spec
, QCdata
, NULL
);
9650 rc
= XpmCreatePixmapFromBuffer (NULL
, FRAME_W32_WINDOW (f
),
9651 XSTRING (buffer
)->data
,
9652 &img
->pixmap
, &img
->mask
,
9657 if (rc
== XpmSuccess
)
9659 /* Remember allocated colors. */
9660 img
->ncolors
= attrs
.nalloc_pixels
;
9661 img
->colors
= (unsigned long *) xmalloc (img
->ncolors
9662 * sizeof *img
->colors
);
9663 for (i
= 0; i
< attrs
.nalloc_pixels
; ++i
)
9664 img
->colors
[i
] = attrs
.alloc_pixels
[i
];
9666 img
->width
= attrs
.width
;
9667 img
->height
= attrs
.height
;
9668 xassert (img
->width
> 0 && img
->height
> 0);
9670 /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */
9672 XpmFreeAttributes (&attrs
);
9680 image_error ("Error opening XPM file (%s)", img
->spec
, Qnil
);
9683 case XpmFileInvalid
:
9684 image_error ("Invalid XPM file (%s)", img
->spec
, Qnil
);
9688 image_error ("Out of memory (%s)", img
->spec
, Qnil
);
9691 case XpmColorFailed
:
9692 image_error ("Color allocation error (%s)", img
->spec
, Qnil
);
9696 image_error ("Unknown error (%s)", img
->spec
, Qnil
);
9701 return rc
== XpmSuccess
;
9704 #endif /* HAVE_XPM != 0 */
9707 #if 0 /* TODO : Color tables on W32. */
9708 /***********************************************************************
9710 ***********************************************************************/
9712 /* An entry in the color table mapping an RGB color to a pixel color. */
9717 unsigned long pixel
;
9719 /* Next in color table collision list. */
9720 struct ct_color
*next
;
9723 /* The bucket vector size to use. Must be prime. */
9727 /* Value is a hash of the RGB color given by R, G, and B. */
9729 #define CT_HASH_RGB(R, G, B) (((R) << 16) ^ ((G) << 8) ^ (B))
9731 /* The color hash table. */
9733 struct ct_color
**ct_table
;
9735 /* Number of entries in the color table. */
9737 int ct_colors_allocated
;
9739 /* Function prototypes. */
9741 static void init_color_table
P_ ((void));
9742 static void free_color_table
P_ ((void));
9743 static unsigned long *colors_in_color_table
P_ ((int *n
));
9744 static unsigned long lookup_rgb_color
P_ ((struct frame
*f
, int r
, int g
, int b
));
9745 static unsigned long lookup_pixel_color
P_ ((struct frame
*f
, unsigned long p
));
9748 /* Initialize the color table. */
9753 int size
= CT_SIZE
* sizeof (*ct_table
);
9754 ct_table
= (struct ct_color
**) xmalloc (size
);
9755 bzero (ct_table
, size
);
9756 ct_colors_allocated
= 0;
9760 /* Free memory associated with the color table. */
9766 struct ct_color
*p
, *next
;
9768 for (i
= 0; i
< CT_SIZE
; ++i
)
9769 for (p
= ct_table
[i
]; p
; p
= next
)
9780 /* Value is a pixel color for RGB color R, G, B on frame F. If an
9781 entry for that color already is in the color table, return the
9782 pixel color of that entry. Otherwise, allocate a new color for R,
9783 G, B, and make an entry in the color table. */
9785 static unsigned long
9786 lookup_rgb_color (f
, r
, g
, b
)
9790 unsigned hash
= CT_HASH_RGB (r
, g
, b
);
9791 int i
= hash
% CT_SIZE
;
9794 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9795 if (p
->r
== r
&& p
->g
== g
&& p
->b
== b
)
9804 color
= PALETTERGB (r
, g
, b
);
9806 ++ct_colors_allocated
;
9808 p
= (struct ct_color
*) xmalloc (sizeof *p
);
9813 p
->next
= ct_table
[i
];
9821 /* Look up pixel color PIXEL which is used on frame F in the color
9822 table. If not already present, allocate it. Value is PIXEL. */
9824 static unsigned long
9825 lookup_pixel_color (f
, pixel
)
9827 unsigned long pixel
;
9829 int i
= pixel
% CT_SIZE
;
9832 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9833 if (p
->pixel
== pixel
)
9844 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9845 color
.pixel
= pixel
;
9846 XQueryColor (NULL
, cmap
, &color
);
9847 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
9852 ++ct_colors_allocated
;
9854 p
= (struct ct_color
*) xmalloc (sizeof *p
);
9859 p
->next
= ct_table
[i
];
9863 return FRAME_FOREGROUND_PIXEL (f
);
9869 /* Value is a vector of all pixel colors contained in the color table,
9870 allocated via xmalloc. Set *N to the number of colors. */
9872 static unsigned long *
9873 colors_in_color_table (n
)
9878 unsigned long *colors
;
9880 if (ct_colors_allocated
== 0)
9887 colors
= (unsigned long *) xmalloc (ct_colors_allocated
9889 *n
= ct_colors_allocated
;
9891 for (i
= j
= 0; i
< CT_SIZE
; ++i
)
9892 for (p
= ct_table
[i
]; p
; p
= p
->next
)
9893 colors
[j
++] = p
->pixel
;
9902 /***********************************************************************
9904 ***********************************************************************/
9906 #if 0 /* TODO : W32 versions of low level algorithms */
9907 static void x_laplace_write_row
P_ ((struct frame
*, long *,
9908 int, XImage
*, int));
9909 static void x_laplace_read_row
P_ ((struct frame
*, Colormap
,
9910 XColor
*, int, XImage
*, int));
9913 /* Fill COLORS with RGB colors from row Y of image XIMG. F is the
9914 frame we operate on, CMAP is the color-map in effect, and WIDTH is
9915 the width of one row in the image. */
9918 x_laplace_read_row (f
, cmap
, colors
, width
, ximg
, y
)
9928 for (x
= 0; x
< width
; ++x
)
9929 colors
[x
].pixel
= XGetPixel (ximg
, x
, y
);
9931 XQueryColors (NULL
, cmap
, colors
, width
);
9935 /* Write row Y of image XIMG. PIXELS is an array of WIDTH longs
9936 containing the pixel colors to write. F is the frame we are
9940 x_laplace_write_row (f
, pixels
, width
, ximg
, y
)
9949 for (x
= 0; x
< width
; ++x
)
9950 XPutPixel (ximg
, x
, y
, pixels
[x
]);
9954 /* Transform image IMG which is used on frame F with a Laplace
9955 edge-detection algorithm. The result is an image that can be used
9956 to draw disabled buttons, for example. */
9963 #if 0 /* TODO : W32 version */
9964 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
9965 XImage
*ximg
, *oimg
;
9971 int in_y
, out_y
, rc
;
9976 /* Get the X image IMG->pixmap. */
9977 ximg
= XGetImage (NULL
, img
->pixmap
,
9978 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
9980 /* Allocate 3 input rows, and one output row of colors. */
9981 for (i
= 0; i
< 3; ++i
)
9982 in
[i
] = (XColor
*) alloca (img
->width
* sizeof (XColor
));
9983 out
= (long *) alloca (img
->width
* sizeof (long));
9985 /* Create an X image for output. */
9986 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 0,
9989 /* Fill first two rows. */
9990 x_laplace_read_row (f
, cmap
, in
[0], img
->width
, ximg
, 0);
9991 x_laplace_read_row (f
, cmap
, in
[1], img
->width
, ximg
, 1);
9994 /* Write first row, all zeros. */
9995 init_color_table ();
9996 pixel
= lookup_rgb_color (f
, 0, 0, 0);
9997 for (x
= 0; x
< img
->width
; ++x
)
9999 x_laplace_write_row (f
, out
, img
->width
, oimg
, 0);
10002 for (y
= 2; y
< img
->height
; ++y
)
10005 int rowb
= (y
+ 2) % 3;
10007 x_laplace_read_row (f
, cmap
, in
[rowa
], img
->width
, ximg
, in_y
++);
10009 for (x
= 0; x
< img
->width
- 2; ++x
)
10011 int r
= in
[rowa
][x
].red
+ mv2
- in
[rowb
][x
+ 2].red
;
10012 int g
= in
[rowa
][x
].green
+ mv2
- in
[rowb
][x
+ 2].green
;
10013 int b
= in
[rowa
][x
].blue
+ mv2
- in
[rowb
][x
+ 2].blue
;
10015 out
[x
+ 1] = lookup_rgb_color (f
, r
& 0xffff, g
& 0xffff,
10019 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
++);
10022 /* Write last line, all zeros. */
10023 for (x
= 0; x
< img
->width
; ++x
)
10025 x_laplace_write_row (f
, out
, img
->width
, oimg
, out_y
);
10027 /* Free the input image, and free resources of IMG. */
10028 XDestroyImage (ximg
);
10029 x_clear_image (f
, img
);
10031 /* Put the output image into pixmap, and destroy it. */
10032 x_put_x_image (f
, oimg
, pixmap
, img
->width
, img
->height
);
10033 x_destroy_x_image (oimg
);
10035 /* Remember new pixmap and colors in IMG. */
10036 img
->pixmap
= pixmap
;
10037 img
->colors
= colors_in_color_table (&img
->ncolors
);
10038 free_color_table ();
10045 /* Build a mask for image IMG which is used on frame F. FILE is the
10046 name of an image file, for error messages. HOW determines how to
10047 determine the background color of IMG. If it is a list '(R G B)',
10048 with R, G, and B being integers >= 0, take that as the color of the
10049 background. Otherwise, determine the background color of IMG
10050 heuristically. Value is non-zero if successful. */
10053 x_build_heuristic_mask (f
, img
, how
)
10058 #if 0 /* TODO : W32 version */
10059 Display
*dpy
= FRAME_W32_DISPLAY (f
);
10060 XImage
*ximg
, *mask_img
;
10061 int x
, y
, rc
, look_at_corners_p
;
10066 /* Create an image and pixmap serving as mask. */
10067 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 1,
10068 &mask_img
, &img
->mask
);
10075 /* Get the X image of IMG->pixmap. */
10076 ximg
= XGetImage (dpy
, img
->pixmap
, 0, 0, img
->width
, img
->height
,
10079 /* Determine the background color of ximg. If HOW is `(R G B)'
10080 take that as color. Otherwise, try to determine the color
10082 look_at_corners_p
= 1;
10090 && NATNUMP (XCAR (how
)))
10092 rgb
[i
] = XFASTINT (XCAR (how
)) & 0xffff;
10096 if (i
== 3 && NILP (how
))
10098 char color_name
[30];
10099 XColor exact
, color
;
10102 sprintf (color_name
, "#%04x%04x%04x", rgb
[0], rgb
[1], rgb
[2]);
10104 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
10105 if (XLookupColor (dpy
, cmap
, color_name
, &exact
, &color
))
10108 look_at_corners_p
= 0;
10113 if (look_at_corners_p
)
10115 unsigned long corners
[4];
10118 /* Get the colors at the corners of ximg. */
10119 corners
[0] = XGetPixel (ximg
, 0, 0);
10120 corners
[1] = XGetPixel (ximg
, img
->width
- 1, 0);
10121 corners
[2] = XGetPixel (ximg
, img
->width
- 1, img
->height
- 1);
10122 corners
[3] = XGetPixel (ximg
, 0, img
->height
- 1);
10124 /* Choose the most frequently found color as background. */
10125 for (i
= best_count
= 0; i
< 4; ++i
)
10129 for (j
= n
= 0; j
< 4; ++j
)
10130 if (corners
[i
] == corners
[j
])
10133 if (n
> best_count
)
10134 bg
= corners
[i
], best_count
= n
;
10138 /* Set all bits in mask_img to 1 whose color in ximg is different
10139 from the background color bg. */
10140 for (y
= 0; y
< img
->height
; ++y
)
10141 for (x
= 0; x
< img
->width
; ++x
)
10142 XPutPixel (mask_img
, x
, y
, XGetPixel (ximg
, x
, y
) != bg
);
10144 /* Put mask_img into img->mask. */
10145 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
10146 x_destroy_x_image (mask_img
);
10147 XDestroyImage (ximg
);
10157 /***********************************************************************
10158 PBM (mono, gray, color)
10159 ***********************************************************************/
10162 static int pbm_image_p
P_ ((Lisp_Object object
));
10163 static int pbm_load
P_ ((struct frame
*f
, struct image
*img
));
10164 static int pbm_scan_number
P_ ((unsigned char **, unsigned char *));
10166 /* The symbol `pbm' identifying images of this type. */
10170 /* Indices of image specification fields in gs_format, below. */
10172 enum pbm_keyword_index
10181 PBM_HEURISTIC_MASK
,
10185 /* Vector of image_keyword structures describing the format
10186 of valid user-defined image specifications. */
10188 static struct image_keyword pbm_format
[PBM_LAST
] =
10190 {":type", IMAGE_SYMBOL_VALUE
, 1},
10191 {":file", IMAGE_STRING_VALUE
, 0},
10192 {":data", IMAGE_STRING_VALUE
, 0},
10193 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10194 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
10195 {":relief", IMAGE_INTEGER_VALUE
, 0},
10196 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10197 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10200 /* Structure describing the image type `pbm'. */
10202 static struct image_type pbm_type
=
10212 /* Return non-zero if OBJECT is a valid PBM image specification. */
10215 pbm_image_p (object
)
10216 Lisp_Object object
;
10218 struct image_keyword fmt
[PBM_LAST
];
10220 bcopy (pbm_format
, fmt
, sizeof fmt
);
10222 if (!parse_image_spec (object
, fmt
, PBM_LAST
, Qpbm
)
10223 || (fmt
[PBM_ASCENT
].count
10224 && XFASTINT (fmt
[PBM_ASCENT
].value
) > 100))
10227 /* Must specify either :data or :file. */
10228 return fmt
[PBM_DATA
].count
+ fmt
[PBM_FILE
].count
== 1;
10232 /* Scan a decimal number from *S and return it. Advance *S while
10233 reading the number. END is the end of the string. Value is -1 at
10237 pbm_scan_number (s
, end
)
10238 unsigned char **s
, *end
;
10244 /* Skip white-space. */
10245 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
10250 /* Skip comment to end of line. */
10251 while (*s
< end
&& (c
= *(*s
)++, c
!= '\n'))
10254 else if (isdigit (c
))
10256 /* Read decimal number. */
10258 while (*s
< end
&& (c
= *(*s
)++, isdigit (c
)))
10259 val
= 10 * val
+ c
- '0';
10270 /* Read FILE into memory. Value is a pointer to a buffer allocated
10271 with xmalloc holding FILE's contents. Value is null if an error
10272 occured. *SIZE is set to the size of the file. */
10275 pbm_read_file (file
, size
)
10283 if (stat (XSTRING (file
)->data
, &st
) == 0
10284 && (fp
= fopen (XSTRING (file
)->data
, "r")) != NULL
10285 && (buf
= (char *) xmalloc (st
.st_size
),
10286 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
10288 *size
= st
.st_size
;
10306 /* Load PBM image IMG for use on frame F. */
10314 int width
, height
, max_color_idx
= 0;
10316 Lisp_Object file
, specified_file
;
10317 enum {PBM_MONO
, PBM_GRAY
, PBM_COLOR
} type
;
10318 struct gcpro gcpro1
;
10319 unsigned char *contents
= NULL
;
10320 unsigned char *end
, *p
;
10323 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10327 if (STRINGP (specified_file
))
10329 file
= x_find_image_file (specified_file
);
10330 if (!STRINGP (file
))
10332 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10337 contents
= pbm_read_file (file
, &size
);
10338 if (contents
== NULL
)
10340 image_error ("Error reading `%s'", file
, Qnil
);
10346 end
= contents
+ size
;
10351 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10352 p
= XSTRING (data
)->data
;
10353 end
= p
+ STRING_BYTES (XSTRING (data
));
10356 /* Check magic number. */
10357 if (end
- p
< 2 || *p
++ != 'P')
10359 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
10369 raw_p
= 0, type
= PBM_MONO
;
10373 raw_p
= 0, type
= PBM_GRAY
;
10377 raw_p
= 0, type
= PBM_COLOR
;
10381 raw_p
= 1, type
= PBM_MONO
;
10385 raw_p
= 1, type
= PBM_GRAY
;
10389 raw_p
= 1, type
= PBM_COLOR
;
10393 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
10397 /* Read width, height, maximum color-component. Characters
10398 starting with `#' up to the end of a line are ignored. */
10399 width
= pbm_scan_number (&p
, end
);
10400 height
= pbm_scan_number (&p
, end
);
10402 if (type
!= PBM_MONO
)
10404 max_color_idx
= pbm_scan_number (&p
, end
);
10405 if (raw_p
&& max_color_idx
> 255)
10406 max_color_idx
= 255;
10411 || (type
!= PBM_MONO
&& max_color_idx
< 0))
10415 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0,
10416 &ximg
, &img
->pixmap
))
10422 /* Initialize the color hash table. */
10423 init_color_table ();
10425 if (type
== PBM_MONO
)
10429 for (y
= 0; y
< height
; ++y
)
10430 for (x
= 0; x
< width
; ++x
)
10440 g
= pbm_scan_number (&p
, end
);
10442 XPutPixel (ximg
, x
, y
, (g
10443 ? FRAME_FOREGROUND_PIXEL (f
)
10444 : FRAME_BACKGROUND_PIXEL (f
)));
10449 for (y
= 0; y
< height
; ++y
)
10450 for (x
= 0; x
< width
; ++x
)
10454 if (type
== PBM_GRAY
)
10455 r
= g
= b
= raw_p
? *p
++ : pbm_scan_number (&p
, end
);
10464 r
= pbm_scan_number (&p
, end
);
10465 g
= pbm_scan_number (&p
, end
);
10466 b
= pbm_scan_number (&p
, end
);
10469 if (r
< 0 || g
< 0 || b
< 0)
10471 xfree (ximg
->data
);
10473 XDestroyImage (ximg
);
10475 image_error ("Invalid pixel value in image `%s'",
10480 /* RGB values are now in the range 0..max_color_idx.
10481 Scale this to the range 0..0xffff supported by X. */
10482 r
= (double) r
* 65535 / max_color_idx
;
10483 g
= (double) g
* 65535 / max_color_idx
;
10484 b
= (double) b
* 65535 / max_color_idx
;
10485 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
10489 /* Store in IMG->colors the colors allocated for the image, and
10490 free the color table. */
10491 img
->colors
= colors_in_color_table (&img
->ncolors
);
10492 free_color_table ();
10494 /* Put the image into a pixmap. */
10495 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10496 x_destroy_x_image (ximg
);
10499 img
->width
= width
;
10500 img
->height
= height
;
10506 #endif /* HAVE_PBM */
10509 /***********************************************************************
10511 ***********************************************************************/
10517 /* Function prototypes. */
10519 static int png_image_p
P_ ((Lisp_Object object
));
10520 static int png_load
P_ ((struct frame
*f
, struct image
*img
));
10522 /* The symbol `png' identifying images of this type. */
10526 /* Indices of image specification fields in png_format, below. */
10528 enum png_keyword_index
10537 PNG_HEURISTIC_MASK
,
10541 /* Vector of image_keyword structures describing the format
10542 of valid user-defined image specifications. */
10544 static struct image_keyword png_format
[PNG_LAST
] =
10546 {":type", IMAGE_SYMBOL_VALUE
, 1},
10547 {":data", IMAGE_STRING_VALUE
, 0},
10548 {":file", IMAGE_STRING_VALUE
, 0},
10549 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
10550 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
10551 {":relief", IMAGE_INTEGER_VALUE
, 0},
10552 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10553 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
10556 /* Structure describing the image type `png'. */
10558 static struct image_type png_type
=
10568 /* Return non-zero if OBJECT is a valid PNG image specification. */
10571 png_image_p (object
)
10572 Lisp_Object object
;
10574 struct image_keyword fmt
[PNG_LAST
];
10575 bcopy (png_format
, fmt
, sizeof fmt
);
10577 if (!parse_image_spec (object
, fmt
, PNG_LAST
, Qpng
)
10578 || (fmt
[PNG_ASCENT
].count
10579 && XFASTINT (fmt
[PNG_ASCENT
].value
) > 100))
10582 /* Must specify either the :data or :file keyword. */
10583 return fmt
[PNG_FILE
].count
+ fmt
[PNG_DATA
].count
== 1;
10587 /* Error and warning handlers installed when the PNG library
10591 my_png_error (png_ptr
, msg
)
10592 png_struct
*png_ptr
;
10595 xassert (png_ptr
!= NULL
);
10596 image_error ("PNG error: %s", build_string (msg
), Qnil
);
10597 longjmp (png_ptr
->jmpbuf
, 1);
10602 my_png_warning (png_ptr
, msg
)
10603 png_struct
*png_ptr
;
10606 xassert (png_ptr
!= NULL
);
10607 image_error ("PNG warning: %s", build_string (msg
), Qnil
);
10610 /* Memory source for PNG decoding. */
10612 struct png_memory_storage
10614 unsigned char *bytes
; /* The data */
10615 size_t len
; /* How big is it? */
10616 int index
; /* Where are we? */
10620 /* Function set as reader function when reading PNG image from memory.
10621 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH
10622 bytes from the input to DATA. */
10625 png_read_from_memory (png_ptr
, data
, length
)
10626 png_structp png_ptr
;
10630 struct png_memory_storage
*tbr
10631 = (struct png_memory_storage
*) png_get_io_ptr (png_ptr
);
10633 if (length
> tbr
->len
- tbr
->index
)
10634 png_error (png_ptr
, "Read error");
10636 bcopy (tbr
->bytes
+ tbr
->index
, data
, length
);
10637 tbr
->index
= tbr
->index
+ length
;
10640 /* Load PNG image IMG for use on frame F. Value is non-zero if
10648 Lisp_Object file
, specified_file
;
10649 Lisp_Object specified_data
;
10651 XImage
*ximg
, *mask_img
= NULL
;
10652 struct gcpro gcpro1
;
10653 png_struct
*png_ptr
= NULL
;
10654 png_info
*info_ptr
= NULL
, *end_info
= NULL
;
10657 png_byte
*pixels
= NULL
;
10658 png_byte
**rows
= NULL
;
10659 png_uint_32 width
, height
;
10660 int bit_depth
, color_type
, interlace_type
;
10662 png_uint_32 row_bytes
;
10665 double screen_gamma
, image_gamma
;
10667 struct png_memory_storage tbr
; /* Data to be read */
10669 /* Find out what file to load. */
10670 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10671 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10675 if (NILP (specified_data
))
10677 file
= x_find_image_file (specified_file
);
10678 if (!STRINGP (file
))
10680 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10685 /* Open the image file. */
10686 fp
= fopen (XSTRING (file
)->data
, "rb");
10689 image_error ("Cannot open image file `%s'", file
, Qnil
);
10695 /* Check PNG signature. */
10696 if (fread (sig
, 1, sizeof sig
, fp
) != sizeof sig
10697 || !png_check_sig (sig
, sizeof sig
))
10699 image_error ("Not a PNG file:` %s'", file
, Qnil
);
10707 /* Read from memory. */
10708 tbr
.bytes
= XSTRING (specified_data
)->data
;
10709 tbr
.len
= STRING_BYTES (XSTRING (specified_data
));
10712 /* Check PNG signature. */
10713 if (tbr
.len
< sizeof sig
10714 || !png_check_sig (tbr
.bytes
, sizeof sig
))
10716 image_error ("Not a PNG image: `%s'", img
->spec
, Qnil
);
10721 /* Need to skip past the signature. */
10722 tbr
.bytes
+= sizeof (sig
);
10725 /* Initialize read and info structs for PNG lib. */
10726 png_ptr
= png_create_read_struct (PNG_LIBPNG_VER_STRING
, NULL
,
10727 my_png_error
, my_png_warning
);
10730 if (fp
) fclose (fp
);
10735 info_ptr
= png_create_info_struct (png_ptr
);
10738 png_destroy_read_struct (&png_ptr
, NULL
, NULL
);
10739 if (fp
) fclose (fp
);
10744 end_info
= png_create_info_struct (png_ptr
);
10747 png_destroy_read_struct (&png_ptr
, &info_ptr
, NULL
);
10748 if (fp
) fclose (fp
);
10753 /* Set error jump-back. We come back here when the PNG library
10754 detects an error. */
10755 if (setjmp (png_ptr
->jmpbuf
))
10759 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
10762 if (fp
) fclose (fp
);
10767 /* Read image info. */
10768 if (!NILP (specified_data
))
10769 png_set_read_fn (png_ptr
, (void *) &tbr
, png_read_from_memory
);
10771 png_init_io (png_ptr
, fp
);
10773 png_set_sig_bytes (png_ptr
, sizeof sig
);
10774 png_read_info (png_ptr
, info_ptr
);
10775 png_get_IHDR (png_ptr
, info_ptr
, &width
, &height
, &bit_depth
, &color_type
,
10776 &interlace_type
, NULL
, NULL
);
10778 /* If image contains simply transparency data, we prefer to
10779 construct a clipping mask. */
10780 if (png_get_valid (png_ptr
, info_ptr
, PNG_INFO_tRNS
))
10785 /* This function is easier to write if we only have to handle
10786 one data format: RGB or RGBA with 8 bits per channel. Let's
10787 transform other formats into that format. */
10789 /* Strip more than 8 bits per channel. */
10790 if (bit_depth
== 16)
10791 png_set_strip_16 (png_ptr
);
10793 /* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha channel
10795 png_set_expand (png_ptr
);
10797 /* Convert grayscale images to RGB. */
10798 if (color_type
== PNG_COLOR_TYPE_GRAY
10799 || color_type
== PNG_COLOR_TYPE_GRAY_ALPHA
)
10800 png_set_gray_to_rgb (png_ptr
);
10802 /* The value 2.2 is a guess for PC monitors from PNG example.c. */
10803 gamma_str
= getenv ("SCREEN_GAMMA");
10804 screen_gamma
= gamma_str
? atof (gamma_str
) : 2.2;
10806 /* Tell the PNG lib to handle gamma correction for us. */
10808 #if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
10809 if (png_get_sRGB (png_ptr
, info_ptr
, &intent
))
10810 /* There is a special chunk in the image specifying the gamma. */
10811 png_set_sRGB (png_ptr
, info_ptr
, intent
);
10814 if (png_get_gAMA (png_ptr
, info_ptr
, &image_gamma
))
10815 /* Image contains gamma information. */
10816 png_set_gamma (png_ptr
, screen_gamma
, image_gamma
);
10818 /* Use a default of 0.5 for the image gamma. */
10819 png_set_gamma (png_ptr
, screen_gamma
, 0.5);
10821 /* Handle alpha channel by combining the image with a background
10822 color. Do this only if a real alpha channel is supplied. For
10823 simple transparency, we prefer a clipping mask. */
10824 if (!transparent_p
)
10826 png_color_16
*image_background
;
10828 if (png_get_bKGD (png_ptr
, info_ptr
, &image_background
))
10829 /* Image contains a background color with which to
10830 combine the image. */
10831 png_set_background (png_ptr
, image_background
,
10832 PNG_BACKGROUND_GAMMA_FILE
, 1, 1.0);
10835 /* Image does not contain a background color with which
10836 to combine the image data via an alpha channel. Use
10837 the frame's background instead. */
10840 png_color_16 frame_background
;
10843 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
10844 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
10845 XQueryColor (FRAME_W32_DISPLAY (f
), cmap
, &color
);
10848 bzero (&frame_background
, sizeof frame_background
);
10849 frame_background
.red
= color
.red
;
10850 frame_background
.green
= color
.green
;
10851 frame_background
.blue
= color
.blue
;
10853 png_set_background (png_ptr
, &frame_background
,
10854 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
10858 /* Update info structure. */
10859 png_read_update_info (png_ptr
, info_ptr
);
10861 /* Get number of channels. Valid values are 1 for grayscale images
10862 and images with a palette, 2 for grayscale images with transparency
10863 information (alpha channel), 3 for RGB images, and 4 for RGB
10864 images with alpha channel, i.e. RGBA. If conversions above were
10865 sufficient we should only have 3 or 4 channels here. */
10866 channels
= png_get_channels (png_ptr
, info_ptr
);
10867 xassert (channels
== 3 || channels
== 4);
10869 /* Number of bytes needed for one row of the image. */
10870 row_bytes
= png_get_rowbytes (png_ptr
, info_ptr
);
10872 /* Allocate memory for the image. */
10873 pixels
= (png_byte
*) xmalloc (row_bytes
* height
* sizeof *pixels
);
10874 rows
= (png_byte
**) xmalloc (height
* sizeof *rows
);
10875 for (i
= 0; i
< height
; ++i
)
10876 rows
[i
] = pixels
+ i
* row_bytes
;
10878 /* Read the entire image. */
10879 png_read_image (png_ptr
, rows
);
10880 png_read_end (png_ptr
, info_ptr
);
10889 /* Create the X image and pixmap. */
10890 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
10897 /* Create an image and pixmap serving as mask if the PNG image
10898 contains an alpha channel. */
10901 && !x_create_x_image_and_pixmap (f
, width
, height
, 1,
10902 &mask_img
, &img
->mask
))
10904 x_destroy_x_image (ximg
);
10905 XFreePixmap (FRAME_W32_DISPLAY (f
), img
->pixmap
);
10911 /* Fill the X image and mask from PNG data. */
10912 init_color_table ();
10914 for (y
= 0; y
< height
; ++y
)
10916 png_byte
*p
= rows
[y
];
10918 for (x
= 0; x
< width
; ++x
)
10925 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
10927 /* An alpha channel, aka mask channel, associates variable
10928 transparency with an image. Where other image formats
10929 support binary transparency---fully transparent or fully
10930 opaque---PNG allows up to 254 levels of partial transparency.
10931 The PNG library implements partial transparency by combining
10932 the image with a specified background color.
10934 I'm not sure how to handle this here nicely: because the
10935 background on which the image is displayed may change, for
10936 real alpha channel support, it would be necessary to create
10937 a new image for each possible background.
10939 What I'm doing now is that a mask is created if we have
10940 boolean transparency information. Otherwise I'm using
10941 the frame's background color to combine the image with. */
10946 XPutPixel (mask_img
, x
, y
, *p
> 0);
10952 /* Remember colors allocated for this image. */
10953 img
->colors
= colors_in_color_table (&img
->ncolors
);
10954 free_color_table ();
10957 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
10961 img
->width
= width
;
10962 img
->height
= height
;
10964 /* Put the image into the pixmap, then free the X image and its buffer. */
10965 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10966 x_destroy_x_image (ximg
);
10968 /* Same for the mask. */
10971 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
10972 x_destroy_x_image (mask_img
);
10980 #endif /* HAVE_PNG != 0 */
10984 /***********************************************************************
10986 ***********************************************************************/
10990 /* Work around a warning about HAVE_STDLIB_H being redefined in
10992 #ifdef HAVE_STDLIB_H
10993 #define HAVE_STDLIB_H_1
10994 #undef HAVE_STDLIB_H
10995 #endif /* HAVE_STLIB_H */
10997 #include <jpeglib.h>
10998 #include <jerror.h>
10999 #include <setjmp.h>
11001 #ifdef HAVE_STLIB_H_1
11002 #define HAVE_STDLIB_H 1
11005 static int jpeg_image_p
P_ ((Lisp_Object object
));
11006 static int jpeg_load
P_ ((struct frame
*f
, struct image
*img
));
11008 /* The symbol `jpeg' identifying images of this type. */
11012 /* Indices of image specification fields in gs_format, below. */
11014 enum jpeg_keyword_index
11023 JPEG_HEURISTIC_MASK
,
11027 /* Vector of image_keyword structures describing the format
11028 of valid user-defined image specifications. */
11030 static struct image_keyword jpeg_format
[JPEG_LAST
] =
11032 {":type", IMAGE_SYMBOL_VALUE
, 1},
11033 {":data", IMAGE_STRING_VALUE
, 0},
11034 {":file", IMAGE_STRING_VALUE
, 0},
11035 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11036 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
11037 {":relief", IMAGE_INTEGER_VALUE
, 0},
11038 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11039 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
11042 /* Structure describing the image type `jpeg'. */
11044 static struct image_type jpeg_type
=
11054 /* Return non-zero if OBJECT is a valid JPEG image specification. */
11057 jpeg_image_p (object
)
11058 Lisp_Object object
;
11060 struct image_keyword fmt
[JPEG_LAST
];
11062 bcopy (jpeg_format
, fmt
, sizeof fmt
);
11064 if (!parse_image_spec (object
, fmt
, JPEG_LAST
, Qjpeg
)
11065 || (fmt
[JPEG_ASCENT
].count
11066 && XFASTINT (fmt
[JPEG_ASCENT
].value
) > 100))
11069 /* Must specify either the :data or :file keyword. */
11070 return fmt
[JPEG_FILE
].count
+ fmt
[JPEG_DATA
].count
== 1;
11074 struct my_jpeg_error_mgr
11076 struct jpeg_error_mgr pub
;
11077 jmp_buf setjmp_buffer
;
11081 my_error_exit (cinfo
)
11082 j_common_ptr cinfo
;
11084 struct my_jpeg_error_mgr
*mgr
= (struct my_jpeg_error_mgr
*) cinfo
->err
;
11085 longjmp (mgr
->setjmp_buffer
, 1);
11088 /* Init source method for JPEG data source manager. Called by
11089 jpeg_read_header() before any data is actually read. See
11090 libjpeg.doc from the JPEG lib distribution. */
11093 our_init_source (cinfo
)
11094 j_decompress_ptr cinfo
;
11099 /* Fill input buffer method for JPEG data source manager. Called
11100 whenever more data is needed. We read the whole image in one step,
11101 so this only adds a fake end of input marker at the end. */
11104 our_fill_input_buffer (cinfo
)
11105 j_decompress_ptr cinfo
;
11107 /* Insert a fake EOI marker. */
11108 struct jpeg_source_mgr
*src
= cinfo
->src
;
11109 static JOCTET buffer
[2];
11111 buffer
[0] = (JOCTET
) 0xFF;
11112 buffer
[1] = (JOCTET
) JPEG_EOI
;
11114 src
->next_input_byte
= buffer
;
11115 src
->bytes_in_buffer
= 2;
11120 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src
11121 is the JPEG data source manager. */
11124 our_skip_input_data (cinfo
, num_bytes
)
11125 j_decompress_ptr cinfo
;
11128 struct jpeg_source_mgr
*src
= (struct jpeg_source_mgr
*) cinfo
->src
;
11132 if (num_bytes
> src
->bytes_in_buffer
)
11133 ERREXIT (cinfo
, JERR_INPUT_EOF
);
11135 src
->bytes_in_buffer
-= num_bytes
;
11136 src
->next_input_byte
+= num_bytes
;
11141 /* Method to terminate data source. Called by
11142 jpeg_finish_decompress() after all data has been processed. */
11145 our_term_source (cinfo
)
11146 j_decompress_ptr cinfo
;
11151 /* Set up the JPEG lib for reading an image from DATA which contains
11152 LEN bytes. CINFO is the decompression info structure created for
11153 reading the image. */
11156 jpeg_memory_src (cinfo
, data
, len
)
11157 j_decompress_ptr cinfo
;
11161 struct jpeg_source_mgr
*src
;
11163 if (cinfo
->src
== NULL
)
11165 /* First time for this JPEG object? */
11166 cinfo
->src
= (struct jpeg_source_mgr
*)
11167 (*cinfo
->mem
->alloc_small
) ((j_common_ptr
) cinfo
, JPOOL_PERMANENT
,
11168 sizeof (struct jpeg_source_mgr
));
11169 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
11170 src
->next_input_byte
= data
;
11173 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
11174 src
->init_source
= our_init_source
;
11175 src
->fill_input_buffer
= our_fill_input_buffer
;
11176 src
->skip_input_data
= our_skip_input_data
;
11177 src
->resync_to_restart
= jpeg_resync_to_restart
; /* Use default method. */
11178 src
->term_source
= our_term_source
;
11179 src
->bytes_in_buffer
= len
;
11180 src
->next_input_byte
= data
;
11184 /* Load image IMG for use on frame F. Patterned after example.c
11185 from the JPEG lib. */
11192 struct jpeg_decompress_struct cinfo
;
11193 struct my_jpeg_error_mgr mgr
;
11194 Lisp_Object file
, specified_file
;
11195 Lisp_Object specified_data
;
11198 int row_stride
, x
, y
;
11199 XImage
*ximg
= NULL
;
11201 unsigned long *colors
;
11203 struct gcpro gcpro1
;
11205 /* Open the JPEG file. */
11206 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11207 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11211 if (NILP (specified_data
))
11213 file
= x_find_image_file (specified_file
);
11214 if (!STRINGP (file
))
11216 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
11221 fp
= fopen (XSTRING (file
)->data
, "r");
11224 image_error ("Cannot open `%s'", file
, Qnil
);
11230 /* Customize libjpeg's error handling to call my_error_exit when an
11231 error is detected. This function will perform a longjmp. */
11232 mgr
.pub
.error_exit
= my_error_exit
;
11233 cinfo
.err
= jpeg_std_error (&mgr
.pub
);
11235 if ((rc
= setjmp (mgr
.setjmp_buffer
)) != 0)
11239 /* Called from my_error_exit. Display a JPEG error. */
11240 char buffer
[JMSG_LENGTH_MAX
];
11241 cinfo
.err
->format_message ((j_common_ptr
) &cinfo
, buffer
);
11242 image_error ("Error reading JPEG image `%s': %s", img
->spec
,
11243 build_string (buffer
));
11246 /* Close the input file and destroy the JPEG object. */
11249 jpeg_destroy_decompress (&cinfo
);
11253 /* If we already have an XImage, free that. */
11254 x_destroy_x_image (ximg
);
11256 /* Free pixmap and colors. */
11257 x_clear_image (f
, img
);
11264 /* Create the JPEG decompression object. Let it read from fp.
11265 Read the JPEG image header. */
11266 jpeg_create_decompress (&cinfo
);
11268 if (NILP (specified_data
))
11269 jpeg_stdio_src (&cinfo
, fp
);
11271 jpeg_memory_src (&cinfo
, XSTRING (specified_data
)->data
,
11272 STRING_BYTES (XSTRING (specified_data
)));
11274 jpeg_read_header (&cinfo
, TRUE
);
11276 /* Customize decompression so that color quantization will be used.
11277 Start decompression. */
11278 cinfo
.quantize_colors
= TRUE
;
11279 jpeg_start_decompress (&cinfo
);
11280 width
= img
->width
= cinfo
.output_width
;
11281 height
= img
->height
= cinfo
.output_height
;
11285 /* Create X image and pixmap. */
11286 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
11290 longjmp (mgr
.setjmp_buffer
, 2);
11293 /* Allocate colors. When color quantization is used,
11294 cinfo.actual_number_of_colors has been set with the number of
11295 colors generated, and cinfo.colormap is a two-dimensional array
11296 of color indices in the range 0..cinfo.actual_number_of_colors.
11297 No more than 255 colors will be generated. */
11301 if (cinfo
.out_color_components
> 2)
11302 ir
= 0, ig
= 1, ib
= 2;
11303 else if (cinfo
.out_color_components
> 1)
11304 ir
= 0, ig
= 1, ib
= 0;
11306 ir
= 0, ig
= 0, ib
= 0;
11308 /* Use the color table mechanism because it handles colors that
11309 cannot be allocated nicely. Such colors will be replaced with
11310 a default color, and we don't have to care about which colors
11311 can be freed safely, and which can't. */
11312 init_color_table ();
11313 colors
= (unsigned long *) alloca (cinfo
.actual_number_of_colors
11316 for (i
= 0; i
< cinfo
.actual_number_of_colors
; ++i
)
11318 /* Multiply RGB values with 255 because X expects RGB values
11319 in the range 0..0xffff. */
11320 int r
= cinfo
.colormap
[ir
][i
] << 8;
11321 int g
= cinfo
.colormap
[ig
][i
] << 8;
11322 int b
= cinfo
.colormap
[ib
][i
] << 8;
11323 colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
11326 /* Remember those colors actually allocated. */
11327 img
->colors
= colors_in_color_table (&img
->ncolors
);
11328 free_color_table ();
11332 row_stride
= width
* cinfo
.output_components
;
11333 buffer
= cinfo
.mem
->alloc_sarray ((j_common_ptr
) &cinfo
, JPOOL_IMAGE
,
11335 for (y
= 0; y
< height
; ++y
)
11337 jpeg_read_scanlines (&cinfo
, buffer
, 1);
11338 for (x
= 0; x
< cinfo
.output_width
; ++x
)
11339 XPutPixel (ximg
, x
, y
, colors
[buffer
[0][x
]]);
11343 jpeg_finish_decompress (&cinfo
);
11344 jpeg_destroy_decompress (&cinfo
);
11348 /* Put the image into the pixmap. */
11349 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11350 x_destroy_x_image (ximg
);
11356 #endif /* HAVE_JPEG */
11360 /***********************************************************************
11362 ***********************************************************************/
11366 #include <tiffio.h>
11368 static int tiff_image_p
P_ ((Lisp_Object object
));
11369 static int tiff_load
P_ ((struct frame
*f
, struct image
*img
));
11371 /* The symbol `tiff' identifying images of this type. */
11375 /* Indices of image specification fields in tiff_format, below. */
11377 enum tiff_keyword_index
11386 TIFF_HEURISTIC_MASK
,
11390 /* Vector of image_keyword structures describing the format
11391 of valid user-defined image specifications. */
11393 static struct image_keyword tiff_format
[TIFF_LAST
] =
11395 {":type", IMAGE_SYMBOL_VALUE
, 1},
11396 {":data", IMAGE_STRING_VALUE
, 0},
11397 {":file", IMAGE_STRING_VALUE
, 0},
11398 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11399 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
11400 {":relief", IMAGE_INTEGER_VALUE
, 0},
11401 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11402 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
11405 /* Structure describing the image type `tiff'. */
11407 static struct image_type tiff_type
=
11417 /* Return non-zero if OBJECT is a valid TIFF image specification. */
11420 tiff_image_p (object
)
11421 Lisp_Object object
;
11423 struct image_keyword fmt
[TIFF_LAST
];
11424 bcopy (tiff_format
, fmt
, sizeof fmt
);
11426 if (!parse_image_spec (object
, fmt
, TIFF_LAST
, Qtiff
)
11427 || (fmt
[TIFF_ASCENT
].count
11428 && XFASTINT (fmt
[TIFF_ASCENT
].value
) > 100))
11431 /* Must specify either the :data or :file keyword. */
11432 return fmt
[TIFF_FILE
].count
+ fmt
[TIFF_DATA
].count
== 1;
11436 /* Reading from a memory buffer for TIFF images Based on the PNG
11437 memory source, but we have to provide a lot of extra functions.
11440 We really only need to implement read and seek, but I am not
11441 convinced that the TIFF library is smart enough not to destroy
11442 itself if we only hand it the function pointers we need to
11447 unsigned char *bytes
;
11451 tiff_memory_source
;
11454 tiff_read_from_memory (data
, buf
, size
)
11459 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
11461 if (size
> src
->len
- src
->index
)
11462 return (size_t) -1;
11463 bcopy (src
->bytes
+ src
->index
, buf
, size
);
11464 src
->index
+= size
;
11469 tiff_write_from_memory (data
, buf
, size
)
11474 return (size_t) -1;
11478 tiff_seek_in_memory (data
, off
, whence
)
11483 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
11488 case SEEK_SET
: /* Go from beginning of source. */
11492 case SEEK_END
: /* Go from end of source. */
11493 idx
= src
->len
+ off
;
11496 case SEEK_CUR
: /* Go from current position. */
11497 idx
= src
->index
+ off
;
11500 default: /* Invalid `whence'. */
11504 if (idx
> src
->len
|| idx
< 0)
11512 tiff_close_memory (data
)
11520 tiff_mmap_memory (data
, pbase
, psize
)
11525 /* It is already _IN_ memory. */
11530 tiff_unmap_memory (data
, base
, size
)
11535 /* We don't need to do this. */
11539 tiff_size_of_memory (data
)
11542 return ((tiff_memory_source
*) data
)->len
;
11545 /* Load TIFF image IMG for use on frame F. Value is non-zero if
11553 Lisp_Object file
, specified_file
;
11554 Lisp_Object specified_data
;
11556 int width
, height
, x
, y
;
11560 struct gcpro gcpro1
;
11561 tiff_memory_source memsrc
;
11563 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11564 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11568 if (NILP (specified_data
))
11570 /* Read from a file */
11571 file
= x_find_image_file (specified_file
);
11572 if (!STRINGP (file
))
11574 image_error ("Cannot find image file `%s'", file
, Qnil
);
11579 /* Try to open the image file. */
11580 tiff
= TIFFOpen (XSTRING (file
)->data
, "r");
11583 image_error ("Cannot open `%s'", file
, Qnil
);
11590 /* Memory source! */
11591 memsrc
.bytes
= XSTRING (specified_data
)->data
;
11592 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
11595 tiff
= TIFFClientOpen ("memory_source", "r", &memsrc
,
11596 (TIFFReadWriteProc
) tiff_read_from_memory
,
11597 (TIFFReadWriteProc
) tiff_write_from_memory
,
11598 tiff_seek_in_memory
,
11600 tiff_size_of_memory
,
11602 tiff_unmap_memory
);
11606 image_error ("Cannot open memory source for `%s'", img
->spec
, Qnil
);
11612 /* Get width and height of the image, and allocate a raster buffer
11613 of width x height 32-bit values. */
11614 TIFFGetField (tiff
, TIFFTAG_IMAGEWIDTH
, &width
);
11615 TIFFGetField (tiff
, TIFFTAG_IMAGELENGTH
, &height
);
11616 buf
= (uint32
*) xmalloc (width
* height
* sizeof *buf
);
11618 rc
= TIFFReadRGBAImage (tiff
, width
, height
, buf
, 0);
11622 image_error ("Error reading TIFF image `%s'", img
->spec
, Qnil
);
11630 /* Create the X image and pixmap. */
11631 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11639 /* Initialize the color table. */
11640 init_color_table ();
11642 /* Process the pixel raster. Origin is in the lower-left corner. */
11643 for (y
= 0; y
< height
; ++y
)
11645 uint32
*row
= buf
+ y
* width
;
11647 for (x
= 0; x
< width
; ++x
)
11649 uint32 abgr
= row
[x
];
11650 int r
= TIFFGetR (abgr
) << 8;
11651 int g
= TIFFGetG (abgr
) << 8;
11652 int b
= TIFFGetB (abgr
) << 8;
11653 XPutPixel (ximg
, x
, height
- 1 - y
, lookup_rgb_color (f
, r
, g
, b
));
11657 /* Remember the colors allocated for the image. Free the color table. */
11658 img
->colors
= colors_in_color_table (&img
->ncolors
);
11659 free_color_table ();
11661 /* Put the image into the pixmap, then free the X image and its buffer. */
11662 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11663 x_destroy_x_image (ximg
);
11667 img
->width
= width
;
11668 img
->height
= height
;
11674 #endif /* HAVE_TIFF != 0 */
11678 /***********************************************************************
11680 ***********************************************************************/
11684 #include <gif_lib.h>
11686 static int gif_image_p
P_ ((Lisp_Object object
));
11687 static int gif_load
P_ ((struct frame
*f
, struct image
*img
));
11689 /* The symbol `gif' identifying images of this type. */
11693 /* Indices of image specification fields in gif_format, below. */
11695 enum gif_keyword_index
11704 GIF_HEURISTIC_MASK
,
11709 /* Vector of image_keyword structures describing the format
11710 of valid user-defined image specifications. */
11712 static struct image_keyword gif_format
[GIF_LAST
] =
11714 {":type", IMAGE_SYMBOL_VALUE
, 1},
11715 {":data", IMAGE_STRING_VALUE
, 0},
11716 {":file", IMAGE_STRING_VALUE
, 0},
11717 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
11718 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
11719 {":relief", IMAGE_INTEGER_VALUE
, 0},
11720 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11721 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
11722 {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0}
11725 /* Structure describing the image type `gif'. */
11727 static struct image_type gif_type
=
11736 /* Return non-zero if OBJECT is a valid GIF image specification. */
11739 gif_image_p (object
)
11740 Lisp_Object object
;
11742 struct image_keyword fmt
[GIF_LAST
];
11743 bcopy (gif_format
, fmt
, sizeof fmt
);
11745 if (!parse_image_spec (object
, fmt
, GIF_LAST
, Qgif
)
11746 || (fmt
[GIF_ASCENT
].count
11747 && XFASTINT (fmt
[GIF_ASCENT
].value
) > 100))
11750 /* Must specify either the :data or :file keyword. */
11751 return fmt
[GIF_FILE
].count
+ fmt
[GIF_DATA
].count
== 1;
11754 /* Reading a GIF image from memory
11755 Based on the PNG memory stuff to a certain extent. */
11759 unsigned char *bytes
;
11765 /* Make the current memory source available to gif_read_from_memory.
11766 It's done this way because not all versions of libungif support
11767 a UserData field in the GifFileType structure. */
11768 static gif_memory_source
*current_gif_memory_src
;
11771 gif_read_from_memory (file
, buf
, len
)
11776 gif_memory_source
*src
= current_gif_memory_src
;
11778 if (len
> src
->len
- src
->index
)
11781 bcopy (src
->bytes
+ src
->index
, buf
, len
);
11787 /* Load GIF image IMG for use on frame F. Value is non-zero if
11795 Lisp_Object file
, specified_file
;
11796 Lisp_Object specified_data
;
11797 int rc
, width
, height
, x
, y
, i
;
11799 ColorMapObject
*gif_color_map
;
11800 unsigned long pixel_colors
[256];
11802 struct gcpro gcpro1
;
11804 int ino
, image_left
, image_top
, image_width
, image_height
;
11805 gif_memory_source memsrc
;
11806 unsigned char *raster
;
11808 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
11809 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
11813 if (NILP (specified_data
))
11815 file
= x_find_image_file (specified_file
);
11816 if (!STRINGP (file
))
11818 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
11823 /* Open the GIF file. */
11824 gif
= DGifOpenFileName (XSTRING (file
)->data
);
11827 image_error ("Cannot open `%s'", file
, Qnil
);
11834 /* Read from memory! */
11835 current_gif_memory_src
= &memsrc
;
11836 memsrc
.bytes
= XSTRING (specified_data
)->data
;
11837 memsrc
.len
= STRING_BYTES (XSTRING (specified_data
));
11840 gif
= DGifOpen(&memsrc
, gif_read_from_memory
);
11843 image_error ("Cannot open memory source `%s'", img
->spec
, Qnil
);
11849 /* Read entire contents. */
11850 rc
= DGifSlurp (gif
);
11851 if (rc
== GIF_ERROR
)
11853 image_error ("Error reading `%s'", img
->spec
, Qnil
);
11854 DGifCloseFile (gif
);
11859 image
= image_spec_value (img
->spec
, QCindex
, NULL
);
11860 ino
= INTEGERP (image
) ? XFASTINT (image
) : 0;
11861 if (ino
>= gif
->ImageCount
)
11863 image_error ("Invalid image number `%s' in image `%s'",
11865 DGifCloseFile (gif
);
11870 width
= img
->width
= gif
->SWidth
;
11871 height
= img
->height
= gif
->SHeight
;
11875 /* Create the X image and pixmap. */
11876 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
11879 DGifCloseFile (gif
);
11884 /* Allocate colors. */
11885 gif_color_map
= gif
->SavedImages
[ino
].ImageDesc
.ColorMap
;
11886 if (!gif_color_map
)
11887 gif_color_map
= gif
->SColorMap
;
11888 init_color_table ();
11889 bzero (pixel_colors
, sizeof pixel_colors
);
11891 for (i
= 0; i
< gif_color_map
->ColorCount
; ++i
)
11893 int r
= gif_color_map
->Colors
[i
].Red
<< 8;
11894 int g
= gif_color_map
->Colors
[i
].Green
<< 8;
11895 int b
= gif_color_map
->Colors
[i
].Blue
<< 8;
11896 pixel_colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
11899 img
->colors
= colors_in_color_table (&img
->ncolors
);
11900 free_color_table ();
11902 /* Clear the part of the screen image that are not covered by
11903 the image from the GIF file. Full animated GIF support
11904 requires more than can be done here (see the gif89 spec,
11905 disposal methods). Let's simply assume that the part
11906 not covered by a sub-image is in the frame's background color. */
11907 image_top
= gif
->SavedImages
[ino
].ImageDesc
.Top
;
11908 image_left
= gif
->SavedImages
[ino
].ImageDesc
.Left
;
11909 image_width
= gif
->SavedImages
[ino
].ImageDesc
.Width
;
11910 image_height
= gif
->SavedImages
[ino
].ImageDesc
.Height
;
11912 for (y
= 0; y
< image_top
; ++y
)
11913 for (x
= 0; x
< width
; ++x
)
11914 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11916 for (y
= image_top
+ image_height
; y
< height
; ++y
)
11917 for (x
= 0; x
< width
; ++x
)
11918 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11920 for (y
= image_top
; y
< image_top
+ image_height
; ++y
)
11922 for (x
= 0; x
< image_left
; ++x
)
11923 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11924 for (x
= image_left
+ image_width
; x
< width
; ++x
)
11925 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
11928 /* Read the GIF image into the X image. We use a local variable
11929 `raster' here because RasterBits below is a char *, and invites
11930 problems with bytes >= 0x80. */
11931 raster
= (unsigned char *) gif
->SavedImages
[ino
].RasterBits
;
11933 if (gif
->SavedImages
[ino
].ImageDesc
.Interlace
)
11935 static int interlace_start
[] = {0, 4, 2, 1};
11936 static int interlace_increment
[] = {8, 8, 4, 2};
11938 int row
= interlace_start
[0];
11942 for (y
= 0; y
< image_height
; y
++)
11944 if (row
>= image_height
)
11946 row
= interlace_start
[++pass
];
11947 while (row
>= image_height
)
11948 row
= interlace_start
[++pass
];
11951 for (x
= 0; x
< image_width
; x
++)
11953 int i
= raster
[(y
* image_width
) + x
];
11954 XPutPixel (ximg
, x
+ image_left
, row
+ image_top
,
11958 row
+= interlace_increment
[pass
];
11963 for (y
= 0; y
< image_height
; ++y
)
11964 for (x
= 0; x
< image_width
; ++x
)
11966 int i
= raster
[y
* image_width
+ x
];
11967 XPutPixel (ximg
, x
+ image_left
, y
+ image_top
, pixel_colors
[i
]);
11971 DGifCloseFile (gif
);
11973 /* Put the image into the pixmap, then free the X image and its buffer. */
11974 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
11975 x_destroy_x_image (ximg
);
11982 #endif /* HAVE_GIF != 0 */
11986 /***********************************************************************
11988 ***********************************************************************/
11990 #ifdef HAVE_GHOSTSCRIPT
11991 static int gs_image_p
P_ ((Lisp_Object object
));
11992 static int gs_load
P_ ((struct frame
*f
, struct image
*img
));
11993 static void gs_clear_image
P_ ((struct frame
*f
, struct image
*img
));
11995 /* The symbol `postscript' identifying images of this type. */
11997 Lisp_Object Qpostscript
;
11999 /* Keyword symbols. */
12001 Lisp_Object QCloader
, QCbounding_box
, QCpt_width
, QCpt_height
;
12003 /* Indices of image specification fields in gs_format, below. */
12005 enum gs_keyword_index
12021 /* Vector of image_keyword structures describing the format
12022 of valid user-defined image specifications. */
12024 static struct image_keyword gs_format
[GS_LAST
] =
12026 {":type", IMAGE_SYMBOL_VALUE
, 1},
12027 {":pt-width", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
12028 {":pt-height", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
12029 {":file", IMAGE_STRING_VALUE
, 1},
12030 {":loader", IMAGE_FUNCTION_VALUE
, 0},
12031 {":bounding-box", IMAGE_DONT_CHECK_VALUE_TYPE
, 1},
12032 {":ascent", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
12033 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
12034 {":relief", IMAGE_INTEGER_VALUE
, 0},
12035 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
12036 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
12039 /* Structure describing the image type `ghostscript'. */
12041 static struct image_type gs_type
=
12051 /* Free X resources of Ghostscript image IMG which is used on frame F. */
12054 gs_clear_image (f
, img
)
12058 /* IMG->data.ptr_val may contain a recorded colormap. */
12059 xfree (img
->data
.ptr_val
);
12060 x_clear_image (f
, img
);
12064 /* Return non-zero if OBJECT is a valid Ghostscript image
12068 gs_image_p (object
)
12069 Lisp_Object object
;
12071 struct image_keyword fmt
[GS_LAST
];
12075 bcopy (gs_format
, fmt
, sizeof fmt
);
12077 if (!parse_image_spec (object
, fmt
, GS_LAST
, Qpostscript
)
12078 || (fmt
[GS_ASCENT
].count
12079 && XFASTINT (fmt
[GS_ASCENT
].value
) > 100))
12082 /* Bounding box must be a list or vector containing 4 integers. */
12083 tem
= fmt
[GS_BOUNDING_BOX
].value
;
12086 for (i
= 0; i
< 4; ++i
, tem
= XCDR (tem
))
12087 if (!CONSP (tem
) || !INTEGERP (XCAR (tem
)))
12092 else if (VECTORP (tem
))
12094 if (XVECTOR (tem
)->size
!= 4)
12096 for (i
= 0; i
< 4; ++i
)
12097 if (!INTEGERP (XVECTOR (tem
)->contents
[i
]))
12107 /* Load Ghostscript image IMG for use on frame F. Value is non-zero
12116 Lisp_Object window_and_pixmap_id
= Qnil
, loader
, pt_height
, pt_width
;
12117 struct gcpro gcpro1
, gcpro2
;
12119 double in_width
, in_height
;
12120 Lisp_Object pixel_colors
= Qnil
;
12122 /* Compute pixel size of pixmap needed from the given size in the
12123 image specification. Sizes in the specification are in pt. 1 pt
12124 = 1/72 in, xdpi and ydpi are stored in the frame's X display
12126 pt_width
= image_spec_value (img
->spec
, QCpt_width
, NULL
);
12127 in_width
= XFASTINT (pt_width
) / 72.0;
12128 img
->width
= in_width
* FRAME_W32_DISPLAY_INFO (f
)->resx
;
12129 pt_height
= image_spec_value (img
->spec
, QCpt_height
, NULL
);
12130 in_height
= XFASTINT (pt_height
) / 72.0;
12131 img
->height
= in_height
* FRAME_W32_DISPLAY_INFO (f
)->resy
;
12133 /* Create the pixmap. */
12135 xassert (img
->pixmap
== 0);
12136 img
->pixmap
= XCreatePixmap (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
12137 img
->width
, img
->height
,
12138 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)));
12143 image_error ("Unable to create pixmap for `%s'", img
->spec
, Qnil
);
12147 /* Call the loader to fill the pixmap. It returns a process object
12148 if successful. We do not record_unwind_protect here because
12149 other places in redisplay like calling window scroll functions
12150 don't either. Let the Lisp loader use `unwind-protect' instead. */
12151 GCPRO2 (window_and_pixmap_id
, pixel_colors
);
12153 sprintf (buffer
, "%lu %lu",
12154 (unsigned long) FRAME_W32_WINDOW (f
),
12155 (unsigned long) img
->pixmap
);
12156 window_and_pixmap_id
= build_string (buffer
);
12158 sprintf (buffer
, "%lu %lu",
12159 FRAME_FOREGROUND_PIXEL (f
),
12160 FRAME_BACKGROUND_PIXEL (f
));
12161 pixel_colors
= build_string (buffer
);
12163 XSETFRAME (frame
, f
);
12164 loader
= image_spec_value (img
->spec
, QCloader
, NULL
);
12166 loader
= intern ("gs-load-image");
12168 img
->data
.lisp_val
= call6 (loader
, frame
, img
->spec
,
12169 make_number (img
->width
),
12170 make_number (img
->height
),
12171 window_and_pixmap_id
,
12174 return PROCESSP (img
->data
.lisp_val
);
12178 /* Kill the Ghostscript process that was started to fill PIXMAP on
12179 frame F. Called from XTread_socket when receiving an event
12180 telling Emacs that Ghostscript has finished drawing. */
12183 x_kill_gs_process (pixmap
, f
)
12187 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
12191 /* Find the image containing PIXMAP. */
12192 for (i
= 0; i
< c
->used
; ++i
)
12193 if (c
->images
[i
]->pixmap
== pixmap
)
12196 /* Kill the GS process. We should have found PIXMAP in the image
12197 cache and its image should contain a process object. */
12198 xassert (i
< c
->used
);
12199 img
= c
->images
[i
];
12200 xassert (PROCESSP (img
->data
.lisp_val
));
12201 Fkill_process (img
->data
.lisp_val
, Qnil
);
12202 img
->data
.lisp_val
= Qnil
;
12204 /* On displays with a mutable colormap, figure out the colors
12205 allocated for the image by looking at the pixels of an XImage for
12207 class = FRAME_W32_DISPLAY_INFO (f
)->visual
->class;
12208 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
12214 /* Try to get an XImage for img->pixmep. */
12215 ximg
= XGetImage (FRAME_W32_DISPLAY (f
), img
->pixmap
,
12216 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
12221 /* Initialize the color table. */
12222 init_color_table ();
12224 /* For each pixel of the image, look its color up in the
12225 color table. After having done so, the color table will
12226 contain an entry for each color used by the image. */
12227 for (y
= 0; y
< img
->height
; ++y
)
12228 for (x
= 0; x
< img
->width
; ++x
)
12230 unsigned long pixel
= XGetPixel (ximg
, x
, y
);
12231 lookup_pixel_color (f
, pixel
);
12234 /* Record colors in the image. Free color table and XImage. */
12235 img
->colors
= colors_in_color_table (&img
->ncolors
);
12236 free_color_table ();
12237 XDestroyImage (ximg
);
12239 #if 0 /* This doesn't seem to be the case. If we free the colors
12240 here, we get a BadAccess later in x_clear_image when
12241 freeing the colors. */
12242 /* We have allocated colors once, but Ghostscript has also
12243 allocated colors on behalf of us. So, to get the
12244 reference counts right, free them once. */
12247 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
12248 XFreeColors (FRAME_W32_DISPLAY (f
), cmap
,
12249 img
->colors
, img
->ncolors
, 0);
12254 image_error ("Cannot get X image of `%s'; colors will not be freed",
12261 #endif /* HAVE_GHOSTSCRIPT */
12264 /***********************************************************************
12266 ***********************************************************************/
12268 DEFUN ("x-change-window-property", Fx_change_window_property
,
12269 Sx_change_window_property
, 2, 3, 0,
12270 "Change window property PROP to VALUE on the X window of FRAME.\n\
12271 PROP and VALUE must be strings. FRAME nil or omitted means use the\n\
12272 selected frame. Value is VALUE.")
12273 (prop
, value
, frame
)
12274 Lisp_Object frame
, prop
, value
;
12276 #if 0 /* TODO : port window properties to W32 */
12277 struct frame
*f
= check_x_frame (frame
);
12280 CHECK_STRING (prop
, 1);
12281 CHECK_STRING (value
, 2);
12284 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
12285 XChangeProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
12286 prop_atom
, XA_STRING
, 8, PropModeReplace
,
12287 XSTRING (value
)->data
, XSTRING (value
)->size
);
12289 /* Make sure the property is set when we return. */
12290 XFlush (FRAME_W32_DISPLAY (f
));
12299 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
12300 Sx_delete_window_property
, 1, 2, 0,
12301 "Remove window property PROP from X window of FRAME.\n\
12302 FRAME nil or omitted means use the selected frame. Value is PROP.")
12304 Lisp_Object prop
, frame
;
12306 #if 0 /* TODO : port window properties to W32 */
12308 struct frame
*f
= check_x_frame (frame
);
12311 CHECK_STRING (prop
, 1);
12313 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
12314 XDeleteProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
), prop_atom
);
12316 /* Make sure the property is removed when we return. */
12317 XFlush (FRAME_W32_DISPLAY (f
));
12325 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
12327 "Value is the value of window property PROP on FRAME.\n\
12328 If FRAME is nil or omitted, use the selected frame. Value is nil\n\
12329 if FRAME hasn't a property with name PROP or if PROP has no string\n\
12332 Lisp_Object prop
, frame
;
12334 #if 0 /* TODO : port window properties to W32 */
12336 struct frame
*f
= check_x_frame (frame
);
12339 Lisp_Object prop_value
= Qnil
;
12340 char *tmp_data
= NULL
;
12343 unsigned long actual_size
, bytes_remaining
;
12345 CHECK_STRING (prop
, 1);
12347 prop_atom
= XInternAtom (FRAME_W32_DISPLAY (f
), XSTRING (prop
)->data
, False
);
12348 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
12349 prop_atom
, 0, 0, False
, XA_STRING
,
12350 &actual_type
, &actual_format
, &actual_size
,
12351 &bytes_remaining
, (unsigned char **) &tmp_data
);
12354 int size
= bytes_remaining
;
12359 rc
= XGetWindowProperty (FRAME_W32_DISPLAY (f
), FRAME_W32_WINDOW (f
),
12360 prop_atom
, 0, bytes_remaining
,
12362 &actual_type
, &actual_format
,
12363 &actual_size
, &bytes_remaining
,
12364 (unsigned char **) &tmp_data
);
12366 prop_value
= make_string (tmp_data
, size
);
12381 /***********************************************************************
12383 ***********************************************************************/
12385 /* If non-null, an asynchronous timer that, when it expires, displays
12386 an hourglass cursor on all frames. */
12388 static struct atimer
*hourglass_atimer
;
12390 /* Non-zero means an hourglass cursor is currently shown. */
12392 static int hourglass_shown_p
;
12394 /* Number of seconds to wait before displaying an hourglass cursor. */
12396 static Lisp_Object Vhourglass_delay
;
12398 /* Default number of seconds to wait before displaying an hourglass
12401 #define DEFAULT_HOURGLASS_DELAY 1
12403 /* Function prototypes. */
12405 static void show_hourglass
P_ ((struct atimer
*));
12406 static void hide_hourglass
P_ ((void));
12409 /* Cancel a currently active hourglass timer, and start a new one. */
12414 #if 0 /* TODO: cursor shape changes. */
12416 int secs
, usecs
= 0;
12418 cancel_hourglass ();
12420 if (INTEGERP (Vhourglass_delay
)
12421 && XINT (Vhourglass_delay
) > 0)
12422 secs
= XFASTINT (Vhourglass_delay
);
12423 else if (FLOATP (Vhourglass_delay
)
12424 && XFLOAT_DATA (Vhourglass_delay
) > 0)
12427 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
12428 secs
= XFASTINT (tem
);
12429 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
12432 secs
= DEFAULT_HOURGLASS_DELAY
;
12434 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
12435 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
12436 show_hourglass
, NULL
);
12441 /* Cancel the hourglass cursor timer if active, hide an hourglass
12442 cursor if shown. */
12445 cancel_hourglass ()
12447 if (hourglass_atimer
)
12449 cancel_atimer (hourglass_atimer
);
12450 hourglass_atimer
= NULL
;
12453 if (hourglass_shown_p
)
12458 /* Timer function of hourglass_atimer. TIMER is equal to
12461 Display an hourglass cursor on all frames by mapping the frames'
12462 hourglass_window. Set the hourglass_p flag in the frames'
12463 output_data.x structure to indicate that an hourglass cursor is
12464 shown on the frames. */
12467 show_hourglass (timer
)
12468 struct atimer
*timer
;
12470 #if 0 /* TODO: cursor shape changes. */
12471 /* The timer implementation will cancel this timer automatically
12472 after this function has run. Set hourglass_atimer to null
12473 so that we know the timer doesn't have to be canceled. */
12474 hourglass_atimer
= NULL
;
12476 if (!hourglass_shown_p
)
12478 Lisp_Object rest
, frame
;
12482 FOR_EACH_FRAME (rest
, frame
)
12483 if (FRAME_W32_P (XFRAME (frame
)))
12485 struct frame
*f
= XFRAME (frame
);
12487 f
->output_data
.w32
->hourglass_p
= 1;
12489 if (!f
->output_data
.w32
->hourglass_window
)
12491 unsigned long mask
= CWCursor
;
12492 XSetWindowAttributes attrs
;
12494 attrs
.cursor
= f
->output_data
.w32
->hourglass_cursor
;
12496 f
->output_data
.w32
->hourglass_window
12497 = XCreateWindow (FRAME_X_DISPLAY (f
),
12498 FRAME_OUTER_WINDOW (f
),
12499 0, 0, 32000, 32000, 0, 0,
12505 XMapRaised (FRAME_X_DISPLAY (f
),
12506 f
->output_data
.w32
->hourglass_window
);
12507 XFlush (FRAME_X_DISPLAY (f
));
12510 hourglass_shown_p
= 1;
12517 /* Hide the hourglass cursor on all frames, if it is currently shown. */
12522 #if 0 /* TODO: cursor shape changes. */
12523 if (hourglass_shown_p
)
12525 Lisp_Object rest
, frame
;
12528 FOR_EACH_FRAME (rest
, frame
)
12530 struct frame
*f
= XFRAME (frame
);
12532 if (FRAME_W32_P (f
)
12533 /* Watch out for newly created frames. */
12534 && f
->output_data
.x
->hourglass_window
)
12536 XUnmapWindow (FRAME_X_DISPLAY (f
),
12537 f
->output_data
.x
->hourglass_window
);
12538 /* Sync here because XTread_socket looks at the
12539 hourglass_p flag that is reset to zero below. */
12540 XSync (FRAME_X_DISPLAY (f
), False
);
12541 f
->output_data
.x
->hourglass_p
= 0;
12545 hourglass_shown_p
= 0;
12553 /***********************************************************************
12555 ***********************************************************************/
12557 static Lisp_Object x_create_tip_frame
P_ ((struct w32_display_info
*,
12560 /* The frame of a currently visible tooltip, or null. */
12562 Lisp_Object tip_frame
;
12564 /* If non-nil, a timer started that hides the last tooltip when it
12567 Lisp_Object tip_timer
;
12571 unwind_create_tip_frame (frame
)
12574 Lisp_Object deleted
;
12576 deleted
= unwind_create_frame (frame
);
12577 if (EQ (deleted
, Qt
))
12587 /* Create a frame for a tooltip on the display described by DPYINFO.
12588 PARMS is a list of frame parameters. Value is the frame.
12590 Note that functions called here, esp. x_default_parameter can
12591 signal errors, for instance when a specified color name is
12592 undefined. We have to make sure that we're in a consistent state
12593 when this happens. */
12596 x_create_tip_frame (dpyinfo
, parms
)
12597 struct w32_display_info
*dpyinfo
;
12600 #if 0 /* TODO : w32 version */
12602 Lisp_Object frame
, tem
;
12604 long window_prompting
= 0;
12606 int count
= BINDING_STACK_SIZE ();
12607 struct gcpro gcpro1
, gcpro2
, gcpro3
;
12612 /* Use this general default value to start with until we know if
12613 this frame has a specified name. */
12614 Vx_resource_name
= Vinvocation_name
;
12616 #ifdef MULTI_KBOARD
12617 kb
= dpyinfo
->kboard
;
12619 kb
= &the_only_kboard
;
12622 /* Get the name of the frame to use for resource lookup. */
12623 name
= w32_get_arg (parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
12624 if (!STRINGP (name
)
12625 && !EQ (name
, Qunbound
)
12627 error ("Invalid frame name--not a string or nil");
12628 Vx_resource_name
= name
;
12631 GCPRO3 (parms
, name
, frame
);
12632 f
= make_frame (1);
12633 XSETFRAME (frame
, f
);
12634 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
12635 record_unwind_protect (unwind_create_tip_frame
, frame
);
12637 f
->output_method
= output_w32
;
12638 f
->output_data
.w32
=
12639 (struct w32_output
*) xmalloc (sizeof (struct w32_output
));
12640 bzero (f
->output_data
.w32
, sizeof (struct w32_output
));
12642 f
->output_data
.w32
->icon_bitmap
= -1;
12644 f
->output_data
.w32
->fontset
= -1;
12645 f
->icon_name
= Qnil
;
12648 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
12649 dpyinfo_refcount
= dpyinfo
->reference_count
;
12650 #endif /* GLYPH_DEBUG */
12651 #ifdef MULTI_KBOARD
12652 FRAME_KBOARD (f
) = kb
;
12654 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
12655 f
->output_data
.w32
->explicit_parent
= 0;
12657 /* Set the name; the functions to which we pass f expect the name to
12659 if (EQ (name
, Qunbound
) || NILP (name
))
12661 f
->name
= build_string (dpyinfo
->x_id_name
);
12662 f
->explicit_name
= 0;
12667 f
->explicit_name
= 1;
12668 /* use the frame's title when getting resources for this frame. */
12669 specbind (Qx_resource_name
, name
);
12672 /* Extract the window parameters from the supplied values
12673 that are needed to determine window geometry. */
12677 font
= w32_get_arg (parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
12680 /* First, try whatever font the caller has specified. */
12681 if (STRINGP (font
))
12683 tem
= Fquery_fontset (font
, Qnil
);
12685 font
= x_new_fontset (f
, XSTRING (tem
)->data
);
12687 font
= x_new_font (f
, XSTRING (font
)->data
);
12690 /* Try out a font which we hope has bold and italic variations. */
12691 if (!STRINGP (font
))
12692 font
= x_new_font (f
, "-*-courier new-normal-r-*-*-*-100-*-*-*-*-iso8859-1");
12693 if (!STRINGP (font
))
12694 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
12695 if (! STRINGP (font
))
12696 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
12697 if (! STRINGP (font
))
12698 /* This was formerly the first thing tried, but it finds too many fonts
12699 and takes too long. */
12700 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
12701 /* If those didn't work, look for something which will at least work. */
12702 if (! STRINGP (font
))
12703 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
12705 if (! STRINGP (font
))
12706 font
= build_string ("fixed");
12708 x_default_parameter (f
, parms
, Qfont
, font
,
12709 "font", "Font", RES_TYPE_STRING
);
12712 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
12713 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
12715 /* This defaults to 2 in order to match xterm. We recognize either
12716 internalBorderWidth or internalBorder (which is what xterm calls
12718 if (NILP (Fassq (Qinternal_border_width
, parms
)))
12722 value
= w32_get_arg (parms
, Qinternal_border_width
,
12723 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
12724 if (! EQ (value
, Qunbound
))
12725 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
12729 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
12730 "internalBorderWidth", "internalBorderWidth",
12733 /* Also do the stuff which must be set before the window exists. */
12734 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
12735 "foreground", "Foreground", RES_TYPE_STRING
);
12736 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
12737 "background", "Background", RES_TYPE_STRING
);
12738 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
12739 "pointerColor", "Foreground", RES_TYPE_STRING
);
12740 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
12741 "cursorColor", "Foreground", RES_TYPE_STRING
);
12742 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
12743 "borderColor", "BorderColor", RES_TYPE_STRING
);
12745 /* Init faces before x_default_parameter is called for scroll-bar
12746 parameters because that function calls x_set_scroll_bar_width,
12747 which calls change_frame_size, which calls Fset_window_buffer,
12748 which runs hooks, which call Fvertical_motion. At the end, we
12749 end up in init_iterator with a null face cache, which should not
12751 init_frame_faces (f
);
12753 f
->output_data
.w32
->parent_desc
= FRAME_W32_DISPLAY_INFO (f
)->root_window
;
12754 window_prompting
= x_figure_window_size (f
, parms
);
12756 if (window_prompting
& XNegative
)
12758 if (window_prompting
& YNegative
)
12759 f
->output_data
.w32
->win_gravity
= SouthEastGravity
;
12761 f
->output_data
.w32
->win_gravity
= NorthEastGravity
;
12765 if (window_prompting
& YNegative
)
12766 f
->output_data
.w32
->win_gravity
= SouthWestGravity
;
12768 f
->output_data
.w32
->win_gravity
= NorthWestGravity
;
12771 f
->output_data
.w32
->size_hint_flags
= window_prompting
;
12773 XSetWindowAttributes attrs
;
12774 unsigned long mask
;
12777 mask
= CWBackPixel
| CWOverrideRedirect
| CWSaveUnder
| CWEventMask
;
12778 /* Window managers looks at the override-redirect flag to
12779 determine whether or net to give windows a decoration (Xlib
12781 attrs
.override_redirect
= True
;
12782 attrs
.save_under
= True
;
12783 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
12784 /* Arrange for getting MapNotify and UnmapNotify events. */
12785 attrs
.event_mask
= StructureNotifyMask
;
12787 = FRAME_W32_WINDOW (f
)
12788 = XCreateWindow (FRAME_W32_DISPLAY (f
),
12789 FRAME_W32_DISPLAY_INFO (f
)->root_window
,
12790 /* x, y, width, height */
12794 CopyFromParent
, InputOutput
, CopyFromParent
,
12801 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
12802 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
12803 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
12804 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
12805 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
12806 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
12808 /* Dimensions, especially f->height, must be done via change_frame_size.
12809 Change will not be effected unless different from the current
12812 height
= f
->height
;
12814 SET_FRAME_WIDTH (f
, 0);
12815 change_frame_size (f
, height
, width
, 1, 0, 0);
12821 /* It is now ok to make the frame official even if we get an error
12822 below. And the frame needs to be on Vframe_list or making it
12823 visible won't work. */
12824 Vframe_list
= Fcons (frame
, Vframe_list
);
12827 /* Now that the frame is official, it counts as a reference to
12829 FRAME_W32_DISPLAY_INFO (f
)->reference_count
++;
12831 return unbind_to (count
, frame
);
12836 #ifdef TODO /* Tooltip support not complete. */
12837 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
12838 "Show STRING in a \"tooltip\" window on frame FRAME.\n\
12839 A tooltip window is a small window displaying a string.\n\
12841 FRAME nil or omitted means use the selected frame.\n\
12843 PARMS is an optional list of frame parameters which can be\n\
12844 used to change the tooltip's appearance.\n\
12846 Automatically hide the tooltip after TIMEOUT seconds.\n\
12847 TIMEOUT nil means use the default timeout of 5 seconds.\n\
12849 If the list of frame parameters PARAMS contains a `left' parameters,\n\
12850 the tooltip is displayed at that x-position. Otherwise it is\n\
12851 displayed at the mouse position, with offset DX added (default is 5 if\n\
12852 DX isn't specified). Likewise for the y-position; if a `top' frame\n\
12853 parameter is specified, it determines the y-position of the tooltip\n\
12854 window, otherwise it is displayed at the mouse position, with offset\n\
12855 DY added (default is 10).")
12856 (string
, frame
, parms
, timeout
, dx
, dy
)
12857 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
12861 Window root
, child
;
12862 Lisp_Object buffer
, top
, left
;
12863 struct buffer
*old_buffer
;
12864 struct text_pos pos
;
12865 int i
, width
, height
;
12866 int root_x
, root_y
, win_x
, win_y
;
12868 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
12869 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
12870 int count
= specpdl_ptr
- specpdl
;
12872 specbind (Qinhibit_redisplay
, Qt
);
12874 GCPRO4 (string
, parms
, frame
, timeout
);
12876 CHECK_STRING (string
, 0);
12877 f
= check_x_frame (frame
);
12878 if (NILP (timeout
))
12879 timeout
= make_number (5);
12881 CHECK_NATNUM (timeout
, 2);
12884 dx
= make_number (5);
12886 CHECK_NUMBER (dx
, 5);
12889 dy
= make_number (-10);
12891 CHECK_NUMBER (dy
, 6);
12893 if (NILP (last_show_tip_args
))
12894 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
12896 if (!NILP (tip_frame
))
12898 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
12899 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
12900 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
12902 if (EQ (frame
, last_frame
)
12903 && !NILP (Fequal (last_string
, string
))
12904 && !NILP (Fequal (last_parms
, parms
)))
12906 struct frame
*f
= XFRAME (tip_frame
);
12908 /* Only DX and DY have changed. */
12909 if (!NILP (tip_timer
))
12911 Lisp_Object timer
= tip_timer
;
12913 call1 (Qcancel_timer
, timer
);
12917 compute_tip_xy (f
, parms
, dx
, dy
, &root_x
, &root_y
);
12918 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12919 root_x
, root_y
- PIXEL_HEIGHT (f
));
12925 /* Hide a previous tip, if any. */
12928 ASET (last_show_tip_args
, 0, string
);
12929 ASET (last_show_tip_args
, 1, frame
);
12930 ASET (last_show_tip_args
, 2, parms
);
12932 /* Add default values to frame parameters. */
12933 if (NILP (Fassq (Qname
, parms
)))
12934 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
12935 if (NILP (Fassq (Qinternal_border_width
, parms
)))
12936 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
12937 if (NILP (Fassq (Qborder_width
, parms
)))
12938 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
12939 if (NILP (Fassq (Qborder_color
, parms
)))
12940 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
12941 if (NILP (Fassq (Qbackground_color
, parms
)))
12942 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
12945 /* Create a frame for the tooltip, and record it in the global
12946 variable tip_frame. */
12947 frame
= x_create_tip_frame (FRAME_W32_DISPLAY_INFO (f
), parms
);
12948 f
= XFRAME (frame
);
12950 /* Set up the frame's root window. Currently we use a size of 80
12951 columns x 40 lines. If someone wants to show a larger tip, he
12952 will loose. I don't think this is a realistic case. */
12953 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
12954 w
->left
= w
->top
= make_number (0);
12955 w
->width
= make_number (80);
12956 w
->height
= make_number (40);
12958 w
->pseudo_window_p
= 1;
12960 /* Display the tooltip text in a temporary buffer. */
12961 buffer
= Fget_buffer_create (build_string (" *tip*"));
12962 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
);
12963 old_buffer
= current_buffer
;
12964 set_buffer_internal_1 (XBUFFER (buffer
));
12966 Finsert (1, &string
);
12967 clear_glyph_matrix (w
->desired_matrix
);
12968 clear_glyph_matrix (w
->current_matrix
);
12969 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
12970 try_window (FRAME_ROOT_WINDOW (f
), pos
);
12972 /* Compute width and height of the tooltip. */
12973 width
= height
= 0;
12974 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
12976 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
12977 struct glyph
*last
;
12980 /* Stop at the first empty row at the end. */
12981 if (!row
->enabled_p
|| !row
->displays_text_p
)
12984 /* Let the row go over the full width of the frame. */
12985 row
->full_width_p
= 1;
12987 /* There's a glyph at the end of rows that is use to place
12988 the cursor there. Don't include the width of this glyph. */
12989 if (row
->used
[TEXT_AREA
])
12991 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
12992 row_width
= row
->pixel_width
- last
->pixel_width
;
12995 row_width
= row
->pixel_width
;
12997 height
+= row
->height
;
12998 width
= max (width
, row_width
);
13001 /* Add the frame's internal border to the width and height the X
13002 window should have. */
13003 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
13004 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
13006 /* Move the tooltip window where the mouse pointer is. Resize and
13008 compute_tip_xy (f
, parms
, dx
, dy
, &root_x
, &root_y
);
13010 #if 0 /* TODO : W32 specifics */
13012 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
13013 root_x
, root_y
- height
, width
, height
);
13014 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13018 /* Draw into the window. */
13019 w
->must_be_updated_p
= 1;
13020 update_single_window (w
, 1);
13022 /* Restore original current buffer. */
13023 set_buffer_internal_1 (old_buffer
);
13024 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
13027 /* Let the tip disappear after timeout seconds. */
13028 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
13029 intern ("x-hide-tip"));
13032 return unbind_to (count
, Qnil
);
13036 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
13037 "Hide the current tooltip window, if there is any.\n\
13038 Value is t is tooltip was open, nil otherwise.")
13042 Lisp_Object deleted
, frame
, timer
;
13043 struct gcpro gcpro1
, gcpro2
;
13045 /* Return quickly if nothing to do. */
13046 if (NILP (tip_timer
) && NILP (tip_frame
))
13051 GCPRO2 (frame
, timer
);
13052 tip_frame
= tip_timer
= deleted
= Qnil
;
13054 count
= BINDING_STACK_SIZE ();
13055 specbind (Qinhibit_redisplay
, Qt
);
13056 specbind (Qinhibit_quit
, Qt
);
13059 call1 (Qcancel_timer
, timer
);
13061 if (FRAMEP (frame
))
13063 Fdelete_frame (frame
, Qnil
);
13068 return unbind_to (count
, deleted
);
13074 /***********************************************************************
13075 File selection dialog
13076 ***********************************************************************/
13078 extern Lisp_Object Qfile_name_history
;
13080 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
13081 "Read file name, prompting with PROMPT in directory DIR.\n\
13082 Use a file selection dialog.\n\
13083 Select DEFAULT-FILENAME in the dialog's file selection box, if\n\
13084 specified. Ensure that file exists if MUSTMATCH is non-nil.")
13085 (prompt
, dir
, default_filename
, mustmatch
)
13086 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
13088 struct frame
*f
= SELECTED_FRAME ();
13089 Lisp_Object file
= Qnil
;
13090 int count
= specpdl_ptr
- specpdl
;
13091 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
13092 char filename
[MAX_PATH
+ 1];
13093 char init_dir
[MAX_PATH
+ 1];
13094 int use_dialog_p
= 1;
13096 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
13097 CHECK_STRING (prompt
, 0);
13098 CHECK_STRING (dir
, 1);
13100 /* Create the dialog with PROMPT as title, using DIR as initial
13101 directory and using "*" as pattern. */
13102 dir
= Fexpand_file_name (dir
, Qnil
);
13103 strncpy (init_dir
, XSTRING (dir
)->data
, MAX_PATH
);
13104 init_dir
[MAX_PATH
] = '\0';
13105 unixtodos_filename (init_dir
);
13107 if (STRINGP (default_filename
))
13109 char *file_name_only
;
13110 char *full_path_name
= XSTRING (default_filename
)->data
;
13112 unixtodos_filename (full_path_name
);
13114 file_name_only
= strrchr (full_path_name
, '\\');
13115 if (!file_name_only
)
13116 file_name_only
= full_path_name
;
13121 /* If default_file_name is a directory, don't use the open
13122 file dialog, as it does not support selecting
13124 if (!(*file_name_only
))
13128 strncpy (filename
, file_name_only
, MAX_PATH
);
13129 filename
[MAX_PATH
] = '\0';
13132 filename
[0] = '\0';
13136 OPENFILENAME file_details
;
13138 /* Prevent redisplay. */
13139 specbind (Qinhibit_redisplay
, Qt
);
13142 bzero (&file_details
, sizeof (file_details
));
13143 file_details
.lStructSize
= sizeof (file_details
);
13144 file_details
.hwndOwner
= FRAME_W32_WINDOW (f
);
13145 /* Undocumented Bug in Common File Dialog:
13146 If a filter is not specified, shell links are not resolved. */
13147 file_details
.lpstrFilter
= "All Files (*.*)\0*.*\0\0";
13148 file_details
.lpstrFile
= filename
;
13149 file_details
.nMaxFile
= sizeof (filename
);
13150 file_details
.lpstrInitialDir
= init_dir
;
13151 file_details
.lpstrTitle
= XSTRING (prompt
)->data
;
13152 file_details
.Flags
= OFN_HIDEREADONLY
| OFN_NOCHANGEDIR
;
13154 if (!NILP (mustmatch
))
13155 file_details
.Flags
|= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
13157 if (GetOpenFileName (&file_details
))
13159 dostounix_filename (filename
);
13160 file
= DECODE_FILE(build_string (filename
));
13166 file
= unbind_to (count
, file
);
13168 /* Open File dialog will not allow folders to be selected, so resort
13169 to minibuffer completing reads for directories. */
13171 file
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
13172 dir
, mustmatch
, dir
, Qfile_name_history
,
13173 default_filename
, Qnil
);
13177 /* Make "Cancel" equivalent to C-g. */
13179 Fsignal (Qquit
, Qnil
);
13181 return unbind_to (count
, file
);
13186 /***********************************************************************
13188 ***********************************************************************/
13192 DEFUN ("imagep", Fimagep
, Simagep
, 1, 1, 0,
13193 "Value is non-nil if SPEC is a valid image specification.")
13197 return valid_image_p (spec
) ? Qt
: Qnil
;
13201 DEFUN ("lookup-image", Flookup_image
, Slookup_image
, 1, 1, 0, "")
13207 if (valid_image_p (spec
))
13208 id
= lookup_image (SELECTED_FRAME (), spec
);
13210 debug_print (spec
);
13211 return make_number (id
);
13214 #endif /* GLYPH_DEBUG != 0 */
13218 /***********************************************************************
13219 w32 specialized functions
13220 ***********************************************************************/
13222 DEFUN ("w32-select-font", Fw32_select_font
, Sw32_select_font
, 0, 1, 0,
13223 "This will display the W32 font dialog and return an X font string corresponding to the selection.")
13227 FRAME_PTR f
= check_x_frame (frame
);
13235 bzero (&cf
, sizeof (cf
));
13236 bzero (&lf
, sizeof (lf
));
13238 cf
.lStructSize
= sizeof (cf
);
13239 cf
.hwndOwner
= FRAME_W32_WINDOW (f
);
13240 cf
.Flags
= CF_FORCEFONTEXIST
| CF_SCREENFONTS
| CF_NOVERTFONTS
;
13241 cf
.lpLogFont
= &lf
;
13243 /* Initialize as much of the font details as we can from the current
13245 hdc
= GetDC (FRAME_W32_WINDOW (f
));
13246 oldobj
= SelectObject (hdc
, FRAME_FONT (f
)->hfont
);
13247 GetTextFace (hdc
, LF_FACESIZE
, lf
.lfFaceName
);
13248 if (GetTextMetrics (hdc
, &tm
))
13250 lf
.lfHeight
= tm
.tmInternalLeading
- tm
.tmHeight
;
13251 lf
.lfWeight
= tm
.tmWeight
;
13252 lf
.lfItalic
= tm
.tmItalic
;
13253 lf
.lfUnderline
= tm
.tmUnderlined
;
13254 lf
.lfStrikeOut
= tm
.tmStruckOut
;
13255 lf
.lfCharSet
= tm
.tmCharSet
;
13256 cf
.Flags
|= CF_INITTOLOGFONTSTRUCT
;
13258 SelectObject (hdc
, oldobj
);
13259 ReleaseDC (FRAME_W32_WINDOW (f
), hdc
);
13261 if (!ChooseFont (&cf
) || !w32_to_x_font (&lf
, buf
, 100, NULL
))
13264 return build_string (buf
);
13267 DEFUN ("w32-send-sys-command", Fw32_send_sys_command
, Sw32_send_sys_command
, 1, 2, 0,
13268 "Send frame a Windows WM_SYSCOMMAND message of type COMMAND.\n\
13269 Some useful values for command are #xf030 to maximise frame (#xf020\n\
13270 to minimize), #xf120 to restore frame to original size, and #xf100\n\
13271 to activate the menubar for keyboard access. #xf140 activates the\n\
13272 screen saver if defined.\n\
13274 If optional parameter FRAME is not specified, use selected frame.")
13276 Lisp_Object command
, frame
;
13278 FRAME_PTR f
= check_x_frame (frame
);
13280 CHECK_NUMBER (command
, 0);
13282 PostMessage (FRAME_W32_WINDOW (f
), WM_SYSCOMMAND
, XINT (command
), 0);
13287 DEFUN ("w32-shell-execute", Fw32_shell_execute
, Sw32_shell_execute
, 2, 4, 0,
13288 "Get Windows to perform OPERATION on DOCUMENT.\n\
13289 This is a wrapper around the ShellExecute system function, which\n\
13290 invokes the application registered to handle OPERATION for DOCUMENT.\n\
13291 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be\n\
13292 nil for the default action), and DOCUMENT is typically the name of a\n\
13293 document file or URL, but can also be a program executable to run or\n\
13294 a directory to open in the Windows Explorer.\n\
13296 If DOCUMENT is a program executable, PARAMETERS can be a string\n\
13297 containing command line parameters, but otherwise should be nil.\n\
13299 SHOW-FLAG can be used to control whether the invoked application is hidden\n\
13300 or minimized. If SHOW-FLAG is nil, the application is displayed normally,\n\
13301 otherwise it is an integer representing a ShowWindow flag:\n\
13303 0 - start hidden\n\
13304 1 - start normally\n\
13305 3 - start maximized\n\
13306 6 - start minimized")
13307 (operation
, document
, parameters
, show_flag
)
13308 Lisp_Object operation
, document
, parameters
, show_flag
;
13310 Lisp_Object current_dir
;
13312 CHECK_STRING (document
, 0);
13314 /* Encode filename and current directory. */
13315 current_dir
= ENCODE_FILE (current_buffer
->directory
);
13316 document
= ENCODE_FILE (document
);
13317 if ((int) ShellExecute (NULL
,
13318 (STRINGP (operation
) ?
13319 XSTRING (operation
)->data
: NULL
),
13320 XSTRING (document
)->data
,
13321 (STRINGP (parameters
) ?
13322 XSTRING (parameters
)->data
: NULL
),
13323 XSTRING (current_dir
)->data
,
13324 (INTEGERP (show_flag
) ?
13325 XINT (show_flag
) : SW_SHOWDEFAULT
))
13328 error ("ShellExecute failed: %s", w32_strerror (0));
13331 /* Lookup virtual keycode from string representing the name of a
13332 non-ascii keystroke into the corresponding virtual key, using
13333 lispy_function_keys. */
13335 lookup_vk_code (char *key
)
13339 for (i
= 0; i
< 256; i
++)
13340 if (lispy_function_keys
[i
] != 0
13341 && strcmp (lispy_function_keys
[i
], key
) == 0)
13347 /* Convert a one-element vector style key sequence to a hot key
13350 w32_parse_hot_key (key
)
13353 /* Copied from Fdefine_key and store_in_keymap. */
13354 register Lisp_Object c
;
13356 int lisp_modifiers
;
13358 struct gcpro gcpro1
;
13360 CHECK_VECTOR (key
, 0);
13362 if (XFASTINT (Flength (key
)) != 1)
13367 c
= Faref (key
, make_number (0));
13369 if (CONSP (c
) && lucid_event_type_list_p (c
))
13370 c
= Fevent_convert_list (c
);
13374 if (! INTEGERP (c
) && ! SYMBOLP (c
))
13375 error ("Key definition is invalid");
13377 /* Work out the base key and the modifiers. */
13380 c
= parse_modifiers (c
);
13381 lisp_modifiers
= Fcar (Fcdr (c
));
13385 vk_code
= lookup_vk_code (XSYMBOL (c
)->name
->data
);
13387 else if (INTEGERP (c
))
13389 lisp_modifiers
= XINT (c
) & ~CHARACTERBITS
;
13390 /* Many ascii characters are their own virtual key code. */
13391 vk_code
= XINT (c
) & CHARACTERBITS
;
13394 if (vk_code
< 0 || vk_code
> 255)
13397 if ((lisp_modifiers
& meta_modifier
) != 0
13398 && !NILP (Vw32_alt_is_meta
))
13399 lisp_modifiers
|= alt_modifier
;
13401 /* Supply defs missing from mingw32. */
13403 #define MOD_ALT 0x0001
13404 #define MOD_CONTROL 0x0002
13405 #define MOD_SHIFT 0x0004
13406 #define MOD_WIN 0x0008
13409 /* Convert lisp modifiers to Windows hot-key form. */
13410 w32_modifiers
= (lisp_modifiers
& hyper_modifier
) ? MOD_WIN
: 0;
13411 w32_modifiers
|= (lisp_modifiers
& alt_modifier
) ? MOD_ALT
: 0;
13412 w32_modifiers
|= (lisp_modifiers
& ctrl_modifier
) ? MOD_CONTROL
: 0;
13413 w32_modifiers
|= (lisp_modifiers
& shift_modifier
) ? MOD_SHIFT
: 0;
13415 return HOTKEY (vk_code
, w32_modifiers
);
13418 DEFUN ("w32-register-hot-key", Fw32_register_hot_key
, Sw32_register_hot_key
, 1, 1, 0,
13419 "Register KEY as a hot-key combination.\n\
13420 Certain key combinations like Alt-Tab are reserved for system use on\n\
13421 Windows, and therefore are normally intercepted by the system. However,\n\
13422 most of these key combinations can be received by registering them as\n\
13423 hot-keys, overriding their special meaning.\n\
13425 KEY must be a one element key definition in vector form that would be\n\
13426 acceptable to `define-key' (e.g. [A-tab] for Alt-Tab). The meta\n\
13427 modifier is interpreted as Alt if `w32-alt-is-meta' is t, and hyper\n\
13428 is always interpreted as the Windows modifier keys.\n\
13430 The return value is the hotkey-id if registered, otherwise nil.")
13434 key
= w32_parse_hot_key (key
);
13436 if (NILP (Fmemq (key
, w32_grabbed_keys
)))
13438 /* Reuse an empty slot if possible. */
13439 Lisp_Object item
= Fmemq (Qnil
, w32_grabbed_keys
);
13441 /* Safe to add new key to list, even if we have focus. */
13443 w32_grabbed_keys
= Fcons (key
, w32_grabbed_keys
);
13447 /* Notify input thread about new hot-key definition, so that it
13448 takes effect without needing to switch focus. */
13449 PostThreadMessage (dwWindowsThreadId
, WM_EMACS_REGISTER_HOT_KEY
,
13456 DEFUN ("w32-unregister-hot-key", Fw32_unregister_hot_key
, Sw32_unregister_hot_key
, 1, 1, 0,
13457 "Unregister HOTKEY as a hot-key combination.")
13463 if (!INTEGERP (key
))
13464 key
= w32_parse_hot_key (key
);
13466 item
= Fmemq (key
, w32_grabbed_keys
);
13470 /* Notify input thread about hot-key definition being removed, so
13471 that it takes effect without needing focus switch. */
13472 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_UNREGISTER_HOT_KEY
,
13473 (WPARAM
) XINT (XCAR (item
)), (LPARAM
) item
))
13476 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
13483 DEFUN ("w32-registered-hot-keys", Fw32_registered_hot_keys
, Sw32_registered_hot_keys
, 0, 0, 0,
13484 "Return list of registered hot-key IDs.")
13487 return Fcopy_sequence (w32_grabbed_keys
);
13490 DEFUN ("w32-reconstruct-hot-key", Fw32_reconstruct_hot_key
, Sw32_reconstruct_hot_key
, 1, 1, 0,
13491 "Convert hot-key ID to a lisp key combination.")
13493 Lisp_Object hotkeyid
;
13495 int vk_code
, w32_modifiers
;
13498 CHECK_NUMBER (hotkeyid
, 0);
13500 vk_code
= HOTKEY_VK_CODE (hotkeyid
);
13501 w32_modifiers
= HOTKEY_MODIFIERS (hotkeyid
);
13503 if (lispy_function_keys
[vk_code
])
13504 key
= intern (lispy_function_keys
[vk_code
]);
13506 key
= make_number (vk_code
);
13508 key
= Fcons (key
, Qnil
);
13509 if (w32_modifiers
& MOD_SHIFT
)
13510 key
= Fcons (Qshift
, key
);
13511 if (w32_modifiers
& MOD_CONTROL
)
13512 key
= Fcons (Qctrl
, key
);
13513 if (w32_modifiers
& MOD_ALT
)
13514 key
= Fcons (NILP (Vw32_alt_is_meta
) ? Qalt
: Qmeta
, key
);
13515 if (w32_modifiers
& MOD_WIN
)
13516 key
= Fcons (Qhyper
, key
);
13521 DEFUN ("w32-toggle-lock-key", Fw32_toggle_lock_key
, Sw32_toggle_lock_key
, 1, 2, 0,
13522 "Toggle the state of the lock key KEY.\n\
13523 KEY can be `capslock', `kp-numlock', or `scroll'.\n\
13524 If the optional parameter NEW-STATE is a number, then the state of KEY\n\
13525 is set to off if the low bit of NEW-STATE is zero, otherwise on.")
13527 Lisp_Object key
, new_state
;
13531 if (EQ (key
, intern ("capslock")))
13532 vk_code
= VK_CAPITAL
;
13533 else if (EQ (key
, intern ("kp-numlock")))
13534 vk_code
= VK_NUMLOCK
;
13535 else if (EQ (key
, intern ("scroll")))
13536 vk_code
= VK_SCROLL
;
13540 if (!dwWindowsThreadId
)
13541 return make_number (w32_console_toggle_lock_key (vk_code
, new_state
));
13543 if (PostThreadMessage (dwWindowsThreadId
, WM_EMACS_TOGGLE_LOCK_KEY
,
13544 (WPARAM
) vk_code
, (LPARAM
) new_state
))
13547 GetMessage (&msg
, NULL
, WM_EMACS_DONE
, WM_EMACS_DONE
);
13548 return make_number (msg
.wParam
);
13553 DEFUN ("file-system-info", Ffile_system_info
, Sfile_system_info
, 1, 1, 0,
13554 "Return storage information about the file system FILENAME is on.\n\
13555 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total\n\
13556 storage of the file system, FREE is the free storage, and AVAIL is the\n\
13557 storage available to a non-superuser. All 3 numbers are in bytes.\n\
13558 If the underlying system call fails, value is nil.")
13560 Lisp_Object filename
;
13562 Lisp_Object encoded
, value
;
13564 CHECK_STRING (filename
, 0);
13565 filename
= Fexpand_file_name (filename
, Qnil
);
13566 encoded
= ENCODE_FILE (filename
);
13570 /* Determining the required information on Windows turns out, sadly,
13571 to be more involved than one would hope. The original Win32 api
13572 call for this will return bogus information on some systems, but we
13573 must dynamically probe for the replacement api, since that was
13574 added rather late on. */
13576 HMODULE hKernel
= GetModuleHandle ("kernel32");
13577 BOOL (*pfn_GetDiskFreeSpaceEx
)
13578 (char *, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
)
13579 = (void *) GetProcAddress (hKernel
, "GetDiskFreeSpaceEx");
13581 /* On Windows, we may need to specify the root directory of the
13582 volume holding FILENAME. */
13583 char rootname
[MAX_PATH
];
13584 char *name
= XSTRING (encoded
)->data
;
13586 /* find the root name of the volume if given */
13587 if (isalpha (name
[0]) && name
[1] == ':')
13589 rootname
[0] = name
[0];
13590 rootname
[1] = name
[1];
13591 rootname
[2] = '\\';
13594 else if (IS_DIRECTORY_SEP (name
[0]) && IS_DIRECTORY_SEP (name
[1]))
13596 char *str
= rootname
;
13600 if (IS_DIRECTORY_SEP (*name
) && --slashes
== 0)
13610 if (pfn_GetDiskFreeSpaceEx
)
13612 LARGE_INTEGER availbytes
;
13613 LARGE_INTEGER freebytes
;
13614 LARGE_INTEGER totalbytes
;
13616 if (pfn_GetDiskFreeSpaceEx(rootname
,
13620 value
= list3 (make_float ((double) totalbytes
.QuadPart
),
13621 make_float ((double) freebytes
.QuadPart
),
13622 make_float ((double) availbytes
.QuadPart
));
13626 DWORD sectors_per_cluster
;
13627 DWORD bytes_per_sector
;
13628 DWORD free_clusters
;
13629 DWORD total_clusters
;
13631 if (GetDiskFreeSpace(rootname
,
13632 §ors_per_cluster
,
13636 value
= list3 (make_float ((double) total_clusters
13637 * sectors_per_cluster
* bytes_per_sector
),
13638 make_float ((double) free_clusters
13639 * sectors_per_cluster
* bytes_per_sector
),
13640 make_float ((double) free_clusters
13641 * sectors_per_cluster
* bytes_per_sector
));
13650 /* This is zero if not using MS-Windows. */
13653 /* The section below is built by the lisp expression at the top of the file,
13654 just above where these variables are declared. */
13655 /*&&& init symbols here &&&*/
13656 Qauto_raise
= intern ("auto-raise");
13657 staticpro (&Qauto_raise
);
13658 Qauto_lower
= intern ("auto-lower");
13659 staticpro (&Qauto_lower
);
13660 Qbar
= intern ("bar");
13662 Qborder_color
= intern ("border-color");
13663 staticpro (&Qborder_color
);
13664 Qborder_width
= intern ("border-width");
13665 staticpro (&Qborder_width
);
13666 Qbox
= intern ("box");
13668 Qcursor_color
= intern ("cursor-color");
13669 staticpro (&Qcursor_color
);
13670 Qcursor_type
= intern ("cursor-type");
13671 staticpro (&Qcursor_type
);
13672 Qgeometry
= intern ("geometry");
13673 staticpro (&Qgeometry
);
13674 Qicon_left
= intern ("icon-left");
13675 staticpro (&Qicon_left
);
13676 Qicon_top
= intern ("icon-top");
13677 staticpro (&Qicon_top
);
13678 Qicon_type
= intern ("icon-type");
13679 staticpro (&Qicon_type
);
13680 Qicon_name
= intern ("icon-name");
13681 staticpro (&Qicon_name
);
13682 Qinternal_border_width
= intern ("internal-border-width");
13683 staticpro (&Qinternal_border_width
);
13684 Qleft
= intern ("left");
13685 staticpro (&Qleft
);
13686 Qright
= intern ("right");
13687 staticpro (&Qright
);
13688 Qmouse_color
= intern ("mouse-color");
13689 staticpro (&Qmouse_color
);
13690 Qnone
= intern ("none");
13691 staticpro (&Qnone
);
13692 Qparent_id
= intern ("parent-id");
13693 staticpro (&Qparent_id
);
13694 Qscroll_bar_width
= intern ("scroll-bar-width");
13695 staticpro (&Qscroll_bar_width
);
13696 Qsuppress_icon
= intern ("suppress-icon");
13697 staticpro (&Qsuppress_icon
);
13698 Qundefined_color
= intern ("undefined-color");
13699 staticpro (&Qundefined_color
);
13700 Qvertical_scroll_bars
= intern ("vertical-scroll-bars");
13701 staticpro (&Qvertical_scroll_bars
);
13702 Qvisibility
= intern ("visibility");
13703 staticpro (&Qvisibility
);
13704 Qwindow_id
= intern ("window-id");
13705 staticpro (&Qwindow_id
);
13706 Qx_frame_parameter
= intern ("x-frame-parameter");
13707 staticpro (&Qx_frame_parameter
);
13708 Qx_resource_name
= intern ("x-resource-name");
13709 staticpro (&Qx_resource_name
);
13710 Quser_position
= intern ("user-position");
13711 staticpro (&Quser_position
);
13712 Quser_size
= intern ("user-size");
13713 staticpro (&Quser_size
);
13714 Qscreen_gamma
= intern ("screen-gamma");
13715 staticpro (&Qscreen_gamma
);
13716 Qline_spacing
= intern ("line-spacing");
13717 staticpro (&Qline_spacing
);
13718 Qcenter
= intern ("center");
13719 staticpro (&Qcenter
);
13720 Qcancel_timer
= intern ("cancel-timer");
13721 staticpro (&Qcancel_timer
);
13722 /* This is the end of symbol initialization. */
13724 Qhyper
= intern ("hyper");
13725 staticpro (&Qhyper
);
13726 Qsuper
= intern ("super");
13727 staticpro (&Qsuper
);
13728 Qmeta
= intern ("meta");
13729 staticpro (&Qmeta
);
13730 Qalt
= intern ("alt");
13732 Qctrl
= intern ("ctrl");
13733 staticpro (&Qctrl
);
13734 Qcontrol
= intern ("control");
13735 staticpro (&Qcontrol
);
13736 Qshift
= intern ("shift");
13737 staticpro (&Qshift
);
13739 /* Text property `display' should be nonsticky by default. */
13740 Vtext_property_default_nonsticky
13741 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
13744 Qlaplace
= intern ("laplace");
13745 staticpro (&Qlaplace
);
13747 Qface_set_after_frame_default
= intern ("face-set-after-frame-default");
13748 staticpro (&Qface_set_after_frame_default
);
13750 Fput (Qundefined_color
, Qerror_conditions
,
13751 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
13752 Fput (Qundefined_color
, Qerror_message
,
13753 build_string ("Undefined color"));
13755 staticpro (&w32_grabbed_keys
);
13756 w32_grabbed_keys
= Qnil
;
13758 DEFVAR_LISP ("w32-color-map", &Vw32_color_map
,
13759 "An array of color name mappings for windows.");
13760 Vw32_color_map
= Qnil
;
13762 DEFVAR_LISP ("w32-pass-alt-to-system", &Vw32_pass_alt_to_system
,
13763 "Non-nil if alt key presses are passed on to Windows.\n\
13764 When non-nil, for example, alt pressed and released and then space will\n\
13765 open the System menu. When nil, Emacs silently swallows alt key events.");
13766 Vw32_pass_alt_to_system
= Qnil
;
13768 DEFVAR_LISP ("w32-alt-is-meta", &Vw32_alt_is_meta
,
13769 "Non-nil if the alt key is to be considered the same as the meta key.\n\
13770 When nil, Emacs will translate the alt key to the Alt modifier, and not Meta.");
13771 Vw32_alt_is_meta
= Qt
;
13773 DEFVAR_INT ("w32-quit-key", &Vw32_quit_key
,
13774 "If non-zero, the virtual key code for an alternative quit key.");
13775 XSETINT (Vw32_quit_key
, 0);
13777 DEFVAR_LISP ("w32-pass-lwindow-to-system",
13778 &Vw32_pass_lwindow_to_system
,
13779 "Non-nil if the left \"Windows\" key is passed on to Windows.\n\
13780 When non-nil, the Start menu is opened by tapping the key.");
13781 Vw32_pass_lwindow_to_system
= Qt
;
13783 DEFVAR_LISP ("w32-pass-rwindow-to-system",
13784 &Vw32_pass_rwindow_to_system
,
13785 "Non-nil if the right \"Windows\" key is passed on to Windows.\n\
13786 When non-nil, the Start menu is opened by tapping the key.");
13787 Vw32_pass_rwindow_to_system
= Qt
;
13789 DEFVAR_INT ("w32-phantom-key-code",
13790 &Vw32_phantom_key_code
,
13791 "Virtual key code used to generate \"phantom\" key presses.\n\
13792 Value is a number between 0 and 255.\n\
13794 Phantom key presses are generated in order to stop the system from\n\
13795 acting on \"Windows\" key events when `w32-pass-lwindow-to-system' or\n\
13796 `w32-pass-rwindow-to-system' is nil.");
13797 /* Although 255 is technically not a valid key code, it works and
13798 means that this hack won't interfere with any real key code. */
13799 Vw32_phantom_key_code
= 255;
13801 DEFVAR_LISP ("w32-enable-num-lock",
13802 &Vw32_enable_num_lock
,
13803 "Non-nil if Num Lock should act normally.\n\
13804 Set to nil to see Num Lock as the key `kp-numlock'.");
13805 Vw32_enable_num_lock
= Qt
;
13807 DEFVAR_LISP ("w32-enable-caps-lock",
13808 &Vw32_enable_caps_lock
,
13809 "Non-nil if Caps Lock should act normally.\n\
13810 Set to nil to see Caps Lock as the key `capslock'.");
13811 Vw32_enable_caps_lock
= Qt
;
13813 DEFVAR_LISP ("w32-scroll-lock-modifier",
13814 &Vw32_scroll_lock_modifier
,
13815 "Modifier to use for the Scroll Lock on state.\n\
13816 The value can be hyper, super, meta, alt, control or shift for the\n\
13817 respective modifier, or nil to see Scroll Lock as the key `scroll'.\n\
13818 Any other value will cause the key to be ignored.");
13819 Vw32_scroll_lock_modifier
= Qt
;
13821 DEFVAR_LISP ("w32-lwindow-modifier",
13822 &Vw32_lwindow_modifier
,
13823 "Modifier to use for the left \"Windows\" key.\n\
13824 The value can be hyper, super, meta, alt, control or shift for the\n\
13825 respective modifier, or nil to appear as the key `lwindow'.\n\
13826 Any other value will cause the key to be ignored.");
13827 Vw32_lwindow_modifier
= Qnil
;
13829 DEFVAR_LISP ("w32-rwindow-modifier",
13830 &Vw32_rwindow_modifier
,
13831 "Modifier to use for the right \"Windows\" key.\n\
13832 The value can be hyper, super, meta, alt, control or shift for the\n\
13833 respective modifier, or nil to appear as the key `rwindow'.\n\
13834 Any other value will cause the key to be ignored.");
13835 Vw32_rwindow_modifier
= Qnil
;
13837 DEFVAR_LISP ("w32-apps-modifier",
13838 &Vw32_apps_modifier
,
13839 "Modifier to use for the \"Apps\" key.\n\
13840 The value can be hyper, super, meta, alt, control or shift for the\n\
13841 respective modifier, or nil to appear as the key `apps'.\n\
13842 Any other value will cause the key to be ignored.");
13843 Vw32_apps_modifier
= Qnil
;
13845 DEFVAR_BOOL ("w32-enable-synthesized-fonts", &w32_enable_synthesized_fonts
,
13846 "Non-nil enables selection of artificially italicized and bold fonts.");
13847 w32_enable_synthesized_fonts
= 0;
13849 DEFVAR_LISP ("w32-enable-palette", &Vw32_enable_palette
,
13850 "Non-nil enables Windows palette management to map colors exactly.");
13851 Vw32_enable_palette
= Qt
;
13853 DEFVAR_INT ("w32-mouse-button-tolerance",
13854 &Vw32_mouse_button_tolerance
,
13855 "Analogue of double click interval for faking middle mouse events.\n\
13856 The value is the minimum time in milliseconds that must elapse between\n\
13857 left/right button down events before they are considered distinct events.\n\
13858 If both mouse buttons are depressed within this interval, a middle mouse\n\
13859 button down event is generated instead.");
13860 XSETINT (Vw32_mouse_button_tolerance
, GetDoubleClickTime () / 2);
13862 DEFVAR_INT ("w32-mouse-move-interval",
13863 &Vw32_mouse_move_interval
,
13864 "Minimum interval between mouse move events.\n\
13865 The value is the minimum time in milliseconds that must elapse between\n\
13866 successive mouse move (or scroll bar drag) events before they are\n\
13867 reported as lisp events.");
13868 XSETINT (Vw32_mouse_move_interval
, 0);
13870 init_x_parm_symbols ();
13872 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
13873 "List of directories to search for bitmap files for w32.");
13874 Vx_bitmap_file_path
= decode_env_path ((char *) 0, "PATH");
13876 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
13877 "The shape of the pointer when over text.\n\
13878 Changing the value does not affect existing frames\n\
13879 unless you set the mouse color.");
13880 Vx_pointer_shape
= Qnil
;
13882 DEFVAR_LISP ("x-resource-name", &Vx_resource_name
,
13883 "The name Emacs uses to look up resources; for internal use only.\n\
13884 `x-get-resource' uses this as the first component of the instance name\n\
13885 when requesting resource values.\n\
13886 Emacs initially sets `x-resource-name' to the name under which Emacs\n\
13887 was invoked, or to the value specified with the `-name' or `-rn'\n\
13888 switches, if present.");
13889 Vx_resource_name
= Qnil
;
13891 Vx_nontext_pointer_shape
= Qnil
;
13893 Vx_mode_pointer_shape
= Qnil
;
13895 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
13896 "The shape of the pointer when Emacs is busy.\n\
13897 This variable takes effect when you create a new frame\n\
13898 or when you set the mouse color.");
13899 Vx_hourglass_pointer_shape
= Qnil
;
13901 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
13902 "Non-zero means Emacs displays an hourglass pointer on window systems.");
13903 display_hourglass_p
= 1;
13905 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
13906 "*Seconds to wait before displaying an hourglass pointer.\n\
13907 Value must be an integer or float.");
13908 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
13910 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
13911 &Vx_sensitive_text_pointer_shape
,
13912 "The shape of the pointer when over mouse-sensitive text.\n\
13913 This variable takes effect when you create a new frame\n\
13914 or when you set the mouse color.");
13915 Vx_sensitive_text_pointer_shape
= Qnil
;
13917 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
13918 &Vx_window_horizontal_drag_shape
,
13919 "Pointer shape to use for indicating a window can be dragged horizontally.\n\
13920 This variable takes effect when you create a new frame\n\
13921 or when you set the mouse color.");
13922 Vx_window_horizontal_drag_shape
= Qnil
;
13924 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
13925 "A string indicating the foreground color of the cursor box.");
13926 Vx_cursor_fore_pixel
= Qnil
;
13928 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
13929 "Non-nil if no window manager is in use.\n\
13930 Emacs doesn't try to figure this out; this is always nil\n\
13931 unless you set it to something else.");
13932 /* We don't have any way to find this out, so set it to nil
13933 and maybe the user would like to set it to t. */
13934 Vx_no_window_manager
= Qnil
;
13936 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
13937 &Vx_pixel_size_width_font_regexp
,
13938 "Regexp matching a font name whose width is the same as `PIXEL_SIZE'.\n\
13940 Since Emacs gets width of a font matching with this regexp from\n\
13941 PIXEL_SIZE field of the name, font finding mechanism gets faster for\n\
13942 such a font. This is especially effective for such large fonts as\n\
13943 Chinese, Japanese, and Korean.");
13944 Vx_pixel_size_width_font_regexp
= Qnil
;
13946 DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay
,
13947 "Time after which cached images are removed from the cache.\n\
13948 When an image has not been displayed this many seconds, remove it\n\
13949 from the image cache. Value must be an integer or nil with nil\n\
13950 meaning don't clear the cache.");
13951 Vimage_cache_eviction_delay
= make_number (30 * 60);
13953 DEFVAR_LISP ("w32-bdf-filename-alist",
13954 &Vw32_bdf_filename_alist
,
13955 "List of bdf fonts and their corresponding filenames.");
13956 Vw32_bdf_filename_alist
= Qnil
;
13958 DEFVAR_BOOL ("w32-strict-fontnames",
13959 &w32_strict_fontnames
,
13960 "Non-nil means only use fonts that are exact matches for those requested.\n\
13961 Default is nil, which allows old fontnames that are not XLFD compliant,\n\
13962 and allows third-party CJK display to work by specifying false charset\n\
13963 fields to trick Emacs into translating to Big5, SJIS etc.\n\
13964 Setting this to t will prevent wrong fonts being selected when\n\
13965 fontsets are automatically created.");
13966 w32_strict_fontnames
= 0;
13968 DEFVAR_BOOL ("w32-strict-painting",
13969 &w32_strict_painting
,
13970 "Non-nil means use strict rules for repainting frames.\n\
13971 Set this to nil to get the old behaviour for repainting; this should\n\
13972 only be necessary if the default setting causes problems.");
13973 w32_strict_painting
= 1;
13975 DEFVAR_LISP ("w32-system-coding-system",
13976 &Vw32_system_coding_system
,
13977 "Coding system used by Windows system functions, such as for font names.");
13978 Vw32_system_coding_system
= Qnil
;
13980 DEFVAR_LISP ("w32-charset-info-alist",
13981 &Vw32_charset_info_alist
,
13982 "Alist linking Emacs character sets to Windows fonts\n\
13983 and codepages. Each entry should be of the form:\n\
13985 (CHARSET-NAME . (WINDOWS-CHARSET . CODEPAGE))\n\
13987 where CHARSET-NAME is a string used in font names to identify the charset,\n\
13988 WINDOWS-CHARSET is a symbol that can be one of:\n\
13989 w32-charset-ansi, w32-charset-default, w32-charset-symbol,\n\
13990 w32-charset-shiftjis, w32-charset-hangeul, w32-charset-gb2312,\n\
13991 w32-charset-chinesebig5, w32-charset-johab, w32-charset-hebrew,\n\
13992 w32-charset-arabic, w32-charset-greek, w32-charset-turkish,\n\
13993 w32-charset-vietnamese, w32-charset-thai, w32-charset-easteurope,\n\
13994 w32-charset-russian, w32-charset-mac, w32-charset-baltic,\n\
13995 w32-charset-unicode, or w32-charset-oem.\n\
13996 (Some of these symbols are only meaningful on certain versions of Windows.)\n\
13997 CODEPAGE should be an integer specifying the codepage that should be used\n\
13998 to display the character set, t to do no translation and output as Unicode,\n\
13999 or nil to do no translation and output as 8 bit (or multibyte on far-east\n\
14000 versions of Windows) characters.");
14001 Vw32_charset_info_alist
= Qnil
;
14003 staticpro (&Qw32_charset_ansi
);
14004 Qw32_charset_ansi
= intern ("w32-charset-ansi");
14005 staticpro (&Qw32_charset_symbol
);
14006 Qw32_charset_symbol
= intern ("w32-charset-symbol");
14007 staticpro (&Qw32_charset_shiftjis
);
14008 Qw32_charset_shiftjis
= intern ("w32-charset-shiftjis");
14009 staticpro (&Qw32_charset_hangeul
);
14010 Qw32_charset_hangeul
= intern ("w32-charset-hangeul");
14011 staticpro (&Qw32_charset_chinesebig5
);
14012 Qw32_charset_chinesebig5
= intern ("w32-charset-chinesebig5");
14013 staticpro (&Qw32_charset_gb2312
);
14014 Qw32_charset_gb2312
= intern ("w32-charset-gb2312");
14015 staticpro (&Qw32_charset_oem
);
14016 Qw32_charset_oem
= intern ("w32-charset-oem");
14018 #ifdef JOHAB_CHARSET
14020 static int w32_extra_charsets_defined
= 1;
14021 DEFVAR_BOOL ("w32-extra-charsets-defined", &w32_extra_charsets_defined
, "");
14023 staticpro (&Qw32_charset_johab
);
14024 Qw32_charset_johab
= intern ("w32-charset-johab");
14025 staticpro (&Qw32_charset_easteurope
);
14026 Qw32_charset_easteurope
= intern ("w32-charset-easteurope");
14027 staticpro (&Qw32_charset_turkish
);
14028 Qw32_charset_turkish
= intern ("w32-charset-turkish");
14029 staticpro (&Qw32_charset_baltic
);
14030 Qw32_charset_baltic
= intern ("w32-charset-baltic");
14031 staticpro (&Qw32_charset_russian
);
14032 Qw32_charset_russian
= intern ("w32-charset-russian");
14033 staticpro (&Qw32_charset_arabic
);
14034 Qw32_charset_arabic
= intern ("w32-charset-arabic");
14035 staticpro (&Qw32_charset_greek
);
14036 Qw32_charset_greek
= intern ("w32-charset-greek");
14037 staticpro (&Qw32_charset_hebrew
);
14038 Qw32_charset_hebrew
= intern ("w32-charset-hebrew");
14039 staticpro (&Qw32_charset_vietnamese
);
14040 Qw32_charset_vietnamese
= intern ("w32-charset-vietnamese");
14041 staticpro (&Qw32_charset_thai
);
14042 Qw32_charset_thai
= intern ("w32-charset-thai");
14043 staticpro (&Qw32_charset_mac
);
14044 Qw32_charset_mac
= intern ("w32-charset-mac");
14048 #ifdef UNICODE_CHARSET
14050 static int w32_unicode_charset_defined
= 1;
14051 DEFVAR_BOOL ("w32-unicode-charset-defined",
14052 &w32_unicode_charset_defined
, "");
14054 staticpro (&Qw32_charset_unicode
);
14055 Qw32_charset_unicode
= intern ("w32-charset-unicode");
14058 defsubr (&Sx_get_resource
);
14059 #if 0 /* TODO: Port to W32 */
14060 defsubr (&Sx_change_window_property
);
14061 defsubr (&Sx_delete_window_property
);
14062 defsubr (&Sx_window_property
);
14064 defsubr (&Sxw_display_color_p
);
14065 defsubr (&Sx_display_grayscale_p
);
14066 defsubr (&Sxw_color_defined_p
);
14067 defsubr (&Sxw_color_values
);
14068 defsubr (&Sx_server_max_request_size
);
14069 defsubr (&Sx_server_vendor
);
14070 defsubr (&Sx_server_version
);
14071 defsubr (&Sx_display_pixel_width
);
14072 defsubr (&Sx_display_pixel_height
);
14073 defsubr (&Sx_display_mm_width
);
14074 defsubr (&Sx_display_mm_height
);
14075 defsubr (&Sx_display_screens
);
14076 defsubr (&Sx_display_planes
);
14077 defsubr (&Sx_display_color_cells
);
14078 defsubr (&Sx_display_visual_class
);
14079 defsubr (&Sx_display_backing_store
);
14080 defsubr (&Sx_display_save_under
);
14081 defsubr (&Sx_parse_geometry
);
14082 defsubr (&Sx_create_frame
);
14083 defsubr (&Sx_open_connection
);
14084 defsubr (&Sx_close_connection
);
14085 defsubr (&Sx_display_list
);
14086 defsubr (&Sx_synchronize
);
14088 /* W32 specific functions */
14090 defsubr (&Sw32_focus_frame
);
14091 defsubr (&Sw32_select_font
);
14092 defsubr (&Sw32_define_rgb_color
);
14093 defsubr (&Sw32_default_color_map
);
14094 defsubr (&Sw32_load_color_file
);
14095 defsubr (&Sw32_send_sys_command
);
14096 defsubr (&Sw32_shell_execute
);
14097 defsubr (&Sw32_register_hot_key
);
14098 defsubr (&Sw32_unregister_hot_key
);
14099 defsubr (&Sw32_registered_hot_keys
);
14100 defsubr (&Sw32_reconstruct_hot_key
);
14101 defsubr (&Sw32_toggle_lock_key
);
14102 defsubr (&Sw32_find_bdf_fonts
);
14104 defsubr (&Sfile_system_info
);
14106 /* Setting callback functions for fontset handler. */
14107 get_font_info_func
= w32_get_font_info
;
14109 #if 0 /* This function pointer doesn't seem to be used anywhere.
14110 And the pointer assigned has the wrong type, anyway. */
14111 list_fonts_func
= w32_list_fonts
;
14114 load_font_func
= w32_load_font
;
14115 find_ccl_program_func
= w32_find_ccl_program
;
14116 query_font_func
= w32_query_font
;
14117 set_frame_fontset_func
= x_set_font
;
14118 check_window_system_func
= check_w32
;
14120 #if 0 /* TODO Image support for W32 */
14122 Qxbm
= intern ("xbm");
14124 QCtype
= intern (":type");
14125 staticpro (&QCtype
);
14126 QCconversion
= intern (":conversion");
14127 staticpro (&QCconversion
);
14128 QCheuristic_mask
= intern (":heuristic-mask");
14129 staticpro (&QCheuristic_mask
);
14130 QCcolor_symbols
= intern (":color-symbols");
14131 staticpro (&QCcolor_symbols
);
14132 QCascent
= intern (":ascent");
14133 staticpro (&QCascent
);
14134 QCmargin
= intern (":margin");
14135 staticpro (&QCmargin
);
14136 QCrelief
= intern (":relief");
14137 staticpro (&QCrelief
);
14138 Qpostscript
= intern ("postscript");
14139 staticpro (&Qpostscript
);
14140 QCloader
= intern (":loader");
14141 staticpro (&QCloader
);
14142 QCbounding_box
= intern (":bounding-box");
14143 staticpro (&QCbounding_box
);
14144 QCpt_width
= intern (":pt-width");
14145 staticpro (&QCpt_width
);
14146 QCpt_height
= intern (":pt-height");
14147 staticpro (&QCpt_height
);
14148 QCindex
= intern (":index");
14149 staticpro (&QCindex
);
14150 Qpbm
= intern ("pbm");
14154 Qxpm
= intern ("xpm");
14159 Qjpeg
= intern ("jpeg");
14160 staticpro (&Qjpeg
);
14164 Qtiff
= intern ("tiff");
14165 staticpro (&Qtiff
);
14169 Qgif
= intern ("gif");
14174 Qpng
= intern ("png");
14178 defsubr (&Sclear_image_cache
);
14181 defsubr (&Simagep
);
14182 defsubr (&Slookup_image
);
14186 hourglass_atimer
= NULL
;
14187 hourglass_shown_p
= 0;
14188 #ifdef TODO /* Tooltip support not complete. */
14189 defsubr (&Sx_show_tip
);
14190 defsubr (&Sx_hide_tip
);
14193 staticpro (&tip_timer
);
14195 staticpro (&tip_frame
);
14197 defsubr (&Sx_file_dialog
);
14204 image_types
= NULL
;
14205 Vimage_types
= Qnil
;
14207 #if 0 /* TODO : Image support for W32 */
14208 define_image_type (&xbm_type
);
14209 define_image_type (&gs_type
);
14210 define_image_type (&pbm_type
);
14213 define_image_type (&xpm_type
);
14217 define_image_type (&jpeg_type
);
14221 define_image_type (&tiff_type
);
14225 define_image_type (&gif_type
);
14229 define_image_type (&png_type
);
14240 button
= MessageBox (NULL
,
14241 "A fatal error has occurred!\n\n"
14242 "Select Abort to exit, Retry to debug, Ignore to continue",
14243 "Emacs Abort Dialog",
14244 MB_ICONEXCLAMATION
| MB_TASKMODAL
14245 | MB_SETFOREGROUND
| MB_ABORTRETRYIGNORE
);
14260 /* For convenience when debugging. */
14264 return GetLastError ();